1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* See the GDB User Guide for details of the GDB remote protocol. */
26 #include "gdb_string.h"
33 /*#include "terminal.h" */
36 #include "gdb-stabs.h"
37 #include "gdbthread.h"
41 #include "gdb_assert.h"
46 #include <sys/types.h>
49 #include "event-loop.h"
50 #include "event-top.h"
56 #include "gdbcore.h" /* for exec_bfd */
58 /* Prototypes for local functions */
59 static void cleanup_sigint_signal_handler (void *dummy
);
60 static void initialize_sigint_signal_handler (void);
61 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
63 static void handle_remote_sigint (int);
64 static void handle_remote_sigint_twice (int);
65 static void async_remote_interrupt (gdb_client_data
);
66 void async_remote_interrupt_twice (gdb_client_data
);
68 static void build_remote_gdbarch_data (void);
70 static int remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
72 static int remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
74 static void remote_files_info (struct target_ops
*ignore
);
76 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
77 int len
, int should_write
,
78 struct mem_attrib
*attrib
,
79 struct target_ops
*target
);
81 static void remote_prepare_to_store (void);
83 static void remote_fetch_registers (int regno
);
85 static void remote_resume (ptid_t ptid
, int step
,
86 enum target_signal siggnal
);
87 static void remote_async_resume (ptid_t ptid
, int step
,
88 enum target_signal siggnal
);
89 static int remote_start_remote (struct ui_out
*uiout
, void *dummy
);
91 static void remote_open (char *name
, int from_tty
);
92 static void remote_async_open (char *name
, int from_tty
);
94 static void extended_remote_open (char *name
, int from_tty
);
95 static void extended_remote_async_open (char *name
, int from_tty
);
97 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
98 static void remote_async_open_1 (char *, int, struct target_ops
*,
101 static void remote_close (int quitting
);
103 static void remote_store_registers (int regno
);
105 static void remote_mourn (void);
106 static void remote_async_mourn (void);
108 static void extended_remote_restart (void);
110 static void extended_remote_mourn (void);
112 static void extended_remote_create_inferior (char *, char *, char **);
113 static void extended_remote_async_create_inferior (char *, char *, char **);
115 static void remote_mourn_1 (struct target_ops
*);
117 static void remote_send (char *buf
, long sizeof_buf
);
119 static int readchar (int timeout
);
121 static ptid_t
remote_wait (ptid_t ptid
,
122 struct target_waitstatus
*status
);
123 static ptid_t
remote_async_wait (ptid_t ptid
,
124 struct target_waitstatus
*status
);
126 static void remote_kill (void);
127 static void remote_async_kill (void);
129 static int tohex (int nib
);
131 static void remote_detach (char *args
, int from_tty
);
132 static void remote_async_detach (char *args
, int from_tty
);
134 static void remote_interrupt (int signo
);
136 static void remote_interrupt_twice (int signo
);
138 static void interrupt_query (void);
140 static void set_thread (int, int);
142 static int remote_thread_alive (ptid_t
);
144 static void get_offsets (void);
146 static long read_frame (char *buf
, long sizeof_buf
);
148 static int remote_insert_breakpoint (CORE_ADDR
, char *);
150 static int remote_remove_breakpoint (CORE_ADDR
, char *);
152 static int hexnumlen (ULONGEST num
);
154 static void init_remote_ops (void);
156 static void init_extended_remote_ops (void);
158 static void init_remote_cisco_ops (void);
160 static struct target_ops remote_cisco_ops
;
162 static void remote_stop (void);
164 static int ishex (int ch
, int *val
);
166 static int stubhex (int ch
);
168 static int remote_query (int /*char */ , char *, char *, int *);
170 static int hexnumstr (char *, ULONGEST
);
172 static int hexnumnstr (char *, ULONGEST
, int);
174 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
176 static void print_packet (char *);
178 static unsigned long crc32 (unsigned char *, int, unsigned int);
180 static void compare_sections_command (char *, int);
182 static void packet_command (char *, int);
184 static int stub_unpack_int (char *buff
, int fieldlength
);
186 static ptid_t
remote_current_thread (ptid_t oldptid
);
188 static void remote_find_new_threads (void);
190 static void record_currthread (int currthread
);
192 static int fromhex (int a
);
194 static int hex2bin (const char *hex
, char *bin
, int count
);
196 static int bin2hex (const char *bin
, char *hex
, int count
);
198 static int putpkt_binary (char *buf
, int cnt
);
200 static void check_binary_download (CORE_ADDR addr
);
202 struct packet_config
;
204 static void show_packet_config_cmd (struct packet_config
*config
);
206 static void update_packet_config (struct packet_config
*config
);
208 /* Define the target subroutine names */
210 void open_remote_target (char *, int, struct target_ops
*, int);
212 void _initialize_remote (void);
214 /* Description of the remote protocol. Strictly speaking, when the
215 target is open()ed, remote.c should create a per-target description
216 of the remote protocol using that target's architecture.
217 Unfortunatly, the target stack doesn't include local state. For
218 the moment keep the information in the target's architecture
223 long offset
; /* Offset into G packet. */
224 long regnum
; /* GDB's internal register number. */
225 LONGEST pnum
; /* Remote protocol register number. */
226 int in_g_packet
; /* Always part of G packet. */
227 /* long size in bytes; == REGISTER_RAW_SIZE (regnum); at present. */
228 /* char *name; == REGISTER_NAME (regnum); at present. */
233 /* Description of the remote protocol registers. */
234 long sizeof_g_packet
;
236 /* Description of the remote protocol registers indexed by REGNUM
237 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
238 struct packet_reg
*regs
;
240 /* This is the size (in chars) of the first response to the ``g''
241 packet. It is used as a heuristic when determining the maximum
242 size of memory-read and memory-write packets. A target will
243 typically only reserve a buffer large enough to hold the ``g''
244 packet. The size does not include packet overhead (headers and
246 long actual_register_packet_size
;
248 /* This is the maximum size (in chars) of a non read/write packet.
249 It is also used as a cap on the size of read/write packets. */
250 long remote_packet_size
;
253 /* Handle for retreving the remote protocol data from gdbarch. */
254 static struct gdbarch_data
*remote_gdbarch_data_handle
;
256 static struct remote_state
*
259 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
263 init_remote_state (struct gdbarch
*gdbarch
)
266 struct remote_state
*rs
= xmalloc (sizeof (struct remote_state
));
268 /* Start out by having the remote protocol mimic the existing
269 behavour - just copy in the description of the register cache. */
270 rs
->sizeof_g_packet
= REGISTER_BYTES
; /* OK use. */
272 /* Assume a 1:1 regnum<->pnum table. */
273 rs
->regs
= xcalloc (NUM_REGS
+ NUM_PSEUDO_REGS
, sizeof (struct packet_reg
));
274 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
276 struct packet_reg
*r
= &rs
->regs
[regnum
];
279 r
->offset
= REGISTER_BYTE (regnum
);
280 r
->in_g_packet
= (regnum
< NUM_REGS
);
281 /* ...size = REGISTER_RAW_SIZE (regnum); */
282 /* ...name = REGISTER_NAME (regnum); */
285 /* Default maximum number of characters in a packet body. Many
286 remote stubs have a hardwired buffer size of 400 bytes
287 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
288 as the maximum packet-size to ensure that the packet and an extra
289 NUL character can always fit in the buffer. This stops GDB
290 trashing stubs that try to squeeze an extra NUL into what is
291 already a full buffer (As of 1999-12-04 that was most stubs. */
292 rs
->remote_packet_size
= 400 - 1;
294 /* Should rs->sizeof_g_packet needs more space than the
295 default, adjust the size accordingly. Remember that each byte is
296 encoded as two characters. 32 is the overhead for the packet
297 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
298 (``$NN:G...#NN'') is a better guess, the below has been padded a
300 if (rs
->sizeof_g_packet
> ((rs
->remote_packet_size
- 32) / 2))
301 rs
->remote_packet_size
= (rs
->sizeof_g_packet
* 2 + 32);
303 /* This one is filled in when a ``g'' packet is received. */
304 rs
->actual_register_packet_size
= 0;
310 free_remote_state (struct gdbarch
*gdbarch
, void *pointer
)
312 struct remote_state
*data
= pointer
;
317 static struct packet_reg
*
318 packet_reg_from_regnum (struct remote_state
*rs
, long regnum
)
320 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
324 struct packet_reg
*r
= &rs
->regs
[regnum
];
325 gdb_assert (r
->regnum
== regnum
);
330 static struct packet_reg
*
331 packet_reg_from_pnum (struct remote_state
*rs
, LONGEST pnum
)
334 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
336 struct packet_reg
*r
= &rs
->regs
[i
];
345 static struct target_ops remote_ops
;
347 static struct target_ops extended_remote_ops
;
349 /* Temporary target ops. Just like the remote_ops and
350 extended_remote_ops, but with asynchronous support. */
351 static struct target_ops remote_async_ops
;
353 static struct target_ops extended_async_remote_ops
;
355 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
356 ``forever'' still use the normal timeout mechanism. This is
357 currently used by the ASYNC code to guarentee that target reads
358 during the initial connect always time-out. Once getpkt has been
359 modified to return a timeout indication and, in turn
360 remote_wait()/wait_for_inferior() have gained a timeout parameter
362 static int wait_forever_enabled_p
= 1;
365 /* This variable chooses whether to send a ^C or a break when the user
366 requests program interruption. Although ^C is usually what remote
367 systems expect, and that is the default here, sometimes a break is
368 preferable instead. */
370 static int remote_break
;
372 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
373 remote_open knows that we don't have a file open when the program
375 static struct serial
*remote_desc
= NULL
;
377 /* This is set by the target (thru the 'S' message)
378 to denote that the target is in kernel mode. */
379 static int cisco_kernel_mode
= 0;
381 /* This variable sets the number of bits in an address that are to be
382 sent in a memory ("M" or "m") packet. Normally, after stripping
383 leading zeros, the entire address would be sent. This variable
384 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
385 initial implementation of remote.c restricted the address sent in
386 memory packets to ``host::sizeof long'' bytes - (typically 32
387 bits). Consequently, for 64 bit targets, the upper 32 bits of an
388 address was never sent. Since fixing this bug may cause a break in
389 some remote targets this variable is principly provided to
390 facilitate backward compatibility. */
392 static int remote_address_size
;
394 /* Tempoary to track who currently owns the terminal. See
395 target_async_terminal_* for more details. */
397 static int remote_async_terminal_ours_p
;
400 /* User configurable variables for the number of characters in a
401 memory read/write packet. MIN ((rs->remote_packet_size),
402 rs->sizeof_g_packet) is the default. Some targets need smaller
403 values (fifo overruns, et.al.) and some users need larger values
404 (speed up transfers). The variables ``preferred_*'' (the user
405 request), ``current_*'' (what was actually set) and ``forced_*''
406 (Positive - a soft limit, negative - a hard limit). */
408 struct memory_packet_config
415 /* Compute the current size of a read/write packet. Since this makes
416 use of ``actual_register_packet_size'' the computation is dynamic. */
419 get_memory_packet_size (struct memory_packet_config
*config
)
421 struct remote_state
*rs
= get_remote_state ();
422 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
423 law?) that some hosts don't cope very well with large alloca()
424 calls. Eventually the alloca() code will be replaced by calls to
425 xmalloc() and make_cleanups() allowing this restriction to either
426 be lifted or removed. */
427 #ifndef MAX_REMOTE_PACKET_SIZE
428 #define MAX_REMOTE_PACKET_SIZE 16384
430 /* NOTE: 16 is just chosen at random. */
431 #ifndef MIN_REMOTE_PACKET_SIZE
432 #define MIN_REMOTE_PACKET_SIZE 16
437 if (config
->size
<= 0)
438 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
440 what_they_get
= config
->size
;
444 what_they_get
= (rs
->remote_packet_size
);
445 /* Limit the packet to the size specified by the user. */
447 && what_they_get
> config
->size
)
448 what_they_get
= config
->size
;
449 /* Limit it to the size of the targets ``g'' response. */
450 if ((rs
->actual_register_packet_size
) > 0
451 && what_they_get
> (rs
->actual_register_packet_size
))
452 what_they_get
= (rs
->actual_register_packet_size
);
454 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
455 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
456 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
457 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
458 return what_they_get
;
461 /* Update the size of a read/write packet. If they user wants
462 something really big then do a sanity check. */
465 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
467 int fixed_p
= config
->fixed_p
;
468 long size
= config
->size
;
470 error ("Argument required (integer, `fixed' or `limited').");
471 else if (strcmp (args
, "hard") == 0
472 || strcmp (args
, "fixed") == 0)
474 else if (strcmp (args
, "soft") == 0
475 || strcmp (args
, "limit") == 0)
480 size
= strtoul (args
, &end
, 0);
482 error ("Invalid %s (bad syntax).", config
->name
);
484 /* Instead of explicitly capping the size of a packet to
485 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
486 instead allowed to set the size to something arbitrarily
488 if (size
> MAX_REMOTE_PACKET_SIZE
)
489 error ("Invalid %s (too large).", config
->name
);
493 if (fixed_p
&& !config
->fixed_p
)
495 if (! query ("The target may not be able to correctly handle a %s\n"
496 "of %ld bytes. Change the packet size? ",
498 error ("Packet size not changed.");
500 /* Update the config. */
501 config
->fixed_p
= fixed_p
;
506 show_memory_packet_size (struct memory_packet_config
*config
)
508 printf_filtered ("The %s is %ld. ", config
->name
, config
->size
);
510 printf_filtered ("Packets are fixed at %ld bytes.\n",
511 get_memory_packet_size (config
));
513 printf_filtered ("Packets are limited to %ld bytes.\n",
514 get_memory_packet_size (config
));
517 static struct memory_packet_config memory_write_packet_config
=
519 "memory-write-packet-size",
523 set_memory_write_packet_size (char *args
, int from_tty
)
525 set_memory_packet_size (args
, &memory_write_packet_config
);
529 show_memory_write_packet_size (char *args
, int from_tty
)
531 show_memory_packet_size (&memory_write_packet_config
);
535 get_memory_write_packet_size (void)
537 return get_memory_packet_size (&memory_write_packet_config
);
540 static struct memory_packet_config memory_read_packet_config
=
542 "memory-read-packet-size",
546 set_memory_read_packet_size (char *args
, int from_tty
)
548 set_memory_packet_size (args
, &memory_read_packet_config
);
552 show_memory_read_packet_size (char *args
, int from_tty
)
554 show_memory_packet_size (&memory_read_packet_config
);
558 get_memory_read_packet_size (void)
560 struct remote_state
*rs
= get_remote_state ();
561 long size
= get_memory_packet_size (&memory_read_packet_config
);
562 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
563 extra buffer size argument before the memory read size can be
564 increased beyond (rs->remote_packet_size). */
565 if (size
> (rs
->remote_packet_size
))
566 size
= (rs
->remote_packet_size
);
571 /* Generic configuration support for packets the stub optionally
572 supports. Allows the user to specify the use of the packet as well
573 as allowing GDB to auto-detect support in the remote stub. */
577 PACKET_SUPPORT_UNKNOWN
= 0,
586 enum cmd_auto_boolean detect
;
587 enum packet_support support
;
590 /* Analyze a packet's return value and update the packet config
601 update_packet_config (struct packet_config
*config
)
603 switch (config
->detect
)
605 case CMD_AUTO_BOOLEAN_TRUE
:
606 config
->support
= PACKET_ENABLE
;
608 case CMD_AUTO_BOOLEAN_FALSE
:
609 config
->support
= PACKET_DISABLE
;
611 case CMD_AUTO_BOOLEAN_AUTO
:
612 config
->support
= PACKET_SUPPORT_UNKNOWN
;
618 show_packet_config_cmd (struct packet_config
*config
)
620 char *support
= "internal-error";
621 switch (config
->support
)
627 support
= "disabled";
629 case PACKET_SUPPORT_UNKNOWN
:
633 switch (config
->detect
)
635 case CMD_AUTO_BOOLEAN_AUTO
:
636 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
637 config
->name
, config
->title
, support
);
639 case CMD_AUTO_BOOLEAN_TRUE
:
640 case CMD_AUTO_BOOLEAN_FALSE
:
641 printf_filtered ("Support for remote protocol `%s' (%s) packet is currently %s.\n",
642 config
->name
, config
->title
, support
);
648 add_packet_config_cmd (struct packet_config
*config
,
651 void (*set_func
) (char *args
, int from_tty
,
652 struct cmd_list_element
*
654 void (*show_func
) (char *name
,
656 struct cmd_list_element
**set_remote_list
,
657 struct cmd_list_element
**show_remote_list
,
660 struct cmd_list_element
*set_cmd
;
661 struct cmd_list_element
*show_cmd
;
666 config
->title
= title
;
667 config
->detect
= CMD_AUTO_BOOLEAN_AUTO
;
668 config
->support
= PACKET_SUPPORT_UNKNOWN
;
669 xasprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
671 xasprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
673 /* set/show TITLE-packet {auto,on,off} */
674 xasprintf (&cmd_name
, "%s-packet", title
);
675 set_cmd
= add_set_auto_boolean_cmd (cmd_name
, class_obscure
,
676 &config
->detect
, set_doc
,
678 set_cmd_sfunc (set_cmd
, set_func
);
679 show_cmd
= add_cmd (cmd_name
, class_obscure
, show_func
, show_doc
,
681 /* set/show remote NAME-packet {auto,on,off} -- legacy */
685 xasprintf (&legacy_name
, "%s-packet", name
);
686 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
688 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
693 static enum packet_result
694 packet_ok (const char *buf
, struct packet_config
*config
)
698 /* The stub recognized the packet request. Check that the
699 operation succeeded. */
700 switch (config
->support
)
702 case PACKET_SUPPORT_UNKNOWN
:
704 fprintf_unfiltered (gdb_stdlog
,
705 "Packet %s (%s) is supported\n",
706 config
->name
, config
->title
);
707 config
->support
= PACKET_ENABLE
;
710 internal_error (__FILE__
, __LINE__
,
711 "packet_ok: attempt to use a disabled packet");
716 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
717 /* "OK" - definitly OK. */
720 && isxdigit (buf
[1]) && isxdigit (buf
[2])
722 /* "Enn" - definitly an error. */
724 /* The packet may or may not be OK. Just assume it is */
729 /* The stub does not support the packet. */
730 switch (config
->support
)
733 if (config
->detect
== CMD_AUTO_BOOLEAN_AUTO
)
734 /* If the stub previously indicated that the packet was
735 supported then there is a protocol error.. */
736 error ("Protocol error: %s (%s) conflicting enabled responses.",
737 config
->name
, config
->title
);
739 /* The user set it wrong. */
740 error ("Enabled packet %s (%s) not recognized by stub",
741 config
->name
, config
->title
);
743 case PACKET_SUPPORT_UNKNOWN
:
745 fprintf_unfiltered (gdb_stdlog
,
746 "Packet %s (%s) is NOT supported\n",
747 config
->name
, config
->title
);
748 config
->support
= PACKET_DISABLE
;
753 return PACKET_UNKNOWN
;
757 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
758 static struct packet_config remote_protocol_qSymbol
;
761 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
762 struct cmd_list_element
*c
)
764 update_packet_config (&remote_protocol_qSymbol
);
768 show_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
)
770 show_packet_config_cmd (&remote_protocol_qSymbol
);
773 /* Should we try the 'e' (step over range) request? */
774 static struct packet_config remote_protocol_e
;
777 set_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
778 struct cmd_list_element
*c
)
780 update_packet_config (&remote_protocol_e
);
784 show_remote_protocol_e_packet_cmd (char *args
, int from_tty
)
786 show_packet_config_cmd (&remote_protocol_e
);
790 /* Should we try the 'E' (step over range / w signal #) request? */
791 static struct packet_config remote_protocol_E
;
794 set_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
795 struct cmd_list_element
*c
)
797 update_packet_config (&remote_protocol_E
);
801 show_remote_protocol_E_packet_cmd (char *args
, int from_tty
)
803 show_packet_config_cmd (&remote_protocol_E
);
807 /* Should we try the 'P' (set register) request? */
809 static struct packet_config remote_protocol_P
;
812 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
813 struct cmd_list_element
*c
)
815 update_packet_config (&remote_protocol_P
);
819 show_remote_protocol_P_packet_cmd (char *args
, int from_tty
)
821 show_packet_config_cmd (&remote_protocol_P
);
824 /* Should we try one of the 'Z' requests? */
828 Z_PACKET_SOFTWARE_BP
,
829 Z_PACKET_HARDWARE_BP
,
836 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
838 /* FIXME: Instead of having all these boiler plate functions, the
839 command callback should include a context argument. */
842 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
843 struct cmd_list_element
*c
)
845 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
849 show_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
)
851 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
855 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
856 struct cmd_list_element
*c
)
858 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
862 show_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
)
864 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
868 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
869 struct cmd_list_element
*c
)
871 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
875 show_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
)
877 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
881 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
882 struct cmd_list_element
*c
)
884 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
888 show_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
)
890 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
894 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
895 struct cmd_list_element
*c
)
897 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
901 show_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
)
903 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
906 /* For compatibility with older distributions. Provide a ``set remote
907 Z-packet ...'' command that updates all the Z packet types. */
909 static enum cmd_auto_boolean remote_Z_packet_detect
;
912 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
913 struct cmd_list_element
*c
)
916 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
918 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
919 update_packet_config (&remote_protocol_Z
[i
]);
924 show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
)
927 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
929 show_packet_config_cmd (&remote_protocol_Z
[i
]);
933 /* Should we try the 'X' (remote binary download) packet?
935 This variable (available to the user via "set remote X-packet")
936 dictates whether downloads are sent in binary (via the 'X' packet).
937 We assume that the stub can, and attempt to do it. This will be
938 cleared if the stub does not understand it. This switch is still
939 needed, though in cases when the packet is supported in the stub,
940 but the connection does not allow it (i.e., 7-bit serial connection
943 static struct packet_config remote_protocol_binary_download
;
945 /* Should we try the 'ThreadInfo' query packet?
947 This variable (NOT available to the user: auto-detect only!)
948 determines whether GDB will use the new, simpler "ThreadInfo"
949 query or the older, more complex syntax for thread queries.
950 This is an auto-detect variable (set to true at each connect,
951 and set to false when the target fails to recognize it). */
953 static int use_threadinfo_query
;
954 static int use_threadextra_query
;
957 set_remote_protocol_binary_download_cmd (char *args
,
959 struct cmd_list_element
*c
)
961 update_packet_config (&remote_protocol_binary_download
);
965 show_remote_protocol_binary_download_cmd (char *args
,
968 show_packet_config_cmd (&remote_protocol_binary_download
);
972 /* Tokens for use by the asynchronous signal handlers for SIGINT */
973 static void *sigint_remote_twice_token
;
974 static void *sigint_remote_token
;
976 /* These are pointers to hook functions that may be set in order to
977 modify resume/wait behavior for a particular architecture. */
979 void (*target_resume_hook
) (void);
980 void (*target_wait_loop_hook
) (void);
984 /* These are the threads which we last sent to the remote system.
985 -1 for all or -2 for not sent yet. */
986 static int general_thread
;
987 static int continue_thread
;
989 /* Call this function as a result of
990 1) A halt indication (T packet) containing a thread id
991 2) A direct query of currthread
992 3) Successful execution of set thread
996 record_currthread (int currthread
)
998 general_thread
= currthread
;
1000 /* If this is a new thread, add it to GDB's thread list.
1001 If we leave it up to WFI to do this, bad things will happen. */
1002 if (!in_thread_list (pid_to_ptid (currthread
)))
1004 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");
1011 #define MAGIC_NULL_PID 42000
1014 set_thread (int th
, int gen
)
1016 struct remote_state
*rs
= get_remote_state ();
1017 char *buf
= alloca (rs
->remote_packet_size
);
1018 int state
= gen
? general_thread
: continue_thread
;
1024 buf
[1] = gen
? 'g' : 'c';
1025 if (th
== MAGIC_NULL_PID
)
1031 sprintf (&buf
[2], "-%x", -th
);
1033 sprintf (&buf
[2], "%x", th
);
1035 getpkt (buf
, (rs
->remote_packet_size
), 0);
1037 general_thread
= th
;
1039 continue_thread
= th
;
1042 /* Return nonzero if the thread TH is still alive on the remote system. */
1045 remote_thread_alive (ptid_t ptid
)
1047 int tid
= PIDGET (ptid
);
1051 sprintf (buf
, "T-%08x", -tid
);
1053 sprintf (buf
, "T%08x", tid
);
1055 getpkt (buf
, sizeof (buf
), 0);
1056 return (buf
[0] == 'O' && buf
[1] == 'K');
1059 /* About these extended threadlist and threadinfo packets. They are
1060 variable length packets but, the fields within them are often fixed
1061 length. They are redundent enough to send over UDP as is the
1062 remote protocol in general. There is a matching unit test module
1065 #define OPAQUETHREADBYTES 8
1067 /* a 64 bit opaque identifier */
1068 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1070 /* WARNING: This threadref data structure comes from the remote O.S., libstub
1071 protocol encoding, and remote.c. it is not particularly changable */
1073 /* Right now, the internal structure is int. We want it to be bigger.
1077 typedef int gdb_threadref
; /* internal GDB thread reference */
1079 /* gdb_ext_thread_info is an internal GDB data structure which is
1080 equivalint to the reply of the remote threadinfo packet */
1082 struct gdb_ext_thread_info
1084 threadref threadid
; /* External form of thread reference */
1085 int active
; /* Has state interesting to GDB? , regs, stack */
1086 char display
[256]; /* Brief state display, name, blocked/syspended */
1087 char shortname
[32]; /* To be used to name threads */
1088 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
1091 /* The volume of remote transfers can be limited by submitting
1092 a mask containing bits specifying the desired information.
1093 Use a union of these values as the 'selection' parameter to
1094 get_thread_info. FIXME: Make these TAG names more thread specific.
1097 #define TAG_THREADID 1
1098 #define TAG_EXISTS 2
1099 #define TAG_DISPLAY 4
1100 #define TAG_THREADNAME 8
1101 #define TAG_MOREDISPLAY 16
1103 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
1105 char *unpack_varlen_hex (char *buff
, int *result
);
1107 static char *unpack_nibble (char *buf
, int *val
);
1109 static char *pack_nibble (char *buf
, int nibble
);
1111 static char *pack_hex_byte (char *pkt
, int /*unsigned char */ byte
);
1113 static char *unpack_byte (char *buf
, int *value
);
1115 static char *pack_int (char *buf
, int value
);
1117 static char *unpack_int (char *buf
, int *value
);
1119 static char *unpack_string (char *src
, char *dest
, int length
);
1121 static char *pack_threadid (char *pkt
, threadref
* id
);
1123 static char *unpack_threadid (char *inbuf
, threadref
* id
);
1125 void int_to_threadref (threadref
* id
, int value
);
1127 static int threadref_to_int (threadref
* ref
);
1129 static void copy_threadref (threadref
* dest
, threadref
* src
);
1131 static int threadmatch (threadref
* dest
, threadref
* src
);
1133 static char *pack_threadinfo_request (char *pkt
, int mode
, threadref
* id
);
1135 static int remote_unpack_thread_info_response (char *pkt
,
1136 threadref
* expectedref
,
1137 struct gdb_ext_thread_info
1141 static int remote_get_threadinfo (threadref
* threadid
, int fieldset
, /*TAG mask */
1142 struct gdb_ext_thread_info
*info
);
1144 static int adapt_remote_get_threadinfo (gdb_threadref
* ref
,
1146 struct gdb_ext_thread_info
*info
);
1148 static char *pack_threadlist_request (char *pkt
, int startflag
,
1150 threadref
* nextthread
);
1152 static int parse_threadlist_response (char *pkt
,
1154 threadref
* original_echo
,
1155 threadref
* resultlist
, int *doneflag
);
1157 static int remote_get_threadlist (int startflag
,
1158 threadref
* nextthread
,
1161 int *result_count
, threadref
* threadlist
);
1163 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
1165 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1166 void *context
, int looplimit
);
1168 static int remote_newthread_step (threadref
* ref
, void *context
);
1170 /* encode 64 bits in 16 chars of hex */
1172 static const char hexchars
[] = "0123456789abcdef";
1175 ishex (int ch
, int *val
)
1177 if ((ch
>= 'a') && (ch
<= 'f'))
1179 *val
= ch
- 'a' + 10;
1182 if ((ch
>= 'A') && (ch
<= 'F'))
1184 *val
= ch
- 'A' + 10;
1187 if ((ch
>= '0') && (ch
<= '9'))
1198 if (ch
>= 'a' && ch
<= 'f')
1199 return ch
- 'a' + 10;
1200 if (ch
>= '0' && ch
<= '9')
1202 if (ch
>= 'A' && ch
<= 'F')
1203 return ch
- 'A' + 10;
1208 stub_unpack_int (char *buff
, int fieldlength
)
1215 nibble
= stubhex (*buff
++);
1219 retval
= retval
<< 4;
1225 unpack_varlen_hex (char *buff
, /* packet to parse */
1231 while (ishex (*buff
, &nibble
))
1234 retval
= retval
<< 4;
1235 retval
|= nibble
& 0x0f;
1242 unpack_nibble (char *buf
, int *val
)
1244 ishex (*buf
++, val
);
1249 pack_nibble (char *buf
, int nibble
)
1251 *buf
++ = hexchars
[(nibble
& 0x0f)];
1256 pack_hex_byte (char *pkt
, int byte
)
1258 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1259 *pkt
++ = hexchars
[(byte
& 0xf)];
1264 unpack_byte (char *buf
, int *value
)
1266 *value
= stub_unpack_int (buf
, 2);
1271 pack_int (char *buf
, int value
)
1273 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1274 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1275 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1276 buf
= pack_hex_byte (buf
, (value
& 0xff));
1281 unpack_int (char *buf
, int *value
)
1283 *value
= stub_unpack_int (buf
, 8);
1287 #if 0 /* currently unused, uncomment when needed */
1288 static char *pack_string (char *pkt
, char *string
);
1291 pack_string (char *pkt
, char *string
)
1296 len
= strlen (string
);
1298 len
= 200; /* Bigger than most GDB packets, junk??? */
1299 pkt
= pack_hex_byte (pkt
, len
);
1303 if ((ch
== '\0') || (ch
== '#'))
1304 ch
= '*'; /* Protect encapsulation */
1309 #endif /* 0 (unused) */
1312 unpack_string (char *src
, char *dest
, int length
)
1321 pack_threadid (char *pkt
, threadref
*id
)
1324 unsigned char *altid
;
1326 altid
= (unsigned char *) id
;
1327 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1329 pkt
= pack_hex_byte (pkt
, *altid
++);
1335 unpack_threadid (char *inbuf
, threadref
*id
)
1338 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1341 altref
= (char *) id
;
1343 while (inbuf
< limit
)
1345 x
= stubhex (*inbuf
++);
1346 y
= stubhex (*inbuf
++);
1347 *altref
++ = (x
<< 4) | y
;
1352 /* Externally, threadrefs are 64 bits but internally, they are still
1353 ints. This is due to a mismatch of specifications. We would like
1354 to use 64bit thread references internally. This is an adapter
1358 int_to_threadref (threadref
*id
, int value
)
1360 unsigned char *scan
;
1362 scan
= (unsigned char *) id
;
1368 *scan
++ = (value
>> 24) & 0xff;
1369 *scan
++ = (value
>> 16) & 0xff;
1370 *scan
++ = (value
>> 8) & 0xff;
1371 *scan
++ = (value
& 0xff);
1375 threadref_to_int (threadref
*ref
)
1378 unsigned char *scan
;
1380 scan
= (char *) ref
;
1384 value
= (value
<< 8) | ((*scan
++) & 0xff);
1389 copy_threadref (threadref
*dest
, threadref
*src
)
1392 unsigned char *csrc
, *cdest
;
1394 csrc
= (unsigned char *) src
;
1395 cdest
= (unsigned char *) dest
;
1402 threadmatch (threadref
*dest
, threadref
*src
)
1404 /* things are broken right now, so just assume we got a match */
1406 unsigned char *srcp
, *destp
;
1408 srcp
= (char *) src
;
1409 destp
= (char *) dest
;
1413 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1420 threadid:1, # always request threadid
1427 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1430 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1432 *pkt
++ = 'q'; /* Info Query */
1433 *pkt
++ = 'P'; /* process or thread info */
1434 pkt
= pack_int (pkt
, mode
); /* mode */
1435 pkt
= pack_threadid (pkt
, id
); /* threadid */
1436 *pkt
= '\0'; /* terminate */
1440 /* These values tag the fields in a thread info response packet */
1441 /* Tagging the fields allows us to request specific fields and to
1442 add more fields as time goes by */
1444 #define TAG_THREADID 1 /* Echo the thread identifier */
1445 #define TAG_EXISTS 2 /* Is this process defined enough to
1446 fetch registers and its stack */
1447 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1448 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1449 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1453 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1454 struct gdb_ext_thread_info
*info
)
1456 struct remote_state
*rs
= get_remote_state ();
1460 char *limit
= pkt
+ (rs
->remote_packet_size
); /* plausable parsing limit */
1463 /* info->threadid = 0; FIXME: implement zero_threadref */
1465 info
->display
[0] = '\0';
1466 info
->shortname
[0] = '\0';
1467 info
->more_display
[0] = '\0';
1469 /* Assume the characters indicating the packet type have been stripped */
1470 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1471 pkt
= unpack_threadid (pkt
, &ref
);
1474 warning ("Incomplete response to threadinfo request\n");
1475 if (!threadmatch (&ref
, expectedref
))
1476 { /* This is an answer to a different request */
1477 warning ("ERROR RMT Thread info mismatch\n");
1480 copy_threadref (&info
->threadid
, &ref
);
1482 /* Loop on tagged fields , try to bail if somthing goes wrong */
1484 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1486 pkt
= unpack_int (pkt
, &tag
); /* tag */
1487 pkt
= unpack_byte (pkt
, &length
); /* length */
1488 if (!(tag
& mask
)) /* tags out of synch with mask */
1490 warning ("ERROR RMT: threadinfo tag mismatch\n");
1494 if (tag
== TAG_THREADID
)
1498 warning ("ERROR RMT: length of threadid is not 16\n");
1502 pkt
= unpack_threadid (pkt
, &ref
);
1503 mask
= mask
& ~TAG_THREADID
;
1506 if (tag
== TAG_EXISTS
)
1508 info
->active
= stub_unpack_int (pkt
, length
);
1510 mask
= mask
& ~(TAG_EXISTS
);
1513 warning ("ERROR RMT: 'exists' length too long\n");
1519 if (tag
== TAG_THREADNAME
)
1521 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1522 mask
= mask
& ~TAG_THREADNAME
;
1525 if (tag
== TAG_DISPLAY
)
1527 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1528 mask
= mask
& ~TAG_DISPLAY
;
1531 if (tag
== TAG_MOREDISPLAY
)
1533 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1534 mask
= mask
& ~TAG_MOREDISPLAY
;
1537 warning ("ERROR RMT: unknown thread info tag\n");
1538 break; /* Not a tag we know about */
1544 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1545 struct gdb_ext_thread_info
*info
)
1547 struct remote_state
*rs
= get_remote_state ();
1549 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1551 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1552 putpkt (threadinfo_pkt
);
1553 getpkt (threadinfo_pkt
, (rs
->remote_packet_size
), 0);
1554 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1559 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1560 representation of a threadid. */
1563 adapt_remote_get_threadinfo (gdb_threadref
*ref
, int selection
,
1564 struct gdb_ext_thread_info
*info
)
1568 int_to_threadref (&lclref
, *ref
);
1569 return remote_get_threadinfo (&lclref
, selection
, info
);
1572 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1575 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1576 threadref
*nextthread
)
1578 *pkt
++ = 'q'; /* info query packet */
1579 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1580 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1581 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1582 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1587 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1590 parse_threadlist_response (char *pkt
, int result_limit
,
1591 threadref
*original_echo
, threadref
*resultlist
,
1594 struct remote_state
*rs
= get_remote_state ();
1596 int count
, resultcount
, done
;
1599 /* Assume the 'q' and 'M chars have been stripped. */
1600 limit
= pkt
+ ((rs
->remote_packet_size
) - BUF_THREAD_ID_SIZE
); /* done parse past here */
1601 pkt
= unpack_byte (pkt
, &count
); /* count field */
1602 pkt
= unpack_nibble (pkt
, &done
);
1603 /* The first threadid is the argument threadid. */
1604 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1605 while ((count
-- > 0) && (pkt
< limit
))
1607 pkt
= unpack_threadid (pkt
, resultlist
++);
1608 if (resultcount
++ >= result_limit
)
1617 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1618 int *done
, int *result_count
, threadref
*threadlist
)
1620 struct remote_state
*rs
= get_remote_state ();
1621 static threadref echo_nextthread
;
1622 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1623 char *t_response
= alloca (rs
->remote_packet_size
);
1626 /* Trancate result limit to be smaller than the packet size */
1627 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= (rs
->remote_packet_size
))
1628 result_limit
= ((rs
->remote_packet_size
) / BUF_THREAD_ID_SIZE
) - 2;
1630 pack_threadlist_request (threadlist_packet
,
1631 startflag
, result_limit
, nextthread
);
1632 putpkt (threadlist_packet
);
1633 getpkt (t_response
, (rs
->remote_packet_size
), 0);
1636 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1639 if (!threadmatch (&echo_nextthread
, nextthread
))
1641 /* FIXME: This is a good reason to drop the packet */
1642 /* Possably, there is a duplicate response */
1644 retransmit immediatly - race conditions
1645 retransmit after timeout - yes
1647 wait for packet, then exit
1649 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1650 return 0; /* I choose simply exiting */
1652 if (*result_count
<= 0)
1656 warning ("RMT ERROR : failed to get remote thread list\n");
1659 return result
; /* break; */
1661 if (*result_count
> result_limit
)
1664 warning ("RMT ERROR: threadlist response longer than requested\n");
1670 /* This is the interface between remote and threads, remotes upper interface */
1672 /* remote_find_new_threads retrieves the thread list and for each
1673 thread in the list, looks up the thread in GDB's internal list,
1674 ading the thread if it does not already exist. This involves
1675 getting partial thread lists from the remote target so, polling the
1676 quit_flag is required. */
1679 /* About this many threadisds fit in a packet. */
1681 #define MAXTHREADLISTRESULTS 32
1684 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1687 int done
, i
, result_count
;
1691 static threadref nextthread
;
1692 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1697 if (loopcount
++ > looplimit
)
1700 warning ("Remote fetch threadlist -infinite loop-\n");
1703 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1704 &done
, &result_count
, resultthreadlist
))
1709 /* clear for later iterations */
1711 /* Setup to resume next batch of thread references, set nextthread. */
1712 if (result_count
>= 1)
1713 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1715 while (result_count
--)
1716 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1723 remote_newthread_step (threadref
*ref
, void *context
)
1727 ptid
= pid_to_ptid (threadref_to_int (ref
));
1729 if (!in_thread_list (ptid
))
1731 return 1; /* continue iterator */
1734 #define CRAZY_MAX_THREADS 1000
1737 remote_current_thread (ptid_t oldpid
)
1739 struct remote_state
*rs
= get_remote_state ();
1740 char *buf
= alloca (rs
->remote_packet_size
);
1743 getpkt (buf
, (rs
->remote_packet_size
), 0);
1744 if (buf
[0] == 'Q' && buf
[1] == 'C')
1745 return pid_to_ptid (strtol (&buf
[2], NULL
, 16));
1750 /* Find new threads for info threads command.
1751 * Original version, using John Metzler's thread protocol.
1755 remote_find_new_threads (void)
1757 remote_threadlist_iterator (remote_newthread_step
, 0,
1759 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1760 inferior_ptid
= remote_current_thread (inferior_ptid
);
1764 * Find all threads for info threads command.
1765 * Uses new thread protocol contributed by Cisco.
1766 * Falls back and attempts to use the older method (above)
1767 * if the target doesn't respond to the new method.
1771 remote_threads_info (void)
1773 struct remote_state
*rs
= get_remote_state ();
1774 char *buf
= alloca (rs
->remote_packet_size
);
1778 if (remote_desc
== 0) /* paranoia */
1779 error ("Command can only be used when connected to the remote target.");
1781 if (use_threadinfo_query
)
1783 putpkt ("qfThreadInfo");
1785 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1786 if (bufp
[0] != '\0') /* q packet recognized */
1788 while (*bufp
++ == 'm') /* reply contains one or more TID */
1792 tid
= strtol (bufp
, &bufp
, 16);
1793 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1794 add_thread (pid_to_ptid (tid
));
1796 while (*bufp
++ == ','); /* comma-separated list */
1797 putpkt ("qsThreadInfo");
1799 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1805 /* Else fall back to old method based on jmetzler protocol. */
1806 use_threadinfo_query
= 0;
1807 remote_find_new_threads ();
1812 * Collect a descriptive string about the given thread.
1813 * The target may say anything it wants to about the thread
1814 * (typically info about its blocked / runnable state, name, etc.).
1815 * This string will appear in the info threads display.
1817 * Optional: targets are not required to implement this function.
1821 remote_threads_extra_info (struct thread_info
*tp
)
1823 struct remote_state
*rs
= get_remote_state ();
1827 struct gdb_ext_thread_info threadinfo
;
1828 static char display_buf
[100]; /* arbitrary... */
1829 char *bufp
= alloca (rs
->remote_packet_size
);
1830 int n
= 0; /* position in display_buf */
1832 if (remote_desc
== 0) /* paranoia */
1833 internal_error (__FILE__
, __LINE__
,
1834 "remote_threads_extra_info");
1836 if (use_threadextra_query
)
1838 sprintf (bufp
, "qThreadExtraInfo,%x", PIDGET (tp
->ptid
));
1840 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1843 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1844 result
= hex2bin (bufp
, display_buf
, n
);
1845 display_buf
[result
] = '\0';
1850 /* If the above query fails, fall back to the old method. */
1851 use_threadextra_query
= 0;
1852 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1853 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1854 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1855 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1856 if (threadinfo
.active
)
1858 if (*threadinfo
.shortname
)
1859 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1860 if (*threadinfo
.display
)
1861 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1862 if (*threadinfo
.more_display
)
1863 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1864 threadinfo
.more_display
);
1868 /* for purely cosmetic reasons, clear up trailing commas */
1869 if (',' == display_buf
[n
-1])
1870 display_buf
[n
-1] = ' ';
1879 /* Restart the remote side; this is an extended protocol operation. */
1882 extended_remote_restart (void)
1884 struct remote_state
*rs
= get_remote_state ();
1885 char *buf
= alloca (rs
->remote_packet_size
);
1887 /* Send the restart command; for reasons I don't understand the
1888 remote side really expects a number after the "R". */
1890 sprintf (&buf
[1], "%x", 0);
1893 /* Now query for status so this looks just like we restarted
1894 gdbserver from scratch. */
1896 getpkt (buf
, (rs
->remote_packet_size
), 0);
1899 /* Clean up connection to a remote debugger. */
1903 remote_close (int quitting
)
1906 serial_close (remote_desc
);
1910 /* Query the remote side for the text, data and bss offsets. */
1915 struct remote_state
*rs
= get_remote_state ();
1916 char *buf
= alloca (rs
->remote_packet_size
);
1919 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1920 struct section_offsets
*offs
;
1922 putpkt ("qOffsets");
1924 getpkt (buf
, (rs
->remote_packet_size
), 0);
1926 if (buf
[0] == '\000')
1927 return; /* Return silently. Stub doesn't support
1931 warning ("Remote failure reply: %s", buf
);
1935 /* Pick up each field in turn. This used to be done with scanf, but
1936 scanf will make trouble if CORE_ADDR size doesn't match
1937 conversion directives correctly. The following code will work
1938 with any size of CORE_ADDR. */
1939 text_addr
= data_addr
= bss_addr
= 0;
1943 if (strncmp (ptr
, "Text=", 5) == 0)
1946 /* Don't use strtol, could lose on big values. */
1947 while (*ptr
&& *ptr
!= ';')
1948 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1953 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1956 while (*ptr
&& *ptr
!= ';')
1957 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1962 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1965 while (*ptr
&& *ptr
!= ';')
1966 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1972 error ("Malformed response to offset query, %s", buf
);
1974 if (symfile_objfile
== NULL
)
1977 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1978 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1980 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
1982 /* This is a temporary kludge to force data and bss to use the same offsets
1983 because that's what nlmconv does now. The real solution requires changes
1984 to the stub and remote.c that I don't have time to do right now. */
1986 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
1987 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
1989 objfile_relocate (symfile_objfile
, offs
);
1993 * Cisco version of section offsets:
1995 * Instead of having GDB query the target for the section offsets,
1996 * Cisco lets the target volunteer the information! It's also in
1997 * a different format, so here are the functions that will decode
1998 * a section offset packet from a Cisco target.
2002 * Function: remote_cisco_section_offsets
2004 * Returns: zero for success, non-zero for failure
2008 remote_cisco_section_offsets (bfd_vma text_addr
,
2011 bfd_signed_vma
*text_offs
,
2012 bfd_signed_vma
*data_offs
,
2013 bfd_signed_vma
*bss_offs
)
2015 bfd_vma text_base
, data_base
, bss_base
;
2016 struct minimal_symbol
*start
;
2021 if (symfile_objfile
== NULL
)
2022 return -1; /* no can do nothin' */
2024 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
2026 return -1; /* Can't find "_start" symbol */
2028 data_base
= bss_base
= 0;
2029 text_base
= SYMBOL_VALUE_ADDRESS (start
);
2031 abfd
= symfile_objfile
->obfd
;
2032 for (sect
= abfd
->sections
;
2036 const char *p
= bfd_get_section_name (abfd
, sect
);
2038 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
2039 if (data_base
== 0 ||
2040 data_base
> bfd_get_section_vma (abfd
, sect
))
2041 data_base
= bfd_get_section_vma (abfd
, sect
);
2042 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
2043 if (bss_base
== 0 ||
2044 bss_base
> bfd_get_section_vma (abfd
, sect
))
2045 bss_base
= bfd_get_section_vma (abfd
, sect
);
2047 *text_offs
= text_addr
- text_base
;
2048 *data_offs
= data_addr
- data_base
;
2049 *bss_offs
= bss_addr
- bss_base
;
2054 sprintf (tmp
, "VMA: text = 0x");
2055 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
2056 sprintf (tmp
+ strlen (tmp
), " data = 0x");
2057 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
2058 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
2059 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
2060 fprintf_filtered (gdb_stdlog
, tmp
);
2061 fprintf_filtered (gdb_stdlog
,
2062 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
2063 paddr_nz (*text_offs
),
2064 paddr_nz (*data_offs
),
2065 paddr_nz (*bss_offs
));
2072 * Function: remote_cisco_objfile_relocate
2074 * Relocate the symbol file for a remote target.
2078 remote_cisco_objfile_relocate (bfd_signed_vma text_off
, bfd_signed_vma data_off
,
2079 bfd_signed_vma bss_off
)
2081 struct section_offsets
*offs
;
2083 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2085 /* FIXME: This code assumes gdb-stabs.h is being used; it's
2086 broken for xcoff, dwarf, sdb-coff, etc. But there is no
2087 simple canonical representation for this stuff. */
2089 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
2090 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
2092 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_off
;
2093 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_off
;
2094 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = bss_off
;
2096 /* First call the standard objfile_relocate. */
2097 objfile_relocate (symfile_objfile
, offs
);
2099 /* Now we need to fix up the section entries already attached to
2100 the exec target. These entries will control memory transfers
2101 from the exec file. */
2103 exec_set_section_offsets (text_off
, data_off
, bss_off
);
2107 /* Stub for catch_errors. */
2110 remote_start_remote_dummy (struct ui_out
*uiout
, void *dummy
)
2112 start_remote (); /* Initialize gdb process mechanisms */
2113 /* NOTE: Return something >=0. A -ve value is reserved for
2114 catch_exceptions. */
2119 remote_start_remote (struct ui_out
*uiout
, void *dummy
)
2121 immediate_quit
++; /* Allow user to interrupt it */
2123 /* Ack any packet which the remote side has already sent. */
2124 serial_write (remote_desc
, "+", 1);
2126 /* Let the stub know that we want it to return the thread. */
2129 inferior_ptid
= remote_current_thread (inferior_ptid
);
2131 get_offsets (); /* Get text, data & bss offsets */
2133 putpkt ("?"); /* initiate a query from remote machine */
2136 /* NOTE: See comment above in remote_start_remote_dummy(). This
2137 function returns something >=0. */
2138 return remote_start_remote_dummy (uiout
, 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);
2229 static struct serial
*
2230 remote_serial_open (char *name
)
2232 static int udp_warning
= 0;
2234 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2235 of in ser-tcp.c, because it is the remote protocol assuming that the
2236 serial connection is reliable and not the serial connection promising
2238 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2240 warning ("The remote protocol may be unreliable over UDP.");
2241 warning ("Some events may be lost, rendering further debugging "
2246 return serial_open (name
);
2250 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2254 struct remote_state
*rs
= get_remote_state ();
2256 error ("To open a remote debug connection, you need to specify what\n"
2257 "serial device is attached to the remote system\n"
2258 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2260 /* See FIXME above */
2261 wait_forever_enabled_p
= 1;
2263 target_preopen (from_tty
);
2265 unpush_target (target
);
2267 remote_desc
= remote_serial_open (name
);
2269 perror_with_name (name
);
2271 if (baud_rate
!= -1)
2273 if (serial_setbaudrate (remote_desc
, baud_rate
))
2275 serial_close (remote_desc
);
2276 perror_with_name (name
);
2280 serial_raw (remote_desc
);
2282 /* If there is something sitting in the buffer we might take it as a
2283 response to a command, which would be bad. */
2284 serial_flush_input (remote_desc
);
2288 puts_filtered ("Remote debugging using ");
2289 puts_filtered (name
);
2290 puts_filtered ("\n");
2292 push_target (target
); /* Switch to using remote target now */
2294 init_all_packet_configs ();
2296 general_thread
= -2;
2297 continue_thread
= -2;
2299 /* Probe for ability to use "ThreadInfo" query, as required. */
2300 use_threadinfo_query
= 1;
2301 use_threadextra_query
= 1;
2303 /* Without this, some commands which require an active target (such
2304 as kill) won't work. This variable serves (at least) double duty
2305 as both the pid of the target process (if it has such), and as a
2306 flag indicating that a target is active. These functions should
2307 be split out into seperate variables, especially since GDB will
2308 someday have a notion of debugging several processes. */
2310 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2311 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2312 /* First delete any symbols previously loaded from shared libraries. */
2313 no_shared_libraries (NULL
, 0);
2316 /* Start the remote connection. If error() or QUIT, discard this
2317 target (we'd otherwise be in an inconsistent state) and then
2318 propogate the error on up the exception chain. This ensures that
2319 the caller doesn't stumble along blindly assuming that the
2320 function succeeded. The CLI doesn't have this problem but other
2321 UI's, such as MI do.
2323 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2324 this function should return an error indication letting the
2325 caller restore the previous state. Unfortunatly the command
2326 ``target remote'' is directly wired to this function making that
2327 impossible. On a positive note, the CLI side of this problem has
2328 been fixed - the function set_cmd_context() makes it possible for
2329 all the ``target ....'' commands to share a common callback
2330 function. See cli-dump.c. */
2331 ex
= catch_exceptions (uiout
,
2332 remote_start_remote
, NULL
,
2333 "Couldn't establish connection to remote"
2339 throw_exception (ex
);
2344 /* Tell the remote that we are using the extended protocol. */
2345 char *buf
= alloca (rs
->remote_packet_size
);
2347 getpkt (buf
, (rs
->remote_packet_size
), 0);
2349 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2350 /* FIXME: need a master target_open vector from which all
2351 remote_opens can be called, so that stuff like this can
2352 go there. Failing that, the following code must be copied
2353 to the open function for any remote target that wants to
2354 support svr4 shared libraries. */
2356 /* Set up to detect and load shared libraries. */
2357 if (exec_bfd
) /* No use without an exec file. */
2359 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2360 remote_check_symbols (symfile_objfile
);
2365 /* Just like remote_open but with asynchronous support. */
2367 remote_async_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2371 struct remote_state
*rs
= get_remote_state ();
2373 error ("To open a remote debug connection, you need to specify what\n"
2374 "serial device is attached to the remote system\n"
2375 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2377 target_preopen (from_tty
);
2379 unpush_target (target
);
2381 remote_desc
= remote_serial_open (name
);
2383 perror_with_name (name
);
2385 if (baud_rate
!= -1)
2387 if (serial_setbaudrate (remote_desc
, baud_rate
))
2389 serial_close (remote_desc
);
2390 perror_with_name (name
);
2394 serial_raw (remote_desc
);
2396 /* If there is something sitting in the buffer we might take it as a
2397 response to a command, which would be bad. */
2398 serial_flush_input (remote_desc
);
2402 puts_filtered ("Remote debugging using ");
2403 puts_filtered (name
);
2404 puts_filtered ("\n");
2407 push_target (target
); /* Switch to using remote target now */
2409 init_all_packet_configs ();
2411 general_thread
= -2;
2412 continue_thread
= -2;
2414 /* Probe for ability to use "ThreadInfo" query, as required. */
2415 use_threadinfo_query
= 1;
2416 use_threadextra_query
= 1;
2418 /* Without this, some commands which require an active target (such
2419 as kill) won't work. This variable serves (at least) double duty
2420 as both the pid of the target process (if it has such), and as a
2421 flag indicating that a target is active. These functions should
2422 be split out into seperate variables, especially since GDB will
2423 someday have a notion of debugging several processes. */
2424 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2426 /* With this target we start out by owning the terminal. */
2427 remote_async_terminal_ours_p
= 1;
2429 /* FIXME: cagney/1999-09-23: During the initial connection it is
2430 assumed that the target is already ready and able to respond to
2431 requests. Unfortunately remote_start_remote() eventually calls
2432 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2433 around this. Eventually a mechanism that allows
2434 wait_for_inferior() to expect/get timeouts will be
2436 wait_forever_enabled_p
= 0;
2438 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2439 /* First delete any symbols previously loaded from shared libraries. */
2440 no_shared_libraries (NULL
, 0);
2443 /* Start the remote connection; if error, discard this target. See
2444 the comments in remote_open_1() for further details such as the
2445 need to re-throw the exception. */
2446 ex
= catch_exceptions (uiout
,
2447 remote_start_remote
, NULL
,
2448 "Couldn't establish connection to remote"
2454 wait_forever_enabled_p
= 1;
2455 throw_exception (ex
);
2458 wait_forever_enabled_p
= 1;
2462 /* Tell the remote that we are using the extended protocol. */
2463 char *buf
= alloca (rs
->remote_packet_size
);
2465 getpkt (buf
, (rs
->remote_packet_size
), 0);
2467 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2468 /* FIXME: need a master target_open vector from which all
2469 remote_opens can be called, so that stuff like this can
2470 go there. Failing that, the following code must be copied
2471 to the open function for any remote target that wants to
2472 support svr4 shared libraries. */
2474 /* Set up to detect and load shared libraries. */
2475 if (exec_bfd
) /* No use without an exec file. */
2477 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2478 remote_check_symbols (symfile_objfile
);
2483 /* This takes a program previously attached to and detaches it. After
2484 this is done, GDB can be used to debug some other program. We
2485 better not have left any breakpoints in the target program or it'll
2486 die when it hits one. */
2489 remote_detach (char *args
, int from_tty
)
2491 struct remote_state
*rs
= get_remote_state ();
2492 char *buf
= alloca (rs
->remote_packet_size
);
2495 error ("Argument given to \"detach\" when remotely debugging.");
2497 /* Tell the remote target to detach. */
2499 remote_send (buf
, (rs
->remote_packet_size
));
2501 target_mourn_inferior ();
2503 puts_filtered ("Ending remote debugging.\n");
2507 /* Same as remote_detach, but with async support. */
2509 remote_async_detach (char *args
, int from_tty
)
2511 struct remote_state
*rs
= get_remote_state ();
2512 char *buf
= alloca (rs
->remote_packet_size
);
2515 error ("Argument given to \"detach\" when remotely debugging.");
2517 /* Tell the remote target to detach. */
2519 remote_send (buf
, (rs
->remote_packet_size
));
2521 /* Unregister the file descriptor from the event loop. */
2522 if (target_is_async_p ())
2523 serial_async (remote_desc
, NULL
, 0);
2525 target_mourn_inferior ();
2527 puts_filtered ("Ending remote debugging.\n");
2530 /* Convert hex digit A to a number. */
2535 if (a
>= '0' && a
<= '9')
2537 else if (a
>= 'a' && a
<= 'f')
2538 return a
- 'a' + 10;
2539 else if (a
>= 'A' && a
<= 'F')
2540 return a
- 'A' + 10;
2542 error ("Reply contains invalid hex digit %d", a
);
2546 hex2bin (const char *hex
, char *bin
, int count
)
2550 for (i
= 0; i
< count
; i
++)
2552 if (hex
[0] == 0 || hex
[1] == 0)
2554 /* Hex string is short, or of uneven length.
2555 Return the count that has been converted so far. */
2558 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2564 /* Convert number NIB to a hex digit. */
2572 return 'a' + nib
- 10;
2576 bin2hex (const char *bin
, char *hex
, int count
)
2579 /* May use a length, or a nul-terminated string as input. */
2581 count
= strlen (bin
);
2583 for (i
= 0; i
< count
; i
++)
2585 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2586 *hex
++ = tohex (*bin
++ & 0xf);
2592 /* Tell the remote machine to resume. */
2594 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2596 static int last_sent_step
;
2599 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2601 struct remote_state
*rs
= get_remote_state ();
2602 char *buf
= alloca (rs
->remote_packet_size
);
2603 int pid
= PIDGET (ptid
);
2607 set_thread (0, 0); /* run any thread */
2609 set_thread (pid
, 0); /* run this thread */
2611 last_sent_signal
= siggnal
;
2612 last_sent_step
= step
;
2614 /* A hook for when we need to do something at the last moment before
2616 if (target_resume_hook
)
2617 (*target_resume_hook
) ();
2620 /* The s/S/c/C packets do not return status. So if the target does
2621 not support the S or C packets, the debug agent returns an empty
2622 string which is detected in remote_wait(). This protocol defect
2623 is fixed in the e/E packets. */
2625 if (step
&& step_range_end
)
2627 /* If the target does not support the 'E' packet, we try the 'S'
2628 packet. Ideally we would fall back to the 'e' packet if that
2629 too is not supported. But that would require another copy of
2630 the code to issue the 'e' packet (and fall back to 's' if not
2631 supported) in remote_wait(). */
2633 if (siggnal
!= TARGET_SIGNAL_0
)
2635 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2639 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2640 *p
++ = tohex (((int) siggnal
) & 0xf);
2642 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2644 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2648 getpkt (buf
, (rs
->remote_packet_size
), 0);
2650 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2656 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2660 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2662 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2666 getpkt (buf
, (rs
->remote_packet_size
), 0);
2668 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2674 if (siggnal
!= TARGET_SIGNAL_0
)
2676 buf
[0] = step
? 'S' : 'C';
2677 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2678 buf
[2] = tohex (((int) siggnal
) & 0xf);
2682 strcpy (buf
, step
? "s" : "c");
2687 /* Same as remote_resume, but with async support. */
2689 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2691 struct remote_state
*rs
= get_remote_state ();
2692 char *buf
= alloca (rs
->remote_packet_size
);
2693 int pid
= PIDGET (ptid
);
2697 set_thread (0, 0); /* run any thread */
2699 set_thread (pid
, 0); /* run this thread */
2701 last_sent_signal
= siggnal
;
2702 last_sent_step
= step
;
2704 /* A hook for when we need to do something at the last moment before
2706 if (target_resume_hook
)
2707 (*target_resume_hook
) ();
2709 /* The s/S/c/C packets do not return status. So if the target does
2710 not support the S or C packets, the debug agent returns an empty
2711 string which is detected in remote_wait(). This protocol defect
2712 is fixed in the e/E packets. */
2714 if (step
&& step_range_end
)
2716 /* If the target does not support the 'E' packet, we try the 'S'
2717 packet. Ideally we would fall back to the 'e' packet if that
2718 too is not supported. But that would require another copy of
2719 the code to issue the 'e' packet (and fall back to 's' if not
2720 supported) in remote_wait(). */
2722 if (siggnal
!= TARGET_SIGNAL_0
)
2724 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2728 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2729 *p
++ = tohex (((int) siggnal
) & 0xf);
2731 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2733 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2737 getpkt (buf
, (rs
->remote_packet_size
), 0);
2739 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2740 goto register_event_loop
;
2745 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2749 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2751 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2755 getpkt (buf
, (rs
->remote_packet_size
), 0);
2757 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2758 goto register_event_loop
;
2763 if (siggnal
!= TARGET_SIGNAL_0
)
2765 buf
[0] = step
? 'S' : 'C';
2766 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2767 buf
[2] = tohex ((int) siggnal
& 0xf);
2771 strcpy (buf
, step
? "s" : "c");
2775 register_event_loop
:
2776 /* We are about to start executing the inferior, let's register it
2777 with the event loop. NOTE: this is the one place where all the
2778 execution commands end up. We could alternatively do this in each
2779 of the execution commands in infcmd.c.*/
2780 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2781 into infcmd.c in order to allow inferior function calls to work
2782 NOT asynchronously. */
2783 if (event_loop_p
&& target_can_async_p ())
2784 target_async (inferior_event_handler
, 0);
2785 /* Tell the world that the target is now executing. */
2786 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2787 this? Instead, should the client of target just assume (for
2788 async targets) that the target is going to start executing? Is
2789 this information already found in the continuation block? */
2790 if (target_is_async_p ())
2791 target_executing
= 1;
2795 /* Set up the signal handler for SIGINT, while the target is
2796 executing, ovewriting the 'regular' SIGINT signal handler. */
2798 initialize_sigint_signal_handler (void)
2800 sigint_remote_token
=
2801 create_async_signal_handler (async_remote_interrupt
, NULL
);
2802 signal (SIGINT
, handle_remote_sigint
);
2805 /* Signal handler for SIGINT, while the target is executing. */
2807 handle_remote_sigint (int sig
)
2809 signal (sig
, handle_remote_sigint_twice
);
2810 sigint_remote_twice_token
=
2811 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2812 mark_async_signal_handler_wrapper (sigint_remote_token
);
2815 /* Signal handler for SIGINT, installed after SIGINT has already been
2816 sent once. It will take effect the second time that the user sends
2819 handle_remote_sigint_twice (int sig
)
2821 signal (sig
, handle_sigint
);
2822 sigint_remote_twice_token
=
2823 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2824 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2827 /* Perform the real interruption of the target execution, in response
2830 async_remote_interrupt (gdb_client_data arg
)
2833 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2838 /* Perform interrupt, if the first attempt did not succeed. Just give
2839 up on the target alltogether. */
2841 async_remote_interrupt_twice (gdb_client_data arg
)
2844 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2845 /* Do something only if the target was not killed by the previous
2847 if (target_executing
)
2850 signal (SIGINT
, handle_remote_sigint
);
2854 /* Reinstall the usual SIGINT handlers, after the target has
2857 cleanup_sigint_signal_handler (void *dummy
)
2859 signal (SIGINT
, handle_sigint
);
2860 if (sigint_remote_twice_token
)
2861 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2862 if (sigint_remote_token
)
2863 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2866 /* Send ^C to target to halt it. Target will respond, and send us a
2868 static void (*ofunc
) (int);
2870 /* The command line interface's stop routine. This function is installed
2871 as a signal handler for SIGINT. The first time a user requests a
2872 stop, we call remote_stop to send a break or ^C. If there is no
2873 response from the target (it didn't stop when the user requested it),
2874 we ask the user if he'd like to detach from the target. */
2876 remote_interrupt (int signo
)
2878 /* If this doesn't work, try more severe steps. */
2879 signal (signo
, remote_interrupt_twice
);
2882 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2887 /* The user typed ^C twice. */
2890 remote_interrupt_twice (int signo
)
2892 signal (signo
, ofunc
);
2894 signal (signo
, remote_interrupt
);
2897 /* This is the generic stop called via the target vector. When a target
2898 interrupt is requested, either by the command line or the GUI, we
2899 will eventually end up here. */
2903 /* Send a break or a ^C, depending on user preference. */
2905 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2908 serial_send_break (remote_desc
);
2910 serial_write (remote_desc
, "\003", 1);
2913 /* Ask the user what to do when an interrupt is received. */
2916 interrupt_query (void)
2918 target_terminal_ours ();
2920 if (query ("Interrupted while waiting for the program.\n\
2921 Give up (and stop debugging it)? "))
2923 target_mourn_inferior ();
2924 throw_exception (RETURN_QUIT
);
2927 target_terminal_inferior ();
2930 /* Enable/disable target terminal ownership. Most targets can use
2931 terminal groups to control terminal ownership. Remote targets are
2932 different in that explicit transfer of ownership to/from GDB/target
2936 remote_async_terminal_inferior (void)
2938 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2939 sync_execution here. This function should only be called when
2940 GDB is resuming the inferior in the forground. A background
2941 resume (``run&'') should leave GDB in control of the terminal and
2942 consequently should not call this code. */
2943 if (!sync_execution
)
2945 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2946 calls target_terminal_*() idenpotent. The event-loop GDB talking
2947 to an asynchronous target with a synchronous command calls this
2948 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2949 stops trying to transfer the terminal to the target when it
2950 shouldn't this guard can go away. */
2951 if (!remote_async_terminal_ours_p
)
2953 delete_file_handler (input_fd
);
2954 remote_async_terminal_ours_p
= 0;
2955 initialize_sigint_signal_handler ();
2956 /* NOTE: At this point we could also register our selves as the
2957 recipient of all input. Any characters typed could then be
2958 passed on down to the target. */
2962 remote_async_terminal_ours (void)
2964 /* See FIXME in remote_async_terminal_inferior. */
2965 if (!sync_execution
)
2967 /* See FIXME in remote_async_terminal_inferior. */
2968 if (remote_async_terminal_ours_p
)
2970 cleanup_sigint_signal_handler (NULL
);
2971 add_file_handler (input_fd
, stdin_event_handler
, 0);
2972 remote_async_terminal_ours_p
= 1;
2975 /* If nonzero, ignore the next kill. */
2980 remote_console_output (char *msg
)
2984 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2987 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2990 fputs_unfiltered (tb
, gdb_stdtarg
);
2992 gdb_flush (gdb_stdtarg
);
2995 /* Wait until the remote machine stops, then return,
2996 storing status in STATUS just as `wait' would.
2997 Returns "pid", which in the case of a multi-threaded
2998 remote OS, is the thread-id. */
3001 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3003 struct remote_state
*rs
= get_remote_state ();
3004 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3005 int thread_num
= -1;
3007 status
->kind
= TARGET_WAITKIND_EXITED
;
3008 status
->value
.integer
= 0;
3014 ofunc
= signal (SIGINT
, remote_interrupt
);
3015 getpkt (buf
, (rs
->remote_packet_size
), 1);
3016 signal (SIGINT
, ofunc
);
3018 /* This is a hook for when we need to do something (perhaps the
3019 collection of trace data) every time the target stops. */
3020 if (target_wait_loop_hook
)
3021 (*target_wait_loop_hook
) ();
3025 case 'E': /* Error of some sort */
3026 warning ("Remote failure reply: %s", buf
);
3028 case 'T': /* Status with PC, SP, FP, ... */
3031 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
3033 /* Expedited reply, containing Signal, {regno, reg} repeat */
3034 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3036 n... = register number
3037 r... = register contents
3039 p
= &buf
[3]; /* after Txx */
3047 /* Read the ``P'' register number. */
3048 LONGEST pnum
= strtol ((const char *) p
, &p_temp
, 16);
3049 p1
= (unsigned char *) p_temp
;
3051 if (p1
== p
) /* No register number present here */
3053 p1
= (unsigned char *) strchr ((const char *) p
, ':');
3055 warning ("Malformed packet(a) (missing colon): %s\n\
3058 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
3060 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3061 record_currthread (thread_num
);
3062 p
= (unsigned char *) p_temp
;
3067 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3071 warning ("Malformed packet(b) (missing colon): %s\n\
3076 warning ("Remote sent bad register number %s: %s\n\
3078 phex_nz (pnum
, 0), p
, buf
);
3080 fieldsize
= hex2bin (p
, regs
, REGISTER_RAW_SIZE (reg
->regnum
));
3082 if (fieldsize
< REGISTER_RAW_SIZE (reg
->regnum
))
3083 warning ("Remote reply is too short: %s", buf
);
3084 supply_register (reg
->regnum
, regs
);
3089 warning ("Remote register badly formatted: %s", buf
);
3090 warning (" here: %s", p
);
3095 case 'S': /* Old style status, just signal only */
3096 status
->kind
= TARGET_WAITKIND_STOPPED
;
3097 status
->value
.sig
= (enum target_signal
)
3098 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3102 /* Export Cisco kernel mode as a convenience variable
3103 (so that it can be used in the GDB prompt if desired). */
3105 if (cisco_kernel_mode
== 1)
3106 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3107 value_from_string ("PDEBUG-"));
3108 cisco_kernel_mode
= 0;
3109 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3110 record_currthread (thread_num
);
3112 else if (buf
[3] == 'k')
3114 /* Export Cisco kernel mode as a convenience variable
3115 (so that it can be used in the GDB prompt if desired). */
3117 if (cisco_kernel_mode
== 1)
3118 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3119 value_from_string ("KDEBUG-"));
3120 cisco_kernel_mode
= 1;
3123 case 'N': /* Cisco special: status and offsets */
3125 bfd_vma text_addr
, data_addr
, bss_addr
;
3126 bfd_signed_vma text_off
, data_off
, bss_off
;
3129 status
->kind
= TARGET_WAITKIND_STOPPED
;
3130 status
->value
.sig
= (enum target_signal
)
3131 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3133 if (symfile_objfile
== NULL
)
3135 warning ("Relocation packet received with no symbol file. \
3140 /* Relocate object file. Buffer format is NAATT;DD;BB
3141 * where AA is the signal number, TT is the new text
3142 * address, DD * is the new data address, and BB is the
3143 * new bss address. */
3146 text_addr
= strtoul (p
, (char **) &p1
, 16);
3147 if (p1
== p
|| *p1
!= ';')
3148 warning ("Malformed relocation packet: Packet '%s'", buf
);
3150 data_addr
= strtoul (p
, (char **) &p1
, 16);
3151 if (p1
== p
|| *p1
!= ';')
3152 warning ("Malformed relocation packet: Packet '%s'", buf
);
3154 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3156 warning ("Malformed relocation packet: Packet '%s'", buf
);
3158 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3159 &text_off
, &data_off
, &bss_off
)
3161 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3162 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3166 case 'W': /* Target exited */
3168 /* The remote process exited. */
3169 status
->kind
= TARGET_WAITKIND_EXITED
;
3170 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3174 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3175 status
->value
.sig
= (enum target_signal
)
3176 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3180 case 'O': /* Console output */
3181 remote_console_output (buf
+ 1);
3184 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3186 /* Zero length reply means that we tried 'S' or 'C' and
3187 the remote system doesn't support it. */
3188 target_terminal_ours_for_output ();
3190 ("Can't send signals to this remote system. %s not sent.\n",
3191 target_signal_to_name (last_sent_signal
));
3192 last_sent_signal
= TARGET_SIGNAL_0
;
3193 target_terminal_inferior ();
3195 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3196 putpkt ((char *) buf
);
3199 /* else fallthrough */
3201 warning ("Invalid remote reply: %s", buf
);
3206 if (thread_num
!= -1)
3208 return pid_to_ptid (thread_num
);
3210 return inferior_ptid
;
3213 /* Async version of remote_wait. */
3215 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3217 struct remote_state
*rs
= get_remote_state ();
3218 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3219 int thread_num
= -1;
3221 status
->kind
= TARGET_WAITKIND_EXITED
;
3222 status
->value
.integer
= 0;
3228 if (!target_is_async_p ())
3229 ofunc
= signal (SIGINT
, remote_interrupt
);
3230 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3231 _never_ wait for ever -> test on target_is_async_p().
3232 However, before we do that we need to ensure that the caller
3233 knows how to take the target into/out of async mode. */
3234 getpkt (buf
, (rs
->remote_packet_size
), wait_forever_enabled_p
);
3235 if (!target_is_async_p ())
3236 signal (SIGINT
, ofunc
);
3238 /* This is a hook for when we need to do something (perhaps the
3239 collection of trace data) every time the target stops. */
3240 if (target_wait_loop_hook
)
3241 (*target_wait_loop_hook
) ();
3245 case 'E': /* Error of some sort */
3246 warning ("Remote failure reply: %s", buf
);
3248 case 'T': /* Status with PC, SP, FP, ... */
3251 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
3253 /* Expedited reply, containing Signal, {regno, reg} repeat */
3254 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3256 n... = register number
3257 r... = register contents
3259 p
= &buf
[3]; /* after Txx */
3267 /* Read the register number */
3268 long pnum
= strtol ((const char *) p
, &p_temp
, 16);
3269 p1
= (unsigned char *) p_temp
;
3271 if (p1
== p
) /* No register number present here */
3273 p1
= (unsigned char *) strchr ((const char *) p
, ':');
3275 warning ("Malformed packet(a) (missing colon): %s\n\
3278 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
3280 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3281 record_currthread (thread_num
);
3282 p
= (unsigned char *) p_temp
;
3287 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3290 warning ("Malformed packet(b) (missing colon): %s\n\
3295 warning ("Remote sent bad register number %ld: %s\n\
3299 fieldsize
= hex2bin (p
, regs
, REGISTER_RAW_SIZE (reg
->regnum
));
3301 if (fieldsize
< REGISTER_RAW_SIZE (reg
->regnum
))
3302 warning ("Remote reply is too short: %s", buf
);
3303 supply_register (reg
->regnum
, regs
);
3308 warning ("Remote register badly formatted: %s", buf
);
3309 warning (" here: %s", p
);
3314 case 'S': /* Old style status, just signal only */
3315 status
->kind
= TARGET_WAITKIND_STOPPED
;
3316 status
->value
.sig
= (enum target_signal
)
3317 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3321 /* Export Cisco kernel mode as a convenience variable
3322 (so that it can be used in the GDB prompt if desired). */
3324 if (cisco_kernel_mode
== 1)
3325 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3326 value_from_string ("PDEBUG-"));
3327 cisco_kernel_mode
= 0;
3328 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3329 record_currthread (thread_num
);
3331 else if (buf
[3] == 'k')
3333 /* Export Cisco kernel mode as a convenience variable
3334 (so that it can be used in the GDB prompt if desired). */
3336 if (cisco_kernel_mode
== 1)
3337 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3338 value_from_string ("KDEBUG-"));
3339 cisco_kernel_mode
= 1;
3342 case 'N': /* Cisco special: status and offsets */
3344 bfd_vma text_addr
, data_addr
, bss_addr
;
3345 bfd_signed_vma text_off
, data_off
, bss_off
;
3348 status
->kind
= TARGET_WAITKIND_STOPPED
;
3349 status
->value
.sig
= (enum target_signal
)
3350 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3352 if (symfile_objfile
== NULL
)
3354 warning ("Relocation packet recieved with no symbol file. \
3359 /* Relocate object file. Buffer format is NAATT;DD;BB
3360 * where AA is the signal number, TT is the new text
3361 * address, DD * is the new data address, and BB is the
3362 * new bss address. */
3365 text_addr
= strtoul (p
, (char **) &p1
, 16);
3366 if (p1
== p
|| *p1
!= ';')
3367 warning ("Malformed relocation packet: Packet '%s'", buf
);
3369 data_addr
= strtoul (p
, (char **) &p1
, 16);
3370 if (p1
== p
|| *p1
!= ';')
3371 warning ("Malformed relocation packet: Packet '%s'", buf
);
3373 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3375 warning ("Malformed relocation packet: Packet '%s'", buf
);
3377 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3378 &text_off
, &data_off
, &bss_off
)
3380 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3381 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3385 case 'W': /* Target exited */
3387 /* The remote process exited. */
3388 status
->kind
= TARGET_WAITKIND_EXITED
;
3389 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3393 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3394 status
->value
.sig
= (enum target_signal
)
3395 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3399 case 'O': /* Console output */
3400 remote_console_output (buf
+ 1);
3401 /* Return immediately to the event loop. The event loop will
3402 still be waiting on the inferior afterwards. */
3403 status
->kind
= TARGET_WAITKIND_IGNORE
;
3406 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3408 /* Zero length reply means that we tried 'S' or 'C' and
3409 the remote system doesn't support it. */
3410 target_terminal_ours_for_output ();
3412 ("Can't send signals to this remote system. %s not sent.\n",
3413 target_signal_to_name (last_sent_signal
));
3414 last_sent_signal
= TARGET_SIGNAL_0
;
3415 target_terminal_inferior ();
3417 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3418 putpkt ((char *) buf
);
3421 /* else fallthrough */
3423 warning ("Invalid remote reply: %s", buf
);
3428 if (thread_num
!= -1)
3430 return pid_to_ptid (thread_num
);
3432 return inferior_ptid
;
3435 /* Number of bytes of registers this stub implements. */
3437 static int register_bytes_found
;
3439 /* Read the remote registers into the block REGS. */
3440 /* Currently we just read all the registers, so we don't use regnum. */
3444 remote_fetch_registers (int regnum
)
3446 struct remote_state
*rs
= get_remote_state ();
3447 char *buf
= alloca (rs
->remote_packet_size
);
3450 char *regs
= alloca (rs
->sizeof_g_packet
);
3452 set_thread (PIDGET (inferior_ptid
), 1);
3456 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3457 gdb_assert (reg
!= NULL
);
3458 if (!reg
->in_g_packet
)
3459 internal_error (__FILE__
, __LINE__
,
3460 "Attempt to fetch a non G-packet register when this "
3461 "remote.c does not support the p-packet.");
3465 remote_send (buf
, (rs
->remote_packet_size
));
3467 /* Save the size of the packet sent to us by the target. Its used
3468 as a heuristic when determining the max size of packets that the
3469 target can safely receive. */
3470 if ((rs
->actual_register_packet_size
) == 0)
3471 (rs
->actual_register_packet_size
) = strlen (buf
);
3473 /* Unimplemented registers read as all bits zero. */
3474 memset (regs
, 0, rs
->sizeof_g_packet
);
3476 /* We can get out of synch in various cases. If the first character
3477 in the buffer is not a hex character, assume that has happened
3478 and try to fetch another packet to read. */
3479 while ((buf
[0] < '0' || buf
[0] > '9')
3480 && (buf
[0] < 'a' || buf
[0] > 'f')
3481 && buf
[0] != 'x') /* New: unavailable register value */
3484 fprintf_unfiltered (gdb_stdlog
,
3485 "Bad register packet; fetching a new packet\n");
3486 getpkt (buf
, (rs
->remote_packet_size
), 0);
3489 /* Reply describes registers byte by byte, each byte encoded as two
3490 hex characters. Suck them all up, then supply them to the
3491 register cacheing/storage mechanism. */
3494 for (i
= 0; i
< rs
->sizeof_g_packet
; i
++)
3500 warning ("Remote reply is of odd length: %s", buf
);
3501 /* Don't change register_bytes_found in this case, and don't
3502 print a second warning. */
3505 if (p
[0] == 'x' && p
[1] == 'x')
3506 regs
[i
] = 0; /* 'x' */
3508 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3512 if (i
!= register_bytes_found
)
3514 register_bytes_found
= i
;
3515 if (REGISTER_BYTES_OK_P ()
3516 && !REGISTER_BYTES_OK (i
))
3517 warning ("Remote reply is too short: %s", buf
);
3523 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3525 struct packet_reg
*r
= &rs
->regs
[i
];
3528 supply_register (r
->regnum
, regs
+ r
->offset
);
3529 if (buf
[r
->offset
* 2] == 'x')
3530 set_register_cached (i
, -1);
3536 /* Prepare to store registers. Since we may send them all (using a
3537 'G' request), we have to read out the ones we don't want to change
3541 remote_prepare_to_store (void)
3543 /* Make sure the entire registers array is valid. */
3544 switch (remote_protocol_P
.support
)
3546 case PACKET_DISABLE
:
3547 case PACKET_SUPPORT_UNKNOWN
:
3548 /* NOTE: This isn't rs->sizeof_g_packet because here, we are
3549 forcing the register cache to read its and not the target
3551 read_register_bytes (0, (char *) NULL
, REGISTER_BYTES
); /* OK use. */
3558 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3559 packet was not recognized. */
3562 store_register_using_P (int regnum
)
3564 struct remote_state
*rs
= get_remote_state ();
3565 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3566 /* Try storing a single register. */
3567 char *buf
= alloca (rs
->remote_packet_size
);
3568 char *regp
= alloca (MAX_REGISTER_RAW_SIZE
);
3572 sprintf (buf
, "P%s=", phex_nz (reg
->pnum
, 0));
3573 p
= buf
+ strlen (buf
);
3574 regcache_collect (reg
->regnum
, regp
);
3575 bin2hex (regp
, p
, REGISTER_RAW_SIZE (reg
->regnum
));
3576 remote_send (buf
, rs
->remote_packet_size
);
3578 return buf
[0] != '\0';
3582 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
3583 of the register cache buffer. FIXME: ignores errors. */
3586 remote_store_registers (int regnum
)
3588 struct remote_state
*rs
= get_remote_state ();
3594 set_thread (PIDGET (inferior_ptid
), 1);
3598 switch (remote_protocol_P
.support
)
3600 case PACKET_DISABLE
:
3603 if (store_register_using_P (regnum
))
3606 error ("Protocol error: P packet not recognized by stub");
3607 case PACKET_SUPPORT_UNKNOWN
:
3608 if (store_register_using_P (regnum
))
3610 /* The stub recognized the 'P' packet. Remember this. */
3611 remote_protocol_P
.support
= PACKET_ENABLE
;
3616 /* The stub does not support the 'P' packet. Use 'G'
3617 instead, and don't try using 'P' in the future (it
3618 will just waste our time). */
3619 remote_protocol_P
.support
= PACKET_DISABLE
;
3625 /* Extract all the registers in the regcache copying them into a
3629 regs
= alloca (rs
->sizeof_g_packet
);
3630 memset (regs
, rs
->sizeof_g_packet
, 0);
3631 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3633 struct packet_reg
*r
= &rs
->regs
[i
];
3635 regcache_collect (r
->regnum
, regs
+ r
->offset
);
3639 /* Command describes registers byte by byte,
3640 each byte encoded as two hex characters. */
3641 buf
= alloca (rs
->remote_packet_size
);
3644 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3645 bin2hex (regs
, p
, register_bytes_found
);
3646 remote_send (buf
, (rs
->remote_packet_size
));
3650 /* Return the number of hex digits in num. */
3653 hexnumlen (ULONGEST num
)
3657 for (i
= 0; num
!= 0; i
++)
3663 /* Set BUF to the minimum number of hex digits representing NUM. */
3666 hexnumstr (char *buf
, ULONGEST num
)
3668 int len
= hexnumlen (num
);
3669 return hexnumnstr (buf
, num
, len
);
3673 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3676 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3682 for (i
= width
- 1; i
>= 0; i
--)
3684 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3691 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3694 remote_address_masked (CORE_ADDR addr
)
3696 if (remote_address_size
> 0
3697 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3699 /* Only create a mask when that mask can safely be constructed
3700 in a ULONGEST variable. */
3702 mask
= (mask
<< remote_address_size
) - 1;
3708 /* Determine whether the remote target supports binary downloading.
3709 This is accomplished by sending a no-op memory write of zero length
3710 to the target at the specified address. It does not suffice to send
3711 the whole packet, since many stubs strip the eighth bit and subsequently
3712 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3714 NOTE: This can still lose if the serial line is not eight-bit
3715 clean. In cases like this, the user should clear "remote
3719 check_binary_download (CORE_ADDR addr
)
3721 struct remote_state
*rs
= get_remote_state ();
3722 switch (remote_protocol_binary_download
.support
)
3724 case PACKET_DISABLE
:
3728 case PACKET_SUPPORT_UNKNOWN
:
3730 char *buf
= alloca (rs
->remote_packet_size
);
3735 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3737 p
+= hexnumstr (p
, (ULONGEST
) 0);
3741 putpkt_binary (buf
, (int) (p
- buf
));
3742 getpkt (buf
, (rs
->remote_packet_size
), 0);
3747 fprintf_unfiltered (gdb_stdlog
,
3748 "binary downloading NOT suppported by target\n");
3749 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3754 fprintf_unfiltered (gdb_stdlog
,
3755 "binary downloading suppported by target\n");
3756 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3763 /* Write memory data directly to the remote machine.
3764 This does not inform the data cache; the data cache uses this.
3765 MEMADDR is the address in the remote memory space.
3766 MYADDR is the address of the buffer in our space.
3767 LEN is the number of bytes.
3769 Returns number of bytes transferred, or 0 (setting errno) for
3770 error. Only transfer a single packet. */
3773 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3776 int max_buf_size
; /* Max size of packet output buffer */
3778 unsigned char *plen
;
3784 /* Verify that the target can support a binary download */
3785 check_binary_download (memaddr
);
3787 /* Determine the max packet size. */
3788 max_buf_size
= get_memory_write_packet_size ();
3789 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3790 buf
= alloca (sizeof_buf
);
3792 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3793 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
3795 /* construct "M"<memaddr>","<len>":" */
3796 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3799 /* Append [XM]. Compute a best guess of the number of bytes
3800 actually transfered. */
3801 switch (remote_protocol_binary_download
.support
)
3805 /* Best guess at number of bytes that will fit. */
3806 todo
= min (len
, max_buf_size
);
3808 case PACKET_DISABLE
:
3810 /* num bytes that will fit */
3811 todo
= min (len
, max_buf_size
/ 2);
3813 case PACKET_SUPPORT_UNKNOWN
:
3814 internal_error (__FILE__
, __LINE__
,
3815 "remote_write_bytes: bad internal state");
3817 internal_error (__FILE__
, __LINE__
, "bad switch");
3820 /* Append <memaddr> */
3821 memaddr
= remote_address_masked (memaddr
);
3822 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3825 /* Append <len>. Retain the location/size of <len>. It may
3826 need to be adjusted once the packet body has been created. */
3828 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3833 /* Append the packet body. */
3834 switch (remote_protocol_binary_download
.support
)
3837 /* Binary mode. Send target system values byte by byte, in
3838 increasing byte addresses. Only escape certain critical
3841 (nr_bytes
< todo
) && (p
- buf
) < (max_buf_size
- 2);
3844 switch (myaddr
[nr_bytes
] & 0xff)
3849 /* These must be escaped */
3851 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3854 *p
++ = myaddr
[nr_bytes
] & 0xff;
3858 if (nr_bytes
< todo
)
3860 /* Escape chars have filled up the buffer prematurely,
3861 and we have actually sent fewer bytes than planned.
3862 Fix-up the length field of the packet. Use the same
3863 number of characters as before. */
3865 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3866 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3869 case PACKET_DISABLE
:
3870 /* Normal mode: Send target system values byte by byte, in
3871 increasing byte addresses. Each byte is encoded as a two hex
3873 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3876 case PACKET_SUPPORT_UNKNOWN
:
3877 internal_error (__FILE__
, __LINE__
,
3878 "remote_write_bytes: bad internal state");
3880 internal_error (__FILE__
, __LINE__
, "bad switch");
3883 putpkt_binary (buf
, (int) (p
- buf
));
3884 getpkt (buf
, sizeof_buf
, 0);
3888 /* There is no correspondance between what the remote protocol
3889 uses for errors and errno codes. We would like a cleaner way
3890 of representing errors (big enough to include errno codes,
3891 bfd_error codes, and others). But for now just return EIO. */
3896 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3897 bytes than we'd planned. */
3901 /* Read memory data directly from the remote machine.
3902 This does not use the data cache; the data cache uses this.
3903 MEMADDR is the address in the remote memory space.
3904 MYADDR is the address of the buffer in our space.
3905 LEN is the number of bytes.
3907 Returns number of bytes transferred, or 0 for error. */
3909 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3910 remote targets) shouldn't attempt to read the entire buffer.
3911 Instead it should read a single packet worth of data and then
3912 return the byte size of that packet to the caller. The caller (its
3913 caller and its callers caller ;-) already contains code for
3914 handling partial reads. */
3917 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3920 int max_buf_size
; /* Max size of packet output buffer */
3924 /* Create a buffer big enough for this packet. */
3925 max_buf_size
= get_memory_read_packet_size ();
3926 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3927 buf
= alloca (sizeof_buf
);
3936 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3938 /* construct "m"<memaddr>","<len>" */
3939 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3940 memaddr
= remote_address_masked (memaddr
);
3943 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3945 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3949 getpkt (buf
, sizeof_buf
, 0);
3953 /* There is no correspondance between what the remote protocol uses
3954 for errors and errno codes. We would like a cleaner way of
3955 representing errors (big enough to include errno codes, bfd_error
3956 codes, and others). But for now just return EIO. */
3961 /* Reply describes memory byte by byte,
3962 each byte encoded as two hex characters. */
3965 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
3967 /* Reply is short. This means that we were able to read
3968 only part of what we wanted to. */
3969 return i
+ (origlen
- len
);
3978 /* Read or write LEN bytes from inferior memory at MEMADDR,
3979 transferring to or from debugger address BUFFER. Write to inferior if
3980 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3981 for error. TARGET is unused. */
3985 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
3986 int should_write
, struct mem_attrib
*attrib
,
3987 struct target_ops
*target
)
3989 CORE_ADDR targ_addr
;
3993 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr
, mem_len
, &targ_addr
, &targ_len
);
3998 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
4000 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
4007 /* Enable after 4.12. */
4010 remote_search (int len
, char *data
, char *mask
, CORE_ADDR startaddr
,
4011 int increment
, CORE_ADDR lorange
, CORE_ADDR hirange
,
4012 CORE_ADDR
*addr_found
, char *data_found
)
4014 if (increment
== -4 && len
== 4)
4016 long mask_long
, data_long
;
4017 long data_found_long
;
4018 CORE_ADDR addr_we_found
;
4019 char *buf
= alloca (rs
->remote_packet_size
);
4020 long returned_long
[2];
4023 mask_long
= extract_unsigned_integer (mask
, len
);
4024 data_long
= extract_unsigned_integer (data
, len
);
4025 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
4027 getpkt (buf
, (rs
->remote_packet_size
), 0);
4030 /* The stub doesn't support the 't' request. We might want to
4031 remember this fact, but on the other hand the stub could be
4032 switched on us. Maybe we should remember it only until
4033 the next "target remote". */
4034 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
4035 hirange
, addr_found
, data_found
);
4040 /* There is no correspondance between what the remote protocol uses
4041 for errors and errno codes. We would like a cleaner way of
4042 representing errors (big enough to include errno codes, bfd_error
4043 codes, and others). But for now just use EIO. */
4044 memory_error (EIO
, startaddr
);
4047 while (*p
!= '\0' && *p
!= ',')
4048 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
4050 error ("Protocol error: short return for search");
4052 data_found_long
= 0;
4053 while (*p
!= '\0' && *p
!= ',')
4054 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
4055 /* Ignore anything after this comma, for future extensions. */
4057 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
4063 *addr_found
= addr_we_found
;
4064 *data_found
= store_unsigned_integer (data_we_found
, len
);
4067 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
4068 hirange
, addr_found
, data_found
);
4073 remote_files_info (struct target_ops
*ignore
)
4075 puts_filtered ("Debugging a target over a serial line.\n");
4078 /* Stuff for dealing with the packets which are part of this protocol.
4079 See comment at top of file for details. */
4081 /* Read a single character from the remote end, masking it down to 7 bits. */
4084 readchar (int timeout
)
4088 ch
= serial_readchar (remote_desc
, timeout
);
4093 switch ((enum serial_rc
) ch
)
4096 target_mourn_inferior ();
4097 error ("Remote connection closed");
4100 perror_with_name ("Remote communication error");
4102 case SERIAL_TIMEOUT
:
4108 /* Send the command in BUF to the remote machine, and read the reply
4109 into BUF. Report an error if we get an error reply. */
4112 remote_send (char *buf
,
4116 getpkt (buf
, sizeof_buf
, 0);
4119 error ("Remote failure reply: %s", buf
);
4122 /* Display a null-terminated packet on stdout, for debugging, using C
4126 print_packet (char *buf
)
4128 puts_filtered ("\"");
4129 fputstr_filtered (buf
, '"', gdb_stdout
);
4130 puts_filtered ("\"");
4136 return putpkt_binary (buf
, strlen (buf
));
4139 /* Send a packet to the remote machine, with error checking. The data
4140 of the packet is in BUF. The string in BUF can be at most (rs->remote_packet_size) - 5
4141 to account for the $, # and checksum, and for a possible /0 if we are
4142 debugging (remote_debug) and want to print the sent packet as a string */
4145 putpkt_binary (char *buf
, int cnt
)
4147 struct remote_state
*rs
= get_remote_state ();
4149 unsigned char csum
= 0;
4150 char *buf2
= alloca (cnt
+ 6);
4151 long sizeof_junkbuf
= (rs
->remote_packet_size
);
4152 char *junkbuf
= alloca (sizeof_junkbuf
);
4158 /* Copy the packet into buffer BUF2, encapsulating it
4159 and giving it a checksum. */
4164 for (i
= 0; i
< cnt
; i
++)
4170 *p
++ = tohex ((csum
>> 4) & 0xf);
4171 *p
++ = tohex (csum
& 0xf);
4173 /* Send it over and over until we get a positive ack. */
4177 int started_error_output
= 0;
4182 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4183 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4184 fprintf_unfiltered (gdb_stdlog
, "...");
4185 gdb_flush (gdb_stdlog
);
4187 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4188 perror_with_name ("putpkt: write failed");
4190 /* read until either a timeout occurs (-2) or '+' is read */
4193 ch
= readchar (remote_timeout
);
4201 case SERIAL_TIMEOUT
:
4203 if (started_error_output
)
4205 putchar_unfiltered ('\n');
4206 started_error_output
= 0;
4215 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4219 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4220 case SERIAL_TIMEOUT
:
4224 break; /* Retransmit buffer */
4228 fprintf_unfiltered (gdb_stdlog
, "Packet instead of Ack, ignoring it\n");
4229 /* It's probably an old response, and we're out of sync.
4230 Just gobble up the packet and ignore it. */
4231 read_frame (junkbuf
, sizeof_junkbuf
);
4232 continue; /* Now, go look for + */
4237 if (!started_error_output
)
4239 started_error_output
= 1;
4240 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4242 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4246 break; /* Here to retransmit */
4250 /* This is wrong. If doing a long backtrace, the user should be
4251 able to get out next time we call QUIT, without anything as
4252 violent as interrupt_query. If we want to provide a way out of
4253 here without getting to the next QUIT, it should be based on
4254 hitting ^C twice as in remote_wait. */
4264 static int remote_cisco_mode
;
4266 /* Come here after finding the start of the frame. Collect the rest
4267 into BUF, verifying the checksum, length, and handling run-length
4268 compression. No more than sizeof_buf-1 characters are read so that
4269 the buffer can be NUL terminated.
4271 Returns -1 on error, number of characters in buffer (ignoring the
4272 trailing NULL) on success. (could be extended to return one of the
4273 SERIAL status indications). */
4276 read_frame (char *buf
,
4288 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
4289 c
= readchar (remote_timeout
);
4292 case SERIAL_TIMEOUT
:
4294 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4298 fputs_filtered ("Saw new packet start in middle of old one\n",
4300 return -1; /* Start a new packet, count retries */
4303 unsigned char pktcsum
;
4309 check_0
= readchar (remote_timeout
);
4311 check_1
= readchar (remote_timeout
);
4313 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4316 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog
);
4319 else if (check_0
< 0 || check_1
< 0)
4322 fputs_filtered ("Communication error in checksum\n", gdb_stdlog
);
4326 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4327 if (csum
== pktcsum
)
4332 fprintf_filtered (gdb_stdlog
,
4333 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4335 fputs_filtered (buf
, gdb_stdlog
);
4336 fputs_filtered ("\n", gdb_stdlog
);
4338 /* Number of characters in buffer ignoring trailing
4342 case '*': /* Run length encoding */
4347 if (remote_cisco_mode
== 0)
4349 c
= readchar (remote_timeout
);
4351 repeat
= c
- ' ' + 3; /* Compute repeat count */
4355 /* Cisco's run-length encoding variant uses two
4356 hex chars to represent the repeat count. */
4358 c
= readchar (remote_timeout
);
4360 repeat
= fromhex (c
) << 4;
4361 c
= readchar (remote_timeout
);
4363 repeat
+= fromhex (c
);
4366 /* The character before ``*'' is repeated. */
4368 if (repeat
> 0 && repeat
<= 255
4370 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4372 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4378 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
4379 puts_filtered (buf
);
4380 puts_filtered ("\n");
4384 if (bc
< sizeof_buf
- 1)
4392 puts_filtered ("Remote packet too long: ");
4393 puts_filtered (buf
);
4394 puts_filtered ("\n");
4401 /* Read a packet from the remote machine, with error checking, and
4402 store it in BUF. If FOREVER, wait forever rather than timing out;
4403 this is used (in synchronous mode) to wait for a target that is is
4404 executing user code to stop. */
4405 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4406 don't have to change all the calls to getpkt to deal with the
4407 return value, because at the moment I don't know what the right
4408 thing to do it for those. */
4416 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4420 /* Read a packet from the remote machine, with error checking, and
4421 store it in BUF. If FOREVER, wait forever rather than timing out;
4422 this is used (in synchronous mode) to wait for a target that is is
4423 executing user code to stop. If FOREVER == 0, this function is
4424 allowed to time out gracefully and return an indication of this to
4427 getpkt_sane (char *buf
,
4436 strcpy (buf
, "timeout");
4440 timeout
= watchdog
> 0 ? watchdog
: -1;
4444 timeout
= remote_timeout
;
4448 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4450 /* This can loop forever if the remote side sends us characters
4451 continuously, but if it pauses, we'll get a zero from readchar
4452 because of timeout. Then we'll count that as a retry. */
4454 /* Note that we will only wait forever prior to the start of a packet.
4455 After that, we expect characters to arrive at a brisk pace. They
4456 should show up within remote_timeout intervals. */
4460 c
= readchar (timeout
);
4462 if (c
== SERIAL_TIMEOUT
)
4464 if (forever
) /* Watchdog went off? Kill the target. */
4467 target_mourn_inferior ();
4468 error ("Watchdog has expired. Target detached.\n");
4471 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4477 /* We've found the start of a packet, now collect the data. */
4479 val
= read_frame (buf
, sizeof_buf
);
4485 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4486 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4487 fprintf_unfiltered (gdb_stdlog
, "\n");
4489 serial_write (remote_desc
, "+", 1);
4493 /* Try the whole thing again. */
4495 serial_write (remote_desc
, "-", 1);
4498 /* We have tried hard enough, and just can't receive the packet. Give up. */
4500 printf_unfiltered ("Ignoring packet error, continuing...\n");
4501 serial_write (remote_desc
, "+", 1);
4508 /* For some mysterious reason, wait_for_inferior calls kill instead of
4509 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4513 target_mourn_inferior ();
4517 /* Use catch_errors so the user can quit from gdb even when we aren't on
4518 speaking terms with the remote system. */
4519 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4521 /* Don't wait for it to die. I'm not really sure it matters whether
4522 we do or not. For the existing stubs, kill is a noop. */
4523 target_mourn_inferior ();
4526 /* Async version of remote_kill. */
4528 remote_async_kill (void)
4530 /* Unregister the file descriptor from the event loop. */
4531 if (target_is_async_p ())
4532 serial_async (remote_desc
, NULL
, 0);
4534 /* For some mysterious reason, wait_for_inferior calls kill instead of
4535 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4539 target_mourn_inferior ();
4543 /* Use catch_errors so the user can quit from gdb even when we aren't on
4544 speaking terms with the remote system. */
4545 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4547 /* Don't wait for it to die. I'm not really sure it matters whether
4548 we do or not. For the existing stubs, kill is a noop. */
4549 target_mourn_inferior ();
4555 remote_mourn_1 (&remote_ops
);
4559 remote_async_mourn (void)
4561 remote_mourn_1 (&remote_async_ops
);
4565 extended_remote_mourn (void)
4567 /* We do _not_ want to mourn the target like this; this will
4568 remove the extended remote target from the target stack,
4569 and the next time the user says "run" it'll fail.
4571 FIXME: What is the right thing to do here? */
4573 remote_mourn_1 (&extended_remote_ops
);
4577 /* Worker function for remote_mourn. */
4579 remote_mourn_1 (struct target_ops
*target
)
4581 unpush_target (target
);
4582 generic_mourn_inferior ();
4585 /* In the extended protocol we want to be able to do things like
4586 "run" and have them basically work as expected. So we need
4587 a special create_inferior function.
4589 FIXME: One day add support for changing the exec file
4590 we're debugging, arguments and an environment. */
4593 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
)
4595 /* Rip out the breakpoints; we'll reinsert them after restarting
4596 the remote server. */
4597 remove_breakpoints ();
4599 /* Now restart the remote server. */
4600 extended_remote_restart ();
4602 /* Now put the breakpoints back in. This way we're safe if the
4603 restart function works via a unix fork on the remote side. */
4604 insert_breakpoints ();
4606 /* Clean up from the last time we were running. */
4607 clear_proceed_status ();
4609 /* Let the remote process run. */
4610 proceed (-1, TARGET_SIGNAL_0
, 0);
4613 /* Async version of extended_remote_create_inferior. */
4615 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
)
4617 /* Rip out the breakpoints; we'll reinsert them after restarting
4618 the remote server. */
4619 remove_breakpoints ();
4621 /* If running asynchronously, register the target file descriptor
4622 with the event loop. */
4623 if (event_loop_p
&& target_can_async_p ())
4624 target_async (inferior_event_handler
, 0);
4626 /* Now restart the remote server. */
4627 extended_remote_restart ();
4629 /* Now put the breakpoints back in. This way we're safe if the
4630 restart function works via a unix fork on the remote side. */
4631 insert_breakpoints ();
4633 /* Clean up from the last time we were running. */
4634 clear_proceed_status ();
4636 /* Let the remote process run. */
4637 proceed (-1, TARGET_SIGNAL_0
, 0);
4641 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
4642 than other targets; in those use REMOTE_BREAKPOINT instead of just
4643 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
4644 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
4645 the standard routines that are in mem-break.c. */
4647 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
4648 the choice of breakpoint instruction affects target program design and
4649 vice versa, and by making it user-tweakable, the special code here
4650 goes away and we need fewer special GDB configurations. */
4652 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4653 #define REMOTE_BREAKPOINT
4656 #ifdef REMOTE_BREAKPOINT
4658 /* If the target isn't bi-endian, just pretend it is. */
4659 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
4660 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4661 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4664 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
4665 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
4667 #endif /* REMOTE_BREAKPOINT */
4669 /* Insert a breakpoint on targets that don't have any better breakpoint
4670 support. We read the contents of the target location and stash it,
4671 then overwrite it with a breakpoint instruction. ADDR is the target
4672 location in the target machine. CONTENTS_CACHE is a pointer to
4673 memory allocated for saving the target contents. It is guaranteed
4674 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
4675 is accomplished via BREAKPOINT_MAX). */
4678 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4680 struct remote_state
*rs
= get_remote_state ();
4681 #ifdef REMOTE_BREAKPOINT
4686 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4687 If it succeeds, then set the support to PACKET_ENABLE. If it
4688 fails, and the user has explicitly requested the Z support then
4689 report an error, otherwise, mark it disabled and go on. */
4691 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4693 char *buf
= alloca (rs
->remote_packet_size
);
4696 addr
= remote_address_masked (addr
);
4700 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4701 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4702 sprintf (p
, ",%d", bp_size
);
4705 getpkt (buf
, (rs
->remote_packet_size
), 0);
4707 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4713 case PACKET_UNKNOWN
:
4718 #ifdef REMOTE_BREAKPOINT
4719 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4723 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4724 val
= target_write_memory (addr
, (char *) big_break_insn
,
4725 sizeof big_break_insn
);
4727 val
= target_write_memory (addr
, (char *) little_break_insn
,
4728 sizeof little_break_insn
);
4733 return memory_insert_breakpoint (addr
, contents_cache
);
4734 #endif /* REMOTE_BREAKPOINT */
4738 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4740 struct remote_state
*rs
= get_remote_state ();
4743 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4745 char *buf
= alloca (rs
->remote_packet_size
);
4752 addr
= remote_address_masked (addr
);
4753 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4754 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4755 sprintf (p
, ",%d", bp_size
);
4758 getpkt (buf
, (rs
->remote_packet_size
), 0);
4760 return (buf
[0] == 'E');
4763 #ifdef REMOTE_BREAKPOINT
4764 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4766 return memory_remove_breakpoint (addr
, contents_cache
);
4767 #endif /* REMOTE_BREAKPOINT */
4771 watchpoint_to_Z_packet (int type
)
4785 internal_error (__FILE__
, __LINE__
,
4786 "hw_bp_to_z: bad watchpoint type %d", type
);
4790 /* FIXME: This function should be static and a member of the remote
4794 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4796 struct remote_state
*rs
= get_remote_state ();
4797 char *buf
= alloca (rs
->remote_packet_size
);
4799 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4801 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4802 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4803 remote_protocol_Z
[packet
].name
,
4804 remote_protocol_Z
[packet
].title
);
4806 sprintf (buf
, "Z%x,", packet
);
4807 p
= strchr (buf
, '\0');
4808 addr
= remote_address_masked (addr
);
4809 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4810 sprintf (p
, ",%x", len
);
4813 getpkt (buf
, (rs
->remote_packet_size
), 0);
4815 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4818 case PACKET_UNKNOWN
:
4823 internal_error (__FILE__
, __LINE__
,
4824 "remote_insert_watchpoint: reached end of function");
4827 /* FIXME: This function should be static and a member of the remote
4831 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4833 struct remote_state
*rs
= get_remote_state ();
4834 char *buf
= alloca (rs
->remote_packet_size
);
4836 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4838 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4839 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4840 remote_protocol_Z
[packet
].name
,
4841 remote_protocol_Z
[packet
].title
);
4843 sprintf (buf
, "z%x,", packet
);
4844 p
= strchr (buf
, '\0');
4845 addr
= remote_address_masked (addr
);
4846 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4847 sprintf (p
, ",%x", len
);
4849 getpkt (buf
, (rs
->remote_packet_size
), 0);
4851 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4854 case PACKET_UNKNOWN
:
4859 internal_error (__FILE__
, __LINE__
,
4860 "remote_remove_watchpoint: reached end of function");
4863 /* FIXME: This function should be static and a member of the remote
4867 remote_insert_hw_breakpoint (CORE_ADDR addr
, int len
)
4869 struct remote_state
*rs
= get_remote_state ();
4870 char *buf
= alloca (rs
->remote_packet_size
);
4873 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4874 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4875 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4876 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4882 addr
= remote_address_masked (addr
);
4883 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4884 sprintf (p
, ",%x", len
);
4887 getpkt (buf
, (rs
->remote_packet_size
), 0);
4889 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4892 case PACKET_UNKNOWN
:
4897 internal_error (__FILE__
, __LINE__
,
4898 "remote_remove_watchpoint: reached end of function");
4901 /* FIXME: This function should be static and a member of the remote
4905 remote_remove_hw_breakpoint (CORE_ADDR addr
, int len
)
4907 struct remote_state
*rs
= get_remote_state ();
4908 char *buf
= alloca (rs
->remote_packet_size
);
4911 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4912 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
4913 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4914 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4920 addr
= remote_address_masked (addr
);
4921 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4922 sprintf (p
, ",%x", len
);
4925 getpkt (buf
, (rs
->remote_packet_size
), 0);
4927 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4930 case PACKET_UNKNOWN
:
4935 internal_error (__FILE__
, __LINE__
,
4936 "remote_remove_watchpoint: reached end of function");
4939 /* Some targets are only capable of doing downloads, and afterwards
4940 they switch to the remote serial protocol. This function provides
4941 a clean way to get from the download target to the remote target.
4942 It's basically just a wrapper so that we don't have to expose any
4943 of the internal workings of remote.c.
4945 Prior to calling this routine, you should shutdown the current
4946 target code, else you will get the "A program is being debugged
4947 already..." message. Usually a call to pop_target() suffices. */
4950 push_remote_target (char *name
, int from_tty
)
4952 printf_filtered ("Switching to remote protocol\n");
4953 remote_open (name
, from_tty
);
4956 /* Other targets want to use the entire remote serial module but with
4957 certain remote_ops overridden. */
4960 open_remote_target (char *name
, int from_tty
, struct target_ops
*target
,
4963 printf_filtered ("Selecting the %sremote protocol\n",
4964 (extended_p
? "extended-" : ""));
4965 remote_open_1 (name
, from_tty
, target
, extended_p
);
4968 /* Table used by the crc32 function to calcuate the checksum. */
4970 static unsigned long crc32_table
[256] =
4973 static unsigned long
4974 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4976 if (!crc32_table
[1])
4978 /* Initialize the CRC table and the decoding table. */
4982 for (i
= 0; i
< 256; i
++)
4984 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4985 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4992 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4998 /* compare-sections command
5000 With no arguments, compares each loadable section in the exec bfd
5001 with the same memory range on the target, and reports mismatches.
5002 Useful for verifying the image on the target against the exec file.
5003 Depends on the target understanding the new "qCRC:" request. */
5005 /* FIXME: cagney/1999-10-26: This command should be broken down into a
5006 target method (target verify memory) and generic version of the
5007 actual command. This will allow other high-level code (especially
5008 generic_load()) to make use of this target functionality. */
5011 compare_sections_command (char *args
, int from_tty
)
5013 struct remote_state
*rs
= get_remote_state ();
5015 unsigned long host_crc
, target_crc
;
5016 extern bfd
*exec_bfd
;
5017 struct cleanup
*old_chain
;
5020 const char *sectname
;
5021 char *buf
= alloca (rs
->remote_packet_size
);
5028 error ("command cannot be used without an exec file");
5029 if (!current_target
.to_shortname
||
5030 strcmp (current_target
.to_shortname
, "remote") != 0)
5031 error ("command can only be used with remote target");
5033 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
5035 if (!(s
->flags
& SEC_LOAD
))
5036 continue; /* skip non-loadable section */
5038 size
= bfd_get_section_size_before_reloc (s
);
5040 continue; /* skip zero-length section */
5042 sectname
= bfd_get_section_name (exec_bfd
, s
);
5043 if (args
&& strcmp (args
, sectname
) != 0)
5044 continue; /* not the section selected by user */
5046 matched
= 1; /* do this section */
5048 /* FIXME: assumes lma can fit into long */
5049 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
5052 /* be clever; compute the host_crc before waiting for target reply */
5053 sectdata
= xmalloc (size
);
5054 old_chain
= make_cleanup (xfree
, sectdata
);
5055 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
5056 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
5058 getpkt (buf
, (rs
->remote_packet_size
), 0);
5060 error ("target memory fault, section %s, range 0x%s -- 0x%s",
5061 sectname
, paddr (lma
), paddr (lma
+ size
));
5063 error ("remote target does not support this operation");
5065 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
5066 target_crc
= target_crc
* 16 + fromhex (*tmp
);
5068 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
5069 sectname
, paddr (lma
), paddr (lma
+ size
));
5070 if (host_crc
== target_crc
)
5071 printf_filtered ("matched.\n");
5074 printf_filtered ("MIS-MATCHED!\n");
5078 do_cleanups (old_chain
);
5081 warning ("One or more sections of the remote executable does not match\n\
5082 the loaded file\n");
5083 if (args
&& !matched
)
5084 printf_filtered ("No loaded section named '%s'.\n", args
);
5088 remote_query (int query_type
, char *buf
, char *outbuf
, int *bufsiz
)
5090 struct remote_state
*rs
= get_remote_state ();
5092 char *buf2
= alloca (rs
->remote_packet_size
);
5093 char *p2
= &buf2
[0];
5096 error ("null pointer to remote bufer size specified");
5098 /* minimum outbuf size is (rs->remote_packet_size) - if bufsiz is not large enough let
5099 the caller know and return what the minimum size is */
5100 /* Note: a zero bufsiz can be used to query the minimum buffer size */
5101 if (*bufsiz
< (rs
->remote_packet_size
))
5103 *bufsiz
= (rs
->remote_packet_size
);
5107 /* except for querying the minimum buffer size, target must be open */
5109 error ("remote query is only available after target open");
5111 /* we only take uppercase letters as query types, at least for now */
5112 if ((query_type
< 'A') || (query_type
> 'Z'))
5113 error ("invalid remote query type");
5116 error ("null remote query specified");
5119 error ("remote query requires a buffer to receive data");
5126 /* we used one buffer char for the remote protocol q command and another
5127 for the query type. As the remote protocol encapsulation uses 4 chars
5128 plus one extra in case we are debugging (remote_debug),
5129 we have PBUFZIZ - 7 left to pack the query string */
5131 while (buf
[i
] && (i
< ((rs
->remote_packet_size
) - 8)))
5133 /* bad caller may have sent forbidden characters */
5134 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
5135 error ("illegal characters in query string");
5143 error ("query larger than available buffer");
5149 getpkt (outbuf
, *bufsiz
, 0);
5155 remote_rcmd (char *command
,
5156 struct ui_file
*outbuf
)
5158 struct remote_state
*rs
= get_remote_state ();
5160 char *buf
= alloca (rs
->remote_packet_size
);
5164 error ("remote rcmd is only available after target open");
5166 /* Send a NULL command across as an empty command */
5167 if (command
== NULL
)
5170 /* The query prefix */
5171 strcpy (buf
, "qRcmd,");
5172 p
= strchr (buf
, '\0');
5174 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > (rs
->remote_packet_size
))
5175 error ("\"monitor\" command ``%s'' is too long\n", command
);
5177 /* Encode the actual command */
5178 bin2hex (command
, p
, 0);
5180 if (putpkt (buf
) < 0)
5181 error ("Communication problem with target\n");
5183 /* get/display the response */
5186 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
5188 getpkt (buf
, (rs
->remote_packet_size
), 0);
5190 error ("Target does not support this command\n");
5191 if (buf
[0] == 'O' && buf
[1] != 'K')
5193 remote_console_output (buf
+ 1); /* 'O' message from stub */
5196 if (strcmp (buf
, "OK") == 0)
5198 if (strlen (buf
) == 3 && buf
[0] == 'E'
5199 && isdigit (buf
[1]) && isdigit (buf
[2]))
5201 error ("Protocol error with Rcmd");
5203 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5205 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5206 fputc_unfiltered (c
, outbuf
);
5213 packet_command (char *args
, int from_tty
)
5215 struct remote_state
*rs
= get_remote_state ();
5216 char *buf
= alloca (rs
->remote_packet_size
);
5219 error ("command can only be used with remote target");
5222 error ("remote-packet command requires packet text as argument");
5224 puts_filtered ("sending: ");
5225 print_packet (args
);
5226 puts_filtered ("\n");
5229 getpkt (buf
, (rs
->remote_packet_size
), 0);
5230 puts_filtered ("received: ");
5232 puts_filtered ("\n");
5236 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
5238 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5240 static void threadset_test_cmd (char *cmd
, int tty
);
5242 static void threadalive_test (char *cmd
, int tty
);
5244 static void threadlist_test_cmd (char *cmd
, int tty
);
5246 int get_and_display_threadinfo (threadref
* ref
);
5248 static void threadinfo_test_cmd (char *cmd
, int tty
);
5250 static int thread_display_step (threadref
* ref
, void *context
);
5252 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5254 static void init_remote_threadtests (void);
5256 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
5259 threadset_test_cmd (char *cmd
, int tty
)
5261 int sample_thread
= SAMPLE_THREAD
;
5263 printf_filtered ("Remote threadset test\n");
5264 set_thread (sample_thread
, 1);
5269 threadalive_test (char *cmd
, int tty
)
5271 int sample_thread
= SAMPLE_THREAD
;
5273 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5274 printf_filtered ("PASS: Thread alive test\n");
5276 printf_filtered ("FAIL: Thread alive test\n");
5279 void output_threadid (char *title
, threadref
* ref
);
5282 output_threadid (char *title
, threadref
*ref
)
5286 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
5288 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5292 threadlist_test_cmd (char *cmd
, int tty
)
5295 threadref nextthread
;
5296 int done
, result_count
;
5297 threadref threadlist
[3];
5299 printf_filtered ("Remote Threadlist test\n");
5300 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5301 &result_count
, &threadlist
[0]))
5302 printf_filtered ("FAIL: threadlist test\n");
5305 threadref
*scan
= threadlist
;
5306 threadref
*limit
= scan
+ result_count
;
5308 while (scan
< limit
)
5309 output_threadid (" thread ", scan
++);
5314 display_thread_info (struct gdb_ext_thread_info
*info
)
5316 output_threadid ("Threadid: ", &info
->threadid
);
5317 printf_filtered ("Name: %s\n ", info
->shortname
);
5318 printf_filtered ("State: %s\n", info
->display
);
5319 printf_filtered ("other: %s\n\n", info
->more_display
);
5323 get_and_display_threadinfo (threadref
*ref
)
5327 struct gdb_ext_thread_info threadinfo
;
5329 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5330 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5331 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5332 display_thread_info (&threadinfo
);
5337 threadinfo_test_cmd (char *cmd
, int tty
)
5339 int athread
= SAMPLE_THREAD
;
5343 int_to_threadref (&thread
, athread
);
5344 printf_filtered ("Remote Threadinfo test\n");
5345 if (!get_and_display_threadinfo (&thread
))
5346 printf_filtered ("FAIL cannot get thread info\n");
5350 thread_display_step (threadref
*ref
, void *context
)
5352 /* output_threadid(" threadstep ",ref); *//* simple test */
5353 return get_and_display_threadinfo (ref
);
5357 threadlist_update_test_cmd (char *cmd
, int tty
)
5359 printf_filtered ("Remote Threadlist update test\n");
5360 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5364 init_remote_threadtests (void)
5366 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
5367 "Fetch and print the remote list of thread identifiers, one pkt only");
5368 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5369 "Fetch and display info about one thread");
5370 add_com ("tset", class_obscure
, threadset_test_cmd
,
5371 "Test setting to a different thread");
5372 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5373 "Iterate through updating all remote thread info");
5374 add_com ("talive", class_obscure
, threadalive_test
,
5375 " Remote thread alive test ");
5380 /* Convert a thread ID to a string. Returns the string in a static
5384 remote_pid_to_str (ptid_t ptid
)
5386 static char buf
[30];
5388 sprintf (buf
, "Thread %d", PIDGET (ptid
));
5393 init_remote_ops (void)
5395 remote_ops
.to_shortname
= "remote";
5396 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5398 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5399 Specify the serial device it is connected to\n\
5400 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5401 remote_ops
.to_open
= remote_open
;
5402 remote_ops
.to_close
= remote_close
;
5403 remote_ops
.to_detach
= remote_detach
;
5404 remote_ops
.to_resume
= remote_resume
;
5405 remote_ops
.to_wait
= remote_wait
;
5406 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5407 remote_ops
.to_store_registers
= remote_store_registers
;
5408 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5409 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
5410 remote_ops
.to_files_info
= remote_files_info
;
5411 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5412 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5413 remote_ops
.to_kill
= remote_kill
;
5414 remote_ops
.to_load
= generic_load
;
5415 remote_ops
.to_mourn_inferior
= remote_mourn
;
5416 remote_ops
.to_thread_alive
= remote_thread_alive
;
5417 remote_ops
.to_find_new_threads
= remote_threads_info
;
5418 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5419 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5420 remote_ops
.to_stop
= remote_stop
;
5421 remote_ops
.to_query
= remote_query
;
5422 remote_ops
.to_rcmd
= remote_rcmd
;
5423 remote_ops
.to_stratum
= process_stratum
;
5424 remote_ops
.to_has_all_memory
= 1;
5425 remote_ops
.to_has_memory
= 1;
5426 remote_ops
.to_has_stack
= 1;
5427 remote_ops
.to_has_registers
= 1;
5428 remote_ops
.to_has_execution
= 1;
5429 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5430 remote_ops
.to_magic
= OPS_MAGIC
;
5433 /* Set up the extended remote vector by making a copy of the standard
5434 remote vector and adding to it. */
5437 init_extended_remote_ops (void)
5439 extended_remote_ops
= remote_ops
;
5441 extended_remote_ops
.to_shortname
= "extended-remote";
5442 extended_remote_ops
.to_longname
=
5443 "Extended remote serial target in gdb-specific protocol";
5444 extended_remote_ops
.to_doc
=
5445 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5446 Specify the serial device it is connected to (e.g. /dev/ttya).",
5447 extended_remote_ops
.to_open
= extended_remote_open
;
5448 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5449 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5453 * Command: info remote-process
5455 * This implements Cisco's version of the "info proc" command.
5457 * This query allows the target stub to return an arbitrary string
5458 * (or strings) giving arbitrary information about the target process.
5459 * This is optional; the target stub isn't required to implement it.
5461 * Syntax: qfProcessInfo request first string
5462 * qsProcessInfo request subsequent string
5463 * reply: 'O'<hex-encoded-string>
5464 * 'l' last reply (empty)
5468 remote_info_process (char *args
, int from_tty
)
5470 struct remote_state
*rs
= get_remote_state ();
5471 char *buf
= alloca (rs
->remote_packet_size
);
5473 if (remote_desc
== 0)
5474 error ("Command can only be used when connected to the remote target.");
5476 putpkt ("qfProcessInfo");
5477 getpkt (buf
, (rs
->remote_packet_size
), 0);
5479 return; /* Silently: target does not support this feature. */
5482 error ("info proc: target error.");
5484 while (buf
[0] == 'O') /* Capitol-O packet */
5486 remote_console_output (&buf
[1]);
5487 putpkt ("qsProcessInfo");
5488 getpkt (buf
, (rs
->remote_packet_size
), 0);
5497 remote_cisco_open (char *name
, int from_tty
)
5501 error ("To open a remote debug connection, you need to specify what \n"
5502 "device is attached to the remote system (e.g. host:port).");
5504 /* See FIXME above */
5505 wait_forever_enabled_p
= 1;
5507 target_preopen (from_tty
);
5509 unpush_target (&remote_cisco_ops
);
5511 remote_desc
= remote_serial_open (name
);
5513 perror_with_name (name
);
5516 * If a baud rate was specified on the gdb command line it will
5517 * be greater than the initial value of -1. If it is, use it otherwise
5521 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
5522 if (serial_setbaudrate (remote_desc
, baud_rate
))
5524 serial_close (remote_desc
);
5525 perror_with_name (name
);
5528 serial_raw (remote_desc
);
5530 /* If there is something sitting in the buffer we might take it as a
5531 response to a command, which would be bad. */
5532 serial_flush_input (remote_desc
);
5536 puts_filtered ("Remote debugging using ");
5537 puts_filtered (name
);
5538 puts_filtered ("\n");
5541 remote_cisco_mode
= 1;
5543 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
5545 init_all_packet_configs ();
5547 general_thread
= -2;
5548 continue_thread
= -2;
5550 /* Probe for ability to use "ThreadInfo" query, as required. */
5551 use_threadinfo_query
= 1;
5552 use_threadextra_query
= 1;
5554 /* Without this, some commands which require an active target (such
5555 as kill) won't work. This variable serves (at least) double duty
5556 as both the pid of the target process (if it has such), and as a
5557 flag indicating that a target is active. These functions should
5558 be split out into seperate variables, especially since GDB will
5559 someday have a notion of debugging several processes. */
5560 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
5562 /* Start the remote connection; if error, discard this target. See
5563 the comments in remote_open_1() for further details such as the
5564 need to re-throw the exception. */
5565 ex
= catch_exceptions (uiout
,
5566 remote_start_remote_dummy
, NULL
,
5567 "Couldn't establish connection to remote"
5573 throw_exception (ex
);
5578 remote_cisco_close (int quitting
)
5580 remote_cisco_mode
= 0;
5581 remote_close (quitting
);
5585 remote_cisco_mourn (void)
5587 remote_mourn_1 (&remote_cisco_ops
);
5599 /* Shared between readsocket() and readtty(). The size is arbitrary,
5600 however all targets are known to support a 400 character packet. */
5601 static char tty_input
[400];
5603 static int escape_count
;
5604 static int echo_check
;
5605 extern int quit_flag
;
5612 /* Loop until the socket doesn't have any more data */
5614 while ((data
= readchar (0)) >= 0)
5616 /* Check for the escape sequence */
5619 /* If this is the fourth escape, get out */
5620 if (++escape_count
== 4)
5625 { /* This is a '|', but not the fourth in a row.
5626 Continue without echoing it. If it isn't actually
5627 one of four in a row, it'll be echoed later. */
5634 /* Ensure any pending '|'s are flushed. */
5636 for (; escape_count
> 0; escape_count
--)
5640 if (data
== '\r') /* If this is a return character, */
5641 continue; /* - just supress it. */
5643 if (echo_check
!= -1) /* Check for echo of user input. */
5645 if (tty_input
[echo_check
] == data
)
5647 gdb_assert (echo_check
<= sizeof (tty_input
));
5648 echo_check
++; /* Character matched user input: */
5649 continue; /* Continue without echoing it. */
5651 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5652 { /* End of the line (and of echo checking). */
5653 echo_check
= -1; /* No more echo supression */
5654 continue; /* Continue without echoing. */
5657 { /* Failed check for echo of user input.
5658 We now have some suppressed output to flush! */
5661 for (j
= 0; j
< echo_check
; j
++)
5662 putchar (tty_input
[j
]);
5666 putchar (data
); /* Default case: output the char. */
5669 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5670 return READ_MORE
; /* Try to read some more */
5672 return FATAL_ERROR
; /* Trouble, bail out */
5680 /* First, read a buffer full from the terminal */
5681 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5682 if (tty_bytecount
== -1)
5684 perror ("readtty: read failed");
5688 /* Remove a quoted newline. */
5689 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5690 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5692 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5693 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5696 /* Turn trailing newlines into returns */
5697 if (tty_input
[tty_bytecount
- 1] == '\n')
5698 tty_input
[tty_bytecount
- 1] = '\r';
5700 /* If the line consists of a ~, enter debugging mode. */
5701 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5704 /* Make this a zero terminated string and write it out */
5705 tty_input
[tty_bytecount
] = 0;
5706 if (serial_write (remote_desc
, tty_input
, tty_bytecount
))
5708 perror_with_name ("readtty: write failed");
5718 fd_set input
; /* file descriptors for select */
5719 int tablesize
; /* max number of FDs for select */
5723 extern int escape_count
; /* global shared by readsocket */
5724 extern int echo_check
; /* ditto */
5729 tablesize
= 8 * sizeof (input
);
5733 /* Check for anything from our socket - doesn't block. Note that
5734 this must be done *before* the select as there may be
5735 buffered I/O waiting to be processed. */
5737 if ((status
= readsocket ()) == FATAL_ERROR
)
5739 error ("Debugging terminated by communications error");
5741 else if (status
!= READ_MORE
)
5746 fflush (stdout
); /* Flush output before blocking */
5748 /* Now block on more socket input or TTY input */
5751 FD_SET (fileno (stdin
), &input
);
5752 FD_SET (deprecated_serial_fd (remote_desc
), &input
);
5754 status
= select (tablesize
, &input
, 0, 0, 0);
5755 if ((status
== -1) && (errno
!= EINTR
))
5757 error ("Communications error on select %d", errno
);
5760 /* Handle Control-C typed */
5764 if ((++quit_count
) == 2)
5766 if (query ("Interrupt GDB? "))
5768 printf_filtered ("Interrupted by user.\n");
5769 throw_exception (RETURN_QUIT
);
5776 serial_send_break (remote_desc
);
5778 serial_write (remote_desc
, "\003", 1);
5783 /* Handle console input */
5785 if (FD_ISSET (fileno (stdin
), &input
))
5789 status
= readtty ();
5790 if (status
== READ_MORE
)
5793 return status
; /* telnet session ended */
5799 remote_cisco_wait (ptid_t ptid
, struct target_waitstatus
*status
)
5801 if (minitelnet () != ENTER_DEBUG
)
5803 error ("Debugging session terminated by protocol error");
5806 return remote_wait (ptid
, status
);
5810 init_remote_cisco_ops (void)
5812 remote_cisco_ops
.to_shortname
= "cisco";
5813 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5814 remote_cisco_ops
.to_doc
=
5815 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5816 Specify the serial device it is connected to (e.g. host:2020).";
5817 remote_cisco_ops
.to_open
= remote_cisco_open
;
5818 remote_cisco_ops
.to_close
= remote_cisco_close
;
5819 remote_cisco_ops
.to_detach
= remote_detach
;
5820 remote_cisco_ops
.to_resume
= remote_resume
;
5821 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5822 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5823 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5824 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5825 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5826 remote_cisco_ops
.to_files_info
= remote_files_info
;
5827 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5828 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5829 remote_cisco_ops
.to_kill
= remote_kill
;
5830 remote_cisco_ops
.to_load
= generic_load
;
5831 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5832 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5833 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5834 remote_cisco_ops
.to_pid_to_str
= remote_pid_to_str
;
5835 remote_cisco_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5836 remote_cisco_ops
.to_stratum
= process_stratum
;
5837 remote_cisco_ops
.to_has_all_memory
= 1;
5838 remote_cisco_ops
.to_has_memory
= 1;
5839 remote_cisco_ops
.to_has_stack
= 1;
5840 remote_cisco_ops
.to_has_registers
= 1;
5841 remote_cisco_ops
.to_has_execution
= 1;
5842 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5846 remote_can_async_p (void)
5848 /* We're async whenever the serial device is. */
5849 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5853 remote_is_async_p (void)
5855 /* We're async whenever the serial device is. */
5856 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5859 /* Pass the SERIAL event on and up to the client. One day this code
5860 will be able to delay notifying the client of an event until the
5861 point where an entire packet has been received. */
5863 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5864 static void *async_client_context
;
5865 static serial_event_ftype remote_async_serial_handler
;
5868 remote_async_serial_handler (struct serial
*scb
, void *context
)
5870 /* Don't propogate error information up to the client. Instead let
5871 the client find out about the error by querying the target. */
5872 async_client_callback (INF_REG_EVENT
, async_client_context
);
5876 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5878 if (current_target
.to_async_mask_value
== 0)
5879 internal_error (__FILE__
, __LINE__
,
5880 "Calling remote_async when async is masked");
5882 if (callback
!= NULL
)
5884 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5885 async_client_callback
= callback
;
5886 async_client_context
= context
;
5889 serial_async (remote_desc
, NULL
, NULL
);
5892 /* Target async and target extended-async.
5894 This are temporary targets, until it is all tested. Eventually
5895 async support will be incorporated int the usual 'remote'
5899 init_remote_async_ops (void)
5901 remote_async_ops
.to_shortname
= "async";
5902 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5903 remote_async_ops
.to_doc
=
5904 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5905 Specify the serial device it is connected to (e.g. /dev/ttya).";
5906 remote_async_ops
.to_open
= remote_async_open
;
5907 remote_async_ops
.to_close
= remote_close
;
5908 remote_async_ops
.to_detach
= remote_async_detach
;
5909 remote_async_ops
.to_resume
= remote_async_resume
;
5910 remote_async_ops
.to_wait
= remote_async_wait
;
5911 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5912 remote_async_ops
.to_store_registers
= remote_store_registers
;
5913 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5914 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5915 remote_async_ops
.to_files_info
= remote_files_info
;
5916 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5917 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5918 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5919 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5920 remote_async_ops
.to_kill
= remote_async_kill
;
5921 remote_async_ops
.to_load
= generic_load
;
5922 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5923 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5924 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5925 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
5926 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5927 remote_async_ops
.to_stop
= remote_stop
;
5928 remote_async_ops
.to_query
= remote_query
;
5929 remote_async_ops
.to_rcmd
= remote_rcmd
;
5930 remote_async_ops
.to_stratum
= process_stratum
;
5931 remote_async_ops
.to_has_all_memory
= 1;
5932 remote_async_ops
.to_has_memory
= 1;
5933 remote_async_ops
.to_has_stack
= 1;
5934 remote_async_ops
.to_has_registers
= 1;
5935 remote_async_ops
.to_has_execution
= 1;
5936 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5937 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5938 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5939 remote_async_ops
.to_async
= remote_async
;
5940 remote_async_ops
.to_async_mask_value
= 1;
5941 remote_async_ops
.to_magic
= OPS_MAGIC
;
5944 /* Set up the async extended remote vector by making a copy of the standard
5945 remote vector and adding to it. */
5948 init_extended_async_remote_ops (void)
5950 extended_async_remote_ops
= remote_async_ops
;
5952 extended_async_remote_ops
.to_shortname
= "extended-async";
5953 extended_async_remote_ops
.to_longname
=
5954 "Extended remote serial target in async gdb-specific protocol";
5955 extended_async_remote_ops
.to_doc
=
5956 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5957 Specify the serial device it is connected to (e.g. /dev/ttya).",
5958 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5959 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5960 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5964 set_remote_cmd (char *args
, int from_tty
)
5969 show_remote_cmd (char *args
, int from_tty
)
5972 show_remote_protocol_Z_packet_cmd (args
, from_tty
);
5973 show_remote_protocol_e_packet_cmd (args
, from_tty
);
5974 show_remote_protocol_E_packet_cmd (args
, from_tty
);
5975 show_remote_protocol_P_packet_cmd (args
, from_tty
);
5976 show_remote_protocol_qSymbol_packet_cmd (args
, from_tty
);
5977 show_remote_protocol_binary_download_cmd (args
, from_tty
);
5981 build_remote_gdbarch_data (void)
5983 remote_address_size
= TARGET_ADDR_BIT
;
5986 /* Saved pointer to previous owner of the new_objfile event. */
5987 static void (*remote_new_objfile_chain
) (struct objfile
*);
5989 /* Function to be called whenever a new objfile (shlib) is detected. */
5991 remote_new_objfile (struct objfile
*objfile
)
5993 if (remote_desc
!= 0) /* Have a remote connection */
5995 remote_check_symbols (objfile
);
5997 /* Call predecessor on chain, if any. */
5998 if (remote_new_objfile_chain
!= 0 &&
6000 remote_new_objfile_chain (objfile
);
6004 _initialize_remote (void)
6006 static struct cmd_list_element
*remote_set_cmdlist
;
6007 static struct cmd_list_element
*remote_show_cmdlist
;
6008 struct cmd_list_element
*tmpcmd
;
6010 /* architecture specific data */
6011 remote_gdbarch_data_handle
= register_gdbarch_data (init_remote_state
,
6014 /* Old tacky stuff. NOTE: This comes after the remote protocol so
6015 that the remote protocol has been initialized. */
6016 register_gdbarch_swap (&remote_address_size
,
6017 sizeof (&remote_address_size
), NULL
);
6018 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
6021 add_target (&remote_ops
);
6023 init_extended_remote_ops ();
6024 add_target (&extended_remote_ops
);
6026 init_remote_async_ops ();
6027 add_target (&remote_async_ops
);
6029 init_extended_async_remote_ops ();
6030 add_target (&extended_async_remote_ops
);
6032 init_remote_cisco_ops ();
6033 add_target (&remote_cisco_ops
);
6035 /* Hook into new objfile notification. */
6036 remote_new_objfile_chain
= target_new_objfile_hook
;
6037 target_new_objfile_hook
= remote_new_objfile
;
6040 init_remote_threadtests ();
6043 /* set/show remote ... */
6045 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
6046 Remote protocol specific variables\n\
6047 Configure various remote-protocol specific variables such as\n\
6048 the packets being used",
6049 &remote_set_cmdlist
, "set remote ",
6050 0/*allow-unknown*/, &setlist
);
6051 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, "\
6052 Remote protocol specific variables\n\
6053 Configure various remote-protocol specific variables such as\n\
6054 the packets being used",
6055 &remote_show_cmdlist
, "show remote ",
6056 0/*allow-unknown*/, &showlist
);
6058 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
6059 "Compare section data on target to the exec file.\n\
6060 Argument is a single section name (default: all loaded sections).",
6063 add_cmd ("packet", class_maintenance
, packet_command
,
6064 "Send an arbitrary packet to a remote target.\n\
6065 maintenance packet TEXT\n\
6066 If GDB is talking to an inferior via the GDB serial protocol, then\n\
6067 this command sends the string TEXT to the inferior, and displays the\n\
6068 response packet. GDB supplies the initial `$' character, and the\n\
6069 terminating `#' character and checksum.",
6073 (add_set_boolean_cmd ("remotebreak", no_class
, &remote_break
,
6074 "Set whether to send break if interrupted.\n",
6078 /* Install commands for configuring memory read/write packets. */
6080 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
6081 "Set the maximum number of bytes per memory write packet (deprecated).\n",
6083 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
,
6084 "Show the maximum number of bytes per memory write packet (deprecated).\n",
6086 add_cmd ("memory-write-packet-size", no_class
,
6087 set_memory_write_packet_size
,
6088 "Set the maximum number of bytes per memory-write packet.\n"
6089 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6090 "default packet size. The actual limit is further reduced\n"
6091 "dependent on the target. Specify ``fixed'' to disable the\n"
6092 "further restriction and ``limit'' to enable that restriction\n",
6093 &remote_set_cmdlist
);
6094 add_cmd ("memory-read-packet-size", no_class
,
6095 set_memory_read_packet_size
,
6096 "Set the maximum number of bytes per memory-read packet.\n"
6097 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6098 "default packet size. The actual limit is further reduced\n"
6099 "dependent on the target. Specify ``fixed'' to disable the\n"
6100 "further restriction and ``limit'' to enable that restriction\n",
6101 &remote_set_cmdlist
);
6102 add_cmd ("memory-write-packet-size", no_class
,
6103 show_memory_write_packet_size
,
6104 "Show the maximum number of bytes per memory-write packet.\n",
6105 &remote_show_cmdlist
);
6106 add_cmd ("memory-read-packet-size", no_class
,
6107 show_memory_read_packet_size
,
6108 "Show the maximum number of bytes per memory-read packet.\n",
6109 &remote_show_cmdlist
);
6112 (add_set_cmd ("remoteaddresssize", class_obscure
,
6113 var_integer
, (char *) &remote_address_size
,
6114 "Set the maximum size of the address (in bits) \
6115 in a memory packet.\n",
6119 add_packet_config_cmd (&remote_protocol_binary_download
,
6120 "X", "binary-download",
6121 set_remote_protocol_binary_download_cmd
,
6122 show_remote_protocol_binary_download_cmd
,
6123 &remote_set_cmdlist
, &remote_show_cmdlist
,
6126 /* XXXX - should ``set remotebinarydownload'' be retained for
6129 (add_set_cmd ("remotebinarydownload", no_class
,
6130 var_boolean
, (char *) &remote_binary_download
,
6131 "Set binary downloads.\n", &setlist
),
6135 add_info ("remote-process", remote_info_process
,
6136 "Query the remote system for process info.");
6138 add_packet_config_cmd (&remote_protocol_qSymbol
,
6139 "qSymbol", "symbol-lookup",
6140 set_remote_protocol_qSymbol_packet_cmd
,
6141 show_remote_protocol_qSymbol_packet_cmd
,
6142 &remote_set_cmdlist
, &remote_show_cmdlist
,
6145 add_packet_config_cmd (&remote_protocol_e
,
6146 "e", "step-over-range",
6147 set_remote_protocol_e_packet_cmd
,
6148 show_remote_protocol_e_packet_cmd
,
6149 &remote_set_cmdlist
, &remote_show_cmdlist
,
6151 /* Disable by default. The ``e'' packet has nasty interactions with
6152 the threading code - it relies on global state. */
6153 remote_protocol_e
.detect
= CMD_AUTO_BOOLEAN_FALSE
;
6154 update_packet_config (&remote_protocol_e
);
6156 add_packet_config_cmd (&remote_protocol_E
,
6157 "E", "step-over-range-w-signal",
6158 set_remote_protocol_E_packet_cmd
,
6159 show_remote_protocol_E_packet_cmd
,
6160 &remote_set_cmdlist
, &remote_show_cmdlist
,
6162 /* Disable by default. The ``e'' packet has nasty interactions with
6163 the threading code - it relies on global state. */
6164 remote_protocol_E
.detect
= CMD_AUTO_BOOLEAN_FALSE
;
6165 update_packet_config (&remote_protocol_E
);
6167 add_packet_config_cmd (&remote_protocol_P
,
6168 "P", "set-register",
6169 set_remote_protocol_P_packet_cmd
,
6170 show_remote_protocol_P_packet_cmd
,
6171 &remote_set_cmdlist
, &remote_show_cmdlist
,
6174 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
6175 "Z0", "software-breakpoint",
6176 set_remote_protocol_Z_software_bp_packet_cmd
,
6177 show_remote_protocol_Z_software_bp_packet_cmd
,
6178 &remote_set_cmdlist
, &remote_show_cmdlist
,
6181 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
6182 "Z1", "hardware-breakpoint",
6183 set_remote_protocol_Z_hardware_bp_packet_cmd
,
6184 show_remote_protocol_Z_hardware_bp_packet_cmd
,
6185 &remote_set_cmdlist
, &remote_show_cmdlist
,
6188 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
6189 "Z2", "write-watchpoint",
6190 set_remote_protocol_Z_write_wp_packet_cmd
,
6191 show_remote_protocol_Z_write_wp_packet_cmd
,
6192 &remote_set_cmdlist
, &remote_show_cmdlist
,
6195 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
6196 "Z3", "read-watchpoint",
6197 set_remote_protocol_Z_read_wp_packet_cmd
,
6198 show_remote_protocol_Z_read_wp_packet_cmd
,
6199 &remote_set_cmdlist
, &remote_show_cmdlist
,
6202 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
6203 "Z4", "access-watchpoint",
6204 set_remote_protocol_Z_access_wp_packet_cmd
,
6205 show_remote_protocol_Z_access_wp_packet_cmd
,
6206 &remote_set_cmdlist
, &remote_show_cmdlist
,
6209 /* Keep the old ``set remote Z-packet ...'' working. */
6210 tmpcmd
= add_set_auto_boolean_cmd ("Z-packet", class_obscure
,
6211 &remote_Z_packet_detect
,
6213 Set use of remote protocol `Z' packets", &remote_set_cmdlist
);
6214 set_cmd_sfunc (tmpcmd
, set_remote_protocol_Z_packet_cmd
);
6215 add_cmd ("Z-packet", class_obscure
, show_remote_protocol_Z_packet_cmd
,
6216 "Show use of remote protocol `Z' packets ",
6217 &remote_show_cmdlist
);