1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* See the GDB User Guide for details of the GDB remote protocol. */
25 #include "gdb_string.h"
34 /*#include "terminal.h" */
37 #include "gdb-stabs.h"
38 #include "gdbthread.h"
46 #include <sys/types.h>
49 #include "event-loop.h"
50 #include "event-top.h"
55 /* Prototypes for local functions */
56 static void cleanup_sigint_signal_handler (void *dummy);
57 static void initialize_sigint_signal_handler (void);
59 static void handle_remote_sigint PARAMS ((int));
60 static void handle_remote_sigint_twice PARAMS ((int));
61 static void async_remote_interrupt PARAMS ((gdb_client_data));
62 static void async_remote_interrupt_twice PARAMS ((gdb_client_data));
64 static void set_extended_protocol PARAMS ((struct continuation_arg *));
66 static void build_remote_gdbarch_data PARAMS ((void));
68 static int remote_write_bytes PARAMS ((CORE_ADDR memaddr,
69 char *myaddr, int len));
71 static int remote_read_bytes PARAMS ((CORE_ADDR memaddr,
72 char *myaddr, int len));
74 static void remote_files_info PARAMS ((struct target_ops * ignore));
76 static int remote_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
77 int len, int should_write,
78 struct target_ops * target));
80 static void remote_prepare_to_store PARAMS ((void));
82 static void remote_fetch_registers PARAMS ((int regno));
84 static void remote_resume PARAMS ((int pid, int step,
85 enum target_signal siggnal));
86 static void remote_async_resume PARAMS ((int pid, int step,
87 enum target_signal siggnal));
88 static int remote_start_remote PARAMS ((PTR));
90 static void remote_open PARAMS ((char *name, int from_tty));
91 static void remote_async_open PARAMS ((char *name, int from_tty));
93 static void extended_remote_open PARAMS ((char *name, int from_tty));
94 static void extended_remote_async_open PARAMS ((char *name, int from_tty));
96 static void remote_open_1 PARAMS ((char *, int, struct target_ops *,
98 static void remote_async_open_1 PARAMS ((char *, int, struct target_ops *,
101 static void remote_close PARAMS ((int quitting));
103 static void remote_store_registers PARAMS ((int regno));
105 static void remote_mourn PARAMS ((void));
106 static void remote_async_mourn PARAMS ((void));
108 static void extended_remote_restart PARAMS ((void));
110 static void extended_remote_mourn PARAMS ((void));
112 static void extended_remote_create_inferior PARAMS ((char *, char *, char **));
113 static void extended_remote_async_create_inferior PARAMS ((char *, char *, char **));
115 static void remote_mourn_1 PARAMS ((struct target_ops *));
117 static void remote_send PARAMS ((char *buf));
119 static int readchar PARAMS ((int timeout));
121 static int remote_wait PARAMS ((int pid, struct target_waitstatus * status));
122 static int remote_async_wait PARAMS ((int pid, struct target_waitstatus * status));
124 static void remote_kill PARAMS ((void));
125 static void remote_async_kill PARAMS ((void));
127 static int tohex PARAMS ((int nib));
129 static void remote_detach PARAMS ((char *args, int from_tty));
130 static void remote_async_detach PARAMS ((char *args, int from_tty));
132 static void remote_interrupt PARAMS ((int signo));
134 static void remote_interrupt_twice PARAMS ((int signo));
136 static void interrupt_query PARAMS ((void));
138 static void set_thread PARAMS ((int, int));
140 static int remote_thread_alive PARAMS ((int));
142 static void get_offsets PARAMS ((void));
144 static int read_frame PARAMS ((char *));
146 static int remote_insert_breakpoint PARAMS ((CORE_ADDR, char *));
148 static int remote_remove_breakpoint PARAMS ((CORE_ADDR, char *));
150 static int hexnumlen PARAMS ((ULONGEST num));
152 static void init_remote_ops PARAMS ((void));
154 static void init_extended_remote_ops PARAMS ((void));
156 static void init_remote_cisco_ops PARAMS ((void));
158 static struct target_ops remote_cisco_ops;
160 static void remote_stop PARAMS ((void));
162 static int ishex PARAMS ((int ch, int *val));
164 static int stubhex PARAMS ((int ch));
166 static int remote_query PARAMS ((int /*char */ , char *, char *, int *));
168 static int hexnumstr PARAMS ((char *, ULONGEST));
170 static CORE_ADDR remote_address_masked PARAMS ((CORE_ADDR));
172 static void print_packet PARAMS ((char *));
174 static unsigned long crc32 PARAMS ((unsigned char *, int, unsigned int));
176 static void compare_sections_command PARAMS ((char *, int));
178 static void packet_command PARAMS ((char *, int));
180 static int stub_unpack_int PARAMS ((char *buff, int fieldlength));
182 static int remote_current_thread PARAMS ((int oldpid));
184 static void remote_find_new_threads PARAMS ((void));
186 static void record_currthread PARAMS ((int currthread));
188 /* exported functions */
190 extern int fromhex PARAMS ((int a));
192 static int putpkt_binary PARAMS ((char *buf, int cnt));
194 static void check_binary_download PARAMS ((CORE_ADDR addr));
196 struct packet_config;
198 static void show_packet_config_cmd PARAMS ((struct packet_config * config));
200 static void set_packet_config_cmd PARAMS ((struct packet_config * config,
201 struct cmd_list_element * c));
203 static void add_packet_config_cmd PARAMS ((struct packet_config * config,
206 void (*set_func) (char *args, int from_tty, struct cmd_list_element * c),
207 void (*show_func) (char *name, int from_tty),
208 struct cmd_list_element **setlist,
209 struct cmd_list_element **showlist));
211 static void init_packet_config PARAMS ((struct packet_config * config));
213 static void set_remote_protocol_P_packet_cmd PARAMS ((char *args,
215 struct cmd_list_element * c));
217 static void show_remote_protocol_P_packet_cmd PARAMS ((char *args,
220 static void set_remote_protocol_Z_packet_cmd PARAMS ((char *args,
222 struct cmd_list_element * c));
224 static void show_remote_protocol_Z_packet_cmd PARAMS ((char *args,
230 /* Define the target subroutine names */
232 void open_remote_target PARAMS ((char *, int, struct target_ops *, int));
234 void _initialize_remote PARAMS ((void));
238 static struct target_ops remote_ops;
240 static struct target_ops extended_remote_ops;
242 /* Temporary target ops. Just like the remote_ops and
243 extended_remote_ops, but with asynchronous support. */
244 static struct target_ops remote_async_ops;
246 static struct target_ops extended_async_remote_ops;
248 /* This was 5 seconds, which is a long time to sit and wait.
249 Unless this is going though some terminal server or multiplexer or
250 other form of hairy serial connection, I would think 2 seconds would
253 /* Changed to allow option to set timeout value.
254 was static int remote_timeout = 2; */
255 extern int remote_timeout;
257 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
258 ``forever'' still use the normal timeout mechanism. This is
259 currently used by the ASYNC code to guarentee that target reads
260 during the initial connect always time-out. Once getpkt has been
261 modified to return a timeout indication and, in turn
262 remote_wait()/wait_for_inferior() have gained a timeout parameter
264 static int wait_forever_enabled_p = 1;
267 /* This variable chooses whether to send a ^C or a break when the user
268 requests program interruption. Although ^C is usually what remote
269 systems expect, and that is the default here, sometimes a break is
270 preferable instead. */
272 static int remote_break;
274 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
275 remote_open knows that we don't have a file open when the program
277 static serial_t remote_desc = NULL;
279 /* This is set by the target (thru the 'S' message)
280 to denote that the target is in kernel mode. */
281 static int cisco_kernel_mode = 0;
283 /* Maximum number of bytes to read/write at once. The value here
284 is chosen to fill up a packet (the headers account for the 32). */
285 #define MAXBUFBYTES(N) (((N)-32)/2)
287 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
288 and i386-stub.c. Normally, no one would notice because it only matters
289 for writing large chunks of memory (e.g. in downloads). Also, this needs
290 to be more than 400 if required to hold the registers (see below, where
291 we round it up based on REGISTER_BYTES). */
292 /* Round up PBUFSIZ to hold all the registers, at least. */
293 #define PBUFSIZ ((REGISTER_BYTES > MAXBUFBYTES (400)) \
294 ? (REGISTER_BYTES * 2 + 32) \
298 /* This variable sets the number of bytes to be written to the target
299 in a single packet. Normally PBUFSIZ is satisfactory, but some
300 targets need smaller values (perhaps because the receiving end
303 static int remote_write_size;
305 /* This variable sets the number of bits in an address that are to be
306 sent in a memory ("M" or "m") packet. Normally, after stripping
307 leading zeros, the entire address would be sent. This variable
308 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
309 initial implementation of remote.c restricted the address sent in
310 memory packets to ``host::sizeof long'' bytes - (typically 32
311 bits). Consequently, for 64 bit targets, the upper 32 bits of an
312 address was never sent. Since fixing this bug may cause a break in
313 some remote targets this variable is principly provided to
314 facilitate backward compatibility. */
316 static int remote_address_size;
318 /* This is the size (in chars) of the first response to the `g' command. This
319 is used to limit the size of the memory read and write commands to prevent
320 stub buffers from overflowing. The size does not include headers and
321 trailers, it is only the payload size. */
323 static int remote_register_buf_size = 0;
325 /* Tempoary to track who currently owns the terminal. See
326 target_async_terminal_* for more details. */
328 static int remote_async_terminal_ours_p;
330 /* Generic configuration support for packets the stub optionally
331 supports. Allows the user to specify the use of the packet as well
332 as allowing GDB to auto-detect support in the remote stub. */
336 PACKET_SUPPORT_UNKNOWN = 0,
343 PACKET_AUTO_DETECT = 0,
352 enum packet_detect detect;
353 enum packet_support support;
356 static char packet_support_auto[] = "auto";
357 static char packet_enable[] = "enable";
358 static char packet_disable[] = "disable";
359 static char *packet_support_enums[] =
368 set_packet_config_cmd (config, c)
369 struct packet_config *config;
370 struct cmd_list_element *c;
372 if (config->state == packet_enable)
374 config->detect = PACKET_MANUAL_DETECT;
375 config->support = PACKET_ENABLE;
377 else if (config->state == packet_disable)
379 config->detect = PACKET_MANUAL_DETECT;
380 config->support = PACKET_DISABLE;
382 else if (config->state == packet_support_auto)
384 config->detect = PACKET_AUTO_DETECT;
385 config->support = PACKET_SUPPORT_UNKNOWN;
388 internal_error ("Bad enum value");
392 show_packet_config_cmd (config)
393 struct packet_config *config;
395 char *support = "internal-error";
396 switch (config->support)
402 support = "disabled";
404 case PACKET_SUPPORT_UNKNOWN:
408 switch (config->detect)
410 case PACKET_AUTO_DETECT:
411 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
412 config->name, config->title, support);
414 case PACKET_MANUAL_DETECT:
415 printf_filtered ("Support for remote protocol `%s' (%s) is currently %s.\n",
416 config->name, config->title, support);
421 add_packet_config_cmd (config, name, title, set_func, show_func,
423 struct packet_config *config;
426 void (*set_func) PARAMS ((char *args, int from_tty,
427 struct cmd_list_element * c));
428 void (*show_func) PARAMS ((char *name, int from_tty));
429 struct cmd_list_element **setlist;
430 struct cmd_list_element **showlist;
432 struct cmd_list_element *c;
437 config->title = title;
438 asprintf (&set_doc, "Set use of remote protocol `%s' (%s) packet",
440 asprintf (&show_doc, "Show current use of remote protocol `%s' (%s) packet",
442 asprintf (&full_name, "%s-packet", name);
443 c = add_set_enum_cmd (full_name,
444 class_obscure, packet_support_enums,
445 (char *) &config->state,
447 c->function.sfunc = set_func;
448 add_cmd (full_name, class_obscure, show_func, show_doc, showlist);
452 init_packet_config (config)
453 struct packet_config *config;
455 switch (config->detect)
457 case PACKET_AUTO_DETECT:
458 config->support = PACKET_SUPPORT_UNKNOWN;
460 case PACKET_MANUAL_DETECT:
461 /* let the user beware */
466 /* Should we try the 'P' (set register) request? */
468 static struct packet_config remote_protocol_P;
471 set_remote_protocol_P_packet_cmd (args, from_tty, c)
474 struct cmd_list_element *c;
476 set_packet_config_cmd (&remote_protocol_P, c);
480 show_remote_protocol_P_packet_cmd (args, from_tty)
484 show_packet_config_cmd (&remote_protocol_P);
487 /* Should we try the 'Z' (set breakpoint) request? */
489 static struct packet_config remote_protocol_Z;
492 set_remote_protocol_Z_packet_cmd (args, from_tty, c)
495 struct cmd_list_element *c;
497 set_packet_config_cmd (&remote_protocol_Z, c);
501 show_remote_protocol_Z_packet_cmd (args, from_tty)
505 show_packet_config_cmd (&remote_protocol_Z);
508 /* Should we try the 'X' (remote binary download) packet?
510 This variable (available to the user via "set remote X-packet")
511 dictates whether downloads are sent in binary (via the 'X' packet).
512 We assume that the stub can, and attempt to do it. This will be
513 cleared if the stub does not understand it. This switch is still
514 needed, though in cases when the packet is supported in the stub,
515 but the connection does not allow it (i.e., 7-bit serial connection
518 static struct packet_config remote_protocol_binary_download;
521 set_remote_protocol_binary_download_cmd (char *args,
523 struct cmd_list_element *c)
525 set_packet_config_cmd (&remote_protocol_binary_download, c);
529 show_remote_protocol_binary_download_cmd (char *args,
532 show_packet_config_cmd (&remote_protocol_binary_download);
536 /* Tokens for use by the asynchronous signal handlers for SIGINT */
537 PTR sigint_remote_twice_token;
538 PTR sigint_remote_token;
540 /* These are pointers to hook functions that may be set in order to
541 modify resume/wait behavior for a particular architecture. */
543 void (*target_resume_hook) PARAMS ((void));
544 void (*target_wait_loop_hook) PARAMS ((void));
548 /* These are the threads which we last sent to the remote system.
549 -1 for all or -2 for not sent yet. */
550 static int general_thread;
551 static int continue_thread;
553 /* Call this function as a result of
554 1) A halt indication (T packet) containing a thread id
555 2) A direct query of currthread
556 3) Successful execution of set thread
560 record_currthread (currthread)
563 general_thread = currthread;
565 /* If this is a new thread, add it to GDB's thread list.
566 If we leave it up to WFI to do this, bad things will happen. */
567 if (!in_thread_list (currthread))
569 add_thread (currthread);
570 printf_filtered ("[New %s]\n", target_pid_to_str (currthread));
574 #define MAGIC_NULL_PID 42000
581 char *buf = alloca (PBUFSIZ);
582 int state = gen ? general_thread : continue_thread;
588 buf[1] = gen ? 'g' : 'c';
589 if (th == MAGIC_NULL_PID)
595 sprintf (&buf[2], "-%x", -th);
597 sprintf (&buf[2], "%x", th);
603 continue_thread = th;
606 /* Return nonzero if the thread TH is still alive on the remote system. */
609 remote_thread_alive (tid)
615 sprintf (buf, "T-%08x", -tid);
617 sprintf (buf, "T%08x", tid);
620 return (buf[0] == 'O' && buf[1] == 'K');
623 /* About these extended threadlist and threadinfo packets. They are
624 variable length packets but, the fields within them are often fixed
625 length. They are redundent enough to send over UDP as is the
626 remote protocol in general. There is a matching unit test module
629 #define OPAQUETHREADBYTES 8
631 /* a 64 bit opaque identifier */
632 typedef unsigned char threadref[OPAQUETHREADBYTES];
634 /* WARNING: This threadref data structure comes from the remote O.S., libstub
635 protocol encoding, and remote.c. it is not particularly changable */
637 /* Right now, the internal structure is int. We want it to be bigger.
641 typedef int gdb_threadref; /* internal GDB thread reference */
643 /* gdb_ext_thread_info is an internal GDB data structure which is
644 equivalint to the reply of the remote threadinfo packet */
646 struct gdb_ext_thread_info
648 threadref threadid; /* External form of thread reference */
649 int active; /* Has state interesting to GDB? , regs, stack */
650 char display[256]; /* Brief state display, name, blocked/syspended */
651 char shortname[32]; /* To be used to name threads */
652 char more_display[256]; /* Long info, statistics, queue depth, whatever */
655 /* The volume of remote transfers can be limited by submitting
656 a mask containing bits specifying the desired information.
657 Use a union of these values as the 'selection' parameter to
658 get_thread_info. FIXME: Make these TAG names more thread specific.
661 #define TAG_THREADID 1
663 #define TAG_DISPLAY 4
664 #define TAG_THREADNAME 8
665 #define TAG_MOREDISPLAY 16
667 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
669 char *unpack_varlen_hex PARAMS ((char *buff, int *result));
671 static char *unpack_nibble PARAMS ((char *buf, int *val));
673 static char *pack_nibble PARAMS ((char *buf, int nibble));
675 static char *pack_hex_byte PARAMS ((char *pkt, int /*unsigned char */ byte));
677 static char *unpack_byte PARAMS ((char *buf, int *value));
679 static char *pack_int PARAMS ((char *buf, int value));
681 static char *unpack_int PARAMS ((char *buf, int *value));
683 static char *unpack_string PARAMS ((char *src, char *dest, int length));
685 static char *pack_threadid PARAMS ((char *pkt, threadref * id));
687 static char *unpack_threadid PARAMS ((char *inbuf, threadref * id));
689 void int_to_threadref PARAMS ((threadref * id, int value));
691 static int threadref_to_int PARAMS ((threadref * ref));
693 static void copy_threadref PARAMS ((threadref * dest, threadref * src));
695 static int threadmatch PARAMS ((threadref * dest, threadref * src));
697 static char *pack_threadinfo_request PARAMS ((char *pkt, int mode,
700 static int remote_unpack_thread_info_response PARAMS ((char *pkt,
701 threadref * expectedref,
702 struct gdb_ext_thread_info * info));
705 static int remote_get_threadinfo PARAMS ((threadref * threadid,
706 int fieldset, /*TAG mask */
707 struct gdb_ext_thread_info * info));
709 static int adapt_remote_get_threadinfo PARAMS ((gdb_threadref * ref,
711 struct gdb_ext_thread_info * info));
713 static char *pack_threadlist_request PARAMS ((char *pkt, int startflag,
715 threadref * nextthread));
717 static int parse_threadlist_response PARAMS ((char *pkt,
719 threadref * original_echo,
720 threadref * resultlist,
723 static int remote_get_threadlist PARAMS ((int startflag,
724 threadref * nextthread,
728 threadref * threadlist));
730 typedef int (*rmt_thread_action) (threadref * ref, void *context);
732 static int remote_threadlist_iterator PARAMS ((rmt_thread_action stepfunction,
733 void *context, int looplimit));
735 static int remote_newthread_step PARAMS ((threadref * ref, void *context));
737 /* encode 64 bits in 16 chars of hex */
739 static const char hexchars[] = "0123456789abcdef";
746 if ((ch >= 'a') && (ch <= 'f'))
748 *val = ch - 'a' + 10;
751 if ((ch >= 'A') && (ch <= 'F'))
753 *val = ch - 'A' + 10;
756 if ((ch >= '0') && (ch <= '9'))
768 if (ch >= 'a' && ch <= 'f')
769 return ch - 'a' + 10;
770 if (ch >= '0' && ch <= '9')
772 if (ch >= 'A' && ch <= 'F')
773 return ch - 'A' + 10;
778 stub_unpack_int (buff, fieldlength)
787 nibble = stubhex (*buff++);
791 retval = retval << 4;
797 unpack_varlen_hex (buff, result)
798 char *buff; /* packet to parse */
804 while (ishex (*buff, &nibble))
807 retval = retval << 4;
808 retval |= nibble & 0x0f;
815 unpack_nibble (buf, val)
824 pack_nibble (buf, nibble)
828 *buf++ = hexchars[(nibble & 0x0f)];
833 pack_hex_byte (pkt, byte)
837 *pkt++ = hexchars[(byte >> 4) & 0xf];
838 *pkt++ = hexchars[(byte & 0xf)];
843 unpack_byte (buf, value)
847 *value = stub_unpack_int (buf, 2);
852 pack_int (buf, value)
856 buf = pack_hex_byte (buf, (value >> 24) & 0xff);
857 buf = pack_hex_byte (buf, (value >> 16) & 0xff);
858 buf = pack_hex_byte (buf, (value >> 8) & 0x0ff);
859 buf = pack_hex_byte (buf, (value & 0xff));
864 unpack_int (buf, value)
868 *value = stub_unpack_int (buf, 8);
872 #if 0 /* currently unused, uncomment when needed */
873 static char *pack_string PARAMS ((char *pkt, char *string));
876 pack_string (pkt, string)
883 len = strlen (string);
885 len = 200; /* Bigger than most GDB packets, junk??? */
886 pkt = pack_hex_byte (pkt, len);
890 if ((ch == '\0') || (ch == '#'))
891 ch = '*'; /* Protect encapsulation */
896 #endif /* 0 (unused) */
899 unpack_string (src, dest, length)
911 pack_threadid (pkt, id)
916 unsigned char *altid;
918 altid = (unsigned char *) id;
919 limit = pkt + BUF_THREAD_ID_SIZE;
921 pkt = pack_hex_byte (pkt, *altid++);
927 unpack_threadid (inbuf, id)
932 char *limit = inbuf + BUF_THREAD_ID_SIZE;
935 altref = (char *) id;
937 while (inbuf < limit)
939 x = stubhex (*inbuf++);
940 y = stubhex (*inbuf++);
941 *altref++ = (x << 4) | y;
946 /* Externally, threadrefs are 64 bits but internally, they are still
947 ints. This is due to a mismatch of specifications. We would like
948 to use 64bit thread references internally. This is an adapter
952 int_to_threadref (id, value)
958 scan = (unsigned char *) id;
964 *scan++ = (value >> 24) & 0xff;
965 *scan++ = (value >> 16) & 0xff;
966 *scan++ = (value >> 8) & 0xff;
967 *scan++ = (value & 0xff);
971 threadref_to_int (ref)
981 value = (value << 8) | ((*scan++) & 0xff);
986 copy_threadref (dest, src)
991 unsigned char *csrc, *cdest;
993 csrc = (unsigned char *) src;
994 cdest = (unsigned char *) dest;
1001 threadmatch (dest, src)
1005 /* things are broken right now, so just assume we got a match */
1007 unsigned char *srcp, *destp;
1009 srcp = (char *) src;
1010 destp = (char *) dest;
1014 result &= (*srcp++ == *destp++) ? 1 : 0;
1021 threadid:1, # always request threadid
1028 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1031 pack_threadinfo_request (pkt, mode, id)
1036 *pkt++ = 'q'; /* Info Query */
1037 *pkt++ = 'P'; /* process or thread info */
1038 pkt = pack_int (pkt, mode); /* mode */
1039 pkt = pack_threadid (pkt, id); /* threadid */
1040 *pkt = '\0'; /* terminate */
1044 /* These values tag the fields in a thread info response packet */
1045 /* Tagging the fields allows us to request specific fields and to
1046 add more fields as time goes by */
1048 #define TAG_THREADID 1 /* Echo the thread identifier */
1049 #define TAG_EXISTS 2 /* Is this process defined enough to
1050 fetch registers and its stack */
1051 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1052 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1053 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1057 remote_unpack_thread_info_response (pkt, expectedref, info)
1059 threadref *expectedref;
1060 struct gdb_ext_thread_info *info;
1065 char *limit = pkt + PBUFSIZ; /* plausable parsing limit */
1068 /* info->threadid = 0; FIXME: implement zero_threadref */
1070 info->display[0] = '\0';
1071 info->shortname[0] = '\0';
1072 info->more_display[0] = '\0';
1074 /* Assume the characters indicating the packet type have been stripped */
1075 pkt = unpack_int (pkt, &mask); /* arg mask */
1076 pkt = unpack_threadid (pkt, &ref);
1079 warning ("Incomplete response to threadinfo request\n");
1080 if (!threadmatch (&ref, expectedref))
1081 { /* This is an answer to a different request */
1082 warning ("ERROR RMT Thread info mismatch\n");
1085 copy_threadref (&info->threadid, &ref);
1087 /* Loop on tagged fields , try to bail if somthing goes wrong */
1089 while ((pkt < limit) && mask && *pkt) /* packets are terminated with nulls */
1091 pkt = unpack_int (pkt, &tag); /* tag */
1092 pkt = unpack_byte (pkt, &length); /* length */
1093 if (!(tag & mask)) /* tags out of synch with mask */
1095 warning ("ERROR RMT: threadinfo tag mismatch\n");
1099 if (tag == TAG_THREADID)
1103 warning ("ERROR RMT: length of threadid is not 16\n");
1107 pkt = unpack_threadid (pkt, &ref);
1108 mask = mask & ~TAG_THREADID;
1111 if (tag == TAG_EXISTS)
1113 info->active = stub_unpack_int (pkt, length);
1115 mask = mask & ~(TAG_EXISTS);
1118 warning ("ERROR RMT: 'exists' length too long\n");
1124 if (tag == TAG_THREADNAME)
1126 pkt = unpack_string (pkt, &info->shortname[0], length);
1127 mask = mask & ~TAG_THREADNAME;
1130 if (tag == TAG_DISPLAY)
1132 pkt = unpack_string (pkt, &info->display[0], length);
1133 mask = mask & ~TAG_DISPLAY;
1136 if (tag == TAG_MOREDISPLAY)
1138 pkt = unpack_string (pkt, &info->more_display[0], length);
1139 mask = mask & ~TAG_MOREDISPLAY;
1142 warning ("ERROR RMT: unknown thread info tag\n");
1143 break; /* Not a tag we know about */
1149 remote_get_threadinfo (threadid, fieldset, info)
1150 threadref *threadid;
1151 int fieldset; /* TAG mask */
1152 struct gdb_ext_thread_info *info;
1155 char *threadinfo_pkt = alloca (PBUFSIZ);
1157 pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
1158 putpkt (threadinfo_pkt);
1159 getpkt (threadinfo_pkt, 0);
1160 result = remote_unpack_thread_info_response (threadinfo_pkt + 2, threadid,
1165 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1166 representation of a threadid. */
1169 adapt_remote_get_threadinfo (ref, selection, info)
1172 struct gdb_ext_thread_info *info;
1176 int_to_threadref (&lclref, *ref);
1177 return remote_get_threadinfo (&lclref, selection, info);
1180 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1183 pack_threadlist_request (pkt, startflag, threadcount, nextthread)
1187 threadref *nextthread;
1189 *pkt++ = 'q'; /* info query packet */
1190 *pkt++ = 'L'; /* Process LIST or threadLIST request */
1191 pkt = pack_nibble (pkt, startflag); /* initflag 1 bytes */
1192 pkt = pack_hex_byte (pkt, threadcount); /* threadcount 2 bytes */
1193 pkt = pack_threadid (pkt, nextthread); /* 64 bit thread identifier */
1198 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1201 parse_threadlist_response (pkt, result_limit, original_echo, resultlist,
1205 threadref *original_echo;
1206 threadref *resultlist;
1210 int count, resultcount, done;
1213 /* Assume the 'q' and 'M chars have been stripped. */
1214 limit = pkt + (PBUFSIZ - BUF_THREAD_ID_SIZE); /* done parse past here */
1215 pkt = unpack_byte (pkt, &count); /* count field */
1216 pkt = unpack_nibble (pkt, &done);
1217 /* The first threadid is the argument threadid. */
1218 pkt = unpack_threadid (pkt, original_echo); /* should match query packet */
1219 while ((count-- > 0) && (pkt < limit))
1221 pkt = unpack_threadid (pkt, resultlist++);
1222 if (resultcount++ >= result_limit)
1231 remote_get_threadlist (startflag, nextthread, result_limit,
1232 done, result_count, threadlist)
1234 threadref *nextthread;
1238 threadref *threadlist;
1241 static threadref echo_nextthread;
1242 char *threadlist_packet = alloca (PBUFSIZ);
1243 char *t_response = alloca (PBUFSIZ);
1246 /* Trancate result limit to be smaller than the packet size */
1247 if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10) >= PBUFSIZ)
1248 result_limit = (PBUFSIZ / BUF_THREAD_ID_SIZE) - 2;
1250 pack_threadlist_request (threadlist_packet,
1251 startflag, result_limit, nextthread);
1252 putpkt (threadlist_packet);
1253 getpkt (t_response, 0);
1256 parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
1259 if (!threadmatch (&echo_nextthread, nextthread))
1261 /* FIXME: This is a good reason to drop the packet */
1262 /* Possably, there is a duplicate response */
1264 retransmit immediatly - race conditions
1265 retransmit after timeout - yes
1267 wait for packet, then exit
1269 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1270 return 0; /* I choose simply exiting */
1272 if (*result_count <= 0)
1276 warning ("RMT ERROR : failed to get remote thread list\n");
1279 return result; /* break; */
1281 if (*result_count > result_limit)
1284 warning ("RMT ERROR: threadlist response longer than requested\n");
1290 /* This is the interface between remote and threads, remotes upper interface */
1292 /* remote_find_new_threads retrieves the thread list and for each
1293 thread in the list, looks up the thread in GDB's internal list,
1294 ading the thread if it does not already exist. This involves
1295 getting partial thread lists from the remote target so, polling the
1296 quit_flag is required. */
1299 /* About this many threadisds fit in a packet. */
1301 #define MAXTHREADLISTRESULTS 32
1304 remote_threadlist_iterator (stepfunction, context, looplimit)
1305 rmt_thread_action stepfunction;
1309 int done, i, result_count;
1313 static threadref nextthread;
1314 static threadref resultthreadlist[MAXTHREADLISTRESULTS];
1319 if (loopcount++ > looplimit)
1322 warning ("Remote fetch threadlist -infinite loop-\n");
1325 if (!remote_get_threadlist (startflag, &nextthread, MAXTHREADLISTRESULTS,
1326 &done, &result_count, resultthreadlist))
1331 /* clear for later iterations */
1333 /* Setup to resume next batch of thread references, set nextthread. */
1334 if (result_count >= 1)
1335 copy_threadref (&nextthread, &resultthreadlist[result_count - 1]);
1337 while (result_count--)
1338 if (!(result = (*stepfunction) (&resultthreadlist[i++], context)))
1345 remote_newthread_step (ref, context)
1351 pid = threadref_to_int (ref);
1352 if (!in_thread_list (pid))
1354 return 1; /* continue iterator */
1357 #define CRAZY_MAX_THREADS 1000
1360 remote_current_thread (oldpid)
1363 char *buf = alloca (PBUFSIZ);
1367 if (buf[0] == 'Q' && buf[1] == 'C')
1368 return strtol (&buf[2], NULL, 16);
1373 /* Find new threads for info threads command. */
1376 remote_find_new_threads ()
1378 remote_threadlist_iterator (remote_newthread_step, 0,
1380 if (inferior_pid == MAGIC_NULL_PID) /* ack ack ack */
1381 inferior_pid = remote_current_thread (inferior_pid);
1385 remote_threads_info (void)
1387 char *buf = alloca (PBUFSIZ);
1391 if (remote_desc == 0) /* paranoia */
1392 error ("Command can only be used when connected to the remote target.");
1394 putpkt ("qfThreadInfo");
1395 getpkt (bufp = buf, 0);
1396 if (bufp[0] == '\0') /* q packet not recognized! */
1397 { /* try old jmetzler method */
1398 remote_find_new_threads ();
1401 else /* try new 'q' method */
1402 while (*bufp++ == 'm') /* reply contains one or more TID */
1406 tid = strtol (bufp, &bufp, 16);
1407 if (tid != 0 && !in_thread_list (tid))
1410 while (*bufp++ == ','); /* comma-separated list */
1411 putpkt ("qsThreadInfo");
1412 getpkt (bufp = buf, 0);
1417 /* Restart the remote side; this is an extended protocol operation. */
1420 extended_remote_restart ()
1422 char *buf = alloca (PBUFSIZ);
1424 /* Send the restart command; for reasons I don't understand the
1425 remote side really expects a number after the "R". */
1427 sprintf (&buf[1], "%x", 0);
1430 /* Now query for status so this looks just like we restarted
1431 gdbserver from scratch. */
1436 /* Clean up connection to a remote debugger. */
1440 remote_close (quitting)
1444 SERIAL_CLOSE (remote_desc);
1448 /* Query the remote side for the text, data and bss offsets. */
1453 char *buf = alloca (PBUFSIZ);
1456 CORE_ADDR text_addr, data_addr, bss_addr;
1457 struct section_offsets *offs;
1459 putpkt ("qOffsets");
1463 if (buf[0] == '\000')
1464 return; /* Return silently. Stub doesn't support
1468 warning ("Remote failure reply: %s", buf);
1472 /* Pick up each field in turn. This used to be done with scanf, but
1473 scanf will make trouble if CORE_ADDR size doesn't match
1474 conversion directives correctly. The following code will work
1475 with any size of CORE_ADDR. */
1476 text_addr = data_addr = bss_addr = 0;
1480 if (strncmp (ptr, "Text=", 5) == 0)
1483 /* Don't use strtol, could lose on big values. */
1484 while (*ptr && *ptr != ';')
1485 text_addr = (text_addr << 4) + fromhex (*ptr++);
1490 if (!lose && strncmp (ptr, ";Data=", 6) == 0)
1493 while (*ptr && *ptr != ';')
1494 data_addr = (data_addr << 4) + fromhex (*ptr++);
1499 if (!lose && strncmp (ptr, ";Bss=", 5) == 0)
1502 while (*ptr && *ptr != ';')
1503 bss_addr = (bss_addr << 4) + fromhex (*ptr++);
1509 error ("Malformed response to offset query, %s", buf);
1511 if (symfile_objfile == NULL)
1514 offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
1515 memcpy (offs, symfile_objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
1517 ANOFFSET (offs, SECT_OFF_TEXT) = text_addr;
1519 /* This is a temporary kludge to force data and bss to use the same offsets
1520 because that's what nlmconv does now. The real solution requires changes
1521 to the stub and remote.c that I don't have time to do right now. */
1523 ANOFFSET (offs, SECT_OFF_DATA) = data_addr;
1524 ANOFFSET (offs, SECT_OFF_BSS) = data_addr;
1526 objfile_relocate (symfile_objfile, offs);
1530 * Cisco version of section offsets:
1532 * Instead of having GDB query the target for the section offsets,
1533 * Cisco lets the target volunteer the information! It's also in
1534 * a different format, so here are the functions that will decode
1535 * a section offset packet from a Cisco target.
1539 * Function: remote_cisco_section_offsets
1541 * Returns: zero for success, non-zero for failure
1545 remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
1546 text_offs, data_offs, bss_offs)
1550 bfd_signed_vma *text_offs;
1551 bfd_signed_vma *data_offs;
1552 bfd_signed_vma *bss_offs;
1554 bfd_vma text_base, data_base, bss_base;
1555 struct minimal_symbol *start;
1561 if (symfile_objfile == NULL)
1562 return -1; /* no can do nothin' */
1564 start = lookup_minimal_symbol ("_start", NULL, NULL);
1566 return -1; /* Can't find "_start" symbol */
1568 data_base = bss_base = 0;
1569 text_base = SYMBOL_VALUE_ADDRESS (start);
1571 abfd = symfile_objfile->obfd;
1572 for (sect = abfd->sections;
1576 p = (unsigned char *) bfd_get_section_name (abfd, sect);
1578 if (strcmp (p + len - 4, "data") == 0) /* ends in "data" */
1579 if (data_base == 0 ||
1580 data_base > bfd_get_section_vma (abfd, sect))
1581 data_base = bfd_get_section_vma (abfd, sect);
1582 if (strcmp (p + len - 3, "bss") == 0) /* ends in "bss" */
1583 if (bss_base == 0 ||
1584 bss_base > bfd_get_section_vma (abfd, sect))
1585 bss_base = bfd_get_section_vma (abfd, sect);
1587 *text_offs = text_addr - text_base;
1588 *data_offs = data_addr - data_base;
1589 *bss_offs = bss_addr - bss_base;
1594 sprintf (tmp, "VMA: text = 0x");
1595 sprintf_vma (tmp + strlen (tmp), text_addr);
1596 sprintf (tmp + strlen (tmp), " data = 0x");
1597 sprintf_vma (tmp + strlen (tmp), data_addr);
1598 sprintf (tmp + strlen (tmp), " bss = 0x");
1599 sprintf_vma (tmp + strlen (tmp), bss_addr);
1600 fprintf_filtered (gdb_stdlog, tmp);
1601 fprintf_filtered (gdb_stdlog,
1602 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
1603 paddr_nz (*text_offs),
1604 paddr_nz (*data_offs),
1605 paddr_nz (*bss_offs));
1612 * Function: remote_cisco_objfile_relocate
1614 * Relocate the symbol file for a remote target.
1618 remote_cisco_objfile_relocate (text_off, data_off, bss_off)
1619 bfd_signed_vma text_off;
1620 bfd_signed_vma data_off;
1621 bfd_signed_vma bss_off;
1623 struct section_offsets *offs;
1625 if (text_off != 0 || data_off != 0 || bss_off != 0)
1627 /* FIXME: This code assumes gdb-stabs.h is being used; it's
1628 broken for xcoff, dwarf, sdb-coff, etc. But there is no
1629 simple canonical representation for this stuff. */
1631 offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
1632 memcpy (offs, symfile_objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
1634 ANOFFSET (offs, SECT_OFF_TEXT) = text_off;
1635 ANOFFSET (offs, SECT_OFF_DATA) = data_off;
1636 ANOFFSET (offs, SECT_OFF_BSS) = bss_off;
1638 /* First call the standard objfile_relocate. */
1639 objfile_relocate (symfile_objfile, offs);
1641 /* Now we need to fix up the section entries already attached to
1642 the exec target. These entries will control memory transfers
1643 from the exec file. */
1645 exec_set_section_offsets (text_off, data_off, bss_off);
1649 /* Stub for catch_errors. */
1652 remote_start_remote_dummy (dummy)
1655 start_remote (); /* Initialize gdb process mechanisms */
1660 remote_start_remote (dummy)
1663 immediate_quit = 1; /* Allow user to interrupt it */
1665 /* Ack any packet which the remote side has already sent. */
1666 SERIAL_WRITE (remote_desc, "+", 1);
1668 /* Let the stub know that we want it to return the thread. */
1671 inferior_pid = remote_current_thread (inferior_pid);
1673 get_offsets (); /* Get text, data & bss offsets */
1675 putpkt ("?"); /* initiate a query from remote machine */
1678 return remote_start_remote_dummy (dummy);
1681 /* Open a connection to a remote debugger.
1682 NAME is the filename used for communication. */
1685 remote_open (name, from_tty)
1689 remote_open_1 (name, from_tty, &remote_ops, 0);
1692 /* Just like remote_open, but with asynchronous support. */
1694 remote_async_open (name, from_tty)
1698 remote_async_open_1 (name, from_tty, &remote_async_ops, 0);
1701 /* Open a connection to a remote debugger using the extended
1702 remote gdb protocol. NAME is the filename used for communication. */
1705 extended_remote_open (name, from_tty)
1709 remote_open_1 (name, from_tty, &extended_remote_ops, 1 /*extended_p */ );
1712 /* Just like extended_remote_open, but with asynchronous support. */
1714 extended_remote_async_open (name, from_tty)
1718 remote_async_open_1 (name, from_tty, &extended_async_remote_ops, 1 /*extended_p */ );
1721 /* Generic code for opening a connection to a remote target. */
1723 static DCACHE *remote_dcache;
1726 remote_open_1 (name, from_tty, target, extended_p)
1729 struct target_ops *target;
1733 error ("To open a remote debug connection, you need to specify what\n\
1734 serial device is attached to the remote system (e.g. /dev/ttya).");
1736 /* See FIXME above */
1737 wait_forever_enabled_p = 1;
1739 target_preopen (from_tty);
1741 unpush_target (target);
1743 remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
1745 remote_desc = SERIAL_OPEN (name);
1747 perror_with_name (name);
1749 if (baud_rate != -1)
1751 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
1753 SERIAL_CLOSE (remote_desc);
1754 perror_with_name (name);
1758 SERIAL_RAW (remote_desc);
1760 /* If there is something sitting in the buffer we might take it as a
1761 response to a command, which would be bad. */
1762 SERIAL_FLUSH_INPUT (remote_desc);
1766 puts_filtered ("Remote debugging using ");
1767 puts_filtered (name);
1768 puts_filtered ("\n");
1770 push_target (target); /* Switch to using remote target now */
1772 init_packet_config (&remote_protocol_P);
1773 init_packet_config (&remote_protocol_Z);
1775 general_thread = -2;
1776 continue_thread = -2;
1778 /* Force remote_write_bytes to check whether target supports
1779 binary downloading. */
1780 init_packet_config (&remote_protocol_binary_download);
1782 /* Without this, some commands which require an active target (such
1783 as kill) won't work. This variable serves (at least) double duty
1784 as both the pid of the target process (if it has such), and as a
1785 flag indicating that a target is active. These functions should
1786 be split out into seperate variables, especially since GDB will
1787 someday have a notion of debugging several processes. */
1789 inferior_pid = MAGIC_NULL_PID;
1790 /* Start the remote connection; if error (0), discard this target.
1791 In particular, if the user quits, be sure to discard it
1792 (we'd be in an inconsistent state otherwise). */
1793 if (!catch_errors (remote_start_remote, NULL,
1794 "Couldn't establish connection to remote target\n",
1803 /* tell the remote that we're using the extended protocol. */
1804 char *buf = alloca (PBUFSIZ);
1810 /* Just like remote_open but with asynchronous support. */
1812 remote_async_open_1 (name, from_tty, target, extended_p)
1815 struct target_ops *target;
1819 error ("To open a remote debug connection, you need to specify what\n\
1820 serial device is attached to the remote system (e.g. /dev/ttya).");
1822 target_preopen (from_tty);
1824 unpush_target (target);
1826 remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
1828 remote_desc = SERIAL_OPEN (name);
1830 perror_with_name (name);
1832 if (baud_rate != -1)
1834 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
1836 SERIAL_CLOSE (remote_desc);
1837 perror_with_name (name);
1841 SERIAL_RAW (remote_desc);
1843 /* If there is something sitting in the buffer we might take it as a
1844 response to a command, which would be bad. */
1845 SERIAL_FLUSH_INPUT (remote_desc);
1849 puts_filtered ("Remote debugging using ");
1850 puts_filtered (name);
1851 puts_filtered ("\n");
1854 push_target (target); /* Switch to using remote target now */
1856 init_packet_config (&remote_protocol_P);
1857 init_packet_config (&remote_protocol_Z);
1859 general_thread = -2;
1860 continue_thread = -2;
1862 /* Force remote_write_bytes to check whether target supports
1863 binary downloading. */
1864 init_packet_config (&remote_protocol_binary_download);
1866 /* Without this, some commands which require an active target (such
1867 as kill) won't work. This variable serves (at least) double duty
1868 as both the pid of the target process (if it has such), and as a
1869 flag indicating that a target is active. These functions should
1870 be split out into seperate variables, especially since GDB will
1871 someday have a notion of debugging several processes. */
1872 inferior_pid = MAGIC_NULL_PID;
1874 /* With this target we start out by owning the terminal. */
1875 remote_async_terminal_ours_p = 1;
1877 /* FIXME: cagney/1999-09-23: During the initial connection it is
1878 assumed that the target is already ready and able to respond to
1879 requests. Unfortunatly remote_start_remote() eventually calls
1880 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
1881 around this. Eventually a mechanism that allows
1882 wait_for_inferior() to expect/get timeouts will be
1884 wait_forever_enabled_p = 0;
1886 /* Start the remote connection; if error (0), discard this target.
1887 In particular, if the user quits, be sure to discard it
1888 (we'd be in an inconsistent state otherwise). */
1889 if (!catch_errors (remote_start_remote, NULL,
1890 "Couldn't establish connection to remote target\n",
1894 wait_forever_enabled_p = 1;
1898 wait_forever_enabled_p = 1;
1902 /* tell the remote that we're using the extended protocol. */
1903 char *buf = alloca (PBUFSIZ);
1908 /* If running in asynchronous mode, register the target with the
1909 event loop. Set things up so that when there is an event on the
1910 file descriptor, the event loop will call fetch_inferior_event,
1911 which will do the proper analysis to determine what happened. */
1912 /* FIXME: cagney/1999-09-26: We shouldn't just put the target into
1913 async mode. Instead we should leave the target synchronous and
1914 then leave it to the client to flip modes. */
1915 if (event_loop_p && target_can_async_p ())
1916 target_async (inferior_event_handler, 0);
1917 if (remote_debug && SERIAL_IS_ASYNC_P (remote_desc))
1918 fputs_unfiltered ("Serial put into async mode.\n", gdb_stdlog);
1921 /* This takes a program previously attached to and detaches it. After
1922 this is done, GDB can be used to debug some other program. We
1923 better not have left any breakpoints in the target program or it'll
1924 die when it hits one. */
1927 remote_detach (args, from_tty)
1931 char *buf = alloca (PBUFSIZ);
1934 error ("Argument given to \"detach\" when remotely debugging.");
1936 /* Tell the remote target to detach. */
1942 puts_filtered ("Ending remote debugging.\n");
1946 /* Same as remote_detach, but with async support. */
1948 remote_async_detach (args, from_tty)
1952 char *buf = alloca (PBUFSIZ);
1955 error ("Argument given to \"detach\" when remotely debugging.");
1957 /* Tell the remote target to detach. */
1961 /* Unregister the file descriptor from the event loop. */
1962 if (SERIAL_IS_ASYNC_P (remote_desc))
1963 SERIAL_ASYNC (remote_desc, NULL, 0);
1967 puts_filtered ("Ending remote debugging.\n");
1970 /* Convert hex digit A to a number. */
1976 if (a >= '0' && a <= '9')
1978 else if (a >= 'a' && a <= 'f')
1979 return a - 'a' + 10;
1980 else if (a >= 'A' && a <= 'F')
1981 return a - 'A' + 10;
1983 error ("Reply contains invalid hex digit %d", a);
1986 /* Convert number NIB to a hex digit. */
1995 return 'a' + nib - 10;
1998 /* Tell the remote machine to resume. */
2000 static enum target_signal last_sent_signal = TARGET_SIGNAL_0;
2002 static int last_sent_step;
2005 remote_resume (pid, step, siggnal)
2007 enum target_signal siggnal;
2009 char *buf = alloca (PBUFSIZ);
2012 set_thread (0, 0); /* run any thread */
2014 set_thread (pid, 0); /* run this thread */
2016 dcache_flush (remote_dcache);
2018 last_sent_signal = siggnal;
2019 last_sent_step = step;
2021 /* A hook for when we need to do something at the last moment before
2023 if (target_resume_hook)
2024 (*target_resume_hook) ();
2026 if (siggnal != TARGET_SIGNAL_0)
2028 buf[0] = step ? 'S' : 'C';
2029 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
2030 buf[2] = tohex ((int) siggnal & 0xf);
2034 strcpy (buf, step ? "s" : "c");
2039 /* Same as remote_resume, but with async support. */
2041 remote_async_resume (pid, step, siggnal)
2043 enum target_signal siggnal;
2045 char *buf = alloca (PBUFSIZ);
2048 set_thread (0, 0); /* run any thread */
2050 set_thread (pid, 0); /* run this thread */
2052 dcache_flush (remote_dcache);
2054 last_sent_signal = siggnal;
2055 last_sent_step = step;
2057 /* A hook for when we need to do something at the last moment before
2059 if (target_resume_hook)
2060 (*target_resume_hook) ();
2062 /* Tell the world that the target is now executing. */
2063 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2064 this? Instead, should the client of target just assume (for
2065 async targets) that the target is going to start executing? Is
2066 this information already found in the continuation block? */
2067 if (SERIAL_IS_ASYNC_P (remote_desc))
2068 target_executing = 1;
2070 if (siggnal != TARGET_SIGNAL_0)
2072 buf[0] = step ? 'S' : 'C';
2073 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
2074 buf[2] = tohex ((int) siggnal & 0xf);
2078 strcpy (buf, step ? "s" : "c");
2084 /* Set up the signal handler for SIGINT, while the target is
2085 executing, ovewriting the 'regular' SIGINT signal handler. */
2087 initialize_sigint_signal_handler ()
2089 sigint_remote_token =
2090 create_async_signal_handler (async_remote_interrupt, NULL);
2091 signal (SIGINT, handle_remote_sigint);
2094 /* Signal handler for SIGINT, while the target is executing. */
2096 handle_remote_sigint (sig)
2099 signal (sig, handle_remote_sigint_twice);
2100 sigint_remote_twice_token =
2101 create_async_signal_handler (async_remote_interrupt_twice, NULL);
2102 mark_async_signal_handler_wrapper (sigint_remote_token);
2105 /* Signal handler for SIGINT, installed after SIGINT has already been
2106 sent once. It will take effect the second time that the user sends
2109 handle_remote_sigint_twice (sig)
2112 signal (sig, handle_sigint);
2113 sigint_remote_twice_token =
2114 create_async_signal_handler (async_remote_interrupt_twice, NULL);
2115 mark_async_signal_handler_wrapper (sigint_remote_twice_token);
2118 /* Perform the real interruption of the target execution, in response
2121 async_remote_interrupt (arg)
2122 gdb_client_data arg;
2125 fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
2130 /* Perform interrupt, if the first attempt did not succeed. Just give
2131 up on the target alltogether. */
2133 async_remote_interrupt_twice (arg)
2134 gdb_client_data arg;
2136 /* Do something only if the target was not killed by the previous
2138 if (target_executing)
2141 signal (SIGINT, handle_remote_sigint);
2145 /* Reinstall the usual SIGINT handlers, after the target has
2148 cleanup_sigint_signal_handler (void *dummy)
2150 signal (SIGINT, handle_sigint);
2151 if (sigint_remote_twice_token)
2152 delete_async_signal_handler ((struct async_signal_handler **) & sigint_remote_twice_token);
2153 if (sigint_remote_token)
2154 delete_async_signal_handler ((struct async_signal_handler **) & sigint_remote_token);
2157 /* Send ^C to target to halt it. Target will respond, and send us a
2159 static void (*ofunc) PARAMS ((int));
2161 /* The command line interface's stop routine. This function is installed
2162 as a signal handler for SIGINT. The first time a user requests a
2163 stop, we call remote_stop to send a break or ^C. If there is no
2164 response from the target (it didn't stop when the user requested it),
2165 we ask the user if he'd like to detach from the target. */
2167 remote_interrupt (signo)
2170 /* If this doesn't work, try more severe steps. */
2171 signal (signo, remote_interrupt_twice);
2174 fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
2179 /* The user typed ^C twice. */
2182 remote_interrupt_twice (signo)
2185 signal (signo, ofunc);
2187 signal (signo, remote_interrupt);
2190 /* This is the generic stop called via the target vector. When a target
2191 interrupt is requested, either by the command line or the GUI, we
2192 will eventually end up here. */
2196 /* Send a break or a ^C, depending on user preference. */
2198 fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
2201 SERIAL_SEND_BREAK (remote_desc);
2203 SERIAL_WRITE (remote_desc, "\003", 1);
2206 /* Ask the user what to do when an interrupt is received. */
2211 target_terminal_ours ();
2213 if (query ("Interrupted while waiting for the program.\n\
2214 Give up (and stop debugging it)? "))
2216 target_mourn_inferior ();
2217 return_to_top_level (RETURN_QUIT);
2220 target_terminal_inferior ();
2223 /* Enable/disable target terminal ownership. Most targets can use
2224 terminal groups to control terminal ownership. Remote targets are
2225 different in that explicit transfer of ownership to/from GDB/target
2229 remote_async_terminal_inferior (void)
2231 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2232 sync_execution here. This function should only be called when
2233 GDB is resuming the inferior in the forground. A background
2234 resume (``run&'') should leave GDB in control of the terminal and
2235 consequently should not call this code. */
2236 if (!sync_execution)
2238 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2239 calls target_terminal_*() idenpotent. The event-loop GDB talking
2240 to an asynchronous target with a synchronous command calls this
2241 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2242 stops trying to transfer the terminal to the target when it
2243 shouldn't this guard can go away. */
2244 if (!remote_async_terminal_ours_p)
2246 delete_file_handler (input_fd);
2247 remote_async_terminal_ours_p = 0;
2248 initialize_sigint_signal_handler ();
2249 /* NOTE: At this point we could also register our selves as the
2250 recipient of all input. Any characters typed could then be
2251 passed on down to the target. */
2255 remote_async_terminal_ours (void)
2257 /* See FIXME in remote_async_terminal_inferior. */
2258 if (!sync_execution)
2260 /* See FIXME in remote_async_terminal_inferior. */
2261 if (remote_async_terminal_ours_p)
2263 cleanup_sigint_signal_handler (NULL);
2264 add_file_handler (input_fd, stdin_event_handler, 0);
2265 remote_async_terminal_ours_p = 1;
2268 /* If nonzero, ignore the next kill. */
2273 remote_console_output (msg)
2278 for (p = msg; p[0] && p[1]; p += 2)
2281 char c = fromhex (p[0]) * 16 + fromhex (p[1]);
2284 fputs_unfiltered (tb, gdb_stdtarg);
2288 /* Wait until the remote machine stops, then return,
2289 storing status in STATUS just as `wait' would.
2290 Returns "pid", which in the case of a multi-threaded
2291 remote OS, is the thread-id. */
2294 remote_wait (pid, status)
2296 struct target_waitstatus *status;
2298 unsigned char *buf = alloca (PBUFSIZ);
2299 int thread_num = -1;
2301 status->kind = TARGET_WAITKIND_EXITED;
2302 status->value.integer = 0;
2308 ofunc = signal (SIGINT, remote_interrupt);
2309 getpkt ((char *) buf, 1);
2310 signal (SIGINT, ofunc);
2312 /* This is a hook for when we need to do something (perhaps the
2313 collection of trace data) every time the target stops. */
2314 if (target_wait_loop_hook)
2315 (*target_wait_loop_hook) ();
2319 case 'E': /* Error of some sort */
2320 warning ("Remote failure reply: %s", buf);
2322 case 'T': /* Status with PC, SP, FP, ... */
2326 char regs[MAX_REGISTER_RAW_SIZE];
2328 /* Expedited reply, containing Signal, {regno, reg} repeat */
2329 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2331 n... = register number
2332 r... = register contents
2334 p = &buf[3]; /* after Txx */
2341 /* Read the register number */
2342 regno = strtol ((const char *) p, &p_temp, 16);
2343 p1 = (unsigned char *) p_temp;
2345 if (p1 == p) /* No register number present here */
2347 p1 = (unsigned char *) strchr ((const char *) p, ':');
2349 warning ("Malformed packet(a) (missing colon): %s\n\
2352 if (strncmp ((const char *) p, "thread", p1 - p) == 0)
2354 p_temp = unpack_varlen_hex (++p1, &thread_num);
2355 record_currthread (thread_num);
2356 p = (unsigned char *) p_temp;
2364 warning ("Malformed packet(b) (missing colon): %s\n\
2368 if (regno >= NUM_REGS)
2369 warning ("Remote sent bad register number %ld: %s\n\
2373 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
2375 if (p[0] == 0 || p[1] == 0)
2376 warning ("Remote reply is too short: %s", buf);
2377 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
2380 supply_register (regno, regs);
2385 warning ("Remote register badly formatted: %s", buf);
2386 warning (" here: %s", p);
2391 case 'S': /* Old style status, just signal only */
2392 status->kind = TARGET_WAITKIND_STOPPED;
2393 status->value.sig = (enum target_signal)
2394 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2398 /* Export Cisco kernel mode as a convenience variable
2399 (so that it can be used in the GDB prompt if desired). */
2401 if (cisco_kernel_mode == 1)
2402 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2403 value_from_string ("PDEBUG-"));
2404 cisco_kernel_mode = 0;
2405 thread_num = strtol ((const char *) &buf[4], NULL, 16);
2406 record_currthread (thread_num);
2408 else if (buf[3] == 'k')
2410 /* Export Cisco kernel mode as a convenience variable
2411 (so that it can be used in the GDB prompt if desired). */
2413 if (cisco_kernel_mode == 1)
2414 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2415 value_from_string ("KDEBUG-"));
2416 cisco_kernel_mode = 1;
2419 case 'N': /* Cisco special: status and offsets */
2421 bfd_vma text_addr, data_addr, bss_addr;
2422 bfd_signed_vma text_off, data_off, bss_off;
2425 status->kind = TARGET_WAITKIND_STOPPED;
2426 status->value.sig = (enum target_signal)
2427 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2429 if (symfile_objfile == NULL)
2431 warning ("Relocation packet received with no symbol file. \
2436 /* Relocate object file. Buffer format is NAATT;DD;BB
2437 * where AA is the signal number, TT is the new text
2438 * address, DD * is the new data address, and BB is the
2439 * new bss address. */
2442 text_addr = strtoul (p, (char **) &p1, 16);
2443 if (p1 == p || *p1 != ';')
2444 warning ("Malformed relocation packet: Packet '%s'", buf);
2446 data_addr = strtoul (p, (char **) &p1, 16);
2447 if (p1 == p || *p1 != ';')
2448 warning ("Malformed relocation packet: Packet '%s'", buf);
2450 bss_addr = strtoul (p, (char **) &p1, 16);
2452 warning ("Malformed relocation packet: Packet '%s'", buf);
2454 if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
2455 &text_off, &data_off, &bss_off)
2457 if (text_off != 0 || data_off != 0 || bss_off != 0)
2458 remote_cisco_objfile_relocate (text_off, data_off, bss_off);
2462 case 'W': /* Target exited */
2464 /* The remote process exited. */
2465 status->kind = TARGET_WAITKIND_EXITED;
2466 status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
2470 status->kind = TARGET_WAITKIND_SIGNALLED;
2471 status->value.sig = (enum target_signal)
2472 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2476 case 'O': /* Console output */
2477 remote_console_output (buf + 1);
2480 if (last_sent_signal != TARGET_SIGNAL_0)
2482 /* Zero length reply means that we tried 'S' or 'C' and
2483 the remote system doesn't support it. */
2484 target_terminal_ours_for_output ();
2486 ("Can't send signals to this remote system. %s not sent.\n",
2487 target_signal_to_name (last_sent_signal));
2488 last_sent_signal = TARGET_SIGNAL_0;
2489 target_terminal_inferior ();
2491 strcpy ((char *) buf, last_sent_step ? "s" : "c");
2492 putpkt ((char *) buf);
2495 /* else fallthrough */
2497 warning ("Invalid remote reply: %s", buf);
2502 if (thread_num != -1)
2506 return inferior_pid;
2509 /* Async version of remote_wait. */
2511 remote_async_wait (pid, status)
2513 struct target_waitstatus *status;
2515 unsigned char *buf = alloca (PBUFSIZ);
2516 int thread_num = -1;
2518 status->kind = TARGET_WAITKIND_EXITED;
2519 status->value.integer = 0;
2525 if (!SERIAL_IS_ASYNC_P (remote_desc))
2526 ofunc = signal (SIGINT, remote_interrupt);
2527 /* FIXME: cagney/1999-09-27: If we're in async mode we should
2528 _never_ wait for ever -> test on target_is_async_p().
2529 However, before we do that we need to ensure that the caller
2530 knows how to take the target into/out of async mode. */
2531 getpkt ((char *) buf, wait_forever_enabled_p);
2532 if (!SERIAL_IS_ASYNC_P (remote_desc))
2533 signal (SIGINT, ofunc);
2535 /* This is a hook for when we need to do something (perhaps the
2536 collection of trace data) every time the target stops. */
2537 if (target_wait_loop_hook)
2538 (*target_wait_loop_hook) ();
2542 case 'E': /* Error of some sort */
2543 warning ("Remote failure reply: %s", buf);
2545 case 'T': /* Status with PC, SP, FP, ... */
2549 char regs[MAX_REGISTER_RAW_SIZE];
2551 /* Expedited reply, containing Signal, {regno, reg} repeat */
2552 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2554 n... = register number
2555 r... = register contents
2557 p = &buf[3]; /* after Txx */
2564 /* Read the register number */
2565 regno = strtol ((const char *) p, &p_temp, 16);
2566 p1 = (unsigned char *) p_temp;
2568 if (p1 == p) /* No register number present here */
2570 p1 = (unsigned char *) strchr ((const char *) p, ':');
2572 warning ("Malformed packet(a) (missing colon): %s\n\
2575 if (strncmp ((const char *) p, "thread", p1 - p) == 0)
2577 p_temp = unpack_varlen_hex (++p1, &thread_num);
2578 record_currthread (thread_num);
2579 p = (unsigned char *) p_temp;
2587 warning ("Malformed packet(b) (missing colon): %s\n\
2591 if (regno >= NUM_REGS)
2592 warning ("Remote sent bad register number %ld: %s\n\
2596 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
2598 if (p[0] == 0 || p[1] == 0)
2599 warning ("Remote reply is too short: %s", buf);
2600 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
2603 supply_register (regno, regs);
2608 warning ("Remote register badly formatted: %s", buf);
2609 warning (" here: %s", p);
2614 case 'S': /* Old style status, just signal only */
2615 status->kind = TARGET_WAITKIND_STOPPED;
2616 status->value.sig = (enum target_signal)
2617 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2621 /* Export Cisco kernel mode as a convenience variable
2622 (so that it can be used in the GDB prompt if desired). */
2624 if (cisco_kernel_mode == 1)
2625 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2626 value_from_string ("PDEBUG-"));
2627 cisco_kernel_mode = 0;
2628 thread_num = strtol ((const char *) &buf[4], NULL, 16);
2629 record_currthread (thread_num);
2631 else if (buf[3] == 'k')
2633 /* Export Cisco kernel mode as a convenience variable
2634 (so that it can be used in the GDB prompt if desired). */
2636 if (cisco_kernel_mode == 1)
2637 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2638 value_from_string ("KDEBUG-"));
2639 cisco_kernel_mode = 1;
2642 case 'N': /* Cisco special: status and offsets */
2644 bfd_vma text_addr, data_addr, bss_addr;
2645 bfd_signed_vma text_off, data_off, bss_off;
2648 status->kind = TARGET_WAITKIND_STOPPED;
2649 status->value.sig = (enum target_signal)
2650 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2652 if (symfile_objfile == NULL)
2654 warning ("Relocation packet recieved with no symbol file. \
2659 /* Relocate object file. Buffer format is NAATT;DD;BB
2660 * where AA is the signal number, TT is the new text
2661 * address, DD * is the new data address, and BB is the
2662 * new bss address. */
2665 text_addr = strtoul (p, (char **) &p1, 16);
2666 if (p1 == p || *p1 != ';')
2667 warning ("Malformed relocation packet: Packet '%s'", buf);
2669 data_addr = strtoul (p, (char **) &p1, 16);
2670 if (p1 == p || *p1 != ';')
2671 warning ("Malformed relocation packet: Packet '%s'", buf);
2673 bss_addr = strtoul (p, (char **) &p1, 16);
2675 warning ("Malformed relocation packet: Packet '%s'", buf);
2677 if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
2678 &text_off, &data_off, &bss_off)
2680 if (text_off != 0 || data_off != 0 || bss_off != 0)
2681 remote_cisco_objfile_relocate (text_off, data_off, bss_off);
2685 case 'W': /* Target exited */
2687 /* The remote process exited. */
2688 status->kind = TARGET_WAITKIND_EXITED;
2689 status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
2693 status->kind = TARGET_WAITKIND_SIGNALLED;
2694 status->value.sig = (enum target_signal)
2695 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2699 case 'O': /* Console output */
2700 remote_console_output (buf + 1);
2703 if (last_sent_signal != TARGET_SIGNAL_0)
2705 /* Zero length reply means that we tried 'S' or 'C' and
2706 the remote system doesn't support it. */
2707 target_terminal_ours_for_output ();
2709 ("Can't send signals to this remote system. %s not sent.\n",
2710 target_signal_to_name (last_sent_signal));
2711 last_sent_signal = TARGET_SIGNAL_0;
2712 target_terminal_inferior ();
2714 strcpy ((char *) buf, last_sent_step ? "s" : "c");
2715 putpkt ((char *) buf);
2718 /* else fallthrough */
2720 warning ("Invalid remote reply: %s", buf);
2725 if (thread_num != -1)
2729 return inferior_pid;
2732 /* Number of bytes of registers this stub implements. */
2734 static int register_bytes_found;
2736 /* Read the remote registers into the block REGS. */
2737 /* Currently we just read all the registers, so we don't use regno. */
2741 remote_fetch_registers (regno)
2744 char *buf = alloca (PBUFSIZ);
2747 char regs[REGISTER_BYTES];
2749 set_thread (inferior_pid, 1);
2754 if (remote_register_buf_size == 0)
2755 remote_register_buf_size = strlen (buf);
2757 /* Unimplemented registers read as all bits zero. */
2758 memset (regs, 0, REGISTER_BYTES);
2760 /* We can get out of synch in various cases. If the first character
2761 in the buffer is not a hex character, assume that has happened
2762 and try to fetch another packet to read. */
2763 while ((buf[0] < '0' || buf[0] > '9')
2764 && (buf[0] < 'a' || buf[0] > 'f')
2765 && buf[0] != 'x') /* New: unavailable register value */
2768 fprintf_unfiltered (gdb_stdlog,
2769 "Bad register packet; fetching a new packet\n");
2773 /* Reply describes registers byte by byte, each byte encoded as two
2774 hex characters. Suck them all up, then supply them to the
2775 register cacheing/storage mechanism. */
2778 for (i = 0; i < REGISTER_BYTES; i++)
2784 warning ("Remote reply is of odd length: %s", buf);
2785 /* Don't change register_bytes_found in this case, and don't
2786 print a second warning. */
2789 if (p[0] == 'x' && p[1] == 'x')
2790 regs[i] = 0; /* 'x' */
2792 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
2796 if (i != register_bytes_found)
2798 register_bytes_found = i;
2799 #ifdef REGISTER_BYTES_OK
2800 if (!REGISTER_BYTES_OK (i))
2801 warning ("Remote reply is too short: %s", buf);
2806 for (i = 0; i < NUM_REGS; i++)
2808 supply_register (i, ®s[REGISTER_BYTE (i)]);
2809 if (buf[REGISTER_BYTE (i) * 2] == 'x')
2810 register_valid[i] = -1; /* register value not available */
2814 /* Prepare to store registers. Since we may send them all (using a
2815 'G' request), we have to read out the ones we don't want to change
2819 remote_prepare_to_store ()
2821 /* Make sure the entire registers array is valid. */
2822 switch (remote_protocol_P.support)
2824 case PACKET_DISABLE:
2825 case PACKET_SUPPORT_UNKNOWN:
2826 read_register_bytes (0, (char *) NULL, REGISTER_BYTES);
2833 /* Helper: Attempt to store REGNO using the P packet. Return fail IFF
2834 packet was not recognized. */
2837 store_register_using_P (regno)
2840 /* Try storing a single register. */
2841 char *buf = alloca (PBUFSIZ);
2846 sprintf (buf, "P%x=", regno);
2847 p = buf + strlen (buf);
2848 regp = ®isters[REGISTER_BYTE (regno)];
2849 for (i = 0; i < REGISTER_RAW_SIZE (regno); ++i)
2851 *p++ = tohex ((regp[i] >> 4) & 0xf);
2852 *p++ = tohex (regp[i] & 0xf);
2857 return buf[0] != '\0';
2861 /* Store register REGNO, or all registers if REGNO == -1, from the contents
2862 of REGISTERS. FIXME: ignores errors. */
2865 remote_store_registers (regno)
2868 char *buf = alloca (PBUFSIZ);
2872 set_thread (inferior_pid, 1);
2876 switch (remote_protocol_P.support)
2878 case PACKET_DISABLE:
2881 if (store_register_using_P (regno))
2884 error ("Protocol error: P packet not recognized by stub");
2885 case PACKET_SUPPORT_UNKNOWN:
2886 if (store_register_using_P (regno))
2888 /* The stub recognized the 'P' packet. Remember this. */
2889 remote_protocol_P.support = PACKET_ENABLE;
2894 /* The stub does not support the 'P' packet. Use 'G'
2895 instead, and don't try using 'P' in the future (it
2896 will just waste our time). */
2897 remote_protocol_P.support = PACKET_DISABLE;
2905 /* Command describes registers byte by byte,
2906 each byte encoded as two hex characters. */
2909 /* remote_prepare_to_store insures that register_bytes_found gets set. */
2910 for (i = 0; i < register_bytes_found; i++)
2912 *p++ = tohex ((registers[i] >> 4) & 0xf);
2913 *p++ = tohex (registers[i] & 0xf);
2920 /* Use of the data cache *used* to be disabled because it loses for looking
2921 at and changing hardware I/O ports and the like. Accepting `volatile'
2922 would perhaps be one way to fix it. Another idea would be to use the
2923 executable file for the text segment (for all SEC_CODE sections?
2924 For all SEC_READONLY sections?). This has problems if you want to
2925 actually see what the memory contains (e.g. self-modifying code,
2926 clobbered memory, user downloaded the wrong thing).
2928 Because it speeds so much up, it's now enabled, if you're playing
2929 with registers you turn it of (set remotecache 0). */
2931 /* Read a word from remote address ADDR and return it.
2932 This goes through the data cache. */
2936 remote_fetch_word (addr)
2939 return dcache_fetch (remote_dcache, addr);
2942 /* Write a word WORD into remote address ADDR.
2943 This goes through the data cache. */
2946 remote_store_word (addr, word)
2950 dcache_poke (remote_dcache, addr, word);
2952 #endif /* 0 (unused?) */
2956 /* Return the number of hex digits in num. */
2964 for (i = 0; num != 0; i++)
2970 /* Set BUF to the hex digits representing NUM. */
2973 hexnumstr (buf, num)
2978 int len = hexnumlen (num);
2982 for (i = len - 1; i >= 0; i--)
2984 buf[i] = "0123456789abcdef"[(num & 0xf)];
2991 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
2994 remote_address_masked (addr)
2997 if (remote_address_size > 0
2998 && remote_address_size < (sizeof (ULONGEST) * 8))
3000 /* Only create a mask when that mask can safely be constructed
3001 in a ULONGEST variable. */
3003 mask = (mask << remote_address_size) - 1;
3009 /* Determine whether the remote target supports binary downloading.
3010 This is accomplished by sending a no-op memory write of zero length
3011 to the target at the specified address. It does not suffice to send
3012 the whole packet, since many stubs strip the eighth bit and subsequently
3013 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3015 NOTE: This can still lose if the serial line is not eight-bit
3016 clean. In cases like this, the user should clear "remote
3020 check_binary_download (addr)
3023 switch (remote_protocol_binary_download.support)
3025 case PACKET_DISABLE:
3029 case PACKET_SUPPORT_UNKNOWN:
3031 char *buf = alloca (PBUFSIZ);
3036 p += hexnumstr (p, (ULONGEST) addr);
3038 p += hexnumstr (p, (ULONGEST) 0);
3042 putpkt_binary (buf, (int) (p - buf));
3048 fprintf_unfiltered (gdb_stdlog,
3049 "binary downloading NOT suppported by target\n");
3050 remote_protocol_binary_download.support = PACKET_DISABLE;
3055 fprintf_unfiltered (gdb_stdlog,
3056 "binary downloading suppported by target\n");
3057 remote_protocol_binary_download.support = PACKET_ENABLE;
3064 /* Write memory data directly to the remote machine.
3065 This does not inform the data cache; the data cache uses this.
3066 MEMADDR is the address in the remote memory space.
3067 MYADDR is the address of the buffer in our space.
3068 LEN is the number of bytes.
3070 Returns number of bytes transferred, or 0 for error. */
3073 remote_write_bytes (memaddr, myaddr, len)
3078 unsigned char *buf = alloca (PBUFSIZ);
3079 int max_buf_size; /* Max size of packet output buffer */
3082 /* Verify that the target can support a binary download */
3083 check_binary_download (memaddr);
3085 /* Chop the transfer down if necessary */
3087 max_buf_size = min (remote_write_size, PBUFSIZ);
3088 if (remote_register_buf_size != 0)
3089 max_buf_size = min (max_buf_size, remote_register_buf_size);
3091 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3092 max_buf_size -= 2 + hexnumlen (memaddr + len - 1) + 1 + hexnumlen (len) + 4;
3097 unsigned char *p, *plen;
3101 /* construct "M"<memaddr>","<len>":" */
3102 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3103 memaddr = remote_address_masked (memaddr);
3105 switch (remote_protocol_binary_download.support)
3109 todo = min (len, max_buf_size);
3111 case PACKET_DISABLE:
3113 todo = min (len, max_buf_size / 2); /* num bytes that will fit */
3115 case PACKET_SUPPORT_UNKNOWN:
3116 internal_error ("remote_write_bytes: bad switch");
3119 p += hexnumstr (p, (ULONGEST) memaddr);
3122 plen = p; /* remember where len field goes */
3123 p += hexnumstr (p, (ULONGEST) todo);
3127 /* We send target system values byte by byte, in increasing byte
3128 addresses, each byte encoded as two hex characters (or one
3129 binary character). */
3130 switch (remote_protocol_binary_download.support)
3136 (i < todo) && (i + escaped) < (max_buf_size - 2);
3139 switch (myaddr[i] & 0xff)
3144 /* These must be escaped */
3147 *p++ = (myaddr[i] & 0xff) ^ 0x20;
3150 *p++ = myaddr[i] & 0xff;
3157 /* Escape chars have filled up the buffer prematurely,
3158 and we have actually sent fewer bytes than planned.
3159 Fix-up the length field of the packet. */
3161 /* FIXME: will fail if new len is a shorter string than
3164 plen += hexnumstr (plen, (ULONGEST) i);
3169 case PACKET_DISABLE:
3171 for (i = 0; i < todo; i++)
3173 *p++ = tohex ((myaddr[i] >> 4) & 0xf);
3174 *p++ = tohex (myaddr[i] & 0xf);
3179 case PACKET_SUPPORT_UNKNOWN:
3180 internal_error ("remote_write_bytes: bad switch");
3183 putpkt_binary (buf, (int) (p - buf));
3188 /* There is no correspondance between what the remote protocol uses
3189 for errors and errno codes. We would like a cleaner way of
3190 representing errors (big enough to include errno codes, bfd_error
3191 codes, and others). But for now just return EIO. */
3196 /* Increment by i, not by todo, in case escape chars
3197 caused us to send fewer bytes than we'd planned. */
3205 /* Read memory data directly from the remote machine.
3206 This does not use the data cache; the data cache uses this.
3207 MEMADDR is the address in the remote memory space.
3208 MYADDR is the address of the buffer in our space.
3209 LEN is the number of bytes.
3211 Returns number of bytes transferred, or 0 for error. */
3214 remote_read_bytes (memaddr, myaddr, len)
3219 char *buf = alloca (PBUFSIZ);
3220 int max_buf_size; /* Max size of packet output buffer */
3223 /* Chop the transfer down if necessary */
3225 max_buf_size = min (remote_write_size, PBUFSIZ);
3226 if (remote_register_buf_size != 0)
3227 max_buf_size = min (max_buf_size, remote_register_buf_size);
3236 todo = min (len, max_buf_size / 2); /* num bytes that will fit */
3238 /* construct "m"<memaddr>","<len>" */
3239 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3240 memaddr = remote_address_masked (memaddr);
3243 p += hexnumstr (p, (ULONGEST) memaddr);
3245 p += hexnumstr (p, (ULONGEST) todo);
3253 /* There is no correspondance between what the remote protocol uses
3254 for errors and errno codes. We would like a cleaner way of
3255 representing errors (big enough to include errno codes, bfd_error
3256 codes, and others). But for now just return EIO. */
3261 /* Reply describes memory byte by byte,
3262 each byte encoded as two hex characters. */
3265 for (i = 0; i < todo; i++)
3267 if (p[0] == 0 || p[1] == 0)
3268 /* Reply is short. This means that we were able to read
3269 only part of what we wanted to. */
3270 return i + (origlen - len);
3271 myaddr[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
3281 /* Read or write LEN bytes from inferior memory at MEMADDR,
3282 transferring to or from debugger address BUFFER. Write to inferior if
3283 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3286 #ifndef REMOTE_TRANSLATE_XFER_ADDRESS
3287 #define REMOTE_TRANSLATE_XFER_ADDRESS(MEM_ADDR, MEM_LEN, TARG_ADDR, TARG_LEN) \
3288 (*(TARG_ADDR) = (MEM_ADDR), *(TARG_LEN) = (MEM_LEN))
3293 remote_xfer_memory (mem_addr, buffer, mem_len, should_write, target)
3298 struct target_ops *target; /* ignored */
3300 CORE_ADDR targ_addr;
3302 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr, mem_len, &targ_addr, &targ_len);
3306 return dcache_xfer_memory (remote_dcache, targ_addr, buffer,
3307 targ_len, should_write);
3312 /* Enable after 4.12. */
3315 remote_search (len, data, mask, startaddr, increment, lorange, hirange
3316 addr_found, data_found)
3320 CORE_ADDR startaddr;
3324 CORE_ADDR *addr_found;
3327 if (increment == -4 && len == 4)
3329 long mask_long, data_long;
3330 long data_found_long;
3331 CORE_ADDR addr_we_found;
3332 char *buf = alloca (PBUFSIZ);
3333 long returned_long[2];
3336 mask_long = extract_unsigned_integer (mask, len);
3337 data_long = extract_unsigned_integer (data, len);
3338 sprintf (buf, "t%x:%x,%x", startaddr, data_long, mask_long);
3343 /* The stub doesn't support the 't' request. We might want to
3344 remember this fact, but on the other hand the stub could be
3345 switched on us. Maybe we should remember it only until
3346 the next "target remote". */
3347 generic_search (len, data, mask, startaddr, increment, lorange,
3348 hirange, addr_found, data_found);
3353 /* There is no correspondance between what the remote protocol uses
3354 for errors and errno codes. We would like a cleaner way of
3355 representing errors (big enough to include errno codes, bfd_error
3356 codes, and others). But for now just use EIO. */
3357 memory_error (EIO, startaddr);
3360 while (*p != '\0' && *p != ',')
3361 addr_we_found = (addr_we_found << 4) + fromhex (*p++);
3363 error ("Protocol error: short return for search");
3365 data_found_long = 0;
3366 while (*p != '\0' && *p != ',')
3367 data_found_long = (data_found_long << 4) + fromhex (*p++);
3368 /* Ignore anything after this comma, for future extensions. */
3370 if (addr_we_found < lorange || addr_we_found >= hirange)
3376 *addr_found = addr_we_found;
3377 *data_found = store_unsigned_integer (data_we_found, len);
3380 generic_search (len, data, mask, startaddr, increment, lorange,
3381 hirange, addr_found, data_found);
3386 remote_files_info (ignore)
3387 struct target_ops *ignore;
3389 puts_filtered ("Debugging a target over a serial line.\n");
3392 /* Stuff for dealing with the packets which are part of this protocol.
3393 See comment at top of file for details. */
3395 /* Read a single character from the remote end, masking it down to 7 bits. */
3403 ch = SERIAL_READCHAR (remote_desc, timeout);
3408 error ("Remote connection closed");
3410 perror_with_name ("Remote communication error");
3411 case SERIAL_TIMEOUT:
3418 /* Send the command in BUF to the remote machine, and read the reply
3419 into BUF. Report an error if we get an error reply. */
3429 error ("Remote failure reply: %s", buf);
3432 /* Display a null-terminated packet on stdout, for debugging, using C
3439 puts_filtered ("\"");
3440 fputstr_filtered (buf, '"', gdb_stdout);
3441 puts_filtered ("\"");
3448 return putpkt_binary (buf, strlen (buf));
3451 /* Send a packet to the remote machine, with error checking. The data
3452 of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
3453 to account for the $, # and checksum, and for a possible /0 if we are
3454 debugging (remote_debug) and want to print the sent packet as a string */
3457 putpkt_binary (buf, cnt)
3462 unsigned char csum = 0;
3463 char *buf2 = alloca (PBUFSIZ);
3464 char *junkbuf = alloca (PBUFSIZ);
3470 /* Copy the packet into buffer BUF2, encapsulating it
3471 and giving it a checksum. */
3473 if (cnt > BUFSIZ - 5) /* Prosanity check */
3479 for (i = 0; i < cnt; i++)
3485 *p++ = tohex ((csum >> 4) & 0xf);
3486 *p++ = tohex (csum & 0xf);
3488 /* Send it over and over until we get a positive ack. */
3492 int started_error_output = 0;
3497 fprintf_unfiltered (gdb_stdlog, "Sending packet: ");
3498 fputstrn_unfiltered (buf2, p - buf2, 0, gdb_stdlog);
3499 fprintf_unfiltered (gdb_stdlog, "...");
3500 gdb_flush (gdb_stdlog);
3502 if (SERIAL_WRITE (remote_desc, buf2, p - buf2))
3503 perror_with_name ("putpkt: write failed");
3505 /* read until either a timeout occurs (-2) or '+' is read */
3508 ch = readchar (remote_timeout);
3515 case SERIAL_TIMEOUT:
3517 if (started_error_output)
3519 putchar_unfiltered ('\n');
3520 started_error_output = 0;
3529 fprintf_unfiltered (gdb_stdlog, "Ack\n");
3531 case SERIAL_TIMEOUT:
3535 break; /* Retransmit buffer */
3538 /* It's probably an old response, and we're out of sync.
3539 Just gobble up the packet and ignore it. */
3540 getpkt (junkbuf, 0);
3541 continue; /* Now, go look for + */
3546 if (!started_error_output)
3548 started_error_output = 1;
3549 fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
3551 fputc_unfiltered (ch & 0177, gdb_stdlog);
3555 break; /* Here to retransmit */
3559 /* This is wrong. If doing a long backtrace, the user should be
3560 able to get out next time we call QUIT, without anything as
3561 violent as interrupt_query. If we want to provide a way out of
3562 here without getting to the next QUIT, it should be based on
3563 hitting ^C twice as in remote_wait. */
3573 static int remote_cisco_mode;
3575 /* Come here after finding the start of the frame. Collect the rest
3576 into BUF, verifying the checksum, length, and handling run-length
3577 compression. Returns 0 on any error, 1 on success. */
3592 c = readchar (remote_timeout);
3596 case SERIAL_TIMEOUT:
3598 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
3602 fputs_filtered ("Saw new packet start in middle of old one\n",
3604 return 0; /* Start a new packet, count retries */
3607 unsigned char pktcsum;
3611 pktcsum = fromhex (readchar (remote_timeout)) << 4;
3612 pktcsum |= fromhex (readchar (remote_timeout));
3614 if (csum == pktcsum)
3619 fprintf_filtered (gdb_stdlog,
3620 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
3622 fputs_filtered (buf, gdb_stdlog);
3623 fputs_filtered ("\n", gdb_stdlog);
3627 case '*': /* Run length encoding */
3632 if (remote_cisco_mode == 0)
3634 c = readchar (remote_timeout);
3636 repeat = c - ' ' + 3; /* Compute repeat count */
3640 /* Cisco's run-length encoding variant uses two
3641 hex chars to represent the repeat count. */
3643 c = readchar (remote_timeout);
3645 repeat = fromhex (c) << 4;
3646 c = readchar (remote_timeout);
3648 repeat += fromhex (c);
3651 if (repeat > 0 && repeat <= 255
3652 && bp + repeat - 1 < buf + PBUFSIZ - 1)
3654 memset (bp, *(bp - 1), repeat);
3660 printf_filtered ("Repeat count %d too large for buffer: ", repeat);
3661 puts_filtered (buf);
3662 puts_filtered ("\n");
3666 if (bp < buf + PBUFSIZ - 1)
3674 puts_filtered ("Remote packet too long: ");
3675 puts_filtered (buf);
3676 puts_filtered ("\n");
3683 /* Read a packet from the remote machine, with error checking, and
3684 store it in BUF. BUF is expected to be of size PBUFSIZ. If
3685 FOREVER, wait forever rather than timing out; this is used while
3686 the target is executing user code. */
3689 getpkt (buf, forever)
3698 strcpy (buf, "timeout");
3702 timeout = watchdog > 0 ? watchdog : -1;
3706 timeout = remote_timeout;
3710 for (tries = 1; tries <= MAX_TRIES; tries++)
3712 /* This can loop forever if the remote side sends us characters
3713 continuously, but if it pauses, we'll get a zero from readchar
3714 because of timeout. Then we'll count that as a retry. */
3716 /* Note that we will only wait forever prior to the start of a packet.
3717 After that, we expect characters to arrive at a brisk pace. They
3718 should show up within remote_timeout intervals. */
3722 c = readchar (timeout);
3724 if (c == SERIAL_TIMEOUT)
3726 if (forever) /* Watchdog went off. Kill the target. */
3728 target_mourn_inferior ();
3729 error ("Watchdog has expired. Target detached.\n");
3732 fputs_filtered ("Timed out.\n", gdb_stdlog);
3738 /* We've found the start of a packet, now collect the data. */
3740 val = read_frame (buf);
3746 fprintf_unfiltered (gdb_stdlog, "Packet received: ");
3747 fputstr_unfiltered (buf, 0, gdb_stdlog);
3748 fprintf_unfiltered (gdb_stdlog, "\n");
3750 SERIAL_WRITE (remote_desc, "+", 1);
3754 /* Try the whole thing again. */
3756 SERIAL_WRITE (remote_desc, "-", 1);
3759 /* We have tried hard enough, and just can't receive the packet. Give up. */
3761 printf_unfiltered ("Ignoring packet error, continuing...\n");
3762 SERIAL_WRITE (remote_desc, "+", 1);
3768 /* For some mysterious reason, wait_for_inferior calls kill instead of
3769 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3773 target_mourn_inferior ();
3777 /* Use catch_errors so the user can quit from gdb even when we aren't on
3778 speaking terms with the remote system. */
3779 catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR);
3781 /* Don't wait for it to die. I'm not really sure it matters whether
3782 we do or not. For the existing stubs, kill is a noop. */
3783 target_mourn_inferior ();
3786 /* Async version of remote_kill. */
3788 remote_async_kill ()
3790 /* Unregister the file descriptor from the event loop. */
3791 if (SERIAL_IS_ASYNC_P (remote_desc))
3792 SERIAL_ASYNC (remote_desc, NULL, 0);
3794 /* For some mysterious reason, wait_for_inferior calls kill instead of
3795 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3799 target_mourn_inferior ();
3803 /* Use catch_errors so the user can quit from gdb even when we aren't on
3804 speaking terms with the remote system. */
3805 catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR);
3807 /* Don't wait for it to die. I'm not really sure it matters whether
3808 we do or not. For the existing stubs, kill is a noop. */
3809 target_mourn_inferior ();
3815 remote_mourn_1 (&remote_ops);
3819 remote_async_mourn ()
3821 remote_mourn_1 (&remote_async_ops);
3825 extended_remote_mourn ()
3827 /* We do _not_ want to mourn the target like this; this will
3828 remove the extended remote target from the target stack,
3829 and the next time the user says "run" it'll fail.
3831 FIXME: What is the right thing to do here? */
3833 remote_mourn_1 (&extended_remote_ops);
3837 /* Worker function for remote_mourn. */
3839 remote_mourn_1 (target)
3840 struct target_ops *target;
3842 unpush_target (target);
3843 generic_mourn_inferior ();
3846 /* In the extended protocol we want to be able to do things like
3847 "run" and have them basically work as expected. So we need
3848 a special create_inferior function.
3850 FIXME: One day add support for changing the exec file
3851 we're debugging, arguments and an environment. */
3854 extended_remote_create_inferior (exec_file, args, env)
3859 /* Rip out the breakpoints; we'll reinsert them after restarting
3860 the remote server. */
3861 remove_breakpoints ();
3863 /* Now restart the remote server. */
3864 extended_remote_restart ();
3866 /* Now put the breakpoints back in. This way we're safe if the
3867 restart function works via a unix fork on the remote side. */
3868 insert_breakpoints ();
3870 /* Clean up from the last time we were running. */
3871 clear_proceed_status ();
3873 /* Let the remote process run. */
3874 proceed (-1, TARGET_SIGNAL_0, 0);
3877 /* Async version of extended_remote_create_inferior. */
3879 extended_remote_async_create_inferior (exec_file, args, env)
3884 /* Rip out the breakpoints; we'll reinsert them after restarting
3885 the remote server. */
3886 remove_breakpoints ();
3888 /* If running asynchronously, register the target file descriptor
3889 with the event loop. */
3890 if (event_loop_p && SERIAL_CAN_ASYNC_P (remote_desc))
3891 SERIAL_ASYNC (remote_desc, inferior_event_handler, 0);
3893 /* Now restart the remote server. */
3894 extended_remote_restart ();
3896 /* Now put the breakpoints back in. This way we're safe if the
3897 restart function works via a unix fork on the remote side. */
3898 insert_breakpoints ();
3900 /* Clean up from the last time we were running. */
3901 clear_proceed_status ();
3903 /* Let the remote process run. */
3904 proceed (-1, TARGET_SIGNAL_0, 0);
3908 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
3909 than other targets; in those use REMOTE_BREAKPOINT instead of just
3910 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
3911 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
3912 the standard routines that are in mem-break.c. */
3914 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
3915 the choice of breakpoint instruction affects target program design and
3916 vice versa, and by making it user-tweakable, the special code here
3917 goes away and we need fewer special GDB configurations. */
3919 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
3920 #define REMOTE_BREAKPOINT
3923 #ifdef REMOTE_BREAKPOINT
3925 /* If the target isn't bi-endian, just pretend it is. */
3926 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
3927 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
3928 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
3931 static unsigned char big_break_insn[] = BIG_REMOTE_BREAKPOINT;
3932 static unsigned char little_break_insn[] = LITTLE_REMOTE_BREAKPOINT;
3934 #endif /* REMOTE_BREAKPOINT */
3936 /* Insert a breakpoint on targets that don't have any better breakpoint
3937 support. We read the contents of the target location and stash it,
3938 then overwrite it with a breakpoint instruction. ADDR is the target
3939 location in the target machine. CONTENTS_CACHE is a pointer to
3940 memory allocated for saving the target contents. It is guaranteed
3941 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
3942 is accomplished via BREAKPOINT_MAX). */
3945 remote_insert_breakpoint (addr, contents_cache)
3947 char *contents_cache;
3949 #ifdef REMOTE_BREAKPOINT
3954 /* Try the "Z" packet if it is not already disabled.
3955 If it succeeds, then set the support to PACKET_ENABLE.
3956 If it fails, and the user has explicitly requested the Z support
3957 then report an error, otherwise, mark it disabled and go on. */
3959 if ((remote_protocol_Z.support == PACKET_ENABLE)
3960 || (remote_protocol_Z.support == PACKET_SUPPORT_UNKNOWN))
3962 char buf[PBUFSIZ], *p = buf;
3964 addr = remote_address_masked (addr);
3968 p += hexnumstr (p, (ULONGEST) addr);
3969 BREAKPOINT_FROM_PC (&addr, &bp_size);
3970 sprintf (p, ",%d", bp_size);
3977 remote_protocol_Z.support = PACKET_ENABLE;
3978 return (buf[0] == 'E');
3981 /* The stub does not support the 'Z' request. If the user has
3982 explicitly requested the Z support, or if the stub previously
3983 said it supported the packet, this is an error,
3984 otherwise, mark it disabled. */
3986 else if (remote_protocol_Z.support == PACKET_ENABLE)
3988 error ("Protocol error: Z packet not recognized by stub");
3992 remote_protocol_Z.support = PACKET_DISABLE;
3996 #ifdef REMOTE_BREAKPOINT
3997 val = target_read_memory (addr, contents_cache, sizeof big_break_insn);
4001 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
4002 val = target_write_memory (addr, (char *) big_break_insn,
4003 sizeof big_break_insn);
4005 val = target_write_memory (addr, (char *) little_break_insn,
4006 sizeof little_break_insn);
4011 return memory_insert_breakpoint (addr, contents_cache);
4012 #endif /* REMOTE_BREAKPOINT */
4016 remote_remove_breakpoint (addr, contents_cache)
4018 char *contents_cache;
4022 if ((remote_protocol_Z.support == PACKET_ENABLE)
4023 || (remote_protocol_Z.support == PACKET_SUPPORT_UNKNOWN))
4025 char buf[PBUFSIZ], *p = buf;
4031 addr = remote_address_masked (addr);
4032 p += hexnumstr (p, (ULONGEST) addr);
4033 BREAKPOINT_FROM_PC (&addr, &bp_size);
4034 sprintf (p, ",%d", bp_size);
4039 return (buf[0] == 'E');
4042 #ifdef REMOTE_BREAKPOINT
4043 return target_write_memory (addr, contents_cache, sizeof big_break_insn);
4045 return memory_remove_breakpoint (addr, contents_cache);
4046 #endif /* REMOTE_BREAKPOINT */
4049 #ifdef TARGET_HAS_HARDWARE_WATCHPOINTS
4051 remote_insert_watchpoint (addr, len, type)
4056 char buf[PBUFSIZ], *p;
4058 if (remote_protocol_Z.support == PACKET_DISABLE)
4059 error ("Can't set hardware watchpoints without the 'Z' packet\n");
4061 sprintf (buf, "Z%x,", type + 2 );
4062 p = strchr (buf, '\0');
4063 addr = remote_address_masked (addr);
4064 p += hexnumstr (p, (ULONGEST) addr);
4065 sprintf (p, ",%x", len);
4070 if (buf[0] == '\0' || buf [0] == 'E')
4077 remote_remove_watchpoint (addr, len, type)
4082 char buf[PBUFSIZ], *p;
4084 sprintf (buf, "z%x,", type + 2 );
4085 p = strchr (buf, '\0');
4086 addr = remote_address_masked (addr);
4087 p += hexnumstr (p, (ULONGEST) addr);
4088 sprintf (p, ",%x", len);
4092 if (buf[0] == '\0' || buf [0] == 'E')
4099 remote_insert_hw_breakpoint (addr, len)
4103 char buf[PBUFSIZ], *p = buf;
4105 if (remote_protocol_Z.support == PACKET_DISABLE)
4106 error ("Can't set hardware breakpoints without the 'Z' packet\n");
4112 addr = remote_address_masked (addr);
4113 p += hexnumstr (p, (ULONGEST) addr);
4119 if (buf[0] == '\0' || buf [0] == 'E')
4126 remote_remove_hw_breakpoint (addr, len)
4130 char buf[PBUFSIZ], *p = buf;
4136 addr = remote_address_masked (addr);
4137 p += hexnumstr (p, (ULONGEST) addr);
4143 if (buf[0] == '\0' || buf [0] == 'E')
4150 /* Some targets are only capable of doing downloads, and afterwards
4151 they switch to the remote serial protocol. This function provides
4152 a clean way to get from the download target to the remote target.
4153 It's basically just a wrapper so that we don't have to expose any
4154 of the internal workings of remote.c.
4156 Prior to calling this routine, you should shutdown the current
4157 target code, else you will get the "A program is being debugged
4158 already..." message. Usually a call to pop_target() suffices. */
4161 push_remote_target (name, from_tty)
4165 printf_filtered ("Switching to remote protocol\n");
4166 remote_open (name, from_tty);
4169 /* Other targets want to use the entire remote serial module but with
4170 certain remote_ops overridden. */
4173 open_remote_target (name, from_tty, target, extended_p)
4176 struct target_ops *target;
4179 printf_filtered ("Selecting the %sremote protocol\n",
4180 (extended_p ? "extended-" : ""));
4181 remote_open_1 (name, from_tty, target, extended_p);
4184 /* Table used by the crc32 function to calcuate the checksum. */
4186 static unsigned long crc32_table[256] =
4189 static unsigned long
4190 crc32 (buf, len, crc)
4195 if (!crc32_table[1])
4197 /* Initialize the CRC table and the decoding table. */
4201 for (i = 0; i < 256; i++)
4203 for (c = i << 24, j = 8; j > 0; --j)
4204 c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1);
4211 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buf) & 255];
4217 /* compare-sections command
4219 With no arguments, compares each loadable section in the exec bfd
4220 with the same memory range on the target, and reports mismatches.
4221 Useful for verifying the image on the target against the exec file.
4222 Depends on the target understanding the new "qCRC:" request. */
4225 compare_sections_command (args, from_tty)
4230 unsigned long host_crc, target_crc;
4231 extern bfd *exec_bfd;
4232 struct cleanup *old_chain;
4236 char *buf = alloca (PBUFSIZ);
4243 error ("command cannot be used without an exec file");
4244 if (!current_target.to_shortname ||
4245 strcmp (current_target.to_shortname, "remote") != 0)
4246 error ("command can only be used with remote target");
4248 for (s = exec_bfd->sections; s; s = s->next)
4250 if (!(s->flags & SEC_LOAD))
4251 continue; /* skip non-loadable section */
4253 size = bfd_get_section_size_before_reloc (s);
4255 continue; /* skip zero-length section */
4257 sectname = (char *) bfd_get_section_name (exec_bfd, s);
4258 if (args && strcmp (args, sectname) != 0)
4259 continue; /* not the section selected by user */
4261 matched = 1; /* do this section */
4263 /* FIXME: assumes lma can fit into long */
4264 sprintf (buf, "qCRC:%lx,%lx", (long) lma, (long) size);
4267 /* be clever; compute the host_crc before waiting for target reply */
4268 sectdata = xmalloc (size);
4269 old_chain = make_cleanup (free, sectdata);
4270 bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
4271 host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
4275 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
4276 sectname, lma, lma + size);
4278 error ("remote target does not support this operation");
4280 for (target_crc = 0, tmp = &buf[1]; *tmp; tmp++)
4281 target_crc = target_crc * 16 + fromhex (*tmp);
4283 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4284 sectname, paddr (lma), paddr (lma + size));
4285 if (host_crc == target_crc)
4286 printf_filtered ("matched.\n");
4289 printf_filtered ("MIS-MATCHED!\n");
4293 do_cleanups (old_chain);
4296 warning ("One or more sections of the remote executable does not match\n\
4297 the loaded file\n");
4298 if (args && !matched)
4299 printf_filtered ("No loaded section named '%s'.\n", args);
4303 remote_query (query_type, buf, outbuf, bufsiz)
4310 char *buf2 = alloca (PBUFSIZ);
4311 char *p2 = &buf2[0];
4314 error ("null pointer to remote bufer size specified");
4316 /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let
4317 the caller know and return what the minimum size is */
4318 /* Note: a zero bufsiz can be used to query the minimum buffer size */
4319 if (*bufsiz < PBUFSIZ)
4325 /* except for querying the minimum buffer size, target must be open */
4327 error ("remote query is only available after target open");
4329 /* we only take uppercase letters as query types, at least for now */
4330 if ((query_type < 'A') || (query_type > 'Z'))
4331 error ("invalid remote query type");
4334 error ("null remote query specified");
4337 error ("remote query requires a buffer to receive data");
4344 /* we used one buffer char for the remote protocol q command and another
4345 for the query type. As the remote protocol encapsulation uses 4 chars
4346 plus one extra in case we are debugging (remote_debug),
4347 we have PBUFZIZ - 7 left to pack the query string */
4349 while (buf[i] && (i < (PBUFSIZ - 8)))
4351 /* bad caller may have sent forbidden characters */
4352 if ((!isprint (buf[i])) || (buf[i] == '$') || (buf[i] == '#'))
4353 error ("illegal characters in query string");
4361 error ("query larger than available buffer");
4373 remote_rcmd (char *command,
4374 struct gdb_file *outbuf)
4377 char *buf = alloca (PBUFSIZ);
4381 error ("remote rcmd is only available after target open");
4383 /* Send a NULL command across as an empty command */
4384 if (command == NULL)
4387 /* The query prefix */
4388 strcpy (buf, "qRcmd,");
4389 p = strchr (buf, '\0');
4391 if ((strlen (buf) + strlen (command) * 2 + 8/*misc*/) > PBUFSIZ)
4392 error ("\"monitor\" command ``%s'' is too long\n", command);
4394 /* Encode the actual command */
4395 for (i = 0; command[i]; i++)
4397 *p++ = tohex ((command[i] >> 4) & 0xf);
4398 *p++ = tohex (command[i] & 0xf);
4402 if (putpkt (buf) < 0)
4403 error ("Communication problem with target\n");
4405 /* get/display the response */
4408 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
4412 error ("Target does not support this command\n");
4413 if (buf[0] == 'O' && buf[1] != 'K')
4415 remote_console_output (buf + 1); /* 'O' message from stub */
4418 if (strcmp (buf, "OK") == 0)
4420 if (strlen (buf) == 3 && buf[0] == 'E'
4421 && isdigit (buf[1]) && isdigit (buf[2]))
4423 error ("Protocol error with Rcmd");
4425 for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
4427 char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
4428 fputc_unfiltered (c, outbuf);
4435 packet_command (args, from_tty)
4439 char *buf = alloca (PBUFSIZ);
4442 error ("command can only be used with remote target");
4445 error ("remote-packet command requires packet text as argument");
4447 puts_filtered ("sending: ");
4448 print_packet (args);
4449 puts_filtered ("\n");
4453 puts_filtered ("received: ");
4455 puts_filtered ("\n");
4459 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
4461 static void display_thread_info PARAMS ((struct gdb_ext_thread_info * info));
4463 static void threadset_test_cmd PARAMS ((char *cmd, int tty));
4465 static void threadalive_test PARAMS ((char *cmd, int tty));
4467 static void threadlist_test_cmd PARAMS ((char *cmd, int tty));
4469 int get_and_display_threadinfo PARAMS ((threadref * ref));
4471 static void threadinfo_test_cmd PARAMS ((char *cmd, int tty));
4473 static int thread_display_step PARAMS ((threadref * ref, void *context));
4475 static void threadlist_update_test_cmd PARAMS ((char *cmd, int tty));
4477 static void init_remote_threadtests PARAMS ((void));
4479 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
4482 threadset_test_cmd (cmd, tty)
4486 int sample_thread = SAMPLE_THREAD;
4488 printf_filtered ("Remote threadset test\n");
4489 set_thread (sample_thread, 1);
4494 threadalive_test (cmd, tty)
4498 int sample_thread = SAMPLE_THREAD;
4500 if (remote_thread_alive (sample_thread))
4501 printf_filtered ("PASS: Thread alive test\n");
4503 printf_filtered ("FAIL: Thread alive test\n");
4506 void output_threadid PARAMS ((char *title, threadref * ref));
4509 output_threadid (title, ref)
4515 pack_threadid (&hexid[0], ref); /* Convert threead id into hex */
4517 printf_filtered ("%s %s\n", title, (&hexid[0]));
4521 threadlist_test_cmd (cmd, tty)
4526 threadref nextthread;
4527 int done, result_count;
4528 threadref threadlist[3];
4530 printf_filtered ("Remote Threadlist test\n");
4531 if (!remote_get_threadlist (startflag, &nextthread, 3, &done,
4532 &result_count, &threadlist[0]))
4533 printf_filtered ("FAIL: threadlist test\n");
4536 threadref *scan = threadlist;
4537 threadref *limit = scan + result_count;
4539 while (scan < limit)
4540 output_threadid (" thread ", scan++);
4545 display_thread_info (info)
4546 struct gdb_ext_thread_info *info;
4548 output_threadid ("Threadid: ", &info->threadid);
4549 printf_filtered ("Name: %s\n ", info->shortname);
4550 printf_filtered ("State: %s\n", info->display);
4551 printf_filtered ("other: %s\n\n", info->more_display);
4555 get_and_display_threadinfo (ref)
4560 struct gdb_ext_thread_info threadinfo;
4562 set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
4563 | TAG_MOREDISPLAY | TAG_DISPLAY;
4564 if (0 != (result = remote_get_threadinfo (ref, set, &threadinfo)))
4565 display_thread_info (&threadinfo);
4570 threadinfo_test_cmd (cmd, tty)
4574 int athread = SAMPLE_THREAD;
4578 int_to_threadref (&thread, athread);
4579 printf_filtered ("Remote Threadinfo test\n");
4580 if (!get_and_display_threadinfo (&thread))
4581 printf_filtered ("FAIL cannot get thread info\n");
4585 thread_display_step (ref, context)
4589 /* output_threadid(" threadstep ",ref); *//* simple test */
4590 return get_and_display_threadinfo (ref);
4594 threadlist_update_test_cmd (cmd, tty)
4598 printf_filtered ("Remote Threadlist update test\n");
4599 remote_threadlist_iterator (thread_display_step, 0, CRAZY_MAX_THREADS);
4603 init_remote_threadtests (void)
4605 add_com ("tlist", class_obscure, threadlist_test_cmd,
4606 "Fetch and print the remote list of thread identifiers, one pkt only");
4607 add_com ("tinfo", class_obscure, threadinfo_test_cmd,
4608 "Fetch and display info about one thread");
4609 add_com ("tset", class_obscure, threadset_test_cmd,
4610 "Test setting to a different thread");
4611 add_com ("tupd", class_obscure, threadlist_update_test_cmd,
4612 "Iterate through updating all remote thread info");
4613 add_com ("talive", class_obscure, threadalive_test,
4614 " Remote thread alive test ");
4622 remote_ops.to_shortname = "remote";
4623 remote_ops.to_longname = "Remote serial target in gdb-specific protocol";
4625 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4626 Specify the serial device it is connected to (e.g. /dev/ttya).";
4627 remote_ops.to_open = remote_open;
4628 remote_ops.to_close = remote_close;
4629 remote_ops.to_detach = remote_detach;
4630 remote_ops.to_resume = remote_resume;
4631 remote_ops.to_wait = remote_wait;
4632 remote_ops.to_fetch_registers = remote_fetch_registers;
4633 remote_ops.to_store_registers = remote_store_registers;
4634 remote_ops.to_prepare_to_store = remote_prepare_to_store;
4635 remote_ops.to_xfer_memory = remote_xfer_memory;
4636 remote_ops.to_files_info = remote_files_info;
4637 remote_ops.to_insert_breakpoint = remote_insert_breakpoint;
4638 remote_ops.to_remove_breakpoint = remote_remove_breakpoint;
4639 remote_ops.to_kill = remote_kill;
4640 remote_ops.to_load = generic_load;
4641 remote_ops.to_mourn_inferior = remote_mourn;
4642 remote_ops.to_thread_alive = remote_thread_alive;
4643 remote_ops.to_find_new_threads = remote_threads_info;
4644 remote_ops.to_stop = remote_stop;
4645 remote_ops.to_query = remote_query;
4646 remote_ops.to_rcmd = remote_rcmd;
4647 remote_ops.to_stratum = process_stratum;
4648 remote_ops.to_has_all_memory = 1;
4649 remote_ops.to_has_memory = 1;
4650 remote_ops.to_has_stack = 1;
4651 remote_ops.to_has_registers = 1;
4652 remote_ops.to_has_execution = 1;
4653 remote_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */
4654 remote_ops.to_magic = OPS_MAGIC;
4657 /* Set up the extended remote vector by making a copy of the standard
4658 remote vector and adding to it. */
4661 init_extended_remote_ops ()
4663 extended_remote_ops = remote_ops;
4665 extended_remote_ops.to_shortname = "extended-remote";
4666 extended_remote_ops.to_longname =
4667 "Extended remote serial target in gdb-specific protocol";
4668 extended_remote_ops.to_doc =
4669 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4670 Specify the serial device it is connected to (e.g. /dev/ttya).",
4671 extended_remote_ops.to_open = extended_remote_open;
4672 extended_remote_ops.to_create_inferior = extended_remote_create_inferior;
4673 extended_remote_ops.to_mourn_inferior = extended_remote_mourn;
4677 * Command: info remote-process
4679 * This implements Cisco's version of the "info proc" command.
4681 * This query allows the target stub to return an arbitrary string
4682 * (or strings) giving arbitrary information about the target process.
4683 * This is optional; the target stub isn't required to implement it.
4685 * Syntax: qfProcessInfo request first string
4686 * qsProcessInfo request subsequent string
4687 * reply: 'O'<hex-encoded-string>
4688 * 'l' last reply (empty)
4692 remote_info_process (args, from_tty)
4696 char *buf = alloca (PBUFSIZ);
4698 if (remote_desc == 0)
4699 error ("Command can only be used when connected to the remote target.");
4701 putpkt ("qfProcessInfo");
4704 return; /* Silently: target does not support this feature. */
4707 error ("info proc: target error.");
4709 while (buf[0] == 'O') /* Capitol-O packet */
4711 remote_console_output (&buf[1]);
4712 putpkt ("qsProcessInfo");
4722 remote_cisco_open (name, from_tty)
4728 "To open a remote debug connection, you need to specify what \n\
4729 device is attached to the remote system (e.g. host:port).");
4731 /* See FIXME above */
4732 wait_forever_enabled_p = 1;
4734 target_preopen (from_tty);
4736 unpush_target (&remote_cisco_ops);
4738 remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
4740 remote_desc = SERIAL_OPEN (name);
4742 perror_with_name (name);
4745 * If a baud rate was specified on the gdb command line it will
4746 * be greater than the initial value of -1. If it is, use it otherwise
4750 baud_rate = (baud_rate > 0) ? baud_rate : 9600;
4751 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
4753 SERIAL_CLOSE (remote_desc);
4754 perror_with_name (name);
4757 SERIAL_RAW (remote_desc);
4759 /* If there is something sitting in the buffer we might take it as a
4760 response to a command, which would be bad. */
4761 SERIAL_FLUSH_INPUT (remote_desc);
4765 puts_filtered ("Remote debugging using ");
4766 puts_filtered (name);
4767 puts_filtered ("\n");
4770 remote_cisco_mode = 1;
4772 push_target (&remote_cisco_ops); /* Switch to using cisco target now */
4774 init_packet_config (&remote_protocol_P);
4775 init_packet_config (&remote_protocol_Z);
4777 general_thread = -2;
4778 continue_thread = -2;
4780 /* Force remote_write_bytes to check whether target supports
4781 binary downloading. */
4782 init_packet_config (&remote_protocol_binary_download);
4784 /* Without this, some commands which require an active target (such
4785 as kill) won't work. This variable serves (at least) double duty
4786 as both the pid of the target process (if it has such), and as a
4787 flag indicating that a target is active. These functions should
4788 be split out into seperate variables, especially since GDB will
4789 someday have a notion of debugging several processes. */
4790 inferior_pid = MAGIC_NULL_PID;
4792 /* Start the remote connection; if error (0), discard this target. */
4794 if (!catch_errors (remote_start_remote_dummy, (char *) 0,
4795 "Couldn't establish connection to remote target\n",
4804 remote_cisco_close (quitting)
4807 remote_cisco_mode = 0;
4808 remote_close (quitting);
4815 remote_mourn_1 (&remote_cisco_ops);
4827 /* shared between readsocket() and readtty() */
4828 static char *tty_input;
4830 static int escape_count;
4831 static int echo_check;
4832 extern int quit_flag;
4839 /* Loop until the socket doesn't have any more data */
4841 while ((data = readchar (0)) >= 0)
4843 /* Check for the escape sequence */
4846 /* If this is the fourth escape, get out */
4847 if (++escape_count == 4)
4852 { /* This is a '|', but not the fourth in a row.
4853 Continue without echoing it. If it isn't actually
4854 one of four in a row, it'll be echoed later. */
4861 /* Ensure any pending '|'s are flushed. */
4863 for (; escape_count > 0; escape_count--)
4867 if (data == '\r') /* If this is a return character, */
4868 continue; /* - just supress it. */
4870 if (echo_check != -1) /* Check for echo of user input. */
4872 if (tty_input[echo_check] == data)
4874 echo_check++; /* Character matched user input: */
4875 continue; /* Continue without echoing it. */
4877 else if ((data == '\n') && (tty_input[echo_check] == '\r'))
4878 { /* End of the line (and of echo checking). */
4879 echo_check = -1; /* No more echo supression */
4880 continue; /* Continue without echoing. */
4883 { /* Failed check for echo of user input.
4884 We now have some suppressed output to flush! */
4887 for (j = 0; j < echo_check; j++)
4888 putchar (tty_input[j]);
4892 putchar (data); /* Default case: output the char. */
4895 if (data == SERIAL_TIMEOUT) /* Timeout returned from readchar. */
4896 return READ_MORE; /* Try to read some more */
4898 return FATAL_ERROR; /* Trouble, bail out */
4906 /* First, read a buffer full from the terminal */
4907 tty_bytecount = read (fileno (stdin), tty_input, sizeof (tty_input) - 1);
4908 if (tty_bytecount == -1)
4910 perror ("readtty: read failed");
4914 /* Remove a quoted newline. */
4915 if (tty_input[tty_bytecount - 1] == '\n' &&
4916 tty_input[tty_bytecount - 2] == '\\') /* line ending in backslash */
4918 tty_input[--tty_bytecount] = 0; /* remove newline */
4919 tty_input[--tty_bytecount] = 0; /* remove backslash */
4922 /* Turn trailing newlines into returns */
4923 if (tty_input[tty_bytecount - 1] == '\n')
4924 tty_input[tty_bytecount - 1] = '\r';
4926 /* If the line consists of a ~, enter debugging mode. */
4927 if ((tty_input[0] == '~') && (tty_bytecount == 2))
4930 /* Make this a zero terminated string and write it out */
4931 tty_input[tty_bytecount] = 0;
4932 if (SERIAL_WRITE (remote_desc, tty_input, tty_bytecount))
4934 perror_with_name ("readtty: write failed");
4944 fd_set input; /* file descriptors for select */
4945 int tablesize; /* max number of FDs for select */
4949 extern int escape_count; /* global shared by readsocket */
4950 extern int echo_check; /* ditto */
4955 tablesize = 8 * sizeof (input);
4959 /* Check for anything from our socket - doesn't block. Note that
4960 this must be done *before* the select as there may be
4961 buffered I/O waiting to be processed. */
4963 if ((status = readsocket ()) == FATAL_ERROR)
4965 error ("Debugging terminated by communications error");
4967 else if (status != READ_MORE)
4972 fflush (stdout); /* Flush output before blocking */
4974 /* Now block on more socket input or TTY input */
4977 FD_SET (fileno (stdin), &input);
4978 FD_SET (DEPRECATED_SERIAL_FD (remote_desc), &input);
4980 status = select (tablesize, &input, 0, 0, 0);
4981 if ((status == -1) && (errno != EINTR))
4983 error ("Communications error on select %d", errno);
4986 /* Handle Control-C typed */
4990 if ((++quit_count) == 2)
4992 if (query ("Interrupt GDB? "))
4994 printf_filtered ("Interrupted by user.\n");
4995 return_to_top_level (RETURN_QUIT);
5002 SERIAL_SEND_BREAK (remote_desc);
5004 SERIAL_WRITE (remote_desc, "\003", 1);
5009 /* Handle console input */
5011 if (FD_ISSET (fileno (stdin), &input))
5015 status = readtty ();
5016 if (status == READ_MORE)
5019 return status; /* telnet session ended */
5025 remote_cisco_wait (pid, status)
5027 struct target_waitstatus *status;
5029 if (minitelnet () != ENTER_DEBUG)
5031 error ("Debugging session terminated by protocol error");
5034 return remote_wait (pid, status);
5038 init_remote_cisco_ops ()
5040 remote_cisco_ops.to_shortname = "cisco";
5041 remote_cisco_ops.to_longname = "Remote serial target in cisco-specific protocol";
5042 remote_cisco_ops.to_doc =
5043 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5044 Specify the serial device it is connected to (e.g. host:2020).";
5045 remote_cisco_ops.to_open = remote_cisco_open;
5046 remote_cisco_ops.to_close = remote_cisco_close;
5047 remote_cisco_ops.to_detach = remote_detach;
5048 remote_cisco_ops.to_resume = remote_resume;
5049 remote_cisco_ops.to_wait = remote_cisco_wait;
5050 remote_cisco_ops.to_fetch_registers = remote_fetch_registers;
5051 remote_cisco_ops.to_store_registers = remote_store_registers;
5052 remote_cisco_ops.to_prepare_to_store = remote_prepare_to_store;
5053 remote_cisco_ops.to_xfer_memory = remote_xfer_memory;
5054 remote_cisco_ops.to_files_info = remote_files_info;
5055 remote_cisco_ops.to_insert_breakpoint = remote_insert_breakpoint;
5056 remote_cisco_ops.to_remove_breakpoint = remote_remove_breakpoint;
5057 remote_cisco_ops.to_kill = remote_kill;
5058 remote_cisco_ops.to_load = generic_load;
5059 remote_cisco_ops.to_mourn_inferior = remote_cisco_mourn;
5060 remote_cisco_ops.to_thread_alive = remote_thread_alive;
5061 remote_cisco_ops.to_find_new_threads = remote_threads_info;
5062 remote_cisco_ops.to_stratum = process_stratum;
5063 remote_cisco_ops.to_has_all_memory = 1;
5064 remote_cisco_ops.to_has_memory = 1;
5065 remote_cisco_ops.to_has_stack = 1;
5066 remote_cisco_ops.to_has_registers = 1;
5067 remote_cisco_ops.to_has_execution = 1;
5068 remote_cisco_ops.to_magic = OPS_MAGIC;
5072 remote_can_async_p (void)
5074 /* We're async whenever the serial device is. */
5075 return SERIAL_CAN_ASYNC_P (remote_desc);
5079 remote_is_async_p (void)
5081 /* We're async whenever the serial device is. */
5082 return SERIAL_IS_ASYNC_P (remote_desc);
5086 remote_async (void (*callback) (int error, void *context, int fd), void *context)
5088 SERIAL_ASYNC (remote_desc, callback, context);
5091 /* Target async and target extended-async.
5093 This are temporary targets, until it is all tested. Eventually
5094 async support will be incorporated int the usual 'remote'
5098 init_remote_async_ops ()
5100 remote_async_ops.to_shortname = "async";
5101 remote_async_ops.to_longname = "Remote serial target in async version of the gdb-specific protocol";
5102 remote_async_ops.to_doc =
5103 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5104 Specify the serial device it is connected to (e.g. /dev/ttya).";
5105 remote_async_ops.to_open = remote_async_open;
5106 remote_async_ops.to_close = remote_close;
5107 remote_async_ops.to_detach = remote_async_detach;
5108 remote_async_ops.to_resume = remote_async_resume;
5109 remote_async_ops.to_wait = remote_async_wait;
5110 remote_async_ops.to_fetch_registers = remote_fetch_registers;
5111 remote_async_ops.to_store_registers = remote_store_registers;
5112 remote_async_ops.to_prepare_to_store = remote_prepare_to_store;
5113 remote_async_ops.to_xfer_memory = remote_xfer_memory;
5114 remote_async_ops.to_files_info = remote_files_info;
5115 remote_async_ops.to_insert_breakpoint = remote_insert_breakpoint;
5116 remote_async_ops.to_remove_breakpoint = remote_remove_breakpoint;
5117 remote_async_ops.to_terminal_inferior = remote_async_terminal_inferior;
5118 remote_async_ops.to_terminal_ours = remote_async_terminal_ours;
5119 remote_async_ops.to_kill = remote_async_kill;
5120 remote_async_ops.to_load = generic_load;
5121 remote_async_ops.to_mourn_inferior = remote_async_mourn;
5122 remote_async_ops.to_thread_alive = remote_thread_alive;
5123 remote_async_ops.to_find_new_threads = remote_threads_info;
5124 remote_async_ops.to_stop = remote_stop;
5125 remote_async_ops.to_query = remote_query;
5126 remote_async_ops.to_rcmd = remote_rcmd;
5127 remote_async_ops.to_stratum = process_stratum;
5128 remote_async_ops.to_has_all_memory = 1;
5129 remote_async_ops.to_has_memory = 1;
5130 remote_async_ops.to_has_stack = 1;
5131 remote_async_ops.to_has_registers = 1;
5132 remote_async_ops.to_has_execution = 1;
5133 remote_async_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */
5134 remote_async_ops.to_can_async_p = remote_can_async_p;
5135 remote_async_ops.to_is_async_p = remote_is_async_p;
5136 remote_async_ops.to_async = remote_async;
5137 remote_async_ops.to_magic = OPS_MAGIC;
5140 /* Set up the async extended remote vector by making a copy of the standard
5141 remote vector and adding to it. */
5144 init_extended_async_remote_ops ()
5146 extended_async_remote_ops = remote_async_ops;
5148 extended_async_remote_ops.to_shortname = "extended-async";
5149 extended_async_remote_ops.to_longname =
5150 "Extended remote serial target in async gdb-specific protocol";
5151 extended_async_remote_ops.to_doc =
5152 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5153 Specify the serial device it is connected to (e.g. /dev/ttya).",
5154 extended_async_remote_ops.to_open = extended_remote_async_open;
5155 extended_async_remote_ops.to_create_inferior = extended_remote_async_create_inferior;
5156 extended_async_remote_ops.to_mourn_inferior = extended_remote_mourn;
5160 set_remote_cmd (args, from_tty)
5169 build_remote_gdbarch_data ()
5171 tty_input = xmalloc (PBUFSIZ);
5175 _initialize_remote ()
5177 static struct cmd_list_element *remote_set_cmdlist;
5178 static struct cmd_list_element *remote_show_cmdlist;
5180 /* architecture specific data */
5181 build_remote_gdbarch_data ();
5182 register_gdbarch_swap (&tty_input, sizeof (&tty_input), NULL);
5183 register_gdbarch_swap (NULL, 0, build_remote_gdbarch_data);
5185 /* runtime constants - we retain the value of remote_write_size
5186 across architecture swaps. */
5187 remote_write_size = PBUFSIZ;
5190 add_target (&remote_ops);
5192 init_extended_remote_ops ();
5193 add_target (&extended_remote_ops);
5195 init_remote_async_ops ();
5196 add_target (&remote_async_ops);
5198 init_extended_async_remote_ops ();
5199 add_target (&extended_async_remote_ops);
5201 init_remote_cisco_ops ();
5202 add_target (&remote_cisco_ops);
5205 init_remote_threadtests ();
5208 add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, "\
5209 Remote protocol specific variables\n\
5210 Configure various remote-protocol specific variables such as\n\
5211 the packets being used",
5212 &remote_set_cmdlist, "set remote ",
5213 0/*allow-unknown*/, &setlist);
5214 add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, "\
5215 Remote protocol specific variables\n\
5216 Configure various remote-protocol specific variables such as\n\
5217 the packets being used",
5218 &remote_show_cmdlist, "show remote ",
5219 0/*allow-unknown*/, &showlist);
5221 add_cmd ("compare-sections", class_obscure, compare_sections_command,
5222 "Compare section data on target to the exec file.\n\
5223 Argument is a single section name (default: all loaded sections).",
5226 add_cmd ("packet", class_maintenance, packet_command,
5227 "Send an arbitrary packet to a remote target.\n\
5228 maintenance packet TEXT\n\
5229 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5230 this command sends the string TEXT to the inferior, and displays the\n\
5231 response packet. GDB supplies the initial `$' character, and the\n\
5232 terminating `#' character and checksum.",
5236 (add_set_cmd ("remotetimeout", no_class,
5237 var_integer, (char *) &remote_timeout,
5238 "Set timeout value for remote read.\n",
5243 (add_set_cmd ("remotebreak", no_class,
5244 var_boolean, (char *) &remote_break,
5245 "Set whether to send break if interrupted.\n",
5250 (add_set_cmd ("remotewritesize", no_class,
5251 var_integer, (char *) &remote_write_size,
5252 "Set the maximum number of bytes per memory write packet.\n",
5256 remote_address_size = TARGET_PTR_BIT;
5258 (add_set_cmd ("remoteaddresssize", class_obscure,
5259 var_integer, (char *) &remote_address_size,
5260 "Set the maximum size of the address (in bits) \
5261 in a memory packet.\n",
5265 add_packet_config_cmd (&remote_protocol_binary_download,
5266 "X", "binary-download",
5267 set_remote_protocol_binary_download_cmd,
5268 show_remote_protocol_binary_download_cmd,
5269 &remote_set_cmdlist, &remote_show_cmdlist);
5271 /* XXXX - should ``set remotebinarydownload'' be retained for
5274 (add_set_cmd ("remotebinarydownload", no_class,
5275 var_boolean, (char *) &remote_binary_download,
5276 "Set binary downloads.\n", &setlist),
5280 add_info ("remote-process", remote_info_process,
5281 "Query the remote system for process info.");
5283 add_packet_config_cmd (&remote_protocol_P, "P", "set-register",
5284 set_remote_protocol_P_packet_cmd,
5285 show_remote_protocol_P_packet_cmd,
5286 &remote_set_cmdlist, &remote_show_cmdlist);
5288 add_packet_config_cmd (&remote_protocol_Z, "Z", "breakpoint",
5289 set_remote_protocol_Z_packet_cmd,
5290 show_remote_protocol_Z_packet_cmd,
5291 &remote_set_cmdlist, &remote_show_cmdlist);