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"
56 /* Prototypes for local functions */
57 static void cleanup_sigint_signal_handler (void *dummy);
58 static void initialize_sigint_signal_handler (void);
60 static void handle_remote_sigint PARAMS ((int));
61 static void handle_remote_sigint_twice PARAMS ((int));
62 static void async_remote_interrupt PARAMS ((gdb_client_data));
63 void async_remote_interrupt_twice PARAMS ((gdb_client_data));
65 static void build_remote_gdbarch_data PARAMS ((void));
67 static int remote_write_bytes PARAMS ((CORE_ADDR memaddr,
68 char *myaddr, int len));
70 static int remote_read_bytes PARAMS ((CORE_ADDR memaddr,
71 char *myaddr, int len));
73 static void remote_files_info PARAMS ((struct target_ops * ignore));
75 static int remote_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
76 int len, int should_write,
77 struct target_ops * target));
79 static void remote_prepare_to_store PARAMS ((void));
81 static void remote_fetch_registers PARAMS ((int regno));
83 static void remote_resume PARAMS ((int pid, int step,
84 enum target_signal siggnal));
85 static void remote_async_resume PARAMS ((int pid, int step,
86 enum target_signal siggnal));
87 static int remote_start_remote PARAMS ((PTR));
89 static void remote_open PARAMS ((char *name, int from_tty));
90 static void remote_async_open PARAMS ((char *name, int from_tty));
92 static void extended_remote_open PARAMS ((char *name, int from_tty));
93 static void extended_remote_async_open PARAMS ((char *name, int from_tty));
95 static void remote_open_1 PARAMS ((char *, int, struct target_ops *,
97 static void remote_async_open_1 PARAMS ((char *, int, struct target_ops *,
100 static void remote_close PARAMS ((int quitting));
102 static void remote_store_registers PARAMS ((int regno));
104 static void remote_mourn PARAMS ((void));
105 static void remote_async_mourn PARAMS ((void));
107 static void extended_remote_restart PARAMS ((void));
109 static void extended_remote_mourn PARAMS ((void));
111 static void extended_remote_create_inferior PARAMS ((char *, char *, char **));
112 static void extended_remote_async_create_inferior PARAMS ((char *, char *, char **));
114 static void remote_mourn_1 PARAMS ((struct target_ops *));
116 static void remote_send PARAMS ((char *buf));
118 static int readchar PARAMS ((int timeout));
120 static int remote_wait PARAMS ((int pid, struct target_waitstatus * status));
121 static int remote_async_wait PARAMS ((int pid, struct target_waitstatus * status));
123 static void remote_kill PARAMS ((void));
124 static void remote_async_kill PARAMS ((void));
126 static int tohex PARAMS ((int nib));
128 static void remote_detach PARAMS ((char *args, int from_tty));
129 static void remote_async_detach PARAMS ((char *args, int from_tty));
131 static void remote_interrupt PARAMS ((int signo));
133 static void remote_interrupt_twice PARAMS ((int signo));
135 static void interrupt_query PARAMS ((void));
137 static void set_thread PARAMS ((int, int));
139 static int remote_thread_alive PARAMS ((int));
141 static void get_offsets PARAMS ((void));
143 static int read_frame PARAMS ((char *));
145 static int remote_insert_breakpoint PARAMS ((CORE_ADDR, char *));
147 static int remote_remove_breakpoint PARAMS ((CORE_ADDR, char *));
149 static int hexnumlen PARAMS ((ULONGEST num));
151 static void init_remote_ops PARAMS ((void));
153 static void init_extended_remote_ops PARAMS ((void));
155 static void init_remote_cisco_ops PARAMS ((void));
157 static struct target_ops remote_cisco_ops;
159 static void remote_stop PARAMS ((void));
161 static int ishex PARAMS ((int ch, int *val));
163 static int stubhex PARAMS ((int ch));
165 static int remote_query PARAMS ((int /*char */ , char *, char *, int *));
167 static int hexnumstr PARAMS ((char *, ULONGEST));
169 static int hexnumnstr PARAMS ((char *, ULONGEST, int));
171 static CORE_ADDR remote_address_masked PARAMS ((CORE_ADDR));
173 static void print_packet PARAMS ((char *));
175 static unsigned long crc32 PARAMS ((unsigned char *, int, unsigned int));
177 static void compare_sections_command PARAMS ((char *, int));
179 static void packet_command PARAMS ((char *, int));
181 static int stub_unpack_int PARAMS ((char *buff, int fieldlength));
183 static int remote_current_thread PARAMS ((int oldpid));
185 static void remote_find_new_threads PARAMS ((void));
187 static void record_currthread PARAMS ((int currthread));
189 /* exported functions */
191 extern int fromhex PARAMS ((int a));
193 static int putpkt_binary PARAMS ((char *buf, int cnt));
195 static void check_binary_download PARAMS ((CORE_ADDR addr));
197 struct packet_config;
199 static void show_packet_config_cmd PARAMS ((struct packet_config * config));
201 static void set_packet_config_cmd PARAMS ((struct packet_config * config,
202 struct cmd_list_element * c));
204 static void add_packet_config_cmd PARAMS ((struct packet_config * config,
207 void (*set_func) (char *args, int from_tty, struct cmd_list_element * c),
208 void (*show_func) (char *name, int from_tty),
209 struct cmd_list_element **setlist,
210 struct cmd_list_element **showlist));
212 static void init_packet_config PARAMS ((struct packet_config * config));
214 static void set_remote_protocol_P_packet_cmd PARAMS ((char *args,
216 struct cmd_list_element * c));
218 static void show_remote_protocol_P_packet_cmd PARAMS ((char *args,
221 static void set_remote_protocol_Z_packet_cmd PARAMS ((char *args,
223 struct cmd_list_element * c));
225 static void show_remote_protocol_Z_packet_cmd PARAMS ((char *args,
231 /* Define the target subroutine names */
233 void open_remote_target PARAMS ((char *, int, struct target_ops *, int));
235 void _initialize_remote PARAMS ((void));
239 static struct target_ops remote_ops;
241 static struct target_ops extended_remote_ops;
243 /* Temporary target ops. Just like the remote_ops and
244 extended_remote_ops, but with asynchronous support. */
245 static struct target_ops remote_async_ops;
247 static struct target_ops extended_async_remote_ops;
249 /* This was 5 seconds, which is a long time to sit and wait.
250 Unless this is going though some terminal server or multiplexer or
251 other form of hairy serial connection, I would think 2 seconds would
254 /* Changed to allow option to set timeout value.
255 was static int remote_timeout = 2; */
256 extern int remote_timeout;
258 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
259 ``forever'' still use the normal timeout mechanism. This is
260 currently used by the ASYNC code to guarentee that target reads
261 during the initial connect always time-out. Once getpkt has been
262 modified to return a timeout indication and, in turn
263 remote_wait()/wait_for_inferior() have gained a timeout parameter
265 static int wait_forever_enabled_p = 1;
268 /* This variable chooses whether to send a ^C or a break when the user
269 requests program interruption. Although ^C is usually what remote
270 systems expect, and that is the default here, sometimes a break is
271 preferable instead. */
273 static int remote_break;
275 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
276 remote_open knows that we don't have a file open when the program
278 static serial_t remote_desc = NULL;
280 /* This is set by the target (thru the 'S' message)
281 to denote that the target is in kernel mode. */
282 static int cisco_kernel_mode = 0;
284 /* Maximum number of bytes to read/write at once. The value here
285 is chosen to fill up a packet (the headers account for the 32). */
286 #define MAXBUFBYTES(N) (((N)-32)/2)
288 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
289 and i386-stub.c. Normally, no one would notice because it only matters
290 for writing large chunks of memory (e.g. in downloads). Also, this needs
291 to be more than 400 if required to hold the registers (see below, where
292 we round it up based on REGISTER_BYTES). */
293 /* Round up PBUFSIZ to hold all the registers, at least. */
294 #define PBUFSIZ ((REGISTER_BYTES > MAXBUFBYTES (400)) \
295 ? (REGISTER_BYTES * 2 + 32) \
299 /* This variable sets the number of bytes to be written to the target
300 in a single packet. Normally PBUFSIZ is satisfactory, but some
301 targets need smaller values (perhaps because the receiving end
304 static int remote_write_size;
306 /* This variable sets the number of bits in an address that are to be
307 sent in a memory ("M" or "m") packet. Normally, after stripping
308 leading zeros, the entire address would be sent. This variable
309 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
310 initial implementation of remote.c restricted the address sent in
311 memory packets to ``host::sizeof long'' bytes - (typically 32
312 bits). Consequently, for 64 bit targets, the upper 32 bits of an
313 address was never sent. Since fixing this bug may cause a break in
314 some remote targets this variable is principly provided to
315 facilitate backward compatibility. */
317 static int remote_address_size;
319 /* This is the size (in chars) of the first response to the `g' command. This
320 is used to limit the size of the memory read and write commands to prevent
321 stub buffers from overflowing. The size does not include headers and
322 trailers, it is only the payload size. */
324 static int remote_register_buf_size = 0;
326 /* Tempoary to track who currently owns the terminal. See
327 target_async_terminal_* for more details. */
329 static int remote_async_terminal_ours_p;
331 /* Generic configuration support for packets the stub optionally
332 supports. Allows the user to specify the use of the packet as well
333 as allowing GDB to auto-detect support in the remote stub. */
337 PACKET_SUPPORT_UNKNOWN = 0,
344 PACKET_AUTO_DETECT = 0,
353 enum packet_detect detect;
354 enum packet_support support;
357 static char packet_support_auto[] = "auto";
358 static char packet_enable[] = "enable";
359 static char packet_disable[] = "disable";
360 static char *packet_support_enums[] =
369 set_packet_config_cmd (config, c)
370 struct packet_config *config;
371 struct cmd_list_element *c;
373 if (config->state == packet_enable)
375 config->detect = PACKET_MANUAL_DETECT;
376 config->support = PACKET_ENABLE;
378 else if (config->state == packet_disable)
380 config->detect = PACKET_MANUAL_DETECT;
381 config->support = PACKET_DISABLE;
383 else if (config->state == packet_support_auto)
385 config->detect = PACKET_AUTO_DETECT;
386 config->support = PACKET_SUPPORT_UNKNOWN;
389 internal_error ("Bad enum value");
393 show_packet_config_cmd (config)
394 struct packet_config *config;
396 char *support = "internal-error";
397 switch (config->support)
403 support = "disabled";
405 case PACKET_SUPPORT_UNKNOWN:
409 switch (config->detect)
411 case PACKET_AUTO_DETECT:
412 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
413 config->name, config->title, support);
415 case PACKET_MANUAL_DETECT:
416 printf_filtered ("Support for remote protocol `%s' (%s) is currently %s.\n",
417 config->name, config->title, support);
422 add_packet_config_cmd (config, name, title, set_func, show_func,
424 struct packet_config *config;
427 void (*set_func) PARAMS ((char *args, int from_tty,
428 struct cmd_list_element * c));
429 void (*show_func) PARAMS ((char *name, int from_tty));
430 struct cmd_list_element **setlist;
431 struct cmd_list_element **showlist;
433 struct cmd_list_element *c;
438 config->title = title;
439 asprintf (&set_doc, "Set use of remote protocol `%s' (%s) packet",
441 asprintf (&show_doc, "Show current use of remote protocol `%s' (%s) packet",
443 asprintf (&full_name, "%s-packet", name);
444 c = add_set_enum_cmd (full_name,
445 class_obscure, packet_support_enums,
446 (char *) &config->state,
448 c->function.sfunc = set_func;
449 add_cmd (full_name, class_obscure, show_func, show_doc, showlist);
453 init_packet_config (config)
454 struct packet_config *config;
456 switch (config->detect)
458 case PACKET_AUTO_DETECT:
459 config->support = PACKET_SUPPORT_UNKNOWN;
461 case PACKET_MANUAL_DETECT:
462 /* let the user beware */
467 /* Should we try the 'P' (set register) request? */
469 static struct packet_config remote_protocol_P;
472 set_remote_protocol_P_packet_cmd (args, from_tty, c)
475 struct cmd_list_element *c;
477 set_packet_config_cmd (&remote_protocol_P, c);
481 show_remote_protocol_P_packet_cmd (args, from_tty)
485 show_packet_config_cmd (&remote_protocol_P);
488 /* Should we try the 'Z' (set breakpoint) request? */
490 static struct packet_config remote_protocol_Z;
493 set_remote_protocol_Z_packet_cmd (args, from_tty, c)
496 struct cmd_list_element *c;
498 set_packet_config_cmd (&remote_protocol_Z, c);
502 show_remote_protocol_Z_packet_cmd (args, from_tty)
506 show_packet_config_cmd (&remote_protocol_Z);
509 /* Should we try the 'X' (remote binary download) packet?
511 This variable (available to the user via "set remote X-packet")
512 dictates whether downloads are sent in binary (via the 'X' packet).
513 We assume that the stub can, and attempt to do it. This will be
514 cleared if the stub does not understand it. This switch is still
515 needed, though in cases when the packet is supported in the stub,
516 but the connection does not allow it (i.e., 7-bit serial connection
519 static struct packet_config remote_protocol_binary_download;
522 set_remote_protocol_binary_download_cmd (char *args,
524 struct cmd_list_element *c)
526 set_packet_config_cmd (&remote_protocol_binary_download, c);
530 show_remote_protocol_binary_download_cmd (char *args,
533 show_packet_config_cmd (&remote_protocol_binary_download);
537 /* Tokens for use by the asynchronous signal handlers for SIGINT */
538 PTR sigint_remote_twice_token;
539 PTR sigint_remote_token;
541 /* These are pointers to hook functions that may be set in order to
542 modify resume/wait behavior for a particular architecture. */
544 void (*target_resume_hook) PARAMS ((void));
545 void (*target_wait_loop_hook) PARAMS ((void));
549 /* These are the threads which we last sent to the remote system.
550 -1 for all or -2 for not sent yet. */
551 static int general_thread;
552 static int continue_thread;
554 /* Call this function as a result of
555 1) A halt indication (T packet) containing a thread id
556 2) A direct query of currthread
557 3) Successful execution of set thread
561 record_currthread (currthread)
564 general_thread = currthread;
566 /* If this is a new thread, add it to GDB's thread list.
567 If we leave it up to WFI to do this, bad things will happen. */
568 if (!in_thread_list (currthread))
570 add_thread (currthread);
571 printf_filtered ("[New %s]\n", target_pid_to_str (currthread));
575 #define MAGIC_NULL_PID 42000
582 char *buf = alloca (PBUFSIZ);
583 int state = gen ? general_thread : continue_thread;
589 buf[1] = gen ? 'g' : 'c';
590 if (th == MAGIC_NULL_PID)
596 sprintf (&buf[2], "-%x", -th);
598 sprintf (&buf[2], "%x", th);
604 continue_thread = th;
607 /* Return nonzero if the thread TH is still alive on the remote system. */
610 remote_thread_alive (tid)
616 sprintf (buf, "T-%08x", -tid);
618 sprintf (buf, "T%08x", tid);
621 return (buf[0] == 'O' && buf[1] == 'K');
624 /* About these extended threadlist and threadinfo packets. They are
625 variable length packets but, the fields within them are often fixed
626 length. They are redundent enough to send over UDP as is the
627 remote protocol in general. There is a matching unit test module
630 #define OPAQUETHREADBYTES 8
632 /* a 64 bit opaque identifier */
633 typedef unsigned char threadref[OPAQUETHREADBYTES];
635 /* WARNING: This threadref data structure comes from the remote O.S., libstub
636 protocol encoding, and remote.c. it is not particularly changable */
638 /* Right now, the internal structure is int. We want it to be bigger.
642 typedef int gdb_threadref; /* internal GDB thread reference */
644 /* gdb_ext_thread_info is an internal GDB data structure which is
645 equivalint to the reply of the remote threadinfo packet */
647 struct gdb_ext_thread_info
649 threadref threadid; /* External form of thread reference */
650 int active; /* Has state interesting to GDB? , regs, stack */
651 char display[256]; /* Brief state display, name, blocked/syspended */
652 char shortname[32]; /* To be used to name threads */
653 char more_display[256]; /* Long info, statistics, queue depth, whatever */
656 /* The volume of remote transfers can be limited by submitting
657 a mask containing bits specifying the desired information.
658 Use a union of these values as the 'selection' parameter to
659 get_thread_info. FIXME: Make these TAG names more thread specific.
662 #define TAG_THREADID 1
664 #define TAG_DISPLAY 4
665 #define TAG_THREADNAME 8
666 #define TAG_MOREDISPLAY 16
668 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
670 char *unpack_varlen_hex PARAMS ((char *buff, int *result));
672 static char *unpack_nibble PARAMS ((char *buf, int *val));
674 static char *pack_nibble PARAMS ((char *buf, int nibble));
676 static char *pack_hex_byte PARAMS ((char *pkt, int /*unsigned char */ byte));
678 static char *unpack_byte PARAMS ((char *buf, int *value));
680 static char *pack_int PARAMS ((char *buf, int value));
682 static char *unpack_int PARAMS ((char *buf, int *value));
684 static char *unpack_string PARAMS ((char *src, char *dest, int length));
686 static char *pack_threadid PARAMS ((char *pkt, threadref * id));
688 static char *unpack_threadid PARAMS ((char *inbuf, threadref * id));
690 void int_to_threadref PARAMS ((threadref * id, int value));
692 static int threadref_to_int PARAMS ((threadref * ref));
694 static void copy_threadref PARAMS ((threadref * dest, threadref * src));
696 static int threadmatch PARAMS ((threadref * dest, threadref * src));
698 static char *pack_threadinfo_request PARAMS ((char *pkt, int mode,
701 static int remote_unpack_thread_info_response PARAMS ((char *pkt,
702 threadref * expectedref,
703 struct gdb_ext_thread_info * info));
706 static int remote_get_threadinfo PARAMS ((threadref * threadid,
707 int fieldset, /*TAG mask */
708 struct gdb_ext_thread_info * info));
710 static int adapt_remote_get_threadinfo PARAMS ((gdb_threadref * ref,
712 struct gdb_ext_thread_info * info));
714 static char *pack_threadlist_request PARAMS ((char *pkt, int startflag,
716 threadref * nextthread));
718 static int parse_threadlist_response PARAMS ((char *pkt,
720 threadref * original_echo,
721 threadref * resultlist,
724 static int remote_get_threadlist PARAMS ((int startflag,
725 threadref * nextthread,
729 threadref * threadlist));
731 typedef int (*rmt_thread_action) (threadref * ref, void *context);
733 static int remote_threadlist_iterator PARAMS ((rmt_thread_action stepfunction,
734 void *context, int looplimit));
736 static int remote_newthread_step PARAMS ((threadref * ref, void *context));
738 /* encode 64 bits in 16 chars of hex */
740 static const char hexchars[] = "0123456789abcdef";
747 if ((ch >= 'a') && (ch <= 'f'))
749 *val = ch - 'a' + 10;
752 if ((ch >= 'A') && (ch <= 'F'))
754 *val = ch - 'A' + 10;
757 if ((ch >= '0') && (ch <= '9'))
769 if (ch >= 'a' && ch <= 'f')
770 return ch - 'a' + 10;
771 if (ch >= '0' && ch <= '9')
773 if (ch >= 'A' && ch <= 'F')
774 return ch - 'A' + 10;
779 stub_unpack_int (buff, fieldlength)
788 nibble = stubhex (*buff++);
792 retval = retval << 4;
798 unpack_varlen_hex (buff, result)
799 char *buff; /* packet to parse */
805 while (ishex (*buff, &nibble))
808 retval = retval << 4;
809 retval |= nibble & 0x0f;
816 unpack_nibble (buf, val)
825 pack_nibble (buf, nibble)
829 *buf++ = hexchars[(nibble & 0x0f)];
834 pack_hex_byte (pkt, byte)
838 *pkt++ = hexchars[(byte >> 4) & 0xf];
839 *pkt++ = hexchars[(byte & 0xf)];
844 unpack_byte (buf, value)
848 *value = stub_unpack_int (buf, 2);
853 pack_int (buf, value)
857 buf = pack_hex_byte (buf, (value >> 24) & 0xff);
858 buf = pack_hex_byte (buf, (value >> 16) & 0xff);
859 buf = pack_hex_byte (buf, (value >> 8) & 0x0ff);
860 buf = pack_hex_byte (buf, (value & 0xff));
865 unpack_int (buf, value)
869 *value = stub_unpack_int (buf, 8);
873 #if 0 /* currently unused, uncomment when needed */
874 static char *pack_string PARAMS ((char *pkt, char *string));
877 pack_string (pkt, string)
884 len = strlen (string);
886 len = 200; /* Bigger than most GDB packets, junk??? */
887 pkt = pack_hex_byte (pkt, len);
891 if ((ch == '\0') || (ch == '#'))
892 ch = '*'; /* Protect encapsulation */
897 #endif /* 0 (unused) */
900 unpack_string (src, dest, length)
912 pack_threadid (pkt, id)
917 unsigned char *altid;
919 altid = (unsigned char *) id;
920 limit = pkt + BUF_THREAD_ID_SIZE;
922 pkt = pack_hex_byte (pkt, *altid++);
928 unpack_threadid (inbuf, id)
933 char *limit = inbuf + BUF_THREAD_ID_SIZE;
936 altref = (char *) id;
938 while (inbuf < limit)
940 x = stubhex (*inbuf++);
941 y = stubhex (*inbuf++);
942 *altref++ = (x << 4) | y;
947 /* Externally, threadrefs are 64 bits but internally, they are still
948 ints. This is due to a mismatch of specifications. We would like
949 to use 64bit thread references internally. This is an adapter
953 int_to_threadref (id, value)
959 scan = (unsigned char *) id;
965 *scan++ = (value >> 24) & 0xff;
966 *scan++ = (value >> 16) & 0xff;
967 *scan++ = (value >> 8) & 0xff;
968 *scan++ = (value & 0xff);
972 threadref_to_int (ref)
982 value = (value << 8) | ((*scan++) & 0xff);
987 copy_threadref (dest, src)
992 unsigned char *csrc, *cdest;
994 csrc = (unsigned char *) src;
995 cdest = (unsigned char *) dest;
1002 threadmatch (dest, src)
1006 /* things are broken right now, so just assume we got a match */
1008 unsigned char *srcp, *destp;
1010 srcp = (char *) src;
1011 destp = (char *) dest;
1015 result &= (*srcp++ == *destp++) ? 1 : 0;
1022 threadid:1, # always request threadid
1029 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1032 pack_threadinfo_request (pkt, mode, id)
1037 *pkt++ = 'q'; /* Info Query */
1038 *pkt++ = 'P'; /* process or thread info */
1039 pkt = pack_int (pkt, mode); /* mode */
1040 pkt = pack_threadid (pkt, id); /* threadid */
1041 *pkt = '\0'; /* terminate */
1045 /* These values tag the fields in a thread info response packet */
1046 /* Tagging the fields allows us to request specific fields and to
1047 add more fields as time goes by */
1049 #define TAG_THREADID 1 /* Echo the thread identifier */
1050 #define TAG_EXISTS 2 /* Is this process defined enough to
1051 fetch registers and its stack */
1052 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1053 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1054 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1058 remote_unpack_thread_info_response (pkt, expectedref, info)
1060 threadref *expectedref;
1061 struct gdb_ext_thread_info *info;
1066 char *limit = pkt + PBUFSIZ; /* plausable parsing limit */
1069 /* info->threadid = 0; FIXME: implement zero_threadref */
1071 info->display[0] = '\0';
1072 info->shortname[0] = '\0';
1073 info->more_display[0] = '\0';
1075 /* Assume the characters indicating the packet type have been stripped */
1076 pkt = unpack_int (pkt, &mask); /* arg mask */
1077 pkt = unpack_threadid (pkt, &ref);
1080 warning ("Incomplete response to threadinfo request\n");
1081 if (!threadmatch (&ref, expectedref))
1082 { /* This is an answer to a different request */
1083 warning ("ERROR RMT Thread info mismatch\n");
1086 copy_threadref (&info->threadid, &ref);
1088 /* Loop on tagged fields , try to bail if somthing goes wrong */
1090 while ((pkt < limit) && mask && *pkt) /* packets are terminated with nulls */
1092 pkt = unpack_int (pkt, &tag); /* tag */
1093 pkt = unpack_byte (pkt, &length); /* length */
1094 if (!(tag & mask)) /* tags out of synch with mask */
1096 warning ("ERROR RMT: threadinfo tag mismatch\n");
1100 if (tag == TAG_THREADID)
1104 warning ("ERROR RMT: length of threadid is not 16\n");
1108 pkt = unpack_threadid (pkt, &ref);
1109 mask = mask & ~TAG_THREADID;
1112 if (tag == TAG_EXISTS)
1114 info->active = stub_unpack_int (pkt, length);
1116 mask = mask & ~(TAG_EXISTS);
1119 warning ("ERROR RMT: 'exists' length too long\n");
1125 if (tag == TAG_THREADNAME)
1127 pkt = unpack_string (pkt, &info->shortname[0], length);
1128 mask = mask & ~TAG_THREADNAME;
1131 if (tag == TAG_DISPLAY)
1133 pkt = unpack_string (pkt, &info->display[0], length);
1134 mask = mask & ~TAG_DISPLAY;
1137 if (tag == TAG_MOREDISPLAY)
1139 pkt = unpack_string (pkt, &info->more_display[0], length);
1140 mask = mask & ~TAG_MOREDISPLAY;
1143 warning ("ERROR RMT: unknown thread info tag\n");
1144 break; /* Not a tag we know about */
1150 remote_get_threadinfo (threadid, fieldset, info)
1151 threadref *threadid;
1152 int fieldset; /* TAG mask */
1153 struct gdb_ext_thread_info *info;
1156 char *threadinfo_pkt = alloca (PBUFSIZ);
1158 pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
1159 putpkt (threadinfo_pkt);
1160 getpkt (threadinfo_pkt, 0);
1161 result = remote_unpack_thread_info_response (threadinfo_pkt + 2, threadid,
1166 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1167 representation of a threadid. */
1170 adapt_remote_get_threadinfo (ref, selection, info)
1173 struct gdb_ext_thread_info *info;
1177 int_to_threadref (&lclref, *ref);
1178 return remote_get_threadinfo (&lclref, selection, info);
1181 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1184 pack_threadlist_request (pkt, startflag, threadcount, nextthread)
1188 threadref *nextthread;
1190 *pkt++ = 'q'; /* info query packet */
1191 *pkt++ = 'L'; /* Process LIST or threadLIST request */
1192 pkt = pack_nibble (pkt, startflag); /* initflag 1 bytes */
1193 pkt = pack_hex_byte (pkt, threadcount); /* threadcount 2 bytes */
1194 pkt = pack_threadid (pkt, nextthread); /* 64 bit thread identifier */
1199 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1202 parse_threadlist_response (pkt, result_limit, original_echo, resultlist,
1206 threadref *original_echo;
1207 threadref *resultlist;
1211 int count, resultcount, done;
1214 /* Assume the 'q' and 'M chars have been stripped. */
1215 limit = pkt + (PBUFSIZ - BUF_THREAD_ID_SIZE); /* done parse past here */
1216 pkt = unpack_byte (pkt, &count); /* count field */
1217 pkt = unpack_nibble (pkt, &done);
1218 /* The first threadid is the argument threadid. */
1219 pkt = unpack_threadid (pkt, original_echo); /* should match query packet */
1220 while ((count-- > 0) && (pkt < limit))
1222 pkt = unpack_threadid (pkt, resultlist++);
1223 if (resultcount++ >= result_limit)
1232 remote_get_threadlist (startflag, nextthread, result_limit,
1233 done, result_count, threadlist)
1235 threadref *nextthread;
1239 threadref *threadlist;
1242 static threadref echo_nextthread;
1243 char *threadlist_packet = alloca (PBUFSIZ);
1244 char *t_response = alloca (PBUFSIZ);
1247 /* Trancate result limit to be smaller than the packet size */
1248 if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10) >= PBUFSIZ)
1249 result_limit = (PBUFSIZ / BUF_THREAD_ID_SIZE) - 2;
1251 pack_threadlist_request (threadlist_packet,
1252 startflag, result_limit, nextthread);
1253 putpkt (threadlist_packet);
1254 getpkt (t_response, 0);
1257 parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
1260 if (!threadmatch (&echo_nextthread, nextthread))
1262 /* FIXME: This is a good reason to drop the packet */
1263 /* Possably, there is a duplicate response */
1265 retransmit immediatly - race conditions
1266 retransmit after timeout - yes
1268 wait for packet, then exit
1270 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1271 return 0; /* I choose simply exiting */
1273 if (*result_count <= 0)
1277 warning ("RMT ERROR : failed to get remote thread list\n");
1280 return result; /* break; */
1282 if (*result_count > result_limit)
1285 warning ("RMT ERROR: threadlist response longer than requested\n");
1291 /* This is the interface between remote and threads, remotes upper interface */
1293 /* remote_find_new_threads retrieves the thread list and for each
1294 thread in the list, looks up the thread in GDB's internal list,
1295 ading the thread if it does not already exist. This involves
1296 getting partial thread lists from the remote target so, polling the
1297 quit_flag is required. */
1300 /* About this many threadisds fit in a packet. */
1302 #define MAXTHREADLISTRESULTS 32
1305 remote_threadlist_iterator (stepfunction, context, looplimit)
1306 rmt_thread_action stepfunction;
1310 int done, i, result_count;
1314 static threadref nextthread;
1315 static threadref resultthreadlist[MAXTHREADLISTRESULTS];
1320 if (loopcount++ > looplimit)
1323 warning ("Remote fetch threadlist -infinite loop-\n");
1326 if (!remote_get_threadlist (startflag, &nextthread, MAXTHREADLISTRESULTS,
1327 &done, &result_count, resultthreadlist))
1332 /* clear for later iterations */
1334 /* Setup to resume next batch of thread references, set nextthread. */
1335 if (result_count >= 1)
1336 copy_threadref (&nextthread, &resultthreadlist[result_count - 1]);
1338 while (result_count--)
1339 if (!(result = (*stepfunction) (&resultthreadlist[i++], context)))
1346 remote_newthread_step (ref, context)
1352 pid = threadref_to_int (ref);
1353 if (!in_thread_list (pid))
1355 return 1; /* continue iterator */
1358 #define CRAZY_MAX_THREADS 1000
1361 remote_current_thread (oldpid)
1364 char *buf = alloca (PBUFSIZ);
1368 if (buf[0] == 'Q' && buf[1] == 'C')
1369 return strtol (&buf[2], NULL, 16);
1374 /* Find new threads for info threads command. */
1377 remote_find_new_threads ()
1379 remote_threadlist_iterator (remote_newthread_step, 0,
1381 if (inferior_pid == MAGIC_NULL_PID) /* ack ack ack */
1382 inferior_pid = remote_current_thread (inferior_pid);
1386 remote_threads_info (void)
1388 char *buf = alloca (PBUFSIZ);
1392 if (remote_desc == 0) /* paranoia */
1393 error ("Command can only be used when connected to the remote target.");
1395 putpkt ("qfThreadInfo");
1396 getpkt (bufp = buf, 0);
1397 if (bufp[0] == '\0') /* q packet not recognized! */
1398 { /* try old jmetzler method */
1399 remote_find_new_threads ();
1402 else /* try new 'q' method */
1403 while (*bufp++ == 'm') /* reply contains one or more TID */
1407 tid = strtol (bufp, &bufp, 16);
1408 if (tid != 0 && !in_thread_list (tid))
1411 while (*bufp++ == ','); /* comma-separated list */
1412 putpkt ("qsThreadInfo");
1413 getpkt (bufp = buf, 0);
1418 /* Restart the remote side; this is an extended protocol operation. */
1421 extended_remote_restart ()
1423 char *buf = alloca (PBUFSIZ);
1425 /* Send the restart command; for reasons I don't understand the
1426 remote side really expects a number after the "R". */
1428 sprintf (&buf[1], "%x", 0);
1431 /* Now query for status so this looks just like we restarted
1432 gdbserver from scratch. */
1437 /* Clean up connection to a remote debugger. */
1441 remote_close (quitting)
1445 SERIAL_CLOSE (remote_desc);
1449 /* Query the remote side for the text, data and bss offsets. */
1454 char *buf = alloca (PBUFSIZ);
1457 CORE_ADDR text_addr, data_addr, bss_addr;
1458 struct section_offsets *offs;
1460 putpkt ("qOffsets");
1464 if (buf[0] == '\000')
1465 return; /* Return silently. Stub doesn't support
1469 warning ("Remote failure reply: %s", buf);
1473 /* Pick up each field in turn. This used to be done with scanf, but
1474 scanf will make trouble if CORE_ADDR size doesn't match
1475 conversion directives correctly. The following code will work
1476 with any size of CORE_ADDR. */
1477 text_addr = data_addr = bss_addr = 0;
1481 if (strncmp (ptr, "Text=", 5) == 0)
1484 /* Don't use strtol, could lose on big values. */
1485 while (*ptr && *ptr != ';')
1486 text_addr = (text_addr << 4) + fromhex (*ptr++);
1491 if (!lose && strncmp (ptr, ";Data=", 6) == 0)
1494 while (*ptr && *ptr != ';')
1495 data_addr = (data_addr << 4) + fromhex (*ptr++);
1500 if (!lose && strncmp (ptr, ";Bss=", 5) == 0)
1503 while (*ptr && *ptr != ';')
1504 bss_addr = (bss_addr << 4) + fromhex (*ptr++);
1510 error ("Malformed response to offset query, %s", buf);
1512 if (symfile_objfile == NULL)
1515 offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
1516 memcpy (offs, symfile_objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
1518 ANOFFSET (offs, SECT_OFF_TEXT) = text_addr;
1520 /* This is a temporary kludge to force data and bss to use the same offsets
1521 because that's what nlmconv does now. The real solution requires changes
1522 to the stub and remote.c that I don't have time to do right now. */
1524 ANOFFSET (offs, SECT_OFF_DATA) = data_addr;
1525 ANOFFSET (offs, SECT_OFF_BSS) = data_addr;
1527 objfile_relocate (symfile_objfile, offs);
1531 * Cisco version of section offsets:
1533 * Instead of having GDB query the target for the section offsets,
1534 * Cisco lets the target volunteer the information! It's also in
1535 * a different format, so here are the functions that will decode
1536 * a section offset packet from a Cisco target.
1540 * Function: remote_cisco_section_offsets
1542 * Returns: zero for success, non-zero for failure
1546 remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
1547 text_offs, data_offs, bss_offs)
1551 bfd_signed_vma *text_offs;
1552 bfd_signed_vma *data_offs;
1553 bfd_signed_vma *bss_offs;
1555 bfd_vma text_base, data_base, bss_base;
1556 struct minimal_symbol *start;
1562 if (symfile_objfile == NULL)
1563 return -1; /* no can do nothin' */
1565 start = lookup_minimal_symbol ("_start", NULL, NULL);
1567 return -1; /* Can't find "_start" symbol */
1569 data_base = bss_base = 0;
1570 text_base = SYMBOL_VALUE_ADDRESS (start);
1572 abfd = symfile_objfile->obfd;
1573 for (sect = abfd->sections;
1577 p = (unsigned char *) bfd_get_section_name (abfd, sect);
1579 if (strcmp (p + len - 4, "data") == 0) /* ends in "data" */
1580 if (data_base == 0 ||
1581 data_base > bfd_get_section_vma (abfd, sect))
1582 data_base = bfd_get_section_vma (abfd, sect);
1583 if (strcmp (p + len - 3, "bss") == 0) /* ends in "bss" */
1584 if (bss_base == 0 ||
1585 bss_base > bfd_get_section_vma (abfd, sect))
1586 bss_base = bfd_get_section_vma (abfd, sect);
1588 *text_offs = text_addr - text_base;
1589 *data_offs = data_addr - data_base;
1590 *bss_offs = bss_addr - bss_base;
1595 sprintf (tmp, "VMA: text = 0x");
1596 sprintf_vma (tmp + strlen (tmp), text_addr);
1597 sprintf (tmp + strlen (tmp), " data = 0x");
1598 sprintf_vma (tmp + strlen (tmp), data_addr);
1599 sprintf (tmp + strlen (tmp), " bss = 0x");
1600 sprintf_vma (tmp + strlen (tmp), bss_addr);
1601 fprintf_filtered (gdb_stdlog, tmp);
1602 fprintf_filtered (gdb_stdlog,
1603 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
1604 paddr_nz (*text_offs),
1605 paddr_nz (*data_offs),
1606 paddr_nz (*bss_offs));
1613 * Function: remote_cisco_objfile_relocate
1615 * Relocate the symbol file for a remote target.
1619 remote_cisco_objfile_relocate (text_off, data_off, bss_off)
1620 bfd_signed_vma text_off;
1621 bfd_signed_vma data_off;
1622 bfd_signed_vma bss_off;
1624 struct section_offsets *offs;
1626 if (text_off != 0 || data_off != 0 || bss_off != 0)
1628 /* FIXME: This code assumes gdb-stabs.h is being used; it's
1629 broken for xcoff, dwarf, sdb-coff, etc. But there is no
1630 simple canonical representation for this stuff. */
1632 offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
1633 memcpy (offs, symfile_objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
1635 ANOFFSET (offs, SECT_OFF_TEXT) = text_off;
1636 ANOFFSET (offs, SECT_OFF_DATA) = data_off;
1637 ANOFFSET (offs, SECT_OFF_BSS) = bss_off;
1639 /* First call the standard objfile_relocate. */
1640 objfile_relocate (symfile_objfile, offs);
1642 /* Now we need to fix up the section entries already attached to
1643 the exec target. These entries will control memory transfers
1644 from the exec file. */
1646 exec_set_section_offsets (text_off, data_off, bss_off);
1650 /* Stub for catch_errors. */
1653 remote_start_remote_dummy (dummy)
1656 start_remote (); /* Initialize gdb process mechanisms */
1661 remote_start_remote (dummy)
1664 immediate_quit = 1; /* Allow user to interrupt it */
1666 /* Ack any packet which the remote side has already sent. */
1667 SERIAL_WRITE (remote_desc, "+", 1);
1669 /* Let the stub know that we want it to return the thread. */
1672 inferior_pid = remote_current_thread (inferior_pid);
1674 get_offsets (); /* Get text, data & bss offsets */
1676 putpkt ("?"); /* initiate a query from remote machine */
1679 return remote_start_remote_dummy (dummy);
1682 /* Open a connection to a remote debugger.
1683 NAME is the filename used for communication. */
1686 remote_open (name, from_tty)
1690 remote_open_1 (name, from_tty, &remote_ops, 0);
1693 /* Just like remote_open, but with asynchronous support. */
1695 remote_async_open (name, from_tty)
1699 remote_async_open_1 (name, from_tty, &remote_async_ops, 0);
1702 /* Open a connection to a remote debugger using the extended
1703 remote gdb protocol. NAME is the filename used for communication. */
1706 extended_remote_open (name, from_tty)
1710 remote_open_1 (name, from_tty, &extended_remote_ops, 1 /*extended_p */ );
1713 /* Just like extended_remote_open, but with asynchronous support. */
1715 extended_remote_async_open (name, from_tty)
1719 remote_async_open_1 (name, from_tty, &extended_async_remote_ops, 1 /*extended_p */ );
1722 /* Generic code for opening a connection to a remote target. */
1724 static DCACHE *remote_dcache;
1727 remote_open_1 (name, from_tty, target, extended_p)
1730 struct target_ops *target;
1734 error ("To open a remote debug connection, you need to specify what\n\
1735 serial device is attached to the remote system (e.g. /dev/ttya).");
1737 /* See FIXME above */
1738 wait_forever_enabled_p = 1;
1740 target_preopen (from_tty);
1742 unpush_target (target);
1744 remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
1746 remote_desc = SERIAL_OPEN (name);
1748 perror_with_name (name);
1750 if (baud_rate != -1)
1752 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
1754 SERIAL_CLOSE (remote_desc);
1755 perror_with_name (name);
1759 SERIAL_RAW (remote_desc);
1761 /* If there is something sitting in the buffer we might take it as a
1762 response to a command, which would be bad. */
1763 SERIAL_FLUSH_INPUT (remote_desc);
1767 puts_filtered ("Remote debugging using ");
1768 puts_filtered (name);
1769 puts_filtered ("\n");
1771 push_target (target); /* Switch to using remote target now */
1773 init_packet_config (&remote_protocol_P);
1774 init_packet_config (&remote_protocol_Z);
1776 general_thread = -2;
1777 continue_thread = -2;
1779 /* Force remote_write_bytes to check whether target supports
1780 binary downloading. */
1781 init_packet_config (&remote_protocol_binary_download);
1783 /* Without this, some commands which require an active target (such
1784 as kill) won't work. This variable serves (at least) double duty
1785 as both the pid of the target process (if it has such), and as a
1786 flag indicating that a target is active. These functions should
1787 be split out into seperate variables, especially since GDB will
1788 someday have a notion of debugging several processes. */
1790 inferior_pid = MAGIC_NULL_PID;
1791 /* Start the remote connection; if error (0), discard this target.
1792 In particular, if the user quits, be sure to discard it
1793 (we'd be in an inconsistent state otherwise). */
1794 if (!catch_errors (remote_start_remote, NULL,
1795 "Couldn't establish connection to remote target\n",
1804 /* tell the remote that we're using the extended protocol. */
1805 char *buf = alloca (PBUFSIZ);
1811 /* Just like remote_open but with asynchronous support. */
1813 remote_async_open_1 (name, from_tty, target, extended_p)
1816 struct target_ops *target;
1820 error ("To open a remote debug connection, you need to specify what\n\
1821 serial device is attached to the remote system (e.g. /dev/ttya).");
1823 target_preopen (from_tty);
1825 unpush_target (target);
1827 remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
1829 remote_desc = SERIAL_OPEN (name);
1831 perror_with_name (name);
1833 if (baud_rate != -1)
1835 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
1837 SERIAL_CLOSE (remote_desc);
1838 perror_with_name (name);
1842 SERIAL_RAW (remote_desc);
1844 /* If there is something sitting in the buffer we might take it as a
1845 response to a command, which would be bad. */
1846 SERIAL_FLUSH_INPUT (remote_desc);
1850 puts_filtered ("Remote debugging using ");
1851 puts_filtered (name);
1852 puts_filtered ("\n");
1855 push_target (target); /* Switch to using remote target now */
1857 init_packet_config (&remote_protocol_P);
1858 init_packet_config (&remote_protocol_Z);
1860 general_thread = -2;
1861 continue_thread = -2;
1863 /* Force remote_write_bytes to check whether target supports
1864 binary downloading. */
1865 init_packet_config (&remote_protocol_binary_download);
1867 /* Without this, some commands which require an active target (such
1868 as kill) won't work. This variable serves (at least) double duty
1869 as both the pid of the target process (if it has such), and as a
1870 flag indicating that a target is active. These functions should
1871 be split out into seperate variables, especially since GDB will
1872 someday have a notion of debugging several processes. */
1873 inferior_pid = MAGIC_NULL_PID;
1875 /* With this target we start out by owning the terminal. */
1876 remote_async_terminal_ours_p = 1;
1878 /* FIXME: cagney/1999-09-23: During the initial connection it is
1879 assumed that the target is already ready and able to respond to
1880 requests. Unfortunatly remote_start_remote() eventually calls
1881 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
1882 around this. Eventually a mechanism that allows
1883 wait_for_inferior() to expect/get timeouts will be
1885 wait_forever_enabled_p = 0;
1887 /* Start the remote connection; if error (0), discard this target.
1888 In particular, if the user quits, be sure to discard it
1889 (we'd be in an inconsistent state otherwise). */
1890 if (!catch_errors (remote_start_remote, NULL,
1891 "Couldn't establish connection to remote target\n",
1895 wait_forever_enabled_p = 1;
1899 wait_forever_enabled_p = 1;
1903 /* tell the remote that we're using the extended protocol. */
1904 char *buf = alloca (PBUFSIZ);
1910 /* This takes a program previously attached to and detaches it. After
1911 this is done, GDB can be used to debug some other program. We
1912 better not have left any breakpoints in the target program or it'll
1913 die when it hits one. */
1916 remote_detach (args, from_tty)
1920 char *buf = alloca (PBUFSIZ);
1923 error ("Argument given to \"detach\" when remotely debugging.");
1925 /* Tell the remote target to detach. */
1931 puts_filtered ("Ending remote debugging.\n");
1935 /* Same as remote_detach, but with async support. */
1937 remote_async_detach (args, from_tty)
1941 char *buf = alloca (PBUFSIZ);
1944 error ("Argument given to \"detach\" when remotely debugging.");
1946 /* Tell the remote target to detach. */
1950 /* Unregister the file descriptor from the event loop. */
1951 if (SERIAL_IS_ASYNC_P (remote_desc))
1952 SERIAL_ASYNC (remote_desc, NULL, 0);
1956 puts_filtered ("Ending remote debugging.\n");
1959 /* Convert hex digit A to a number. */
1965 if (a >= '0' && a <= '9')
1967 else if (a >= 'a' && a <= 'f')
1968 return a - 'a' + 10;
1969 else if (a >= 'A' && a <= 'F')
1970 return a - 'A' + 10;
1972 error ("Reply contains invalid hex digit %d", a);
1975 /* Convert number NIB to a hex digit. */
1984 return 'a' + nib - 10;
1987 /* Tell the remote machine to resume. */
1989 static enum target_signal last_sent_signal = TARGET_SIGNAL_0;
1991 static int last_sent_step;
1994 remote_resume (pid, step, siggnal)
1996 enum target_signal siggnal;
1998 char *buf = alloca (PBUFSIZ);
2001 set_thread (0, 0); /* run any thread */
2003 set_thread (pid, 0); /* run this thread */
2005 dcache_flush (remote_dcache);
2007 last_sent_signal = siggnal;
2008 last_sent_step = step;
2010 /* A hook for when we need to do something at the last moment before
2012 if (target_resume_hook)
2013 (*target_resume_hook) ();
2015 if (siggnal != TARGET_SIGNAL_0)
2017 buf[0] = step ? 'S' : 'C';
2018 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
2019 buf[2] = tohex ((int) siggnal & 0xf);
2023 strcpy (buf, step ? "s" : "c");
2028 /* Same as remote_resume, but with async support. */
2030 remote_async_resume (pid, step, siggnal)
2032 enum target_signal siggnal;
2034 char *buf = alloca (PBUFSIZ);
2037 set_thread (0, 0); /* run any thread */
2039 set_thread (pid, 0); /* run this thread */
2041 dcache_flush (remote_dcache);
2043 last_sent_signal = siggnal;
2044 last_sent_step = step;
2046 /* A hook for when we need to do something at the last moment before
2048 if (target_resume_hook)
2049 (*target_resume_hook) ();
2051 if (siggnal != TARGET_SIGNAL_0)
2053 buf[0] = step ? 'S' : 'C';
2054 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
2055 buf[2] = tohex ((int) siggnal & 0xf);
2059 strcpy (buf, step ? "s" : "c");
2061 /* We are about to start executing the inferior, let's register it
2062 with the event loop. NOTE: this is the one place where all the
2063 execution commands end up. We could alternatively do this in each
2064 of the execution commands in infcmd.c.*/
2065 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2066 into infcmd.c in order to allow inferior function calls to work
2067 NOT asynchronously. */
2068 if (event_loop_p && SERIAL_CAN_ASYNC_P (remote_desc))
2069 target_async (inferior_event_handler, 0);
2070 /* Tell the world that the target is now executing. */
2071 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2072 this? Instead, should the client of target just assume (for
2073 async targets) that the target is going to start executing? Is
2074 this information already found in the continuation block? */
2075 if (SERIAL_IS_ASYNC_P (remote_desc))
2076 target_executing = 1;
2081 /* Set up the signal handler for SIGINT, while the target is
2082 executing, ovewriting the 'regular' SIGINT signal handler. */
2084 initialize_sigint_signal_handler ()
2086 sigint_remote_token =
2087 create_async_signal_handler (async_remote_interrupt, NULL);
2088 signal (SIGINT, handle_remote_sigint);
2091 /* Signal handler for SIGINT, while the target is executing. */
2093 handle_remote_sigint (sig)
2096 signal (sig, handle_remote_sigint_twice);
2097 sigint_remote_twice_token =
2098 create_async_signal_handler (async_remote_interrupt_twice, NULL);
2099 mark_async_signal_handler_wrapper (sigint_remote_token);
2102 /* Signal handler for SIGINT, installed after SIGINT has already been
2103 sent once. It will take effect the second time that the user sends
2106 handle_remote_sigint_twice (sig)
2109 signal (sig, handle_sigint);
2110 sigint_remote_twice_token =
2111 create_async_signal_handler (inferior_event_handler_wrapper, NULL);
2112 mark_async_signal_handler_wrapper (sigint_remote_twice_token);
2115 /* Perform the real interruption of the target execution, in response
2118 async_remote_interrupt (arg)
2119 gdb_client_data arg;
2122 fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
2127 /* Perform interrupt, if the first attempt did not succeed. Just give
2128 up on the target alltogether. */
2130 async_remote_interrupt_twice (arg)
2131 gdb_client_data arg;
2134 fprintf_unfiltered (gdb_stdlog, "remote_interrupt_twice called\n");
2135 /* Do something only if the target was not killed by the previous
2137 if (target_executing)
2140 signal (SIGINT, handle_remote_sigint);
2144 /* Reinstall the usual SIGINT handlers, after the target has
2147 cleanup_sigint_signal_handler (void *dummy)
2149 signal (SIGINT, handle_sigint);
2150 if (sigint_remote_twice_token)
2151 delete_async_signal_handler ((struct async_signal_handler **) & sigint_remote_twice_token);
2152 if (sigint_remote_token)
2153 delete_async_signal_handler ((struct async_signal_handler **) & sigint_remote_token);
2156 /* Send ^C to target to halt it. Target will respond, and send us a
2158 static void (*ofunc) PARAMS ((int));
2160 /* The command line interface's stop routine. This function is installed
2161 as a signal handler for SIGINT. The first time a user requests a
2162 stop, we call remote_stop to send a break or ^C. If there is no
2163 response from the target (it didn't stop when the user requested it),
2164 we ask the user if he'd like to detach from the target. */
2166 remote_interrupt (signo)
2169 /* If this doesn't work, try more severe steps. */
2170 signal (signo, remote_interrupt_twice);
2173 fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
2178 /* The user typed ^C twice. */
2181 remote_interrupt_twice (signo)
2184 signal (signo, ofunc);
2186 signal (signo, remote_interrupt);
2189 /* This is the generic stop called via the target vector. When a target
2190 interrupt is requested, either by the command line or the GUI, we
2191 will eventually end up here. */
2195 /* Send a break or a ^C, depending on user preference. */
2197 fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
2200 SERIAL_SEND_BREAK (remote_desc);
2202 SERIAL_WRITE (remote_desc, "\003", 1);
2205 /* Ask the user what to do when an interrupt is received. */
2210 target_terminal_ours ();
2212 if (query ("Interrupted while waiting for the program.\n\
2213 Give up (and stop debugging it)? "))
2215 target_mourn_inferior ();
2216 return_to_top_level (RETURN_QUIT);
2219 target_terminal_inferior ();
2222 /* Enable/disable target terminal ownership. Most targets can use
2223 terminal groups to control terminal ownership. Remote targets are
2224 different in that explicit transfer of ownership to/from GDB/target
2228 remote_async_terminal_inferior (void)
2230 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2231 sync_execution here. This function should only be called when
2232 GDB is resuming the inferior in the forground. A background
2233 resume (``run&'') should leave GDB in control of the terminal and
2234 consequently should not call this code. */
2235 if (!sync_execution)
2237 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2238 calls target_terminal_*() idenpotent. The event-loop GDB talking
2239 to an asynchronous target with a synchronous command calls this
2240 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2241 stops trying to transfer the terminal to the target when it
2242 shouldn't this guard can go away. */
2243 if (!remote_async_terminal_ours_p)
2245 delete_file_handler (input_fd);
2246 remote_async_terminal_ours_p = 0;
2247 initialize_sigint_signal_handler ();
2248 /* NOTE: At this point we could also register our selves as the
2249 recipient of all input. Any characters typed could then be
2250 passed on down to the target. */
2254 remote_async_terminal_ours (void)
2256 /* See FIXME in remote_async_terminal_inferior. */
2257 if (!sync_execution)
2259 /* See FIXME in remote_async_terminal_inferior. */
2260 if (remote_async_terminal_ours_p)
2262 cleanup_sigint_signal_handler (NULL);
2263 add_file_handler (input_fd, stdin_event_handler, 0);
2264 remote_async_terminal_ours_p = 1;
2267 /* If nonzero, ignore the next kill. */
2272 remote_console_output (msg)
2277 for (p = msg; p[0] && p[1]; p += 2)
2280 char c = fromhex (p[0]) * 16 + fromhex (p[1]);
2283 fputs_unfiltered (tb, gdb_stdtarg);
2287 /* Wait until the remote machine stops, then return,
2288 storing status in STATUS just as `wait' would.
2289 Returns "pid", which in the case of a multi-threaded
2290 remote OS, is the thread-id. */
2293 remote_wait (pid, status)
2295 struct target_waitstatus *status;
2297 unsigned char *buf = alloca (PBUFSIZ);
2298 int thread_num = -1;
2300 status->kind = TARGET_WAITKIND_EXITED;
2301 status->value.integer = 0;
2307 ofunc = signal (SIGINT, remote_interrupt);
2308 getpkt ((char *) buf, 1);
2309 signal (SIGINT, ofunc);
2311 /* This is a hook for when we need to do something (perhaps the
2312 collection of trace data) every time the target stops. */
2313 if (target_wait_loop_hook)
2314 (*target_wait_loop_hook) ();
2318 case 'E': /* Error of some sort */
2319 warning ("Remote failure reply: %s", buf);
2321 case 'T': /* Status with PC, SP, FP, ... */
2325 char regs[MAX_REGISTER_RAW_SIZE];
2327 /* Expedited reply, containing Signal, {regno, reg} repeat */
2328 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2330 n... = register number
2331 r... = register contents
2333 p = &buf[3]; /* after Txx */
2340 /* Read the register number */
2341 regno = strtol ((const char *) p, &p_temp, 16);
2342 p1 = (unsigned char *) p_temp;
2344 if (p1 == p) /* No register number present here */
2346 p1 = (unsigned char *) strchr ((const char *) p, ':');
2348 warning ("Malformed packet(a) (missing colon): %s\n\
2351 if (strncmp ((const char *) p, "thread", p1 - p) == 0)
2353 p_temp = unpack_varlen_hex (++p1, &thread_num);
2354 record_currthread (thread_num);
2355 p = (unsigned char *) p_temp;
2363 warning ("Malformed packet(b) (missing colon): %s\n\
2367 if (regno >= NUM_REGS)
2368 warning ("Remote sent bad register number %ld: %s\n\
2372 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
2374 if (p[0] == 0 || p[1] == 0)
2375 warning ("Remote reply is too short: %s", buf);
2376 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
2379 supply_register (regno, regs);
2384 warning ("Remote register badly formatted: %s", buf);
2385 warning (" here: %s", p);
2390 case 'S': /* Old style status, just signal only */
2391 status->kind = TARGET_WAITKIND_STOPPED;
2392 status->value.sig = (enum target_signal)
2393 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2397 /* Export Cisco kernel mode as a convenience variable
2398 (so that it can be used in the GDB prompt if desired). */
2400 if (cisco_kernel_mode == 1)
2401 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2402 value_from_string ("PDEBUG-"));
2403 cisco_kernel_mode = 0;
2404 thread_num = strtol ((const char *) &buf[4], NULL, 16);
2405 record_currthread (thread_num);
2407 else if (buf[3] == 'k')
2409 /* Export Cisco kernel mode as a convenience variable
2410 (so that it can be used in the GDB prompt if desired). */
2412 if (cisco_kernel_mode == 1)
2413 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2414 value_from_string ("KDEBUG-"));
2415 cisco_kernel_mode = 1;
2418 case 'N': /* Cisco special: status and offsets */
2420 bfd_vma text_addr, data_addr, bss_addr;
2421 bfd_signed_vma text_off, data_off, bss_off;
2424 status->kind = TARGET_WAITKIND_STOPPED;
2425 status->value.sig = (enum target_signal)
2426 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2428 if (symfile_objfile == NULL)
2430 warning ("Relocation packet received with no symbol file. \
2435 /* Relocate object file. Buffer format is NAATT;DD;BB
2436 * where AA is the signal number, TT is the new text
2437 * address, DD * is the new data address, and BB is the
2438 * new bss address. */
2441 text_addr = strtoul (p, (char **) &p1, 16);
2442 if (p1 == p || *p1 != ';')
2443 warning ("Malformed relocation packet: Packet '%s'", buf);
2445 data_addr = strtoul (p, (char **) &p1, 16);
2446 if (p1 == p || *p1 != ';')
2447 warning ("Malformed relocation packet: Packet '%s'", buf);
2449 bss_addr = strtoul (p, (char **) &p1, 16);
2451 warning ("Malformed relocation packet: Packet '%s'", buf);
2453 if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
2454 &text_off, &data_off, &bss_off)
2456 if (text_off != 0 || data_off != 0 || bss_off != 0)
2457 remote_cisco_objfile_relocate (text_off, data_off, bss_off);
2461 case 'W': /* Target exited */
2463 /* The remote process exited. */
2464 status->kind = TARGET_WAITKIND_EXITED;
2465 status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
2469 status->kind = TARGET_WAITKIND_SIGNALLED;
2470 status->value.sig = (enum target_signal)
2471 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2475 case 'O': /* Console output */
2476 remote_console_output (buf + 1);
2479 if (last_sent_signal != TARGET_SIGNAL_0)
2481 /* Zero length reply means that we tried 'S' or 'C' and
2482 the remote system doesn't support it. */
2483 target_terminal_ours_for_output ();
2485 ("Can't send signals to this remote system. %s not sent.\n",
2486 target_signal_to_name (last_sent_signal));
2487 last_sent_signal = TARGET_SIGNAL_0;
2488 target_terminal_inferior ();
2490 strcpy ((char *) buf, last_sent_step ? "s" : "c");
2491 putpkt ((char *) buf);
2494 /* else fallthrough */
2496 warning ("Invalid remote reply: %s", buf);
2501 if (thread_num != -1)
2505 return inferior_pid;
2508 /* Async version of remote_wait. */
2510 remote_async_wait (pid, status)
2512 struct target_waitstatus *status;
2514 unsigned char *buf = alloca (PBUFSIZ);
2515 int thread_num = -1;
2517 status->kind = TARGET_WAITKIND_EXITED;
2518 status->value.integer = 0;
2524 if (!SERIAL_IS_ASYNC_P (remote_desc))
2525 ofunc = signal (SIGINT, remote_interrupt);
2526 /* FIXME: cagney/1999-09-27: If we're in async mode we should
2527 _never_ wait for ever -> test on target_is_async_p().
2528 However, before we do that we need to ensure that the caller
2529 knows how to take the target into/out of async mode. */
2530 getpkt ((char *) buf, wait_forever_enabled_p);
2531 if (!SERIAL_IS_ASYNC_P (remote_desc))
2532 signal (SIGINT, ofunc);
2534 /* This is a hook for when we need to do something (perhaps the
2535 collection of trace data) every time the target stops. */
2536 if (target_wait_loop_hook)
2537 (*target_wait_loop_hook) ();
2541 case 'E': /* Error of some sort */
2542 warning ("Remote failure reply: %s", buf);
2544 case 'T': /* Status with PC, SP, FP, ... */
2548 char regs[MAX_REGISTER_RAW_SIZE];
2550 /* Expedited reply, containing Signal, {regno, reg} repeat */
2551 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2553 n... = register number
2554 r... = register contents
2556 p = &buf[3]; /* after Txx */
2563 /* Read the register number */
2564 regno = strtol ((const char *) p, &p_temp, 16);
2565 p1 = (unsigned char *) p_temp;
2567 if (p1 == p) /* No register number present here */
2569 p1 = (unsigned char *) strchr ((const char *) p, ':');
2571 warning ("Malformed packet(a) (missing colon): %s\n\
2574 if (strncmp ((const char *) p, "thread", p1 - p) == 0)
2576 p_temp = unpack_varlen_hex (++p1, &thread_num);
2577 record_currthread (thread_num);
2578 p = (unsigned char *) p_temp;
2586 warning ("Malformed packet(b) (missing colon): %s\n\
2590 if (regno >= NUM_REGS)
2591 warning ("Remote sent bad register number %ld: %s\n\
2595 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
2597 if (p[0] == 0 || p[1] == 0)
2598 warning ("Remote reply is too short: %s", buf);
2599 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
2602 supply_register (regno, regs);
2607 warning ("Remote register badly formatted: %s", buf);
2608 warning (" here: %s", p);
2613 case 'S': /* Old style status, just signal only */
2614 status->kind = TARGET_WAITKIND_STOPPED;
2615 status->value.sig = (enum target_signal)
2616 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2620 /* Export Cisco kernel mode as a convenience variable
2621 (so that it can be used in the GDB prompt if desired). */
2623 if (cisco_kernel_mode == 1)
2624 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2625 value_from_string ("PDEBUG-"));
2626 cisco_kernel_mode = 0;
2627 thread_num = strtol ((const char *) &buf[4], NULL, 16);
2628 record_currthread (thread_num);
2630 else if (buf[3] == 'k')
2632 /* Export Cisco kernel mode as a convenience variable
2633 (so that it can be used in the GDB prompt if desired). */
2635 if (cisco_kernel_mode == 1)
2636 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2637 value_from_string ("KDEBUG-"));
2638 cisco_kernel_mode = 1;
2641 case 'N': /* Cisco special: status and offsets */
2643 bfd_vma text_addr, data_addr, bss_addr;
2644 bfd_signed_vma text_off, data_off, bss_off;
2647 status->kind = TARGET_WAITKIND_STOPPED;
2648 status->value.sig = (enum target_signal)
2649 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2651 if (symfile_objfile == NULL)
2653 warning ("Relocation packet recieved with no symbol file. \
2658 /* Relocate object file. Buffer format is NAATT;DD;BB
2659 * where AA is the signal number, TT is the new text
2660 * address, DD * is the new data address, and BB is the
2661 * new bss address. */
2664 text_addr = strtoul (p, (char **) &p1, 16);
2665 if (p1 == p || *p1 != ';')
2666 warning ("Malformed relocation packet: Packet '%s'", buf);
2668 data_addr = strtoul (p, (char **) &p1, 16);
2669 if (p1 == p || *p1 != ';')
2670 warning ("Malformed relocation packet: Packet '%s'", buf);
2672 bss_addr = strtoul (p, (char **) &p1, 16);
2674 warning ("Malformed relocation packet: Packet '%s'", buf);
2676 if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
2677 &text_off, &data_off, &bss_off)
2679 if (text_off != 0 || data_off != 0 || bss_off != 0)
2680 remote_cisco_objfile_relocate (text_off, data_off, bss_off);
2684 case 'W': /* Target exited */
2686 /* The remote process exited. */
2687 status->kind = TARGET_WAITKIND_EXITED;
2688 status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
2692 status->kind = TARGET_WAITKIND_SIGNALLED;
2693 status->value.sig = (enum target_signal)
2694 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2698 case 'O': /* Console output */
2699 remote_console_output (buf + 1);
2702 if (last_sent_signal != TARGET_SIGNAL_0)
2704 /* Zero length reply means that we tried 'S' or 'C' and
2705 the remote system doesn't support it. */
2706 target_terminal_ours_for_output ();
2708 ("Can't send signals to this remote system. %s not sent.\n",
2709 target_signal_to_name (last_sent_signal));
2710 last_sent_signal = TARGET_SIGNAL_0;
2711 target_terminal_inferior ();
2713 strcpy ((char *) buf, last_sent_step ? "s" : "c");
2714 putpkt ((char *) buf);
2717 /* else fallthrough */
2719 warning ("Invalid remote reply: %s", buf);
2724 if (thread_num != -1)
2728 return inferior_pid;
2731 /* Number of bytes of registers this stub implements. */
2733 static int register_bytes_found;
2735 /* Read the remote registers into the block REGS. */
2736 /* Currently we just read all the registers, so we don't use regno. */
2740 remote_fetch_registers (regno)
2743 char *buf = alloca (PBUFSIZ);
2746 char regs[REGISTER_BYTES];
2748 set_thread (inferior_pid, 1);
2753 if (remote_register_buf_size == 0)
2754 remote_register_buf_size = strlen (buf);
2756 /* Unimplemented registers read as all bits zero. */
2757 memset (regs, 0, REGISTER_BYTES);
2759 /* We can get out of synch in various cases. If the first character
2760 in the buffer is not a hex character, assume that has happened
2761 and try to fetch another packet to read. */
2762 while ((buf[0] < '0' || buf[0] > '9')
2763 && (buf[0] < 'a' || buf[0] > 'f')
2764 && buf[0] != 'x') /* New: unavailable register value */
2767 fprintf_unfiltered (gdb_stdlog,
2768 "Bad register packet; fetching a new packet\n");
2772 /* Reply describes registers byte by byte, each byte encoded as two
2773 hex characters. Suck them all up, then supply them to the
2774 register cacheing/storage mechanism. */
2777 for (i = 0; i < REGISTER_BYTES; i++)
2783 warning ("Remote reply is of odd length: %s", buf);
2784 /* Don't change register_bytes_found in this case, and don't
2785 print a second warning. */
2788 if (p[0] == 'x' && p[1] == 'x')
2789 regs[i] = 0; /* 'x' */
2791 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
2795 if (i != register_bytes_found)
2797 register_bytes_found = i;
2798 #ifdef REGISTER_BYTES_OK
2799 if (!REGISTER_BYTES_OK (i))
2800 warning ("Remote reply is too short: %s", buf);
2805 for (i = 0; i < NUM_REGS; i++)
2807 supply_register (i, ®s[REGISTER_BYTE (i)]);
2808 if (buf[REGISTER_BYTE (i) * 2] == 'x')
2809 register_valid[i] = -1; /* register value not available */
2813 /* Prepare to store registers. Since we may send them all (using a
2814 'G' request), we have to read out the ones we don't want to change
2818 remote_prepare_to_store ()
2820 /* Make sure the entire registers array is valid. */
2821 switch (remote_protocol_P.support)
2823 case PACKET_DISABLE:
2824 case PACKET_SUPPORT_UNKNOWN:
2825 read_register_bytes (0, (char *) NULL, REGISTER_BYTES);
2832 /* Helper: Attempt to store REGNO using the P packet. Return fail IFF
2833 packet was not recognized. */
2836 store_register_using_P (regno)
2839 /* Try storing a single register. */
2840 char *buf = alloca (PBUFSIZ);
2845 sprintf (buf, "P%x=", regno);
2846 p = buf + strlen (buf);
2847 regp = ®isters[REGISTER_BYTE (regno)];
2848 for (i = 0; i < REGISTER_RAW_SIZE (regno); ++i)
2850 *p++ = tohex ((regp[i] >> 4) & 0xf);
2851 *p++ = tohex (regp[i] & 0xf);
2856 return buf[0] != '\0';
2860 /* Store register REGNO, or all registers if REGNO == -1, from the contents
2861 of REGISTERS. FIXME: ignores errors. */
2864 remote_store_registers (regno)
2867 char *buf = alloca (PBUFSIZ);
2871 set_thread (inferior_pid, 1);
2875 switch (remote_protocol_P.support)
2877 case PACKET_DISABLE:
2880 if (store_register_using_P (regno))
2883 error ("Protocol error: P packet not recognized by stub");
2884 case PACKET_SUPPORT_UNKNOWN:
2885 if (store_register_using_P (regno))
2887 /* The stub recognized the 'P' packet. Remember this. */
2888 remote_protocol_P.support = PACKET_ENABLE;
2893 /* The stub does not support the 'P' packet. Use 'G'
2894 instead, and don't try using 'P' in the future (it
2895 will just waste our time). */
2896 remote_protocol_P.support = PACKET_DISABLE;
2904 /* Command describes registers byte by byte,
2905 each byte encoded as two hex characters. */
2908 /* remote_prepare_to_store insures that register_bytes_found gets set. */
2909 for (i = 0; i < register_bytes_found; i++)
2911 *p++ = tohex ((registers[i] >> 4) & 0xf);
2912 *p++ = tohex (registers[i] & 0xf);
2919 /* Use of the data cache *used* to be disabled because it loses for looking
2920 at and changing hardware I/O ports and the like. Accepting `volatile'
2921 would perhaps be one way to fix it. Another idea would be to use the
2922 executable file for the text segment (for all SEC_CODE sections?
2923 For all SEC_READONLY sections?). This has problems if you want to
2924 actually see what the memory contains (e.g. self-modifying code,
2925 clobbered memory, user downloaded the wrong thing).
2927 Because it speeds so much up, it's now enabled, if you're playing
2928 with registers you turn it of (set remotecache 0). */
2930 /* Read a word from remote address ADDR and return it.
2931 This goes through the data cache. */
2935 remote_fetch_word (addr)
2938 return dcache_fetch (remote_dcache, addr);
2941 /* Write a word WORD into remote address ADDR.
2942 This goes through the data cache. */
2945 remote_store_word (addr, word)
2949 dcache_poke (remote_dcache, addr, word);
2951 #endif /* 0 (unused?) */
2955 /* Return the number of hex digits in num. */
2963 for (i = 0; num != 0; i++)
2969 /* Set BUF to the minimum number of hex digits representing NUM. */
2972 hexnumstr (buf, num)
2976 int len = hexnumlen (num);
2977 return hexnumnstr (buf, num, len);
2981 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
2984 hexnumnstr (buf, num, width)
2993 for (i = width - 1; i >= 0; i--)
2995 buf[i] = "0123456789abcdef"[(num & 0xf)];
3002 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3005 remote_address_masked (addr)
3008 if (remote_address_size > 0
3009 && remote_address_size < (sizeof (ULONGEST) * 8))
3011 /* Only create a mask when that mask can safely be constructed
3012 in a ULONGEST variable. */
3014 mask = (mask << remote_address_size) - 1;
3020 /* Determine whether the remote target supports binary downloading.
3021 This is accomplished by sending a no-op memory write of zero length
3022 to the target at the specified address. It does not suffice to send
3023 the whole packet, since many stubs strip the eighth bit and subsequently
3024 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3026 NOTE: This can still lose if the serial line is not eight-bit
3027 clean. In cases like this, the user should clear "remote
3031 check_binary_download (addr)
3034 switch (remote_protocol_binary_download.support)
3036 case PACKET_DISABLE:
3040 case PACKET_SUPPORT_UNKNOWN:
3042 char *buf = alloca (PBUFSIZ);
3047 p += hexnumstr (p, (ULONGEST) addr);
3049 p += hexnumstr (p, (ULONGEST) 0);
3053 putpkt_binary (buf, (int) (p - buf));
3059 fprintf_unfiltered (gdb_stdlog,
3060 "binary downloading NOT suppported by target\n");
3061 remote_protocol_binary_download.support = PACKET_DISABLE;
3066 fprintf_unfiltered (gdb_stdlog,
3067 "binary downloading suppported by target\n");
3068 remote_protocol_binary_download.support = PACKET_ENABLE;
3075 /* Write memory data directly to the remote machine.
3076 This does not inform the data cache; the data cache uses this.
3077 MEMADDR is the address in the remote memory space.
3078 MYADDR is the address of the buffer in our space.
3079 LEN is the number of bytes.
3081 Returns number of bytes transferred, or 0 for error. */
3084 remote_write_bytes (memaddr, myaddr, len)
3089 unsigned char *buf = alloca (PBUFSIZ);
3090 int max_buf_size; /* Max size of packet output buffer */
3093 /* Verify that the target can support a binary download */
3094 check_binary_download (memaddr);
3096 /* Chop the transfer down if necessary */
3098 max_buf_size = min (remote_write_size, PBUFSIZ);
3099 if (remote_register_buf_size != 0)
3100 max_buf_size = min (max_buf_size, remote_register_buf_size);
3102 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3103 max_buf_size -= 2 + hexnumlen (memaddr + len - 1) + 1 + hexnumlen (len) + 4;
3108 unsigned char *p, *plen;
3113 /* construct "M"<memaddr>","<len>":" */
3114 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3115 memaddr = remote_address_masked (memaddr);
3117 switch (remote_protocol_binary_download.support)
3121 todo = min (len, max_buf_size);
3123 case PACKET_DISABLE:
3125 todo = min (len, max_buf_size / 2); /* num bytes that will fit */
3127 case PACKET_SUPPORT_UNKNOWN:
3128 internal_error ("remote_write_bytes: bad switch");
3131 p += hexnumstr (p, (ULONGEST) memaddr);
3134 plen = p; /* remember where len field goes */
3135 plenlen = hexnumstr (p, (ULONGEST) todo);
3140 /* We send target system values byte by byte, in increasing byte
3141 addresses, each byte encoded as two hex characters (or one
3142 binary character). */
3143 switch (remote_protocol_binary_download.support)
3149 (i < todo) && (i + escaped) < (max_buf_size - 2);
3152 switch (myaddr[i] & 0xff)
3157 /* These must be escaped */
3160 *p++ = (myaddr[i] & 0xff) ^ 0x20;
3163 *p++ = myaddr[i] & 0xff;
3170 /* Escape chars have filled up the buffer prematurely,
3171 and we have actually sent fewer bytes than planned.
3172 Fix-up the length field of the packet. Use the same
3173 number of characters as before. */
3175 plen += hexnumnstr (plen, (ULONGEST) i, plenlen);
3176 *plen = ':'; /* overwrite \0 from hexnumnstr() */
3180 case PACKET_DISABLE:
3182 for (i = 0; i < todo; i++)
3184 *p++ = tohex ((myaddr[i] >> 4) & 0xf);
3185 *p++ = tohex (myaddr[i] & 0xf);
3190 case PACKET_SUPPORT_UNKNOWN:
3191 internal_error ("remote_write_bytes: bad switch");
3194 putpkt_binary (buf, (int) (p - buf));
3199 /* There is no correspondance between what the remote protocol uses
3200 for errors and errno codes. We would like a cleaner way of
3201 representing errors (big enough to include errno codes, bfd_error
3202 codes, and others). But for now just return EIO. */
3207 /* Increment by i, not by todo, in case escape chars
3208 caused us to send fewer bytes than we'd planned. */
3216 /* Read memory data directly from the remote machine.
3217 This does not use the data cache; the data cache uses this.
3218 MEMADDR is the address in the remote memory space.
3219 MYADDR is the address of the buffer in our space.
3220 LEN is the number of bytes.
3222 Returns number of bytes transferred, or 0 for error. */
3225 remote_read_bytes (memaddr, myaddr, len)
3230 char *buf = alloca (PBUFSIZ);
3231 int max_buf_size; /* Max size of packet output buffer */
3234 /* Chop the transfer down if necessary */
3236 max_buf_size = min (remote_write_size, PBUFSIZ);
3237 if (remote_register_buf_size != 0)
3238 max_buf_size = min (max_buf_size, remote_register_buf_size);
3247 todo = min (len, max_buf_size / 2); /* num bytes that will fit */
3249 /* construct "m"<memaddr>","<len>" */
3250 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3251 memaddr = remote_address_masked (memaddr);
3254 p += hexnumstr (p, (ULONGEST) memaddr);
3256 p += hexnumstr (p, (ULONGEST) todo);
3264 /* There is no correspondance between what the remote protocol uses
3265 for errors and errno codes. We would like a cleaner way of
3266 representing errors (big enough to include errno codes, bfd_error
3267 codes, and others). But for now just return EIO. */
3272 /* Reply describes memory byte by byte,
3273 each byte encoded as two hex characters. */
3276 for (i = 0; i < todo; i++)
3278 if (p[0] == 0 || p[1] == 0)
3279 /* Reply is short. This means that we were able to read
3280 only part of what we wanted to. */
3281 return i + (origlen - len);
3282 myaddr[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
3292 /* Read or write LEN bytes from inferior memory at MEMADDR,
3293 transferring to or from debugger address BUFFER. Write to inferior if
3294 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3297 #ifndef REMOTE_TRANSLATE_XFER_ADDRESS
3298 #define REMOTE_TRANSLATE_XFER_ADDRESS(MEM_ADDR, MEM_LEN, TARG_ADDR, TARG_LEN) \
3299 (*(TARG_ADDR) = (MEM_ADDR), *(TARG_LEN) = (MEM_LEN))
3304 remote_xfer_memory (mem_addr, buffer, mem_len, should_write, target)
3309 struct target_ops *target; /* ignored */
3311 CORE_ADDR targ_addr;
3313 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr, mem_len, &targ_addr, &targ_len);
3317 return dcache_xfer_memory (remote_dcache, targ_addr, buffer,
3318 targ_len, should_write);
3323 /* Enable after 4.12. */
3326 remote_search (len, data, mask, startaddr, increment, lorange, hirange
3327 addr_found, data_found)
3331 CORE_ADDR startaddr;
3335 CORE_ADDR *addr_found;
3338 if (increment == -4 && len == 4)
3340 long mask_long, data_long;
3341 long data_found_long;
3342 CORE_ADDR addr_we_found;
3343 char *buf = alloca (PBUFSIZ);
3344 long returned_long[2];
3347 mask_long = extract_unsigned_integer (mask, len);
3348 data_long = extract_unsigned_integer (data, len);
3349 sprintf (buf, "t%x:%x,%x", startaddr, data_long, mask_long);
3354 /* The stub doesn't support the 't' request. We might want to
3355 remember this fact, but on the other hand the stub could be
3356 switched on us. Maybe we should remember it only until
3357 the next "target remote". */
3358 generic_search (len, data, mask, startaddr, increment, lorange,
3359 hirange, addr_found, data_found);
3364 /* There is no correspondance between what the remote protocol uses
3365 for errors and errno codes. We would like a cleaner way of
3366 representing errors (big enough to include errno codes, bfd_error
3367 codes, and others). But for now just use EIO. */
3368 memory_error (EIO, startaddr);
3371 while (*p != '\0' && *p != ',')
3372 addr_we_found = (addr_we_found << 4) + fromhex (*p++);
3374 error ("Protocol error: short return for search");
3376 data_found_long = 0;
3377 while (*p != '\0' && *p != ',')
3378 data_found_long = (data_found_long << 4) + fromhex (*p++);
3379 /* Ignore anything after this comma, for future extensions. */
3381 if (addr_we_found < lorange || addr_we_found >= hirange)
3387 *addr_found = addr_we_found;
3388 *data_found = store_unsigned_integer (data_we_found, len);
3391 generic_search (len, data, mask, startaddr, increment, lorange,
3392 hirange, addr_found, data_found);
3397 remote_files_info (ignore)
3398 struct target_ops *ignore;
3400 puts_filtered ("Debugging a target over a serial line.\n");
3403 /* Stuff for dealing with the packets which are part of this protocol.
3404 See comment at top of file for details. */
3406 /* Read a single character from the remote end, masking it down to 7 bits. */
3414 ch = SERIAL_READCHAR (remote_desc, timeout);
3419 switch ((enum serial_rc) ch)
3422 target_mourn_inferior ();
3423 error ("Remote connection closed");
3426 perror_with_name ("Remote communication error");
3428 case SERIAL_TIMEOUT:
3434 /* Send the command in BUF to the remote machine, and read the reply
3435 into BUF. Report an error if we get an error reply. */
3445 error ("Remote failure reply: %s", buf);
3448 /* Display a null-terminated packet on stdout, for debugging, using C
3455 puts_filtered ("\"");
3456 fputstr_filtered (buf, '"', gdb_stdout);
3457 puts_filtered ("\"");
3464 return putpkt_binary (buf, strlen (buf));
3467 /* Send a packet to the remote machine, with error checking. The data
3468 of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
3469 to account for the $, # and checksum, and for a possible /0 if we are
3470 debugging (remote_debug) and want to print the sent packet as a string */
3473 putpkt_binary (buf, cnt)
3478 unsigned char csum = 0;
3479 char *buf2 = alloca (PBUFSIZ);
3480 char *junkbuf = alloca (PBUFSIZ);
3486 /* Copy the packet into buffer BUF2, encapsulating it
3487 and giving it a checksum. */
3489 if (cnt > BUFSIZ - 5) /* Prosanity check */
3495 for (i = 0; i < cnt; i++)
3501 *p++ = tohex ((csum >> 4) & 0xf);
3502 *p++ = tohex (csum & 0xf);
3504 /* Send it over and over until we get a positive ack. */
3508 int started_error_output = 0;
3513 fprintf_unfiltered (gdb_stdlog, "Sending packet: ");
3514 fputstrn_unfiltered (buf2, p - buf2, 0, gdb_stdlog);
3515 fprintf_unfiltered (gdb_stdlog, "...");
3516 gdb_flush (gdb_stdlog);
3518 if (SERIAL_WRITE (remote_desc, buf2, p - buf2))
3519 perror_with_name ("putpkt: write failed");
3521 /* read until either a timeout occurs (-2) or '+' is read */
3524 ch = readchar (remote_timeout);
3531 case SERIAL_TIMEOUT:
3533 if (started_error_output)
3535 putchar_unfiltered ('\n');
3536 started_error_output = 0;
3545 fprintf_unfiltered (gdb_stdlog, "Ack\n");
3547 case SERIAL_TIMEOUT:
3551 break; /* Retransmit buffer */
3554 /* It's probably an old response, and we're out of sync.
3555 Just gobble up the packet and ignore it. */
3556 getpkt (junkbuf, 0);
3557 continue; /* Now, go look for + */
3562 if (!started_error_output)
3564 started_error_output = 1;
3565 fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
3567 fputc_unfiltered (ch & 0177, gdb_stdlog);
3571 break; /* Here to retransmit */
3575 /* This is wrong. If doing a long backtrace, the user should be
3576 able to get out next time we call QUIT, without anything as
3577 violent as interrupt_query. If we want to provide a way out of
3578 here without getting to the next QUIT, it should be based on
3579 hitting ^C twice as in remote_wait. */
3589 static int remote_cisco_mode;
3591 /* Come here after finding the start of the frame. Collect the rest
3592 into BUF, verifying the checksum, length, and handling run-length
3593 compression. Returns 0 on any error, 1 on success. */
3608 c = readchar (remote_timeout);
3612 case SERIAL_TIMEOUT:
3614 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
3618 fputs_filtered ("Saw new packet start in middle of old one\n",
3620 return 0; /* Start a new packet, count retries */
3623 unsigned char pktcsum;
3627 pktcsum = fromhex (readchar (remote_timeout)) << 4;
3628 pktcsum |= fromhex (readchar (remote_timeout));
3630 if (csum == pktcsum)
3635 fprintf_filtered (gdb_stdlog,
3636 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
3638 fputs_filtered (buf, gdb_stdlog);
3639 fputs_filtered ("\n", gdb_stdlog);
3643 case '*': /* Run length encoding */
3648 if (remote_cisco_mode == 0)
3650 c = readchar (remote_timeout);
3652 repeat = c - ' ' + 3; /* Compute repeat count */
3656 /* Cisco's run-length encoding variant uses two
3657 hex chars to represent the repeat count. */
3659 c = readchar (remote_timeout);
3661 repeat = fromhex (c) << 4;
3662 c = readchar (remote_timeout);
3664 repeat += fromhex (c);
3667 if (repeat > 0 && repeat <= 255
3668 && bp + repeat - 1 < buf + PBUFSIZ - 1)
3670 memset (bp, *(bp - 1), repeat);
3676 printf_filtered ("Repeat count %d too large for buffer: ", repeat);
3677 puts_filtered (buf);
3678 puts_filtered ("\n");
3682 if (bp < buf + PBUFSIZ - 1)
3690 puts_filtered ("Remote packet too long: ");
3691 puts_filtered (buf);
3692 puts_filtered ("\n");
3699 /* Read a packet from the remote machine, with error checking, and
3700 store it in BUF. BUF is expected to be of size PBUFSIZ. If
3701 FOREVER, wait forever rather than timing out; this is used while
3702 the target is executing user code. */
3705 getpkt (buf, forever)
3714 strcpy (buf, "timeout");
3718 timeout = watchdog > 0 ? watchdog : -1;
3722 timeout = remote_timeout;
3726 for (tries = 1; tries <= MAX_TRIES; tries++)
3728 /* This can loop forever if the remote side sends us characters
3729 continuously, but if it pauses, we'll get a zero from readchar
3730 because of timeout. Then we'll count that as a retry. */
3732 /* Note that we will only wait forever prior to the start of a packet.
3733 After that, we expect characters to arrive at a brisk pace. They
3734 should show up within remote_timeout intervals. */
3738 c = readchar (timeout);
3740 if (c == SERIAL_TIMEOUT)
3742 if (forever) /* Watchdog went off? Kill the target. */
3745 target_mourn_inferior ();
3746 error ("Watchdog has expired. Target detached.\n");
3749 fputs_filtered ("Timed out.\n", gdb_stdlog);
3755 /* We've found the start of a packet, now collect the data. */
3757 val = read_frame (buf);
3763 fprintf_unfiltered (gdb_stdlog, "Packet received: ");
3764 fputstr_unfiltered (buf, 0, gdb_stdlog);
3765 fprintf_unfiltered (gdb_stdlog, "\n");
3767 SERIAL_WRITE (remote_desc, "+", 1);
3771 /* Try the whole thing again. */
3773 SERIAL_WRITE (remote_desc, "-", 1);
3776 /* We have tried hard enough, and just can't receive the packet. Give up. */
3778 printf_unfiltered ("Ignoring packet error, continuing...\n");
3779 SERIAL_WRITE (remote_desc, "+", 1);
3785 /* For some mysterious reason, wait_for_inferior calls kill instead of
3786 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3790 target_mourn_inferior ();
3794 /* Use catch_errors so the user can quit from gdb even when we aren't on
3795 speaking terms with the remote system. */
3796 catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR);
3798 /* Don't wait for it to die. I'm not really sure it matters whether
3799 we do or not. For the existing stubs, kill is a noop. */
3800 target_mourn_inferior ();
3803 /* Async version of remote_kill. */
3805 remote_async_kill ()
3807 /* Unregister the file descriptor from the event loop. */
3808 if (SERIAL_IS_ASYNC_P (remote_desc))
3809 SERIAL_ASYNC (remote_desc, NULL, 0);
3811 /* For some mysterious reason, wait_for_inferior calls kill instead of
3812 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3816 target_mourn_inferior ();
3820 /* Use catch_errors so the user can quit from gdb even when we aren't on
3821 speaking terms with the remote system. */
3822 catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR);
3824 /* Don't wait for it to die. I'm not really sure it matters whether
3825 we do or not. For the existing stubs, kill is a noop. */
3826 target_mourn_inferior ();
3832 remote_mourn_1 (&remote_ops);
3836 remote_async_mourn ()
3838 remote_mourn_1 (&remote_async_ops);
3842 extended_remote_mourn ()
3844 /* We do _not_ want to mourn the target like this; this will
3845 remove the extended remote target from the target stack,
3846 and the next time the user says "run" it'll fail.
3848 FIXME: What is the right thing to do here? */
3850 remote_mourn_1 (&extended_remote_ops);
3854 /* Worker function for remote_mourn. */
3856 remote_mourn_1 (target)
3857 struct target_ops *target;
3859 unpush_target (target);
3860 generic_mourn_inferior ();
3863 /* In the extended protocol we want to be able to do things like
3864 "run" and have them basically work as expected. So we need
3865 a special create_inferior function.
3867 FIXME: One day add support for changing the exec file
3868 we're debugging, arguments and an environment. */
3871 extended_remote_create_inferior (exec_file, args, env)
3876 /* Rip out the breakpoints; we'll reinsert them after restarting
3877 the remote server. */
3878 remove_breakpoints ();
3880 /* Now restart the remote server. */
3881 extended_remote_restart ();
3883 /* Now put the breakpoints back in. This way we're safe if the
3884 restart function works via a unix fork on the remote side. */
3885 insert_breakpoints ();
3887 /* Clean up from the last time we were running. */
3888 clear_proceed_status ();
3890 /* Let the remote process run. */
3891 proceed (-1, TARGET_SIGNAL_0, 0);
3894 /* Async version of extended_remote_create_inferior. */
3896 extended_remote_async_create_inferior (exec_file, args, env)
3901 /* Rip out the breakpoints; we'll reinsert them after restarting
3902 the remote server. */
3903 remove_breakpoints ();
3905 /* If running asynchronously, register the target file descriptor
3906 with the event loop. */
3907 if (event_loop_p && target_can_async_p ())
3908 target_async (inferior_event_handler, 0);
3910 /* Now restart the remote server. */
3911 extended_remote_restart ();
3913 /* Now put the breakpoints back in. This way we're safe if the
3914 restart function works via a unix fork on the remote side. */
3915 insert_breakpoints ();
3917 /* Clean up from the last time we were running. */
3918 clear_proceed_status ();
3920 /* Let the remote process run. */
3921 proceed (-1, TARGET_SIGNAL_0, 0);
3925 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
3926 than other targets; in those use REMOTE_BREAKPOINT instead of just
3927 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
3928 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
3929 the standard routines that are in mem-break.c. */
3931 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
3932 the choice of breakpoint instruction affects target program design and
3933 vice versa, and by making it user-tweakable, the special code here
3934 goes away and we need fewer special GDB configurations. */
3936 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
3937 #define REMOTE_BREAKPOINT
3940 #ifdef REMOTE_BREAKPOINT
3942 /* If the target isn't bi-endian, just pretend it is. */
3943 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
3944 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
3945 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
3948 static unsigned char big_break_insn[] = BIG_REMOTE_BREAKPOINT;
3949 static unsigned char little_break_insn[] = LITTLE_REMOTE_BREAKPOINT;
3951 #endif /* REMOTE_BREAKPOINT */
3953 /* Insert a breakpoint on targets that don't have any better breakpoint
3954 support. We read the contents of the target location and stash it,
3955 then overwrite it with a breakpoint instruction. ADDR is the target
3956 location in the target machine. CONTENTS_CACHE is a pointer to
3957 memory allocated for saving the target contents. It is guaranteed
3958 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
3959 is accomplished via BREAKPOINT_MAX). */
3962 remote_insert_breakpoint (addr, contents_cache)
3964 char *contents_cache;
3966 #ifdef REMOTE_BREAKPOINT
3971 /* Try the "Z" packet if it is not already disabled.
3972 If it succeeds, then set the support to PACKET_ENABLE.
3973 If it fails, and the user has explicitly requested the Z support
3974 then report an error, otherwise, mark it disabled and go on. */
3976 if ((remote_protocol_Z.support == PACKET_ENABLE)
3977 || (remote_protocol_Z.support == PACKET_SUPPORT_UNKNOWN))
3979 char buf[PBUFSIZ], *p = buf;
3981 addr = remote_address_masked (addr);
3985 p += hexnumstr (p, (ULONGEST) addr);
3986 BREAKPOINT_FROM_PC (&addr, &bp_size);
3987 sprintf (p, ",%d", bp_size);
3994 remote_protocol_Z.support = PACKET_ENABLE;
3995 return (buf[0] == 'E');
3998 /* The stub does not support the 'Z' request. If the user has
3999 explicitly requested the Z support, or if the stub previously
4000 said it supported the packet, this is an error,
4001 otherwise, mark it disabled. */
4003 else if (remote_protocol_Z.support == PACKET_ENABLE)
4005 error ("Protocol error: Z packet not recognized by stub");
4009 remote_protocol_Z.support = PACKET_DISABLE;
4013 #ifdef REMOTE_BREAKPOINT
4014 val = target_read_memory (addr, contents_cache, sizeof big_break_insn);
4018 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
4019 val = target_write_memory (addr, (char *) big_break_insn,
4020 sizeof big_break_insn);
4022 val = target_write_memory (addr, (char *) little_break_insn,
4023 sizeof little_break_insn);
4028 return memory_insert_breakpoint (addr, contents_cache);
4029 #endif /* REMOTE_BREAKPOINT */
4033 remote_remove_breakpoint (addr, contents_cache)
4035 char *contents_cache;
4039 if ((remote_protocol_Z.support == PACKET_ENABLE)
4040 || (remote_protocol_Z.support == PACKET_SUPPORT_UNKNOWN))
4042 char buf[PBUFSIZ], *p = buf;
4048 addr = remote_address_masked (addr);
4049 p += hexnumstr (p, (ULONGEST) addr);
4050 BREAKPOINT_FROM_PC (&addr, &bp_size);
4051 sprintf (p, ",%d", bp_size);
4056 return (buf[0] == 'E');
4059 #ifdef REMOTE_BREAKPOINT
4060 return target_write_memory (addr, contents_cache, sizeof big_break_insn);
4062 return memory_remove_breakpoint (addr, contents_cache);
4063 #endif /* REMOTE_BREAKPOINT */
4066 #ifdef TARGET_HAS_HARDWARE_WATCHPOINTS
4068 remote_insert_watchpoint (addr, len, type)
4073 char buf[PBUFSIZ], *p;
4075 if (remote_protocol_Z.support == PACKET_DISABLE)
4076 error ("Can't set hardware watchpoints without the 'Z' packet\n");
4078 sprintf (buf, "Z%x,", type + 2 );
4079 p = strchr (buf, '\0');
4080 addr = remote_address_masked (addr);
4081 p += hexnumstr (p, (ULONGEST) addr);
4082 sprintf (p, ",%x", len);
4087 if (buf[0] == '\0' || buf [0] == 'E')
4094 remote_remove_watchpoint (addr, len, type)
4099 char buf[PBUFSIZ], *p;
4101 sprintf (buf, "z%x,", type + 2 );
4102 p = strchr (buf, '\0');
4103 addr = remote_address_masked (addr);
4104 p += hexnumstr (p, (ULONGEST) addr);
4105 sprintf (p, ",%x", len);
4109 if (buf[0] == '\0' || buf [0] == 'E')
4116 remote_insert_hw_breakpoint (addr, len)
4120 char buf[PBUFSIZ], *p = buf;
4122 if (remote_protocol_Z.support == PACKET_DISABLE)
4123 error ("Can't set hardware breakpoints without the 'Z' packet\n");
4129 addr = remote_address_masked (addr);
4130 p += hexnumstr (p, (ULONGEST) addr);
4136 if (buf[0] == '\0' || buf [0] == 'E')
4143 remote_remove_hw_breakpoint (addr, len)
4147 char buf[PBUFSIZ], *p = buf;
4153 addr = remote_address_masked (addr);
4154 p += hexnumstr (p, (ULONGEST) addr);
4160 if (buf[0] == '\0' || buf [0] == 'E')
4167 /* Some targets are only capable of doing downloads, and afterwards
4168 they switch to the remote serial protocol. This function provides
4169 a clean way to get from the download target to the remote target.
4170 It's basically just a wrapper so that we don't have to expose any
4171 of the internal workings of remote.c.
4173 Prior to calling this routine, you should shutdown the current
4174 target code, else you will get the "A program is being debugged
4175 already..." message. Usually a call to pop_target() suffices. */
4178 push_remote_target (name, from_tty)
4182 printf_filtered ("Switching to remote protocol\n");
4183 remote_open (name, from_tty);
4186 /* Other targets want to use the entire remote serial module but with
4187 certain remote_ops overridden. */
4190 open_remote_target (name, from_tty, target, extended_p)
4193 struct target_ops *target;
4196 printf_filtered ("Selecting the %sremote protocol\n",
4197 (extended_p ? "extended-" : ""));
4198 remote_open_1 (name, from_tty, target, extended_p);
4201 /* Table used by the crc32 function to calcuate the checksum. */
4203 static unsigned long crc32_table[256] =
4206 static unsigned long
4207 crc32 (buf, len, crc)
4212 if (!crc32_table[1])
4214 /* Initialize the CRC table and the decoding table. */
4218 for (i = 0; i < 256; i++)
4220 for (c = i << 24, j = 8; j > 0; --j)
4221 c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1);
4228 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buf) & 255];
4234 /* compare-sections command
4236 With no arguments, compares each loadable section in the exec bfd
4237 with the same memory range on the target, and reports mismatches.
4238 Useful for verifying the image on the target against the exec file.
4239 Depends on the target understanding the new "qCRC:" request. */
4242 compare_sections_command (args, from_tty)
4247 unsigned long host_crc, target_crc;
4248 extern bfd *exec_bfd;
4249 struct cleanup *old_chain;
4253 char *buf = alloca (PBUFSIZ);
4260 error ("command cannot be used without an exec file");
4261 if (!current_target.to_shortname ||
4262 strcmp (current_target.to_shortname, "remote") != 0)
4263 error ("command can only be used with remote target");
4265 for (s = exec_bfd->sections; s; s = s->next)
4267 if (!(s->flags & SEC_LOAD))
4268 continue; /* skip non-loadable section */
4270 size = bfd_get_section_size_before_reloc (s);
4272 continue; /* skip zero-length section */
4274 sectname = (char *) bfd_get_section_name (exec_bfd, s);
4275 if (args && strcmp (args, sectname) != 0)
4276 continue; /* not the section selected by user */
4278 matched = 1; /* do this section */
4280 /* FIXME: assumes lma can fit into long */
4281 sprintf (buf, "qCRC:%lx,%lx", (long) lma, (long) size);
4284 /* be clever; compute the host_crc before waiting for target reply */
4285 sectdata = xmalloc (size);
4286 old_chain = make_cleanup (free, sectdata);
4287 bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
4288 host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
4292 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
4293 sectname, lma, lma + size);
4295 error ("remote target does not support this operation");
4297 for (target_crc = 0, tmp = &buf[1]; *tmp; tmp++)
4298 target_crc = target_crc * 16 + fromhex (*tmp);
4300 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4301 sectname, paddr (lma), paddr (lma + size));
4302 if (host_crc == target_crc)
4303 printf_filtered ("matched.\n");
4306 printf_filtered ("MIS-MATCHED!\n");
4310 do_cleanups (old_chain);
4313 warning ("One or more sections of the remote executable does not match\n\
4314 the loaded file\n");
4315 if (args && !matched)
4316 printf_filtered ("No loaded section named '%s'.\n", args);
4320 remote_query (query_type, buf, outbuf, bufsiz)
4327 char *buf2 = alloca (PBUFSIZ);
4328 char *p2 = &buf2[0];
4331 error ("null pointer to remote bufer size specified");
4333 /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let
4334 the caller know and return what the minimum size is */
4335 /* Note: a zero bufsiz can be used to query the minimum buffer size */
4336 if (*bufsiz < PBUFSIZ)
4342 /* except for querying the minimum buffer size, target must be open */
4344 error ("remote query is only available after target open");
4346 /* we only take uppercase letters as query types, at least for now */
4347 if ((query_type < 'A') || (query_type > 'Z'))
4348 error ("invalid remote query type");
4351 error ("null remote query specified");
4354 error ("remote query requires a buffer to receive data");
4361 /* we used one buffer char for the remote protocol q command and another
4362 for the query type. As the remote protocol encapsulation uses 4 chars
4363 plus one extra in case we are debugging (remote_debug),
4364 we have PBUFZIZ - 7 left to pack the query string */
4366 while (buf[i] && (i < (PBUFSIZ - 8)))
4368 /* bad caller may have sent forbidden characters */
4369 if ((!isprint (buf[i])) || (buf[i] == '$') || (buf[i] == '#'))
4370 error ("illegal characters in query string");
4378 error ("query larger than available buffer");
4390 remote_rcmd (char *command,
4391 struct gdb_file *outbuf)
4394 char *buf = alloca (PBUFSIZ);
4398 error ("remote rcmd is only available after target open");
4400 /* Send a NULL command across as an empty command */
4401 if (command == NULL)
4404 /* The query prefix */
4405 strcpy (buf, "qRcmd,");
4406 p = strchr (buf, '\0');
4408 if ((strlen (buf) + strlen (command) * 2 + 8/*misc*/) > PBUFSIZ)
4409 error ("\"monitor\" command ``%s'' is too long\n", command);
4411 /* Encode the actual command */
4412 for (i = 0; command[i]; i++)
4414 *p++ = tohex ((command[i] >> 4) & 0xf);
4415 *p++ = tohex (command[i] & 0xf);
4419 if (putpkt (buf) < 0)
4420 error ("Communication problem with target\n");
4422 /* get/display the response */
4425 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
4429 error ("Target does not support this command\n");
4430 if (buf[0] == 'O' && buf[1] != 'K')
4432 remote_console_output (buf + 1); /* 'O' message from stub */
4435 if (strcmp (buf, "OK") == 0)
4437 if (strlen (buf) == 3 && buf[0] == 'E'
4438 && isdigit (buf[1]) && isdigit (buf[2]))
4440 error ("Protocol error with Rcmd");
4442 for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
4444 char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
4445 fputc_unfiltered (c, outbuf);
4452 packet_command (args, from_tty)
4456 char *buf = alloca (PBUFSIZ);
4459 error ("command can only be used with remote target");
4462 error ("remote-packet command requires packet text as argument");
4464 puts_filtered ("sending: ");
4465 print_packet (args);
4466 puts_filtered ("\n");
4470 puts_filtered ("received: ");
4472 puts_filtered ("\n");
4476 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
4478 static void display_thread_info PARAMS ((struct gdb_ext_thread_info * info));
4480 static void threadset_test_cmd PARAMS ((char *cmd, int tty));
4482 static void threadalive_test PARAMS ((char *cmd, int tty));
4484 static void threadlist_test_cmd PARAMS ((char *cmd, int tty));
4486 int get_and_display_threadinfo PARAMS ((threadref * ref));
4488 static void threadinfo_test_cmd PARAMS ((char *cmd, int tty));
4490 static int thread_display_step PARAMS ((threadref * ref, void *context));
4492 static void threadlist_update_test_cmd PARAMS ((char *cmd, int tty));
4494 static void init_remote_threadtests PARAMS ((void));
4496 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
4499 threadset_test_cmd (cmd, tty)
4503 int sample_thread = SAMPLE_THREAD;
4505 printf_filtered ("Remote threadset test\n");
4506 set_thread (sample_thread, 1);
4511 threadalive_test (cmd, tty)
4515 int sample_thread = SAMPLE_THREAD;
4517 if (remote_thread_alive (sample_thread))
4518 printf_filtered ("PASS: Thread alive test\n");
4520 printf_filtered ("FAIL: Thread alive test\n");
4523 void output_threadid PARAMS ((char *title, threadref * ref));
4526 output_threadid (title, ref)
4532 pack_threadid (&hexid[0], ref); /* Convert threead id into hex */
4534 printf_filtered ("%s %s\n", title, (&hexid[0]));
4538 threadlist_test_cmd (cmd, tty)
4543 threadref nextthread;
4544 int done, result_count;
4545 threadref threadlist[3];
4547 printf_filtered ("Remote Threadlist test\n");
4548 if (!remote_get_threadlist (startflag, &nextthread, 3, &done,
4549 &result_count, &threadlist[0]))
4550 printf_filtered ("FAIL: threadlist test\n");
4553 threadref *scan = threadlist;
4554 threadref *limit = scan + result_count;
4556 while (scan < limit)
4557 output_threadid (" thread ", scan++);
4562 display_thread_info (info)
4563 struct gdb_ext_thread_info *info;
4565 output_threadid ("Threadid: ", &info->threadid);
4566 printf_filtered ("Name: %s\n ", info->shortname);
4567 printf_filtered ("State: %s\n", info->display);
4568 printf_filtered ("other: %s\n\n", info->more_display);
4572 get_and_display_threadinfo (ref)
4577 struct gdb_ext_thread_info threadinfo;
4579 set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
4580 | TAG_MOREDISPLAY | TAG_DISPLAY;
4581 if (0 != (result = remote_get_threadinfo (ref, set, &threadinfo)))
4582 display_thread_info (&threadinfo);
4587 threadinfo_test_cmd (cmd, tty)
4591 int athread = SAMPLE_THREAD;
4595 int_to_threadref (&thread, athread);
4596 printf_filtered ("Remote Threadinfo test\n");
4597 if (!get_and_display_threadinfo (&thread))
4598 printf_filtered ("FAIL cannot get thread info\n");
4602 thread_display_step (ref, context)
4606 /* output_threadid(" threadstep ",ref); *//* simple test */
4607 return get_and_display_threadinfo (ref);
4611 threadlist_update_test_cmd (cmd, tty)
4615 printf_filtered ("Remote Threadlist update test\n");
4616 remote_threadlist_iterator (thread_display_step, 0, CRAZY_MAX_THREADS);
4620 init_remote_threadtests (void)
4622 add_com ("tlist", class_obscure, threadlist_test_cmd,
4623 "Fetch and print the remote list of thread identifiers, one pkt only");
4624 add_com ("tinfo", class_obscure, threadinfo_test_cmd,
4625 "Fetch and display info about one thread");
4626 add_com ("tset", class_obscure, threadset_test_cmd,
4627 "Test setting to a different thread");
4628 add_com ("tupd", class_obscure, threadlist_update_test_cmd,
4629 "Iterate through updating all remote thread info");
4630 add_com ("talive", class_obscure, threadalive_test,
4631 " Remote thread alive test ");
4639 remote_ops.to_shortname = "remote";
4640 remote_ops.to_longname = "Remote serial target in gdb-specific protocol";
4642 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4643 Specify the serial device it is connected to (e.g. /dev/ttya).";
4644 remote_ops.to_open = remote_open;
4645 remote_ops.to_close = remote_close;
4646 remote_ops.to_detach = remote_detach;
4647 remote_ops.to_resume = remote_resume;
4648 remote_ops.to_wait = remote_wait;
4649 remote_ops.to_fetch_registers = remote_fetch_registers;
4650 remote_ops.to_store_registers = remote_store_registers;
4651 remote_ops.to_prepare_to_store = remote_prepare_to_store;
4652 remote_ops.to_xfer_memory = remote_xfer_memory;
4653 remote_ops.to_files_info = remote_files_info;
4654 remote_ops.to_insert_breakpoint = remote_insert_breakpoint;
4655 remote_ops.to_remove_breakpoint = remote_remove_breakpoint;
4656 remote_ops.to_kill = remote_kill;
4657 remote_ops.to_load = generic_load;
4658 remote_ops.to_mourn_inferior = remote_mourn;
4659 remote_ops.to_thread_alive = remote_thread_alive;
4660 remote_ops.to_find_new_threads = remote_threads_info;
4661 remote_ops.to_stop = remote_stop;
4662 remote_ops.to_query = remote_query;
4663 remote_ops.to_rcmd = remote_rcmd;
4664 remote_ops.to_stratum = process_stratum;
4665 remote_ops.to_has_all_memory = 1;
4666 remote_ops.to_has_memory = 1;
4667 remote_ops.to_has_stack = 1;
4668 remote_ops.to_has_registers = 1;
4669 remote_ops.to_has_execution = 1;
4670 remote_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */
4671 remote_ops.to_magic = OPS_MAGIC;
4674 /* Set up the extended remote vector by making a copy of the standard
4675 remote vector and adding to it. */
4678 init_extended_remote_ops ()
4680 extended_remote_ops = remote_ops;
4682 extended_remote_ops.to_shortname = "extended-remote";
4683 extended_remote_ops.to_longname =
4684 "Extended remote serial target in gdb-specific protocol";
4685 extended_remote_ops.to_doc =
4686 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4687 Specify the serial device it is connected to (e.g. /dev/ttya).",
4688 extended_remote_ops.to_open = extended_remote_open;
4689 extended_remote_ops.to_create_inferior = extended_remote_create_inferior;
4690 extended_remote_ops.to_mourn_inferior = extended_remote_mourn;
4694 * Command: info remote-process
4696 * This implements Cisco's version of the "info proc" command.
4698 * This query allows the target stub to return an arbitrary string
4699 * (or strings) giving arbitrary information about the target process.
4700 * This is optional; the target stub isn't required to implement it.
4702 * Syntax: qfProcessInfo request first string
4703 * qsProcessInfo request subsequent string
4704 * reply: 'O'<hex-encoded-string>
4705 * 'l' last reply (empty)
4709 remote_info_process (args, from_tty)
4713 char *buf = alloca (PBUFSIZ);
4715 if (remote_desc == 0)
4716 error ("Command can only be used when connected to the remote target.");
4718 putpkt ("qfProcessInfo");
4721 return; /* Silently: target does not support this feature. */
4724 error ("info proc: target error.");
4726 while (buf[0] == 'O') /* Capitol-O packet */
4728 remote_console_output (&buf[1]);
4729 putpkt ("qsProcessInfo");
4739 remote_cisco_open (name, from_tty)
4745 "To open a remote debug connection, you need to specify what \n\
4746 device is attached to the remote system (e.g. host:port).");
4748 /* See FIXME above */
4749 wait_forever_enabled_p = 1;
4751 target_preopen (from_tty);
4753 unpush_target (&remote_cisco_ops);
4755 remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
4757 remote_desc = SERIAL_OPEN (name);
4759 perror_with_name (name);
4762 * If a baud rate was specified on the gdb command line it will
4763 * be greater than the initial value of -1. If it is, use it otherwise
4767 baud_rate = (baud_rate > 0) ? baud_rate : 9600;
4768 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
4770 SERIAL_CLOSE (remote_desc);
4771 perror_with_name (name);
4774 SERIAL_RAW (remote_desc);
4776 /* If there is something sitting in the buffer we might take it as a
4777 response to a command, which would be bad. */
4778 SERIAL_FLUSH_INPUT (remote_desc);
4782 puts_filtered ("Remote debugging using ");
4783 puts_filtered (name);
4784 puts_filtered ("\n");
4787 remote_cisco_mode = 1;
4789 push_target (&remote_cisco_ops); /* Switch to using cisco target now */
4791 init_packet_config (&remote_protocol_P);
4792 init_packet_config (&remote_protocol_Z);
4794 general_thread = -2;
4795 continue_thread = -2;
4797 /* Force remote_write_bytes to check whether target supports
4798 binary downloading. */
4799 init_packet_config (&remote_protocol_binary_download);
4801 /* Without this, some commands which require an active target (such
4802 as kill) won't work. This variable serves (at least) double duty
4803 as both the pid of the target process (if it has such), and as a
4804 flag indicating that a target is active. These functions should
4805 be split out into seperate variables, especially since GDB will
4806 someday have a notion of debugging several processes. */
4807 inferior_pid = MAGIC_NULL_PID;
4809 /* Start the remote connection; if error (0), discard this target. */
4811 if (!catch_errors (remote_start_remote_dummy, (char *) 0,
4812 "Couldn't establish connection to remote target\n",
4821 remote_cisco_close (quitting)
4824 remote_cisco_mode = 0;
4825 remote_close (quitting);
4832 remote_mourn_1 (&remote_cisco_ops);
4844 /* shared between readsocket() and readtty() */
4845 static char *tty_input;
4847 static int escape_count;
4848 static int echo_check;
4849 extern int quit_flag;
4856 /* Loop until the socket doesn't have any more data */
4858 while ((data = readchar (0)) >= 0)
4860 /* Check for the escape sequence */
4863 /* If this is the fourth escape, get out */
4864 if (++escape_count == 4)
4869 { /* This is a '|', but not the fourth in a row.
4870 Continue without echoing it. If it isn't actually
4871 one of four in a row, it'll be echoed later. */
4878 /* Ensure any pending '|'s are flushed. */
4880 for (; escape_count > 0; escape_count--)
4884 if (data == '\r') /* If this is a return character, */
4885 continue; /* - just supress it. */
4887 if (echo_check != -1) /* Check for echo of user input. */
4889 if (tty_input[echo_check] == data)
4891 echo_check++; /* Character matched user input: */
4892 continue; /* Continue without echoing it. */
4894 else if ((data == '\n') && (tty_input[echo_check] == '\r'))
4895 { /* End of the line (and of echo checking). */
4896 echo_check = -1; /* No more echo supression */
4897 continue; /* Continue without echoing. */
4900 { /* Failed check for echo of user input.
4901 We now have some suppressed output to flush! */
4904 for (j = 0; j < echo_check; j++)
4905 putchar (tty_input[j]);
4909 putchar (data); /* Default case: output the char. */
4912 if (data == SERIAL_TIMEOUT) /* Timeout returned from readchar. */
4913 return READ_MORE; /* Try to read some more */
4915 return FATAL_ERROR; /* Trouble, bail out */
4923 /* First, read a buffer full from the terminal */
4924 tty_bytecount = read (fileno (stdin), tty_input, sizeof (tty_input) - 1);
4925 if (tty_bytecount == -1)
4927 perror ("readtty: read failed");
4931 /* Remove a quoted newline. */
4932 if (tty_input[tty_bytecount - 1] == '\n' &&
4933 tty_input[tty_bytecount - 2] == '\\') /* line ending in backslash */
4935 tty_input[--tty_bytecount] = 0; /* remove newline */
4936 tty_input[--tty_bytecount] = 0; /* remove backslash */
4939 /* Turn trailing newlines into returns */
4940 if (tty_input[tty_bytecount - 1] == '\n')
4941 tty_input[tty_bytecount - 1] = '\r';
4943 /* If the line consists of a ~, enter debugging mode. */
4944 if ((tty_input[0] == '~') && (tty_bytecount == 2))
4947 /* Make this a zero terminated string and write it out */
4948 tty_input[tty_bytecount] = 0;
4949 if (SERIAL_WRITE (remote_desc, tty_input, tty_bytecount))
4951 perror_with_name ("readtty: write failed");
4961 fd_set input; /* file descriptors for select */
4962 int tablesize; /* max number of FDs for select */
4966 extern int escape_count; /* global shared by readsocket */
4967 extern int echo_check; /* ditto */
4972 tablesize = 8 * sizeof (input);
4976 /* Check for anything from our socket - doesn't block. Note that
4977 this must be done *before* the select as there may be
4978 buffered I/O waiting to be processed. */
4980 if ((status = readsocket ()) == FATAL_ERROR)
4982 error ("Debugging terminated by communications error");
4984 else if (status != READ_MORE)
4989 fflush (stdout); /* Flush output before blocking */
4991 /* Now block on more socket input or TTY input */
4994 FD_SET (fileno (stdin), &input);
4995 FD_SET (DEPRECATED_SERIAL_FD (remote_desc), &input);
4997 status = select (tablesize, &input, 0, 0, 0);
4998 if ((status == -1) && (errno != EINTR))
5000 error ("Communications error on select %d", errno);
5003 /* Handle Control-C typed */
5007 if ((++quit_count) == 2)
5009 if (query ("Interrupt GDB? "))
5011 printf_filtered ("Interrupted by user.\n");
5012 return_to_top_level (RETURN_QUIT);
5019 SERIAL_SEND_BREAK (remote_desc);
5021 SERIAL_WRITE (remote_desc, "\003", 1);
5026 /* Handle console input */
5028 if (FD_ISSET (fileno (stdin), &input))
5032 status = readtty ();
5033 if (status == READ_MORE)
5036 return status; /* telnet session ended */
5042 remote_cisco_wait (pid, status)
5044 struct target_waitstatus *status;
5046 if (minitelnet () != ENTER_DEBUG)
5048 error ("Debugging session terminated by protocol error");
5051 return remote_wait (pid, status);
5055 init_remote_cisco_ops ()
5057 remote_cisco_ops.to_shortname = "cisco";
5058 remote_cisco_ops.to_longname = "Remote serial target in cisco-specific protocol";
5059 remote_cisco_ops.to_doc =
5060 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5061 Specify the serial device it is connected to (e.g. host:2020).";
5062 remote_cisco_ops.to_open = remote_cisco_open;
5063 remote_cisco_ops.to_close = remote_cisco_close;
5064 remote_cisco_ops.to_detach = remote_detach;
5065 remote_cisco_ops.to_resume = remote_resume;
5066 remote_cisco_ops.to_wait = remote_cisco_wait;
5067 remote_cisco_ops.to_fetch_registers = remote_fetch_registers;
5068 remote_cisco_ops.to_store_registers = remote_store_registers;
5069 remote_cisco_ops.to_prepare_to_store = remote_prepare_to_store;
5070 remote_cisco_ops.to_xfer_memory = remote_xfer_memory;
5071 remote_cisco_ops.to_files_info = remote_files_info;
5072 remote_cisco_ops.to_insert_breakpoint = remote_insert_breakpoint;
5073 remote_cisco_ops.to_remove_breakpoint = remote_remove_breakpoint;
5074 remote_cisco_ops.to_kill = remote_kill;
5075 remote_cisco_ops.to_load = generic_load;
5076 remote_cisco_ops.to_mourn_inferior = remote_cisco_mourn;
5077 remote_cisco_ops.to_thread_alive = remote_thread_alive;
5078 remote_cisco_ops.to_find_new_threads = remote_threads_info;
5079 remote_cisco_ops.to_stratum = process_stratum;
5080 remote_cisco_ops.to_has_all_memory = 1;
5081 remote_cisco_ops.to_has_memory = 1;
5082 remote_cisco_ops.to_has_stack = 1;
5083 remote_cisco_ops.to_has_registers = 1;
5084 remote_cisco_ops.to_has_execution = 1;
5085 remote_cisco_ops.to_magic = OPS_MAGIC;
5089 remote_can_async_p (void)
5091 /* We're async whenever the serial device is. */
5092 return SERIAL_CAN_ASYNC_P (remote_desc);
5096 remote_is_async_p (void)
5098 /* We're async whenever the serial device is. */
5099 return SERIAL_IS_ASYNC_P (remote_desc);
5102 /* Pass the SERIAL event on and up to the client. One day this code
5103 will be able to delay notifying the client of an event until the
5104 point where an entire packet has been received. */
5106 static void (*async_client_callback) (enum inferior_event_type event_type, void *context);
5107 static void *async_client_context;
5108 static serial_event_ftype remote_async_serial_handler;
5111 remote_async_serial_handler (serial_t scb, void *context)
5113 /* Don't propogate error information up to the client. Instead let
5114 the client find out about the error by querying the target. */
5115 async_client_callback (INF_REG_EVENT, async_client_context);
5119 remote_async (void (*callback) (enum inferior_event_type event_type, void *context), void *context)
5121 if (callback != NULL)
5123 SERIAL_ASYNC (remote_desc, remote_async_serial_handler, NULL);
5124 async_client_callback = callback;
5125 async_client_context = context;
5128 SERIAL_ASYNC (remote_desc, NULL, NULL);
5131 /* Target async and target extended-async.
5133 This are temporary targets, until it is all tested. Eventually
5134 async support will be incorporated int the usual 'remote'
5138 init_remote_async_ops ()
5140 remote_async_ops.to_shortname = "async";
5141 remote_async_ops.to_longname = "Remote serial target in async version of the gdb-specific protocol";
5142 remote_async_ops.to_doc =
5143 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5144 Specify the serial device it is connected to (e.g. /dev/ttya).";
5145 remote_async_ops.to_open = remote_async_open;
5146 remote_async_ops.to_close = remote_close;
5147 remote_async_ops.to_detach = remote_async_detach;
5148 remote_async_ops.to_resume = remote_async_resume;
5149 remote_async_ops.to_wait = remote_async_wait;
5150 remote_async_ops.to_fetch_registers = remote_fetch_registers;
5151 remote_async_ops.to_store_registers = remote_store_registers;
5152 remote_async_ops.to_prepare_to_store = remote_prepare_to_store;
5153 remote_async_ops.to_xfer_memory = remote_xfer_memory;
5154 remote_async_ops.to_files_info = remote_files_info;
5155 remote_async_ops.to_insert_breakpoint = remote_insert_breakpoint;
5156 remote_async_ops.to_remove_breakpoint = remote_remove_breakpoint;
5157 remote_async_ops.to_terminal_inferior = remote_async_terminal_inferior;
5158 remote_async_ops.to_terminal_ours = remote_async_terminal_ours;
5159 remote_async_ops.to_kill = remote_async_kill;
5160 remote_async_ops.to_load = generic_load;
5161 remote_async_ops.to_mourn_inferior = remote_async_mourn;
5162 remote_async_ops.to_thread_alive = remote_thread_alive;
5163 remote_async_ops.to_find_new_threads = remote_threads_info;
5164 remote_async_ops.to_stop = remote_stop;
5165 remote_async_ops.to_query = remote_query;
5166 remote_async_ops.to_rcmd = remote_rcmd;
5167 remote_async_ops.to_stratum = process_stratum;
5168 remote_async_ops.to_has_all_memory = 1;
5169 remote_async_ops.to_has_memory = 1;
5170 remote_async_ops.to_has_stack = 1;
5171 remote_async_ops.to_has_registers = 1;
5172 remote_async_ops.to_has_execution = 1;
5173 remote_async_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */
5174 remote_async_ops.to_can_async_p = remote_can_async_p;
5175 remote_async_ops.to_is_async_p = remote_is_async_p;
5176 remote_async_ops.to_async = remote_async;
5177 remote_async_ops.to_magic = OPS_MAGIC;
5180 /* Set up the async extended remote vector by making a copy of the standard
5181 remote vector and adding to it. */
5184 init_extended_async_remote_ops ()
5186 extended_async_remote_ops = remote_async_ops;
5188 extended_async_remote_ops.to_shortname = "extended-async";
5189 extended_async_remote_ops.to_longname =
5190 "Extended remote serial target in async gdb-specific protocol";
5191 extended_async_remote_ops.to_doc =
5192 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5193 Specify the serial device it is connected to (e.g. /dev/ttya).",
5194 extended_async_remote_ops.to_open = extended_remote_async_open;
5195 extended_async_remote_ops.to_create_inferior = extended_remote_async_create_inferior;
5196 extended_async_remote_ops.to_mourn_inferior = extended_remote_mourn;
5200 set_remote_cmd (args, from_tty)
5209 build_remote_gdbarch_data ()
5211 tty_input = xmalloc (PBUFSIZ);
5215 _initialize_remote ()
5217 static struct cmd_list_element *remote_set_cmdlist;
5218 static struct cmd_list_element *remote_show_cmdlist;
5220 /* architecture specific data */
5221 build_remote_gdbarch_data ();
5222 register_gdbarch_swap (&tty_input, sizeof (&tty_input), NULL);
5223 register_gdbarch_swap (NULL, 0, build_remote_gdbarch_data);
5225 /* runtime constants - we retain the value of remote_write_size
5226 across architecture swaps. */
5227 remote_write_size = PBUFSIZ;
5230 add_target (&remote_ops);
5232 init_extended_remote_ops ();
5233 add_target (&extended_remote_ops);
5235 init_remote_async_ops ();
5236 add_target (&remote_async_ops);
5238 init_extended_async_remote_ops ();
5239 add_target (&extended_async_remote_ops);
5241 init_remote_cisco_ops ();
5242 add_target (&remote_cisco_ops);
5245 init_remote_threadtests ();
5248 add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, "\
5249 Remote protocol specific variables\n\
5250 Configure various remote-protocol specific variables such as\n\
5251 the packets being used",
5252 &remote_set_cmdlist, "set remote ",
5253 0/*allow-unknown*/, &setlist);
5254 add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, "\
5255 Remote protocol specific variables\n\
5256 Configure various remote-protocol specific variables such as\n\
5257 the packets being used",
5258 &remote_show_cmdlist, "show remote ",
5259 0/*allow-unknown*/, &showlist);
5261 add_cmd ("compare-sections", class_obscure, compare_sections_command,
5262 "Compare section data on target to the exec file.\n\
5263 Argument is a single section name (default: all loaded sections).",
5266 add_cmd ("packet", class_maintenance, packet_command,
5267 "Send an arbitrary packet to a remote target.\n\
5268 maintenance packet TEXT\n\
5269 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5270 this command sends the string TEXT to the inferior, and displays the\n\
5271 response packet. GDB supplies the initial `$' character, and the\n\
5272 terminating `#' character and checksum.",
5276 (add_set_cmd ("remotetimeout", no_class,
5277 var_integer, (char *) &remote_timeout,
5278 "Set timeout value for remote read.\n",
5283 (add_set_cmd ("remotebreak", no_class,
5284 var_boolean, (char *) &remote_break,
5285 "Set whether to send break if interrupted.\n",
5290 (add_set_cmd ("remotewritesize", no_class,
5291 var_integer, (char *) &remote_write_size,
5292 "Set the maximum number of bytes per memory write packet.\n",
5296 remote_address_size = TARGET_PTR_BIT;
5298 (add_set_cmd ("remoteaddresssize", class_obscure,
5299 var_integer, (char *) &remote_address_size,
5300 "Set the maximum size of the address (in bits) \
5301 in a memory packet.\n",
5305 add_packet_config_cmd (&remote_protocol_binary_download,
5306 "X", "binary-download",
5307 set_remote_protocol_binary_download_cmd,
5308 show_remote_protocol_binary_download_cmd,
5309 &remote_set_cmdlist, &remote_show_cmdlist);
5311 /* XXXX - should ``set remotebinarydownload'' be retained for
5314 (add_set_cmd ("remotebinarydownload", no_class,
5315 var_boolean, (char *) &remote_binary_download,
5316 "Set binary downloads.\n", &setlist),
5320 add_info ("remote-process", remote_info_process,
5321 "Query the remote system for process info.");
5323 add_packet_config_cmd (&remote_protocol_P, "P", "set-register",
5324 set_remote_protocol_P_packet_cmd,
5325 show_remote_protocol_P_packet_cmd,
5326 &remote_set_cmdlist, &remote_show_cmdlist);
5328 add_packet_config_cmd (&remote_protocol_Z, "Z", "breakpoint",
5329 set_remote_protocol_Z_packet_cmd,
5330 show_remote_protocol_Z_packet_cmd,
5331 &remote_set_cmdlist, &remote_show_cmdlist);