1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* See the GDB User Guide for details of the GDB remote protocol. */
26 #include "gdb_string.h"
33 /*#include "terminal.h" */
36 #include "gdb-stabs.h"
37 #include "gdbthread.h"
41 #include "gdb_assert.h"
46 #include <sys/types.h>
49 #include "event-loop.h"
50 #include "event-top.h"
56 #include "gdbcore.h" /* for exec_bfd */
58 /* Prototypes for local functions */
59 static void cleanup_sigint_signal_handler (void *dummy
);
60 static void initialize_sigint_signal_handler (void);
61 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
63 static void handle_remote_sigint (int);
64 static void handle_remote_sigint_twice (int);
65 static void async_remote_interrupt (gdb_client_data
);
66 void async_remote_interrupt_twice (gdb_client_data
);
68 static void build_remote_gdbarch_data (void);
70 static int remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
72 static int remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
74 static void remote_files_info (struct target_ops
*ignore
);
76 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
77 int len
, int should_write
,
78 struct mem_attrib
*attrib
,
79 struct target_ops
*target
);
81 static void remote_prepare_to_store (void);
83 static void remote_fetch_registers (int regno
);
85 static void remote_resume (ptid_t ptid
, int step
,
86 enum target_signal siggnal
);
87 static void remote_async_resume (ptid_t ptid
, int step
,
88 enum target_signal siggnal
);
89 static int remote_start_remote (struct ui_out
*uiout
, void *dummy
);
91 static void remote_open (char *name
, int from_tty
);
92 static void remote_async_open (char *name
, int from_tty
);
94 static void extended_remote_open (char *name
, int from_tty
);
95 static void extended_remote_async_open (char *name
, int from_tty
);
97 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
,
100 static void remote_close (int quitting
);
102 static void remote_store_registers (int regno
);
104 static void remote_mourn (void);
105 static void remote_async_mourn (void);
107 static void extended_remote_restart (void);
109 static void extended_remote_mourn (void);
111 static void extended_remote_create_inferior (char *, char *, char **);
112 static void extended_remote_async_create_inferior (char *, char *, char **);
114 static void remote_mourn_1 (struct target_ops
*);
116 static void remote_send (char *buf
, long sizeof_buf
);
118 static int readchar (int timeout
);
120 static ptid_t
remote_wait (ptid_t ptid
,
121 struct target_waitstatus
*status
);
122 static ptid_t
remote_async_wait (ptid_t ptid
,
123 struct target_waitstatus
*status
);
125 static void remote_kill (void);
126 static void remote_async_kill (void);
128 static int tohex (int nib
);
130 static void remote_detach (char *args
, int from_tty
);
131 static void remote_async_detach (char *args
, int from_tty
);
133 static void remote_interrupt (int signo
);
135 static void remote_interrupt_twice (int signo
);
137 static void interrupt_query (void);
139 static void set_thread (int, int);
141 static int remote_thread_alive (ptid_t
);
143 static void get_offsets (void);
145 static long read_frame (char *buf
, long sizeof_buf
);
147 static int remote_insert_breakpoint (CORE_ADDR
, char *);
149 static int remote_remove_breakpoint (CORE_ADDR
, char *);
151 static int hexnumlen (ULONGEST num
);
153 static void init_remote_ops (void);
155 static void init_extended_remote_ops (void);
157 static void init_remote_cisco_ops (void);
159 static struct target_ops remote_cisco_ops
;
161 static void remote_stop (void);
163 static int ishex (int ch
, int *val
);
165 static int stubhex (int ch
);
167 static int remote_query (int /*char */ , char *, char *, int *);
169 static int hexnumstr (char *, ULONGEST
);
171 static int hexnumnstr (char *, ULONGEST
, int);
173 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
175 static void print_packet (char *);
177 static unsigned long crc32 (unsigned char *, int, unsigned int);
179 static void compare_sections_command (char *, int);
181 static void packet_command (char *, int);
183 static int stub_unpack_int (char *buff
, int fieldlength
);
185 static ptid_t
remote_current_thread (ptid_t oldptid
);
187 static void remote_find_new_threads (void);
189 static void record_currthread (int currthread
);
191 static int fromhex (int a
);
193 static int hex2bin (const char *hex
, char *bin
, int count
);
195 static int bin2hex (const char *bin
, char *hex
, int count
);
197 static int putpkt_binary (char *buf
, int cnt
);
199 static void check_binary_download (CORE_ADDR addr
);
201 struct packet_config
;
203 static void show_packet_config_cmd (struct packet_config
*config
);
205 static void update_packet_config (struct packet_config
*config
);
207 void _initialize_remote (void);
209 /* Description of the remote protocol. Strictly speaking, when the
210 target is open()ed, remote.c should create a per-target description
211 of the remote protocol using that target's architecture.
212 Unfortunatly, the target stack doesn't include local state. For
213 the moment keep the information in the target's architecture
218 long offset
; /* Offset into G packet. */
219 long regnum
; /* GDB's internal register number. */
220 LONGEST pnum
; /* Remote protocol register number. */
221 int in_g_packet
; /* Always part of G packet. */
222 /* long size in bytes; == REGISTER_RAW_SIZE (regnum); at present. */
223 /* char *name; == REGISTER_NAME (regnum); at present. */
228 /* Description of the remote protocol registers. */
229 long sizeof_g_packet
;
231 /* Description of the remote protocol registers indexed by REGNUM
232 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
233 struct packet_reg
*regs
;
235 /* This is the size (in chars) of the first response to the ``g''
236 packet. It is used as a heuristic when determining the maximum
237 size of memory-read and memory-write packets. A target will
238 typically only reserve a buffer large enough to hold the ``g''
239 packet. The size does not include packet overhead (headers and
241 long actual_register_packet_size
;
243 /* This is the maximum size (in chars) of a non read/write packet.
244 It is also used as a cap on the size of read/write packets. */
245 long remote_packet_size
;
249 /* Handle for retreving the remote protocol data from gdbarch. */
250 static struct gdbarch_data
*remote_gdbarch_data_handle
;
252 static struct remote_state
*
253 get_remote_state (void)
255 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
259 init_remote_state (struct gdbarch
*gdbarch
)
262 struct remote_state
*rs
= xmalloc (sizeof (struct remote_state
));
264 /* Start out by having the remote protocol mimic the existing
265 behavour - just copy in the description of the register cache. */
266 rs
->sizeof_g_packet
= REGISTER_BYTES
; /* OK use. */
268 /* Assume a 1:1 regnum<->pnum table. */
269 rs
->regs
= xcalloc (NUM_REGS
+ NUM_PSEUDO_REGS
, sizeof (struct packet_reg
));
270 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
272 struct packet_reg
*r
= &rs
->regs
[regnum
];
275 r
->offset
= REGISTER_BYTE (regnum
);
276 r
->in_g_packet
= (regnum
< NUM_REGS
);
277 /* ...size = REGISTER_RAW_SIZE (regnum); */
278 /* ...name = REGISTER_NAME (regnum); */
281 /* Default maximum number of characters in a packet body. Many
282 remote stubs have a hardwired buffer size of 400 bytes
283 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
284 as the maximum packet-size to ensure that the packet and an extra
285 NUL character can always fit in the buffer. This stops GDB
286 trashing stubs that try to squeeze an extra NUL into what is
287 already a full buffer (As of 1999-12-04 that was most stubs. */
288 rs
->remote_packet_size
= 400 - 1;
290 /* Should rs->sizeof_g_packet needs more space than the
291 default, adjust the size accordingly. Remember that each byte is
292 encoded as two characters. 32 is the overhead for the packet
293 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
294 (``$NN:G...#NN'') is a better guess, the below has been padded a
296 if (rs
->sizeof_g_packet
> ((rs
->remote_packet_size
- 32) / 2))
297 rs
->remote_packet_size
= (rs
->sizeof_g_packet
* 2 + 32);
299 /* This one is filled in when a ``g'' packet is received. */
300 rs
->actual_register_packet_size
= 0;
306 free_remote_state (struct gdbarch
*gdbarch
, void *pointer
)
308 struct remote_state
*data
= pointer
;
313 static struct packet_reg
*
314 packet_reg_from_regnum (struct remote_state
*rs
, long regnum
)
316 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
320 struct packet_reg
*r
= &rs
->regs
[regnum
];
321 gdb_assert (r
->regnum
== regnum
);
326 static struct packet_reg
*
327 packet_reg_from_pnum (struct remote_state
*rs
, LONGEST pnum
)
330 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
332 struct packet_reg
*r
= &rs
->regs
[i
];
339 /* FIXME: graces/2002-08-08: These variables should eventually be
340 bound to an instance of the target object (as in gdbarch-tdep()),
341 when such a thing exists. */
343 /* This is set to the data address of the access causing the target
344 to stop for a watchpoint. */
345 static CORE_ADDR remote_watch_data_address
;
347 /* This is non-zero if taregt stopped for a watchpoint. */
348 static int remote_stopped_by_watchpoint_p
;
351 static struct target_ops remote_ops
;
353 static struct target_ops extended_remote_ops
;
355 /* Temporary target ops. Just like the remote_ops and
356 extended_remote_ops, but with asynchronous support. */
357 static struct target_ops remote_async_ops
;
359 static struct target_ops extended_async_remote_ops
;
361 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
362 ``forever'' still use the normal timeout mechanism. This is
363 currently used by the ASYNC code to guarentee that target reads
364 during the initial connect always time-out. Once getpkt has been
365 modified to return a timeout indication and, in turn
366 remote_wait()/wait_for_inferior() have gained a timeout parameter
368 static int wait_forever_enabled_p
= 1;
371 /* This variable chooses whether to send a ^C or a break when the user
372 requests program interruption. Although ^C is usually what remote
373 systems expect, and that is the default here, sometimes a break is
374 preferable instead. */
376 static int remote_break
;
378 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
379 remote_open knows that we don't have a file open when the program
381 static struct serial
*remote_desc
= NULL
;
383 /* This is set by the target (thru the 'S' message)
384 to denote that the target is in kernel mode. */
385 static int cisco_kernel_mode
= 0;
387 /* This variable sets the number of bits in an address that are to be
388 sent in a memory ("M" or "m") packet. Normally, after stripping
389 leading zeros, the entire address would be sent. This variable
390 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
391 initial implementation of remote.c restricted the address sent in
392 memory packets to ``host::sizeof long'' bytes - (typically 32
393 bits). Consequently, for 64 bit targets, the upper 32 bits of an
394 address was never sent. Since fixing this bug may cause a break in
395 some remote targets this variable is principly provided to
396 facilitate backward compatibility. */
398 static int remote_address_size
;
400 /* Tempoary to track who currently owns the terminal. See
401 target_async_terminal_* for more details. */
403 static int remote_async_terminal_ours_p
;
406 /* User configurable variables for the number of characters in a
407 memory read/write packet. MIN ((rs->remote_packet_size),
408 rs->sizeof_g_packet) is the default. Some targets need smaller
409 values (fifo overruns, et.al.) and some users need larger values
410 (speed up transfers). The variables ``preferred_*'' (the user
411 request), ``current_*'' (what was actually set) and ``forced_*''
412 (Positive - a soft limit, negative - a hard limit). */
414 struct memory_packet_config
421 /* Compute the current size of a read/write packet. Since this makes
422 use of ``actual_register_packet_size'' the computation is dynamic. */
425 get_memory_packet_size (struct memory_packet_config
*config
)
427 struct remote_state
*rs
= get_remote_state ();
428 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
429 law?) that some hosts don't cope very well with large alloca()
430 calls. Eventually the alloca() code will be replaced by calls to
431 xmalloc() and make_cleanups() allowing this restriction to either
432 be lifted or removed. */
433 #ifndef MAX_REMOTE_PACKET_SIZE
434 #define MAX_REMOTE_PACKET_SIZE 16384
436 /* NOTE: 16 is just chosen at random. */
437 #ifndef MIN_REMOTE_PACKET_SIZE
438 #define MIN_REMOTE_PACKET_SIZE 16
443 if (config
->size
<= 0)
444 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
446 what_they_get
= config
->size
;
450 what_they_get
= (rs
->remote_packet_size
);
451 /* Limit the packet to the size specified by the user. */
453 && what_they_get
> config
->size
)
454 what_they_get
= config
->size
;
455 /* Limit it to the size of the targets ``g'' response. */
456 if ((rs
->actual_register_packet_size
) > 0
457 && what_they_get
> (rs
->actual_register_packet_size
))
458 what_they_get
= (rs
->actual_register_packet_size
);
460 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
461 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
462 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
463 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
464 return what_they_get
;
467 /* Update the size of a read/write packet. If they user wants
468 something really big then do a sanity check. */
471 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
473 int fixed_p
= config
->fixed_p
;
474 long size
= config
->size
;
476 error ("Argument required (integer, `fixed' or `limited').");
477 else if (strcmp (args
, "hard") == 0
478 || strcmp (args
, "fixed") == 0)
480 else if (strcmp (args
, "soft") == 0
481 || strcmp (args
, "limit") == 0)
486 size
= strtoul (args
, &end
, 0);
488 error ("Invalid %s (bad syntax).", config
->name
);
490 /* Instead of explicitly capping the size of a packet to
491 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
492 instead allowed to set the size to something arbitrarily
494 if (size
> MAX_REMOTE_PACKET_SIZE
)
495 error ("Invalid %s (too large).", config
->name
);
499 if (fixed_p
&& !config
->fixed_p
)
501 if (! query ("The target may not be able to correctly handle a %s\n"
502 "of %ld bytes. Change the packet size? ",
504 error ("Packet size not changed.");
506 /* Update the config. */
507 config
->fixed_p
= fixed_p
;
512 show_memory_packet_size (struct memory_packet_config
*config
)
514 printf_filtered ("The %s is %ld. ", config
->name
, config
->size
);
516 printf_filtered ("Packets are fixed at %ld bytes.\n",
517 get_memory_packet_size (config
));
519 printf_filtered ("Packets are limited to %ld bytes.\n",
520 get_memory_packet_size (config
));
523 static struct memory_packet_config memory_write_packet_config
=
525 "memory-write-packet-size",
529 set_memory_write_packet_size (char *args
, int from_tty
)
531 set_memory_packet_size (args
, &memory_write_packet_config
);
535 show_memory_write_packet_size (char *args
, int from_tty
)
537 show_memory_packet_size (&memory_write_packet_config
);
541 get_memory_write_packet_size (void)
543 return get_memory_packet_size (&memory_write_packet_config
);
546 static struct memory_packet_config memory_read_packet_config
=
548 "memory-read-packet-size",
552 set_memory_read_packet_size (char *args
, int from_tty
)
554 set_memory_packet_size (args
, &memory_read_packet_config
);
558 show_memory_read_packet_size (char *args
, int from_tty
)
560 show_memory_packet_size (&memory_read_packet_config
);
564 get_memory_read_packet_size (void)
566 struct remote_state
*rs
= get_remote_state ();
567 long size
= get_memory_packet_size (&memory_read_packet_config
);
568 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
569 extra buffer size argument before the memory read size can be
570 increased beyond (rs->remote_packet_size). */
571 if (size
> (rs
->remote_packet_size
))
572 size
= (rs
->remote_packet_size
);
577 /* Generic configuration support for packets the stub optionally
578 supports. Allows the user to specify the use of the packet as well
579 as allowing GDB to auto-detect support in the remote stub. */
583 PACKET_SUPPORT_UNKNOWN
= 0,
592 enum auto_boolean detect
;
593 enum packet_support support
;
596 /* Analyze a packet's return value and update the packet config
607 update_packet_config (struct packet_config
*config
)
609 switch (config
->detect
)
611 case AUTO_BOOLEAN_TRUE
:
612 config
->support
= PACKET_ENABLE
;
614 case AUTO_BOOLEAN_FALSE
:
615 config
->support
= PACKET_DISABLE
;
617 case AUTO_BOOLEAN_AUTO
:
618 config
->support
= PACKET_SUPPORT_UNKNOWN
;
624 show_packet_config_cmd (struct packet_config
*config
)
626 char *support
= "internal-error";
627 switch (config
->support
)
633 support
= "disabled";
635 case PACKET_SUPPORT_UNKNOWN
:
639 switch (config
->detect
)
641 case AUTO_BOOLEAN_AUTO
:
642 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
643 config
->name
, config
->title
, support
);
645 case AUTO_BOOLEAN_TRUE
:
646 case AUTO_BOOLEAN_FALSE
:
647 printf_filtered ("Support for remote protocol `%s' (%s) packet is currently %s.\n",
648 config
->name
, config
->title
, support
);
654 add_packet_config_cmd (struct packet_config
*config
,
657 cmd_sfunc_ftype
*set_func
,
658 cmd_sfunc_ftype
*show_func
,
659 struct cmd_list_element
**set_remote_list
,
660 struct cmd_list_element
**show_remote_list
,
663 struct cmd_list_element
*set_cmd
;
664 struct cmd_list_element
*show_cmd
;
669 config
->title
= title
;
670 config
->detect
= AUTO_BOOLEAN_AUTO
;
671 config
->support
= PACKET_SUPPORT_UNKNOWN
;
672 xasprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
674 xasprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
676 /* set/show TITLE-packet {auto,on,off} */
677 xasprintf (&cmd_name
, "%s-packet", title
);
678 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
679 &config
->detect
, set_doc
, show_doc
,
681 set_remote_list
, show_remote_list
);
682 /* set/show remote NAME-packet {auto,on,off} -- legacy */
686 xasprintf (&legacy_name
, "%s-packet", name
);
687 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
689 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
694 static enum packet_result
695 packet_ok (const char *buf
, struct packet_config
*config
)
699 /* The stub recognized the packet request. Check that the
700 operation succeeded. */
701 switch (config
->support
)
703 case PACKET_SUPPORT_UNKNOWN
:
705 fprintf_unfiltered (gdb_stdlog
,
706 "Packet %s (%s) is supported\n",
707 config
->name
, config
->title
);
708 config
->support
= PACKET_ENABLE
;
711 internal_error (__FILE__
, __LINE__
,
712 "packet_ok: attempt to use a disabled packet");
717 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
718 /* "OK" - definitly OK. */
721 && isxdigit (buf
[1]) && isxdigit (buf
[2])
723 /* "Enn" - definitly an error. */
725 /* The packet may or may not be OK. Just assume it is */
730 /* The stub does not support the packet. */
731 switch (config
->support
)
734 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
735 /* If the stub previously indicated that the packet was
736 supported then there is a protocol error.. */
737 error ("Protocol error: %s (%s) conflicting enabled responses.",
738 config
->name
, config
->title
);
740 /* The user set it wrong. */
741 error ("Enabled packet %s (%s) not recognized by stub",
742 config
->name
, config
->title
);
744 case PACKET_SUPPORT_UNKNOWN
:
746 fprintf_unfiltered (gdb_stdlog
,
747 "Packet %s (%s) is NOT supported\n",
748 config
->name
, config
->title
);
749 config
->support
= PACKET_DISABLE
;
754 return PACKET_UNKNOWN
;
758 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
759 static struct packet_config remote_protocol_qSymbol
;
762 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
763 struct cmd_list_element
*c
)
765 update_packet_config (&remote_protocol_qSymbol
);
769 show_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
770 struct cmd_list_element
*c
)
772 show_packet_config_cmd (&remote_protocol_qSymbol
);
775 /* Should we try the 'e' (step over range) request? */
776 static struct packet_config remote_protocol_e
;
779 set_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
780 struct cmd_list_element
*c
)
782 update_packet_config (&remote_protocol_e
);
786 show_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
787 struct cmd_list_element
*c
)
789 show_packet_config_cmd (&remote_protocol_e
);
793 /* Should we try the 'E' (step over range / w signal #) request? */
794 static struct packet_config remote_protocol_E
;
797 set_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
798 struct cmd_list_element
*c
)
800 update_packet_config (&remote_protocol_E
);
804 show_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
805 struct cmd_list_element
*c
)
807 show_packet_config_cmd (&remote_protocol_E
);
811 /* Should we try the 'P' (set register) request? */
813 static struct packet_config remote_protocol_P
;
816 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
817 struct cmd_list_element
*c
)
819 update_packet_config (&remote_protocol_P
);
823 show_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
824 struct cmd_list_element
*c
)
826 show_packet_config_cmd (&remote_protocol_P
);
829 /* Should we try one of the 'Z' requests? */
833 Z_PACKET_SOFTWARE_BP
,
834 Z_PACKET_HARDWARE_BP
,
841 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
843 /* FIXME: Instead of having all these boiler plate functions, the
844 command callback should include a context argument. */
847 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
848 struct cmd_list_element
*c
)
850 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
854 show_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
855 struct cmd_list_element
*c
)
857 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
861 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
862 struct cmd_list_element
*c
)
864 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
868 show_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
869 struct cmd_list_element
*c
)
871 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
875 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
876 struct cmd_list_element
*c
)
878 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
882 show_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
883 struct cmd_list_element
*c
)
885 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
889 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
890 struct cmd_list_element
*c
)
892 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
896 show_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
897 struct cmd_list_element
*c
)
899 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
903 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
904 struct cmd_list_element
*c
)
906 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
910 show_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
911 struct cmd_list_element
*c
)
913 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
916 /* For compatibility with older distributions. Provide a ``set remote
917 Z-packet ...'' command that updates all the Z packet types. */
919 static enum auto_boolean remote_Z_packet_detect
;
922 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
923 struct cmd_list_element
*c
)
926 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
928 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
929 update_packet_config (&remote_protocol_Z
[i
]);
934 show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
935 struct cmd_list_element
*c
)
938 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
940 show_packet_config_cmd (&remote_protocol_Z
[i
]);
944 /* Should we try the 'X' (remote binary download) packet?
946 This variable (available to the user via "set remote X-packet")
947 dictates whether downloads are sent in binary (via the 'X' packet).
948 We assume that the stub can, and attempt to do it. This will be
949 cleared if the stub does not understand it. This switch is still
950 needed, though in cases when the packet is supported in the stub,
951 but the connection does not allow it (i.e., 7-bit serial connection
954 static struct packet_config remote_protocol_binary_download
;
956 /* Should we try the 'ThreadInfo' query packet?
958 This variable (NOT available to the user: auto-detect only!)
959 determines whether GDB will use the new, simpler "ThreadInfo"
960 query or the older, more complex syntax for thread queries.
961 This is an auto-detect variable (set to true at each connect,
962 and set to false when the target fails to recognize it). */
964 static int use_threadinfo_query
;
965 static int use_threadextra_query
;
968 set_remote_protocol_binary_download_cmd (char *args
,
970 struct cmd_list_element
*c
)
972 update_packet_config (&remote_protocol_binary_download
);
976 show_remote_protocol_binary_download_cmd (char *args
, int from_tty
,
977 struct cmd_list_element
*c
)
979 show_packet_config_cmd (&remote_protocol_binary_download
);
983 /* Tokens for use by the asynchronous signal handlers for SIGINT */
984 static void *sigint_remote_twice_token
;
985 static void *sigint_remote_token
;
987 /* These are pointers to hook functions that may be set in order to
988 modify resume/wait behavior for a particular architecture. */
990 void (*target_resume_hook
) (void);
991 void (*target_wait_loop_hook
) (void);
995 /* These are the threads which we last sent to the remote system.
996 -1 for all or -2 for not sent yet. */
997 static int general_thread
;
998 static int continue_thread
;
1000 /* Call this function as a result of
1001 1) A halt indication (T packet) containing a thread id
1002 2) A direct query of currthread
1003 3) Successful execution of set thread
1007 record_currthread (int currthread
)
1009 general_thread
= currthread
;
1011 /* If this is a new thread, add it to GDB's thread list.
1012 If we leave it up to WFI to do this, bad things will happen. */
1013 if (!in_thread_list (pid_to_ptid (currthread
)))
1015 add_thread (pid_to_ptid (currthread
));
1016 ui_out_text (uiout
, "[New ");
1017 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
1018 ui_out_text (uiout
, "]\n");
1022 #define MAGIC_NULL_PID 42000
1025 set_thread (int th
, int gen
)
1027 struct remote_state
*rs
= get_remote_state ();
1028 char *buf
= alloca (rs
->remote_packet_size
);
1029 int state
= gen
? general_thread
: continue_thread
;
1035 buf
[1] = gen
? 'g' : 'c';
1036 if (th
== MAGIC_NULL_PID
)
1042 sprintf (&buf
[2], "-%x", -th
);
1044 sprintf (&buf
[2], "%x", th
);
1046 getpkt (buf
, (rs
->remote_packet_size
), 0);
1048 general_thread
= th
;
1050 continue_thread
= th
;
1053 /* Return nonzero if the thread TH is still alive on the remote system. */
1056 remote_thread_alive (ptid_t ptid
)
1058 int tid
= PIDGET (ptid
);
1062 sprintf (buf
, "T-%08x", -tid
);
1064 sprintf (buf
, "T%08x", tid
);
1066 getpkt (buf
, sizeof (buf
), 0);
1067 return (buf
[0] == 'O' && buf
[1] == 'K');
1070 /* About these extended threadlist and threadinfo packets. They are
1071 variable length packets but, the fields within them are often fixed
1072 length. They are redundent enough to send over UDP as is the
1073 remote protocol in general. There is a matching unit test module
1076 #define OPAQUETHREADBYTES 8
1078 /* a 64 bit opaque identifier */
1079 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1081 /* WARNING: This threadref data structure comes from the remote O.S., libstub
1082 protocol encoding, and remote.c. it is not particularly changable */
1084 /* Right now, the internal structure is int. We want it to be bigger.
1088 typedef int gdb_threadref
; /* internal GDB thread reference */
1090 /* gdb_ext_thread_info is an internal GDB data structure which is
1091 equivalint to the reply of the remote threadinfo packet */
1093 struct gdb_ext_thread_info
1095 threadref threadid
; /* External form of thread reference */
1096 int active
; /* Has state interesting to GDB? , regs, stack */
1097 char display
[256]; /* Brief state display, name, blocked/syspended */
1098 char shortname
[32]; /* To be used to name threads */
1099 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
1102 /* The volume of remote transfers can be limited by submitting
1103 a mask containing bits specifying the desired information.
1104 Use a union of these values as the 'selection' parameter to
1105 get_thread_info. FIXME: Make these TAG names more thread specific.
1108 #define TAG_THREADID 1
1109 #define TAG_EXISTS 2
1110 #define TAG_DISPLAY 4
1111 #define TAG_THREADNAME 8
1112 #define TAG_MOREDISPLAY 16
1114 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
1116 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1118 static char *unpack_nibble (char *buf
, int *val
);
1120 static char *pack_nibble (char *buf
, int nibble
);
1122 static char *pack_hex_byte (char *pkt
, int /*unsigned char */ byte
);
1124 static char *unpack_byte (char *buf
, int *value
);
1126 static char *pack_int (char *buf
, int value
);
1128 static char *unpack_int (char *buf
, int *value
);
1130 static char *unpack_string (char *src
, char *dest
, int length
);
1132 static char *pack_threadid (char *pkt
, threadref
* id
);
1134 static char *unpack_threadid (char *inbuf
, threadref
* id
);
1136 void int_to_threadref (threadref
* id
, int value
);
1138 static int threadref_to_int (threadref
* ref
);
1140 static void copy_threadref (threadref
* dest
, threadref
* src
);
1142 static int threadmatch (threadref
* dest
, threadref
* src
);
1144 static char *pack_threadinfo_request (char *pkt
, int mode
, threadref
* id
);
1146 static int remote_unpack_thread_info_response (char *pkt
,
1147 threadref
* expectedref
,
1148 struct gdb_ext_thread_info
1152 static int remote_get_threadinfo (threadref
* threadid
, int fieldset
, /*TAG mask */
1153 struct gdb_ext_thread_info
*info
);
1155 static int adapt_remote_get_threadinfo (gdb_threadref
* ref
,
1157 struct gdb_ext_thread_info
*info
);
1159 static char *pack_threadlist_request (char *pkt
, int startflag
,
1161 threadref
* nextthread
);
1163 static int parse_threadlist_response (char *pkt
,
1165 threadref
* original_echo
,
1166 threadref
* resultlist
, int *doneflag
);
1168 static int remote_get_threadlist (int startflag
,
1169 threadref
* nextthread
,
1172 int *result_count
, threadref
* threadlist
);
1174 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
1176 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1177 void *context
, int looplimit
);
1179 static int remote_newthread_step (threadref
* ref
, void *context
);
1181 /* encode 64 bits in 16 chars of hex */
1183 static const char hexchars
[] = "0123456789abcdef";
1186 ishex (int ch
, int *val
)
1188 if ((ch
>= 'a') && (ch
<= 'f'))
1190 *val
= ch
- 'a' + 10;
1193 if ((ch
>= 'A') && (ch
<= 'F'))
1195 *val
= ch
- 'A' + 10;
1198 if ((ch
>= '0') && (ch
<= '9'))
1209 if (ch
>= 'a' && ch
<= 'f')
1210 return ch
- 'a' + 10;
1211 if (ch
>= '0' && ch
<= '9')
1213 if (ch
>= 'A' && ch
<= 'F')
1214 return ch
- 'A' + 10;
1219 stub_unpack_int (char *buff
, int fieldlength
)
1226 nibble
= stubhex (*buff
++);
1230 retval
= retval
<< 4;
1236 unpack_varlen_hex (char *buff
, /* packet to parse */
1242 while (ishex (*buff
, &nibble
))
1245 retval
= retval
<< 4;
1246 retval
|= nibble
& 0x0f;
1253 unpack_nibble (char *buf
, int *val
)
1255 ishex (*buf
++, val
);
1260 pack_nibble (char *buf
, int nibble
)
1262 *buf
++ = hexchars
[(nibble
& 0x0f)];
1267 pack_hex_byte (char *pkt
, int byte
)
1269 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1270 *pkt
++ = hexchars
[(byte
& 0xf)];
1275 unpack_byte (char *buf
, int *value
)
1277 *value
= stub_unpack_int (buf
, 2);
1282 pack_int (char *buf
, int value
)
1284 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1285 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1286 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1287 buf
= pack_hex_byte (buf
, (value
& 0xff));
1292 unpack_int (char *buf
, int *value
)
1294 *value
= stub_unpack_int (buf
, 8);
1298 #if 0 /* currently unused, uncomment when needed */
1299 static char *pack_string (char *pkt
, char *string
);
1302 pack_string (char *pkt
, char *string
)
1307 len
= strlen (string
);
1309 len
= 200; /* Bigger than most GDB packets, junk??? */
1310 pkt
= pack_hex_byte (pkt
, len
);
1314 if ((ch
== '\0') || (ch
== '#'))
1315 ch
= '*'; /* Protect encapsulation */
1320 #endif /* 0 (unused) */
1323 unpack_string (char *src
, char *dest
, int length
)
1332 pack_threadid (char *pkt
, threadref
*id
)
1335 unsigned char *altid
;
1337 altid
= (unsigned char *) id
;
1338 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1340 pkt
= pack_hex_byte (pkt
, *altid
++);
1346 unpack_threadid (char *inbuf
, threadref
*id
)
1349 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1352 altref
= (char *) id
;
1354 while (inbuf
< limit
)
1356 x
= stubhex (*inbuf
++);
1357 y
= stubhex (*inbuf
++);
1358 *altref
++ = (x
<< 4) | y
;
1363 /* Externally, threadrefs are 64 bits but internally, they are still
1364 ints. This is due to a mismatch of specifications. We would like
1365 to use 64bit thread references internally. This is an adapter
1369 int_to_threadref (threadref
*id
, int value
)
1371 unsigned char *scan
;
1373 scan
= (unsigned char *) id
;
1379 *scan
++ = (value
>> 24) & 0xff;
1380 *scan
++ = (value
>> 16) & 0xff;
1381 *scan
++ = (value
>> 8) & 0xff;
1382 *scan
++ = (value
& 0xff);
1386 threadref_to_int (threadref
*ref
)
1389 unsigned char *scan
;
1391 scan
= (char *) ref
;
1395 value
= (value
<< 8) | ((*scan
++) & 0xff);
1400 copy_threadref (threadref
*dest
, threadref
*src
)
1403 unsigned char *csrc
, *cdest
;
1405 csrc
= (unsigned char *) src
;
1406 cdest
= (unsigned char *) dest
;
1413 threadmatch (threadref
*dest
, threadref
*src
)
1415 /* things are broken right now, so just assume we got a match */
1417 unsigned char *srcp
, *destp
;
1419 srcp
= (char *) src
;
1420 destp
= (char *) dest
;
1424 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1431 threadid:1, # always request threadid
1438 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1441 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1443 *pkt
++ = 'q'; /* Info Query */
1444 *pkt
++ = 'P'; /* process or thread info */
1445 pkt
= pack_int (pkt
, mode
); /* mode */
1446 pkt
= pack_threadid (pkt
, id
); /* threadid */
1447 *pkt
= '\0'; /* terminate */
1451 /* These values tag the fields in a thread info response packet */
1452 /* Tagging the fields allows us to request specific fields and to
1453 add more fields as time goes by */
1455 #define TAG_THREADID 1 /* Echo the thread identifier */
1456 #define TAG_EXISTS 2 /* Is this process defined enough to
1457 fetch registers and its stack */
1458 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1459 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1460 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1464 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1465 struct gdb_ext_thread_info
*info
)
1467 struct remote_state
*rs
= get_remote_state ();
1471 char *limit
= pkt
+ (rs
->remote_packet_size
); /* plausable parsing limit */
1474 /* info->threadid = 0; FIXME: implement zero_threadref */
1476 info
->display
[0] = '\0';
1477 info
->shortname
[0] = '\0';
1478 info
->more_display
[0] = '\0';
1480 /* Assume the characters indicating the packet type have been stripped */
1481 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1482 pkt
= unpack_threadid (pkt
, &ref
);
1485 warning ("Incomplete response to threadinfo request\n");
1486 if (!threadmatch (&ref
, expectedref
))
1487 { /* This is an answer to a different request */
1488 warning ("ERROR RMT Thread info mismatch\n");
1491 copy_threadref (&info
->threadid
, &ref
);
1493 /* Loop on tagged fields , try to bail if somthing goes wrong */
1495 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1497 pkt
= unpack_int (pkt
, &tag
); /* tag */
1498 pkt
= unpack_byte (pkt
, &length
); /* length */
1499 if (!(tag
& mask
)) /* tags out of synch with mask */
1501 warning ("ERROR RMT: threadinfo tag mismatch\n");
1505 if (tag
== TAG_THREADID
)
1509 warning ("ERROR RMT: length of threadid is not 16\n");
1513 pkt
= unpack_threadid (pkt
, &ref
);
1514 mask
= mask
& ~TAG_THREADID
;
1517 if (tag
== TAG_EXISTS
)
1519 info
->active
= stub_unpack_int (pkt
, length
);
1521 mask
= mask
& ~(TAG_EXISTS
);
1524 warning ("ERROR RMT: 'exists' length too long\n");
1530 if (tag
== TAG_THREADNAME
)
1532 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1533 mask
= mask
& ~TAG_THREADNAME
;
1536 if (tag
== TAG_DISPLAY
)
1538 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1539 mask
= mask
& ~TAG_DISPLAY
;
1542 if (tag
== TAG_MOREDISPLAY
)
1544 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1545 mask
= mask
& ~TAG_MOREDISPLAY
;
1548 warning ("ERROR RMT: unknown thread info tag\n");
1549 break; /* Not a tag we know about */
1555 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1556 struct gdb_ext_thread_info
*info
)
1558 struct remote_state
*rs
= get_remote_state ();
1560 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1562 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1563 putpkt (threadinfo_pkt
);
1564 getpkt (threadinfo_pkt
, (rs
->remote_packet_size
), 0);
1565 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1570 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1571 representation of a threadid. */
1574 adapt_remote_get_threadinfo (gdb_threadref
*ref
, int selection
,
1575 struct gdb_ext_thread_info
*info
)
1579 int_to_threadref (&lclref
, *ref
);
1580 return remote_get_threadinfo (&lclref
, selection
, info
);
1583 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1586 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1587 threadref
*nextthread
)
1589 *pkt
++ = 'q'; /* info query packet */
1590 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1591 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1592 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1593 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1598 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1601 parse_threadlist_response (char *pkt
, int result_limit
,
1602 threadref
*original_echo
, threadref
*resultlist
,
1605 struct remote_state
*rs
= get_remote_state ();
1607 int count
, resultcount
, done
;
1610 /* Assume the 'q' and 'M chars have been stripped. */
1611 limit
= pkt
+ ((rs
->remote_packet_size
) - BUF_THREAD_ID_SIZE
); /* done parse past here */
1612 pkt
= unpack_byte (pkt
, &count
); /* count field */
1613 pkt
= unpack_nibble (pkt
, &done
);
1614 /* The first threadid is the argument threadid. */
1615 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1616 while ((count
-- > 0) && (pkt
< limit
))
1618 pkt
= unpack_threadid (pkt
, resultlist
++);
1619 if (resultcount
++ >= result_limit
)
1628 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1629 int *done
, int *result_count
, threadref
*threadlist
)
1631 struct remote_state
*rs
= get_remote_state ();
1632 static threadref echo_nextthread
;
1633 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1634 char *t_response
= alloca (rs
->remote_packet_size
);
1637 /* Trancate result limit to be smaller than the packet size */
1638 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= (rs
->remote_packet_size
))
1639 result_limit
= ((rs
->remote_packet_size
) / BUF_THREAD_ID_SIZE
) - 2;
1641 pack_threadlist_request (threadlist_packet
,
1642 startflag
, result_limit
, nextthread
);
1643 putpkt (threadlist_packet
);
1644 getpkt (t_response
, (rs
->remote_packet_size
), 0);
1647 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1650 if (!threadmatch (&echo_nextthread
, nextthread
))
1652 /* FIXME: This is a good reason to drop the packet */
1653 /* Possably, there is a duplicate response */
1655 retransmit immediatly - race conditions
1656 retransmit after timeout - yes
1658 wait for packet, then exit
1660 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1661 return 0; /* I choose simply exiting */
1663 if (*result_count
<= 0)
1667 warning ("RMT ERROR : failed to get remote thread list\n");
1670 return result
; /* break; */
1672 if (*result_count
> result_limit
)
1675 warning ("RMT ERROR: threadlist response longer than requested\n");
1681 /* This is the interface between remote and threads, remotes upper interface */
1683 /* remote_find_new_threads retrieves the thread list and for each
1684 thread in the list, looks up the thread in GDB's internal list,
1685 ading the thread if it does not already exist. This involves
1686 getting partial thread lists from the remote target so, polling the
1687 quit_flag is required. */
1690 /* About this many threadisds fit in a packet. */
1692 #define MAXTHREADLISTRESULTS 32
1695 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1698 int done
, i
, result_count
;
1702 static threadref nextthread
;
1703 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1708 if (loopcount
++ > looplimit
)
1711 warning ("Remote fetch threadlist -infinite loop-\n");
1714 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1715 &done
, &result_count
, resultthreadlist
))
1720 /* clear for later iterations */
1722 /* Setup to resume next batch of thread references, set nextthread. */
1723 if (result_count
>= 1)
1724 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1726 while (result_count
--)
1727 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1734 remote_newthread_step (threadref
*ref
, void *context
)
1738 ptid
= pid_to_ptid (threadref_to_int (ref
));
1740 if (!in_thread_list (ptid
))
1742 return 1; /* continue iterator */
1745 #define CRAZY_MAX_THREADS 1000
1748 remote_current_thread (ptid_t oldpid
)
1750 struct remote_state
*rs
= get_remote_state ();
1751 char *buf
= alloca (rs
->remote_packet_size
);
1754 getpkt (buf
, (rs
->remote_packet_size
), 0);
1755 if (buf
[0] == 'Q' && buf
[1] == 'C')
1756 return pid_to_ptid (strtol (&buf
[2], NULL
, 16));
1761 /* Find new threads for info threads command.
1762 * Original version, using John Metzler's thread protocol.
1766 remote_find_new_threads (void)
1768 remote_threadlist_iterator (remote_newthread_step
, 0,
1770 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1771 inferior_ptid
= remote_current_thread (inferior_ptid
);
1775 * Find all threads for info threads command.
1776 * Uses new thread protocol contributed by Cisco.
1777 * Falls back and attempts to use the older method (above)
1778 * if the target doesn't respond to the new method.
1782 remote_threads_info (void)
1784 struct remote_state
*rs
= get_remote_state ();
1785 char *buf
= alloca (rs
->remote_packet_size
);
1789 if (remote_desc
== 0) /* paranoia */
1790 error ("Command can only be used when connected to the remote target.");
1792 if (use_threadinfo_query
)
1794 putpkt ("qfThreadInfo");
1796 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1797 if (bufp
[0] != '\0') /* q packet recognized */
1799 while (*bufp
++ == 'm') /* reply contains one or more TID */
1803 tid
= strtol (bufp
, &bufp
, 16);
1804 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1805 add_thread (pid_to_ptid (tid
));
1807 while (*bufp
++ == ','); /* comma-separated list */
1808 putpkt ("qsThreadInfo");
1810 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1816 /* Else fall back to old method based on jmetzler protocol. */
1817 use_threadinfo_query
= 0;
1818 remote_find_new_threads ();
1823 * Collect a descriptive string about the given thread.
1824 * The target may say anything it wants to about the thread
1825 * (typically info about its blocked / runnable state, name, etc.).
1826 * This string will appear in the info threads display.
1828 * Optional: targets are not required to implement this function.
1832 remote_threads_extra_info (struct thread_info
*tp
)
1834 struct remote_state
*rs
= get_remote_state ();
1838 struct gdb_ext_thread_info threadinfo
;
1839 static char display_buf
[100]; /* arbitrary... */
1840 char *bufp
= alloca (rs
->remote_packet_size
);
1841 int n
= 0; /* position in display_buf */
1843 if (remote_desc
== 0) /* paranoia */
1844 internal_error (__FILE__
, __LINE__
,
1845 "remote_threads_extra_info");
1847 if (use_threadextra_query
)
1849 sprintf (bufp
, "qThreadExtraInfo,%x", PIDGET (tp
->ptid
));
1851 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1854 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1855 result
= hex2bin (bufp
, display_buf
, n
);
1856 display_buf
[result
] = '\0';
1861 /* If the above query fails, fall back to the old method. */
1862 use_threadextra_query
= 0;
1863 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1864 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1865 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1866 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1867 if (threadinfo
.active
)
1869 if (*threadinfo
.shortname
)
1870 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1871 if (*threadinfo
.display
)
1872 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1873 if (*threadinfo
.more_display
)
1874 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1875 threadinfo
.more_display
);
1879 /* for purely cosmetic reasons, clear up trailing commas */
1880 if (',' == display_buf
[n
-1])
1881 display_buf
[n
-1] = ' ';
1890 /* Restart the remote side; this is an extended protocol operation. */
1893 extended_remote_restart (void)
1895 struct remote_state
*rs
= get_remote_state ();
1896 char *buf
= alloca (rs
->remote_packet_size
);
1898 /* Send the restart command; for reasons I don't understand the
1899 remote side really expects a number after the "R". */
1901 sprintf (&buf
[1], "%x", 0);
1904 /* Now query for status so this looks just like we restarted
1905 gdbserver from scratch. */
1907 getpkt (buf
, (rs
->remote_packet_size
), 0);
1910 /* Clean up connection to a remote debugger. */
1914 remote_close (int quitting
)
1917 serial_close (remote_desc
);
1921 /* Query the remote side for the text, data and bss offsets. */
1926 struct remote_state
*rs
= get_remote_state ();
1927 char *buf
= alloca (rs
->remote_packet_size
);
1930 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1931 struct section_offsets
*offs
;
1933 putpkt ("qOffsets");
1935 getpkt (buf
, (rs
->remote_packet_size
), 0);
1937 if (buf
[0] == '\000')
1938 return; /* Return silently. Stub doesn't support
1942 warning ("Remote failure reply: %s", buf
);
1946 /* Pick up each field in turn. This used to be done with scanf, but
1947 scanf will make trouble if CORE_ADDR size doesn't match
1948 conversion directives correctly. The following code will work
1949 with any size of CORE_ADDR. */
1950 text_addr
= data_addr
= bss_addr
= 0;
1954 if (strncmp (ptr
, "Text=", 5) == 0)
1957 /* Don't use strtol, could lose on big values. */
1958 while (*ptr
&& *ptr
!= ';')
1959 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1964 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1967 while (*ptr
&& *ptr
!= ';')
1968 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1973 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1976 while (*ptr
&& *ptr
!= ';')
1977 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1983 error ("Malformed response to offset query, %s", buf
);
1985 if (symfile_objfile
== NULL
)
1988 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1989 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1991 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
1993 /* This is a temporary kludge to force data and bss to use the same offsets
1994 because that's what nlmconv does now. The real solution requires changes
1995 to the stub and remote.c that I don't have time to do right now. */
1997 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
1998 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2000 objfile_relocate (symfile_objfile
, offs
);
2004 * Cisco version of section offsets:
2006 * Instead of having GDB query the target for the section offsets,
2007 * Cisco lets the target volunteer the information! It's also in
2008 * a different format, so here are the functions that will decode
2009 * a section offset packet from a Cisco target.
2013 * Function: remote_cisco_section_offsets
2015 * Returns: zero for success, non-zero for failure
2019 remote_cisco_section_offsets (bfd_vma text_addr
,
2022 bfd_signed_vma
*text_offs
,
2023 bfd_signed_vma
*data_offs
,
2024 bfd_signed_vma
*bss_offs
)
2026 bfd_vma text_base
, data_base
, bss_base
;
2027 struct minimal_symbol
*start
;
2032 if (symfile_objfile
== NULL
)
2033 return -1; /* no can do nothin' */
2035 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
2037 return -1; /* Can't find "_start" symbol */
2039 data_base
= bss_base
= 0;
2040 text_base
= SYMBOL_VALUE_ADDRESS (start
);
2042 abfd
= symfile_objfile
->obfd
;
2043 for (sect
= abfd
->sections
;
2047 const char *p
= bfd_get_section_name (abfd
, sect
);
2049 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
2050 if (data_base
== 0 ||
2051 data_base
> bfd_get_section_vma (abfd
, sect
))
2052 data_base
= bfd_get_section_vma (abfd
, sect
);
2053 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
2054 if (bss_base
== 0 ||
2055 bss_base
> bfd_get_section_vma (abfd
, sect
))
2056 bss_base
= bfd_get_section_vma (abfd
, sect
);
2058 *text_offs
= text_addr
- text_base
;
2059 *data_offs
= data_addr
- data_base
;
2060 *bss_offs
= bss_addr
- bss_base
;
2065 sprintf (tmp
, "VMA: text = 0x");
2066 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
2067 sprintf (tmp
+ strlen (tmp
), " data = 0x");
2068 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
2069 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
2070 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
2071 fprintf_filtered (gdb_stdlog
, tmp
);
2072 fprintf_filtered (gdb_stdlog
,
2073 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
2074 paddr_nz (*text_offs
),
2075 paddr_nz (*data_offs
),
2076 paddr_nz (*bss_offs
));
2083 * Function: remote_cisco_objfile_relocate
2085 * Relocate the symbol file for a remote target.
2089 remote_cisco_objfile_relocate (bfd_signed_vma text_off
, bfd_signed_vma data_off
,
2090 bfd_signed_vma bss_off
)
2092 struct section_offsets
*offs
;
2094 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2096 /* FIXME: This code assumes gdb-stabs.h is being used; it's
2097 broken for xcoff, dwarf, sdb-coff, etc. But there is no
2098 simple canonical representation for this stuff. */
2100 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
2101 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
2103 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_off
;
2104 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_off
;
2105 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = bss_off
;
2107 /* First call the standard objfile_relocate. */
2108 objfile_relocate (symfile_objfile
, offs
);
2110 /* Now we need to fix up the section entries already attached to
2111 the exec target. These entries will control memory transfers
2112 from the exec file. */
2114 exec_set_section_offsets (text_off
, data_off
, bss_off
);
2118 /* Stub for catch_errors. */
2121 remote_start_remote_dummy (struct ui_out
*uiout
, void *dummy
)
2123 start_remote (); /* Initialize gdb process mechanisms */
2124 /* NOTE: Return something >=0. A -ve value is reserved for
2125 catch_exceptions. */
2130 remote_start_remote (struct ui_out
*uiout
, void *dummy
)
2132 immediate_quit
++; /* Allow user to interrupt it */
2134 /* Ack any packet which the remote side has already sent. */
2135 serial_write (remote_desc
, "+", 1);
2137 /* Let the stub know that we want it to return the thread. */
2140 inferior_ptid
= remote_current_thread (inferior_ptid
);
2142 get_offsets (); /* Get text, data & bss offsets */
2144 putpkt ("?"); /* initiate a query from remote machine */
2147 /* NOTE: See comment above in remote_start_remote_dummy(). This
2148 function returns something >=0. */
2149 return remote_start_remote_dummy (uiout
, dummy
);
2152 /* Open a connection to a remote debugger.
2153 NAME is the filename used for communication. */
2156 remote_open (char *name
, int from_tty
)
2158 remote_open_1 (name
, from_tty
, &remote_ops
, 0, 0);
2161 /* Just like remote_open, but with asynchronous support. */
2163 remote_async_open (char *name
, int from_tty
)
2165 remote_open_1 (name
, from_tty
, &remote_async_ops
, 0, 1);
2168 /* Open a connection to a remote debugger using the extended
2169 remote gdb protocol. NAME is the filename used for communication. */
2172 extended_remote_open (char *name
, int from_tty
)
2174 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */,
2178 /* Just like extended_remote_open, but with asynchronous support. */
2180 extended_remote_async_open (char *name
, int from_tty
)
2182 remote_open_1 (name
, from_tty
, &extended_async_remote_ops
,
2183 1 /*extended_p */, 1 /* async_p */);
2186 /* Generic code for opening a connection to a remote target. */
2189 init_all_packet_configs (void)
2192 update_packet_config (&remote_protocol_e
);
2193 update_packet_config (&remote_protocol_E
);
2194 update_packet_config (&remote_protocol_P
);
2195 update_packet_config (&remote_protocol_qSymbol
);
2196 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2197 update_packet_config (&remote_protocol_Z
[i
]);
2198 /* Force remote_write_bytes to check whether target supports binary
2200 update_packet_config (&remote_protocol_binary_download
);
2203 /* Symbol look-up. */
2206 remote_check_symbols (struct objfile
*objfile
)
2208 struct remote_state
*rs
= get_remote_state ();
2209 char *msg
, *reply
, *tmp
;
2210 struct minimal_symbol
*sym
;
2213 if (remote_protocol_qSymbol
.support
== PACKET_DISABLE
)
2216 msg
= alloca (rs
->remote_packet_size
);
2217 reply
= alloca (rs
->remote_packet_size
);
2219 /* Invite target to request symbol lookups. */
2221 putpkt ("qSymbol::");
2222 getpkt (reply
, (rs
->remote_packet_size
), 0);
2223 packet_ok (reply
, &remote_protocol_qSymbol
);
2225 while (strncmp (reply
, "qSymbol:", 8) == 0)
2228 end
= hex2bin (tmp
, msg
, strlen (tmp
) / 2);
2230 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2232 sprintf (msg
, "qSymbol::%s", &reply
[8]);
2234 sprintf (msg
, "qSymbol:%s:%s",
2235 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2238 getpkt (reply
, (rs
->remote_packet_size
), 0);
2242 static struct serial
*
2243 remote_serial_open (char *name
)
2245 static int udp_warning
= 0;
2247 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2248 of in ser-tcp.c, because it is the remote protocol assuming that the
2249 serial connection is reliable and not the serial connection promising
2251 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2253 warning ("The remote protocol may be unreliable over UDP.");
2254 warning ("Some events may be lost, rendering further debugging "
2259 return serial_open (name
);
2263 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2264 int extended_p
, int async_p
)
2267 struct remote_state
*rs
= get_remote_state ();
2269 error ("To open a remote debug connection, you need to specify what\n"
2270 "serial device is attached to the remote system\n"
2271 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2273 /* See FIXME above */
2275 wait_forever_enabled_p
= 1;
2277 target_preopen (from_tty
);
2279 unpush_target (target
);
2281 remote_desc
= remote_serial_open (name
);
2283 perror_with_name (name
);
2285 if (baud_rate
!= -1)
2287 if (serial_setbaudrate (remote_desc
, baud_rate
))
2289 serial_close (remote_desc
);
2290 perror_with_name (name
);
2294 serial_raw (remote_desc
);
2296 /* If there is something sitting in the buffer we might take it as a
2297 response to a command, which would be bad. */
2298 serial_flush_input (remote_desc
);
2302 puts_filtered ("Remote debugging using ");
2303 puts_filtered (name
);
2304 puts_filtered ("\n");
2306 push_target (target
); /* Switch to using remote target now */
2308 init_all_packet_configs ();
2310 general_thread
= -2;
2311 continue_thread
= -2;
2313 /* Probe for ability to use "ThreadInfo" query, as required. */
2314 use_threadinfo_query
= 1;
2315 use_threadextra_query
= 1;
2317 /* Without this, some commands which require an active target (such
2318 as kill) won't work. This variable serves (at least) double duty
2319 as both the pid of the target process (if it has such), and as a
2320 flag indicating that a target is active. These functions should
2321 be split out into seperate variables, especially since GDB will
2322 someday have a notion of debugging several processes. */
2324 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2328 /* With this target we start out by owning the terminal. */
2329 remote_async_terminal_ours_p
= 1;
2331 /* FIXME: cagney/1999-09-23: During the initial connection it is
2332 assumed that the target is already ready and able to respond to
2333 requests. Unfortunately remote_start_remote() eventually calls
2334 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2335 around this. Eventually a mechanism that allows
2336 wait_for_inferior() to expect/get timeouts will be
2338 wait_forever_enabled_p
= 0;
2341 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2342 /* First delete any symbols previously loaded from shared libraries. */
2343 no_shared_libraries (NULL
, 0);
2346 /* Start the remote connection. If error() or QUIT, discard this
2347 target (we'd otherwise be in an inconsistent state) and then
2348 propogate the error on up the exception chain. This ensures that
2349 the caller doesn't stumble along blindly assuming that the
2350 function succeeded. The CLI doesn't have this problem but other
2351 UI's, such as MI do.
2353 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2354 this function should return an error indication letting the
2355 caller restore the previous state. Unfortunatly the command
2356 ``target remote'' is directly wired to this function making that
2357 impossible. On a positive note, the CLI side of this problem has
2358 been fixed - the function set_cmd_context() makes it possible for
2359 all the ``target ....'' commands to share a common callback
2360 function. See cli-dump.c. */
2361 ex
= catch_exceptions (uiout
,
2362 remote_start_remote
, NULL
,
2363 "Couldn't establish connection to remote"
2370 wait_forever_enabled_p
= 1;
2371 throw_exception (ex
);
2375 wait_forever_enabled_p
= 1;
2379 /* Tell the remote that we are using the extended protocol. */
2380 char *buf
= alloca (rs
->remote_packet_size
);
2382 getpkt (buf
, (rs
->remote_packet_size
), 0);
2384 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2385 /* FIXME: need a master target_open vector from which all
2386 remote_opens can be called, so that stuff like this can
2387 go there. Failing that, the following code must be copied
2388 to the open function for any remote target that wants to
2389 support svr4 shared libraries. */
2391 /* Set up to detect and load shared libraries. */
2392 if (exec_bfd
) /* No use without an exec file. */
2394 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2395 remote_check_symbols (symfile_objfile
);
2400 /* This takes a program previously attached to and detaches it. After
2401 this is done, GDB can be used to debug some other program. We
2402 better not have left any breakpoints in the target program or it'll
2403 die when it hits one. */
2406 remote_detach (char *args
, int from_tty
)
2408 struct remote_state
*rs
= get_remote_state ();
2409 char *buf
= alloca (rs
->remote_packet_size
);
2412 error ("Argument given to \"detach\" when remotely debugging.");
2414 /* Tell the remote target to detach. */
2416 remote_send (buf
, (rs
->remote_packet_size
));
2418 target_mourn_inferior ();
2420 puts_filtered ("Ending remote debugging.\n");
2424 /* Same as remote_detach, but with async support. */
2426 remote_async_detach (char *args
, int from_tty
)
2428 struct remote_state
*rs
= get_remote_state ();
2429 char *buf
= alloca (rs
->remote_packet_size
);
2432 error ("Argument given to \"detach\" when remotely debugging.");
2434 /* Tell the remote target to detach. */
2436 remote_send (buf
, (rs
->remote_packet_size
));
2438 /* Unregister the file descriptor from the event loop. */
2439 if (target_is_async_p ())
2440 serial_async (remote_desc
, NULL
, 0);
2442 target_mourn_inferior ();
2444 puts_filtered ("Ending remote debugging.\n");
2447 /* Convert hex digit A to a number. */
2452 if (a
>= '0' && a
<= '9')
2454 else if (a
>= 'a' && a
<= 'f')
2455 return a
- 'a' + 10;
2456 else if (a
>= 'A' && a
<= 'F')
2457 return a
- 'A' + 10;
2459 error ("Reply contains invalid hex digit %d", a
);
2463 hex2bin (const char *hex
, char *bin
, int count
)
2467 for (i
= 0; i
< count
; i
++)
2469 if (hex
[0] == 0 || hex
[1] == 0)
2471 /* Hex string is short, or of uneven length.
2472 Return the count that has been converted so far. */
2475 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2481 /* Convert number NIB to a hex digit. */
2489 return 'a' + nib
- 10;
2493 bin2hex (const char *bin
, char *hex
, int count
)
2496 /* May use a length, or a nul-terminated string as input. */
2498 count
= strlen (bin
);
2500 for (i
= 0; i
< count
; i
++)
2502 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2503 *hex
++ = tohex (*bin
++ & 0xf);
2509 /* Tell the remote machine to resume. */
2511 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2513 static int last_sent_step
;
2516 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2518 struct remote_state
*rs
= get_remote_state ();
2519 char *buf
= alloca (rs
->remote_packet_size
);
2520 int pid
= PIDGET (ptid
);
2524 set_thread (0, 0); /* run any thread */
2526 set_thread (pid
, 0); /* run this thread */
2528 last_sent_signal
= siggnal
;
2529 last_sent_step
= step
;
2531 /* A hook for when we need to do something at the last moment before
2533 if (target_resume_hook
)
2534 (*target_resume_hook
) ();
2537 /* The s/S/c/C packets do not return status. So if the target does
2538 not support the S or C packets, the debug agent returns an empty
2539 string which is detected in remote_wait(). This protocol defect
2540 is fixed in the e/E packets. */
2542 if (step
&& step_range_end
)
2544 /* If the target does not support the 'E' packet, we try the 'S'
2545 packet. Ideally we would fall back to the 'e' packet if that
2546 too is not supported. But that would require another copy of
2547 the code to issue the 'e' packet (and fall back to 's' if not
2548 supported) in remote_wait(). */
2550 if (siggnal
!= TARGET_SIGNAL_0
)
2552 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2556 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2557 *p
++ = tohex (((int) siggnal
) & 0xf);
2559 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2561 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2565 getpkt (buf
, (rs
->remote_packet_size
), 0);
2567 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2573 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2577 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2579 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2583 getpkt (buf
, (rs
->remote_packet_size
), 0);
2585 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2591 if (siggnal
!= TARGET_SIGNAL_0
)
2593 buf
[0] = step
? 'S' : 'C';
2594 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2595 buf
[2] = tohex (((int) siggnal
) & 0xf);
2599 strcpy (buf
, step
? "s" : "c");
2604 /* Same as remote_resume, but with async support. */
2606 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2608 struct remote_state
*rs
= get_remote_state ();
2609 char *buf
= alloca (rs
->remote_packet_size
);
2610 int pid
= PIDGET (ptid
);
2614 set_thread (0, 0); /* run any thread */
2616 set_thread (pid
, 0); /* run this thread */
2618 last_sent_signal
= siggnal
;
2619 last_sent_step
= step
;
2621 /* A hook for when we need to do something at the last moment before
2623 if (target_resume_hook
)
2624 (*target_resume_hook
) ();
2626 /* The s/S/c/C packets do not return status. So if the target does
2627 not support the S or C packets, the debug agent returns an empty
2628 string which is detected in remote_wait(). This protocol defect
2629 is fixed in the e/E packets. */
2631 if (step
&& step_range_end
)
2633 /* If the target does not support the 'E' packet, we try the 'S'
2634 packet. Ideally we would fall back to the 'e' packet if that
2635 too is not supported. But that would require another copy of
2636 the code to issue the 'e' packet (and fall back to 's' if not
2637 supported) in remote_wait(). */
2639 if (siggnal
!= TARGET_SIGNAL_0
)
2641 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2645 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2646 *p
++ = tohex (((int) siggnal
) & 0xf);
2648 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2650 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2654 getpkt (buf
, (rs
->remote_packet_size
), 0);
2656 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2657 goto register_event_loop
;
2662 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2666 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2668 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2672 getpkt (buf
, (rs
->remote_packet_size
), 0);
2674 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2675 goto register_event_loop
;
2680 if (siggnal
!= TARGET_SIGNAL_0
)
2682 buf
[0] = step
? 'S' : 'C';
2683 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2684 buf
[2] = tohex ((int) siggnal
& 0xf);
2688 strcpy (buf
, step
? "s" : "c");
2692 register_event_loop
:
2693 /* We are about to start executing the inferior, let's register it
2694 with the event loop. NOTE: this is the one place where all the
2695 execution commands end up. We could alternatively do this in each
2696 of the execution commands in infcmd.c.*/
2697 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2698 into infcmd.c in order to allow inferior function calls to work
2699 NOT asynchronously. */
2700 if (event_loop_p
&& target_can_async_p ())
2701 target_async (inferior_event_handler
, 0);
2702 /* Tell the world that the target is now executing. */
2703 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2704 this? Instead, should the client of target just assume (for
2705 async targets) that the target is going to start executing? Is
2706 this information already found in the continuation block? */
2707 if (target_is_async_p ())
2708 target_executing
= 1;
2712 /* Set up the signal handler for SIGINT, while the target is
2713 executing, ovewriting the 'regular' SIGINT signal handler. */
2715 initialize_sigint_signal_handler (void)
2717 sigint_remote_token
=
2718 create_async_signal_handler (async_remote_interrupt
, NULL
);
2719 signal (SIGINT
, handle_remote_sigint
);
2722 /* Signal handler for SIGINT, while the target is executing. */
2724 handle_remote_sigint (int sig
)
2726 signal (sig
, handle_remote_sigint_twice
);
2727 sigint_remote_twice_token
=
2728 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2729 mark_async_signal_handler_wrapper (sigint_remote_token
);
2732 /* Signal handler for SIGINT, installed after SIGINT has already been
2733 sent once. It will take effect the second time that the user sends
2736 handle_remote_sigint_twice (int sig
)
2738 signal (sig
, handle_sigint
);
2739 sigint_remote_twice_token
=
2740 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2741 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2744 /* Perform the real interruption of the target execution, in response
2747 async_remote_interrupt (gdb_client_data arg
)
2750 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2755 /* Perform interrupt, if the first attempt did not succeed. Just give
2756 up on the target alltogether. */
2758 async_remote_interrupt_twice (gdb_client_data arg
)
2761 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2762 /* Do something only if the target was not killed by the previous
2764 if (target_executing
)
2767 signal (SIGINT
, handle_remote_sigint
);
2771 /* Reinstall the usual SIGINT handlers, after the target has
2774 cleanup_sigint_signal_handler (void *dummy
)
2776 signal (SIGINT
, handle_sigint
);
2777 if (sigint_remote_twice_token
)
2778 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2779 if (sigint_remote_token
)
2780 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2783 /* Send ^C to target to halt it. Target will respond, and send us a
2785 static void (*ofunc
) (int);
2787 /* The command line interface's stop routine. This function is installed
2788 as a signal handler for SIGINT. The first time a user requests a
2789 stop, we call remote_stop to send a break or ^C. If there is no
2790 response from the target (it didn't stop when the user requested it),
2791 we ask the user if he'd like to detach from the target. */
2793 remote_interrupt (int signo
)
2795 /* If this doesn't work, try more severe steps. */
2796 signal (signo
, remote_interrupt_twice
);
2799 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2804 /* The user typed ^C twice. */
2807 remote_interrupt_twice (int signo
)
2809 signal (signo
, ofunc
);
2811 signal (signo
, remote_interrupt
);
2814 /* This is the generic stop called via the target vector. When a target
2815 interrupt is requested, either by the command line or the GUI, we
2816 will eventually end up here. */
2820 /* Send a break or a ^C, depending on user preference. */
2822 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2825 serial_send_break (remote_desc
);
2827 serial_write (remote_desc
, "\003", 1);
2830 /* Ask the user what to do when an interrupt is received. */
2833 interrupt_query (void)
2835 target_terminal_ours ();
2837 if (query ("Interrupted while waiting for the program.\n\
2838 Give up (and stop debugging it)? "))
2840 target_mourn_inferior ();
2841 throw_exception (RETURN_QUIT
);
2844 target_terminal_inferior ();
2847 /* Enable/disable target terminal ownership. Most targets can use
2848 terminal groups to control terminal ownership. Remote targets are
2849 different in that explicit transfer of ownership to/from GDB/target
2853 remote_async_terminal_inferior (void)
2855 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2856 sync_execution here. This function should only be called when
2857 GDB is resuming the inferior in the forground. A background
2858 resume (``run&'') should leave GDB in control of the terminal and
2859 consequently should not call this code. */
2860 if (!sync_execution
)
2862 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2863 calls target_terminal_*() idenpotent. The event-loop GDB talking
2864 to an asynchronous target with a synchronous command calls this
2865 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2866 stops trying to transfer the terminal to the target when it
2867 shouldn't this guard can go away. */
2868 if (!remote_async_terminal_ours_p
)
2870 delete_file_handler (input_fd
);
2871 remote_async_terminal_ours_p
= 0;
2872 initialize_sigint_signal_handler ();
2873 /* NOTE: At this point we could also register our selves as the
2874 recipient of all input. Any characters typed could then be
2875 passed on down to the target. */
2879 remote_async_terminal_ours (void)
2881 /* See FIXME in remote_async_terminal_inferior. */
2882 if (!sync_execution
)
2884 /* See FIXME in remote_async_terminal_inferior. */
2885 if (remote_async_terminal_ours_p
)
2887 cleanup_sigint_signal_handler (NULL
);
2888 add_file_handler (input_fd
, stdin_event_handler
, 0);
2889 remote_async_terminal_ours_p
= 1;
2892 /* If nonzero, ignore the next kill. */
2897 remote_console_output (char *msg
)
2901 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2904 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2907 fputs_unfiltered (tb
, gdb_stdtarg
);
2909 gdb_flush (gdb_stdtarg
);
2912 /* Wait until the remote machine stops, then return,
2913 storing status in STATUS just as `wait' would.
2914 Returns "pid", which in the case of a multi-threaded
2915 remote OS, is the thread-id. */
2918 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2920 struct remote_state
*rs
= get_remote_state ();
2921 unsigned char *buf
= alloca (rs
->remote_packet_size
);
2922 ULONGEST thread_num
= -1;
2925 status
->kind
= TARGET_WAITKIND_EXITED
;
2926 status
->value
.integer
= 0;
2932 ofunc
= signal (SIGINT
, remote_interrupt
);
2933 getpkt (buf
, (rs
->remote_packet_size
), 1);
2934 signal (SIGINT
, ofunc
);
2936 /* This is a hook for when we need to do something (perhaps the
2937 collection of trace data) every time the target stops. */
2938 if (target_wait_loop_hook
)
2939 (*target_wait_loop_hook
) ();
2941 remote_stopped_by_watchpoint_p
= 0;
2945 case 'E': /* Error of some sort */
2946 warning ("Remote failure reply: %s", buf
);
2948 case 'T': /* Status with PC, SP, FP, ... */
2951 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
2953 /* Expedited reply, containing Signal, {regno, reg} repeat */
2954 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2956 n... = register number
2957 r... = register contents
2959 p
= &buf
[3]; /* after Txx */
2968 /* If the packet contains a register number save it in pnum
2969 and set p1 to point to the character following it.
2970 Otherwise p1 points to p. */
2972 /* If this packet is an awatch packet, don't parse the 'a'
2973 as a register number. */
2975 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
2977 /* Read the ``P'' register number. */
2978 pnum
= strtol (p
, &p_temp
, 16);
2979 p1
= (unsigned char *) p_temp
;
2984 if (p1
== p
) /* No register number present here */
2986 p1
= (unsigned char *) strchr (p
, ':');
2988 warning ("Malformed packet(a) (missing colon): %s\n\
2991 if (strncmp (p
, "thread", p1
- p
) == 0)
2993 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2994 record_currthread (thread_num
);
2995 p
= (unsigned char *) p_temp
;
2997 else if ((strncmp (p
, "watch", p1
- p
) == 0)
2998 || (strncmp (p
, "rwatch", p1
- p
) == 0)
2999 || (strncmp (p
, "awatch", p1
- p
) == 0))
3001 remote_stopped_by_watchpoint_p
= 1;
3002 p
= unpack_varlen_hex (++p1
, &addr
);
3003 remote_watch_data_address
= (CORE_ADDR
)addr
;
3007 /* Silently skip unknown optional info. */
3008 p_temp
= strchr (p1
+ 1, ';');
3010 p
= (unsigned char *) p_temp
;
3015 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3019 warning ("Malformed packet(b) (missing colon): %s\n\
3024 warning ("Remote sent bad register number %s: %s\n\
3026 phex_nz (pnum
, 0), p
, buf
);
3028 fieldsize
= hex2bin (p
, regs
, REGISTER_RAW_SIZE (reg
->regnum
));
3030 if (fieldsize
< REGISTER_RAW_SIZE (reg
->regnum
))
3031 warning ("Remote reply is too short: %s", buf
);
3032 supply_register (reg
->regnum
, regs
);
3037 warning ("Remote register badly formatted: %s", buf
);
3038 warning (" here: %s", p
);
3043 case 'S': /* Old style status, just signal only */
3044 status
->kind
= TARGET_WAITKIND_STOPPED
;
3045 status
->value
.sig
= (enum target_signal
)
3046 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3050 /* Export Cisco kernel mode as a convenience variable
3051 (so that it can be used in the GDB prompt if desired). */
3053 if (cisco_kernel_mode
== 1)
3054 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3055 value_from_string ("PDEBUG-"));
3056 cisco_kernel_mode
= 0;
3057 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3058 record_currthread (thread_num
);
3060 else if (buf
[3] == 'k')
3062 /* Export Cisco kernel mode as a convenience variable
3063 (so that it can be used in the GDB prompt if desired). */
3065 if (cisco_kernel_mode
== 1)
3066 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3067 value_from_string ("KDEBUG-"));
3068 cisco_kernel_mode
= 1;
3071 case 'N': /* Cisco special: status and offsets */
3073 bfd_vma text_addr
, data_addr
, bss_addr
;
3074 bfd_signed_vma text_off
, data_off
, bss_off
;
3077 status
->kind
= TARGET_WAITKIND_STOPPED
;
3078 status
->value
.sig
= (enum target_signal
)
3079 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3081 if (symfile_objfile
== NULL
)
3083 warning ("Relocation packet received with no symbol file. \
3088 /* Relocate object file. Buffer format is NAATT;DD;BB
3089 * where AA is the signal number, TT is the new text
3090 * address, DD * is the new data address, and BB is the
3091 * new bss address. */
3094 text_addr
= strtoul (p
, (char **) &p1
, 16);
3095 if (p1
== p
|| *p1
!= ';')
3096 warning ("Malformed relocation packet: Packet '%s'", buf
);
3098 data_addr
= strtoul (p
, (char **) &p1
, 16);
3099 if (p1
== p
|| *p1
!= ';')
3100 warning ("Malformed relocation packet: Packet '%s'", buf
);
3102 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3104 warning ("Malformed relocation packet: Packet '%s'", buf
);
3106 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3107 &text_off
, &data_off
, &bss_off
)
3109 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3110 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3114 case 'W': /* Target exited */
3116 /* The remote process exited. */
3117 status
->kind
= TARGET_WAITKIND_EXITED
;
3118 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3122 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3123 status
->value
.sig
= (enum target_signal
)
3124 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3128 case 'O': /* Console output */
3129 remote_console_output (buf
+ 1);
3132 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3134 /* Zero length reply means that we tried 'S' or 'C' and
3135 the remote system doesn't support it. */
3136 target_terminal_ours_for_output ();
3138 ("Can't send signals to this remote system. %s not sent.\n",
3139 target_signal_to_name (last_sent_signal
));
3140 last_sent_signal
= TARGET_SIGNAL_0
;
3141 target_terminal_inferior ();
3143 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3144 putpkt ((char *) buf
);
3147 /* else fallthrough */
3149 warning ("Invalid remote reply: %s", buf
);
3154 if (thread_num
!= -1)
3156 return pid_to_ptid (thread_num
);
3158 return inferior_ptid
;
3161 /* Async version of remote_wait. */
3163 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3165 struct remote_state
*rs
= get_remote_state ();
3166 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3167 ULONGEST thread_num
= -1;
3170 status
->kind
= TARGET_WAITKIND_EXITED
;
3171 status
->value
.integer
= 0;
3173 remote_stopped_by_watchpoint_p
= 0;
3179 if (!target_is_async_p ())
3180 ofunc
= signal (SIGINT
, remote_interrupt
);
3181 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3182 _never_ wait for ever -> test on target_is_async_p().
3183 However, before we do that we need to ensure that the caller
3184 knows how to take the target into/out of async mode. */
3185 getpkt (buf
, (rs
->remote_packet_size
), wait_forever_enabled_p
);
3186 if (!target_is_async_p ())
3187 signal (SIGINT
, ofunc
);
3189 /* This is a hook for when we need to do something (perhaps the
3190 collection of trace data) every time the target stops. */
3191 if (target_wait_loop_hook
)
3192 (*target_wait_loop_hook
) ();
3196 case 'E': /* Error of some sort */
3197 warning ("Remote failure reply: %s", buf
);
3199 case 'T': /* Status with PC, SP, FP, ... */
3202 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
3204 /* Expedited reply, containing Signal, {regno, reg} repeat */
3205 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3207 n... = register number
3208 r... = register contents
3210 p
= &buf
[3]; /* after Txx */
3219 /* If the packet contains a register number, save it in pnum
3220 and set p1 to point to the character following it.
3221 Otherwise p1 points to p. */
3223 /* If this packet is an awatch packet, don't parse the 'a'
3224 as a register number. */
3226 if (!strncmp (p
, "awatch", strlen ("awatch")) != 0)
3228 /* Read the register number. */
3229 pnum
= strtol (p
, &p_temp
, 16);
3230 p1
= (unsigned char *) p_temp
;
3235 if (p1
== p
) /* No register number present here */
3237 p1
= (unsigned char *) strchr (p
, ':');
3239 warning ("Malformed packet(a) (missing colon): %s\n\
3242 if (strncmp (p
, "thread", p1
- p
) == 0)
3244 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3245 record_currthread (thread_num
);
3246 p
= (unsigned char *) p_temp
;
3248 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3249 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3250 || (strncmp (p
, "awatch", p1
- p
) == 0))
3252 remote_stopped_by_watchpoint_p
= 1;
3253 p
= unpack_varlen_hex (++p1
, &addr
);
3254 remote_watch_data_address
= (CORE_ADDR
)addr
;
3258 /* Silently skip unknown optional info. */
3259 p_temp
= (unsigned char *) strchr (p1
+ 1, ';');
3267 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3270 warning ("Malformed packet(b) (missing colon): %s\n\
3275 warning ("Remote sent bad register number %ld: %s\n\
3279 fieldsize
= hex2bin (p
, regs
, REGISTER_RAW_SIZE (reg
->regnum
));
3281 if (fieldsize
< REGISTER_RAW_SIZE (reg
->regnum
))
3282 warning ("Remote reply is too short: %s", buf
);
3283 supply_register (reg
->regnum
, regs
);
3288 warning ("Remote register badly formatted: %s", buf
);
3289 warning (" here: %s", p
);
3294 case 'S': /* Old style status, just signal only */
3295 status
->kind
= TARGET_WAITKIND_STOPPED
;
3296 status
->value
.sig
= (enum target_signal
)
3297 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3301 /* Export Cisco kernel mode as a convenience variable
3302 (so that it can be used in the GDB prompt if desired). */
3304 if (cisco_kernel_mode
== 1)
3305 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3306 value_from_string ("PDEBUG-"));
3307 cisco_kernel_mode
= 0;
3308 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3309 record_currthread (thread_num
);
3311 else if (buf
[3] == 'k')
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 ("KDEBUG-"));
3319 cisco_kernel_mode
= 1;
3322 case 'N': /* Cisco special: status and offsets */
3324 bfd_vma text_addr
, data_addr
, bss_addr
;
3325 bfd_signed_vma text_off
, data_off
, bss_off
;
3328 status
->kind
= TARGET_WAITKIND_STOPPED
;
3329 status
->value
.sig
= (enum target_signal
)
3330 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3332 if (symfile_objfile
== NULL
)
3334 warning ("Relocation packet recieved with no symbol file. \
3339 /* Relocate object file. Buffer format is NAATT;DD;BB
3340 * where AA is the signal number, TT is the new text
3341 * address, DD * is the new data address, and BB is the
3342 * new bss address. */
3345 text_addr
= strtoul (p
, (char **) &p1
, 16);
3346 if (p1
== p
|| *p1
!= ';')
3347 warning ("Malformed relocation packet: Packet '%s'", buf
);
3349 data_addr
= strtoul (p
, (char **) &p1
, 16);
3350 if (p1
== p
|| *p1
!= ';')
3351 warning ("Malformed relocation packet: Packet '%s'", buf
);
3353 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3355 warning ("Malformed relocation packet: Packet '%s'", buf
);
3357 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3358 &text_off
, &data_off
, &bss_off
)
3360 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3361 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3365 case 'W': /* Target exited */
3367 /* The remote process exited. */
3368 status
->kind
= TARGET_WAITKIND_EXITED
;
3369 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3373 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3374 status
->value
.sig
= (enum target_signal
)
3375 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3379 case 'O': /* Console output */
3380 remote_console_output (buf
+ 1);
3381 /* Return immediately to the event loop. The event loop will
3382 still be waiting on the inferior afterwards. */
3383 status
->kind
= TARGET_WAITKIND_IGNORE
;
3386 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3388 /* Zero length reply means that we tried 'S' or 'C' and
3389 the remote system doesn't support it. */
3390 target_terminal_ours_for_output ();
3392 ("Can't send signals to this remote system. %s not sent.\n",
3393 target_signal_to_name (last_sent_signal
));
3394 last_sent_signal
= TARGET_SIGNAL_0
;
3395 target_terminal_inferior ();
3397 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3398 putpkt ((char *) buf
);
3401 /* else fallthrough */
3403 warning ("Invalid remote reply: %s", buf
);
3408 if (thread_num
!= -1)
3410 return pid_to_ptid (thread_num
);
3412 return inferior_ptid
;
3415 /* Number of bytes of registers this stub implements. */
3417 static int register_bytes_found
;
3419 /* Read the remote registers into the block REGS. */
3420 /* Currently we just read all the registers, so we don't use regnum. */
3424 remote_fetch_registers (int regnum
)
3426 struct remote_state
*rs
= get_remote_state ();
3427 char *buf
= alloca (rs
->remote_packet_size
);
3430 char *regs
= alloca (rs
->sizeof_g_packet
);
3432 set_thread (PIDGET (inferior_ptid
), 1);
3436 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3437 gdb_assert (reg
!= NULL
);
3438 if (!reg
->in_g_packet
)
3439 internal_error (__FILE__
, __LINE__
,
3440 "Attempt to fetch a non G-packet register when this "
3441 "remote.c does not support the p-packet.");
3445 remote_send (buf
, (rs
->remote_packet_size
));
3447 /* Save the size of the packet sent to us by the target. Its used
3448 as a heuristic when determining the max size of packets that the
3449 target can safely receive. */
3450 if ((rs
->actual_register_packet_size
) == 0)
3451 (rs
->actual_register_packet_size
) = strlen (buf
);
3453 /* Unimplemented registers read as all bits zero. */
3454 memset (regs
, 0, rs
->sizeof_g_packet
);
3456 /* We can get out of synch in various cases. If the first character
3457 in the buffer is not a hex character, assume that has happened
3458 and try to fetch another packet to read. */
3459 while ((buf
[0] < '0' || buf
[0] > '9')
3460 && (buf
[0] < 'a' || buf
[0] > 'f')
3461 && buf
[0] != 'x') /* New: unavailable register value */
3464 fprintf_unfiltered (gdb_stdlog
,
3465 "Bad register packet; fetching a new packet\n");
3466 getpkt (buf
, (rs
->remote_packet_size
), 0);
3469 /* Reply describes registers byte by byte, each byte encoded as two
3470 hex characters. Suck them all up, then supply them to the
3471 register cacheing/storage mechanism. */
3474 for (i
= 0; i
< rs
->sizeof_g_packet
; i
++)
3480 warning ("Remote reply is of odd length: %s", buf
);
3481 /* Don't change register_bytes_found in this case, and don't
3482 print a second warning. */
3485 if (p
[0] == 'x' && p
[1] == 'x')
3486 regs
[i
] = 0; /* 'x' */
3488 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3492 if (i
!= register_bytes_found
)
3494 register_bytes_found
= i
;
3495 if (REGISTER_BYTES_OK_P ()
3496 && !REGISTER_BYTES_OK (i
))
3497 warning ("Remote reply is too short: %s", buf
);
3503 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3505 struct packet_reg
*r
= &rs
->regs
[i
];
3508 supply_register (r
->regnum
, regs
+ r
->offset
);
3509 if (buf
[r
->offset
* 2] == 'x')
3510 set_register_cached (i
, -1);
3516 /* Prepare to store registers. Since we may send them all (using a
3517 'G' request), we have to read out the ones we don't want to change
3521 remote_prepare_to_store (void)
3523 /* Make sure the entire registers array is valid. */
3524 switch (remote_protocol_P
.support
)
3526 case PACKET_DISABLE
:
3527 case PACKET_SUPPORT_UNKNOWN
:
3528 /* NOTE: This isn't rs->sizeof_g_packet because here, we are
3529 forcing the register cache to read its and not the target
3531 read_register_bytes (0, (char *) NULL
, REGISTER_BYTES
); /* OK use. */
3538 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3539 packet was not recognized. */
3542 store_register_using_P (int regnum
)
3544 struct remote_state
*rs
= get_remote_state ();
3545 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3546 /* Try storing a single register. */
3547 char *buf
= alloca (rs
->remote_packet_size
);
3548 char *regp
= alloca (MAX_REGISTER_RAW_SIZE
);
3552 sprintf (buf
, "P%s=", phex_nz (reg
->pnum
, 0));
3553 p
= buf
+ strlen (buf
);
3554 regcache_collect (reg
->regnum
, regp
);
3555 bin2hex (regp
, p
, REGISTER_RAW_SIZE (reg
->regnum
));
3556 remote_send (buf
, rs
->remote_packet_size
);
3558 return buf
[0] != '\0';
3562 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
3563 of the register cache buffer. FIXME: ignores errors. */
3566 remote_store_registers (int regnum
)
3568 struct remote_state
*rs
= get_remote_state ();
3574 set_thread (PIDGET (inferior_ptid
), 1);
3578 switch (remote_protocol_P
.support
)
3580 case PACKET_DISABLE
:
3583 if (store_register_using_P (regnum
))
3586 error ("Protocol error: P packet not recognized by stub");
3587 case PACKET_SUPPORT_UNKNOWN
:
3588 if (store_register_using_P (regnum
))
3590 /* The stub recognized the 'P' packet. Remember this. */
3591 remote_protocol_P
.support
= PACKET_ENABLE
;
3596 /* The stub does not support the 'P' packet. Use 'G'
3597 instead, and don't try using 'P' in the future (it
3598 will just waste our time). */
3599 remote_protocol_P
.support
= PACKET_DISABLE
;
3605 /* Extract all the registers in the regcache copying them into a
3609 regs
= alloca (rs
->sizeof_g_packet
);
3610 memset (regs
, rs
->sizeof_g_packet
, 0);
3611 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3613 struct packet_reg
*r
= &rs
->regs
[i
];
3615 regcache_collect (r
->regnum
, regs
+ r
->offset
);
3619 /* Command describes registers byte by byte,
3620 each byte encoded as two hex characters. */
3621 buf
= alloca (rs
->remote_packet_size
);
3624 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3625 bin2hex (regs
, p
, register_bytes_found
);
3626 remote_send (buf
, (rs
->remote_packet_size
));
3630 /* Return the number of hex digits in num. */
3633 hexnumlen (ULONGEST num
)
3637 for (i
= 0; num
!= 0; i
++)
3643 /* Set BUF to the minimum number of hex digits representing NUM. */
3646 hexnumstr (char *buf
, ULONGEST num
)
3648 int len
= hexnumlen (num
);
3649 return hexnumnstr (buf
, num
, len
);
3653 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3656 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3662 for (i
= width
- 1; i
>= 0; i
--)
3664 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3671 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3674 remote_address_masked (CORE_ADDR addr
)
3676 if (remote_address_size
> 0
3677 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3679 /* Only create a mask when that mask can safely be constructed
3680 in a ULONGEST variable. */
3682 mask
= (mask
<< remote_address_size
) - 1;
3688 /* Determine whether the remote target supports binary downloading.
3689 This is accomplished by sending a no-op memory write of zero length
3690 to the target at the specified address. It does not suffice to send
3691 the whole packet, since many stubs strip the eighth bit and subsequently
3692 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3694 NOTE: This can still lose if the serial line is not eight-bit
3695 clean. In cases like this, the user should clear "remote
3699 check_binary_download (CORE_ADDR addr
)
3701 struct remote_state
*rs
= get_remote_state ();
3702 switch (remote_protocol_binary_download
.support
)
3704 case PACKET_DISABLE
:
3708 case PACKET_SUPPORT_UNKNOWN
:
3710 char *buf
= alloca (rs
->remote_packet_size
);
3715 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3717 p
+= hexnumstr (p
, (ULONGEST
) 0);
3721 putpkt_binary (buf
, (int) (p
- buf
));
3722 getpkt (buf
, (rs
->remote_packet_size
), 0);
3727 fprintf_unfiltered (gdb_stdlog
,
3728 "binary downloading NOT suppported by target\n");
3729 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3734 fprintf_unfiltered (gdb_stdlog
,
3735 "binary downloading suppported by target\n");
3736 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3743 /* Write memory data directly to the remote machine.
3744 This does not inform the data cache; the data cache uses this.
3745 MEMADDR is the address in the remote memory space.
3746 MYADDR is the address of the buffer in our space.
3747 LEN is the number of bytes.
3749 Returns number of bytes transferred, or 0 (setting errno) for
3750 error. Only transfer a single packet. */
3753 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3756 int max_buf_size
; /* Max size of packet output buffer */
3758 unsigned char *plen
;
3764 /* Verify that the target can support a binary download */
3765 check_binary_download (memaddr
);
3767 /* Determine the max packet size. */
3768 max_buf_size
= get_memory_write_packet_size ();
3769 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3770 buf
= alloca (sizeof_buf
);
3772 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3773 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
3775 /* construct "M"<memaddr>","<len>":" */
3776 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3779 /* Append [XM]. Compute a best guess of the number of bytes
3780 actually transfered. */
3781 switch (remote_protocol_binary_download
.support
)
3785 /* Best guess at number of bytes that will fit. */
3786 todo
= min (len
, max_buf_size
);
3788 case PACKET_DISABLE
:
3790 /* num bytes that will fit */
3791 todo
= min (len
, max_buf_size
/ 2);
3793 case PACKET_SUPPORT_UNKNOWN
:
3794 internal_error (__FILE__
, __LINE__
,
3795 "remote_write_bytes: bad internal state");
3797 internal_error (__FILE__
, __LINE__
, "bad switch");
3800 /* Append <memaddr> */
3801 memaddr
= remote_address_masked (memaddr
);
3802 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3805 /* Append <len>. Retain the location/size of <len>. It may
3806 need to be adjusted once the packet body has been created. */
3808 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3813 /* Append the packet body. */
3814 switch (remote_protocol_binary_download
.support
)
3817 /* Binary mode. Send target system values byte by byte, in
3818 increasing byte addresses. Only escape certain critical
3821 (nr_bytes
< todo
) && (p
- buf
) < (max_buf_size
- 2);
3824 switch (myaddr
[nr_bytes
] & 0xff)
3829 /* These must be escaped */
3831 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3834 *p
++ = myaddr
[nr_bytes
] & 0xff;
3838 if (nr_bytes
< todo
)
3840 /* Escape chars have filled up the buffer prematurely,
3841 and we have actually sent fewer bytes than planned.
3842 Fix-up the length field of the packet. Use the same
3843 number of characters as before. */
3845 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3846 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3849 case PACKET_DISABLE
:
3850 /* Normal mode: Send target system values byte by byte, in
3851 increasing byte addresses. Each byte is encoded as a two hex
3853 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3856 case PACKET_SUPPORT_UNKNOWN
:
3857 internal_error (__FILE__
, __LINE__
,
3858 "remote_write_bytes: bad internal state");
3860 internal_error (__FILE__
, __LINE__
, "bad switch");
3863 putpkt_binary (buf
, (int) (p
- buf
));
3864 getpkt (buf
, sizeof_buf
, 0);
3868 /* There is no correspondance between what the remote protocol
3869 uses for errors and errno codes. We would like a cleaner way
3870 of representing errors (big enough to include errno codes,
3871 bfd_error codes, and others). But for now just return EIO. */
3876 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3877 bytes than we'd planned. */
3881 /* Read memory data directly from the remote machine.
3882 This does not use the data cache; the data cache uses this.
3883 MEMADDR is the address in the remote memory space.
3884 MYADDR is the address of the buffer in our space.
3885 LEN is the number of bytes.
3887 Returns number of bytes transferred, or 0 for error. */
3889 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3890 remote targets) shouldn't attempt to read the entire buffer.
3891 Instead it should read a single packet worth of data and then
3892 return the byte size of that packet to the caller. The caller (its
3893 caller and its callers caller ;-) already contains code for
3894 handling partial reads. */
3897 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3900 int max_buf_size
; /* Max size of packet output buffer */
3904 /* Create a buffer big enough for this packet. */
3905 max_buf_size
= get_memory_read_packet_size ();
3906 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3907 buf
= alloca (sizeof_buf
);
3916 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3918 /* construct "m"<memaddr>","<len>" */
3919 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3920 memaddr
= remote_address_masked (memaddr
);
3923 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3925 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3929 getpkt (buf
, sizeof_buf
, 0);
3932 && isxdigit (buf
[1]) && isxdigit (buf
[2])
3935 /* There is no correspondance between what the remote protocol uses
3936 for errors and errno codes. We would like a cleaner way of
3937 representing errors (big enough to include errno codes, bfd_error
3938 codes, and others). But for now just return EIO. */
3943 /* Reply describes memory byte by byte,
3944 each byte encoded as two hex characters. */
3947 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
3949 /* Reply is short. This means that we were able to read
3950 only part of what we wanted to. */
3951 return i
+ (origlen
- len
);
3960 /* Read or write LEN bytes from inferior memory at MEMADDR,
3961 transferring to or from debugger address BUFFER. Write to inferior if
3962 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3963 for error. TARGET is unused. */
3967 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
3968 int should_write
, struct mem_attrib
*attrib
,
3969 struct target_ops
*target
)
3971 CORE_ADDR targ_addr
;
3975 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr
, mem_len
, &targ_addr
, &targ_len
);
3980 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
3982 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
3989 /* Enable after 4.12. */
3992 remote_search (int len
, char *data
, char *mask
, CORE_ADDR startaddr
,
3993 int increment
, CORE_ADDR lorange
, CORE_ADDR hirange
,
3994 CORE_ADDR
*addr_found
, char *data_found
)
3996 if (increment
== -4 && len
== 4)
3998 long mask_long
, data_long
;
3999 long data_found_long
;
4000 CORE_ADDR addr_we_found
;
4001 char *buf
= alloca (rs
->remote_packet_size
);
4002 long returned_long
[2];
4005 mask_long
= extract_unsigned_integer (mask
, len
);
4006 data_long
= extract_unsigned_integer (data
, len
);
4007 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
4009 getpkt (buf
, (rs
->remote_packet_size
), 0);
4012 /* The stub doesn't support the 't' request. We might want to
4013 remember this fact, but on the other hand the stub could be
4014 switched on us. Maybe we should remember it only until
4015 the next "target remote". */
4016 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
4017 hirange
, addr_found
, data_found
);
4022 /* There is no correspondance between what the remote protocol uses
4023 for errors and errno codes. We would like a cleaner way of
4024 representing errors (big enough to include errno codes, bfd_error
4025 codes, and others). But for now just use EIO. */
4026 memory_error (EIO
, startaddr
);
4029 while (*p
!= '\0' && *p
!= ',')
4030 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
4032 error ("Protocol error: short return for search");
4034 data_found_long
= 0;
4035 while (*p
!= '\0' && *p
!= ',')
4036 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
4037 /* Ignore anything after this comma, for future extensions. */
4039 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
4045 *addr_found
= addr_we_found
;
4046 *data_found
= store_unsigned_integer (data_we_found
, len
);
4049 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
4050 hirange
, addr_found
, data_found
);
4055 remote_files_info (struct target_ops
*ignore
)
4057 puts_filtered ("Debugging a target over a serial line.\n");
4060 /* Stuff for dealing with the packets which are part of this protocol.
4061 See comment at top of file for details. */
4063 /* Read a single character from the remote end, masking it down to 7 bits. */
4066 readchar (int timeout
)
4070 ch
= serial_readchar (remote_desc
, timeout
);
4075 switch ((enum serial_rc
) ch
)
4078 target_mourn_inferior ();
4079 error ("Remote connection closed");
4082 perror_with_name ("Remote communication error");
4084 case SERIAL_TIMEOUT
:
4090 /* Send the command in BUF to the remote machine, and read the reply
4091 into BUF. Report an error if we get an error reply. */
4094 remote_send (char *buf
,
4098 getpkt (buf
, sizeof_buf
, 0);
4101 error ("Remote failure reply: %s", buf
);
4104 /* Display a null-terminated packet on stdout, for debugging, using C
4108 print_packet (char *buf
)
4110 puts_filtered ("\"");
4111 fputstr_filtered (buf
, '"', gdb_stdout
);
4112 puts_filtered ("\"");
4118 return putpkt_binary (buf
, strlen (buf
));
4121 /* Send a packet to the remote machine, with error checking. The data
4122 of the packet is in BUF. The string in BUF can be at most (rs->remote_packet_size) - 5
4123 to account for the $, # and checksum, and for a possible /0 if we are
4124 debugging (remote_debug) and want to print the sent packet as a string */
4127 putpkt_binary (char *buf
, int cnt
)
4129 struct remote_state
*rs
= get_remote_state ();
4131 unsigned char csum
= 0;
4132 char *buf2
= alloca (cnt
+ 6);
4133 long sizeof_junkbuf
= (rs
->remote_packet_size
);
4134 char *junkbuf
= alloca (sizeof_junkbuf
);
4140 /* Copy the packet into buffer BUF2, encapsulating it
4141 and giving it a checksum. */
4146 for (i
= 0; i
< cnt
; i
++)
4152 *p
++ = tohex ((csum
>> 4) & 0xf);
4153 *p
++ = tohex (csum
& 0xf);
4155 /* Send it over and over until we get a positive ack. */
4159 int started_error_output
= 0;
4164 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4165 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4166 fprintf_unfiltered (gdb_stdlog
, "...");
4167 gdb_flush (gdb_stdlog
);
4169 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4170 perror_with_name ("putpkt: write failed");
4172 /* read until either a timeout occurs (-2) or '+' is read */
4175 ch
= readchar (remote_timeout
);
4183 case SERIAL_TIMEOUT
:
4185 if (started_error_output
)
4187 putchar_unfiltered ('\n');
4188 started_error_output
= 0;
4197 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4201 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4202 case SERIAL_TIMEOUT
:
4206 break; /* Retransmit buffer */
4210 fprintf_unfiltered (gdb_stdlog
, "Packet instead of Ack, ignoring it\n");
4211 /* It's probably an old response, and we're out of sync.
4212 Just gobble up the packet and ignore it. */
4213 read_frame (junkbuf
, sizeof_junkbuf
);
4214 continue; /* Now, go look for + */
4219 if (!started_error_output
)
4221 started_error_output
= 1;
4222 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4224 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4228 break; /* Here to retransmit */
4232 /* This is wrong. If doing a long backtrace, the user should be
4233 able to get out next time we call QUIT, without anything as
4234 violent as interrupt_query. If we want to provide a way out of
4235 here without getting to the next QUIT, it should be based on
4236 hitting ^C twice as in remote_wait. */
4246 static int remote_cisco_mode
;
4248 /* Come here after finding the start of the frame. Collect the rest
4249 into BUF, verifying the checksum, length, and handling run-length
4250 compression. No more than sizeof_buf-1 characters are read so that
4251 the buffer can be NUL terminated.
4253 Returns -1 on error, number of characters in buffer (ignoring the
4254 trailing NULL) on success. (could be extended to return one of the
4255 SERIAL status indications). */
4258 read_frame (char *buf
,
4270 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
4271 c
= readchar (remote_timeout
);
4274 case SERIAL_TIMEOUT
:
4276 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4280 fputs_filtered ("Saw new packet start in middle of old one\n",
4282 return -1; /* Start a new packet, count retries */
4285 unsigned char pktcsum
;
4291 check_0
= readchar (remote_timeout
);
4293 check_1
= readchar (remote_timeout
);
4295 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4298 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog
);
4301 else if (check_0
< 0 || check_1
< 0)
4304 fputs_filtered ("Communication error in checksum\n", gdb_stdlog
);
4308 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4309 if (csum
== pktcsum
)
4314 fprintf_filtered (gdb_stdlog
,
4315 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4317 fputs_filtered (buf
, gdb_stdlog
);
4318 fputs_filtered ("\n", gdb_stdlog
);
4320 /* Number of characters in buffer ignoring trailing
4324 case '*': /* Run length encoding */
4329 if (remote_cisco_mode
== 0)
4331 c
= readchar (remote_timeout
);
4333 repeat
= c
- ' ' + 3; /* Compute repeat count */
4337 /* Cisco's run-length encoding variant uses two
4338 hex chars to represent the repeat count. */
4340 c
= readchar (remote_timeout
);
4342 repeat
= fromhex (c
) << 4;
4343 c
= readchar (remote_timeout
);
4345 repeat
+= fromhex (c
);
4348 /* The character before ``*'' is repeated. */
4350 if (repeat
> 0 && repeat
<= 255
4352 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4354 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4360 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
4361 puts_filtered (buf
);
4362 puts_filtered ("\n");
4366 if (bc
< sizeof_buf
- 1)
4374 puts_filtered ("Remote packet too long: ");
4375 puts_filtered (buf
);
4376 puts_filtered ("\n");
4383 /* Read a packet from the remote machine, with error checking, and
4384 store it in BUF. If FOREVER, wait forever rather than timing out;
4385 this is used (in synchronous mode) to wait for a target that is is
4386 executing user code to stop. */
4387 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4388 don't have to change all the calls to getpkt to deal with the
4389 return value, because at the moment I don't know what the right
4390 thing to do it for those. */
4398 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4402 /* Read a packet from the remote machine, with error checking, and
4403 store it in BUF. If FOREVER, wait forever rather than timing out;
4404 this is used (in synchronous mode) to wait for a target that is is
4405 executing user code to stop. If FOREVER == 0, this function is
4406 allowed to time out gracefully and return an indication of this to
4409 getpkt_sane (char *buf
,
4418 strcpy (buf
, "timeout");
4422 timeout
= watchdog
> 0 ? watchdog
: -1;
4426 timeout
= remote_timeout
;
4430 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4432 /* This can loop forever if the remote side sends us characters
4433 continuously, but if it pauses, we'll get a zero from readchar
4434 because of timeout. Then we'll count that as a retry. */
4436 /* Note that we will only wait forever prior to the start of a packet.
4437 After that, we expect characters to arrive at a brisk pace. They
4438 should show up within remote_timeout intervals. */
4442 c
= readchar (timeout
);
4444 if (c
== SERIAL_TIMEOUT
)
4446 if (forever
) /* Watchdog went off? Kill the target. */
4449 target_mourn_inferior ();
4450 error ("Watchdog has expired. Target detached.\n");
4453 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4459 /* We've found the start of a packet, now collect the data. */
4461 val
= read_frame (buf
, sizeof_buf
);
4467 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4468 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4469 fprintf_unfiltered (gdb_stdlog
, "\n");
4471 serial_write (remote_desc
, "+", 1);
4475 /* Try the whole thing again. */
4477 serial_write (remote_desc
, "-", 1);
4480 /* We have tried hard enough, and just can't receive the packet. Give up. */
4482 printf_unfiltered ("Ignoring packet error, continuing...\n");
4483 serial_write (remote_desc
, "+", 1);
4490 /* For some mysterious reason, wait_for_inferior calls kill instead of
4491 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4495 target_mourn_inferior ();
4499 /* Use catch_errors so the user can quit from gdb even when we aren't on
4500 speaking terms with the remote system. */
4501 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4503 /* Don't wait for it to die. I'm not really sure it matters whether
4504 we do or not. For the existing stubs, kill is a noop. */
4505 target_mourn_inferior ();
4508 /* Async version of remote_kill. */
4510 remote_async_kill (void)
4512 /* Unregister the file descriptor from the event loop. */
4513 if (target_is_async_p ())
4514 serial_async (remote_desc
, NULL
, 0);
4516 /* For some mysterious reason, wait_for_inferior calls kill instead of
4517 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4521 target_mourn_inferior ();
4525 /* Use catch_errors so the user can quit from gdb even when we aren't on
4526 speaking terms with the remote system. */
4527 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4529 /* Don't wait for it to die. I'm not really sure it matters whether
4530 we do or not. For the existing stubs, kill is a noop. */
4531 target_mourn_inferior ();
4537 remote_mourn_1 (&remote_ops
);
4541 remote_async_mourn (void)
4543 remote_mourn_1 (&remote_async_ops
);
4547 extended_remote_mourn (void)
4549 /* We do _not_ want to mourn the target like this; this will
4550 remove the extended remote target from the target stack,
4551 and the next time the user says "run" it'll fail.
4553 FIXME: What is the right thing to do here? */
4555 remote_mourn_1 (&extended_remote_ops
);
4559 /* Worker function for remote_mourn. */
4561 remote_mourn_1 (struct target_ops
*target
)
4563 unpush_target (target
);
4564 generic_mourn_inferior ();
4567 /* In the extended protocol we want to be able to do things like
4568 "run" and have them basically work as expected. So we need
4569 a special create_inferior function.
4571 FIXME: One day add support for changing the exec file
4572 we're debugging, arguments and an environment. */
4575 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
)
4577 /* Rip out the breakpoints; we'll reinsert them after restarting
4578 the remote server. */
4579 remove_breakpoints ();
4581 /* Now restart the remote server. */
4582 extended_remote_restart ();
4584 /* Now put the breakpoints back in. This way we're safe if the
4585 restart function works via a unix fork on the remote side. */
4586 insert_breakpoints ();
4588 /* Clean up from the last time we were running. */
4589 clear_proceed_status ();
4591 /* Let the remote process run. */
4592 proceed (-1, TARGET_SIGNAL_0
, 0);
4595 /* Async version of extended_remote_create_inferior. */
4597 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
)
4599 /* Rip out the breakpoints; we'll reinsert them after restarting
4600 the remote server. */
4601 remove_breakpoints ();
4603 /* If running asynchronously, register the target file descriptor
4604 with the event loop. */
4605 if (event_loop_p
&& target_can_async_p ())
4606 target_async (inferior_event_handler
, 0);
4608 /* Now restart the remote server. */
4609 extended_remote_restart ();
4611 /* Now put the breakpoints back in. This way we're safe if the
4612 restart function works via a unix fork on the remote side. */
4613 insert_breakpoints ();
4615 /* Clean up from the last time we were running. */
4616 clear_proceed_status ();
4618 /* Let the remote process run. */
4619 proceed (-1, TARGET_SIGNAL_0
, 0);
4623 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
4624 than other targets; in those use REMOTE_BREAKPOINT instead of just
4625 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
4626 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
4627 the standard routines that are in mem-break.c. */
4629 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
4630 the choice of breakpoint instruction affects target program design and
4631 vice versa, and by making it user-tweakable, the special code here
4632 goes away and we need fewer special GDB configurations. */
4634 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4635 #define REMOTE_BREAKPOINT
4638 #ifdef REMOTE_BREAKPOINT
4640 /* If the target isn't bi-endian, just pretend it is. */
4641 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
4642 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4643 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4646 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
4647 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
4649 #endif /* REMOTE_BREAKPOINT */
4651 /* Insert a breakpoint on targets that don't have any better breakpoint
4652 support. We read the contents of the target location and stash it,
4653 then overwrite it with a breakpoint instruction. ADDR is the target
4654 location in the target machine. CONTENTS_CACHE is a pointer to
4655 memory allocated for saving the target contents. It is guaranteed
4656 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
4657 is accomplished via BREAKPOINT_MAX). */
4660 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4662 struct remote_state
*rs
= get_remote_state ();
4663 #ifdef REMOTE_BREAKPOINT
4668 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4669 If it succeeds, then set the support to PACKET_ENABLE. If it
4670 fails, and the user has explicitly requested the Z support then
4671 report an error, otherwise, mark it disabled and go on. */
4673 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4675 char *buf
= alloca (rs
->remote_packet_size
);
4678 addr
= remote_address_masked (addr
);
4682 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4683 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4684 sprintf (p
, ",%d", bp_size
);
4687 getpkt (buf
, (rs
->remote_packet_size
), 0);
4689 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4695 case PACKET_UNKNOWN
:
4700 #ifdef REMOTE_BREAKPOINT
4701 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4705 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4706 val
= target_write_memory (addr
, (char *) big_break_insn
,
4707 sizeof big_break_insn
);
4709 val
= target_write_memory (addr
, (char *) little_break_insn
,
4710 sizeof little_break_insn
);
4715 return memory_insert_breakpoint (addr
, contents_cache
);
4716 #endif /* REMOTE_BREAKPOINT */
4720 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4722 struct remote_state
*rs
= get_remote_state ();
4725 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4727 char *buf
= alloca (rs
->remote_packet_size
);
4734 addr
= remote_address_masked (addr
);
4735 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4736 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4737 sprintf (p
, ",%d", bp_size
);
4740 getpkt (buf
, (rs
->remote_packet_size
), 0);
4742 return (buf
[0] == 'E');
4745 #ifdef REMOTE_BREAKPOINT
4746 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4748 return memory_remove_breakpoint (addr
, contents_cache
);
4749 #endif /* REMOTE_BREAKPOINT */
4753 watchpoint_to_Z_packet (int type
)
4767 internal_error (__FILE__
, __LINE__
,
4768 "hw_bp_to_z: bad watchpoint type %d", type
);
4773 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4775 struct remote_state
*rs
= get_remote_state ();
4776 char *buf
= alloca (rs
->remote_packet_size
);
4778 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4780 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4781 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4782 remote_protocol_Z
[packet
].name
,
4783 remote_protocol_Z
[packet
].title
);
4785 sprintf (buf
, "Z%x,", packet
);
4786 p
= strchr (buf
, '\0');
4787 addr
= remote_address_masked (addr
);
4788 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4789 sprintf (p
, ",%x", len
);
4792 getpkt (buf
, (rs
->remote_packet_size
), 0);
4794 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4797 case PACKET_UNKNOWN
:
4802 internal_error (__FILE__
, __LINE__
,
4803 "remote_insert_watchpoint: reached end of function");
4808 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4810 struct remote_state
*rs
= get_remote_state ();
4811 char *buf
= alloca (rs
->remote_packet_size
);
4813 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4815 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4816 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4817 remote_protocol_Z
[packet
].name
,
4818 remote_protocol_Z
[packet
].title
);
4820 sprintf (buf
, "z%x,", packet
);
4821 p
= strchr (buf
, '\0');
4822 addr
= remote_address_masked (addr
);
4823 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4824 sprintf (p
, ",%x", len
);
4826 getpkt (buf
, (rs
->remote_packet_size
), 0);
4828 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4831 case PACKET_UNKNOWN
:
4836 internal_error (__FILE__
, __LINE__
,
4837 "remote_remove_watchpoint: reached end of function");
4841 int remote_hw_watchpoint_limit
= 0;
4842 int remote_hw_breakpoint_limit
= 0;
4845 remote_check_watch_resources (int type
, int cnt
, int ot
)
4847 if (type
== bp_hardware_breakpoint
)
4849 if (remote_hw_breakpoint_limit
== 0)
4851 else if (cnt
<= remote_hw_breakpoint_limit
)
4856 if (remote_hw_watchpoint_limit
== 0)
4860 else if (cnt
<= remote_hw_watchpoint_limit
)
4867 remote_stopped_by_watchpoint (void)
4869 return remote_stopped_by_watchpoint_p
;
4873 remote_stopped_data_address (void)
4875 if (remote_stopped_by_watchpoint ())
4876 return remote_watch_data_address
;
4877 return (CORE_ADDR
)0;
4882 remote_insert_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4885 struct remote_state
*rs
= get_remote_state ();
4886 char *buf
= alloca (rs
->remote_packet_size
);
4889 /* The length field should be set to the size of a breakpoint
4892 BREAKPOINT_FROM_PC (&addr
, &len
);
4894 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4895 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4896 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4897 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4903 addr
= remote_address_masked (addr
);
4904 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4905 sprintf (p
, ",%x", len
);
4908 getpkt (buf
, (rs
->remote_packet_size
), 0);
4910 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4913 case PACKET_UNKNOWN
:
4918 internal_error (__FILE__
, __LINE__
,
4919 "remote_insert_hw_breakpoint: reached end of function");
4924 remote_remove_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4927 struct remote_state
*rs
= get_remote_state ();
4928 char *buf
= alloca (rs
->remote_packet_size
);
4931 /* The length field should be set to the size of a breakpoint
4934 BREAKPOINT_FROM_PC (&addr
, &len
);
4936 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4937 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
4938 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4939 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4945 addr
= remote_address_masked (addr
);
4946 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4947 sprintf (p
, ",%x", len
);
4950 getpkt (buf
, (rs
->remote_packet_size
), 0);
4952 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4955 case PACKET_UNKNOWN
:
4960 internal_error (__FILE__
, __LINE__
,
4961 "remote_remove_hw_breakpoint: reached end of function");
4964 /* Some targets are only capable of doing downloads, and afterwards
4965 they switch to the remote serial protocol. This function provides
4966 a clean way to get from the download target to the remote target.
4967 It's basically just a wrapper so that we don't have to expose any
4968 of the internal workings of remote.c.
4970 Prior to calling this routine, you should shutdown the current
4971 target code, else you will get the "A program is being debugged
4972 already..." message. Usually a call to pop_target() suffices. */
4975 push_remote_target (char *name
, int from_tty
)
4977 printf_filtered ("Switching to remote protocol\n");
4978 remote_open (name
, from_tty
);
4981 /* Table used by the crc32 function to calcuate the checksum. */
4983 static unsigned long crc32_table
[256] =
4986 static unsigned long
4987 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4989 if (!crc32_table
[1])
4991 /* Initialize the CRC table and the decoding table. */
4995 for (i
= 0; i
< 256; i
++)
4997 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4998 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
5005 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
5011 /* compare-sections command
5013 With no arguments, compares each loadable section in the exec bfd
5014 with the same memory range on the target, and reports mismatches.
5015 Useful for verifying the image on the target against the exec file.
5016 Depends on the target understanding the new "qCRC:" request. */
5018 /* FIXME: cagney/1999-10-26: This command should be broken down into a
5019 target method (target verify memory) and generic version of the
5020 actual command. This will allow other high-level code (especially
5021 generic_load()) to make use of this target functionality. */
5024 compare_sections_command (char *args
, int from_tty
)
5026 struct remote_state
*rs
= get_remote_state ();
5028 unsigned long host_crc
, target_crc
;
5029 extern bfd
*exec_bfd
;
5030 struct cleanup
*old_chain
;
5033 const char *sectname
;
5034 char *buf
= alloca (rs
->remote_packet_size
);
5041 error ("command cannot be used without an exec file");
5042 if (!current_target
.to_shortname
||
5043 strcmp (current_target
.to_shortname
, "remote") != 0)
5044 error ("command can only be used with remote target");
5046 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
5048 if (!(s
->flags
& SEC_LOAD
))
5049 continue; /* skip non-loadable section */
5051 size
= bfd_get_section_size_before_reloc (s
);
5053 continue; /* skip zero-length section */
5055 sectname
= bfd_get_section_name (exec_bfd
, s
);
5056 if (args
&& strcmp (args
, sectname
) != 0)
5057 continue; /* not the section selected by user */
5059 matched
= 1; /* do this section */
5061 /* FIXME: assumes lma can fit into long */
5062 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
5065 /* be clever; compute the host_crc before waiting for target reply */
5066 sectdata
= xmalloc (size
);
5067 old_chain
= make_cleanup (xfree
, sectdata
);
5068 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
5069 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
5071 getpkt (buf
, (rs
->remote_packet_size
), 0);
5073 error ("target memory fault, section %s, range 0x%s -- 0x%s",
5074 sectname
, paddr (lma
), paddr (lma
+ size
));
5076 error ("remote target does not support this operation");
5078 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
5079 target_crc
= target_crc
* 16 + fromhex (*tmp
);
5081 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
5082 sectname
, paddr (lma
), paddr (lma
+ size
));
5083 if (host_crc
== target_crc
)
5084 printf_filtered ("matched.\n");
5087 printf_filtered ("MIS-MATCHED!\n");
5091 do_cleanups (old_chain
);
5094 warning ("One or more sections of the remote executable does not match\n\
5095 the loaded file\n");
5096 if (args
&& !matched
)
5097 printf_filtered ("No loaded section named '%s'.\n", args
);
5101 remote_query (int query_type
, char *buf
, char *outbuf
, int *bufsiz
)
5103 struct remote_state
*rs
= get_remote_state ();
5105 char *buf2
= alloca (rs
->remote_packet_size
);
5106 char *p2
= &buf2
[0];
5109 error ("null pointer to remote bufer size specified");
5111 /* minimum outbuf size is (rs->remote_packet_size) - if bufsiz is not large enough let
5112 the caller know and return what the minimum size is */
5113 /* Note: a zero bufsiz can be used to query the minimum buffer size */
5114 if (*bufsiz
< (rs
->remote_packet_size
))
5116 *bufsiz
= (rs
->remote_packet_size
);
5120 /* except for querying the minimum buffer size, target must be open */
5122 error ("remote query is only available after target open");
5124 /* we only take uppercase letters as query types, at least for now */
5125 if ((query_type
< 'A') || (query_type
> 'Z'))
5126 error ("invalid remote query type");
5129 error ("null remote query specified");
5132 error ("remote query requires a buffer to receive data");
5139 /* we used one buffer char for the remote protocol q command and another
5140 for the query type. As the remote protocol encapsulation uses 4 chars
5141 plus one extra in case we are debugging (remote_debug),
5142 we have PBUFZIZ - 7 left to pack the query string */
5144 while (buf
[i
] && (i
< ((rs
->remote_packet_size
) - 8)))
5146 /* bad caller may have sent forbidden characters */
5147 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
5148 error ("illegal characters in query string");
5156 error ("query larger than available buffer");
5162 getpkt (outbuf
, *bufsiz
, 0);
5168 remote_rcmd (char *command
,
5169 struct ui_file
*outbuf
)
5171 struct remote_state
*rs
= get_remote_state ();
5173 char *buf
= alloca (rs
->remote_packet_size
);
5177 error ("remote rcmd is only available after target open");
5179 /* Send a NULL command across as an empty command */
5180 if (command
== NULL
)
5183 /* The query prefix */
5184 strcpy (buf
, "qRcmd,");
5185 p
= strchr (buf
, '\0');
5187 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > (rs
->remote_packet_size
))
5188 error ("\"monitor\" command ``%s'' is too long\n", command
);
5190 /* Encode the actual command */
5191 bin2hex (command
, p
, 0);
5193 if (putpkt (buf
) < 0)
5194 error ("Communication problem with target\n");
5196 /* get/display the response */
5199 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
5201 getpkt (buf
, (rs
->remote_packet_size
), 0);
5203 error ("Target does not support this command\n");
5204 if (buf
[0] == 'O' && buf
[1] != 'K')
5206 remote_console_output (buf
+ 1); /* 'O' message from stub */
5209 if (strcmp (buf
, "OK") == 0)
5211 if (strlen (buf
) == 3 && buf
[0] == 'E'
5212 && isdigit (buf
[1]) && isdigit (buf
[2]))
5214 error ("Protocol error with Rcmd");
5216 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5218 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5219 fputc_unfiltered (c
, outbuf
);
5226 packet_command (char *args
, int from_tty
)
5228 struct remote_state
*rs
= get_remote_state ();
5229 char *buf
= alloca (rs
->remote_packet_size
);
5232 error ("command can only be used with remote target");
5235 error ("remote-packet command requires packet text as argument");
5237 puts_filtered ("sending: ");
5238 print_packet (args
);
5239 puts_filtered ("\n");
5242 getpkt (buf
, (rs
->remote_packet_size
), 0);
5243 puts_filtered ("received: ");
5245 puts_filtered ("\n");
5249 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
5251 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5253 static void threadset_test_cmd (char *cmd
, int tty
);
5255 static void threadalive_test (char *cmd
, int tty
);
5257 static void threadlist_test_cmd (char *cmd
, int tty
);
5259 int get_and_display_threadinfo (threadref
* ref
);
5261 static void threadinfo_test_cmd (char *cmd
, int tty
);
5263 static int thread_display_step (threadref
* ref
, void *context
);
5265 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5267 static void init_remote_threadtests (void);
5269 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
5272 threadset_test_cmd (char *cmd
, int tty
)
5274 int sample_thread
= SAMPLE_THREAD
;
5276 printf_filtered ("Remote threadset test\n");
5277 set_thread (sample_thread
, 1);
5282 threadalive_test (char *cmd
, int tty
)
5284 int sample_thread
= SAMPLE_THREAD
;
5286 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5287 printf_filtered ("PASS: Thread alive test\n");
5289 printf_filtered ("FAIL: Thread alive test\n");
5292 void output_threadid (char *title
, threadref
* ref
);
5295 output_threadid (char *title
, threadref
*ref
)
5299 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
5301 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5305 threadlist_test_cmd (char *cmd
, int tty
)
5308 threadref nextthread
;
5309 int done
, result_count
;
5310 threadref threadlist
[3];
5312 printf_filtered ("Remote Threadlist test\n");
5313 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5314 &result_count
, &threadlist
[0]))
5315 printf_filtered ("FAIL: threadlist test\n");
5318 threadref
*scan
= threadlist
;
5319 threadref
*limit
= scan
+ result_count
;
5321 while (scan
< limit
)
5322 output_threadid (" thread ", scan
++);
5327 display_thread_info (struct gdb_ext_thread_info
*info
)
5329 output_threadid ("Threadid: ", &info
->threadid
);
5330 printf_filtered ("Name: %s\n ", info
->shortname
);
5331 printf_filtered ("State: %s\n", info
->display
);
5332 printf_filtered ("other: %s\n\n", info
->more_display
);
5336 get_and_display_threadinfo (threadref
*ref
)
5340 struct gdb_ext_thread_info threadinfo
;
5342 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5343 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5344 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5345 display_thread_info (&threadinfo
);
5350 threadinfo_test_cmd (char *cmd
, int tty
)
5352 int athread
= SAMPLE_THREAD
;
5356 int_to_threadref (&thread
, athread
);
5357 printf_filtered ("Remote Threadinfo test\n");
5358 if (!get_and_display_threadinfo (&thread
))
5359 printf_filtered ("FAIL cannot get thread info\n");
5363 thread_display_step (threadref
*ref
, void *context
)
5365 /* output_threadid(" threadstep ",ref); *//* simple test */
5366 return get_and_display_threadinfo (ref
);
5370 threadlist_update_test_cmd (char *cmd
, int tty
)
5372 printf_filtered ("Remote Threadlist update test\n");
5373 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5377 init_remote_threadtests (void)
5379 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
5380 "Fetch and print the remote list of thread identifiers, one pkt only");
5381 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5382 "Fetch and display info about one thread");
5383 add_com ("tset", class_obscure
, threadset_test_cmd
,
5384 "Test setting to a different thread");
5385 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5386 "Iterate through updating all remote thread info");
5387 add_com ("talive", class_obscure
, threadalive_test
,
5388 " Remote thread alive test ");
5393 /* Convert a thread ID to a string. Returns the string in a static
5397 remote_pid_to_str (ptid_t ptid
)
5399 static char buf
[30];
5401 sprintf (buf
, "Thread %d", PIDGET (ptid
));
5406 init_remote_ops (void)
5408 remote_ops
.to_shortname
= "remote";
5409 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5411 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5412 Specify the serial device it is connected to\n\
5413 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5414 remote_ops
.to_open
= remote_open
;
5415 remote_ops
.to_close
= remote_close
;
5416 remote_ops
.to_detach
= remote_detach
;
5417 remote_ops
.to_resume
= remote_resume
;
5418 remote_ops
.to_wait
= remote_wait
;
5419 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5420 remote_ops
.to_store_registers
= remote_store_registers
;
5421 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5422 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
5423 remote_ops
.to_files_info
= remote_files_info
;
5424 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5425 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5426 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5427 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5428 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5429 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5430 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5431 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5432 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5433 remote_ops
.to_kill
= remote_kill
;
5434 remote_ops
.to_load
= generic_load
;
5435 remote_ops
.to_mourn_inferior
= remote_mourn
;
5436 remote_ops
.to_thread_alive
= remote_thread_alive
;
5437 remote_ops
.to_find_new_threads
= remote_threads_info
;
5438 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5439 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5440 remote_ops
.to_stop
= remote_stop
;
5441 remote_ops
.to_query
= remote_query
;
5442 remote_ops
.to_rcmd
= remote_rcmd
;
5443 remote_ops
.to_stratum
= process_stratum
;
5444 remote_ops
.to_has_all_memory
= 1;
5445 remote_ops
.to_has_memory
= 1;
5446 remote_ops
.to_has_stack
= 1;
5447 remote_ops
.to_has_registers
= 1;
5448 remote_ops
.to_has_execution
= 1;
5449 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5450 remote_ops
.to_magic
= OPS_MAGIC
;
5453 /* Set up the extended remote vector by making a copy of the standard
5454 remote vector and adding to it. */
5457 init_extended_remote_ops (void)
5459 extended_remote_ops
= remote_ops
;
5461 extended_remote_ops
.to_shortname
= "extended-remote";
5462 extended_remote_ops
.to_longname
=
5463 "Extended remote serial target in gdb-specific protocol";
5464 extended_remote_ops
.to_doc
=
5465 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5466 Specify the serial device it is connected to (e.g. /dev/ttya).",
5467 extended_remote_ops
.to_open
= extended_remote_open
;
5468 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5469 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5473 * Command: info remote-process
5475 * This implements Cisco's version of the "info proc" command.
5477 * This query allows the target stub to return an arbitrary string
5478 * (or strings) giving arbitrary information about the target process.
5479 * This is optional; the target stub isn't required to implement it.
5481 * Syntax: qfProcessInfo request first string
5482 * qsProcessInfo request subsequent string
5483 * reply: 'O'<hex-encoded-string>
5484 * 'l' last reply (empty)
5488 remote_info_process (char *args
, int from_tty
)
5490 struct remote_state
*rs
= get_remote_state ();
5491 char *buf
= alloca (rs
->remote_packet_size
);
5493 if (remote_desc
== 0)
5494 error ("Command can only be used when connected to the remote target.");
5496 putpkt ("qfProcessInfo");
5497 getpkt (buf
, (rs
->remote_packet_size
), 0);
5499 return; /* Silently: target does not support this feature. */
5502 error ("info proc: target error.");
5504 while (buf
[0] == 'O') /* Capitol-O packet */
5506 remote_console_output (&buf
[1]);
5507 putpkt ("qsProcessInfo");
5508 getpkt (buf
, (rs
->remote_packet_size
), 0);
5517 remote_cisco_open (char *name
, int from_tty
)
5521 error ("To open a remote debug connection, you need to specify what \n"
5522 "device is attached to the remote system (e.g. host:port).");
5524 /* See FIXME above */
5525 wait_forever_enabled_p
= 1;
5527 target_preopen (from_tty
);
5529 unpush_target (&remote_cisco_ops
);
5531 remote_desc
= remote_serial_open (name
);
5533 perror_with_name (name
);
5536 * If a baud rate was specified on the gdb command line it will
5537 * be greater than the initial value of -1. If it is, use it otherwise
5541 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
5542 if (serial_setbaudrate (remote_desc
, baud_rate
))
5544 serial_close (remote_desc
);
5545 perror_with_name (name
);
5548 serial_raw (remote_desc
);
5550 /* If there is something sitting in the buffer we might take it as a
5551 response to a command, which would be bad. */
5552 serial_flush_input (remote_desc
);
5556 puts_filtered ("Remote debugging using ");
5557 puts_filtered (name
);
5558 puts_filtered ("\n");
5561 remote_cisco_mode
= 1;
5563 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
5565 init_all_packet_configs ();
5567 general_thread
= -2;
5568 continue_thread
= -2;
5570 /* Probe for ability to use "ThreadInfo" query, as required. */
5571 use_threadinfo_query
= 1;
5572 use_threadextra_query
= 1;
5574 /* Without this, some commands which require an active target (such
5575 as kill) won't work. This variable serves (at least) double duty
5576 as both the pid of the target process (if it has such), and as a
5577 flag indicating that a target is active. These functions should
5578 be split out into seperate variables, especially since GDB will
5579 someday have a notion of debugging several processes. */
5580 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
5582 /* Start the remote connection; if error, discard this target. See
5583 the comments in remote_open_1() for further details such as the
5584 need to re-throw the exception. */
5585 ex
= catch_exceptions (uiout
,
5586 remote_start_remote_dummy
, NULL
,
5587 "Couldn't establish connection to remote"
5593 throw_exception (ex
);
5598 remote_cisco_close (int quitting
)
5600 remote_cisco_mode
= 0;
5601 remote_close (quitting
);
5605 remote_cisco_mourn (void)
5607 remote_mourn_1 (&remote_cisco_ops
);
5619 /* Shared between readsocket() and readtty(). The size is arbitrary,
5620 however all targets are known to support a 400 character packet. */
5621 static char tty_input
[400];
5623 static int escape_count
;
5624 static int echo_check
;
5625 extern int quit_flag
;
5632 /* Loop until the socket doesn't have any more data */
5634 while ((data
= readchar (0)) >= 0)
5636 /* Check for the escape sequence */
5639 /* If this is the fourth escape, get out */
5640 if (++escape_count
== 4)
5645 { /* This is a '|', but not the fourth in a row.
5646 Continue without echoing it. If it isn't actually
5647 one of four in a row, it'll be echoed later. */
5654 /* Ensure any pending '|'s are flushed. */
5656 for (; escape_count
> 0; escape_count
--)
5660 if (data
== '\r') /* If this is a return character, */
5661 continue; /* - just supress it. */
5663 if (echo_check
!= -1) /* Check for echo of user input. */
5665 if (tty_input
[echo_check
] == data
)
5667 gdb_assert (echo_check
<= sizeof (tty_input
));
5668 echo_check
++; /* Character matched user input: */
5669 continue; /* Continue without echoing it. */
5671 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5672 { /* End of the line (and of echo checking). */
5673 echo_check
= -1; /* No more echo supression */
5674 continue; /* Continue without echoing. */
5677 { /* Failed check for echo of user input.
5678 We now have some suppressed output to flush! */
5681 for (j
= 0; j
< echo_check
; j
++)
5682 putchar (tty_input
[j
]);
5686 putchar (data
); /* Default case: output the char. */
5689 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5690 return READ_MORE
; /* Try to read some more */
5692 return FATAL_ERROR
; /* Trouble, bail out */
5700 /* First, read a buffer full from the terminal */
5701 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5702 if (tty_bytecount
== -1)
5704 perror ("readtty: read failed");
5708 /* Remove a quoted newline. */
5709 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5710 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5712 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5713 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5716 /* Turn trailing newlines into returns */
5717 if (tty_input
[tty_bytecount
- 1] == '\n')
5718 tty_input
[tty_bytecount
- 1] = '\r';
5720 /* If the line consists of a ~, enter debugging mode. */
5721 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5724 /* Make this a zero terminated string and write it out */
5725 tty_input
[tty_bytecount
] = 0;
5726 if (serial_write (remote_desc
, tty_input
, tty_bytecount
))
5728 perror_with_name ("readtty: write failed");
5738 fd_set input
; /* file descriptors for select */
5739 int tablesize
; /* max number of FDs for select */
5743 extern int escape_count
; /* global shared by readsocket */
5744 extern int echo_check
; /* ditto */
5749 tablesize
= 8 * sizeof (input
);
5753 /* Check for anything from our socket - doesn't block. Note that
5754 this must be done *before* the select as there may be
5755 buffered I/O waiting to be processed. */
5757 if ((status
= readsocket ()) == FATAL_ERROR
)
5759 error ("Debugging terminated by communications error");
5761 else if (status
!= READ_MORE
)
5766 fflush (stdout
); /* Flush output before blocking */
5768 /* Now block on more socket input or TTY input */
5771 FD_SET (fileno (stdin
), &input
);
5772 FD_SET (deprecated_serial_fd (remote_desc
), &input
);
5774 status
= select (tablesize
, &input
, 0, 0, 0);
5775 if ((status
== -1) && (errno
!= EINTR
))
5777 error ("Communications error on select %d", errno
);
5780 /* Handle Control-C typed */
5784 if ((++quit_count
) == 2)
5786 if (query ("Interrupt GDB? "))
5788 printf_filtered ("Interrupted by user.\n");
5789 throw_exception (RETURN_QUIT
);
5796 serial_send_break (remote_desc
);
5798 serial_write (remote_desc
, "\003", 1);
5803 /* Handle console input */
5805 if (FD_ISSET (fileno (stdin
), &input
))
5809 status
= readtty ();
5810 if (status
== READ_MORE
)
5813 return status
; /* telnet session ended */
5819 remote_cisco_wait (ptid_t ptid
, struct target_waitstatus
*status
)
5821 if (minitelnet () != ENTER_DEBUG
)
5823 error ("Debugging session terminated by protocol error");
5826 return remote_wait (ptid
, status
);
5830 init_remote_cisco_ops (void)
5832 remote_cisco_ops
.to_shortname
= "cisco";
5833 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5834 remote_cisco_ops
.to_doc
=
5835 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5836 Specify the serial device it is connected to (e.g. host:2020).";
5837 remote_cisco_ops
.to_open
= remote_cisco_open
;
5838 remote_cisco_ops
.to_close
= remote_cisco_close
;
5839 remote_cisco_ops
.to_detach
= remote_detach
;
5840 remote_cisco_ops
.to_resume
= remote_resume
;
5841 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5842 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5843 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5844 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5845 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5846 remote_cisco_ops
.to_files_info
= remote_files_info
;
5847 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5848 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5849 remote_cisco_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5850 remote_cisco_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5851 remote_cisco_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5852 remote_cisco_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5853 remote_cisco_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5854 remote_cisco_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5855 remote_cisco_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5856 remote_cisco_ops
.to_kill
= remote_kill
;
5857 remote_cisco_ops
.to_load
= generic_load
;
5858 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5859 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5860 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5861 remote_cisco_ops
.to_pid_to_str
= remote_pid_to_str
;
5862 remote_cisco_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5863 remote_cisco_ops
.to_stratum
= process_stratum
;
5864 remote_cisco_ops
.to_has_all_memory
= 1;
5865 remote_cisco_ops
.to_has_memory
= 1;
5866 remote_cisco_ops
.to_has_stack
= 1;
5867 remote_cisco_ops
.to_has_registers
= 1;
5868 remote_cisco_ops
.to_has_execution
= 1;
5869 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5873 remote_can_async_p (void)
5875 /* We're async whenever the serial device is. */
5876 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5880 remote_is_async_p (void)
5882 /* We're async whenever the serial device is. */
5883 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5886 /* Pass the SERIAL event on and up to the client. One day this code
5887 will be able to delay notifying the client of an event until the
5888 point where an entire packet has been received. */
5890 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5891 static void *async_client_context
;
5892 static serial_event_ftype remote_async_serial_handler
;
5895 remote_async_serial_handler (struct serial
*scb
, void *context
)
5897 /* Don't propogate error information up to the client. Instead let
5898 the client find out about the error by querying the target. */
5899 async_client_callback (INF_REG_EVENT
, async_client_context
);
5903 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5905 if (current_target
.to_async_mask_value
== 0)
5906 internal_error (__FILE__
, __LINE__
,
5907 "Calling remote_async when async is masked");
5909 if (callback
!= NULL
)
5911 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5912 async_client_callback
= callback
;
5913 async_client_context
= context
;
5916 serial_async (remote_desc
, NULL
, NULL
);
5919 /* Target async and target extended-async.
5921 This are temporary targets, until it is all tested. Eventually
5922 async support will be incorporated int the usual 'remote'
5926 init_remote_async_ops (void)
5928 remote_async_ops
.to_shortname
= "async";
5929 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5930 remote_async_ops
.to_doc
=
5931 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5932 Specify the serial device it is connected to (e.g. /dev/ttya).";
5933 remote_async_ops
.to_open
= remote_async_open
;
5934 remote_async_ops
.to_close
= remote_close
;
5935 remote_async_ops
.to_detach
= remote_async_detach
;
5936 remote_async_ops
.to_resume
= remote_async_resume
;
5937 remote_async_ops
.to_wait
= remote_async_wait
;
5938 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5939 remote_async_ops
.to_store_registers
= remote_store_registers
;
5940 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5941 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5942 remote_async_ops
.to_files_info
= remote_files_info
;
5943 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5944 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5945 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5946 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5947 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5948 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5949 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5950 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5951 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5952 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5953 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5954 remote_async_ops
.to_kill
= remote_async_kill
;
5955 remote_async_ops
.to_load
= generic_load
;
5956 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5957 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5958 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5959 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
5960 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5961 remote_async_ops
.to_stop
= remote_stop
;
5962 remote_async_ops
.to_query
= remote_query
;
5963 remote_async_ops
.to_rcmd
= remote_rcmd
;
5964 remote_async_ops
.to_stratum
= process_stratum
;
5965 remote_async_ops
.to_has_all_memory
= 1;
5966 remote_async_ops
.to_has_memory
= 1;
5967 remote_async_ops
.to_has_stack
= 1;
5968 remote_async_ops
.to_has_registers
= 1;
5969 remote_async_ops
.to_has_execution
= 1;
5970 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5971 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5972 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5973 remote_async_ops
.to_async
= remote_async
;
5974 remote_async_ops
.to_async_mask_value
= 1;
5975 remote_async_ops
.to_magic
= OPS_MAGIC
;
5978 /* Set up the async extended remote vector by making a copy of the standard
5979 remote vector and adding to it. */
5982 init_extended_async_remote_ops (void)
5984 extended_async_remote_ops
= remote_async_ops
;
5986 extended_async_remote_ops
.to_shortname
= "extended-async";
5987 extended_async_remote_ops
.to_longname
=
5988 "Extended remote serial target in async gdb-specific protocol";
5989 extended_async_remote_ops
.to_doc
=
5990 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5991 Specify the serial device it is connected to (e.g. /dev/ttya).",
5992 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5993 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5994 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5998 set_remote_cmd (char *args
, int from_tty
)
6003 show_remote_cmd (char *args
, int from_tty
)
6005 /* FIXME: cagney/2002-06-15: This function should iterate over
6006 remote_show_cmdlist for a list of sub commands to show. */
6007 show_remote_protocol_Z_packet_cmd (args
, from_tty
, NULL
);
6008 show_remote_protocol_e_packet_cmd (args
, from_tty
, NULL
);
6009 show_remote_protocol_E_packet_cmd (args
, from_tty
, NULL
);
6010 show_remote_protocol_P_packet_cmd (args
, from_tty
, NULL
);
6011 show_remote_protocol_qSymbol_packet_cmd (args
, from_tty
, NULL
);
6012 show_remote_protocol_binary_download_cmd (args
, from_tty
, NULL
);
6016 build_remote_gdbarch_data (void)
6018 remote_address_size
= TARGET_ADDR_BIT
;
6021 /* Saved pointer to previous owner of the new_objfile event. */
6022 static void (*remote_new_objfile_chain
) (struct objfile
*);
6024 /* Function to be called whenever a new objfile (shlib) is detected. */
6026 remote_new_objfile (struct objfile
*objfile
)
6028 if (remote_desc
!= 0) /* Have a remote connection */
6030 remote_check_symbols (objfile
);
6032 /* Call predecessor on chain, if any. */
6033 if (remote_new_objfile_chain
!= 0 &&
6035 remote_new_objfile_chain (objfile
);
6039 _initialize_remote (void)
6041 static struct cmd_list_element
*remote_set_cmdlist
;
6042 static struct cmd_list_element
*remote_show_cmdlist
;
6043 struct cmd_list_element
*tmpcmd
;
6045 /* architecture specific data */
6046 remote_gdbarch_data_handle
= register_gdbarch_data (init_remote_state
,
6049 /* Old tacky stuff. NOTE: This comes after the remote protocol so
6050 that the remote protocol has been initialized. */
6051 register_gdbarch_swap (&remote_address_size
,
6052 sizeof (&remote_address_size
), NULL
);
6053 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
6056 add_target (&remote_ops
);
6058 init_extended_remote_ops ();
6059 add_target (&extended_remote_ops
);
6061 init_remote_async_ops ();
6062 add_target (&remote_async_ops
);
6064 init_extended_async_remote_ops ();
6065 add_target (&extended_async_remote_ops
);
6067 init_remote_cisco_ops ();
6068 add_target (&remote_cisco_ops
);
6070 /* Hook into new objfile notification. */
6071 remote_new_objfile_chain
= target_new_objfile_hook
;
6072 target_new_objfile_hook
= remote_new_objfile
;
6075 init_remote_threadtests ();
6078 /* set/show remote ... */
6080 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
6081 Remote protocol specific variables\n\
6082 Configure various remote-protocol specific variables such as\n\
6083 the packets being used",
6084 &remote_set_cmdlist
, "set remote ",
6085 0/*allow-unknown*/, &setlist
);
6086 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, "\
6087 Remote protocol specific variables\n\
6088 Configure various remote-protocol specific variables such as\n\
6089 the packets being used",
6090 &remote_show_cmdlist
, "show remote ",
6091 0/*allow-unknown*/, &showlist
);
6093 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
6094 "Compare section data on target to the exec file.\n\
6095 Argument is a single section name (default: all loaded sections).",
6098 add_cmd ("packet", class_maintenance
, packet_command
,
6099 "Send an arbitrary packet to a remote target.\n\
6100 maintenance packet TEXT\n\
6101 If GDB is talking to an inferior via the GDB serial protocol, then\n\
6102 this command sends the string TEXT to the inferior, and displays the\n\
6103 response packet. GDB supplies the initial `$' character, and the\n\
6104 terminating `#' character and checksum.",
6107 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
,
6108 "Set whether to send break if interrupted.\n",
6109 "Show whether to send break if interrupted.\n",
6111 &setlist
, &showlist
);
6113 /* Install commands for configuring memory read/write packets. */
6115 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
6116 "Set the maximum number of bytes per memory write packet (deprecated).\n",
6118 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
,
6119 "Show the maximum number of bytes per memory write packet (deprecated).\n",
6121 add_cmd ("memory-write-packet-size", no_class
,
6122 set_memory_write_packet_size
,
6123 "Set the maximum number of bytes per memory-write packet.\n"
6124 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6125 "default packet size. The actual limit is further reduced\n"
6126 "dependent on the target. Specify ``fixed'' to disable the\n"
6127 "further restriction and ``limit'' to enable that restriction\n",
6128 &remote_set_cmdlist
);
6129 add_cmd ("memory-read-packet-size", no_class
,
6130 set_memory_read_packet_size
,
6131 "Set the maximum number of bytes per memory-read packet.\n"
6132 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6133 "default packet size. The actual limit is further reduced\n"
6134 "dependent on the target. Specify ``fixed'' to disable the\n"
6135 "further restriction and ``limit'' to enable that restriction\n",
6136 &remote_set_cmdlist
);
6137 add_cmd ("memory-write-packet-size", no_class
,
6138 show_memory_write_packet_size
,
6139 "Show the maximum number of bytes per memory-write packet.\n",
6140 &remote_show_cmdlist
);
6141 add_cmd ("memory-read-packet-size", no_class
,
6142 show_memory_read_packet_size
,
6143 "Show the maximum number of bytes per memory-read packet.\n",
6144 &remote_show_cmdlist
);
6147 (add_set_cmd ("remoteaddresssize", class_obscure
,
6148 var_integer
, (char *) &remote_address_size
,
6149 "Set the maximum size of the address (in bits) \
6150 in a memory packet.\n",
6154 add_packet_config_cmd (&remote_protocol_binary_download
,
6155 "X", "binary-download",
6156 set_remote_protocol_binary_download_cmd
,
6157 show_remote_protocol_binary_download_cmd
,
6158 &remote_set_cmdlist
, &remote_show_cmdlist
,
6161 /* XXXX - should ``set remotebinarydownload'' be retained for
6164 (add_set_cmd ("remotebinarydownload", no_class
,
6165 var_boolean
, (char *) &remote_binary_download
,
6166 "Set binary downloads.\n", &setlist
),
6170 add_info ("remote-process", remote_info_process
,
6171 "Query the remote system for process info.");
6173 add_packet_config_cmd (&remote_protocol_qSymbol
,
6174 "qSymbol", "symbol-lookup",
6175 set_remote_protocol_qSymbol_packet_cmd
,
6176 show_remote_protocol_qSymbol_packet_cmd
,
6177 &remote_set_cmdlist
, &remote_show_cmdlist
,
6180 add_packet_config_cmd (&remote_protocol_e
,
6181 "e", "step-over-range",
6182 set_remote_protocol_e_packet_cmd
,
6183 show_remote_protocol_e_packet_cmd
,
6184 &remote_set_cmdlist
, &remote_show_cmdlist
,
6186 /* Disable by default. The ``e'' packet has nasty interactions with
6187 the threading code - it relies on global state. */
6188 remote_protocol_e
.detect
= AUTO_BOOLEAN_FALSE
;
6189 update_packet_config (&remote_protocol_e
);
6191 add_packet_config_cmd (&remote_protocol_E
,
6192 "E", "step-over-range-w-signal",
6193 set_remote_protocol_E_packet_cmd
,
6194 show_remote_protocol_E_packet_cmd
,
6195 &remote_set_cmdlist
, &remote_show_cmdlist
,
6197 /* Disable by default. The ``e'' packet has nasty interactions with
6198 the threading code - it relies on global state. */
6199 remote_protocol_E
.detect
= AUTO_BOOLEAN_FALSE
;
6200 update_packet_config (&remote_protocol_E
);
6202 add_packet_config_cmd (&remote_protocol_P
,
6203 "P", "set-register",
6204 set_remote_protocol_P_packet_cmd
,
6205 show_remote_protocol_P_packet_cmd
,
6206 &remote_set_cmdlist
, &remote_show_cmdlist
,
6209 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
6210 "Z0", "software-breakpoint",
6211 set_remote_protocol_Z_software_bp_packet_cmd
,
6212 show_remote_protocol_Z_software_bp_packet_cmd
,
6213 &remote_set_cmdlist
, &remote_show_cmdlist
,
6216 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
6217 "Z1", "hardware-breakpoint",
6218 set_remote_protocol_Z_hardware_bp_packet_cmd
,
6219 show_remote_protocol_Z_hardware_bp_packet_cmd
,
6220 &remote_set_cmdlist
, &remote_show_cmdlist
,
6223 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
6224 "Z2", "write-watchpoint",
6225 set_remote_protocol_Z_write_wp_packet_cmd
,
6226 show_remote_protocol_Z_write_wp_packet_cmd
,
6227 &remote_set_cmdlist
, &remote_show_cmdlist
,
6230 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
6231 "Z3", "read-watchpoint",
6232 set_remote_protocol_Z_read_wp_packet_cmd
,
6233 show_remote_protocol_Z_read_wp_packet_cmd
,
6234 &remote_set_cmdlist
, &remote_show_cmdlist
,
6237 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
6238 "Z4", "access-watchpoint",
6239 set_remote_protocol_Z_access_wp_packet_cmd
,
6240 show_remote_protocol_Z_access_wp_packet_cmd
,
6241 &remote_set_cmdlist
, &remote_show_cmdlist
,
6244 /* Keep the old ``set remote Z-packet ...'' working. */
6245 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
6246 &remote_Z_packet_detect
, "\
6247 Set use of remote protocol `Z' packets",
6248 "Show use of remote protocol `Z' packets ",
6249 set_remote_protocol_Z_packet_cmd
,
6250 show_remote_protocol_Z_packet_cmd
,
6251 &remote_set_cmdlist
, &remote_show_cmdlist
);