1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* See the GDB User Guide for details of the GDB remote protocol. */
26 #include "gdb_string.h"
33 /*#include "terminal.h" */
36 #include "gdb-stabs.h"
37 #include "gdbthread.h"
41 #include "gdb_assert.h"
46 #include <sys/types.h>
49 #include "event-loop.h"
50 #include "event-top.h"
56 #include "gdbcore.h" /* for exec_bfd */
58 #include "remote-fileio.h"
60 /* Prototypes for local functions */
61 static void cleanup_sigint_signal_handler (void *dummy
);
62 static void initialize_sigint_signal_handler (void);
63 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
65 static void handle_remote_sigint (int);
66 static void handle_remote_sigint_twice (int);
67 static void async_remote_interrupt (gdb_client_data
);
68 void async_remote_interrupt_twice (gdb_client_data
);
70 static void build_remote_gdbarch_data (void);
72 static void remote_files_info (struct target_ops
*ignore
);
74 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
75 int len
, int should_write
,
76 struct mem_attrib
*attrib
,
77 struct target_ops
*target
);
79 static void remote_prepare_to_store (void);
81 static void remote_fetch_registers (int regno
);
83 static void remote_resume (ptid_t ptid
, int step
,
84 enum target_signal siggnal
);
85 static void remote_async_resume (ptid_t ptid
, int step
,
86 enum target_signal siggnal
);
87 static int remote_start_remote (struct ui_out
*uiout
, void *dummy
);
89 static void remote_open (char *name
, int from_tty
);
90 static void remote_async_open (char *name
, int from_tty
);
92 static void extended_remote_open (char *name
, int from_tty
);
93 static void extended_remote_async_open (char *name
, int from_tty
);
95 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
,
98 static void remote_close (int quitting
);
100 static void remote_store_registers (int regno
);
102 static void remote_mourn (void);
103 static void remote_async_mourn (void);
105 static void extended_remote_restart (void);
107 static void extended_remote_mourn (void);
109 static void extended_remote_create_inferior (char *, char *, char **);
110 static void extended_remote_async_create_inferior (char *, char *, char **);
112 static void remote_mourn_1 (struct target_ops
*);
114 static void remote_send (char *buf
, long sizeof_buf
);
116 static int readchar (int timeout
);
118 static ptid_t
remote_wait (ptid_t ptid
,
119 struct target_waitstatus
*status
);
120 static ptid_t
remote_async_wait (ptid_t ptid
,
121 struct target_waitstatus
*status
);
123 static void remote_kill (void);
124 static void remote_async_kill (void);
126 static int tohex (int nib
);
128 static void remote_detach (char *args
, int from_tty
);
129 static void remote_async_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 remote_query (int /*char */ , char *, char *, int *);
167 static int hexnumstr (char *, ULONGEST
);
169 static int hexnumnstr (char *, ULONGEST
, int);
171 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
173 static void print_packet (char *);
175 static unsigned long crc32 (unsigned char *, int, unsigned int);
177 static void compare_sections_command (char *, int);
179 static void packet_command (char *, int);
181 static int stub_unpack_int (char *buff
, int fieldlength
);
183 static ptid_t
remote_current_thread (ptid_t oldptid
);
185 static void remote_find_new_threads (void);
187 static void record_currthread (int currthread
);
189 static int fromhex (int a
);
191 static int hex2bin (const char *hex
, char *bin
, int count
);
193 static int bin2hex (const char *bin
, char *hex
, int count
);
195 static int putpkt_binary (char *buf
, int cnt
);
197 static void check_binary_download (CORE_ADDR addr
);
199 struct packet_config
;
201 static void show_packet_config_cmd (struct packet_config
*config
);
203 static void update_packet_config (struct packet_config
*config
);
205 void _initialize_remote (void);
207 /* Description of the remote protocol. Strictly speaking, when the
208 target is open()ed, remote.c should create a per-target description
209 of the remote protocol using that target's architecture.
210 Unfortunatly, the target stack doesn't include local state. For
211 the moment keep the information in the target's architecture
216 long offset
; /* Offset into G packet. */
217 long regnum
; /* GDB's internal register number. */
218 LONGEST pnum
; /* Remote protocol register number. */
219 int in_g_packet
; /* Always part of G packet. */
220 /* long size in bytes; == REGISTER_RAW_SIZE (regnum); at present. */
221 /* char *name; == REGISTER_NAME (regnum); at present. */
226 /* Description of the remote protocol registers. */
227 long sizeof_g_packet
;
229 /* Description of the remote protocol registers indexed by REGNUM
230 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
231 struct packet_reg
*regs
;
233 /* This is the size (in chars) of the first response to the ``g''
234 packet. It is used as a heuristic when determining the maximum
235 size of memory-read and memory-write packets. A target will
236 typically only reserve a buffer large enough to hold the ``g''
237 packet. The size does not include packet overhead (headers and
239 long actual_register_packet_size
;
241 /* This is the maximum size (in chars) of a non read/write packet.
242 It is also used as a cap on the size of read/write packets. */
243 long remote_packet_size
;
247 /* Handle for retreving the remote protocol data from gdbarch. */
248 static struct gdbarch_data
*remote_gdbarch_data_handle
;
250 static struct remote_state
*
251 get_remote_state (void)
253 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
257 init_remote_state (struct gdbarch
*gdbarch
)
260 struct remote_state
*rs
= xmalloc (sizeof (struct remote_state
));
262 if (DEPRECATED_REGISTER_BYTES
!= 0)
263 rs
->sizeof_g_packet
= DEPRECATED_REGISTER_BYTES
;
265 rs
->sizeof_g_packet
= 0;
267 /* Assume a 1:1 regnum<->pnum table. */
268 rs
->regs
= xcalloc (NUM_REGS
+ NUM_PSEUDO_REGS
, sizeof (struct packet_reg
));
269 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
271 struct packet_reg
*r
= &rs
->regs
[regnum
];
274 r
->offset
= REGISTER_BYTE (regnum
);
275 r
->in_g_packet
= (regnum
< NUM_REGS
);
276 /* ...name = REGISTER_NAME (regnum); */
278 /* Compute packet size by accumulating the size of all registers. */
279 if (DEPRECATED_REGISTER_BYTES
== 0)
280 rs
->sizeof_g_packet
+= register_size (current_gdbarch
, regnum
);
283 /* Default maximum number of characters in a packet body. Many
284 remote stubs have a hardwired buffer size of 400 bytes
285 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
286 as the maximum packet-size to ensure that the packet and an extra
287 NUL character can always fit in the buffer. This stops GDB
288 trashing stubs that try to squeeze an extra NUL into what is
289 already a full buffer (As of 1999-12-04 that was most stubs. */
290 rs
->remote_packet_size
= 400 - 1;
292 /* Should rs->sizeof_g_packet needs more space than the
293 default, adjust the size accordingly. Remember that each byte is
294 encoded as two characters. 32 is the overhead for the packet
295 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
296 (``$NN:G...#NN'') is a better guess, the below has been padded a
298 if (rs
->sizeof_g_packet
> ((rs
->remote_packet_size
- 32) / 2))
299 rs
->remote_packet_size
= (rs
->sizeof_g_packet
* 2 + 32);
301 /* This one is filled in when a ``g'' packet is received. */
302 rs
->actual_register_packet_size
= 0;
308 free_remote_state (struct gdbarch
*gdbarch
, void *pointer
)
310 struct remote_state
*data
= pointer
;
315 static struct packet_reg
*
316 packet_reg_from_regnum (struct remote_state
*rs
, long regnum
)
318 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
322 struct packet_reg
*r
= &rs
->regs
[regnum
];
323 gdb_assert (r
->regnum
== regnum
);
328 static struct packet_reg
*
329 packet_reg_from_pnum (struct remote_state
*rs
, LONGEST pnum
)
332 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
334 struct packet_reg
*r
= &rs
->regs
[i
];
341 /* FIXME: graces/2002-08-08: These variables should eventually be
342 bound to an instance of the target object (as in gdbarch-tdep()),
343 when such a thing exists. */
345 /* This is set to the data address of the access causing the target
346 to stop for a watchpoint. */
347 static CORE_ADDR remote_watch_data_address
;
349 /* This is non-zero if taregt stopped for a watchpoint. */
350 static int remote_stopped_by_watchpoint_p
;
353 static struct target_ops remote_ops
;
355 static struct target_ops extended_remote_ops
;
357 /* Temporary target ops. Just like the remote_ops and
358 extended_remote_ops, but with asynchronous support. */
359 static struct target_ops remote_async_ops
;
361 static struct target_ops extended_async_remote_ops
;
363 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
364 ``forever'' still use the normal timeout mechanism. This is
365 currently used by the ASYNC code to guarentee that target reads
366 during the initial connect always time-out. Once getpkt has been
367 modified to return a timeout indication and, in turn
368 remote_wait()/wait_for_inferior() have gained a timeout parameter
370 static int wait_forever_enabled_p
= 1;
373 /* This variable chooses whether to send a ^C or a break when the user
374 requests program interruption. Although ^C is usually what remote
375 systems expect, and that is the default here, sometimes a break is
376 preferable instead. */
378 static int remote_break
;
380 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
381 remote_open knows that we don't have a file open when the program
383 static struct serial
*remote_desc
= NULL
;
385 /* This is set by the target (thru the 'S' message)
386 to denote that the target is in kernel mode. */
387 static int cisco_kernel_mode
= 0;
389 /* This variable sets the number of bits in an address that are to be
390 sent in a memory ("M" or "m") packet. Normally, after stripping
391 leading zeros, the entire address would be sent. This variable
392 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
393 initial implementation of remote.c restricted the address sent in
394 memory packets to ``host::sizeof long'' bytes - (typically 32
395 bits). Consequently, for 64 bit targets, the upper 32 bits of an
396 address was never sent. Since fixing this bug may cause a break in
397 some remote targets this variable is principly provided to
398 facilitate backward compatibility. */
400 static int remote_address_size
;
402 /* Tempoary to track who currently owns the terminal. See
403 target_async_terminal_* for more details. */
405 static int remote_async_terminal_ours_p
;
408 /* User configurable variables for the number of characters in a
409 memory read/write packet. MIN ((rs->remote_packet_size),
410 rs->sizeof_g_packet) is the default. Some targets need smaller
411 values (fifo overruns, et.al.) and some users need larger values
412 (speed up transfers). The variables ``preferred_*'' (the user
413 request), ``current_*'' (what was actually set) and ``forced_*''
414 (Positive - a soft limit, negative - a hard limit). */
416 struct memory_packet_config
423 /* Compute the current size of a read/write packet. Since this makes
424 use of ``actual_register_packet_size'' the computation is dynamic. */
427 get_memory_packet_size (struct memory_packet_config
*config
)
429 struct remote_state
*rs
= get_remote_state ();
430 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
431 law?) that some hosts don't cope very well with large alloca()
432 calls. Eventually the alloca() code will be replaced by calls to
433 xmalloc() and make_cleanups() allowing this restriction to either
434 be lifted or removed. */
435 #ifndef MAX_REMOTE_PACKET_SIZE
436 #define MAX_REMOTE_PACKET_SIZE 16384
438 /* NOTE: 16 is just chosen at random. */
439 #ifndef MIN_REMOTE_PACKET_SIZE
440 #define MIN_REMOTE_PACKET_SIZE 16
445 if (config
->size
<= 0)
446 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
448 what_they_get
= config
->size
;
452 what_they_get
= (rs
->remote_packet_size
);
453 /* Limit the packet to the size specified by the user. */
455 && what_they_get
> config
->size
)
456 what_they_get
= config
->size
;
457 /* Limit it to the size of the targets ``g'' response. */
458 if ((rs
->actual_register_packet_size
) > 0
459 && what_they_get
> (rs
->actual_register_packet_size
))
460 what_they_get
= (rs
->actual_register_packet_size
);
462 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
463 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
464 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
465 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
466 return what_they_get
;
469 /* Update the size of a read/write packet. If they user wants
470 something really big then do a sanity check. */
473 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
475 int fixed_p
= config
->fixed_p
;
476 long size
= config
->size
;
478 error ("Argument required (integer, `fixed' or `limited').");
479 else if (strcmp (args
, "hard") == 0
480 || strcmp (args
, "fixed") == 0)
482 else if (strcmp (args
, "soft") == 0
483 || strcmp (args
, "limit") == 0)
488 size
= strtoul (args
, &end
, 0);
490 error ("Invalid %s (bad syntax).", config
->name
);
492 /* Instead of explicitly capping the size of a packet to
493 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
494 instead allowed to set the size to something arbitrarily
496 if (size
> MAX_REMOTE_PACKET_SIZE
)
497 error ("Invalid %s (too large).", config
->name
);
501 if (fixed_p
&& !config
->fixed_p
)
503 if (! query ("The target may not be able to correctly handle a %s\n"
504 "of %ld bytes. Change the packet size? ",
506 error ("Packet size not changed.");
508 /* Update the config. */
509 config
->fixed_p
= fixed_p
;
514 show_memory_packet_size (struct memory_packet_config
*config
)
516 printf_filtered ("The %s is %ld. ", config
->name
, config
->size
);
518 printf_filtered ("Packets are fixed at %ld bytes.\n",
519 get_memory_packet_size (config
));
521 printf_filtered ("Packets are limited to %ld bytes.\n",
522 get_memory_packet_size (config
));
525 static struct memory_packet_config memory_write_packet_config
=
527 "memory-write-packet-size",
531 set_memory_write_packet_size (char *args
, int from_tty
)
533 set_memory_packet_size (args
, &memory_write_packet_config
);
537 show_memory_write_packet_size (char *args
, int from_tty
)
539 show_memory_packet_size (&memory_write_packet_config
);
543 get_memory_write_packet_size (void)
545 return get_memory_packet_size (&memory_write_packet_config
);
548 static struct memory_packet_config memory_read_packet_config
=
550 "memory-read-packet-size",
554 set_memory_read_packet_size (char *args
, int from_tty
)
556 set_memory_packet_size (args
, &memory_read_packet_config
);
560 show_memory_read_packet_size (char *args
, int from_tty
)
562 show_memory_packet_size (&memory_read_packet_config
);
566 get_memory_read_packet_size (void)
568 struct remote_state
*rs
= get_remote_state ();
569 long size
= get_memory_packet_size (&memory_read_packet_config
);
570 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
571 extra buffer size argument before the memory read size can be
572 increased beyond (rs->remote_packet_size). */
573 if (size
> (rs
->remote_packet_size
))
574 size
= (rs
->remote_packet_size
);
579 /* Generic configuration support for packets the stub optionally
580 supports. Allows the user to specify the use of the packet as well
581 as allowing GDB to auto-detect support in the remote stub. */
585 PACKET_SUPPORT_UNKNOWN
= 0,
594 enum auto_boolean detect
;
595 enum packet_support support
;
598 /* Analyze a packet's return value and update the packet config
609 update_packet_config (struct packet_config
*config
)
611 switch (config
->detect
)
613 case AUTO_BOOLEAN_TRUE
:
614 config
->support
= PACKET_ENABLE
;
616 case AUTO_BOOLEAN_FALSE
:
617 config
->support
= PACKET_DISABLE
;
619 case AUTO_BOOLEAN_AUTO
:
620 config
->support
= PACKET_SUPPORT_UNKNOWN
;
626 show_packet_config_cmd (struct packet_config
*config
)
628 char *support
= "internal-error";
629 switch (config
->support
)
635 support
= "disabled";
637 case PACKET_SUPPORT_UNKNOWN
:
641 switch (config
->detect
)
643 case AUTO_BOOLEAN_AUTO
:
644 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
645 config
->name
, config
->title
, support
);
647 case AUTO_BOOLEAN_TRUE
:
648 case AUTO_BOOLEAN_FALSE
:
649 printf_filtered ("Support for remote protocol `%s' (%s) packet is currently %s.\n",
650 config
->name
, config
->title
, support
);
656 add_packet_config_cmd (struct packet_config
*config
,
659 cmd_sfunc_ftype
*set_func
,
660 cmd_sfunc_ftype
*show_func
,
661 struct cmd_list_element
**set_remote_list
,
662 struct cmd_list_element
**show_remote_list
,
665 struct cmd_list_element
*set_cmd
;
666 struct cmd_list_element
*show_cmd
;
671 config
->title
= title
;
672 config
->detect
= AUTO_BOOLEAN_AUTO
;
673 config
->support
= PACKET_SUPPORT_UNKNOWN
;
674 xasprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
676 xasprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
678 /* set/show TITLE-packet {auto,on,off} */
679 xasprintf (&cmd_name
, "%s-packet", title
);
680 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
681 &config
->detect
, set_doc
, show_doc
,
683 set_remote_list
, show_remote_list
);
684 /* set/show remote NAME-packet {auto,on,off} -- legacy */
688 xasprintf (&legacy_name
, "%s-packet", name
);
689 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
691 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
696 static enum packet_result
697 packet_ok (const char *buf
, struct packet_config
*config
)
701 /* The stub recognized the packet request. Check that the
702 operation succeeded. */
703 switch (config
->support
)
705 case PACKET_SUPPORT_UNKNOWN
:
707 fprintf_unfiltered (gdb_stdlog
,
708 "Packet %s (%s) is supported\n",
709 config
->name
, config
->title
);
710 config
->support
= PACKET_ENABLE
;
713 internal_error (__FILE__
, __LINE__
,
714 "packet_ok: attempt to use a disabled packet");
719 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
720 /* "OK" - definitly OK. */
723 && isxdigit (buf
[1]) && isxdigit (buf
[2])
725 /* "Enn" - definitly an error. */
727 /* The packet may or may not be OK. Just assume it is */
732 /* The stub does not support the packet. */
733 switch (config
->support
)
736 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
737 /* If the stub previously indicated that the packet was
738 supported then there is a protocol error.. */
739 error ("Protocol error: %s (%s) conflicting enabled responses.",
740 config
->name
, config
->title
);
742 /* The user set it wrong. */
743 error ("Enabled packet %s (%s) not recognized by stub",
744 config
->name
, config
->title
);
746 case PACKET_SUPPORT_UNKNOWN
:
748 fprintf_unfiltered (gdb_stdlog
,
749 "Packet %s (%s) is NOT supported\n",
750 config
->name
, config
->title
);
751 config
->support
= PACKET_DISABLE
;
756 return PACKET_UNKNOWN
;
760 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
761 static struct packet_config remote_protocol_qSymbol
;
764 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
765 struct cmd_list_element
*c
)
767 update_packet_config (&remote_protocol_qSymbol
);
771 show_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
772 struct cmd_list_element
*c
)
774 show_packet_config_cmd (&remote_protocol_qSymbol
);
777 /* Should we try the 'e' (step over range) request? */
778 static struct packet_config remote_protocol_e
;
781 set_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
782 struct cmd_list_element
*c
)
784 update_packet_config (&remote_protocol_e
);
788 show_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
789 struct cmd_list_element
*c
)
791 show_packet_config_cmd (&remote_protocol_e
);
795 /* Should we try the 'E' (step over range / w signal #) request? */
796 static struct packet_config remote_protocol_E
;
799 set_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
800 struct cmd_list_element
*c
)
802 update_packet_config (&remote_protocol_E
);
806 show_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
807 struct cmd_list_element
*c
)
809 show_packet_config_cmd (&remote_protocol_E
);
813 /* Should we try the 'P' (set register) request? */
815 static struct packet_config remote_protocol_P
;
818 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
819 struct cmd_list_element
*c
)
821 update_packet_config (&remote_protocol_P
);
825 show_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
826 struct cmd_list_element
*c
)
828 show_packet_config_cmd (&remote_protocol_P
);
831 /* Should we try one of the 'Z' requests? */
835 Z_PACKET_SOFTWARE_BP
,
836 Z_PACKET_HARDWARE_BP
,
843 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
845 /* FIXME: Instead of having all these boiler plate functions, the
846 command callback should include a context argument. */
849 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
850 struct cmd_list_element
*c
)
852 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
856 show_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
857 struct cmd_list_element
*c
)
859 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
863 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
864 struct cmd_list_element
*c
)
866 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
870 show_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
871 struct cmd_list_element
*c
)
873 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
877 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
878 struct cmd_list_element
*c
)
880 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
884 show_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
885 struct cmd_list_element
*c
)
887 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
891 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
892 struct cmd_list_element
*c
)
894 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
898 show_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
899 struct cmd_list_element
*c
)
901 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
905 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
906 struct cmd_list_element
*c
)
908 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
912 show_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
913 struct cmd_list_element
*c
)
915 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
918 /* For compatibility with older distributions. Provide a ``set remote
919 Z-packet ...'' command that updates all the Z packet types. */
921 static enum auto_boolean remote_Z_packet_detect
;
924 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
925 struct cmd_list_element
*c
)
928 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
930 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
931 update_packet_config (&remote_protocol_Z
[i
]);
936 show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
937 struct cmd_list_element
*c
)
940 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
942 show_packet_config_cmd (&remote_protocol_Z
[i
]);
946 /* Should we try the 'X' (remote binary download) packet?
948 This variable (available to the user via "set remote X-packet")
949 dictates whether downloads are sent in binary (via the 'X' packet).
950 We assume that the stub can, and attempt to do it. This will be
951 cleared if the stub does not understand it. This switch is still
952 needed, though in cases when the packet is supported in the stub,
953 but the connection does not allow it (i.e., 7-bit serial connection
956 static struct packet_config remote_protocol_binary_download
;
958 /* Should we try the 'ThreadInfo' query packet?
960 This variable (NOT available to the user: auto-detect only!)
961 determines whether GDB will use the new, simpler "ThreadInfo"
962 query or the older, more complex syntax for thread queries.
963 This is an auto-detect variable (set to true at each connect,
964 and set to false when the target fails to recognize it). */
966 static int use_threadinfo_query
;
967 static int use_threadextra_query
;
970 set_remote_protocol_binary_download_cmd (char *args
,
972 struct cmd_list_element
*c
)
974 update_packet_config (&remote_protocol_binary_download
);
978 show_remote_protocol_binary_download_cmd (char *args
, int from_tty
,
979 struct cmd_list_element
*c
)
981 show_packet_config_cmd (&remote_protocol_binary_download
);
985 /* Tokens for use by the asynchronous signal handlers for SIGINT */
986 static void *sigint_remote_twice_token
;
987 static void *sigint_remote_token
;
989 /* These are pointers to hook functions that may be set in order to
990 modify resume/wait behavior for a particular architecture. */
992 void (*target_resume_hook
) (void);
993 void (*target_wait_loop_hook
) (void);
997 /* These are the threads which we last sent to the remote system.
998 -1 for all or -2 for not sent yet. */
999 static int general_thread
;
1000 static int continue_thread
;
1002 /* Call this function as a result of
1003 1) A halt indication (T packet) containing a thread id
1004 2) A direct query of currthread
1005 3) Successful execution of set thread
1009 record_currthread (int currthread
)
1011 general_thread
= currthread
;
1013 /* If this is a new thread, add it to GDB's thread list.
1014 If we leave it up to WFI to do this, bad things will happen. */
1015 if (!in_thread_list (pid_to_ptid (currthread
)))
1017 add_thread (pid_to_ptid (currthread
));
1018 ui_out_text (uiout
, "[New ");
1019 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
1020 ui_out_text (uiout
, "]\n");
1024 #define MAGIC_NULL_PID 42000
1027 set_thread (int th
, int gen
)
1029 struct remote_state
*rs
= get_remote_state ();
1030 char *buf
= alloca (rs
->remote_packet_size
);
1031 int state
= gen
? general_thread
: continue_thread
;
1037 buf
[1] = gen
? 'g' : 'c';
1038 if (th
== MAGIC_NULL_PID
)
1044 sprintf (&buf
[2], "-%x", -th
);
1046 sprintf (&buf
[2], "%x", th
);
1048 getpkt (buf
, (rs
->remote_packet_size
), 0);
1050 general_thread
= th
;
1052 continue_thread
= th
;
1055 /* Return nonzero if the thread TH is still alive on the remote system. */
1058 remote_thread_alive (ptid_t ptid
)
1060 int tid
= PIDGET (ptid
);
1064 sprintf (buf
, "T-%08x", -tid
);
1066 sprintf (buf
, "T%08x", tid
);
1068 getpkt (buf
, sizeof (buf
), 0);
1069 return (buf
[0] == 'O' && buf
[1] == 'K');
1072 /* About these extended threadlist and threadinfo packets. They are
1073 variable length packets but, the fields within them are often fixed
1074 length. They are redundent enough to send over UDP as is the
1075 remote protocol in general. There is a matching unit test module
1078 #define OPAQUETHREADBYTES 8
1080 /* a 64 bit opaque identifier */
1081 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1083 /* WARNING: This threadref data structure comes from the remote O.S., libstub
1084 protocol encoding, and remote.c. it is not particularly changable */
1086 /* Right now, the internal structure is int. We want it to be bigger.
1090 typedef int gdb_threadref
; /* internal GDB thread reference */
1092 /* gdb_ext_thread_info is an internal GDB data structure which is
1093 equivalint to the reply of the remote threadinfo packet */
1095 struct gdb_ext_thread_info
1097 threadref threadid
; /* External form of thread reference */
1098 int active
; /* Has state interesting to GDB? , regs, stack */
1099 char display
[256]; /* Brief state display, name, blocked/syspended */
1100 char shortname
[32]; /* To be used to name threads */
1101 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
1104 /* The volume of remote transfers can be limited by submitting
1105 a mask containing bits specifying the desired information.
1106 Use a union of these values as the 'selection' parameter to
1107 get_thread_info. FIXME: Make these TAG names more thread specific.
1110 #define TAG_THREADID 1
1111 #define TAG_EXISTS 2
1112 #define TAG_DISPLAY 4
1113 #define TAG_THREADNAME 8
1114 #define TAG_MOREDISPLAY 16
1116 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
1118 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1120 static char *unpack_nibble (char *buf
, int *val
);
1122 static char *pack_nibble (char *buf
, int nibble
);
1124 static char *pack_hex_byte (char *pkt
, int /*unsigned char */ byte
);
1126 static char *unpack_byte (char *buf
, int *value
);
1128 static char *pack_int (char *buf
, int value
);
1130 static char *unpack_int (char *buf
, int *value
);
1132 static char *unpack_string (char *src
, char *dest
, int length
);
1134 static char *pack_threadid (char *pkt
, threadref
* id
);
1136 static char *unpack_threadid (char *inbuf
, threadref
* id
);
1138 void int_to_threadref (threadref
* id
, int value
);
1140 static int threadref_to_int (threadref
* ref
);
1142 static void copy_threadref (threadref
* dest
, threadref
* src
);
1144 static int threadmatch (threadref
* dest
, threadref
* src
);
1146 static char *pack_threadinfo_request (char *pkt
, int mode
, threadref
* id
);
1148 static int remote_unpack_thread_info_response (char *pkt
,
1149 threadref
* expectedref
,
1150 struct gdb_ext_thread_info
1154 static int remote_get_threadinfo (threadref
* threadid
, int fieldset
, /*TAG mask */
1155 struct gdb_ext_thread_info
*info
);
1157 static int adapt_remote_get_threadinfo (gdb_threadref
* ref
,
1159 struct gdb_ext_thread_info
*info
);
1161 static char *pack_threadlist_request (char *pkt
, int startflag
,
1163 threadref
* nextthread
);
1165 static int parse_threadlist_response (char *pkt
,
1167 threadref
* original_echo
,
1168 threadref
* resultlist
, int *doneflag
);
1170 static int remote_get_threadlist (int startflag
,
1171 threadref
* nextthread
,
1174 int *result_count
, threadref
* threadlist
);
1176 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
1178 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1179 void *context
, int looplimit
);
1181 static int remote_newthread_step (threadref
* ref
, void *context
);
1183 /* encode 64 bits in 16 chars of hex */
1185 static const char hexchars
[] = "0123456789abcdef";
1188 ishex (int ch
, int *val
)
1190 if ((ch
>= 'a') && (ch
<= 'f'))
1192 *val
= ch
- 'a' + 10;
1195 if ((ch
>= 'A') && (ch
<= 'F'))
1197 *val
= ch
- 'A' + 10;
1200 if ((ch
>= '0') && (ch
<= '9'))
1211 if (ch
>= 'a' && ch
<= 'f')
1212 return ch
- 'a' + 10;
1213 if (ch
>= '0' && ch
<= '9')
1215 if (ch
>= 'A' && ch
<= 'F')
1216 return ch
- 'A' + 10;
1221 stub_unpack_int (char *buff
, int fieldlength
)
1228 nibble
= stubhex (*buff
++);
1232 retval
= retval
<< 4;
1238 unpack_varlen_hex (char *buff
, /* packet to parse */
1244 while (ishex (*buff
, &nibble
))
1247 retval
= retval
<< 4;
1248 retval
|= nibble
& 0x0f;
1255 unpack_nibble (char *buf
, int *val
)
1257 ishex (*buf
++, val
);
1262 pack_nibble (char *buf
, int nibble
)
1264 *buf
++ = hexchars
[(nibble
& 0x0f)];
1269 pack_hex_byte (char *pkt
, int byte
)
1271 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1272 *pkt
++ = hexchars
[(byte
& 0xf)];
1277 unpack_byte (char *buf
, int *value
)
1279 *value
= stub_unpack_int (buf
, 2);
1284 pack_int (char *buf
, int value
)
1286 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1287 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1288 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1289 buf
= pack_hex_byte (buf
, (value
& 0xff));
1294 unpack_int (char *buf
, int *value
)
1296 *value
= stub_unpack_int (buf
, 8);
1300 #if 0 /* currently unused, uncomment when needed */
1301 static char *pack_string (char *pkt
, char *string
);
1304 pack_string (char *pkt
, char *string
)
1309 len
= strlen (string
);
1311 len
= 200; /* Bigger than most GDB packets, junk??? */
1312 pkt
= pack_hex_byte (pkt
, len
);
1316 if ((ch
== '\0') || (ch
== '#'))
1317 ch
= '*'; /* Protect encapsulation */
1322 #endif /* 0 (unused) */
1325 unpack_string (char *src
, char *dest
, int length
)
1334 pack_threadid (char *pkt
, threadref
*id
)
1337 unsigned char *altid
;
1339 altid
= (unsigned char *) id
;
1340 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1342 pkt
= pack_hex_byte (pkt
, *altid
++);
1348 unpack_threadid (char *inbuf
, threadref
*id
)
1351 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1354 altref
= (char *) id
;
1356 while (inbuf
< limit
)
1358 x
= stubhex (*inbuf
++);
1359 y
= stubhex (*inbuf
++);
1360 *altref
++ = (x
<< 4) | y
;
1365 /* Externally, threadrefs are 64 bits but internally, they are still
1366 ints. This is due to a mismatch of specifications. We would like
1367 to use 64bit thread references internally. This is an adapter
1371 int_to_threadref (threadref
*id
, int value
)
1373 unsigned char *scan
;
1375 scan
= (unsigned char *) id
;
1381 *scan
++ = (value
>> 24) & 0xff;
1382 *scan
++ = (value
>> 16) & 0xff;
1383 *scan
++ = (value
>> 8) & 0xff;
1384 *scan
++ = (value
& 0xff);
1388 threadref_to_int (threadref
*ref
)
1391 unsigned char *scan
;
1393 scan
= (char *) ref
;
1397 value
= (value
<< 8) | ((*scan
++) & 0xff);
1402 copy_threadref (threadref
*dest
, threadref
*src
)
1405 unsigned char *csrc
, *cdest
;
1407 csrc
= (unsigned char *) src
;
1408 cdest
= (unsigned char *) dest
;
1415 threadmatch (threadref
*dest
, threadref
*src
)
1417 /* things are broken right now, so just assume we got a match */
1419 unsigned char *srcp
, *destp
;
1421 srcp
= (char *) src
;
1422 destp
= (char *) dest
;
1426 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1433 threadid:1, # always request threadid
1440 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1443 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1445 *pkt
++ = 'q'; /* Info Query */
1446 *pkt
++ = 'P'; /* process or thread info */
1447 pkt
= pack_int (pkt
, mode
); /* mode */
1448 pkt
= pack_threadid (pkt
, id
); /* threadid */
1449 *pkt
= '\0'; /* terminate */
1453 /* These values tag the fields in a thread info response packet */
1454 /* Tagging the fields allows us to request specific fields and to
1455 add more fields as time goes by */
1457 #define TAG_THREADID 1 /* Echo the thread identifier */
1458 #define TAG_EXISTS 2 /* Is this process defined enough to
1459 fetch registers and its stack */
1460 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1461 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1462 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1466 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1467 struct gdb_ext_thread_info
*info
)
1469 struct remote_state
*rs
= get_remote_state ();
1473 char *limit
= pkt
+ (rs
->remote_packet_size
); /* plausable parsing limit */
1476 /* info->threadid = 0; FIXME: implement zero_threadref */
1478 info
->display
[0] = '\0';
1479 info
->shortname
[0] = '\0';
1480 info
->more_display
[0] = '\0';
1482 /* Assume the characters indicating the packet type have been stripped */
1483 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1484 pkt
= unpack_threadid (pkt
, &ref
);
1487 warning ("Incomplete response to threadinfo request\n");
1488 if (!threadmatch (&ref
, expectedref
))
1489 { /* This is an answer to a different request */
1490 warning ("ERROR RMT Thread info mismatch\n");
1493 copy_threadref (&info
->threadid
, &ref
);
1495 /* Loop on tagged fields , try to bail if somthing goes wrong */
1497 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1499 pkt
= unpack_int (pkt
, &tag
); /* tag */
1500 pkt
= unpack_byte (pkt
, &length
); /* length */
1501 if (!(tag
& mask
)) /* tags out of synch with mask */
1503 warning ("ERROR RMT: threadinfo tag mismatch\n");
1507 if (tag
== TAG_THREADID
)
1511 warning ("ERROR RMT: length of threadid is not 16\n");
1515 pkt
= unpack_threadid (pkt
, &ref
);
1516 mask
= mask
& ~TAG_THREADID
;
1519 if (tag
== TAG_EXISTS
)
1521 info
->active
= stub_unpack_int (pkt
, length
);
1523 mask
= mask
& ~(TAG_EXISTS
);
1526 warning ("ERROR RMT: 'exists' length too long\n");
1532 if (tag
== TAG_THREADNAME
)
1534 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1535 mask
= mask
& ~TAG_THREADNAME
;
1538 if (tag
== TAG_DISPLAY
)
1540 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1541 mask
= mask
& ~TAG_DISPLAY
;
1544 if (tag
== TAG_MOREDISPLAY
)
1546 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1547 mask
= mask
& ~TAG_MOREDISPLAY
;
1550 warning ("ERROR RMT: unknown thread info tag\n");
1551 break; /* Not a tag we know about */
1557 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1558 struct gdb_ext_thread_info
*info
)
1560 struct remote_state
*rs
= get_remote_state ();
1562 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1564 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1565 putpkt (threadinfo_pkt
);
1566 getpkt (threadinfo_pkt
, (rs
->remote_packet_size
), 0);
1567 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1572 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1573 representation of a threadid. */
1576 adapt_remote_get_threadinfo (gdb_threadref
*ref
, int selection
,
1577 struct gdb_ext_thread_info
*info
)
1581 int_to_threadref (&lclref
, *ref
);
1582 return remote_get_threadinfo (&lclref
, selection
, info
);
1585 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1588 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1589 threadref
*nextthread
)
1591 *pkt
++ = 'q'; /* info query packet */
1592 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1593 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1594 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1595 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1600 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1603 parse_threadlist_response (char *pkt
, int result_limit
,
1604 threadref
*original_echo
, threadref
*resultlist
,
1607 struct remote_state
*rs
= get_remote_state ();
1609 int count
, resultcount
, done
;
1612 /* Assume the 'q' and 'M chars have been stripped. */
1613 limit
= pkt
+ ((rs
->remote_packet_size
) - BUF_THREAD_ID_SIZE
); /* done parse past here */
1614 pkt
= unpack_byte (pkt
, &count
); /* count field */
1615 pkt
= unpack_nibble (pkt
, &done
);
1616 /* The first threadid is the argument threadid. */
1617 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1618 while ((count
-- > 0) && (pkt
< limit
))
1620 pkt
= unpack_threadid (pkt
, resultlist
++);
1621 if (resultcount
++ >= result_limit
)
1630 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1631 int *done
, int *result_count
, threadref
*threadlist
)
1633 struct remote_state
*rs
= get_remote_state ();
1634 static threadref echo_nextthread
;
1635 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1636 char *t_response
= alloca (rs
->remote_packet_size
);
1639 /* Trancate result limit to be smaller than the packet size */
1640 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= (rs
->remote_packet_size
))
1641 result_limit
= ((rs
->remote_packet_size
) / BUF_THREAD_ID_SIZE
) - 2;
1643 pack_threadlist_request (threadlist_packet
,
1644 startflag
, result_limit
, nextthread
);
1645 putpkt (threadlist_packet
);
1646 getpkt (t_response
, (rs
->remote_packet_size
), 0);
1649 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1652 if (!threadmatch (&echo_nextthread
, nextthread
))
1654 /* FIXME: This is a good reason to drop the packet */
1655 /* Possably, there is a duplicate response */
1657 retransmit immediatly - race conditions
1658 retransmit after timeout - yes
1660 wait for packet, then exit
1662 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1663 return 0; /* I choose simply exiting */
1665 if (*result_count
<= 0)
1669 warning ("RMT ERROR : failed to get remote thread list\n");
1672 return result
; /* break; */
1674 if (*result_count
> result_limit
)
1677 warning ("RMT ERROR: threadlist response longer than requested\n");
1683 /* This is the interface between remote and threads, remotes upper interface */
1685 /* remote_find_new_threads retrieves the thread list and for each
1686 thread in the list, looks up the thread in GDB's internal list,
1687 ading the thread if it does not already exist. This involves
1688 getting partial thread lists from the remote target so, polling the
1689 quit_flag is required. */
1692 /* About this many threadisds fit in a packet. */
1694 #define MAXTHREADLISTRESULTS 32
1697 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1700 int done
, i
, result_count
;
1704 static threadref nextthread
;
1705 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1710 if (loopcount
++ > looplimit
)
1713 warning ("Remote fetch threadlist -infinite loop-\n");
1716 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1717 &done
, &result_count
, resultthreadlist
))
1722 /* clear for later iterations */
1724 /* Setup to resume next batch of thread references, set nextthread. */
1725 if (result_count
>= 1)
1726 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1728 while (result_count
--)
1729 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1736 remote_newthread_step (threadref
*ref
, void *context
)
1740 ptid
= pid_to_ptid (threadref_to_int (ref
));
1742 if (!in_thread_list (ptid
))
1744 return 1; /* continue iterator */
1747 #define CRAZY_MAX_THREADS 1000
1750 remote_current_thread (ptid_t oldpid
)
1752 struct remote_state
*rs
= get_remote_state ();
1753 char *buf
= alloca (rs
->remote_packet_size
);
1756 getpkt (buf
, (rs
->remote_packet_size
), 0);
1757 if (buf
[0] == 'Q' && buf
[1] == 'C')
1758 return pid_to_ptid (strtol (&buf
[2], NULL
, 16));
1763 /* Find new threads for info threads command.
1764 * Original version, using John Metzler's thread protocol.
1768 remote_find_new_threads (void)
1770 remote_threadlist_iterator (remote_newthread_step
, 0,
1772 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1773 inferior_ptid
= remote_current_thread (inferior_ptid
);
1777 * Find all threads for info threads command.
1778 * Uses new thread protocol contributed by Cisco.
1779 * Falls back and attempts to use the older method (above)
1780 * if the target doesn't respond to the new method.
1784 remote_threads_info (void)
1786 struct remote_state
*rs
= get_remote_state ();
1787 char *buf
= alloca (rs
->remote_packet_size
);
1791 if (remote_desc
== 0) /* paranoia */
1792 error ("Command can only be used when connected to the remote target.");
1794 if (use_threadinfo_query
)
1796 putpkt ("qfThreadInfo");
1798 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1799 if (bufp
[0] != '\0') /* q packet recognized */
1801 while (*bufp
++ == 'm') /* reply contains one or more TID */
1805 tid
= strtol (bufp
, &bufp
, 16);
1806 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1807 add_thread (pid_to_ptid (tid
));
1809 while (*bufp
++ == ','); /* comma-separated list */
1810 putpkt ("qsThreadInfo");
1812 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1818 /* Else fall back to old method based on jmetzler protocol. */
1819 use_threadinfo_query
= 0;
1820 remote_find_new_threads ();
1825 * Collect a descriptive string about the given thread.
1826 * The target may say anything it wants to about the thread
1827 * (typically info about its blocked / runnable state, name, etc.).
1828 * This string will appear in the info threads display.
1830 * Optional: targets are not required to implement this function.
1834 remote_threads_extra_info (struct thread_info
*tp
)
1836 struct remote_state
*rs
= get_remote_state ();
1840 struct gdb_ext_thread_info threadinfo
;
1841 static char display_buf
[100]; /* arbitrary... */
1842 char *bufp
= alloca (rs
->remote_packet_size
);
1843 int n
= 0; /* position in display_buf */
1845 if (remote_desc
== 0) /* paranoia */
1846 internal_error (__FILE__
, __LINE__
,
1847 "remote_threads_extra_info");
1849 if (use_threadextra_query
)
1851 sprintf (bufp
, "qThreadExtraInfo,%x", PIDGET (tp
->ptid
));
1853 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1856 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1857 result
= hex2bin (bufp
, display_buf
, n
);
1858 display_buf
[result
] = '\0';
1863 /* If the above query fails, fall back to the old method. */
1864 use_threadextra_query
= 0;
1865 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1866 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1867 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1868 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1869 if (threadinfo
.active
)
1871 if (*threadinfo
.shortname
)
1872 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1873 if (*threadinfo
.display
)
1874 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1875 if (*threadinfo
.more_display
)
1876 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1877 threadinfo
.more_display
);
1881 /* for purely cosmetic reasons, clear up trailing commas */
1882 if (',' == display_buf
[n
-1])
1883 display_buf
[n
-1] = ' ';
1892 /* Restart the remote side; this is an extended protocol operation. */
1895 extended_remote_restart (void)
1897 struct remote_state
*rs
= get_remote_state ();
1898 char *buf
= alloca (rs
->remote_packet_size
);
1900 /* Send the restart command; for reasons I don't understand the
1901 remote side really expects a number after the "R". */
1903 sprintf (&buf
[1], "%x", 0);
1906 /* Now query for status so this looks just like we restarted
1907 gdbserver from scratch. */
1909 getpkt (buf
, (rs
->remote_packet_size
), 0);
1912 /* Clean up connection to a remote debugger. */
1916 remote_close (int quitting
)
1919 serial_close (remote_desc
);
1923 /* Query the remote side for the text, data and bss offsets. */
1928 struct remote_state
*rs
= get_remote_state ();
1929 char *buf
= alloca (rs
->remote_packet_size
);
1932 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1933 struct section_offsets
*offs
;
1935 putpkt ("qOffsets");
1937 getpkt (buf
, (rs
->remote_packet_size
), 0);
1939 if (buf
[0] == '\000')
1940 return; /* Return silently. Stub doesn't support
1944 warning ("Remote failure reply: %s", buf
);
1948 /* Pick up each field in turn. This used to be done with scanf, but
1949 scanf will make trouble if CORE_ADDR size doesn't match
1950 conversion directives correctly. The following code will work
1951 with any size of CORE_ADDR. */
1952 text_addr
= data_addr
= bss_addr
= 0;
1956 if (strncmp (ptr
, "Text=", 5) == 0)
1959 /* Don't use strtol, could lose on big values. */
1960 while (*ptr
&& *ptr
!= ';')
1961 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1966 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1969 while (*ptr
&& *ptr
!= ';')
1970 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1975 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1978 while (*ptr
&& *ptr
!= ';')
1979 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1985 error ("Malformed response to offset query, %s", buf
);
1987 if (symfile_objfile
== NULL
)
1990 offs
= ((struct section_offsets
*)
1991 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
1992 memcpy (offs
, symfile_objfile
->section_offsets
,
1993 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
1995 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
1997 /* This is a temporary kludge to force data and bss to use the same offsets
1998 because that's what nlmconv does now. The real solution requires changes
1999 to the stub and remote.c that I don't have time to do right now. */
2001 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2002 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2004 objfile_relocate (symfile_objfile
, offs
);
2008 * Cisco version of section offsets:
2010 * Instead of having GDB query the target for the section offsets,
2011 * Cisco lets the target volunteer the information! It's also in
2012 * a different format, so here are the functions that will decode
2013 * a section offset packet from a Cisco target.
2017 * Function: remote_cisco_section_offsets
2019 * Returns: zero for success, non-zero for failure
2023 remote_cisco_section_offsets (bfd_vma text_addr
,
2026 bfd_signed_vma
*text_offs
,
2027 bfd_signed_vma
*data_offs
,
2028 bfd_signed_vma
*bss_offs
)
2030 bfd_vma text_base
, data_base
, bss_base
;
2031 struct minimal_symbol
*start
;
2036 if (symfile_objfile
== NULL
)
2037 return -1; /* no can do nothin' */
2039 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
2041 return -1; /* Can't find "_start" symbol */
2043 data_base
= bss_base
= 0;
2044 text_base
= SYMBOL_VALUE_ADDRESS (start
);
2046 abfd
= symfile_objfile
->obfd
;
2047 for (sect
= abfd
->sections
;
2051 const char *p
= bfd_get_section_name (abfd
, sect
);
2053 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
2054 if (data_base
== 0 ||
2055 data_base
> bfd_get_section_vma (abfd
, sect
))
2056 data_base
= bfd_get_section_vma (abfd
, sect
);
2057 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
2058 if (bss_base
== 0 ||
2059 bss_base
> bfd_get_section_vma (abfd
, sect
))
2060 bss_base
= bfd_get_section_vma (abfd
, sect
);
2062 *text_offs
= text_addr
- text_base
;
2063 *data_offs
= data_addr
- data_base
;
2064 *bss_offs
= bss_addr
- bss_base
;
2069 sprintf (tmp
, "VMA: text = 0x");
2070 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
2071 sprintf (tmp
+ strlen (tmp
), " data = 0x");
2072 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
2073 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
2074 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
2075 fprintf_filtered (gdb_stdlog
, tmp
);
2076 fprintf_filtered (gdb_stdlog
,
2077 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
2078 paddr_nz (*text_offs
),
2079 paddr_nz (*data_offs
),
2080 paddr_nz (*bss_offs
));
2087 * Function: remote_cisco_objfile_relocate
2089 * Relocate the symbol file for a remote target.
2093 remote_cisco_objfile_relocate (bfd_signed_vma text_off
, bfd_signed_vma data_off
,
2094 bfd_signed_vma bss_off
)
2096 struct section_offsets
*offs
;
2098 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2100 /* FIXME: This code assumes gdb-stabs.h is being used; it's
2101 broken for xcoff, dwarf, sdb-coff, etc. But there is no
2102 simple canonical representation for this stuff. */
2104 offs
= (struct section_offsets
*)
2105 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2106 memcpy (offs
, symfile_objfile
->section_offsets
,
2107 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2109 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_off
;
2110 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_off
;
2111 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = bss_off
;
2113 /* First call the standard objfile_relocate. */
2114 objfile_relocate (symfile_objfile
, offs
);
2116 /* Now we need to fix up the section entries already attached to
2117 the exec target. These entries will control memory transfers
2118 from the exec file. */
2120 exec_set_section_offsets (text_off
, data_off
, bss_off
);
2124 /* Stub for catch_errors. */
2127 remote_start_remote_dummy (struct ui_out
*uiout
, void *dummy
)
2129 start_remote (); /* Initialize gdb process mechanisms */
2130 /* NOTE: Return something >=0. A -ve value is reserved for
2131 catch_exceptions. */
2136 remote_start_remote (struct ui_out
*uiout
, void *dummy
)
2138 immediate_quit
++; /* Allow user to interrupt it */
2140 /* Ack any packet which the remote side has already sent. */
2141 serial_write (remote_desc
, "+", 1);
2143 /* Let the stub know that we want it to return the thread. */
2146 inferior_ptid
= remote_current_thread (inferior_ptid
);
2148 get_offsets (); /* Get text, data & bss offsets */
2150 putpkt ("?"); /* initiate a query from remote machine */
2153 /* NOTE: See comment above in remote_start_remote_dummy(). This
2154 function returns something >=0. */
2155 return remote_start_remote_dummy (uiout
, dummy
);
2158 /* Open a connection to a remote debugger.
2159 NAME is the filename used for communication. */
2162 remote_open (char *name
, int from_tty
)
2164 remote_open_1 (name
, from_tty
, &remote_ops
, 0, 0);
2167 /* Just like remote_open, but with asynchronous support. */
2169 remote_async_open (char *name
, int from_tty
)
2171 remote_open_1 (name
, from_tty
, &remote_async_ops
, 0, 1);
2174 /* Open a connection to a remote debugger using the extended
2175 remote gdb protocol. NAME is the filename used for communication. */
2178 extended_remote_open (char *name
, int from_tty
)
2180 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */,
2184 /* Just like extended_remote_open, but with asynchronous support. */
2186 extended_remote_async_open (char *name
, int from_tty
)
2188 remote_open_1 (name
, from_tty
, &extended_async_remote_ops
,
2189 1 /*extended_p */, 1 /* async_p */);
2192 /* Generic code for opening a connection to a remote target. */
2195 init_all_packet_configs (void)
2198 update_packet_config (&remote_protocol_e
);
2199 update_packet_config (&remote_protocol_E
);
2200 update_packet_config (&remote_protocol_P
);
2201 update_packet_config (&remote_protocol_qSymbol
);
2202 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2203 update_packet_config (&remote_protocol_Z
[i
]);
2204 /* Force remote_write_bytes to check whether target supports binary
2206 update_packet_config (&remote_protocol_binary_download
);
2209 /* Symbol look-up. */
2212 remote_check_symbols (struct objfile
*objfile
)
2214 struct remote_state
*rs
= get_remote_state ();
2215 char *msg
, *reply
, *tmp
;
2216 struct minimal_symbol
*sym
;
2219 if (remote_protocol_qSymbol
.support
== PACKET_DISABLE
)
2222 msg
= alloca (rs
->remote_packet_size
);
2223 reply
= alloca (rs
->remote_packet_size
);
2225 /* Invite target to request symbol lookups. */
2227 putpkt ("qSymbol::");
2228 getpkt (reply
, (rs
->remote_packet_size
), 0);
2229 packet_ok (reply
, &remote_protocol_qSymbol
);
2231 while (strncmp (reply
, "qSymbol:", 8) == 0)
2234 end
= hex2bin (tmp
, msg
, strlen (tmp
) / 2);
2236 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2238 sprintf (msg
, "qSymbol::%s", &reply
[8]);
2240 sprintf (msg
, "qSymbol:%s:%s",
2241 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2244 getpkt (reply
, (rs
->remote_packet_size
), 0);
2248 static struct serial
*
2249 remote_serial_open (char *name
)
2251 static int udp_warning
= 0;
2253 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2254 of in ser-tcp.c, because it is the remote protocol assuming that the
2255 serial connection is reliable and not the serial connection promising
2257 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2259 warning ("The remote protocol may be unreliable over UDP.");
2260 warning ("Some events may be lost, rendering further debugging "
2265 return serial_open (name
);
2269 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2270 int extended_p
, int async_p
)
2273 struct remote_state
*rs
= get_remote_state ();
2275 error ("To open a remote debug connection, you need to specify what\n"
2276 "serial device is attached to the remote system\n"
2277 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2279 /* See FIXME above */
2281 wait_forever_enabled_p
= 1;
2283 target_preopen (from_tty
);
2285 unpush_target (target
);
2287 remote_desc
= remote_serial_open (name
);
2289 perror_with_name (name
);
2291 if (baud_rate
!= -1)
2293 if (serial_setbaudrate (remote_desc
, baud_rate
))
2295 serial_close (remote_desc
);
2296 perror_with_name (name
);
2300 serial_raw (remote_desc
);
2302 /* If there is something sitting in the buffer we might take it as a
2303 response to a command, which would be bad. */
2304 serial_flush_input (remote_desc
);
2308 puts_filtered ("Remote debugging using ");
2309 puts_filtered (name
);
2310 puts_filtered ("\n");
2312 push_target (target
); /* Switch to using remote target now */
2314 init_all_packet_configs ();
2316 general_thread
= -2;
2317 continue_thread
= -2;
2319 /* Probe for ability to use "ThreadInfo" query, as required. */
2320 use_threadinfo_query
= 1;
2321 use_threadextra_query
= 1;
2323 /* Without this, some commands which require an active target (such
2324 as kill) won't work. This variable serves (at least) double duty
2325 as both the pid of the target process (if it has such), and as a
2326 flag indicating that a target is active. These functions should
2327 be split out into seperate variables, especially since GDB will
2328 someday have a notion of debugging several processes. */
2330 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2334 /* With this target we start out by owning the terminal. */
2335 remote_async_terminal_ours_p
= 1;
2337 /* FIXME: cagney/1999-09-23: During the initial connection it is
2338 assumed that the target is already ready and able to respond to
2339 requests. Unfortunately remote_start_remote() eventually calls
2340 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2341 around this. Eventually a mechanism that allows
2342 wait_for_inferior() to expect/get timeouts will be
2344 wait_forever_enabled_p
= 0;
2347 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2348 /* First delete any symbols previously loaded from shared libraries. */
2349 no_shared_libraries (NULL
, 0);
2352 /* Start the remote connection. If error() or QUIT, discard this
2353 target (we'd otherwise be in an inconsistent state) and then
2354 propogate the error on up the exception chain. This ensures that
2355 the caller doesn't stumble along blindly assuming that the
2356 function succeeded. The CLI doesn't have this problem but other
2357 UI's, such as MI do.
2359 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2360 this function should return an error indication letting the
2361 caller restore the previous state. Unfortunatly the command
2362 ``target remote'' is directly wired to this function making that
2363 impossible. On a positive note, the CLI side of this problem has
2364 been fixed - the function set_cmd_context() makes it possible for
2365 all the ``target ....'' commands to share a common callback
2366 function. See cli-dump.c. */
2367 ex
= catch_exceptions (uiout
,
2368 remote_start_remote
, NULL
,
2369 "Couldn't establish connection to remote"
2376 wait_forever_enabled_p
= 1;
2377 throw_exception (ex
);
2381 wait_forever_enabled_p
= 1;
2385 /* Tell the remote that we are using the extended protocol. */
2386 char *buf
= alloca (rs
->remote_packet_size
);
2388 getpkt (buf
, (rs
->remote_packet_size
), 0);
2390 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2391 /* FIXME: need a master target_open vector from which all
2392 remote_opens can be called, so that stuff like this can
2393 go there. Failing that, the following code must be copied
2394 to the open function for any remote target that wants to
2395 support svr4 shared libraries. */
2397 /* Set up to detect and load shared libraries. */
2398 if (exec_bfd
) /* No use without an exec file. */
2400 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2401 remote_check_symbols (symfile_objfile
);
2406 /* This takes a program previously attached to and detaches it. After
2407 this is done, GDB can be used to debug some other program. We
2408 better not have left any breakpoints in the target program or it'll
2409 die when it hits one. */
2412 remote_detach (char *args
, int from_tty
)
2414 struct remote_state
*rs
= get_remote_state ();
2415 char *buf
= alloca (rs
->remote_packet_size
);
2418 error ("Argument given to \"detach\" when remotely debugging.");
2420 /* Tell the remote target to detach. */
2422 remote_send (buf
, (rs
->remote_packet_size
));
2424 target_mourn_inferior ();
2426 puts_filtered ("Ending remote debugging.\n");
2430 /* Same as remote_detach, but with async support. */
2432 remote_async_detach (char *args
, int from_tty
)
2434 struct remote_state
*rs
= get_remote_state ();
2435 char *buf
= alloca (rs
->remote_packet_size
);
2438 error ("Argument given to \"detach\" when remotely debugging.");
2440 /* Tell the remote target to detach. */
2442 remote_send (buf
, (rs
->remote_packet_size
));
2444 /* Unregister the file descriptor from the event loop. */
2445 if (target_is_async_p ())
2446 serial_async (remote_desc
, NULL
, 0);
2448 target_mourn_inferior ();
2450 puts_filtered ("Ending remote debugging.\n");
2453 /* Convert hex digit A to a number. */
2458 if (a
>= '0' && a
<= '9')
2460 else if (a
>= 'a' && a
<= 'f')
2461 return a
- 'a' + 10;
2462 else if (a
>= 'A' && a
<= 'F')
2463 return a
- 'A' + 10;
2465 error ("Reply contains invalid hex digit %d", a
);
2469 hex2bin (const char *hex
, char *bin
, int count
)
2473 for (i
= 0; i
< count
; i
++)
2475 if (hex
[0] == 0 || hex
[1] == 0)
2477 /* Hex string is short, or of uneven length.
2478 Return the count that has been converted so far. */
2481 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2487 /* Convert number NIB to a hex digit. */
2495 return 'a' + nib
- 10;
2499 bin2hex (const char *bin
, char *hex
, int count
)
2502 /* May use a length, or a nul-terminated string as input. */
2504 count
= strlen (bin
);
2506 for (i
= 0; i
< count
; i
++)
2508 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2509 *hex
++ = tohex (*bin
++ & 0xf);
2515 /* Tell the remote machine to resume. */
2517 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2519 static int last_sent_step
;
2522 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2524 struct remote_state
*rs
= get_remote_state ();
2525 char *buf
= alloca (rs
->remote_packet_size
);
2526 int pid
= PIDGET (ptid
);
2530 set_thread (0, 0); /* run any thread */
2532 set_thread (pid
, 0); /* run this thread */
2534 last_sent_signal
= siggnal
;
2535 last_sent_step
= step
;
2537 /* A hook for when we need to do something at the last moment before
2539 if (target_resume_hook
)
2540 (*target_resume_hook
) ();
2543 /* The s/S/c/C packets do not return status. So if the target does
2544 not support the S or C packets, the debug agent returns an empty
2545 string which is detected in remote_wait(). This protocol defect
2546 is fixed in the e/E packets. */
2548 if (step
&& step_range_end
)
2550 /* If the target does not support the 'E' packet, we try the 'S'
2551 packet. Ideally we would fall back to the 'e' packet if that
2552 too is not supported. But that would require another copy of
2553 the code to issue the 'e' packet (and fall back to 's' if not
2554 supported) in remote_wait(). */
2556 if (siggnal
!= TARGET_SIGNAL_0
)
2558 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2562 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2563 *p
++ = tohex (((int) siggnal
) & 0xf);
2565 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2567 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2571 getpkt (buf
, (rs
->remote_packet_size
), 0);
2573 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2579 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2583 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2585 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2589 getpkt (buf
, (rs
->remote_packet_size
), 0);
2591 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2597 if (siggnal
!= TARGET_SIGNAL_0
)
2599 buf
[0] = step
? 'S' : 'C';
2600 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2601 buf
[2] = tohex (((int) siggnal
) & 0xf);
2605 strcpy (buf
, step
? "s" : "c");
2610 /* Same as remote_resume, but with async support. */
2612 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2614 struct remote_state
*rs
= get_remote_state ();
2615 char *buf
= alloca (rs
->remote_packet_size
);
2616 int pid
= PIDGET (ptid
);
2620 set_thread (0, 0); /* run any thread */
2622 set_thread (pid
, 0); /* run this thread */
2624 last_sent_signal
= siggnal
;
2625 last_sent_step
= step
;
2627 /* A hook for when we need to do something at the last moment before
2629 if (target_resume_hook
)
2630 (*target_resume_hook
) ();
2632 /* The s/S/c/C packets do not return status. So if the target does
2633 not support the S or C packets, the debug agent returns an empty
2634 string which is detected in remote_wait(). This protocol defect
2635 is fixed in the e/E packets. */
2637 if (step
&& step_range_end
)
2639 /* If the target does not support the 'E' packet, we try the 'S'
2640 packet. Ideally we would fall back to the 'e' packet if that
2641 too is not supported. But that would require another copy of
2642 the code to issue the 'e' packet (and fall back to 's' if not
2643 supported) in remote_wait(). */
2645 if (siggnal
!= TARGET_SIGNAL_0
)
2647 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2651 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2652 *p
++ = tohex (((int) siggnal
) & 0xf);
2654 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2656 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2660 getpkt (buf
, (rs
->remote_packet_size
), 0);
2662 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2663 goto register_event_loop
;
2668 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2672 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2674 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2678 getpkt (buf
, (rs
->remote_packet_size
), 0);
2680 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2681 goto register_event_loop
;
2686 if (siggnal
!= TARGET_SIGNAL_0
)
2688 buf
[0] = step
? 'S' : 'C';
2689 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2690 buf
[2] = tohex ((int) siggnal
& 0xf);
2694 strcpy (buf
, step
? "s" : "c");
2698 register_event_loop
:
2699 /* We are about to start executing the inferior, let's register it
2700 with the event loop. NOTE: this is the one place where all the
2701 execution commands end up. We could alternatively do this in each
2702 of the execution commands in infcmd.c.*/
2703 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2704 into infcmd.c in order to allow inferior function calls to work
2705 NOT asynchronously. */
2706 if (event_loop_p
&& target_can_async_p ())
2707 target_async (inferior_event_handler
, 0);
2708 /* Tell the world that the target is now executing. */
2709 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2710 this? Instead, should the client of target just assume (for
2711 async targets) that the target is going to start executing? Is
2712 this information already found in the continuation block? */
2713 if (target_is_async_p ())
2714 target_executing
= 1;
2718 /* Set up the signal handler for SIGINT, while the target is
2719 executing, ovewriting the 'regular' SIGINT signal handler. */
2721 initialize_sigint_signal_handler (void)
2723 sigint_remote_token
=
2724 create_async_signal_handler (async_remote_interrupt
, NULL
);
2725 signal (SIGINT
, handle_remote_sigint
);
2728 /* Signal handler for SIGINT, while the target is executing. */
2730 handle_remote_sigint (int sig
)
2732 signal (sig
, handle_remote_sigint_twice
);
2733 sigint_remote_twice_token
=
2734 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2735 mark_async_signal_handler_wrapper (sigint_remote_token
);
2738 /* Signal handler for SIGINT, installed after SIGINT has already been
2739 sent once. It will take effect the second time that the user sends
2742 handle_remote_sigint_twice (int sig
)
2744 signal (sig
, handle_sigint
);
2745 sigint_remote_twice_token
=
2746 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2747 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2750 /* Perform the real interruption of the target execution, in response
2753 async_remote_interrupt (gdb_client_data arg
)
2756 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2761 /* Perform interrupt, if the first attempt did not succeed. Just give
2762 up on the target alltogether. */
2764 async_remote_interrupt_twice (gdb_client_data arg
)
2767 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2768 /* Do something only if the target was not killed by the previous
2770 if (target_executing
)
2773 signal (SIGINT
, handle_remote_sigint
);
2777 /* Reinstall the usual SIGINT handlers, after the target has
2780 cleanup_sigint_signal_handler (void *dummy
)
2782 signal (SIGINT
, handle_sigint
);
2783 if (sigint_remote_twice_token
)
2784 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2785 if (sigint_remote_token
)
2786 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2789 /* Send ^C to target to halt it. Target will respond, and send us a
2791 static void (*ofunc
) (int);
2793 /* The command line interface's stop routine. This function is installed
2794 as a signal handler for SIGINT. The first time a user requests a
2795 stop, we call remote_stop to send a break or ^C. If there is no
2796 response from the target (it didn't stop when the user requested it),
2797 we ask the user if he'd like to detach from the target. */
2799 remote_interrupt (int signo
)
2801 /* If this doesn't work, try more severe steps. */
2802 signal (signo
, remote_interrupt_twice
);
2805 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2810 /* The user typed ^C twice. */
2813 remote_interrupt_twice (int signo
)
2815 signal (signo
, ofunc
);
2817 signal (signo
, remote_interrupt
);
2820 /* This is the generic stop called via the target vector. When a target
2821 interrupt is requested, either by the command line or the GUI, we
2822 will eventually end up here. */
2826 /* Send a break or a ^C, depending on user preference. */
2828 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2831 serial_send_break (remote_desc
);
2833 serial_write (remote_desc
, "\003", 1);
2836 /* Ask the user what to do when an interrupt is received. */
2839 interrupt_query (void)
2841 target_terminal_ours ();
2843 if (query ("Interrupted while waiting for the program.\n\
2844 Give up (and stop debugging it)? "))
2846 target_mourn_inferior ();
2847 throw_exception (RETURN_QUIT
);
2850 target_terminal_inferior ();
2853 /* Enable/disable target terminal ownership. Most targets can use
2854 terminal groups to control terminal ownership. Remote targets are
2855 different in that explicit transfer of ownership to/from GDB/target
2859 remote_async_terminal_inferior (void)
2861 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2862 sync_execution here. This function should only be called when
2863 GDB is resuming the inferior in the forground. A background
2864 resume (``run&'') should leave GDB in control of the terminal and
2865 consequently should not call this code. */
2866 if (!sync_execution
)
2868 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2869 calls target_terminal_*() idenpotent. The event-loop GDB talking
2870 to an asynchronous target with a synchronous command calls this
2871 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2872 stops trying to transfer the terminal to the target when it
2873 shouldn't this guard can go away. */
2874 if (!remote_async_terminal_ours_p
)
2876 delete_file_handler (input_fd
);
2877 remote_async_terminal_ours_p
= 0;
2878 initialize_sigint_signal_handler ();
2879 /* NOTE: At this point we could also register our selves as the
2880 recipient of all input. Any characters typed could then be
2881 passed on down to the target. */
2885 remote_async_terminal_ours (void)
2887 /* See FIXME in remote_async_terminal_inferior. */
2888 if (!sync_execution
)
2890 /* See FIXME in remote_async_terminal_inferior. */
2891 if (remote_async_terminal_ours_p
)
2893 cleanup_sigint_signal_handler (NULL
);
2894 add_file_handler (input_fd
, stdin_event_handler
, 0);
2895 remote_async_terminal_ours_p
= 1;
2898 /* If nonzero, ignore the next kill. */
2903 remote_console_output (char *msg
)
2907 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2910 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2913 fputs_unfiltered (tb
, gdb_stdtarg
);
2915 gdb_flush (gdb_stdtarg
);
2918 /* Wait until the remote machine stops, then return,
2919 storing status in STATUS just as `wait' would.
2920 Returns "pid", which in the case of a multi-threaded
2921 remote OS, is the thread-id. */
2924 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2926 struct remote_state
*rs
= get_remote_state ();
2927 unsigned char *buf
= alloca (rs
->remote_packet_size
);
2928 ULONGEST thread_num
= -1;
2931 status
->kind
= TARGET_WAITKIND_EXITED
;
2932 status
->value
.integer
= 0;
2938 ofunc
= signal (SIGINT
, remote_interrupt
);
2939 getpkt (buf
, (rs
->remote_packet_size
), 1);
2940 signal (SIGINT
, ofunc
);
2942 /* This is a hook for when we need to do something (perhaps the
2943 collection of trace data) every time the target stops. */
2944 if (target_wait_loop_hook
)
2945 (*target_wait_loop_hook
) ();
2947 remote_stopped_by_watchpoint_p
= 0;
2951 case 'E': /* Error of some sort */
2952 warning ("Remote failure reply: %s", buf
);
2954 case 'F': /* File-I/O request */
2955 remote_fileio_request (buf
);
2957 case 'T': /* Status with PC, SP, FP, ... */
2960 char regs
[MAX_REGISTER_SIZE
];
2962 /* Expedited reply, containing Signal, {regno, reg} repeat */
2963 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2965 n... = register number
2966 r... = register contents
2968 p
= &buf
[3]; /* after Txx */
2977 /* If the packet contains a register number save it in pnum
2978 and set p1 to point to the character following it.
2979 Otherwise p1 points to p. */
2981 /* If this packet is an awatch packet, don't parse the 'a'
2982 as a register number. */
2984 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
2986 /* Read the ``P'' register number. */
2987 pnum
= strtol (p
, &p_temp
, 16);
2988 p1
= (unsigned char *) p_temp
;
2993 if (p1
== p
) /* No register number present here */
2995 p1
= (unsigned char *) strchr (p
, ':');
2997 warning ("Malformed packet(a) (missing colon): %s\n\
3000 if (strncmp (p
, "thread", p1
- p
) == 0)
3002 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3003 record_currthread (thread_num
);
3004 p
= (unsigned char *) p_temp
;
3006 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3007 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3008 || (strncmp (p
, "awatch", p1
- p
) == 0))
3010 remote_stopped_by_watchpoint_p
= 1;
3011 p
= unpack_varlen_hex (++p1
, &addr
);
3012 remote_watch_data_address
= (CORE_ADDR
)addr
;
3016 /* Silently skip unknown optional info. */
3017 p_temp
= strchr (p1
+ 1, ';');
3019 p
= (unsigned char *) p_temp
;
3024 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3028 warning ("Malformed packet(b) (missing colon): %s\n\
3033 warning ("Remote sent bad register number %s: %s\n\
3035 phex_nz (pnum
, 0), p
, buf
);
3037 fieldsize
= hex2bin (p
, regs
, REGISTER_RAW_SIZE (reg
->regnum
));
3039 if (fieldsize
< REGISTER_RAW_SIZE (reg
->regnum
))
3040 warning ("Remote reply is too short: %s", buf
);
3041 supply_register (reg
->regnum
, regs
);
3046 warning ("Remote register badly formatted: %s", buf
);
3047 warning (" here: %s", p
);
3052 case 'S': /* Old style status, just signal only */
3053 status
->kind
= TARGET_WAITKIND_STOPPED
;
3054 status
->value
.sig
= (enum target_signal
)
3055 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3059 /* Export Cisco kernel mode as a convenience variable
3060 (so that it can be used in the GDB prompt if desired). */
3062 if (cisco_kernel_mode
== 1)
3063 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3064 value_from_string ("PDEBUG-"));
3065 cisco_kernel_mode
= 0;
3066 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3067 record_currthread (thread_num
);
3069 else if (buf
[3] == 'k')
3071 /* Export Cisco kernel mode as a convenience variable
3072 (so that it can be used in the GDB prompt if desired). */
3074 if (cisco_kernel_mode
== 1)
3075 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3076 value_from_string ("KDEBUG-"));
3077 cisco_kernel_mode
= 1;
3080 case 'N': /* Cisco special: status and offsets */
3082 bfd_vma text_addr
, data_addr
, bss_addr
;
3083 bfd_signed_vma text_off
, data_off
, bss_off
;
3086 status
->kind
= TARGET_WAITKIND_STOPPED
;
3087 status
->value
.sig
= (enum target_signal
)
3088 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3090 if (symfile_objfile
== NULL
)
3092 warning ("Relocation packet received with no symbol file. \
3097 /* Relocate object file. Buffer format is NAATT;DD;BB
3098 * where AA is the signal number, TT is the new text
3099 * address, DD * is the new data address, and BB is the
3100 * new bss address. */
3103 text_addr
= strtoul (p
, (char **) &p1
, 16);
3104 if (p1
== p
|| *p1
!= ';')
3105 warning ("Malformed relocation packet: Packet '%s'", buf
);
3107 data_addr
= strtoul (p
, (char **) &p1
, 16);
3108 if (p1
== p
|| *p1
!= ';')
3109 warning ("Malformed relocation packet: Packet '%s'", buf
);
3111 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3113 warning ("Malformed relocation packet: Packet '%s'", buf
);
3115 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3116 &text_off
, &data_off
, &bss_off
)
3118 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3119 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3123 case 'W': /* Target exited */
3125 /* The remote process exited. */
3126 status
->kind
= TARGET_WAITKIND_EXITED
;
3127 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3131 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3132 status
->value
.sig
= (enum target_signal
)
3133 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3137 case 'O': /* Console output */
3138 remote_console_output (buf
+ 1);
3141 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3143 /* Zero length reply means that we tried 'S' or 'C' and
3144 the remote system doesn't support it. */
3145 target_terminal_ours_for_output ();
3147 ("Can't send signals to this remote system. %s not sent.\n",
3148 target_signal_to_name (last_sent_signal
));
3149 last_sent_signal
= TARGET_SIGNAL_0
;
3150 target_terminal_inferior ();
3152 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3153 putpkt ((char *) buf
);
3156 /* else fallthrough */
3158 warning ("Invalid remote reply: %s", buf
);
3163 if (thread_num
!= -1)
3165 return pid_to_ptid (thread_num
);
3167 return inferior_ptid
;
3170 /* Async version of remote_wait. */
3172 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3174 struct remote_state
*rs
= get_remote_state ();
3175 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3176 ULONGEST thread_num
= -1;
3179 status
->kind
= TARGET_WAITKIND_EXITED
;
3180 status
->value
.integer
= 0;
3182 remote_stopped_by_watchpoint_p
= 0;
3188 if (!target_is_async_p ())
3189 ofunc
= signal (SIGINT
, remote_interrupt
);
3190 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3191 _never_ wait for ever -> test on target_is_async_p().
3192 However, before we do that we need to ensure that the caller
3193 knows how to take the target into/out of async mode. */
3194 getpkt (buf
, (rs
->remote_packet_size
), wait_forever_enabled_p
);
3195 if (!target_is_async_p ())
3196 signal (SIGINT
, ofunc
);
3198 /* This is a hook for when we need to do something (perhaps the
3199 collection of trace data) every time the target stops. */
3200 if (target_wait_loop_hook
)
3201 (*target_wait_loop_hook
) ();
3205 case 'E': /* Error of some sort */
3206 warning ("Remote failure reply: %s", buf
);
3208 case 'F': /* File-I/O request */
3209 remote_fileio_request (buf
);
3211 case 'T': /* Status with PC, SP, FP, ... */
3214 char regs
[MAX_REGISTER_SIZE
];
3216 /* Expedited reply, containing Signal, {regno, reg} repeat */
3217 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3219 n... = register number
3220 r... = register contents
3222 p
= &buf
[3]; /* after Txx */
3231 /* If the packet contains a register number, save it in pnum
3232 and set p1 to point to the character following it.
3233 Otherwise p1 points to p. */
3235 /* If this packet is an awatch packet, don't parse the 'a'
3236 as a register number. */
3238 if (!strncmp (p
, "awatch", strlen ("awatch")) != 0)
3240 /* Read the register number. */
3241 pnum
= strtol (p
, &p_temp
, 16);
3242 p1
= (unsigned char *) p_temp
;
3247 if (p1
== p
) /* No register number present here */
3249 p1
= (unsigned char *) strchr (p
, ':');
3251 warning ("Malformed packet(a) (missing colon): %s\n\
3254 if (strncmp (p
, "thread", p1
- p
) == 0)
3256 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3257 record_currthread (thread_num
);
3258 p
= (unsigned char *) p_temp
;
3260 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3261 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3262 || (strncmp (p
, "awatch", p1
- p
) == 0))
3264 remote_stopped_by_watchpoint_p
= 1;
3265 p
= unpack_varlen_hex (++p1
, &addr
);
3266 remote_watch_data_address
= (CORE_ADDR
)addr
;
3270 /* Silently skip unknown optional info. */
3271 p_temp
= (unsigned char *) strchr (p1
+ 1, ';');
3279 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3282 warning ("Malformed packet(b) (missing colon): %s\n\
3287 warning ("Remote sent bad register number %ld: %s\n\
3291 fieldsize
= hex2bin (p
, regs
, REGISTER_RAW_SIZE (reg
->regnum
));
3293 if (fieldsize
< REGISTER_RAW_SIZE (reg
->regnum
))
3294 warning ("Remote reply is too short: %s", buf
);
3295 supply_register (reg
->regnum
, regs
);
3300 warning ("Remote register badly formatted: %s", buf
);
3301 warning (" here: %s", p
);
3306 case 'S': /* Old style status, just signal only */
3307 status
->kind
= TARGET_WAITKIND_STOPPED
;
3308 status
->value
.sig
= (enum target_signal
)
3309 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3313 /* Export Cisco kernel mode as a convenience variable
3314 (so that it can be used in the GDB prompt if desired). */
3316 if (cisco_kernel_mode
== 1)
3317 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3318 value_from_string ("PDEBUG-"));
3319 cisco_kernel_mode
= 0;
3320 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3321 record_currthread (thread_num
);
3323 else if (buf
[3] == 'k')
3325 /* Export Cisco kernel mode as a convenience variable
3326 (so that it can be used in the GDB prompt if desired). */
3328 if (cisco_kernel_mode
== 1)
3329 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3330 value_from_string ("KDEBUG-"));
3331 cisco_kernel_mode
= 1;
3334 case 'N': /* Cisco special: status and offsets */
3336 bfd_vma text_addr
, data_addr
, bss_addr
;
3337 bfd_signed_vma text_off
, data_off
, bss_off
;
3340 status
->kind
= TARGET_WAITKIND_STOPPED
;
3341 status
->value
.sig
= (enum target_signal
)
3342 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3344 if (symfile_objfile
== NULL
)
3346 warning ("Relocation packet recieved with no symbol file. \
3351 /* Relocate object file. Buffer format is NAATT;DD;BB
3352 * where AA is the signal number, TT is the new text
3353 * address, DD * is the new data address, and BB is the
3354 * new bss address. */
3357 text_addr
= strtoul (p
, (char **) &p1
, 16);
3358 if (p1
== p
|| *p1
!= ';')
3359 warning ("Malformed relocation packet: Packet '%s'", buf
);
3361 data_addr
= strtoul (p
, (char **) &p1
, 16);
3362 if (p1
== p
|| *p1
!= ';')
3363 warning ("Malformed relocation packet: Packet '%s'", buf
);
3365 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3367 warning ("Malformed relocation packet: Packet '%s'", buf
);
3369 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3370 &text_off
, &data_off
, &bss_off
)
3372 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3373 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3377 case 'W': /* Target exited */
3379 /* The remote process exited. */
3380 status
->kind
= TARGET_WAITKIND_EXITED
;
3381 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3385 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3386 status
->value
.sig
= (enum target_signal
)
3387 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3391 case 'O': /* Console output */
3392 remote_console_output (buf
+ 1);
3393 /* Return immediately to the event loop. The event loop will
3394 still be waiting on the inferior afterwards. */
3395 status
->kind
= TARGET_WAITKIND_IGNORE
;
3398 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3400 /* Zero length reply means that we tried 'S' or 'C' and
3401 the remote system doesn't support it. */
3402 target_terminal_ours_for_output ();
3404 ("Can't send signals to this remote system. %s not sent.\n",
3405 target_signal_to_name (last_sent_signal
));
3406 last_sent_signal
= TARGET_SIGNAL_0
;
3407 target_terminal_inferior ();
3409 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3410 putpkt ((char *) buf
);
3413 /* else fallthrough */
3415 warning ("Invalid remote reply: %s", buf
);
3420 if (thread_num
!= -1)
3422 return pid_to_ptid (thread_num
);
3424 return inferior_ptid
;
3427 /* Number of bytes of registers this stub implements. */
3429 static int register_bytes_found
;
3431 /* Read the remote registers into the block REGS. */
3432 /* Currently we just read all the registers, so we don't use regnum. */
3436 remote_fetch_registers (int regnum
)
3438 struct remote_state
*rs
= get_remote_state ();
3439 char *buf
= alloca (rs
->remote_packet_size
);
3442 char *regs
= alloca (rs
->sizeof_g_packet
);
3444 set_thread (PIDGET (inferior_ptid
), 1);
3448 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3449 gdb_assert (reg
!= NULL
);
3450 if (!reg
->in_g_packet
)
3451 internal_error (__FILE__
, __LINE__
,
3452 "Attempt to fetch a non G-packet register when this "
3453 "remote.c does not support the p-packet.");
3457 remote_send (buf
, (rs
->remote_packet_size
));
3459 /* Save the size of the packet sent to us by the target. Its used
3460 as a heuristic when determining the max size of packets that the
3461 target can safely receive. */
3462 if ((rs
->actual_register_packet_size
) == 0)
3463 (rs
->actual_register_packet_size
) = strlen (buf
);
3465 /* Unimplemented registers read as all bits zero. */
3466 memset (regs
, 0, rs
->sizeof_g_packet
);
3468 /* We can get out of synch in various cases. If the first character
3469 in the buffer is not a hex character, assume that has happened
3470 and try to fetch another packet to read. */
3471 while ((buf
[0] < '0' || buf
[0] > '9')
3472 && (buf
[0] < 'a' || buf
[0] > 'f')
3473 && buf
[0] != 'x') /* New: unavailable register value */
3476 fprintf_unfiltered (gdb_stdlog
,
3477 "Bad register packet; fetching a new packet\n");
3478 getpkt (buf
, (rs
->remote_packet_size
), 0);
3481 /* Reply describes registers byte by byte, each byte encoded as two
3482 hex characters. Suck them all up, then supply them to the
3483 register cacheing/storage mechanism. */
3486 for (i
= 0; i
< rs
->sizeof_g_packet
; i
++)
3492 warning ("Remote reply is of odd length: %s", buf
);
3493 /* Don't change register_bytes_found in this case, and don't
3494 print a second warning. */
3497 if (p
[0] == 'x' && p
[1] == 'x')
3498 regs
[i
] = 0; /* 'x' */
3500 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3504 if (i
!= register_bytes_found
)
3506 register_bytes_found
= i
;
3507 if (REGISTER_BYTES_OK_P ()
3508 && !REGISTER_BYTES_OK (i
))
3509 warning ("Remote reply is too short: %s", buf
);
3515 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3517 struct packet_reg
*r
= &rs
->regs
[i
];
3520 supply_register (r
->regnum
, regs
+ r
->offset
);
3521 if (buf
[r
->offset
* 2] == 'x')
3522 set_register_cached (i
, -1);
3528 /* Prepare to store registers. Since we may send them all (using a
3529 'G' request), we have to read out the ones we don't want to change
3533 remote_prepare_to_store (void)
3535 /* Make sure the entire registers array is valid. */
3536 switch (remote_protocol_P
.support
)
3538 case PACKET_DISABLE
:
3539 case PACKET_SUPPORT_UNKNOWN
:
3540 /* NOTE: This isn't rs->sizeof_g_packet because here, we are
3541 forcing the register cache to read its and not the target
3543 deprecated_read_register_bytes (0, (char *) NULL
,
3544 DEPRECATED_REGISTER_BYTES
); /* OK */
3551 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3552 packet was not recognized. */
3555 store_register_using_P (int regnum
)
3557 struct remote_state
*rs
= get_remote_state ();
3558 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3559 /* Try storing a single register. */
3560 char *buf
= alloca (rs
->remote_packet_size
);
3561 char regp
[MAX_REGISTER_SIZE
];
3565 sprintf (buf
, "P%s=", phex_nz (reg
->pnum
, 0));
3566 p
= buf
+ strlen (buf
);
3567 regcache_collect (reg
->regnum
, regp
);
3568 bin2hex (regp
, p
, REGISTER_RAW_SIZE (reg
->regnum
));
3569 remote_send (buf
, rs
->remote_packet_size
);
3571 return buf
[0] != '\0';
3575 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
3576 of the register cache buffer. FIXME: ignores errors. */
3579 remote_store_registers (int regnum
)
3581 struct remote_state
*rs
= get_remote_state ();
3587 set_thread (PIDGET (inferior_ptid
), 1);
3591 switch (remote_protocol_P
.support
)
3593 case PACKET_DISABLE
:
3596 if (store_register_using_P (regnum
))
3599 error ("Protocol error: P packet not recognized by stub");
3600 case PACKET_SUPPORT_UNKNOWN
:
3601 if (store_register_using_P (regnum
))
3603 /* The stub recognized the 'P' packet. Remember this. */
3604 remote_protocol_P
.support
= PACKET_ENABLE
;
3609 /* The stub does not support the 'P' packet. Use 'G'
3610 instead, and don't try using 'P' in the future (it
3611 will just waste our time). */
3612 remote_protocol_P
.support
= PACKET_DISABLE
;
3618 /* Extract all the registers in the regcache copying them into a
3622 regs
= alloca (rs
->sizeof_g_packet
);
3623 memset (regs
, rs
->sizeof_g_packet
, 0);
3624 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3626 struct packet_reg
*r
= &rs
->regs
[i
];
3628 regcache_collect (r
->regnum
, regs
+ r
->offset
);
3632 /* Command describes registers byte by byte,
3633 each byte encoded as two hex characters. */
3634 buf
= alloca (rs
->remote_packet_size
);
3637 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3638 bin2hex (regs
, p
, register_bytes_found
);
3639 remote_send (buf
, (rs
->remote_packet_size
));
3643 /* Return the number of hex digits in num. */
3646 hexnumlen (ULONGEST num
)
3650 for (i
= 0; num
!= 0; i
++)
3656 /* Set BUF to the minimum number of hex digits representing NUM. */
3659 hexnumstr (char *buf
, ULONGEST num
)
3661 int len
= hexnumlen (num
);
3662 return hexnumnstr (buf
, num
, len
);
3666 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3669 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3675 for (i
= width
- 1; i
>= 0; i
--)
3677 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3684 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3687 remote_address_masked (CORE_ADDR addr
)
3689 if (remote_address_size
> 0
3690 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3692 /* Only create a mask when that mask can safely be constructed
3693 in a ULONGEST variable. */
3695 mask
= (mask
<< remote_address_size
) - 1;
3701 /* Determine whether the remote target supports binary downloading.
3702 This is accomplished by sending a no-op memory write of zero length
3703 to the target at the specified address. It does not suffice to send
3704 the whole packet, since many stubs strip the eighth bit and subsequently
3705 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3707 NOTE: This can still lose if the serial line is not eight-bit
3708 clean. In cases like this, the user should clear "remote
3712 check_binary_download (CORE_ADDR addr
)
3714 struct remote_state
*rs
= get_remote_state ();
3715 switch (remote_protocol_binary_download
.support
)
3717 case PACKET_DISABLE
:
3721 case PACKET_SUPPORT_UNKNOWN
:
3723 char *buf
= alloca (rs
->remote_packet_size
);
3728 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3730 p
+= hexnumstr (p
, (ULONGEST
) 0);
3734 putpkt_binary (buf
, (int) (p
- buf
));
3735 getpkt (buf
, (rs
->remote_packet_size
), 0);
3740 fprintf_unfiltered (gdb_stdlog
,
3741 "binary downloading NOT suppported by target\n");
3742 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3747 fprintf_unfiltered (gdb_stdlog
,
3748 "binary downloading suppported by target\n");
3749 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3756 /* Write memory data directly to the remote machine.
3757 This does not inform the data cache; the data cache uses this.
3758 MEMADDR is the address in the remote memory space.
3759 MYADDR is the address of the buffer in our space.
3760 LEN is the number of bytes.
3762 Returns number of bytes transferred, or 0 (setting errno) for
3763 error. Only transfer a single packet. */
3766 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3769 int max_buf_size
; /* Max size of packet output buffer */
3771 unsigned char *plen
;
3777 /* Verify that the target can support a binary download */
3778 check_binary_download (memaddr
);
3780 /* Determine the max packet size. */
3781 max_buf_size
= get_memory_write_packet_size ();
3782 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3783 buf
= alloca (sizeof_buf
);
3785 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3786 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
3788 /* construct "M"<memaddr>","<len>":" */
3789 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3792 /* Append [XM]. Compute a best guess of the number of bytes
3793 actually transfered. */
3794 switch (remote_protocol_binary_download
.support
)
3798 /* Best guess at number of bytes that will fit. */
3799 todo
= min (len
, max_buf_size
);
3801 case PACKET_DISABLE
:
3803 /* num bytes that will fit */
3804 todo
= min (len
, max_buf_size
/ 2);
3806 case PACKET_SUPPORT_UNKNOWN
:
3807 internal_error (__FILE__
, __LINE__
,
3808 "remote_write_bytes: bad internal state");
3810 internal_error (__FILE__
, __LINE__
, "bad switch");
3813 /* Append <memaddr> */
3814 memaddr
= remote_address_masked (memaddr
);
3815 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3818 /* Append <len>. Retain the location/size of <len>. It may
3819 need to be adjusted once the packet body has been created. */
3821 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3826 /* Append the packet body. */
3827 switch (remote_protocol_binary_download
.support
)
3830 /* Binary mode. Send target system values byte by byte, in
3831 increasing byte addresses. Only escape certain critical
3834 (nr_bytes
< todo
) && (p
- buf
) < (max_buf_size
- 2);
3837 switch (myaddr
[nr_bytes
] & 0xff)
3842 /* These must be escaped */
3844 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3847 *p
++ = myaddr
[nr_bytes
] & 0xff;
3851 if (nr_bytes
< todo
)
3853 /* Escape chars have filled up the buffer prematurely,
3854 and we have actually sent fewer bytes than planned.
3855 Fix-up the length field of the packet. Use the same
3856 number of characters as before. */
3858 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3859 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3862 case PACKET_DISABLE
:
3863 /* Normal mode: Send target system values byte by byte, in
3864 increasing byte addresses. Each byte is encoded as a two hex
3866 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3869 case PACKET_SUPPORT_UNKNOWN
:
3870 internal_error (__FILE__
, __LINE__
,
3871 "remote_write_bytes: bad internal state");
3873 internal_error (__FILE__
, __LINE__
, "bad switch");
3876 putpkt_binary (buf
, (int) (p
- buf
));
3877 getpkt (buf
, sizeof_buf
, 0);
3881 /* There is no correspondance between what the remote protocol
3882 uses for errors and errno codes. We would like a cleaner way
3883 of representing errors (big enough to include errno codes,
3884 bfd_error codes, and others). But for now just return EIO. */
3889 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3890 bytes than we'd planned. */
3894 /* Read memory data directly from the remote machine.
3895 This does not use the data cache; the data cache uses this.
3896 MEMADDR is the address in the remote memory space.
3897 MYADDR is the address of the buffer in our space.
3898 LEN is the number of bytes.
3900 Returns number of bytes transferred, or 0 for error. */
3902 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3903 remote targets) shouldn't attempt to read the entire buffer.
3904 Instead it should read a single packet worth of data and then
3905 return the byte size of that packet to the caller. The caller (its
3906 caller and its callers caller ;-) already contains code for
3907 handling partial reads. */
3910 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3913 int max_buf_size
; /* Max size of packet output buffer */
3917 /* Create a buffer big enough for this packet. */
3918 max_buf_size
= get_memory_read_packet_size ();
3919 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3920 buf
= alloca (sizeof_buf
);
3929 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3931 /* construct "m"<memaddr>","<len>" */
3932 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3933 memaddr
= remote_address_masked (memaddr
);
3936 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3938 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3942 getpkt (buf
, sizeof_buf
, 0);
3945 && isxdigit (buf
[1]) && isxdigit (buf
[2])
3948 /* There is no correspondance between what the remote protocol uses
3949 for errors and errno codes. We would like a cleaner way of
3950 representing errors (big enough to include errno codes, bfd_error
3951 codes, and others). But for now just return EIO. */
3956 /* Reply describes memory byte by byte,
3957 each byte encoded as two hex characters. */
3960 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
3962 /* Reply is short. This means that we were able to read
3963 only part of what we wanted to. */
3964 return i
+ (origlen
- len
);
3973 /* Read or write LEN bytes from inferior memory at MEMADDR,
3974 transferring to or from debugger address BUFFER. Write to inferior if
3975 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3976 for error. TARGET is unused. */
3980 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
3981 int should_write
, struct mem_attrib
*attrib
,
3982 struct target_ops
*target
)
3984 CORE_ADDR targ_addr
;
3988 /* Should this be the selected frame? */
3989 gdbarch_remote_translate_xfer_address (current_gdbarch
, current_regcache
,
3991 &targ_addr
, &targ_len
);
3996 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
3998 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
4005 /* Enable after 4.12. */
4008 remote_search (int len
, char *data
, char *mask
, CORE_ADDR startaddr
,
4009 int increment
, CORE_ADDR lorange
, CORE_ADDR hirange
,
4010 CORE_ADDR
*addr_found
, char *data_found
)
4012 if (increment
== -4 && len
== 4)
4014 long mask_long
, data_long
;
4015 long data_found_long
;
4016 CORE_ADDR addr_we_found
;
4017 char *buf
= alloca (rs
->remote_packet_size
);
4018 long returned_long
[2];
4021 mask_long
= extract_unsigned_integer (mask
, len
);
4022 data_long
= extract_unsigned_integer (data
, len
);
4023 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
4025 getpkt (buf
, (rs
->remote_packet_size
), 0);
4028 /* The stub doesn't support the 't' request. We might want to
4029 remember this fact, but on the other hand the stub could be
4030 switched on us. Maybe we should remember it only until
4031 the next "target remote". */
4032 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
4033 hirange
, addr_found
, data_found
);
4038 /* There is no correspondance between what the remote protocol uses
4039 for errors and errno codes. We would like a cleaner way of
4040 representing errors (big enough to include errno codes, bfd_error
4041 codes, and others). But for now just use EIO. */
4042 memory_error (EIO
, startaddr
);
4045 while (*p
!= '\0' && *p
!= ',')
4046 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
4048 error ("Protocol error: short return for search");
4050 data_found_long
= 0;
4051 while (*p
!= '\0' && *p
!= ',')
4052 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
4053 /* Ignore anything after this comma, for future extensions. */
4055 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
4061 *addr_found
= addr_we_found
;
4062 *data_found
= store_unsigned_integer (data_we_found
, len
);
4065 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
4066 hirange
, addr_found
, data_found
);
4071 remote_files_info (struct target_ops
*ignore
)
4073 puts_filtered ("Debugging a target over a serial line.\n");
4076 /* Stuff for dealing with the packets which are part of this protocol.
4077 See comment at top of file for details. */
4079 /* Read a single character from the remote end, masking it down to 7 bits. */
4082 readchar (int timeout
)
4086 ch
= serial_readchar (remote_desc
, timeout
);
4091 switch ((enum serial_rc
) ch
)
4094 target_mourn_inferior ();
4095 error ("Remote connection closed");
4098 perror_with_name ("Remote communication error");
4100 case SERIAL_TIMEOUT
:
4106 /* Send the command in BUF to the remote machine, and read the reply
4107 into BUF. Report an error if we get an error reply. */
4110 remote_send (char *buf
,
4114 getpkt (buf
, sizeof_buf
, 0);
4117 error ("Remote failure reply: %s", buf
);
4120 /* Display a null-terminated packet on stdout, for debugging, using C
4124 print_packet (char *buf
)
4126 puts_filtered ("\"");
4127 fputstr_filtered (buf
, '"', gdb_stdout
);
4128 puts_filtered ("\"");
4134 return putpkt_binary (buf
, strlen (buf
));
4137 /* Send a packet to the remote machine, with error checking. The data
4138 of the packet is in BUF. The string in BUF can be at most (rs->remote_packet_size) - 5
4139 to account for the $, # and checksum, and for a possible /0 if we are
4140 debugging (remote_debug) and want to print the sent packet as a string */
4143 putpkt_binary (char *buf
, int cnt
)
4145 struct remote_state
*rs
= get_remote_state ();
4147 unsigned char csum
= 0;
4148 char *buf2
= alloca (cnt
+ 6);
4149 long sizeof_junkbuf
= (rs
->remote_packet_size
);
4150 char *junkbuf
= alloca (sizeof_junkbuf
);
4156 /* Copy the packet into buffer BUF2, encapsulating it
4157 and giving it a checksum. */
4162 for (i
= 0; i
< cnt
; i
++)
4168 *p
++ = tohex ((csum
>> 4) & 0xf);
4169 *p
++ = tohex (csum
& 0xf);
4171 /* Send it over and over until we get a positive ack. */
4175 int started_error_output
= 0;
4180 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4181 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4182 fprintf_unfiltered (gdb_stdlog
, "...");
4183 gdb_flush (gdb_stdlog
);
4185 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4186 perror_with_name ("putpkt: write failed");
4188 /* read until either a timeout occurs (-2) or '+' is read */
4191 ch
= readchar (remote_timeout
);
4199 case SERIAL_TIMEOUT
:
4201 if (started_error_output
)
4203 putchar_unfiltered ('\n');
4204 started_error_output
= 0;
4213 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4217 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4218 case SERIAL_TIMEOUT
:
4222 break; /* Retransmit buffer */
4226 fprintf_unfiltered (gdb_stdlog
, "Packet instead of Ack, ignoring it\n");
4227 /* It's probably an old response, and we're out of sync.
4228 Just gobble up the packet and ignore it. */
4229 read_frame (junkbuf
, sizeof_junkbuf
);
4230 continue; /* Now, go look for + */
4235 if (!started_error_output
)
4237 started_error_output
= 1;
4238 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4240 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4244 break; /* Here to retransmit */
4248 /* This is wrong. If doing a long backtrace, the user should be
4249 able to get out next time we call QUIT, without anything as
4250 violent as interrupt_query. If we want to provide a way out of
4251 here without getting to the next QUIT, it should be based on
4252 hitting ^C twice as in remote_wait. */
4262 static int remote_cisco_mode
;
4264 /* Come here after finding the start of the frame. Collect the rest
4265 into BUF, verifying the checksum, length, and handling run-length
4266 compression. No more than sizeof_buf-1 characters are read so that
4267 the buffer can be NUL terminated.
4269 Returns -1 on error, number of characters in buffer (ignoring the
4270 trailing NULL) on success. (could be extended to return one of the
4271 SERIAL status indications). */
4274 read_frame (char *buf
,
4286 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
4287 c
= readchar (remote_timeout
);
4290 case SERIAL_TIMEOUT
:
4292 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4296 fputs_filtered ("Saw new packet start in middle of old one\n",
4298 return -1; /* Start a new packet, count retries */
4301 unsigned char pktcsum
;
4307 check_0
= readchar (remote_timeout
);
4309 check_1
= readchar (remote_timeout
);
4311 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4314 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog
);
4317 else if (check_0
< 0 || check_1
< 0)
4320 fputs_filtered ("Communication error in checksum\n", gdb_stdlog
);
4324 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4325 if (csum
== pktcsum
)
4330 fprintf_filtered (gdb_stdlog
,
4331 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4333 fputs_filtered (buf
, gdb_stdlog
);
4334 fputs_filtered ("\n", gdb_stdlog
);
4336 /* Number of characters in buffer ignoring trailing
4340 case '*': /* Run length encoding */
4345 if (remote_cisco_mode
== 0)
4347 c
= readchar (remote_timeout
);
4349 repeat
= c
- ' ' + 3; /* Compute repeat count */
4353 /* Cisco's run-length encoding variant uses two
4354 hex chars to represent the repeat count. */
4356 c
= readchar (remote_timeout
);
4358 repeat
= fromhex (c
) << 4;
4359 c
= readchar (remote_timeout
);
4361 repeat
+= fromhex (c
);
4364 /* The character before ``*'' is repeated. */
4366 if (repeat
> 0 && repeat
<= 255
4368 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4370 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4376 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
4377 puts_filtered (buf
);
4378 puts_filtered ("\n");
4382 if (bc
< sizeof_buf
- 1)
4390 puts_filtered ("Remote packet too long: ");
4391 puts_filtered (buf
);
4392 puts_filtered ("\n");
4399 /* Read a packet from the remote machine, with error checking, and
4400 store it in BUF. If FOREVER, wait forever rather than timing out;
4401 this is used (in synchronous mode) to wait for a target that is is
4402 executing user code to stop. */
4403 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4404 don't have to change all the calls to getpkt to deal with the
4405 return value, because at the moment I don't know what the right
4406 thing to do it for those. */
4414 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4418 /* Read a packet from the remote machine, with error checking, and
4419 store it in BUF. If FOREVER, wait forever rather than timing out;
4420 this is used (in synchronous mode) to wait for a target that is is
4421 executing user code to stop. If FOREVER == 0, this function is
4422 allowed to time out gracefully and return an indication of this to
4425 getpkt_sane (char *buf
,
4434 strcpy (buf
, "timeout");
4438 timeout
= watchdog
> 0 ? watchdog
: -1;
4442 timeout
= remote_timeout
;
4446 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4448 /* This can loop forever if the remote side sends us characters
4449 continuously, but if it pauses, we'll get a zero from readchar
4450 because of timeout. Then we'll count that as a retry. */
4452 /* Note that we will only wait forever prior to the start of a packet.
4453 After that, we expect characters to arrive at a brisk pace. They
4454 should show up within remote_timeout intervals. */
4458 c
= readchar (timeout
);
4460 if (c
== SERIAL_TIMEOUT
)
4462 if (forever
) /* Watchdog went off? Kill the target. */
4465 target_mourn_inferior ();
4466 error ("Watchdog has expired. Target detached.\n");
4469 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4475 /* We've found the start of a packet, now collect the data. */
4477 val
= read_frame (buf
, sizeof_buf
);
4483 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4484 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4485 fprintf_unfiltered (gdb_stdlog
, "\n");
4487 serial_write (remote_desc
, "+", 1);
4491 /* Try the whole thing again. */
4493 serial_write (remote_desc
, "-", 1);
4496 /* We have tried hard enough, and just can't receive the packet. Give up. */
4498 printf_unfiltered ("Ignoring packet error, continuing...\n");
4499 serial_write (remote_desc
, "+", 1);
4506 /* For some mysterious reason, wait_for_inferior calls kill instead of
4507 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4511 target_mourn_inferior ();
4515 /* Use catch_errors so the user can quit from gdb even when we aren't on
4516 speaking terms with the remote system. */
4517 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4519 /* Don't wait for it to die. I'm not really sure it matters whether
4520 we do or not. For the existing stubs, kill is a noop. */
4521 target_mourn_inferior ();
4524 /* Async version of remote_kill. */
4526 remote_async_kill (void)
4528 /* Unregister the file descriptor from the event loop. */
4529 if (target_is_async_p ())
4530 serial_async (remote_desc
, NULL
, 0);
4532 /* For some mysterious reason, wait_for_inferior calls kill instead of
4533 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4537 target_mourn_inferior ();
4541 /* Use catch_errors so the user can quit from gdb even when we aren't on
4542 speaking terms with the remote system. */
4543 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4545 /* Don't wait for it to die. I'm not really sure it matters whether
4546 we do or not. For the existing stubs, kill is a noop. */
4547 target_mourn_inferior ();
4553 remote_mourn_1 (&remote_ops
);
4557 remote_async_mourn (void)
4559 remote_mourn_1 (&remote_async_ops
);
4563 extended_remote_mourn (void)
4565 /* We do _not_ want to mourn the target like this; this will
4566 remove the extended remote target from the target stack,
4567 and the next time the user says "run" it'll fail.
4569 FIXME: What is the right thing to do here? */
4571 remote_mourn_1 (&extended_remote_ops
);
4575 /* Worker function for remote_mourn. */
4577 remote_mourn_1 (struct target_ops
*target
)
4579 unpush_target (target
);
4580 generic_mourn_inferior ();
4583 /* In the extended protocol we want to be able to do things like
4584 "run" and have them basically work as expected. So we need
4585 a special create_inferior function.
4587 FIXME: One day add support for changing the exec file
4588 we're debugging, arguments and an environment. */
4591 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
)
4593 /* Rip out the breakpoints; we'll reinsert them after restarting
4594 the remote server. */
4595 remove_breakpoints ();
4597 /* Now restart the remote server. */
4598 extended_remote_restart ();
4600 /* Now put the breakpoints back in. This way we're safe if the
4601 restart function works via a unix fork on the remote side. */
4602 insert_breakpoints ();
4604 /* Clean up from the last time we were running. */
4605 clear_proceed_status ();
4607 /* Let the remote process run. */
4608 proceed (-1, TARGET_SIGNAL_0
, 0);
4611 /* Async version of extended_remote_create_inferior. */
4613 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
)
4615 /* Rip out the breakpoints; we'll reinsert them after restarting
4616 the remote server. */
4617 remove_breakpoints ();
4619 /* If running asynchronously, register the target file descriptor
4620 with the event loop. */
4621 if (event_loop_p
&& target_can_async_p ())
4622 target_async (inferior_event_handler
, 0);
4624 /* Now restart the remote server. */
4625 extended_remote_restart ();
4627 /* Now put the breakpoints back in. This way we're safe if the
4628 restart function works via a unix fork on the remote side. */
4629 insert_breakpoints ();
4631 /* Clean up from the last time we were running. */
4632 clear_proceed_status ();
4634 /* Let the remote process run. */
4635 proceed (-1, TARGET_SIGNAL_0
, 0);
4639 /* On some machines, e.g. 68k, we may use a different breakpoint
4640 instruction than other targets; in those use
4641 DEPRECATED_REMOTE_BREAKPOINT instead of just BREAKPOINT_FROM_PC.
4642 Also, bi-endian targets may define
4643 DEPRECATED_LITTLE_REMOTE_BREAKPOINT and
4644 DEPRECATED_BIG_REMOTE_BREAKPOINT. If none of these are defined, we
4645 just call the standard routines that are in mem-break.c. */
4647 /* NOTE: cagney/2003-06-08: This is silly. A remote and simulator
4648 target should use an identical BREAKPOINT_FROM_PC. As for native,
4649 the ARCH-OS-tdep.c code can override the default. */
4651 #if defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) && !defined(DEPRECATED_REMOTE_BREAKPOINT)
4652 #define DEPRECATED_REMOTE_BREAKPOINT
4655 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4657 /* If the target isn't bi-endian, just pretend it is. */
4658 #if !defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && !defined (DEPRECATED_BIG_REMOTE_BREAKPOINT)
4659 #define DEPRECATED_LITTLE_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4660 #define DEPRECATED_BIG_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4663 static unsigned char big_break_insn
[] = DEPRECATED_BIG_REMOTE_BREAKPOINT
;
4664 static unsigned char little_break_insn
[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT
;
4666 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4668 /* Insert a breakpoint on targets that don't have any better
4669 breakpoint support. We read the contents of the target location
4670 and stash it, then overwrite it with a breakpoint instruction.
4671 ADDR is the target location in the target machine. CONTENTS_CACHE
4672 is a pointer to memory allocated for saving the target contents.
4673 It is guaranteed by the caller to be long enough to save the number
4674 of bytes returned by BREAKPOINT_FROM_PC. */
4677 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4679 struct remote_state
*rs
= get_remote_state ();
4680 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4685 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4686 If it succeeds, then set the support to PACKET_ENABLE. If it
4687 fails, and the user has explicitly requested the Z support then
4688 report an error, otherwise, mark it disabled and go on. */
4690 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4692 char *buf
= alloca (rs
->remote_packet_size
);
4695 addr
= remote_address_masked (addr
);
4699 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4700 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4701 sprintf (p
, ",%d", bp_size
);
4704 getpkt (buf
, (rs
->remote_packet_size
), 0);
4706 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4712 case PACKET_UNKNOWN
:
4717 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4718 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4722 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4723 val
= target_write_memory (addr
, (char *) big_break_insn
,
4724 sizeof big_break_insn
);
4726 val
= target_write_memory (addr
, (char *) little_break_insn
,
4727 sizeof little_break_insn
);
4732 return memory_insert_breakpoint (addr
, contents_cache
);
4733 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4737 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4739 struct remote_state
*rs
= get_remote_state ();
4742 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4744 char *buf
= alloca (rs
->remote_packet_size
);
4751 addr
= remote_address_masked (addr
);
4752 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4753 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4754 sprintf (p
, ",%d", bp_size
);
4757 getpkt (buf
, (rs
->remote_packet_size
), 0);
4759 return (buf
[0] == 'E');
4762 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4763 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4765 return memory_remove_breakpoint (addr
, contents_cache
);
4766 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4770 watchpoint_to_Z_packet (int type
)
4784 internal_error (__FILE__
, __LINE__
,
4785 "hw_bp_to_z: bad watchpoint type %d", type
);
4790 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4792 struct remote_state
*rs
= get_remote_state ();
4793 char *buf
= alloca (rs
->remote_packet_size
);
4795 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4797 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4798 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4799 remote_protocol_Z
[packet
].name
,
4800 remote_protocol_Z
[packet
].title
);
4802 sprintf (buf
, "Z%x,", packet
);
4803 p
= strchr (buf
, '\0');
4804 addr
= remote_address_masked (addr
);
4805 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4806 sprintf (p
, ",%x", len
);
4809 getpkt (buf
, (rs
->remote_packet_size
), 0);
4811 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4814 case PACKET_UNKNOWN
:
4819 internal_error (__FILE__
, __LINE__
,
4820 "remote_insert_watchpoint: reached end of function");
4825 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4827 struct remote_state
*rs
= get_remote_state ();
4828 char *buf
= alloca (rs
->remote_packet_size
);
4830 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4832 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4833 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4834 remote_protocol_Z
[packet
].name
,
4835 remote_protocol_Z
[packet
].title
);
4837 sprintf (buf
, "z%x,", packet
);
4838 p
= strchr (buf
, '\0');
4839 addr
= remote_address_masked (addr
);
4840 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4841 sprintf (p
, ",%x", len
);
4843 getpkt (buf
, (rs
->remote_packet_size
), 0);
4845 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4848 case PACKET_UNKNOWN
:
4853 internal_error (__FILE__
, __LINE__
,
4854 "remote_remove_watchpoint: reached end of function");
4858 int remote_hw_watchpoint_limit
= -1;
4859 int remote_hw_breakpoint_limit
= -1;
4862 remote_check_watch_resources (int type
, int cnt
, int ot
)
4864 if (type
== bp_hardware_breakpoint
)
4866 if (remote_hw_breakpoint_limit
== 0)
4868 else if (remote_hw_breakpoint_limit
< 0)
4870 else if (cnt
<= remote_hw_breakpoint_limit
)
4875 if (remote_hw_watchpoint_limit
== 0)
4877 else if (remote_hw_watchpoint_limit
< 0)
4881 else if (cnt
<= remote_hw_watchpoint_limit
)
4888 remote_stopped_by_watchpoint (void)
4890 return remote_stopped_by_watchpoint_p
;
4894 remote_stopped_data_address (void)
4896 if (remote_stopped_by_watchpoint ())
4897 return remote_watch_data_address
;
4898 return (CORE_ADDR
)0;
4903 remote_insert_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4906 struct remote_state
*rs
= get_remote_state ();
4907 char *buf
= alloca (rs
->remote_packet_size
);
4910 /* The length field should be set to the size of a breakpoint
4913 BREAKPOINT_FROM_PC (&addr
, &len
);
4915 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4916 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4917 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4918 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4924 addr
= remote_address_masked (addr
);
4925 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4926 sprintf (p
, ",%x", len
);
4929 getpkt (buf
, (rs
->remote_packet_size
), 0);
4931 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4934 case PACKET_UNKNOWN
:
4939 internal_error (__FILE__
, __LINE__
,
4940 "remote_insert_hw_breakpoint: reached end of function");
4945 remote_remove_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4948 struct remote_state
*rs
= get_remote_state ();
4949 char *buf
= alloca (rs
->remote_packet_size
);
4952 /* The length field should be set to the size of a breakpoint
4955 BREAKPOINT_FROM_PC (&addr
, &len
);
4957 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4958 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
4959 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4960 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4966 addr
= remote_address_masked (addr
);
4967 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4968 sprintf (p
, ",%x", len
);
4971 getpkt (buf
, (rs
->remote_packet_size
), 0);
4973 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4976 case PACKET_UNKNOWN
:
4981 internal_error (__FILE__
, __LINE__
,
4982 "remote_remove_hw_breakpoint: reached end of function");
4985 /* Some targets are only capable of doing downloads, and afterwards
4986 they switch to the remote serial protocol. This function provides
4987 a clean way to get from the download target to the remote target.
4988 It's basically just a wrapper so that we don't have to expose any
4989 of the internal workings of remote.c.
4991 Prior to calling this routine, you should shutdown the current
4992 target code, else you will get the "A program is being debugged
4993 already..." message. Usually a call to pop_target() suffices. */
4996 push_remote_target (char *name
, int from_tty
)
4998 printf_filtered ("Switching to remote protocol\n");
4999 remote_open (name
, from_tty
);
5002 /* Table used by the crc32 function to calcuate the checksum. */
5004 static unsigned long crc32_table
[256] =
5007 static unsigned long
5008 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
5010 if (!crc32_table
[1])
5012 /* Initialize the CRC table and the decoding table. */
5016 for (i
= 0; i
< 256; i
++)
5018 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
5019 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
5026 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
5032 /* compare-sections command
5034 With no arguments, compares each loadable section in the exec bfd
5035 with the same memory range on the target, and reports mismatches.
5036 Useful for verifying the image on the target against the exec file.
5037 Depends on the target understanding the new "qCRC:" request. */
5039 /* FIXME: cagney/1999-10-26: This command should be broken down into a
5040 target method (target verify memory) and generic version of the
5041 actual command. This will allow other high-level code (especially
5042 generic_load()) to make use of this target functionality. */
5045 compare_sections_command (char *args
, int from_tty
)
5047 struct remote_state
*rs
= get_remote_state ();
5049 unsigned long host_crc
, target_crc
;
5050 extern bfd
*exec_bfd
;
5051 struct cleanup
*old_chain
;
5054 const char *sectname
;
5055 char *buf
= alloca (rs
->remote_packet_size
);
5062 error ("command cannot be used without an exec file");
5063 if (!current_target
.to_shortname
||
5064 strcmp (current_target
.to_shortname
, "remote") != 0)
5065 error ("command can only be used with remote target");
5067 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
5069 if (!(s
->flags
& SEC_LOAD
))
5070 continue; /* skip non-loadable section */
5072 size
= bfd_get_section_size_before_reloc (s
);
5074 continue; /* skip zero-length section */
5076 sectname
= bfd_get_section_name (exec_bfd
, s
);
5077 if (args
&& strcmp (args
, sectname
) != 0)
5078 continue; /* not the section selected by user */
5080 matched
= 1; /* do this section */
5082 /* FIXME: assumes lma can fit into long */
5083 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
5086 /* be clever; compute the host_crc before waiting for target reply */
5087 sectdata
= xmalloc (size
);
5088 old_chain
= make_cleanup (xfree
, sectdata
);
5089 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
5090 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
5092 getpkt (buf
, (rs
->remote_packet_size
), 0);
5094 error ("target memory fault, section %s, range 0x%s -- 0x%s",
5095 sectname
, paddr (lma
), paddr (lma
+ size
));
5097 error ("remote target does not support this operation");
5099 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
5100 target_crc
= target_crc
* 16 + fromhex (*tmp
);
5102 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
5103 sectname
, paddr (lma
), paddr (lma
+ size
));
5104 if (host_crc
== target_crc
)
5105 printf_filtered ("matched.\n");
5108 printf_filtered ("MIS-MATCHED!\n");
5112 do_cleanups (old_chain
);
5115 warning ("One or more sections of the remote executable does not match\n\
5116 the loaded file\n");
5117 if (args
&& !matched
)
5118 printf_filtered ("No loaded section named '%s'.\n", args
);
5122 remote_query (int query_type
, char *buf
, char *outbuf
, int *bufsiz
)
5124 struct remote_state
*rs
= get_remote_state ();
5126 char *buf2
= alloca (rs
->remote_packet_size
);
5127 char *p2
= &buf2
[0];
5130 error ("null pointer to remote bufer size specified");
5132 /* minimum outbuf size is (rs->remote_packet_size) - if bufsiz is not large enough let
5133 the caller know and return what the minimum size is */
5134 /* Note: a zero bufsiz can be used to query the minimum buffer size */
5135 if (*bufsiz
< (rs
->remote_packet_size
))
5137 *bufsiz
= (rs
->remote_packet_size
);
5141 /* except for querying the minimum buffer size, target must be open */
5143 error ("remote query is only available after target open");
5145 /* we only take uppercase letters as query types, at least for now */
5146 if ((query_type
< 'A') || (query_type
> 'Z'))
5147 error ("invalid remote query type");
5150 error ("null remote query specified");
5153 error ("remote query requires a buffer to receive data");
5160 /* we used one buffer char for the remote protocol q command and another
5161 for the query type. As the remote protocol encapsulation uses 4 chars
5162 plus one extra in case we are debugging (remote_debug),
5163 we have PBUFZIZ - 7 left to pack the query string */
5165 while (buf
[i
] && (i
< ((rs
->remote_packet_size
) - 8)))
5167 /* bad caller may have sent forbidden characters */
5168 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
5169 error ("illegal characters in query string");
5177 error ("query larger than available buffer");
5183 getpkt (outbuf
, *bufsiz
, 0);
5189 remote_rcmd (char *command
,
5190 struct ui_file
*outbuf
)
5192 struct remote_state
*rs
= get_remote_state ();
5194 char *buf
= alloca (rs
->remote_packet_size
);
5198 error ("remote rcmd is only available after target open");
5200 /* Send a NULL command across as an empty command */
5201 if (command
== NULL
)
5204 /* The query prefix */
5205 strcpy (buf
, "qRcmd,");
5206 p
= strchr (buf
, '\0');
5208 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > (rs
->remote_packet_size
))
5209 error ("\"monitor\" command ``%s'' is too long\n", command
);
5211 /* Encode the actual command */
5212 bin2hex (command
, p
, 0);
5214 if (putpkt (buf
) < 0)
5215 error ("Communication problem with target\n");
5217 /* get/display the response */
5220 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
5222 getpkt (buf
, (rs
->remote_packet_size
), 0);
5224 error ("Target does not support this command\n");
5225 if (buf
[0] == 'O' && buf
[1] != 'K')
5227 remote_console_output (buf
+ 1); /* 'O' message from stub */
5230 if (strcmp (buf
, "OK") == 0)
5232 if (strlen (buf
) == 3 && buf
[0] == 'E'
5233 && isdigit (buf
[1]) && isdigit (buf
[2]))
5235 error ("Protocol error with Rcmd");
5237 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5239 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5240 fputc_unfiltered (c
, outbuf
);
5247 packet_command (char *args
, int from_tty
)
5249 struct remote_state
*rs
= get_remote_state ();
5250 char *buf
= alloca (rs
->remote_packet_size
);
5253 error ("command can only be used with remote target");
5256 error ("remote-packet command requires packet text as argument");
5258 puts_filtered ("sending: ");
5259 print_packet (args
);
5260 puts_filtered ("\n");
5263 getpkt (buf
, (rs
->remote_packet_size
), 0);
5264 puts_filtered ("received: ");
5266 puts_filtered ("\n");
5270 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
5272 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5274 static void threadset_test_cmd (char *cmd
, int tty
);
5276 static void threadalive_test (char *cmd
, int tty
);
5278 static void threadlist_test_cmd (char *cmd
, int tty
);
5280 int get_and_display_threadinfo (threadref
* ref
);
5282 static void threadinfo_test_cmd (char *cmd
, int tty
);
5284 static int thread_display_step (threadref
* ref
, void *context
);
5286 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5288 static void init_remote_threadtests (void);
5290 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
5293 threadset_test_cmd (char *cmd
, int tty
)
5295 int sample_thread
= SAMPLE_THREAD
;
5297 printf_filtered ("Remote threadset test\n");
5298 set_thread (sample_thread
, 1);
5303 threadalive_test (char *cmd
, int tty
)
5305 int sample_thread
= SAMPLE_THREAD
;
5307 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5308 printf_filtered ("PASS: Thread alive test\n");
5310 printf_filtered ("FAIL: Thread alive test\n");
5313 void output_threadid (char *title
, threadref
* ref
);
5316 output_threadid (char *title
, threadref
*ref
)
5320 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
5322 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5326 threadlist_test_cmd (char *cmd
, int tty
)
5329 threadref nextthread
;
5330 int done
, result_count
;
5331 threadref threadlist
[3];
5333 printf_filtered ("Remote Threadlist test\n");
5334 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5335 &result_count
, &threadlist
[0]))
5336 printf_filtered ("FAIL: threadlist test\n");
5339 threadref
*scan
= threadlist
;
5340 threadref
*limit
= scan
+ result_count
;
5342 while (scan
< limit
)
5343 output_threadid (" thread ", scan
++);
5348 display_thread_info (struct gdb_ext_thread_info
*info
)
5350 output_threadid ("Threadid: ", &info
->threadid
);
5351 printf_filtered ("Name: %s\n ", info
->shortname
);
5352 printf_filtered ("State: %s\n", info
->display
);
5353 printf_filtered ("other: %s\n\n", info
->more_display
);
5357 get_and_display_threadinfo (threadref
*ref
)
5361 struct gdb_ext_thread_info threadinfo
;
5363 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5364 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5365 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5366 display_thread_info (&threadinfo
);
5371 threadinfo_test_cmd (char *cmd
, int tty
)
5373 int athread
= SAMPLE_THREAD
;
5377 int_to_threadref (&thread
, athread
);
5378 printf_filtered ("Remote Threadinfo test\n");
5379 if (!get_and_display_threadinfo (&thread
))
5380 printf_filtered ("FAIL cannot get thread info\n");
5384 thread_display_step (threadref
*ref
, void *context
)
5386 /* output_threadid(" threadstep ",ref); *//* simple test */
5387 return get_and_display_threadinfo (ref
);
5391 threadlist_update_test_cmd (char *cmd
, int tty
)
5393 printf_filtered ("Remote Threadlist update test\n");
5394 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5398 init_remote_threadtests (void)
5400 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
5401 "Fetch and print the remote list of thread identifiers, one pkt only");
5402 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5403 "Fetch and display info about one thread");
5404 add_com ("tset", class_obscure
, threadset_test_cmd
,
5405 "Test setting to a different thread");
5406 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5407 "Iterate through updating all remote thread info");
5408 add_com ("talive", class_obscure
, threadalive_test
,
5409 " Remote thread alive test ");
5414 /* Convert a thread ID to a string. Returns the string in a static
5418 remote_pid_to_str (ptid_t ptid
)
5420 static char buf
[30];
5422 sprintf (buf
, "Thread %d", PIDGET (ptid
));
5427 init_remote_ops (void)
5429 remote_ops
.to_shortname
= "remote";
5430 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5432 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5433 Specify the serial device it is connected to\n\
5434 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5435 remote_ops
.to_open
= remote_open
;
5436 remote_ops
.to_close
= remote_close
;
5437 remote_ops
.to_detach
= remote_detach
;
5438 remote_ops
.to_resume
= remote_resume
;
5439 remote_ops
.to_wait
= remote_wait
;
5440 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5441 remote_ops
.to_store_registers
= remote_store_registers
;
5442 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5443 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
5444 remote_ops
.to_files_info
= remote_files_info
;
5445 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5446 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5447 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5448 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5449 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5450 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5451 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5452 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5453 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5454 remote_ops
.to_kill
= remote_kill
;
5455 remote_ops
.to_load
= generic_load
;
5456 remote_ops
.to_mourn_inferior
= remote_mourn
;
5457 remote_ops
.to_thread_alive
= remote_thread_alive
;
5458 remote_ops
.to_find_new_threads
= remote_threads_info
;
5459 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5460 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5461 remote_ops
.to_stop
= remote_stop
;
5462 remote_ops
.to_query
= remote_query
;
5463 remote_ops
.to_rcmd
= remote_rcmd
;
5464 remote_ops
.to_stratum
= process_stratum
;
5465 remote_ops
.to_has_all_memory
= 1;
5466 remote_ops
.to_has_memory
= 1;
5467 remote_ops
.to_has_stack
= 1;
5468 remote_ops
.to_has_registers
= 1;
5469 remote_ops
.to_has_execution
= 1;
5470 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5471 remote_ops
.to_magic
= OPS_MAGIC
;
5474 /* Set up the extended remote vector by making a copy of the standard
5475 remote vector and adding to it. */
5478 init_extended_remote_ops (void)
5480 extended_remote_ops
= remote_ops
;
5482 extended_remote_ops
.to_shortname
= "extended-remote";
5483 extended_remote_ops
.to_longname
=
5484 "Extended remote serial target in gdb-specific protocol";
5485 extended_remote_ops
.to_doc
=
5486 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5487 Specify the serial device it is connected to (e.g. /dev/ttya).",
5488 extended_remote_ops
.to_open
= extended_remote_open
;
5489 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5490 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5494 * Command: info remote-process
5496 * This implements Cisco's version of the "info proc" command.
5498 * This query allows the target stub to return an arbitrary string
5499 * (or strings) giving arbitrary information about the target process.
5500 * This is optional; the target stub isn't required to implement it.
5502 * Syntax: qfProcessInfo request first string
5503 * qsProcessInfo request subsequent string
5504 * reply: 'O'<hex-encoded-string>
5505 * 'l' last reply (empty)
5509 remote_info_process (char *args
, int from_tty
)
5511 struct remote_state
*rs
= get_remote_state ();
5512 char *buf
= alloca (rs
->remote_packet_size
);
5514 if (remote_desc
== 0)
5515 error ("Command can only be used when connected to the remote target.");
5517 putpkt ("qfProcessInfo");
5518 getpkt (buf
, (rs
->remote_packet_size
), 0);
5520 return; /* Silently: target does not support this feature. */
5523 error ("info proc: target error.");
5525 while (buf
[0] == 'O') /* Capitol-O packet */
5527 remote_console_output (&buf
[1]);
5528 putpkt ("qsProcessInfo");
5529 getpkt (buf
, (rs
->remote_packet_size
), 0);
5538 remote_cisco_open (char *name
, int from_tty
)
5542 error ("To open a remote debug connection, you need to specify what \n"
5543 "device is attached to the remote system (e.g. host:port).");
5545 /* See FIXME above */
5546 wait_forever_enabled_p
= 1;
5548 target_preopen (from_tty
);
5550 unpush_target (&remote_cisco_ops
);
5552 remote_desc
= remote_serial_open (name
);
5554 perror_with_name (name
);
5557 * If a baud rate was specified on the gdb command line it will
5558 * be greater than the initial value of -1. If it is, use it otherwise
5562 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
5563 if (serial_setbaudrate (remote_desc
, baud_rate
))
5565 serial_close (remote_desc
);
5566 perror_with_name (name
);
5569 serial_raw (remote_desc
);
5571 /* If there is something sitting in the buffer we might take it as a
5572 response to a command, which would be bad. */
5573 serial_flush_input (remote_desc
);
5577 puts_filtered ("Remote debugging using ");
5578 puts_filtered (name
);
5579 puts_filtered ("\n");
5582 remote_cisco_mode
= 1;
5584 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
5586 init_all_packet_configs ();
5588 general_thread
= -2;
5589 continue_thread
= -2;
5591 /* Probe for ability to use "ThreadInfo" query, as required. */
5592 use_threadinfo_query
= 1;
5593 use_threadextra_query
= 1;
5595 /* Without this, some commands which require an active target (such
5596 as kill) won't work. This variable serves (at least) double duty
5597 as both the pid of the target process (if it has such), and as a
5598 flag indicating that a target is active. These functions should
5599 be split out into seperate variables, especially since GDB will
5600 someday have a notion of debugging several processes. */
5601 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
5603 /* Start the remote connection; if error, discard this target. See
5604 the comments in remote_open_1() for further details such as the
5605 need to re-throw the exception. */
5606 ex
= catch_exceptions (uiout
,
5607 remote_start_remote_dummy
, NULL
,
5608 "Couldn't establish connection to remote"
5614 throw_exception (ex
);
5619 remote_cisco_close (int quitting
)
5621 remote_cisco_mode
= 0;
5622 remote_close (quitting
);
5626 remote_cisco_mourn (void)
5628 remote_mourn_1 (&remote_cisco_ops
);
5640 /* Shared between readsocket() and readtty(). The size is arbitrary,
5641 however all targets are known to support a 400 character packet. */
5642 static char tty_input
[400];
5644 static int escape_count
;
5645 static int echo_check
;
5646 extern int quit_flag
;
5653 /* Loop until the socket doesn't have any more data */
5655 while ((data
= readchar (0)) >= 0)
5657 /* Check for the escape sequence */
5660 /* If this is the fourth escape, get out */
5661 if (++escape_count
== 4)
5666 { /* This is a '|', but not the fourth in a row.
5667 Continue without echoing it. If it isn't actually
5668 one of four in a row, it'll be echoed later. */
5675 /* Ensure any pending '|'s are flushed. */
5677 for (; escape_count
> 0; escape_count
--)
5681 if (data
== '\r') /* If this is a return character, */
5682 continue; /* - just supress it. */
5684 if (echo_check
!= -1) /* Check for echo of user input. */
5686 if (tty_input
[echo_check
] == data
)
5688 gdb_assert (echo_check
<= sizeof (tty_input
));
5689 echo_check
++; /* Character matched user input: */
5690 continue; /* Continue without echoing it. */
5692 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5693 { /* End of the line (and of echo checking). */
5694 echo_check
= -1; /* No more echo supression */
5695 continue; /* Continue without echoing. */
5698 { /* Failed check for echo of user input.
5699 We now have some suppressed output to flush! */
5702 for (j
= 0; j
< echo_check
; j
++)
5703 putchar (tty_input
[j
]);
5707 putchar (data
); /* Default case: output the char. */
5710 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5711 return READ_MORE
; /* Try to read some more */
5713 return FATAL_ERROR
; /* Trouble, bail out */
5721 /* First, read a buffer full from the terminal */
5722 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5723 if (tty_bytecount
== -1)
5725 perror ("readtty: read failed");
5729 /* Remove a quoted newline. */
5730 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5731 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5733 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5734 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5737 /* Turn trailing newlines into returns */
5738 if (tty_input
[tty_bytecount
- 1] == '\n')
5739 tty_input
[tty_bytecount
- 1] = '\r';
5741 /* If the line consists of a ~, enter debugging mode. */
5742 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5745 /* Make this a zero terminated string and write it out */
5746 tty_input
[tty_bytecount
] = 0;
5747 if (serial_write (remote_desc
, tty_input
, tty_bytecount
))
5749 perror_with_name ("readtty: write failed");
5759 fd_set input
; /* file descriptors for select */
5760 int tablesize
; /* max number of FDs for select */
5767 tablesize
= 8 * sizeof (input
);
5771 /* Check for anything from our socket - doesn't block. Note that
5772 this must be done *before* the select as there may be
5773 buffered I/O waiting to be processed. */
5775 if ((status
= readsocket ()) == FATAL_ERROR
)
5777 error ("Debugging terminated by communications error");
5779 else if (status
!= READ_MORE
)
5784 fflush (stdout
); /* Flush output before blocking */
5786 /* Now block on more socket input or TTY input */
5789 FD_SET (fileno (stdin
), &input
);
5790 FD_SET (deprecated_serial_fd (remote_desc
), &input
);
5792 status
= select (tablesize
, &input
, 0, 0, 0);
5793 if ((status
== -1) && (errno
!= EINTR
))
5795 error ("Communications error on select %d", errno
);
5798 /* Handle Control-C typed */
5802 if ((++quit_count
) == 2)
5804 if (query ("Interrupt GDB? "))
5806 printf_filtered ("Interrupted by user.\n");
5807 throw_exception (RETURN_QUIT
);
5814 serial_send_break (remote_desc
);
5816 serial_write (remote_desc
, "\003", 1);
5821 /* Handle console input */
5823 if (FD_ISSET (fileno (stdin
), &input
))
5827 status
= readtty ();
5828 if (status
== READ_MORE
)
5831 return status
; /* telnet session ended */
5837 remote_cisco_wait (ptid_t ptid
, struct target_waitstatus
*status
)
5839 if (minitelnet () != ENTER_DEBUG
)
5841 error ("Debugging session terminated by protocol error");
5844 return remote_wait (ptid
, status
);
5848 init_remote_cisco_ops (void)
5850 remote_cisco_ops
.to_shortname
= "cisco";
5851 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5852 remote_cisco_ops
.to_doc
=
5853 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5854 Specify the serial device it is connected to (e.g. host:2020).";
5855 remote_cisco_ops
.to_open
= remote_cisco_open
;
5856 remote_cisco_ops
.to_close
= remote_cisco_close
;
5857 remote_cisco_ops
.to_detach
= remote_detach
;
5858 remote_cisco_ops
.to_resume
= remote_resume
;
5859 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5860 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5861 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5862 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5863 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5864 remote_cisco_ops
.to_files_info
= remote_files_info
;
5865 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5866 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5867 remote_cisco_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5868 remote_cisco_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5869 remote_cisco_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5870 remote_cisco_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5871 remote_cisco_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5872 remote_cisco_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5873 remote_cisco_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5874 remote_cisco_ops
.to_kill
= remote_kill
;
5875 remote_cisco_ops
.to_load
= generic_load
;
5876 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5877 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5878 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5879 remote_cisco_ops
.to_pid_to_str
= remote_pid_to_str
;
5880 remote_cisco_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5881 remote_cisco_ops
.to_stratum
= process_stratum
;
5882 remote_cisco_ops
.to_has_all_memory
= 1;
5883 remote_cisco_ops
.to_has_memory
= 1;
5884 remote_cisco_ops
.to_has_stack
= 1;
5885 remote_cisco_ops
.to_has_registers
= 1;
5886 remote_cisco_ops
.to_has_execution
= 1;
5887 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5891 remote_can_async_p (void)
5893 /* We're async whenever the serial device is. */
5894 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5898 remote_is_async_p (void)
5900 /* We're async whenever the serial device is. */
5901 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5904 /* Pass the SERIAL event on and up to the client. One day this code
5905 will be able to delay notifying the client of an event until the
5906 point where an entire packet has been received. */
5908 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5909 static void *async_client_context
;
5910 static serial_event_ftype remote_async_serial_handler
;
5913 remote_async_serial_handler (struct serial
*scb
, void *context
)
5915 /* Don't propogate error information up to the client. Instead let
5916 the client find out about the error by querying the target. */
5917 async_client_callback (INF_REG_EVENT
, async_client_context
);
5921 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5923 if (current_target
.to_async_mask_value
== 0)
5924 internal_error (__FILE__
, __LINE__
,
5925 "Calling remote_async when async is masked");
5927 if (callback
!= NULL
)
5929 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5930 async_client_callback
= callback
;
5931 async_client_context
= context
;
5934 serial_async (remote_desc
, NULL
, NULL
);
5937 /* Target async and target extended-async.
5939 This are temporary targets, until it is all tested. Eventually
5940 async support will be incorporated int the usual 'remote'
5944 init_remote_async_ops (void)
5946 remote_async_ops
.to_shortname
= "async";
5947 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5948 remote_async_ops
.to_doc
=
5949 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5950 Specify the serial device it is connected to (e.g. /dev/ttya).";
5951 remote_async_ops
.to_open
= remote_async_open
;
5952 remote_async_ops
.to_close
= remote_close
;
5953 remote_async_ops
.to_detach
= remote_async_detach
;
5954 remote_async_ops
.to_resume
= remote_async_resume
;
5955 remote_async_ops
.to_wait
= remote_async_wait
;
5956 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5957 remote_async_ops
.to_store_registers
= remote_store_registers
;
5958 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5959 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5960 remote_async_ops
.to_files_info
= remote_files_info
;
5961 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5962 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5963 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5964 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5965 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5966 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5967 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5968 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5969 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5970 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5971 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5972 remote_async_ops
.to_kill
= remote_async_kill
;
5973 remote_async_ops
.to_load
= generic_load
;
5974 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5975 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5976 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5977 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
5978 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5979 remote_async_ops
.to_stop
= remote_stop
;
5980 remote_async_ops
.to_query
= remote_query
;
5981 remote_async_ops
.to_rcmd
= remote_rcmd
;
5982 remote_async_ops
.to_stratum
= process_stratum
;
5983 remote_async_ops
.to_has_all_memory
= 1;
5984 remote_async_ops
.to_has_memory
= 1;
5985 remote_async_ops
.to_has_stack
= 1;
5986 remote_async_ops
.to_has_registers
= 1;
5987 remote_async_ops
.to_has_execution
= 1;
5988 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5989 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5990 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5991 remote_async_ops
.to_async
= remote_async
;
5992 remote_async_ops
.to_async_mask_value
= 1;
5993 remote_async_ops
.to_magic
= OPS_MAGIC
;
5996 /* Set up the async extended remote vector by making a copy of the standard
5997 remote vector and adding to it. */
6000 init_extended_async_remote_ops (void)
6002 extended_async_remote_ops
= remote_async_ops
;
6004 extended_async_remote_ops
.to_shortname
= "extended-async";
6005 extended_async_remote_ops
.to_longname
=
6006 "Extended remote serial target in async gdb-specific protocol";
6007 extended_async_remote_ops
.to_doc
=
6008 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
6009 Specify the serial device it is connected to (e.g. /dev/ttya).",
6010 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
6011 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
6012 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
6016 set_remote_cmd (char *args
, int from_tty
)
6021 show_remote_cmd (char *args
, int from_tty
)
6023 /* FIXME: cagney/2002-06-15: This function should iterate over
6024 remote_show_cmdlist for a list of sub commands to show. */
6025 show_remote_protocol_Z_packet_cmd (args
, from_tty
, NULL
);
6026 show_remote_protocol_e_packet_cmd (args
, from_tty
, NULL
);
6027 show_remote_protocol_E_packet_cmd (args
, from_tty
, NULL
);
6028 show_remote_protocol_P_packet_cmd (args
, from_tty
, NULL
);
6029 show_remote_protocol_qSymbol_packet_cmd (args
, from_tty
, NULL
);
6030 show_remote_protocol_binary_download_cmd (args
, from_tty
, NULL
);
6034 build_remote_gdbarch_data (void)
6036 remote_address_size
= TARGET_ADDR_BIT
;
6039 /* Saved pointer to previous owner of the new_objfile event. */
6040 static void (*remote_new_objfile_chain
) (struct objfile
*);
6042 /* Function to be called whenever a new objfile (shlib) is detected. */
6044 remote_new_objfile (struct objfile
*objfile
)
6046 if (remote_desc
!= 0) /* Have a remote connection */
6048 remote_check_symbols (objfile
);
6050 /* Call predecessor on chain, if any. */
6051 if (remote_new_objfile_chain
!= 0 &&
6053 remote_new_objfile_chain (objfile
);
6057 _initialize_remote (void)
6059 static struct cmd_list_element
*remote_set_cmdlist
;
6060 static struct cmd_list_element
*remote_show_cmdlist
;
6061 struct cmd_list_element
*tmpcmd
;
6063 /* architecture specific data */
6064 remote_gdbarch_data_handle
= register_gdbarch_data (init_remote_state
,
6067 /* Old tacky stuff. NOTE: This comes after the remote protocol so
6068 that the remote protocol has been initialized. */
6069 register_gdbarch_swap (&remote_address_size
,
6070 sizeof (&remote_address_size
), NULL
);
6071 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
6074 add_target (&remote_ops
);
6076 init_extended_remote_ops ();
6077 add_target (&extended_remote_ops
);
6079 init_remote_async_ops ();
6080 add_target (&remote_async_ops
);
6082 init_extended_async_remote_ops ();
6083 add_target (&extended_async_remote_ops
);
6085 init_remote_cisco_ops ();
6086 add_target (&remote_cisco_ops
);
6088 /* Hook into new objfile notification. */
6089 remote_new_objfile_chain
= target_new_objfile_hook
;
6090 target_new_objfile_hook
= remote_new_objfile
;
6093 init_remote_threadtests ();
6096 /* set/show remote ... */
6098 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
6099 Remote protocol specific variables\n\
6100 Configure various remote-protocol specific variables such as\n\
6101 the packets being used",
6102 &remote_set_cmdlist
, "set remote ",
6103 0/*allow-unknown*/, &setlist
);
6104 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, "\
6105 Remote protocol specific variables\n\
6106 Configure various remote-protocol specific variables such as\n\
6107 the packets being used",
6108 &remote_show_cmdlist
, "show remote ",
6109 0/*allow-unknown*/, &showlist
);
6111 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
6112 "Compare section data on target to the exec file.\n\
6113 Argument is a single section name (default: all loaded sections).",
6116 add_cmd ("packet", class_maintenance
, packet_command
,
6117 "Send an arbitrary packet to a remote target.\n\
6118 maintenance packet TEXT\n\
6119 If GDB is talking to an inferior via the GDB serial protocol, then\n\
6120 this command sends the string TEXT to the inferior, and displays the\n\
6121 response packet. GDB supplies the initial `$' character, and the\n\
6122 terminating `#' character and checksum.",
6125 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
,
6126 "Set whether to send break if interrupted.\n",
6127 "Show whether to send break if interrupted.\n",
6129 &setlist
, &showlist
);
6131 /* Install commands for configuring memory read/write packets. */
6133 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
6134 "Set the maximum number of bytes per memory write packet (deprecated).\n",
6136 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
,
6137 "Show the maximum number of bytes per memory write packet (deprecated).\n",
6139 add_cmd ("memory-write-packet-size", no_class
,
6140 set_memory_write_packet_size
,
6141 "Set the maximum number of bytes per memory-write packet.\n"
6142 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6143 "default packet size. The actual limit is further reduced\n"
6144 "dependent on the target. Specify ``fixed'' to disable the\n"
6145 "further restriction and ``limit'' to enable that restriction\n",
6146 &remote_set_cmdlist
);
6147 add_cmd ("memory-read-packet-size", no_class
,
6148 set_memory_read_packet_size
,
6149 "Set the maximum number of bytes per memory-read packet.\n"
6150 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6151 "default packet size. The actual limit is further reduced\n"
6152 "dependent on the target. Specify ``fixed'' to disable the\n"
6153 "further restriction and ``limit'' to enable that restriction\n",
6154 &remote_set_cmdlist
);
6155 add_cmd ("memory-write-packet-size", no_class
,
6156 show_memory_write_packet_size
,
6157 "Show the maximum number of bytes per memory-write packet.\n",
6158 &remote_show_cmdlist
);
6159 add_cmd ("memory-read-packet-size", no_class
,
6160 show_memory_read_packet_size
,
6161 "Show the maximum number of bytes per memory-read packet.\n",
6162 &remote_show_cmdlist
);
6164 add_setshow_cmd ("hardware-watchpoint-limit", no_class
,
6165 var_zinteger
, &remote_hw_watchpoint_limit
, "\
6166 Set the maximum number of target hardware watchpoints.\n\
6167 Specify a negative limit for unlimited.", "\
6168 Show the maximum number of target hardware watchpoints.\n",
6169 NULL
, NULL
, &remote_set_cmdlist
, &remote_show_cmdlist
);
6170 add_setshow_cmd ("hardware-breakpoint-limit", no_class
,
6171 var_zinteger
, &remote_hw_breakpoint_limit
, "\
6172 Set the maximum number of target hardware breakpoints.\n\
6173 Specify a negative limit for unlimited.", "\
6174 Show the maximum number of target hardware breakpoints.\n",
6175 NULL
, NULL
, &remote_set_cmdlist
, &remote_show_cmdlist
);
6178 (add_set_cmd ("remoteaddresssize", class_obscure
,
6179 var_integer
, (char *) &remote_address_size
,
6180 "Set the maximum size of the address (in bits) \
6181 in a memory packet.\n",
6185 add_packet_config_cmd (&remote_protocol_binary_download
,
6186 "X", "binary-download",
6187 set_remote_protocol_binary_download_cmd
,
6188 show_remote_protocol_binary_download_cmd
,
6189 &remote_set_cmdlist
, &remote_show_cmdlist
,
6192 /* XXXX - should ``set remotebinarydownload'' be retained for
6195 (add_set_cmd ("remotebinarydownload", no_class
,
6196 var_boolean
, (char *) &remote_binary_download
,
6197 "Set binary downloads.\n", &setlist
),
6201 add_info ("remote-process", remote_info_process
,
6202 "Query the remote system for process info.");
6204 add_packet_config_cmd (&remote_protocol_qSymbol
,
6205 "qSymbol", "symbol-lookup",
6206 set_remote_protocol_qSymbol_packet_cmd
,
6207 show_remote_protocol_qSymbol_packet_cmd
,
6208 &remote_set_cmdlist
, &remote_show_cmdlist
,
6211 add_packet_config_cmd (&remote_protocol_e
,
6212 "e", "step-over-range",
6213 set_remote_protocol_e_packet_cmd
,
6214 show_remote_protocol_e_packet_cmd
,
6215 &remote_set_cmdlist
, &remote_show_cmdlist
,
6217 /* Disable by default. The ``e'' packet has nasty interactions with
6218 the threading code - it relies on global state. */
6219 remote_protocol_e
.detect
= AUTO_BOOLEAN_FALSE
;
6220 update_packet_config (&remote_protocol_e
);
6222 add_packet_config_cmd (&remote_protocol_E
,
6223 "E", "step-over-range-w-signal",
6224 set_remote_protocol_E_packet_cmd
,
6225 show_remote_protocol_E_packet_cmd
,
6226 &remote_set_cmdlist
, &remote_show_cmdlist
,
6228 /* Disable by default. The ``e'' packet has nasty interactions with
6229 the threading code - it relies on global state. */
6230 remote_protocol_E
.detect
= AUTO_BOOLEAN_FALSE
;
6231 update_packet_config (&remote_protocol_E
);
6233 add_packet_config_cmd (&remote_protocol_P
,
6234 "P", "set-register",
6235 set_remote_protocol_P_packet_cmd
,
6236 show_remote_protocol_P_packet_cmd
,
6237 &remote_set_cmdlist
, &remote_show_cmdlist
,
6240 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
6241 "Z0", "software-breakpoint",
6242 set_remote_protocol_Z_software_bp_packet_cmd
,
6243 show_remote_protocol_Z_software_bp_packet_cmd
,
6244 &remote_set_cmdlist
, &remote_show_cmdlist
,
6247 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
6248 "Z1", "hardware-breakpoint",
6249 set_remote_protocol_Z_hardware_bp_packet_cmd
,
6250 show_remote_protocol_Z_hardware_bp_packet_cmd
,
6251 &remote_set_cmdlist
, &remote_show_cmdlist
,
6254 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
6255 "Z2", "write-watchpoint",
6256 set_remote_protocol_Z_write_wp_packet_cmd
,
6257 show_remote_protocol_Z_write_wp_packet_cmd
,
6258 &remote_set_cmdlist
, &remote_show_cmdlist
,
6261 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
6262 "Z3", "read-watchpoint",
6263 set_remote_protocol_Z_read_wp_packet_cmd
,
6264 show_remote_protocol_Z_read_wp_packet_cmd
,
6265 &remote_set_cmdlist
, &remote_show_cmdlist
,
6268 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
6269 "Z4", "access-watchpoint",
6270 set_remote_protocol_Z_access_wp_packet_cmd
,
6271 show_remote_protocol_Z_access_wp_packet_cmd
,
6272 &remote_set_cmdlist
, &remote_show_cmdlist
,
6275 /* Keep the old ``set remote Z-packet ...'' working. */
6276 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
6277 &remote_Z_packet_detect
, "\
6278 Set use of remote protocol `Z' packets",
6279 "Show use of remote protocol `Z' packets ",
6280 set_remote_protocol_Z_packet_cmd
,
6281 show_remote_protocol_Z_packet_cmd
,
6282 &remote_set_cmdlist
, &remote_show_cmdlist
);
6284 /* Eventually initialize fileio. See fileio.c */
6285 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);