1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* See the GDB User Guide for details of the GDB remote protocol. */
26 #include "gdb_string.h"
33 /*#include "terminal.h" */
36 #include "gdb-stabs.h"
37 #include "gdbthread.h"
41 #include "gdb_assert.h"
46 #include <sys/types.h>
49 #include "event-loop.h"
50 #include "event-top.h"
56 #include "gdbcore.h" /* for exec_bfd */
58 /* Prototypes for local functions */
59 static void cleanup_sigint_signal_handler (void *dummy
);
60 static void initialize_sigint_signal_handler (void);
61 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
63 static void handle_remote_sigint (int);
64 static void handle_remote_sigint_twice (int);
65 static void async_remote_interrupt (gdb_client_data
);
66 void async_remote_interrupt_twice (gdb_client_data
);
68 static void build_remote_gdbarch_data (void);
70 static int remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
72 static int remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
);
74 static void remote_files_info (struct target_ops
*ignore
);
76 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
77 int len
, int should_write
,
78 struct mem_attrib
*attrib
,
79 struct target_ops
*target
);
81 static void remote_prepare_to_store (void);
83 static void remote_fetch_registers (int regno
);
85 static void remote_resume (ptid_t ptid
, int step
,
86 enum target_signal siggnal
);
87 static void remote_async_resume (ptid_t ptid
, int step
,
88 enum target_signal siggnal
);
89 static int remote_start_remote (struct ui_out
*uiout
, void *dummy
);
91 static void remote_open (char *name
, int from_tty
);
92 static void remote_async_open (char *name
, int from_tty
);
94 static void extended_remote_open (char *name
, int from_tty
);
95 static void extended_remote_async_open (char *name
, int from_tty
);
97 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
98 static void remote_async_open_1 (char *, int, struct target_ops
*,
101 static void remote_close (int quitting
);
103 static void remote_store_registers (int regno
);
105 static void remote_mourn (void);
106 static void remote_async_mourn (void);
108 static void extended_remote_restart (void);
110 static void extended_remote_mourn (void);
112 static void extended_remote_create_inferior (char *, char *, char **);
113 static void extended_remote_async_create_inferior (char *, char *, char **);
115 static void remote_mourn_1 (struct target_ops
*);
117 static void remote_send (char *buf
, long sizeof_buf
);
119 static int readchar (int timeout
);
121 static ptid_t
remote_wait (ptid_t ptid
,
122 struct target_waitstatus
*status
);
123 static ptid_t
remote_async_wait (ptid_t ptid
,
124 struct target_waitstatus
*status
);
126 static void remote_kill (void);
127 static void remote_async_kill (void);
129 static int tohex (int nib
);
131 static void remote_detach (char *args
, int from_tty
);
132 static void remote_async_detach (char *args
, int from_tty
);
134 static void remote_interrupt (int signo
);
136 static void remote_interrupt_twice (int signo
);
138 static void interrupt_query (void);
140 static void set_thread (int, int);
142 static int remote_thread_alive (ptid_t
);
144 static void get_offsets (void);
146 static long read_frame (char *buf
, long sizeof_buf
);
148 static int remote_insert_breakpoint (CORE_ADDR
, char *);
150 static int remote_remove_breakpoint (CORE_ADDR
, char *);
152 static int hexnumlen (ULONGEST num
);
154 static void init_remote_ops (void);
156 static void init_extended_remote_ops (void);
158 static void init_remote_cisco_ops (void);
160 static struct target_ops remote_cisco_ops
;
162 static void remote_stop (void);
164 static int ishex (int ch
, int *val
);
166 static int stubhex (int ch
);
168 static int remote_query (int /*char */ , char *, char *, int *);
170 static int hexnumstr (char *, ULONGEST
);
172 static int hexnumnstr (char *, ULONGEST
, int);
174 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
176 static void print_packet (char *);
178 static unsigned long crc32 (unsigned char *, int, unsigned int);
180 static void compare_sections_command (char *, int);
182 static void packet_command (char *, int);
184 static int stub_unpack_int (char *buff
, int fieldlength
);
186 static ptid_t
remote_current_thread (ptid_t oldptid
);
188 static void remote_find_new_threads (void);
190 static void record_currthread (int currthread
);
192 static int fromhex (int a
);
194 static int hex2bin (const char *hex
, char *bin
, int count
);
196 static int bin2hex (const char *bin
, char *hex
, int count
);
198 static int putpkt_binary (char *buf
, int cnt
);
200 static void check_binary_download (CORE_ADDR addr
);
202 struct packet_config
;
204 static void show_packet_config_cmd (struct packet_config
*config
);
206 static void update_packet_config (struct packet_config
*config
);
208 /* Define the target subroutine names */
210 void open_remote_target (char *, int, struct target_ops
*, int);
212 void _initialize_remote (void);
214 /* Description of the remote protocol. Strictly speaking, when the
215 target is open()ed, remote.c should create a per-target description
216 of the remote protocol using that target's architecture.
217 Unfortunatly, the target stack doesn't include local state. For
218 the moment keep the information in the target's architecture
223 long offset
; /* Offset into G packet. */
224 long regnum
; /* GDB's internal register number. */
225 LONGEST pnum
; /* Remote protocol register number. */
226 int in_g_packet
; /* Always part of G packet. */
227 /* long size in bytes; == REGISTER_RAW_SIZE (regnum); at present. */
228 /* char *name; == REGISTER_NAME (regnum); at present. */
233 /* Description of the remote protocol registers. */
234 long sizeof_g_packet
;
236 /* Description of the remote protocol registers indexed by REGNUM
237 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
238 struct packet_reg
*regs
;
240 /* This is the size (in chars) of the first response to the ``g''
241 packet. It is used as a heuristic when determining the maximum
242 size of memory-read and memory-write packets. A target will
243 typically only reserve a buffer large enough to hold the ``g''
244 packet. The size does not include packet overhead (headers and
246 long actual_register_packet_size
;
248 /* This is the maximum size (in chars) of a non read/write packet.
249 It is also used as a cap on the size of read/write packets. */
250 long remote_packet_size
;
254 /* Handle for retreving the remote protocol data from gdbarch. */
255 static struct gdbarch_data
*remote_gdbarch_data_handle
;
257 static struct remote_state
*
258 get_remote_state (void)
260 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
264 init_remote_state (struct gdbarch
*gdbarch
)
267 struct remote_state
*rs
= xmalloc (sizeof (struct remote_state
));
269 /* Start out by having the remote protocol mimic the existing
270 behavour - just copy in the description of the register cache. */
271 rs
->sizeof_g_packet
= REGISTER_BYTES
; /* OK use. */
273 /* Assume a 1:1 regnum<->pnum table. */
274 rs
->regs
= xcalloc (NUM_REGS
+ NUM_PSEUDO_REGS
, sizeof (struct packet_reg
));
275 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
277 struct packet_reg
*r
= &rs
->regs
[regnum
];
280 r
->offset
= REGISTER_BYTE (regnum
);
281 r
->in_g_packet
= (regnum
< NUM_REGS
);
282 /* ...size = REGISTER_RAW_SIZE (regnum); */
283 /* ...name = REGISTER_NAME (regnum); */
286 /* Default maximum number of characters in a packet body. Many
287 remote stubs have a hardwired buffer size of 400 bytes
288 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
289 as the maximum packet-size to ensure that the packet and an extra
290 NUL character can always fit in the buffer. This stops GDB
291 trashing stubs that try to squeeze an extra NUL into what is
292 already a full buffer (As of 1999-12-04 that was most stubs. */
293 rs
->remote_packet_size
= 400 - 1;
295 /* Should rs->sizeof_g_packet needs more space than the
296 default, adjust the size accordingly. Remember that each byte is
297 encoded as two characters. 32 is the overhead for the packet
298 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
299 (``$NN:G...#NN'') is a better guess, the below has been padded a
301 if (rs
->sizeof_g_packet
> ((rs
->remote_packet_size
- 32) / 2))
302 rs
->remote_packet_size
= (rs
->sizeof_g_packet
* 2 + 32);
304 /* This one is filled in when a ``g'' packet is received. */
305 rs
->actual_register_packet_size
= 0;
311 free_remote_state (struct gdbarch
*gdbarch
, void *pointer
)
313 struct remote_state
*data
= pointer
;
318 static struct packet_reg
*
319 packet_reg_from_regnum (struct remote_state
*rs
, long regnum
)
321 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
325 struct packet_reg
*r
= &rs
->regs
[regnum
];
326 gdb_assert (r
->regnum
== regnum
);
331 static struct packet_reg
*
332 packet_reg_from_pnum (struct remote_state
*rs
, LONGEST pnum
)
335 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
337 struct packet_reg
*r
= &rs
->regs
[i
];
344 /* FIXME: graces/2002-08-08: These variables should eventually be
345 bound to an instance of the target object (as in gdbarch-tdep()),
346 when such a thing exists. */
348 /* This is set to the data address of the access causing the target
349 to stop for a watchpoint. */
350 static CORE_ADDR remote_watch_data_address
;
352 /* This is non-zero if taregt stopped for a watchpoint. */
353 static int remote_stopped_by_watchpoint_p
;
356 static struct target_ops remote_ops
;
358 static struct target_ops extended_remote_ops
;
360 /* Temporary target ops. Just like the remote_ops and
361 extended_remote_ops, but with asynchronous support. */
362 static struct target_ops remote_async_ops
;
364 static struct target_ops extended_async_remote_ops
;
366 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
367 ``forever'' still use the normal timeout mechanism. This is
368 currently used by the ASYNC code to guarentee that target reads
369 during the initial connect always time-out. Once getpkt has been
370 modified to return a timeout indication and, in turn
371 remote_wait()/wait_for_inferior() have gained a timeout parameter
373 static int wait_forever_enabled_p
= 1;
376 /* This variable chooses whether to send a ^C or a break when the user
377 requests program interruption. Although ^C is usually what remote
378 systems expect, and that is the default here, sometimes a break is
379 preferable instead. */
381 static int remote_break
;
383 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
384 remote_open knows that we don't have a file open when the program
386 static struct serial
*remote_desc
= NULL
;
388 /* This is set by the target (thru the 'S' message)
389 to denote that the target is in kernel mode. */
390 static int cisco_kernel_mode
= 0;
392 /* This variable sets the number of bits in an address that are to be
393 sent in a memory ("M" or "m") packet. Normally, after stripping
394 leading zeros, the entire address would be sent. This variable
395 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
396 initial implementation of remote.c restricted the address sent in
397 memory packets to ``host::sizeof long'' bytes - (typically 32
398 bits). Consequently, for 64 bit targets, the upper 32 bits of an
399 address was never sent. Since fixing this bug may cause a break in
400 some remote targets this variable is principly provided to
401 facilitate backward compatibility. */
403 static int remote_address_size
;
405 /* Tempoary to track who currently owns the terminal. See
406 target_async_terminal_* for more details. */
408 static int remote_async_terminal_ours_p
;
411 /* User configurable variables for the number of characters in a
412 memory read/write packet. MIN ((rs->remote_packet_size),
413 rs->sizeof_g_packet) is the default. Some targets need smaller
414 values (fifo overruns, et.al.) and some users need larger values
415 (speed up transfers). The variables ``preferred_*'' (the user
416 request), ``current_*'' (what was actually set) and ``forced_*''
417 (Positive - a soft limit, negative - a hard limit). */
419 struct memory_packet_config
426 /* Compute the current size of a read/write packet. Since this makes
427 use of ``actual_register_packet_size'' the computation is dynamic. */
430 get_memory_packet_size (struct memory_packet_config
*config
)
432 struct remote_state
*rs
= get_remote_state ();
433 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
434 law?) that some hosts don't cope very well with large alloca()
435 calls. Eventually the alloca() code will be replaced by calls to
436 xmalloc() and make_cleanups() allowing this restriction to either
437 be lifted or removed. */
438 #ifndef MAX_REMOTE_PACKET_SIZE
439 #define MAX_REMOTE_PACKET_SIZE 16384
441 /* NOTE: 16 is just chosen at random. */
442 #ifndef MIN_REMOTE_PACKET_SIZE
443 #define MIN_REMOTE_PACKET_SIZE 16
448 if (config
->size
<= 0)
449 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
451 what_they_get
= config
->size
;
455 what_they_get
= (rs
->remote_packet_size
);
456 /* Limit the packet to the size specified by the user. */
458 && what_they_get
> config
->size
)
459 what_they_get
= config
->size
;
460 /* Limit it to the size of the targets ``g'' response. */
461 if ((rs
->actual_register_packet_size
) > 0
462 && what_they_get
> (rs
->actual_register_packet_size
))
463 what_they_get
= (rs
->actual_register_packet_size
);
465 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
466 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
467 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
468 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
469 return what_they_get
;
472 /* Update the size of a read/write packet. If they user wants
473 something really big then do a sanity check. */
476 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
478 int fixed_p
= config
->fixed_p
;
479 long size
= config
->size
;
481 error ("Argument required (integer, `fixed' or `limited').");
482 else if (strcmp (args
, "hard") == 0
483 || strcmp (args
, "fixed") == 0)
485 else if (strcmp (args
, "soft") == 0
486 || strcmp (args
, "limit") == 0)
491 size
= strtoul (args
, &end
, 0);
493 error ("Invalid %s (bad syntax).", config
->name
);
495 /* Instead of explicitly capping the size of a packet to
496 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
497 instead allowed to set the size to something arbitrarily
499 if (size
> MAX_REMOTE_PACKET_SIZE
)
500 error ("Invalid %s (too large).", config
->name
);
504 if (fixed_p
&& !config
->fixed_p
)
506 if (! query ("The target may not be able to correctly handle a %s\n"
507 "of %ld bytes. Change the packet size? ",
509 error ("Packet size not changed.");
511 /* Update the config. */
512 config
->fixed_p
= fixed_p
;
517 show_memory_packet_size (struct memory_packet_config
*config
)
519 printf_filtered ("The %s is %ld. ", config
->name
, config
->size
);
521 printf_filtered ("Packets are fixed at %ld bytes.\n",
522 get_memory_packet_size (config
));
524 printf_filtered ("Packets are limited to %ld bytes.\n",
525 get_memory_packet_size (config
));
528 static struct memory_packet_config memory_write_packet_config
=
530 "memory-write-packet-size",
534 set_memory_write_packet_size (char *args
, int from_tty
)
536 set_memory_packet_size (args
, &memory_write_packet_config
);
540 show_memory_write_packet_size (char *args
, int from_tty
)
542 show_memory_packet_size (&memory_write_packet_config
);
546 get_memory_write_packet_size (void)
548 return get_memory_packet_size (&memory_write_packet_config
);
551 static struct memory_packet_config memory_read_packet_config
=
553 "memory-read-packet-size",
557 set_memory_read_packet_size (char *args
, int from_tty
)
559 set_memory_packet_size (args
, &memory_read_packet_config
);
563 show_memory_read_packet_size (char *args
, int from_tty
)
565 show_memory_packet_size (&memory_read_packet_config
);
569 get_memory_read_packet_size (void)
571 struct remote_state
*rs
= get_remote_state ();
572 long size
= get_memory_packet_size (&memory_read_packet_config
);
573 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
574 extra buffer size argument before the memory read size can be
575 increased beyond (rs->remote_packet_size). */
576 if (size
> (rs
->remote_packet_size
))
577 size
= (rs
->remote_packet_size
);
582 /* Generic configuration support for packets the stub optionally
583 supports. Allows the user to specify the use of the packet as well
584 as allowing GDB to auto-detect support in the remote stub. */
588 PACKET_SUPPORT_UNKNOWN
= 0,
597 enum auto_boolean detect
;
598 enum packet_support support
;
601 /* Analyze a packet's return value and update the packet config
612 update_packet_config (struct packet_config
*config
)
614 switch (config
->detect
)
616 case AUTO_BOOLEAN_TRUE
:
617 config
->support
= PACKET_ENABLE
;
619 case AUTO_BOOLEAN_FALSE
:
620 config
->support
= PACKET_DISABLE
;
622 case AUTO_BOOLEAN_AUTO
:
623 config
->support
= PACKET_SUPPORT_UNKNOWN
;
629 show_packet_config_cmd (struct packet_config
*config
)
631 char *support
= "internal-error";
632 switch (config
->support
)
638 support
= "disabled";
640 case PACKET_SUPPORT_UNKNOWN
:
644 switch (config
->detect
)
646 case AUTO_BOOLEAN_AUTO
:
647 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
648 config
->name
, config
->title
, support
);
650 case AUTO_BOOLEAN_TRUE
:
651 case AUTO_BOOLEAN_FALSE
:
652 printf_filtered ("Support for remote protocol `%s' (%s) packet is currently %s.\n",
653 config
->name
, config
->title
, support
);
659 add_packet_config_cmd (struct packet_config
*config
,
662 cmd_sfunc_ftype
*set_func
,
663 cmd_sfunc_ftype
*show_func
,
664 struct cmd_list_element
**set_remote_list
,
665 struct cmd_list_element
**show_remote_list
,
668 struct cmd_list_element
*set_cmd
;
669 struct cmd_list_element
*show_cmd
;
674 config
->title
= title
;
675 config
->detect
= AUTO_BOOLEAN_AUTO
;
676 config
->support
= PACKET_SUPPORT_UNKNOWN
;
677 xasprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
679 xasprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
681 /* set/show TITLE-packet {auto,on,off} */
682 xasprintf (&cmd_name
, "%s-packet", title
);
683 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
684 &config
->detect
, set_doc
, show_doc
,
686 set_remote_list
, show_remote_list
);
687 /* set/show remote NAME-packet {auto,on,off} -- legacy */
691 xasprintf (&legacy_name
, "%s-packet", name
);
692 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
694 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
699 static enum packet_result
700 packet_ok (const char *buf
, struct packet_config
*config
)
704 /* The stub recognized the packet request. Check that the
705 operation succeeded. */
706 switch (config
->support
)
708 case PACKET_SUPPORT_UNKNOWN
:
710 fprintf_unfiltered (gdb_stdlog
,
711 "Packet %s (%s) is supported\n",
712 config
->name
, config
->title
);
713 config
->support
= PACKET_ENABLE
;
716 internal_error (__FILE__
, __LINE__
,
717 "packet_ok: attempt to use a disabled packet");
722 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
723 /* "OK" - definitly OK. */
726 && isxdigit (buf
[1]) && isxdigit (buf
[2])
728 /* "Enn" - definitly an error. */
730 /* The packet may or may not be OK. Just assume it is */
735 /* The stub does not support the packet. */
736 switch (config
->support
)
739 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
740 /* If the stub previously indicated that the packet was
741 supported then there is a protocol error.. */
742 error ("Protocol error: %s (%s) conflicting enabled responses.",
743 config
->name
, config
->title
);
745 /* The user set it wrong. */
746 error ("Enabled packet %s (%s) not recognized by stub",
747 config
->name
, config
->title
);
749 case PACKET_SUPPORT_UNKNOWN
:
751 fprintf_unfiltered (gdb_stdlog
,
752 "Packet %s (%s) is NOT supported\n",
753 config
->name
, config
->title
);
754 config
->support
= PACKET_DISABLE
;
759 return PACKET_UNKNOWN
;
763 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
764 static struct packet_config remote_protocol_qSymbol
;
767 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
768 struct cmd_list_element
*c
)
770 update_packet_config (&remote_protocol_qSymbol
);
774 show_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
775 struct cmd_list_element
*c
)
777 show_packet_config_cmd (&remote_protocol_qSymbol
);
780 /* Should we try the 'e' (step over range) request? */
781 static struct packet_config remote_protocol_e
;
784 set_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
785 struct cmd_list_element
*c
)
787 update_packet_config (&remote_protocol_e
);
791 show_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
792 struct cmd_list_element
*c
)
794 show_packet_config_cmd (&remote_protocol_e
);
798 /* Should we try the 'E' (step over range / w signal #) request? */
799 static struct packet_config remote_protocol_E
;
802 set_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
803 struct cmd_list_element
*c
)
805 update_packet_config (&remote_protocol_E
);
809 show_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
810 struct cmd_list_element
*c
)
812 show_packet_config_cmd (&remote_protocol_E
);
816 /* Should we try the 'P' (set register) request? */
818 static struct packet_config remote_protocol_P
;
821 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
822 struct cmd_list_element
*c
)
824 update_packet_config (&remote_protocol_P
);
828 show_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
829 struct cmd_list_element
*c
)
831 show_packet_config_cmd (&remote_protocol_P
);
834 /* Should we try one of the 'Z' requests? */
838 Z_PACKET_SOFTWARE_BP
,
839 Z_PACKET_HARDWARE_BP
,
846 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
848 /* FIXME: Instead of having all these boiler plate functions, the
849 command callback should include a context argument. */
852 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
853 struct cmd_list_element
*c
)
855 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
859 show_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
860 struct cmd_list_element
*c
)
862 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
866 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
867 struct cmd_list_element
*c
)
869 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
873 show_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
874 struct cmd_list_element
*c
)
876 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
880 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
881 struct cmd_list_element
*c
)
883 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
887 show_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
888 struct cmd_list_element
*c
)
890 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
894 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
895 struct cmd_list_element
*c
)
897 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
901 show_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
902 struct cmd_list_element
*c
)
904 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
908 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
909 struct cmd_list_element
*c
)
911 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
915 show_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
916 struct cmd_list_element
*c
)
918 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
921 /* For compatibility with older distributions. Provide a ``set remote
922 Z-packet ...'' command that updates all the Z packet types. */
924 static enum auto_boolean remote_Z_packet_detect
;
927 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
928 struct cmd_list_element
*c
)
931 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
933 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
934 update_packet_config (&remote_protocol_Z
[i
]);
939 show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
940 struct cmd_list_element
*c
)
943 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
945 show_packet_config_cmd (&remote_protocol_Z
[i
]);
949 /* Should we try the 'X' (remote binary download) packet?
951 This variable (available to the user via "set remote X-packet")
952 dictates whether downloads are sent in binary (via the 'X' packet).
953 We assume that the stub can, and attempt to do it. This will be
954 cleared if the stub does not understand it. This switch is still
955 needed, though in cases when the packet is supported in the stub,
956 but the connection does not allow it (i.e., 7-bit serial connection
959 static struct packet_config remote_protocol_binary_download
;
961 /* Should we try the 'ThreadInfo' query packet?
963 This variable (NOT available to the user: auto-detect only!)
964 determines whether GDB will use the new, simpler "ThreadInfo"
965 query or the older, more complex syntax for thread queries.
966 This is an auto-detect variable (set to true at each connect,
967 and set to false when the target fails to recognize it). */
969 static int use_threadinfo_query
;
970 static int use_threadextra_query
;
973 set_remote_protocol_binary_download_cmd (char *args
,
975 struct cmd_list_element
*c
)
977 update_packet_config (&remote_protocol_binary_download
);
981 show_remote_protocol_binary_download_cmd (char *args
, int from_tty
,
982 struct cmd_list_element
*c
)
984 show_packet_config_cmd (&remote_protocol_binary_download
);
988 /* Tokens for use by the asynchronous signal handlers for SIGINT */
989 static void *sigint_remote_twice_token
;
990 static void *sigint_remote_token
;
992 /* These are pointers to hook functions that may be set in order to
993 modify resume/wait behavior for a particular architecture. */
995 void (*target_resume_hook
) (void);
996 void (*target_wait_loop_hook
) (void);
1000 /* These are the threads which we last sent to the remote system.
1001 -1 for all or -2 for not sent yet. */
1002 static int general_thread
;
1003 static int continue_thread
;
1005 /* Call this function as a result of
1006 1) A halt indication (T packet) containing a thread id
1007 2) A direct query of currthread
1008 3) Successful execution of set thread
1012 record_currthread (int currthread
)
1014 general_thread
= currthread
;
1016 /* If this is a new thread, add it to GDB's thread list.
1017 If we leave it up to WFI to do this, bad things will happen. */
1018 if (!in_thread_list (pid_to_ptid (currthread
)))
1020 add_thread (pid_to_ptid (currthread
));
1021 ui_out_text (uiout
, "[New ");
1022 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
1023 ui_out_text (uiout
, "]\n");
1027 #define MAGIC_NULL_PID 42000
1030 set_thread (int th
, int gen
)
1032 struct remote_state
*rs
= get_remote_state ();
1033 char *buf
= alloca (rs
->remote_packet_size
);
1034 int state
= gen
? general_thread
: continue_thread
;
1040 buf
[1] = gen
? 'g' : 'c';
1041 if (th
== MAGIC_NULL_PID
)
1047 sprintf (&buf
[2], "-%x", -th
);
1049 sprintf (&buf
[2], "%x", th
);
1051 getpkt (buf
, (rs
->remote_packet_size
), 0);
1053 general_thread
= th
;
1055 continue_thread
= th
;
1058 /* Return nonzero if the thread TH is still alive on the remote system. */
1061 remote_thread_alive (ptid_t ptid
)
1063 int tid
= PIDGET (ptid
);
1067 sprintf (buf
, "T-%08x", -tid
);
1069 sprintf (buf
, "T%08x", tid
);
1071 getpkt (buf
, sizeof (buf
), 0);
1072 return (buf
[0] == 'O' && buf
[1] == 'K');
1075 /* About these extended threadlist and threadinfo packets. They are
1076 variable length packets but, the fields within them are often fixed
1077 length. They are redundent enough to send over UDP as is the
1078 remote protocol in general. There is a matching unit test module
1081 #define OPAQUETHREADBYTES 8
1083 /* a 64 bit opaque identifier */
1084 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1086 /* WARNING: This threadref data structure comes from the remote O.S., libstub
1087 protocol encoding, and remote.c. it is not particularly changable */
1089 /* Right now, the internal structure is int. We want it to be bigger.
1093 typedef int gdb_threadref
; /* internal GDB thread reference */
1095 /* gdb_ext_thread_info is an internal GDB data structure which is
1096 equivalint to the reply of the remote threadinfo packet */
1098 struct gdb_ext_thread_info
1100 threadref threadid
; /* External form of thread reference */
1101 int active
; /* Has state interesting to GDB? , regs, stack */
1102 char display
[256]; /* Brief state display, name, blocked/syspended */
1103 char shortname
[32]; /* To be used to name threads */
1104 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
1107 /* The volume of remote transfers can be limited by submitting
1108 a mask containing bits specifying the desired information.
1109 Use a union of these values as the 'selection' parameter to
1110 get_thread_info. FIXME: Make these TAG names more thread specific.
1113 #define TAG_THREADID 1
1114 #define TAG_EXISTS 2
1115 #define TAG_DISPLAY 4
1116 #define TAG_THREADNAME 8
1117 #define TAG_MOREDISPLAY 16
1119 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
1121 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1123 static char *unpack_nibble (char *buf
, int *val
);
1125 static char *pack_nibble (char *buf
, int nibble
);
1127 static char *pack_hex_byte (char *pkt
, int /*unsigned char */ byte
);
1129 static char *unpack_byte (char *buf
, int *value
);
1131 static char *pack_int (char *buf
, int value
);
1133 static char *unpack_int (char *buf
, int *value
);
1135 static char *unpack_string (char *src
, char *dest
, int length
);
1137 static char *pack_threadid (char *pkt
, threadref
* id
);
1139 static char *unpack_threadid (char *inbuf
, threadref
* id
);
1141 void int_to_threadref (threadref
* id
, int value
);
1143 static int threadref_to_int (threadref
* ref
);
1145 static void copy_threadref (threadref
* dest
, threadref
* src
);
1147 static int threadmatch (threadref
* dest
, threadref
* src
);
1149 static char *pack_threadinfo_request (char *pkt
, int mode
, threadref
* id
);
1151 static int remote_unpack_thread_info_response (char *pkt
,
1152 threadref
* expectedref
,
1153 struct gdb_ext_thread_info
1157 static int remote_get_threadinfo (threadref
* threadid
, int fieldset
, /*TAG mask */
1158 struct gdb_ext_thread_info
*info
);
1160 static int adapt_remote_get_threadinfo (gdb_threadref
* ref
,
1162 struct gdb_ext_thread_info
*info
);
1164 static char *pack_threadlist_request (char *pkt
, int startflag
,
1166 threadref
* nextthread
);
1168 static int parse_threadlist_response (char *pkt
,
1170 threadref
* original_echo
,
1171 threadref
* resultlist
, int *doneflag
);
1173 static int remote_get_threadlist (int startflag
,
1174 threadref
* nextthread
,
1177 int *result_count
, threadref
* threadlist
);
1179 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
1181 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1182 void *context
, int looplimit
);
1184 static int remote_newthread_step (threadref
* ref
, void *context
);
1186 /* encode 64 bits in 16 chars of hex */
1188 static const char hexchars
[] = "0123456789abcdef";
1191 ishex (int ch
, int *val
)
1193 if ((ch
>= 'a') && (ch
<= 'f'))
1195 *val
= ch
- 'a' + 10;
1198 if ((ch
>= 'A') && (ch
<= 'F'))
1200 *val
= ch
- 'A' + 10;
1203 if ((ch
>= '0') && (ch
<= '9'))
1214 if (ch
>= 'a' && ch
<= 'f')
1215 return ch
- 'a' + 10;
1216 if (ch
>= '0' && ch
<= '9')
1218 if (ch
>= 'A' && ch
<= 'F')
1219 return ch
- 'A' + 10;
1224 stub_unpack_int (char *buff
, int fieldlength
)
1231 nibble
= stubhex (*buff
++);
1235 retval
= retval
<< 4;
1241 unpack_varlen_hex (char *buff
, /* packet to parse */
1247 while (ishex (*buff
, &nibble
))
1250 retval
= retval
<< 4;
1251 retval
|= nibble
& 0x0f;
1258 unpack_nibble (char *buf
, int *val
)
1260 ishex (*buf
++, val
);
1265 pack_nibble (char *buf
, int nibble
)
1267 *buf
++ = hexchars
[(nibble
& 0x0f)];
1272 pack_hex_byte (char *pkt
, int byte
)
1274 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1275 *pkt
++ = hexchars
[(byte
& 0xf)];
1280 unpack_byte (char *buf
, int *value
)
1282 *value
= stub_unpack_int (buf
, 2);
1287 pack_int (char *buf
, int value
)
1289 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1290 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1291 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1292 buf
= pack_hex_byte (buf
, (value
& 0xff));
1297 unpack_int (char *buf
, int *value
)
1299 *value
= stub_unpack_int (buf
, 8);
1303 #if 0 /* currently unused, uncomment when needed */
1304 static char *pack_string (char *pkt
, char *string
);
1307 pack_string (char *pkt
, char *string
)
1312 len
= strlen (string
);
1314 len
= 200; /* Bigger than most GDB packets, junk??? */
1315 pkt
= pack_hex_byte (pkt
, len
);
1319 if ((ch
== '\0') || (ch
== '#'))
1320 ch
= '*'; /* Protect encapsulation */
1325 #endif /* 0 (unused) */
1328 unpack_string (char *src
, char *dest
, int length
)
1337 pack_threadid (char *pkt
, threadref
*id
)
1340 unsigned char *altid
;
1342 altid
= (unsigned char *) id
;
1343 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1345 pkt
= pack_hex_byte (pkt
, *altid
++);
1351 unpack_threadid (char *inbuf
, threadref
*id
)
1354 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1357 altref
= (char *) id
;
1359 while (inbuf
< limit
)
1361 x
= stubhex (*inbuf
++);
1362 y
= stubhex (*inbuf
++);
1363 *altref
++ = (x
<< 4) | y
;
1368 /* Externally, threadrefs are 64 bits but internally, they are still
1369 ints. This is due to a mismatch of specifications. We would like
1370 to use 64bit thread references internally. This is an adapter
1374 int_to_threadref (threadref
*id
, int value
)
1376 unsigned char *scan
;
1378 scan
= (unsigned char *) id
;
1384 *scan
++ = (value
>> 24) & 0xff;
1385 *scan
++ = (value
>> 16) & 0xff;
1386 *scan
++ = (value
>> 8) & 0xff;
1387 *scan
++ = (value
& 0xff);
1391 threadref_to_int (threadref
*ref
)
1394 unsigned char *scan
;
1396 scan
= (char *) ref
;
1400 value
= (value
<< 8) | ((*scan
++) & 0xff);
1405 copy_threadref (threadref
*dest
, threadref
*src
)
1408 unsigned char *csrc
, *cdest
;
1410 csrc
= (unsigned char *) src
;
1411 cdest
= (unsigned char *) dest
;
1418 threadmatch (threadref
*dest
, threadref
*src
)
1420 /* things are broken right now, so just assume we got a match */
1422 unsigned char *srcp
, *destp
;
1424 srcp
= (char *) src
;
1425 destp
= (char *) dest
;
1429 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1436 threadid:1, # always request threadid
1443 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1446 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1448 *pkt
++ = 'q'; /* Info Query */
1449 *pkt
++ = 'P'; /* process or thread info */
1450 pkt
= pack_int (pkt
, mode
); /* mode */
1451 pkt
= pack_threadid (pkt
, id
); /* threadid */
1452 *pkt
= '\0'; /* terminate */
1456 /* These values tag the fields in a thread info response packet */
1457 /* Tagging the fields allows us to request specific fields and to
1458 add more fields as time goes by */
1460 #define TAG_THREADID 1 /* Echo the thread identifier */
1461 #define TAG_EXISTS 2 /* Is this process defined enough to
1462 fetch registers and its stack */
1463 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1464 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1465 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1469 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1470 struct gdb_ext_thread_info
*info
)
1472 struct remote_state
*rs
= get_remote_state ();
1476 char *limit
= pkt
+ (rs
->remote_packet_size
); /* plausable parsing limit */
1479 /* info->threadid = 0; FIXME: implement zero_threadref */
1481 info
->display
[0] = '\0';
1482 info
->shortname
[0] = '\0';
1483 info
->more_display
[0] = '\0';
1485 /* Assume the characters indicating the packet type have been stripped */
1486 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1487 pkt
= unpack_threadid (pkt
, &ref
);
1490 warning ("Incomplete response to threadinfo request\n");
1491 if (!threadmatch (&ref
, expectedref
))
1492 { /* This is an answer to a different request */
1493 warning ("ERROR RMT Thread info mismatch\n");
1496 copy_threadref (&info
->threadid
, &ref
);
1498 /* Loop on tagged fields , try to bail if somthing goes wrong */
1500 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1502 pkt
= unpack_int (pkt
, &tag
); /* tag */
1503 pkt
= unpack_byte (pkt
, &length
); /* length */
1504 if (!(tag
& mask
)) /* tags out of synch with mask */
1506 warning ("ERROR RMT: threadinfo tag mismatch\n");
1510 if (tag
== TAG_THREADID
)
1514 warning ("ERROR RMT: length of threadid is not 16\n");
1518 pkt
= unpack_threadid (pkt
, &ref
);
1519 mask
= mask
& ~TAG_THREADID
;
1522 if (tag
== TAG_EXISTS
)
1524 info
->active
= stub_unpack_int (pkt
, length
);
1526 mask
= mask
& ~(TAG_EXISTS
);
1529 warning ("ERROR RMT: 'exists' length too long\n");
1535 if (tag
== TAG_THREADNAME
)
1537 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1538 mask
= mask
& ~TAG_THREADNAME
;
1541 if (tag
== TAG_DISPLAY
)
1543 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1544 mask
= mask
& ~TAG_DISPLAY
;
1547 if (tag
== TAG_MOREDISPLAY
)
1549 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1550 mask
= mask
& ~TAG_MOREDISPLAY
;
1553 warning ("ERROR RMT: unknown thread info tag\n");
1554 break; /* Not a tag we know about */
1560 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1561 struct gdb_ext_thread_info
*info
)
1563 struct remote_state
*rs
= get_remote_state ();
1565 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1567 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1568 putpkt (threadinfo_pkt
);
1569 getpkt (threadinfo_pkt
, (rs
->remote_packet_size
), 0);
1570 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1575 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1576 representation of a threadid. */
1579 adapt_remote_get_threadinfo (gdb_threadref
*ref
, int selection
,
1580 struct gdb_ext_thread_info
*info
)
1584 int_to_threadref (&lclref
, *ref
);
1585 return remote_get_threadinfo (&lclref
, selection
, info
);
1588 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1591 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1592 threadref
*nextthread
)
1594 *pkt
++ = 'q'; /* info query packet */
1595 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1596 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1597 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1598 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1603 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1606 parse_threadlist_response (char *pkt
, int result_limit
,
1607 threadref
*original_echo
, threadref
*resultlist
,
1610 struct remote_state
*rs
= get_remote_state ();
1612 int count
, resultcount
, done
;
1615 /* Assume the 'q' and 'M chars have been stripped. */
1616 limit
= pkt
+ ((rs
->remote_packet_size
) - BUF_THREAD_ID_SIZE
); /* done parse past here */
1617 pkt
= unpack_byte (pkt
, &count
); /* count field */
1618 pkt
= unpack_nibble (pkt
, &done
);
1619 /* The first threadid is the argument threadid. */
1620 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1621 while ((count
-- > 0) && (pkt
< limit
))
1623 pkt
= unpack_threadid (pkt
, resultlist
++);
1624 if (resultcount
++ >= result_limit
)
1633 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1634 int *done
, int *result_count
, threadref
*threadlist
)
1636 struct remote_state
*rs
= get_remote_state ();
1637 static threadref echo_nextthread
;
1638 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1639 char *t_response
= alloca (rs
->remote_packet_size
);
1642 /* Trancate result limit to be smaller than the packet size */
1643 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= (rs
->remote_packet_size
))
1644 result_limit
= ((rs
->remote_packet_size
) / BUF_THREAD_ID_SIZE
) - 2;
1646 pack_threadlist_request (threadlist_packet
,
1647 startflag
, result_limit
, nextthread
);
1648 putpkt (threadlist_packet
);
1649 getpkt (t_response
, (rs
->remote_packet_size
), 0);
1652 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1655 if (!threadmatch (&echo_nextthread
, nextthread
))
1657 /* FIXME: This is a good reason to drop the packet */
1658 /* Possably, there is a duplicate response */
1660 retransmit immediatly - race conditions
1661 retransmit after timeout - yes
1663 wait for packet, then exit
1665 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1666 return 0; /* I choose simply exiting */
1668 if (*result_count
<= 0)
1672 warning ("RMT ERROR : failed to get remote thread list\n");
1675 return result
; /* break; */
1677 if (*result_count
> result_limit
)
1680 warning ("RMT ERROR: threadlist response longer than requested\n");
1686 /* This is the interface between remote and threads, remotes upper interface */
1688 /* remote_find_new_threads retrieves the thread list and for each
1689 thread in the list, looks up the thread in GDB's internal list,
1690 ading the thread if it does not already exist. This involves
1691 getting partial thread lists from the remote target so, polling the
1692 quit_flag is required. */
1695 /* About this many threadisds fit in a packet. */
1697 #define MAXTHREADLISTRESULTS 32
1700 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1703 int done
, i
, result_count
;
1707 static threadref nextthread
;
1708 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1713 if (loopcount
++ > looplimit
)
1716 warning ("Remote fetch threadlist -infinite loop-\n");
1719 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1720 &done
, &result_count
, resultthreadlist
))
1725 /* clear for later iterations */
1727 /* Setup to resume next batch of thread references, set nextthread. */
1728 if (result_count
>= 1)
1729 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1731 while (result_count
--)
1732 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1739 remote_newthread_step (threadref
*ref
, void *context
)
1743 ptid
= pid_to_ptid (threadref_to_int (ref
));
1745 if (!in_thread_list (ptid
))
1747 return 1; /* continue iterator */
1750 #define CRAZY_MAX_THREADS 1000
1753 remote_current_thread (ptid_t oldpid
)
1755 struct remote_state
*rs
= get_remote_state ();
1756 char *buf
= alloca (rs
->remote_packet_size
);
1759 getpkt (buf
, (rs
->remote_packet_size
), 0);
1760 if (buf
[0] == 'Q' && buf
[1] == 'C')
1761 return pid_to_ptid (strtol (&buf
[2], NULL
, 16));
1766 /* Find new threads for info threads command.
1767 * Original version, using John Metzler's thread protocol.
1771 remote_find_new_threads (void)
1773 remote_threadlist_iterator (remote_newthread_step
, 0,
1775 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1776 inferior_ptid
= remote_current_thread (inferior_ptid
);
1780 * Find all threads for info threads command.
1781 * Uses new thread protocol contributed by Cisco.
1782 * Falls back and attempts to use the older method (above)
1783 * if the target doesn't respond to the new method.
1787 remote_threads_info (void)
1789 struct remote_state
*rs
= get_remote_state ();
1790 char *buf
= alloca (rs
->remote_packet_size
);
1794 if (remote_desc
== 0) /* paranoia */
1795 error ("Command can only be used when connected to the remote target.");
1797 if (use_threadinfo_query
)
1799 putpkt ("qfThreadInfo");
1801 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1802 if (bufp
[0] != '\0') /* q packet recognized */
1804 while (*bufp
++ == 'm') /* reply contains one or more TID */
1808 tid
= strtol (bufp
, &bufp
, 16);
1809 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1810 add_thread (pid_to_ptid (tid
));
1812 while (*bufp
++ == ','); /* comma-separated list */
1813 putpkt ("qsThreadInfo");
1815 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1821 /* Else fall back to old method based on jmetzler protocol. */
1822 use_threadinfo_query
= 0;
1823 remote_find_new_threads ();
1828 * Collect a descriptive string about the given thread.
1829 * The target may say anything it wants to about the thread
1830 * (typically info about its blocked / runnable state, name, etc.).
1831 * This string will appear in the info threads display.
1833 * Optional: targets are not required to implement this function.
1837 remote_threads_extra_info (struct thread_info
*tp
)
1839 struct remote_state
*rs
= get_remote_state ();
1843 struct gdb_ext_thread_info threadinfo
;
1844 static char display_buf
[100]; /* arbitrary... */
1845 char *bufp
= alloca (rs
->remote_packet_size
);
1846 int n
= 0; /* position in display_buf */
1848 if (remote_desc
== 0) /* paranoia */
1849 internal_error (__FILE__
, __LINE__
,
1850 "remote_threads_extra_info");
1852 if (use_threadextra_query
)
1854 sprintf (bufp
, "qThreadExtraInfo,%x", PIDGET (tp
->ptid
));
1856 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1859 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1860 result
= hex2bin (bufp
, display_buf
, n
);
1861 display_buf
[result
] = '\0';
1866 /* If the above query fails, fall back to the old method. */
1867 use_threadextra_query
= 0;
1868 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1869 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1870 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1871 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1872 if (threadinfo
.active
)
1874 if (*threadinfo
.shortname
)
1875 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1876 if (*threadinfo
.display
)
1877 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1878 if (*threadinfo
.more_display
)
1879 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1880 threadinfo
.more_display
);
1884 /* for purely cosmetic reasons, clear up trailing commas */
1885 if (',' == display_buf
[n
-1])
1886 display_buf
[n
-1] = ' ';
1895 /* Restart the remote side; this is an extended protocol operation. */
1898 extended_remote_restart (void)
1900 struct remote_state
*rs
= get_remote_state ();
1901 char *buf
= alloca (rs
->remote_packet_size
);
1903 /* Send the restart command; for reasons I don't understand the
1904 remote side really expects a number after the "R". */
1906 sprintf (&buf
[1], "%x", 0);
1909 /* Now query for status so this looks just like we restarted
1910 gdbserver from scratch. */
1912 getpkt (buf
, (rs
->remote_packet_size
), 0);
1915 /* Clean up connection to a remote debugger. */
1919 remote_close (int quitting
)
1922 serial_close (remote_desc
);
1926 /* Query the remote side for the text, data and bss offsets. */
1931 struct remote_state
*rs
= get_remote_state ();
1932 char *buf
= alloca (rs
->remote_packet_size
);
1935 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1936 struct section_offsets
*offs
;
1938 putpkt ("qOffsets");
1940 getpkt (buf
, (rs
->remote_packet_size
), 0);
1942 if (buf
[0] == '\000')
1943 return; /* Return silently. Stub doesn't support
1947 warning ("Remote failure reply: %s", buf
);
1951 /* Pick up each field in turn. This used to be done with scanf, but
1952 scanf will make trouble if CORE_ADDR size doesn't match
1953 conversion directives correctly. The following code will work
1954 with any size of CORE_ADDR. */
1955 text_addr
= data_addr
= bss_addr
= 0;
1959 if (strncmp (ptr
, "Text=", 5) == 0)
1962 /* Don't use strtol, could lose on big values. */
1963 while (*ptr
&& *ptr
!= ';')
1964 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1969 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1972 while (*ptr
&& *ptr
!= ';')
1973 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1978 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1981 while (*ptr
&& *ptr
!= ';')
1982 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1988 error ("Malformed response to offset query, %s", buf
);
1990 if (symfile_objfile
== NULL
)
1993 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
1994 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
1996 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
1998 /* This is a temporary kludge to force data and bss to use the same offsets
1999 because that's what nlmconv does now. The real solution requires changes
2000 to the stub and remote.c that I don't have time to do right now. */
2002 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2003 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2005 objfile_relocate (symfile_objfile
, offs
);
2009 * Cisco version of section offsets:
2011 * Instead of having GDB query the target for the section offsets,
2012 * Cisco lets the target volunteer the information! It's also in
2013 * a different format, so here are the functions that will decode
2014 * a section offset packet from a Cisco target.
2018 * Function: remote_cisco_section_offsets
2020 * Returns: zero for success, non-zero for failure
2024 remote_cisco_section_offsets (bfd_vma text_addr
,
2027 bfd_signed_vma
*text_offs
,
2028 bfd_signed_vma
*data_offs
,
2029 bfd_signed_vma
*bss_offs
)
2031 bfd_vma text_base
, data_base
, bss_base
;
2032 struct minimal_symbol
*start
;
2037 if (symfile_objfile
== NULL
)
2038 return -1; /* no can do nothin' */
2040 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
2042 return -1; /* Can't find "_start" symbol */
2044 data_base
= bss_base
= 0;
2045 text_base
= SYMBOL_VALUE_ADDRESS (start
);
2047 abfd
= symfile_objfile
->obfd
;
2048 for (sect
= abfd
->sections
;
2052 const char *p
= bfd_get_section_name (abfd
, sect
);
2054 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
2055 if (data_base
== 0 ||
2056 data_base
> bfd_get_section_vma (abfd
, sect
))
2057 data_base
= bfd_get_section_vma (abfd
, sect
);
2058 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
2059 if (bss_base
== 0 ||
2060 bss_base
> bfd_get_section_vma (abfd
, sect
))
2061 bss_base
= bfd_get_section_vma (abfd
, sect
);
2063 *text_offs
= text_addr
- text_base
;
2064 *data_offs
= data_addr
- data_base
;
2065 *bss_offs
= bss_addr
- bss_base
;
2070 sprintf (tmp
, "VMA: text = 0x");
2071 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
2072 sprintf (tmp
+ strlen (tmp
), " data = 0x");
2073 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
2074 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
2075 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
2076 fprintf_filtered (gdb_stdlog
, tmp
);
2077 fprintf_filtered (gdb_stdlog
,
2078 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
2079 paddr_nz (*text_offs
),
2080 paddr_nz (*data_offs
),
2081 paddr_nz (*bss_offs
));
2088 * Function: remote_cisco_objfile_relocate
2090 * Relocate the symbol file for a remote target.
2094 remote_cisco_objfile_relocate (bfd_signed_vma text_off
, bfd_signed_vma data_off
,
2095 bfd_signed_vma bss_off
)
2097 struct section_offsets
*offs
;
2099 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2101 /* FIXME: This code assumes gdb-stabs.h is being used; it's
2102 broken for xcoff, dwarf, sdb-coff, etc. But there is no
2103 simple canonical representation for this stuff. */
2105 offs
= (struct section_offsets
*) alloca (SIZEOF_SECTION_OFFSETS
);
2106 memcpy (offs
, symfile_objfile
->section_offsets
, SIZEOF_SECTION_OFFSETS
);
2108 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_off
;
2109 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_off
;
2110 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = bss_off
;
2112 /* First call the standard objfile_relocate. */
2113 objfile_relocate (symfile_objfile
, offs
);
2115 /* Now we need to fix up the section entries already attached to
2116 the exec target. These entries will control memory transfers
2117 from the exec file. */
2119 exec_set_section_offsets (text_off
, data_off
, bss_off
);
2123 /* Stub for catch_errors. */
2126 remote_start_remote_dummy (struct ui_out
*uiout
, void *dummy
)
2128 start_remote (); /* Initialize gdb process mechanisms */
2129 /* NOTE: Return something >=0. A -ve value is reserved for
2130 catch_exceptions. */
2135 remote_start_remote (struct ui_out
*uiout
, void *dummy
)
2137 immediate_quit
++; /* Allow user to interrupt it */
2139 /* Ack any packet which the remote side has already sent. */
2140 serial_write (remote_desc
, "+", 1);
2142 /* Let the stub know that we want it to return the thread. */
2145 inferior_ptid
= remote_current_thread (inferior_ptid
);
2147 get_offsets (); /* Get text, data & bss offsets */
2149 putpkt ("?"); /* initiate a query from remote machine */
2152 /* NOTE: See comment above in remote_start_remote_dummy(). This
2153 function returns something >=0. */
2154 return remote_start_remote_dummy (uiout
, dummy
);
2157 /* Open a connection to a remote debugger.
2158 NAME is the filename used for communication. */
2161 remote_open (char *name
, int from_tty
)
2163 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
2166 /* Just like remote_open, but with asynchronous support. */
2168 remote_async_open (char *name
, int from_tty
)
2170 remote_async_open_1 (name
, from_tty
, &remote_async_ops
, 0);
2173 /* Open a connection to a remote debugger using the extended
2174 remote gdb protocol. NAME is the filename used for communication. */
2177 extended_remote_open (char *name
, int from_tty
)
2179 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */ );
2182 /* Just like extended_remote_open, but with asynchronous support. */
2184 extended_remote_async_open (char *name
, int from_tty
)
2186 remote_async_open_1 (name
, from_tty
, &extended_async_remote_ops
, 1 /*extended_p */ );
2189 /* Generic code for opening a connection to a remote target. */
2192 init_all_packet_configs (void)
2195 update_packet_config (&remote_protocol_e
);
2196 update_packet_config (&remote_protocol_E
);
2197 update_packet_config (&remote_protocol_P
);
2198 update_packet_config (&remote_protocol_qSymbol
);
2199 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2200 update_packet_config (&remote_protocol_Z
[i
]);
2201 /* Force remote_write_bytes to check whether target supports binary
2203 update_packet_config (&remote_protocol_binary_download
);
2206 /* Symbol look-up. */
2209 remote_check_symbols (struct objfile
*objfile
)
2211 struct remote_state
*rs
= get_remote_state ();
2212 char *msg
, *reply
, *tmp
;
2213 struct minimal_symbol
*sym
;
2216 if (remote_protocol_qSymbol
.support
== PACKET_DISABLE
)
2219 msg
= alloca (rs
->remote_packet_size
);
2220 reply
= alloca (rs
->remote_packet_size
);
2222 /* Invite target to request symbol lookups. */
2224 putpkt ("qSymbol::");
2225 getpkt (reply
, (rs
->remote_packet_size
), 0);
2226 packet_ok (reply
, &remote_protocol_qSymbol
);
2228 while (strncmp (reply
, "qSymbol:", 8) == 0)
2231 end
= hex2bin (tmp
, msg
, strlen (tmp
) / 2);
2233 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2235 sprintf (msg
, "qSymbol::%s", &reply
[8]);
2237 sprintf (msg
, "qSymbol:%s:%s",
2238 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2241 getpkt (reply
, (rs
->remote_packet_size
), 0);
2245 static struct serial
*
2246 remote_serial_open (char *name
)
2248 static int udp_warning
= 0;
2250 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2251 of in ser-tcp.c, because it is the remote protocol assuming that the
2252 serial connection is reliable and not the serial connection promising
2254 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2256 warning ("The remote protocol may be unreliable over UDP.");
2257 warning ("Some events may be lost, rendering further debugging "
2262 return serial_open (name
);
2266 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2270 struct remote_state
*rs
= get_remote_state ();
2272 error ("To open a remote debug connection, you need to specify what\n"
2273 "serial device is attached to the remote system\n"
2274 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2276 /* See FIXME above */
2277 wait_forever_enabled_p
= 1;
2279 target_preopen (from_tty
);
2281 unpush_target (target
);
2283 remote_desc
= remote_serial_open (name
);
2285 perror_with_name (name
);
2287 if (baud_rate
!= -1)
2289 if (serial_setbaudrate (remote_desc
, baud_rate
))
2291 serial_close (remote_desc
);
2292 perror_with_name (name
);
2296 serial_raw (remote_desc
);
2298 /* If there is something sitting in the buffer we might take it as a
2299 response to a command, which would be bad. */
2300 serial_flush_input (remote_desc
);
2304 puts_filtered ("Remote debugging using ");
2305 puts_filtered (name
);
2306 puts_filtered ("\n");
2308 push_target (target
); /* Switch to using remote target now */
2310 init_all_packet_configs ();
2312 general_thread
= -2;
2313 continue_thread
= -2;
2315 /* Probe for ability to use "ThreadInfo" query, as required. */
2316 use_threadinfo_query
= 1;
2317 use_threadextra_query
= 1;
2319 /* Without this, some commands which require an active target (such
2320 as kill) won't work. This variable serves (at least) double duty
2321 as both the pid of the target process (if it has such), and as a
2322 flag indicating that a target is active. These functions should
2323 be split out into seperate variables, especially since GDB will
2324 someday have a notion of debugging several processes. */
2326 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2327 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2328 /* First delete any symbols previously loaded from shared libraries. */
2329 no_shared_libraries (NULL
, 0);
2332 /* Start the remote connection. If error() or QUIT, discard this
2333 target (we'd otherwise be in an inconsistent state) and then
2334 propogate the error on up the exception chain. This ensures that
2335 the caller doesn't stumble along blindly assuming that the
2336 function succeeded. The CLI doesn't have this problem but other
2337 UI's, such as MI do.
2339 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2340 this function should return an error indication letting the
2341 caller restore the previous state. Unfortunatly the command
2342 ``target remote'' is directly wired to this function making that
2343 impossible. On a positive note, the CLI side of this problem has
2344 been fixed - the function set_cmd_context() makes it possible for
2345 all the ``target ....'' commands to share a common callback
2346 function. See cli-dump.c. */
2347 ex
= catch_exceptions (uiout
,
2348 remote_start_remote
, NULL
,
2349 "Couldn't establish connection to remote"
2355 throw_exception (ex
);
2360 /* Tell the remote that we are using the extended protocol. */
2361 char *buf
= alloca (rs
->remote_packet_size
);
2363 getpkt (buf
, (rs
->remote_packet_size
), 0);
2365 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2366 /* FIXME: need a master target_open vector from which all
2367 remote_opens can be called, so that stuff like this can
2368 go there. Failing that, the following code must be copied
2369 to the open function for any remote target that wants to
2370 support svr4 shared libraries. */
2372 /* Set up to detect and load shared libraries. */
2373 if (exec_bfd
) /* No use without an exec file. */
2375 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2376 remote_check_symbols (symfile_objfile
);
2381 /* Just like remote_open but with asynchronous support. */
2383 remote_async_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2387 struct remote_state
*rs
= get_remote_state ();
2389 error ("To open a remote debug connection, you need to specify what\n"
2390 "serial device is attached to the remote system\n"
2391 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2393 target_preopen (from_tty
);
2395 unpush_target (target
);
2397 remote_desc
= remote_serial_open (name
);
2399 perror_with_name (name
);
2401 if (baud_rate
!= -1)
2403 if (serial_setbaudrate (remote_desc
, baud_rate
))
2405 serial_close (remote_desc
);
2406 perror_with_name (name
);
2410 serial_raw (remote_desc
);
2412 /* If there is something sitting in the buffer we might take it as a
2413 response to a command, which would be bad. */
2414 serial_flush_input (remote_desc
);
2418 puts_filtered ("Remote debugging using ");
2419 puts_filtered (name
);
2420 puts_filtered ("\n");
2423 push_target (target
); /* Switch to using remote target now */
2425 init_all_packet_configs ();
2427 general_thread
= -2;
2428 continue_thread
= -2;
2430 /* Probe for ability to use "ThreadInfo" query, as required. */
2431 use_threadinfo_query
= 1;
2432 use_threadextra_query
= 1;
2434 /* Without this, some commands which require an active target (such
2435 as kill) won't work. This variable serves (at least) double duty
2436 as both the pid of the target process (if it has such), and as a
2437 flag indicating that a target is active. These functions should
2438 be split out into seperate variables, especially since GDB will
2439 someday have a notion of debugging several processes. */
2440 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2442 /* With this target we start out by owning the terminal. */
2443 remote_async_terminal_ours_p
= 1;
2445 /* FIXME: cagney/1999-09-23: During the initial connection it is
2446 assumed that the target is already ready and able to respond to
2447 requests. Unfortunately remote_start_remote() eventually calls
2448 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2449 around this. Eventually a mechanism that allows
2450 wait_for_inferior() to expect/get timeouts will be
2452 wait_forever_enabled_p
= 0;
2454 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2455 /* First delete any symbols previously loaded from shared libraries. */
2456 no_shared_libraries (NULL
, 0);
2459 /* Start the remote connection; if error, discard this target. See
2460 the comments in remote_open_1() for further details such as the
2461 need to re-throw the exception. */
2462 ex
= catch_exceptions (uiout
,
2463 remote_start_remote
, NULL
,
2464 "Couldn't establish connection to remote"
2470 wait_forever_enabled_p
= 1;
2471 throw_exception (ex
);
2474 wait_forever_enabled_p
= 1;
2478 /* Tell the remote that we are using the extended protocol. */
2479 char *buf
= alloca (rs
->remote_packet_size
);
2481 getpkt (buf
, (rs
->remote_packet_size
), 0);
2483 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2484 /* FIXME: need a master target_open vector from which all
2485 remote_opens can be called, so that stuff like this can
2486 go there. Failing that, the following code must be copied
2487 to the open function for any remote target that wants to
2488 support svr4 shared libraries. */
2490 /* Set up to detect and load shared libraries. */
2491 if (exec_bfd
) /* No use without an exec file. */
2493 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2494 remote_check_symbols (symfile_objfile
);
2499 /* This takes a program previously attached to and detaches it. After
2500 this is done, GDB can be used to debug some other program. We
2501 better not have left any breakpoints in the target program or it'll
2502 die when it hits one. */
2505 remote_detach (char *args
, int from_tty
)
2507 struct remote_state
*rs
= get_remote_state ();
2508 char *buf
= alloca (rs
->remote_packet_size
);
2511 error ("Argument given to \"detach\" when remotely debugging.");
2513 /* Tell the remote target to detach. */
2515 remote_send (buf
, (rs
->remote_packet_size
));
2517 target_mourn_inferior ();
2519 puts_filtered ("Ending remote debugging.\n");
2523 /* Same as remote_detach, but with async support. */
2525 remote_async_detach (char *args
, int from_tty
)
2527 struct remote_state
*rs
= get_remote_state ();
2528 char *buf
= alloca (rs
->remote_packet_size
);
2531 error ("Argument given to \"detach\" when remotely debugging.");
2533 /* Tell the remote target to detach. */
2535 remote_send (buf
, (rs
->remote_packet_size
));
2537 /* Unregister the file descriptor from the event loop. */
2538 if (target_is_async_p ())
2539 serial_async (remote_desc
, NULL
, 0);
2541 target_mourn_inferior ();
2543 puts_filtered ("Ending remote debugging.\n");
2546 /* Convert hex digit A to a number. */
2551 if (a
>= '0' && a
<= '9')
2553 else if (a
>= 'a' && a
<= 'f')
2554 return a
- 'a' + 10;
2555 else if (a
>= 'A' && a
<= 'F')
2556 return a
- 'A' + 10;
2558 error ("Reply contains invalid hex digit %d", a
);
2562 hex2bin (const char *hex
, char *bin
, int count
)
2566 for (i
= 0; i
< count
; i
++)
2568 if (hex
[0] == 0 || hex
[1] == 0)
2570 /* Hex string is short, or of uneven length.
2571 Return the count that has been converted so far. */
2574 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2580 /* Convert number NIB to a hex digit. */
2588 return 'a' + nib
- 10;
2592 bin2hex (const char *bin
, char *hex
, int count
)
2595 /* May use a length, or a nul-terminated string as input. */
2597 count
= strlen (bin
);
2599 for (i
= 0; i
< count
; i
++)
2601 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2602 *hex
++ = tohex (*bin
++ & 0xf);
2608 /* Tell the remote machine to resume. */
2610 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2612 static int last_sent_step
;
2615 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2617 struct remote_state
*rs
= get_remote_state ();
2618 char *buf
= alloca (rs
->remote_packet_size
);
2619 int pid
= PIDGET (ptid
);
2623 set_thread (0, 0); /* run any thread */
2625 set_thread (pid
, 0); /* run this thread */
2627 last_sent_signal
= siggnal
;
2628 last_sent_step
= step
;
2630 /* A hook for when we need to do something at the last moment before
2632 if (target_resume_hook
)
2633 (*target_resume_hook
) ();
2636 /* The s/S/c/C packets do not return status. So if the target does
2637 not support the S or C packets, the debug agent returns an empty
2638 string which is detected in remote_wait(). This protocol defect
2639 is fixed in the e/E packets. */
2641 if (step
&& step_range_end
)
2643 /* If the target does not support the 'E' packet, we try the 'S'
2644 packet. Ideally we would fall back to the 'e' packet if that
2645 too is not supported. But that would require another copy of
2646 the code to issue the 'e' packet (and fall back to 's' if not
2647 supported) in remote_wait(). */
2649 if (siggnal
!= TARGET_SIGNAL_0
)
2651 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2655 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2656 *p
++ = tohex (((int) siggnal
) & 0xf);
2658 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2660 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2664 getpkt (buf
, (rs
->remote_packet_size
), 0);
2666 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2672 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2676 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2678 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2682 getpkt (buf
, (rs
->remote_packet_size
), 0);
2684 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2690 if (siggnal
!= TARGET_SIGNAL_0
)
2692 buf
[0] = step
? 'S' : 'C';
2693 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2694 buf
[2] = tohex (((int) siggnal
) & 0xf);
2698 strcpy (buf
, step
? "s" : "c");
2703 /* Same as remote_resume, but with async support. */
2705 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2707 struct remote_state
*rs
= get_remote_state ();
2708 char *buf
= alloca (rs
->remote_packet_size
);
2709 int pid
= PIDGET (ptid
);
2713 set_thread (0, 0); /* run any thread */
2715 set_thread (pid
, 0); /* run this thread */
2717 last_sent_signal
= siggnal
;
2718 last_sent_step
= step
;
2720 /* A hook for when we need to do something at the last moment before
2722 if (target_resume_hook
)
2723 (*target_resume_hook
) ();
2725 /* The s/S/c/C packets do not return status. So if the target does
2726 not support the S or C packets, the debug agent returns an empty
2727 string which is detected in remote_wait(). This protocol defect
2728 is fixed in the e/E packets. */
2730 if (step
&& step_range_end
)
2732 /* If the target does not support the 'E' packet, we try the 'S'
2733 packet. Ideally we would fall back to the 'e' packet if that
2734 too is not supported. But that would require another copy of
2735 the code to issue the 'e' packet (and fall back to 's' if not
2736 supported) in remote_wait(). */
2738 if (siggnal
!= TARGET_SIGNAL_0
)
2740 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2744 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2745 *p
++ = tohex (((int) siggnal
) & 0xf);
2747 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2749 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2753 getpkt (buf
, (rs
->remote_packet_size
), 0);
2755 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2756 goto register_event_loop
;
2761 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2765 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2767 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2771 getpkt (buf
, (rs
->remote_packet_size
), 0);
2773 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2774 goto register_event_loop
;
2779 if (siggnal
!= TARGET_SIGNAL_0
)
2781 buf
[0] = step
? 'S' : 'C';
2782 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2783 buf
[2] = tohex ((int) siggnal
& 0xf);
2787 strcpy (buf
, step
? "s" : "c");
2791 register_event_loop
:
2792 /* We are about to start executing the inferior, let's register it
2793 with the event loop. NOTE: this is the one place where all the
2794 execution commands end up. We could alternatively do this in each
2795 of the execution commands in infcmd.c.*/
2796 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2797 into infcmd.c in order to allow inferior function calls to work
2798 NOT asynchronously. */
2799 if (event_loop_p
&& target_can_async_p ())
2800 target_async (inferior_event_handler
, 0);
2801 /* Tell the world that the target is now executing. */
2802 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2803 this? Instead, should the client of target just assume (for
2804 async targets) that the target is going to start executing? Is
2805 this information already found in the continuation block? */
2806 if (target_is_async_p ())
2807 target_executing
= 1;
2811 /* Set up the signal handler for SIGINT, while the target is
2812 executing, ovewriting the 'regular' SIGINT signal handler. */
2814 initialize_sigint_signal_handler (void)
2816 sigint_remote_token
=
2817 create_async_signal_handler (async_remote_interrupt
, NULL
);
2818 signal (SIGINT
, handle_remote_sigint
);
2821 /* Signal handler for SIGINT, while the target is executing. */
2823 handle_remote_sigint (int sig
)
2825 signal (sig
, handle_remote_sigint_twice
);
2826 sigint_remote_twice_token
=
2827 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2828 mark_async_signal_handler_wrapper (sigint_remote_token
);
2831 /* Signal handler for SIGINT, installed after SIGINT has already been
2832 sent once. It will take effect the second time that the user sends
2835 handle_remote_sigint_twice (int sig
)
2837 signal (sig
, handle_sigint
);
2838 sigint_remote_twice_token
=
2839 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2840 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2843 /* Perform the real interruption of the target execution, in response
2846 async_remote_interrupt (gdb_client_data arg
)
2849 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2854 /* Perform interrupt, if the first attempt did not succeed. Just give
2855 up on the target alltogether. */
2857 async_remote_interrupt_twice (gdb_client_data arg
)
2860 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2861 /* Do something only if the target was not killed by the previous
2863 if (target_executing
)
2866 signal (SIGINT
, handle_remote_sigint
);
2870 /* Reinstall the usual SIGINT handlers, after the target has
2873 cleanup_sigint_signal_handler (void *dummy
)
2875 signal (SIGINT
, handle_sigint
);
2876 if (sigint_remote_twice_token
)
2877 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2878 if (sigint_remote_token
)
2879 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2882 /* Send ^C to target to halt it. Target will respond, and send us a
2884 static void (*ofunc
) (int);
2886 /* The command line interface's stop routine. This function is installed
2887 as a signal handler for SIGINT. The first time a user requests a
2888 stop, we call remote_stop to send a break or ^C. If there is no
2889 response from the target (it didn't stop when the user requested it),
2890 we ask the user if he'd like to detach from the target. */
2892 remote_interrupt (int signo
)
2894 /* If this doesn't work, try more severe steps. */
2895 signal (signo
, remote_interrupt_twice
);
2898 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2903 /* The user typed ^C twice. */
2906 remote_interrupt_twice (int signo
)
2908 signal (signo
, ofunc
);
2910 signal (signo
, remote_interrupt
);
2913 /* This is the generic stop called via the target vector. When a target
2914 interrupt is requested, either by the command line or the GUI, we
2915 will eventually end up here. */
2919 /* Send a break or a ^C, depending on user preference. */
2921 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2924 serial_send_break (remote_desc
);
2926 serial_write (remote_desc
, "\003", 1);
2929 /* Ask the user what to do when an interrupt is received. */
2932 interrupt_query (void)
2934 target_terminal_ours ();
2936 if (query ("Interrupted while waiting for the program.\n\
2937 Give up (and stop debugging it)? "))
2939 target_mourn_inferior ();
2940 throw_exception (RETURN_QUIT
);
2943 target_terminal_inferior ();
2946 /* Enable/disable target terminal ownership. Most targets can use
2947 terminal groups to control terminal ownership. Remote targets are
2948 different in that explicit transfer of ownership to/from GDB/target
2952 remote_async_terminal_inferior (void)
2954 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2955 sync_execution here. This function should only be called when
2956 GDB is resuming the inferior in the forground. A background
2957 resume (``run&'') should leave GDB in control of the terminal and
2958 consequently should not call this code. */
2959 if (!sync_execution
)
2961 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2962 calls target_terminal_*() idenpotent. The event-loop GDB talking
2963 to an asynchronous target with a synchronous command calls this
2964 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2965 stops trying to transfer the terminal to the target when it
2966 shouldn't this guard can go away. */
2967 if (!remote_async_terminal_ours_p
)
2969 delete_file_handler (input_fd
);
2970 remote_async_terminal_ours_p
= 0;
2971 initialize_sigint_signal_handler ();
2972 /* NOTE: At this point we could also register our selves as the
2973 recipient of all input. Any characters typed could then be
2974 passed on down to the target. */
2978 remote_async_terminal_ours (void)
2980 /* See FIXME in remote_async_terminal_inferior. */
2981 if (!sync_execution
)
2983 /* See FIXME in remote_async_terminal_inferior. */
2984 if (remote_async_terminal_ours_p
)
2986 cleanup_sigint_signal_handler (NULL
);
2987 add_file_handler (input_fd
, stdin_event_handler
, 0);
2988 remote_async_terminal_ours_p
= 1;
2991 /* If nonzero, ignore the next kill. */
2996 remote_console_output (char *msg
)
3000 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
3003 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
3006 fputs_unfiltered (tb
, gdb_stdtarg
);
3008 gdb_flush (gdb_stdtarg
);
3011 /* Wait until the remote machine stops, then return,
3012 storing status in STATUS just as `wait' would.
3013 Returns "pid", which in the case of a multi-threaded
3014 remote OS, is the thread-id. */
3017 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3019 struct remote_state
*rs
= get_remote_state ();
3020 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3021 ULONGEST thread_num
= -1;
3024 status
->kind
= TARGET_WAITKIND_EXITED
;
3025 status
->value
.integer
= 0;
3031 ofunc
= signal (SIGINT
, remote_interrupt
);
3032 getpkt (buf
, (rs
->remote_packet_size
), 1);
3033 signal (SIGINT
, ofunc
);
3035 /* This is a hook for when we need to do something (perhaps the
3036 collection of trace data) every time the target stops. */
3037 if (target_wait_loop_hook
)
3038 (*target_wait_loop_hook
) ();
3040 remote_stopped_by_watchpoint_p
= 0;
3044 case 'E': /* Error of some sort */
3045 warning ("Remote failure reply: %s", buf
);
3047 case 'T': /* Status with PC, SP, FP, ... */
3050 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
3052 /* Expedited reply, containing Signal, {regno, reg} repeat */
3053 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3055 n... = register number
3056 r... = register contents
3058 p
= &buf
[3]; /* after Txx */
3067 /* If the packet contains a register number save it in pnum
3068 and set p1 to point to the character following it.
3069 Otherwise p1 points to p. */
3071 /* If this packet is an awatch packet, don't parse the 'a'
3072 as a register number. */
3074 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
3076 /* Read the ``P'' register number. */
3077 pnum
= strtol (p
, &p_temp
, 16);
3078 p1
= (unsigned char *) p_temp
;
3083 if (p1
== p
) /* No register number present here */
3085 p1
= (unsigned char *) strchr (p
, ':');
3087 warning ("Malformed packet(a) (missing colon): %s\n\
3090 if (strncmp (p
, "thread", p1
- p
) == 0)
3092 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3093 record_currthread (thread_num
);
3094 p
= (unsigned char *) p_temp
;
3096 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3097 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3098 || (strncmp (p
, "awatch", p1
- p
) == 0))
3100 remote_stopped_by_watchpoint_p
= 1;
3101 p
= unpack_varlen_hex (++p1
, &addr
);
3102 remote_watch_data_address
= (CORE_ADDR
)addr
;
3106 /* Silently skip unknown optional info. */
3107 p_temp
= strchr (p1
+ 1, ';');
3109 p
= (unsigned char *) p_temp
;
3114 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3118 warning ("Malformed packet(b) (missing colon): %s\n\
3123 warning ("Remote sent bad register number %s: %s\n\
3125 phex_nz (pnum
, 0), p
, buf
);
3127 fieldsize
= hex2bin (p
, regs
, REGISTER_RAW_SIZE (reg
->regnum
));
3129 if (fieldsize
< REGISTER_RAW_SIZE (reg
->regnum
))
3130 warning ("Remote reply is too short: %s", buf
);
3131 supply_register (reg
->regnum
, regs
);
3136 warning ("Remote register badly formatted: %s", buf
);
3137 warning (" here: %s", p
);
3142 case 'S': /* Old style status, just signal only */
3143 status
->kind
= TARGET_WAITKIND_STOPPED
;
3144 status
->value
.sig
= (enum target_signal
)
3145 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3149 /* Export Cisco kernel mode as a convenience variable
3150 (so that it can be used in the GDB prompt if desired). */
3152 if (cisco_kernel_mode
== 1)
3153 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3154 value_from_string ("PDEBUG-"));
3155 cisco_kernel_mode
= 0;
3156 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3157 record_currthread (thread_num
);
3159 else if (buf
[3] == 'k')
3161 /* Export Cisco kernel mode as a convenience variable
3162 (so that it can be used in the GDB prompt if desired). */
3164 if (cisco_kernel_mode
== 1)
3165 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3166 value_from_string ("KDEBUG-"));
3167 cisco_kernel_mode
= 1;
3170 case 'N': /* Cisco special: status and offsets */
3172 bfd_vma text_addr
, data_addr
, bss_addr
;
3173 bfd_signed_vma text_off
, data_off
, bss_off
;
3176 status
->kind
= TARGET_WAITKIND_STOPPED
;
3177 status
->value
.sig
= (enum target_signal
)
3178 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3180 if (symfile_objfile
== NULL
)
3182 warning ("Relocation packet received with no symbol file. \
3187 /* Relocate object file. Buffer format is NAATT;DD;BB
3188 * where AA is the signal number, TT is the new text
3189 * address, DD * is the new data address, and BB is the
3190 * new bss address. */
3193 text_addr
= strtoul (p
, (char **) &p1
, 16);
3194 if (p1
== p
|| *p1
!= ';')
3195 warning ("Malformed relocation packet: Packet '%s'", buf
);
3197 data_addr
= strtoul (p
, (char **) &p1
, 16);
3198 if (p1
== p
|| *p1
!= ';')
3199 warning ("Malformed relocation packet: Packet '%s'", buf
);
3201 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3203 warning ("Malformed relocation packet: Packet '%s'", buf
);
3205 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3206 &text_off
, &data_off
, &bss_off
)
3208 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3209 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3213 case 'W': /* Target exited */
3215 /* The remote process exited. */
3216 status
->kind
= TARGET_WAITKIND_EXITED
;
3217 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3221 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3222 status
->value
.sig
= (enum target_signal
)
3223 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3227 case 'O': /* Console output */
3228 remote_console_output (buf
+ 1);
3231 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3233 /* Zero length reply means that we tried 'S' or 'C' and
3234 the remote system doesn't support it. */
3235 target_terminal_ours_for_output ();
3237 ("Can't send signals to this remote system. %s not sent.\n",
3238 target_signal_to_name (last_sent_signal
));
3239 last_sent_signal
= TARGET_SIGNAL_0
;
3240 target_terminal_inferior ();
3242 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3243 putpkt ((char *) buf
);
3246 /* else fallthrough */
3248 warning ("Invalid remote reply: %s", buf
);
3253 if (thread_num
!= -1)
3255 return pid_to_ptid (thread_num
);
3257 return inferior_ptid
;
3260 /* Async version of remote_wait. */
3262 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3264 struct remote_state
*rs
= get_remote_state ();
3265 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3266 ULONGEST thread_num
= -1;
3269 status
->kind
= TARGET_WAITKIND_EXITED
;
3270 status
->value
.integer
= 0;
3272 remote_stopped_by_watchpoint_p
= 0;
3278 if (!target_is_async_p ())
3279 ofunc
= signal (SIGINT
, remote_interrupt
);
3280 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3281 _never_ wait for ever -> test on target_is_async_p().
3282 However, before we do that we need to ensure that the caller
3283 knows how to take the target into/out of async mode. */
3284 getpkt (buf
, (rs
->remote_packet_size
), wait_forever_enabled_p
);
3285 if (!target_is_async_p ())
3286 signal (SIGINT
, ofunc
);
3288 /* This is a hook for when we need to do something (perhaps the
3289 collection of trace data) every time the target stops. */
3290 if (target_wait_loop_hook
)
3291 (*target_wait_loop_hook
) ();
3295 case 'E': /* Error of some sort */
3296 warning ("Remote failure reply: %s", buf
);
3298 case 'T': /* Status with PC, SP, FP, ... */
3301 char* regs
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
3303 /* Expedited reply, containing Signal, {regno, reg} repeat */
3304 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3306 n... = register number
3307 r... = register contents
3309 p
= &buf
[3]; /* after Txx */
3318 /* If the packet contains a register number, save it in pnum
3319 and set p1 to point to the character following it.
3320 Otherwise p1 points to p. */
3322 /* If this packet is an awatch packet, don't parse the 'a'
3323 as a register number. */
3325 if (!strncmp (p
, "awatch", strlen ("awatch")) != 0)
3327 /* Read the register number. */
3328 pnum
= strtol (p
, &p_temp
, 16);
3329 p1
= (unsigned char *) p_temp
;
3334 if (p1
== p
) /* No register number present here */
3336 p1
= (unsigned char *) strchr (p
, ':');
3338 warning ("Malformed packet(a) (missing colon): %s\n\
3341 if (strncmp (p
, "thread", p1
- p
) == 0)
3343 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3344 record_currthread (thread_num
);
3345 p
= (unsigned char *) p_temp
;
3347 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3348 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3349 || (strncmp (p
, "awatch", p1
- p
) == 0))
3351 remote_stopped_by_watchpoint_p
= 1;
3352 p
= unpack_varlen_hex (++p1
, &addr
);
3353 remote_watch_data_address
= (CORE_ADDR
)addr
;
3357 /* Silently skip unknown optional info. */
3358 p_temp
= (unsigned char *) strchr (p1
+ 1, ';');
3366 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3369 warning ("Malformed packet(b) (missing colon): %s\n\
3374 warning ("Remote sent bad register number %ld: %s\n\
3378 fieldsize
= hex2bin (p
, regs
, REGISTER_RAW_SIZE (reg
->regnum
));
3380 if (fieldsize
< REGISTER_RAW_SIZE (reg
->regnum
))
3381 warning ("Remote reply is too short: %s", buf
);
3382 supply_register (reg
->regnum
, regs
);
3387 warning ("Remote register badly formatted: %s", buf
);
3388 warning (" here: %s", p
);
3393 case 'S': /* Old style status, just signal only */
3394 status
->kind
= TARGET_WAITKIND_STOPPED
;
3395 status
->value
.sig
= (enum target_signal
)
3396 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3400 /* Export Cisco kernel mode as a convenience variable
3401 (so that it can be used in the GDB prompt if desired). */
3403 if (cisco_kernel_mode
== 1)
3404 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3405 value_from_string ("PDEBUG-"));
3406 cisco_kernel_mode
= 0;
3407 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3408 record_currthread (thread_num
);
3410 else if (buf
[3] == 'k')
3412 /* Export Cisco kernel mode as a convenience variable
3413 (so that it can be used in the GDB prompt if desired). */
3415 if (cisco_kernel_mode
== 1)
3416 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3417 value_from_string ("KDEBUG-"));
3418 cisco_kernel_mode
= 1;
3421 case 'N': /* Cisco special: status and offsets */
3423 bfd_vma text_addr
, data_addr
, bss_addr
;
3424 bfd_signed_vma text_off
, data_off
, bss_off
;
3427 status
->kind
= TARGET_WAITKIND_STOPPED
;
3428 status
->value
.sig
= (enum target_signal
)
3429 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3431 if (symfile_objfile
== NULL
)
3433 warning ("Relocation packet recieved with no symbol file. \
3438 /* Relocate object file. Buffer format is NAATT;DD;BB
3439 * where AA is the signal number, TT is the new text
3440 * address, DD * is the new data address, and BB is the
3441 * new bss address. */
3444 text_addr
= strtoul (p
, (char **) &p1
, 16);
3445 if (p1
== p
|| *p1
!= ';')
3446 warning ("Malformed relocation packet: Packet '%s'", buf
);
3448 data_addr
= strtoul (p
, (char **) &p1
, 16);
3449 if (p1
== p
|| *p1
!= ';')
3450 warning ("Malformed relocation packet: Packet '%s'", buf
);
3452 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3454 warning ("Malformed relocation packet: Packet '%s'", buf
);
3456 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3457 &text_off
, &data_off
, &bss_off
)
3459 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3460 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3464 case 'W': /* Target exited */
3466 /* The remote process exited. */
3467 status
->kind
= TARGET_WAITKIND_EXITED
;
3468 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3472 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3473 status
->value
.sig
= (enum target_signal
)
3474 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3478 case 'O': /* Console output */
3479 remote_console_output (buf
+ 1);
3480 /* Return immediately to the event loop. The event loop will
3481 still be waiting on the inferior afterwards. */
3482 status
->kind
= TARGET_WAITKIND_IGNORE
;
3485 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3487 /* Zero length reply means that we tried 'S' or 'C' and
3488 the remote system doesn't support it. */
3489 target_terminal_ours_for_output ();
3491 ("Can't send signals to this remote system. %s not sent.\n",
3492 target_signal_to_name (last_sent_signal
));
3493 last_sent_signal
= TARGET_SIGNAL_0
;
3494 target_terminal_inferior ();
3496 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3497 putpkt ((char *) buf
);
3500 /* else fallthrough */
3502 warning ("Invalid remote reply: %s", buf
);
3507 if (thread_num
!= -1)
3509 return pid_to_ptid (thread_num
);
3511 return inferior_ptid
;
3514 /* Number of bytes of registers this stub implements. */
3516 static int register_bytes_found
;
3518 /* Read the remote registers into the block REGS. */
3519 /* Currently we just read all the registers, so we don't use regnum. */
3523 remote_fetch_registers (int regnum
)
3525 struct remote_state
*rs
= get_remote_state ();
3526 char *buf
= alloca (rs
->remote_packet_size
);
3529 char *regs
= alloca (rs
->sizeof_g_packet
);
3531 set_thread (PIDGET (inferior_ptid
), 1);
3535 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3536 gdb_assert (reg
!= NULL
);
3537 if (!reg
->in_g_packet
)
3538 internal_error (__FILE__
, __LINE__
,
3539 "Attempt to fetch a non G-packet register when this "
3540 "remote.c does not support the p-packet.");
3544 remote_send (buf
, (rs
->remote_packet_size
));
3546 /* Save the size of the packet sent to us by the target. Its used
3547 as a heuristic when determining the max size of packets that the
3548 target can safely receive. */
3549 if ((rs
->actual_register_packet_size
) == 0)
3550 (rs
->actual_register_packet_size
) = strlen (buf
);
3552 /* Unimplemented registers read as all bits zero. */
3553 memset (regs
, 0, rs
->sizeof_g_packet
);
3555 /* We can get out of synch in various cases. If the first character
3556 in the buffer is not a hex character, assume that has happened
3557 and try to fetch another packet to read. */
3558 while ((buf
[0] < '0' || buf
[0] > '9')
3559 && (buf
[0] < 'a' || buf
[0] > 'f')
3560 && buf
[0] != 'x') /* New: unavailable register value */
3563 fprintf_unfiltered (gdb_stdlog
,
3564 "Bad register packet; fetching a new packet\n");
3565 getpkt (buf
, (rs
->remote_packet_size
), 0);
3568 /* Reply describes registers byte by byte, each byte encoded as two
3569 hex characters. Suck them all up, then supply them to the
3570 register cacheing/storage mechanism. */
3573 for (i
= 0; i
< rs
->sizeof_g_packet
; i
++)
3579 warning ("Remote reply is of odd length: %s", buf
);
3580 /* Don't change register_bytes_found in this case, and don't
3581 print a second warning. */
3584 if (p
[0] == 'x' && p
[1] == 'x')
3585 regs
[i
] = 0; /* 'x' */
3587 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3591 if (i
!= register_bytes_found
)
3593 register_bytes_found
= i
;
3594 if (REGISTER_BYTES_OK_P ()
3595 && !REGISTER_BYTES_OK (i
))
3596 warning ("Remote reply is too short: %s", buf
);
3602 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3604 struct packet_reg
*r
= &rs
->regs
[i
];
3607 supply_register (r
->regnum
, regs
+ r
->offset
);
3608 if (buf
[r
->offset
* 2] == 'x')
3609 set_register_cached (i
, -1);
3615 /* Prepare to store registers. Since we may send them all (using a
3616 'G' request), we have to read out the ones we don't want to change
3620 remote_prepare_to_store (void)
3622 /* Make sure the entire registers array is valid. */
3623 switch (remote_protocol_P
.support
)
3625 case PACKET_DISABLE
:
3626 case PACKET_SUPPORT_UNKNOWN
:
3627 /* NOTE: This isn't rs->sizeof_g_packet because here, we are
3628 forcing the register cache to read its and not the target
3630 read_register_bytes (0, (char *) NULL
, REGISTER_BYTES
); /* OK use. */
3637 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3638 packet was not recognized. */
3641 store_register_using_P (int regnum
)
3643 struct remote_state
*rs
= get_remote_state ();
3644 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3645 /* Try storing a single register. */
3646 char *buf
= alloca (rs
->remote_packet_size
);
3647 char *regp
= alloca (MAX_REGISTER_RAW_SIZE
);
3651 sprintf (buf
, "P%s=", phex_nz (reg
->pnum
, 0));
3652 p
= buf
+ strlen (buf
);
3653 regcache_collect (reg
->regnum
, regp
);
3654 bin2hex (regp
, p
, REGISTER_RAW_SIZE (reg
->regnum
));
3655 remote_send (buf
, rs
->remote_packet_size
);
3657 return buf
[0] != '\0';
3661 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
3662 of the register cache buffer. FIXME: ignores errors. */
3665 remote_store_registers (int regnum
)
3667 struct remote_state
*rs
= get_remote_state ();
3673 set_thread (PIDGET (inferior_ptid
), 1);
3677 switch (remote_protocol_P
.support
)
3679 case PACKET_DISABLE
:
3682 if (store_register_using_P (regnum
))
3685 error ("Protocol error: P packet not recognized by stub");
3686 case PACKET_SUPPORT_UNKNOWN
:
3687 if (store_register_using_P (regnum
))
3689 /* The stub recognized the 'P' packet. Remember this. */
3690 remote_protocol_P
.support
= PACKET_ENABLE
;
3695 /* The stub does not support the 'P' packet. Use 'G'
3696 instead, and don't try using 'P' in the future (it
3697 will just waste our time). */
3698 remote_protocol_P
.support
= PACKET_DISABLE
;
3704 /* Extract all the registers in the regcache copying them into a
3708 regs
= alloca (rs
->sizeof_g_packet
);
3709 memset (regs
, rs
->sizeof_g_packet
, 0);
3710 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3712 struct packet_reg
*r
= &rs
->regs
[i
];
3714 regcache_collect (r
->regnum
, regs
+ r
->offset
);
3718 /* Command describes registers byte by byte,
3719 each byte encoded as two hex characters. */
3720 buf
= alloca (rs
->remote_packet_size
);
3723 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3724 bin2hex (regs
, p
, register_bytes_found
);
3725 remote_send (buf
, (rs
->remote_packet_size
));
3729 /* Return the number of hex digits in num. */
3732 hexnumlen (ULONGEST num
)
3736 for (i
= 0; num
!= 0; i
++)
3742 /* Set BUF to the minimum number of hex digits representing NUM. */
3745 hexnumstr (char *buf
, ULONGEST num
)
3747 int len
= hexnumlen (num
);
3748 return hexnumnstr (buf
, num
, len
);
3752 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3755 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3761 for (i
= width
- 1; i
>= 0; i
--)
3763 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3770 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3773 remote_address_masked (CORE_ADDR addr
)
3775 if (remote_address_size
> 0
3776 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3778 /* Only create a mask when that mask can safely be constructed
3779 in a ULONGEST variable. */
3781 mask
= (mask
<< remote_address_size
) - 1;
3787 /* Determine whether the remote target supports binary downloading.
3788 This is accomplished by sending a no-op memory write of zero length
3789 to the target at the specified address. It does not suffice to send
3790 the whole packet, since many stubs strip the eighth bit and subsequently
3791 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3793 NOTE: This can still lose if the serial line is not eight-bit
3794 clean. In cases like this, the user should clear "remote
3798 check_binary_download (CORE_ADDR addr
)
3800 struct remote_state
*rs
= get_remote_state ();
3801 switch (remote_protocol_binary_download
.support
)
3803 case PACKET_DISABLE
:
3807 case PACKET_SUPPORT_UNKNOWN
:
3809 char *buf
= alloca (rs
->remote_packet_size
);
3814 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3816 p
+= hexnumstr (p
, (ULONGEST
) 0);
3820 putpkt_binary (buf
, (int) (p
- buf
));
3821 getpkt (buf
, (rs
->remote_packet_size
), 0);
3826 fprintf_unfiltered (gdb_stdlog
,
3827 "binary downloading NOT suppported by target\n");
3828 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3833 fprintf_unfiltered (gdb_stdlog
,
3834 "binary downloading suppported by target\n");
3835 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3842 /* Write memory data directly to the remote machine.
3843 This does not inform the data cache; the data cache uses this.
3844 MEMADDR is the address in the remote memory space.
3845 MYADDR is the address of the buffer in our space.
3846 LEN is the number of bytes.
3848 Returns number of bytes transferred, or 0 (setting errno) for
3849 error. Only transfer a single packet. */
3852 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3855 int max_buf_size
; /* Max size of packet output buffer */
3857 unsigned char *plen
;
3863 /* Verify that the target can support a binary download */
3864 check_binary_download (memaddr
);
3866 /* Determine the max packet size. */
3867 max_buf_size
= get_memory_write_packet_size ();
3868 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3869 buf
= alloca (sizeof_buf
);
3871 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3872 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
3874 /* construct "M"<memaddr>","<len>":" */
3875 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3878 /* Append [XM]. Compute a best guess of the number of bytes
3879 actually transfered. */
3880 switch (remote_protocol_binary_download
.support
)
3884 /* Best guess at number of bytes that will fit. */
3885 todo
= min (len
, max_buf_size
);
3887 case PACKET_DISABLE
:
3889 /* num bytes that will fit */
3890 todo
= min (len
, max_buf_size
/ 2);
3892 case PACKET_SUPPORT_UNKNOWN
:
3893 internal_error (__FILE__
, __LINE__
,
3894 "remote_write_bytes: bad internal state");
3896 internal_error (__FILE__
, __LINE__
, "bad switch");
3899 /* Append <memaddr> */
3900 memaddr
= remote_address_masked (memaddr
);
3901 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3904 /* Append <len>. Retain the location/size of <len>. It may
3905 need to be adjusted once the packet body has been created. */
3907 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3912 /* Append the packet body. */
3913 switch (remote_protocol_binary_download
.support
)
3916 /* Binary mode. Send target system values byte by byte, in
3917 increasing byte addresses. Only escape certain critical
3920 (nr_bytes
< todo
) && (p
- buf
) < (max_buf_size
- 2);
3923 switch (myaddr
[nr_bytes
] & 0xff)
3928 /* These must be escaped */
3930 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3933 *p
++ = myaddr
[nr_bytes
] & 0xff;
3937 if (nr_bytes
< todo
)
3939 /* Escape chars have filled up the buffer prematurely,
3940 and we have actually sent fewer bytes than planned.
3941 Fix-up the length field of the packet. Use the same
3942 number of characters as before. */
3944 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3945 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3948 case PACKET_DISABLE
:
3949 /* Normal mode: Send target system values byte by byte, in
3950 increasing byte addresses. Each byte is encoded as a two hex
3952 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3955 case PACKET_SUPPORT_UNKNOWN
:
3956 internal_error (__FILE__
, __LINE__
,
3957 "remote_write_bytes: bad internal state");
3959 internal_error (__FILE__
, __LINE__
, "bad switch");
3962 putpkt_binary (buf
, (int) (p
- buf
));
3963 getpkt (buf
, sizeof_buf
, 0);
3967 /* There is no correspondance between what the remote protocol
3968 uses for errors and errno codes. We would like a cleaner way
3969 of representing errors (big enough to include errno codes,
3970 bfd_error codes, and others). But for now just return EIO. */
3975 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3976 bytes than we'd planned. */
3980 /* Read memory data directly from the remote machine.
3981 This does not use the data cache; the data cache uses this.
3982 MEMADDR is the address in the remote memory space.
3983 MYADDR is the address of the buffer in our space.
3984 LEN is the number of bytes.
3986 Returns number of bytes transferred, or 0 for error. */
3988 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3989 remote targets) shouldn't attempt to read the entire buffer.
3990 Instead it should read a single packet worth of data and then
3991 return the byte size of that packet to the caller. The caller (its
3992 caller and its callers caller ;-) already contains code for
3993 handling partial reads. */
3996 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3999 int max_buf_size
; /* Max size of packet output buffer */
4003 /* Create a buffer big enough for this packet. */
4004 max_buf_size
= get_memory_read_packet_size ();
4005 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
4006 buf
= alloca (sizeof_buf
);
4015 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
4017 /* construct "m"<memaddr>","<len>" */
4018 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
4019 memaddr
= remote_address_masked (memaddr
);
4022 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
4024 p
+= hexnumstr (p
, (ULONGEST
) todo
);
4028 getpkt (buf
, sizeof_buf
, 0);
4031 && isxdigit (buf
[1]) && isxdigit (buf
[2])
4034 /* There is no correspondance between what the remote protocol uses
4035 for errors and errno codes. We would like a cleaner way of
4036 representing errors (big enough to include errno codes, bfd_error
4037 codes, and others). But for now just return EIO. */
4042 /* Reply describes memory byte by byte,
4043 each byte encoded as two hex characters. */
4046 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
4048 /* Reply is short. This means that we were able to read
4049 only part of what we wanted to. */
4050 return i
+ (origlen
- len
);
4059 /* Read or write LEN bytes from inferior memory at MEMADDR,
4060 transferring to or from debugger address BUFFER. Write to inferior if
4061 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
4062 for error. TARGET is unused. */
4066 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
4067 int should_write
, struct mem_attrib
*attrib
,
4068 struct target_ops
*target
)
4070 CORE_ADDR targ_addr
;
4074 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr
, mem_len
, &targ_addr
, &targ_len
);
4079 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
4081 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
4088 /* Enable after 4.12. */
4091 remote_search (int len
, char *data
, char *mask
, CORE_ADDR startaddr
,
4092 int increment
, CORE_ADDR lorange
, CORE_ADDR hirange
,
4093 CORE_ADDR
*addr_found
, char *data_found
)
4095 if (increment
== -4 && len
== 4)
4097 long mask_long
, data_long
;
4098 long data_found_long
;
4099 CORE_ADDR addr_we_found
;
4100 char *buf
= alloca (rs
->remote_packet_size
);
4101 long returned_long
[2];
4104 mask_long
= extract_unsigned_integer (mask
, len
);
4105 data_long
= extract_unsigned_integer (data
, len
);
4106 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
4108 getpkt (buf
, (rs
->remote_packet_size
), 0);
4111 /* The stub doesn't support the 't' request. We might want to
4112 remember this fact, but on the other hand the stub could be
4113 switched on us. Maybe we should remember it only until
4114 the next "target remote". */
4115 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
4116 hirange
, addr_found
, data_found
);
4121 /* There is no correspondance between what the remote protocol uses
4122 for errors and errno codes. We would like a cleaner way of
4123 representing errors (big enough to include errno codes, bfd_error
4124 codes, and others). But for now just use EIO. */
4125 memory_error (EIO
, startaddr
);
4128 while (*p
!= '\0' && *p
!= ',')
4129 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
4131 error ("Protocol error: short return for search");
4133 data_found_long
= 0;
4134 while (*p
!= '\0' && *p
!= ',')
4135 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
4136 /* Ignore anything after this comma, for future extensions. */
4138 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
4144 *addr_found
= addr_we_found
;
4145 *data_found
= store_unsigned_integer (data_we_found
, len
);
4148 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
4149 hirange
, addr_found
, data_found
);
4154 remote_files_info (struct target_ops
*ignore
)
4156 puts_filtered ("Debugging a target over a serial line.\n");
4159 /* Stuff for dealing with the packets which are part of this protocol.
4160 See comment at top of file for details. */
4162 /* Read a single character from the remote end, masking it down to 7 bits. */
4165 readchar (int timeout
)
4169 ch
= serial_readchar (remote_desc
, timeout
);
4174 switch ((enum serial_rc
) ch
)
4177 target_mourn_inferior ();
4178 error ("Remote connection closed");
4181 perror_with_name ("Remote communication error");
4183 case SERIAL_TIMEOUT
:
4189 /* Send the command in BUF to the remote machine, and read the reply
4190 into BUF. Report an error if we get an error reply. */
4193 remote_send (char *buf
,
4197 getpkt (buf
, sizeof_buf
, 0);
4200 error ("Remote failure reply: %s", buf
);
4203 /* Display a null-terminated packet on stdout, for debugging, using C
4207 print_packet (char *buf
)
4209 puts_filtered ("\"");
4210 fputstr_filtered (buf
, '"', gdb_stdout
);
4211 puts_filtered ("\"");
4217 return putpkt_binary (buf
, strlen (buf
));
4220 /* Send a packet to the remote machine, with error checking. The data
4221 of the packet is in BUF. The string in BUF can be at most (rs->remote_packet_size) - 5
4222 to account for the $, # and checksum, and for a possible /0 if we are
4223 debugging (remote_debug) and want to print the sent packet as a string */
4226 putpkt_binary (char *buf
, int cnt
)
4228 struct remote_state
*rs
= get_remote_state ();
4230 unsigned char csum
= 0;
4231 char *buf2
= alloca (cnt
+ 6);
4232 long sizeof_junkbuf
= (rs
->remote_packet_size
);
4233 char *junkbuf
= alloca (sizeof_junkbuf
);
4239 /* Copy the packet into buffer BUF2, encapsulating it
4240 and giving it a checksum. */
4245 for (i
= 0; i
< cnt
; i
++)
4251 *p
++ = tohex ((csum
>> 4) & 0xf);
4252 *p
++ = tohex (csum
& 0xf);
4254 /* Send it over and over until we get a positive ack. */
4258 int started_error_output
= 0;
4263 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4264 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4265 fprintf_unfiltered (gdb_stdlog
, "...");
4266 gdb_flush (gdb_stdlog
);
4268 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4269 perror_with_name ("putpkt: write failed");
4271 /* read until either a timeout occurs (-2) or '+' is read */
4274 ch
= readchar (remote_timeout
);
4282 case SERIAL_TIMEOUT
:
4284 if (started_error_output
)
4286 putchar_unfiltered ('\n');
4287 started_error_output
= 0;
4296 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4300 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4301 case SERIAL_TIMEOUT
:
4305 break; /* Retransmit buffer */
4309 fprintf_unfiltered (gdb_stdlog
, "Packet instead of Ack, ignoring it\n");
4310 /* It's probably an old response, and we're out of sync.
4311 Just gobble up the packet and ignore it. */
4312 read_frame (junkbuf
, sizeof_junkbuf
);
4313 continue; /* Now, go look for + */
4318 if (!started_error_output
)
4320 started_error_output
= 1;
4321 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4323 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4327 break; /* Here to retransmit */
4331 /* This is wrong. If doing a long backtrace, the user should be
4332 able to get out next time we call QUIT, without anything as
4333 violent as interrupt_query. If we want to provide a way out of
4334 here without getting to the next QUIT, it should be based on
4335 hitting ^C twice as in remote_wait. */
4345 static int remote_cisco_mode
;
4347 /* Come here after finding the start of the frame. Collect the rest
4348 into BUF, verifying the checksum, length, and handling run-length
4349 compression. No more than sizeof_buf-1 characters are read so that
4350 the buffer can be NUL terminated.
4352 Returns -1 on error, number of characters in buffer (ignoring the
4353 trailing NULL) on success. (could be extended to return one of the
4354 SERIAL status indications). */
4357 read_frame (char *buf
,
4369 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
4370 c
= readchar (remote_timeout
);
4373 case SERIAL_TIMEOUT
:
4375 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4379 fputs_filtered ("Saw new packet start in middle of old one\n",
4381 return -1; /* Start a new packet, count retries */
4384 unsigned char pktcsum
;
4390 check_0
= readchar (remote_timeout
);
4392 check_1
= readchar (remote_timeout
);
4394 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4397 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog
);
4400 else if (check_0
< 0 || check_1
< 0)
4403 fputs_filtered ("Communication error in checksum\n", gdb_stdlog
);
4407 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4408 if (csum
== pktcsum
)
4413 fprintf_filtered (gdb_stdlog
,
4414 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4416 fputs_filtered (buf
, gdb_stdlog
);
4417 fputs_filtered ("\n", gdb_stdlog
);
4419 /* Number of characters in buffer ignoring trailing
4423 case '*': /* Run length encoding */
4428 if (remote_cisco_mode
== 0)
4430 c
= readchar (remote_timeout
);
4432 repeat
= c
- ' ' + 3; /* Compute repeat count */
4436 /* Cisco's run-length encoding variant uses two
4437 hex chars to represent the repeat count. */
4439 c
= readchar (remote_timeout
);
4441 repeat
= fromhex (c
) << 4;
4442 c
= readchar (remote_timeout
);
4444 repeat
+= fromhex (c
);
4447 /* The character before ``*'' is repeated. */
4449 if (repeat
> 0 && repeat
<= 255
4451 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4453 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4459 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
4460 puts_filtered (buf
);
4461 puts_filtered ("\n");
4465 if (bc
< sizeof_buf
- 1)
4473 puts_filtered ("Remote packet too long: ");
4474 puts_filtered (buf
);
4475 puts_filtered ("\n");
4482 /* Read a packet from the remote machine, with error checking, and
4483 store it in BUF. If FOREVER, wait forever rather than timing out;
4484 this is used (in synchronous mode) to wait for a target that is is
4485 executing user code to stop. */
4486 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4487 don't have to change all the calls to getpkt to deal with the
4488 return value, because at the moment I don't know what the right
4489 thing to do it for those. */
4497 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4501 /* Read a packet from the remote machine, with error checking, and
4502 store it in BUF. If FOREVER, wait forever rather than timing out;
4503 this is used (in synchronous mode) to wait for a target that is is
4504 executing user code to stop. If FOREVER == 0, this function is
4505 allowed to time out gracefully and return an indication of this to
4508 getpkt_sane (char *buf
,
4517 strcpy (buf
, "timeout");
4521 timeout
= watchdog
> 0 ? watchdog
: -1;
4525 timeout
= remote_timeout
;
4529 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4531 /* This can loop forever if the remote side sends us characters
4532 continuously, but if it pauses, we'll get a zero from readchar
4533 because of timeout. Then we'll count that as a retry. */
4535 /* Note that we will only wait forever prior to the start of a packet.
4536 After that, we expect characters to arrive at a brisk pace. They
4537 should show up within remote_timeout intervals. */
4541 c
= readchar (timeout
);
4543 if (c
== SERIAL_TIMEOUT
)
4545 if (forever
) /* Watchdog went off? Kill the target. */
4548 target_mourn_inferior ();
4549 error ("Watchdog has expired. Target detached.\n");
4552 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4558 /* We've found the start of a packet, now collect the data. */
4560 val
= read_frame (buf
, sizeof_buf
);
4566 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4567 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4568 fprintf_unfiltered (gdb_stdlog
, "\n");
4570 serial_write (remote_desc
, "+", 1);
4574 /* Try the whole thing again. */
4576 serial_write (remote_desc
, "-", 1);
4579 /* We have tried hard enough, and just can't receive the packet. Give up. */
4581 printf_unfiltered ("Ignoring packet error, continuing...\n");
4582 serial_write (remote_desc
, "+", 1);
4589 /* For some mysterious reason, wait_for_inferior calls kill instead of
4590 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4594 target_mourn_inferior ();
4598 /* Use catch_errors so the user can quit from gdb even when we aren't on
4599 speaking terms with the remote system. */
4600 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4602 /* Don't wait for it to die. I'm not really sure it matters whether
4603 we do or not. For the existing stubs, kill is a noop. */
4604 target_mourn_inferior ();
4607 /* Async version of remote_kill. */
4609 remote_async_kill (void)
4611 /* Unregister the file descriptor from the event loop. */
4612 if (target_is_async_p ())
4613 serial_async (remote_desc
, NULL
, 0);
4615 /* For some mysterious reason, wait_for_inferior calls kill instead of
4616 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4620 target_mourn_inferior ();
4624 /* Use catch_errors so the user can quit from gdb even when we aren't on
4625 speaking terms with the remote system. */
4626 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4628 /* Don't wait for it to die. I'm not really sure it matters whether
4629 we do or not. For the existing stubs, kill is a noop. */
4630 target_mourn_inferior ();
4636 remote_mourn_1 (&remote_ops
);
4640 remote_async_mourn (void)
4642 remote_mourn_1 (&remote_async_ops
);
4646 extended_remote_mourn (void)
4648 /* We do _not_ want to mourn the target like this; this will
4649 remove the extended remote target from the target stack,
4650 and the next time the user says "run" it'll fail.
4652 FIXME: What is the right thing to do here? */
4654 remote_mourn_1 (&extended_remote_ops
);
4658 /* Worker function for remote_mourn. */
4660 remote_mourn_1 (struct target_ops
*target
)
4662 unpush_target (target
);
4663 generic_mourn_inferior ();
4666 /* In the extended protocol we want to be able to do things like
4667 "run" and have them basically work as expected. So we need
4668 a special create_inferior function.
4670 FIXME: One day add support for changing the exec file
4671 we're debugging, arguments and an environment. */
4674 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
)
4676 /* Rip out the breakpoints; we'll reinsert them after restarting
4677 the remote server. */
4678 remove_breakpoints ();
4680 /* Now restart the remote server. */
4681 extended_remote_restart ();
4683 /* Now put the breakpoints back in. This way we're safe if the
4684 restart function works via a unix fork on the remote side. */
4685 insert_breakpoints ();
4687 /* Clean up from the last time we were running. */
4688 clear_proceed_status ();
4690 /* Let the remote process run. */
4691 proceed (-1, TARGET_SIGNAL_0
, 0);
4694 /* Async version of extended_remote_create_inferior. */
4696 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
)
4698 /* Rip out the breakpoints; we'll reinsert them after restarting
4699 the remote server. */
4700 remove_breakpoints ();
4702 /* If running asynchronously, register the target file descriptor
4703 with the event loop. */
4704 if (event_loop_p
&& target_can_async_p ())
4705 target_async (inferior_event_handler
, 0);
4707 /* Now restart the remote server. */
4708 extended_remote_restart ();
4710 /* Now put the breakpoints back in. This way we're safe if the
4711 restart function works via a unix fork on the remote side. */
4712 insert_breakpoints ();
4714 /* Clean up from the last time we were running. */
4715 clear_proceed_status ();
4717 /* Let the remote process run. */
4718 proceed (-1, TARGET_SIGNAL_0
, 0);
4722 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
4723 than other targets; in those use REMOTE_BREAKPOINT instead of just
4724 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
4725 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
4726 the standard routines that are in mem-break.c. */
4728 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
4729 the choice of breakpoint instruction affects target program design and
4730 vice versa, and by making it user-tweakable, the special code here
4731 goes away and we need fewer special GDB configurations. */
4733 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4734 #define REMOTE_BREAKPOINT
4737 #ifdef REMOTE_BREAKPOINT
4739 /* If the target isn't bi-endian, just pretend it is. */
4740 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
4741 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4742 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4745 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
4746 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
4748 #endif /* REMOTE_BREAKPOINT */
4750 /* Insert a breakpoint on targets that don't have any better breakpoint
4751 support. We read the contents of the target location and stash it,
4752 then overwrite it with a breakpoint instruction. ADDR is the target
4753 location in the target machine. CONTENTS_CACHE is a pointer to
4754 memory allocated for saving the target contents. It is guaranteed
4755 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
4756 is accomplished via BREAKPOINT_MAX). */
4759 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4761 struct remote_state
*rs
= get_remote_state ();
4762 #ifdef REMOTE_BREAKPOINT
4767 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4768 If it succeeds, then set the support to PACKET_ENABLE. If it
4769 fails, and the user has explicitly requested the Z support then
4770 report an error, otherwise, mark it disabled and go on. */
4772 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4774 char *buf
= alloca (rs
->remote_packet_size
);
4777 addr
= remote_address_masked (addr
);
4781 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4782 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4783 sprintf (p
, ",%d", bp_size
);
4786 getpkt (buf
, (rs
->remote_packet_size
), 0);
4788 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4794 case PACKET_UNKNOWN
:
4799 #ifdef REMOTE_BREAKPOINT
4800 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4804 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4805 val
= target_write_memory (addr
, (char *) big_break_insn
,
4806 sizeof big_break_insn
);
4808 val
= target_write_memory (addr
, (char *) little_break_insn
,
4809 sizeof little_break_insn
);
4814 return memory_insert_breakpoint (addr
, contents_cache
);
4815 #endif /* REMOTE_BREAKPOINT */
4819 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4821 struct remote_state
*rs
= get_remote_state ();
4824 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4826 char *buf
= alloca (rs
->remote_packet_size
);
4833 addr
= remote_address_masked (addr
);
4834 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4835 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4836 sprintf (p
, ",%d", bp_size
);
4839 getpkt (buf
, (rs
->remote_packet_size
), 0);
4841 return (buf
[0] == 'E');
4844 #ifdef REMOTE_BREAKPOINT
4845 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4847 return memory_remove_breakpoint (addr
, contents_cache
);
4848 #endif /* REMOTE_BREAKPOINT */
4852 watchpoint_to_Z_packet (int type
)
4866 internal_error (__FILE__
, __LINE__
,
4867 "hw_bp_to_z: bad watchpoint type %d", type
);
4872 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4874 struct remote_state
*rs
= get_remote_state ();
4875 char *buf
= alloca (rs
->remote_packet_size
);
4877 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4879 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4880 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4881 remote_protocol_Z
[packet
].name
,
4882 remote_protocol_Z
[packet
].title
);
4884 sprintf (buf
, "Z%x,", packet
);
4885 p
= strchr (buf
, '\0');
4886 addr
= remote_address_masked (addr
);
4887 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4888 sprintf (p
, ",%x", len
);
4891 getpkt (buf
, (rs
->remote_packet_size
), 0);
4893 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4896 case PACKET_UNKNOWN
:
4901 internal_error (__FILE__
, __LINE__
,
4902 "remote_insert_watchpoint: reached end of function");
4907 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4909 struct remote_state
*rs
= get_remote_state ();
4910 char *buf
= alloca (rs
->remote_packet_size
);
4912 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4914 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4915 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4916 remote_protocol_Z
[packet
].name
,
4917 remote_protocol_Z
[packet
].title
);
4919 sprintf (buf
, "z%x,", packet
);
4920 p
= strchr (buf
, '\0');
4921 addr
= remote_address_masked (addr
);
4922 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4923 sprintf (p
, ",%x", len
);
4925 getpkt (buf
, (rs
->remote_packet_size
), 0);
4927 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4930 case PACKET_UNKNOWN
:
4935 internal_error (__FILE__
, __LINE__
,
4936 "remote_remove_watchpoint: reached end of function");
4940 int remote_hw_watchpoint_limit
= 0;
4941 int remote_hw_breakpoint_limit
= 0;
4944 remote_check_watch_resources (int type
, int cnt
, int ot
)
4946 if (type
== bp_hardware_breakpoint
)
4948 if (remote_hw_breakpoint_limit
== 0)
4950 else if (cnt
<= remote_hw_breakpoint_limit
)
4955 if (remote_hw_watchpoint_limit
== 0)
4959 else if (cnt
<= remote_hw_watchpoint_limit
)
4966 remote_stopped_by_watchpoint (void)
4968 return remote_stopped_by_watchpoint_p
;
4972 remote_stopped_data_address (void)
4974 if (remote_stopped_by_watchpoint ())
4975 return remote_watch_data_address
;
4976 return (CORE_ADDR
)0;
4981 remote_insert_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4984 struct remote_state
*rs
= get_remote_state ();
4985 char *buf
= alloca (rs
->remote_packet_size
);
4988 /* The length field should be set to the size of a breakpoint
4991 BREAKPOINT_FROM_PC (&addr
, &len
);
4993 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4994 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4995 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4996 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
5002 addr
= remote_address_masked (addr
);
5003 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5004 sprintf (p
, ",%x", len
);
5007 getpkt (buf
, (rs
->remote_packet_size
), 0);
5009 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
5012 case PACKET_UNKNOWN
:
5017 internal_error (__FILE__
, __LINE__
,
5018 "remote_insert_hw_breakpoint: reached end of function");
5023 remote_remove_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
5026 struct remote_state
*rs
= get_remote_state ();
5027 char *buf
= alloca (rs
->remote_packet_size
);
5030 /* The length field should be set to the size of a breakpoint
5033 BREAKPOINT_FROM_PC (&addr
, &len
);
5035 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
5036 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
5037 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
5038 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
5044 addr
= remote_address_masked (addr
);
5045 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5046 sprintf (p
, ",%x", len
);
5049 getpkt (buf
, (rs
->remote_packet_size
), 0);
5051 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
5054 case PACKET_UNKNOWN
:
5059 internal_error (__FILE__
, __LINE__
,
5060 "remote_remove_hw_breakpoint: reached end of function");
5063 /* Some targets are only capable of doing downloads, and afterwards
5064 they switch to the remote serial protocol. This function provides
5065 a clean way to get from the download target to the remote target.
5066 It's basically just a wrapper so that we don't have to expose any
5067 of the internal workings of remote.c.
5069 Prior to calling this routine, you should shutdown the current
5070 target code, else you will get the "A program is being debugged
5071 already..." message. Usually a call to pop_target() suffices. */
5074 push_remote_target (char *name
, int from_tty
)
5076 printf_filtered ("Switching to remote protocol\n");
5077 remote_open (name
, from_tty
);
5080 /* Other targets want to use the entire remote serial module but with
5081 certain remote_ops overridden. */
5084 open_remote_target (char *name
, int from_tty
, struct target_ops
*target
,
5087 printf_filtered ("Selecting the %sremote protocol\n",
5088 (extended_p
? "extended-" : ""));
5089 remote_open_1 (name
, from_tty
, target
, extended_p
);
5092 /* Table used by the crc32 function to calcuate the checksum. */
5094 static unsigned long crc32_table
[256] =
5097 static unsigned long
5098 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
5100 if (!crc32_table
[1])
5102 /* Initialize the CRC table and the decoding table. */
5106 for (i
= 0; i
< 256; i
++)
5108 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
5109 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
5116 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
5122 /* compare-sections command
5124 With no arguments, compares each loadable section in the exec bfd
5125 with the same memory range on the target, and reports mismatches.
5126 Useful for verifying the image on the target against the exec file.
5127 Depends on the target understanding the new "qCRC:" request. */
5129 /* FIXME: cagney/1999-10-26: This command should be broken down into a
5130 target method (target verify memory) and generic version of the
5131 actual command. This will allow other high-level code (especially
5132 generic_load()) to make use of this target functionality. */
5135 compare_sections_command (char *args
, int from_tty
)
5137 struct remote_state
*rs
= get_remote_state ();
5139 unsigned long host_crc
, target_crc
;
5140 extern bfd
*exec_bfd
;
5141 struct cleanup
*old_chain
;
5144 const char *sectname
;
5145 char *buf
= alloca (rs
->remote_packet_size
);
5152 error ("command cannot be used without an exec file");
5153 if (!current_target
.to_shortname
||
5154 strcmp (current_target
.to_shortname
, "remote") != 0)
5155 error ("command can only be used with remote target");
5157 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
5159 if (!(s
->flags
& SEC_LOAD
))
5160 continue; /* skip non-loadable section */
5162 size
= bfd_get_section_size_before_reloc (s
);
5164 continue; /* skip zero-length section */
5166 sectname
= bfd_get_section_name (exec_bfd
, s
);
5167 if (args
&& strcmp (args
, sectname
) != 0)
5168 continue; /* not the section selected by user */
5170 matched
= 1; /* do this section */
5172 /* FIXME: assumes lma can fit into long */
5173 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
5176 /* be clever; compute the host_crc before waiting for target reply */
5177 sectdata
= xmalloc (size
);
5178 old_chain
= make_cleanup (xfree
, sectdata
);
5179 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
5180 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
5182 getpkt (buf
, (rs
->remote_packet_size
), 0);
5184 error ("target memory fault, section %s, range 0x%s -- 0x%s",
5185 sectname
, paddr (lma
), paddr (lma
+ size
));
5187 error ("remote target does not support this operation");
5189 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
5190 target_crc
= target_crc
* 16 + fromhex (*tmp
);
5192 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
5193 sectname
, paddr (lma
), paddr (lma
+ size
));
5194 if (host_crc
== target_crc
)
5195 printf_filtered ("matched.\n");
5198 printf_filtered ("MIS-MATCHED!\n");
5202 do_cleanups (old_chain
);
5205 warning ("One or more sections of the remote executable does not match\n\
5206 the loaded file\n");
5207 if (args
&& !matched
)
5208 printf_filtered ("No loaded section named '%s'.\n", args
);
5212 remote_query (int query_type
, char *buf
, char *outbuf
, int *bufsiz
)
5214 struct remote_state
*rs
= get_remote_state ();
5216 char *buf2
= alloca (rs
->remote_packet_size
);
5217 char *p2
= &buf2
[0];
5220 error ("null pointer to remote bufer size specified");
5222 /* minimum outbuf size is (rs->remote_packet_size) - if bufsiz is not large enough let
5223 the caller know and return what the minimum size is */
5224 /* Note: a zero bufsiz can be used to query the minimum buffer size */
5225 if (*bufsiz
< (rs
->remote_packet_size
))
5227 *bufsiz
= (rs
->remote_packet_size
);
5231 /* except for querying the minimum buffer size, target must be open */
5233 error ("remote query is only available after target open");
5235 /* we only take uppercase letters as query types, at least for now */
5236 if ((query_type
< 'A') || (query_type
> 'Z'))
5237 error ("invalid remote query type");
5240 error ("null remote query specified");
5243 error ("remote query requires a buffer to receive data");
5250 /* we used one buffer char for the remote protocol q command and another
5251 for the query type. As the remote protocol encapsulation uses 4 chars
5252 plus one extra in case we are debugging (remote_debug),
5253 we have PBUFZIZ - 7 left to pack the query string */
5255 while (buf
[i
] && (i
< ((rs
->remote_packet_size
) - 8)))
5257 /* bad caller may have sent forbidden characters */
5258 if ((!isprint (buf
[i
])) || (buf
[i
] == '$') || (buf
[i
] == '#'))
5259 error ("illegal characters in query string");
5267 error ("query larger than available buffer");
5273 getpkt (outbuf
, *bufsiz
, 0);
5279 remote_rcmd (char *command
,
5280 struct ui_file
*outbuf
)
5282 struct remote_state
*rs
= get_remote_state ();
5284 char *buf
= alloca (rs
->remote_packet_size
);
5288 error ("remote rcmd is only available after target open");
5290 /* Send a NULL command across as an empty command */
5291 if (command
== NULL
)
5294 /* The query prefix */
5295 strcpy (buf
, "qRcmd,");
5296 p
= strchr (buf
, '\0');
5298 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > (rs
->remote_packet_size
))
5299 error ("\"monitor\" command ``%s'' is too long\n", command
);
5301 /* Encode the actual command */
5302 bin2hex (command
, p
, 0);
5304 if (putpkt (buf
) < 0)
5305 error ("Communication problem with target\n");
5307 /* get/display the response */
5310 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
5312 getpkt (buf
, (rs
->remote_packet_size
), 0);
5314 error ("Target does not support this command\n");
5315 if (buf
[0] == 'O' && buf
[1] != 'K')
5317 remote_console_output (buf
+ 1); /* 'O' message from stub */
5320 if (strcmp (buf
, "OK") == 0)
5322 if (strlen (buf
) == 3 && buf
[0] == 'E'
5323 && isdigit (buf
[1]) && isdigit (buf
[2]))
5325 error ("Protocol error with Rcmd");
5327 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5329 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5330 fputc_unfiltered (c
, outbuf
);
5337 packet_command (char *args
, int from_tty
)
5339 struct remote_state
*rs
= get_remote_state ();
5340 char *buf
= alloca (rs
->remote_packet_size
);
5343 error ("command can only be used with remote target");
5346 error ("remote-packet command requires packet text as argument");
5348 puts_filtered ("sending: ");
5349 print_packet (args
);
5350 puts_filtered ("\n");
5353 getpkt (buf
, (rs
->remote_packet_size
), 0);
5354 puts_filtered ("received: ");
5356 puts_filtered ("\n");
5360 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
5362 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5364 static void threadset_test_cmd (char *cmd
, int tty
);
5366 static void threadalive_test (char *cmd
, int tty
);
5368 static void threadlist_test_cmd (char *cmd
, int tty
);
5370 int get_and_display_threadinfo (threadref
* ref
);
5372 static void threadinfo_test_cmd (char *cmd
, int tty
);
5374 static int thread_display_step (threadref
* ref
, void *context
);
5376 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5378 static void init_remote_threadtests (void);
5380 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
5383 threadset_test_cmd (char *cmd
, int tty
)
5385 int sample_thread
= SAMPLE_THREAD
;
5387 printf_filtered ("Remote threadset test\n");
5388 set_thread (sample_thread
, 1);
5393 threadalive_test (char *cmd
, int tty
)
5395 int sample_thread
= SAMPLE_THREAD
;
5397 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5398 printf_filtered ("PASS: Thread alive test\n");
5400 printf_filtered ("FAIL: Thread alive test\n");
5403 void output_threadid (char *title
, threadref
* ref
);
5406 output_threadid (char *title
, threadref
*ref
)
5410 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
5412 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5416 threadlist_test_cmd (char *cmd
, int tty
)
5419 threadref nextthread
;
5420 int done
, result_count
;
5421 threadref threadlist
[3];
5423 printf_filtered ("Remote Threadlist test\n");
5424 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5425 &result_count
, &threadlist
[0]))
5426 printf_filtered ("FAIL: threadlist test\n");
5429 threadref
*scan
= threadlist
;
5430 threadref
*limit
= scan
+ result_count
;
5432 while (scan
< limit
)
5433 output_threadid (" thread ", scan
++);
5438 display_thread_info (struct gdb_ext_thread_info
*info
)
5440 output_threadid ("Threadid: ", &info
->threadid
);
5441 printf_filtered ("Name: %s\n ", info
->shortname
);
5442 printf_filtered ("State: %s\n", info
->display
);
5443 printf_filtered ("other: %s\n\n", info
->more_display
);
5447 get_and_display_threadinfo (threadref
*ref
)
5451 struct gdb_ext_thread_info threadinfo
;
5453 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5454 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5455 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5456 display_thread_info (&threadinfo
);
5461 threadinfo_test_cmd (char *cmd
, int tty
)
5463 int athread
= SAMPLE_THREAD
;
5467 int_to_threadref (&thread
, athread
);
5468 printf_filtered ("Remote Threadinfo test\n");
5469 if (!get_and_display_threadinfo (&thread
))
5470 printf_filtered ("FAIL cannot get thread info\n");
5474 thread_display_step (threadref
*ref
, void *context
)
5476 /* output_threadid(" threadstep ",ref); *//* simple test */
5477 return get_and_display_threadinfo (ref
);
5481 threadlist_update_test_cmd (char *cmd
, int tty
)
5483 printf_filtered ("Remote Threadlist update test\n");
5484 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5488 init_remote_threadtests (void)
5490 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
5491 "Fetch and print the remote list of thread identifiers, one pkt only");
5492 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5493 "Fetch and display info about one thread");
5494 add_com ("tset", class_obscure
, threadset_test_cmd
,
5495 "Test setting to a different thread");
5496 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5497 "Iterate through updating all remote thread info");
5498 add_com ("talive", class_obscure
, threadalive_test
,
5499 " Remote thread alive test ");
5504 /* Convert a thread ID to a string. Returns the string in a static
5508 remote_pid_to_str (ptid_t ptid
)
5510 static char buf
[30];
5512 sprintf (buf
, "Thread %d", PIDGET (ptid
));
5517 init_remote_ops (void)
5519 remote_ops
.to_shortname
= "remote";
5520 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5522 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5523 Specify the serial device it is connected to\n\
5524 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5525 remote_ops
.to_open
= remote_open
;
5526 remote_ops
.to_close
= remote_close
;
5527 remote_ops
.to_detach
= remote_detach
;
5528 remote_ops
.to_resume
= remote_resume
;
5529 remote_ops
.to_wait
= remote_wait
;
5530 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5531 remote_ops
.to_store_registers
= remote_store_registers
;
5532 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5533 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
5534 remote_ops
.to_files_info
= remote_files_info
;
5535 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5536 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5537 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5538 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5539 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5540 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5541 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5542 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5543 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5544 remote_ops
.to_kill
= remote_kill
;
5545 remote_ops
.to_load
= generic_load
;
5546 remote_ops
.to_mourn_inferior
= remote_mourn
;
5547 remote_ops
.to_thread_alive
= remote_thread_alive
;
5548 remote_ops
.to_find_new_threads
= remote_threads_info
;
5549 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5550 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5551 remote_ops
.to_stop
= remote_stop
;
5552 remote_ops
.to_query
= remote_query
;
5553 remote_ops
.to_rcmd
= remote_rcmd
;
5554 remote_ops
.to_stratum
= process_stratum
;
5555 remote_ops
.to_has_all_memory
= 1;
5556 remote_ops
.to_has_memory
= 1;
5557 remote_ops
.to_has_stack
= 1;
5558 remote_ops
.to_has_registers
= 1;
5559 remote_ops
.to_has_execution
= 1;
5560 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5561 remote_ops
.to_magic
= OPS_MAGIC
;
5564 /* Set up the extended remote vector by making a copy of the standard
5565 remote vector and adding to it. */
5568 init_extended_remote_ops (void)
5570 extended_remote_ops
= remote_ops
;
5572 extended_remote_ops
.to_shortname
= "extended-remote";
5573 extended_remote_ops
.to_longname
=
5574 "Extended remote serial target in gdb-specific protocol";
5575 extended_remote_ops
.to_doc
=
5576 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5577 Specify the serial device it is connected to (e.g. /dev/ttya).",
5578 extended_remote_ops
.to_open
= extended_remote_open
;
5579 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5580 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5584 * Command: info remote-process
5586 * This implements Cisco's version of the "info proc" command.
5588 * This query allows the target stub to return an arbitrary string
5589 * (or strings) giving arbitrary information about the target process.
5590 * This is optional; the target stub isn't required to implement it.
5592 * Syntax: qfProcessInfo request first string
5593 * qsProcessInfo request subsequent string
5594 * reply: 'O'<hex-encoded-string>
5595 * 'l' last reply (empty)
5599 remote_info_process (char *args
, int from_tty
)
5601 struct remote_state
*rs
= get_remote_state ();
5602 char *buf
= alloca (rs
->remote_packet_size
);
5604 if (remote_desc
== 0)
5605 error ("Command can only be used when connected to the remote target.");
5607 putpkt ("qfProcessInfo");
5608 getpkt (buf
, (rs
->remote_packet_size
), 0);
5610 return; /* Silently: target does not support this feature. */
5613 error ("info proc: target error.");
5615 while (buf
[0] == 'O') /* Capitol-O packet */
5617 remote_console_output (&buf
[1]);
5618 putpkt ("qsProcessInfo");
5619 getpkt (buf
, (rs
->remote_packet_size
), 0);
5628 remote_cisco_open (char *name
, int from_tty
)
5632 error ("To open a remote debug connection, you need to specify what \n"
5633 "device is attached to the remote system (e.g. host:port).");
5635 /* See FIXME above */
5636 wait_forever_enabled_p
= 1;
5638 target_preopen (from_tty
);
5640 unpush_target (&remote_cisco_ops
);
5642 remote_desc
= remote_serial_open (name
);
5644 perror_with_name (name
);
5647 * If a baud rate was specified on the gdb command line it will
5648 * be greater than the initial value of -1. If it is, use it otherwise
5652 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
5653 if (serial_setbaudrate (remote_desc
, baud_rate
))
5655 serial_close (remote_desc
);
5656 perror_with_name (name
);
5659 serial_raw (remote_desc
);
5661 /* If there is something sitting in the buffer we might take it as a
5662 response to a command, which would be bad. */
5663 serial_flush_input (remote_desc
);
5667 puts_filtered ("Remote debugging using ");
5668 puts_filtered (name
);
5669 puts_filtered ("\n");
5672 remote_cisco_mode
= 1;
5674 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
5676 init_all_packet_configs ();
5678 general_thread
= -2;
5679 continue_thread
= -2;
5681 /* Probe for ability to use "ThreadInfo" query, as required. */
5682 use_threadinfo_query
= 1;
5683 use_threadextra_query
= 1;
5685 /* Without this, some commands which require an active target (such
5686 as kill) won't work. This variable serves (at least) double duty
5687 as both the pid of the target process (if it has such), and as a
5688 flag indicating that a target is active. These functions should
5689 be split out into seperate variables, especially since GDB will
5690 someday have a notion of debugging several processes. */
5691 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
5693 /* Start the remote connection; if error, discard this target. See
5694 the comments in remote_open_1() for further details such as the
5695 need to re-throw the exception. */
5696 ex
= catch_exceptions (uiout
,
5697 remote_start_remote_dummy
, NULL
,
5698 "Couldn't establish connection to remote"
5704 throw_exception (ex
);
5709 remote_cisco_close (int quitting
)
5711 remote_cisco_mode
= 0;
5712 remote_close (quitting
);
5716 remote_cisco_mourn (void)
5718 remote_mourn_1 (&remote_cisco_ops
);
5730 /* Shared between readsocket() and readtty(). The size is arbitrary,
5731 however all targets are known to support a 400 character packet. */
5732 static char tty_input
[400];
5734 static int escape_count
;
5735 static int echo_check
;
5736 extern int quit_flag
;
5743 /* Loop until the socket doesn't have any more data */
5745 while ((data
= readchar (0)) >= 0)
5747 /* Check for the escape sequence */
5750 /* If this is the fourth escape, get out */
5751 if (++escape_count
== 4)
5756 { /* This is a '|', but not the fourth in a row.
5757 Continue without echoing it. If it isn't actually
5758 one of four in a row, it'll be echoed later. */
5765 /* Ensure any pending '|'s are flushed. */
5767 for (; escape_count
> 0; escape_count
--)
5771 if (data
== '\r') /* If this is a return character, */
5772 continue; /* - just supress it. */
5774 if (echo_check
!= -1) /* Check for echo of user input. */
5776 if (tty_input
[echo_check
] == data
)
5778 gdb_assert (echo_check
<= sizeof (tty_input
));
5779 echo_check
++; /* Character matched user input: */
5780 continue; /* Continue without echoing it. */
5782 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5783 { /* End of the line (and of echo checking). */
5784 echo_check
= -1; /* No more echo supression */
5785 continue; /* Continue without echoing. */
5788 { /* Failed check for echo of user input.
5789 We now have some suppressed output to flush! */
5792 for (j
= 0; j
< echo_check
; j
++)
5793 putchar (tty_input
[j
]);
5797 putchar (data
); /* Default case: output the char. */
5800 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5801 return READ_MORE
; /* Try to read some more */
5803 return FATAL_ERROR
; /* Trouble, bail out */
5811 /* First, read a buffer full from the terminal */
5812 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5813 if (tty_bytecount
== -1)
5815 perror ("readtty: read failed");
5819 /* Remove a quoted newline. */
5820 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5821 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5823 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5824 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5827 /* Turn trailing newlines into returns */
5828 if (tty_input
[tty_bytecount
- 1] == '\n')
5829 tty_input
[tty_bytecount
- 1] = '\r';
5831 /* If the line consists of a ~, enter debugging mode. */
5832 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5835 /* Make this a zero terminated string and write it out */
5836 tty_input
[tty_bytecount
] = 0;
5837 if (serial_write (remote_desc
, tty_input
, tty_bytecount
))
5839 perror_with_name ("readtty: write failed");
5849 fd_set input
; /* file descriptors for select */
5850 int tablesize
; /* max number of FDs for select */
5854 extern int escape_count
; /* global shared by readsocket */
5855 extern int echo_check
; /* ditto */
5860 tablesize
= 8 * sizeof (input
);
5864 /* Check for anything from our socket - doesn't block. Note that
5865 this must be done *before* the select as there may be
5866 buffered I/O waiting to be processed. */
5868 if ((status
= readsocket ()) == FATAL_ERROR
)
5870 error ("Debugging terminated by communications error");
5872 else if (status
!= READ_MORE
)
5877 fflush (stdout
); /* Flush output before blocking */
5879 /* Now block on more socket input or TTY input */
5882 FD_SET (fileno (stdin
), &input
);
5883 FD_SET (deprecated_serial_fd (remote_desc
), &input
);
5885 status
= select (tablesize
, &input
, 0, 0, 0);
5886 if ((status
== -1) && (errno
!= EINTR
))
5888 error ("Communications error on select %d", errno
);
5891 /* Handle Control-C typed */
5895 if ((++quit_count
) == 2)
5897 if (query ("Interrupt GDB? "))
5899 printf_filtered ("Interrupted by user.\n");
5900 throw_exception (RETURN_QUIT
);
5907 serial_send_break (remote_desc
);
5909 serial_write (remote_desc
, "\003", 1);
5914 /* Handle console input */
5916 if (FD_ISSET (fileno (stdin
), &input
))
5920 status
= readtty ();
5921 if (status
== READ_MORE
)
5924 return status
; /* telnet session ended */
5930 remote_cisco_wait (ptid_t ptid
, struct target_waitstatus
*status
)
5932 if (minitelnet () != ENTER_DEBUG
)
5934 error ("Debugging session terminated by protocol error");
5937 return remote_wait (ptid
, status
);
5941 init_remote_cisco_ops (void)
5943 remote_cisco_ops
.to_shortname
= "cisco";
5944 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5945 remote_cisco_ops
.to_doc
=
5946 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5947 Specify the serial device it is connected to (e.g. host:2020).";
5948 remote_cisco_ops
.to_open
= remote_cisco_open
;
5949 remote_cisco_ops
.to_close
= remote_cisco_close
;
5950 remote_cisco_ops
.to_detach
= remote_detach
;
5951 remote_cisco_ops
.to_resume
= remote_resume
;
5952 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5953 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5954 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5955 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5956 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5957 remote_cisco_ops
.to_files_info
= remote_files_info
;
5958 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5959 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5960 remote_cisco_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5961 remote_cisco_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5962 remote_cisco_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5963 remote_cisco_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5964 remote_cisco_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5965 remote_cisco_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5966 remote_cisco_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5967 remote_cisco_ops
.to_kill
= remote_kill
;
5968 remote_cisco_ops
.to_load
= generic_load
;
5969 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5970 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5971 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5972 remote_cisco_ops
.to_pid_to_str
= remote_pid_to_str
;
5973 remote_cisco_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5974 remote_cisco_ops
.to_stratum
= process_stratum
;
5975 remote_cisco_ops
.to_has_all_memory
= 1;
5976 remote_cisco_ops
.to_has_memory
= 1;
5977 remote_cisco_ops
.to_has_stack
= 1;
5978 remote_cisco_ops
.to_has_registers
= 1;
5979 remote_cisco_ops
.to_has_execution
= 1;
5980 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5984 remote_can_async_p (void)
5986 /* We're async whenever the serial device is. */
5987 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5991 remote_is_async_p (void)
5993 /* We're async whenever the serial device is. */
5994 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5997 /* Pass the SERIAL event on and up to the client. One day this code
5998 will be able to delay notifying the client of an event until the
5999 point where an entire packet has been received. */
6001 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
6002 static void *async_client_context
;
6003 static serial_event_ftype remote_async_serial_handler
;
6006 remote_async_serial_handler (struct serial
*scb
, void *context
)
6008 /* Don't propogate error information up to the client. Instead let
6009 the client find out about the error by querying the target. */
6010 async_client_callback (INF_REG_EVENT
, async_client_context
);
6014 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
6016 if (current_target
.to_async_mask_value
== 0)
6017 internal_error (__FILE__
, __LINE__
,
6018 "Calling remote_async when async is masked");
6020 if (callback
!= NULL
)
6022 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
6023 async_client_callback
= callback
;
6024 async_client_context
= context
;
6027 serial_async (remote_desc
, NULL
, NULL
);
6030 /* Target async and target extended-async.
6032 This are temporary targets, until it is all tested. Eventually
6033 async support will be incorporated int the usual 'remote'
6037 init_remote_async_ops (void)
6039 remote_async_ops
.to_shortname
= "async";
6040 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
6041 remote_async_ops
.to_doc
=
6042 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
6043 Specify the serial device it is connected to (e.g. /dev/ttya).";
6044 remote_async_ops
.to_open
= remote_async_open
;
6045 remote_async_ops
.to_close
= remote_close
;
6046 remote_async_ops
.to_detach
= remote_async_detach
;
6047 remote_async_ops
.to_resume
= remote_async_resume
;
6048 remote_async_ops
.to_wait
= remote_async_wait
;
6049 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
6050 remote_async_ops
.to_store_registers
= remote_store_registers
;
6051 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
6052 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
6053 remote_async_ops
.to_files_info
= remote_files_info
;
6054 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
6055 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
6056 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
6057 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
6058 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
6059 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
6060 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
6061 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
6062 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
6063 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
6064 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
6065 remote_async_ops
.to_kill
= remote_async_kill
;
6066 remote_async_ops
.to_load
= generic_load
;
6067 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
6068 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
6069 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
6070 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
6071 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
6072 remote_async_ops
.to_stop
= remote_stop
;
6073 remote_async_ops
.to_query
= remote_query
;
6074 remote_async_ops
.to_rcmd
= remote_rcmd
;
6075 remote_async_ops
.to_stratum
= process_stratum
;
6076 remote_async_ops
.to_has_all_memory
= 1;
6077 remote_async_ops
.to_has_memory
= 1;
6078 remote_async_ops
.to_has_stack
= 1;
6079 remote_async_ops
.to_has_registers
= 1;
6080 remote_async_ops
.to_has_execution
= 1;
6081 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
6082 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
6083 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
6084 remote_async_ops
.to_async
= remote_async
;
6085 remote_async_ops
.to_async_mask_value
= 1;
6086 remote_async_ops
.to_magic
= OPS_MAGIC
;
6089 /* Set up the async extended remote vector by making a copy of the standard
6090 remote vector and adding to it. */
6093 init_extended_async_remote_ops (void)
6095 extended_async_remote_ops
= remote_async_ops
;
6097 extended_async_remote_ops
.to_shortname
= "extended-async";
6098 extended_async_remote_ops
.to_longname
=
6099 "Extended remote serial target in async gdb-specific protocol";
6100 extended_async_remote_ops
.to_doc
=
6101 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
6102 Specify the serial device it is connected to (e.g. /dev/ttya).",
6103 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
6104 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
6105 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
6109 set_remote_cmd (char *args
, int from_tty
)
6114 show_remote_cmd (char *args
, int from_tty
)
6116 /* FIXME: cagney/2002-06-15: This function should iterate over
6117 remote_show_cmdlist for a list of sub commands to show. */
6118 show_remote_protocol_Z_packet_cmd (args
, from_tty
, NULL
);
6119 show_remote_protocol_e_packet_cmd (args
, from_tty
, NULL
);
6120 show_remote_protocol_E_packet_cmd (args
, from_tty
, NULL
);
6121 show_remote_protocol_P_packet_cmd (args
, from_tty
, NULL
);
6122 show_remote_protocol_qSymbol_packet_cmd (args
, from_tty
, NULL
);
6123 show_remote_protocol_binary_download_cmd (args
, from_tty
, NULL
);
6127 build_remote_gdbarch_data (void)
6129 remote_address_size
= TARGET_ADDR_BIT
;
6132 /* Saved pointer to previous owner of the new_objfile event. */
6133 static void (*remote_new_objfile_chain
) (struct objfile
*);
6135 /* Function to be called whenever a new objfile (shlib) is detected. */
6137 remote_new_objfile (struct objfile
*objfile
)
6139 if (remote_desc
!= 0) /* Have a remote connection */
6141 remote_check_symbols (objfile
);
6143 /* Call predecessor on chain, if any. */
6144 if (remote_new_objfile_chain
!= 0 &&
6146 remote_new_objfile_chain (objfile
);
6150 _initialize_remote (void)
6152 static struct cmd_list_element
*remote_set_cmdlist
;
6153 static struct cmd_list_element
*remote_show_cmdlist
;
6154 struct cmd_list_element
*tmpcmd
;
6156 /* architecture specific data */
6157 remote_gdbarch_data_handle
= register_gdbarch_data (init_remote_state
,
6160 /* Old tacky stuff. NOTE: This comes after the remote protocol so
6161 that the remote protocol has been initialized. */
6162 register_gdbarch_swap (&remote_address_size
,
6163 sizeof (&remote_address_size
), NULL
);
6164 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
6167 add_target (&remote_ops
);
6169 init_extended_remote_ops ();
6170 add_target (&extended_remote_ops
);
6172 init_remote_async_ops ();
6173 add_target (&remote_async_ops
);
6175 init_extended_async_remote_ops ();
6176 add_target (&extended_async_remote_ops
);
6178 init_remote_cisco_ops ();
6179 add_target (&remote_cisco_ops
);
6181 /* Hook into new objfile notification. */
6182 remote_new_objfile_chain
= target_new_objfile_hook
;
6183 target_new_objfile_hook
= remote_new_objfile
;
6186 init_remote_threadtests ();
6189 /* set/show remote ... */
6191 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
6192 Remote protocol specific variables\n\
6193 Configure various remote-protocol specific variables such as\n\
6194 the packets being used",
6195 &remote_set_cmdlist
, "set remote ",
6196 0/*allow-unknown*/, &setlist
);
6197 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, "\
6198 Remote protocol specific variables\n\
6199 Configure various remote-protocol specific variables such as\n\
6200 the packets being used",
6201 &remote_show_cmdlist
, "show remote ",
6202 0/*allow-unknown*/, &showlist
);
6204 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
6205 "Compare section data on target to the exec file.\n\
6206 Argument is a single section name (default: all loaded sections).",
6209 add_cmd ("packet", class_maintenance
, packet_command
,
6210 "Send an arbitrary packet to a remote target.\n\
6211 maintenance packet TEXT\n\
6212 If GDB is talking to an inferior via the GDB serial protocol, then\n\
6213 this command sends the string TEXT to the inferior, and displays the\n\
6214 response packet. GDB supplies the initial `$' character, and the\n\
6215 terminating `#' character and checksum.",
6218 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
,
6219 "Set whether to send break if interrupted.\n",
6220 "Show whether to send break if interrupted.\n",
6222 &setlist
, &showlist
);
6224 /* Install commands for configuring memory read/write packets. */
6226 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
6227 "Set the maximum number of bytes per memory write packet (deprecated).\n",
6229 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
,
6230 "Show the maximum number of bytes per memory write packet (deprecated).\n",
6232 add_cmd ("memory-write-packet-size", no_class
,
6233 set_memory_write_packet_size
,
6234 "Set the maximum number of bytes per memory-write packet.\n"
6235 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6236 "default packet size. The actual limit is further reduced\n"
6237 "dependent on the target. Specify ``fixed'' to disable the\n"
6238 "further restriction and ``limit'' to enable that restriction\n",
6239 &remote_set_cmdlist
);
6240 add_cmd ("memory-read-packet-size", no_class
,
6241 set_memory_read_packet_size
,
6242 "Set the maximum number of bytes per memory-read packet.\n"
6243 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6244 "default packet size. The actual limit is further reduced\n"
6245 "dependent on the target. Specify ``fixed'' to disable the\n"
6246 "further restriction and ``limit'' to enable that restriction\n",
6247 &remote_set_cmdlist
);
6248 add_cmd ("memory-write-packet-size", no_class
,
6249 show_memory_write_packet_size
,
6250 "Show the maximum number of bytes per memory-write packet.\n",
6251 &remote_show_cmdlist
);
6252 add_cmd ("memory-read-packet-size", no_class
,
6253 show_memory_read_packet_size
,
6254 "Show the maximum number of bytes per memory-read packet.\n",
6255 &remote_show_cmdlist
);
6258 (add_set_cmd ("remoteaddresssize", class_obscure
,
6259 var_integer
, (char *) &remote_address_size
,
6260 "Set the maximum size of the address (in bits) \
6261 in a memory packet.\n",
6265 add_packet_config_cmd (&remote_protocol_binary_download
,
6266 "X", "binary-download",
6267 set_remote_protocol_binary_download_cmd
,
6268 show_remote_protocol_binary_download_cmd
,
6269 &remote_set_cmdlist
, &remote_show_cmdlist
,
6272 /* XXXX - should ``set remotebinarydownload'' be retained for
6275 (add_set_cmd ("remotebinarydownload", no_class
,
6276 var_boolean
, (char *) &remote_binary_download
,
6277 "Set binary downloads.\n", &setlist
),
6281 add_info ("remote-process", remote_info_process
,
6282 "Query the remote system for process info.");
6284 add_packet_config_cmd (&remote_protocol_qSymbol
,
6285 "qSymbol", "symbol-lookup",
6286 set_remote_protocol_qSymbol_packet_cmd
,
6287 show_remote_protocol_qSymbol_packet_cmd
,
6288 &remote_set_cmdlist
, &remote_show_cmdlist
,
6291 add_packet_config_cmd (&remote_protocol_e
,
6292 "e", "step-over-range",
6293 set_remote_protocol_e_packet_cmd
,
6294 show_remote_protocol_e_packet_cmd
,
6295 &remote_set_cmdlist
, &remote_show_cmdlist
,
6297 /* Disable by default. The ``e'' packet has nasty interactions with
6298 the threading code - it relies on global state. */
6299 remote_protocol_e
.detect
= AUTO_BOOLEAN_FALSE
;
6300 update_packet_config (&remote_protocol_e
);
6302 add_packet_config_cmd (&remote_protocol_E
,
6303 "E", "step-over-range-w-signal",
6304 set_remote_protocol_E_packet_cmd
,
6305 show_remote_protocol_E_packet_cmd
,
6306 &remote_set_cmdlist
, &remote_show_cmdlist
,
6308 /* Disable by default. The ``e'' packet has nasty interactions with
6309 the threading code - it relies on global state. */
6310 remote_protocol_E
.detect
= AUTO_BOOLEAN_FALSE
;
6311 update_packet_config (&remote_protocol_E
);
6313 add_packet_config_cmd (&remote_protocol_P
,
6314 "P", "set-register",
6315 set_remote_protocol_P_packet_cmd
,
6316 show_remote_protocol_P_packet_cmd
,
6317 &remote_set_cmdlist
, &remote_show_cmdlist
,
6320 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
6321 "Z0", "software-breakpoint",
6322 set_remote_protocol_Z_software_bp_packet_cmd
,
6323 show_remote_protocol_Z_software_bp_packet_cmd
,
6324 &remote_set_cmdlist
, &remote_show_cmdlist
,
6327 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
6328 "Z1", "hardware-breakpoint",
6329 set_remote_protocol_Z_hardware_bp_packet_cmd
,
6330 show_remote_protocol_Z_hardware_bp_packet_cmd
,
6331 &remote_set_cmdlist
, &remote_show_cmdlist
,
6334 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
6335 "Z2", "write-watchpoint",
6336 set_remote_protocol_Z_write_wp_packet_cmd
,
6337 show_remote_protocol_Z_write_wp_packet_cmd
,
6338 &remote_set_cmdlist
, &remote_show_cmdlist
,
6341 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
6342 "Z3", "read-watchpoint",
6343 set_remote_protocol_Z_read_wp_packet_cmd
,
6344 show_remote_protocol_Z_read_wp_packet_cmd
,
6345 &remote_set_cmdlist
, &remote_show_cmdlist
,
6348 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
6349 "Z4", "access-watchpoint",
6350 set_remote_protocol_Z_access_wp_packet_cmd
,
6351 show_remote_protocol_Z_access_wp_packet_cmd
,
6352 &remote_set_cmdlist
, &remote_show_cmdlist
,
6355 /* Keep the old ``set remote Z-packet ...'' working. */
6356 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
6357 &remote_Z_packet_detect
, "\
6358 Set use of remote protocol `Z' packets",
6359 "Show use of remote protocol `Z' packets ",
6360 set_remote_protocol_Z_packet_cmd
,
6361 show_remote_protocol_Z_packet_cmd
,
6362 &remote_set_cmdlist
, &remote_show_cmdlist
);