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 long offset
; /* Offset into G packet. */
223 long regnum
; /* GDB's internal register number. */
224 LONGEST pnum
; /* Remote protocol register number. */
225 int in_g_packet
; /* Always part of G packet. */
226 /* long size in bytes; == REGISTER_RAW_SIZE (regnum); at present. */
227 /* char *name; == REGISTER_NAME (regnum); at present. */
232 /* Description of the remote protocol registers. */
233 long sizeof_g_packet
;
235 /* Description of the remote protocol registers indexed by REGNUM
236 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
237 struct packet_reg
*regs
;
239 /* This is the size (in chars) of the first response to the ``g''
240 packet. It is used as a heuristic when determining the maximum
241 size of memory-read and memory-write packets. A target will
242 typically only reserve a buffer large enough to hold the ``g''
243 packet. The size does not include packet overhead (headers and
245 long actual_register_packet_size
;
247 /* This is the maximum size (in chars) of a non read/write packet.
248 It is also used as a cap on the size of read/write packets. */
249 long remote_packet_size
;
252 /* Handle for retreving the remote protocol data from gdbarch. */
253 static struct gdbarch_data
*remote_gdbarch_data_handle
;
255 static struct remote_state
*
258 return gdbarch_data (remote_gdbarch_data_handle
);
262 init_remote_state (struct gdbarch
*gdbarch
)
265 struct remote_state
*rs
= xmalloc (sizeof (struct remote_state
));
267 /* Start out by having the remote protocol mimic the existing
268 behavour - just copy in the description of the register cache. */
269 rs
->sizeof_g_packet
= REGISTER_BYTES
; /* OK use. */
271 /* Assume a 1:1 regnum<->pnum table. */
272 rs
->regs
= xcalloc (NUM_REGS
+ NUM_PSEUDO_REGS
, sizeof (struct packet_reg
));
273 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
275 struct packet_reg
*r
= &rs
->regs
[regnum
];
278 r
->offset
= REGISTER_BYTE (regnum
);
279 r
->in_g_packet
= (regnum
< NUM_REGS
);
280 /* ...size = REGISTER_RAW_SIZE (regnum); */
281 /* ...name = REGISTER_NAME (regnum); */
284 /* Default maximum number of characters in a packet body. Many
285 remote stubs have a hardwired buffer size of 400 bytes
286 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
287 as the maximum packet-size to ensure that the packet and an extra
288 NUL character can always fit in the buffer. This stops GDB
289 trashing stubs that try to squeeze an extra NUL into what is
290 already a full buffer (As of 1999-12-04 that was most stubs. */
291 rs
->remote_packet_size
= 400 - 1;
293 /* Should rs->sizeof_g_packet needs more space than the
294 default, adjust the size accordingly. Remember that each byte is
295 encoded as two characters. 32 is the overhead for the packet
296 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
297 (``$NN:G...#NN'') is a better guess, the below has been padded a
299 if (rs
->sizeof_g_packet
> ((rs
->remote_packet_size
- 32) / 2))
300 rs
->remote_packet_size
= (rs
->sizeof_g_packet
* 2 + 32);
302 /* This one is filled in when a ``g'' packet is received. */
303 rs
->actual_register_packet_size
= 0;
309 free_remote_state (struct gdbarch
*gdbarch
, void *pointer
)
311 struct remote_state
*data
= pointer
;
316 static struct packet_reg
*
317 packet_reg_from_regnum (struct remote_state
*rs
, long regnum
)
319 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
323 struct packet_reg
*r
= &rs
->regs
[regnum
];
324 gdb_assert (r
->regnum
== regnum
);
329 static struct packet_reg
*
330 packet_reg_from_pnum (struct remote_state
*rs
, LONGEST pnum
)
333 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
335 struct packet_reg
*r
= &rs
->regs
[i
];
344 static struct target_ops remote_ops
;
346 static struct target_ops extended_remote_ops
;
348 /* Temporary target ops. Just like the remote_ops and
349 extended_remote_ops, but with asynchronous support. */
350 static struct target_ops remote_async_ops
;
352 static struct target_ops extended_async_remote_ops
;
354 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
355 ``forever'' still use the normal timeout mechanism. This is
356 currently used by the ASYNC code to guarentee that target reads
357 during the initial connect always time-out. Once getpkt has been
358 modified to return a timeout indication and, in turn
359 remote_wait()/wait_for_inferior() have gained a timeout parameter
361 static int wait_forever_enabled_p
= 1;
364 /* This variable chooses whether to send a ^C or a break when the user
365 requests program interruption. Although ^C is usually what remote
366 systems expect, and that is the default here, sometimes a break is
367 preferable instead. */
369 static int remote_break
;
371 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
372 remote_open knows that we don't have a file open when the program
374 static struct serial
*remote_desc
= NULL
;
376 /* This is set by the target (thru the 'S' message)
377 to denote that the target is in kernel mode. */
378 static int cisco_kernel_mode
= 0;
380 /* This variable sets the number of bits in an address that are to be
381 sent in a memory ("M" or "m") packet. Normally, after stripping
382 leading zeros, the entire address would be sent. This variable
383 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
384 initial implementation of remote.c restricted the address sent in
385 memory packets to ``host::sizeof long'' bytes - (typically 32
386 bits). Consequently, for 64 bit targets, the upper 32 bits of an
387 address was never sent. Since fixing this bug may cause a break in
388 some remote targets this variable is principly provided to
389 facilitate backward compatibility. */
391 static int remote_address_size
;
393 /* Tempoary to track who currently owns the terminal. See
394 target_async_terminal_* for more details. */
396 static int remote_async_terminal_ours_p
;
399 /* User configurable variables for the number of characters in a
400 memory read/write packet. MIN ((rs->remote_packet_size),
401 rs->sizeof_g_packet) is the default. Some targets need smaller
402 values (fifo overruns, et.al.) and some users need larger values
403 (speed up transfers). The variables ``preferred_*'' (the user
404 request), ``current_*'' (what was actually set) and ``forced_*''
405 (Positive - a soft limit, negative - a hard limit). */
407 struct memory_packet_config
414 /* Compute the current size of a read/write packet. Since this makes
415 use of ``actual_register_packet_size'' the computation is dynamic. */
418 get_memory_packet_size (struct memory_packet_config
*config
)
420 struct remote_state
*rs
= get_remote_state ();
421 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
422 law?) that some hosts don't cope very well with large alloca()
423 calls. Eventually the alloca() code will be replaced by calls to
424 xmalloc() and make_cleanups() allowing this restriction to either
425 be lifted or removed. */
426 #ifndef MAX_REMOTE_PACKET_SIZE
427 #define MAX_REMOTE_PACKET_SIZE 16384
429 /* NOTE: 16 is just chosen at random. */
430 #ifndef MIN_REMOTE_PACKET_SIZE
431 #define MIN_REMOTE_PACKET_SIZE 16
436 if (config
->size
<= 0)
437 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
439 what_they_get
= config
->size
;
443 what_they_get
= (rs
->remote_packet_size
);
444 /* Limit the packet to the size specified by the user. */
446 && what_they_get
> config
->size
)
447 what_they_get
= config
->size
;
448 /* Limit it to the size of the targets ``g'' response. */
449 if ((rs
->actual_register_packet_size
) > 0
450 && what_they_get
> (rs
->actual_register_packet_size
))
451 what_they_get
= (rs
->actual_register_packet_size
);
453 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
454 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
455 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
456 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
457 return what_they_get
;
460 /* Update the size of a read/write packet. If they user wants
461 something really big then do a sanity check. */
464 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
466 int fixed_p
= config
->fixed_p
;
467 long size
= config
->size
;
469 error ("Argument required (integer, `fixed' or `limited').");
470 else if (strcmp (args
, "hard") == 0
471 || strcmp (args
, "fixed") == 0)
473 else if (strcmp (args
, "soft") == 0
474 || strcmp (args
, "limit") == 0)
479 size
= strtoul (args
, &end
, 0);
481 error ("Invalid %s (bad syntax).", config
->name
);
483 /* Instead of explicitly capping the size of a packet to
484 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
485 instead allowed to set the size to something arbitrarily
487 if (size
> MAX_REMOTE_PACKET_SIZE
)
488 error ("Invalid %s (too large).", config
->name
);
492 if (fixed_p
&& !config
->fixed_p
)
494 if (! query ("The target may not be able to correctly handle a %s\n"
495 "of %ld bytes. Change the packet size? ",
497 error ("Packet size not changed.");
499 /* Update the config. */
500 config
->fixed_p
= fixed_p
;
505 show_memory_packet_size (struct memory_packet_config
*config
)
507 printf_filtered ("The %s is %ld. ", config
->name
, config
->size
);
509 printf_filtered ("Packets are fixed at %ld bytes.\n",
510 get_memory_packet_size (config
));
512 printf_filtered ("Packets are limited to %ld bytes.\n",
513 get_memory_packet_size (config
));
516 static struct memory_packet_config memory_write_packet_config
=
518 "memory-write-packet-size",
522 set_memory_write_packet_size (char *args
, int from_tty
)
524 set_memory_packet_size (args
, &memory_write_packet_config
);
528 show_memory_write_packet_size (char *args
, int from_tty
)
530 show_memory_packet_size (&memory_write_packet_config
);
534 get_memory_write_packet_size (void)
536 return get_memory_packet_size (&memory_write_packet_config
);
539 static struct memory_packet_config memory_read_packet_config
=
541 "memory-read-packet-size",
545 set_memory_read_packet_size (char *args
, int from_tty
)
547 set_memory_packet_size (args
, &memory_read_packet_config
);
551 show_memory_read_packet_size (char *args
, int from_tty
)
553 show_memory_packet_size (&memory_read_packet_config
);
557 get_memory_read_packet_size (void)
559 struct remote_state
*rs
= get_remote_state ();
560 long size
= get_memory_packet_size (&memory_read_packet_config
);
561 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
562 extra buffer size argument before the memory read size can be
563 increased beyond (rs->remote_packet_size). */
564 if (size
> (rs
->remote_packet_size
))
565 size
= (rs
->remote_packet_size
);
570 /* Generic configuration support for packets the stub optionally
571 supports. Allows the user to specify the use of the packet as well
572 as allowing GDB to auto-detect support in the remote stub. */
576 PACKET_SUPPORT_UNKNOWN
= 0,
585 enum cmd_auto_boolean detect
;
586 enum packet_support support
;
589 /* Analyze a packet's return value and update the packet config
600 update_packet_config (struct packet_config
*config
)
602 switch (config
->detect
)
604 case CMD_AUTO_BOOLEAN_TRUE
:
605 config
->support
= PACKET_ENABLE
;
607 case CMD_AUTO_BOOLEAN_FALSE
:
608 config
->support
= PACKET_DISABLE
;
610 case CMD_AUTO_BOOLEAN_AUTO
:
611 config
->support
= PACKET_SUPPORT_UNKNOWN
;
617 show_packet_config_cmd (struct packet_config
*config
)
619 char *support
= "internal-error";
620 switch (config
->support
)
626 support
= "disabled";
628 case PACKET_SUPPORT_UNKNOWN
:
632 switch (config
->detect
)
634 case CMD_AUTO_BOOLEAN_AUTO
:
635 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
636 config
->name
, config
->title
, support
);
638 case CMD_AUTO_BOOLEAN_TRUE
:
639 case CMD_AUTO_BOOLEAN_FALSE
:
640 printf_filtered ("Support for remote protocol `%s' (%s) packet is currently %s.\n",
641 config
->name
, config
->title
, support
);
647 add_packet_config_cmd (struct packet_config
*config
,
650 void (*set_func
) (char *args
, int from_tty
,
651 struct cmd_list_element
*
653 void (*show_func
) (char *name
,
655 struct cmd_list_element
**set_remote_list
,
656 struct cmd_list_element
**show_remote_list
,
659 struct cmd_list_element
*set_cmd
;
660 struct cmd_list_element
*show_cmd
;
665 config
->title
= title
;
666 config
->detect
= CMD_AUTO_BOOLEAN_AUTO
;
667 config
->support
= PACKET_SUPPORT_UNKNOWN
;
668 xasprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
670 xasprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
672 /* set/show TITLE-packet {auto,on,off} */
673 xasprintf (&cmd_name
, "%s-packet", title
);
674 set_cmd
= add_set_auto_boolean_cmd (cmd_name
, class_obscure
,
675 &config
->detect
, set_doc
,
677 set_cmd
->function
.sfunc
= set_func
;
678 show_cmd
= add_cmd (cmd_name
, class_obscure
, show_func
, show_doc
,
680 /* set/show remote NAME-packet {auto,on,off} -- legacy */
684 xasprintf (&legacy_name
, "%s-packet", name
);
685 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
687 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
692 static enum packet_result
693 packet_ok (const char *buf
, struct packet_config
*config
)
697 /* The stub recognized the packet request. Check that the
698 operation succeeded. */
699 switch (config
->support
)
701 case PACKET_SUPPORT_UNKNOWN
:
703 fprintf_unfiltered (gdb_stdlog
,
704 "Packet %s (%s) is supported\n",
705 config
->name
, config
->title
);
706 config
->support
= PACKET_ENABLE
;
709 internal_error (__FILE__
, __LINE__
,
710 "packet_ok: attempt to use a disabled packet");
715 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
716 /* "OK" - definitly OK. */
719 && isxdigit (buf
[1]) && isxdigit (buf
[2])
721 /* "Enn" - definitly an error. */
723 /* The packet may or may not be OK. Just assume it is */
728 /* The stub does not support the packet. */
729 switch (config
->support
)
732 if (config
->detect
== CMD_AUTO_BOOLEAN_AUTO
)
733 /* If the stub previously indicated that the packet was
734 supported then there is a protocol error.. */
735 error ("Protocol error: %s (%s) conflicting enabled responses.",
736 config
->name
, config
->title
);
738 /* The user set it wrong. */
739 error ("Enabled packet %s (%s) not recognized by stub",
740 config
->name
, config
->title
);
742 case PACKET_SUPPORT_UNKNOWN
:
744 fprintf_unfiltered (gdb_stdlog
,
745 "Packet %s (%s) is NOT supported\n",
746 config
->name
, config
->title
);
747 config
->support
= PACKET_DISABLE
;
752 return PACKET_UNKNOWN
;
756 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
757 static struct packet_config remote_protocol_qSymbol
;
760 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
761 struct cmd_list_element
*c
)
763 update_packet_config (&remote_protocol_qSymbol
);
767 show_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
)
769 show_packet_config_cmd (&remote_protocol_qSymbol
);
772 /* Should we try the 'e' (step over range) request? */
773 static struct packet_config remote_protocol_e
;
776 set_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
777 struct cmd_list_element
*c
)
779 update_packet_config (&remote_protocol_e
);
783 show_remote_protocol_e_packet_cmd (char *args
, int from_tty
)
785 show_packet_config_cmd (&remote_protocol_e
);
789 /* Should we try the 'E' (step over range / w signal #) request? */
790 static struct packet_config remote_protocol_E
;
793 set_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
794 struct cmd_list_element
*c
)
796 update_packet_config (&remote_protocol_E
);
800 show_remote_protocol_E_packet_cmd (char *args
, int from_tty
)
802 show_packet_config_cmd (&remote_protocol_E
);
806 /* Should we try the 'P' (set register) request? */
808 static struct packet_config remote_protocol_P
;
811 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
812 struct cmd_list_element
*c
)
814 update_packet_config (&remote_protocol_P
);
818 show_remote_protocol_P_packet_cmd (char *args
, int from_tty
)
820 show_packet_config_cmd (&remote_protocol_P
);
823 /* Should we try one of the 'Z' requests? */
827 Z_PACKET_SOFTWARE_BP
,
828 Z_PACKET_HARDWARE_BP
,
835 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
837 /* FIXME: Instead of having all these boiler plate functions, the
838 command callback should include a context argument. */
841 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
842 struct cmd_list_element
*c
)
844 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
848 show_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
)
850 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
854 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
855 struct cmd_list_element
*c
)
857 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
861 show_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
)
863 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
867 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
868 struct cmd_list_element
*c
)
870 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
874 show_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
)
876 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
880 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
881 struct cmd_list_element
*c
)
883 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
887 show_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
)
889 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
893 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
894 struct cmd_list_element
*c
)
896 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
900 show_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
)
902 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
905 /* For compatibility with older distributions. Provide a ``set remote
906 Z-packet ...'' command that updates all the Z packet types. */
908 static enum cmd_auto_boolean remote_Z_packet_detect
;
911 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
912 struct cmd_list_element
*c
)
915 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
917 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
918 update_packet_config (&remote_protocol_Z
[i
]);
923 show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
)
926 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
928 show_packet_config_cmd (&remote_protocol_Z
[i
]);
932 /* Should we try the 'X' (remote binary download) packet?
934 This variable (available to the user via "set remote X-packet")
935 dictates whether downloads are sent in binary (via the 'X' packet).
936 We assume that the stub can, and attempt to do it. This will be
937 cleared if the stub does not understand it. This switch is still
938 needed, though in cases when the packet is supported in the stub,
939 but the connection does not allow it (i.e., 7-bit serial connection
942 static struct packet_config remote_protocol_binary_download
;
944 /* Should we try the 'ThreadInfo' query packet?
946 This variable (NOT available to the user: auto-detect only!)
947 determines whether GDB will use the new, simpler "ThreadInfo"
948 query or the older, more complex syntax for thread queries.
949 This is an auto-detect variable (set to true at each connect,
950 and set to false when the target fails to recognize it). */
952 static int use_threadinfo_query
;
953 static int use_threadextra_query
;
956 set_remote_protocol_binary_download_cmd (char *args
,
958 struct cmd_list_element
*c
)
960 update_packet_config (&remote_protocol_binary_download
);
964 show_remote_protocol_binary_download_cmd (char *args
,
967 show_packet_config_cmd (&remote_protocol_binary_download
);
971 /* Tokens for use by the asynchronous signal handlers for SIGINT */
972 PTR sigint_remote_twice_token
;
973 PTR sigint_remote_token
;
975 /* These are pointers to hook functions that may be set in order to
976 modify resume/wait behavior for a particular architecture. */
978 void (*target_resume_hook
) (void);
979 void (*target_wait_loop_hook
) (void);
983 /* These are the threads which we last sent to the remote system.
984 -1 for all or -2 for not sent yet. */
985 static int general_thread
;
986 static int continue_thread
;
988 /* Call this function as a result of
989 1) A halt indication (T packet) containing a thread id
990 2) A direct query of currthread
991 3) Successful execution of set thread
995 record_currthread (int currthread
)
997 general_thread
= currthread
;
999 /* If this is a new thread, add it to GDB's thread list.
1000 If we leave it up to WFI to do this, bad things will happen. */
1001 if (!in_thread_list (pid_to_ptid (currthread
)))
1003 add_thread (pid_to_ptid (currthread
));
1005 ui_out_text (uiout
, "[New ");
1006 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
1007 ui_out_text (uiout
, "]\n");
1009 printf_filtered ("[New %s]\n",
1010 target_pid_to_str (pid_to_ptid (currthread
)));
1015 #define MAGIC_NULL_PID 42000
1018 set_thread (int th
, int gen
)
1020 struct remote_state
*rs
= get_remote_state ();
1021 char *buf
= alloca (rs
->remote_packet_size
);
1022 int state
= gen
? general_thread
: continue_thread
;
1028 buf
[1] = gen
? 'g' : 'c';
1029 if (th
== MAGIC_NULL_PID
)
1035 sprintf (&buf
[2], "-%x", -th
);
1037 sprintf (&buf
[2], "%x", th
);
1039 getpkt (buf
, (rs
->remote_packet_size
), 0);
1041 general_thread
= th
;
1043 continue_thread
= th
;
1046 /* Return nonzero if the thread TH is still alive on the remote system. */
1049 remote_thread_alive (ptid_t ptid
)
1051 int tid
= PIDGET (ptid
);
1055 sprintf (buf
, "T-%08x", -tid
);
1057 sprintf (buf
, "T%08x", tid
);
1059 getpkt (buf
, sizeof (buf
), 0);
1060 return (buf
[0] == 'O' && buf
[1] == 'K');
1063 /* About these extended threadlist and threadinfo packets. They are
1064 variable length packets but, the fields within them are often fixed
1065 length. They are redundent enough to send over UDP as is the
1066 remote protocol in general. There is a matching unit test module
1069 #define OPAQUETHREADBYTES 8
1071 /* a 64 bit opaque identifier */
1072 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1074 /* WARNING: This threadref data structure comes from the remote O.S., libstub
1075 protocol encoding, and remote.c. it is not particularly changable */
1077 /* Right now, the internal structure is int. We want it to be bigger.
1081 typedef int gdb_threadref
; /* internal GDB thread reference */
1083 /* gdb_ext_thread_info is an internal GDB data structure which is
1084 equivalint to the reply of the remote threadinfo packet */
1086 struct gdb_ext_thread_info
1088 threadref threadid
; /* External form of thread reference */
1089 int active
; /* Has state interesting to GDB? , regs, stack */
1090 char display
[256]; /* Brief state display, name, blocked/syspended */
1091 char shortname
[32]; /* To be used to name threads */
1092 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
1095 /* The volume of remote transfers can be limited by submitting
1096 a mask containing bits specifying the desired information.
1097 Use a union of these values as the 'selection' parameter to
1098 get_thread_info. FIXME: Make these TAG names more thread specific.
1101 #define TAG_THREADID 1
1102 #define TAG_EXISTS 2
1103 #define TAG_DISPLAY 4
1104 #define TAG_THREADNAME 8
1105 #define TAG_MOREDISPLAY 16
1107 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
1109 char *unpack_varlen_hex (char *buff
, int *result
);
1111 static char *unpack_nibble (char *buf
, int *val
);
1113 static char *pack_nibble (char *buf
, int nibble
);
1115 static char *pack_hex_byte (char *pkt
, int /*unsigned char */ byte
);
1117 static char *unpack_byte (char *buf
, int *value
);
1119 static char *pack_int (char *buf
, int value
);
1121 static char *unpack_int (char *buf
, int *value
);
1123 static char *unpack_string (char *src
, char *dest
, int length
);
1125 static char *pack_threadid (char *pkt
, threadref
* id
);
1127 static char *unpack_threadid (char *inbuf
, threadref
* id
);
1129 void int_to_threadref (threadref
* id
, int value
);
1131 static int threadref_to_int (threadref
* ref
);
1133 static void copy_threadref (threadref
* dest
, threadref
* src
);
1135 static int threadmatch (threadref
* dest
, threadref
* src
);
1137 static char *pack_threadinfo_request (char *pkt
, int mode
, threadref
* id
);
1139 static int remote_unpack_thread_info_response (char *pkt
,
1140 threadref
* expectedref
,
1141 struct gdb_ext_thread_info
1145 static int remote_get_threadinfo (threadref
* threadid
, int fieldset
, /*TAG mask */
1146 struct gdb_ext_thread_info
*info
);
1148 static int adapt_remote_get_threadinfo (gdb_threadref
* ref
,
1150 struct gdb_ext_thread_info
*info
);
1152 static char *pack_threadlist_request (char *pkt
, int startflag
,
1154 threadref
* nextthread
);
1156 static int parse_threadlist_response (char *pkt
,
1158 threadref
* original_echo
,
1159 threadref
* resultlist
, int *doneflag
);
1161 static int remote_get_threadlist (int startflag
,
1162 threadref
* nextthread
,
1165 int *result_count
, threadref
* threadlist
);
1167 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
1169 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1170 void *context
, int looplimit
);
1172 static int remote_newthread_step (threadref
* ref
, void *context
);
1174 /* encode 64 bits in 16 chars of hex */
1176 static const char hexchars
[] = "0123456789abcdef";
1179 ishex (int ch
, int *val
)
1181 if ((ch
>= 'a') && (ch
<= 'f'))
1183 *val
= ch
- 'a' + 10;
1186 if ((ch
>= 'A') && (ch
<= 'F'))
1188 *val
= ch
- 'A' + 10;
1191 if ((ch
>= '0') && (ch
<= '9'))
1202 if (ch
>= 'a' && ch
<= 'f')
1203 return ch
- 'a' + 10;
1204 if (ch
>= '0' && ch
<= '9')
1206 if (ch
>= 'A' && ch
<= 'F')
1207 return ch
- 'A' + 10;
1212 stub_unpack_int (char *buff
, int fieldlength
)
1219 nibble
= stubhex (*buff
++);
1223 retval
= retval
<< 4;
1229 unpack_varlen_hex (char *buff
, /* packet to parse */
1235 while (ishex (*buff
, &nibble
))
1238 retval
= retval
<< 4;
1239 retval
|= nibble
& 0x0f;
1246 unpack_nibble (char *buf
, int *val
)
1248 ishex (*buf
++, val
);
1253 pack_nibble (char *buf
, int nibble
)
1255 *buf
++ = hexchars
[(nibble
& 0x0f)];
1260 pack_hex_byte (char *pkt
, int byte
)
1262 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1263 *pkt
++ = hexchars
[(byte
& 0xf)];
1268 unpack_byte (char *buf
, int *value
)
1270 *value
= stub_unpack_int (buf
, 2);
1275 pack_int (char *buf
, int value
)
1277 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1278 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1279 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1280 buf
= pack_hex_byte (buf
, (value
& 0xff));
1285 unpack_int (char *buf
, int *value
)
1287 *value
= stub_unpack_int (buf
, 8);
1291 #if 0 /* currently unused, uncomment when needed */
1292 static char *pack_string (char *pkt
, char *string
);
1295 pack_string (char *pkt
, char *string
)
1300 len
= strlen (string
);
1302 len
= 200; /* Bigger than most GDB packets, junk??? */
1303 pkt
= pack_hex_byte (pkt
, len
);
1307 if ((ch
== '\0') || (ch
== '#'))
1308 ch
= '*'; /* Protect encapsulation */
1313 #endif /* 0 (unused) */
1316 unpack_string (char *src
, char *dest
, int length
)
1325 pack_threadid (char *pkt
, threadref
*id
)
1328 unsigned char *altid
;
1330 altid
= (unsigned char *) id
;
1331 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1333 pkt
= pack_hex_byte (pkt
, *altid
++);
1339 unpack_threadid (char *inbuf
, threadref
*id
)
1342 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1345 altref
= (char *) id
;
1347 while (inbuf
< limit
)
1349 x
= stubhex (*inbuf
++);
1350 y
= stubhex (*inbuf
++);
1351 *altref
++ = (x
<< 4) | y
;
1356 /* Externally, threadrefs are 64 bits but internally, they are still
1357 ints. This is due to a mismatch of specifications. We would like
1358 to use 64bit thread references internally. This is an adapter
1362 int_to_threadref (threadref
*id
, int value
)
1364 unsigned char *scan
;
1366 scan
= (unsigned char *) id
;
1372 *scan
++ = (value
>> 24) & 0xff;
1373 *scan
++ = (value
>> 16) & 0xff;
1374 *scan
++ = (value
>> 8) & 0xff;
1375 *scan
++ = (value
& 0xff);
1379 threadref_to_int (threadref
*ref
)
1382 unsigned char *scan
;
1384 scan
= (char *) ref
;
1388 value
= (value
<< 8) | ((*scan
++) & 0xff);
1393 copy_threadref (threadref
*dest
, threadref
*src
)
1396 unsigned char *csrc
, *cdest
;
1398 csrc
= (unsigned char *) src
;
1399 cdest
= (unsigned char *) dest
;
1406 threadmatch (threadref
*dest
, threadref
*src
)
1408 /* things are broken right now, so just assume we got a match */
1410 unsigned char *srcp
, *destp
;
1412 srcp
= (char *) src
;
1413 destp
= (char *) dest
;
1417 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1424 threadid:1, # always request threadid
1431 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1434 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1436 *pkt
++ = 'q'; /* Info Query */
1437 *pkt
++ = 'P'; /* process or thread info */
1438 pkt
= pack_int (pkt
, mode
); /* mode */
1439 pkt
= pack_threadid (pkt
, id
); /* threadid */
1440 *pkt
= '\0'; /* terminate */
1444 /* These values tag the fields in a thread info response packet */
1445 /* Tagging the fields allows us to request specific fields and to
1446 add more fields as time goes by */
1448 #define TAG_THREADID 1 /* Echo the thread identifier */
1449 #define TAG_EXISTS 2 /* Is this process defined enough to
1450 fetch registers and its stack */
1451 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1452 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1453 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1457 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1458 struct gdb_ext_thread_info
*info
)
1460 struct remote_state
*rs
= get_remote_state ();
1464 char *limit
= pkt
+ (rs
->remote_packet_size
); /* plausable parsing limit */
1467 /* info->threadid = 0; FIXME: implement zero_threadref */
1469 info
->display
[0] = '\0';
1470 info
->shortname
[0] = '\0';
1471 info
->more_display
[0] = '\0';
1473 /* Assume the characters indicating the packet type have been stripped */
1474 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1475 pkt
= unpack_threadid (pkt
, &ref
);
1478 warning ("Incomplete response to threadinfo request\n");
1479 if (!threadmatch (&ref
, expectedref
))
1480 { /* This is an answer to a different request */
1481 warning ("ERROR RMT Thread info mismatch\n");
1484 copy_threadref (&info
->threadid
, &ref
);
1486 /* Loop on tagged fields , try to bail if somthing goes wrong */
1488 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1490 pkt
= unpack_int (pkt
, &tag
); /* tag */
1491 pkt
= unpack_byte (pkt
, &length
); /* length */
1492 if (!(tag
& mask
)) /* tags out of synch with mask */
1494 warning ("ERROR RMT: threadinfo tag mismatch\n");
1498 if (tag
== TAG_THREADID
)
1502 warning ("ERROR RMT: length of threadid is not 16\n");
1506 pkt
= unpack_threadid (pkt
, &ref
);
1507 mask
= mask
& ~TAG_THREADID
;
1510 if (tag
== TAG_EXISTS
)
1512 info
->active
= stub_unpack_int (pkt
, length
);
1514 mask
= mask
& ~(TAG_EXISTS
);
1517 warning ("ERROR RMT: 'exists' length too long\n");
1523 if (tag
== TAG_THREADNAME
)
1525 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1526 mask
= mask
& ~TAG_THREADNAME
;
1529 if (tag
== TAG_DISPLAY
)
1531 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1532 mask
= mask
& ~TAG_DISPLAY
;
1535 if (tag
== TAG_MOREDISPLAY
)
1537 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1538 mask
= mask
& ~TAG_MOREDISPLAY
;
1541 warning ("ERROR RMT: unknown thread info tag\n");
1542 break; /* Not a tag we know about */
1548 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1549 struct gdb_ext_thread_info
*info
)
1551 struct remote_state
*rs
= get_remote_state ();
1553 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1555 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1556 putpkt (threadinfo_pkt
);
1557 getpkt (threadinfo_pkt
, (rs
->remote_packet_size
), 0);
1558 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1563 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1564 representation of a threadid. */
1567 adapt_remote_get_threadinfo (gdb_threadref
*ref
, int selection
,
1568 struct gdb_ext_thread_info
*info
)
1572 int_to_threadref (&lclref
, *ref
);
1573 return remote_get_threadinfo (&lclref
, selection
, info
);
1576 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1579 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1580 threadref
*nextthread
)
1582 *pkt
++ = 'q'; /* info query packet */
1583 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1584 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1585 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1586 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1591 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1594 parse_threadlist_response (char *pkt
, int result_limit
,
1595 threadref
*original_echo
, threadref
*resultlist
,
1598 struct remote_state
*rs
= get_remote_state ();
1600 int count
, resultcount
, done
;
1603 /* Assume the 'q' and 'M chars have been stripped. */
1604 limit
= pkt
+ ((rs
->remote_packet_size
) - BUF_THREAD_ID_SIZE
); /* done parse past here */
1605 pkt
= unpack_byte (pkt
, &count
); /* count field */
1606 pkt
= unpack_nibble (pkt
, &done
);
1607 /* The first threadid is the argument threadid. */
1608 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1609 while ((count
-- > 0) && (pkt
< limit
))
1611 pkt
= unpack_threadid (pkt
, resultlist
++);
1612 if (resultcount
++ >= result_limit
)
1621 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1622 int *done
, int *result_count
, threadref
*threadlist
)
1624 struct remote_state
*rs
= get_remote_state ();
1625 static threadref echo_nextthread
;
1626 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1627 char *t_response
= alloca (rs
->remote_packet_size
);
1630 /* Trancate result limit to be smaller than the packet size */
1631 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= (rs
->remote_packet_size
))
1632 result_limit
= ((rs
->remote_packet_size
) / BUF_THREAD_ID_SIZE
) - 2;
1634 pack_threadlist_request (threadlist_packet
,
1635 startflag
, result_limit
, nextthread
);
1636 putpkt (threadlist_packet
);
1637 getpkt (t_response
, (rs
->remote_packet_size
), 0);
1640 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1643 if (!threadmatch (&echo_nextthread
, nextthread
))
1645 /* FIXME: This is a good reason to drop the packet */
1646 /* Possably, there is a duplicate response */
1648 retransmit immediatly - race conditions
1649 retransmit after timeout - yes
1651 wait for packet, then exit
1653 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1654 return 0; /* I choose simply exiting */
1656 if (*result_count
<= 0)
1660 warning ("RMT ERROR : failed to get remote thread list\n");
1663 return result
; /* break; */
1665 if (*result_count
> result_limit
)
1668 warning ("RMT ERROR: threadlist response longer than requested\n");
1674 /* This is the interface between remote and threads, remotes upper interface */
1676 /* remote_find_new_threads retrieves the thread list and for each
1677 thread in the list, looks up the thread in GDB's internal list,
1678 ading the thread if it does not already exist. This involves
1679 getting partial thread lists from the remote target so, polling the
1680 quit_flag is required. */
1683 /* About this many threadisds fit in a packet. */
1685 #define MAXTHREADLISTRESULTS 32
1688 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1691 int done
, i
, result_count
;
1695 static threadref nextthread
;
1696 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1701 if (loopcount
++ > looplimit
)
1704 warning ("Remote fetch threadlist -infinite loop-\n");
1707 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1708 &done
, &result_count
, resultthreadlist
))
1713 /* clear for later iterations */
1715 /* Setup to resume next batch of thread references, set nextthread. */
1716 if (result_count
>= 1)
1717 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1719 while (result_count
--)
1720 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1727 remote_newthread_step (threadref
*ref
, void *context
)
1731 ptid
= pid_to_ptid (threadref_to_int (ref
));
1733 if (!in_thread_list (ptid
))
1735 return 1; /* continue iterator */
1738 #define CRAZY_MAX_THREADS 1000
1741 remote_current_thread (ptid_t oldpid
)
1743 struct remote_state
*rs
= get_remote_state ();
1744 char *buf
= alloca (rs
->remote_packet_size
);
1747 getpkt (buf
, (rs
->remote_packet_size
), 0);
1748 if (buf
[0] == 'Q' && buf
[1] == 'C')
1749 return pid_to_ptid (strtol (&buf
[2], NULL
, 16));
1754 /* Find new threads for info threads command.
1755 * Original version, using John Metzler's thread protocol.
1759 remote_find_new_threads (void)
1761 remote_threadlist_iterator (remote_newthread_step
, 0,
1763 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1764 inferior_ptid
= remote_current_thread (inferior_ptid
);
1768 * Find all threads for info threads command.
1769 * Uses new thread protocol contributed by Cisco.
1770 * Falls back and attempts to use the older method (above)
1771 * if the target doesn't respond to the new method.
1775 remote_threads_info (void)
1777 struct remote_state
*rs
= get_remote_state ();
1778 char *buf
= alloca (rs
->remote_packet_size
);
1782 if (remote_desc
== 0) /* paranoia */
1783 error ("Command can only be used when connected to the remote target.");
1785 if (use_threadinfo_query
)
1787 putpkt ("qfThreadInfo");
1789 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1790 if (bufp
[0] != '\0') /* q packet recognized */
1792 while (*bufp
++ == 'm') /* reply contains one or more TID */
1796 tid
= strtol (bufp
, &bufp
, 16);
1797 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1798 add_thread (pid_to_ptid (tid
));
1800 while (*bufp
++ == ','); /* comma-separated list */
1801 putpkt ("qsThreadInfo");
1803 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1809 /* Else fall back to old method based on jmetzler protocol. */
1810 use_threadinfo_query
= 0;
1811 remote_find_new_threads ();
1816 * Collect a descriptive string about the given thread.
1817 * The target may say anything it wants to about the thread
1818 * (typically info about its blocked / runnable state, name, etc.).
1819 * This string will appear in the info threads display.
1821 * Optional: targets are not required to implement this function.
1825 remote_threads_extra_info (struct thread_info
*tp
)
1827 struct remote_state
*rs
= get_remote_state ();
1831 struct gdb_ext_thread_info threadinfo
;
1832 static char display_buf
[100]; /* arbitrary... */
1833 char *bufp
= alloca (rs
->remote_packet_size
);
1834 int n
= 0; /* position in display_buf */
1836 if (remote_desc
== 0) /* paranoia */
1837 internal_error (__FILE__
, __LINE__
,
1838 "remote_threads_extra_info");
1840 if (use_threadextra_query
)
1842 sprintf (bufp
, "qThreadExtraInfo,%x", PIDGET (tp
->ptid
));
1844 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1847 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1848 result
= hex2bin (bufp
, display_buf
, n
);
1849 display_buf
[result
] = '\0';
1854 /* If the above query fails, fall back to the old method. */
1855 use_threadextra_query
= 0;
1856 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1857 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1858 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1859 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1860 if (threadinfo
.active
)
1862 if (*threadinfo
.shortname
)
1863 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1864 if (*threadinfo
.display
)
1865 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1866 if (*threadinfo
.more_display
)
1867 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1868 threadinfo
.more_display
);
1872 /* for purely cosmetic reasons, clear up trailing commas */
1873 if (',' == display_buf
[n
-1])
1874 display_buf
[n
-1] = ' ';
1883 /* Restart the remote side; this is an extended protocol operation. */
1886 extended_remote_restart (void)
1888 struct remote_state
*rs
= get_remote_state ();
1889 char *buf
= alloca (rs
->remote_packet_size
);
1891 /* Send the restart command; for reasons I don't understand the
1892 remote side really expects a number after the "R". */
1894 sprintf (&buf
[1], "%x", 0);
1897 /* Now query for status so this looks just like we restarted
1898 gdbserver from scratch. */
1900 getpkt (buf
, (rs
->remote_packet_size
), 0);
1903 /* Clean up connection to a remote debugger. */
1907 remote_close (int quitting
)
1910 serial_close (remote_desc
);
1914 /* Query the remote side for the text, data and bss offsets. */
1919 struct remote_state
*rs
= get_remote_state ();
1920 char *buf
= alloca (rs
->remote_packet_size
);
1923 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1924 struct section_offsets
*offs
;
1926 putpkt ("qOffsets");
1928 getpkt (buf
, (rs
->remote_packet_size
), 0);
1930 if (buf
[0] == '\000')
1931 return; /* Return silently. Stub doesn't support
1935 warning ("Remote failure reply: %s", buf
);
1939 /* Pick up each field in turn. This used to be done with scanf, but
1940 scanf will make trouble if CORE_ADDR size doesn't match
1941 conversion directives correctly. The following code will work
1942 with any size of CORE_ADDR. */
1943 text_addr
= data_addr
= bss_addr
= 0;
1947 if (strncmp (ptr
, "Text=", 5) == 0)
1950 /* Don't use strtol, could lose on big values. */
1951 while (*ptr
&& *ptr
!= ';')
1952 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1957 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1960 while (*ptr
&& *ptr
!= ';')
1961 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1966 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1969 while (*ptr
&& *ptr
!= ';')
1970 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1976 error ("Malformed response to offset query, %s", buf
);
1978 if (symfile_objfile
== NULL
)
1981 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1982 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1984 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
1986 /* This is a temporary kludge to force data and bss to use the same offsets
1987 because that's what nlmconv does now. The real solution requires changes
1988 to the stub and remote.c that I don't have time to do right now. */
1990 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
1991 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
1993 objfile_relocate (symfile_objfile
, offs
);
1997 * Cisco version of section offsets:
1999 * Instead of having GDB query the target for the section offsets,
2000 * Cisco lets the target volunteer the information! It's also in
2001 * a different format, so here are the functions that will decode
2002 * a section offset packet from a Cisco target.
2006 * Function: remote_cisco_section_offsets
2008 * Returns: zero for success, non-zero for failure
2012 remote_cisco_section_offsets (bfd_vma text_addr
,
2015 bfd_signed_vma
*text_offs
,
2016 bfd_signed_vma
*data_offs
,
2017 bfd_signed_vma
*bss_offs
)
2019 bfd_vma text_base
, data_base
, bss_base
;
2020 struct minimal_symbol
*start
;
2025 if (symfile_objfile
== NULL
)
2026 return -1; /* no can do nothin' */
2028 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
2030 return -1; /* Can't find "_start" symbol */
2032 data_base
= bss_base
= 0;
2033 text_base
= SYMBOL_VALUE_ADDRESS (start
);
2035 abfd
= symfile_objfile
->obfd
;
2036 for (sect
= abfd
->sections
;
2040 const char *p
= bfd_get_section_name (abfd
, sect
);
2042 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
2043 if (data_base
== 0 ||
2044 data_base
> bfd_get_section_vma (abfd
, sect
))
2045 data_base
= bfd_get_section_vma (abfd
, sect
);
2046 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
2047 if (bss_base
== 0 ||
2048 bss_base
> bfd_get_section_vma (abfd
, sect
))
2049 bss_base
= bfd_get_section_vma (abfd
, sect
);
2051 *text_offs
= text_addr
- text_base
;
2052 *data_offs
= data_addr
- data_base
;
2053 *bss_offs
= bss_addr
- bss_base
;
2058 sprintf (tmp
, "VMA: text = 0x");
2059 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
2060 sprintf (tmp
+ strlen (tmp
), " data = 0x");
2061 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
2062 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
2063 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
2064 fprintf_filtered (gdb_stdlog
, tmp
);
2065 fprintf_filtered (gdb_stdlog
,
2066 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
2067 paddr_nz (*text_offs
),
2068 paddr_nz (*data_offs
),
2069 paddr_nz (*bss_offs
));
2076 * Function: remote_cisco_objfile_relocate
2078 * Relocate the symbol file for a remote target.
2082 remote_cisco_objfile_relocate (bfd_signed_vma text_off
, bfd_signed_vma data_off
,
2083 bfd_signed_vma bss_off
)
2085 struct section_offsets
*offs
;
2087 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2089 /* FIXME: This code assumes gdb-stabs.h is being used; it's
2090 broken for xcoff, dwarf, sdb-coff, etc. But there is no
2091 simple canonical representation for this stuff. */
2093 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
2094 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
2096 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_off
;
2097 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_off
;
2098 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = bss_off
;
2100 /* First call the standard objfile_relocate. */
2101 objfile_relocate (symfile_objfile
, offs
);
2103 /* Now we need to fix up the section entries already attached to
2104 the exec target. These entries will control memory transfers
2105 from the exec file. */
2107 exec_set_section_offsets (text_off
, data_off
, bss_off
);
2111 /* Stub for catch_errors. */
2114 remote_start_remote_dummy (void *dummy
)
2116 start_remote (); /* Initialize gdb process mechanisms */
2121 remote_start_remote (PTR dummy
)
2123 immediate_quit
++; /* Allow user to interrupt it */
2125 /* Ack any packet which the remote side has already sent. */
2126 serial_write (remote_desc
, "+", 1);
2128 /* Let the stub know that we want it to return the thread. */
2131 inferior_ptid
= remote_current_thread (inferior_ptid
);
2133 get_offsets (); /* Get text, data & bss offsets */
2135 putpkt ("?"); /* initiate a query from remote machine */
2138 return remote_start_remote_dummy (dummy
);
2141 /* Open a connection to a remote debugger.
2142 NAME is the filename used for communication. */
2145 remote_open (char *name
, int from_tty
)
2147 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
2150 /* Just like remote_open, but with asynchronous support. */
2152 remote_async_open (char *name
, int from_tty
)
2154 remote_async_open_1 (name
, from_tty
, &remote_async_ops
, 0);
2157 /* Open a connection to a remote debugger using the extended
2158 remote gdb protocol. NAME is the filename used for communication. */
2161 extended_remote_open (char *name
, int from_tty
)
2163 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */ );
2166 /* Just like extended_remote_open, but with asynchronous support. */
2168 extended_remote_async_open (char *name
, int from_tty
)
2170 remote_async_open_1 (name
, from_tty
, &extended_async_remote_ops
, 1 /*extended_p */ );
2173 /* Generic code for opening a connection to a remote target. */
2176 init_all_packet_configs (void)
2179 update_packet_config (&remote_protocol_e
);
2180 update_packet_config (&remote_protocol_E
);
2181 update_packet_config (&remote_protocol_P
);
2182 update_packet_config (&remote_protocol_qSymbol
);
2183 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2184 update_packet_config (&remote_protocol_Z
[i
]);
2185 /* Force remote_write_bytes to check whether target supports binary
2187 update_packet_config (&remote_protocol_binary_download
);
2190 /* Symbol look-up. */
2193 remote_check_symbols (struct objfile
*objfile
)
2195 struct remote_state
*rs
= get_remote_state ();
2196 char *msg
, *reply
, *tmp
;
2197 struct minimal_symbol
*sym
;
2200 if (remote_protocol_qSymbol
.support
== PACKET_DISABLE
)
2203 msg
= alloca (rs
->remote_packet_size
);
2204 reply
= alloca (rs
->remote_packet_size
);
2206 /* Invite target to request symbol lookups. */
2208 putpkt ("qSymbol::");
2209 getpkt (reply
, (rs
->remote_packet_size
), 0);
2210 packet_ok (reply
, &remote_protocol_qSymbol
);
2212 while (strncmp (reply
, "qSymbol:", 8) == 0)
2215 end
= hex2bin (tmp
, msg
, strlen (tmp
) / 2);
2217 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2219 sprintf (msg
, "qSymbol::%s", &reply
[8]);
2221 sprintf (msg
, "qSymbol:%s:%s",
2222 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2225 getpkt (reply
, (rs
->remote_packet_size
), 0);
2230 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2233 struct remote_state
*rs
= get_remote_state ();
2235 error ("To open a remote debug connection, you need to specify what\n"
2236 "serial device is attached to the remote system\n"
2237 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2239 /* See FIXME above */
2240 wait_forever_enabled_p
= 1;
2242 target_preopen (from_tty
);
2244 unpush_target (target
);
2246 remote_desc
= serial_open (name
);
2248 perror_with_name (name
);
2250 if (baud_rate
!= -1)
2252 if (serial_setbaudrate (remote_desc
, baud_rate
))
2254 serial_close (remote_desc
);
2255 perror_with_name (name
);
2259 serial_raw (remote_desc
);
2261 /* If there is something sitting in the buffer we might take it as a
2262 response to a command, which would be bad. */
2263 serial_flush_input (remote_desc
);
2267 puts_filtered ("Remote debugging using ");
2268 puts_filtered (name
);
2269 puts_filtered ("\n");
2271 push_target (target
); /* Switch to using remote target now */
2273 init_all_packet_configs ();
2275 general_thread
= -2;
2276 continue_thread
= -2;
2278 /* Probe for ability to use "ThreadInfo" query, as required. */
2279 use_threadinfo_query
= 1;
2280 use_threadextra_query
= 1;
2282 /* Without this, some commands which require an active target (such
2283 as kill) won't work. This variable serves (at least) double duty
2284 as both the pid of the target process (if it has such), and as a
2285 flag indicating that a target is active. These functions should
2286 be split out into seperate variables, especially since GDB will
2287 someday have a notion of debugging several processes. */
2289 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2290 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2291 /* First delete any symbols previously loaded from shared libraries. */
2292 no_shared_libraries (NULL
, 0);
2295 /* Start the remote connection; if error (0), discard this target.
2296 In particular, if the user quits, be sure to discard it
2297 (we'd be in an inconsistent state otherwise). */
2298 if (!catch_errors (remote_start_remote
, NULL
,
2299 "Couldn't establish connection to remote target\n",
2308 /* Tell the remote that we are using the extended protocol. */
2309 char *buf
= alloca (rs
->remote_packet_size
);
2311 getpkt (buf
, (rs
->remote_packet_size
), 0);
2313 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2314 /* FIXME: need a master target_open vector from which all
2315 remote_opens can be called, so that stuff like this can
2316 go there. Failing that, the following code must be copied
2317 to the open function for any remote target that wants to
2318 support svr4 shared libraries. */
2320 /* Set up to detect and load shared libraries. */
2321 if (exec_bfd
) /* No use without an exec file. */
2323 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2324 remote_check_symbols (symfile_objfile
);
2329 /* Just like remote_open but with asynchronous support. */
2331 remote_async_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2334 struct remote_state
*rs
= get_remote_state ();
2336 error ("To open a remote debug connection, you need to specify what\n"
2337 "serial device is attached to the remote system\n"
2338 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2340 target_preopen (from_tty
);
2342 unpush_target (target
);
2344 remote_desc
= serial_open (name
);
2346 perror_with_name (name
);
2348 if (baud_rate
!= -1)
2350 if (serial_setbaudrate (remote_desc
, baud_rate
))
2352 serial_close (remote_desc
);
2353 perror_with_name (name
);
2357 serial_raw (remote_desc
);
2359 /* If there is something sitting in the buffer we might take it as a
2360 response to a command, which would be bad. */
2361 serial_flush_input (remote_desc
);
2365 puts_filtered ("Remote debugging using ");
2366 puts_filtered (name
);
2367 puts_filtered ("\n");
2370 push_target (target
); /* Switch to using remote target now */
2372 init_all_packet_configs ();
2374 general_thread
= -2;
2375 continue_thread
= -2;
2377 /* Probe for ability to use "ThreadInfo" query, as required. */
2378 use_threadinfo_query
= 1;
2379 use_threadextra_query
= 1;
2381 /* Without this, some commands which require an active target (such
2382 as kill) won't work. This variable serves (at least) double duty
2383 as both the pid of the target process (if it has such), and as a
2384 flag indicating that a target is active. These functions should
2385 be split out into seperate variables, especially since GDB will
2386 someday have a notion of debugging several processes. */
2387 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2389 /* With this target we start out by owning the terminal. */
2390 remote_async_terminal_ours_p
= 1;
2392 /* FIXME: cagney/1999-09-23: During the initial connection it is
2393 assumed that the target is already ready and able to respond to
2394 requests. Unfortunately remote_start_remote() eventually calls
2395 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2396 around this. Eventually a mechanism that allows
2397 wait_for_inferior() to expect/get timeouts will be
2399 wait_forever_enabled_p
= 0;
2401 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2402 /* First delete any symbols previously loaded from shared libraries. */
2403 no_shared_libraries (NULL
, 0);
2406 /* Start the remote connection; if error (0), discard this target.
2407 In particular, if the user quits, be sure to discard it
2408 (we'd be in an inconsistent state otherwise). */
2409 if (!catch_errors (remote_start_remote
, NULL
,
2410 "Couldn't establish connection to remote target\n",
2414 wait_forever_enabled_p
= 1;
2418 wait_forever_enabled_p
= 1;
2422 /* Tell the remote that we are using the extended protocol. */
2423 char *buf
= alloca (rs
->remote_packet_size
);
2425 getpkt (buf
, (rs
->remote_packet_size
), 0);
2427 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2428 /* FIXME: need a master target_open vector from which all
2429 remote_opens can be called, so that stuff like this can
2430 go there. Failing that, the following code must be copied
2431 to the open function for any remote target that wants to
2432 support svr4 shared libraries. */
2434 /* Set up to detect and load shared libraries. */
2435 if (exec_bfd
) /* No use without an exec file. */
2437 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2438 remote_check_symbols (symfile_objfile
);
2443 /* This takes a program previously attached to and detaches it. After
2444 this is done, GDB can be used to debug some other program. We
2445 better not have left any breakpoints in the target program or it'll
2446 die when it hits one. */
2449 remote_detach (char *args
, int from_tty
)
2451 struct remote_state
*rs
= get_remote_state ();
2452 char *buf
= alloca (rs
->remote_packet_size
);
2455 error ("Argument given to \"detach\" when remotely debugging.");
2457 /* Tell the remote target to detach. */
2459 remote_send (buf
, (rs
->remote_packet_size
));
2461 target_mourn_inferior ();
2463 puts_filtered ("Ending remote debugging.\n");
2467 /* Same as remote_detach, but with async support. */
2469 remote_async_detach (char *args
, int from_tty
)
2471 struct remote_state
*rs
= get_remote_state ();
2472 char *buf
= alloca (rs
->remote_packet_size
);
2475 error ("Argument given to \"detach\" when remotely debugging.");
2477 /* Tell the remote target to detach. */
2479 remote_send (buf
, (rs
->remote_packet_size
));
2481 /* Unregister the file descriptor from the event loop. */
2482 if (target_is_async_p ())
2483 serial_async (remote_desc
, NULL
, 0);
2485 target_mourn_inferior ();
2487 puts_filtered ("Ending remote debugging.\n");
2490 /* Convert hex digit A to a number. */
2495 if (a
>= '0' && a
<= '9')
2497 else if (a
>= 'a' && a
<= 'f')
2498 return a
- 'a' + 10;
2499 else if (a
>= 'A' && a
<= 'F')
2500 return a
- 'A' + 10;
2502 error ("Reply contains invalid hex digit %d", a
);
2506 hex2bin (const char *hex
, char *bin
, int count
)
2510 for (i
= 0; i
< count
; i
++)
2512 if (hex
[0] == 0 || hex
[1] == 0)
2514 /* Hex string is short, or of uneven length.
2515 Return the count that has been converted so far. */
2518 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2524 /* Convert number NIB to a hex digit. */
2532 return 'a' + nib
- 10;
2536 bin2hex (const char *bin
, char *hex
, int count
)
2539 /* May use a length, or a nul-terminated string as input. */
2541 count
= strlen (bin
);
2543 for (i
= 0; i
< count
; i
++)
2545 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2546 *hex
++ = tohex (*bin
++ & 0xf);
2552 /* Tell the remote machine to resume. */
2554 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2556 static int last_sent_step
;
2559 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2561 struct remote_state
*rs
= get_remote_state ();
2562 char *buf
= alloca (rs
->remote_packet_size
);
2563 int pid
= PIDGET (ptid
);
2567 set_thread (0, 0); /* run any thread */
2569 set_thread (pid
, 0); /* run this thread */
2571 last_sent_signal
= siggnal
;
2572 last_sent_step
= step
;
2574 /* A hook for when we need to do something at the last moment before
2576 if (target_resume_hook
)
2577 (*target_resume_hook
) ();
2580 /* The s/S/c/C packets do not return status. So if the target does
2581 not support the S or C packets, the debug agent returns an empty
2582 string which is detected in remote_wait(). This protocol defect
2583 is fixed in the e/E packets. */
2585 if (step
&& step_range_end
)
2587 /* If the target does not support the 'E' packet, we try the 'S'
2588 packet. Ideally we would fall back to the 'e' packet if that
2589 too is not supported. But that would require another copy of
2590 the code to issue the 'e' packet (and fall back to 's' if not
2591 supported) in remote_wait(). */
2593 if (siggnal
!= TARGET_SIGNAL_0
)
2595 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2599 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2600 *p
++ = tohex (((int) siggnal
) & 0xf);
2602 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2604 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2608 getpkt (buf
, (rs
->remote_packet_size
), 0);
2610 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2616 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2620 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2622 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2626 getpkt (buf
, (rs
->remote_packet_size
), 0);
2628 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2634 if (siggnal
!= TARGET_SIGNAL_0
)
2636 buf
[0] = step
? 'S' : 'C';
2637 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2638 buf
[2] = tohex (((int) siggnal
) & 0xf);
2642 strcpy (buf
, step
? "s" : "c");
2647 /* Same as remote_resume, but with async support. */
2649 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2651 struct remote_state
*rs
= get_remote_state ();
2652 char *buf
= alloca (rs
->remote_packet_size
);
2653 int pid
= PIDGET (ptid
);
2657 set_thread (0, 0); /* run any thread */
2659 set_thread (pid
, 0); /* run this thread */
2661 last_sent_signal
= siggnal
;
2662 last_sent_step
= step
;
2664 /* A hook for when we need to do something at the last moment before
2666 if (target_resume_hook
)
2667 (*target_resume_hook
) ();
2669 /* The s/S/c/C packets do not return status. So if the target does
2670 not support the S or C packets, the debug agent returns an empty
2671 string which is detected in remote_wait(). This protocol defect
2672 is fixed in the e/E packets. */
2674 if (step
&& step_range_end
)
2676 /* If the target does not support the 'E' packet, we try the 'S'
2677 packet. Ideally we would fall back to the 'e' packet if that
2678 too is not supported. But that would require another copy of
2679 the code to issue the 'e' packet (and fall back to 's' if not
2680 supported) in remote_wait(). */
2682 if (siggnal
!= TARGET_SIGNAL_0
)
2684 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2688 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2689 *p
++ = tohex (((int) siggnal
) & 0xf);
2691 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2693 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2697 getpkt (buf
, (rs
->remote_packet_size
), 0);
2699 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2700 goto register_event_loop
;
2705 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2709 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2711 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2715 getpkt (buf
, (rs
->remote_packet_size
), 0);
2717 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2718 goto register_event_loop
;
2723 if (siggnal
!= TARGET_SIGNAL_0
)
2725 buf
[0] = step
? 'S' : 'C';
2726 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2727 buf
[2] = tohex ((int) siggnal
& 0xf);
2731 strcpy (buf
, step
? "s" : "c");
2735 register_event_loop
:
2736 /* We are about to start executing the inferior, let's register it
2737 with the event loop. NOTE: this is the one place where all the
2738 execution commands end up. We could alternatively do this in each
2739 of the execution commands in infcmd.c.*/
2740 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2741 into infcmd.c in order to allow inferior function calls to work
2742 NOT asynchronously. */
2743 if (event_loop_p
&& target_can_async_p ())
2744 target_async (inferior_event_handler
, 0);
2745 /* Tell the world that the target is now executing. */
2746 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2747 this? Instead, should the client of target just assume (for
2748 async targets) that the target is going to start executing? Is
2749 this information already found in the continuation block? */
2750 if (target_is_async_p ())
2751 target_executing
= 1;
2755 /* Set up the signal handler for SIGINT, while the target is
2756 executing, ovewriting the 'regular' SIGINT signal handler. */
2758 initialize_sigint_signal_handler (void)
2760 sigint_remote_token
=
2761 create_async_signal_handler (async_remote_interrupt
, NULL
);
2762 signal (SIGINT
, handle_remote_sigint
);
2765 /* Signal handler for SIGINT, while the target is executing. */
2767 handle_remote_sigint (int sig
)
2769 signal (sig
, handle_remote_sigint_twice
);
2770 sigint_remote_twice_token
=
2771 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2772 mark_async_signal_handler_wrapper (sigint_remote_token
);
2775 /* Signal handler for SIGINT, installed after SIGINT has already been
2776 sent once. It will take effect the second time that the user sends
2779 handle_remote_sigint_twice (int sig
)
2781 signal (sig
, handle_sigint
);
2782 sigint_remote_twice_token
=
2783 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2784 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2787 /* Perform the real interruption of the target execution, in response
2790 async_remote_interrupt (gdb_client_data arg
)
2793 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2798 /* Perform interrupt, if the first attempt did not succeed. Just give
2799 up on the target alltogether. */
2801 async_remote_interrupt_twice (gdb_client_data arg
)
2804 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2805 /* Do something only if the target was not killed by the previous
2807 if (target_executing
)
2810 signal (SIGINT
, handle_remote_sigint
);
2814 /* Reinstall the usual SIGINT handlers, after the target has
2817 cleanup_sigint_signal_handler (void *dummy
)
2819 signal (SIGINT
, handle_sigint
);
2820 if (sigint_remote_twice_token
)
2821 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2822 if (sigint_remote_token
)
2823 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2826 /* Send ^C to target to halt it. Target will respond, and send us a
2828 static void (*ofunc
) (int);
2830 /* The command line interface's stop routine. This function is installed
2831 as a signal handler for SIGINT. The first time a user requests a
2832 stop, we call remote_stop to send a break or ^C. If there is no
2833 response from the target (it didn't stop when the user requested it),
2834 we ask the user if he'd like to detach from the target. */
2836 remote_interrupt (int signo
)
2838 /* If this doesn't work, try more severe steps. */
2839 signal (signo
, remote_interrupt_twice
);
2842 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2847 /* The user typed ^C twice. */
2850 remote_interrupt_twice (int signo
)
2852 signal (signo
, ofunc
);
2854 signal (signo
, remote_interrupt
);
2857 /* This is the generic stop called via the target vector. When a target
2858 interrupt is requested, either by the command line or the GUI, we
2859 will eventually end up here. */
2863 /* Send a break or a ^C, depending on user preference. */
2865 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2868 serial_send_break (remote_desc
);
2870 serial_write (remote_desc
, "\003", 1);
2873 /* Ask the user what to do when an interrupt is received. */
2876 interrupt_query (void)
2878 target_terminal_ours ();
2880 if (query ("Interrupted while waiting for the program.\n\
2881 Give up (and stop debugging it)? "))
2883 target_mourn_inferior ();
2884 return_to_top_level (RETURN_QUIT
);
2887 target_terminal_inferior ();
2890 /* Enable/disable target terminal ownership. Most targets can use
2891 terminal groups to control terminal ownership. Remote targets are
2892 different in that explicit transfer of ownership to/from GDB/target
2896 remote_async_terminal_inferior (void)
2898 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2899 sync_execution here. This function should only be called when
2900 GDB is resuming the inferior in the forground. A background
2901 resume (``run&'') should leave GDB in control of the terminal and
2902 consequently should not call this code. */
2903 if (!sync_execution
)
2905 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2906 calls target_terminal_*() idenpotent. The event-loop GDB talking
2907 to an asynchronous target with a synchronous command calls this
2908 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2909 stops trying to transfer the terminal to the target when it
2910 shouldn't this guard can go away. */
2911 if (!remote_async_terminal_ours_p
)
2913 delete_file_handler (input_fd
);
2914 remote_async_terminal_ours_p
= 0;
2915 initialize_sigint_signal_handler ();
2916 /* NOTE: At this point we could also register our selves as the
2917 recipient of all input. Any characters typed could then be
2918 passed on down to the target. */
2922 remote_async_terminal_ours (void)
2924 /* See FIXME in remote_async_terminal_inferior. */
2925 if (!sync_execution
)
2927 /* See FIXME in remote_async_terminal_inferior. */
2928 if (remote_async_terminal_ours_p
)
2930 cleanup_sigint_signal_handler (NULL
);
2931 add_file_handler (input_fd
, stdin_event_handler
, 0);
2932 remote_async_terminal_ours_p
= 1;
2935 /* If nonzero, ignore the next kill. */
2940 remote_console_output (char *msg
)
2944 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2947 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2950 fputs_unfiltered (tb
, gdb_stdtarg
);
2952 gdb_flush (gdb_stdtarg
);
2955 /* Wait until the remote machine stops, then return,
2956 storing status in STATUS just as `wait' would.
2957 Returns "pid", which in the case of a multi-threaded
2958 remote OS, is the thread-id. */
2961 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2963 struct remote_state
*rs
= get_remote_state ();
2964 unsigned char *buf
= alloca (rs
->remote_packet_size
);
2965 int thread_num
= -1;
2967 status
->kind
= TARGET_WAITKIND_EXITED
;
2968 status
->value
.integer
= 0;
2974 ofunc
= signal (SIGINT
, remote_interrupt
);
2975 getpkt (buf
, (rs
->remote_packet_size
), 1);
2976 signal (SIGINT
, ofunc
);
2978 /* This is a hook for when we need to do something (perhaps the
2979 collection of trace data) every time the target stops. */
2980 if (target_wait_loop_hook
)
2981 (*target_wait_loop_hook
) ();
2985 case 'E': /* Error of some sort */
2986 warning ("Remote failure reply: %s", buf
);
2988 case 'T': /* Status with PC, SP, FP, ... */
2991 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
2993 /* Expedited reply, containing Signal, {regno, reg} repeat */
2994 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2996 n... = register number
2997 r... = register contents
2999 p
= &buf
[3]; /* after Txx */
3007 /* Read the ``P'' register number. */
3008 LONGEST pnum
= strtol ((const char *) p
, &p_temp
, 16);
3009 p1
= (unsigned char *) p_temp
;
3011 if (p1
== p
) /* No register number present here */
3013 p1
= (unsigned char *) strchr ((const char *) p
, ':');
3015 warning ("Malformed packet(a) (missing colon): %s\n\
3018 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
3020 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3021 record_currthread (thread_num
);
3022 p
= (unsigned char *) p_temp
;
3027 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3031 warning ("Malformed packet(b) (missing colon): %s\n\
3036 warning ("Remote sent bad register number %s: %s\n\
3038 phex_nz (pnum
, 0), p
, buf
);
3040 fieldsize
= hex2bin (p
, regs
, REGISTER_RAW_SIZE (reg
->regnum
));
3042 if (fieldsize
< REGISTER_RAW_SIZE (reg
->regnum
))
3043 warning ("Remote reply is too short: %s", buf
);
3044 supply_register (reg
->regnum
, regs
);
3049 warning ("Remote register badly formatted: %s", buf
);
3050 warning (" here: %s", p
);
3055 case 'S': /* Old style status, just signal only */
3056 status
->kind
= TARGET_WAITKIND_STOPPED
;
3057 status
->value
.sig
= (enum target_signal
)
3058 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3062 /* Export Cisco kernel mode as a convenience variable
3063 (so that it can be used in the GDB prompt if desired). */
3065 if (cisco_kernel_mode
== 1)
3066 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3067 value_from_string ("PDEBUG-"));
3068 cisco_kernel_mode
= 0;
3069 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3070 record_currthread (thread_num
);
3072 else if (buf
[3] == 'k')
3074 /* Export Cisco kernel mode as a convenience variable
3075 (so that it can be used in the GDB prompt if desired). */
3077 if (cisco_kernel_mode
== 1)
3078 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3079 value_from_string ("KDEBUG-"));
3080 cisco_kernel_mode
= 1;
3083 case 'N': /* Cisco special: status and offsets */
3085 bfd_vma text_addr
, data_addr
, bss_addr
;
3086 bfd_signed_vma text_off
, data_off
, bss_off
;
3089 status
->kind
= TARGET_WAITKIND_STOPPED
;
3090 status
->value
.sig
= (enum target_signal
)
3091 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3093 if (symfile_objfile
== NULL
)
3095 warning ("Relocation packet received with no symbol file. \
3100 /* Relocate object file. Buffer format is NAATT;DD;BB
3101 * where AA is the signal number, TT is the new text
3102 * address, DD * is the new data address, and BB is the
3103 * new bss address. */
3106 text_addr
= strtoul (p
, (char **) &p1
, 16);
3107 if (p1
== p
|| *p1
!= ';')
3108 warning ("Malformed relocation packet: Packet '%s'", buf
);
3110 data_addr
= strtoul (p
, (char **) &p1
, 16);
3111 if (p1
== p
|| *p1
!= ';')
3112 warning ("Malformed relocation packet: Packet '%s'", buf
);
3114 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3116 warning ("Malformed relocation packet: Packet '%s'", buf
);
3118 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3119 &text_off
, &data_off
, &bss_off
)
3121 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3122 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3126 case 'W': /* Target exited */
3128 /* The remote process exited. */
3129 status
->kind
= TARGET_WAITKIND_EXITED
;
3130 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3134 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3135 status
->value
.sig
= (enum target_signal
)
3136 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3140 case 'O': /* Console output */
3141 remote_console_output (buf
+ 1);
3144 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3146 /* Zero length reply means that we tried 'S' or 'C' and
3147 the remote system doesn't support it. */
3148 target_terminal_ours_for_output ();
3150 ("Can't send signals to this remote system. %s not sent.\n",
3151 target_signal_to_name (last_sent_signal
));
3152 last_sent_signal
= TARGET_SIGNAL_0
;
3153 target_terminal_inferior ();
3155 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3156 putpkt ((char *) buf
);
3159 /* else fallthrough */
3161 warning ("Invalid remote reply: %s", buf
);
3166 if (thread_num
!= -1)
3168 return pid_to_ptid (thread_num
);
3170 return inferior_ptid
;
3173 /* Async version of remote_wait. */
3175 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3177 struct remote_state
*rs
= get_remote_state ();
3178 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3179 int thread_num
= -1;
3181 status
->kind
= TARGET_WAITKIND_EXITED
;
3182 status
->value
.integer
= 0;
3188 if (!target_is_async_p ())
3189 ofunc
= signal (SIGINT
, remote_interrupt
);
3190 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3191 _never_ wait for ever -> test on target_is_async_p().
3192 However, before we do that we need to ensure that the caller
3193 knows how to take the target into/out of async mode. */
3194 getpkt (buf
, (rs
->remote_packet_size
), wait_forever_enabled_p
);
3195 if (!target_is_async_p ())
3196 signal (SIGINT
, ofunc
);
3198 /* This is a hook for when we need to do something (perhaps the
3199 collection of trace data) every time the target stops. */
3200 if (target_wait_loop_hook
)
3201 (*target_wait_loop_hook
) ();
3205 case 'E': /* Error of some sort */
3206 warning ("Remote failure reply: %s", buf
);
3208 case 'T': /* Status with PC, SP, FP, ... */
3211 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
3213 /* Expedited reply, containing Signal, {regno, reg} repeat */
3214 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3216 n... = register number
3217 r... = register contents
3219 p
= &buf
[3]; /* after Txx */
3227 /* Read the register number */
3228 long pnum
= strtol ((const char *) p
, &p_temp
, 16);
3229 p1
= (unsigned char *) p_temp
;
3231 if (p1
== p
) /* No register number present here */
3233 p1
= (unsigned char *) strchr ((const char *) p
, ':');
3235 warning ("Malformed packet(a) (missing colon): %s\n\
3238 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
3240 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3241 record_currthread (thread_num
);
3242 p
= (unsigned char *) p_temp
;
3247 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3250 warning ("Malformed packet(b) (missing colon): %s\n\
3255 warning ("Remote sent bad register number %ld: %s\n\
3259 fieldsize
= hex2bin (p
, regs
, REGISTER_RAW_SIZE (reg
->regnum
));
3261 if (fieldsize
< REGISTER_RAW_SIZE (reg
->regnum
))
3262 warning ("Remote reply is too short: %s", buf
);
3263 supply_register (reg
->regnum
, regs
);
3268 warning ("Remote register badly formatted: %s", buf
);
3269 warning (" here: %s", p
);
3274 case 'S': /* Old style status, just signal only */
3275 status
->kind
= TARGET_WAITKIND_STOPPED
;
3276 status
->value
.sig
= (enum target_signal
)
3277 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3281 /* Export Cisco kernel mode as a convenience variable
3282 (so that it can be used in the GDB prompt if desired). */
3284 if (cisco_kernel_mode
== 1)
3285 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3286 value_from_string ("PDEBUG-"));
3287 cisco_kernel_mode
= 0;
3288 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3289 record_currthread (thread_num
);
3291 else if (buf
[3] == 'k')
3293 /* Export Cisco kernel mode as a convenience variable
3294 (so that it can be used in the GDB prompt if desired). */
3296 if (cisco_kernel_mode
== 1)
3297 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3298 value_from_string ("KDEBUG-"));
3299 cisco_kernel_mode
= 1;
3302 case 'N': /* Cisco special: status and offsets */
3304 bfd_vma text_addr
, data_addr
, bss_addr
;
3305 bfd_signed_vma text_off
, data_off
, bss_off
;
3308 status
->kind
= TARGET_WAITKIND_STOPPED
;
3309 status
->value
.sig
= (enum target_signal
)
3310 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3312 if (symfile_objfile
== NULL
)
3314 warning ("Relocation packet recieved with no symbol file. \
3319 /* Relocate object file. Buffer format is NAATT;DD;BB
3320 * where AA is the signal number, TT is the new text
3321 * address, DD * is the new data address, and BB is the
3322 * new bss address. */
3325 text_addr
= strtoul (p
, (char **) &p1
, 16);
3326 if (p1
== p
|| *p1
!= ';')
3327 warning ("Malformed relocation packet: Packet '%s'", buf
);
3329 data_addr
= strtoul (p
, (char **) &p1
, 16);
3330 if (p1
== p
|| *p1
!= ';')
3331 warning ("Malformed relocation packet: Packet '%s'", buf
);
3333 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3335 warning ("Malformed relocation packet: Packet '%s'", buf
);
3337 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3338 &text_off
, &data_off
, &bss_off
)
3340 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3341 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3345 case 'W': /* Target exited */
3347 /* The remote process exited. */
3348 status
->kind
= TARGET_WAITKIND_EXITED
;
3349 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3353 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3354 status
->value
.sig
= (enum target_signal
)
3355 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3359 case 'O': /* Console output */
3360 remote_console_output (buf
+ 1);
3361 /* Return immediately to the event loop. The event loop will
3362 still be waiting on the inferior afterwards. */
3363 status
->kind
= TARGET_WAITKIND_IGNORE
;
3366 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3368 /* Zero length reply means that we tried 'S' or 'C' and
3369 the remote system doesn't support it. */
3370 target_terminal_ours_for_output ();
3372 ("Can't send signals to this remote system. %s not sent.\n",
3373 target_signal_to_name (last_sent_signal
));
3374 last_sent_signal
= TARGET_SIGNAL_0
;
3375 target_terminal_inferior ();
3377 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3378 putpkt ((char *) buf
);
3381 /* else fallthrough */
3383 warning ("Invalid remote reply: %s", buf
);
3388 if (thread_num
!= -1)
3390 return pid_to_ptid (thread_num
);
3392 return inferior_ptid
;
3395 /* Number of bytes of registers this stub implements. */
3397 static int register_bytes_found
;
3399 /* Read the remote registers into the block REGS. */
3400 /* Currently we just read all the registers, so we don't use regnum. */
3404 remote_fetch_registers (int regnum
)
3406 struct remote_state
*rs
= get_remote_state ();
3407 char *buf
= alloca (rs
->remote_packet_size
);
3410 char *regs
= alloca (rs
->sizeof_g_packet
);
3412 set_thread (PIDGET (inferior_ptid
), 1);
3416 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3417 gdb_assert (reg
!= NULL
);
3418 if (!reg
->in_g_packet
)
3419 internal_error (__FILE__
, __LINE__
,
3420 "Attempt to fetch a non G-packet register when this "
3421 "remote.c does not support the p-packet.");
3425 remote_send (buf
, (rs
->remote_packet_size
));
3427 /* Save the size of the packet sent to us by the target. Its used
3428 as a heuristic when determining the max size of packets that the
3429 target can safely receive. */
3430 if ((rs
->actual_register_packet_size
) == 0)
3431 (rs
->actual_register_packet_size
) = strlen (buf
);
3433 /* Unimplemented registers read as all bits zero. */
3434 memset (regs
, 0, rs
->sizeof_g_packet
);
3436 /* We can get out of synch in various cases. If the first character
3437 in the buffer is not a hex character, assume that has happened
3438 and try to fetch another packet to read. */
3439 while ((buf
[0] < '0' || buf
[0] > '9')
3440 && (buf
[0] < 'a' || buf
[0] > 'f')
3441 && buf
[0] != 'x') /* New: unavailable register value */
3444 fprintf_unfiltered (gdb_stdlog
,
3445 "Bad register packet; fetching a new packet\n");
3446 getpkt (buf
, (rs
->remote_packet_size
), 0);
3449 /* Reply describes registers byte by byte, each byte encoded as two
3450 hex characters. Suck them all up, then supply them to the
3451 register cacheing/storage mechanism. */
3454 for (i
= 0; i
< rs
->sizeof_g_packet
; i
++)
3460 warning ("Remote reply is of odd length: %s", buf
);
3461 /* Don't change register_bytes_found in this case, and don't
3462 print a second warning. */
3465 if (p
[0] == 'x' && p
[1] == 'x')
3466 regs
[i
] = 0; /* 'x' */
3468 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3472 if (i
!= register_bytes_found
)
3474 register_bytes_found
= i
;
3475 if (REGISTER_BYTES_OK_P ()
3476 && !REGISTER_BYTES_OK (i
))
3477 warning ("Remote reply is too short: %s", buf
);
3483 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3485 struct packet_reg
*r
= &rs
->regs
[i
];
3488 supply_register (r
->regnum
, regs
+ r
->offset
);
3489 if (buf
[r
->offset
* 2] == 'x')
3490 set_register_cached (i
, -1);
3496 /* Prepare to store registers. Since we may send them all (using a
3497 'G' request), we have to read out the ones we don't want to change
3501 remote_prepare_to_store (void)
3503 /* Make sure the entire registers array is valid. */
3504 switch (remote_protocol_P
.support
)
3506 case PACKET_DISABLE
:
3507 case PACKET_SUPPORT_UNKNOWN
:
3508 /* NOTE: This isn't rs->sizeof_g_packet because here, we are
3509 forcing the register cache to read its and not the target
3511 read_register_bytes (0, (char *) NULL
, REGISTER_BYTES
); /* OK use. */
3518 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3519 packet was not recognized. */
3522 store_register_using_P (int regnum
)
3524 struct remote_state
*rs
= get_remote_state ();
3525 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3526 /* Try storing a single register. */
3527 char *buf
= alloca (rs
->remote_packet_size
);
3528 char *regp
= alloca (MAX_REGISTER_RAW_SIZE
);
3532 sprintf (buf
, "P%s=", phex_nz (reg
->pnum
, 0));
3533 p
= buf
+ strlen (buf
);
3534 regcache_collect (reg
->regnum
, regp
);
3535 bin2hex (regp
, p
, REGISTER_RAW_SIZE (reg
->regnum
));
3536 remote_send (buf
, rs
->remote_packet_size
);
3538 return buf
[0] != '\0';
3542 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
3543 of the register cache buffer. FIXME: ignores errors. */
3546 remote_store_registers (int regnum
)
3548 struct remote_state
*rs
= get_remote_state ();
3554 set_thread (PIDGET (inferior_ptid
), 1);
3558 switch (remote_protocol_P
.support
)
3560 case PACKET_DISABLE
:
3563 if (store_register_using_P (regnum
))
3566 error ("Protocol error: P packet not recognized by stub");
3567 case PACKET_SUPPORT_UNKNOWN
:
3568 if (store_register_using_P (regnum
))
3570 /* The stub recognized the 'P' packet. Remember this. */
3571 remote_protocol_P
.support
= PACKET_ENABLE
;
3576 /* The stub does not support the 'P' packet. Use 'G'
3577 instead, and don't try using 'P' in the future (it
3578 will just waste our time). */
3579 remote_protocol_P
.support
= PACKET_DISABLE
;
3585 /* Extract all the registers in the regcache copying them into a
3589 regs
= alloca (rs
->sizeof_g_packet
);
3590 memset (regs
, rs
->sizeof_g_packet
, 0);
3591 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3593 struct packet_reg
*r
= &rs
->regs
[i
];
3595 regcache_collect (r
->regnum
, regs
+ r
->offset
);
3599 /* Command describes registers byte by byte,
3600 each byte encoded as two hex characters. */
3601 buf
= alloca (rs
->remote_packet_size
);
3604 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3605 bin2hex (regs
, p
, register_bytes_found
);
3606 remote_send (buf
, (rs
->remote_packet_size
));
3610 /* Return the number of hex digits in num. */
3613 hexnumlen (ULONGEST num
)
3617 for (i
= 0; num
!= 0; i
++)
3623 /* Set BUF to the minimum number of hex digits representing NUM. */
3626 hexnumstr (char *buf
, ULONGEST num
)
3628 int len
= hexnumlen (num
);
3629 return hexnumnstr (buf
, num
, len
);
3633 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3636 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3642 for (i
= width
- 1; i
>= 0; i
--)
3644 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3651 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3654 remote_address_masked (CORE_ADDR addr
)
3656 if (remote_address_size
> 0
3657 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3659 /* Only create a mask when that mask can safely be constructed
3660 in a ULONGEST variable. */
3662 mask
= (mask
<< remote_address_size
) - 1;
3668 /* Determine whether the remote target supports binary downloading.
3669 This is accomplished by sending a no-op memory write of zero length
3670 to the target at the specified address. It does not suffice to send
3671 the whole packet, since many stubs strip the eighth bit and subsequently
3672 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3674 NOTE: This can still lose if the serial line is not eight-bit
3675 clean. In cases like this, the user should clear "remote
3679 check_binary_download (CORE_ADDR addr
)
3681 struct remote_state
*rs
= get_remote_state ();
3682 switch (remote_protocol_binary_download
.support
)
3684 case PACKET_DISABLE
:
3688 case PACKET_SUPPORT_UNKNOWN
:
3690 char *buf
= alloca (rs
->remote_packet_size
);
3695 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3697 p
+= hexnumstr (p
, (ULONGEST
) 0);
3701 putpkt_binary (buf
, (int) (p
- buf
));
3702 getpkt (buf
, (rs
->remote_packet_size
), 0);
3707 fprintf_unfiltered (gdb_stdlog
,
3708 "binary downloading NOT suppported by target\n");
3709 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3714 fprintf_unfiltered (gdb_stdlog
,
3715 "binary downloading suppported by target\n");
3716 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3723 /* Write memory data directly to the remote machine.
3724 This does not inform the data cache; the data cache uses this.
3725 MEMADDR is the address in the remote memory space.
3726 MYADDR is the address of the buffer in our space.
3727 LEN is the number of bytes.
3729 Returns number of bytes transferred, or 0 (setting errno) for
3730 error. Only transfer a single packet. */
3733 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3736 int max_buf_size
; /* Max size of packet output buffer */
3738 unsigned char *plen
;
3744 /* Verify that the target can support a binary download */
3745 check_binary_download (memaddr
);
3747 /* Determine the max packet size. */
3748 max_buf_size
= get_memory_write_packet_size ();
3749 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3750 buf
= alloca (sizeof_buf
);
3752 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3753 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
3755 /* construct "M"<memaddr>","<len>":" */
3756 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3759 /* Append [XM]. Compute a best guess of the number of bytes
3760 actually transfered. */
3761 switch (remote_protocol_binary_download
.support
)
3765 /* Best guess at number of bytes that will fit. */
3766 todo
= min (len
, max_buf_size
);
3768 case PACKET_DISABLE
:
3770 /* num bytes that will fit */
3771 todo
= min (len
, max_buf_size
/ 2);
3773 case PACKET_SUPPORT_UNKNOWN
:
3774 internal_error (__FILE__
, __LINE__
,
3775 "remote_write_bytes: bad internal state");
3777 internal_error (__FILE__
, __LINE__
, "bad switch");
3780 /* Append <memaddr> */
3781 memaddr
= remote_address_masked (memaddr
);
3782 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3785 /* Append <len>. Retain the location/size of <len>. It may
3786 need to be adjusted once the packet body has been created. */
3788 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3793 /* Append the packet body. */
3794 switch (remote_protocol_binary_download
.support
)
3797 /* Binary mode. Send target system values byte by byte, in
3798 increasing byte addresses. Only escape certain critical
3801 (nr_bytes
< todo
) && (p
- buf
) < (max_buf_size
- 2);
3804 switch (myaddr
[nr_bytes
] & 0xff)
3809 /* These must be escaped */
3811 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3814 *p
++ = myaddr
[nr_bytes
] & 0xff;
3818 if (nr_bytes
< todo
)
3820 /* Escape chars have filled up the buffer prematurely,
3821 and we have actually sent fewer bytes than planned.
3822 Fix-up the length field of the packet. Use the same
3823 number of characters as before. */
3825 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3826 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3829 case PACKET_DISABLE
:
3830 /* Normal mode: Send target system values byte by byte, in
3831 increasing byte addresses. Each byte is encoded as a two hex
3833 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3836 case PACKET_SUPPORT_UNKNOWN
:
3837 internal_error (__FILE__
, __LINE__
,
3838 "remote_write_bytes: bad internal state");
3840 internal_error (__FILE__
, __LINE__
, "bad switch");
3843 putpkt_binary (buf
, (int) (p
- buf
));
3844 getpkt (buf
, sizeof_buf
, 0);
3848 /* There is no correspondance between what the remote protocol
3849 uses for errors and errno codes. We would like a cleaner way
3850 of representing errors (big enough to include errno codes,
3851 bfd_error codes, and others). But for now just return EIO. */
3856 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3857 bytes than we'd planned. */
3861 /* Read memory data directly from the remote machine.
3862 This does not use the data cache; the data cache uses this.
3863 MEMADDR is the address in the remote memory space.
3864 MYADDR is the address of the buffer in our space.
3865 LEN is the number of bytes.
3867 Returns number of bytes transferred, or 0 for error. */
3869 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3870 remote targets) shouldn't attempt to read the entire buffer.
3871 Instead it should read a single packet worth of data and then
3872 return the byte size of that packet to the caller. The caller (its
3873 caller and its callers caller ;-) already contains code for
3874 handling partial reads. */
3877 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3880 int max_buf_size
; /* Max size of packet output buffer */
3884 /* Create a buffer big enough for this packet. */
3885 max_buf_size
= get_memory_read_packet_size ();
3886 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3887 buf
= alloca (sizeof_buf
);
3896 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3898 /* construct "m"<memaddr>","<len>" */
3899 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3900 memaddr
= remote_address_masked (memaddr
);
3903 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3905 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3909 getpkt (buf
, sizeof_buf
, 0);
3913 /* There is no correspondance between what the remote protocol uses
3914 for errors and errno codes. We would like a cleaner way of
3915 representing errors (big enough to include errno codes, bfd_error
3916 codes, and others). But for now just return EIO. */
3921 /* Reply describes memory byte by byte,
3922 each byte encoded as two hex characters. */
3925 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
3927 /* Reply is short. This means that we were able to read
3928 only part of what we wanted to. */
3929 return i
+ (origlen
- len
);
3938 /* Read or write LEN bytes from inferior memory at MEMADDR,
3939 transferring to or from debugger address BUFFER. Write to inferior if
3940 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3941 for error. TARGET is unused. */
3945 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
3947 struct mem_attrib
*attrib ATTRIBUTE_UNUSED
,
3948 struct target_ops
*target
)
3950 CORE_ADDR targ_addr
;
3954 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr
, mem_len
, &targ_addr
, &targ_len
);
3959 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
3961 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
3968 /* Enable after 4.12. */
3971 remote_search (int len
, char *data
, char *mask
, CORE_ADDR startaddr
,
3972 int increment
, CORE_ADDR lorange
, CORE_ADDR hirange
,
3973 CORE_ADDR
*addr_found
, char *data_found
)
3975 if (increment
== -4 && len
== 4)
3977 long mask_long
, data_long
;
3978 long data_found_long
;
3979 CORE_ADDR addr_we_found
;
3980 char *buf
= alloca (rs
->remote_packet_size
);
3981 long returned_long
[2];
3984 mask_long
= extract_unsigned_integer (mask
, len
);
3985 data_long
= extract_unsigned_integer (data
, len
);
3986 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
3988 getpkt (buf
, (rs
->remote_packet_size
), 0);
3991 /* The stub doesn't support the 't' request. We might want to
3992 remember this fact, but on the other hand the stub could be
3993 switched on us. Maybe we should remember it only until
3994 the next "target remote". */
3995 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
3996 hirange
, addr_found
, data_found
);
4001 /* There is no correspondance between what the remote protocol uses
4002 for errors and errno codes. We would like a cleaner way of
4003 representing errors (big enough to include errno codes, bfd_error
4004 codes, and others). But for now just use EIO. */
4005 memory_error (EIO
, startaddr
);
4008 while (*p
!= '\0' && *p
!= ',')
4009 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
4011 error ("Protocol error: short return for search");
4013 data_found_long
= 0;
4014 while (*p
!= '\0' && *p
!= ',')
4015 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
4016 /* Ignore anything after this comma, for future extensions. */
4018 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
4024 *addr_found
= addr_we_found
;
4025 *data_found
= store_unsigned_integer (data_we_found
, len
);
4028 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
4029 hirange
, addr_found
, data_found
);
4034 remote_files_info (struct target_ops
*ignore
)
4036 puts_filtered ("Debugging a target over a serial line.\n");
4039 /* Stuff for dealing with the packets which are part of this protocol.
4040 See comment at top of file for details. */
4042 /* Read a single character from the remote end, masking it down to 7 bits. */
4045 readchar (int timeout
)
4049 ch
= serial_readchar (remote_desc
, timeout
);
4054 switch ((enum serial_rc
) ch
)
4057 target_mourn_inferior ();
4058 error ("Remote connection closed");
4061 perror_with_name ("Remote communication error");
4063 case SERIAL_TIMEOUT
:
4069 /* Send the command in BUF to the remote machine, and read the reply
4070 into BUF. Report an error if we get an error reply. */
4073 remote_send (char *buf
,
4077 getpkt (buf
, sizeof_buf
, 0);
4080 error ("Remote failure reply: %s", buf
);
4083 /* Display a null-terminated packet on stdout, for debugging, using C
4087 print_packet (char *buf
)
4089 puts_filtered ("\"");
4090 fputstr_filtered (buf
, '"', gdb_stdout
);
4091 puts_filtered ("\"");
4097 return putpkt_binary (buf
, strlen (buf
));
4100 /* Send a packet to the remote machine, with error checking. The data
4101 of the packet is in BUF. The string in BUF can be at most (rs->remote_packet_size) - 5
4102 to account for the $, # and checksum, and for a possible /0 if we are
4103 debugging (remote_debug) and want to print the sent packet as a string */
4106 putpkt_binary (char *buf
, int cnt
)
4108 struct remote_state
*rs
= get_remote_state ();
4110 unsigned char csum
= 0;
4111 char *buf2
= alloca (cnt
+ 6);
4112 long sizeof_junkbuf
= (rs
->remote_packet_size
);
4113 char *junkbuf
= alloca (sizeof_junkbuf
);
4119 /* Copy the packet into buffer BUF2, encapsulating it
4120 and giving it a checksum. */
4125 for (i
= 0; i
< cnt
; i
++)
4131 *p
++ = tohex ((csum
>> 4) & 0xf);
4132 *p
++ = tohex (csum
& 0xf);
4134 /* Send it over and over until we get a positive ack. */
4138 int started_error_output
= 0;
4143 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4144 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4145 fprintf_unfiltered (gdb_stdlog
, "...");
4146 gdb_flush (gdb_stdlog
);
4148 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4149 perror_with_name ("putpkt: write failed");
4151 /* read until either a timeout occurs (-2) or '+' is read */
4154 ch
= readchar (remote_timeout
);
4162 case SERIAL_TIMEOUT
:
4164 if (started_error_output
)
4166 putchar_unfiltered ('\n');
4167 started_error_output
= 0;
4176 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4180 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4181 case SERIAL_TIMEOUT
:
4185 break; /* Retransmit buffer */
4189 fprintf_unfiltered (gdb_stdlog
, "Packet instead of Ack, ignoring it\n");
4190 /* It's probably an old response, and we're out of sync.
4191 Just gobble up the packet and ignore it. */
4192 read_frame (junkbuf
, sizeof_junkbuf
);
4193 continue; /* Now, go look for + */
4198 if (!started_error_output
)
4200 started_error_output
= 1;
4201 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4203 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4207 break; /* Here to retransmit */
4211 /* This is wrong. If doing a long backtrace, the user should be
4212 able to get out next time we call QUIT, without anything as
4213 violent as interrupt_query. If we want to provide a way out of
4214 here without getting to the next QUIT, it should be based on
4215 hitting ^C twice as in remote_wait. */
4225 static int remote_cisco_mode
;
4227 /* Come here after finding the start of the frame. Collect the rest
4228 into BUF, verifying the checksum, length, and handling run-length
4229 compression. No more than sizeof_buf-1 characters are read so that
4230 the buffer can be NUL terminated.
4232 Returns -1 on error, number of characters in buffer (ignoring the
4233 trailing NULL) on success. (could be extended to return one of the
4234 SERIAL status indications). */
4237 read_frame (char *buf
,
4249 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
4250 c
= readchar (remote_timeout
);
4253 case SERIAL_TIMEOUT
:
4255 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4259 fputs_filtered ("Saw new packet start in middle of old one\n",
4261 return -1; /* Start a new packet, count retries */
4264 unsigned char pktcsum
;
4270 check_0
= readchar (remote_timeout
);
4272 check_1
= readchar (remote_timeout
);
4274 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4277 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog
);
4280 else if (check_0
< 0 || check_1
< 0)
4283 fputs_filtered ("Communication error in checksum\n", gdb_stdlog
);
4287 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4288 if (csum
== pktcsum
)
4293 fprintf_filtered (gdb_stdlog
,
4294 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4296 fputs_filtered (buf
, gdb_stdlog
);
4297 fputs_filtered ("\n", gdb_stdlog
);
4299 /* Number of characters in buffer ignoring trailing
4303 case '*': /* Run length encoding */
4308 if (remote_cisco_mode
== 0)
4310 c
= readchar (remote_timeout
);
4312 repeat
= c
- ' ' + 3; /* Compute repeat count */
4316 /* Cisco's run-length encoding variant uses two
4317 hex chars to represent the repeat count. */
4319 c
= readchar (remote_timeout
);
4321 repeat
= fromhex (c
) << 4;
4322 c
= readchar (remote_timeout
);
4324 repeat
+= fromhex (c
);
4327 /* The character before ``*'' is repeated. */
4329 if (repeat
> 0 && repeat
<= 255
4331 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4333 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4339 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
4340 puts_filtered (buf
);
4341 puts_filtered ("\n");
4345 if (bc
< sizeof_buf
- 1)
4353 puts_filtered ("Remote packet too long: ");
4354 puts_filtered (buf
);
4355 puts_filtered ("\n");
4362 /* Read a packet from the remote machine, with error checking, and
4363 store it in BUF. If FOREVER, wait forever rather than timing out;
4364 this is used (in synchronous mode) to wait for a target that is is
4365 executing user code to stop. */
4366 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4367 don't have to change all the calls to getpkt to deal with the
4368 return value, because at the moment I don't know what the right
4369 thing to do it for those. */
4377 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4381 /* Read a packet from the remote machine, with error checking, and
4382 store it in BUF. If FOREVER, wait forever rather than timing out;
4383 this is used (in synchronous mode) to wait for a target that is is
4384 executing user code to stop. If FOREVER == 0, this function is
4385 allowed to time out gracefully and return an indication of this to
4388 getpkt_sane (char *buf
,
4397 strcpy (buf
, "timeout");
4401 timeout
= watchdog
> 0 ? watchdog
: -1;
4405 timeout
= remote_timeout
;
4409 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4411 /* This can loop forever if the remote side sends us characters
4412 continuously, but if it pauses, we'll get a zero from readchar
4413 because of timeout. Then we'll count that as a retry. */
4415 /* Note that we will only wait forever prior to the start of a packet.
4416 After that, we expect characters to arrive at a brisk pace. They
4417 should show up within remote_timeout intervals. */
4421 c
= readchar (timeout
);
4423 if (c
== SERIAL_TIMEOUT
)
4425 if (forever
) /* Watchdog went off? Kill the target. */
4428 target_mourn_inferior ();
4429 error ("Watchdog has expired. Target detached.\n");
4432 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4438 /* We've found the start of a packet, now collect the data. */
4440 val
= read_frame (buf
, sizeof_buf
);
4446 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4447 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4448 fprintf_unfiltered (gdb_stdlog
, "\n");
4450 serial_write (remote_desc
, "+", 1);
4454 /* Try the whole thing again. */
4456 serial_write (remote_desc
, "-", 1);
4459 /* We have tried hard enough, and just can't receive the packet. Give up. */
4461 printf_unfiltered ("Ignoring packet error, continuing...\n");
4462 serial_write (remote_desc
, "+", 1);
4469 /* For some mysterious reason, wait_for_inferior calls kill instead of
4470 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4474 target_mourn_inferior ();
4478 /* Use catch_errors so the user can quit from gdb even when we aren't on
4479 speaking terms with the remote system. */
4480 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4482 /* Don't wait for it to die. I'm not really sure it matters whether
4483 we do or not. For the existing stubs, kill is a noop. */
4484 target_mourn_inferior ();
4487 /* Async version of remote_kill. */
4489 remote_async_kill (void)
4491 /* Unregister the file descriptor from the event loop. */
4492 if (target_is_async_p ())
4493 serial_async (remote_desc
, NULL
, 0);
4495 /* For some mysterious reason, wait_for_inferior calls kill instead of
4496 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4500 target_mourn_inferior ();
4504 /* Use catch_errors so the user can quit from gdb even when we aren't on
4505 speaking terms with the remote system. */
4506 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4508 /* Don't wait for it to die. I'm not really sure it matters whether
4509 we do or not. For the existing stubs, kill is a noop. */
4510 target_mourn_inferior ();
4516 remote_mourn_1 (&remote_ops
);
4520 remote_async_mourn (void)
4522 remote_mourn_1 (&remote_async_ops
);
4526 extended_remote_mourn (void)
4528 /* We do _not_ want to mourn the target like this; this will
4529 remove the extended remote target from the target stack,
4530 and the next time the user says "run" it'll fail.
4532 FIXME: What is the right thing to do here? */
4534 remote_mourn_1 (&extended_remote_ops
);
4538 /* Worker function for remote_mourn. */
4540 remote_mourn_1 (struct target_ops
*target
)
4542 unpush_target (target
);
4543 generic_mourn_inferior ();
4546 /* In the extended protocol we want to be able to do things like
4547 "run" and have them basically work as expected. So we need
4548 a special create_inferior function.
4550 FIXME: One day add support for changing the exec file
4551 we're debugging, arguments and an environment. */
4554 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
)
4556 /* Rip out the breakpoints; we'll reinsert them after restarting
4557 the remote server. */
4558 remove_breakpoints ();
4560 /* Now restart the remote server. */
4561 extended_remote_restart ();
4563 /* Now put the breakpoints back in. This way we're safe if the
4564 restart function works via a unix fork on the remote side. */
4565 insert_breakpoints ();
4567 /* Clean up from the last time we were running. */
4568 clear_proceed_status ();
4570 /* Let the remote process run. */
4571 proceed (-1, TARGET_SIGNAL_0
, 0);
4574 /* Async version of extended_remote_create_inferior. */
4576 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
)
4578 /* Rip out the breakpoints; we'll reinsert them after restarting
4579 the remote server. */
4580 remove_breakpoints ();
4582 /* If running asynchronously, register the target file descriptor
4583 with the event loop. */
4584 if (event_loop_p
&& target_can_async_p ())
4585 target_async (inferior_event_handler
, 0);
4587 /* Now restart the remote server. */
4588 extended_remote_restart ();
4590 /* Now put the breakpoints back in. This way we're safe if the
4591 restart function works via a unix fork on the remote side. */
4592 insert_breakpoints ();
4594 /* Clean up from the last time we were running. */
4595 clear_proceed_status ();
4597 /* Let the remote process run. */
4598 proceed (-1, TARGET_SIGNAL_0
, 0);
4602 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
4603 than other targets; in those use REMOTE_BREAKPOINT instead of just
4604 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
4605 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
4606 the standard routines that are in mem-break.c. */
4608 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
4609 the choice of breakpoint instruction affects target program design and
4610 vice versa, and by making it user-tweakable, the special code here
4611 goes away and we need fewer special GDB configurations. */
4613 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4614 #define REMOTE_BREAKPOINT
4617 #ifdef REMOTE_BREAKPOINT
4619 /* If the target isn't bi-endian, just pretend it is. */
4620 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
4621 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4622 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4625 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
4626 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
4628 #endif /* REMOTE_BREAKPOINT */
4630 /* Insert a breakpoint on targets that don't have any better breakpoint
4631 support. We read the contents of the target location and stash it,
4632 then overwrite it with a breakpoint instruction. ADDR is the target
4633 location in the target machine. CONTENTS_CACHE is a pointer to
4634 memory allocated for saving the target contents. It is guaranteed
4635 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
4636 is accomplished via BREAKPOINT_MAX). */
4639 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4641 struct remote_state
*rs
= get_remote_state ();
4642 #ifdef REMOTE_BREAKPOINT
4647 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4648 If it succeeds, then set the support to PACKET_ENABLE. If it
4649 fails, and the user has explicitly requested the Z support then
4650 report an error, otherwise, mark it disabled and go on. */
4652 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4654 char *buf
= alloca (rs
->remote_packet_size
);
4657 addr
= remote_address_masked (addr
);
4661 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4662 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4663 sprintf (p
, ",%d", bp_size
);
4666 getpkt (buf
, (rs
->remote_packet_size
), 0);
4668 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4674 case PACKET_UNKNOWN
:
4679 #ifdef REMOTE_BREAKPOINT
4680 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4684 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4685 val
= target_write_memory (addr
, (char *) big_break_insn
,
4686 sizeof big_break_insn
);
4688 val
= target_write_memory (addr
, (char *) little_break_insn
,
4689 sizeof little_break_insn
);
4694 return memory_insert_breakpoint (addr
, contents_cache
);
4695 #endif /* REMOTE_BREAKPOINT */
4699 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4701 struct remote_state
*rs
= get_remote_state ();
4704 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4706 char *buf
= alloca (rs
->remote_packet_size
);
4713 addr
= remote_address_masked (addr
);
4714 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4715 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4716 sprintf (p
, ",%d", bp_size
);
4719 getpkt (buf
, (rs
->remote_packet_size
), 0);
4721 return (buf
[0] == 'E');
4724 #ifdef REMOTE_BREAKPOINT
4725 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4727 return memory_remove_breakpoint (addr
, contents_cache
);
4728 #endif /* REMOTE_BREAKPOINT */
4732 watchpoint_to_Z_packet (int type
)
4746 internal_error (__FILE__
, __LINE__
,
4747 "hw_bp_to_z: bad watchpoint type %d", type
);
4751 /* FIXME: This function should be static and a member of the remote
4755 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4757 struct remote_state
*rs
= get_remote_state ();
4758 char *buf
= alloca (rs
->remote_packet_size
);
4760 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4762 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4763 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4764 remote_protocol_Z
[packet
].name
,
4765 remote_protocol_Z
[packet
].title
);
4767 sprintf (buf
, "Z%x,", packet
);
4768 p
= strchr (buf
, '\0');
4769 addr
= remote_address_masked (addr
);
4770 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4771 sprintf (p
, ",%x", len
);
4774 getpkt (buf
, (rs
->remote_packet_size
), 0);
4776 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4779 case PACKET_UNKNOWN
:
4784 internal_error (__FILE__
, __LINE__
,
4785 "remote_insert_watchpoint: reached end of function");
4788 /* FIXME: This function should be static and a member of the remote
4792 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4794 struct remote_state
*rs
= get_remote_state ();
4795 char *buf
= alloca (rs
->remote_packet_size
);
4797 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4799 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4800 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4801 remote_protocol_Z
[packet
].name
,
4802 remote_protocol_Z
[packet
].title
);
4804 sprintf (buf
, "z%x,", packet
);
4805 p
= strchr (buf
, '\0');
4806 addr
= remote_address_masked (addr
);
4807 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4808 sprintf (p
, ",%x", len
);
4810 getpkt (buf
, (rs
->remote_packet_size
), 0);
4812 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4815 case PACKET_UNKNOWN
:
4820 internal_error (__FILE__
, __LINE__
,
4821 "remote_remove_watchpoint: reached end of function");
4824 /* FIXME: This function should be static and a member of the remote
4828 remote_insert_hw_breakpoint (CORE_ADDR addr
, int len
)
4830 struct remote_state
*rs
= get_remote_state ();
4831 char *buf
= alloca (rs
->remote_packet_size
);
4834 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4835 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4836 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4837 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4843 addr
= remote_address_masked (addr
);
4844 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4845 sprintf (p
, ",%x", len
);
4848 getpkt (buf
, (rs
->remote_packet_size
), 0);
4850 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4853 case PACKET_UNKNOWN
:
4858 internal_error (__FILE__
, __LINE__
,
4859 "remote_remove_watchpoint: reached end of function");
4862 /* FIXME: This function should be static and a member of the remote
4866 remote_remove_hw_breakpoint (CORE_ADDR addr
, int len
)
4868 struct remote_state
*rs
= get_remote_state ();
4869 char *buf
= alloca (rs
->remote_packet_size
);
4872 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4873 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
4874 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4875 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4881 addr
= remote_address_masked (addr
);
4882 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4883 sprintf (p
, ",%x", len
);
4886 getpkt (buf
, (rs
->remote_packet_size
), 0);
4888 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4891 case PACKET_UNKNOWN
:
4896 internal_error (__FILE__
, __LINE__
,
4897 "remote_remove_watchpoint: reached end of function");
4900 /* Some targets are only capable of doing downloads, and afterwards
4901 they switch to the remote serial protocol. This function provides
4902 a clean way to get from the download target to the remote target.
4903 It's basically just a wrapper so that we don't have to expose any
4904 of the internal workings of remote.c.
4906 Prior to calling this routine, you should shutdown the current
4907 target code, else you will get the "A program is being debugged
4908 already..." message. Usually a call to pop_target() suffices. */
4911 push_remote_target (char *name
, int from_tty
)
4913 printf_filtered ("Switching to remote protocol\n");
4914 remote_open (name
, from_tty
);
4917 /* Other targets want to use the entire remote serial module but with
4918 certain remote_ops overridden. */
4921 open_remote_target (char *name
, int from_tty
, struct target_ops
*target
,
4924 printf_filtered ("Selecting the %sremote protocol\n",
4925 (extended_p
? "extended-" : ""));
4926 remote_open_1 (name
, from_tty
, target
, extended_p
);
4929 /* Table used by the crc32 function to calcuate the checksum. */
4931 static unsigned long crc32_table
[256] =
4934 static unsigned long
4935 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4937 if (!crc32_table
[1])
4939 /* Initialize the CRC table and the decoding table. */
4943 for (i
= 0; i
< 256; i
++)
4945 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4946 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4953 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4959 /* compare-sections command
4961 With no arguments, compares each loadable section in the exec bfd
4962 with the same memory range on the target, and reports mismatches.
4963 Useful for verifying the image on the target against the exec file.
4964 Depends on the target understanding the new "qCRC:" request. */
4966 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4967 target method (target verify memory) and generic version of the
4968 actual command. This will allow other high-level code (especially
4969 generic_load()) to make use of this target functionality. */
4972 compare_sections_command (char *args
, int from_tty
)
4974 struct remote_state
*rs
= get_remote_state ();
4976 unsigned long host_crc
, target_crc
;
4977 extern bfd
*exec_bfd
;
4978 struct cleanup
*old_chain
;
4981 const char *sectname
;
4982 char *buf
= alloca (rs
->remote_packet_size
);
4989 error ("command cannot be used without an exec file");
4990 if (!current_target
.to_shortname
||
4991 strcmp (current_target
.to_shortname
, "remote") != 0)
4992 error ("command can only be used with remote target");
4994 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4996 if (!(s
->flags
& SEC_LOAD
))
4997 continue; /* skip non-loadable section */
4999 size
= bfd_get_section_size_before_reloc (s
);
5001 continue; /* skip zero-length section */
5003 sectname
= bfd_get_section_name (exec_bfd
, s
);
5004 if (args
&& strcmp (args
, sectname
) != 0)
5005 continue; /* not the section selected by user */
5007 matched
= 1; /* do this section */
5009 /* FIXME: assumes lma can fit into long */
5010 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
5013 /* be clever; compute the host_crc before waiting for target reply */
5014 sectdata
= xmalloc (size
);
5015 old_chain
= make_cleanup (xfree
, sectdata
);
5016 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
5017 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
5019 getpkt (buf
, (rs
->remote_packet_size
), 0);
5021 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
5022 sectname
, lma
, lma
+ size
);
5024 error ("remote target does not support this operation");
5026 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
5027 target_crc
= target_crc
* 16 + fromhex (*tmp
);
5029 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
5030 sectname
, paddr (lma
), paddr (lma
+ size
));
5031 if (host_crc
== target_crc
)
5032 printf_filtered ("matched.\n");
5035 printf_filtered ("MIS-MATCHED!\n");
5039 do_cleanups (old_chain
);
5042 warning ("One or more sections of the remote executable does not match\n\
5043 the loaded file\n");
5044 if (args
&& !matched
)
5045 printf_filtered ("No loaded section named '%s'.\n", args
);
5049 remote_query (int query_type
, char *buf
, char *outbuf
, int *bufsiz
)
5051 struct remote_state
*rs
= get_remote_state ();
5053 char *buf2
= alloca (rs
->remote_packet_size
);
5054 char *p2
= &buf2
[0];
5057 error ("null pointer to remote bufer size specified");
5059 /* minimum outbuf size is (rs->remote_packet_size) - if bufsiz is not large enough let
5060 the caller know and return what the minimum size is */
5061 /* Note: a zero bufsiz can be used to query the minimum buffer size */
5062 if (*bufsiz
< (rs
->remote_packet_size
))
5064 *bufsiz
= (rs
->remote_packet_size
);
5068 /* except for querying the minimum buffer size, target must be open */
5070 error ("remote query is only available after target open");
5072 /* we only take uppercase letters as query types, at least for now */
5073 if ((query_type
< 'A') || (query_type
> 'Z'))
5074 error ("invalid remote query type");
5077 error ("null remote query specified");
5080 error ("remote query requires a buffer to receive data");
5087 /* we used one buffer char for the remote protocol q command and another
5088 for the query type. As the remote protocol encapsulation uses 4 chars
5089 plus one extra in case we are debugging (remote_debug),
5090 we have PBUFZIZ - 7 left to pack the query string */
5092 while (buf
[i
] && (i
< ((rs
->remote_packet_size
) - 8)))
5094 /* bad caller may have sent forbidden characters */
5095 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
5096 error ("illegal characters in query string");
5104 error ("query larger than available buffer");
5110 getpkt (outbuf
, *bufsiz
, 0);
5116 remote_rcmd (char *command
,
5117 struct ui_file
*outbuf
)
5119 struct remote_state
*rs
= get_remote_state ();
5121 char *buf
= alloca (rs
->remote_packet_size
);
5125 error ("remote rcmd is only available after target open");
5127 /* Send a NULL command across as an empty command */
5128 if (command
== NULL
)
5131 /* The query prefix */
5132 strcpy (buf
, "qRcmd,");
5133 p
= strchr (buf
, '\0');
5135 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > (rs
->remote_packet_size
))
5136 error ("\"monitor\" command ``%s'' is too long\n", command
);
5138 /* Encode the actual command */
5139 bin2hex (command
, p
, 0);
5141 if (putpkt (buf
) < 0)
5142 error ("Communication problem with target\n");
5144 /* get/display the response */
5147 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
5149 getpkt (buf
, (rs
->remote_packet_size
), 0);
5151 error ("Target does not support this command\n");
5152 if (buf
[0] == 'O' && buf
[1] != 'K')
5154 remote_console_output (buf
+ 1); /* 'O' message from stub */
5157 if (strcmp (buf
, "OK") == 0)
5159 if (strlen (buf
) == 3 && buf
[0] == 'E'
5160 && isdigit (buf
[1]) && isdigit (buf
[2]))
5162 error ("Protocol error with Rcmd");
5164 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5166 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5167 fputc_unfiltered (c
, outbuf
);
5174 packet_command (char *args
, int from_tty
)
5176 struct remote_state
*rs
= get_remote_state ();
5177 char *buf
= alloca (rs
->remote_packet_size
);
5180 error ("command can only be used with remote target");
5183 error ("remote-packet command requires packet text as argument");
5185 puts_filtered ("sending: ");
5186 print_packet (args
);
5187 puts_filtered ("\n");
5190 getpkt (buf
, (rs
->remote_packet_size
), 0);
5191 puts_filtered ("received: ");
5193 puts_filtered ("\n");
5197 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
5199 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5201 static void threadset_test_cmd (char *cmd
, int tty
);
5203 static void threadalive_test (char *cmd
, int tty
);
5205 static void threadlist_test_cmd (char *cmd
, int tty
);
5207 int get_and_display_threadinfo (threadref
* ref
);
5209 static void threadinfo_test_cmd (char *cmd
, int tty
);
5211 static int thread_display_step (threadref
* ref
, void *context
);
5213 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5215 static void init_remote_threadtests (void);
5217 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
5220 threadset_test_cmd (char *cmd
, int tty
)
5222 int sample_thread
= SAMPLE_THREAD
;
5224 printf_filtered ("Remote threadset test\n");
5225 set_thread (sample_thread
, 1);
5230 threadalive_test (char *cmd
, int tty
)
5232 int sample_thread
= SAMPLE_THREAD
;
5234 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5235 printf_filtered ("PASS: Thread alive test\n");
5237 printf_filtered ("FAIL: Thread alive test\n");
5240 void output_threadid (char *title
, threadref
* ref
);
5243 output_threadid (char *title
, threadref
*ref
)
5247 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
5249 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5253 threadlist_test_cmd (char *cmd
, int tty
)
5256 threadref nextthread
;
5257 int done
, result_count
;
5258 threadref threadlist
[3];
5260 printf_filtered ("Remote Threadlist test\n");
5261 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5262 &result_count
, &threadlist
[0]))
5263 printf_filtered ("FAIL: threadlist test\n");
5266 threadref
*scan
= threadlist
;
5267 threadref
*limit
= scan
+ result_count
;
5269 while (scan
< limit
)
5270 output_threadid (" thread ", scan
++);
5275 display_thread_info (struct gdb_ext_thread_info
*info
)
5277 output_threadid ("Threadid: ", &info
->threadid
);
5278 printf_filtered ("Name: %s\n ", info
->shortname
);
5279 printf_filtered ("State: %s\n", info
->display
);
5280 printf_filtered ("other: %s\n\n", info
->more_display
);
5284 get_and_display_threadinfo (threadref
*ref
)
5288 struct gdb_ext_thread_info threadinfo
;
5290 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5291 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5292 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5293 display_thread_info (&threadinfo
);
5298 threadinfo_test_cmd (char *cmd
, int tty
)
5300 int athread
= SAMPLE_THREAD
;
5304 int_to_threadref (&thread
, athread
);
5305 printf_filtered ("Remote Threadinfo test\n");
5306 if (!get_and_display_threadinfo (&thread
))
5307 printf_filtered ("FAIL cannot get thread info\n");
5311 thread_display_step (threadref
*ref
, void *context
)
5313 /* output_threadid(" threadstep ",ref); *//* simple test */
5314 return get_and_display_threadinfo (ref
);
5318 threadlist_update_test_cmd (char *cmd
, int tty
)
5320 printf_filtered ("Remote Threadlist update test\n");
5321 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5325 init_remote_threadtests (void)
5327 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
5328 "Fetch and print the remote list of thread identifiers, one pkt only");
5329 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5330 "Fetch and display info about one thread");
5331 add_com ("tset", class_obscure
, threadset_test_cmd
,
5332 "Test setting to a different thread");
5333 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5334 "Iterate through updating all remote thread info");
5335 add_com ("talive", class_obscure
, threadalive_test
,
5336 " Remote thread alive test ");
5341 /* Convert a thread ID to a string. Returns the string in a static
5345 remote_pid_to_str (ptid_t ptid
)
5347 static char buf
[30];
5349 sprintf (buf
, "Thread %d", PIDGET (ptid
));
5354 init_remote_ops (void)
5356 remote_ops
.to_shortname
= "remote";
5357 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5359 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5360 Specify the serial device it is connected to\n\
5361 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5362 remote_ops
.to_open
= remote_open
;
5363 remote_ops
.to_close
= remote_close
;
5364 remote_ops
.to_detach
= remote_detach
;
5365 remote_ops
.to_resume
= remote_resume
;
5366 remote_ops
.to_wait
= remote_wait
;
5367 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5368 remote_ops
.to_store_registers
= remote_store_registers
;
5369 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5370 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
5371 remote_ops
.to_files_info
= remote_files_info
;
5372 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5373 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5374 remote_ops
.to_kill
= remote_kill
;
5375 remote_ops
.to_load
= generic_load
;
5376 remote_ops
.to_mourn_inferior
= remote_mourn
;
5377 remote_ops
.to_thread_alive
= remote_thread_alive
;
5378 remote_ops
.to_find_new_threads
= remote_threads_info
;
5379 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5380 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5381 remote_ops
.to_stop
= remote_stop
;
5382 remote_ops
.to_query
= remote_query
;
5383 remote_ops
.to_rcmd
= remote_rcmd
;
5384 remote_ops
.to_stratum
= process_stratum
;
5385 remote_ops
.to_has_all_memory
= 1;
5386 remote_ops
.to_has_memory
= 1;
5387 remote_ops
.to_has_stack
= 1;
5388 remote_ops
.to_has_registers
= 1;
5389 remote_ops
.to_has_execution
= 1;
5390 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5391 remote_ops
.to_magic
= OPS_MAGIC
;
5394 /* Set up the extended remote vector by making a copy of the standard
5395 remote vector and adding to it. */
5398 init_extended_remote_ops (void)
5400 extended_remote_ops
= remote_ops
;
5402 extended_remote_ops
.to_shortname
= "extended-remote";
5403 extended_remote_ops
.to_longname
=
5404 "Extended remote serial target in gdb-specific protocol";
5405 extended_remote_ops
.to_doc
=
5406 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5407 Specify the serial device it is connected to (e.g. /dev/ttya).",
5408 extended_remote_ops
.to_open
= extended_remote_open
;
5409 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5410 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5414 * Command: info remote-process
5416 * This implements Cisco's version of the "info proc" command.
5418 * This query allows the target stub to return an arbitrary string
5419 * (or strings) giving arbitrary information about the target process.
5420 * This is optional; the target stub isn't required to implement it.
5422 * Syntax: qfProcessInfo request first string
5423 * qsProcessInfo request subsequent string
5424 * reply: 'O'<hex-encoded-string>
5425 * 'l' last reply (empty)
5429 remote_info_process (char *args
, int from_tty
)
5431 struct remote_state
*rs
= get_remote_state ();
5432 char *buf
= alloca (rs
->remote_packet_size
);
5434 if (remote_desc
== 0)
5435 error ("Command can only be used when connected to the remote target.");
5437 putpkt ("qfProcessInfo");
5438 getpkt (buf
, (rs
->remote_packet_size
), 0);
5440 return; /* Silently: target does not support this feature. */
5443 error ("info proc: target error.");
5445 while (buf
[0] == 'O') /* Capitol-O packet */
5447 remote_console_output (&buf
[1]);
5448 putpkt ("qsProcessInfo");
5449 getpkt (buf
, (rs
->remote_packet_size
), 0);
5458 remote_cisco_open (char *name
, int from_tty
)
5461 error ("To open a remote debug connection, you need to specify what \n"
5462 "device is attached to the remote system (e.g. host:port).");
5464 /* See FIXME above */
5465 wait_forever_enabled_p
= 1;
5467 target_preopen (from_tty
);
5469 unpush_target (&remote_cisco_ops
);
5471 remote_desc
= serial_open (name
);
5473 perror_with_name (name
);
5476 * If a baud rate was specified on the gdb command line it will
5477 * be greater than the initial value of -1. If it is, use it otherwise
5481 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
5482 if (serial_setbaudrate (remote_desc
, baud_rate
))
5484 serial_close (remote_desc
);
5485 perror_with_name (name
);
5488 serial_raw (remote_desc
);
5490 /* If there is something sitting in the buffer we might take it as a
5491 response to a command, which would be bad. */
5492 serial_flush_input (remote_desc
);
5496 puts_filtered ("Remote debugging using ");
5497 puts_filtered (name
);
5498 puts_filtered ("\n");
5501 remote_cisco_mode
= 1;
5503 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
5505 init_all_packet_configs ();
5507 general_thread
= -2;
5508 continue_thread
= -2;
5510 /* Probe for ability to use "ThreadInfo" query, as required. */
5511 use_threadinfo_query
= 1;
5512 use_threadextra_query
= 1;
5514 /* Without this, some commands which require an active target (such
5515 as kill) won't work. This variable serves (at least) double duty
5516 as both the pid of the target process (if it has such), and as a
5517 flag indicating that a target is active. These functions should
5518 be split out into seperate variables, especially since GDB will
5519 someday have a notion of debugging several processes. */
5520 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
5522 /* Start the remote connection; if error (0), discard this target. */
5524 if (!catch_errors (remote_start_remote_dummy
, (char *) 0,
5525 "Couldn't establish connection to remote target\n",
5534 remote_cisco_close (int quitting
)
5536 remote_cisco_mode
= 0;
5537 remote_close (quitting
);
5541 remote_cisco_mourn (void)
5543 remote_mourn_1 (&remote_cisco_ops
);
5555 /* Shared between readsocket() and readtty(). The size is arbitrary,
5556 however all targets are known to support a 400 character packet. */
5557 static char tty_input
[400];
5559 static int escape_count
;
5560 static int echo_check
;
5561 extern int quit_flag
;
5568 /* Loop until the socket doesn't have any more data */
5570 while ((data
= readchar (0)) >= 0)
5572 /* Check for the escape sequence */
5575 /* If this is the fourth escape, get out */
5576 if (++escape_count
== 4)
5581 { /* This is a '|', but not the fourth in a row.
5582 Continue without echoing it. If it isn't actually
5583 one of four in a row, it'll be echoed later. */
5590 /* Ensure any pending '|'s are flushed. */
5592 for (; escape_count
> 0; escape_count
--)
5596 if (data
== '\r') /* If this is a return character, */
5597 continue; /* - just supress it. */
5599 if (echo_check
!= -1) /* Check for echo of user input. */
5601 if (tty_input
[echo_check
] == data
)
5603 gdb_assert (echo_check
<= sizeof (tty_input
));
5604 echo_check
++; /* Character matched user input: */
5605 continue; /* Continue without echoing it. */
5607 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5608 { /* End of the line (and of echo checking). */
5609 echo_check
= -1; /* No more echo supression */
5610 continue; /* Continue without echoing. */
5613 { /* Failed check for echo of user input.
5614 We now have some suppressed output to flush! */
5617 for (j
= 0; j
< echo_check
; j
++)
5618 putchar (tty_input
[j
]);
5622 putchar (data
); /* Default case: output the char. */
5625 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5626 return READ_MORE
; /* Try to read some more */
5628 return FATAL_ERROR
; /* Trouble, bail out */
5636 /* First, read a buffer full from the terminal */
5637 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5638 if (tty_bytecount
== -1)
5640 perror ("readtty: read failed");
5644 /* Remove a quoted newline. */
5645 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5646 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5648 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5649 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5652 /* Turn trailing newlines into returns */
5653 if (tty_input
[tty_bytecount
- 1] == '\n')
5654 tty_input
[tty_bytecount
- 1] = '\r';
5656 /* If the line consists of a ~, enter debugging mode. */
5657 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5660 /* Make this a zero terminated string and write it out */
5661 tty_input
[tty_bytecount
] = 0;
5662 if (serial_write (remote_desc
, tty_input
, tty_bytecount
))
5664 perror_with_name ("readtty: write failed");
5674 fd_set input
; /* file descriptors for select */
5675 int tablesize
; /* max number of FDs for select */
5679 extern int escape_count
; /* global shared by readsocket */
5680 extern int echo_check
; /* ditto */
5685 tablesize
= 8 * sizeof (input
);
5689 /* Check for anything from our socket - doesn't block. Note that
5690 this must be done *before* the select as there may be
5691 buffered I/O waiting to be processed. */
5693 if ((status
= readsocket ()) == FATAL_ERROR
)
5695 error ("Debugging terminated by communications error");
5697 else if (status
!= READ_MORE
)
5702 fflush (stdout
); /* Flush output before blocking */
5704 /* Now block on more socket input or TTY input */
5707 FD_SET (fileno (stdin
), &input
);
5708 FD_SET (deprecated_serial_fd (remote_desc
), &input
);
5710 status
= select (tablesize
, &input
, 0, 0, 0);
5711 if ((status
== -1) && (errno
!= EINTR
))
5713 error ("Communications error on select %d", errno
);
5716 /* Handle Control-C typed */
5720 if ((++quit_count
) == 2)
5722 if (query ("Interrupt GDB? "))
5724 printf_filtered ("Interrupted by user.\n");
5725 return_to_top_level (RETURN_QUIT
);
5732 serial_send_break (remote_desc
);
5734 serial_write (remote_desc
, "\003", 1);
5739 /* Handle console input */
5741 if (FD_ISSET (fileno (stdin
), &input
))
5745 status
= readtty ();
5746 if (status
== READ_MORE
)
5749 return status
; /* telnet session ended */
5755 remote_cisco_wait (ptid_t ptid
, struct target_waitstatus
*status
)
5757 if (minitelnet () != ENTER_DEBUG
)
5759 error ("Debugging session terminated by protocol error");
5762 return remote_wait (ptid
, status
);
5766 init_remote_cisco_ops (void)
5768 remote_cisco_ops
.to_shortname
= "cisco";
5769 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5770 remote_cisco_ops
.to_doc
=
5771 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5772 Specify the serial device it is connected to (e.g. host:2020).";
5773 remote_cisco_ops
.to_open
= remote_cisco_open
;
5774 remote_cisco_ops
.to_close
= remote_cisco_close
;
5775 remote_cisco_ops
.to_detach
= remote_detach
;
5776 remote_cisco_ops
.to_resume
= remote_resume
;
5777 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5778 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5779 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5780 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5781 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5782 remote_cisco_ops
.to_files_info
= remote_files_info
;
5783 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5784 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5785 remote_cisco_ops
.to_kill
= remote_kill
;
5786 remote_cisco_ops
.to_load
= generic_load
;
5787 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5788 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5789 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5790 remote_cisco_ops
.to_pid_to_str
= remote_pid_to_str
;
5791 remote_cisco_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5792 remote_cisco_ops
.to_stratum
= process_stratum
;
5793 remote_cisco_ops
.to_has_all_memory
= 1;
5794 remote_cisco_ops
.to_has_memory
= 1;
5795 remote_cisco_ops
.to_has_stack
= 1;
5796 remote_cisco_ops
.to_has_registers
= 1;
5797 remote_cisco_ops
.to_has_execution
= 1;
5798 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5802 remote_can_async_p (void)
5804 /* We're async whenever the serial device is. */
5805 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5809 remote_is_async_p (void)
5811 /* We're async whenever the serial device is. */
5812 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5815 /* Pass the SERIAL event on and up to the client. One day this code
5816 will be able to delay notifying the client of an event until the
5817 point where an entire packet has been received. */
5819 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5820 static void *async_client_context
;
5821 static serial_event_ftype remote_async_serial_handler
;
5824 remote_async_serial_handler (struct serial
*scb
, void *context
)
5826 /* Don't propogate error information up to the client. Instead let
5827 the client find out about the error by querying the target. */
5828 async_client_callback (INF_REG_EVENT
, async_client_context
);
5832 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5834 if (current_target
.to_async_mask_value
== 0)
5835 internal_error (__FILE__
, __LINE__
,
5836 "Calling remote_async when async is masked");
5838 if (callback
!= NULL
)
5840 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5841 async_client_callback
= callback
;
5842 async_client_context
= context
;
5845 serial_async (remote_desc
, NULL
, NULL
);
5848 /* Target async and target extended-async.
5850 This are temporary targets, until it is all tested. Eventually
5851 async support will be incorporated int the usual 'remote'
5855 init_remote_async_ops (void)
5857 remote_async_ops
.to_shortname
= "async";
5858 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5859 remote_async_ops
.to_doc
=
5860 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5861 Specify the serial device it is connected to (e.g. /dev/ttya).";
5862 remote_async_ops
.to_open
= remote_async_open
;
5863 remote_async_ops
.to_close
= remote_close
;
5864 remote_async_ops
.to_detach
= remote_async_detach
;
5865 remote_async_ops
.to_resume
= remote_async_resume
;
5866 remote_async_ops
.to_wait
= remote_async_wait
;
5867 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5868 remote_async_ops
.to_store_registers
= remote_store_registers
;
5869 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5870 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5871 remote_async_ops
.to_files_info
= remote_files_info
;
5872 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5873 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5874 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5875 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5876 remote_async_ops
.to_kill
= remote_async_kill
;
5877 remote_async_ops
.to_load
= generic_load
;
5878 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5879 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5880 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5881 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
5882 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5883 remote_async_ops
.to_stop
= remote_stop
;
5884 remote_async_ops
.to_query
= remote_query
;
5885 remote_async_ops
.to_rcmd
= remote_rcmd
;
5886 remote_async_ops
.to_stratum
= process_stratum
;
5887 remote_async_ops
.to_has_all_memory
= 1;
5888 remote_async_ops
.to_has_memory
= 1;
5889 remote_async_ops
.to_has_stack
= 1;
5890 remote_async_ops
.to_has_registers
= 1;
5891 remote_async_ops
.to_has_execution
= 1;
5892 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5893 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5894 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5895 remote_async_ops
.to_async
= remote_async
;
5896 remote_async_ops
.to_async_mask_value
= 1;
5897 remote_async_ops
.to_magic
= OPS_MAGIC
;
5900 /* Set up the async extended remote vector by making a copy of the standard
5901 remote vector and adding to it. */
5904 init_extended_async_remote_ops (void)
5906 extended_async_remote_ops
= remote_async_ops
;
5908 extended_async_remote_ops
.to_shortname
= "extended-async";
5909 extended_async_remote_ops
.to_longname
=
5910 "Extended remote serial target in async gdb-specific protocol";
5911 extended_async_remote_ops
.to_doc
=
5912 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5913 Specify the serial device it is connected to (e.g. /dev/ttya).",
5914 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5915 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5916 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5920 set_remote_cmd (char *args
, int from_tty
)
5925 show_remote_cmd (char *args
, int from_tty
)
5928 show_remote_protocol_Z_packet_cmd (args
, from_tty
);
5929 show_remote_protocol_e_packet_cmd (args
, from_tty
);
5930 show_remote_protocol_E_packet_cmd (args
, from_tty
);
5931 show_remote_protocol_P_packet_cmd (args
, from_tty
);
5932 show_remote_protocol_qSymbol_packet_cmd (args
, from_tty
);
5933 show_remote_protocol_binary_download_cmd (args
, from_tty
);
5937 build_remote_gdbarch_data (void)
5939 remote_address_size
= TARGET_ADDR_BIT
;
5942 /* Saved pointer to previous owner of the new_objfile event. */
5943 static void (*remote_new_objfile_chain
) (struct objfile
*);
5945 /* Function to be called whenever a new objfile (shlib) is detected. */
5947 remote_new_objfile (struct objfile
*objfile
)
5949 if (remote_desc
!= 0) /* Have a remote connection */
5951 remote_check_symbols (objfile
);
5953 /* Call predecessor on chain, if any. */
5954 if (remote_new_objfile_chain
!= 0 &&
5956 remote_new_objfile_chain (objfile
);
5960 _initialize_remote (void)
5962 static struct cmd_list_element
*remote_set_cmdlist
;
5963 static struct cmd_list_element
*remote_show_cmdlist
;
5964 struct cmd_list_element
*tmpcmd
;
5966 /* architecture specific data */
5967 remote_gdbarch_data_handle
= register_gdbarch_data (init_remote_state
,
5970 /* Old tacky stuff. NOTE: This comes after the remote protocol so
5971 that the remote protocol has been initialized. */
5972 register_gdbarch_swap (&remote_address_size
,
5973 sizeof (&remote_address_size
), NULL
);
5974 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5977 add_target (&remote_ops
);
5979 init_extended_remote_ops ();
5980 add_target (&extended_remote_ops
);
5982 init_remote_async_ops ();
5983 add_target (&remote_async_ops
);
5985 init_extended_async_remote_ops ();
5986 add_target (&extended_async_remote_ops
);
5988 init_remote_cisco_ops ();
5989 add_target (&remote_cisco_ops
);
5991 /* Hook into new objfile notification. */
5992 remote_new_objfile_chain
= target_new_objfile_hook
;
5993 target_new_objfile_hook
= remote_new_objfile
;
5996 init_remote_threadtests ();
5999 /* set/show remote ... */
6001 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
6002 Remote protocol specific variables\n\
6003 Configure various remote-protocol specific variables such as\n\
6004 the packets being used",
6005 &remote_set_cmdlist
, "set remote ",
6006 0/*allow-unknown*/, &setlist
);
6007 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, "\
6008 Remote protocol specific variables\n\
6009 Configure various remote-protocol specific variables such as\n\
6010 the packets being used",
6011 &remote_show_cmdlist
, "show remote ",
6012 0/*allow-unknown*/, &showlist
);
6014 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
6015 "Compare section data on target to the exec file.\n\
6016 Argument is a single section name (default: all loaded sections).",
6019 add_cmd ("packet", class_maintenance
, packet_command
,
6020 "Send an arbitrary packet to a remote target.\n\
6021 maintenance packet TEXT\n\
6022 If GDB is talking to an inferior via the GDB serial protocol, then\n\
6023 this command sends the string TEXT to the inferior, and displays the\n\
6024 response packet. GDB supplies the initial `$' character, and the\n\
6025 terminating `#' character and checksum.",
6029 (add_set_boolean_cmd ("remotebreak", no_class
, &remote_break
,
6030 "Set whether to send break if interrupted.\n",
6034 /* Install commands for configuring memory read/write packets. */
6036 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
6037 "Set the maximum number of bytes per memory write packet (deprecated).\n",
6039 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
,
6040 "Show the maximum number of bytes per memory write packet (deprecated).\n",
6042 add_cmd ("memory-write-packet-size", no_class
,
6043 set_memory_write_packet_size
,
6044 "Set the maximum number of bytes per memory-write packet.\n"
6045 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6046 "default packet size. The actual limit is further reduced\n"
6047 "dependent on the target. Specify ``fixed'' to disable the\n"
6048 "further restriction and ``limit'' to enable that restriction\n",
6049 &remote_set_cmdlist
);
6050 add_cmd ("memory-read-packet-size", no_class
,
6051 set_memory_read_packet_size
,
6052 "Set the maximum number of bytes per memory-read packet.\n"
6053 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6054 "default packet size. The actual limit is further reduced\n"
6055 "dependent on the target. Specify ``fixed'' to disable the\n"
6056 "further restriction and ``limit'' to enable that restriction\n",
6057 &remote_set_cmdlist
);
6058 add_cmd ("memory-write-packet-size", no_class
,
6059 show_memory_write_packet_size
,
6060 "Show the maximum number of bytes per memory-write packet.\n",
6061 &remote_show_cmdlist
);
6062 add_cmd ("memory-read-packet-size", no_class
,
6063 show_memory_read_packet_size
,
6064 "Show the maximum number of bytes per memory-read packet.\n",
6065 &remote_show_cmdlist
);
6068 (add_set_cmd ("remoteaddresssize", class_obscure
,
6069 var_integer
, (char *) &remote_address_size
,
6070 "Set the maximum size of the address (in bits) \
6071 in a memory packet.\n",
6075 add_packet_config_cmd (&remote_protocol_binary_download
,
6076 "X", "binary-download",
6077 set_remote_protocol_binary_download_cmd
,
6078 show_remote_protocol_binary_download_cmd
,
6079 &remote_set_cmdlist
, &remote_show_cmdlist
,
6082 /* XXXX - should ``set remotebinarydownload'' be retained for
6085 (add_set_cmd ("remotebinarydownload", no_class
,
6086 var_boolean
, (char *) &remote_binary_download
,
6087 "Set binary downloads.\n", &setlist
),
6091 add_info ("remote-process", remote_info_process
,
6092 "Query the remote system for process info.");
6094 add_packet_config_cmd (&remote_protocol_qSymbol
,
6095 "qSymbol", "symbol-lookup",
6096 set_remote_protocol_qSymbol_packet_cmd
,
6097 show_remote_protocol_qSymbol_packet_cmd
,
6098 &remote_set_cmdlist
, &remote_show_cmdlist
,
6101 add_packet_config_cmd (&remote_protocol_e
,
6102 "e", "step-over-range",
6103 set_remote_protocol_e_packet_cmd
,
6104 show_remote_protocol_e_packet_cmd
,
6105 &remote_set_cmdlist
, &remote_show_cmdlist
,
6108 add_packet_config_cmd (&remote_protocol_E
,
6109 "E", "step-over-range-w-signal",
6110 set_remote_protocol_E_packet_cmd
,
6111 show_remote_protocol_E_packet_cmd
,
6112 &remote_set_cmdlist
, &remote_show_cmdlist
,
6115 add_packet_config_cmd (&remote_protocol_P
,
6116 "P", "set-register",
6117 set_remote_protocol_P_packet_cmd
,
6118 show_remote_protocol_P_packet_cmd
,
6119 &remote_set_cmdlist
, &remote_show_cmdlist
,
6122 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
6123 "Z0", "software-breakpoint",
6124 set_remote_protocol_Z_software_bp_packet_cmd
,
6125 show_remote_protocol_Z_software_bp_packet_cmd
,
6126 &remote_set_cmdlist
, &remote_show_cmdlist
,
6129 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
6130 "Z1", "hardware-breakpoint",
6131 set_remote_protocol_Z_hardware_bp_packet_cmd
,
6132 show_remote_protocol_Z_hardware_bp_packet_cmd
,
6133 &remote_set_cmdlist
, &remote_show_cmdlist
,
6136 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
6137 "Z2", "write-watchpoint",
6138 set_remote_protocol_Z_write_wp_packet_cmd
,
6139 show_remote_protocol_Z_write_wp_packet_cmd
,
6140 &remote_set_cmdlist
, &remote_show_cmdlist
,
6143 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
6144 "Z3", "read-watchpoint",
6145 set_remote_protocol_Z_read_wp_packet_cmd
,
6146 show_remote_protocol_Z_read_wp_packet_cmd
,
6147 &remote_set_cmdlist
, &remote_show_cmdlist
,
6150 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
6151 "Z4", "access-watchpoint",
6152 set_remote_protocol_Z_access_wp_packet_cmd
,
6153 show_remote_protocol_Z_access_wp_packet_cmd
,
6154 &remote_set_cmdlist
, &remote_show_cmdlist
,
6157 /* Keep the old ``set remote Z-packet ...'' working. */
6158 tmpcmd
= add_set_auto_boolean_cmd ("Z-packet", class_obscure
,
6159 &remote_Z_packet_detect
,
6161 Set use of remote protocol `Z' packets", &remote_set_cmdlist
);
6162 tmpcmd
->function
.sfunc
= set_remote_protocol_Z_packet_cmd
;
6163 add_cmd ("Z-packet", class_obscure
, show_remote_protocol_Z_packet_cmd
,
6164 "Show use of remote protocol `Z' packets ",
6165 &remote_show_cmdlist
);