1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001 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"
32 /*#include "terminal.h" */
35 #include "gdb-stabs.h"
36 #include "gdbthread.h"
40 #include "gdb_assert.h"
45 #include <sys/types.h>
48 #include "event-loop.h"
49 #include "event-top.h"
55 #include "gdbcore.h" /* for exec_bfd */
57 /* Prototypes for local functions */
58 static void cleanup_sigint_signal_handler (void *dummy
);
59 static void initialize_sigint_signal_handler (void);
60 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
62 static void handle_remote_sigint (int);
63 static void handle_remote_sigint_twice (int);
64 static void async_remote_interrupt (gdb_client_data
);
65 void async_remote_interrupt_twice (gdb_client_data
);
67 static void build_remote_gdbarch_data (void);
69 static int remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
71 static int remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
73 static void remote_files_info (struct target_ops
*ignore
);
75 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
76 int len
, int should_write
,
77 struct mem_attrib
*attrib
,
78 struct target_ops
*target
);
80 static void remote_prepare_to_store (void);
82 static void remote_fetch_registers (int regno
);
84 static void remote_resume (ptid_t ptid
, int step
,
85 enum target_signal siggnal
);
86 static void remote_async_resume (ptid_t ptid
, int step
,
87 enum target_signal siggnal
);
88 static int remote_start_remote (PTR
);
90 static void remote_open (char *name
, int from_tty
);
91 static void remote_async_open (char *name
, int from_tty
);
93 static void extended_remote_open (char *name
, int from_tty
);
94 static void extended_remote_async_open (char *name
, int from_tty
);
96 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
97 static void remote_async_open_1 (char *, int, struct target_ops
*,
100 static void remote_close (int quitting
);
102 static void remote_store_registers (int regno
);
104 static void remote_mourn (void);
105 static void remote_async_mourn (void);
107 static void extended_remote_restart (void);
109 static void extended_remote_mourn (void);
111 static void extended_remote_create_inferior (char *, char *, char **);
112 static void extended_remote_async_create_inferior (char *, char *, char **);
114 static void remote_mourn_1 (struct target_ops
*);
116 static void remote_send (char *buf
, long sizeof_buf
);
118 static int readchar (int timeout
);
120 static ptid_t
remote_wait (ptid_t ptid
,
121 struct target_waitstatus
*status
);
122 static ptid_t
remote_async_wait (ptid_t ptid
,
123 struct target_waitstatus
*status
);
125 static void remote_kill (void);
126 static void remote_async_kill (void);
128 static int tohex (int nib
);
130 static void remote_detach (char *args
, int from_tty
);
131 static void remote_async_detach (char *args
, int from_tty
);
133 static void remote_interrupt (int signo
);
135 static void remote_interrupt_twice (int signo
);
137 static void interrupt_query (void);
139 static void set_thread (int, int);
141 static int remote_thread_alive (ptid_t
);
143 static void get_offsets (void);
145 static long read_frame (char *buf
, long sizeof_buf
);
147 static int remote_insert_breakpoint (CORE_ADDR
, char *);
149 static int remote_remove_breakpoint (CORE_ADDR
, char *);
151 static int hexnumlen (ULONGEST num
);
153 static void init_remote_ops (void);
155 static void init_extended_remote_ops (void);
157 static void init_remote_cisco_ops (void);
159 static struct target_ops remote_cisco_ops
;
161 static void remote_stop (void);
163 static int ishex (int ch
, int *val
);
165 static int stubhex (int ch
);
167 static int remote_query (int /*char */ , char *, char *, int *);
169 static int hexnumstr (char *, ULONGEST
);
171 static int hexnumnstr (char *, ULONGEST
, int);
173 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
175 static void print_packet (char *);
177 static unsigned long crc32 (unsigned char *, int, unsigned int);
179 static void compare_sections_command (char *, int);
181 static void packet_command (char *, int);
183 static int stub_unpack_int (char *buff
, int fieldlength
);
185 static ptid_t
remote_current_thread (ptid_t oldptid
);
187 static void remote_find_new_threads (void);
189 static void record_currthread (int currthread
);
191 static int fromhex (int a
);
193 static int hex2bin (const char *hex
, char *bin
, int count
);
195 static int bin2hex (const char *bin
, char *hex
, int count
);
197 static int putpkt_binary (char *buf
, int cnt
);
199 static void check_binary_download (CORE_ADDR addr
);
201 struct packet_config
;
203 static void show_packet_config_cmd (struct packet_config
*config
);
205 static void update_packet_config (struct packet_config
*config
);
207 /* Define the target subroutine names */
209 void open_remote_target (char *, int, struct target_ops
*, int);
211 void _initialize_remote (void);
213 /* Description of the remote protocol. Strictly speeking, when the
214 target is open()ed, remote.c should create a per-target description
215 of the remote protocol using that target's architecture.
216 Unfortunatly, the target stack doesn't include local state. For
217 the moment keep the information in the target's architecture
222 /* This is the size (in chars) of the first response to the ``g''
223 packet. It is used as a heuristic when determining the maximum
224 size of memory-read and memory-write packets. A target will
225 typically only reserve a buffer large enough to hold the ``g''
226 packet. The size does not include packet overhead (headers and
228 long actual_register_packet_size
;
230 /* This is the maximum size (in chars) of a non read/write packet.
231 It is also used as a cap on the size of read/write packets. */
232 long remote_packet_size
;
235 /* Handle for retreving the remote protocol data from gdbarch. */
236 static struct gdbarch_data
*remote_gdbarch_data_handle
;
238 static struct remote_state
*
241 return gdbarch_data (remote_gdbarch_data_handle
);
245 init_remote_state (struct gdbarch
*gdbarch
)
248 struct remote_state
*rs
= xmalloc (sizeof (struct remote_state
));
250 /* Default maximum number of characters in a packet body. Many
251 remote stubs have a hardwired buffer size of 400 bytes
252 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
253 as the maximum packet-size to ensure that the packet and an extra
254 NUL character can always fit in the buffer. This stops GDB
255 trashing stubs that try to squeeze an extra NUL into what is
256 already a full buffer (As of 1999-12-04 that was most stubs. */
257 rs
->remote_packet_size
= 400 - 1;
259 /* Should REGISTER_BYTES needs more space than the default, adjust
260 the size accordingly. Remember that each byte is encoded as two
261 characters. 32 is the overhead for the packet header /
262 footer. NOTE: cagney/1999-10-26: I suspect that 8
263 (``$NN:G...#NN'') is a better guess, the below has been padded a
265 if (REGISTER_BYTES
> ((rs
->remote_packet_size
- 32) / 2))
266 rs
->remote_packet_size
= (REGISTER_BYTES
* 2 + 32);
268 /* This one is filled in when a ``g'' packet is received. */
269 rs
->actual_register_packet_size
= 0;
275 free_remote_state (struct gdbarch
*gdbarch
, void *pointer
)
277 struct remote_state
*state
= pointer
;
283 static struct target_ops remote_ops
;
285 static struct target_ops extended_remote_ops
;
287 /* Temporary target ops. Just like the remote_ops and
288 extended_remote_ops, but with asynchronous support. */
289 static struct target_ops remote_async_ops
;
291 static struct target_ops extended_async_remote_ops
;
293 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
294 ``forever'' still use the normal timeout mechanism. This is
295 currently used by the ASYNC code to guarentee that target reads
296 during the initial connect always time-out. Once getpkt has been
297 modified to return a timeout indication and, in turn
298 remote_wait()/wait_for_inferior() have gained a timeout parameter
300 static int wait_forever_enabled_p
= 1;
303 /* This variable chooses whether to send a ^C or a break when the user
304 requests program interruption. Although ^C is usually what remote
305 systems expect, and that is the default here, sometimes a break is
306 preferable instead. */
308 static int remote_break
;
310 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
311 remote_open knows that we don't have a file open when the program
313 static struct serial
*remote_desc
= NULL
;
315 /* This is set by the target (thru the 'S' message)
316 to denote that the target is in kernel mode. */
317 static int cisco_kernel_mode
= 0;
319 /* This variable sets the number of bits in an address that are to be
320 sent in a memory ("M" or "m") packet. Normally, after stripping
321 leading zeros, the entire address would be sent. This variable
322 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
323 initial implementation of remote.c restricted the address sent in
324 memory packets to ``host::sizeof long'' bytes - (typically 32
325 bits). Consequently, for 64 bit targets, the upper 32 bits of an
326 address was never sent. Since fixing this bug may cause a break in
327 some remote targets this variable is principly provided to
328 facilitate backward compatibility. */
330 static int remote_address_size
;
332 /* Tempoary to track who currently owns the terminal. See
333 target_async_terminal_* for more details. */
335 static int remote_async_terminal_ours_p
;
338 /* User configurable variables for the number of characters in a
339 memory read/write packet. MIN ((rs->remote_packet_size), g-packet-size) is the
340 default. Some targets need smaller values (fifo overruns, et.al.)
341 and some users need larger values (speed up transfers). The
342 variables ``preferred_*'' (the user request), ``current_*'' (what
343 was actually set) and ``forced_*'' (Positive - a soft limit,
344 negative - a hard limit). */
346 struct memory_packet_config
353 /* Compute the current size of a read/write packet. Since this makes
354 use of ``actual_register_packet_size'' the computation is dynamic. */
357 get_memory_packet_size (struct memory_packet_config
*config
)
359 struct remote_state
*rs
= get_remote_state ();
360 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
361 law?) that some hosts don't cope very well with large alloca()
362 calls. Eventually the alloca() code will be replaced by calls to
363 xmalloc() and make_cleanups() allowing this restriction to either
364 be lifted or removed. */
365 #ifndef MAX_REMOTE_PACKET_SIZE
366 #define MAX_REMOTE_PACKET_SIZE 16384
368 /* NOTE: 16 is just chosen at random. */
369 #ifndef MIN_REMOTE_PACKET_SIZE
370 #define MIN_REMOTE_PACKET_SIZE 16
375 if (config
->size
<= 0)
376 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
378 what_they_get
= config
->size
;
382 what_they_get
= (rs
->remote_packet_size
);
383 /* Limit the packet to the size specified by the user. */
385 && what_they_get
> config
->size
)
386 what_they_get
= config
->size
;
387 /* Limit it to the size of the targets ``g'' response. */
388 if ((rs
->actual_register_packet_size
) > 0
389 && what_they_get
> (rs
->actual_register_packet_size
))
390 what_they_get
= (rs
->actual_register_packet_size
);
392 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
393 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
394 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
395 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
396 return what_they_get
;
399 /* Update the size of a read/write packet. If they user wants
400 something really big then do a sanity check. */
403 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
405 int fixed_p
= config
->fixed_p
;
406 long size
= config
->size
;
408 error ("Argument required (integer, `fixed' or `limited').");
409 else if (strcmp (args
, "hard") == 0
410 || strcmp (args
, "fixed") == 0)
412 else if (strcmp (args
, "soft") == 0
413 || strcmp (args
, "limit") == 0)
418 size
= strtoul (args
, &end
, 0);
420 error ("Invalid %s (bad syntax).", config
->name
);
422 /* Instead of explicitly capping the size of a packet to
423 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
424 instead allowed to set the size to something arbitrarily
426 if (size
> MAX_REMOTE_PACKET_SIZE
)
427 error ("Invalid %s (too large).", config
->name
);
431 if (fixed_p
&& !config
->fixed_p
)
433 if (! query ("The target may not be able to correctly handle a %s\n"
434 "of %ld bytes. Change the packet size? ",
436 error ("Packet size not changed.");
438 /* Update the config. */
439 config
->fixed_p
= fixed_p
;
444 show_memory_packet_size (struct memory_packet_config
*config
)
446 printf_filtered ("The %s is %ld. ", config
->name
, config
->size
);
448 printf_filtered ("Packets are fixed at %ld bytes.\n",
449 get_memory_packet_size (config
));
451 printf_filtered ("Packets are limited to %ld bytes.\n",
452 get_memory_packet_size (config
));
455 static struct memory_packet_config memory_write_packet_config
=
457 "memory-write-packet-size",
461 set_memory_write_packet_size (char *args
, int from_tty
)
463 set_memory_packet_size (args
, &memory_write_packet_config
);
467 show_memory_write_packet_size (char *args
, int from_tty
)
469 show_memory_packet_size (&memory_write_packet_config
);
473 get_memory_write_packet_size (void)
475 return get_memory_packet_size (&memory_write_packet_config
);
478 static struct memory_packet_config memory_read_packet_config
=
480 "memory-read-packet-size",
484 set_memory_read_packet_size (char *args
, int from_tty
)
486 set_memory_packet_size (args
, &memory_read_packet_config
);
490 show_memory_read_packet_size (char *args
, int from_tty
)
492 show_memory_packet_size (&memory_read_packet_config
);
496 get_memory_read_packet_size (void)
498 struct remote_state
*rs
= get_remote_state ();
499 long size
= get_memory_packet_size (&memory_read_packet_config
);
500 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
501 extra buffer size argument before the memory read size can be
502 increased beyond (rs->remote_packet_size). */
503 if (size
> (rs
->remote_packet_size
))
504 size
= (rs
->remote_packet_size
);
509 /* Generic configuration support for packets the stub optionally
510 supports. Allows the user to specify the use of the packet as well
511 as allowing GDB to auto-detect support in the remote stub. */
515 PACKET_SUPPORT_UNKNOWN
= 0,
524 enum cmd_auto_boolean detect
;
525 enum packet_support support
;
528 /* Analyze a packet's return value and update the packet config
539 update_packet_config (struct packet_config
*config
)
541 switch (config
->detect
)
543 case CMD_AUTO_BOOLEAN_TRUE
:
544 config
->support
= PACKET_ENABLE
;
546 case CMD_AUTO_BOOLEAN_FALSE
:
547 config
->support
= PACKET_DISABLE
;
549 case CMD_AUTO_BOOLEAN_AUTO
:
550 config
->support
= PACKET_SUPPORT_UNKNOWN
;
556 show_packet_config_cmd (struct packet_config
*config
)
558 char *support
= "internal-error";
559 switch (config
->support
)
565 support
= "disabled";
567 case PACKET_SUPPORT_UNKNOWN
:
571 switch (config
->detect
)
573 case CMD_AUTO_BOOLEAN_AUTO
:
574 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
575 config
->name
, config
->title
, support
);
577 case CMD_AUTO_BOOLEAN_TRUE
:
578 case CMD_AUTO_BOOLEAN_FALSE
:
579 printf_filtered ("Support for remote protocol `%s' (%s) packet is currently %s.\n",
580 config
->name
, config
->title
, support
);
586 add_packet_config_cmd (struct packet_config
*config
,
589 void (*set_func
) (char *args
, int from_tty
,
590 struct cmd_list_element
*
592 void (*show_func
) (char *name
,
594 struct cmd_list_element
**set_remote_list
,
595 struct cmd_list_element
**show_remote_list
,
598 struct cmd_list_element
*set_cmd
;
599 struct cmd_list_element
*show_cmd
;
604 config
->title
= title
;
605 config
->detect
= CMD_AUTO_BOOLEAN_AUTO
;
606 config
->support
= PACKET_SUPPORT_UNKNOWN
;
607 xasprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
609 xasprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
611 /* set/show TITLE-packet {auto,on,off} */
612 xasprintf (&cmd_name
, "%s-packet", title
);
613 set_cmd
= add_set_auto_boolean_cmd (cmd_name
, class_obscure
,
614 &config
->detect
, set_doc
,
616 set_cmd
->function
.sfunc
= set_func
;
617 show_cmd
= add_cmd (cmd_name
, class_obscure
, show_func
, show_doc
,
619 /* set/show remote NAME-packet {auto,on,off} -- legacy */
623 xasprintf (&legacy_name
, "%s-packet", name
);
624 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
626 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
631 static enum packet_result
632 packet_ok (const char *buf
, struct packet_config
*config
)
636 /* The stub recognized the packet request. Check that the
637 operation succeeded. */
638 switch (config
->support
)
640 case PACKET_SUPPORT_UNKNOWN
:
642 fprintf_unfiltered (gdb_stdlog
,
643 "Packet %s (%s) is supported\n",
644 config
->name
, config
->title
);
645 config
->support
= PACKET_ENABLE
;
648 internal_error (__FILE__
, __LINE__
,
649 "packet_ok: attempt to use a disabled packet");
654 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
655 /* "OK" - definitly OK. */
658 && isxdigit (buf
[1]) && isxdigit (buf
[2])
660 /* "Enn" - definitly an error. */
662 /* The packet may or may not be OK. Just assume it is */
667 /* The stub does not support the packet. */
668 switch (config
->support
)
671 if (config
->detect
== CMD_AUTO_BOOLEAN_AUTO
)
672 /* If the stub previously indicated that the packet was
673 supported then there is a protocol error.. */
674 error ("Protocol error: %s (%s) conflicting enabled responses.",
675 config
->name
, config
->title
);
677 /* The user set it wrong. */
678 error ("Enabled packet %s (%s) not recognized by stub",
679 config
->name
, config
->title
);
681 case PACKET_SUPPORT_UNKNOWN
:
683 fprintf_unfiltered (gdb_stdlog
,
684 "Packet %s (%s) is NOT supported\n",
685 config
->name
, config
->title
);
686 config
->support
= PACKET_DISABLE
;
691 return PACKET_UNKNOWN
;
695 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
696 static struct packet_config remote_protocol_qSymbol
;
699 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
700 struct cmd_list_element
*c
)
702 update_packet_config (&remote_protocol_qSymbol
);
706 show_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
)
708 show_packet_config_cmd (&remote_protocol_qSymbol
);
711 /* Should we try the 'e' (step over range) request? */
712 static struct packet_config remote_protocol_e
;
715 set_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
716 struct cmd_list_element
*c
)
718 update_packet_config (&remote_protocol_e
);
722 show_remote_protocol_e_packet_cmd (char *args
, int from_tty
)
724 show_packet_config_cmd (&remote_protocol_e
);
728 /* Should we try the 'E' (step over range / w signal #) request? */
729 static struct packet_config remote_protocol_E
;
732 set_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
733 struct cmd_list_element
*c
)
735 update_packet_config (&remote_protocol_E
);
739 show_remote_protocol_E_packet_cmd (char *args
, int from_tty
)
741 show_packet_config_cmd (&remote_protocol_E
);
745 /* Should we try the 'P' (set register) request? */
747 static struct packet_config remote_protocol_P
;
750 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
751 struct cmd_list_element
*c
)
753 update_packet_config (&remote_protocol_P
);
757 show_remote_protocol_P_packet_cmd (char *args
, int from_tty
)
759 show_packet_config_cmd (&remote_protocol_P
);
762 /* Should we try one of the 'Z' requests? */
766 Z_PACKET_SOFTWARE_BP
,
767 Z_PACKET_HARDWARE_BP
,
774 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
776 /* FIXME: Instead of having all these boiler plate functions, the
777 command callback should include a context argument. */
780 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
781 struct cmd_list_element
*c
)
783 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
787 show_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
)
789 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
793 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
794 struct cmd_list_element
*c
)
796 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
800 show_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
)
802 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
806 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
807 struct cmd_list_element
*c
)
809 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
813 show_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
)
815 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
819 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
820 struct cmd_list_element
*c
)
822 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
826 show_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
)
828 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
832 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
833 struct cmd_list_element
*c
)
835 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
839 show_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
)
841 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
844 /* For compatibility with older distributions. Provide a ``set remote
845 Z-packet ...'' command that updates all the Z packet types. */
847 static enum cmd_auto_boolean remote_Z_packet_detect
;
850 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
851 struct cmd_list_element
*c
)
854 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
856 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
857 update_packet_config (&remote_protocol_Z
[i
]);
862 show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
)
865 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
867 show_packet_config_cmd (&remote_protocol_Z
[i
]);
871 /* Should we try the 'X' (remote binary download) packet?
873 This variable (available to the user via "set remote X-packet")
874 dictates whether downloads are sent in binary (via the 'X' packet).
875 We assume that the stub can, and attempt to do it. This will be
876 cleared if the stub does not understand it. This switch is still
877 needed, though in cases when the packet is supported in the stub,
878 but the connection does not allow it (i.e., 7-bit serial connection
881 static struct packet_config remote_protocol_binary_download
;
883 /* Should we try the 'ThreadInfo' query packet?
885 This variable (NOT available to the user: auto-detect only!)
886 determines whether GDB will use the new, simpler "ThreadInfo"
887 query or the older, more complex syntax for thread queries.
888 This is an auto-detect variable (set to true at each connect,
889 and set to false when the target fails to recognize it). */
891 static int use_threadinfo_query
;
892 static int use_threadextra_query
;
895 set_remote_protocol_binary_download_cmd (char *args
,
897 struct cmd_list_element
*c
)
899 update_packet_config (&remote_protocol_binary_download
);
903 show_remote_protocol_binary_download_cmd (char *args
,
906 show_packet_config_cmd (&remote_protocol_binary_download
);
910 /* Tokens for use by the asynchronous signal handlers for SIGINT */
911 PTR sigint_remote_twice_token
;
912 PTR sigint_remote_token
;
914 /* These are pointers to hook functions that may be set in order to
915 modify resume/wait behavior for a particular architecture. */
917 void (*target_resume_hook
) (void);
918 void (*target_wait_loop_hook
) (void);
922 /* These are the threads which we last sent to the remote system.
923 -1 for all or -2 for not sent yet. */
924 static int general_thread
;
925 static int continue_thread
;
927 /* Call this function as a result of
928 1) A halt indication (T packet) containing a thread id
929 2) A direct query of currthread
930 3) Successful execution of set thread
934 record_currthread (int currthread
)
936 general_thread
= currthread
;
938 /* If this is a new thread, add it to GDB's thread list.
939 If we leave it up to WFI to do this, bad things will happen. */
940 if (!in_thread_list (pid_to_ptid (currthread
)))
942 add_thread (pid_to_ptid (currthread
));
944 ui_out_text (uiout
, "[New ");
945 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
946 ui_out_text (uiout
, "]\n");
948 printf_filtered ("[New %s]\n",
949 target_pid_to_str (pid_to_ptid (currthread
)));
954 #define MAGIC_NULL_PID 42000
957 set_thread (int th
, int gen
)
959 struct remote_state
*rs
= get_remote_state ();
960 char *buf
= alloca (rs
->remote_packet_size
);
961 int state
= gen
? general_thread
: continue_thread
;
967 buf
[1] = gen
? 'g' : 'c';
968 if (th
== MAGIC_NULL_PID
)
974 sprintf (&buf
[2], "-%x", -th
);
976 sprintf (&buf
[2], "%x", th
);
978 getpkt (buf
, (rs
->remote_packet_size
), 0);
982 continue_thread
= th
;
985 /* Return nonzero if the thread TH is still alive on the remote system. */
988 remote_thread_alive (ptid_t ptid
)
990 int tid
= PIDGET (ptid
);
994 sprintf (buf
, "T-%08x", -tid
);
996 sprintf (buf
, "T%08x", tid
);
998 getpkt (buf
, sizeof (buf
), 0);
999 return (buf
[0] == 'O' && buf
[1] == 'K');
1002 /* About these extended threadlist and threadinfo packets. They are
1003 variable length packets but, the fields within them are often fixed
1004 length. They are redundent enough to send over UDP as is the
1005 remote protocol in general. There is a matching unit test module
1008 #define OPAQUETHREADBYTES 8
1010 /* a 64 bit opaque identifier */
1011 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1013 /* WARNING: This threadref data structure comes from the remote O.S., libstub
1014 protocol encoding, and remote.c. it is not particularly changable */
1016 /* Right now, the internal structure is int. We want it to be bigger.
1020 typedef int gdb_threadref
; /* internal GDB thread reference */
1022 /* gdb_ext_thread_info is an internal GDB data structure which is
1023 equivalint to the reply of the remote threadinfo packet */
1025 struct gdb_ext_thread_info
1027 threadref threadid
; /* External form of thread reference */
1028 int active
; /* Has state interesting to GDB? , regs, stack */
1029 char display
[256]; /* Brief state display, name, blocked/syspended */
1030 char shortname
[32]; /* To be used to name threads */
1031 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
1034 /* The volume of remote transfers can be limited by submitting
1035 a mask containing bits specifying the desired information.
1036 Use a union of these values as the 'selection' parameter to
1037 get_thread_info. FIXME: Make these TAG names more thread specific.
1040 #define TAG_THREADID 1
1041 #define TAG_EXISTS 2
1042 #define TAG_DISPLAY 4
1043 #define TAG_THREADNAME 8
1044 #define TAG_MOREDISPLAY 16
1046 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
1048 char *unpack_varlen_hex (char *buff
, int *result
);
1050 static char *unpack_nibble (char *buf
, int *val
);
1052 static char *pack_nibble (char *buf
, int nibble
);
1054 static char *pack_hex_byte (char *pkt
, int /*unsigned char */ byte
);
1056 static char *unpack_byte (char *buf
, int *value
);
1058 static char *pack_int (char *buf
, int value
);
1060 static char *unpack_int (char *buf
, int *value
);
1062 static char *unpack_string (char *src
, char *dest
, int length
);
1064 static char *pack_threadid (char *pkt
, threadref
* id
);
1066 static char *unpack_threadid (char *inbuf
, threadref
* id
);
1068 void int_to_threadref (threadref
* id
, int value
);
1070 static int threadref_to_int (threadref
* ref
);
1072 static void copy_threadref (threadref
* dest
, threadref
* src
);
1074 static int threadmatch (threadref
* dest
, threadref
* src
);
1076 static char *pack_threadinfo_request (char *pkt
, int mode
, threadref
* id
);
1078 static int remote_unpack_thread_info_response (char *pkt
,
1079 threadref
* expectedref
,
1080 struct gdb_ext_thread_info
1084 static int remote_get_threadinfo (threadref
* threadid
, int fieldset
, /*TAG mask */
1085 struct gdb_ext_thread_info
*info
);
1087 static int adapt_remote_get_threadinfo (gdb_threadref
* ref
,
1089 struct gdb_ext_thread_info
*info
);
1091 static char *pack_threadlist_request (char *pkt
, int startflag
,
1093 threadref
* nextthread
);
1095 static int parse_threadlist_response (char *pkt
,
1097 threadref
* original_echo
,
1098 threadref
* resultlist
, int *doneflag
);
1100 static int remote_get_threadlist (int startflag
,
1101 threadref
* nextthread
,
1104 int *result_count
, threadref
* threadlist
);
1106 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
1108 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1109 void *context
, int looplimit
);
1111 static int remote_newthread_step (threadref
* ref
, void *context
);
1113 /* encode 64 bits in 16 chars of hex */
1115 static const char hexchars
[] = "0123456789abcdef";
1118 ishex (int ch
, int *val
)
1120 if ((ch
>= 'a') && (ch
<= 'f'))
1122 *val
= ch
- 'a' + 10;
1125 if ((ch
>= 'A') && (ch
<= 'F'))
1127 *val
= ch
- 'A' + 10;
1130 if ((ch
>= '0') && (ch
<= '9'))
1141 if (ch
>= 'a' && ch
<= 'f')
1142 return ch
- 'a' + 10;
1143 if (ch
>= '0' && ch
<= '9')
1145 if (ch
>= 'A' && ch
<= 'F')
1146 return ch
- 'A' + 10;
1151 stub_unpack_int (char *buff
, int fieldlength
)
1158 nibble
= stubhex (*buff
++);
1162 retval
= retval
<< 4;
1168 unpack_varlen_hex (char *buff
, /* packet to parse */
1174 while (ishex (*buff
, &nibble
))
1177 retval
= retval
<< 4;
1178 retval
|= nibble
& 0x0f;
1185 unpack_nibble (char *buf
, int *val
)
1187 ishex (*buf
++, val
);
1192 pack_nibble (char *buf
, int nibble
)
1194 *buf
++ = hexchars
[(nibble
& 0x0f)];
1199 pack_hex_byte (char *pkt
, int byte
)
1201 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1202 *pkt
++ = hexchars
[(byte
& 0xf)];
1207 unpack_byte (char *buf
, int *value
)
1209 *value
= stub_unpack_int (buf
, 2);
1214 pack_int (char *buf
, int value
)
1216 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1217 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1218 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1219 buf
= pack_hex_byte (buf
, (value
& 0xff));
1224 unpack_int (char *buf
, int *value
)
1226 *value
= stub_unpack_int (buf
, 8);
1230 #if 0 /* currently unused, uncomment when needed */
1231 static char *pack_string (char *pkt
, char *string
);
1234 pack_string (char *pkt
, char *string
)
1239 len
= strlen (string
);
1241 len
= 200; /* Bigger than most GDB packets, junk??? */
1242 pkt
= pack_hex_byte (pkt
, len
);
1246 if ((ch
== '\0') || (ch
== '#'))
1247 ch
= '*'; /* Protect encapsulation */
1252 #endif /* 0 (unused) */
1255 unpack_string (char *src
, char *dest
, int length
)
1264 pack_threadid (char *pkt
, threadref
*id
)
1267 unsigned char *altid
;
1269 altid
= (unsigned char *) id
;
1270 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1272 pkt
= pack_hex_byte (pkt
, *altid
++);
1278 unpack_threadid (char *inbuf
, threadref
*id
)
1281 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1284 altref
= (char *) id
;
1286 while (inbuf
< limit
)
1288 x
= stubhex (*inbuf
++);
1289 y
= stubhex (*inbuf
++);
1290 *altref
++ = (x
<< 4) | y
;
1295 /* Externally, threadrefs are 64 bits but internally, they are still
1296 ints. This is due to a mismatch of specifications. We would like
1297 to use 64bit thread references internally. This is an adapter
1301 int_to_threadref (threadref
*id
, int value
)
1303 unsigned char *scan
;
1305 scan
= (unsigned char *) id
;
1311 *scan
++ = (value
>> 24) & 0xff;
1312 *scan
++ = (value
>> 16) & 0xff;
1313 *scan
++ = (value
>> 8) & 0xff;
1314 *scan
++ = (value
& 0xff);
1318 threadref_to_int (threadref
*ref
)
1321 unsigned char *scan
;
1323 scan
= (char *) ref
;
1327 value
= (value
<< 8) | ((*scan
++) & 0xff);
1332 copy_threadref (threadref
*dest
, threadref
*src
)
1335 unsigned char *csrc
, *cdest
;
1337 csrc
= (unsigned char *) src
;
1338 cdest
= (unsigned char *) dest
;
1345 threadmatch (threadref
*dest
, threadref
*src
)
1347 /* things are broken right now, so just assume we got a match */
1349 unsigned char *srcp
, *destp
;
1351 srcp
= (char *) src
;
1352 destp
= (char *) dest
;
1356 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1363 threadid:1, # always request threadid
1370 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1373 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1375 *pkt
++ = 'q'; /* Info Query */
1376 *pkt
++ = 'P'; /* process or thread info */
1377 pkt
= pack_int (pkt
, mode
); /* mode */
1378 pkt
= pack_threadid (pkt
, id
); /* threadid */
1379 *pkt
= '\0'; /* terminate */
1383 /* These values tag the fields in a thread info response packet */
1384 /* Tagging the fields allows us to request specific fields and to
1385 add more fields as time goes by */
1387 #define TAG_THREADID 1 /* Echo the thread identifier */
1388 #define TAG_EXISTS 2 /* Is this process defined enough to
1389 fetch registers and its stack */
1390 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1391 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1392 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1396 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1397 struct gdb_ext_thread_info
*info
)
1399 struct remote_state
*rs
= get_remote_state ();
1403 char *limit
= pkt
+ (rs
->remote_packet_size
); /* plausable parsing limit */
1406 /* info->threadid = 0; FIXME: implement zero_threadref */
1408 info
->display
[0] = '\0';
1409 info
->shortname
[0] = '\0';
1410 info
->more_display
[0] = '\0';
1412 /* Assume the characters indicating the packet type have been stripped */
1413 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1414 pkt
= unpack_threadid (pkt
, &ref
);
1417 warning ("Incomplete response to threadinfo request\n");
1418 if (!threadmatch (&ref
, expectedref
))
1419 { /* This is an answer to a different request */
1420 warning ("ERROR RMT Thread info mismatch\n");
1423 copy_threadref (&info
->threadid
, &ref
);
1425 /* Loop on tagged fields , try to bail if somthing goes wrong */
1427 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1429 pkt
= unpack_int (pkt
, &tag
); /* tag */
1430 pkt
= unpack_byte (pkt
, &length
); /* length */
1431 if (!(tag
& mask
)) /* tags out of synch with mask */
1433 warning ("ERROR RMT: threadinfo tag mismatch\n");
1437 if (tag
== TAG_THREADID
)
1441 warning ("ERROR RMT: length of threadid is not 16\n");
1445 pkt
= unpack_threadid (pkt
, &ref
);
1446 mask
= mask
& ~TAG_THREADID
;
1449 if (tag
== TAG_EXISTS
)
1451 info
->active
= stub_unpack_int (pkt
, length
);
1453 mask
= mask
& ~(TAG_EXISTS
);
1456 warning ("ERROR RMT: 'exists' length too long\n");
1462 if (tag
== TAG_THREADNAME
)
1464 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1465 mask
= mask
& ~TAG_THREADNAME
;
1468 if (tag
== TAG_DISPLAY
)
1470 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1471 mask
= mask
& ~TAG_DISPLAY
;
1474 if (tag
== TAG_MOREDISPLAY
)
1476 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1477 mask
= mask
& ~TAG_MOREDISPLAY
;
1480 warning ("ERROR RMT: unknown thread info tag\n");
1481 break; /* Not a tag we know about */
1487 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1488 struct gdb_ext_thread_info
*info
)
1490 struct remote_state
*rs
= get_remote_state ();
1492 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1494 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1495 putpkt (threadinfo_pkt
);
1496 getpkt (threadinfo_pkt
, (rs
->remote_packet_size
), 0);
1497 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1502 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1503 representation of a threadid. */
1506 adapt_remote_get_threadinfo (gdb_threadref
*ref
, int selection
,
1507 struct gdb_ext_thread_info
*info
)
1511 int_to_threadref (&lclref
, *ref
);
1512 return remote_get_threadinfo (&lclref
, selection
, info
);
1515 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1518 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1519 threadref
*nextthread
)
1521 *pkt
++ = 'q'; /* info query packet */
1522 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1523 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1524 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1525 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1530 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1533 parse_threadlist_response (char *pkt
, int result_limit
,
1534 threadref
*original_echo
, threadref
*resultlist
,
1537 struct remote_state
*rs
= get_remote_state ();
1539 int count
, resultcount
, done
;
1542 /* Assume the 'q' and 'M chars have been stripped. */
1543 limit
= pkt
+ ((rs
->remote_packet_size
) - BUF_THREAD_ID_SIZE
); /* done parse past here */
1544 pkt
= unpack_byte (pkt
, &count
); /* count field */
1545 pkt
= unpack_nibble (pkt
, &done
);
1546 /* The first threadid is the argument threadid. */
1547 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1548 while ((count
-- > 0) && (pkt
< limit
))
1550 pkt
= unpack_threadid (pkt
, resultlist
++);
1551 if (resultcount
++ >= result_limit
)
1560 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1561 int *done
, int *result_count
, threadref
*threadlist
)
1563 struct remote_state
*rs
= get_remote_state ();
1564 static threadref echo_nextthread
;
1565 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1566 char *t_response
= alloca (rs
->remote_packet_size
);
1569 /* Trancate result limit to be smaller than the packet size */
1570 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= (rs
->remote_packet_size
))
1571 result_limit
= ((rs
->remote_packet_size
) / BUF_THREAD_ID_SIZE
) - 2;
1573 pack_threadlist_request (threadlist_packet
,
1574 startflag
, result_limit
, nextthread
);
1575 putpkt (threadlist_packet
);
1576 getpkt (t_response
, (rs
->remote_packet_size
), 0);
1579 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1582 if (!threadmatch (&echo_nextthread
, nextthread
))
1584 /* FIXME: This is a good reason to drop the packet */
1585 /* Possably, there is a duplicate response */
1587 retransmit immediatly - race conditions
1588 retransmit after timeout - yes
1590 wait for packet, then exit
1592 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1593 return 0; /* I choose simply exiting */
1595 if (*result_count
<= 0)
1599 warning ("RMT ERROR : failed to get remote thread list\n");
1602 return result
; /* break; */
1604 if (*result_count
> result_limit
)
1607 warning ("RMT ERROR: threadlist response longer than requested\n");
1613 /* This is the interface between remote and threads, remotes upper interface */
1615 /* remote_find_new_threads retrieves the thread list and for each
1616 thread in the list, looks up the thread in GDB's internal list,
1617 ading the thread if it does not already exist. This involves
1618 getting partial thread lists from the remote target so, polling the
1619 quit_flag is required. */
1622 /* About this many threadisds fit in a packet. */
1624 #define MAXTHREADLISTRESULTS 32
1627 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1630 int done
, i
, result_count
;
1634 static threadref nextthread
;
1635 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1640 if (loopcount
++ > looplimit
)
1643 warning ("Remote fetch threadlist -infinite loop-\n");
1646 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1647 &done
, &result_count
, resultthreadlist
))
1652 /* clear for later iterations */
1654 /* Setup to resume next batch of thread references, set nextthread. */
1655 if (result_count
>= 1)
1656 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1658 while (result_count
--)
1659 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1666 remote_newthread_step (threadref
*ref
, void *context
)
1670 ptid
= pid_to_ptid (threadref_to_int (ref
));
1672 if (!in_thread_list (ptid
))
1674 return 1; /* continue iterator */
1677 #define CRAZY_MAX_THREADS 1000
1680 remote_current_thread (ptid_t oldpid
)
1682 struct remote_state
*rs
= get_remote_state ();
1683 char *buf
= alloca (rs
->remote_packet_size
);
1686 getpkt (buf
, (rs
->remote_packet_size
), 0);
1687 if (buf
[0] == 'Q' && buf
[1] == 'C')
1688 return pid_to_ptid (strtol (&buf
[2], NULL
, 16));
1693 /* Find new threads for info threads command.
1694 * Original version, using John Metzler's thread protocol.
1698 remote_find_new_threads (void)
1700 remote_threadlist_iterator (remote_newthread_step
, 0,
1702 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1703 inferior_ptid
= remote_current_thread (inferior_ptid
);
1707 * Find all threads for info threads command.
1708 * Uses new thread protocol contributed by Cisco.
1709 * Falls back and attempts to use the older method (above)
1710 * if the target doesn't respond to the new method.
1714 remote_threads_info (void)
1716 struct remote_state
*rs
= get_remote_state ();
1717 char *buf
= alloca (rs
->remote_packet_size
);
1721 if (remote_desc
== 0) /* paranoia */
1722 error ("Command can only be used when connected to the remote target.");
1724 if (use_threadinfo_query
)
1726 putpkt ("qfThreadInfo");
1728 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1729 if (bufp
[0] != '\0') /* q packet recognized */
1731 while (*bufp
++ == 'm') /* reply contains one or more TID */
1735 tid
= strtol (bufp
, &bufp
, 16);
1736 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1737 add_thread (pid_to_ptid (tid
));
1739 while (*bufp
++ == ','); /* comma-separated list */
1740 putpkt ("qsThreadInfo");
1742 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1748 /* Else fall back to old method based on jmetzler protocol. */
1749 use_threadinfo_query
= 0;
1750 remote_find_new_threads ();
1755 * Collect a descriptive string about the given thread.
1756 * The target may say anything it wants to about the thread
1757 * (typically info about its blocked / runnable state, name, etc.).
1758 * This string will appear in the info threads display.
1760 * Optional: targets are not required to implement this function.
1764 remote_threads_extra_info (struct thread_info
*tp
)
1766 struct remote_state
*rs
= get_remote_state ();
1770 struct gdb_ext_thread_info threadinfo
;
1771 static char display_buf
[100]; /* arbitrary... */
1772 char *bufp
= alloca (rs
->remote_packet_size
);
1773 int n
= 0; /* position in display_buf */
1775 if (remote_desc
== 0) /* paranoia */
1776 internal_error (__FILE__
, __LINE__
,
1777 "remote_threads_extra_info");
1779 if (use_threadextra_query
)
1781 sprintf (bufp
, "qThreadExtraInfo,%x", PIDGET (tp
->ptid
));
1783 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1786 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1787 result
= hex2bin (bufp
, display_buf
, n
);
1788 display_buf
[result
] = '\0';
1793 /* If the above query fails, fall back to the old method. */
1794 use_threadextra_query
= 0;
1795 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1796 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1797 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1798 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1799 if (threadinfo
.active
)
1801 if (*threadinfo
.shortname
)
1802 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1803 if (*threadinfo
.display
)
1804 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1805 if (*threadinfo
.more_display
)
1806 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1807 threadinfo
.more_display
);
1811 /* for purely cosmetic reasons, clear up trailing commas */
1812 if (',' == display_buf
[n
-1])
1813 display_buf
[n
-1] = ' ';
1822 /* Restart the remote side; this is an extended protocol operation. */
1825 extended_remote_restart (void)
1827 struct remote_state
*rs
= get_remote_state ();
1828 char *buf
= alloca (rs
->remote_packet_size
);
1830 /* Send the restart command; for reasons I don't understand the
1831 remote side really expects a number after the "R". */
1833 sprintf (&buf
[1], "%x", 0);
1836 /* Now query for status so this looks just like we restarted
1837 gdbserver from scratch. */
1839 getpkt (buf
, (rs
->remote_packet_size
), 0);
1842 /* Clean up connection to a remote debugger. */
1846 remote_close (int quitting
)
1849 serial_close (remote_desc
);
1853 /* Query the remote side for the text, data and bss offsets. */
1858 struct remote_state
*rs
= get_remote_state ();
1859 char *buf
= alloca (rs
->remote_packet_size
);
1862 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1863 struct section_offsets
*offs
;
1865 putpkt ("qOffsets");
1867 getpkt (buf
, (rs
->remote_packet_size
), 0);
1869 if (buf
[0] == '\000')
1870 return; /* Return silently. Stub doesn't support
1874 warning ("Remote failure reply: %s", buf
);
1878 /* Pick up each field in turn. This used to be done with scanf, but
1879 scanf will make trouble if CORE_ADDR size doesn't match
1880 conversion directives correctly. The following code will work
1881 with any size of CORE_ADDR. */
1882 text_addr
= data_addr
= bss_addr
= 0;
1886 if (strncmp (ptr
, "Text=", 5) == 0)
1889 /* Don't use strtol, could lose on big values. */
1890 while (*ptr
&& *ptr
!= ';')
1891 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1896 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1899 while (*ptr
&& *ptr
!= ';')
1900 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1905 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1908 while (*ptr
&& *ptr
!= ';')
1909 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1915 error ("Malformed response to offset query, %s", buf
);
1917 if (symfile_objfile
== NULL
)
1920 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1921 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1923 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
1925 /* This is a temporary kludge to force data and bss to use the same offsets
1926 because that's what nlmconv does now. The real solution requires changes
1927 to the stub and remote.c that I don't have time to do right now. */
1929 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
1930 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
1932 objfile_relocate (symfile_objfile
, offs
);
1936 * Cisco version of section offsets:
1938 * Instead of having GDB query the target for the section offsets,
1939 * Cisco lets the target volunteer the information! It's also in
1940 * a different format, so here are the functions that will decode
1941 * a section offset packet from a Cisco target.
1945 * Function: remote_cisco_section_offsets
1947 * Returns: zero for success, non-zero for failure
1951 remote_cisco_section_offsets (bfd_vma text_addr
,
1954 bfd_signed_vma
*text_offs
,
1955 bfd_signed_vma
*data_offs
,
1956 bfd_signed_vma
*bss_offs
)
1958 bfd_vma text_base
, data_base
, bss_base
;
1959 struct minimal_symbol
*start
;
1964 if (symfile_objfile
== NULL
)
1965 return -1; /* no can do nothin' */
1967 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
1969 return -1; /* Can't find "_start" symbol */
1971 data_base
= bss_base
= 0;
1972 text_base
= SYMBOL_VALUE_ADDRESS (start
);
1974 abfd
= symfile_objfile
->obfd
;
1975 for (sect
= abfd
->sections
;
1979 const char *p
= bfd_get_section_name (abfd
, sect
);
1981 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
1982 if (data_base
== 0 ||
1983 data_base
> bfd_get_section_vma (abfd
, sect
))
1984 data_base
= bfd_get_section_vma (abfd
, sect
);
1985 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
1986 if (bss_base
== 0 ||
1987 bss_base
> bfd_get_section_vma (abfd
, sect
))
1988 bss_base
= bfd_get_section_vma (abfd
, sect
);
1990 *text_offs
= text_addr
- text_base
;
1991 *data_offs
= data_addr
- data_base
;
1992 *bss_offs
= bss_addr
- bss_base
;
1997 sprintf (tmp
, "VMA: text = 0x");
1998 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
1999 sprintf (tmp
+ strlen (tmp
), " data = 0x");
2000 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
2001 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
2002 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
2003 fprintf_filtered (gdb_stdlog
, tmp
);
2004 fprintf_filtered (gdb_stdlog
,
2005 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
2006 paddr_nz (*text_offs
),
2007 paddr_nz (*data_offs
),
2008 paddr_nz (*bss_offs
));
2015 * Function: remote_cisco_objfile_relocate
2017 * Relocate the symbol file for a remote target.
2021 remote_cisco_objfile_relocate (bfd_signed_vma text_off
, bfd_signed_vma data_off
,
2022 bfd_signed_vma bss_off
)
2024 struct section_offsets
*offs
;
2026 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2028 /* FIXME: This code assumes gdb-stabs.h is being used; it's
2029 broken for xcoff, dwarf, sdb-coff, etc. But there is no
2030 simple canonical representation for this stuff. */
2032 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
2033 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
2035 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_off
;
2036 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_off
;
2037 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = bss_off
;
2039 /* First call the standard objfile_relocate. */
2040 objfile_relocate (symfile_objfile
, offs
);
2042 /* Now we need to fix up the section entries already attached to
2043 the exec target. These entries will control memory transfers
2044 from the exec file. */
2046 exec_set_section_offsets (text_off
, data_off
, bss_off
);
2050 /* Stub for catch_errors. */
2053 remote_start_remote_dummy (void *dummy
)
2055 start_remote (); /* Initialize gdb process mechanisms */
2060 remote_start_remote (PTR dummy
)
2062 immediate_quit
++; /* Allow user to interrupt it */
2064 /* Ack any packet which the remote side has already sent. */
2065 serial_write (remote_desc
, "+", 1);
2067 /* Let the stub know that we want it to return the thread. */
2070 inferior_ptid
= remote_current_thread (inferior_ptid
);
2072 get_offsets (); /* Get text, data & bss offsets */
2074 putpkt ("?"); /* initiate a query from remote machine */
2077 return remote_start_remote_dummy (dummy
);
2080 /* Open a connection to a remote debugger.
2081 NAME is the filename used for communication. */
2084 remote_open (char *name
, int from_tty
)
2086 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
2089 /* Just like remote_open, but with asynchronous support. */
2091 remote_async_open (char *name
, int from_tty
)
2093 remote_async_open_1 (name
, from_tty
, &remote_async_ops
, 0);
2096 /* Open a connection to a remote debugger using the extended
2097 remote gdb protocol. NAME is the filename used for communication. */
2100 extended_remote_open (char *name
, int from_tty
)
2102 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */ );
2105 /* Just like extended_remote_open, but with asynchronous support. */
2107 extended_remote_async_open (char *name
, int from_tty
)
2109 remote_async_open_1 (name
, from_tty
, &extended_async_remote_ops
, 1 /*extended_p */ );
2112 /* Generic code for opening a connection to a remote target. */
2115 init_all_packet_configs (void)
2118 update_packet_config (&remote_protocol_e
);
2119 update_packet_config (&remote_protocol_E
);
2120 update_packet_config (&remote_protocol_P
);
2121 update_packet_config (&remote_protocol_qSymbol
);
2122 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2123 update_packet_config (&remote_protocol_Z
[i
]);
2124 /* Force remote_write_bytes to check whether target supports binary
2126 update_packet_config (&remote_protocol_binary_download
);
2129 /* Symbol look-up. */
2132 remote_check_symbols (struct objfile
*objfile
)
2134 struct remote_state
*rs
= get_remote_state ();
2135 char *msg
, *reply
, *tmp
;
2136 struct minimal_symbol
*sym
;
2139 if (remote_protocol_qSymbol
.support
== PACKET_DISABLE
)
2142 msg
= alloca (rs
->remote_packet_size
);
2143 reply
= alloca (rs
->remote_packet_size
);
2145 /* Invite target to request symbol lookups. */
2147 putpkt ("qSymbol::");
2148 getpkt (reply
, (rs
->remote_packet_size
), 0);
2149 packet_ok (reply
, &remote_protocol_qSymbol
);
2151 while (strncmp (reply
, "qSymbol:", 8) == 0)
2154 end
= hex2bin (tmp
, msg
, strlen (tmp
) / 2);
2156 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2158 sprintf (msg
, "qSymbol::%s", &reply
[8]);
2160 sprintf (msg
, "qSymbol:%s:%s",
2161 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2164 getpkt (reply
, (rs
->remote_packet_size
), 0);
2169 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2172 struct remote_state
*rs
= get_remote_state ();
2174 error ("To open a remote debug connection, you need to specify what\n\
2175 serial device is attached to the remote system\n\
2176 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2178 /* See FIXME above */
2179 wait_forever_enabled_p
= 1;
2181 target_preopen (from_tty
);
2183 unpush_target (target
);
2185 remote_desc
= serial_open (name
);
2187 perror_with_name (name
);
2189 if (baud_rate
!= -1)
2191 if (serial_setbaudrate (remote_desc
, baud_rate
))
2193 serial_close (remote_desc
);
2194 perror_with_name (name
);
2198 serial_raw (remote_desc
);
2200 /* If there is something sitting in the buffer we might take it as a
2201 response to a command, which would be bad. */
2202 serial_flush_input (remote_desc
);
2206 puts_filtered ("Remote debugging using ");
2207 puts_filtered (name
);
2208 puts_filtered ("\n");
2210 push_target (target
); /* Switch to using remote target now */
2212 init_all_packet_configs ();
2214 general_thread
= -2;
2215 continue_thread
= -2;
2217 /* Probe for ability to use "ThreadInfo" query, as required. */
2218 use_threadinfo_query
= 1;
2219 use_threadextra_query
= 1;
2221 /* Without this, some commands which require an active target (such
2222 as kill) won't work. This variable serves (at least) double duty
2223 as both the pid of the target process (if it has such), and as a
2224 flag indicating that a target is active. These functions should
2225 be split out into seperate variables, especially since GDB will
2226 someday have a notion of debugging several processes. */
2228 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2229 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2230 /* First delete any symbols previously loaded from shared libraries. */
2231 no_shared_libraries (NULL
, 0);
2234 /* Start the remote connection; if error (0), discard this target.
2235 In particular, if the user quits, be sure to discard it
2236 (we'd be in an inconsistent state otherwise). */
2237 if (!catch_errors (remote_start_remote
, NULL
,
2238 "Couldn't establish connection to remote target\n",
2247 /* Tell the remote that we are using the extended protocol. */
2248 char *buf
= alloca (rs
->remote_packet_size
);
2250 getpkt (buf
, (rs
->remote_packet_size
), 0);
2252 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2253 /* FIXME: need a master target_open vector from which all
2254 remote_opens can be called, so that stuff like this can
2255 go there. Failing that, the following code must be copied
2256 to the open function for any remote target that wants to
2257 support svr4 shared libraries. */
2259 /* Set up to detect and load shared libraries. */
2260 if (exec_bfd
) /* No use without an exec file. */
2262 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2263 remote_check_symbols (symfile_objfile
);
2268 /* Just like remote_open but with asynchronous support. */
2270 remote_async_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2273 struct remote_state
*rs
= get_remote_state ();
2275 error ("To open a remote debug connection, you need to specify what\n\
2276 serial device is attached to the remote system\n\
2277 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2279 target_preopen (from_tty
);
2281 unpush_target (target
);
2283 remote_desc
= serial_open (name
);
2285 perror_with_name (name
);
2287 if (baud_rate
!= -1)
2289 if (serial_setbaudrate (remote_desc
, baud_rate
))
2291 serial_close (remote_desc
);
2292 perror_with_name (name
);
2296 serial_raw (remote_desc
);
2298 /* If there is something sitting in the buffer we might take it as a
2299 response to a command, which would be bad. */
2300 serial_flush_input (remote_desc
);
2304 puts_filtered ("Remote debugging using ");
2305 puts_filtered (name
);
2306 puts_filtered ("\n");
2309 push_target (target
); /* Switch to using remote target now */
2311 init_all_packet_configs ();
2313 general_thread
= -2;
2314 continue_thread
= -2;
2316 /* Probe for ability to use "ThreadInfo" query, as required. */
2317 use_threadinfo_query
= 1;
2318 use_threadextra_query
= 1;
2320 /* Without this, some commands which require an active target (such
2321 as kill) won't work. This variable serves (at least) double duty
2322 as both the pid of the target process (if it has such), and as a
2323 flag indicating that a target is active. These functions should
2324 be split out into seperate variables, especially since GDB will
2325 someday have a notion of debugging several processes. */
2326 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2328 /* With this target we start out by owning the terminal. */
2329 remote_async_terminal_ours_p
= 1;
2331 /* FIXME: cagney/1999-09-23: During the initial connection it is
2332 assumed that the target is already ready and able to respond to
2333 requests. Unfortunately remote_start_remote() eventually calls
2334 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2335 around this. Eventually a mechanism that allows
2336 wait_for_inferior() to expect/get timeouts will be
2338 wait_forever_enabled_p
= 0;
2340 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2341 /* First delete any symbols previously loaded from shared libraries. */
2342 no_shared_libraries (NULL
, 0);
2345 /* Start the remote connection; if error (0), discard this target.
2346 In particular, if the user quits, be sure to discard it
2347 (we'd be in an inconsistent state otherwise). */
2348 if (!catch_errors (remote_start_remote
, NULL
,
2349 "Couldn't establish connection to remote target\n",
2353 wait_forever_enabled_p
= 1;
2357 wait_forever_enabled_p
= 1;
2361 /* Tell the remote that we are using the extended protocol. */
2362 char *buf
= alloca (rs
->remote_packet_size
);
2364 getpkt (buf
, (rs
->remote_packet_size
), 0);
2366 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2367 /* FIXME: need a master target_open vector from which all
2368 remote_opens can be called, so that stuff like this can
2369 go there. Failing that, the following code must be copied
2370 to the open function for any remote target that wants to
2371 support svr4 shared libraries. */
2373 /* Set up to detect and load shared libraries. */
2374 if (exec_bfd
) /* No use without an exec file. */
2376 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2377 remote_check_symbols (symfile_objfile
);
2382 /* This takes a program previously attached to and detaches it. After
2383 this is done, GDB can be used to debug some other program. We
2384 better not have left any breakpoints in the target program or it'll
2385 die when it hits one. */
2388 remote_detach (char *args
, int from_tty
)
2390 struct remote_state
*rs
= get_remote_state ();
2391 char *buf
= alloca (rs
->remote_packet_size
);
2394 error ("Argument given to \"detach\" when remotely debugging.");
2396 /* Tell the remote target to detach. */
2398 remote_send (buf
, (rs
->remote_packet_size
));
2400 target_mourn_inferior ();
2402 puts_filtered ("Ending remote debugging.\n");
2406 /* Same as remote_detach, but with async support. */
2408 remote_async_detach (char *args
, int from_tty
)
2410 struct remote_state
*rs
= get_remote_state ();
2411 char *buf
= alloca (rs
->remote_packet_size
);
2414 error ("Argument given to \"detach\" when remotely debugging.");
2416 /* Tell the remote target to detach. */
2418 remote_send (buf
, (rs
->remote_packet_size
));
2420 /* Unregister the file descriptor from the event loop. */
2421 if (target_is_async_p ())
2422 serial_async (remote_desc
, NULL
, 0);
2424 target_mourn_inferior ();
2426 puts_filtered ("Ending remote debugging.\n");
2429 /* Convert hex digit A to a number. */
2434 if (a
>= '0' && a
<= '9')
2436 else if (a
>= 'a' && a
<= 'f')
2437 return a
- 'a' + 10;
2438 else if (a
>= 'A' && a
<= 'F')
2439 return a
- 'A' + 10;
2441 error ("Reply contains invalid hex digit %d", a
);
2445 hex2bin (const char *hex
, char *bin
, int count
)
2449 for (i
= 0; i
< count
; i
++)
2451 if (hex
[0] == 0 || hex
[1] == 0)
2453 /* Hex string is short, or of uneven length.
2454 Return the count that has been converted so far. */
2457 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2463 /* Convert number NIB to a hex digit. */
2471 return 'a' + nib
- 10;
2475 bin2hex (const char *bin
, char *hex
, int count
)
2478 /* May use a length, or a nul-terminated string as input. */
2480 count
= strlen (bin
);
2482 for (i
= 0; i
< count
; i
++)
2484 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2485 *hex
++ = tohex (*bin
++ & 0xf);
2491 /* Tell the remote machine to resume. */
2493 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2495 static int last_sent_step
;
2498 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2500 struct remote_state
*rs
= get_remote_state ();
2501 char *buf
= alloca (rs
->remote_packet_size
);
2502 int pid
= PIDGET (ptid
);
2506 set_thread (0, 0); /* run any thread */
2508 set_thread (pid
, 0); /* run this thread */
2510 last_sent_signal
= siggnal
;
2511 last_sent_step
= step
;
2513 /* A hook for when we need to do something at the last moment before
2515 if (target_resume_hook
)
2516 (*target_resume_hook
) ();
2519 /* The s/S/c/C packets do not return status. So if the target does
2520 not support the S or C packets, the debug agent returns an empty
2521 string which is detected in remote_wait(). This protocol defect
2522 is fixed in the e/E packets. */
2524 if (step
&& step_range_end
)
2526 /* If the target does not support the 'E' packet, we try the 'S'
2527 packet. Ideally we would fall back to the 'e' packet if that
2528 too is not supported. But that would require another copy of
2529 the code to issue the 'e' packet (and fall back to 's' if not
2530 supported) in remote_wait(). */
2532 if (siggnal
!= TARGET_SIGNAL_0
)
2534 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2538 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2539 *p
++ = tohex (((int) siggnal
) & 0xf);
2541 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2543 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2547 getpkt (buf
, (rs
->remote_packet_size
), 0);
2549 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2555 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2559 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2561 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2565 getpkt (buf
, (rs
->remote_packet_size
), 0);
2567 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2573 if (siggnal
!= TARGET_SIGNAL_0
)
2575 buf
[0] = step
? 'S' : 'C';
2576 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2577 buf
[2] = tohex (((int) siggnal
) & 0xf);
2581 strcpy (buf
, step
? "s" : "c");
2586 /* Same as remote_resume, but with async support. */
2588 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2590 struct remote_state
*rs
= get_remote_state ();
2591 char *buf
= alloca (rs
->remote_packet_size
);
2592 int pid
= PIDGET (ptid
);
2596 set_thread (0, 0); /* run any thread */
2598 set_thread (pid
, 0); /* run this thread */
2600 last_sent_signal
= siggnal
;
2601 last_sent_step
= step
;
2603 /* A hook for when we need to do something at the last moment before
2605 if (target_resume_hook
)
2606 (*target_resume_hook
) ();
2608 /* The s/S/c/C packets do not return status. So if the target does
2609 not support the S or C packets, the debug agent returns an empty
2610 string which is detected in remote_wait(). This protocol defect
2611 is fixed in the e/E packets. */
2613 if (step
&& step_range_end
)
2615 /* If the target does not support the 'E' packet, we try the 'S'
2616 packet. Ideally we would fall back to the 'e' packet if that
2617 too is not supported. But that would require another copy of
2618 the code to issue the 'e' packet (and fall back to 's' if not
2619 supported) in remote_wait(). */
2621 if (siggnal
!= TARGET_SIGNAL_0
)
2623 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2627 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2628 *p
++ = tohex (((int) siggnal
) & 0xf);
2630 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2632 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2636 getpkt (buf
, (rs
->remote_packet_size
), 0);
2638 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2639 goto register_event_loop
;
2644 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2648 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2650 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2654 getpkt (buf
, (rs
->remote_packet_size
), 0);
2656 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2657 goto register_event_loop
;
2662 if (siggnal
!= TARGET_SIGNAL_0
)
2664 buf
[0] = step
? 'S' : 'C';
2665 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2666 buf
[2] = tohex ((int) siggnal
& 0xf);
2670 strcpy (buf
, step
? "s" : "c");
2674 register_event_loop
:
2675 /* We are about to start executing the inferior, let's register it
2676 with the event loop. NOTE: this is the one place where all the
2677 execution commands end up. We could alternatively do this in each
2678 of the execution commands in infcmd.c.*/
2679 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2680 into infcmd.c in order to allow inferior function calls to work
2681 NOT asynchronously. */
2682 if (event_loop_p
&& target_can_async_p ())
2683 target_async (inferior_event_handler
, 0);
2684 /* Tell the world that the target is now executing. */
2685 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2686 this? Instead, should the client of target just assume (for
2687 async targets) that the target is going to start executing? Is
2688 this information already found in the continuation block? */
2689 if (target_is_async_p ())
2690 target_executing
= 1;
2694 /* Set up the signal handler for SIGINT, while the target is
2695 executing, ovewriting the 'regular' SIGINT signal handler. */
2697 initialize_sigint_signal_handler (void)
2699 sigint_remote_token
=
2700 create_async_signal_handler (async_remote_interrupt
, NULL
);
2701 signal (SIGINT
, handle_remote_sigint
);
2704 /* Signal handler for SIGINT, while the target is executing. */
2706 handle_remote_sigint (int sig
)
2708 signal (sig
, handle_remote_sigint_twice
);
2709 sigint_remote_twice_token
=
2710 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2711 mark_async_signal_handler_wrapper (sigint_remote_token
);
2714 /* Signal handler for SIGINT, installed after SIGINT has already been
2715 sent once. It will take effect the second time that the user sends
2718 handle_remote_sigint_twice (int sig
)
2720 signal (sig
, handle_sigint
);
2721 sigint_remote_twice_token
=
2722 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2723 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2726 /* Perform the real interruption of the target execution, in response
2729 async_remote_interrupt (gdb_client_data arg
)
2732 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2737 /* Perform interrupt, if the first attempt did not succeed. Just give
2738 up on the target alltogether. */
2740 async_remote_interrupt_twice (gdb_client_data arg
)
2743 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2744 /* Do something only if the target was not killed by the previous
2746 if (target_executing
)
2749 signal (SIGINT
, handle_remote_sigint
);
2753 /* Reinstall the usual SIGINT handlers, after the target has
2756 cleanup_sigint_signal_handler (void *dummy
)
2758 signal (SIGINT
, handle_sigint
);
2759 if (sigint_remote_twice_token
)
2760 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2761 if (sigint_remote_token
)
2762 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2765 /* Send ^C to target to halt it. Target will respond, and send us a
2767 static void (*ofunc
) (int);
2769 /* The command line interface's stop routine. This function is installed
2770 as a signal handler for SIGINT. The first time a user requests a
2771 stop, we call remote_stop to send a break or ^C. If there is no
2772 response from the target (it didn't stop when the user requested it),
2773 we ask the user if he'd like to detach from the target. */
2775 remote_interrupt (int signo
)
2777 /* If this doesn't work, try more severe steps. */
2778 signal (signo
, remote_interrupt_twice
);
2781 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2786 /* The user typed ^C twice. */
2789 remote_interrupt_twice (int signo
)
2791 signal (signo
, ofunc
);
2793 signal (signo
, remote_interrupt
);
2796 /* This is the generic stop called via the target vector. When a target
2797 interrupt is requested, either by the command line or the GUI, we
2798 will eventually end up here. */
2802 /* Send a break or a ^C, depending on user preference. */
2804 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2807 serial_send_break (remote_desc
);
2809 serial_write (remote_desc
, "\003", 1);
2812 /* Ask the user what to do when an interrupt is received. */
2815 interrupt_query (void)
2817 target_terminal_ours ();
2819 if (query ("Interrupted while waiting for the program.\n\
2820 Give up (and stop debugging it)? "))
2822 target_mourn_inferior ();
2823 return_to_top_level (RETURN_QUIT
);
2826 target_terminal_inferior ();
2829 /* Enable/disable target terminal ownership. Most targets can use
2830 terminal groups to control terminal ownership. Remote targets are
2831 different in that explicit transfer of ownership to/from GDB/target
2835 remote_async_terminal_inferior (void)
2837 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2838 sync_execution here. This function should only be called when
2839 GDB is resuming the inferior in the forground. A background
2840 resume (``run&'') should leave GDB in control of the terminal and
2841 consequently should not call this code. */
2842 if (!sync_execution
)
2844 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2845 calls target_terminal_*() idenpotent. The event-loop GDB talking
2846 to an asynchronous target with a synchronous command calls this
2847 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2848 stops trying to transfer the terminal to the target when it
2849 shouldn't this guard can go away. */
2850 if (!remote_async_terminal_ours_p
)
2852 delete_file_handler (input_fd
);
2853 remote_async_terminal_ours_p
= 0;
2854 initialize_sigint_signal_handler ();
2855 /* NOTE: At this point we could also register our selves as the
2856 recipient of all input. Any characters typed could then be
2857 passed on down to the target. */
2861 remote_async_terminal_ours (void)
2863 /* See FIXME in remote_async_terminal_inferior. */
2864 if (!sync_execution
)
2866 /* See FIXME in remote_async_terminal_inferior. */
2867 if (remote_async_terminal_ours_p
)
2869 cleanup_sigint_signal_handler (NULL
);
2870 add_file_handler (input_fd
, stdin_event_handler
, 0);
2871 remote_async_terminal_ours_p
= 1;
2874 /* If nonzero, ignore the next kill. */
2879 remote_console_output (char *msg
)
2883 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2886 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2889 fputs_unfiltered (tb
, gdb_stdtarg
);
2891 gdb_flush (gdb_stdtarg
);
2894 /* Wait until the remote machine stops, then return,
2895 storing status in STATUS just as `wait' would.
2896 Returns "pid", which in the case of a multi-threaded
2897 remote OS, is the thread-id. */
2900 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2902 struct remote_state
*rs
= get_remote_state ();
2903 unsigned char *buf
= alloca (rs
->remote_packet_size
);
2904 int thread_num
= -1;
2906 status
->kind
= TARGET_WAITKIND_EXITED
;
2907 status
->value
.integer
= 0;
2913 ofunc
= signal (SIGINT
, remote_interrupt
);
2914 getpkt (buf
, (rs
->remote_packet_size
), 1);
2915 signal (SIGINT
, ofunc
);
2917 /* This is a hook for when we need to do something (perhaps the
2918 collection of trace data) every time the target stops. */
2919 if (target_wait_loop_hook
)
2920 (*target_wait_loop_hook
) ();
2924 case 'E': /* Error of some sort */
2925 warning ("Remote failure reply: %s", buf
);
2927 case 'T': /* Status with PC, SP, FP, ... */
2931 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
2933 /* Expedited reply, containing Signal, {regno, reg} repeat */
2934 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2936 n... = register number
2937 r... = register contents
2939 p
= &buf
[3]; /* after Txx */
2947 /* Read the register number */
2948 regno
= strtol ((const char *) p
, &p_temp
, 16);
2949 p1
= (unsigned char *) p_temp
;
2951 if (p1
== p
) /* No register number present here */
2953 p1
= (unsigned char *) strchr ((const char *) p
, ':');
2955 warning ("Malformed packet(a) (missing colon): %s\n\
2958 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
2960 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2961 record_currthread (thread_num
);
2962 p
= (unsigned char *) p_temp
;
2970 warning ("Malformed packet(b) (missing colon): %s\n\
2974 if (regno
>= NUM_REGS
)
2975 warning ("Remote sent bad register number %ld: %s\n\
2979 fieldsize
= hex2bin (p
, regs
, REGISTER_RAW_SIZE (regno
));
2981 if (fieldsize
< REGISTER_RAW_SIZE (regno
))
2982 warning ("Remote reply is too short: %s", buf
);
2983 supply_register (regno
, regs
);
2988 warning ("Remote register badly formatted: %s", buf
);
2989 warning (" here: %s", p
);
2994 case 'S': /* Old style status, just signal only */
2995 status
->kind
= TARGET_WAITKIND_STOPPED
;
2996 status
->value
.sig
= (enum target_signal
)
2997 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3001 /* Export Cisco kernel mode as a convenience variable
3002 (so that it can be used in the GDB prompt if desired). */
3004 if (cisco_kernel_mode
== 1)
3005 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3006 value_from_string ("PDEBUG-"));
3007 cisco_kernel_mode
= 0;
3008 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3009 record_currthread (thread_num
);
3011 else if (buf
[3] == 'k')
3013 /* Export Cisco kernel mode as a convenience variable
3014 (so that it can be used in the GDB prompt if desired). */
3016 if (cisco_kernel_mode
== 1)
3017 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3018 value_from_string ("KDEBUG-"));
3019 cisco_kernel_mode
= 1;
3022 case 'N': /* Cisco special: status and offsets */
3024 bfd_vma text_addr
, data_addr
, bss_addr
;
3025 bfd_signed_vma text_off
, data_off
, bss_off
;
3028 status
->kind
= TARGET_WAITKIND_STOPPED
;
3029 status
->value
.sig
= (enum target_signal
)
3030 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3032 if (symfile_objfile
== NULL
)
3034 warning ("Relocation packet received with no symbol file. \
3039 /* Relocate object file. Buffer format is NAATT;DD;BB
3040 * where AA is the signal number, TT is the new text
3041 * address, DD * is the new data address, and BB is the
3042 * new bss address. */
3045 text_addr
= strtoul (p
, (char **) &p1
, 16);
3046 if (p1
== p
|| *p1
!= ';')
3047 warning ("Malformed relocation packet: Packet '%s'", buf
);
3049 data_addr
= strtoul (p
, (char **) &p1
, 16);
3050 if (p1
== p
|| *p1
!= ';')
3051 warning ("Malformed relocation packet: Packet '%s'", buf
);
3053 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3055 warning ("Malformed relocation packet: Packet '%s'", buf
);
3057 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3058 &text_off
, &data_off
, &bss_off
)
3060 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3061 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3065 case 'W': /* Target exited */
3067 /* The remote process exited. */
3068 status
->kind
= TARGET_WAITKIND_EXITED
;
3069 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3073 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3074 status
->value
.sig
= (enum target_signal
)
3075 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3079 case 'O': /* Console output */
3080 remote_console_output (buf
+ 1);
3083 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3085 /* Zero length reply means that we tried 'S' or 'C' and
3086 the remote system doesn't support it. */
3087 target_terminal_ours_for_output ();
3089 ("Can't send signals to this remote system. %s not sent.\n",
3090 target_signal_to_name (last_sent_signal
));
3091 last_sent_signal
= TARGET_SIGNAL_0
;
3092 target_terminal_inferior ();
3094 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3095 putpkt ((char *) buf
);
3098 /* else fallthrough */
3100 warning ("Invalid remote reply: %s", buf
);
3105 if (thread_num
!= -1)
3107 return pid_to_ptid (thread_num
);
3109 return inferior_ptid
;
3112 /* Async version of remote_wait. */
3114 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3116 struct remote_state
*rs
= get_remote_state ();
3117 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3118 int thread_num
= -1;
3120 status
->kind
= TARGET_WAITKIND_EXITED
;
3121 status
->value
.integer
= 0;
3127 if (!target_is_async_p ())
3128 ofunc
= signal (SIGINT
, remote_interrupt
);
3129 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3130 _never_ wait for ever -> test on target_is_async_p().
3131 However, before we do that we need to ensure that the caller
3132 knows how to take the target into/out of async mode. */
3133 getpkt (buf
, (rs
->remote_packet_size
), wait_forever_enabled_p
);
3134 if (!target_is_async_p ())
3135 signal (SIGINT
, ofunc
);
3137 /* This is a hook for when we need to do something (perhaps the
3138 collection of trace data) every time the target stops. */
3139 if (target_wait_loop_hook
)
3140 (*target_wait_loop_hook
) ();
3144 case 'E': /* Error of some sort */
3145 warning ("Remote failure reply: %s", buf
);
3147 case 'T': /* Status with PC, SP, FP, ... */
3151 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
3153 /* Expedited reply, containing Signal, {regno, reg} repeat */
3154 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3156 n... = register number
3157 r... = register contents
3159 p
= &buf
[3]; /* after Txx */
3167 /* Read the register number */
3168 regno
= strtol ((const char *) p
, &p_temp
, 16);
3169 p1
= (unsigned char *) p_temp
;
3171 if (p1
== p
) /* No register number present here */
3173 p1
= (unsigned char *) strchr ((const char *) p
, ':');
3175 warning ("Malformed packet(a) (missing colon): %s\n\
3178 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
3180 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3181 record_currthread (thread_num
);
3182 p
= (unsigned char *) p_temp
;
3190 warning ("Malformed packet(b) (missing colon): %s\n\
3194 if (regno
>= NUM_REGS
)
3195 warning ("Remote sent bad register number %ld: %s\n\
3199 fieldsize
= hex2bin (p
, regs
, REGISTER_RAW_SIZE (regno
));
3201 if (fieldsize
< REGISTER_RAW_SIZE (regno
))
3202 warning ("Remote reply is too short: %s", buf
);
3203 supply_register (regno
, regs
);
3208 warning ("Remote register badly formatted: %s", buf
);
3209 warning (" here: %s", p
);
3214 case 'S': /* Old style status, just signal only */
3215 status
->kind
= TARGET_WAITKIND_STOPPED
;
3216 status
->value
.sig
= (enum target_signal
)
3217 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3221 /* Export Cisco kernel mode as a convenience variable
3222 (so that it can be used in the GDB prompt if desired). */
3224 if (cisco_kernel_mode
== 1)
3225 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3226 value_from_string ("PDEBUG-"));
3227 cisco_kernel_mode
= 0;
3228 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3229 record_currthread (thread_num
);
3231 else if (buf
[3] == 'k')
3233 /* Export Cisco kernel mode as a convenience variable
3234 (so that it can be used in the GDB prompt if desired). */
3236 if (cisco_kernel_mode
== 1)
3237 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3238 value_from_string ("KDEBUG-"));
3239 cisco_kernel_mode
= 1;
3242 case 'N': /* Cisco special: status and offsets */
3244 bfd_vma text_addr
, data_addr
, bss_addr
;
3245 bfd_signed_vma text_off
, data_off
, bss_off
;
3248 status
->kind
= TARGET_WAITKIND_STOPPED
;
3249 status
->value
.sig
= (enum target_signal
)
3250 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3252 if (symfile_objfile
== NULL
)
3254 warning ("Relocation packet recieved with no symbol file. \
3259 /* Relocate object file. Buffer format is NAATT;DD;BB
3260 * where AA is the signal number, TT is the new text
3261 * address, DD * is the new data address, and BB is the
3262 * new bss address. */
3265 text_addr
= strtoul (p
, (char **) &p1
, 16);
3266 if (p1
== p
|| *p1
!= ';')
3267 warning ("Malformed relocation packet: Packet '%s'", buf
);
3269 data_addr
= strtoul (p
, (char **) &p1
, 16);
3270 if (p1
== p
|| *p1
!= ';')
3271 warning ("Malformed relocation packet: Packet '%s'", buf
);
3273 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3275 warning ("Malformed relocation packet: Packet '%s'", buf
);
3277 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3278 &text_off
, &data_off
, &bss_off
)
3280 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3281 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3285 case 'W': /* Target exited */
3287 /* The remote process exited. */
3288 status
->kind
= TARGET_WAITKIND_EXITED
;
3289 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3293 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3294 status
->value
.sig
= (enum target_signal
)
3295 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3299 case 'O': /* Console output */
3300 remote_console_output (buf
+ 1);
3301 /* Return immediately to the event loop. The event loop will
3302 still be waiting on the inferior afterwards. */
3303 status
->kind
= TARGET_WAITKIND_IGNORE
;
3306 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3308 /* Zero length reply means that we tried 'S' or 'C' and
3309 the remote system doesn't support it. */
3310 target_terminal_ours_for_output ();
3312 ("Can't send signals to this remote system. %s not sent.\n",
3313 target_signal_to_name (last_sent_signal
));
3314 last_sent_signal
= TARGET_SIGNAL_0
;
3315 target_terminal_inferior ();
3317 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3318 putpkt ((char *) buf
);
3321 /* else fallthrough */
3323 warning ("Invalid remote reply: %s", buf
);
3328 if (thread_num
!= -1)
3330 return pid_to_ptid (thread_num
);
3332 return inferior_ptid
;
3335 /* Number of bytes of registers this stub implements. */
3337 static int register_bytes_found
;
3339 /* Read the remote registers into the block REGS. */
3340 /* Currently we just read all the registers, so we don't use regno. */
3344 remote_fetch_registers (int regno
)
3346 struct remote_state
*rs
= get_remote_state ();
3347 char *buf
= alloca (rs
->remote_packet_size
);
3350 char *regs
= alloca (REGISTER_BYTES
);
3352 set_thread (PIDGET (inferior_ptid
), 1);
3355 remote_send (buf
, (rs
->remote_packet_size
));
3357 /* Save the size of the packet sent to us by the target. Its used
3358 as a heuristic when determining the max size of packets that the
3359 target can safely receive. */
3360 if ((rs
->actual_register_packet_size
) == 0)
3361 (rs
->actual_register_packet_size
) = strlen (buf
);
3363 /* Unimplemented registers read as all bits zero. */
3364 memset (regs
, 0, REGISTER_BYTES
);
3366 /* We can get out of synch in various cases. If the first character
3367 in the buffer is not a hex character, assume that has happened
3368 and try to fetch another packet to read. */
3369 while ((buf
[0] < '0' || buf
[0] > '9')
3370 && (buf
[0] < 'a' || buf
[0] > 'f')
3371 && buf
[0] != 'x') /* New: unavailable register value */
3374 fprintf_unfiltered (gdb_stdlog
,
3375 "Bad register packet; fetching a new packet\n");
3376 getpkt (buf
, (rs
->remote_packet_size
), 0);
3379 /* Reply describes registers byte by byte, each byte encoded as two
3380 hex characters. Suck them all up, then supply them to the
3381 register cacheing/storage mechanism. */
3384 for (i
= 0; i
< REGISTER_BYTES
; i
++)
3390 warning ("Remote reply is of odd length: %s", buf
);
3391 /* Don't change register_bytes_found in this case, and don't
3392 print a second warning. */
3395 if (p
[0] == 'x' && p
[1] == 'x')
3396 regs
[i
] = 0; /* 'x' */
3398 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3402 if (i
!= register_bytes_found
)
3404 register_bytes_found
= i
;
3405 if (REGISTER_BYTES_OK_P ()
3406 && !REGISTER_BYTES_OK (i
))
3407 warning ("Remote reply is too short: %s", buf
);
3411 for (i
= 0; i
< NUM_REGS
; i
++)
3413 supply_register (i
, ®s
[REGISTER_BYTE (i
)]);
3414 if (buf
[REGISTER_BYTE (i
) * 2] == 'x')
3415 set_register_cached (i
, -1);
3419 /* Prepare to store registers. Since we may send them all (using a
3420 'G' request), we have to read out the ones we don't want to change
3424 remote_prepare_to_store (void)
3426 /* Make sure the entire registers array is valid. */
3427 switch (remote_protocol_P
.support
)
3429 case PACKET_DISABLE
:
3430 case PACKET_SUPPORT_UNKNOWN
:
3431 read_register_bytes (0, (char *) NULL
, REGISTER_BYTES
);
3438 /* Helper: Attempt to store REGNO using the P packet. Return fail IFF
3439 packet was not recognized. */
3442 store_register_using_P (int regno
)
3444 struct remote_state
*rs
= get_remote_state ();
3445 /* Try storing a single register. */
3446 char *buf
= alloca (rs
->remote_packet_size
);
3447 char *regp
= alloca (MAX_REGISTER_RAW_SIZE
);
3451 sprintf (buf
, "P%x=", regno
);
3452 p
= buf
+ strlen (buf
);
3453 regcache_collect (regno
, regp
);
3454 bin2hex (regp
, p
, REGISTER_RAW_SIZE (regno
));
3455 remote_send (buf
, (rs
->remote_packet_size
));
3457 return buf
[0] != '\0';
3461 /* Store register REGNO, or all registers if REGNO == -1, from the contents
3462 of the register cache buffer. FIXME: ignores errors. */
3465 remote_store_registers (int regno
)
3467 struct remote_state
*rs
= get_remote_state ();
3473 set_thread (PIDGET (inferior_ptid
), 1);
3477 switch (remote_protocol_P
.support
)
3479 case PACKET_DISABLE
:
3482 if (store_register_using_P (regno
))
3485 error ("Protocol error: P packet not recognized by stub");
3486 case PACKET_SUPPORT_UNKNOWN
:
3487 if (store_register_using_P (regno
))
3489 /* The stub recognized the 'P' packet. Remember this. */
3490 remote_protocol_P
.support
= PACKET_ENABLE
;
3495 /* The stub does not support the 'P' packet. Use 'G'
3496 instead, and don't try using 'P' in the future (it
3497 will just waste our time). */
3498 remote_protocol_P
.support
= PACKET_DISABLE
;
3504 /* Extract all the registers in the regcache copying them into a
3508 regs
= alloca (REGISTER_BYTES
);
3509 memset (regs
, REGISTER_BYTES
, 0);
3510 for (i
= 0; i
< NUM_REGS
; i
++)
3512 regcache_collect (i
, regs
+ REGISTER_BYTE (i
));
3516 /* Command describes registers byte by byte,
3517 each byte encoded as two hex characters. */
3518 buf
= alloca (rs
->remote_packet_size
);
3521 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3522 bin2hex (regs
, p
, register_bytes_found
);
3523 remote_send (buf
, (rs
->remote_packet_size
));
3527 /* Return the number of hex digits in num. */
3530 hexnumlen (ULONGEST num
)
3534 for (i
= 0; num
!= 0; i
++)
3540 /* Set BUF to the minimum number of hex digits representing NUM. */
3543 hexnumstr (char *buf
, ULONGEST num
)
3545 int len
= hexnumlen (num
);
3546 return hexnumnstr (buf
, num
, len
);
3550 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3553 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3559 for (i
= width
- 1; i
>= 0; i
--)
3561 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3568 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3571 remote_address_masked (CORE_ADDR addr
)
3573 if (remote_address_size
> 0
3574 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3576 /* Only create a mask when that mask can safely be constructed
3577 in a ULONGEST variable. */
3579 mask
= (mask
<< remote_address_size
) - 1;
3585 /* Determine whether the remote target supports binary downloading.
3586 This is accomplished by sending a no-op memory write of zero length
3587 to the target at the specified address. It does not suffice to send
3588 the whole packet, since many stubs strip the eighth bit and subsequently
3589 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3591 NOTE: This can still lose if the serial line is not eight-bit
3592 clean. In cases like this, the user should clear "remote
3596 check_binary_download (CORE_ADDR addr
)
3598 struct remote_state
*rs
= get_remote_state ();
3599 switch (remote_protocol_binary_download
.support
)
3601 case PACKET_DISABLE
:
3605 case PACKET_SUPPORT_UNKNOWN
:
3607 char *buf
= alloca (rs
->remote_packet_size
);
3612 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3614 p
+= hexnumstr (p
, (ULONGEST
) 0);
3618 putpkt_binary (buf
, (int) (p
- buf
));
3619 getpkt (buf
, (rs
->remote_packet_size
), 0);
3624 fprintf_unfiltered (gdb_stdlog
,
3625 "binary downloading NOT suppported by target\n");
3626 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3631 fprintf_unfiltered (gdb_stdlog
,
3632 "binary downloading suppported by target\n");
3633 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3640 /* Write memory data directly to the remote machine.
3641 This does not inform the data cache; the data cache uses this.
3642 MEMADDR is the address in the remote memory space.
3643 MYADDR is the address of the buffer in our space.
3644 LEN is the number of bytes.
3646 Returns number of bytes transferred, or 0 (setting errno) for
3647 error. Only transfer a single packet. */
3650 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3653 int max_buf_size
; /* Max size of packet output buffer */
3655 unsigned char *plen
;
3661 /* Verify that the target can support a binary download */
3662 check_binary_download (memaddr
);
3664 /* Determine the max packet size. */
3665 max_buf_size
= get_memory_write_packet_size ();
3666 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3667 buf
= alloca (sizeof_buf
);
3669 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3670 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
3672 /* construct "M"<memaddr>","<len>":" */
3673 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3676 /* Append [XM]. Compute a best guess of the number of bytes
3677 actually transfered. */
3678 switch (remote_protocol_binary_download
.support
)
3682 /* Best guess at number of bytes that will fit. */
3683 todo
= min (len
, max_buf_size
);
3685 case PACKET_DISABLE
:
3687 /* num bytes that will fit */
3688 todo
= min (len
, max_buf_size
/ 2);
3690 case PACKET_SUPPORT_UNKNOWN
:
3691 internal_error (__FILE__
, __LINE__
,
3692 "remote_write_bytes: bad internal state");
3694 internal_error (__FILE__
, __LINE__
, "bad switch");
3697 /* Append <memaddr> */
3698 memaddr
= remote_address_masked (memaddr
);
3699 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3702 /* Append <len>. Retain the location/size of <len>. It may
3703 need to be adjusted once the packet body has been created. */
3705 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3710 /* Append the packet body. */
3711 switch (remote_protocol_binary_download
.support
)
3714 /* Binary mode. Send target system values byte by byte, in
3715 increasing byte addresses. Only escape certain critical
3718 (nr_bytes
< todo
) && (p
- buf
) < (max_buf_size
- 2);
3721 switch (myaddr
[nr_bytes
] & 0xff)
3726 /* These must be escaped */
3728 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3731 *p
++ = myaddr
[nr_bytes
] & 0xff;
3735 if (nr_bytes
< todo
)
3737 /* Escape chars have filled up the buffer prematurely,
3738 and we have actually sent fewer bytes than planned.
3739 Fix-up the length field of the packet. Use the same
3740 number of characters as before. */
3742 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3743 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3746 case PACKET_DISABLE
:
3747 /* Normal mode: Send target system values byte by byte, in
3748 increasing byte addresses. Each byte is encoded as a two hex
3750 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3753 case PACKET_SUPPORT_UNKNOWN
:
3754 internal_error (__FILE__
, __LINE__
,
3755 "remote_write_bytes: bad internal state");
3757 internal_error (__FILE__
, __LINE__
, "bad switch");
3760 putpkt_binary (buf
, (int) (p
- buf
));
3761 getpkt (buf
, sizeof_buf
, 0);
3765 /* There is no correspondance between what the remote protocol
3766 uses for errors and errno codes. We would like a cleaner way
3767 of representing errors (big enough to include errno codes,
3768 bfd_error codes, and others). But for now just return EIO. */
3773 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3774 bytes than we'd planned. */
3778 /* Read memory data directly from the remote machine.
3779 This does not use the data cache; the data cache uses this.
3780 MEMADDR is the address in the remote memory space.
3781 MYADDR is the address of the buffer in our space.
3782 LEN is the number of bytes.
3784 Returns number of bytes transferred, or 0 for error. */
3786 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3787 remote targets) shouldn't attempt to read the entire buffer.
3788 Instead it should read a single packet worth of data and then
3789 return the byte size of that packet to the caller. The caller (its
3790 caller and its callers caller ;-) already contains code for
3791 handling partial reads. */
3794 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3797 int max_buf_size
; /* Max size of packet output buffer */
3801 /* Create a buffer big enough for this packet. */
3802 max_buf_size
= get_memory_read_packet_size ();
3803 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3804 buf
= alloca (sizeof_buf
);
3813 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3815 /* construct "m"<memaddr>","<len>" */
3816 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3817 memaddr
= remote_address_masked (memaddr
);
3820 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3822 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3826 getpkt (buf
, sizeof_buf
, 0);
3830 /* There is no correspondance between what the remote protocol uses
3831 for errors and errno codes. We would like a cleaner way of
3832 representing errors (big enough to include errno codes, bfd_error
3833 codes, and others). But for now just return EIO. */
3838 /* Reply describes memory byte by byte,
3839 each byte encoded as two hex characters. */
3842 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
3844 /* Reply is short. This means that we were able to read
3845 only part of what we wanted to. */
3846 return i
+ (origlen
- len
);
3855 /* Read or write LEN bytes from inferior memory at MEMADDR,
3856 transferring to or from debugger address BUFFER. Write to inferior if
3857 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3858 for error. TARGET is unused. */
3862 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
3864 struct mem_attrib
*attrib ATTRIBUTE_UNUSED
,
3865 struct target_ops
*target
)
3867 CORE_ADDR targ_addr
;
3871 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr
, mem_len
, &targ_addr
, &targ_len
);
3876 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
3878 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
3885 /* Enable after 4.12. */
3888 remote_search (int len
, char *data
, char *mask
, CORE_ADDR startaddr
,
3889 int increment
, CORE_ADDR lorange
, CORE_ADDR hirange
,
3890 CORE_ADDR
*addr_found
, char *data_found
)
3892 if (increment
== -4 && len
== 4)
3894 long mask_long
, data_long
;
3895 long data_found_long
;
3896 CORE_ADDR addr_we_found
;
3897 char *buf
= alloca (rs
->remote_packet_size
);
3898 long returned_long
[2];
3901 mask_long
= extract_unsigned_integer (mask
, len
);
3902 data_long
= extract_unsigned_integer (data
, len
);
3903 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
3905 getpkt (buf
, (rs
->remote_packet_size
), 0);
3908 /* The stub doesn't support the 't' request. We might want to
3909 remember this fact, but on the other hand the stub could be
3910 switched on us. Maybe we should remember it only until
3911 the next "target remote". */
3912 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3913 hirange
, addr_found
, data_found
);
3918 /* There is no correspondance between what the remote protocol uses
3919 for errors and errno codes. We would like a cleaner way of
3920 representing errors (big enough to include errno codes, bfd_error
3921 codes, and others). But for now just use EIO. */
3922 memory_error (EIO
, startaddr
);
3925 while (*p
!= '\0' && *p
!= ',')
3926 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
3928 error ("Protocol error: short return for search");
3930 data_found_long
= 0;
3931 while (*p
!= '\0' && *p
!= ',')
3932 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
3933 /* Ignore anything after this comma, for future extensions. */
3935 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
3941 *addr_found
= addr_we_found
;
3942 *data_found
= store_unsigned_integer (data_we_found
, len
);
3945 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3946 hirange
, addr_found
, data_found
);
3951 remote_files_info (struct target_ops
*ignore
)
3953 puts_filtered ("Debugging a target over a serial line.\n");
3956 /* Stuff for dealing with the packets which are part of this protocol.
3957 See comment at top of file for details. */
3959 /* Read a single character from the remote end, masking it down to 7 bits. */
3962 readchar (int timeout
)
3966 ch
= serial_readchar (remote_desc
, timeout
);
3971 switch ((enum serial_rc
) ch
)
3974 target_mourn_inferior ();
3975 error ("Remote connection closed");
3978 perror_with_name ("Remote communication error");
3980 case SERIAL_TIMEOUT
:
3986 /* Send the command in BUF to the remote machine, and read the reply
3987 into BUF. Report an error if we get an error reply. */
3990 remote_send (char *buf
,
3994 getpkt (buf
, sizeof_buf
, 0);
3997 error ("Remote failure reply: %s", buf
);
4000 /* Display a null-terminated packet on stdout, for debugging, using C
4004 print_packet (char *buf
)
4006 puts_filtered ("\"");
4007 fputstr_filtered (buf
, '"', gdb_stdout
);
4008 puts_filtered ("\"");
4014 return putpkt_binary (buf
, strlen (buf
));
4017 /* Send a packet to the remote machine, with error checking. The data
4018 of the packet is in BUF. The string in BUF can be at most (rs->remote_packet_size) - 5
4019 to account for the $, # and checksum, and for a possible /0 if we are
4020 debugging (remote_debug) and want to print the sent packet as a string */
4023 putpkt_binary (char *buf
, int cnt
)
4025 struct remote_state
*rs
= get_remote_state ();
4027 unsigned char csum
= 0;
4028 char *buf2
= alloca (cnt
+ 6);
4029 long sizeof_junkbuf
= (rs
->remote_packet_size
);
4030 char *junkbuf
= alloca (sizeof_junkbuf
);
4036 /* Copy the packet into buffer BUF2, encapsulating it
4037 and giving it a checksum. */
4042 for (i
= 0; i
< cnt
; i
++)
4048 *p
++ = tohex ((csum
>> 4) & 0xf);
4049 *p
++ = tohex (csum
& 0xf);
4051 /* Send it over and over until we get a positive ack. */
4055 int started_error_output
= 0;
4060 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4061 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4062 fprintf_unfiltered (gdb_stdlog
, "...");
4063 gdb_flush (gdb_stdlog
);
4065 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4066 perror_with_name ("putpkt: write failed");
4068 /* read until either a timeout occurs (-2) or '+' is read */
4071 ch
= readchar (remote_timeout
);
4079 case SERIAL_TIMEOUT
:
4081 if (started_error_output
)
4083 putchar_unfiltered ('\n');
4084 started_error_output
= 0;
4093 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4097 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4098 case SERIAL_TIMEOUT
:
4102 break; /* Retransmit buffer */
4106 fprintf_unfiltered (gdb_stdlog
, "Packet instead of Ack, ignoring it\n");
4107 /* It's probably an old response, and we're out of sync.
4108 Just gobble up the packet and ignore it. */
4109 read_frame (junkbuf
, sizeof_junkbuf
);
4110 continue; /* Now, go look for + */
4115 if (!started_error_output
)
4117 started_error_output
= 1;
4118 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4120 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4124 break; /* Here to retransmit */
4128 /* This is wrong. If doing a long backtrace, the user should be
4129 able to get out next time we call QUIT, without anything as
4130 violent as interrupt_query. If we want to provide a way out of
4131 here without getting to the next QUIT, it should be based on
4132 hitting ^C twice as in remote_wait. */
4142 static int remote_cisco_mode
;
4144 /* Come here after finding the start of the frame. Collect the rest
4145 into BUF, verifying the checksum, length, and handling run-length
4146 compression. No more than sizeof_buf-1 characters are read so that
4147 the buffer can be NUL terminated.
4149 Returns -1 on error, number of characters in buffer (ignoring the
4150 trailing NULL) on success. (could be extended to return one of the
4151 SERIAL status indications). */
4154 read_frame (char *buf
,
4166 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
4167 c
= readchar (remote_timeout
);
4170 case SERIAL_TIMEOUT
:
4172 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4176 fputs_filtered ("Saw new packet start in middle of old one\n",
4178 return -1; /* Start a new packet, count retries */
4181 unsigned char pktcsum
;
4187 check_0
= readchar (remote_timeout
);
4189 check_1
= readchar (remote_timeout
);
4191 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4194 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog
);
4197 else if (check_0
< 0 || check_1
< 0)
4200 fputs_filtered ("Communication error in checksum\n", gdb_stdlog
);
4204 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4205 if (csum
== pktcsum
)
4210 fprintf_filtered (gdb_stdlog
,
4211 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4213 fputs_filtered (buf
, gdb_stdlog
);
4214 fputs_filtered ("\n", gdb_stdlog
);
4216 /* Number of characters in buffer ignoring trailing
4220 case '*': /* Run length encoding */
4225 if (remote_cisco_mode
== 0)
4227 c
= readchar (remote_timeout
);
4229 repeat
= c
- ' ' + 3; /* Compute repeat count */
4233 /* Cisco's run-length encoding variant uses two
4234 hex chars to represent the repeat count. */
4236 c
= readchar (remote_timeout
);
4238 repeat
= fromhex (c
) << 4;
4239 c
= readchar (remote_timeout
);
4241 repeat
+= fromhex (c
);
4244 /* The character before ``*'' is repeated. */
4246 if (repeat
> 0 && repeat
<= 255
4248 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4250 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4256 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
4257 puts_filtered (buf
);
4258 puts_filtered ("\n");
4262 if (bc
< sizeof_buf
- 1)
4270 puts_filtered ("Remote packet too long: ");
4271 puts_filtered (buf
);
4272 puts_filtered ("\n");
4279 /* Read a packet from the remote machine, with error checking, and
4280 store it in BUF. If FOREVER, wait forever rather than timing out;
4281 this is used (in synchronous mode) to wait for a target that is is
4282 executing user code to stop. */
4283 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4284 don't have to change all the calls to getpkt to deal with the
4285 return value, because at the moment I don't know what the right
4286 thing to do it for those. */
4294 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4298 /* Read a packet from the remote machine, with error checking, and
4299 store it in BUF. If FOREVER, wait forever rather than timing out;
4300 this is used (in synchronous mode) to wait for a target that is is
4301 executing user code to stop. If FOREVER == 0, this function is
4302 allowed to time out gracefully and return an indication of this to
4305 getpkt_sane (char *buf
,
4314 strcpy (buf
, "timeout");
4318 timeout
= watchdog
> 0 ? watchdog
: -1;
4322 timeout
= remote_timeout
;
4326 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4328 /* This can loop forever if the remote side sends us characters
4329 continuously, but if it pauses, we'll get a zero from readchar
4330 because of timeout. Then we'll count that as a retry. */
4332 /* Note that we will only wait forever prior to the start of a packet.
4333 After that, we expect characters to arrive at a brisk pace. They
4334 should show up within remote_timeout intervals. */
4338 c
= readchar (timeout
);
4340 if (c
== SERIAL_TIMEOUT
)
4342 if (forever
) /* Watchdog went off? Kill the target. */
4345 target_mourn_inferior ();
4346 error ("Watchdog has expired. Target detached.\n");
4349 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4355 /* We've found the start of a packet, now collect the data. */
4357 val
= read_frame (buf
, sizeof_buf
);
4363 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4364 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4365 fprintf_unfiltered (gdb_stdlog
, "\n");
4367 serial_write (remote_desc
, "+", 1);
4371 /* Try the whole thing again. */
4373 serial_write (remote_desc
, "-", 1);
4376 /* We have tried hard enough, and just can't receive the packet. Give up. */
4378 printf_unfiltered ("Ignoring packet error, continuing...\n");
4379 serial_write (remote_desc
, "+", 1);
4386 /* For some mysterious reason, wait_for_inferior calls kill instead of
4387 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4391 target_mourn_inferior ();
4395 /* Use catch_errors so the user can quit from gdb even when we aren't on
4396 speaking terms with the remote system. */
4397 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4399 /* Don't wait for it to die. I'm not really sure it matters whether
4400 we do or not. For the existing stubs, kill is a noop. */
4401 target_mourn_inferior ();
4404 /* Async version of remote_kill. */
4406 remote_async_kill (void)
4408 /* Unregister the file descriptor from the event loop. */
4409 if (target_is_async_p ())
4410 serial_async (remote_desc
, NULL
, 0);
4412 /* For some mysterious reason, wait_for_inferior calls kill instead of
4413 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4417 target_mourn_inferior ();
4421 /* Use catch_errors so the user can quit from gdb even when we aren't on
4422 speaking terms with the remote system. */
4423 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4425 /* Don't wait for it to die. I'm not really sure it matters whether
4426 we do or not. For the existing stubs, kill is a noop. */
4427 target_mourn_inferior ();
4433 remote_mourn_1 (&remote_ops
);
4437 remote_async_mourn (void)
4439 remote_mourn_1 (&remote_async_ops
);
4443 extended_remote_mourn (void)
4445 /* We do _not_ want to mourn the target like this; this will
4446 remove the extended remote target from the target stack,
4447 and the next time the user says "run" it'll fail.
4449 FIXME: What is the right thing to do here? */
4451 remote_mourn_1 (&extended_remote_ops
);
4455 /* Worker function for remote_mourn. */
4457 remote_mourn_1 (struct target_ops
*target
)
4459 unpush_target (target
);
4460 generic_mourn_inferior ();
4463 /* In the extended protocol we want to be able to do things like
4464 "run" and have them basically work as expected. So we need
4465 a special create_inferior function.
4467 FIXME: One day add support for changing the exec file
4468 we're debugging, arguments and an environment. */
4471 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
)
4473 /* Rip out the breakpoints; we'll reinsert them after restarting
4474 the remote server. */
4475 remove_breakpoints ();
4477 /* Now restart the remote server. */
4478 extended_remote_restart ();
4480 /* Now put the breakpoints back in. This way we're safe if the
4481 restart function works via a unix fork on the remote side. */
4482 insert_breakpoints ();
4484 /* Clean up from the last time we were running. */
4485 clear_proceed_status ();
4487 /* Let the remote process run. */
4488 proceed (-1, TARGET_SIGNAL_0
, 0);
4491 /* Async version of extended_remote_create_inferior. */
4493 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
)
4495 /* Rip out the breakpoints; we'll reinsert them after restarting
4496 the remote server. */
4497 remove_breakpoints ();
4499 /* If running asynchronously, register the target file descriptor
4500 with the event loop. */
4501 if (event_loop_p
&& target_can_async_p ())
4502 target_async (inferior_event_handler
, 0);
4504 /* Now restart the remote server. */
4505 extended_remote_restart ();
4507 /* Now put the breakpoints back in. This way we're safe if the
4508 restart function works via a unix fork on the remote side. */
4509 insert_breakpoints ();
4511 /* Clean up from the last time we were running. */
4512 clear_proceed_status ();
4514 /* Let the remote process run. */
4515 proceed (-1, TARGET_SIGNAL_0
, 0);
4519 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
4520 than other targets; in those use REMOTE_BREAKPOINT instead of just
4521 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
4522 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
4523 the standard routines that are in mem-break.c. */
4525 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
4526 the choice of breakpoint instruction affects target program design and
4527 vice versa, and by making it user-tweakable, the special code here
4528 goes away and we need fewer special GDB configurations. */
4530 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4531 #define REMOTE_BREAKPOINT
4534 #ifdef REMOTE_BREAKPOINT
4536 /* If the target isn't bi-endian, just pretend it is. */
4537 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
4538 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4539 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4542 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
4543 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
4545 #endif /* REMOTE_BREAKPOINT */
4547 /* Insert a breakpoint on targets that don't have any better breakpoint
4548 support. We read the contents of the target location and stash it,
4549 then overwrite it with a breakpoint instruction. ADDR is the target
4550 location in the target machine. CONTENTS_CACHE is a pointer to
4551 memory allocated for saving the target contents. It is guaranteed
4552 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
4553 is accomplished via BREAKPOINT_MAX). */
4556 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4558 struct remote_state
*rs
= get_remote_state ();
4559 #ifdef REMOTE_BREAKPOINT
4564 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4565 If it succeeds, then set the support to PACKET_ENABLE. If it
4566 fails, and the user has explicitly requested the Z support then
4567 report an error, otherwise, mark it disabled and go on. */
4569 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4571 char *buf
= alloca (rs
->remote_packet_size
);
4574 addr
= remote_address_masked (addr
);
4578 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4579 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4580 sprintf (p
, ",%d", bp_size
);
4583 getpkt (buf
, (rs
->remote_packet_size
), 0);
4585 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4591 case PACKET_UNKNOWN
:
4596 #ifdef REMOTE_BREAKPOINT
4597 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4601 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
4602 val
= target_write_memory (addr
, (char *) big_break_insn
,
4603 sizeof big_break_insn
);
4605 val
= target_write_memory (addr
, (char *) little_break_insn
,
4606 sizeof little_break_insn
);
4611 return memory_insert_breakpoint (addr
, contents_cache
);
4612 #endif /* REMOTE_BREAKPOINT */
4616 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4618 struct remote_state
*rs
= get_remote_state ();
4621 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4623 char *buf
= alloca (rs
->remote_packet_size
);
4630 addr
= remote_address_masked (addr
);
4631 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4632 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4633 sprintf (p
, ",%d", bp_size
);
4636 getpkt (buf
, (rs
->remote_packet_size
), 0);
4638 return (buf
[0] == 'E');
4641 #ifdef REMOTE_BREAKPOINT
4642 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4644 return memory_remove_breakpoint (addr
, contents_cache
);
4645 #endif /* REMOTE_BREAKPOINT */
4649 watchpoint_to_Z_packet (int type
)
4663 internal_error (__FILE__
, __LINE__
,
4664 "hw_bp_to_z: bad watchpoint type %d", type
);
4668 /* FIXME: This function should be static and a member of the remote
4672 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4674 struct remote_state
*rs
= get_remote_state ();
4675 char *buf
= alloca (rs
->remote_packet_size
);
4677 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4679 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4680 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4681 remote_protocol_Z
[packet
].name
,
4682 remote_protocol_Z
[packet
].title
);
4684 sprintf (buf
, "Z%x,", packet
);
4685 p
= strchr (buf
, '\0');
4686 addr
= remote_address_masked (addr
);
4687 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4688 sprintf (p
, ",%x", len
);
4691 getpkt (buf
, (rs
->remote_packet_size
), 0);
4693 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4696 case PACKET_UNKNOWN
:
4701 internal_error (__FILE__
, __LINE__
,
4702 "remote_insert_watchpoint: reached end of function");
4705 /* FIXME: This function should be static and a member of the remote
4709 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4711 struct remote_state
*rs
= get_remote_state ();
4712 char *buf
= alloca (rs
->remote_packet_size
);
4714 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4716 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4717 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4718 remote_protocol_Z
[packet
].name
,
4719 remote_protocol_Z
[packet
].title
);
4721 sprintf (buf
, "z%x,", packet
);
4722 p
= strchr (buf
, '\0');
4723 addr
= remote_address_masked (addr
);
4724 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4725 sprintf (p
, ",%x", len
);
4727 getpkt (buf
, (rs
->remote_packet_size
), 0);
4729 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4732 case PACKET_UNKNOWN
:
4737 internal_error (__FILE__
, __LINE__
,
4738 "remote_remove_watchpoint: reached end of function");
4741 /* FIXME: This function should be static and a member of the remote
4745 remote_insert_hw_breakpoint (CORE_ADDR addr
, int len
)
4747 struct remote_state
*rs
= get_remote_state ();
4748 char *buf
= alloca (rs
->remote_packet_size
);
4751 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4752 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4753 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4754 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4760 addr
= remote_address_masked (addr
);
4761 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4762 sprintf (p
, ",%x", len
);
4765 getpkt (buf
, (rs
->remote_packet_size
), 0);
4767 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4770 case PACKET_UNKNOWN
:
4775 internal_error (__FILE__
, __LINE__
,
4776 "remote_remove_watchpoint: reached end of function");
4779 /* FIXME: This function should be static and a member of the remote
4783 remote_remove_hw_breakpoint (CORE_ADDR addr
, int len
)
4785 struct remote_state
*rs
= get_remote_state ();
4786 char *buf
= alloca (rs
->remote_packet_size
);
4789 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4790 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
4791 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4792 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4798 addr
= remote_address_masked (addr
);
4799 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4800 sprintf (p
, ",%x", len
);
4803 getpkt (buf
, (rs
->remote_packet_size
), 0);
4805 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4808 case PACKET_UNKNOWN
:
4813 internal_error (__FILE__
, __LINE__
,
4814 "remote_remove_watchpoint: reached end of function");
4817 /* Some targets are only capable of doing downloads, and afterwards
4818 they switch to the remote serial protocol. This function provides
4819 a clean way to get from the download target to the remote target.
4820 It's basically just a wrapper so that we don't have to expose any
4821 of the internal workings of remote.c.
4823 Prior to calling this routine, you should shutdown the current
4824 target code, else you will get the "A program is being debugged
4825 already..." message. Usually a call to pop_target() suffices. */
4828 push_remote_target (char *name
, int from_tty
)
4830 printf_filtered ("Switching to remote protocol\n");
4831 remote_open (name
, from_tty
);
4834 /* Other targets want to use the entire remote serial module but with
4835 certain remote_ops overridden. */
4838 open_remote_target (char *name
, int from_tty
, struct target_ops
*target
,
4841 printf_filtered ("Selecting the %sremote protocol\n",
4842 (extended_p
? "extended-" : ""));
4843 remote_open_1 (name
, from_tty
, target
, extended_p
);
4846 /* Table used by the crc32 function to calcuate the checksum. */
4848 static unsigned long crc32_table
[256] =
4851 static unsigned long
4852 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4854 if (!crc32_table
[1])
4856 /* Initialize the CRC table and the decoding table. */
4860 for (i
= 0; i
< 256; i
++)
4862 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4863 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4870 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4876 /* compare-sections command
4878 With no arguments, compares each loadable section in the exec bfd
4879 with the same memory range on the target, and reports mismatches.
4880 Useful for verifying the image on the target against the exec file.
4881 Depends on the target understanding the new "qCRC:" request. */
4883 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4884 target method (target verify memory) and generic version of the
4885 actual command. This will allow other high-level code (especially
4886 generic_load()) to make use of this target functionality. */
4889 compare_sections_command (char *args
, int from_tty
)
4891 struct remote_state
*rs
= get_remote_state ();
4893 unsigned long host_crc
, target_crc
;
4894 extern bfd
*exec_bfd
;
4895 struct cleanup
*old_chain
;
4898 const char *sectname
;
4899 char *buf
= alloca (rs
->remote_packet_size
);
4906 error ("command cannot be used without an exec file");
4907 if (!current_target
.to_shortname
||
4908 strcmp (current_target
.to_shortname
, "remote") != 0)
4909 error ("command can only be used with remote target");
4911 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4913 if (!(s
->flags
& SEC_LOAD
))
4914 continue; /* skip non-loadable section */
4916 size
= bfd_get_section_size_before_reloc (s
);
4918 continue; /* skip zero-length section */
4920 sectname
= bfd_get_section_name (exec_bfd
, s
);
4921 if (args
&& strcmp (args
, sectname
) != 0)
4922 continue; /* not the section selected by user */
4924 matched
= 1; /* do this section */
4926 /* FIXME: assumes lma can fit into long */
4927 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
4930 /* be clever; compute the host_crc before waiting for target reply */
4931 sectdata
= xmalloc (size
);
4932 old_chain
= make_cleanup (xfree
, sectdata
);
4933 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
4934 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
4936 getpkt (buf
, (rs
->remote_packet_size
), 0);
4938 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
4939 sectname
, lma
, lma
+ size
);
4941 error ("remote target does not support this operation");
4943 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
4944 target_crc
= target_crc
* 16 + fromhex (*tmp
);
4946 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4947 sectname
, paddr (lma
), paddr (lma
+ size
));
4948 if (host_crc
== target_crc
)
4949 printf_filtered ("matched.\n");
4952 printf_filtered ("MIS-MATCHED!\n");
4956 do_cleanups (old_chain
);
4959 warning ("One or more sections of the remote executable does not match\n\
4960 the loaded file\n");
4961 if (args
&& !matched
)
4962 printf_filtered ("No loaded section named '%s'.\n", args
);
4966 remote_query (int query_type
, char *buf
, char *outbuf
, int *bufsiz
)
4968 struct remote_state
*rs
= get_remote_state ();
4970 char *buf2
= alloca (rs
->remote_packet_size
);
4971 char *p2
= &buf2
[0];
4974 error ("null pointer to remote bufer size specified");
4976 /* minimum outbuf size is (rs->remote_packet_size) - if bufsiz is not large enough let
4977 the caller know and return what the minimum size is */
4978 /* Note: a zero bufsiz can be used to query the minimum buffer size */
4979 if (*bufsiz
< (rs
->remote_packet_size
))
4981 *bufsiz
= (rs
->remote_packet_size
);
4985 /* except for querying the minimum buffer size, target must be open */
4987 error ("remote query is only available after target open");
4989 /* we only take uppercase letters as query types, at least for now */
4990 if ((query_type
< 'A') || (query_type
> 'Z'))
4991 error ("invalid remote query type");
4994 error ("null remote query specified");
4997 error ("remote query requires a buffer to receive data");
5004 /* we used one buffer char for the remote protocol q command and another
5005 for the query type. As the remote protocol encapsulation uses 4 chars
5006 plus one extra in case we are debugging (remote_debug),
5007 we have PBUFZIZ - 7 left to pack the query string */
5009 while (buf
[i
] && (i
< ((rs
->remote_packet_size
) - 8)))
5011 /* bad caller may have sent forbidden characters */
5012 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
5013 error ("illegal characters in query string");
5021 error ("query larger than available buffer");
5027 getpkt (outbuf
, *bufsiz
, 0);
5033 remote_rcmd (char *command
,
5034 struct ui_file
*outbuf
)
5036 struct remote_state
*rs
= get_remote_state ();
5038 char *buf
= alloca (rs
->remote_packet_size
);
5042 error ("remote rcmd is only available after target open");
5044 /* Send a NULL command across as an empty command */
5045 if (command
== NULL
)
5048 /* The query prefix */
5049 strcpy (buf
, "qRcmd,");
5050 p
= strchr (buf
, '\0');
5052 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > (rs
->remote_packet_size
))
5053 error ("\"monitor\" command ``%s'' is too long\n", command
);
5055 /* Encode the actual command */
5056 bin2hex (command
, p
, 0);
5058 if (putpkt (buf
) < 0)
5059 error ("Communication problem with target\n");
5061 /* get/display the response */
5064 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
5066 getpkt (buf
, (rs
->remote_packet_size
), 0);
5068 error ("Target does not support this command\n");
5069 if (buf
[0] == 'O' && buf
[1] != 'K')
5071 remote_console_output (buf
+ 1); /* 'O' message from stub */
5074 if (strcmp (buf
, "OK") == 0)
5076 if (strlen (buf
) == 3 && buf
[0] == 'E'
5077 && isdigit (buf
[1]) && isdigit (buf
[2]))
5079 error ("Protocol error with Rcmd");
5081 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5083 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5084 fputc_unfiltered (c
, outbuf
);
5091 packet_command (char *args
, int from_tty
)
5093 struct remote_state
*rs
= get_remote_state ();
5094 char *buf
= alloca (rs
->remote_packet_size
);
5097 error ("command can only be used with remote target");
5100 error ("remote-packet command requires packet text as argument");
5102 puts_filtered ("sending: ");
5103 print_packet (args
);
5104 puts_filtered ("\n");
5107 getpkt (buf
, (rs
->remote_packet_size
), 0);
5108 puts_filtered ("received: ");
5110 puts_filtered ("\n");
5114 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
5116 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5118 static void threadset_test_cmd (char *cmd
, int tty
);
5120 static void threadalive_test (char *cmd
, int tty
);
5122 static void threadlist_test_cmd (char *cmd
, int tty
);
5124 int get_and_display_threadinfo (threadref
* ref
);
5126 static void threadinfo_test_cmd (char *cmd
, int tty
);
5128 static int thread_display_step (threadref
* ref
, void *context
);
5130 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5132 static void init_remote_threadtests (void);
5134 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
5137 threadset_test_cmd (char *cmd
, int tty
)
5139 int sample_thread
= SAMPLE_THREAD
;
5141 printf_filtered ("Remote threadset test\n");
5142 set_thread (sample_thread
, 1);
5147 threadalive_test (char *cmd
, int tty
)
5149 int sample_thread
= SAMPLE_THREAD
;
5151 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5152 printf_filtered ("PASS: Thread alive test\n");
5154 printf_filtered ("FAIL: Thread alive test\n");
5157 void output_threadid (char *title
, threadref
* ref
);
5160 output_threadid (char *title
, threadref
*ref
)
5164 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
5166 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5170 threadlist_test_cmd (char *cmd
, int tty
)
5173 threadref nextthread
;
5174 int done
, result_count
;
5175 threadref threadlist
[3];
5177 printf_filtered ("Remote Threadlist test\n");
5178 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5179 &result_count
, &threadlist
[0]))
5180 printf_filtered ("FAIL: threadlist test\n");
5183 threadref
*scan
= threadlist
;
5184 threadref
*limit
= scan
+ result_count
;
5186 while (scan
< limit
)
5187 output_threadid (" thread ", scan
++);
5192 display_thread_info (struct gdb_ext_thread_info
*info
)
5194 output_threadid ("Threadid: ", &info
->threadid
);
5195 printf_filtered ("Name: %s\n ", info
->shortname
);
5196 printf_filtered ("State: %s\n", info
->display
);
5197 printf_filtered ("other: %s\n\n", info
->more_display
);
5201 get_and_display_threadinfo (threadref
*ref
)
5205 struct gdb_ext_thread_info threadinfo
;
5207 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5208 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5209 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5210 display_thread_info (&threadinfo
);
5215 threadinfo_test_cmd (char *cmd
, int tty
)
5217 int athread
= SAMPLE_THREAD
;
5221 int_to_threadref (&thread
, athread
);
5222 printf_filtered ("Remote Threadinfo test\n");
5223 if (!get_and_display_threadinfo (&thread
))
5224 printf_filtered ("FAIL cannot get thread info\n");
5228 thread_display_step (threadref
*ref
, void *context
)
5230 /* output_threadid(" threadstep ",ref); *//* simple test */
5231 return get_and_display_threadinfo (ref
);
5235 threadlist_update_test_cmd (char *cmd
, int tty
)
5237 printf_filtered ("Remote Threadlist update test\n");
5238 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5242 init_remote_threadtests (void)
5244 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
5245 "Fetch and print the remote list of thread identifiers, one pkt only");
5246 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5247 "Fetch and display info about one thread");
5248 add_com ("tset", class_obscure
, threadset_test_cmd
,
5249 "Test setting to a different thread");
5250 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5251 "Iterate through updating all remote thread info");
5252 add_com ("talive", class_obscure
, threadalive_test
,
5253 " Remote thread alive test ");
5258 /* Convert a thread ID to a string. Returns the string in a static
5262 remote_pid_to_str (ptid_t ptid
)
5264 static char buf
[30];
5266 sprintf (buf
, "Thread %d", PIDGET (ptid
));
5271 init_remote_ops (void)
5273 remote_ops
.to_shortname
= "remote";
5274 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5276 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5277 Specify the serial device it is connected to\n\
5278 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5279 remote_ops
.to_open
= remote_open
;
5280 remote_ops
.to_close
= remote_close
;
5281 remote_ops
.to_detach
= remote_detach
;
5282 remote_ops
.to_resume
= remote_resume
;
5283 remote_ops
.to_wait
= remote_wait
;
5284 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5285 remote_ops
.to_store_registers
= remote_store_registers
;
5286 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5287 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
5288 remote_ops
.to_files_info
= remote_files_info
;
5289 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5290 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5291 remote_ops
.to_kill
= remote_kill
;
5292 remote_ops
.to_load
= generic_load
;
5293 remote_ops
.to_mourn_inferior
= remote_mourn
;
5294 remote_ops
.to_thread_alive
= remote_thread_alive
;
5295 remote_ops
.to_find_new_threads
= remote_threads_info
;
5296 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5297 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5298 remote_ops
.to_stop
= remote_stop
;
5299 remote_ops
.to_query
= remote_query
;
5300 remote_ops
.to_rcmd
= remote_rcmd
;
5301 remote_ops
.to_stratum
= process_stratum
;
5302 remote_ops
.to_has_all_memory
= 1;
5303 remote_ops
.to_has_memory
= 1;
5304 remote_ops
.to_has_stack
= 1;
5305 remote_ops
.to_has_registers
= 1;
5306 remote_ops
.to_has_execution
= 1;
5307 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5308 remote_ops
.to_magic
= OPS_MAGIC
;
5311 /* Set up the extended remote vector by making a copy of the standard
5312 remote vector and adding to it. */
5315 init_extended_remote_ops (void)
5317 extended_remote_ops
= remote_ops
;
5319 extended_remote_ops
.to_shortname
= "extended-remote";
5320 extended_remote_ops
.to_longname
=
5321 "Extended remote serial target in gdb-specific protocol";
5322 extended_remote_ops
.to_doc
=
5323 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5324 Specify the serial device it is connected to (e.g. /dev/ttya).",
5325 extended_remote_ops
.to_open
= extended_remote_open
;
5326 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5327 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5331 * Command: info remote-process
5333 * This implements Cisco's version of the "info proc" command.
5335 * This query allows the target stub to return an arbitrary string
5336 * (or strings) giving arbitrary information about the target process.
5337 * This is optional; the target stub isn't required to implement it.
5339 * Syntax: qfProcessInfo request first string
5340 * qsProcessInfo request subsequent string
5341 * reply: 'O'<hex-encoded-string>
5342 * 'l' last reply (empty)
5346 remote_info_process (char *args
, int from_tty
)
5348 struct remote_state
*rs
= get_remote_state ();
5349 char *buf
= alloca (rs
->remote_packet_size
);
5351 if (remote_desc
== 0)
5352 error ("Command can only be used when connected to the remote target.");
5354 putpkt ("qfProcessInfo");
5355 getpkt (buf
, (rs
->remote_packet_size
), 0);
5357 return; /* Silently: target does not support this feature. */
5360 error ("info proc: target error.");
5362 while (buf
[0] == 'O') /* Capitol-O packet */
5364 remote_console_output (&buf
[1]);
5365 putpkt ("qsProcessInfo");
5366 getpkt (buf
, (rs
->remote_packet_size
), 0);
5375 remote_cisco_open (char *name
, int from_tty
)
5379 "To open a remote debug connection, you need to specify what \n\
5380 device is attached to the remote system (e.g. host:port).");
5382 /* See FIXME above */
5383 wait_forever_enabled_p
= 1;
5385 target_preopen (from_tty
);
5387 unpush_target (&remote_cisco_ops
);
5389 remote_desc
= serial_open (name
);
5391 perror_with_name (name
);
5394 * If a baud rate was specified on the gdb command line it will
5395 * be greater than the initial value of -1. If it is, use it otherwise
5399 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
5400 if (serial_setbaudrate (remote_desc
, baud_rate
))
5402 serial_close (remote_desc
);
5403 perror_with_name (name
);
5406 serial_raw (remote_desc
);
5408 /* If there is something sitting in the buffer we might take it as a
5409 response to a command, which would be bad. */
5410 serial_flush_input (remote_desc
);
5414 puts_filtered ("Remote debugging using ");
5415 puts_filtered (name
);
5416 puts_filtered ("\n");
5419 remote_cisco_mode
= 1;
5421 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
5423 init_all_packet_configs ();
5425 general_thread
= -2;
5426 continue_thread
= -2;
5428 /* Probe for ability to use "ThreadInfo" query, as required. */
5429 use_threadinfo_query
= 1;
5430 use_threadextra_query
= 1;
5432 /* Without this, some commands which require an active target (such
5433 as kill) won't work. This variable serves (at least) double duty
5434 as both the pid of the target process (if it has such), and as a
5435 flag indicating that a target is active. These functions should
5436 be split out into seperate variables, especially since GDB will
5437 someday have a notion of debugging several processes. */
5438 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
5440 /* Start the remote connection; if error (0), discard this target. */
5442 if (!catch_errors (remote_start_remote_dummy
, (char *) 0,
5443 "Couldn't establish connection to remote target\n",
5452 remote_cisco_close (int quitting
)
5454 remote_cisco_mode
= 0;
5455 remote_close (quitting
);
5459 remote_cisco_mourn (void)
5461 remote_mourn_1 (&remote_cisco_ops
);
5473 /* Shared between readsocket() and readtty(). The size is arbitrary,
5474 however all targets are known to support a 400 character packet. */
5475 static char tty_input
[400];
5477 static int escape_count
;
5478 static int echo_check
;
5479 extern int quit_flag
;
5486 /* Loop until the socket doesn't have any more data */
5488 while ((data
= readchar (0)) >= 0)
5490 /* Check for the escape sequence */
5493 /* If this is the fourth escape, get out */
5494 if (++escape_count
== 4)
5499 { /* This is a '|', but not the fourth in a row.
5500 Continue without echoing it. If it isn't actually
5501 one of four in a row, it'll be echoed later. */
5508 /* Ensure any pending '|'s are flushed. */
5510 for (; escape_count
> 0; escape_count
--)
5514 if (data
== '\r') /* If this is a return character, */
5515 continue; /* - just supress it. */
5517 if (echo_check
!= -1) /* Check for echo of user input. */
5519 if (tty_input
[echo_check
] == data
)
5521 gdb_assert (echo_check
<= sizeof (tty_input
));
5522 echo_check
++; /* Character matched user input: */
5523 continue; /* Continue without echoing it. */
5525 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5526 { /* End of the line (and of echo checking). */
5527 echo_check
= -1; /* No more echo supression */
5528 continue; /* Continue without echoing. */
5531 { /* Failed check for echo of user input.
5532 We now have some suppressed output to flush! */
5535 for (j
= 0; j
< echo_check
; j
++)
5536 putchar (tty_input
[j
]);
5540 putchar (data
); /* Default case: output the char. */
5543 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5544 return READ_MORE
; /* Try to read some more */
5546 return FATAL_ERROR
; /* Trouble, bail out */
5554 /* First, read a buffer full from the terminal */
5555 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5556 if (tty_bytecount
== -1)
5558 perror ("readtty: read failed");
5562 /* Remove a quoted newline. */
5563 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5564 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5566 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5567 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5570 /* Turn trailing newlines into returns */
5571 if (tty_input
[tty_bytecount
- 1] == '\n')
5572 tty_input
[tty_bytecount
- 1] = '\r';
5574 /* If the line consists of a ~, enter debugging mode. */
5575 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5578 /* Make this a zero terminated string and write it out */
5579 tty_input
[tty_bytecount
] = 0;
5580 if (serial_write (remote_desc
, tty_input
, tty_bytecount
))
5582 perror_with_name ("readtty: write failed");
5592 fd_set input
; /* file descriptors for select */
5593 int tablesize
; /* max number of FDs for select */
5597 extern int escape_count
; /* global shared by readsocket */
5598 extern int echo_check
; /* ditto */
5603 tablesize
= 8 * sizeof (input
);
5607 /* Check for anything from our socket - doesn't block. Note that
5608 this must be done *before* the select as there may be
5609 buffered I/O waiting to be processed. */
5611 if ((status
= readsocket ()) == FATAL_ERROR
)
5613 error ("Debugging terminated by communications error");
5615 else if (status
!= READ_MORE
)
5620 fflush (stdout
); /* Flush output before blocking */
5622 /* Now block on more socket input or TTY input */
5625 FD_SET (fileno (stdin
), &input
);
5626 FD_SET (deprecated_serial_fd (remote_desc
), &input
);
5628 status
= select (tablesize
, &input
, 0, 0, 0);
5629 if ((status
== -1) && (errno
!= EINTR
))
5631 error ("Communications error on select %d", errno
);
5634 /* Handle Control-C typed */
5638 if ((++quit_count
) == 2)
5640 if (query ("Interrupt GDB? "))
5642 printf_filtered ("Interrupted by user.\n");
5643 return_to_top_level (RETURN_QUIT
);
5650 serial_send_break (remote_desc
);
5652 serial_write (remote_desc
, "\003", 1);
5657 /* Handle console input */
5659 if (FD_ISSET (fileno (stdin
), &input
))
5663 status
= readtty ();
5664 if (status
== READ_MORE
)
5667 return status
; /* telnet session ended */
5673 remote_cisco_wait (ptid_t ptid
, struct target_waitstatus
*status
)
5675 if (minitelnet () != ENTER_DEBUG
)
5677 error ("Debugging session terminated by protocol error");
5680 return remote_wait (ptid
, status
);
5684 init_remote_cisco_ops (void)
5686 remote_cisco_ops
.to_shortname
= "cisco";
5687 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5688 remote_cisco_ops
.to_doc
=
5689 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5690 Specify the serial device it is connected to (e.g. host:2020).";
5691 remote_cisco_ops
.to_open
= remote_cisco_open
;
5692 remote_cisco_ops
.to_close
= remote_cisco_close
;
5693 remote_cisco_ops
.to_detach
= remote_detach
;
5694 remote_cisco_ops
.to_resume
= remote_resume
;
5695 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5696 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5697 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5698 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5699 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5700 remote_cisco_ops
.to_files_info
= remote_files_info
;
5701 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5702 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5703 remote_cisco_ops
.to_kill
= remote_kill
;
5704 remote_cisco_ops
.to_load
= generic_load
;
5705 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5706 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5707 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5708 remote_cisco_ops
.to_pid_to_str
= remote_pid_to_str
;
5709 remote_cisco_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5710 remote_cisco_ops
.to_stratum
= process_stratum
;
5711 remote_cisco_ops
.to_has_all_memory
= 1;
5712 remote_cisco_ops
.to_has_memory
= 1;
5713 remote_cisco_ops
.to_has_stack
= 1;
5714 remote_cisco_ops
.to_has_registers
= 1;
5715 remote_cisco_ops
.to_has_execution
= 1;
5716 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5720 remote_can_async_p (void)
5722 /* We're async whenever the serial device is. */
5723 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5727 remote_is_async_p (void)
5729 /* We're async whenever the serial device is. */
5730 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5733 /* Pass the SERIAL event on and up to the client. One day this code
5734 will be able to delay notifying the client of an event until the
5735 point where an entire packet has been received. */
5737 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5738 static void *async_client_context
;
5739 static serial_event_ftype remote_async_serial_handler
;
5742 remote_async_serial_handler (struct serial
*scb
, void *context
)
5744 /* Don't propogate error information up to the client. Instead let
5745 the client find out about the error by querying the target. */
5746 async_client_callback (INF_REG_EVENT
, async_client_context
);
5750 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5752 if (current_target
.to_async_mask_value
== 0)
5753 internal_error (__FILE__
, __LINE__
,
5754 "Calling remote_async when async is masked");
5756 if (callback
!= NULL
)
5758 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5759 async_client_callback
= callback
;
5760 async_client_context
= context
;
5763 serial_async (remote_desc
, NULL
, NULL
);
5766 /* Target async and target extended-async.
5768 This are temporary targets, until it is all tested. Eventually
5769 async support will be incorporated int the usual 'remote'
5773 init_remote_async_ops (void)
5775 remote_async_ops
.to_shortname
= "async";
5776 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5777 remote_async_ops
.to_doc
=
5778 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5779 Specify the serial device it is connected to (e.g. /dev/ttya).";
5780 remote_async_ops
.to_open
= remote_async_open
;
5781 remote_async_ops
.to_close
= remote_close
;
5782 remote_async_ops
.to_detach
= remote_async_detach
;
5783 remote_async_ops
.to_resume
= remote_async_resume
;
5784 remote_async_ops
.to_wait
= remote_async_wait
;
5785 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5786 remote_async_ops
.to_store_registers
= remote_store_registers
;
5787 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5788 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5789 remote_async_ops
.to_files_info
= remote_files_info
;
5790 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5791 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5792 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5793 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5794 remote_async_ops
.to_kill
= remote_async_kill
;
5795 remote_async_ops
.to_load
= generic_load
;
5796 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5797 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5798 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5799 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
5800 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5801 remote_async_ops
.to_stop
= remote_stop
;
5802 remote_async_ops
.to_query
= remote_query
;
5803 remote_async_ops
.to_rcmd
= remote_rcmd
;
5804 remote_async_ops
.to_stratum
= process_stratum
;
5805 remote_async_ops
.to_has_all_memory
= 1;
5806 remote_async_ops
.to_has_memory
= 1;
5807 remote_async_ops
.to_has_stack
= 1;
5808 remote_async_ops
.to_has_registers
= 1;
5809 remote_async_ops
.to_has_execution
= 1;
5810 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5811 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5812 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5813 remote_async_ops
.to_async
= remote_async
;
5814 remote_async_ops
.to_async_mask_value
= 1;
5815 remote_async_ops
.to_magic
= OPS_MAGIC
;
5818 /* Set up the async extended remote vector by making a copy of the standard
5819 remote vector and adding to it. */
5822 init_extended_async_remote_ops (void)
5824 extended_async_remote_ops
= remote_async_ops
;
5826 extended_async_remote_ops
.to_shortname
= "extended-async";
5827 extended_async_remote_ops
.to_longname
=
5828 "Extended remote serial target in async gdb-specific protocol";
5829 extended_async_remote_ops
.to_doc
=
5830 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5831 Specify the serial device it is connected to (e.g. /dev/ttya).",
5832 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5833 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5834 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5838 set_remote_cmd (char *args
, int from_tty
)
5843 show_remote_cmd (char *args
, int from_tty
)
5846 show_remote_protocol_Z_packet_cmd (args
, from_tty
);
5847 show_remote_protocol_e_packet_cmd (args
, from_tty
);
5848 show_remote_protocol_E_packet_cmd (args
, from_tty
);
5849 show_remote_protocol_P_packet_cmd (args
, from_tty
);
5850 show_remote_protocol_qSymbol_packet_cmd (args
, from_tty
);
5851 show_remote_protocol_binary_download_cmd (args
, from_tty
);
5855 build_remote_gdbarch_data (void)
5857 remote_address_size
= TARGET_ADDR_BIT
;
5860 /* Saved pointer to previous owner of the new_objfile event. */
5861 static void (*remote_new_objfile_chain
) (struct objfile
*);
5863 /* Function to be called whenever a new objfile (shlib) is detected. */
5865 remote_new_objfile (struct objfile
*objfile
)
5867 if (remote_desc
!= 0) /* Have a remote connection */
5869 remote_check_symbols (objfile
);
5871 /* Call predecessor on chain, if any. */
5872 if (remote_new_objfile_chain
!= 0 &&
5874 remote_new_objfile_chain (objfile
);
5878 _initialize_remote (void)
5880 static struct cmd_list_element
*remote_set_cmdlist
;
5881 static struct cmd_list_element
*remote_show_cmdlist
;
5882 struct cmd_list_element
*tmpcmd
;
5884 /* architecture specific data */
5885 remote_gdbarch_data_handle
= register_gdbarch_data (init_remote_state
,
5888 /* Old tacky stuff. NOTE: This comes after the remote protocol so
5889 that the remote protocol has been initialized. */
5890 register_gdbarch_swap (&remote_address_size
,
5891 sizeof (&remote_address_size
), NULL
);
5892 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5895 add_target (&remote_ops
);
5897 init_extended_remote_ops ();
5898 add_target (&extended_remote_ops
);
5900 init_remote_async_ops ();
5901 add_target (&remote_async_ops
);
5903 init_extended_async_remote_ops ();
5904 add_target (&extended_async_remote_ops
);
5906 init_remote_cisco_ops ();
5907 add_target (&remote_cisco_ops
);
5909 /* Hook into new objfile notification. */
5910 remote_new_objfile_chain
= target_new_objfile_hook
;
5911 target_new_objfile_hook
= remote_new_objfile
;
5914 init_remote_threadtests ();
5917 /* set/show remote ... */
5919 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
5920 Remote protocol specific variables\n\
5921 Configure various remote-protocol specific variables such as\n\
5922 the packets being used",
5923 &remote_set_cmdlist
, "set remote ",
5924 0/*allow-unknown*/, &setlist
);
5925 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, "\
5926 Remote protocol specific variables\n\
5927 Configure various remote-protocol specific variables such as\n\
5928 the packets being used",
5929 &remote_show_cmdlist
, "show remote ",
5930 0/*allow-unknown*/, &showlist
);
5932 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
5933 "Compare section data on target to the exec file.\n\
5934 Argument is a single section name (default: all loaded sections).",
5937 add_cmd ("packet", class_maintenance
, packet_command
,
5938 "Send an arbitrary packet to a remote target.\n\
5939 maintenance packet TEXT\n\
5940 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5941 this command sends the string TEXT to the inferior, and displays the\n\
5942 response packet. GDB supplies the initial `$' character, and the\n\
5943 terminating `#' character and checksum.",
5947 (add_set_boolean_cmd ("remotebreak", no_class
, &remote_break
,
5948 "Set whether to send break if interrupted.\n",
5952 /* Install commands for configuring memory read/write packets. */
5954 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
5955 "Set the maximum number of bytes per memory write packet (deprecated).\n",
5957 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
,
5958 "Show the maximum number of bytes per memory write packet (deprecated).\n",
5960 add_cmd ("memory-write-packet-size", no_class
,
5961 set_memory_write_packet_size
,
5962 "Set the maximum number of bytes per memory-write packet.\n"
5963 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5964 "default packet size. The actual limit is further reduced\n"
5965 "dependent on the target. Specify ``fixed'' to disable the\n"
5966 "further restriction and ``limit'' to enable that restriction\n",
5967 &remote_set_cmdlist
);
5968 add_cmd ("memory-read-packet-size", no_class
,
5969 set_memory_read_packet_size
,
5970 "Set the maximum number of bytes per memory-read packet.\n"
5971 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5972 "default packet size. The actual limit is further reduced\n"
5973 "dependent on the target. Specify ``fixed'' to disable the\n"
5974 "further restriction and ``limit'' to enable that restriction\n",
5975 &remote_set_cmdlist
);
5976 add_cmd ("memory-write-packet-size", no_class
,
5977 show_memory_write_packet_size
,
5978 "Show the maximum number of bytes per memory-write packet.\n",
5979 &remote_show_cmdlist
);
5980 add_cmd ("memory-read-packet-size", no_class
,
5981 show_memory_read_packet_size
,
5982 "Show the maximum number of bytes per memory-read packet.\n",
5983 &remote_show_cmdlist
);
5986 (add_set_cmd ("remoteaddresssize", class_obscure
,
5987 var_integer
, (char *) &remote_address_size
,
5988 "Set the maximum size of the address (in bits) \
5989 in a memory packet.\n",
5993 add_packet_config_cmd (&remote_protocol_binary_download
,
5994 "X", "binary-download",
5995 set_remote_protocol_binary_download_cmd
,
5996 show_remote_protocol_binary_download_cmd
,
5997 &remote_set_cmdlist
, &remote_show_cmdlist
,
6000 /* XXXX - should ``set remotebinarydownload'' be retained for
6003 (add_set_cmd ("remotebinarydownload", no_class
,
6004 var_boolean
, (char *) &remote_binary_download
,
6005 "Set binary downloads.\n", &setlist
),
6009 add_info ("remote-process", remote_info_process
,
6010 "Query the remote system for process info.");
6012 add_packet_config_cmd (&remote_protocol_qSymbol
,
6013 "qSymbol", "symbol-lookup",
6014 set_remote_protocol_qSymbol_packet_cmd
,
6015 show_remote_protocol_qSymbol_packet_cmd
,
6016 &remote_set_cmdlist
, &remote_show_cmdlist
,
6019 add_packet_config_cmd (&remote_protocol_e
,
6020 "e", "step-over-range",
6021 set_remote_protocol_e_packet_cmd
,
6022 show_remote_protocol_e_packet_cmd
,
6023 &remote_set_cmdlist
, &remote_show_cmdlist
,
6026 add_packet_config_cmd (&remote_protocol_E
,
6027 "E", "step-over-range-w-signal",
6028 set_remote_protocol_E_packet_cmd
,
6029 show_remote_protocol_E_packet_cmd
,
6030 &remote_set_cmdlist
, &remote_show_cmdlist
,
6033 add_packet_config_cmd (&remote_protocol_P
,
6034 "P", "set-register",
6035 set_remote_protocol_P_packet_cmd
,
6036 show_remote_protocol_P_packet_cmd
,
6037 &remote_set_cmdlist
, &remote_show_cmdlist
,
6040 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
6041 "Z0", "software-breakpoint",
6042 set_remote_protocol_Z_software_bp_packet_cmd
,
6043 show_remote_protocol_Z_software_bp_packet_cmd
,
6044 &remote_set_cmdlist
, &remote_show_cmdlist
,
6047 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
6048 "Z1", "hardware-breakpoint",
6049 set_remote_protocol_Z_hardware_bp_packet_cmd
,
6050 show_remote_protocol_Z_hardware_bp_packet_cmd
,
6051 &remote_set_cmdlist
, &remote_show_cmdlist
,
6054 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
6055 "Z2", "write-watchpoint",
6056 set_remote_protocol_Z_write_wp_packet_cmd
,
6057 show_remote_protocol_Z_write_wp_packet_cmd
,
6058 &remote_set_cmdlist
, &remote_show_cmdlist
,
6061 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
6062 "Z3", "read-watchpoint",
6063 set_remote_protocol_Z_read_wp_packet_cmd
,
6064 show_remote_protocol_Z_read_wp_packet_cmd
,
6065 &remote_set_cmdlist
, &remote_show_cmdlist
,
6068 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
6069 "Z4", "access-watchpoint",
6070 set_remote_protocol_Z_access_wp_packet_cmd
,
6071 show_remote_protocol_Z_access_wp_packet_cmd
,
6072 &remote_set_cmdlist
, &remote_show_cmdlist
,
6075 /* Keep the old ``set remote Z-packet ...'' working. */
6076 tmpcmd
= add_set_auto_boolean_cmd ("Z-packet", class_obscure
,
6077 &remote_Z_packet_detect
,
6079 Set use of remote protocol `Z' packets", &remote_set_cmdlist
);
6080 tmpcmd
->function
.sfunc
= set_remote_protocol_Z_packet_cmd
;
6081 add_cmd ("Z-packet", class_obscure
, show_remote_protocol_Z_packet_cmd
,
6082 "Show use of remote protocol `Z' packets ",
6083 &remote_show_cmdlist
);