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, 2003, 2004
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 /* See the GDB User Guide for details of the GDB remote protocol. */
27 #include "gdb_string.h"
34 /*#include "terminal.h" */
37 #include "gdb-stabs.h"
38 #include "gdbthread.h"
42 #include "gdb_assert.h"
47 #include <sys/types.h>
50 #include "event-loop.h"
51 #include "event-top.h"
57 #include "gdbcore.h" /* for exec_bfd */
59 #include "remote-fileio.h"
61 /* Prototypes for local functions */
62 static void cleanup_sigint_signal_handler (void *dummy
);
63 static void initialize_sigint_signal_handler (void);
64 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
66 static void handle_remote_sigint (int);
67 static void handle_remote_sigint_twice (int);
68 static void async_remote_interrupt (gdb_client_data
);
69 void async_remote_interrupt_twice (gdb_client_data
);
71 static void build_remote_gdbarch_data (void);
73 static void remote_files_info (struct target_ops
*ignore
);
75 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
76 int len
, int should_write
,
77 struct mem_attrib
*attrib
,
78 struct target_ops
*target
);
80 static void remote_prepare_to_store (void);
82 static void remote_fetch_registers (int regno
);
84 static void remote_resume (ptid_t ptid
, int step
,
85 enum target_signal siggnal
);
86 static void remote_async_resume (ptid_t ptid
, int step
,
87 enum target_signal siggnal
);
88 static int remote_start_remote (struct ui_out
*uiout
, void *dummy
);
90 static void remote_open (char *name
, int from_tty
);
91 static void remote_async_open (char *name
, int from_tty
);
93 static void extended_remote_open (char *name
, int from_tty
);
94 static void extended_remote_async_open (char *name
, int from_tty
);
96 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
,
99 static void remote_close (int quitting
);
101 static void remote_store_registers (int regno
);
103 static void remote_mourn (void);
104 static void remote_async_mourn (void);
106 static void extended_remote_restart (void);
108 static void extended_remote_mourn (void);
110 static void extended_remote_create_inferior (char *, char *, char **);
111 static void extended_remote_async_create_inferior (char *, char *, char **);
113 static void remote_mourn_1 (struct target_ops
*);
115 static void remote_send (char *buf
, long sizeof_buf
);
117 static int readchar (int timeout
);
119 static ptid_t
remote_wait (ptid_t ptid
,
120 struct target_waitstatus
*status
);
121 static ptid_t
remote_async_wait (ptid_t ptid
,
122 struct target_waitstatus
*status
);
124 static void remote_kill (void);
125 static void remote_async_kill (void);
127 static int tohex (int nib
);
129 static void remote_detach (char *args
, int from_tty
);
131 static void remote_interrupt (int signo
);
133 static void remote_interrupt_twice (int signo
);
135 static void interrupt_query (void);
137 static void set_thread (int, int);
139 static int remote_thread_alive (ptid_t
);
141 static void get_offsets (void);
143 static long read_frame (char *buf
, long sizeof_buf
);
145 static int remote_insert_breakpoint (CORE_ADDR
, char *);
147 static int remote_remove_breakpoint (CORE_ADDR
, char *);
149 static int hexnumlen (ULONGEST num
);
151 static void init_remote_ops (void);
153 static void init_extended_remote_ops (void);
155 static void init_remote_cisco_ops (void);
157 static struct target_ops remote_cisco_ops
;
159 static void remote_stop (void);
161 static int ishex (int ch
, int *val
);
163 static int stubhex (int ch
);
165 static int hexnumstr (char *, ULONGEST
);
167 static int hexnumnstr (char *, ULONGEST
, int);
169 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
171 static void print_packet (char *);
173 static unsigned long crc32 (unsigned char *, int, unsigned int);
175 static void compare_sections_command (char *, int);
177 static void packet_command (char *, int);
179 static int stub_unpack_int (char *buff
, int fieldlength
);
181 static ptid_t
remote_current_thread (ptid_t oldptid
);
183 static void remote_find_new_threads (void);
185 static void record_currthread (int currthread
);
187 static int fromhex (int a
);
189 static int hex2bin (const char *hex
, char *bin
, int count
);
191 static int bin2hex (const char *bin
, char *hex
, int count
);
193 static int putpkt_binary (char *buf
, int cnt
);
195 static void check_binary_download (CORE_ADDR addr
);
197 struct packet_config
;
199 static void show_packet_config_cmd (struct packet_config
*config
);
201 static void update_packet_config (struct packet_config
*config
);
203 void _initialize_remote (void);
205 /* Description of the remote protocol. Strictly speaking, when the
206 target is open()ed, remote.c should create a per-target description
207 of the remote protocol using that target's architecture.
208 Unfortunately, the target stack doesn't include local state. For
209 the moment keep the information in the target's architecture
214 long offset
; /* Offset into G packet. */
215 long regnum
; /* GDB's internal register number. */
216 LONGEST pnum
; /* Remote protocol register number. */
217 int in_g_packet
; /* Always part of G packet. */
218 /* long size in bytes; == DEPRECATED_REGISTER_RAW_SIZE (regnum); at present. */
219 /* char *name; == REGISTER_NAME (regnum); at present. */
224 /* Description of the remote protocol registers. */
225 long sizeof_g_packet
;
227 /* Description of the remote protocol registers indexed by REGNUM
228 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
229 struct packet_reg
*regs
;
231 /* This is the size (in chars) of the first response to the ``g''
232 packet. It is used as a heuristic when determining the maximum
233 size of memory-read and memory-write packets. A target will
234 typically only reserve a buffer large enough to hold the ``g''
235 packet. The size does not include packet overhead (headers and
237 long actual_register_packet_size
;
239 /* This is the maximum size (in chars) of a non read/write packet.
240 It is also used as a cap on the size of read/write packets. */
241 long remote_packet_size
;
245 /* Handle for retreving the remote protocol data from gdbarch. */
246 static struct gdbarch_data
*remote_gdbarch_data_handle
;
248 static struct remote_state
*
249 get_remote_state (void)
251 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
255 init_remote_state (struct gdbarch
*gdbarch
)
258 struct remote_state
*rs
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_state
);
260 if (DEPRECATED_REGISTER_BYTES
!= 0)
261 rs
->sizeof_g_packet
= DEPRECATED_REGISTER_BYTES
;
263 rs
->sizeof_g_packet
= 0;
265 /* Assume a 1:1 regnum<->pnum table. */
266 rs
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
, NUM_REGS
+ NUM_PSEUDO_REGS
,
268 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
270 struct packet_reg
*r
= &rs
->regs
[regnum
];
273 r
->offset
= DEPRECATED_REGISTER_BYTE (regnum
);
274 r
->in_g_packet
= (regnum
< NUM_REGS
);
275 /* ...name = REGISTER_NAME (regnum); */
277 /* Compute packet size by accumulating the size of all registers. */
278 if (DEPRECATED_REGISTER_BYTES
== 0)
279 rs
->sizeof_g_packet
+= register_size (current_gdbarch
, regnum
);
282 /* Default maximum number of characters in a packet body. Many
283 remote stubs have a hardwired buffer size of 400 bytes
284 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
285 as the maximum packet-size to ensure that the packet and an extra
286 NUL character can always fit in the buffer. This stops GDB
287 trashing stubs that try to squeeze an extra NUL into what is
288 already a full buffer (As of 1999-12-04 that was most stubs. */
289 rs
->remote_packet_size
= 400 - 1;
291 /* Should rs->sizeof_g_packet needs more space than the
292 default, adjust the size accordingly. Remember that each byte is
293 encoded as two characters. 32 is the overhead for the packet
294 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
295 (``$NN:G...#NN'') is a better guess, the below has been padded a
297 if (rs
->sizeof_g_packet
> ((rs
->remote_packet_size
- 32) / 2))
298 rs
->remote_packet_size
= (rs
->sizeof_g_packet
* 2 + 32);
300 /* This one is filled in when a ``g'' packet is received. */
301 rs
->actual_register_packet_size
= 0;
306 static struct packet_reg
*
307 packet_reg_from_regnum (struct remote_state
*rs
, long regnum
)
309 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
313 struct packet_reg
*r
= &rs
->regs
[regnum
];
314 gdb_assert (r
->regnum
== regnum
);
319 static struct packet_reg
*
320 packet_reg_from_pnum (struct remote_state
*rs
, LONGEST pnum
)
323 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
325 struct packet_reg
*r
= &rs
->regs
[i
];
332 /* FIXME: graces/2002-08-08: These variables should eventually be
333 bound to an instance of the target object (as in gdbarch-tdep()),
334 when such a thing exists. */
336 /* This is set to the data address of the access causing the target
337 to stop for a watchpoint. */
338 static CORE_ADDR remote_watch_data_address
;
340 /* This is non-zero if taregt stopped for a watchpoint. */
341 static int remote_stopped_by_watchpoint_p
;
344 static struct target_ops remote_ops
;
346 static struct target_ops extended_remote_ops
;
348 /* Temporary target ops. Just like the remote_ops and
349 extended_remote_ops, but with asynchronous support. */
350 static struct target_ops remote_async_ops
;
352 static struct target_ops extended_async_remote_ops
;
354 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
355 ``forever'' still use the normal timeout mechanism. This is
356 currently used by the ASYNC code to guarentee that target reads
357 during the initial connect always time-out. Once getpkt has been
358 modified to return a timeout indication and, in turn
359 remote_wait()/wait_for_inferior() have gained a timeout parameter
361 static int wait_forever_enabled_p
= 1;
364 /* This variable chooses whether to send a ^C or a break when the user
365 requests program interruption. Although ^C is usually what remote
366 systems expect, and that is the default here, sometimes a break is
367 preferable instead. */
369 static int remote_break
;
371 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
372 remote_open knows that we don't have a file open when the program
374 static struct serial
*remote_desc
= NULL
;
376 /* This is set by the target (thru the 'S' message)
377 to denote that the target is in kernel mode. */
378 static int cisco_kernel_mode
= 0;
380 /* This variable sets the number of bits in an address that are to be
381 sent in a memory ("M" or "m") packet. Normally, after stripping
382 leading zeros, the entire address would be sent. This variable
383 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
384 initial implementation of remote.c restricted the address sent in
385 memory packets to ``host::sizeof long'' bytes - (typically 32
386 bits). Consequently, for 64 bit targets, the upper 32 bits of an
387 address was never sent. Since fixing this bug may cause a break in
388 some remote targets this variable is principly provided to
389 facilitate backward compatibility. */
391 static int remote_address_size
;
393 /* Tempoary to track who currently owns the terminal. See
394 target_async_terminal_* for more details. */
396 static int remote_async_terminal_ours_p
;
399 /* User configurable variables for the number of characters in a
400 memory read/write packet. MIN ((rs->remote_packet_size),
401 rs->sizeof_g_packet) is the default. Some targets need smaller
402 values (fifo overruns, et.al.) and some users need larger values
403 (speed up transfers). The variables ``preferred_*'' (the user
404 request), ``current_*'' (what was actually set) and ``forced_*''
405 (Positive - a soft limit, negative - a hard limit). */
407 struct memory_packet_config
414 /* Compute the current size of a read/write packet. Since this makes
415 use of ``actual_register_packet_size'' the computation is dynamic. */
418 get_memory_packet_size (struct memory_packet_config
*config
)
420 struct remote_state
*rs
= get_remote_state ();
421 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
422 law?) that some hosts don't cope very well with large alloca()
423 calls. Eventually the alloca() code will be replaced by calls to
424 xmalloc() and make_cleanups() allowing this restriction to either
425 be lifted or removed. */
426 #ifndef MAX_REMOTE_PACKET_SIZE
427 #define MAX_REMOTE_PACKET_SIZE 16384
429 /* NOTE: 16 is just chosen at random. */
430 #ifndef MIN_REMOTE_PACKET_SIZE
431 #define MIN_REMOTE_PACKET_SIZE 16
436 if (config
->size
<= 0)
437 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
439 what_they_get
= config
->size
;
443 what_they_get
= (rs
->remote_packet_size
);
444 /* Limit the packet to the size specified by the user. */
446 && what_they_get
> config
->size
)
447 what_they_get
= config
->size
;
448 /* Limit it to the size of the targets ``g'' response. */
449 if ((rs
->actual_register_packet_size
) > 0
450 && what_they_get
> (rs
->actual_register_packet_size
))
451 what_they_get
= (rs
->actual_register_packet_size
);
453 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
454 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
455 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
456 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
457 return what_they_get
;
460 /* Update the size of a read/write packet. If they user wants
461 something really big then do a sanity check. */
464 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
466 int fixed_p
= config
->fixed_p
;
467 long size
= config
->size
;
469 error ("Argument required (integer, `fixed' or `limited').");
470 else if (strcmp (args
, "hard") == 0
471 || strcmp (args
, "fixed") == 0)
473 else if (strcmp (args
, "soft") == 0
474 || strcmp (args
, "limit") == 0)
479 size
= strtoul (args
, &end
, 0);
481 error ("Invalid %s (bad syntax).", config
->name
);
483 /* Instead of explicitly capping the size of a packet to
484 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
485 instead allowed to set the size to something arbitrarily
487 if (size
> MAX_REMOTE_PACKET_SIZE
)
488 error ("Invalid %s (too large).", config
->name
);
492 if (fixed_p
&& !config
->fixed_p
)
494 if (! query ("The target may not be able to correctly handle a %s\n"
495 "of %ld bytes. Change the packet size? ",
497 error ("Packet size not changed.");
499 /* Update the config. */
500 config
->fixed_p
= fixed_p
;
505 show_memory_packet_size (struct memory_packet_config
*config
)
507 printf_filtered ("The %s is %ld. ", config
->name
, config
->size
);
509 printf_filtered ("Packets are fixed at %ld bytes.\n",
510 get_memory_packet_size (config
));
512 printf_filtered ("Packets are limited to %ld bytes.\n",
513 get_memory_packet_size (config
));
516 static struct memory_packet_config memory_write_packet_config
=
518 "memory-write-packet-size",
522 set_memory_write_packet_size (char *args
, int from_tty
)
524 set_memory_packet_size (args
, &memory_write_packet_config
);
528 show_memory_write_packet_size (char *args
, int from_tty
)
530 show_memory_packet_size (&memory_write_packet_config
);
534 get_memory_write_packet_size (void)
536 return get_memory_packet_size (&memory_write_packet_config
);
539 static struct memory_packet_config memory_read_packet_config
=
541 "memory-read-packet-size",
545 set_memory_read_packet_size (char *args
, int from_tty
)
547 set_memory_packet_size (args
, &memory_read_packet_config
);
551 show_memory_read_packet_size (char *args
, int from_tty
)
553 show_memory_packet_size (&memory_read_packet_config
);
557 get_memory_read_packet_size (void)
559 struct remote_state
*rs
= get_remote_state ();
560 long size
= get_memory_packet_size (&memory_read_packet_config
);
561 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
562 extra buffer size argument before the memory read size can be
563 increased beyond (rs->remote_packet_size). */
564 if (size
> (rs
->remote_packet_size
))
565 size
= (rs
->remote_packet_size
);
570 /* Generic configuration support for packets the stub optionally
571 supports. Allows the user to specify the use of the packet as well
572 as allowing GDB to auto-detect support in the remote stub. */
576 PACKET_SUPPORT_UNKNOWN
= 0,
585 enum auto_boolean detect
;
586 enum packet_support support
;
589 /* Analyze a packet's return value and update the packet config
600 update_packet_config (struct packet_config
*config
)
602 switch (config
->detect
)
604 case AUTO_BOOLEAN_TRUE
:
605 config
->support
= PACKET_ENABLE
;
607 case AUTO_BOOLEAN_FALSE
:
608 config
->support
= PACKET_DISABLE
;
610 case AUTO_BOOLEAN_AUTO
:
611 config
->support
= PACKET_SUPPORT_UNKNOWN
;
617 show_packet_config_cmd (struct packet_config
*config
)
619 char *support
= "internal-error";
620 switch (config
->support
)
626 support
= "disabled";
628 case PACKET_SUPPORT_UNKNOWN
:
632 switch (config
->detect
)
634 case AUTO_BOOLEAN_AUTO
:
635 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
636 config
->name
, config
->title
, support
);
638 case AUTO_BOOLEAN_TRUE
:
639 case AUTO_BOOLEAN_FALSE
:
640 printf_filtered ("Support for remote protocol `%s' (%s) packet is currently %s.\n",
641 config
->name
, config
->title
, support
);
647 add_packet_config_cmd (struct packet_config
*config
,
650 cmd_sfunc_ftype
*set_func
,
651 cmd_sfunc_ftype
*show_func
,
652 struct cmd_list_element
**set_remote_list
,
653 struct cmd_list_element
**show_remote_list
,
656 struct cmd_list_element
*set_cmd
;
657 struct cmd_list_element
*show_cmd
;
662 config
->title
= title
;
663 config
->detect
= AUTO_BOOLEAN_AUTO
;
664 config
->support
= PACKET_SUPPORT_UNKNOWN
;
665 xasprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
667 xasprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
669 /* set/show TITLE-packet {auto,on,off} */
670 xasprintf (&cmd_name
, "%s-packet", title
);
671 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
672 &config
->detect
, set_doc
, show_doc
,
674 set_remote_list
, show_remote_list
);
675 /* set/show remote NAME-packet {auto,on,off} -- legacy */
679 xasprintf (&legacy_name
, "%s-packet", name
);
680 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
682 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
687 static enum packet_result
688 packet_ok (const char *buf
, struct packet_config
*config
)
692 /* The stub recognized the packet request. Check that the
693 operation succeeded. */
694 switch (config
->support
)
696 case PACKET_SUPPORT_UNKNOWN
:
698 fprintf_unfiltered (gdb_stdlog
,
699 "Packet %s (%s) is supported\n",
700 config
->name
, config
->title
);
701 config
->support
= PACKET_ENABLE
;
704 internal_error (__FILE__
, __LINE__
,
705 "packet_ok: attempt to use a disabled packet");
710 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
711 /* "OK" - definitly OK. */
714 && isxdigit (buf
[1]) && isxdigit (buf
[2])
716 /* "Enn" - definitly an error. */
718 /* The packet may or may not be OK. Just assume it is */
723 /* The stub does not support the packet. */
724 switch (config
->support
)
727 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
728 /* If the stub previously indicated that the packet was
729 supported then there is a protocol error.. */
730 error ("Protocol error: %s (%s) conflicting enabled responses.",
731 config
->name
, config
->title
);
733 /* The user set it wrong. */
734 error ("Enabled packet %s (%s) not recognized by stub",
735 config
->name
, config
->title
);
737 case PACKET_SUPPORT_UNKNOWN
:
739 fprintf_unfiltered (gdb_stdlog
,
740 "Packet %s (%s) is NOT supported\n",
741 config
->name
, config
->title
);
742 config
->support
= PACKET_DISABLE
;
747 return PACKET_UNKNOWN
;
751 /* Should we try the 'vCont' (descriptive resume) request? */
752 static struct packet_config remote_protocol_vcont
;
755 set_remote_protocol_vcont_packet_cmd (char *args
, int from_tty
,
756 struct cmd_list_element
*c
)
758 update_packet_config (&remote_protocol_vcont
);
762 show_remote_protocol_vcont_packet_cmd (char *args
, int from_tty
,
763 struct cmd_list_element
*c
)
765 show_packet_config_cmd (&remote_protocol_vcont
);
768 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
769 static struct packet_config remote_protocol_qSymbol
;
772 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
773 struct cmd_list_element
*c
)
775 update_packet_config (&remote_protocol_qSymbol
);
779 show_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
780 struct cmd_list_element
*c
)
782 show_packet_config_cmd (&remote_protocol_qSymbol
);
785 /* Should we try the 'e' (step over range) request? */
786 static struct packet_config remote_protocol_e
;
789 set_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
790 struct cmd_list_element
*c
)
792 update_packet_config (&remote_protocol_e
);
796 show_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
797 struct cmd_list_element
*c
)
799 show_packet_config_cmd (&remote_protocol_e
);
803 /* Should we try the 'E' (step over range / w signal #) request? */
804 static struct packet_config remote_protocol_E
;
807 set_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
808 struct cmd_list_element
*c
)
810 update_packet_config (&remote_protocol_E
);
814 show_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
815 struct cmd_list_element
*c
)
817 show_packet_config_cmd (&remote_protocol_E
);
821 /* Should we try the 'P' (set register) request? */
823 static struct packet_config remote_protocol_P
;
826 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
827 struct cmd_list_element
*c
)
829 update_packet_config (&remote_protocol_P
);
833 show_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
834 struct cmd_list_element
*c
)
836 show_packet_config_cmd (&remote_protocol_P
);
839 /* Should we try one of the 'Z' requests? */
843 Z_PACKET_SOFTWARE_BP
,
844 Z_PACKET_HARDWARE_BP
,
851 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
853 /* FIXME: Instead of having all these boiler plate functions, the
854 command callback should include a context argument. */
857 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
858 struct cmd_list_element
*c
)
860 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
864 show_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
865 struct cmd_list_element
*c
)
867 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
871 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
872 struct cmd_list_element
*c
)
874 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
878 show_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
879 struct cmd_list_element
*c
)
881 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
885 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
886 struct cmd_list_element
*c
)
888 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
892 show_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
893 struct cmd_list_element
*c
)
895 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
899 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
900 struct cmd_list_element
*c
)
902 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
906 show_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
907 struct cmd_list_element
*c
)
909 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
913 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
914 struct cmd_list_element
*c
)
916 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
920 show_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
921 struct cmd_list_element
*c
)
923 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
926 /* For compatibility with older distributions. Provide a ``set remote
927 Z-packet ...'' command that updates all the Z packet types. */
929 static enum auto_boolean remote_Z_packet_detect
;
932 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
933 struct cmd_list_element
*c
)
936 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
938 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
939 update_packet_config (&remote_protocol_Z
[i
]);
944 show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
945 struct cmd_list_element
*c
)
948 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
950 show_packet_config_cmd (&remote_protocol_Z
[i
]);
954 /* Should we try the 'X' (remote binary download) packet?
956 This variable (available to the user via "set remote X-packet")
957 dictates whether downloads are sent in binary (via the 'X' packet).
958 We assume that the stub can, and attempt to do it. This will be
959 cleared if the stub does not understand it. This switch is still
960 needed, though in cases when the packet is supported in the stub,
961 but the connection does not allow it (i.e., 7-bit serial connection
964 static struct packet_config remote_protocol_binary_download
;
966 /* Should we try the 'ThreadInfo' query packet?
968 This variable (NOT available to the user: auto-detect only!)
969 determines whether GDB will use the new, simpler "ThreadInfo"
970 query or the older, more complex syntax for thread queries.
971 This is an auto-detect variable (set to true at each connect,
972 and set to false when the target fails to recognize it). */
974 static int use_threadinfo_query
;
975 static int use_threadextra_query
;
978 set_remote_protocol_binary_download_cmd (char *args
,
980 struct cmd_list_element
*c
)
982 update_packet_config (&remote_protocol_binary_download
);
986 show_remote_protocol_binary_download_cmd (char *args
, int from_tty
,
987 struct cmd_list_element
*c
)
989 show_packet_config_cmd (&remote_protocol_binary_download
);
993 /* Tokens for use by the asynchronous signal handlers for SIGINT */
994 static void *sigint_remote_twice_token
;
995 static void *sigint_remote_token
;
997 /* These are pointers to hook functions that may be set in order to
998 modify resume/wait behavior for a particular architecture. */
1000 void (*target_resume_hook
) (void);
1001 void (*target_wait_loop_hook
) (void);
1005 /* These are the threads which we last sent to the remote system.
1006 -1 for all or -2 for not sent yet. */
1007 static int general_thread
;
1008 static int continue_thread
;
1010 /* Call this function as a result of
1011 1) A halt indication (T packet) containing a thread id
1012 2) A direct query of currthread
1013 3) Successful execution of set thread
1017 record_currthread (int currthread
)
1019 general_thread
= currthread
;
1021 /* If this is a new thread, add it to GDB's thread list.
1022 If we leave it up to WFI to do this, bad things will happen. */
1023 if (!in_thread_list (pid_to_ptid (currthread
)))
1025 add_thread (pid_to_ptid (currthread
));
1026 ui_out_text (uiout
, "[New ");
1027 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
1028 ui_out_text (uiout
, "]\n");
1032 #define MAGIC_NULL_PID 42000
1035 set_thread (int th
, int gen
)
1037 struct remote_state
*rs
= get_remote_state ();
1038 char *buf
= alloca (rs
->remote_packet_size
);
1039 int state
= gen
? general_thread
: continue_thread
;
1045 buf
[1] = gen
? 'g' : 'c';
1046 if (th
== MAGIC_NULL_PID
)
1052 sprintf (&buf
[2], "-%x", -th
);
1054 sprintf (&buf
[2], "%x", th
);
1056 getpkt (buf
, (rs
->remote_packet_size
), 0);
1058 general_thread
= th
;
1060 continue_thread
= th
;
1063 /* Return nonzero if the thread TH is still alive on the remote system. */
1066 remote_thread_alive (ptid_t ptid
)
1068 int tid
= PIDGET (ptid
);
1072 sprintf (buf
, "T-%08x", -tid
);
1074 sprintf (buf
, "T%08x", tid
);
1076 getpkt (buf
, sizeof (buf
), 0);
1077 return (buf
[0] == 'O' && buf
[1] == 'K');
1080 /* About these extended threadlist and threadinfo packets. They are
1081 variable length packets but, the fields within them are often fixed
1082 length. They are redundent enough to send over UDP as is the
1083 remote protocol in general. There is a matching unit test module
1086 #define OPAQUETHREADBYTES 8
1088 /* a 64 bit opaque identifier */
1089 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1091 /* WARNING: This threadref data structure comes from the remote O.S., libstub
1092 protocol encoding, and remote.c. it is not particularly changable */
1094 /* Right now, the internal structure is int. We want it to be bigger.
1098 typedef int gdb_threadref
; /* internal GDB thread reference */
1100 /* gdb_ext_thread_info is an internal GDB data structure which is
1101 equivalint to the reply of the remote threadinfo packet */
1103 struct gdb_ext_thread_info
1105 threadref threadid
; /* External form of thread reference */
1106 int active
; /* Has state interesting to GDB? , regs, stack */
1107 char display
[256]; /* Brief state display, name, blocked/syspended */
1108 char shortname
[32]; /* To be used to name threads */
1109 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
1112 /* The volume of remote transfers can be limited by submitting
1113 a mask containing bits specifying the desired information.
1114 Use a union of these values as the 'selection' parameter to
1115 get_thread_info. FIXME: Make these TAG names more thread specific.
1118 #define TAG_THREADID 1
1119 #define TAG_EXISTS 2
1120 #define TAG_DISPLAY 4
1121 #define TAG_THREADNAME 8
1122 #define TAG_MOREDISPLAY 16
1124 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
1126 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1128 static char *unpack_nibble (char *buf
, int *val
);
1130 static char *pack_nibble (char *buf
, int nibble
);
1132 static char *pack_hex_byte (char *pkt
, int /*unsigned char */ byte
);
1134 static char *unpack_byte (char *buf
, int *value
);
1136 static char *pack_int (char *buf
, int value
);
1138 static char *unpack_int (char *buf
, int *value
);
1140 static char *unpack_string (char *src
, char *dest
, int length
);
1142 static char *pack_threadid (char *pkt
, threadref
* id
);
1144 static char *unpack_threadid (char *inbuf
, threadref
* id
);
1146 void int_to_threadref (threadref
* id
, int value
);
1148 static int threadref_to_int (threadref
* ref
);
1150 static void copy_threadref (threadref
* dest
, threadref
* src
);
1152 static int threadmatch (threadref
* dest
, threadref
* src
);
1154 static char *pack_threadinfo_request (char *pkt
, int mode
, threadref
* id
);
1156 static int remote_unpack_thread_info_response (char *pkt
,
1157 threadref
* expectedref
,
1158 struct gdb_ext_thread_info
1162 static int remote_get_threadinfo (threadref
* threadid
, int fieldset
, /*TAG mask */
1163 struct gdb_ext_thread_info
*info
);
1165 static int adapt_remote_get_threadinfo (gdb_threadref
* ref
,
1167 struct gdb_ext_thread_info
*info
);
1169 static char *pack_threadlist_request (char *pkt
, int startflag
,
1171 threadref
* nextthread
);
1173 static int parse_threadlist_response (char *pkt
,
1175 threadref
* original_echo
,
1176 threadref
* resultlist
, int *doneflag
);
1178 static int remote_get_threadlist (int startflag
,
1179 threadref
* nextthread
,
1182 int *result_count
, threadref
* threadlist
);
1184 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
1186 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1187 void *context
, int looplimit
);
1189 static int remote_newthread_step (threadref
* ref
, void *context
);
1191 /* encode 64 bits in 16 chars of hex */
1193 static const char hexchars
[] = "0123456789abcdef";
1196 ishex (int ch
, int *val
)
1198 if ((ch
>= 'a') && (ch
<= 'f'))
1200 *val
= ch
- 'a' + 10;
1203 if ((ch
>= 'A') && (ch
<= 'F'))
1205 *val
= ch
- 'A' + 10;
1208 if ((ch
>= '0') && (ch
<= '9'))
1219 if (ch
>= 'a' && ch
<= 'f')
1220 return ch
- 'a' + 10;
1221 if (ch
>= '0' && ch
<= '9')
1223 if (ch
>= 'A' && ch
<= 'F')
1224 return ch
- 'A' + 10;
1229 stub_unpack_int (char *buff
, int fieldlength
)
1236 nibble
= stubhex (*buff
++);
1240 retval
= retval
<< 4;
1246 unpack_varlen_hex (char *buff
, /* packet to parse */
1252 while (ishex (*buff
, &nibble
))
1255 retval
= retval
<< 4;
1256 retval
|= nibble
& 0x0f;
1263 unpack_nibble (char *buf
, int *val
)
1265 ishex (*buf
++, val
);
1270 pack_nibble (char *buf
, int nibble
)
1272 *buf
++ = hexchars
[(nibble
& 0x0f)];
1277 pack_hex_byte (char *pkt
, int byte
)
1279 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1280 *pkt
++ = hexchars
[(byte
& 0xf)];
1285 unpack_byte (char *buf
, int *value
)
1287 *value
= stub_unpack_int (buf
, 2);
1292 pack_int (char *buf
, int value
)
1294 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1295 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1296 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1297 buf
= pack_hex_byte (buf
, (value
& 0xff));
1302 unpack_int (char *buf
, int *value
)
1304 *value
= stub_unpack_int (buf
, 8);
1308 #if 0 /* currently unused, uncomment when needed */
1309 static char *pack_string (char *pkt
, char *string
);
1312 pack_string (char *pkt
, char *string
)
1317 len
= strlen (string
);
1319 len
= 200; /* Bigger than most GDB packets, junk??? */
1320 pkt
= pack_hex_byte (pkt
, len
);
1324 if ((ch
== '\0') || (ch
== '#'))
1325 ch
= '*'; /* Protect encapsulation */
1330 #endif /* 0 (unused) */
1333 unpack_string (char *src
, char *dest
, int length
)
1342 pack_threadid (char *pkt
, threadref
*id
)
1345 unsigned char *altid
;
1347 altid
= (unsigned char *) id
;
1348 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1350 pkt
= pack_hex_byte (pkt
, *altid
++);
1356 unpack_threadid (char *inbuf
, threadref
*id
)
1359 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1362 altref
= (char *) id
;
1364 while (inbuf
< limit
)
1366 x
= stubhex (*inbuf
++);
1367 y
= stubhex (*inbuf
++);
1368 *altref
++ = (x
<< 4) | y
;
1373 /* Externally, threadrefs are 64 bits but internally, they are still
1374 ints. This is due to a mismatch of specifications. We would like
1375 to use 64bit thread references internally. This is an adapter
1379 int_to_threadref (threadref
*id
, int value
)
1381 unsigned char *scan
;
1383 scan
= (unsigned char *) id
;
1389 *scan
++ = (value
>> 24) & 0xff;
1390 *scan
++ = (value
>> 16) & 0xff;
1391 *scan
++ = (value
>> 8) & 0xff;
1392 *scan
++ = (value
& 0xff);
1396 threadref_to_int (threadref
*ref
)
1399 unsigned char *scan
;
1401 scan
= (char *) ref
;
1405 value
= (value
<< 8) | ((*scan
++) & 0xff);
1410 copy_threadref (threadref
*dest
, threadref
*src
)
1413 unsigned char *csrc
, *cdest
;
1415 csrc
= (unsigned char *) src
;
1416 cdest
= (unsigned char *) dest
;
1423 threadmatch (threadref
*dest
, threadref
*src
)
1425 /* things are broken right now, so just assume we got a match */
1427 unsigned char *srcp
, *destp
;
1429 srcp
= (char *) src
;
1430 destp
= (char *) dest
;
1434 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1441 threadid:1, # always request threadid
1448 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1451 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1453 *pkt
++ = 'q'; /* Info Query */
1454 *pkt
++ = 'P'; /* process or thread info */
1455 pkt
= pack_int (pkt
, mode
); /* mode */
1456 pkt
= pack_threadid (pkt
, id
); /* threadid */
1457 *pkt
= '\0'; /* terminate */
1461 /* These values tag the fields in a thread info response packet */
1462 /* Tagging the fields allows us to request specific fields and to
1463 add more fields as time goes by */
1465 #define TAG_THREADID 1 /* Echo the thread identifier */
1466 #define TAG_EXISTS 2 /* Is this process defined enough to
1467 fetch registers and its stack */
1468 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1469 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1470 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1474 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1475 struct gdb_ext_thread_info
*info
)
1477 struct remote_state
*rs
= get_remote_state ();
1481 char *limit
= pkt
+ (rs
->remote_packet_size
); /* plausable parsing limit */
1484 /* info->threadid = 0; FIXME: implement zero_threadref */
1486 info
->display
[0] = '\0';
1487 info
->shortname
[0] = '\0';
1488 info
->more_display
[0] = '\0';
1490 /* Assume the characters indicating the packet type have been stripped */
1491 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1492 pkt
= unpack_threadid (pkt
, &ref
);
1495 warning ("Incomplete response to threadinfo request\n");
1496 if (!threadmatch (&ref
, expectedref
))
1497 { /* This is an answer to a different request */
1498 warning ("ERROR RMT Thread info mismatch\n");
1501 copy_threadref (&info
->threadid
, &ref
);
1503 /* Loop on tagged fields , try to bail if somthing goes wrong */
1505 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1507 pkt
= unpack_int (pkt
, &tag
); /* tag */
1508 pkt
= unpack_byte (pkt
, &length
); /* length */
1509 if (!(tag
& mask
)) /* tags out of synch with mask */
1511 warning ("ERROR RMT: threadinfo tag mismatch\n");
1515 if (tag
== TAG_THREADID
)
1519 warning ("ERROR RMT: length of threadid is not 16\n");
1523 pkt
= unpack_threadid (pkt
, &ref
);
1524 mask
= mask
& ~TAG_THREADID
;
1527 if (tag
== TAG_EXISTS
)
1529 info
->active
= stub_unpack_int (pkt
, length
);
1531 mask
= mask
& ~(TAG_EXISTS
);
1534 warning ("ERROR RMT: 'exists' length too long\n");
1540 if (tag
== TAG_THREADNAME
)
1542 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1543 mask
= mask
& ~TAG_THREADNAME
;
1546 if (tag
== TAG_DISPLAY
)
1548 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1549 mask
= mask
& ~TAG_DISPLAY
;
1552 if (tag
== TAG_MOREDISPLAY
)
1554 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1555 mask
= mask
& ~TAG_MOREDISPLAY
;
1558 warning ("ERROR RMT: unknown thread info tag\n");
1559 break; /* Not a tag we know about */
1565 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1566 struct gdb_ext_thread_info
*info
)
1568 struct remote_state
*rs
= get_remote_state ();
1570 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1572 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1573 putpkt (threadinfo_pkt
);
1574 getpkt (threadinfo_pkt
, (rs
->remote_packet_size
), 0);
1575 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1580 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1581 representation of a threadid. */
1584 adapt_remote_get_threadinfo (gdb_threadref
*ref
, int selection
,
1585 struct gdb_ext_thread_info
*info
)
1589 int_to_threadref (&lclref
, *ref
);
1590 return remote_get_threadinfo (&lclref
, selection
, info
);
1593 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1596 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1597 threadref
*nextthread
)
1599 *pkt
++ = 'q'; /* info query packet */
1600 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1601 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1602 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1603 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1608 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1611 parse_threadlist_response (char *pkt
, int result_limit
,
1612 threadref
*original_echo
, threadref
*resultlist
,
1615 struct remote_state
*rs
= get_remote_state ();
1617 int count
, resultcount
, done
;
1620 /* Assume the 'q' and 'M chars have been stripped. */
1621 limit
= pkt
+ ((rs
->remote_packet_size
) - BUF_THREAD_ID_SIZE
); /* done parse past here */
1622 pkt
= unpack_byte (pkt
, &count
); /* count field */
1623 pkt
= unpack_nibble (pkt
, &done
);
1624 /* The first threadid is the argument threadid. */
1625 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1626 while ((count
-- > 0) && (pkt
< limit
))
1628 pkt
= unpack_threadid (pkt
, resultlist
++);
1629 if (resultcount
++ >= result_limit
)
1638 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1639 int *done
, int *result_count
, threadref
*threadlist
)
1641 struct remote_state
*rs
= get_remote_state ();
1642 static threadref echo_nextthread
;
1643 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1644 char *t_response
= alloca (rs
->remote_packet_size
);
1647 /* Trancate result limit to be smaller than the packet size */
1648 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= (rs
->remote_packet_size
))
1649 result_limit
= ((rs
->remote_packet_size
) / BUF_THREAD_ID_SIZE
) - 2;
1651 pack_threadlist_request (threadlist_packet
,
1652 startflag
, result_limit
, nextthread
);
1653 putpkt (threadlist_packet
);
1654 getpkt (t_response
, (rs
->remote_packet_size
), 0);
1657 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1660 if (!threadmatch (&echo_nextthread
, nextthread
))
1662 /* FIXME: This is a good reason to drop the packet */
1663 /* Possably, there is a duplicate response */
1665 retransmit immediatly - race conditions
1666 retransmit after timeout - yes
1668 wait for packet, then exit
1670 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1671 return 0; /* I choose simply exiting */
1673 if (*result_count
<= 0)
1677 warning ("RMT ERROR : failed to get remote thread list\n");
1680 return result
; /* break; */
1682 if (*result_count
> result_limit
)
1685 warning ("RMT ERROR: threadlist response longer than requested\n");
1691 /* This is the interface between remote and threads, remotes upper interface */
1693 /* remote_find_new_threads retrieves the thread list and for each
1694 thread in the list, looks up the thread in GDB's internal list,
1695 ading the thread if it does not already exist. This involves
1696 getting partial thread lists from the remote target so, polling the
1697 quit_flag is required. */
1700 /* About this many threadisds fit in a packet. */
1702 #define MAXTHREADLISTRESULTS 32
1705 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1708 int done
, i
, result_count
;
1712 static threadref nextthread
;
1713 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1718 if (loopcount
++ > looplimit
)
1721 warning ("Remote fetch threadlist -infinite loop-\n");
1724 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1725 &done
, &result_count
, resultthreadlist
))
1730 /* clear for later iterations */
1732 /* Setup to resume next batch of thread references, set nextthread. */
1733 if (result_count
>= 1)
1734 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1736 while (result_count
--)
1737 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1744 remote_newthread_step (threadref
*ref
, void *context
)
1748 ptid
= pid_to_ptid (threadref_to_int (ref
));
1750 if (!in_thread_list (ptid
))
1752 return 1; /* continue iterator */
1755 #define CRAZY_MAX_THREADS 1000
1758 remote_current_thread (ptid_t oldpid
)
1760 struct remote_state
*rs
= get_remote_state ();
1761 char *buf
= alloca (rs
->remote_packet_size
);
1764 getpkt (buf
, (rs
->remote_packet_size
), 0);
1765 if (buf
[0] == 'Q' && buf
[1] == 'C')
1766 return pid_to_ptid (strtol (&buf
[2], NULL
, 16));
1771 /* Find new threads for info threads command.
1772 * Original version, using John Metzler's thread protocol.
1776 remote_find_new_threads (void)
1778 remote_threadlist_iterator (remote_newthread_step
, 0,
1780 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1781 inferior_ptid
= remote_current_thread (inferior_ptid
);
1785 * Find all threads for info threads command.
1786 * Uses new thread protocol contributed by Cisco.
1787 * Falls back and attempts to use the older method (above)
1788 * if the target doesn't respond to the new method.
1792 remote_threads_info (void)
1794 struct remote_state
*rs
= get_remote_state ();
1795 char *buf
= alloca (rs
->remote_packet_size
);
1799 if (remote_desc
== 0) /* paranoia */
1800 error ("Command can only be used when connected to the remote target.");
1802 if (use_threadinfo_query
)
1804 putpkt ("qfThreadInfo");
1806 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1807 if (bufp
[0] != '\0') /* q packet recognized */
1809 while (*bufp
++ == 'm') /* reply contains one or more TID */
1813 tid
= strtol (bufp
, &bufp
, 16);
1814 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1815 add_thread (pid_to_ptid (tid
));
1817 while (*bufp
++ == ','); /* comma-separated list */
1818 putpkt ("qsThreadInfo");
1820 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1826 /* Else fall back to old method based on jmetzler protocol. */
1827 use_threadinfo_query
= 0;
1828 remote_find_new_threads ();
1833 * Collect a descriptive string about the given thread.
1834 * The target may say anything it wants to about the thread
1835 * (typically info about its blocked / runnable state, name, etc.).
1836 * This string will appear in the info threads display.
1838 * Optional: targets are not required to implement this function.
1842 remote_threads_extra_info (struct thread_info
*tp
)
1844 struct remote_state
*rs
= get_remote_state ();
1848 struct gdb_ext_thread_info threadinfo
;
1849 static char display_buf
[100]; /* arbitrary... */
1850 char *bufp
= alloca (rs
->remote_packet_size
);
1851 int n
= 0; /* position in display_buf */
1853 if (remote_desc
== 0) /* paranoia */
1854 internal_error (__FILE__
, __LINE__
,
1855 "remote_threads_extra_info");
1857 if (use_threadextra_query
)
1859 sprintf (bufp
, "qThreadExtraInfo,%x", PIDGET (tp
->ptid
));
1861 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1864 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1865 result
= hex2bin (bufp
, display_buf
, n
);
1866 display_buf
[result
] = '\0';
1871 /* If the above query fails, fall back to the old method. */
1872 use_threadextra_query
= 0;
1873 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1874 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1875 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1876 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1877 if (threadinfo
.active
)
1879 if (*threadinfo
.shortname
)
1880 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1881 if (*threadinfo
.display
)
1882 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1883 if (*threadinfo
.more_display
)
1884 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1885 threadinfo
.more_display
);
1889 /* for purely cosmetic reasons, clear up trailing commas */
1890 if (',' == display_buf
[n
-1])
1891 display_buf
[n
-1] = ' ';
1900 /* Restart the remote side; this is an extended protocol operation. */
1903 extended_remote_restart (void)
1905 struct remote_state
*rs
= get_remote_state ();
1906 char *buf
= alloca (rs
->remote_packet_size
);
1908 /* Send the restart command; for reasons I don't understand the
1909 remote side really expects a number after the "R". */
1911 sprintf (&buf
[1], "%x", 0);
1914 /* Now query for status so this looks just like we restarted
1915 gdbserver from scratch. */
1917 getpkt (buf
, (rs
->remote_packet_size
), 0);
1920 /* Clean up connection to a remote debugger. */
1923 remote_close (int quitting
)
1926 serial_close (remote_desc
);
1930 /* Query the remote side for the text, data and bss offsets. */
1935 struct remote_state
*rs
= get_remote_state ();
1936 char *buf
= alloca (rs
->remote_packet_size
);
1939 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1940 struct section_offsets
*offs
;
1942 putpkt ("qOffsets");
1944 getpkt (buf
, (rs
->remote_packet_size
), 0);
1946 if (buf
[0] == '\000')
1947 return; /* Return silently. Stub doesn't support
1951 warning ("Remote failure reply: %s", buf
);
1955 /* Pick up each field in turn. This used to be done with scanf, but
1956 scanf will make trouble if CORE_ADDR size doesn't match
1957 conversion directives correctly. The following code will work
1958 with any size of CORE_ADDR. */
1959 text_addr
= data_addr
= bss_addr
= 0;
1963 if (strncmp (ptr
, "Text=", 5) == 0)
1966 /* Don't use strtol, could lose on big values. */
1967 while (*ptr
&& *ptr
!= ';')
1968 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1973 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1976 while (*ptr
&& *ptr
!= ';')
1977 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1982 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1985 while (*ptr
&& *ptr
!= ';')
1986 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1992 error ("Malformed response to offset query, %s", buf
);
1994 if (symfile_objfile
== NULL
)
1997 offs
= ((struct section_offsets
*)
1998 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
1999 memcpy (offs
, symfile_objfile
->section_offsets
,
2000 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2002 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2004 /* This is a temporary kludge to force data and bss to use the same offsets
2005 because that's what nlmconv does now. The real solution requires changes
2006 to the stub and remote.c that I don't have time to do right now. */
2008 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2009 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2011 objfile_relocate (symfile_objfile
, offs
);
2015 * Cisco version of section offsets:
2017 * Instead of having GDB query the target for the section offsets,
2018 * Cisco lets the target volunteer the information! It's also in
2019 * a different format, so here are the functions that will decode
2020 * a section offset packet from a Cisco target.
2024 * Function: remote_cisco_section_offsets
2026 * Returns: zero for success, non-zero for failure
2030 remote_cisco_section_offsets (bfd_vma text_addr
,
2033 bfd_signed_vma
*text_offs
,
2034 bfd_signed_vma
*data_offs
,
2035 bfd_signed_vma
*bss_offs
)
2037 bfd_vma text_base
, data_base
, bss_base
;
2038 struct minimal_symbol
*start
;
2043 if (symfile_objfile
== NULL
)
2044 return -1; /* no can do nothin' */
2046 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
2048 return -1; /* Can't find "_start" symbol */
2050 data_base
= bss_base
= 0;
2051 text_base
= SYMBOL_VALUE_ADDRESS (start
);
2053 abfd
= symfile_objfile
->obfd
;
2054 for (sect
= abfd
->sections
;
2058 const char *p
= bfd_get_section_name (abfd
, sect
);
2060 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
2061 if (data_base
== 0 ||
2062 data_base
> bfd_get_section_vma (abfd
, sect
))
2063 data_base
= bfd_get_section_vma (abfd
, sect
);
2064 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
2065 if (bss_base
== 0 ||
2066 bss_base
> bfd_get_section_vma (abfd
, sect
))
2067 bss_base
= bfd_get_section_vma (abfd
, sect
);
2069 *text_offs
= text_addr
- text_base
;
2070 *data_offs
= data_addr
- data_base
;
2071 *bss_offs
= bss_addr
- bss_base
;
2076 sprintf (tmp
, "VMA: text = 0x");
2077 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
2078 sprintf (tmp
+ strlen (tmp
), " data = 0x");
2079 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
2080 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
2081 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
2082 fputs_filtered (tmp
, gdb_stdlog
);
2083 fprintf_filtered (gdb_stdlog
,
2084 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
2085 paddr_nz (*text_offs
),
2086 paddr_nz (*data_offs
),
2087 paddr_nz (*bss_offs
));
2094 * Function: remote_cisco_objfile_relocate
2096 * Relocate the symbol file for a remote target.
2100 remote_cisco_objfile_relocate (bfd_signed_vma text_off
, bfd_signed_vma data_off
,
2101 bfd_signed_vma bss_off
)
2103 struct section_offsets
*offs
;
2105 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2107 /* FIXME: This code assumes gdb-stabs.h is being used; it's
2108 broken for xcoff, dwarf, sdb-coff, etc. But there is no
2109 simple canonical representation for this stuff. */
2111 offs
= (struct section_offsets
*)
2112 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2113 memcpy (offs
, symfile_objfile
->section_offsets
,
2114 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2116 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_off
;
2117 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_off
;
2118 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = bss_off
;
2120 /* First call the standard objfile_relocate. */
2121 objfile_relocate (symfile_objfile
, offs
);
2123 /* Now we need to fix up the section entries already attached to
2124 the exec target. These entries will control memory transfers
2125 from the exec file. */
2127 exec_set_section_offsets (text_off
, data_off
, bss_off
);
2131 /* Stub for catch_errors. */
2134 remote_start_remote_dummy (struct ui_out
*uiout
, void *dummy
)
2136 start_remote (); /* Initialize gdb process mechanisms */
2137 /* NOTE: Return something >=0. A -ve value is reserved for
2138 catch_exceptions. */
2143 remote_start_remote (struct ui_out
*uiout
, void *dummy
)
2145 immediate_quit
++; /* Allow user to interrupt it */
2147 /* Ack any packet which the remote side has already sent. */
2148 serial_write (remote_desc
, "+", 1);
2150 /* Let the stub know that we want it to return the thread. */
2153 inferior_ptid
= remote_current_thread (inferior_ptid
);
2155 get_offsets (); /* Get text, data & bss offsets */
2157 putpkt ("?"); /* initiate a query from remote machine */
2160 /* NOTE: See comment above in remote_start_remote_dummy(). This
2161 function returns something >=0. */
2162 return remote_start_remote_dummy (uiout
, dummy
);
2165 /* Open a connection to a remote debugger.
2166 NAME is the filename used for communication. */
2169 remote_open (char *name
, int from_tty
)
2171 remote_open_1 (name
, from_tty
, &remote_ops
, 0, 0);
2174 /* Just like remote_open, but with asynchronous support. */
2176 remote_async_open (char *name
, int from_tty
)
2178 remote_open_1 (name
, from_tty
, &remote_async_ops
, 0, 1);
2181 /* Open a connection to a remote debugger using the extended
2182 remote gdb protocol. NAME is the filename used for communication. */
2185 extended_remote_open (char *name
, int from_tty
)
2187 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */,
2191 /* Just like extended_remote_open, but with asynchronous support. */
2193 extended_remote_async_open (char *name
, int from_tty
)
2195 remote_open_1 (name
, from_tty
, &extended_async_remote_ops
,
2196 1 /*extended_p */, 1 /* async_p */);
2199 /* Generic code for opening a connection to a remote target. */
2202 init_all_packet_configs (void)
2205 update_packet_config (&remote_protocol_e
);
2206 update_packet_config (&remote_protocol_E
);
2207 update_packet_config (&remote_protocol_P
);
2208 update_packet_config (&remote_protocol_qSymbol
);
2209 update_packet_config (&remote_protocol_vcont
);
2210 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2211 update_packet_config (&remote_protocol_Z
[i
]);
2212 /* Force remote_write_bytes to check whether target supports binary
2214 update_packet_config (&remote_protocol_binary_download
);
2217 /* Symbol look-up. */
2220 remote_check_symbols (struct objfile
*objfile
)
2222 struct remote_state
*rs
= get_remote_state ();
2223 char *msg
, *reply
, *tmp
;
2224 struct minimal_symbol
*sym
;
2227 if (remote_protocol_qSymbol
.support
== PACKET_DISABLE
)
2230 msg
= alloca (rs
->remote_packet_size
);
2231 reply
= alloca (rs
->remote_packet_size
);
2233 /* Invite target to request symbol lookups. */
2235 putpkt ("qSymbol::");
2236 getpkt (reply
, (rs
->remote_packet_size
), 0);
2237 packet_ok (reply
, &remote_protocol_qSymbol
);
2239 while (strncmp (reply
, "qSymbol:", 8) == 0)
2242 end
= hex2bin (tmp
, msg
, strlen (tmp
) / 2);
2244 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2246 sprintf (msg
, "qSymbol::%s", &reply
[8]);
2248 sprintf (msg
, "qSymbol:%s:%s",
2249 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2252 getpkt (reply
, (rs
->remote_packet_size
), 0);
2256 static struct serial
*
2257 remote_serial_open (char *name
)
2259 static int udp_warning
= 0;
2261 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2262 of in ser-tcp.c, because it is the remote protocol assuming that the
2263 serial connection is reliable and not the serial connection promising
2265 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2267 warning ("The remote protocol may be unreliable over UDP.");
2268 warning ("Some events may be lost, rendering further debugging "
2273 return serial_open (name
);
2277 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2278 int extended_p
, int async_p
)
2281 struct remote_state
*rs
= get_remote_state ();
2283 error ("To open a remote debug connection, you need to specify what\n"
2284 "serial device is attached to the remote system\n"
2285 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2287 /* See FIXME above */
2289 wait_forever_enabled_p
= 1;
2291 target_preopen (from_tty
);
2293 unpush_target (target
);
2295 remote_desc
= remote_serial_open (name
);
2297 perror_with_name (name
);
2299 if (baud_rate
!= -1)
2301 if (serial_setbaudrate (remote_desc
, baud_rate
))
2303 /* The requested speed could not be set. Error out to
2304 top level after closing remote_desc. Take care to
2305 set remote_desc to NULL to avoid closing remote_desc
2307 serial_close (remote_desc
);
2309 perror_with_name (name
);
2313 serial_raw (remote_desc
);
2315 /* If there is something sitting in the buffer we might take it as a
2316 response to a command, which would be bad. */
2317 serial_flush_input (remote_desc
);
2321 puts_filtered ("Remote debugging using ");
2322 puts_filtered (name
);
2323 puts_filtered ("\n");
2325 push_target (target
); /* Switch to using remote target now */
2327 init_all_packet_configs ();
2329 general_thread
= -2;
2330 continue_thread
= -2;
2332 /* Probe for ability to use "ThreadInfo" query, as required. */
2333 use_threadinfo_query
= 1;
2334 use_threadextra_query
= 1;
2336 /* Without this, some commands which require an active target (such
2337 as kill) won't work. This variable serves (at least) double duty
2338 as both the pid of the target process (if it has such), and as a
2339 flag indicating that a target is active. These functions should
2340 be split out into seperate variables, especially since GDB will
2341 someday have a notion of debugging several processes. */
2343 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2347 /* With this target we start out by owning the terminal. */
2348 remote_async_terminal_ours_p
= 1;
2350 /* FIXME: cagney/1999-09-23: During the initial connection it is
2351 assumed that the target is already ready and able to respond to
2352 requests. Unfortunately remote_start_remote() eventually calls
2353 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2354 around this. Eventually a mechanism that allows
2355 wait_for_inferior() to expect/get timeouts will be
2357 wait_forever_enabled_p
= 0;
2360 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2361 /* First delete any symbols previously loaded from shared libraries. */
2362 no_shared_libraries (NULL
, 0);
2365 /* Start the remote connection. If error() or QUIT, discard this
2366 target (we'd otherwise be in an inconsistent state) and then
2367 propogate the error on up the exception chain. This ensures that
2368 the caller doesn't stumble along blindly assuming that the
2369 function succeeded. The CLI doesn't have this problem but other
2370 UI's, such as MI do.
2372 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2373 this function should return an error indication letting the
2374 caller restore the previous state. Unfortunately the command
2375 ``target remote'' is directly wired to this function making that
2376 impossible. On a positive note, the CLI side of this problem has
2377 been fixed - the function set_cmd_context() makes it possible for
2378 all the ``target ....'' commands to share a common callback
2379 function. See cli-dump.c. */
2380 ex
= catch_exceptions (uiout
,
2381 remote_start_remote
, NULL
,
2382 "Couldn't establish connection to remote"
2389 wait_forever_enabled_p
= 1;
2390 throw_exception (ex
);
2394 wait_forever_enabled_p
= 1;
2398 /* Tell the remote that we are using the extended protocol. */
2399 char *buf
= alloca (rs
->remote_packet_size
);
2401 getpkt (buf
, (rs
->remote_packet_size
), 0);
2403 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2404 /* FIXME: need a master target_open vector from which all
2405 remote_opens can be called, so that stuff like this can
2406 go there. Failing that, the following code must be copied
2407 to the open function for any remote target that wants to
2408 support svr4 shared libraries. */
2410 /* Set up to detect and load shared libraries. */
2411 if (exec_bfd
) /* No use without an exec file. */
2413 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2414 remote_check_symbols (symfile_objfile
);
2419 /* This takes a program previously attached to and detaches it. After
2420 this is done, GDB can be used to debug some other program. We
2421 better not have left any breakpoints in the target program or it'll
2422 die when it hits one. */
2425 remote_detach (char *args
, int from_tty
)
2427 struct remote_state
*rs
= get_remote_state ();
2428 char *buf
= alloca (rs
->remote_packet_size
);
2431 error ("Argument given to \"detach\" when remotely debugging.");
2433 /* Tell the remote target to detach. */
2435 remote_send (buf
, (rs
->remote_packet_size
));
2437 /* Unregister the file descriptor from the event loop. */
2438 if (target_is_async_p ())
2439 serial_async (remote_desc
, NULL
, 0);
2441 target_mourn_inferior ();
2443 puts_filtered ("Ending remote debugging.\n");
2446 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
2449 remote_disconnect (char *args
, int from_tty
)
2451 struct remote_state
*rs
= get_remote_state ();
2452 char *buf
= alloca (rs
->remote_packet_size
);
2455 error ("Argument given to \"detach\" when remotely debugging.");
2457 /* Unregister the file descriptor from the event loop. */
2458 if (target_is_async_p ())
2459 serial_async (remote_desc
, NULL
, 0);
2461 target_mourn_inferior ();
2463 puts_filtered ("Ending remote debugging.\n");
2466 /* Convert hex digit A to a number. */
2471 if (a
>= '0' && a
<= '9')
2473 else if (a
>= 'a' && a
<= 'f')
2474 return a
- 'a' + 10;
2475 else if (a
>= 'A' && a
<= 'F')
2476 return a
- 'A' + 10;
2478 error ("Reply contains invalid hex digit %d", a
);
2482 hex2bin (const char *hex
, char *bin
, int count
)
2486 for (i
= 0; i
< count
; i
++)
2488 if (hex
[0] == 0 || hex
[1] == 0)
2490 /* Hex string is short, or of uneven length.
2491 Return the count that has been converted so far. */
2494 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2500 /* Convert number NIB to a hex digit. */
2508 return 'a' + nib
- 10;
2512 bin2hex (const char *bin
, char *hex
, int count
)
2515 /* May use a length, or a nul-terminated string as input. */
2517 count
= strlen (bin
);
2519 for (i
= 0; i
< count
; i
++)
2521 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2522 *hex
++ = tohex (*bin
++ & 0xf);
2528 /* Check for the availability of vCont. This function should also check
2532 remote_vcont_probe (struct remote_state
*rs
, char *buf
)
2534 strcpy (buf
, "vCont?");
2536 getpkt (buf
, rs
->remote_packet_size
, 0);
2538 /* Make sure that the features we assume are supported. */
2539 if (strncmp (buf
, "vCont", 5) == 0)
2542 int support_s
, support_S
, support_c
, support_C
;
2548 while (p
&& *p
== ';')
2551 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2553 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2555 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2557 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2560 p
= strchr (p
, ';');
2563 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
2564 BUF will make packet_ok disable the packet. */
2565 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
2569 packet_ok (buf
, &remote_protocol_vcont
);
2572 /* Resume the remote inferior by using a "vCont" packet. The thread
2573 to be resumed is PTID; STEP and SIGGNAL indicate whether the
2574 resumed thread should be single-stepped and/or signalled. If PTID's
2575 PID is -1, then all threads are resumed; the thread to be stepped and/or
2576 signalled is given in the global INFERIOR_PTID. This function returns
2577 non-zero iff it resumes the inferior.
2579 This function issues a strict subset of all possible vCont commands at the
2583 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2585 struct remote_state
*rs
= get_remote_state ();
2586 int pid
= PIDGET (ptid
);
2587 char *buf
= NULL
, *outbuf
;
2588 struct cleanup
*old_cleanup
;
2590 buf
= xmalloc (rs
->remote_packet_size
);
2591 old_cleanup
= make_cleanup (xfree
, buf
);
2593 if (remote_protocol_vcont
.support
== PACKET_SUPPORT_UNKNOWN
)
2594 remote_vcont_probe (rs
, buf
);
2596 if (remote_protocol_vcont
.support
== PACKET_DISABLE
)
2598 do_cleanups (old_cleanup
);
2602 /* If we could generate a wider range of packets, we'd have to worry
2603 about overflowing BUF. Should there be a generic
2604 "multi-part-packet" packet? */
2606 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
)
2608 /* MAGIC_NULL_PTID means that we don't have any active threads, so we
2609 don't have any PID numbers the inferior will understand. Make sure
2610 to only send forms that do not specify a PID. */
2611 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2612 outbuf
= xstrprintf ("vCont;S%02x", siggnal
);
2614 outbuf
= xstrprintf ("vCont;s");
2615 else if (siggnal
!= TARGET_SIGNAL_0
)
2616 outbuf
= xstrprintf ("vCont;C%02x", siggnal
);
2618 outbuf
= xstrprintf ("vCont;c");
2622 /* Resume all threads, with preference for INFERIOR_PTID. */
2623 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2624 outbuf
= xstrprintf ("vCont;S%02x:%x;c", siggnal
,
2625 PIDGET (inferior_ptid
));
2627 outbuf
= xstrprintf ("vCont;s:%x;c", PIDGET (inferior_ptid
));
2628 else if (siggnal
!= TARGET_SIGNAL_0
)
2629 outbuf
= xstrprintf ("vCont;C%02x:%x;c", siggnal
,
2630 PIDGET (inferior_ptid
));
2632 outbuf
= xstrprintf ("vCont;c");
2636 /* Scheduler locking; resume only PTID. */
2637 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2638 outbuf
= xstrprintf ("vCont;S%02x:%x", siggnal
, pid
);
2640 outbuf
= xstrprintf ("vCont;s:%x", pid
);
2641 else if (siggnal
!= TARGET_SIGNAL_0
)
2642 outbuf
= xstrprintf ("vCont;C%02x:%x", siggnal
, pid
);
2644 outbuf
= xstrprintf ("vCont;c:%x", pid
);
2647 gdb_assert (outbuf
&& strlen (outbuf
) < rs
->remote_packet_size
);
2648 make_cleanup (xfree
, outbuf
);
2652 do_cleanups (old_cleanup
);
2657 /* Tell the remote machine to resume. */
2659 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2661 static int last_sent_step
;
2664 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2666 struct remote_state
*rs
= get_remote_state ();
2667 char *buf
= alloca (rs
->remote_packet_size
);
2668 int pid
= PIDGET (ptid
);
2671 last_sent_signal
= siggnal
;
2672 last_sent_step
= step
;
2674 /* A hook for when we need to do something at the last moment before
2676 if (target_resume_hook
)
2677 (*target_resume_hook
) ();
2679 /* The vCont packet doesn't need to specify threads via Hc. */
2680 if (remote_vcont_resume (ptid
, step
, siggnal
))
2683 /* All other supported resume packets do use Hc, so call set_thread. */
2685 set_thread (0, 0); /* run any thread */
2687 set_thread (pid
, 0); /* run this thread */
2689 /* The s/S/c/C packets do not return status. So if the target does
2690 not support the S or C packets, the debug agent returns an empty
2691 string which is detected in remote_wait(). This protocol defect
2692 is fixed in the e/E packets. */
2694 if (step
&& step_range_end
)
2696 /* If the target does not support the 'E' packet, we try the 'S'
2697 packet. Ideally we would fall back to the 'e' packet if that
2698 too is not supported. But that would require another copy of
2699 the code to issue the 'e' packet (and fall back to 's' if not
2700 supported) in remote_wait(). */
2702 if (siggnal
!= TARGET_SIGNAL_0
)
2704 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2708 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2709 *p
++ = tohex (((int) siggnal
) & 0xf);
2711 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2713 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2717 getpkt (buf
, (rs
->remote_packet_size
), 0);
2719 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2725 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2729 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2731 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2735 getpkt (buf
, (rs
->remote_packet_size
), 0);
2737 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2743 if (siggnal
!= TARGET_SIGNAL_0
)
2745 buf
[0] = step
? 'S' : 'C';
2746 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2747 buf
[2] = tohex (((int) siggnal
) & 0xf);
2751 strcpy (buf
, step
? "s" : "c");
2756 /* Same as remote_resume, but with async support. */
2758 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2760 remote_resume (ptid
, step
, siggnal
);
2762 /* We are about to start executing the inferior, let's register it
2763 with the event loop. NOTE: this is the one place where all the
2764 execution commands end up. We could alternatively do this in each
2765 of the execution commands in infcmd.c.*/
2766 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2767 into infcmd.c in order to allow inferior function calls to work
2768 NOT asynchronously. */
2769 if (event_loop_p
&& target_can_async_p ())
2770 target_async (inferior_event_handler
, 0);
2771 /* Tell the world that the target is now executing. */
2772 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2773 this? Instead, should the client of target just assume (for
2774 async targets) that the target is going to start executing? Is
2775 this information already found in the continuation block? */
2776 if (target_is_async_p ())
2777 target_executing
= 1;
2781 /* Set up the signal handler for SIGINT, while the target is
2782 executing, ovewriting the 'regular' SIGINT signal handler. */
2784 initialize_sigint_signal_handler (void)
2786 sigint_remote_token
=
2787 create_async_signal_handler (async_remote_interrupt
, NULL
);
2788 signal (SIGINT
, handle_remote_sigint
);
2791 /* Signal handler for SIGINT, while the target is executing. */
2793 handle_remote_sigint (int sig
)
2795 signal (sig
, handle_remote_sigint_twice
);
2796 sigint_remote_twice_token
=
2797 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2798 mark_async_signal_handler_wrapper (sigint_remote_token
);
2801 /* Signal handler for SIGINT, installed after SIGINT has already been
2802 sent once. It will take effect the second time that the user sends
2805 handle_remote_sigint_twice (int sig
)
2807 signal (sig
, handle_sigint
);
2808 sigint_remote_twice_token
=
2809 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2810 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2813 /* Perform the real interruption of the target execution, in response
2816 async_remote_interrupt (gdb_client_data arg
)
2819 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2824 /* Perform interrupt, if the first attempt did not succeed. Just give
2825 up on the target alltogether. */
2827 async_remote_interrupt_twice (gdb_client_data arg
)
2830 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2831 /* Do something only if the target was not killed by the previous
2833 if (target_executing
)
2836 signal (SIGINT
, handle_remote_sigint
);
2840 /* Reinstall the usual SIGINT handlers, after the target has
2843 cleanup_sigint_signal_handler (void *dummy
)
2845 signal (SIGINT
, handle_sigint
);
2846 if (sigint_remote_twice_token
)
2847 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2848 if (sigint_remote_token
)
2849 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2852 /* Send ^C to target to halt it. Target will respond, and send us a
2854 static void (*ofunc
) (int);
2856 /* The command line interface's stop routine. This function is installed
2857 as a signal handler for SIGINT. The first time a user requests a
2858 stop, we call remote_stop to send a break or ^C. If there is no
2859 response from the target (it didn't stop when the user requested it),
2860 we ask the user if he'd like to detach from the target. */
2862 remote_interrupt (int signo
)
2864 /* If this doesn't work, try more severe steps. */
2865 signal (signo
, remote_interrupt_twice
);
2868 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2873 /* The user typed ^C twice. */
2876 remote_interrupt_twice (int signo
)
2878 signal (signo
, ofunc
);
2880 signal (signo
, remote_interrupt
);
2883 /* This is the generic stop called via the target vector. When a target
2884 interrupt is requested, either by the command line or the GUI, we
2885 will eventually end up here. */
2889 /* Send a break or a ^C, depending on user preference. */
2891 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2894 serial_send_break (remote_desc
);
2896 serial_write (remote_desc
, "\003", 1);
2899 /* Ask the user what to do when an interrupt is received. */
2902 interrupt_query (void)
2904 target_terminal_ours ();
2906 if (query ("Interrupted while waiting for the program.\n\
2907 Give up (and stop debugging it)? "))
2909 target_mourn_inferior ();
2910 throw_exception (RETURN_QUIT
);
2913 target_terminal_inferior ();
2916 /* Enable/disable target terminal ownership. Most targets can use
2917 terminal groups to control terminal ownership. Remote targets are
2918 different in that explicit transfer of ownership to/from GDB/target
2922 remote_async_terminal_inferior (void)
2924 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2925 sync_execution here. This function should only be called when
2926 GDB is resuming the inferior in the forground. A background
2927 resume (``run&'') should leave GDB in control of the terminal and
2928 consequently should not call this code. */
2929 if (!sync_execution
)
2931 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2932 calls target_terminal_*() idenpotent. The event-loop GDB talking
2933 to an asynchronous target with a synchronous command calls this
2934 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2935 stops trying to transfer the terminal to the target when it
2936 shouldn't this guard can go away. */
2937 if (!remote_async_terminal_ours_p
)
2939 delete_file_handler (input_fd
);
2940 remote_async_terminal_ours_p
= 0;
2941 initialize_sigint_signal_handler ();
2942 /* NOTE: At this point we could also register our selves as the
2943 recipient of all input. Any characters typed could then be
2944 passed on down to the target. */
2948 remote_async_terminal_ours (void)
2950 /* See FIXME in remote_async_terminal_inferior. */
2951 if (!sync_execution
)
2953 /* See FIXME in remote_async_terminal_inferior. */
2954 if (remote_async_terminal_ours_p
)
2956 cleanup_sigint_signal_handler (NULL
);
2957 add_file_handler (input_fd
, stdin_event_handler
, 0);
2958 remote_async_terminal_ours_p
= 1;
2961 /* If nonzero, ignore the next kill. */
2966 remote_console_output (char *msg
)
2970 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2973 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2976 fputs_unfiltered (tb
, gdb_stdtarg
);
2978 gdb_flush (gdb_stdtarg
);
2981 /* Wait until the remote machine stops, then return,
2982 storing status in STATUS just as `wait' would.
2983 Returns "pid", which in the case of a multi-threaded
2984 remote OS, is the thread-id. */
2987 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2989 struct remote_state
*rs
= get_remote_state ();
2990 unsigned char *buf
= alloca (rs
->remote_packet_size
);
2991 ULONGEST thread_num
= -1;
2994 status
->kind
= TARGET_WAITKIND_EXITED
;
2995 status
->value
.integer
= 0;
3001 ofunc
= signal (SIGINT
, remote_interrupt
);
3002 getpkt (buf
, (rs
->remote_packet_size
), 1);
3003 signal (SIGINT
, ofunc
);
3005 /* This is a hook for when we need to do something (perhaps the
3006 collection of trace data) every time the target stops. */
3007 if (target_wait_loop_hook
)
3008 (*target_wait_loop_hook
) ();
3010 remote_stopped_by_watchpoint_p
= 0;
3014 case 'E': /* Error of some sort */
3015 warning ("Remote failure reply: %s", buf
);
3017 case 'F': /* File-I/O request */
3018 remote_fileio_request (buf
);
3020 case 'T': /* Status with PC, SP, FP, ... */
3023 char regs
[MAX_REGISTER_SIZE
];
3025 /* Expedited reply, containing Signal, {regno, reg} repeat */
3026 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3028 n... = register number
3029 r... = register contents
3031 p
= &buf
[3]; /* after Txx */
3040 /* If the packet contains a register number save it in pnum
3041 and set p1 to point to the character following it.
3042 Otherwise p1 points to p. */
3044 /* If this packet is an awatch packet, don't parse the 'a'
3045 as a register number. */
3047 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
3049 /* Read the ``P'' register number. */
3050 pnum
= strtol (p
, &p_temp
, 16);
3051 p1
= (unsigned char *) p_temp
;
3056 if (p1
== p
) /* No register number present here */
3058 p1
= (unsigned char *) strchr (p
, ':');
3060 warning ("Malformed packet(a) (missing colon): %s\n\
3063 if (strncmp (p
, "thread", p1
- p
) == 0)
3065 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3066 record_currthread (thread_num
);
3067 p
= (unsigned char *) p_temp
;
3069 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3070 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3071 || (strncmp (p
, "awatch", p1
- p
) == 0))
3073 remote_stopped_by_watchpoint_p
= 1;
3074 p
= unpack_varlen_hex (++p1
, &addr
);
3075 remote_watch_data_address
= (CORE_ADDR
)addr
;
3079 /* Silently skip unknown optional info. */
3080 p_temp
= strchr (p1
+ 1, ';');
3082 p
= (unsigned char *) p_temp
;
3087 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3091 error ("Malformed packet(b) (missing colon): %s\nPacket: '%s'\n",
3095 error ("Remote sent bad register number %s: %s\nPacket: '%s'\n",
3096 phex_nz (pnum
, 0), p
, buf
);
3098 fieldsize
= hex2bin (p
, regs
, DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
));
3100 if (fieldsize
< DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
))
3101 warning ("Remote reply is too short: %s", buf
);
3102 supply_register (reg
->regnum
, regs
);
3106 error ("Remote register badly formatted: %s\nhere: %s", buf
, p
);
3110 case 'S': /* Old style status, just signal only */
3111 status
->kind
= TARGET_WAITKIND_STOPPED
;
3112 status
->value
.sig
= (enum target_signal
)
3113 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3117 /* Export Cisco kernel mode as a convenience variable
3118 (so that it can be used in the GDB prompt if desired). */
3120 if (cisco_kernel_mode
== 1)
3121 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3122 value_from_string ("PDEBUG-"));
3123 cisco_kernel_mode
= 0;
3124 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3125 record_currthread (thread_num
);
3127 else if (buf
[3] == 'k')
3129 /* Export Cisco kernel mode as a convenience variable
3130 (so that it can be used in the GDB prompt if desired). */
3132 if (cisco_kernel_mode
== 1)
3133 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3134 value_from_string ("KDEBUG-"));
3135 cisco_kernel_mode
= 1;
3138 case 'N': /* Cisco special: status and offsets */
3140 bfd_vma text_addr
, data_addr
, bss_addr
;
3141 bfd_signed_vma text_off
, data_off
, bss_off
;
3144 status
->kind
= TARGET_WAITKIND_STOPPED
;
3145 status
->value
.sig
= (enum target_signal
)
3146 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3148 if (symfile_objfile
== NULL
)
3150 warning ("Relocation packet received with no symbol file. \
3155 /* Relocate object file. Buffer format is NAATT;DD;BB
3156 * where AA is the signal number, TT is the new text
3157 * address, DD * is the new data address, and BB is the
3158 * new bss address. */
3161 text_addr
= strtoul (p
, (char **) &p1
, 16);
3162 if (p1
== p
|| *p1
!= ';')
3163 warning ("Malformed relocation packet: Packet '%s'", buf
);
3165 data_addr
= strtoul (p
, (char **) &p1
, 16);
3166 if (p1
== p
|| *p1
!= ';')
3167 warning ("Malformed relocation packet: Packet '%s'", buf
);
3169 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3171 warning ("Malformed relocation packet: Packet '%s'", buf
);
3173 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3174 &text_off
, &data_off
, &bss_off
)
3176 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3177 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3181 case 'W': /* Target exited */
3183 /* The remote process exited. */
3184 status
->kind
= TARGET_WAITKIND_EXITED
;
3185 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3189 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3190 status
->value
.sig
= (enum target_signal
)
3191 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3195 case 'O': /* Console output */
3196 remote_console_output (buf
+ 1);
3199 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3201 /* Zero length reply means that we tried 'S' or 'C' and
3202 the remote system doesn't support it. */
3203 target_terminal_ours_for_output ();
3205 ("Can't send signals to this remote system. %s not sent.\n",
3206 target_signal_to_name (last_sent_signal
));
3207 last_sent_signal
= TARGET_SIGNAL_0
;
3208 target_terminal_inferior ();
3210 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3211 putpkt ((char *) buf
);
3214 /* else fallthrough */
3216 warning ("Invalid remote reply: %s", buf
);
3221 if (thread_num
!= -1)
3223 return pid_to_ptid (thread_num
);
3225 return inferior_ptid
;
3228 /* Async version of remote_wait. */
3230 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3232 struct remote_state
*rs
= get_remote_state ();
3233 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3234 ULONGEST thread_num
= -1;
3237 status
->kind
= TARGET_WAITKIND_EXITED
;
3238 status
->value
.integer
= 0;
3240 remote_stopped_by_watchpoint_p
= 0;
3246 if (!target_is_async_p ())
3247 ofunc
= signal (SIGINT
, remote_interrupt
);
3248 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3249 _never_ wait for ever -> test on target_is_async_p().
3250 However, before we do that we need to ensure that the caller
3251 knows how to take the target into/out of async mode. */
3252 getpkt (buf
, (rs
->remote_packet_size
), wait_forever_enabled_p
);
3253 if (!target_is_async_p ())
3254 signal (SIGINT
, ofunc
);
3256 /* This is a hook for when we need to do something (perhaps the
3257 collection of trace data) every time the target stops. */
3258 if (target_wait_loop_hook
)
3259 (*target_wait_loop_hook
) ();
3263 case 'E': /* Error of some sort */
3264 warning ("Remote failure reply: %s", buf
);
3266 case 'F': /* File-I/O request */
3267 remote_fileio_request (buf
);
3269 case 'T': /* Status with PC, SP, FP, ... */
3272 char regs
[MAX_REGISTER_SIZE
];
3274 /* Expedited reply, containing Signal, {regno, reg} repeat */
3275 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3277 n... = register number
3278 r... = register contents
3280 p
= &buf
[3]; /* after Txx */
3289 /* If the packet contains a register number, save it in pnum
3290 and set p1 to point to the character following it.
3291 Otherwise p1 points to p. */
3293 /* If this packet is an awatch packet, don't parse the 'a'
3294 as a register number. */
3296 if (!strncmp (p
, "awatch", strlen ("awatch")) != 0)
3298 /* Read the register number. */
3299 pnum
= strtol (p
, &p_temp
, 16);
3300 p1
= (unsigned char *) p_temp
;
3305 if (p1
== p
) /* No register number present here */
3307 p1
= (unsigned char *) strchr (p
, ':');
3309 error ("Malformed packet(a) (missing colon): %s\nPacket: '%s'\n",
3311 if (strncmp (p
, "thread", p1
- p
) == 0)
3313 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3314 record_currthread (thread_num
);
3315 p
= (unsigned char *) p_temp
;
3317 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3318 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3319 || (strncmp (p
, "awatch", p1
- p
) == 0))
3321 remote_stopped_by_watchpoint_p
= 1;
3322 p
= unpack_varlen_hex (++p1
, &addr
);
3323 remote_watch_data_address
= (CORE_ADDR
)addr
;
3327 /* Silently skip unknown optional info. */
3328 p_temp
= (unsigned char *) strchr (p1
+ 1, ';');
3336 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3339 error ("Malformed packet(b) (missing colon): %s\nPacket: '%s'\n",
3343 error ("Remote sent bad register number %ld: %s\nPacket: '%s'\n",
3346 fieldsize
= hex2bin (p
, regs
, DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
));
3348 if (fieldsize
< DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
))
3349 warning ("Remote reply is too short: %s", buf
);
3350 supply_register (reg
->regnum
, regs
);
3354 error ("Remote register badly formatted: %s\nhere: %s",
3359 case 'S': /* Old style status, just signal only */
3360 status
->kind
= TARGET_WAITKIND_STOPPED
;
3361 status
->value
.sig
= (enum target_signal
)
3362 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3366 /* Export Cisco kernel mode as a convenience variable
3367 (so that it can be used in the GDB prompt if desired). */
3369 if (cisco_kernel_mode
== 1)
3370 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3371 value_from_string ("PDEBUG-"));
3372 cisco_kernel_mode
= 0;
3373 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3374 record_currthread (thread_num
);
3376 else if (buf
[3] == 'k')
3378 /* Export Cisco kernel mode as a convenience variable
3379 (so that it can be used in the GDB prompt if desired). */
3381 if (cisco_kernel_mode
== 1)
3382 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3383 value_from_string ("KDEBUG-"));
3384 cisco_kernel_mode
= 1;
3387 case 'N': /* Cisco special: status and offsets */
3389 bfd_vma text_addr
, data_addr
, bss_addr
;
3390 bfd_signed_vma text_off
, data_off
, bss_off
;
3393 status
->kind
= TARGET_WAITKIND_STOPPED
;
3394 status
->value
.sig
= (enum target_signal
)
3395 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3397 if (symfile_objfile
== NULL
)
3399 warning ("Relocation packet recieved with no symbol file. \
3404 /* Relocate object file. Buffer format is NAATT;DD;BB
3405 * where AA is the signal number, TT is the new text
3406 * address, DD * is the new data address, and BB is the
3407 * new bss address. */
3410 text_addr
= strtoul (p
, (char **) &p1
, 16);
3411 if (p1
== p
|| *p1
!= ';')
3412 warning ("Malformed relocation packet: Packet '%s'", buf
);
3414 data_addr
= strtoul (p
, (char **) &p1
, 16);
3415 if (p1
== p
|| *p1
!= ';')
3416 warning ("Malformed relocation packet: Packet '%s'", buf
);
3418 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3420 warning ("Malformed relocation packet: Packet '%s'", buf
);
3422 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3423 &text_off
, &data_off
, &bss_off
)
3425 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3426 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3430 case 'W': /* Target exited */
3432 /* The remote process exited. */
3433 status
->kind
= TARGET_WAITKIND_EXITED
;
3434 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3438 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3439 status
->value
.sig
= (enum target_signal
)
3440 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3444 case 'O': /* Console output */
3445 remote_console_output (buf
+ 1);
3446 /* Return immediately to the event loop. The event loop will
3447 still be waiting on the inferior afterwards. */
3448 status
->kind
= TARGET_WAITKIND_IGNORE
;
3451 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3453 /* Zero length reply means that we tried 'S' or 'C' and
3454 the remote system doesn't support it. */
3455 target_terminal_ours_for_output ();
3457 ("Can't send signals to this remote system. %s not sent.\n",
3458 target_signal_to_name (last_sent_signal
));
3459 last_sent_signal
= TARGET_SIGNAL_0
;
3460 target_terminal_inferior ();
3462 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3463 putpkt ((char *) buf
);
3466 /* else fallthrough */
3468 warning ("Invalid remote reply: %s", buf
);
3473 if (thread_num
!= -1)
3475 return pid_to_ptid (thread_num
);
3477 return inferior_ptid
;
3480 /* Number of bytes of registers this stub implements. */
3482 static int register_bytes_found
;
3484 /* Read the remote registers into the block REGS. */
3485 /* Currently we just read all the registers, so we don't use regnum. */
3488 remote_fetch_registers (int regnum
)
3490 struct remote_state
*rs
= get_remote_state ();
3491 char *buf
= alloca (rs
->remote_packet_size
);
3494 char *regs
= alloca (rs
->sizeof_g_packet
);
3496 set_thread (PIDGET (inferior_ptid
), 1);
3500 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3501 gdb_assert (reg
!= NULL
);
3502 if (!reg
->in_g_packet
)
3503 internal_error (__FILE__
, __LINE__
,
3504 "Attempt to fetch a non G-packet register when this "
3505 "remote.c does not support the p-packet.");
3509 remote_send (buf
, (rs
->remote_packet_size
));
3511 /* Save the size of the packet sent to us by the target. Its used
3512 as a heuristic when determining the max size of packets that the
3513 target can safely receive. */
3514 if ((rs
->actual_register_packet_size
) == 0)
3515 (rs
->actual_register_packet_size
) = strlen (buf
);
3517 /* Unimplemented registers read as all bits zero. */
3518 memset (regs
, 0, rs
->sizeof_g_packet
);
3520 /* We can get out of synch in various cases. If the first character
3521 in the buffer is not a hex character, assume that has happened
3522 and try to fetch another packet to read. */
3523 while ((buf
[0] < '0' || buf
[0] > '9')
3524 && (buf
[0] < 'a' || buf
[0] > 'f')
3525 && buf
[0] != 'x') /* New: unavailable register value */
3528 fprintf_unfiltered (gdb_stdlog
,
3529 "Bad register packet; fetching a new packet\n");
3530 getpkt (buf
, (rs
->remote_packet_size
), 0);
3533 /* Reply describes registers byte by byte, each byte encoded as two
3534 hex characters. Suck them all up, then supply them to the
3535 register cacheing/storage mechanism. */
3538 for (i
= 0; i
< rs
->sizeof_g_packet
; i
++)
3544 warning ("Remote reply is of odd length: %s", buf
);
3545 /* Don't change register_bytes_found in this case, and don't
3546 print a second warning. */
3549 if (p
[0] == 'x' && p
[1] == 'x')
3550 regs
[i
] = 0; /* 'x' */
3552 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3556 if (i
!= register_bytes_found
)
3558 register_bytes_found
= i
;
3559 if (REGISTER_BYTES_OK_P ()
3560 && !REGISTER_BYTES_OK (i
))
3561 warning ("Remote reply is too short: %s", buf
);
3567 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3569 struct packet_reg
*r
= &rs
->regs
[i
];
3572 if (r
->offset
* 2 >= strlen (buf
))
3573 /* A short packet that didn't include the register's
3574 value, this implies that the register is zero (and
3575 not that the register is unavailable). Supply that
3577 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3578 else if (buf
[r
->offset
* 2] == 'x')
3580 gdb_assert (r
->offset
* 2 < strlen (buf
));
3581 /* The register isn't available, mark it as such (at
3582 the same time setting the value to zero). */
3583 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3584 set_register_cached (i
, -1);
3587 regcache_raw_supply (current_regcache
, r
->regnum
,
3594 /* Prepare to store registers. Since we may send them all (using a
3595 'G' request), we have to read out the ones we don't want to change
3599 remote_prepare_to_store (void)
3601 struct remote_state
*rs
= get_remote_state ();
3603 char buf
[MAX_REGISTER_SIZE
];
3605 /* Make sure the entire registers array is valid. */
3606 switch (remote_protocol_P
.support
)
3608 case PACKET_DISABLE
:
3609 case PACKET_SUPPORT_UNKNOWN
:
3610 /* Make sure all the necessary registers are cached. */
3611 for (i
= 0; i
< NUM_REGS
; i
++)
3612 if (rs
->regs
[i
].in_g_packet
)
3613 regcache_raw_read (current_regcache
, rs
->regs
[i
].regnum
, buf
);
3620 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3621 packet was not recognized. */
3624 store_register_using_P (int regnum
)
3626 struct remote_state
*rs
= get_remote_state ();
3627 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3628 /* Try storing a single register. */
3629 char *buf
= alloca (rs
->remote_packet_size
);
3630 char regp
[MAX_REGISTER_SIZE
];
3634 sprintf (buf
, "P%s=", phex_nz (reg
->pnum
, 0));
3635 p
= buf
+ strlen (buf
);
3636 regcache_collect (reg
->regnum
, regp
);
3637 bin2hex (regp
, p
, DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
));
3638 remote_send (buf
, rs
->remote_packet_size
);
3640 return buf
[0] != '\0';
3644 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
3645 of the register cache buffer. FIXME: ignores errors. */
3648 remote_store_registers (int regnum
)
3650 struct remote_state
*rs
= get_remote_state ();
3656 set_thread (PIDGET (inferior_ptid
), 1);
3660 switch (remote_protocol_P
.support
)
3662 case PACKET_DISABLE
:
3665 if (store_register_using_P (regnum
))
3668 error ("Protocol error: P packet not recognized by stub");
3669 case PACKET_SUPPORT_UNKNOWN
:
3670 if (store_register_using_P (regnum
))
3672 /* The stub recognized the 'P' packet. Remember this. */
3673 remote_protocol_P
.support
= PACKET_ENABLE
;
3678 /* The stub does not support the 'P' packet. Use 'G'
3679 instead, and don't try using 'P' in the future (it
3680 will just waste our time). */
3681 remote_protocol_P
.support
= PACKET_DISABLE
;
3687 /* Extract all the registers in the regcache copying them into a
3691 regs
= alloca (rs
->sizeof_g_packet
);
3692 memset (regs
, rs
->sizeof_g_packet
, 0);
3693 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3695 struct packet_reg
*r
= &rs
->regs
[i
];
3697 regcache_collect (r
->regnum
, regs
+ r
->offset
);
3701 /* Command describes registers byte by byte,
3702 each byte encoded as two hex characters. */
3703 buf
= alloca (rs
->remote_packet_size
);
3706 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3707 bin2hex (regs
, p
, register_bytes_found
);
3708 remote_send (buf
, (rs
->remote_packet_size
));
3712 /* Return the number of hex digits in num. */
3715 hexnumlen (ULONGEST num
)
3719 for (i
= 0; num
!= 0; i
++)
3725 /* Set BUF to the minimum number of hex digits representing NUM. */
3728 hexnumstr (char *buf
, ULONGEST num
)
3730 int len
= hexnumlen (num
);
3731 return hexnumnstr (buf
, num
, len
);
3735 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3738 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3744 for (i
= width
- 1; i
>= 0; i
--)
3746 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3753 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3756 remote_address_masked (CORE_ADDR addr
)
3758 if (remote_address_size
> 0
3759 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3761 /* Only create a mask when that mask can safely be constructed
3762 in a ULONGEST variable. */
3764 mask
= (mask
<< remote_address_size
) - 1;
3770 /* Determine whether the remote target supports binary downloading.
3771 This is accomplished by sending a no-op memory write of zero length
3772 to the target at the specified address. It does not suffice to send
3773 the whole packet, since many stubs strip the eighth bit and subsequently
3774 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3776 NOTE: This can still lose if the serial line is not eight-bit
3777 clean. In cases like this, the user should clear "remote
3781 check_binary_download (CORE_ADDR addr
)
3783 struct remote_state
*rs
= get_remote_state ();
3784 switch (remote_protocol_binary_download
.support
)
3786 case PACKET_DISABLE
:
3790 case PACKET_SUPPORT_UNKNOWN
:
3792 char *buf
= alloca (rs
->remote_packet_size
);
3797 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3799 p
+= hexnumstr (p
, (ULONGEST
) 0);
3803 putpkt_binary (buf
, (int) (p
- buf
));
3804 getpkt (buf
, (rs
->remote_packet_size
), 0);
3809 fprintf_unfiltered (gdb_stdlog
,
3810 "binary downloading NOT suppported by target\n");
3811 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3816 fprintf_unfiltered (gdb_stdlog
,
3817 "binary downloading suppported by target\n");
3818 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3825 /* Write memory data directly to the remote machine.
3826 This does not inform the data cache; the data cache uses this.
3827 MEMADDR is the address in the remote memory space.
3828 MYADDR is the address of the buffer in our space.
3829 LEN is the number of bytes.
3831 Returns number of bytes transferred, or 0 (setting errno) for
3832 error. Only transfer a single packet. */
3835 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3839 unsigned char *plen
;
3845 unsigned char *payload_start
;
3847 /* Verify that the target can support a binary download. */
3848 check_binary_download (memaddr
);
3850 /* Compute the size, and then allocate space for the largest
3851 possible packet. Include space for an extra trailing NUL. */
3852 sizeof_buf
= get_memory_write_packet_size () + 1;
3853 buf
= alloca (sizeof_buf
);
3855 /* Compute the size of the actual payload by subtracting out the
3856 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
3857 payload_size
= (get_memory_write_packet_size () - (strlen ("$M,:#NN")
3858 + hexnumlen (memaddr
)
3859 + hexnumlen (len
)));
3861 /* Construct the packet header: "[MX]<memaddr>,<len>:". */
3863 /* Append "[XM]". Compute a best guess of the number of bytes
3864 actually transfered. */
3866 switch (remote_protocol_binary_download
.support
)
3870 /* Best guess at number of bytes that will fit. */
3871 todo
= min (len
, payload_size
);
3873 case PACKET_DISABLE
:
3875 /* num bytes that will fit */
3876 todo
= min (len
, payload_size
/ 2);
3878 case PACKET_SUPPORT_UNKNOWN
:
3879 internal_error (__FILE__
, __LINE__
,
3880 "remote_write_bytes: bad internal state");
3882 internal_error (__FILE__
, __LINE__
, "bad switch");
3885 /* Append "<memaddr>". */
3886 memaddr
= remote_address_masked (memaddr
);
3887 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3892 /* Append <len>. Retain the location/size of <len>. It may need to
3893 be adjusted once the packet body has been created. */
3895 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3902 /* Append the packet body. */
3904 switch (remote_protocol_binary_download
.support
)
3907 /* Binary mode. Send target system values byte by byte, in
3908 increasing byte addresses. Only escape certain critical
3911 (nr_bytes
< todo
) && (p
- payload_start
) < payload_size
;
3914 switch (myaddr
[nr_bytes
] & 0xff)
3919 /* These must be escaped */
3921 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3924 *p
++ = myaddr
[nr_bytes
] & 0xff;
3928 if (nr_bytes
< todo
)
3930 /* Escape chars have filled up the buffer prematurely,
3931 and we have actually sent fewer bytes than planned.
3932 Fix-up the length field of the packet. Use the same
3933 number of characters as before. */
3934 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3935 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3938 case PACKET_DISABLE
:
3939 /* Normal mode: Send target system values byte by byte, in
3940 increasing byte addresses. Each byte is encoded as a two hex
3942 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3945 case PACKET_SUPPORT_UNKNOWN
:
3946 internal_error (__FILE__
, __LINE__
,
3947 "remote_write_bytes: bad internal state");
3949 internal_error (__FILE__
, __LINE__
, "bad switch");
3952 putpkt_binary (buf
, (int) (p
- buf
));
3953 getpkt (buf
, sizeof_buf
, 0);
3957 /* There is no correspondance between what the remote protocol
3958 uses for errors and errno codes. We would like a cleaner way
3959 of representing errors (big enough to include errno codes,
3960 bfd_error codes, and others). But for now just return EIO. */
3965 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3966 bytes than we'd planned. */
3970 /* Read memory data directly from the remote machine.
3971 This does not use the data cache; the data cache uses this.
3972 MEMADDR is the address in the remote memory space.
3973 MYADDR is the address of the buffer in our space.
3974 LEN is the number of bytes.
3976 Returns number of bytes transferred, or 0 for error. */
3978 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3979 remote targets) shouldn't attempt to read the entire buffer.
3980 Instead it should read a single packet worth of data and then
3981 return the byte size of that packet to the caller. The caller (its
3982 caller and its callers caller ;-) already contains code for
3983 handling partial reads. */
3986 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3989 int max_buf_size
; /* Max size of packet output buffer */
3993 /* Create a buffer big enough for this packet. */
3994 max_buf_size
= get_memory_read_packet_size ();
3995 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3996 buf
= alloca (sizeof_buf
);
4005 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
4007 /* construct "m"<memaddr>","<len>" */
4008 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
4009 memaddr
= remote_address_masked (memaddr
);
4012 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
4014 p
+= hexnumstr (p
, (ULONGEST
) todo
);
4018 getpkt (buf
, sizeof_buf
, 0);
4021 && isxdigit (buf
[1]) && isxdigit (buf
[2])
4024 /* There is no correspondance between what the remote protocol uses
4025 for errors and errno codes. We would like a cleaner way of
4026 representing errors (big enough to include errno codes, bfd_error
4027 codes, and others). But for now just return EIO. */
4032 /* Reply describes memory byte by byte,
4033 each byte encoded as two hex characters. */
4036 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
4038 /* Reply is short. This means that we were able to read
4039 only part of what we wanted to. */
4040 return i
+ (origlen
- len
);
4049 /* Read or write LEN bytes from inferior memory at MEMADDR,
4050 transferring to or from debugger address BUFFER. Write to inferior if
4051 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
4052 for error. TARGET is unused. */
4055 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
4056 int should_write
, struct mem_attrib
*attrib
,
4057 struct target_ops
*target
)
4059 CORE_ADDR targ_addr
;
4063 /* Should this be the selected frame? */
4064 gdbarch_remote_translate_xfer_address (current_gdbarch
, current_regcache
,
4066 &targ_addr
, &targ_len
);
4071 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
4073 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
4079 remote_files_info (struct target_ops
*ignore
)
4081 puts_filtered ("Debugging a target over a serial line.\n");
4084 /* Stuff for dealing with the packets which are part of this protocol.
4085 See comment at top of file for details. */
4087 /* Read a single character from the remote end, masking it down to 7 bits. */
4090 readchar (int timeout
)
4094 ch
= serial_readchar (remote_desc
, timeout
);
4099 switch ((enum serial_rc
) ch
)
4102 target_mourn_inferior ();
4103 error ("Remote connection closed");
4106 perror_with_name ("Remote communication error");
4108 case SERIAL_TIMEOUT
:
4114 /* Send the command in BUF to the remote machine, and read the reply
4115 into BUF. Report an error if we get an error reply. */
4118 remote_send (char *buf
,
4122 getpkt (buf
, sizeof_buf
, 0);
4125 error ("Remote failure reply: %s", buf
);
4128 /* Display a null-terminated packet on stdout, for debugging, using C
4132 print_packet (char *buf
)
4134 puts_filtered ("\"");
4135 fputstr_filtered (buf
, '"', gdb_stdout
);
4136 puts_filtered ("\"");
4142 return putpkt_binary (buf
, strlen (buf
));
4145 /* Send a packet to the remote machine, with error checking. The data
4146 of the packet is in BUF. The string in BUF can be at most (rs->remote_packet_size) - 5
4147 to account for the $, # and checksum, and for a possible /0 if we are
4148 debugging (remote_debug) and want to print the sent packet as a string */
4151 putpkt_binary (char *buf
, int cnt
)
4153 struct remote_state
*rs
= get_remote_state ();
4155 unsigned char csum
= 0;
4156 char *buf2
= alloca (cnt
+ 6);
4157 long sizeof_junkbuf
= (rs
->remote_packet_size
);
4158 char *junkbuf
= alloca (sizeof_junkbuf
);
4164 /* Copy the packet into buffer BUF2, encapsulating it
4165 and giving it a checksum. */
4170 for (i
= 0; i
< cnt
; i
++)
4176 *p
++ = tohex ((csum
>> 4) & 0xf);
4177 *p
++ = tohex (csum
& 0xf);
4179 /* Send it over and over until we get a positive ack. */
4183 int started_error_output
= 0;
4188 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4189 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4190 fprintf_unfiltered (gdb_stdlog
, "...");
4191 gdb_flush (gdb_stdlog
);
4193 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4194 perror_with_name ("putpkt: write failed");
4196 /* read until either a timeout occurs (-2) or '+' is read */
4199 ch
= readchar (remote_timeout
);
4207 case SERIAL_TIMEOUT
:
4209 if (started_error_output
)
4211 putchar_unfiltered ('\n');
4212 started_error_output
= 0;
4221 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4225 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4226 case SERIAL_TIMEOUT
:
4230 break; /* Retransmit buffer */
4234 fprintf_unfiltered (gdb_stdlog
, "Packet instead of Ack, ignoring it\n");
4235 /* It's probably an old response, and we're out of sync.
4236 Just gobble up the packet and ignore it. */
4237 read_frame (junkbuf
, sizeof_junkbuf
);
4238 continue; /* Now, go look for + */
4243 if (!started_error_output
)
4245 started_error_output
= 1;
4246 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4248 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4252 break; /* Here to retransmit */
4256 /* This is wrong. If doing a long backtrace, the user should be
4257 able to get out next time we call QUIT, without anything as
4258 violent as interrupt_query. If we want to provide a way out of
4259 here without getting to the next QUIT, it should be based on
4260 hitting ^C twice as in remote_wait. */
4270 static int remote_cisco_mode
;
4272 /* Come here after finding the start of the frame. Collect the rest
4273 into BUF, verifying the checksum, length, and handling run-length
4274 compression. No more than sizeof_buf-1 characters are read so that
4275 the buffer can be NUL terminated.
4277 Returns -1 on error, number of characters in buffer (ignoring the
4278 trailing NULL) on success. (could be extended to return one of the
4279 SERIAL status indications). */
4282 read_frame (char *buf
,
4294 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
4295 c
= readchar (remote_timeout
);
4298 case SERIAL_TIMEOUT
:
4300 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4304 fputs_filtered ("Saw new packet start in middle of old one\n",
4306 return -1; /* Start a new packet, count retries */
4309 unsigned char pktcsum
;
4315 check_0
= readchar (remote_timeout
);
4317 check_1
= readchar (remote_timeout
);
4319 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4322 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog
);
4325 else if (check_0
< 0 || check_1
< 0)
4328 fputs_filtered ("Communication error in checksum\n", gdb_stdlog
);
4332 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4333 if (csum
== pktcsum
)
4338 fprintf_filtered (gdb_stdlog
,
4339 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4341 fputs_filtered (buf
, gdb_stdlog
);
4342 fputs_filtered ("\n", gdb_stdlog
);
4344 /* Number of characters in buffer ignoring trailing
4348 case '*': /* Run length encoding */
4353 if (remote_cisco_mode
== 0)
4355 c
= readchar (remote_timeout
);
4357 repeat
= c
- ' ' + 3; /* Compute repeat count */
4361 /* Cisco's run-length encoding variant uses two
4362 hex chars to represent the repeat count. */
4364 c
= readchar (remote_timeout
);
4366 repeat
= fromhex (c
) << 4;
4367 c
= readchar (remote_timeout
);
4369 repeat
+= fromhex (c
);
4372 /* The character before ``*'' is repeated. */
4374 if (repeat
> 0 && repeat
<= 255
4376 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4378 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4384 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
4385 puts_filtered (buf
);
4386 puts_filtered ("\n");
4390 if (bc
< sizeof_buf
- 1)
4398 puts_filtered ("Remote packet too long: ");
4399 puts_filtered (buf
);
4400 puts_filtered ("\n");
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. */
4411 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4412 don't have to change all the calls to getpkt to deal with the
4413 return value, because at the moment I don't know what the right
4414 thing to do it for those. */
4422 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4426 /* Read a packet from the remote machine, with error checking, and
4427 store it in BUF. If FOREVER, wait forever rather than timing out;
4428 this is used (in synchronous mode) to wait for a target that is is
4429 executing user code to stop. If FOREVER == 0, this function is
4430 allowed to time out gracefully and return an indication of this to
4433 getpkt_sane (char *buf
,
4442 strcpy (buf
, "timeout");
4446 timeout
= watchdog
> 0 ? watchdog
: -1;
4450 timeout
= remote_timeout
;
4454 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4456 /* This can loop forever if the remote side sends us characters
4457 continuously, but if it pauses, we'll get a zero from readchar
4458 because of timeout. Then we'll count that as a retry. */
4460 /* Note that we will only wait forever prior to the start of a packet.
4461 After that, we expect characters to arrive at a brisk pace. They
4462 should show up within remote_timeout intervals. */
4466 c
= readchar (timeout
);
4468 if (c
== SERIAL_TIMEOUT
)
4470 if (forever
) /* Watchdog went off? Kill the target. */
4473 target_mourn_inferior ();
4474 error ("Watchdog has expired. Target detached.\n");
4477 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4483 /* We've found the start of a packet, now collect the data. */
4485 val
= read_frame (buf
, sizeof_buf
);
4491 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4492 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4493 fprintf_unfiltered (gdb_stdlog
, "\n");
4495 serial_write (remote_desc
, "+", 1);
4499 /* Try the whole thing again. */
4501 serial_write (remote_desc
, "-", 1);
4504 /* We have tried hard enough, and just can't receive the packet. Give up. */
4506 printf_unfiltered ("Ignoring packet error, continuing...\n");
4507 serial_write (remote_desc
, "+", 1);
4514 /* For some mysterious reason, wait_for_inferior calls kill instead of
4515 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4519 target_mourn_inferior ();
4523 /* Use catch_errors so the user can quit from gdb even when we aren't on
4524 speaking terms with the remote system. */
4525 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4527 /* Don't wait for it to die. I'm not really sure it matters whether
4528 we do or not. For the existing stubs, kill is a noop. */
4529 target_mourn_inferior ();
4532 /* Async version of remote_kill. */
4534 remote_async_kill (void)
4536 /* Unregister the file descriptor from the event loop. */
4537 if (target_is_async_p ())
4538 serial_async (remote_desc
, NULL
, 0);
4540 /* For some mysterious reason, wait_for_inferior calls kill instead of
4541 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4545 target_mourn_inferior ();
4549 /* Use catch_errors so the user can quit from gdb even when we aren't on
4550 speaking terms with the remote system. */
4551 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4553 /* Don't wait for it to die. I'm not really sure it matters whether
4554 we do or not. For the existing stubs, kill is a noop. */
4555 target_mourn_inferior ();
4561 remote_mourn_1 (&remote_ops
);
4565 remote_async_mourn (void)
4567 remote_mourn_1 (&remote_async_ops
);
4571 extended_remote_mourn (void)
4573 /* We do _not_ want to mourn the target like this; this will
4574 remove the extended remote target from the target stack,
4575 and the next time the user says "run" it'll fail.
4577 FIXME: What is the right thing to do here? */
4579 remote_mourn_1 (&extended_remote_ops
);
4583 /* Worker function for remote_mourn. */
4585 remote_mourn_1 (struct target_ops
*target
)
4587 unpush_target (target
);
4588 generic_mourn_inferior ();
4591 /* In the extended protocol we want to be able to do things like
4592 "run" and have them basically work as expected. So we need
4593 a special create_inferior function.
4595 FIXME: One day add support for changing the exec file
4596 we're debugging, arguments and an environment. */
4599 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
)
4601 /* Rip out the breakpoints; we'll reinsert them after restarting
4602 the remote server. */
4603 remove_breakpoints ();
4605 /* Now restart the remote server. */
4606 extended_remote_restart ();
4608 /* Now put the breakpoints back in. This way we're safe if the
4609 restart function works via a unix fork on the remote side. */
4610 insert_breakpoints ();
4612 /* Clean up from the last time we were running. */
4613 clear_proceed_status ();
4615 /* Let the remote process run. */
4616 proceed (-1, TARGET_SIGNAL_0
, 0);
4619 /* Async version of extended_remote_create_inferior. */
4621 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
)
4623 /* Rip out the breakpoints; we'll reinsert them after restarting
4624 the remote server. */
4625 remove_breakpoints ();
4627 /* If running asynchronously, register the target file descriptor
4628 with the event loop. */
4629 if (event_loop_p
&& target_can_async_p ())
4630 target_async (inferior_event_handler
, 0);
4632 /* Now restart the remote server. */
4633 extended_remote_restart ();
4635 /* Now put the breakpoints back in. This way we're safe if the
4636 restart function works via a unix fork on the remote side. */
4637 insert_breakpoints ();
4639 /* Clean up from the last time we were running. */
4640 clear_proceed_status ();
4642 /* Let the remote process run. */
4643 proceed (-1, TARGET_SIGNAL_0
, 0);
4647 /* On some machines, e.g. 68k, we may use a different breakpoint
4648 instruction than other targets; in those use
4649 DEPRECATED_REMOTE_BREAKPOINT instead of just BREAKPOINT_FROM_PC.
4650 Also, bi-endian targets may define
4651 DEPRECATED_LITTLE_REMOTE_BREAKPOINT and
4652 DEPRECATED_BIG_REMOTE_BREAKPOINT. If none of these are defined, we
4653 just call the standard routines that are in mem-break.c. */
4655 /* NOTE: cagney/2003-06-08: This is silly. A remote and simulator
4656 target should use an identical BREAKPOINT_FROM_PC. As for native,
4657 the ARCH-OS-tdep.c code can override the default. */
4659 #if defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) && !defined(DEPRECATED_REMOTE_BREAKPOINT)
4660 #define DEPRECATED_REMOTE_BREAKPOINT
4663 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4665 /* If the target isn't bi-endian, just pretend it is. */
4666 #if !defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && !defined (DEPRECATED_BIG_REMOTE_BREAKPOINT)
4667 #define DEPRECATED_LITTLE_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4668 #define DEPRECATED_BIG_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4671 static unsigned char big_break_insn
[] = DEPRECATED_BIG_REMOTE_BREAKPOINT
;
4672 static unsigned char little_break_insn
[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT
;
4674 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4676 /* Insert a breakpoint on targets that don't have any better
4677 breakpoint support. We read the contents of the target location
4678 and stash it, then overwrite it with a breakpoint instruction.
4679 ADDR is the target location in the target machine. CONTENTS_CACHE
4680 is a pointer to memory allocated for saving the target contents.
4681 It is guaranteed by the caller to be long enough to save the number
4682 of bytes returned by BREAKPOINT_FROM_PC. */
4685 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4687 struct remote_state
*rs
= get_remote_state ();
4688 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4693 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4694 If it succeeds, then set the support to PACKET_ENABLE. If it
4695 fails, and the user has explicitly requested the Z support then
4696 report an error, otherwise, mark it disabled and go on. */
4698 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4700 char *buf
= alloca (rs
->remote_packet_size
);
4703 addr
= remote_address_masked (addr
);
4707 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4708 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4709 sprintf (p
, ",%d", bp_size
);
4712 getpkt (buf
, (rs
->remote_packet_size
), 0);
4714 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4720 case PACKET_UNKNOWN
:
4725 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4726 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4730 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4731 val
= target_write_memory (addr
, (char *) big_break_insn
,
4732 sizeof big_break_insn
);
4734 val
= target_write_memory (addr
, (char *) little_break_insn
,
4735 sizeof little_break_insn
);
4740 return memory_insert_breakpoint (addr
, contents_cache
);
4741 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4745 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4747 struct remote_state
*rs
= get_remote_state ();
4750 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4752 char *buf
= alloca (rs
->remote_packet_size
);
4759 addr
= remote_address_masked (addr
);
4760 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4761 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4762 sprintf (p
, ",%d", bp_size
);
4765 getpkt (buf
, (rs
->remote_packet_size
), 0);
4767 return (buf
[0] == 'E');
4770 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4771 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4773 return memory_remove_breakpoint (addr
, contents_cache
);
4774 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4778 watchpoint_to_Z_packet (int type
)
4792 internal_error (__FILE__
, __LINE__
,
4793 "hw_bp_to_z: bad watchpoint type %d", type
);
4798 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4800 struct remote_state
*rs
= get_remote_state ();
4801 char *buf
= alloca (rs
->remote_packet_size
);
4803 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4805 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4806 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4807 remote_protocol_Z
[packet
].name
,
4808 remote_protocol_Z
[packet
].title
);
4810 sprintf (buf
, "Z%x,", packet
);
4811 p
= strchr (buf
, '\0');
4812 addr
= remote_address_masked (addr
);
4813 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4814 sprintf (p
, ",%x", len
);
4817 getpkt (buf
, (rs
->remote_packet_size
), 0);
4819 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4822 case PACKET_UNKNOWN
:
4827 internal_error (__FILE__
, __LINE__
,
4828 "remote_insert_watchpoint: reached end of function");
4833 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4835 struct remote_state
*rs
= get_remote_state ();
4836 char *buf
= alloca (rs
->remote_packet_size
);
4838 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4840 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4841 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4842 remote_protocol_Z
[packet
].name
,
4843 remote_protocol_Z
[packet
].title
);
4845 sprintf (buf
, "z%x,", packet
);
4846 p
= strchr (buf
, '\0');
4847 addr
= remote_address_masked (addr
);
4848 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4849 sprintf (p
, ",%x", len
);
4851 getpkt (buf
, (rs
->remote_packet_size
), 0);
4853 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4856 case PACKET_UNKNOWN
:
4861 internal_error (__FILE__
, __LINE__
,
4862 "remote_remove_watchpoint: reached end of function");
4866 int remote_hw_watchpoint_limit
= -1;
4867 int remote_hw_breakpoint_limit
= -1;
4870 remote_check_watch_resources (int type
, int cnt
, int ot
)
4872 if (type
== bp_hardware_breakpoint
)
4874 if (remote_hw_breakpoint_limit
== 0)
4876 else if (remote_hw_breakpoint_limit
< 0)
4878 else if (cnt
<= remote_hw_breakpoint_limit
)
4883 if (remote_hw_watchpoint_limit
== 0)
4885 else if (remote_hw_watchpoint_limit
< 0)
4889 else if (cnt
<= remote_hw_watchpoint_limit
)
4896 remote_stopped_by_watchpoint (void)
4898 return remote_stopped_by_watchpoint_p
;
4902 remote_stopped_data_address (void)
4904 if (remote_stopped_by_watchpoint ())
4905 return remote_watch_data_address
;
4906 return (CORE_ADDR
)0;
4911 remote_insert_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4914 struct remote_state
*rs
= get_remote_state ();
4915 char *buf
= alloca (rs
->remote_packet_size
);
4918 /* The length field should be set to the size of a breakpoint
4921 BREAKPOINT_FROM_PC (&addr
, &len
);
4923 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4924 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4925 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4926 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4932 addr
= remote_address_masked (addr
);
4933 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4934 sprintf (p
, ",%x", len
);
4937 getpkt (buf
, (rs
->remote_packet_size
), 0);
4939 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4942 case PACKET_UNKNOWN
:
4947 internal_error (__FILE__
, __LINE__
,
4948 "remote_insert_hw_breakpoint: reached end of function");
4953 remote_remove_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4956 struct remote_state
*rs
= get_remote_state ();
4957 char *buf
= alloca (rs
->remote_packet_size
);
4960 /* The length field should be set to the size of a breakpoint
4963 BREAKPOINT_FROM_PC (&addr
, &len
);
4965 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4966 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
4967 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4968 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4974 addr
= remote_address_masked (addr
);
4975 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4976 sprintf (p
, ",%x", len
);
4979 getpkt (buf
, (rs
->remote_packet_size
), 0);
4981 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4984 case PACKET_UNKNOWN
:
4989 internal_error (__FILE__
, __LINE__
,
4990 "remote_remove_hw_breakpoint: reached end of function");
4993 /* Some targets are only capable of doing downloads, and afterwards
4994 they switch to the remote serial protocol. This function provides
4995 a clean way to get from the download target to the remote target.
4996 It's basically just a wrapper so that we don't have to expose any
4997 of the internal workings of remote.c.
4999 Prior to calling this routine, you should shutdown the current
5000 target code, else you will get the "A program is being debugged
5001 already..." message. Usually a call to pop_target() suffices. */
5004 push_remote_target (char *name
, int from_tty
)
5006 printf_filtered ("Switching to remote protocol\n");
5007 remote_open (name
, from_tty
);
5010 /* Table used by the crc32 function to calcuate the checksum. */
5012 static unsigned long crc32_table
[256] =
5015 static unsigned long
5016 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
5018 if (!crc32_table
[1])
5020 /* Initialize the CRC table and the decoding table. */
5024 for (i
= 0; i
< 256; i
++)
5026 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
5027 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
5034 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
5040 /* compare-sections command
5042 With no arguments, compares each loadable section in the exec bfd
5043 with the same memory range on the target, and reports mismatches.
5044 Useful for verifying the image on the target against the exec file.
5045 Depends on the target understanding the new "qCRC:" request. */
5047 /* FIXME: cagney/1999-10-26: This command should be broken down into a
5048 target method (target verify memory) and generic version of the
5049 actual command. This will allow other high-level code (especially
5050 generic_load()) to make use of this target functionality. */
5053 compare_sections_command (char *args
, int from_tty
)
5055 struct remote_state
*rs
= get_remote_state ();
5057 unsigned long host_crc
, target_crc
;
5058 extern bfd
*exec_bfd
;
5059 struct cleanup
*old_chain
;
5062 const char *sectname
;
5063 char *buf
= alloca (rs
->remote_packet_size
);
5070 error ("command cannot be used without an exec file");
5071 if (!current_target
.to_shortname
||
5072 strcmp (current_target
.to_shortname
, "remote") != 0)
5073 error ("command can only be used with remote target");
5075 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
5077 if (!(s
->flags
& SEC_LOAD
))
5078 continue; /* skip non-loadable section */
5080 size
= bfd_get_section_size_before_reloc (s
);
5082 continue; /* skip zero-length section */
5084 sectname
= bfd_get_section_name (exec_bfd
, s
);
5085 if (args
&& strcmp (args
, sectname
) != 0)
5086 continue; /* not the section selected by user */
5088 matched
= 1; /* do this section */
5090 /* FIXME: assumes lma can fit into long */
5091 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
5094 /* be clever; compute the host_crc before waiting for target reply */
5095 sectdata
= xmalloc (size
);
5096 old_chain
= make_cleanup (xfree
, sectdata
);
5097 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
5098 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
5100 getpkt (buf
, (rs
->remote_packet_size
), 0);
5102 error ("target memory fault, section %s, range 0x%s -- 0x%s",
5103 sectname
, paddr (lma
), paddr (lma
+ size
));
5105 error ("remote target does not support this operation");
5107 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
5108 target_crc
= target_crc
* 16 + fromhex (*tmp
);
5110 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
5111 sectname
, paddr (lma
), paddr (lma
+ size
));
5112 if (host_crc
== target_crc
)
5113 printf_filtered ("matched.\n");
5116 printf_filtered ("MIS-MATCHED!\n");
5120 do_cleanups (old_chain
);
5123 warning ("One or more sections of the remote executable does not match\n\
5124 the loaded file\n");
5125 if (args
&& !matched
)
5126 printf_filtered ("No loaded section named '%s'.\n", args
);
5130 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
5131 const char *annex
, void *readbuf
, const void *writebuf
,
5132 ULONGEST offset
, LONGEST len
)
5134 struct remote_state
*rs
= get_remote_state ();
5136 char *buf2
= alloca (rs
->remote_packet_size
);
5137 char *p2
= &buf2
[0];
5140 /* Only handle reads. */
5141 if (writebuf
!= NULL
|| readbuf
== NULL
)
5144 /* Map pre-existing objects onto letters. DO NOT do this for new
5145 objects!!! Instead specify new query packets. */
5148 case TARGET_OBJECT_KOD
:
5151 case TARGET_OBJECT_AVR
:
5158 /* Note: a zero OFFSET and LEN can be used to query the minimum
5160 if (offset
== 0 && len
== 0)
5161 return (rs
->remote_packet_size
);
5162 /* Minimum outbuf size is (rs->remote_packet_size) - if bufsiz is
5163 not large enough let the caller. */
5164 if (len
< (rs
->remote_packet_size
))
5166 len
= rs
->remote_packet_size
;
5168 /* except for querying the minimum buffer size, target must be open */
5170 error ("remote query is only available after target open");
5172 gdb_assert (annex
!= NULL
);
5173 gdb_assert (readbuf
!= NULL
);
5178 /* we used one buffer char for the remote protocol q command and another
5179 for the query type. As the remote protocol encapsulation uses 4 chars
5180 plus one extra in case we are debugging (remote_debug),
5181 we have PBUFZIZ - 7 left to pack the query string */
5183 while (annex
[i
] && (i
< ((rs
->remote_packet_size
) - 8)))
5185 /* Bad caller may have sent forbidden characters. */
5186 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
5191 gdb_assert (annex
[i
] == '\0');
5197 getpkt (readbuf
, len
, 0);
5199 return strlen (readbuf
);
5203 remote_rcmd (char *command
,
5204 struct ui_file
*outbuf
)
5206 struct remote_state
*rs
= get_remote_state ();
5208 char *buf
= alloca (rs
->remote_packet_size
);
5212 error ("remote rcmd is only available after target open");
5214 /* Send a NULL command across as an empty command */
5215 if (command
== NULL
)
5218 /* The query prefix */
5219 strcpy (buf
, "qRcmd,");
5220 p
= strchr (buf
, '\0');
5222 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > (rs
->remote_packet_size
))
5223 error ("\"monitor\" command ``%s'' is too long\n", command
);
5225 /* Encode the actual command */
5226 bin2hex (command
, p
, 0);
5228 if (putpkt (buf
) < 0)
5229 error ("Communication problem with target\n");
5231 /* get/display the response */
5234 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
5236 getpkt (buf
, (rs
->remote_packet_size
), 0);
5238 error ("Target does not support this command\n");
5239 if (buf
[0] == 'O' && buf
[1] != 'K')
5241 remote_console_output (buf
+ 1); /* 'O' message from stub */
5244 if (strcmp (buf
, "OK") == 0)
5246 if (strlen (buf
) == 3 && buf
[0] == 'E'
5247 && isdigit (buf
[1]) && isdigit (buf
[2]))
5249 error ("Protocol error with Rcmd");
5251 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5253 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5254 fputc_unfiltered (c
, outbuf
);
5261 packet_command (char *args
, int from_tty
)
5263 struct remote_state
*rs
= get_remote_state ();
5264 char *buf
= alloca (rs
->remote_packet_size
);
5267 error ("command can only be used with remote target");
5270 error ("remote-packet command requires packet text as argument");
5272 puts_filtered ("sending: ");
5273 print_packet (args
);
5274 puts_filtered ("\n");
5277 getpkt (buf
, (rs
->remote_packet_size
), 0);
5278 puts_filtered ("received: ");
5280 puts_filtered ("\n");
5284 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
5286 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5288 static void threadset_test_cmd (char *cmd
, int tty
);
5290 static void threadalive_test (char *cmd
, int tty
);
5292 static void threadlist_test_cmd (char *cmd
, int tty
);
5294 int get_and_display_threadinfo (threadref
* ref
);
5296 static void threadinfo_test_cmd (char *cmd
, int tty
);
5298 static int thread_display_step (threadref
* ref
, void *context
);
5300 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5302 static void init_remote_threadtests (void);
5304 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
5307 threadset_test_cmd (char *cmd
, int tty
)
5309 int sample_thread
= SAMPLE_THREAD
;
5311 printf_filtered ("Remote threadset test\n");
5312 set_thread (sample_thread
, 1);
5317 threadalive_test (char *cmd
, int tty
)
5319 int sample_thread
= SAMPLE_THREAD
;
5321 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5322 printf_filtered ("PASS: Thread alive test\n");
5324 printf_filtered ("FAIL: Thread alive test\n");
5327 void output_threadid (char *title
, threadref
* ref
);
5330 output_threadid (char *title
, threadref
*ref
)
5334 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
5336 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5340 threadlist_test_cmd (char *cmd
, int tty
)
5343 threadref nextthread
;
5344 int done
, result_count
;
5345 threadref threadlist
[3];
5347 printf_filtered ("Remote Threadlist test\n");
5348 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5349 &result_count
, &threadlist
[0]))
5350 printf_filtered ("FAIL: threadlist test\n");
5353 threadref
*scan
= threadlist
;
5354 threadref
*limit
= scan
+ result_count
;
5356 while (scan
< limit
)
5357 output_threadid (" thread ", scan
++);
5362 display_thread_info (struct gdb_ext_thread_info
*info
)
5364 output_threadid ("Threadid: ", &info
->threadid
);
5365 printf_filtered ("Name: %s\n ", info
->shortname
);
5366 printf_filtered ("State: %s\n", info
->display
);
5367 printf_filtered ("other: %s\n\n", info
->more_display
);
5371 get_and_display_threadinfo (threadref
*ref
)
5375 struct gdb_ext_thread_info threadinfo
;
5377 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5378 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5379 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5380 display_thread_info (&threadinfo
);
5385 threadinfo_test_cmd (char *cmd
, int tty
)
5387 int athread
= SAMPLE_THREAD
;
5391 int_to_threadref (&thread
, athread
);
5392 printf_filtered ("Remote Threadinfo test\n");
5393 if (!get_and_display_threadinfo (&thread
))
5394 printf_filtered ("FAIL cannot get thread info\n");
5398 thread_display_step (threadref
*ref
, void *context
)
5400 /* output_threadid(" threadstep ",ref); *//* simple test */
5401 return get_and_display_threadinfo (ref
);
5405 threadlist_update_test_cmd (char *cmd
, int tty
)
5407 printf_filtered ("Remote Threadlist update test\n");
5408 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5412 init_remote_threadtests (void)
5414 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
5415 "Fetch and print the remote list of thread identifiers, one pkt only");
5416 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5417 "Fetch and display info about one thread");
5418 add_com ("tset", class_obscure
, threadset_test_cmd
,
5419 "Test setting to a different thread");
5420 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5421 "Iterate through updating all remote thread info");
5422 add_com ("talive", class_obscure
, threadalive_test
,
5423 " Remote thread alive test ");
5428 /* Convert a thread ID to a string. Returns the string in a static
5432 remote_pid_to_str (ptid_t ptid
)
5434 static char buf
[30];
5436 sprintf (buf
, "Thread %d", PIDGET (ptid
));
5441 init_remote_ops (void)
5443 remote_ops
.to_shortname
= "remote";
5444 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5446 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5447 Specify the serial device it is connected to\n\
5448 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5449 remote_ops
.to_open
= remote_open
;
5450 remote_ops
.to_close
= remote_close
;
5451 remote_ops
.to_detach
= remote_detach
;
5452 remote_ops
.to_disconnect
= remote_disconnect
;
5453 remote_ops
.to_resume
= remote_resume
;
5454 remote_ops
.to_wait
= remote_wait
;
5455 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5456 remote_ops
.to_store_registers
= remote_store_registers
;
5457 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5458 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
5459 remote_ops
.to_files_info
= remote_files_info
;
5460 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5461 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5462 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5463 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5464 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5465 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5466 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5467 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5468 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5469 remote_ops
.to_kill
= remote_kill
;
5470 remote_ops
.to_load
= generic_load
;
5471 remote_ops
.to_mourn_inferior
= remote_mourn
;
5472 remote_ops
.to_thread_alive
= remote_thread_alive
;
5473 remote_ops
.to_find_new_threads
= remote_threads_info
;
5474 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5475 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5476 remote_ops
.to_stop
= remote_stop
;
5477 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
5478 remote_ops
.to_rcmd
= remote_rcmd
;
5479 remote_ops
.to_stratum
= process_stratum
;
5480 remote_ops
.to_has_all_memory
= 1;
5481 remote_ops
.to_has_memory
= 1;
5482 remote_ops
.to_has_stack
= 1;
5483 remote_ops
.to_has_registers
= 1;
5484 remote_ops
.to_has_execution
= 1;
5485 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5486 remote_ops
.to_magic
= OPS_MAGIC
;
5489 /* Set up the extended remote vector by making a copy of the standard
5490 remote vector and adding to it. */
5493 init_extended_remote_ops (void)
5495 extended_remote_ops
= remote_ops
;
5497 extended_remote_ops
.to_shortname
= "extended-remote";
5498 extended_remote_ops
.to_longname
=
5499 "Extended remote serial target in gdb-specific protocol";
5500 extended_remote_ops
.to_doc
=
5501 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5502 Specify the serial device it is connected to (e.g. /dev/ttya).",
5503 extended_remote_ops
.to_open
= extended_remote_open
;
5504 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5505 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5509 * Command: info remote-process
5511 * This implements Cisco's version of the "info proc" command.
5513 * This query allows the target stub to return an arbitrary string
5514 * (or strings) giving arbitrary information about the target process.
5515 * This is optional; the target stub isn't required to implement it.
5517 * Syntax: qfProcessInfo request first string
5518 * qsProcessInfo request subsequent string
5519 * reply: 'O'<hex-encoded-string>
5520 * 'l' last reply (empty)
5524 remote_info_process (char *args
, int from_tty
)
5526 struct remote_state
*rs
= get_remote_state ();
5527 char *buf
= alloca (rs
->remote_packet_size
);
5529 if (remote_desc
== 0)
5530 error ("Command can only be used when connected to the remote target.");
5532 putpkt ("qfProcessInfo");
5533 getpkt (buf
, (rs
->remote_packet_size
), 0);
5535 return; /* Silently: target does not support this feature. */
5538 error ("info proc: target error.");
5540 while (buf
[0] == 'O') /* Capitol-O packet */
5542 remote_console_output (&buf
[1]);
5543 putpkt ("qsProcessInfo");
5544 getpkt (buf
, (rs
->remote_packet_size
), 0);
5553 remote_cisco_open (char *name
, int from_tty
)
5557 error ("To open a remote debug connection, you need to specify what \n"
5558 "device is attached to the remote system (e.g. host:port).");
5560 /* See FIXME above */
5561 wait_forever_enabled_p
= 1;
5563 target_preopen (from_tty
);
5565 unpush_target (&remote_cisco_ops
);
5567 remote_desc
= remote_serial_open (name
);
5569 perror_with_name (name
);
5572 * If a baud rate was specified on the gdb command line it will
5573 * be greater than the initial value of -1. If it is, use it otherwise
5577 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
5578 if (serial_setbaudrate (remote_desc
, baud_rate
))
5580 /* The requested speed could not be set. Error out to
5581 top level after closing remote_desc. Take care to
5582 set remote_desc to NULL to avoid closing remote_desc
5584 serial_close (remote_desc
);
5586 perror_with_name (name
);
5589 serial_raw (remote_desc
);
5591 /* If there is something sitting in the buffer we might take it as a
5592 response to a command, which would be bad. */
5593 serial_flush_input (remote_desc
);
5597 puts_filtered ("Remote debugging using ");
5598 puts_filtered (name
);
5599 puts_filtered ("\n");
5602 remote_cisco_mode
= 1;
5604 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
5606 init_all_packet_configs ();
5608 general_thread
= -2;
5609 continue_thread
= -2;
5611 /* Probe for ability to use "ThreadInfo" query, as required. */
5612 use_threadinfo_query
= 1;
5613 use_threadextra_query
= 1;
5615 /* Without this, some commands which require an active target (such
5616 as kill) won't work. This variable serves (at least) double duty
5617 as both the pid of the target process (if it has such), and as a
5618 flag indicating that a target is active. These functions should
5619 be split out into seperate variables, especially since GDB will
5620 someday have a notion of debugging several processes. */
5621 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
5623 /* Start the remote connection; if error, discard this target. See
5624 the comments in remote_open_1() for further details such as the
5625 need to re-throw the exception. */
5626 ex
= catch_exceptions (uiout
,
5627 remote_start_remote_dummy
, NULL
,
5628 "Couldn't establish connection to remote"
5634 throw_exception (ex
);
5639 remote_cisco_close (int quitting
)
5641 remote_cisco_mode
= 0;
5642 remote_close (quitting
);
5646 remote_cisco_mourn (void)
5648 remote_mourn_1 (&remote_cisco_ops
);
5660 /* Shared between readsocket() and readtty(). The size is arbitrary,
5661 however all targets are known to support a 400 character packet. */
5662 static char tty_input
[400];
5664 static int escape_count
;
5665 static int echo_check
;
5666 extern int quit_flag
;
5673 /* Loop until the socket doesn't have any more data */
5675 while ((data
= readchar (0)) >= 0)
5677 /* Check for the escape sequence */
5680 /* If this is the fourth escape, get out */
5681 if (++escape_count
== 4)
5686 { /* This is a '|', but not the fourth in a row.
5687 Continue without echoing it. If it isn't actually
5688 one of four in a row, it'll be echoed later. */
5695 /* Ensure any pending '|'s are flushed. */
5697 for (; escape_count
> 0; escape_count
--)
5701 if (data
== '\r') /* If this is a return character, */
5702 continue; /* - just supress it. */
5704 if (echo_check
!= -1) /* Check for echo of user input. */
5706 if (tty_input
[echo_check
] == data
)
5708 gdb_assert (echo_check
<= sizeof (tty_input
));
5709 echo_check
++; /* Character matched user input: */
5710 continue; /* Continue without echoing it. */
5712 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5713 { /* End of the line (and of echo checking). */
5714 echo_check
= -1; /* No more echo supression */
5715 continue; /* Continue without echoing. */
5718 { /* Failed check for echo of user input.
5719 We now have some suppressed output to flush! */
5722 for (j
= 0; j
< echo_check
; j
++)
5723 putchar (tty_input
[j
]);
5727 putchar (data
); /* Default case: output the char. */
5730 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5731 return READ_MORE
; /* Try to read some more */
5733 return FATAL_ERROR
; /* Trouble, bail out */
5741 /* First, read a buffer full from the terminal */
5742 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5743 if (tty_bytecount
== -1)
5745 perror ("readtty: read failed");
5749 /* Remove a quoted newline. */
5750 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5751 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5753 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5754 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5757 /* Turn trailing newlines into returns */
5758 if (tty_input
[tty_bytecount
- 1] == '\n')
5759 tty_input
[tty_bytecount
- 1] = '\r';
5761 /* If the line consists of a ~, enter debugging mode. */
5762 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5765 /* Make this a zero terminated string and write it out */
5766 tty_input
[tty_bytecount
] = 0;
5767 if (serial_write (remote_desc
, tty_input
, tty_bytecount
))
5769 perror_with_name ("readtty: write failed");
5779 fd_set input
; /* file descriptors for select */
5780 int tablesize
; /* max number of FDs for select */
5787 tablesize
= 8 * sizeof (input
);
5791 /* Check for anything from our socket - doesn't block. Note that
5792 this must be done *before* the select as there may be
5793 buffered I/O waiting to be processed. */
5795 if ((status
= readsocket ()) == FATAL_ERROR
)
5797 error ("Debugging terminated by communications error");
5799 else if (status
!= READ_MORE
)
5804 fflush (stdout
); /* Flush output before blocking */
5806 /* Now block on more socket input or TTY input */
5809 FD_SET (fileno (stdin
), &input
);
5810 FD_SET (deprecated_serial_fd (remote_desc
), &input
);
5812 status
= select (tablesize
, &input
, 0, 0, 0);
5813 if ((status
== -1) && (errno
!= EINTR
))
5815 error ("Communications error on select %d", errno
);
5818 /* Handle Control-C typed */
5822 if ((++quit_count
) == 2)
5824 if (query ("Interrupt GDB? "))
5826 printf_filtered ("Interrupted by user.\n");
5827 throw_exception (RETURN_QUIT
);
5834 serial_send_break (remote_desc
);
5836 serial_write (remote_desc
, "\003", 1);
5841 /* Handle console input */
5843 if (FD_ISSET (fileno (stdin
), &input
))
5847 status
= readtty ();
5848 if (status
== READ_MORE
)
5851 return status
; /* telnet session ended */
5857 remote_cisco_wait (ptid_t ptid
, struct target_waitstatus
*status
)
5859 if (minitelnet () != ENTER_DEBUG
)
5861 error ("Debugging session terminated by protocol error");
5864 return remote_wait (ptid
, status
);
5868 init_remote_cisco_ops (void)
5870 remote_cisco_ops
.to_shortname
= "cisco";
5871 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5872 remote_cisco_ops
.to_doc
=
5873 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5874 Specify the serial device it is connected to (e.g. host:2020).";
5875 remote_cisco_ops
.to_open
= remote_cisco_open
;
5876 remote_cisco_ops
.to_close
= remote_cisco_close
;
5877 remote_cisco_ops
.to_detach
= remote_detach
;
5878 remote_cisco_ops
.to_disconnect
= remote_disconnect
;
5879 remote_cisco_ops
.to_resume
= remote_resume
;
5880 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5881 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5882 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5883 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5884 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5885 remote_cisco_ops
.to_files_info
= remote_files_info
;
5886 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5887 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5888 remote_cisco_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5889 remote_cisco_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5890 remote_cisco_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5891 remote_cisco_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5892 remote_cisco_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5893 remote_cisco_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5894 remote_cisco_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5895 remote_cisco_ops
.to_kill
= remote_kill
;
5896 remote_cisco_ops
.to_load
= generic_load
;
5897 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5898 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5899 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5900 remote_cisco_ops
.to_pid_to_str
= remote_pid_to_str
;
5901 remote_cisco_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5902 remote_cisco_ops
.to_stratum
= process_stratum
;
5903 remote_cisco_ops
.to_has_all_memory
= 1;
5904 remote_cisco_ops
.to_has_memory
= 1;
5905 remote_cisco_ops
.to_has_stack
= 1;
5906 remote_cisco_ops
.to_has_registers
= 1;
5907 remote_cisco_ops
.to_has_execution
= 1;
5908 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5912 remote_can_async_p (void)
5914 /* We're async whenever the serial device is. */
5915 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5919 remote_is_async_p (void)
5921 /* We're async whenever the serial device is. */
5922 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5925 /* Pass the SERIAL event on and up to the client. One day this code
5926 will be able to delay notifying the client of an event until the
5927 point where an entire packet has been received. */
5929 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5930 static void *async_client_context
;
5931 static serial_event_ftype remote_async_serial_handler
;
5934 remote_async_serial_handler (struct serial
*scb
, void *context
)
5936 /* Don't propogate error information up to the client. Instead let
5937 the client find out about the error by querying the target. */
5938 async_client_callback (INF_REG_EVENT
, async_client_context
);
5942 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5944 if (current_target
.to_async_mask_value
== 0)
5945 internal_error (__FILE__
, __LINE__
,
5946 "Calling remote_async when async is masked");
5948 if (callback
!= NULL
)
5950 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5951 async_client_callback
= callback
;
5952 async_client_context
= context
;
5955 serial_async (remote_desc
, NULL
, NULL
);
5958 /* Target async and target extended-async.
5960 This are temporary targets, until it is all tested. Eventually
5961 async support will be incorporated int the usual 'remote'
5965 init_remote_async_ops (void)
5967 remote_async_ops
.to_shortname
= "async";
5968 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5969 remote_async_ops
.to_doc
=
5970 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5971 Specify the serial device it is connected to (e.g. /dev/ttya).";
5972 remote_async_ops
.to_open
= remote_async_open
;
5973 remote_async_ops
.to_close
= remote_close
;
5974 remote_async_ops
.to_detach
= remote_detach
;
5975 remote_async_ops
.to_disconnect
= remote_disconnect
;
5976 remote_async_ops
.to_resume
= remote_async_resume
;
5977 remote_async_ops
.to_wait
= remote_async_wait
;
5978 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5979 remote_async_ops
.to_store_registers
= remote_store_registers
;
5980 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5981 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5982 remote_async_ops
.to_files_info
= remote_files_info
;
5983 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5984 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5985 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5986 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5987 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5988 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5989 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5990 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5991 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5992 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5993 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5994 remote_async_ops
.to_kill
= remote_async_kill
;
5995 remote_async_ops
.to_load
= generic_load
;
5996 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5997 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5998 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5999 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
6000 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
6001 remote_async_ops
.to_stop
= remote_stop
;
6002 remote_async_ops
.to_xfer_partial
= remote_xfer_partial
;
6003 remote_async_ops
.to_rcmd
= remote_rcmd
;
6004 remote_async_ops
.to_stratum
= process_stratum
;
6005 remote_async_ops
.to_has_all_memory
= 1;
6006 remote_async_ops
.to_has_memory
= 1;
6007 remote_async_ops
.to_has_stack
= 1;
6008 remote_async_ops
.to_has_registers
= 1;
6009 remote_async_ops
.to_has_execution
= 1;
6010 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
6011 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
6012 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
6013 remote_async_ops
.to_async
= remote_async
;
6014 remote_async_ops
.to_async_mask_value
= 1;
6015 remote_async_ops
.to_magic
= OPS_MAGIC
;
6018 /* Set up the async extended remote vector by making a copy of the standard
6019 remote vector and adding to it. */
6022 init_extended_async_remote_ops (void)
6024 extended_async_remote_ops
= remote_async_ops
;
6026 extended_async_remote_ops
.to_shortname
= "extended-async";
6027 extended_async_remote_ops
.to_longname
=
6028 "Extended remote serial target in async gdb-specific protocol";
6029 extended_async_remote_ops
.to_doc
=
6030 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
6031 Specify the serial device it is connected to (e.g. /dev/ttya).",
6032 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
6033 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
6034 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
6038 set_remote_cmd (char *args
, int from_tty
)
6043 show_remote_cmd (char *args
, int from_tty
)
6045 /* FIXME: cagney/2002-06-15: This function should iterate over
6046 remote_show_cmdlist for a list of sub commands to show. */
6047 show_remote_protocol_Z_packet_cmd (args
, from_tty
, NULL
);
6048 show_remote_protocol_e_packet_cmd (args
, from_tty
, NULL
);
6049 show_remote_protocol_E_packet_cmd (args
, from_tty
, NULL
);
6050 show_remote_protocol_P_packet_cmd (args
, from_tty
, NULL
);
6051 show_remote_protocol_qSymbol_packet_cmd (args
, from_tty
, NULL
);
6052 show_remote_protocol_vcont_packet_cmd (args
, from_tty
, NULL
);
6053 show_remote_protocol_binary_download_cmd (args
, from_tty
, NULL
);
6057 build_remote_gdbarch_data (void)
6059 remote_address_size
= TARGET_ADDR_BIT
;
6062 /* Saved pointer to previous owner of the new_objfile event. */
6063 static void (*remote_new_objfile_chain
) (struct objfile
*);
6065 /* Function to be called whenever a new objfile (shlib) is detected. */
6067 remote_new_objfile (struct objfile
*objfile
)
6069 if (remote_desc
!= 0) /* Have a remote connection */
6071 remote_check_symbols (objfile
);
6073 /* Call predecessor on chain, if any. */
6074 if (remote_new_objfile_chain
!= 0 &&
6076 remote_new_objfile_chain (objfile
);
6080 _initialize_remote (void)
6082 static struct cmd_list_element
*remote_set_cmdlist
;
6083 static struct cmd_list_element
*remote_show_cmdlist
;
6084 struct cmd_list_element
*tmpcmd
;
6086 /* architecture specific data */
6087 remote_gdbarch_data_handle
= register_gdbarch_data (init_remote_state
);
6089 /* Old tacky stuff. NOTE: This comes after the remote protocol so
6090 that the remote protocol has been initialized. */
6091 register_gdbarch_swap (&remote_address_size
,
6092 sizeof (&remote_address_size
), NULL
);
6093 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
6096 add_target (&remote_ops
);
6098 init_extended_remote_ops ();
6099 add_target (&extended_remote_ops
);
6101 init_remote_async_ops ();
6102 add_target (&remote_async_ops
);
6104 init_extended_async_remote_ops ();
6105 add_target (&extended_async_remote_ops
);
6107 init_remote_cisco_ops ();
6108 add_target (&remote_cisco_ops
);
6110 /* Hook into new objfile notification. */
6111 remote_new_objfile_chain
= target_new_objfile_hook
;
6112 target_new_objfile_hook
= remote_new_objfile
;
6115 init_remote_threadtests ();
6118 /* set/show remote ... */
6120 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
6121 Remote protocol specific variables\n\
6122 Configure various remote-protocol specific variables such as\n\
6123 the packets being used",
6124 &remote_set_cmdlist
, "set remote ",
6125 0/*allow-unknown*/, &setlist
);
6126 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, "\
6127 Remote protocol specific variables\n\
6128 Configure various remote-protocol specific variables such as\n\
6129 the packets being used",
6130 &remote_show_cmdlist
, "show remote ",
6131 0/*allow-unknown*/, &showlist
);
6133 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
6134 "Compare section data on target to the exec file.\n\
6135 Argument is a single section name (default: all loaded sections).",
6138 add_cmd ("packet", class_maintenance
, packet_command
,
6139 "Send an arbitrary packet to a remote target.\n\
6140 maintenance packet TEXT\n\
6141 If GDB is talking to an inferior via the GDB serial protocol, then\n\
6142 this command sends the string TEXT to the inferior, and displays the\n\
6143 response packet. GDB supplies the initial `$' character, and the\n\
6144 terminating `#' character and checksum.",
6147 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
,
6148 "Set whether to send break if interrupted.\n",
6149 "Show whether to send break if interrupted.\n",
6151 &setlist
, &showlist
);
6153 /* Install commands for configuring memory read/write packets. */
6155 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
6156 "Set the maximum number of bytes per memory write packet (deprecated).\n",
6158 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
,
6159 "Show the maximum number of bytes per memory write packet (deprecated).\n",
6161 add_cmd ("memory-write-packet-size", no_class
,
6162 set_memory_write_packet_size
,
6163 "Set the maximum number of bytes per memory-write packet.\n"
6164 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6165 "default packet size. The actual limit is further reduced\n"
6166 "dependent on the target. Specify ``fixed'' to disable the\n"
6167 "further restriction and ``limit'' to enable that restriction\n",
6168 &remote_set_cmdlist
);
6169 add_cmd ("memory-read-packet-size", no_class
,
6170 set_memory_read_packet_size
,
6171 "Set the maximum number of bytes per memory-read packet.\n"
6172 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6173 "default packet size. The actual limit is further reduced\n"
6174 "dependent on the target. Specify ``fixed'' to disable the\n"
6175 "further restriction and ``limit'' to enable that restriction\n",
6176 &remote_set_cmdlist
);
6177 add_cmd ("memory-write-packet-size", no_class
,
6178 show_memory_write_packet_size
,
6179 "Show the maximum number of bytes per memory-write packet.\n",
6180 &remote_show_cmdlist
);
6181 add_cmd ("memory-read-packet-size", no_class
,
6182 show_memory_read_packet_size
,
6183 "Show the maximum number of bytes per memory-read packet.\n",
6184 &remote_show_cmdlist
);
6186 add_setshow_cmd ("hardware-watchpoint-limit", no_class
,
6187 var_zinteger
, &remote_hw_watchpoint_limit
, "\
6188 Set the maximum number of target hardware watchpoints.\n\
6189 Specify a negative limit for unlimited.", "\
6190 Show the maximum number of target hardware watchpoints.\n",
6191 NULL
, NULL
, &remote_set_cmdlist
, &remote_show_cmdlist
);
6192 add_setshow_cmd ("hardware-breakpoint-limit", no_class
,
6193 var_zinteger
, &remote_hw_breakpoint_limit
, "\
6194 Set the maximum number of target hardware breakpoints.\n\
6195 Specify a negative limit for unlimited.", "\
6196 Show the maximum number of target hardware breakpoints.\n",
6197 NULL
, NULL
, &remote_set_cmdlist
, &remote_show_cmdlist
);
6200 (add_set_cmd ("remoteaddresssize", class_obscure
,
6201 var_integer
, (char *) &remote_address_size
,
6202 "Set the maximum size of the address (in bits) \
6203 in a memory packet.\n",
6207 add_packet_config_cmd (&remote_protocol_binary_download
,
6208 "X", "binary-download",
6209 set_remote_protocol_binary_download_cmd
,
6210 show_remote_protocol_binary_download_cmd
,
6211 &remote_set_cmdlist
, &remote_show_cmdlist
,
6214 /* XXXX - should ``set remotebinarydownload'' be retained for
6217 (add_set_cmd ("remotebinarydownload", no_class
,
6218 var_boolean
, (char *) &remote_binary_download
,
6219 "Set binary downloads.\n", &setlist
),
6223 add_info ("remote-process", remote_info_process
,
6224 "Query the remote system for process info.");
6226 add_packet_config_cmd (&remote_protocol_vcont
,
6227 "vCont", "verbose-resume",
6228 set_remote_protocol_vcont_packet_cmd
,
6229 show_remote_protocol_vcont_packet_cmd
,
6230 &remote_set_cmdlist
, &remote_show_cmdlist
,
6233 add_packet_config_cmd (&remote_protocol_qSymbol
,
6234 "qSymbol", "symbol-lookup",
6235 set_remote_protocol_qSymbol_packet_cmd
,
6236 show_remote_protocol_qSymbol_packet_cmd
,
6237 &remote_set_cmdlist
, &remote_show_cmdlist
,
6240 add_packet_config_cmd (&remote_protocol_e
,
6241 "e", "step-over-range",
6242 set_remote_protocol_e_packet_cmd
,
6243 show_remote_protocol_e_packet_cmd
,
6244 &remote_set_cmdlist
, &remote_show_cmdlist
,
6246 /* Disable by default. The ``e'' packet has nasty interactions with
6247 the threading code - it relies on global state. */
6248 remote_protocol_e
.detect
= AUTO_BOOLEAN_FALSE
;
6249 update_packet_config (&remote_protocol_e
);
6251 add_packet_config_cmd (&remote_protocol_E
,
6252 "E", "step-over-range-w-signal",
6253 set_remote_protocol_E_packet_cmd
,
6254 show_remote_protocol_E_packet_cmd
,
6255 &remote_set_cmdlist
, &remote_show_cmdlist
,
6257 /* Disable by default. The ``e'' packet has nasty interactions with
6258 the threading code - it relies on global state. */
6259 remote_protocol_E
.detect
= AUTO_BOOLEAN_FALSE
;
6260 update_packet_config (&remote_protocol_E
);
6262 add_packet_config_cmd (&remote_protocol_P
,
6263 "P", "set-register",
6264 set_remote_protocol_P_packet_cmd
,
6265 show_remote_protocol_P_packet_cmd
,
6266 &remote_set_cmdlist
, &remote_show_cmdlist
,
6269 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
6270 "Z0", "software-breakpoint",
6271 set_remote_protocol_Z_software_bp_packet_cmd
,
6272 show_remote_protocol_Z_software_bp_packet_cmd
,
6273 &remote_set_cmdlist
, &remote_show_cmdlist
,
6276 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
6277 "Z1", "hardware-breakpoint",
6278 set_remote_protocol_Z_hardware_bp_packet_cmd
,
6279 show_remote_protocol_Z_hardware_bp_packet_cmd
,
6280 &remote_set_cmdlist
, &remote_show_cmdlist
,
6283 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
6284 "Z2", "write-watchpoint",
6285 set_remote_protocol_Z_write_wp_packet_cmd
,
6286 show_remote_protocol_Z_write_wp_packet_cmd
,
6287 &remote_set_cmdlist
, &remote_show_cmdlist
,
6290 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
6291 "Z3", "read-watchpoint",
6292 set_remote_protocol_Z_read_wp_packet_cmd
,
6293 show_remote_protocol_Z_read_wp_packet_cmd
,
6294 &remote_set_cmdlist
, &remote_show_cmdlist
,
6297 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
6298 "Z4", "access-watchpoint",
6299 set_remote_protocol_Z_access_wp_packet_cmd
,
6300 show_remote_protocol_Z_access_wp_packet_cmd
,
6301 &remote_set_cmdlist
, &remote_show_cmdlist
,
6304 /* Keep the old ``set remote Z-packet ...'' working. */
6305 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
6306 &remote_Z_packet_detect
, "\
6307 Set use of remote protocol `Z' packets",
6308 "Show use of remote protocol `Z' packets ",
6309 set_remote_protocol_Z_packet_cmd
,
6310 show_remote_protocol_Z_packet_cmd
,
6311 &remote_set_cmdlist
, &remote_show_cmdlist
);
6313 /* Eventually initialize fileio. See fileio.c */
6314 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);