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 #include "remote-fileio.h"
60 /* Prototypes for local functions */
61 static void cleanup_sigint_signal_handler (void *dummy
);
62 static void initialize_sigint_signal_handler (void);
63 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
65 static void handle_remote_sigint (int);
66 static void handle_remote_sigint_twice (int);
67 static void async_remote_interrupt (gdb_client_data
);
68 void async_remote_interrupt_twice (gdb_client_data
);
70 static void build_remote_gdbarch_data (void);
72 static void remote_files_info (struct target_ops
*ignore
);
74 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
75 int len
, int should_write
,
76 struct mem_attrib
*attrib
,
77 struct target_ops
*target
);
79 static void remote_prepare_to_store (void);
81 static void remote_fetch_registers (int regno
);
83 static void remote_resume (ptid_t ptid
, int step
,
84 enum target_signal siggnal
);
85 static void remote_async_resume (ptid_t ptid
, int step
,
86 enum target_signal siggnal
);
87 static int remote_start_remote (struct ui_out
*uiout
, void *dummy
);
89 static void remote_open (char *name
, int from_tty
);
90 static void remote_async_open (char *name
, int from_tty
);
92 static void extended_remote_open (char *name
, int from_tty
);
93 static void extended_remote_async_open (char *name
, int from_tty
);
95 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
,
98 static void remote_close (int quitting
);
100 static void remote_store_registers (int regno
);
102 static void remote_mourn (void);
103 static void remote_async_mourn (void);
105 static void extended_remote_restart (void);
107 static void extended_remote_mourn (void);
109 static void extended_remote_create_inferior (char *, char *, char **);
110 static void extended_remote_async_create_inferior (char *, char *, char **);
112 static void remote_mourn_1 (struct target_ops
*);
114 static void remote_send (char *buf
, long sizeof_buf
);
116 static int readchar (int timeout
);
118 static ptid_t
remote_wait (ptid_t ptid
,
119 struct target_waitstatus
*status
);
120 static ptid_t
remote_async_wait (ptid_t ptid
,
121 struct target_waitstatus
*status
);
123 static void remote_kill (void);
124 static void remote_async_kill (void);
126 static int tohex (int nib
);
128 static void remote_detach (char *args
, int from_tty
);
130 static void remote_interrupt (int signo
);
132 static void remote_interrupt_twice (int signo
);
134 static void interrupt_query (void);
136 static void set_thread (int, int);
138 static int remote_thread_alive (ptid_t
);
140 static void get_offsets (void);
142 static long read_frame (char *buf
, long sizeof_buf
);
144 static int remote_insert_breakpoint (CORE_ADDR
, char *);
146 static int remote_remove_breakpoint (CORE_ADDR
, char *);
148 static int hexnumlen (ULONGEST num
);
150 static void init_remote_ops (void);
152 static void init_extended_remote_ops (void);
154 static void init_remote_cisco_ops (void);
156 static struct target_ops remote_cisco_ops
;
158 static void remote_stop (void);
160 static int ishex (int ch
, int *val
);
162 static int stubhex (int ch
);
164 static int remote_query (int /*char */ , char *, char *, int *);
166 static int hexnumstr (char *, ULONGEST
);
168 static int hexnumnstr (char *, ULONGEST
, int);
170 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
172 static void print_packet (char *);
174 static unsigned long crc32 (unsigned char *, int, unsigned int);
176 static void compare_sections_command (char *, int);
178 static void packet_command (char *, int);
180 static int stub_unpack_int (char *buff
, int fieldlength
);
182 static ptid_t
remote_current_thread (ptid_t oldptid
);
184 static void remote_find_new_threads (void);
186 static void record_currthread (int currthread
);
188 static int fromhex (int a
);
190 static int hex2bin (const char *hex
, char *bin
, int count
);
192 static int bin2hex (const char *bin
, char *hex
, int count
);
194 static int putpkt_binary (char *buf
, int cnt
);
196 static void check_binary_download (CORE_ADDR addr
);
198 struct packet_config
;
200 static void show_packet_config_cmd (struct packet_config
*config
);
202 static void update_packet_config (struct packet_config
*config
);
204 void _initialize_remote (void);
206 /* Description of the remote protocol. Strictly speaking, when the
207 target is open()ed, remote.c should create a per-target description
208 of the remote protocol using that target's architecture.
209 Unfortunatly, the target stack doesn't include local state. For
210 the moment keep the information in the target's architecture
215 long offset
; /* Offset into G packet. */
216 long regnum
; /* GDB's internal register number. */
217 LONGEST pnum
; /* Remote protocol register number. */
218 int in_g_packet
; /* Always part of G packet. */
219 /* long size in bytes; == DEPRECATED_REGISTER_RAW_SIZE (regnum); at present. */
220 /* char *name; == REGISTER_NAME (regnum); at present. */
225 /* Description of the remote protocol registers. */
226 long sizeof_g_packet
;
228 /* Description of the remote protocol registers indexed by REGNUM
229 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
230 struct packet_reg
*regs
;
232 /* This is the size (in chars) of the first response to the ``g''
233 packet. It is used as a heuristic when determining the maximum
234 size of memory-read and memory-write packets. A target will
235 typically only reserve a buffer large enough to hold the ``g''
236 packet. The size does not include packet overhead (headers and
238 long actual_register_packet_size
;
240 /* This is the maximum size (in chars) of a non read/write packet.
241 It is also used as a cap on the size of read/write packets. */
242 long remote_packet_size
;
246 /* Handle for retreving the remote protocol data from gdbarch. */
247 static struct gdbarch_data
*remote_gdbarch_data_handle
;
249 static struct remote_state
*
250 get_remote_state (void)
252 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
256 init_remote_state (struct gdbarch
*gdbarch
)
259 struct remote_state
*rs
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_state
);
261 if (DEPRECATED_REGISTER_BYTES
!= 0)
262 rs
->sizeof_g_packet
= DEPRECATED_REGISTER_BYTES
;
264 rs
->sizeof_g_packet
= 0;
266 /* Assume a 1:1 regnum<->pnum table. */
267 rs
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
, NUM_REGS
+ NUM_PSEUDO_REGS
,
269 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
271 struct packet_reg
*r
= &rs
->regs
[regnum
];
274 r
->offset
= DEPRECATED_REGISTER_BYTE (regnum
);
275 r
->in_g_packet
= (regnum
< NUM_REGS
);
276 /* ...name = REGISTER_NAME (regnum); */
278 /* Compute packet size by accumulating the size of all registers. */
279 if (DEPRECATED_REGISTER_BYTES
== 0)
280 rs
->sizeof_g_packet
+= register_size (current_gdbarch
, regnum
);
283 /* Default maximum number of characters in a packet body. Many
284 remote stubs have a hardwired buffer size of 400 bytes
285 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
286 as the maximum packet-size to ensure that the packet and an extra
287 NUL character can always fit in the buffer. This stops GDB
288 trashing stubs that try to squeeze an extra NUL into what is
289 already a full buffer (As of 1999-12-04 that was most stubs. */
290 rs
->remote_packet_size
= 400 - 1;
292 /* Should rs->sizeof_g_packet needs more space than the
293 default, adjust the size accordingly. Remember that each byte is
294 encoded as two characters. 32 is the overhead for the packet
295 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
296 (``$NN:G...#NN'') is a better guess, the below has been padded a
298 if (rs
->sizeof_g_packet
> ((rs
->remote_packet_size
- 32) / 2))
299 rs
->remote_packet_size
= (rs
->sizeof_g_packet
* 2 + 32);
301 /* This one is filled in when a ``g'' packet is received. */
302 rs
->actual_register_packet_size
= 0;
307 static struct packet_reg
*
308 packet_reg_from_regnum (struct remote_state
*rs
, long regnum
)
310 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
314 struct packet_reg
*r
= &rs
->regs
[regnum
];
315 gdb_assert (r
->regnum
== regnum
);
320 static struct packet_reg
*
321 packet_reg_from_pnum (struct remote_state
*rs
, LONGEST pnum
)
324 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
326 struct packet_reg
*r
= &rs
->regs
[i
];
333 /* FIXME: graces/2002-08-08: These variables should eventually be
334 bound to an instance of the target object (as in gdbarch-tdep()),
335 when such a thing exists. */
337 /* This is set to the data address of the access causing the target
338 to stop for a watchpoint. */
339 static CORE_ADDR remote_watch_data_address
;
341 /* This is non-zero if taregt stopped for a watchpoint. */
342 static int remote_stopped_by_watchpoint_p
;
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 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 AUTO_BOOLEAN_TRUE
:
606 config
->support
= PACKET_ENABLE
;
608 case AUTO_BOOLEAN_FALSE
:
609 config
->support
= PACKET_DISABLE
;
611 case 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 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 AUTO_BOOLEAN_TRUE
:
640 case 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 cmd_sfunc_ftype
*set_func
,
652 cmd_sfunc_ftype
*show_func
,
653 struct cmd_list_element
**set_remote_list
,
654 struct cmd_list_element
**show_remote_list
,
657 struct cmd_list_element
*set_cmd
;
658 struct cmd_list_element
*show_cmd
;
663 config
->title
= title
;
664 config
->detect
= AUTO_BOOLEAN_AUTO
;
665 config
->support
= PACKET_SUPPORT_UNKNOWN
;
666 xasprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
668 xasprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
670 /* set/show TITLE-packet {auto,on,off} */
671 xasprintf (&cmd_name
, "%s-packet", title
);
672 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
673 &config
->detect
, set_doc
, show_doc
,
675 set_remote_list
, show_remote_list
);
676 /* set/show remote NAME-packet {auto,on,off} -- legacy */
680 xasprintf (&legacy_name
, "%s-packet", name
);
681 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
683 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
688 static enum packet_result
689 packet_ok (const char *buf
, struct packet_config
*config
)
693 /* The stub recognized the packet request. Check that the
694 operation succeeded. */
695 switch (config
->support
)
697 case PACKET_SUPPORT_UNKNOWN
:
699 fprintf_unfiltered (gdb_stdlog
,
700 "Packet %s (%s) is supported\n",
701 config
->name
, config
->title
);
702 config
->support
= PACKET_ENABLE
;
705 internal_error (__FILE__
, __LINE__
,
706 "packet_ok: attempt to use a disabled packet");
711 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
712 /* "OK" - definitly OK. */
715 && isxdigit (buf
[1]) && isxdigit (buf
[2])
717 /* "Enn" - definitly an error. */
719 /* The packet may or may not be OK. Just assume it is */
724 /* The stub does not support the packet. */
725 switch (config
->support
)
728 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
729 /* If the stub previously indicated that the packet was
730 supported then there is a protocol error.. */
731 error ("Protocol error: %s (%s) conflicting enabled responses.",
732 config
->name
, config
->title
);
734 /* The user set it wrong. */
735 error ("Enabled packet %s (%s) not recognized by stub",
736 config
->name
, config
->title
);
738 case PACKET_SUPPORT_UNKNOWN
:
740 fprintf_unfiltered (gdb_stdlog
,
741 "Packet %s (%s) is NOT supported\n",
742 config
->name
, config
->title
);
743 config
->support
= PACKET_DISABLE
;
748 return PACKET_UNKNOWN
;
752 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
753 static struct packet_config remote_protocol_qSymbol
;
756 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
757 struct cmd_list_element
*c
)
759 update_packet_config (&remote_protocol_qSymbol
);
763 show_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
764 struct cmd_list_element
*c
)
766 show_packet_config_cmd (&remote_protocol_qSymbol
);
769 /* Should we try the 'e' (step over range) request? */
770 static struct packet_config remote_protocol_e
;
773 set_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
774 struct cmd_list_element
*c
)
776 update_packet_config (&remote_protocol_e
);
780 show_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
781 struct cmd_list_element
*c
)
783 show_packet_config_cmd (&remote_protocol_e
);
787 /* Should we try the 'E' (step over range / w signal #) request? */
788 static struct packet_config remote_protocol_E
;
791 set_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
792 struct cmd_list_element
*c
)
794 update_packet_config (&remote_protocol_E
);
798 show_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
799 struct cmd_list_element
*c
)
801 show_packet_config_cmd (&remote_protocol_E
);
805 /* Should we try the 'P' (set register) request? */
807 static struct packet_config remote_protocol_P
;
810 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
811 struct cmd_list_element
*c
)
813 update_packet_config (&remote_protocol_P
);
817 show_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
818 struct cmd_list_element
*c
)
820 show_packet_config_cmd (&remote_protocol_P
);
823 /* Should we try one of the 'Z' requests? */
827 Z_PACKET_SOFTWARE_BP
,
828 Z_PACKET_HARDWARE_BP
,
835 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
837 /* FIXME: Instead of having all these boiler plate functions, the
838 command callback should include a context argument. */
841 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
842 struct cmd_list_element
*c
)
844 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
848 show_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
849 struct cmd_list_element
*c
)
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
,
863 struct cmd_list_element
*c
)
865 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
869 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
870 struct cmd_list_element
*c
)
872 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
876 show_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
877 struct cmd_list_element
*c
)
879 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
883 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
884 struct cmd_list_element
*c
)
886 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
890 show_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
891 struct cmd_list_element
*c
)
893 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
897 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
898 struct cmd_list_element
*c
)
900 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
904 show_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
905 struct cmd_list_element
*c
)
907 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
910 /* For compatibility with older distributions. Provide a ``set remote
911 Z-packet ...'' command that updates all the Z packet types. */
913 static enum auto_boolean remote_Z_packet_detect
;
916 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
917 struct cmd_list_element
*c
)
920 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
922 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
923 update_packet_config (&remote_protocol_Z
[i
]);
928 show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
929 struct cmd_list_element
*c
)
932 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
934 show_packet_config_cmd (&remote_protocol_Z
[i
]);
938 /* Should we try the 'X' (remote binary download) packet?
940 This variable (available to the user via "set remote X-packet")
941 dictates whether downloads are sent in binary (via the 'X' packet).
942 We assume that the stub can, and attempt to do it. This will be
943 cleared if the stub does not understand it. This switch is still
944 needed, though in cases when the packet is supported in the stub,
945 but the connection does not allow it (i.e., 7-bit serial connection
948 static struct packet_config remote_protocol_binary_download
;
950 /* Should we try the 'ThreadInfo' query packet?
952 This variable (NOT available to the user: auto-detect only!)
953 determines whether GDB will use the new, simpler "ThreadInfo"
954 query or the older, more complex syntax for thread queries.
955 This is an auto-detect variable (set to true at each connect,
956 and set to false when the target fails to recognize it). */
958 static int use_threadinfo_query
;
959 static int use_threadextra_query
;
962 set_remote_protocol_binary_download_cmd (char *args
,
964 struct cmd_list_element
*c
)
966 update_packet_config (&remote_protocol_binary_download
);
970 show_remote_protocol_binary_download_cmd (char *args
, int from_tty
,
971 struct cmd_list_element
*c
)
973 show_packet_config_cmd (&remote_protocol_binary_download
);
977 /* Tokens for use by the asynchronous signal handlers for SIGINT */
978 static void *sigint_remote_twice_token
;
979 static void *sigint_remote_token
;
981 /* These are pointers to hook functions that may be set in order to
982 modify resume/wait behavior for a particular architecture. */
984 void (*target_resume_hook
) (void);
985 void (*target_wait_loop_hook
) (void);
989 /* These are the threads which we last sent to the remote system.
990 -1 for all or -2 for not sent yet. */
991 static int general_thread
;
992 static int continue_thread
;
994 /* Call this function as a result of
995 1) A halt indication (T packet) containing a thread id
996 2) A direct query of currthread
997 3) Successful execution of set thread
1001 record_currthread (int currthread
)
1003 general_thread
= currthread
;
1005 /* If this is a new thread, add it to GDB's thread list.
1006 If we leave it up to WFI to do this, bad things will happen. */
1007 if (!in_thread_list (pid_to_ptid (currthread
)))
1009 add_thread (pid_to_ptid (currthread
));
1010 ui_out_text (uiout
, "[New ");
1011 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
1012 ui_out_text (uiout
, "]\n");
1016 #define MAGIC_NULL_PID 42000
1019 set_thread (int th
, int gen
)
1021 struct remote_state
*rs
= get_remote_state ();
1022 char *buf
= alloca (rs
->remote_packet_size
);
1023 int state
= gen
? general_thread
: continue_thread
;
1029 buf
[1] = gen
? 'g' : 'c';
1030 if (th
== MAGIC_NULL_PID
)
1036 sprintf (&buf
[2], "-%x", -th
);
1038 sprintf (&buf
[2], "%x", th
);
1040 getpkt (buf
, (rs
->remote_packet_size
), 0);
1042 general_thread
= th
;
1044 continue_thread
= th
;
1047 /* Return nonzero if the thread TH is still alive on the remote system. */
1050 remote_thread_alive (ptid_t ptid
)
1052 int tid
= PIDGET (ptid
);
1056 sprintf (buf
, "T-%08x", -tid
);
1058 sprintf (buf
, "T%08x", tid
);
1060 getpkt (buf
, sizeof (buf
), 0);
1061 return (buf
[0] == 'O' && buf
[1] == 'K');
1064 /* About these extended threadlist and threadinfo packets. They are
1065 variable length packets but, the fields within them are often fixed
1066 length. They are redundent enough to send over UDP as is the
1067 remote protocol in general. There is a matching unit test module
1070 #define OPAQUETHREADBYTES 8
1072 /* a 64 bit opaque identifier */
1073 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1075 /* WARNING: This threadref data structure comes from the remote O.S., libstub
1076 protocol encoding, and remote.c. it is not particularly changable */
1078 /* Right now, the internal structure is int. We want it to be bigger.
1082 typedef int gdb_threadref
; /* internal GDB thread reference */
1084 /* gdb_ext_thread_info is an internal GDB data structure which is
1085 equivalint to the reply of the remote threadinfo packet */
1087 struct gdb_ext_thread_info
1089 threadref threadid
; /* External form of thread reference */
1090 int active
; /* Has state interesting to GDB? , regs, stack */
1091 char display
[256]; /* Brief state display, name, blocked/syspended */
1092 char shortname
[32]; /* To be used to name threads */
1093 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
1096 /* The volume of remote transfers can be limited by submitting
1097 a mask containing bits specifying the desired information.
1098 Use a union of these values as the 'selection' parameter to
1099 get_thread_info. FIXME: Make these TAG names more thread specific.
1102 #define TAG_THREADID 1
1103 #define TAG_EXISTS 2
1104 #define TAG_DISPLAY 4
1105 #define TAG_THREADNAME 8
1106 #define TAG_MOREDISPLAY 16
1108 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
1110 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1112 static char *unpack_nibble (char *buf
, int *val
);
1114 static char *pack_nibble (char *buf
, int nibble
);
1116 static char *pack_hex_byte (char *pkt
, int /*unsigned char */ byte
);
1118 static char *unpack_byte (char *buf
, int *value
);
1120 static char *pack_int (char *buf
, int value
);
1122 static char *unpack_int (char *buf
, int *value
);
1124 static char *unpack_string (char *src
, char *dest
, int length
);
1126 static char *pack_threadid (char *pkt
, threadref
* id
);
1128 static char *unpack_threadid (char *inbuf
, threadref
* id
);
1130 void int_to_threadref (threadref
* id
, int value
);
1132 static int threadref_to_int (threadref
* ref
);
1134 static void copy_threadref (threadref
* dest
, threadref
* src
);
1136 static int threadmatch (threadref
* dest
, threadref
* src
);
1138 static char *pack_threadinfo_request (char *pkt
, int mode
, threadref
* id
);
1140 static int remote_unpack_thread_info_response (char *pkt
,
1141 threadref
* expectedref
,
1142 struct gdb_ext_thread_info
1146 static int remote_get_threadinfo (threadref
* threadid
, int fieldset
, /*TAG mask */
1147 struct gdb_ext_thread_info
*info
);
1149 static int adapt_remote_get_threadinfo (gdb_threadref
* ref
,
1151 struct gdb_ext_thread_info
*info
);
1153 static char *pack_threadlist_request (char *pkt
, int startflag
,
1155 threadref
* nextthread
);
1157 static int parse_threadlist_response (char *pkt
,
1159 threadref
* original_echo
,
1160 threadref
* resultlist
, int *doneflag
);
1162 static int remote_get_threadlist (int startflag
,
1163 threadref
* nextthread
,
1166 int *result_count
, threadref
* threadlist
);
1168 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
1170 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1171 void *context
, int looplimit
);
1173 static int remote_newthread_step (threadref
* ref
, void *context
);
1175 /* encode 64 bits in 16 chars of hex */
1177 static const char hexchars
[] = "0123456789abcdef";
1180 ishex (int ch
, int *val
)
1182 if ((ch
>= 'a') && (ch
<= 'f'))
1184 *val
= ch
- 'a' + 10;
1187 if ((ch
>= 'A') && (ch
<= 'F'))
1189 *val
= ch
- 'A' + 10;
1192 if ((ch
>= '0') && (ch
<= '9'))
1203 if (ch
>= 'a' && ch
<= 'f')
1204 return ch
- 'a' + 10;
1205 if (ch
>= '0' && ch
<= '9')
1207 if (ch
>= 'A' && ch
<= 'F')
1208 return ch
- 'A' + 10;
1213 stub_unpack_int (char *buff
, int fieldlength
)
1220 nibble
= stubhex (*buff
++);
1224 retval
= retval
<< 4;
1230 unpack_varlen_hex (char *buff
, /* packet to parse */
1236 while (ishex (*buff
, &nibble
))
1239 retval
= retval
<< 4;
1240 retval
|= nibble
& 0x0f;
1247 unpack_nibble (char *buf
, int *val
)
1249 ishex (*buf
++, val
);
1254 pack_nibble (char *buf
, int nibble
)
1256 *buf
++ = hexchars
[(nibble
& 0x0f)];
1261 pack_hex_byte (char *pkt
, int byte
)
1263 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1264 *pkt
++ = hexchars
[(byte
& 0xf)];
1269 unpack_byte (char *buf
, int *value
)
1271 *value
= stub_unpack_int (buf
, 2);
1276 pack_int (char *buf
, int value
)
1278 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1279 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1280 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1281 buf
= pack_hex_byte (buf
, (value
& 0xff));
1286 unpack_int (char *buf
, int *value
)
1288 *value
= stub_unpack_int (buf
, 8);
1292 #if 0 /* currently unused, uncomment when needed */
1293 static char *pack_string (char *pkt
, char *string
);
1296 pack_string (char *pkt
, char *string
)
1301 len
= strlen (string
);
1303 len
= 200; /* Bigger than most GDB packets, junk??? */
1304 pkt
= pack_hex_byte (pkt
, len
);
1308 if ((ch
== '\0') || (ch
== '#'))
1309 ch
= '*'; /* Protect encapsulation */
1314 #endif /* 0 (unused) */
1317 unpack_string (char *src
, char *dest
, int length
)
1326 pack_threadid (char *pkt
, threadref
*id
)
1329 unsigned char *altid
;
1331 altid
= (unsigned char *) id
;
1332 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1334 pkt
= pack_hex_byte (pkt
, *altid
++);
1340 unpack_threadid (char *inbuf
, threadref
*id
)
1343 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1346 altref
= (char *) id
;
1348 while (inbuf
< limit
)
1350 x
= stubhex (*inbuf
++);
1351 y
= stubhex (*inbuf
++);
1352 *altref
++ = (x
<< 4) | y
;
1357 /* Externally, threadrefs are 64 bits but internally, they are still
1358 ints. This is due to a mismatch of specifications. We would like
1359 to use 64bit thread references internally. This is an adapter
1363 int_to_threadref (threadref
*id
, int value
)
1365 unsigned char *scan
;
1367 scan
= (unsigned char *) id
;
1373 *scan
++ = (value
>> 24) & 0xff;
1374 *scan
++ = (value
>> 16) & 0xff;
1375 *scan
++ = (value
>> 8) & 0xff;
1376 *scan
++ = (value
& 0xff);
1380 threadref_to_int (threadref
*ref
)
1383 unsigned char *scan
;
1385 scan
= (char *) ref
;
1389 value
= (value
<< 8) | ((*scan
++) & 0xff);
1394 copy_threadref (threadref
*dest
, threadref
*src
)
1397 unsigned char *csrc
, *cdest
;
1399 csrc
= (unsigned char *) src
;
1400 cdest
= (unsigned char *) dest
;
1407 threadmatch (threadref
*dest
, threadref
*src
)
1409 /* things are broken right now, so just assume we got a match */
1411 unsigned char *srcp
, *destp
;
1413 srcp
= (char *) src
;
1414 destp
= (char *) dest
;
1418 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1425 threadid:1, # always request threadid
1432 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1435 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1437 *pkt
++ = 'q'; /* Info Query */
1438 *pkt
++ = 'P'; /* process or thread info */
1439 pkt
= pack_int (pkt
, mode
); /* mode */
1440 pkt
= pack_threadid (pkt
, id
); /* threadid */
1441 *pkt
= '\0'; /* terminate */
1445 /* These values tag the fields in a thread info response packet */
1446 /* Tagging the fields allows us to request specific fields and to
1447 add more fields as time goes by */
1449 #define TAG_THREADID 1 /* Echo the thread identifier */
1450 #define TAG_EXISTS 2 /* Is this process defined enough to
1451 fetch registers and its stack */
1452 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1453 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1454 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1458 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1459 struct gdb_ext_thread_info
*info
)
1461 struct remote_state
*rs
= get_remote_state ();
1465 char *limit
= pkt
+ (rs
->remote_packet_size
); /* plausable parsing limit */
1468 /* info->threadid = 0; FIXME: implement zero_threadref */
1470 info
->display
[0] = '\0';
1471 info
->shortname
[0] = '\0';
1472 info
->more_display
[0] = '\0';
1474 /* Assume the characters indicating the packet type have been stripped */
1475 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1476 pkt
= unpack_threadid (pkt
, &ref
);
1479 warning ("Incomplete response to threadinfo request\n");
1480 if (!threadmatch (&ref
, expectedref
))
1481 { /* This is an answer to a different request */
1482 warning ("ERROR RMT Thread info mismatch\n");
1485 copy_threadref (&info
->threadid
, &ref
);
1487 /* Loop on tagged fields , try to bail if somthing goes wrong */
1489 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1491 pkt
= unpack_int (pkt
, &tag
); /* tag */
1492 pkt
= unpack_byte (pkt
, &length
); /* length */
1493 if (!(tag
& mask
)) /* tags out of synch with mask */
1495 warning ("ERROR RMT: threadinfo tag mismatch\n");
1499 if (tag
== TAG_THREADID
)
1503 warning ("ERROR RMT: length of threadid is not 16\n");
1507 pkt
= unpack_threadid (pkt
, &ref
);
1508 mask
= mask
& ~TAG_THREADID
;
1511 if (tag
== TAG_EXISTS
)
1513 info
->active
= stub_unpack_int (pkt
, length
);
1515 mask
= mask
& ~(TAG_EXISTS
);
1518 warning ("ERROR RMT: 'exists' length too long\n");
1524 if (tag
== TAG_THREADNAME
)
1526 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1527 mask
= mask
& ~TAG_THREADNAME
;
1530 if (tag
== TAG_DISPLAY
)
1532 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1533 mask
= mask
& ~TAG_DISPLAY
;
1536 if (tag
== TAG_MOREDISPLAY
)
1538 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1539 mask
= mask
& ~TAG_MOREDISPLAY
;
1542 warning ("ERROR RMT: unknown thread info tag\n");
1543 break; /* Not a tag we know about */
1549 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1550 struct gdb_ext_thread_info
*info
)
1552 struct remote_state
*rs
= get_remote_state ();
1554 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1556 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1557 putpkt (threadinfo_pkt
);
1558 getpkt (threadinfo_pkt
, (rs
->remote_packet_size
), 0);
1559 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1564 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1565 representation of a threadid. */
1568 adapt_remote_get_threadinfo (gdb_threadref
*ref
, int selection
,
1569 struct gdb_ext_thread_info
*info
)
1573 int_to_threadref (&lclref
, *ref
);
1574 return remote_get_threadinfo (&lclref
, selection
, info
);
1577 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1580 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1581 threadref
*nextthread
)
1583 *pkt
++ = 'q'; /* info query packet */
1584 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1585 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1586 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1587 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1592 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1595 parse_threadlist_response (char *pkt
, int result_limit
,
1596 threadref
*original_echo
, threadref
*resultlist
,
1599 struct remote_state
*rs
= get_remote_state ();
1601 int count
, resultcount
, done
;
1604 /* Assume the 'q' and 'M chars have been stripped. */
1605 limit
= pkt
+ ((rs
->remote_packet_size
) - BUF_THREAD_ID_SIZE
); /* done parse past here */
1606 pkt
= unpack_byte (pkt
, &count
); /* count field */
1607 pkt
= unpack_nibble (pkt
, &done
);
1608 /* The first threadid is the argument threadid. */
1609 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1610 while ((count
-- > 0) && (pkt
< limit
))
1612 pkt
= unpack_threadid (pkt
, resultlist
++);
1613 if (resultcount
++ >= result_limit
)
1622 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1623 int *done
, int *result_count
, threadref
*threadlist
)
1625 struct remote_state
*rs
= get_remote_state ();
1626 static threadref echo_nextthread
;
1627 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1628 char *t_response
= alloca (rs
->remote_packet_size
);
1631 /* Trancate result limit to be smaller than the packet size */
1632 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= (rs
->remote_packet_size
))
1633 result_limit
= ((rs
->remote_packet_size
) / BUF_THREAD_ID_SIZE
) - 2;
1635 pack_threadlist_request (threadlist_packet
,
1636 startflag
, result_limit
, nextthread
);
1637 putpkt (threadlist_packet
);
1638 getpkt (t_response
, (rs
->remote_packet_size
), 0);
1641 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1644 if (!threadmatch (&echo_nextthread
, nextthread
))
1646 /* FIXME: This is a good reason to drop the packet */
1647 /* Possably, there is a duplicate response */
1649 retransmit immediatly - race conditions
1650 retransmit after timeout - yes
1652 wait for packet, then exit
1654 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1655 return 0; /* I choose simply exiting */
1657 if (*result_count
<= 0)
1661 warning ("RMT ERROR : failed to get remote thread list\n");
1664 return result
; /* break; */
1666 if (*result_count
> result_limit
)
1669 warning ("RMT ERROR: threadlist response longer than requested\n");
1675 /* This is the interface between remote and threads, remotes upper interface */
1677 /* remote_find_new_threads retrieves the thread list and for each
1678 thread in the list, looks up the thread in GDB's internal list,
1679 ading the thread if it does not already exist. This involves
1680 getting partial thread lists from the remote target so, polling the
1681 quit_flag is required. */
1684 /* About this many threadisds fit in a packet. */
1686 #define MAXTHREADLISTRESULTS 32
1689 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1692 int done
, i
, result_count
;
1696 static threadref nextthread
;
1697 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1702 if (loopcount
++ > looplimit
)
1705 warning ("Remote fetch threadlist -infinite loop-\n");
1708 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1709 &done
, &result_count
, resultthreadlist
))
1714 /* clear for later iterations */
1716 /* Setup to resume next batch of thread references, set nextthread. */
1717 if (result_count
>= 1)
1718 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1720 while (result_count
--)
1721 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1728 remote_newthread_step (threadref
*ref
, void *context
)
1732 ptid
= pid_to_ptid (threadref_to_int (ref
));
1734 if (!in_thread_list (ptid
))
1736 return 1; /* continue iterator */
1739 #define CRAZY_MAX_THREADS 1000
1742 remote_current_thread (ptid_t oldpid
)
1744 struct remote_state
*rs
= get_remote_state ();
1745 char *buf
= alloca (rs
->remote_packet_size
);
1748 getpkt (buf
, (rs
->remote_packet_size
), 0);
1749 if (buf
[0] == 'Q' && buf
[1] == 'C')
1750 return pid_to_ptid (strtol (&buf
[2], NULL
, 16));
1755 /* Find new threads for info threads command.
1756 * Original version, using John Metzler's thread protocol.
1760 remote_find_new_threads (void)
1762 remote_threadlist_iterator (remote_newthread_step
, 0,
1764 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1765 inferior_ptid
= remote_current_thread (inferior_ptid
);
1769 * Find all threads for info threads command.
1770 * Uses new thread protocol contributed by Cisco.
1771 * Falls back and attempts to use the older method (above)
1772 * if the target doesn't respond to the new method.
1776 remote_threads_info (void)
1778 struct remote_state
*rs
= get_remote_state ();
1779 char *buf
= alloca (rs
->remote_packet_size
);
1783 if (remote_desc
== 0) /* paranoia */
1784 error ("Command can only be used when connected to the remote target.");
1786 if (use_threadinfo_query
)
1788 putpkt ("qfThreadInfo");
1790 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1791 if (bufp
[0] != '\0') /* q packet recognized */
1793 while (*bufp
++ == 'm') /* reply contains one or more TID */
1797 tid
= strtol (bufp
, &bufp
, 16);
1798 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1799 add_thread (pid_to_ptid (tid
));
1801 while (*bufp
++ == ','); /* comma-separated list */
1802 putpkt ("qsThreadInfo");
1804 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1810 /* Else fall back to old method based on jmetzler protocol. */
1811 use_threadinfo_query
= 0;
1812 remote_find_new_threads ();
1817 * Collect a descriptive string about the given thread.
1818 * The target may say anything it wants to about the thread
1819 * (typically info about its blocked / runnable state, name, etc.).
1820 * This string will appear in the info threads display.
1822 * Optional: targets are not required to implement this function.
1826 remote_threads_extra_info (struct thread_info
*tp
)
1828 struct remote_state
*rs
= get_remote_state ();
1832 struct gdb_ext_thread_info threadinfo
;
1833 static char display_buf
[100]; /* arbitrary... */
1834 char *bufp
= alloca (rs
->remote_packet_size
);
1835 int n
= 0; /* position in display_buf */
1837 if (remote_desc
== 0) /* paranoia */
1838 internal_error (__FILE__
, __LINE__
,
1839 "remote_threads_extra_info");
1841 if (use_threadextra_query
)
1843 sprintf (bufp
, "qThreadExtraInfo,%x", PIDGET (tp
->ptid
));
1845 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1848 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1849 result
= hex2bin (bufp
, display_buf
, n
);
1850 display_buf
[result
] = '\0';
1855 /* If the above query fails, fall back to the old method. */
1856 use_threadextra_query
= 0;
1857 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1858 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1859 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1860 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1861 if (threadinfo
.active
)
1863 if (*threadinfo
.shortname
)
1864 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1865 if (*threadinfo
.display
)
1866 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1867 if (*threadinfo
.more_display
)
1868 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1869 threadinfo
.more_display
);
1873 /* for purely cosmetic reasons, clear up trailing commas */
1874 if (',' == display_buf
[n
-1])
1875 display_buf
[n
-1] = ' ';
1884 /* Restart the remote side; this is an extended protocol operation. */
1887 extended_remote_restart (void)
1889 struct remote_state
*rs
= get_remote_state ();
1890 char *buf
= alloca (rs
->remote_packet_size
);
1892 /* Send the restart command; for reasons I don't understand the
1893 remote side really expects a number after the "R". */
1895 sprintf (&buf
[1], "%x", 0);
1898 /* Now query for status so this looks just like we restarted
1899 gdbserver from scratch. */
1901 getpkt (buf
, (rs
->remote_packet_size
), 0);
1904 /* Clean up connection to a remote debugger. */
1907 remote_close (int quitting
)
1910 serial_close (remote_desc
);
1914 /* Query the remote side for the text, data and bss offsets. */
1919 struct remote_state
*rs
= get_remote_state ();
1920 char *buf
= alloca (rs
->remote_packet_size
);
1923 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1924 struct section_offsets
*offs
;
1926 putpkt ("qOffsets");
1928 getpkt (buf
, (rs
->remote_packet_size
), 0);
1930 if (buf
[0] == '\000')
1931 return; /* Return silently. Stub doesn't support
1935 warning ("Remote failure reply: %s", buf
);
1939 /* Pick up each field in turn. This used to be done with scanf, but
1940 scanf will make trouble if CORE_ADDR size doesn't match
1941 conversion directives correctly. The following code will work
1942 with any size of CORE_ADDR. */
1943 text_addr
= data_addr
= bss_addr
= 0;
1947 if (strncmp (ptr
, "Text=", 5) == 0)
1950 /* Don't use strtol, could lose on big values. */
1951 while (*ptr
&& *ptr
!= ';')
1952 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1957 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1960 while (*ptr
&& *ptr
!= ';')
1961 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1966 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1969 while (*ptr
&& *ptr
!= ';')
1970 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1976 error ("Malformed response to offset query, %s", buf
);
1978 if (symfile_objfile
== NULL
)
1981 offs
= ((struct section_offsets
*)
1982 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
1983 memcpy (offs
, symfile_objfile
->section_offsets
,
1984 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
1986 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
1988 /* This is a temporary kludge to force data and bss to use the same offsets
1989 because that's what nlmconv does now. The real solution requires changes
1990 to the stub and remote.c that I don't have time to do right now. */
1992 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
1993 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
1995 objfile_relocate (symfile_objfile
, offs
);
1999 * Cisco version of section offsets:
2001 * Instead of having GDB query the target for the section offsets,
2002 * Cisco lets the target volunteer the information! It's also in
2003 * a different format, so here are the functions that will decode
2004 * a section offset packet from a Cisco target.
2008 * Function: remote_cisco_section_offsets
2010 * Returns: zero for success, non-zero for failure
2014 remote_cisco_section_offsets (bfd_vma text_addr
,
2017 bfd_signed_vma
*text_offs
,
2018 bfd_signed_vma
*data_offs
,
2019 bfd_signed_vma
*bss_offs
)
2021 bfd_vma text_base
, data_base
, bss_base
;
2022 struct minimal_symbol
*start
;
2027 if (symfile_objfile
== NULL
)
2028 return -1; /* no can do nothin' */
2030 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
2032 return -1; /* Can't find "_start" symbol */
2034 data_base
= bss_base
= 0;
2035 text_base
= SYMBOL_VALUE_ADDRESS (start
);
2037 abfd
= symfile_objfile
->obfd
;
2038 for (sect
= abfd
->sections
;
2042 const char *p
= bfd_get_section_name (abfd
, sect
);
2044 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
2045 if (data_base
== 0 ||
2046 data_base
> bfd_get_section_vma (abfd
, sect
))
2047 data_base
= bfd_get_section_vma (abfd
, sect
);
2048 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
2049 if (bss_base
== 0 ||
2050 bss_base
> bfd_get_section_vma (abfd
, sect
))
2051 bss_base
= bfd_get_section_vma (abfd
, sect
);
2053 *text_offs
= text_addr
- text_base
;
2054 *data_offs
= data_addr
- data_base
;
2055 *bss_offs
= bss_addr
- bss_base
;
2060 sprintf (tmp
, "VMA: text = 0x");
2061 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
2062 sprintf (tmp
+ strlen (tmp
), " data = 0x");
2063 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
2064 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
2065 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
2066 fputs_filtered (tmp
, gdb_stdlog
);
2067 fprintf_filtered (gdb_stdlog
,
2068 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
2069 paddr_nz (*text_offs
),
2070 paddr_nz (*data_offs
),
2071 paddr_nz (*bss_offs
));
2078 * Function: remote_cisco_objfile_relocate
2080 * Relocate the symbol file for a remote target.
2084 remote_cisco_objfile_relocate (bfd_signed_vma text_off
, bfd_signed_vma data_off
,
2085 bfd_signed_vma bss_off
)
2087 struct section_offsets
*offs
;
2089 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2091 /* FIXME: This code assumes gdb-stabs.h is being used; it's
2092 broken for xcoff, dwarf, sdb-coff, etc. But there is no
2093 simple canonical representation for this stuff. */
2095 offs
= (struct section_offsets
*)
2096 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2097 memcpy (offs
, symfile_objfile
->section_offsets
,
2098 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2100 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_off
;
2101 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_off
;
2102 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = bss_off
;
2104 /* First call the standard objfile_relocate. */
2105 objfile_relocate (symfile_objfile
, offs
);
2107 /* Now we need to fix up the section entries already attached to
2108 the exec target. These entries will control memory transfers
2109 from the exec file. */
2111 exec_set_section_offsets (text_off
, data_off
, bss_off
);
2115 /* Stub for catch_errors. */
2118 remote_start_remote_dummy (struct ui_out
*uiout
, void *dummy
)
2120 start_remote (); /* Initialize gdb process mechanisms */
2121 /* NOTE: Return something >=0. A -ve value is reserved for
2122 catch_exceptions. */
2127 remote_start_remote (struct ui_out
*uiout
, void *dummy
)
2129 immediate_quit
++; /* Allow user to interrupt it */
2131 /* Ack any packet which the remote side has already sent. */
2132 serial_write (remote_desc
, "+", 1);
2134 /* Let the stub know that we want it to return the thread. */
2137 inferior_ptid
= remote_current_thread (inferior_ptid
);
2139 get_offsets (); /* Get text, data & bss offsets */
2141 putpkt ("?"); /* initiate a query from remote machine */
2144 /* NOTE: See comment above in remote_start_remote_dummy(). This
2145 function returns something >=0. */
2146 return remote_start_remote_dummy (uiout
, dummy
);
2149 /* Open a connection to a remote debugger.
2150 NAME is the filename used for communication. */
2153 remote_open (char *name
, int from_tty
)
2155 remote_open_1 (name
, from_tty
, &remote_ops
, 0, 0);
2158 /* Just like remote_open, but with asynchronous support. */
2160 remote_async_open (char *name
, int from_tty
)
2162 remote_open_1 (name
, from_tty
, &remote_async_ops
, 0, 1);
2165 /* Open a connection to a remote debugger using the extended
2166 remote gdb protocol. NAME is the filename used for communication. */
2169 extended_remote_open (char *name
, int from_tty
)
2171 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */,
2175 /* Just like extended_remote_open, but with asynchronous support. */
2177 extended_remote_async_open (char *name
, int from_tty
)
2179 remote_open_1 (name
, from_tty
, &extended_async_remote_ops
,
2180 1 /*extended_p */, 1 /* async_p */);
2183 /* Generic code for opening a connection to a remote target. */
2186 init_all_packet_configs (void)
2189 update_packet_config (&remote_protocol_e
);
2190 update_packet_config (&remote_protocol_E
);
2191 update_packet_config (&remote_protocol_P
);
2192 update_packet_config (&remote_protocol_qSymbol
);
2193 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2194 update_packet_config (&remote_protocol_Z
[i
]);
2195 /* Force remote_write_bytes to check whether target supports binary
2197 update_packet_config (&remote_protocol_binary_download
);
2200 /* Symbol look-up. */
2203 remote_check_symbols (struct objfile
*objfile
)
2205 struct remote_state
*rs
= get_remote_state ();
2206 char *msg
, *reply
, *tmp
;
2207 struct minimal_symbol
*sym
;
2210 if (remote_protocol_qSymbol
.support
== PACKET_DISABLE
)
2213 msg
= alloca (rs
->remote_packet_size
);
2214 reply
= alloca (rs
->remote_packet_size
);
2216 /* Invite target to request symbol lookups. */
2218 putpkt ("qSymbol::");
2219 getpkt (reply
, (rs
->remote_packet_size
), 0);
2220 packet_ok (reply
, &remote_protocol_qSymbol
);
2222 while (strncmp (reply
, "qSymbol:", 8) == 0)
2225 end
= hex2bin (tmp
, msg
, strlen (tmp
) / 2);
2227 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2229 sprintf (msg
, "qSymbol::%s", &reply
[8]);
2231 sprintf (msg
, "qSymbol:%s:%s",
2232 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2235 getpkt (reply
, (rs
->remote_packet_size
), 0);
2239 static struct serial
*
2240 remote_serial_open (char *name
)
2242 static int udp_warning
= 0;
2244 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2245 of in ser-tcp.c, because it is the remote protocol assuming that the
2246 serial connection is reliable and not the serial connection promising
2248 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2250 warning ("The remote protocol may be unreliable over UDP.");
2251 warning ("Some events may be lost, rendering further debugging "
2256 return serial_open (name
);
2260 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2261 int extended_p
, int async_p
)
2264 struct remote_state
*rs
= get_remote_state ();
2266 error ("To open a remote debug connection, you need to specify what\n"
2267 "serial device is attached to the remote system\n"
2268 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2270 /* See FIXME above */
2272 wait_forever_enabled_p
= 1;
2274 target_preopen (from_tty
);
2276 unpush_target (target
);
2278 remote_desc
= remote_serial_open (name
);
2280 perror_with_name (name
);
2282 if (baud_rate
!= -1)
2284 if (serial_setbaudrate (remote_desc
, baud_rate
))
2286 serial_close (remote_desc
);
2287 perror_with_name (name
);
2291 serial_raw (remote_desc
);
2293 /* If there is something sitting in the buffer we might take it as a
2294 response to a command, which would be bad. */
2295 serial_flush_input (remote_desc
);
2299 puts_filtered ("Remote debugging using ");
2300 puts_filtered (name
);
2301 puts_filtered ("\n");
2303 push_target (target
); /* Switch to using remote target now */
2305 init_all_packet_configs ();
2307 general_thread
= -2;
2308 continue_thread
= -2;
2310 /* Probe for ability to use "ThreadInfo" query, as required. */
2311 use_threadinfo_query
= 1;
2312 use_threadextra_query
= 1;
2314 /* Without this, some commands which require an active target (such
2315 as kill) won't work. This variable serves (at least) double duty
2316 as both the pid of the target process (if it has such), and as a
2317 flag indicating that a target is active. These functions should
2318 be split out into seperate variables, especially since GDB will
2319 someday have a notion of debugging several processes. */
2321 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2325 /* With this target we start out by owning the terminal. */
2326 remote_async_terminal_ours_p
= 1;
2328 /* FIXME: cagney/1999-09-23: During the initial connection it is
2329 assumed that the target is already ready and able to respond to
2330 requests. Unfortunately remote_start_remote() eventually calls
2331 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2332 around this. Eventually a mechanism that allows
2333 wait_for_inferior() to expect/get timeouts will be
2335 wait_forever_enabled_p
= 0;
2338 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2339 /* First delete any symbols previously loaded from shared libraries. */
2340 no_shared_libraries (NULL
, 0);
2343 /* Start the remote connection. If error() or QUIT, discard this
2344 target (we'd otherwise be in an inconsistent state) and then
2345 propogate the error on up the exception chain. This ensures that
2346 the caller doesn't stumble along blindly assuming that the
2347 function succeeded. The CLI doesn't have this problem but other
2348 UI's, such as MI do.
2350 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2351 this function should return an error indication letting the
2352 caller restore the previous state. Unfortunatly the command
2353 ``target remote'' is directly wired to this function making that
2354 impossible. On a positive note, the CLI side of this problem has
2355 been fixed - the function set_cmd_context() makes it possible for
2356 all the ``target ....'' commands to share a common callback
2357 function. See cli-dump.c. */
2358 ex
= catch_exceptions (uiout
,
2359 remote_start_remote
, NULL
,
2360 "Couldn't establish connection to remote"
2367 wait_forever_enabled_p
= 1;
2368 throw_exception (ex
);
2372 wait_forever_enabled_p
= 1;
2376 /* Tell the remote that we are using the extended protocol. */
2377 char *buf
= alloca (rs
->remote_packet_size
);
2379 getpkt (buf
, (rs
->remote_packet_size
), 0);
2381 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2382 /* FIXME: need a master target_open vector from which all
2383 remote_opens can be called, so that stuff like this can
2384 go there. Failing that, the following code must be copied
2385 to the open function for any remote target that wants to
2386 support svr4 shared libraries. */
2388 /* Set up to detect and load shared libraries. */
2389 if (exec_bfd
) /* No use without an exec file. */
2391 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2392 remote_check_symbols (symfile_objfile
);
2397 /* This takes a program previously attached to and detaches it. After
2398 this is done, GDB can be used to debug some other program. We
2399 better not have left any breakpoints in the target program or it'll
2400 die when it hits one. */
2403 remote_detach (char *args
, int from_tty
)
2405 struct remote_state
*rs
= get_remote_state ();
2406 char *buf
= alloca (rs
->remote_packet_size
);
2409 error ("Argument given to \"detach\" when remotely debugging.");
2411 /* Tell the remote target to detach. */
2413 remote_send (buf
, (rs
->remote_packet_size
));
2415 /* Unregister the file descriptor from the event loop. */
2416 if (target_is_async_p ())
2417 serial_async (remote_desc
, NULL
, 0);
2419 target_mourn_inferior ();
2421 puts_filtered ("Ending remote debugging.\n");
2424 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
2427 remote_disconnect (char *args
, int from_tty
)
2429 struct remote_state
*rs
= get_remote_state ();
2430 char *buf
= alloca (rs
->remote_packet_size
);
2433 error ("Argument given to \"detach\" when remotely debugging.");
2435 /* Unregister the file descriptor from the event loop. */
2436 if (target_is_async_p ())
2437 serial_async (remote_desc
, NULL
, 0);
2439 target_mourn_inferior ();
2441 puts_filtered ("Ending remote debugging.\n");
2444 /* Convert hex digit A to a number. */
2449 if (a
>= '0' && a
<= '9')
2451 else if (a
>= 'a' && a
<= 'f')
2452 return a
- 'a' + 10;
2453 else if (a
>= 'A' && a
<= 'F')
2454 return a
- 'A' + 10;
2456 error ("Reply contains invalid hex digit %d", a
);
2460 hex2bin (const char *hex
, char *bin
, int count
)
2464 for (i
= 0; i
< count
; i
++)
2466 if (hex
[0] == 0 || hex
[1] == 0)
2468 /* Hex string is short, or of uneven length.
2469 Return the count that has been converted so far. */
2472 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2478 /* Convert number NIB to a hex digit. */
2486 return 'a' + nib
- 10;
2490 bin2hex (const char *bin
, char *hex
, int count
)
2493 /* May use a length, or a nul-terminated string as input. */
2495 count
= strlen (bin
);
2497 for (i
= 0; i
< count
; i
++)
2499 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2500 *hex
++ = tohex (*bin
++ & 0xf);
2506 /* Tell the remote machine to resume. */
2508 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2510 static int last_sent_step
;
2513 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2515 struct remote_state
*rs
= get_remote_state ();
2516 char *buf
= alloca (rs
->remote_packet_size
);
2517 int pid
= PIDGET (ptid
);
2521 set_thread (0, 0); /* run any thread */
2523 set_thread (pid
, 0); /* run this thread */
2525 last_sent_signal
= siggnal
;
2526 last_sent_step
= step
;
2528 /* A hook for when we need to do something at the last moment before
2530 if (target_resume_hook
)
2531 (*target_resume_hook
) ();
2534 /* The s/S/c/C packets do not return status. So if the target does
2535 not support the S or C packets, the debug agent returns an empty
2536 string which is detected in remote_wait(). This protocol defect
2537 is fixed in the e/E packets. */
2539 if (step
&& step_range_end
)
2541 /* If the target does not support the 'E' packet, we try the 'S'
2542 packet. Ideally we would fall back to the 'e' packet if that
2543 too is not supported. But that would require another copy of
2544 the code to issue the 'e' packet (and fall back to 's' if not
2545 supported) in remote_wait(). */
2547 if (siggnal
!= TARGET_SIGNAL_0
)
2549 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2553 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2554 *p
++ = tohex (((int) siggnal
) & 0xf);
2556 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2558 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2562 getpkt (buf
, (rs
->remote_packet_size
), 0);
2564 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2570 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2574 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2576 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2580 getpkt (buf
, (rs
->remote_packet_size
), 0);
2582 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2588 if (siggnal
!= TARGET_SIGNAL_0
)
2590 buf
[0] = step
? 'S' : 'C';
2591 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2592 buf
[2] = tohex (((int) siggnal
) & 0xf);
2596 strcpy (buf
, step
? "s" : "c");
2601 /* Same as remote_resume, but with async support. */
2603 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2605 struct remote_state
*rs
= get_remote_state ();
2606 char *buf
= alloca (rs
->remote_packet_size
);
2607 int pid
= PIDGET (ptid
);
2611 set_thread (0, 0); /* run any thread */
2613 set_thread (pid
, 0); /* run this thread */
2615 last_sent_signal
= siggnal
;
2616 last_sent_step
= step
;
2618 /* A hook for when we need to do something at the last moment before
2620 if (target_resume_hook
)
2621 (*target_resume_hook
) ();
2623 /* The s/S/c/C packets do not return status. So if the target does
2624 not support the S or C packets, the debug agent returns an empty
2625 string which is detected in remote_wait(). This protocol defect
2626 is fixed in the e/E packets. */
2628 if (step
&& step_range_end
)
2630 /* If the target does not support the 'E' packet, we try the 'S'
2631 packet. Ideally we would fall back to the 'e' packet if that
2632 too is not supported. But that would require another copy of
2633 the code to issue the 'e' packet (and fall back to 's' if not
2634 supported) in remote_wait(). */
2636 if (siggnal
!= TARGET_SIGNAL_0
)
2638 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2642 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2643 *p
++ = tohex (((int) siggnal
) & 0xf);
2645 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2647 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2651 getpkt (buf
, (rs
->remote_packet_size
), 0);
2653 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2654 goto register_event_loop
;
2659 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2663 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2665 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2669 getpkt (buf
, (rs
->remote_packet_size
), 0);
2671 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2672 goto register_event_loop
;
2677 if (siggnal
!= TARGET_SIGNAL_0
)
2679 buf
[0] = step
? 'S' : 'C';
2680 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2681 buf
[2] = tohex ((int) siggnal
& 0xf);
2685 strcpy (buf
, step
? "s" : "c");
2689 register_event_loop
:
2690 /* We are about to start executing the inferior, let's register it
2691 with the event loop. NOTE: this is the one place where all the
2692 execution commands end up. We could alternatively do this in each
2693 of the execution commands in infcmd.c.*/
2694 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2695 into infcmd.c in order to allow inferior function calls to work
2696 NOT asynchronously. */
2697 if (event_loop_p
&& target_can_async_p ())
2698 target_async (inferior_event_handler
, 0);
2699 /* Tell the world that the target is now executing. */
2700 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2701 this? Instead, should the client of target just assume (for
2702 async targets) that the target is going to start executing? Is
2703 this information already found in the continuation block? */
2704 if (target_is_async_p ())
2705 target_executing
= 1;
2709 /* Set up the signal handler for SIGINT, while the target is
2710 executing, ovewriting the 'regular' SIGINT signal handler. */
2712 initialize_sigint_signal_handler (void)
2714 sigint_remote_token
=
2715 create_async_signal_handler (async_remote_interrupt
, NULL
);
2716 signal (SIGINT
, handle_remote_sigint
);
2719 /* Signal handler for SIGINT, while the target is executing. */
2721 handle_remote_sigint (int sig
)
2723 signal (sig
, handle_remote_sigint_twice
);
2724 sigint_remote_twice_token
=
2725 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2726 mark_async_signal_handler_wrapper (sigint_remote_token
);
2729 /* Signal handler for SIGINT, installed after SIGINT has already been
2730 sent once. It will take effect the second time that the user sends
2733 handle_remote_sigint_twice (int sig
)
2735 signal (sig
, handle_sigint
);
2736 sigint_remote_twice_token
=
2737 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2738 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2741 /* Perform the real interruption of the target execution, in response
2744 async_remote_interrupt (gdb_client_data arg
)
2747 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2752 /* Perform interrupt, if the first attempt did not succeed. Just give
2753 up on the target alltogether. */
2755 async_remote_interrupt_twice (gdb_client_data arg
)
2758 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2759 /* Do something only if the target was not killed by the previous
2761 if (target_executing
)
2764 signal (SIGINT
, handle_remote_sigint
);
2768 /* Reinstall the usual SIGINT handlers, after the target has
2771 cleanup_sigint_signal_handler (void *dummy
)
2773 signal (SIGINT
, handle_sigint
);
2774 if (sigint_remote_twice_token
)
2775 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2776 if (sigint_remote_token
)
2777 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2780 /* Send ^C to target to halt it. Target will respond, and send us a
2782 static void (*ofunc
) (int);
2784 /* The command line interface's stop routine. This function is installed
2785 as a signal handler for SIGINT. The first time a user requests a
2786 stop, we call remote_stop to send a break or ^C. If there is no
2787 response from the target (it didn't stop when the user requested it),
2788 we ask the user if he'd like to detach from the target. */
2790 remote_interrupt (int signo
)
2792 /* If this doesn't work, try more severe steps. */
2793 signal (signo
, remote_interrupt_twice
);
2796 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2801 /* The user typed ^C twice. */
2804 remote_interrupt_twice (int signo
)
2806 signal (signo
, ofunc
);
2808 signal (signo
, remote_interrupt
);
2811 /* This is the generic stop called via the target vector. When a target
2812 interrupt is requested, either by the command line or the GUI, we
2813 will eventually end up here. */
2817 /* Send a break or a ^C, depending on user preference. */
2819 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2822 serial_send_break (remote_desc
);
2824 serial_write (remote_desc
, "\003", 1);
2827 /* Ask the user what to do when an interrupt is received. */
2830 interrupt_query (void)
2832 target_terminal_ours ();
2834 if (query ("Interrupted while waiting for the program.\n\
2835 Give up (and stop debugging it)? "))
2837 target_mourn_inferior ();
2838 throw_exception (RETURN_QUIT
);
2841 target_terminal_inferior ();
2844 /* Enable/disable target terminal ownership. Most targets can use
2845 terminal groups to control terminal ownership. Remote targets are
2846 different in that explicit transfer of ownership to/from GDB/target
2850 remote_async_terminal_inferior (void)
2852 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2853 sync_execution here. This function should only be called when
2854 GDB is resuming the inferior in the forground. A background
2855 resume (``run&'') should leave GDB in control of the terminal and
2856 consequently should not call this code. */
2857 if (!sync_execution
)
2859 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2860 calls target_terminal_*() idenpotent. The event-loop GDB talking
2861 to an asynchronous target with a synchronous command calls this
2862 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2863 stops trying to transfer the terminal to the target when it
2864 shouldn't this guard can go away. */
2865 if (!remote_async_terminal_ours_p
)
2867 delete_file_handler (input_fd
);
2868 remote_async_terminal_ours_p
= 0;
2869 initialize_sigint_signal_handler ();
2870 /* NOTE: At this point we could also register our selves as the
2871 recipient of all input. Any characters typed could then be
2872 passed on down to the target. */
2876 remote_async_terminal_ours (void)
2878 /* See FIXME in remote_async_terminal_inferior. */
2879 if (!sync_execution
)
2881 /* See FIXME in remote_async_terminal_inferior. */
2882 if (remote_async_terminal_ours_p
)
2884 cleanup_sigint_signal_handler (NULL
);
2885 add_file_handler (input_fd
, stdin_event_handler
, 0);
2886 remote_async_terminal_ours_p
= 1;
2889 /* If nonzero, ignore the next kill. */
2894 remote_console_output (char *msg
)
2898 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2901 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2904 fputs_unfiltered (tb
, gdb_stdtarg
);
2906 gdb_flush (gdb_stdtarg
);
2909 /* Wait until the remote machine stops, then return,
2910 storing status in STATUS just as `wait' would.
2911 Returns "pid", which in the case of a multi-threaded
2912 remote OS, is the thread-id. */
2915 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2917 struct remote_state
*rs
= get_remote_state ();
2918 unsigned char *buf
= alloca (rs
->remote_packet_size
);
2919 ULONGEST thread_num
= -1;
2922 status
->kind
= TARGET_WAITKIND_EXITED
;
2923 status
->value
.integer
= 0;
2929 ofunc
= signal (SIGINT
, remote_interrupt
);
2930 getpkt (buf
, (rs
->remote_packet_size
), 1);
2931 signal (SIGINT
, ofunc
);
2933 /* This is a hook for when we need to do something (perhaps the
2934 collection of trace data) every time the target stops. */
2935 if (target_wait_loop_hook
)
2936 (*target_wait_loop_hook
) ();
2938 remote_stopped_by_watchpoint_p
= 0;
2942 case 'E': /* Error of some sort */
2943 warning ("Remote failure reply: %s", buf
);
2945 case 'F': /* File-I/O request */
2946 remote_fileio_request (buf
);
2948 case 'T': /* Status with PC, SP, FP, ... */
2951 char regs
[MAX_REGISTER_SIZE
];
2953 /* Expedited reply, containing Signal, {regno, reg} repeat */
2954 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2956 n... = register number
2957 r... = register contents
2959 p
= &buf
[3]; /* after Txx */
2968 /* If the packet contains a register number save it in pnum
2969 and set p1 to point to the character following it.
2970 Otherwise p1 points to p. */
2972 /* If this packet is an awatch packet, don't parse the 'a'
2973 as a register number. */
2975 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
2977 /* Read the ``P'' register number. */
2978 pnum
= strtol (p
, &p_temp
, 16);
2979 p1
= (unsigned char *) p_temp
;
2984 if (p1
== p
) /* No register number present here */
2986 p1
= (unsigned char *) strchr (p
, ':');
2988 warning ("Malformed packet(a) (missing colon): %s\n\
2991 if (strncmp (p
, "thread", p1
- p
) == 0)
2993 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2994 record_currthread (thread_num
);
2995 p
= (unsigned char *) p_temp
;
2997 else if ((strncmp (p
, "watch", p1
- p
) == 0)
2998 || (strncmp (p
, "rwatch", p1
- p
) == 0)
2999 || (strncmp (p
, "awatch", p1
- p
) == 0))
3001 remote_stopped_by_watchpoint_p
= 1;
3002 p
= unpack_varlen_hex (++p1
, &addr
);
3003 remote_watch_data_address
= (CORE_ADDR
)addr
;
3007 /* Silently skip unknown optional info. */
3008 p_temp
= strchr (p1
+ 1, ';');
3010 p
= (unsigned char *) p_temp
;
3015 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3019 error ("Malformed packet(b) (missing colon): %s\nPacket: '%s'\n",
3023 error ("Remote sent bad register number %s: %s\nPacket: '%s'\n",
3024 phex_nz (pnum
, 0), p
, buf
);
3026 fieldsize
= hex2bin (p
, regs
, DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
));
3028 if (fieldsize
< DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
))
3029 warning ("Remote reply is too short: %s", buf
);
3030 supply_register (reg
->regnum
, regs
);
3034 error ("Remote register badly formatted: %s\nhere: %s", buf
, p
);
3038 case 'S': /* Old style status, just signal only */
3039 status
->kind
= TARGET_WAITKIND_STOPPED
;
3040 status
->value
.sig
= (enum target_signal
)
3041 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3045 /* Export Cisco kernel mode as a convenience variable
3046 (so that it can be used in the GDB prompt if desired). */
3048 if (cisco_kernel_mode
== 1)
3049 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3050 value_from_string ("PDEBUG-"));
3051 cisco_kernel_mode
= 0;
3052 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3053 record_currthread (thread_num
);
3055 else if (buf
[3] == 'k')
3057 /* Export Cisco kernel mode as a convenience variable
3058 (so that it can be used in the GDB prompt if desired). */
3060 if (cisco_kernel_mode
== 1)
3061 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3062 value_from_string ("KDEBUG-"));
3063 cisco_kernel_mode
= 1;
3066 case 'N': /* Cisco special: status and offsets */
3068 bfd_vma text_addr
, data_addr
, bss_addr
;
3069 bfd_signed_vma text_off
, data_off
, bss_off
;
3072 status
->kind
= TARGET_WAITKIND_STOPPED
;
3073 status
->value
.sig
= (enum target_signal
)
3074 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3076 if (symfile_objfile
== NULL
)
3078 warning ("Relocation packet received with no symbol file. \
3083 /* Relocate object file. Buffer format is NAATT;DD;BB
3084 * where AA is the signal number, TT is the new text
3085 * address, DD * is the new data address, and BB is the
3086 * new bss address. */
3089 text_addr
= strtoul (p
, (char **) &p1
, 16);
3090 if (p1
== p
|| *p1
!= ';')
3091 warning ("Malformed relocation packet: Packet '%s'", buf
);
3093 data_addr
= strtoul (p
, (char **) &p1
, 16);
3094 if (p1
== p
|| *p1
!= ';')
3095 warning ("Malformed relocation packet: Packet '%s'", buf
);
3097 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3099 warning ("Malformed relocation packet: Packet '%s'", buf
);
3101 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3102 &text_off
, &data_off
, &bss_off
)
3104 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3105 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3109 case 'W': /* Target exited */
3111 /* The remote process exited. */
3112 status
->kind
= TARGET_WAITKIND_EXITED
;
3113 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3117 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3118 status
->value
.sig
= (enum target_signal
)
3119 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3123 case 'O': /* Console output */
3124 remote_console_output (buf
+ 1);
3127 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3129 /* Zero length reply means that we tried 'S' or 'C' and
3130 the remote system doesn't support it. */
3131 target_terminal_ours_for_output ();
3133 ("Can't send signals to this remote system. %s not sent.\n",
3134 target_signal_to_name (last_sent_signal
));
3135 last_sent_signal
= TARGET_SIGNAL_0
;
3136 target_terminal_inferior ();
3138 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3139 putpkt ((char *) buf
);
3142 /* else fallthrough */
3144 warning ("Invalid remote reply: %s", buf
);
3149 if (thread_num
!= -1)
3151 return pid_to_ptid (thread_num
);
3153 return inferior_ptid
;
3156 /* Async version of remote_wait. */
3158 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3160 struct remote_state
*rs
= get_remote_state ();
3161 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3162 ULONGEST thread_num
= -1;
3165 status
->kind
= TARGET_WAITKIND_EXITED
;
3166 status
->value
.integer
= 0;
3168 remote_stopped_by_watchpoint_p
= 0;
3174 if (!target_is_async_p ())
3175 ofunc
= signal (SIGINT
, remote_interrupt
);
3176 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3177 _never_ wait for ever -> test on target_is_async_p().
3178 However, before we do that we need to ensure that the caller
3179 knows how to take the target into/out of async mode. */
3180 getpkt (buf
, (rs
->remote_packet_size
), wait_forever_enabled_p
);
3181 if (!target_is_async_p ())
3182 signal (SIGINT
, ofunc
);
3184 /* This is a hook for when we need to do something (perhaps the
3185 collection of trace data) every time the target stops. */
3186 if (target_wait_loop_hook
)
3187 (*target_wait_loop_hook
) ();
3191 case 'E': /* Error of some sort */
3192 warning ("Remote failure reply: %s", buf
);
3194 case 'F': /* File-I/O request */
3195 remote_fileio_request (buf
);
3197 case 'T': /* Status with PC, SP, FP, ... */
3200 char regs
[MAX_REGISTER_SIZE
];
3202 /* Expedited reply, containing Signal, {regno, reg} repeat */
3203 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3205 n... = register number
3206 r... = register contents
3208 p
= &buf
[3]; /* after Txx */
3217 /* If the packet contains a register number, save it in pnum
3218 and set p1 to point to the character following it.
3219 Otherwise p1 points to p. */
3221 /* If this packet is an awatch packet, don't parse the 'a'
3222 as a register number. */
3224 if (!strncmp (p
, "awatch", strlen ("awatch")) != 0)
3226 /* Read the register number. */
3227 pnum
= strtol (p
, &p_temp
, 16);
3228 p1
= (unsigned char *) p_temp
;
3233 if (p1
== p
) /* No register number present here */
3235 p1
= (unsigned char *) strchr (p
, ':');
3237 error ("Malformed packet(a) (missing colon): %s\nPacket: '%s'\n",
3239 if (strncmp (p
, "thread", p1
- p
) == 0)
3241 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3242 record_currthread (thread_num
);
3243 p
= (unsigned char *) p_temp
;
3245 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3246 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3247 || (strncmp (p
, "awatch", p1
- p
) == 0))
3249 remote_stopped_by_watchpoint_p
= 1;
3250 p
= unpack_varlen_hex (++p1
, &addr
);
3251 remote_watch_data_address
= (CORE_ADDR
)addr
;
3255 /* Silently skip unknown optional info. */
3256 p_temp
= (unsigned char *) strchr (p1
+ 1, ';');
3264 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3267 error ("Malformed packet(b) (missing colon): %s\nPacket: '%s'\n",
3271 error ("Remote sent bad register number %ld: %s\nPacket: '%s'\n",
3274 fieldsize
= hex2bin (p
, regs
, DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
));
3276 if (fieldsize
< DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
))
3277 warning ("Remote reply is too short: %s", buf
);
3278 supply_register (reg
->regnum
, regs
);
3282 error ("Remote register badly formatted: %s\nhere: %s",
3287 case 'S': /* Old style status, just signal only */
3288 status
->kind
= TARGET_WAITKIND_STOPPED
;
3289 status
->value
.sig
= (enum target_signal
)
3290 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3294 /* Export Cisco kernel mode as a convenience variable
3295 (so that it can be used in the GDB prompt if desired). */
3297 if (cisco_kernel_mode
== 1)
3298 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3299 value_from_string ("PDEBUG-"));
3300 cisco_kernel_mode
= 0;
3301 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3302 record_currthread (thread_num
);
3304 else if (buf
[3] == 'k')
3306 /* Export Cisco kernel mode as a convenience variable
3307 (so that it can be used in the GDB prompt if desired). */
3309 if (cisco_kernel_mode
== 1)
3310 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3311 value_from_string ("KDEBUG-"));
3312 cisco_kernel_mode
= 1;
3315 case 'N': /* Cisco special: status and offsets */
3317 bfd_vma text_addr
, data_addr
, bss_addr
;
3318 bfd_signed_vma text_off
, data_off
, bss_off
;
3321 status
->kind
= TARGET_WAITKIND_STOPPED
;
3322 status
->value
.sig
= (enum target_signal
)
3323 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3325 if (symfile_objfile
== NULL
)
3327 warning ("Relocation packet recieved with no symbol file. \
3332 /* Relocate object file. Buffer format is NAATT;DD;BB
3333 * where AA is the signal number, TT is the new text
3334 * address, DD * is the new data address, and BB is the
3335 * new bss address. */
3338 text_addr
= strtoul (p
, (char **) &p1
, 16);
3339 if (p1
== p
|| *p1
!= ';')
3340 warning ("Malformed relocation packet: Packet '%s'", buf
);
3342 data_addr
= strtoul (p
, (char **) &p1
, 16);
3343 if (p1
== p
|| *p1
!= ';')
3344 warning ("Malformed relocation packet: Packet '%s'", buf
);
3346 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3348 warning ("Malformed relocation packet: Packet '%s'", buf
);
3350 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3351 &text_off
, &data_off
, &bss_off
)
3353 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3354 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3358 case 'W': /* Target exited */
3360 /* The remote process exited. */
3361 status
->kind
= TARGET_WAITKIND_EXITED
;
3362 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3366 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3367 status
->value
.sig
= (enum target_signal
)
3368 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3372 case 'O': /* Console output */
3373 remote_console_output (buf
+ 1);
3374 /* Return immediately to the event loop. The event loop will
3375 still be waiting on the inferior afterwards. */
3376 status
->kind
= TARGET_WAITKIND_IGNORE
;
3379 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3381 /* Zero length reply means that we tried 'S' or 'C' and
3382 the remote system doesn't support it. */
3383 target_terminal_ours_for_output ();
3385 ("Can't send signals to this remote system. %s not sent.\n",
3386 target_signal_to_name (last_sent_signal
));
3387 last_sent_signal
= TARGET_SIGNAL_0
;
3388 target_terminal_inferior ();
3390 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3391 putpkt ((char *) buf
);
3394 /* else fallthrough */
3396 warning ("Invalid remote reply: %s", buf
);
3401 if (thread_num
!= -1)
3403 return pid_to_ptid (thread_num
);
3405 return inferior_ptid
;
3408 /* Number of bytes of registers this stub implements. */
3410 static int register_bytes_found
;
3412 /* Read the remote registers into the block REGS. */
3413 /* Currently we just read all the registers, so we don't use regnum. */
3416 remote_fetch_registers (int regnum
)
3418 struct remote_state
*rs
= get_remote_state ();
3419 char *buf
= alloca (rs
->remote_packet_size
);
3422 char *regs
= alloca (rs
->sizeof_g_packet
);
3424 set_thread (PIDGET (inferior_ptid
), 1);
3428 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3429 gdb_assert (reg
!= NULL
);
3430 if (!reg
->in_g_packet
)
3431 internal_error (__FILE__
, __LINE__
,
3432 "Attempt to fetch a non G-packet register when this "
3433 "remote.c does not support the p-packet.");
3437 remote_send (buf
, (rs
->remote_packet_size
));
3439 /* Save the size of the packet sent to us by the target. Its used
3440 as a heuristic when determining the max size of packets that the
3441 target can safely receive. */
3442 if ((rs
->actual_register_packet_size
) == 0)
3443 (rs
->actual_register_packet_size
) = strlen (buf
);
3445 /* Unimplemented registers read as all bits zero. */
3446 memset (regs
, 0, rs
->sizeof_g_packet
);
3448 /* We can get out of synch in various cases. If the first character
3449 in the buffer is not a hex character, assume that has happened
3450 and try to fetch another packet to read. */
3451 while ((buf
[0] < '0' || buf
[0] > '9')
3452 && (buf
[0] < 'a' || buf
[0] > 'f')
3453 && buf
[0] != 'x') /* New: unavailable register value */
3456 fprintf_unfiltered (gdb_stdlog
,
3457 "Bad register packet; fetching a new packet\n");
3458 getpkt (buf
, (rs
->remote_packet_size
), 0);
3461 /* Reply describes registers byte by byte, each byte encoded as two
3462 hex characters. Suck them all up, then supply them to the
3463 register cacheing/storage mechanism. */
3466 for (i
= 0; i
< rs
->sizeof_g_packet
; i
++)
3472 warning ("Remote reply is of odd length: %s", buf
);
3473 /* Don't change register_bytes_found in this case, and don't
3474 print a second warning. */
3477 if (p
[0] == 'x' && p
[1] == 'x')
3478 regs
[i
] = 0; /* 'x' */
3480 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3484 if (i
!= register_bytes_found
)
3486 register_bytes_found
= i
;
3487 if (REGISTER_BYTES_OK_P ()
3488 && !REGISTER_BYTES_OK (i
))
3489 warning ("Remote reply is too short: %s", buf
);
3495 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3497 struct packet_reg
*r
= &rs
->regs
[i
];
3500 supply_register (r
->regnum
, regs
+ r
->offset
);
3501 if (buf
[r
->offset
* 2] == 'x')
3502 set_register_cached (i
, -1);
3508 /* Prepare to store registers. Since we may send them all (using a
3509 'G' request), we have to read out the ones we don't want to change
3513 remote_prepare_to_store (void)
3515 struct remote_state
*rs
= get_remote_state ();
3517 char buf
[MAX_REGISTER_SIZE
];
3519 /* Make sure the entire registers array is valid. */
3520 switch (remote_protocol_P
.support
)
3522 case PACKET_DISABLE
:
3523 case PACKET_SUPPORT_UNKNOWN
:
3524 /* Make sure all the necessary registers are cached. */
3525 for (i
= 0; i
< NUM_REGS
; i
++)
3526 if (rs
->regs
[i
].in_g_packet
)
3527 regcache_raw_read (current_regcache
, rs
->regs
[i
].regnum
, buf
);
3534 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3535 packet was not recognized. */
3538 store_register_using_P (int regnum
)
3540 struct remote_state
*rs
= get_remote_state ();
3541 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3542 /* Try storing a single register. */
3543 char *buf
= alloca (rs
->remote_packet_size
);
3544 char regp
[MAX_REGISTER_SIZE
];
3548 sprintf (buf
, "P%s=", phex_nz (reg
->pnum
, 0));
3549 p
= buf
+ strlen (buf
);
3550 regcache_collect (reg
->regnum
, regp
);
3551 bin2hex (regp
, p
, DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
));
3552 remote_send (buf
, rs
->remote_packet_size
);
3554 return buf
[0] != '\0';
3558 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
3559 of the register cache buffer. FIXME: ignores errors. */
3562 remote_store_registers (int regnum
)
3564 struct remote_state
*rs
= get_remote_state ();
3570 set_thread (PIDGET (inferior_ptid
), 1);
3574 switch (remote_protocol_P
.support
)
3576 case PACKET_DISABLE
:
3579 if (store_register_using_P (regnum
))
3582 error ("Protocol error: P packet not recognized by stub");
3583 case PACKET_SUPPORT_UNKNOWN
:
3584 if (store_register_using_P (regnum
))
3586 /* The stub recognized the 'P' packet. Remember this. */
3587 remote_protocol_P
.support
= PACKET_ENABLE
;
3592 /* The stub does not support the 'P' packet. Use 'G'
3593 instead, and don't try using 'P' in the future (it
3594 will just waste our time). */
3595 remote_protocol_P
.support
= PACKET_DISABLE
;
3601 /* Extract all the registers in the regcache copying them into a
3605 regs
= alloca (rs
->sizeof_g_packet
);
3606 memset (regs
, rs
->sizeof_g_packet
, 0);
3607 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3609 struct packet_reg
*r
= &rs
->regs
[i
];
3611 regcache_collect (r
->regnum
, regs
+ r
->offset
);
3615 /* Command describes registers byte by byte,
3616 each byte encoded as two hex characters. */
3617 buf
= alloca (rs
->remote_packet_size
);
3620 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3621 bin2hex (regs
, p
, register_bytes_found
);
3622 remote_send (buf
, (rs
->remote_packet_size
));
3626 /* Return the number of hex digits in num. */
3629 hexnumlen (ULONGEST num
)
3633 for (i
= 0; num
!= 0; i
++)
3639 /* Set BUF to the minimum number of hex digits representing NUM. */
3642 hexnumstr (char *buf
, ULONGEST num
)
3644 int len
= hexnumlen (num
);
3645 return hexnumnstr (buf
, num
, len
);
3649 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3652 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3658 for (i
= width
- 1; i
>= 0; i
--)
3660 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3667 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3670 remote_address_masked (CORE_ADDR addr
)
3672 if (remote_address_size
> 0
3673 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3675 /* Only create a mask when that mask can safely be constructed
3676 in a ULONGEST variable. */
3678 mask
= (mask
<< remote_address_size
) - 1;
3684 /* Determine whether the remote target supports binary downloading.
3685 This is accomplished by sending a no-op memory write of zero length
3686 to the target at the specified address. It does not suffice to send
3687 the whole packet, since many stubs strip the eighth bit and subsequently
3688 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3690 NOTE: This can still lose if the serial line is not eight-bit
3691 clean. In cases like this, the user should clear "remote
3695 check_binary_download (CORE_ADDR addr
)
3697 struct remote_state
*rs
= get_remote_state ();
3698 switch (remote_protocol_binary_download
.support
)
3700 case PACKET_DISABLE
:
3704 case PACKET_SUPPORT_UNKNOWN
:
3706 char *buf
= alloca (rs
->remote_packet_size
);
3711 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3713 p
+= hexnumstr (p
, (ULONGEST
) 0);
3717 putpkt_binary (buf
, (int) (p
- buf
));
3718 getpkt (buf
, (rs
->remote_packet_size
), 0);
3723 fprintf_unfiltered (gdb_stdlog
,
3724 "binary downloading NOT suppported by target\n");
3725 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3730 fprintf_unfiltered (gdb_stdlog
,
3731 "binary downloading suppported by target\n");
3732 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3739 /* Write memory data directly to the remote machine.
3740 This does not inform the data cache; the data cache uses this.
3741 MEMADDR is the address in the remote memory space.
3742 MYADDR is the address of the buffer in our space.
3743 LEN is the number of bytes.
3745 Returns number of bytes transferred, or 0 (setting errno) for
3746 error. Only transfer a single packet. */
3749 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3753 unsigned char *plen
;
3759 unsigned char *payload_start
;
3761 /* Verify that the target can support a binary download. */
3762 check_binary_download (memaddr
);
3764 /* Compute the size, and then allocate space for the largest
3765 possible packet. Include space for an extra trailing NUL. */
3766 sizeof_buf
= get_memory_write_packet_size () + 1;
3767 buf
= alloca (sizeof_buf
);
3769 /* Compute the size of the actual payload by subtracting out the
3770 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
3771 payload_size
= (get_memory_write_packet_size () - (strlen ("$M,:#NN")
3772 + hexnumlen (memaddr
)
3773 + hexnumlen (len
)));
3775 /* Construct the packet header: "[MX]<memaddr>,<len>:". */
3777 /* Append "[XM]". Compute a best guess of the number of bytes
3778 actually transfered. */
3780 switch (remote_protocol_binary_download
.support
)
3784 /* Best guess at number of bytes that will fit. */
3785 todo
= min (len
, payload_size
);
3787 case PACKET_DISABLE
:
3789 /* num bytes that will fit */
3790 todo
= min (len
, payload_size
/ 2);
3792 case PACKET_SUPPORT_UNKNOWN
:
3793 internal_error (__FILE__
, __LINE__
,
3794 "remote_write_bytes: bad internal state");
3796 internal_error (__FILE__
, __LINE__
, "bad switch");
3799 /* Append "<memaddr>". */
3800 memaddr
= remote_address_masked (memaddr
);
3801 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3806 /* Append <len>. Retain the location/size of <len>. It may need to
3807 be adjusted once the packet body has been created. */
3809 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3816 /* Append the packet body. */
3818 switch (remote_protocol_binary_download
.support
)
3821 /* Binary mode. Send target system values byte by byte, in
3822 increasing byte addresses. Only escape certain critical
3825 (nr_bytes
< todo
) && (p
- payload_start
) < payload_size
;
3828 switch (myaddr
[nr_bytes
] & 0xff)
3833 /* These must be escaped */
3835 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3838 *p
++ = myaddr
[nr_bytes
] & 0xff;
3842 if (nr_bytes
< todo
)
3844 /* Escape chars have filled up the buffer prematurely,
3845 and we have actually sent fewer bytes than planned.
3846 Fix-up the length field of the packet. Use the same
3847 number of characters as before. */
3848 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3849 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3852 case PACKET_DISABLE
:
3853 /* Normal mode: Send target system values byte by byte, in
3854 increasing byte addresses. Each byte is encoded as a two hex
3856 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3859 case PACKET_SUPPORT_UNKNOWN
:
3860 internal_error (__FILE__
, __LINE__
,
3861 "remote_write_bytes: bad internal state");
3863 internal_error (__FILE__
, __LINE__
, "bad switch");
3866 putpkt_binary (buf
, (int) (p
- buf
));
3867 getpkt (buf
, sizeof_buf
, 0);
3871 /* There is no correspondance between what the remote protocol
3872 uses for errors and errno codes. We would like a cleaner way
3873 of representing errors (big enough to include errno codes,
3874 bfd_error codes, and others). But for now just return EIO. */
3879 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3880 bytes than we'd planned. */
3884 /* Read memory data directly from the remote machine.
3885 This does not use the data cache; the data cache uses this.
3886 MEMADDR is the address in the remote memory space.
3887 MYADDR is the address of the buffer in our space.
3888 LEN is the number of bytes.
3890 Returns number of bytes transferred, or 0 for error. */
3892 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3893 remote targets) shouldn't attempt to read the entire buffer.
3894 Instead it should read a single packet worth of data and then
3895 return the byte size of that packet to the caller. The caller (its
3896 caller and its callers caller ;-) already contains code for
3897 handling partial reads. */
3900 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3903 int max_buf_size
; /* Max size of packet output buffer */
3907 /* Create a buffer big enough for this packet. */
3908 max_buf_size
= get_memory_read_packet_size ();
3909 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3910 buf
= alloca (sizeof_buf
);
3919 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3921 /* construct "m"<memaddr>","<len>" */
3922 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3923 memaddr
= remote_address_masked (memaddr
);
3926 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3928 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3932 getpkt (buf
, sizeof_buf
, 0);
3935 && isxdigit (buf
[1]) && isxdigit (buf
[2])
3938 /* There is no correspondance between what the remote protocol uses
3939 for errors and errno codes. We would like a cleaner way of
3940 representing errors (big enough to include errno codes, bfd_error
3941 codes, and others). But for now just return EIO. */
3946 /* Reply describes memory byte by byte,
3947 each byte encoded as two hex characters. */
3950 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
3952 /* Reply is short. This means that we were able to read
3953 only part of what we wanted to. */
3954 return i
+ (origlen
- len
);
3963 /* Read or write LEN bytes from inferior memory at MEMADDR,
3964 transferring to or from debugger address BUFFER. Write to inferior if
3965 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3966 for error. TARGET is unused. */
3969 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
3970 int should_write
, struct mem_attrib
*attrib
,
3971 struct target_ops
*target
)
3973 CORE_ADDR targ_addr
;
3977 /* Should this be the selected frame? */
3978 gdbarch_remote_translate_xfer_address (current_gdbarch
, current_regcache
,
3980 &targ_addr
, &targ_len
);
3985 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
3987 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
3994 /* Enable after 4.12. */
3997 remote_search (int len
, char *data
, char *mask
, CORE_ADDR startaddr
,
3998 int increment
, CORE_ADDR lorange
, CORE_ADDR hirange
,
3999 CORE_ADDR
*addr_found
, char *data_found
)
4001 if (increment
== -4 && len
== 4)
4003 long mask_long
, data_long
;
4004 long data_found_long
;
4005 CORE_ADDR addr_we_found
;
4006 char *buf
= alloca (rs
->remote_packet_size
);
4007 long returned_long
[2];
4010 mask_long
= extract_unsigned_integer (mask
, len
);
4011 data_long
= extract_unsigned_integer (data
, len
);
4012 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
4014 getpkt (buf
, (rs
->remote_packet_size
), 0);
4017 /* The stub doesn't support the 't' request. We might want to
4018 remember this fact, but on the other hand the stub could be
4019 switched on us. Maybe we should remember it only until
4020 the next "target remote". */
4021 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
4022 hirange
, addr_found
, data_found
);
4027 /* There is no correspondance between what the remote protocol uses
4028 for errors and errno codes. We would like a cleaner way of
4029 representing errors (big enough to include errno codes, bfd_error
4030 codes, and others). But for now just use EIO. */
4031 memory_error (EIO
, startaddr
);
4034 while (*p
!= '\0' && *p
!= ',')
4035 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
4037 error ("Protocol error: short return for search");
4039 data_found_long
= 0;
4040 while (*p
!= '\0' && *p
!= ',')
4041 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
4042 /* Ignore anything after this comma, for future extensions. */
4044 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
4050 *addr_found
= addr_we_found
;
4051 *data_found
= store_unsigned_integer (data_we_found
, len
);
4054 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
4055 hirange
, addr_found
, data_found
);
4060 remote_files_info (struct target_ops
*ignore
)
4062 puts_filtered ("Debugging a target over a serial line.\n");
4065 /* Stuff for dealing with the packets which are part of this protocol.
4066 See comment at top of file for details. */
4068 /* Read a single character from the remote end, masking it down to 7 bits. */
4071 readchar (int timeout
)
4075 ch
= serial_readchar (remote_desc
, timeout
);
4080 switch ((enum serial_rc
) ch
)
4083 target_mourn_inferior ();
4084 error ("Remote connection closed");
4087 perror_with_name ("Remote communication error");
4089 case SERIAL_TIMEOUT
:
4095 /* Send the command in BUF to the remote machine, and read the reply
4096 into BUF. Report an error if we get an error reply. */
4099 remote_send (char *buf
,
4103 getpkt (buf
, sizeof_buf
, 0);
4106 error ("Remote failure reply: %s", buf
);
4109 /* Display a null-terminated packet on stdout, for debugging, using C
4113 print_packet (char *buf
)
4115 puts_filtered ("\"");
4116 fputstr_filtered (buf
, '"', gdb_stdout
);
4117 puts_filtered ("\"");
4123 return putpkt_binary (buf
, strlen (buf
));
4126 /* Send a packet to the remote machine, with error checking. The data
4127 of the packet is in BUF. The string in BUF can be at most (rs->remote_packet_size) - 5
4128 to account for the $, # and checksum, and for a possible /0 if we are
4129 debugging (remote_debug) and want to print the sent packet as a string */
4132 putpkt_binary (char *buf
, int cnt
)
4134 struct remote_state
*rs
= get_remote_state ();
4136 unsigned char csum
= 0;
4137 char *buf2
= alloca (cnt
+ 6);
4138 long sizeof_junkbuf
= (rs
->remote_packet_size
);
4139 char *junkbuf
= alloca (sizeof_junkbuf
);
4145 /* Copy the packet into buffer BUF2, encapsulating it
4146 and giving it a checksum. */
4151 for (i
= 0; i
< cnt
; i
++)
4157 *p
++ = tohex ((csum
>> 4) & 0xf);
4158 *p
++ = tohex (csum
& 0xf);
4160 /* Send it over and over until we get a positive ack. */
4164 int started_error_output
= 0;
4169 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4170 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4171 fprintf_unfiltered (gdb_stdlog
, "...");
4172 gdb_flush (gdb_stdlog
);
4174 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4175 perror_with_name ("putpkt: write failed");
4177 /* read until either a timeout occurs (-2) or '+' is read */
4180 ch
= readchar (remote_timeout
);
4188 case SERIAL_TIMEOUT
:
4190 if (started_error_output
)
4192 putchar_unfiltered ('\n');
4193 started_error_output
= 0;
4202 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4206 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4207 case SERIAL_TIMEOUT
:
4211 break; /* Retransmit buffer */
4215 fprintf_unfiltered (gdb_stdlog
, "Packet instead of Ack, ignoring it\n");
4216 /* It's probably an old response, and we're out of sync.
4217 Just gobble up the packet and ignore it. */
4218 read_frame (junkbuf
, sizeof_junkbuf
);
4219 continue; /* Now, go look for + */
4224 if (!started_error_output
)
4226 started_error_output
= 1;
4227 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4229 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4233 break; /* Here to retransmit */
4237 /* This is wrong. If doing a long backtrace, the user should be
4238 able to get out next time we call QUIT, without anything as
4239 violent as interrupt_query. If we want to provide a way out of
4240 here without getting to the next QUIT, it should be based on
4241 hitting ^C twice as in remote_wait. */
4251 static int remote_cisco_mode
;
4253 /* Come here after finding the start of the frame. Collect the rest
4254 into BUF, verifying the checksum, length, and handling run-length
4255 compression. No more than sizeof_buf-1 characters are read so that
4256 the buffer can be NUL terminated.
4258 Returns -1 on error, number of characters in buffer (ignoring the
4259 trailing NULL) on success. (could be extended to return one of the
4260 SERIAL status indications). */
4263 read_frame (char *buf
,
4275 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
4276 c
= readchar (remote_timeout
);
4279 case SERIAL_TIMEOUT
:
4281 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4285 fputs_filtered ("Saw new packet start in middle of old one\n",
4287 return -1; /* Start a new packet, count retries */
4290 unsigned char pktcsum
;
4296 check_0
= readchar (remote_timeout
);
4298 check_1
= readchar (remote_timeout
);
4300 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4303 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog
);
4306 else if (check_0
< 0 || check_1
< 0)
4309 fputs_filtered ("Communication error in checksum\n", gdb_stdlog
);
4313 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4314 if (csum
== pktcsum
)
4319 fprintf_filtered (gdb_stdlog
,
4320 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4322 fputs_filtered (buf
, gdb_stdlog
);
4323 fputs_filtered ("\n", gdb_stdlog
);
4325 /* Number of characters in buffer ignoring trailing
4329 case '*': /* Run length encoding */
4334 if (remote_cisco_mode
== 0)
4336 c
= readchar (remote_timeout
);
4338 repeat
= c
- ' ' + 3; /* Compute repeat count */
4342 /* Cisco's run-length encoding variant uses two
4343 hex chars to represent the repeat count. */
4345 c
= readchar (remote_timeout
);
4347 repeat
= fromhex (c
) << 4;
4348 c
= readchar (remote_timeout
);
4350 repeat
+= fromhex (c
);
4353 /* The character before ``*'' is repeated. */
4355 if (repeat
> 0 && repeat
<= 255
4357 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4359 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4365 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
4366 puts_filtered (buf
);
4367 puts_filtered ("\n");
4371 if (bc
< sizeof_buf
- 1)
4379 puts_filtered ("Remote packet too long: ");
4380 puts_filtered (buf
);
4381 puts_filtered ("\n");
4388 /* Read a packet from the remote machine, with error checking, and
4389 store it in BUF. If FOREVER, wait forever rather than timing out;
4390 this is used (in synchronous mode) to wait for a target that is is
4391 executing user code to stop. */
4392 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4393 don't have to change all the calls to getpkt to deal with the
4394 return value, because at the moment I don't know what the right
4395 thing to do it for those. */
4403 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4407 /* Read a packet from the remote machine, with error checking, and
4408 store it in BUF. If FOREVER, wait forever rather than timing out;
4409 this is used (in synchronous mode) to wait for a target that is is
4410 executing user code to stop. If FOREVER == 0, this function is
4411 allowed to time out gracefully and return an indication of this to
4414 getpkt_sane (char *buf
,
4423 strcpy (buf
, "timeout");
4427 timeout
= watchdog
> 0 ? watchdog
: -1;
4431 timeout
= remote_timeout
;
4435 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4437 /* This can loop forever if the remote side sends us characters
4438 continuously, but if it pauses, we'll get a zero from readchar
4439 because of timeout. Then we'll count that as a retry. */
4441 /* Note that we will only wait forever prior to the start of a packet.
4442 After that, we expect characters to arrive at a brisk pace. They
4443 should show up within remote_timeout intervals. */
4447 c
= readchar (timeout
);
4449 if (c
== SERIAL_TIMEOUT
)
4451 if (forever
) /* Watchdog went off? Kill the target. */
4454 target_mourn_inferior ();
4455 error ("Watchdog has expired. Target detached.\n");
4458 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4464 /* We've found the start of a packet, now collect the data. */
4466 val
= read_frame (buf
, sizeof_buf
);
4472 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4473 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4474 fprintf_unfiltered (gdb_stdlog
, "\n");
4476 serial_write (remote_desc
, "+", 1);
4480 /* Try the whole thing again. */
4482 serial_write (remote_desc
, "-", 1);
4485 /* We have tried hard enough, and just can't receive the packet. Give up. */
4487 printf_unfiltered ("Ignoring packet error, continuing...\n");
4488 serial_write (remote_desc
, "+", 1);
4495 /* For some mysterious reason, wait_for_inferior calls kill instead of
4496 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4500 target_mourn_inferior ();
4504 /* Use catch_errors so the user can quit from gdb even when we aren't on
4505 speaking terms with the remote system. */
4506 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4508 /* Don't wait for it to die. I'm not really sure it matters whether
4509 we do or not. For the existing stubs, kill is a noop. */
4510 target_mourn_inferior ();
4513 /* Async version of remote_kill. */
4515 remote_async_kill (void)
4517 /* Unregister the file descriptor from the event loop. */
4518 if (target_is_async_p ())
4519 serial_async (remote_desc
, NULL
, 0);
4521 /* For some mysterious reason, wait_for_inferior calls kill instead of
4522 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4526 target_mourn_inferior ();
4530 /* Use catch_errors so the user can quit from gdb even when we aren't on
4531 speaking terms with the remote system. */
4532 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4534 /* Don't wait for it to die. I'm not really sure it matters whether
4535 we do or not. For the existing stubs, kill is a noop. */
4536 target_mourn_inferior ();
4542 remote_mourn_1 (&remote_ops
);
4546 remote_async_mourn (void)
4548 remote_mourn_1 (&remote_async_ops
);
4552 extended_remote_mourn (void)
4554 /* We do _not_ want to mourn the target like this; this will
4555 remove the extended remote target from the target stack,
4556 and the next time the user says "run" it'll fail.
4558 FIXME: What is the right thing to do here? */
4560 remote_mourn_1 (&extended_remote_ops
);
4564 /* Worker function for remote_mourn. */
4566 remote_mourn_1 (struct target_ops
*target
)
4568 unpush_target (target
);
4569 generic_mourn_inferior ();
4572 /* In the extended protocol we want to be able to do things like
4573 "run" and have them basically work as expected. So we need
4574 a special create_inferior function.
4576 FIXME: One day add support for changing the exec file
4577 we're debugging, arguments and an environment. */
4580 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
)
4582 /* Rip out the breakpoints; we'll reinsert them after restarting
4583 the remote server. */
4584 remove_breakpoints ();
4586 /* Now restart the remote server. */
4587 extended_remote_restart ();
4589 /* Now put the breakpoints back in. This way we're safe if the
4590 restart function works via a unix fork on the remote side. */
4591 insert_breakpoints ();
4593 /* Clean up from the last time we were running. */
4594 clear_proceed_status ();
4596 /* Let the remote process run. */
4597 proceed (-1, TARGET_SIGNAL_0
, 0);
4600 /* Async version of extended_remote_create_inferior. */
4602 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
)
4604 /* Rip out the breakpoints; we'll reinsert them after restarting
4605 the remote server. */
4606 remove_breakpoints ();
4608 /* If running asynchronously, register the target file descriptor
4609 with the event loop. */
4610 if (event_loop_p
&& target_can_async_p ())
4611 target_async (inferior_event_handler
, 0);
4613 /* Now restart the remote server. */
4614 extended_remote_restart ();
4616 /* Now put the breakpoints back in. This way we're safe if the
4617 restart function works via a unix fork on the remote side. */
4618 insert_breakpoints ();
4620 /* Clean up from the last time we were running. */
4621 clear_proceed_status ();
4623 /* Let the remote process run. */
4624 proceed (-1, TARGET_SIGNAL_0
, 0);
4628 /* On some machines, e.g. 68k, we may use a different breakpoint
4629 instruction than other targets; in those use
4630 DEPRECATED_REMOTE_BREAKPOINT instead of just BREAKPOINT_FROM_PC.
4631 Also, bi-endian targets may define
4632 DEPRECATED_LITTLE_REMOTE_BREAKPOINT and
4633 DEPRECATED_BIG_REMOTE_BREAKPOINT. If none of these are defined, we
4634 just call the standard routines that are in mem-break.c. */
4636 /* NOTE: cagney/2003-06-08: This is silly. A remote and simulator
4637 target should use an identical BREAKPOINT_FROM_PC. As for native,
4638 the ARCH-OS-tdep.c code can override the default. */
4640 #if defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) && !defined(DEPRECATED_REMOTE_BREAKPOINT)
4641 #define DEPRECATED_REMOTE_BREAKPOINT
4644 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4646 /* If the target isn't bi-endian, just pretend it is. */
4647 #if !defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && !defined (DEPRECATED_BIG_REMOTE_BREAKPOINT)
4648 #define DEPRECATED_LITTLE_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4649 #define DEPRECATED_BIG_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4652 static unsigned char big_break_insn
[] = DEPRECATED_BIG_REMOTE_BREAKPOINT
;
4653 static unsigned char little_break_insn
[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT
;
4655 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4657 /* Insert a breakpoint on targets that don't have any better
4658 breakpoint support. We read the contents of the target location
4659 and stash it, then overwrite it with a breakpoint instruction.
4660 ADDR is the target location in the target machine. CONTENTS_CACHE
4661 is a pointer to memory allocated for saving the target contents.
4662 It is guaranteed by the caller to be long enough to save the number
4663 of bytes returned by BREAKPOINT_FROM_PC. */
4666 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4668 struct remote_state
*rs
= get_remote_state ();
4669 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4674 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4675 If it succeeds, then set the support to PACKET_ENABLE. If it
4676 fails, and the user has explicitly requested the Z support then
4677 report an error, otherwise, mark it disabled and go on. */
4679 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4681 char *buf
= alloca (rs
->remote_packet_size
);
4684 addr
= remote_address_masked (addr
);
4688 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4689 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4690 sprintf (p
, ",%d", bp_size
);
4693 getpkt (buf
, (rs
->remote_packet_size
), 0);
4695 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4701 case PACKET_UNKNOWN
:
4706 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4707 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4711 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4712 val
= target_write_memory (addr
, (char *) big_break_insn
,
4713 sizeof big_break_insn
);
4715 val
= target_write_memory (addr
, (char *) little_break_insn
,
4716 sizeof little_break_insn
);
4721 return memory_insert_breakpoint (addr
, contents_cache
);
4722 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4726 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4728 struct remote_state
*rs
= get_remote_state ();
4731 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4733 char *buf
= alloca (rs
->remote_packet_size
);
4740 addr
= remote_address_masked (addr
);
4741 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4742 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4743 sprintf (p
, ",%d", bp_size
);
4746 getpkt (buf
, (rs
->remote_packet_size
), 0);
4748 return (buf
[0] == 'E');
4751 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4752 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4754 return memory_remove_breakpoint (addr
, contents_cache
);
4755 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4759 watchpoint_to_Z_packet (int type
)
4773 internal_error (__FILE__
, __LINE__
,
4774 "hw_bp_to_z: bad watchpoint type %d", type
);
4779 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4781 struct remote_state
*rs
= get_remote_state ();
4782 char *buf
= alloca (rs
->remote_packet_size
);
4784 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4786 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4787 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4788 remote_protocol_Z
[packet
].name
,
4789 remote_protocol_Z
[packet
].title
);
4791 sprintf (buf
, "Z%x,", packet
);
4792 p
= strchr (buf
, '\0');
4793 addr
= remote_address_masked (addr
);
4794 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4795 sprintf (p
, ",%x", len
);
4798 getpkt (buf
, (rs
->remote_packet_size
), 0);
4800 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4803 case PACKET_UNKNOWN
:
4808 internal_error (__FILE__
, __LINE__
,
4809 "remote_insert_watchpoint: reached end of function");
4814 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4816 struct remote_state
*rs
= get_remote_state ();
4817 char *buf
= alloca (rs
->remote_packet_size
);
4819 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4821 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4822 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4823 remote_protocol_Z
[packet
].name
,
4824 remote_protocol_Z
[packet
].title
);
4826 sprintf (buf
, "z%x,", packet
);
4827 p
= strchr (buf
, '\0');
4828 addr
= remote_address_masked (addr
);
4829 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4830 sprintf (p
, ",%x", len
);
4832 getpkt (buf
, (rs
->remote_packet_size
), 0);
4834 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4837 case PACKET_UNKNOWN
:
4842 internal_error (__FILE__
, __LINE__
,
4843 "remote_remove_watchpoint: reached end of function");
4847 int remote_hw_watchpoint_limit
= -1;
4848 int remote_hw_breakpoint_limit
= -1;
4851 remote_check_watch_resources (int type
, int cnt
, int ot
)
4853 if (type
== bp_hardware_breakpoint
)
4855 if (remote_hw_breakpoint_limit
== 0)
4857 else if (remote_hw_breakpoint_limit
< 0)
4859 else if (cnt
<= remote_hw_breakpoint_limit
)
4864 if (remote_hw_watchpoint_limit
== 0)
4866 else if (remote_hw_watchpoint_limit
< 0)
4870 else if (cnt
<= remote_hw_watchpoint_limit
)
4877 remote_stopped_by_watchpoint (void)
4879 return remote_stopped_by_watchpoint_p
;
4883 remote_stopped_data_address (void)
4885 if (remote_stopped_by_watchpoint ())
4886 return remote_watch_data_address
;
4887 return (CORE_ADDR
)0;
4892 remote_insert_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4895 struct remote_state
*rs
= get_remote_state ();
4896 char *buf
= alloca (rs
->remote_packet_size
);
4899 /* The length field should be set to the size of a breakpoint
4902 BREAKPOINT_FROM_PC (&addr
, &len
);
4904 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4905 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4906 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4907 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4913 addr
= remote_address_masked (addr
);
4914 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4915 sprintf (p
, ",%x", len
);
4918 getpkt (buf
, (rs
->remote_packet_size
), 0);
4920 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4923 case PACKET_UNKNOWN
:
4928 internal_error (__FILE__
, __LINE__
,
4929 "remote_insert_hw_breakpoint: reached end of function");
4934 remote_remove_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4937 struct remote_state
*rs
= get_remote_state ();
4938 char *buf
= alloca (rs
->remote_packet_size
);
4941 /* The length field should be set to the size of a breakpoint
4944 BREAKPOINT_FROM_PC (&addr
, &len
);
4946 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4947 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
4948 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4949 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4955 addr
= remote_address_masked (addr
);
4956 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4957 sprintf (p
, ",%x", len
);
4960 getpkt (buf
, (rs
->remote_packet_size
), 0);
4962 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4965 case PACKET_UNKNOWN
:
4970 internal_error (__FILE__
, __LINE__
,
4971 "remote_remove_hw_breakpoint: reached end of function");
4974 /* Some targets are only capable of doing downloads, and afterwards
4975 they switch to the remote serial protocol. This function provides
4976 a clean way to get from the download target to the remote target.
4977 It's basically just a wrapper so that we don't have to expose any
4978 of the internal workings of remote.c.
4980 Prior to calling this routine, you should shutdown the current
4981 target code, else you will get the "A program is being debugged
4982 already..." message. Usually a call to pop_target() suffices. */
4985 push_remote_target (char *name
, int from_tty
)
4987 printf_filtered ("Switching to remote protocol\n");
4988 remote_open (name
, from_tty
);
4991 /* Table used by the crc32 function to calcuate the checksum. */
4993 static unsigned long crc32_table
[256] =
4996 static unsigned long
4997 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4999 if (!crc32_table
[1])
5001 /* Initialize the CRC table and the decoding table. */
5005 for (i
= 0; i
< 256; i
++)
5007 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
5008 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
5015 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
5021 /* compare-sections command
5023 With no arguments, compares each loadable section in the exec bfd
5024 with the same memory range on the target, and reports mismatches.
5025 Useful for verifying the image on the target against the exec file.
5026 Depends on the target understanding the new "qCRC:" request. */
5028 /* FIXME: cagney/1999-10-26: This command should be broken down into a
5029 target method (target verify memory) and generic version of the
5030 actual command. This will allow other high-level code (especially
5031 generic_load()) to make use of this target functionality. */
5034 compare_sections_command (char *args
, int from_tty
)
5036 struct remote_state
*rs
= get_remote_state ();
5038 unsigned long host_crc
, target_crc
;
5039 extern bfd
*exec_bfd
;
5040 struct cleanup
*old_chain
;
5043 const char *sectname
;
5044 char *buf
= alloca (rs
->remote_packet_size
);
5051 error ("command cannot be used without an exec file");
5052 if (!current_target
.to_shortname
||
5053 strcmp (current_target
.to_shortname
, "remote") != 0)
5054 error ("command can only be used with remote target");
5056 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
5058 if (!(s
->flags
& SEC_LOAD
))
5059 continue; /* skip non-loadable section */
5061 size
= bfd_get_section_size_before_reloc (s
);
5063 continue; /* skip zero-length section */
5065 sectname
= bfd_get_section_name (exec_bfd
, s
);
5066 if (args
&& strcmp (args
, sectname
) != 0)
5067 continue; /* not the section selected by user */
5069 matched
= 1; /* do this section */
5071 /* FIXME: assumes lma can fit into long */
5072 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
5075 /* be clever; compute the host_crc before waiting for target reply */
5076 sectdata
= xmalloc (size
);
5077 old_chain
= make_cleanup (xfree
, sectdata
);
5078 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
5079 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
5081 getpkt (buf
, (rs
->remote_packet_size
), 0);
5083 error ("target memory fault, section %s, range 0x%s -- 0x%s",
5084 sectname
, paddr (lma
), paddr (lma
+ size
));
5086 error ("remote target does not support this operation");
5088 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
5089 target_crc
= target_crc
* 16 + fromhex (*tmp
);
5091 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
5092 sectname
, paddr (lma
), paddr (lma
+ size
));
5093 if (host_crc
== target_crc
)
5094 printf_filtered ("matched.\n");
5097 printf_filtered ("MIS-MATCHED!\n");
5101 do_cleanups (old_chain
);
5104 warning ("One or more sections of the remote executable does not match\n\
5105 the loaded file\n");
5106 if (args
&& !matched
)
5107 printf_filtered ("No loaded section named '%s'.\n", args
);
5111 remote_query (int query_type
, char *buf
, char *outbuf
, int *bufsiz
)
5113 struct remote_state
*rs
= get_remote_state ();
5115 char *buf2
= alloca (rs
->remote_packet_size
);
5116 char *p2
= &buf2
[0];
5119 error ("null pointer to remote bufer size specified");
5121 /* minimum outbuf size is (rs->remote_packet_size) - if bufsiz is not large enough let
5122 the caller know and return what the minimum size is */
5123 /* Note: a zero bufsiz can be used to query the minimum buffer size */
5124 if (*bufsiz
< (rs
->remote_packet_size
))
5126 *bufsiz
= (rs
->remote_packet_size
);
5130 /* except for querying the minimum buffer size, target must be open */
5132 error ("remote query is only available after target open");
5134 /* we only take uppercase letters as query types, at least for now */
5135 if ((query_type
< 'A') || (query_type
> 'Z'))
5136 error ("invalid remote query type");
5139 error ("null remote query specified");
5142 error ("remote query requires a buffer to receive data");
5149 /* we used one buffer char for the remote protocol q command and another
5150 for the query type. As the remote protocol encapsulation uses 4 chars
5151 plus one extra in case we are debugging (remote_debug),
5152 we have PBUFZIZ - 7 left to pack the query string */
5154 while (buf
[i
] && (i
< ((rs
->remote_packet_size
) - 8)))
5156 /* bad caller may have sent forbidden characters */
5157 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
5158 error ("illegal characters in query string");
5166 error ("query larger than available buffer");
5172 getpkt (outbuf
, *bufsiz
, 0);
5178 remote_rcmd (char *command
,
5179 struct ui_file
*outbuf
)
5181 struct remote_state
*rs
= get_remote_state ();
5183 char *buf
= alloca (rs
->remote_packet_size
);
5187 error ("remote rcmd is only available after target open");
5189 /* Send a NULL command across as an empty command */
5190 if (command
== NULL
)
5193 /* The query prefix */
5194 strcpy (buf
, "qRcmd,");
5195 p
= strchr (buf
, '\0');
5197 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > (rs
->remote_packet_size
))
5198 error ("\"monitor\" command ``%s'' is too long\n", command
);
5200 /* Encode the actual command */
5201 bin2hex (command
, p
, 0);
5203 if (putpkt (buf
) < 0)
5204 error ("Communication problem with target\n");
5206 /* get/display the response */
5209 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
5211 getpkt (buf
, (rs
->remote_packet_size
), 0);
5213 error ("Target does not support this command\n");
5214 if (buf
[0] == 'O' && buf
[1] != 'K')
5216 remote_console_output (buf
+ 1); /* 'O' message from stub */
5219 if (strcmp (buf
, "OK") == 0)
5221 if (strlen (buf
) == 3 && buf
[0] == 'E'
5222 && isdigit (buf
[1]) && isdigit (buf
[2]))
5224 error ("Protocol error with Rcmd");
5226 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5228 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5229 fputc_unfiltered (c
, outbuf
);
5236 packet_command (char *args
, int from_tty
)
5238 struct remote_state
*rs
= get_remote_state ();
5239 char *buf
= alloca (rs
->remote_packet_size
);
5242 error ("command can only be used with remote target");
5245 error ("remote-packet command requires packet text as argument");
5247 puts_filtered ("sending: ");
5248 print_packet (args
);
5249 puts_filtered ("\n");
5252 getpkt (buf
, (rs
->remote_packet_size
), 0);
5253 puts_filtered ("received: ");
5255 puts_filtered ("\n");
5259 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
5261 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5263 static void threadset_test_cmd (char *cmd
, int tty
);
5265 static void threadalive_test (char *cmd
, int tty
);
5267 static void threadlist_test_cmd (char *cmd
, int tty
);
5269 int get_and_display_threadinfo (threadref
* ref
);
5271 static void threadinfo_test_cmd (char *cmd
, int tty
);
5273 static int thread_display_step (threadref
* ref
, void *context
);
5275 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5277 static void init_remote_threadtests (void);
5279 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
5282 threadset_test_cmd (char *cmd
, int tty
)
5284 int sample_thread
= SAMPLE_THREAD
;
5286 printf_filtered ("Remote threadset test\n");
5287 set_thread (sample_thread
, 1);
5292 threadalive_test (char *cmd
, int tty
)
5294 int sample_thread
= SAMPLE_THREAD
;
5296 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5297 printf_filtered ("PASS: Thread alive test\n");
5299 printf_filtered ("FAIL: Thread alive test\n");
5302 void output_threadid (char *title
, threadref
* ref
);
5305 output_threadid (char *title
, threadref
*ref
)
5309 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
5311 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5315 threadlist_test_cmd (char *cmd
, int tty
)
5318 threadref nextthread
;
5319 int done
, result_count
;
5320 threadref threadlist
[3];
5322 printf_filtered ("Remote Threadlist test\n");
5323 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5324 &result_count
, &threadlist
[0]))
5325 printf_filtered ("FAIL: threadlist test\n");
5328 threadref
*scan
= threadlist
;
5329 threadref
*limit
= scan
+ result_count
;
5331 while (scan
< limit
)
5332 output_threadid (" thread ", scan
++);
5337 display_thread_info (struct gdb_ext_thread_info
*info
)
5339 output_threadid ("Threadid: ", &info
->threadid
);
5340 printf_filtered ("Name: %s\n ", info
->shortname
);
5341 printf_filtered ("State: %s\n", info
->display
);
5342 printf_filtered ("other: %s\n\n", info
->more_display
);
5346 get_and_display_threadinfo (threadref
*ref
)
5350 struct gdb_ext_thread_info threadinfo
;
5352 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5353 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5354 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5355 display_thread_info (&threadinfo
);
5360 threadinfo_test_cmd (char *cmd
, int tty
)
5362 int athread
= SAMPLE_THREAD
;
5366 int_to_threadref (&thread
, athread
);
5367 printf_filtered ("Remote Threadinfo test\n");
5368 if (!get_and_display_threadinfo (&thread
))
5369 printf_filtered ("FAIL cannot get thread info\n");
5373 thread_display_step (threadref
*ref
, void *context
)
5375 /* output_threadid(" threadstep ",ref); *//* simple test */
5376 return get_and_display_threadinfo (ref
);
5380 threadlist_update_test_cmd (char *cmd
, int tty
)
5382 printf_filtered ("Remote Threadlist update test\n");
5383 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5387 init_remote_threadtests (void)
5389 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
5390 "Fetch and print the remote list of thread identifiers, one pkt only");
5391 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5392 "Fetch and display info about one thread");
5393 add_com ("tset", class_obscure
, threadset_test_cmd
,
5394 "Test setting to a different thread");
5395 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5396 "Iterate through updating all remote thread info");
5397 add_com ("talive", class_obscure
, threadalive_test
,
5398 " Remote thread alive test ");
5403 /* Convert a thread ID to a string. Returns the string in a static
5407 remote_pid_to_str (ptid_t ptid
)
5409 static char buf
[30];
5411 sprintf (buf
, "Thread %d", PIDGET (ptid
));
5416 init_remote_ops (void)
5418 remote_ops
.to_shortname
= "remote";
5419 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5421 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5422 Specify the serial device it is connected to\n\
5423 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5424 remote_ops
.to_open
= remote_open
;
5425 remote_ops
.to_close
= remote_close
;
5426 remote_ops
.to_detach
= remote_detach
;
5427 remote_ops
.to_disconnect
= remote_disconnect
;
5428 remote_ops
.to_resume
= remote_resume
;
5429 remote_ops
.to_wait
= remote_wait
;
5430 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5431 remote_ops
.to_store_registers
= remote_store_registers
;
5432 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5433 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
5434 remote_ops
.to_files_info
= remote_files_info
;
5435 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5436 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5437 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5438 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5439 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5440 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5441 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5442 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5443 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5444 remote_ops
.to_kill
= remote_kill
;
5445 remote_ops
.to_load
= generic_load
;
5446 remote_ops
.to_mourn_inferior
= remote_mourn
;
5447 remote_ops
.to_thread_alive
= remote_thread_alive
;
5448 remote_ops
.to_find_new_threads
= remote_threads_info
;
5449 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5450 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5451 remote_ops
.to_stop
= remote_stop
;
5452 remote_ops
.to_query
= remote_query
;
5453 remote_ops
.to_rcmd
= remote_rcmd
;
5454 remote_ops
.to_stratum
= process_stratum
;
5455 remote_ops
.to_has_all_memory
= 1;
5456 remote_ops
.to_has_memory
= 1;
5457 remote_ops
.to_has_stack
= 1;
5458 remote_ops
.to_has_registers
= 1;
5459 remote_ops
.to_has_execution
= 1;
5460 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5461 remote_ops
.to_magic
= OPS_MAGIC
;
5464 /* Set up the extended remote vector by making a copy of the standard
5465 remote vector and adding to it. */
5468 init_extended_remote_ops (void)
5470 extended_remote_ops
= remote_ops
;
5472 extended_remote_ops
.to_shortname
= "extended-remote";
5473 extended_remote_ops
.to_longname
=
5474 "Extended remote serial target in gdb-specific protocol";
5475 extended_remote_ops
.to_doc
=
5476 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5477 Specify the serial device it is connected to (e.g. /dev/ttya).",
5478 extended_remote_ops
.to_open
= extended_remote_open
;
5479 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5480 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5484 * Command: info remote-process
5486 * This implements Cisco's version of the "info proc" command.
5488 * This query allows the target stub to return an arbitrary string
5489 * (or strings) giving arbitrary information about the target process.
5490 * This is optional; the target stub isn't required to implement it.
5492 * Syntax: qfProcessInfo request first string
5493 * qsProcessInfo request subsequent string
5494 * reply: 'O'<hex-encoded-string>
5495 * 'l' last reply (empty)
5499 remote_info_process (char *args
, int from_tty
)
5501 struct remote_state
*rs
= get_remote_state ();
5502 char *buf
= alloca (rs
->remote_packet_size
);
5504 if (remote_desc
== 0)
5505 error ("Command can only be used when connected to the remote target.");
5507 putpkt ("qfProcessInfo");
5508 getpkt (buf
, (rs
->remote_packet_size
), 0);
5510 return; /* Silently: target does not support this feature. */
5513 error ("info proc: target error.");
5515 while (buf
[0] == 'O') /* Capitol-O packet */
5517 remote_console_output (&buf
[1]);
5518 putpkt ("qsProcessInfo");
5519 getpkt (buf
, (rs
->remote_packet_size
), 0);
5528 remote_cisco_open (char *name
, int from_tty
)
5532 error ("To open a remote debug connection, you need to specify what \n"
5533 "device is attached to the remote system (e.g. host:port).");
5535 /* See FIXME above */
5536 wait_forever_enabled_p
= 1;
5538 target_preopen (from_tty
);
5540 unpush_target (&remote_cisco_ops
);
5542 remote_desc
= remote_serial_open (name
);
5544 perror_with_name (name
);
5547 * If a baud rate was specified on the gdb command line it will
5548 * be greater than the initial value of -1. If it is, use it otherwise
5552 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
5553 if (serial_setbaudrate (remote_desc
, baud_rate
))
5555 serial_close (remote_desc
);
5556 perror_with_name (name
);
5559 serial_raw (remote_desc
);
5561 /* If there is something sitting in the buffer we might take it as a
5562 response to a command, which would be bad. */
5563 serial_flush_input (remote_desc
);
5567 puts_filtered ("Remote debugging using ");
5568 puts_filtered (name
);
5569 puts_filtered ("\n");
5572 remote_cisco_mode
= 1;
5574 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
5576 init_all_packet_configs ();
5578 general_thread
= -2;
5579 continue_thread
= -2;
5581 /* Probe for ability to use "ThreadInfo" query, as required. */
5582 use_threadinfo_query
= 1;
5583 use_threadextra_query
= 1;
5585 /* Without this, some commands which require an active target (such
5586 as kill) won't work. This variable serves (at least) double duty
5587 as both the pid of the target process (if it has such), and as a
5588 flag indicating that a target is active. These functions should
5589 be split out into seperate variables, especially since GDB will
5590 someday have a notion of debugging several processes. */
5591 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
5593 /* Start the remote connection; if error, discard this target. See
5594 the comments in remote_open_1() for further details such as the
5595 need to re-throw the exception. */
5596 ex
= catch_exceptions (uiout
,
5597 remote_start_remote_dummy
, NULL
,
5598 "Couldn't establish connection to remote"
5604 throw_exception (ex
);
5609 remote_cisco_close (int quitting
)
5611 remote_cisco_mode
= 0;
5612 remote_close (quitting
);
5616 remote_cisco_mourn (void)
5618 remote_mourn_1 (&remote_cisco_ops
);
5630 /* Shared between readsocket() and readtty(). The size is arbitrary,
5631 however all targets are known to support a 400 character packet. */
5632 static char tty_input
[400];
5634 static int escape_count
;
5635 static int echo_check
;
5636 extern int quit_flag
;
5643 /* Loop until the socket doesn't have any more data */
5645 while ((data
= readchar (0)) >= 0)
5647 /* Check for the escape sequence */
5650 /* If this is the fourth escape, get out */
5651 if (++escape_count
== 4)
5656 { /* This is a '|', but not the fourth in a row.
5657 Continue without echoing it. If it isn't actually
5658 one of four in a row, it'll be echoed later. */
5665 /* Ensure any pending '|'s are flushed. */
5667 for (; escape_count
> 0; escape_count
--)
5671 if (data
== '\r') /* If this is a return character, */
5672 continue; /* - just supress it. */
5674 if (echo_check
!= -1) /* Check for echo of user input. */
5676 if (tty_input
[echo_check
] == data
)
5678 gdb_assert (echo_check
<= sizeof (tty_input
));
5679 echo_check
++; /* Character matched user input: */
5680 continue; /* Continue without echoing it. */
5682 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5683 { /* End of the line (and of echo checking). */
5684 echo_check
= -1; /* No more echo supression */
5685 continue; /* Continue without echoing. */
5688 { /* Failed check for echo of user input.
5689 We now have some suppressed output to flush! */
5692 for (j
= 0; j
< echo_check
; j
++)
5693 putchar (tty_input
[j
]);
5697 putchar (data
); /* Default case: output the char. */
5700 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5701 return READ_MORE
; /* Try to read some more */
5703 return FATAL_ERROR
; /* Trouble, bail out */
5711 /* First, read a buffer full from the terminal */
5712 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5713 if (tty_bytecount
== -1)
5715 perror ("readtty: read failed");
5719 /* Remove a quoted newline. */
5720 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5721 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5723 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5724 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5727 /* Turn trailing newlines into returns */
5728 if (tty_input
[tty_bytecount
- 1] == '\n')
5729 tty_input
[tty_bytecount
- 1] = '\r';
5731 /* If the line consists of a ~, enter debugging mode. */
5732 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5735 /* Make this a zero terminated string and write it out */
5736 tty_input
[tty_bytecount
] = 0;
5737 if (serial_write (remote_desc
, tty_input
, tty_bytecount
))
5739 perror_with_name ("readtty: write failed");
5749 fd_set input
; /* file descriptors for select */
5750 int tablesize
; /* max number of FDs for select */
5757 tablesize
= 8 * sizeof (input
);
5761 /* Check for anything from our socket - doesn't block. Note that
5762 this must be done *before* the select as there may be
5763 buffered I/O waiting to be processed. */
5765 if ((status
= readsocket ()) == FATAL_ERROR
)
5767 error ("Debugging terminated by communications error");
5769 else if (status
!= READ_MORE
)
5774 fflush (stdout
); /* Flush output before blocking */
5776 /* Now block on more socket input or TTY input */
5779 FD_SET (fileno (stdin
), &input
);
5780 FD_SET (deprecated_serial_fd (remote_desc
), &input
);
5782 status
= select (tablesize
, &input
, 0, 0, 0);
5783 if ((status
== -1) && (errno
!= EINTR
))
5785 error ("Communications error on select %d", errno
);
5788 /* Handle Control-C typed */
5792 if ((++quit_count
) == 2)
5794 if (query ("Interrupt GDB? "))
5796 printf_filtered ("Interrupted by user.\n");
5797 throw_exception (RETURN_QUIT
);
5804 serial_send_break (remote_desc
);
5806 serial_write (remote_desc
, "\003", 1);
5811 /* Handle console input */
5813 if (FD_ISSET (fileno (stdin
), &input
))
5817 status
= readtty ();
5818 if (status
== READ_MORE
)
5821 return status
; /* telnet session ended */
5827 remote_cisco_wait (ptid_t ptid
, struct target_waitstatus
*status
)
5829 if (minitelnet () != ENTER_DEBUG
)
5831 error ("Debugging session terminated by protocol error");
5834 return remote_wait (ptid
, status
);
5838 init_remote_cisco_ops (void)
5840 remote_cisco_ops
.to_shortname
= "cisco";
5841 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5842 remote_cisco_ops
.to_doc
=
5843 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5844 Specify the serial device it is connected to (e.g. host:2020).";
5845 remote_cisco_ops
.to_open
= remote_cisco_open
;
5846 remote_cisco_ops
.to_close
= remote_cisco_close
;
5847 remote_cisco_ops
.to_detach
= remote_detach
;
5848 remote_cisco_ops
.to_disconnect
= remote_disconnect
;
5849 remote_cisco_ops
.to_resume
= remote_resume
;
5850 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5851 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5852 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5853 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5854 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5855 remote_cisco_ops
.to_files_info
= remote_files_info
;
5856 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5857 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5858 remote_cisco_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5859 remote_cisco_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5860 remote_cisco_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5861 remote_cisco_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5862 remote_cisco_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5863 remote_cisco_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5864 remote_cisco_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5865 remote_cisco_ops
.to_kill
= remote_kill
;
5866 remote_cisco_ops
.to_load
= generic_load
;
5867 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5868 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5869 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5870 remote_cisco_ops
.to_pid_to_str
= remote_pid_to_str
;
5871 remote_cisco_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5872 remote_cisco_ops
.to_stratum
= process_stratum
;
5873 remote_cisco_ops
.to_has_all_memory
= 1;
5874 remote_cisco_ops
.to_has_memory
= 1;
5875 remote_cisco_ops
.to_has_stack
= 1;
5876 remote_cisco_ops
.to_has_registers
= 1;
5877 remote_cisco_ops
.to_has_execution
= 1;
5878 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5882 remote_can_async_p (void)
5884 /* We're async whenever the serial device is. */
5885 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5889 remote_is_async_p (void)
5891 /* We're async whenever the serial device is. */
5892 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5895 /* Pass the SERIAL event on and up to the client. One day this code
5896 will be able to delay notifying the client of an event until the
5897 point where an entire packet has been received. */
5899 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5900 static void *async_client_context
;
5901 static serial_event_ftype remote_async_serial_handler
;
5904 remote_async_serial_handler (struct serial
*scb
, void *context
)
5906 /* Don't propogate error information up to the client. Instead let
5907 the client find out about the error by querying the target. */
5908 async_client_callback (INF_REG_EVENT
, async_client_context
);
5912 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5914 if (current_target
.to_async_mask_value
== 0)
5915 internal_error (__FILE__
, __LINE__
,
5916 "Calling remote_async when async is masked");
5918 if (callback
!= NULL
)
5920 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5921 async_client_callback
= callback
;
5922 async_client_context
= context
;
5925 serial_async (remote_desc
, NULL
, NULL
);
5928 /* Target async and target extended-async.
5930 This are temporary targets, until it is all tested. Eventually
5931 async support will be incorporated int the usual 'remote'
5935 init_remote_async_ops (void)
5937 remote_async_ops
.to_shortname
= "async";
5938 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5939 remote_async_ops
.to_doc
=
5940 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5941 Specify the serial device it is connected to (e.g. /dev/ttya).";
5942 remote_async_ops
.to_open
= remote_async_open
;
5943 remote_async_ops
.to_close
= remote_close
;
5944 remote_async_ops
.to_detach
= remote_detach
;
5945 remote_async_ops
.to_disconnect
= remote_disconnect
;
5946 remote_async_ops
.to_resume
= remote_async_resume
;
5947 remote_async_ops
.to_wait
= remote_async_wait
;
5948 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5949 remote_async_ops
.to_store_registers
= remote_store_registers
;
5950 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5951 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5952 remote_async_ops
.to_files_info
= remote_files_info
;
5953 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5954 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5955 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5956 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5957 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5958 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5959 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5960 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5961 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5962 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5963 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5964 remote_async_ops
.to_kill
= remote_async_kill
;
5965 remote_async_ops
.to_load
= generic_load
;
5966 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5967 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5968 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5969 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
5970 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5971 remote_async_ops
.to_stop
= remote_stop
;
5972 remote_async_ops
.to_query
= remote_query
;
5973 remote_async_ops
.to_rcmd
= remote_rcmd
;
5974 remote_async_ops
.to_stratum
= process_stratum
;
5975 remote_async_ops
.to_has_all_memory
= 1;
5976 remote_async_ops
.to_has_memory
= 1;
5977 remote_async_ops
.to_has_stack
= 1;
5978 remote_async_ops
.to_has_registers
= 1;
5979 remote_async_ops
.to_has_execution
= 1;
5980 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5981 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5982 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5983 remote_async_ops
.to_async
= remote_async
;
5984 remote_async_ops
.to_async_mask_value
= 1;
5985 remote_async_ops
.to_magic
= OPS_MAGIC
;
5988 /* Set up the async extended remote vector by making a copy of the standard
5989 remote vector and adding to it. */
5992 init_extended_async_remote_ops (void)
5994 extended_async_remote_ops
= remote_async_ops
;
5996 extended_async_remote_ops
.to_shortname
= "extended-async";
5997 extended_async_remote_ops
.to_longname
=
5998 "Extended remote serial target in async gdb-specific protocol";
5999 extended_async_remote_ops
.to_doc
=
6000 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
6001 Specify the serial device it is connected to (e.g. /dev/ttya).",
6002 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
6003 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
6004 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
6008 set_remote_cmd (char *args
, int from_tty
)
6013 show_remote_cmd (char *args
, int from_tty
)
6015 /* FIXME: cagney/2002-06-15: This function should iterate over
6016 remote_show_cmdlist for a list of sub commands to show. */
6017 show_remote_protocol_Z_packet_cmd (args
, from_tty
, NULL
);
6018 show_remote_protocol_e_packet_cmd (args
, from_tty
, NULL
);
6019 show_remote_protocol_E_packet_cmd (args
, from_tty
, NULL
);
6020 show_remote_protocol_P_packet_cmd (args
, from_tty
, NULL
);
6021 show_remote_protocol_qSymbol_packet_cmd (args
, from_tty
, NULL
);
6022 show_remote_protocol_binary_download_cmd (args
, from_tty
, NULL
);
6026 build_remote_gdbarch_data (void)
6028 remote_address_size
= TARGET_ADDR_BIT
;
6031 /* Saved pointer to previous owner of the new_objfile event. */
6032 static void (*remote_new_objfile_chain
) (struct objfile
*);
6034 /* Function to be called whenever a new objfile (shlib) is detected. */
6036 remote_new_objfile (struct objfile
*objfile
)
6038 if (remote_desc
!= 0) /* Have a remote connection */
6040 remote_check_symbols (objfile
);
6042 /* Call predecessor on chain, if any. */
6043 if (remote_new_objfile_chain
!= 0 &&
6045 remote_new_objfile_chain (objfile
);
6049 _initialize_remote (void)
6051 static struct cmd_list_element
*remote_set_cmdlist
;
6052 static struct cmd_list_element
*remote_show_cmdlist
;
6053 struct cmd_list_element
*tmpcmd
;
6055 /* architecture specific data */
6056 remote_gdbarch_data_handle
= register_gdbarch_data (init_remote_state
);
6058 /* Old tacky stuff. NOTE: This comes after the remote protocol so
6059 that the remote protocol has been initialized. */
6060 register_gdbarch_swap (&remote_address_size
,
6061 sizeof (&remote_address_size
), NULL
);
6062 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
6065 add_target (&remote_ops
);
6067 init_extended_remote_ops ();
6068 add_target (&extended_remote_ops
);
6070 init_remote_async_ops ();
6071 add_target (&remote_async_ops
);
6073 init_extended_async_remote_ops ();
6074 add_target (&extended_async_remote_ops
);
6076 init_remote_cisco_ops ();
6077 add_target (&remote_cisco_ops
);
6079 /* Hook into new objfile notification. */
6080 remote_new_objfile_chain
= target_new_objfile_hook
;
6081 target_new_objfile_hook
= remote_new_objfile
;
6084 init_remote_threadtests ();
6087 /* set/show remote ... */
6089 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
6090 Remote protocol specific variables\n\
6091 Configure various remote-protocol specific variables such as\n\
6092 the packets being used",
6093 &remote_set_cmdlist
, "set remote ",
6094 0/*allow-unknown*/, &setlist
);
6095 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, "\
6096 Remote protocol specific variables\n\
6097 Configure various remote-protocol specific variables such as\n\
6098 the packets being used",
6099 &remote_show_cmdlist
, "show remote ",
6100 0/*allow-unknown*/, &showlist
);
6102 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
6103 "Compare section data on target to the exec file.\n\
6104 Argument is a single section name (default: all loaded sections).",
6107 add_cmd ("packet", class_maintenance
, packet_command
,
6108 "Send an arbitrary packet to a remote target.\n\
6109 maintenance packet TEXT\n\
6110 If GDB is talking to an inferior via the GDB serial protocol, then\n\
6111 this command sends the string TEXT to the inferior, and displays the\n\
6112 response packet. GDB supplies the initial `$' character, and the\n\
6113 terminating `#' character and checksum.",
6116 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
,
6117 "Set whether to send break if interrupted.\n",
6118 "Show whether to send break if interrupted.\n",
6120 &setlist
, &showlist
);
6122 /* Install commands for configuring memory read/write packets. */
6124 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
6125 "Set the maximum number of bytes per memory write packet (deprecated).\n",
6127 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
,
6128 "Show the maximum number of bytes per memory write packet (deprecated).\n",
6130 add_cmd ("memory-write-packet-size", no_class
,
6131 set_memory_write_packet_size
,
6132 "Set the maximum number of bytes per memory-write packet.\n"
6133 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6134 "default packet size. The actual limit is further reduced\n"
6135 "dependent on the target. Specify ``fixed'' to disable the\n"
6136 "further restriction and ``limit'' to enable that restriction\n",
6137 &remote_set_cmdlist
);
6138 add_cmd ("memory-read-packet-size", no_class
,
6139 set_memory_read_packet_size
,
6140 "Set the maximum number of bytes per memory-read packet.\n"
6141 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6142 "default packet size. The actual limit is further reduced\n"
6143 "dependent on the target. Specify ``fixed'' to disable the\n"
6144 "further restriction and ``limit'' to enable that restriction\n",
6145 &remote_set_cmdlist
);
6146 add_cmd ("memory-write-packet-size", no_class
,
6147 show_memory_write_packet_size
,
6148 "Show the maximum number of bytes per memory-write packet.\n",
6149 &remote_show_cmdlist
);
6150 add_cmd ("memory-read-packet-size", no_class
,
6151 show_memory_read_packet_size
,
6152 "Show the maximum number of bytes per memory-read packet.\n",
6153 &remote_show_cmdlist
);
6155 add_setshow_cmd ("hardware-watchpoint-limit", no_class
,
6156 var_zinteger
, &remote_hw_watchpoint_limit
, "\
6157 Set the maximum number of target hardware watchpoints.\n\
6158 Specify a negative limit for unlimited.", "\
6159 Show the maximum number of target hardware watchpoints.\n",
6160 NULL
, NULL
, &remote_set_cmdlist
, &remote_show_cmdlist
);
6161 add_setshow_cmd ("hardware-breakpoint-limit", no_class
,
6162 var_zinteger
, &remote_hw_breakpoint_limit
, "\
6163 Set the maximum number of target hardware breakpoints.\n\
6164 Specify a negative limit for unlimited.", "\
6165 Show the maximum number of target hardware breakpoints.\n",
6166 NULL
, NULL
, &remote_set_cmdlist
, &remote_show_cmdlist
);
6169 (add_set_cmd ("remoteaddresssize", class_obscure
,
6170 var_integer
, (char *) &remote_address_size
,
6171 "Set the maximum size of the address (in bits) \
6172 in a memory packet.\n",
6176 add_packet_config_cmd (&remote_protocol_binary_download
,
6177 "X", "binary-download",
6178 set_remote_protocol_binary_download_cmd
,
6179 show_remote_protocol_binary_download_cmd
,
6180 &remote_set_cmdlist
, &remote_show_cmdlist
,
6183 /* XXXX - should ``set remotebinarydownload'' be retained for
6186 (add_set_cmd ("remotebinarydownload", no_class
,
6187 var_boolean
, (char *) &remote_binary_download
,
6188 "Set binary downloads.\n", &setlist
),
6192 add_info ("remote-process", remote_info_process
,
6193 "Query the remote system for process info.");
6195 add_packet_config_cmd (&remote_protocol_qSymbol
,
6196 "qSymbol", "symbol-lookup",
6197 set_remote_protocol_qSymbol_packet_cmd
,
6198 show_remote_protocol_qSymbol_packet_cmd
,
6199 &remote_set_cmdlist
, &remote_show_cmdlist
,
6202 add_packet_config_cmd (&remote_protocol_e
,
6203 "e", "step-over-range",
6204 set_remote_protocol_e_packet_cmd
,
6205 show_remote_protocol_e_packet_cmd
,
6206 &remote_set_cmdlist
, &remote_show_cmdlist
,
6208 /* Disable by default. The ``e'' packet has nasty interactions with
6209 the threading code - it relies on global state. */
6210 remote_protocol_e
.detect
= AUTO_BOOLEAN_FALSE
;
6211 update_packet_config (&remote_protocol_e
);
6213 add_packet_config_cmd (&remote_protocol_E
,
6214 "E", "step-over-range-w-signal",
6215 set_remote_protocol_E_packet_cmd
,
6216 show_remote_protocol_E_packet_cmd
,
6217 &remote_set_cmdlist
, &remote_show_cmdlist
,
6219 /* Disable by default. The ``e'' packet has nasty interactions with
6220 the threading code - it relies on global state. */
6221 remote_protocol_E
.detect
= AUTO_BOOLEAN_FALSE
;
6222 update_packet_config (&remote_protocol_E
);
6224 add_packet_config_cmd (&remote_protocol_P
,
6225 "P", "set-register",
6226 set_remote_protocol_P_packet_cmd
,
6227 show_remote_protocol_P_packet_cmd
,
6228 &remote_set_cmdlist
, &remote_show_cmdlist
,
6231 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
6232 "Z0", "software-breakpoint",
6233 set_remote_protocol_Z_software_bp_packet_cmd
,
6234 show_remote_protocol_Z_software_bp_packet_cmd
,
6235 &remote_set_cmdlist
, &remote_show_cmdlist
,
6238 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
6239 "Z1", "hardware-breakpoint",
6240 set_remote_protocol_Z_hardware_bp_packet_cmd
,
6241 show_remote_protocol_Z_hardware_bp_packet_cmd
,
6242 &remote_set_cmdlist
, &remote_show_cmdlist
,
6245 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
6246 "Z2", "write-watchpoint",
6247 set_remote_protocol_Z_write_wp_packet_cmd
,
6248 show_remote_protocol_Z_write_wp_packet_cmd
,
6249 &remote_set_cmdlist
, &remote_show_cmdlist
,
6252 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
6253 "Z3", "read-watchpoint",
6254 set_remote_protocol_Z_read_wp_packet_cmd
,
6255 show_remote_protocol_Z_read_wp_packet_cmd
,
6256 &remote_set_cmdlist
, &remote_show_cmdlist
,
6259 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
6260 "Z4", "access-watchpoint",
6261 set_remote_protocol_Z_access_wp_packet_cmd
,
6262 show_remote_protocol_Z_access_wp_packet_cmd
,
6263 &remote_set_cmdlist
, &remote_show_cmdlist
,
6266 /* Keep the old ``set remote Z-packet ...'' working. */
6267 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
6268 &remote_Z_packet_detect
, "\
6269 Set use of remote protocol `Z' packets",
6270 "Show use of remote protocol `Z' packets ",
6271 set_remote_protocol_Z_packet_cmd
,
6272 show_remote_protocol_Z_packet_cmd
,
6273 &remote_set_cmdlist
, &remote_show_cmdlist
);
6275 /* Eventually initialize fileio. See fileio.c */
6276 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);