1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* See the GDB User Guide for details of the GDB remote protocol. */
26 #include "gdb_string.h"
33 /*#include "terminal.h" */
36 #include "gdb-stabs.h"
37 #include "gdbthread.h"
41 #include "gdb_assert.h"
46 #include <sys/types.h>
49 #include "event-loop.h"
50 #include "event-top.h"
56 #include "gdbcore.h" /* for exec_bfd */
58 #include "remote-fileio.h"
60 /* Prototypes for local functions */
61 static void cleanup_sigint_signal_handler (void *dummy
);
62 static void initialize_sigint_signal_handler (void);
63 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
65 static void handle_remote_sigint (int);
66 static void handle_remote_sigint_twice (int);
67 static void async_remote_interrupt (gdb_client_data
);
68 void async_remote_interrupt_twice (gdb_client_data
);
70 static void build_remote_gdbarch_data (void);
72 static void remote_files_info (struct target_ops
*ignore
);
74 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
75 int len
, int should_write
,
76 struct mem_attrib
*attrib
,
77 struct target_ops
*target
);
79 static void remote_prepare_to_store (void);
81 static void remote_fetch_registers (int regno
);
83 static void remote_resume (ptid_t ptid
, int step
,
84 enum target_signal siggnal
);
85 static void remote_async_resume (ptid_t ptid
, int step
,
86 enum target_signal siggnal
);
87 static int remote_start_remote (struct ui_out
*uiout
, void *dummy
);
89 static void remote_open (char *name
, int from_tty
);
90 static void remote_async_open (char *name
, int from_tty
);
92 static void extended_remote_open (char *name
, int from_tty
);
93 static void extended_remote_async_open (char *name
, int from_tty
);
95 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
,
98 static void remote_close (int quitting
);
100 static void remote_store_registers (int regno
);
102 static void remote_mourn (void);
103 static void remote_async_mourn (void);
105 static void extended_remote_restart (void);
107 static void extended_remote_mourn (void);
109 static void extended_remote_create_inferior (char *, char *, char **);
110 static void extended_remote_async_create_inferior (char *, char *, char **);
112 static void remote_mourn_1 (struct target_ops
*);
114 static void remote_send (char *buf
, long sizeof_buf
);
116 static int readchar (int timeout
);
118 static ptid_t
remote_wait (ptid_t ptid
,
119 struct target_waitstatus
*status
);
120 static ptid_t
remote_async_wait (ptid_t ptid
,
121 struct target_waitstatus
*status
);
123 static void remote_kill (void);
124 static void remote_async_kill (void);
126 static int tohex (int nib
);
128 static void remote_detach (char *args
, int from_tty
);
130 static void remote_interrupt (int signo
);
132 static void remote_interrupt_twice (int signo
);
134 static void interrupt_query (void);
136 static void set_thread (int, int);
138 static int remote_thread_alive (ptid_t
);
140 static void get_offsets (void);
142 static long read_frame (char *buf
, long sizeof_buf
);
144 static int remote_insert_breakpoint (CORE_ADDR
, char *);
146 static int remote_remove_breakpoint (CORE_ADDR
, char *);
148 static int hexnumlen (ULONGEST num
);
150 static void init_remote_ops (void);
152 static void init_extended_remote_ops (void);
154 static void init_remote_cisco_ops (void);
156 static struct target_ops remote_cisco_ops
;
158 static void remote_stop (void);
160 static int ishex (int ch
, int *val
);
162 static int stubhex (int ch
);
164 static int hexnumstr (char *, ULONGEST
);
166 static int hexnumnstr (char *, ULONGEST
, int);
168 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
170 static void print_packet (char *);
172 static unsigned long crc32 (unsigned char *, int, unsigned int);
174 static void compare_sections_command (char *, int);
176 static void packet_command (char *, int);
178 static int stub_unpack_int (char *buff
, int fieldlength
);
180 static ptid_t
remote_current_thread (ptid_t oldptid
);
182 static void remote_find_new_threads (void);
184 static void record_currthread (int currthread
);
186 static int fromhex (int a
);
188 static int hex2bin (const char *hex
, char *bin
, int count
);
190 static int bin2hex (const char *bin
, char *hex
, int count
);
192 static int putpkt_binary (char *buf
, int cnt
);
194 static void check_binary_download (CORE_ADDR addr
);
196 struct packet_config
;
198 static void show_packet_config_cmd (struct packet_config
*config
);
200 static void update_packet_config (struct packet_config
*config
);
202 void _initialize_remote (void);
204 /* Description of the remote protocol. Strictly speaking, when the
205 target is open()ed, remote.c should create a per-target description
206 of the remote protocol using that target's architecture.
207 Unfortunately, the target stack doesn't include local state. For
208 the moment keep the information in the target's architecture
213 long offset
; /* Offset into G packet. */
214 long regnum
; /* GDB's internal register number. */
215 LONGEST pnum
; /* Remote protocol register number. */
216 int in_g_packet
; /* Always part of G packet. */
217 /* long size in bytes; == DEPRECATED_REGISTER_RAW_SIZE (regnum); at present. */
218 /* char *name; == REGISTER_NAME (regnum); at present. */
223 /* Description of the remote protocol registers. */
224 long sizeof_g_packet
;
226 /* Description of the remote protocol registers indexed by REGNUM
227 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
228 struct packet_reg
*regs
;
230 /* This is the size (in chars) of the first response to the ``g''
231 packet. It is used as a heuristic when determining the maximum
232 size of memory-read and memory-write packets. A target will
233 typically only reserve a buffer large enough to hold the ``g''
234 packet. The size does not include packet overhead (headers and
236 long actual_register_packet_size
;
238 /* This is the maximum size (in chars) of a non read/write packet.
239 It is also used as a cap on the size of read/write packets. */
240 long remote_packet_size
;
244 /* Handle for retreving the remote protocol data from gdbarch. */
245 static struct gdbarch_data
*remote_gdbarch_data_handle
;
247 static struct remote_state
*
248 get_remote_state (void)
250 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
254 init_remote_state (struct gdbarch
*gdbarch
)
257 struct remote_state
*rs
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_state
);
259 if (DEPRECATED_REGISTER_BYTES
!= 0)
260 rs
->sizeof_g_packet
= DEPRECATED_REGISTER_BYTES
;
262 rs
->sizeof_g_packet
= 0;
264 /* Assume a 1:1 regnum<->pnum table. */
265 rs
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
, NUM_REGS
+ NUM_PSEUDO_REGS
,
267 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
269 struct packet_reg
*r
= &rs
->regs
[regnum
];
272 r
->offset
= DEPRECATED_REGISTER_BYTE (regnum
);
273 r
->in_g_packet
= (regnum
< NUM_REGS
);
274 /* ...name = REGISTER_NAME (regnum); */
276 /* Compute packet size by accumulating the size of all registers. */
277 if (DEPRECATED_REGISTER_BYTES
== 0)
278 rs
->sizeof_g_packet
+= register_size (current_gdbarch
, regnum
);
281 /* Default maximum number of characters in a packet body. Many
282 remote stubs have a hardwired buffer size of 400 bytes
283 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
284 as the maximum packet-size to ensure that the packet and an extra
285 NUL character can always fit in the buffer. This stops GDB
286 trashing stubs that try to squeeze an extra NUL into what is
287 already a full buffer (As of 1999-12-04 that was most stubs. */
288 rs
->remote_packet_size
= 400 - 1;
290 /* Should rs->sizeof_g_packet needs more space than the
291 default, adjust the size accordingly. Remember that each byte is
292 encoded as two characters. 32 is the overhead for the packet
293 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
294 (``$NN:G...#NN'') is a better guess, the below has been padded a
296 if (rs
->sizeof_g_packet
> ((rs
->remote_packet_size
- 32) / 2))
297 rs
->remote_packet_size
= (rs
->sizeof_g_packet
* 2 + 32);
299 /* This one is filled in when a ``g'' packet is received. */
300 rs
->actual_register_packet_size
= 0;
305 static struct packet_reg
*
306 packet_reg_from_regnum (struct remote_state
*rs
, long regnum
)
308 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
312 struct packet_reg
*r
= &rs
->regs
[regnum
];
313 gdb_assert (r
->regnum
== regnum
);
318 static struct packet_reg
*
319 packet_reg_from_pnum (struct remote_state
*rs
, LONGEST pnum
)
322 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
324 struct packet_reg
*r
= &rs
->regs
[i
];
331 /* FIXME: graces/2002-08-08: These variables should eventually be
332 bound to an instance of the target object (as in gdbarch-tdep()),
333 when such a thing exists. */
335 /* This is set to the data address of the access causing the target
336 to stop for a watchpoint. */
337 static CORE_ADDR remote_watch_data_address
;
339 /* This is non-zero if taregt stopped for a watchpoint. */
340 static int remote_stopped_by_watchpoint_p
;
343 static struct target_ops remote_ops
;
345 static struct target_ops extended_remote_ops
;
347 /* Temporary target ops. Just like the remote_ops and
348 extended_remote_ops, but with asynchronous support. */
349 static struct target_ops remote_async_ops
;
351 static struct target_ops extended_async_remote_ops
;
353 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
354 ``forever'' still use the normal timeout mechanism. This is
355 currently used by the ASYNC code to guarentee that target reads
356 during the initial connect always time-out. Once getpkt has been
357 modified to return a timeout indication and, in turn
358 remote_wait()/wait_for_inferior() have gained a timeout parameter
360 static int wait_forever_enabled_p
= 1;
363 /* This variable chooses whether to send a ^C or a break when the user
364 requests program interruption. Although ^C is usually what remote
365 systems expect, and that is the default here, sometimes a break is
366 preferable instead. */
368 static int remote_break
;
370 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
371 remote_open knows that we don't have a file open when the program
373 static struct serial
*remote_desc
= NULL
;
375 /* This is set by the target (thru the 'S' message)
376 to denote that the target is in kernel mode. */
377 static int cisco_kernel_mode
= 0;
379 /* This variable sets the number of bits in an address that are to be
380 sent in a memory ("M" or "m") packet. Normally, after stripping
381 leading zeros, the entire address would be sent. This variable
382 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
383 initial implementation of remote.c restricted the address sent in
384 memory packets to ``host::sizeof long'' bytes - (typically 32
385 bits). Consequently, for 64 bit targets, the upper 32 bits of an
386 address was never sent. Since fixing this bug may cause a break in
387 some remote targets this variable is principly provided to
388 facilitate backward compatibility. */
390 static int remote_address_size
;
392 /* Tempoary to track who currently owns the terminal. See
393 target_async_terminal_* for more details. */
395 static int remote_async_terminal_ours_p
;
398 /* User configurable variables for the number of characters in a
399 memory read/write packet. MIN ((rs->remote_packet_size),
400 rs->sizeof_g_packet) is the default. Some targets need smaller
401 values (fifo overruns, et.al.) and some users need larger values
402 (speed up transfers). The variables ``preferred_*'' (the user
403 request), ``current_*'' (what was actually set) and ``forced_*''
404 (Positive - a soft limit, negative - a hard limit). */
406 struct memory_packet_config
413 /* Compute the current size of a read/write packet. Since this makes
414 use of ``actual_register_packet_size'' the computation is dynamic. */
417 get_memory_packet_size (struct memory_packet_config
*config
)
419 struct remote_state
*rs
= get_remote_state ();
420 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
421 law?) that some hosts don't cope very well with large alloca()
422 calls. Eventually the alloca() code will be replaced by calls to
423 xmalloc() and make_cleanups() allowing this restriction to either
424 be lifted or removed. */
425 #ifndef MAX_REMOTE_PACKET_SIZE
426 #define MAX_REMOTE_PACKET_SIZE 16384
428 /* NOTE: 16 is just chosen at random. */
429 #ifndef MIN_REMOTE_PACKET_SIZE
430 #define MIN_REMOTE_PACKET_SIZE 16
435 if (config
->size
<= 0)
436 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
438 what_they_get
= config
->size
;
442 what_they_get
= (rs
->remote_packet_size
);
443 /* Limit the packet to the size specified by the user. */
445 && what_they_get
> config
->size
)
446 what_they_get
= config
->size
;
447 /* Limit it to the size of the targets ``g'' response. */
448 if ((rs
->actual_register_packet_size
) > 0
449 && what_they_get
> (rs
->actual_register_packet_size
))
450 what_they_get
= (rs
->actual_register_packet_size
);
452 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
453 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
454 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
455 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
456 return what_they_get
;
459 /* Update the size of a read/write packet. If they user wants
460 something really big then do a sanity check. */
463 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
465 int fixed_p
= config
->fixed_p
;
466 long size
= config
->size
;
468 error ("Argument required (integer, `fixed' or `limited').");
469 else if (strcmp (args
, "hard") == 0
470 || strcmp (args
, "fixed") == 0)
472 else if (strcmp (args
, "soft") == 0
473 || strcmp (args
, "limit") == 0)
478 size
= strtoul (args
, &end
, 0);
480 error ("Invalid %s (bad syntax).", config
->name
);
482 /* Instead of explicitly capping the size of a packet to
483 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
484 instead allowed to set the size to something arbitrarily
486 if (size
> MAX_REMOTE_PACKET_SIZE
)
487 error ("Invalid %s (too large).", config
->name
);
491 if (fixed_p
&& !config
->fixed_p
)
493 if (! query ("The target may not be able to correctly handle a %s\n"
494 "of %ld bytes. Change the packet size? ",
496 error ("Packet size not changed.");
498 /* Update the config. */
499 config
->fixed_p
= fixed_p
;
504 show_memory_packet_size (struct memory_packet_config
*config
)
506 printf_filtered ("The %s is %ld. ", config
->name
, config
->size
);
508 printf_filtered ("Packets are fixed at %ld bytes.\n",
509 get_memory_packet_size (config
));
511 printf_filtered ("Packets are limited to %ld bytes.\n",
512 get_memory_packet_size (config
));
515 static struct memory_packet_config memory_write_packet_config
=
517 "memory-write-packet-size",
521 set_memory_write_packet_size (char *args
, int from_tty
)
523 set_memory_packet_size (args
, &memory_write_packet_config
);
527 show_memory_write_packet_size (char *args
, int from_tty
)
529 show_memory_packet_size (&memory_write_packet_config
);
533 get_memory_write_packet_size (void)
535 return get_memory_packet_size (&memory_write_packet_config
);
538 static struct memory_packet_config memory_read_packet_config
=
540 "memory-read-packet-size",
544 set_memory_read_packet_size (char *args
, int from_tty
)
546 set_memory_packet_size (args
, &memory_read_packet_config
);
550 show_memory_read_packet_size (char *args
, int from_tty
)
552 show_memory_packet_size (&memory_read_packet_config
);
556 get_memory_read_packet_size (void)
558 struct remote_state
*rs
= get_remote_state ();
559 long size
= get_memory_packet_size (&memory_read_packet_config
);
560 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
561 extra buffer size argument before the memory read size can be
562 increased beyond (rs->remote_packet_size). */
563 if (size
> (rs
->remote_packet_size
))
564 size
= (rs
->remote_packet_size
);
569 /* Generic configuration support for packets the stub optionally
570 supports. Allows the user to specify the use of the packet as well
571 as allowing GDB to auto-detect support in the remote stub. */
575 PACKET_SUPPORT_UNKNOWN
= 0,
584 enum auto_boolean detect
;
585 enum packet_support support
;
588 /* Analyze a packet's return value and update the packet config
599 update_packet_config (struct packet_config
*config
)
601 switch (config
->detect
)
603 case AUTO_BOOLEAN_TRUE
:
604 config
->support
= PACKET_ENABLE
;
606 case AUTO_BOOLEAN_FALSE
:
607 config
->support
= PACKET_DISABLE
;
609 case AUTO_BOOLEAN_AUTO
:
610 config
->support
= PACKET_SUPPORT_UNKNOWN
;
616 show_packet_config_cmd (struct packet_config
*config
)
618 char *support
= "internal-error";
619 switch (config
->support
)
625 support
= "disabled";
627 case PACKET_SUPPORT_UNKNOWN
:
631 switch (config
->detect
)
633 case AUTO_BOOLEAN_AUTO
:
634 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
635 config
->name
, config
->title
, support
);
637 case AUTO_BOOLEAN_TRUE
:
638 case AUTO_BOOLEAN_FALSE
:
639 printf_filtered ("Support for remote protocol `%s' (%s) packet is currently %s.\n",
640 config
->name
, config
->title
, support
);
646 add_packet_config_cmd (struct packet_config
*config
,
649 cmd_sfunc_ftype
*set_func
,
650 cmd_sfunc_ftype
*show_func
,
651 struct cmd_list_element
**set_remote_list
,
652 struct cmd_list_element
**show_remote_list
,
655 struct cmd_list_element
*set_cmd
;
656 struct cmd_list_element
*show_cmd
;
661 config
->title
= title
;
662 config
->detect
= AUTO_BOOLEAN_AUTO
;
663 config
->support
= PACKET_SUPPORT_UNKNOWN
;
664 xasprintf (&set_doc
, "Set use of remote protocol `%s' (%s) packet",
666 xasprintf (&show_doc
, "Show current use of remote protocol `%s' (%s) packet",
668 /* set/show TITLE-packet {auto,on,off} */
669 xasprintf (&cmd_name
, "%s-packet", title
);
670 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
671 &config
->detect
, set_doc
, show_doc
,
673 set_remote_list
, show_remote_list
);
674 /* set/show remote NAME-packet {auto,on,off} -- legacy */
678 xasprintf (&legacy_name
, "%s-packet", name
);
679 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
681 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
686 static enum packet_result
687 packet_ok (const char *buf
, struct packet_config
*config
)
691 /* The stub recognized the packet request. Check that the
692 operation succeeded. */
693 switch (config
->support
)
695 case PACKET_SUPPORT_UNKNOWN
:
697 fprintf_unfiltered (gdb_stdlog
,
698 "Packet %s (%s) is supported\n",
699 config
->name
, config
->title
);
700 config
->support
= PACKET_ENABLE
;
703 internal_error (__FILE__
, __LINE__
,
704 "packet_ok: attempt to use a disabled packet");
709 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
710 /* "OK" - definitly OK. */
713 && isxdigit (buf
[1]) && isxdigit (buf
[2])
715 /* "Enn" - definitly an error. */
717 /* The packet may or may not be OK. Just assume it is */
722 /* The stub does not support the packet. */
723 switch (config
->support
)
726 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
727 /* If the stub previously indicated that the packet was
728 supported then there is a protocol error.. */
729 error ("Protocol error: %s (%s) conflicting enabled responses.",
730 config
->name
, config
->title
);
732 /* The user set it wrong. */
733 error ("Enabled packet %s (%s) not recognized by stub",
734 config
->name
, config
->title
);
736 case PACKET_SUPPORT_UNKNOWN
:
738 fprintf_unfiltered (gdb_stdlog
,
739 "Packet %s (%s) is NOT supported\n",
740 config
->name
, config
->title
);
741 config
->support
= PACKET_DISABLE
;
746 return PACKET_UNKNOWN
;
750 /* Should we try the 'vCont' (descriptive resume) request? */
751 static struct packet_config remote_protocol_vcont
;
754 set_remote_protocol_vcont_packet_cmd (char *args
, int from_tty
,
755 struct cmd_list_element
*c
)
757 update_packet_config (&remote_protocol_vcont
);
761 show_remote_protocol_vcont_packet_cmd (char *args
, int from_tty
,
762 struct cmd_list_element
*c
)
764 show_packet_config_cmd (&remote_protocol_vcont
);
767 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
768 static struct packet_config remote_protocol_qSymbol
;
771 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
772 struct cmd_list_element
*c
)
774 update_packet_config (&remote_protocol_qSymbol
);
778 show_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
779 struct cmd_list_element
*c
)
781 show_packet_config_cmd (&remote_protocol_qSymbol
);
784 /* Should we try the 'e' (step over range) request? */
785 static struct packet_config remote_protocol_e
;
788 set_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
789 struct cmd_list_element
*c
)
791 update_packet_config (&remote_protocol_e
);
795 show_remote_protocol_e_packet_cmd (char *args
, int from_tty
,
796 struct cmd_list_element
*c
)
798 show_packet_config_cmd (&remote_protocol_e
);
802 /* Should we try the 'E' (step over range / w signal #) request? */
803 static struct packet_config remote_protocol_E
;
806 set_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
807 struct cmd_list_element
*c
)
809 update_packet_config (&remote_protocol_E
);
813 show_remote_protocol_E_packet_cmd (char *args
, int from_tty
,
814 struct cmd_list_element
*c
)
816 show_packet_config_cmd (&remote_protocol_E
);
820 /* Should we try the 'P' (set register) request? */
822 static struct packet_config remote_protocol_P
;
825 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
826 struct cmd_list_element
*c
)
828 update_packet_config (&remote_protocol_P
);
832 show_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
833 struct cmd_list_element
*c
)
835 show_packet_config_cmd (&remote_protocol_P
);
838 /* Should we try one of the 'Z' requests? */
842 Z_PACKET_SOFTWARE_BP
,
843 Z_PACKET_HARDWARE_BP
,
850 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
852 /* FIXME: Instead of having all these boiler plate functions, the
853 command callback should include a context argument. */
856 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
857 struct cmd_list_element
*c
)
859 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
863 show_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
864 struct cmd_list_element
*c
)
866 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
870 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
871 struct cmd_list_element
*c
)
873 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
877 show_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
878 struct cmd_list_element
*c
)
880 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
884 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
885 struct cmd_list_element
*c
)
887 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
891 show_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
892 struct cmd_list_element
*c
)
894 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
898 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
899 struct cmd_list_element
*c
)
901 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
905 show_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
906 struct cmd_list_element
*c
)
908 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
912 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
913 struct cmd_list_element
*c
)
915 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
919 show_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
920 struct cmd_list_element
*c
)
922 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
925 /* For compatibility with older distributions. Provide a ``set remote
926 Z-packet ...'' command that updates all the Z packet types. */
928 static enum auto_boolean remote_Z_packet_detect
;
931 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
932 struct cmd_list_element
*c
)
935 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
937 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
938 update_packet_config (&remote_protocol_Z
[i
]);
943 show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
944 struct cmd_list_element
*c
)
947 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
949 show_packet_config_cmd (&remote_protocol_Z
[i
]);
953 /* Should we try the 'X' (remote binary download) packet?
955 This variable (available to the user via "set remote X-packet")
956 dictates whether downloads are sent in binary (via the 'X' packet).
957 We assume that the stub can, and attempt to do it. This will be
958 cleared if the stub does not understand it. This switch is still
959 needed, though in cases when the packet is supported in the stub,
960 but the connection does not allow it (i.e., 7-bit serial connection
963 static struct packet_config remote_protocol_binary_download
;
965 /* Should we try the 'ThreadInfo' query packet?
967 This variable (NOT available to the user: auto-detect only!)
968 determines whether GDB will use the new, simpler "ThreadInfo"
969 query or the older, more complex syntax for thread queries.
970 This is an auto-detect variable (set to true at each connect,
971 and set to false when the target fails to recognize it). */
973 static int use_threadinfo_query
;
974 static int use_threadextra_query
;
977 set_remote_protocol_binary_download_cmd (char *args
,
979 struct cmd_list_element
*c
)
981 update_packet_config (&remote_protocol_binary_download
);
985 show_remote_protocol_binary_download_cmd (char *args
, int from_tty
,
986 struct cmd_list_element
*c
)
988 show_packet_config_cmd (&remote_protocol_binary_download
);
992 /* Tokens for use by the asynchronous signal handlers for SIGINT */
993 static void *sigint_remote_twice_token
;
994 static void *sigint_remote_token
;
996 /* These are pointers to hook functions that may be set in order to
997 modify resume/wait behavior for a particular architecture. */
999 void (*target_resume_hook
) (void);
1000 void (*target_wait_loop_hook
) (void);
1004 /* These are the threads which we last sent to the remote system.
1005 -1 for all or -2 for not sent yet. */
1006 static int general_thread
;
1007 static int continue_thread
;
1009 /* Call this function as a result of
1010 1) A halt indication (T packet) containing a thread id
1011 2) A direct query of currthread
1012 3) Successful execution of set thread
1016 record_currthread (int currthread
)
1018 general_thread
= currthread
;
1020 /* If this is a new thread, add it to GDB's thread list.
1021 If we leave it up to WFI to do this, bad things will happen. */
1022 if (!in_thread_list (pid_to_ptid (currthread
)))
1024 add_thread (pid_to_ptid (currthread
));
1025 ui_out_text (uiout
, "[New ");
1026 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
1027 ui_out_text (uiout
, "]\n");
1031 #define MAGIC_NULL_PID 42000
1034 set_thread (int th
, int gen
)
1036 struct remote_state
*rs
= get_remote_state ();
1037 char *buf
= alloca (rs
->remote_packet_size
);
1038 int state
= gen
? general_thread
: continue_thread
;
1044 buf
[1] = gen
? 'g' : 'c';
1045 if (th
== MAGIC_NULL_PID
)
1051 sprintf (&buf
[2], "-%x", -th
);
1053 sprintf (&buf
[2], "%x", th
);
1055 getpkt (buf
, (rs
->remote_packet_size
), 0);
1057 general_thread
= th
;
1059 continue_thread
= th
;
1062 /* Return nonzero if the thread TH is still alive on the remote system. */
1065 remote_thread_alive (ptid_t ptid
)
1067 int tid
= PIDGET (ptid
);
1071 sprintf (buf
, "T-%08x", -tid
);
1073 sprintf (buf
, "T%08x", tid
);
1075 getpkt (buf
, sizeof (buf
), 0);
1076 return (buf
[0] == 'O' && buf
[1] == 'K');
1079 /* About these extended threadlist and threadinfo packets. They are
1080 variable length packets but, the fields within them are often fixed
1081 length. They are redundent enough to send over UDP as is the
1082 remote protocol in general. There is a matching unit test module
1085 #define OPAQUETHREADBYTES 8
1087 /* a 64 bit opaque identifier */
1088 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1090 /* WARNING: This threadref data structure comes from the remote O.S., libstub
1091 protocol encoding, and remote.c. it is not particularly changable */
1093 /* Right now, the internal structure is int. We want it to be bigger.
1097 typedef int gdb_threadref
; /* internal GDB thread reference */
1099 /* gdb_ext_thread_info is an internal GDB data structure which is
1100 equivalint to the reply of the remote threadinfo packet */
1102 struct gdb_ext_thread_info
1104 threadref threadid
; /* External form of thread reference */
1105 int active
; /* Has state interesting to GDB? , regs, stack */
1106 char display
[256]; /* Brief state display, name, blocked/syspended */
1107 char shortname
[32]; /* To be used to name threads */
1108 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
1111 /* The volume of remote transfers can be limited by submitting
1112 a mask containing bits specifying the desired information.
1113 Use a union of these values as the 'selection' parameter to
1114 get_thread_info. FIXME: Make these TAG names more thread specific.
1117 #define TAG_THREADID 1
1118 #define TAG_EXISTS 2
1119 #define TAG_DISPLAY 4
1120 #define TAG_THREADNAME 8
1121 #define TAG_MOREDISPLAY 16
1123 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
1125 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1127 static char *unpack_nibble (char *buf
, int *val
);
1129 static char *pack_nibble (char *buf
, int nibble
);
1131 static char *pack_hex_byte (char *pkt
, int /*unsigned char */ byte
);
1133 static char *unpack_byte (char *buf
, int *value
);
1135 static char *pack_int (char *buf
, int value
);
1137 static char *unpack_int (char *buf
, int *value
);
1139 static char *unpack_string (char *src
, char *dest
, int length
);
1141 static char *pack_threadid (char *pkt
, threadref
* id
);
1143 static char *unpack_threadid (char *inbuf
, threadref
* id
);
1145 void int_to_threadref (threadref
* id
, int value
);
1147 static int threadref_to_int (threadref
* ref
);
1149 static void copy_threadref (threadref
* dest
, threadref
* src
);
1151 static int threadmatch (threadref
* dest
, threadref
* src
);
1153 static char *pack_threadinfo_request (char *pkt
, int mode
, threadref
* id
);
1155 static int remote_unpack_thread_info_response (char *pkt
,
1156 threadref
* expectedref
,
1157 struct gdb_ext_thread_info
1161 static int remote_get_threadinfo (threadref
* threadid
, int fieldset
, /*TAG mask */
1162 struct gdb_ext_thread_info
*info
);
1164 static int adapt_remote_get_threadinfo (gdb_threadref
* ref
,
1166 struct gdb_ext_thread_info
*info
);
1168 static char *pack_threadlist_request (char *pkt
, int startflag
,
1170 threadref
* nextthread
);
1172 static int parse_threadlist_response (char *pkt
,
1174 threadref
* original_echo
,
1175 threadref
* resultlist
, int *doneflag
);
1177 static int remote_get_threadlist (int startflag
,
1178 threadref
* nextthread
,
1181 int *result_count
, threadref
* threadlist
);
1183 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
1185 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1186 void *context
, int looplimit
);
1188 static int remote_newthread_step (threadref
* ref
, void *context
);
1190 /* encode 64 bits in 16 chars of hex */
1192 static const char hexchars
[] = "0123456789abcdef";
1195 ishex (int ch
, int *val
)
1197 if ((ch
>= 'a') && (ch
<= 'f'))
1199 *val
= ch
- 'a' + 10;
1202 if ((ch
>= 'A') && (ch
<= 'F'))
1204 *val
= ch
- 'A' + 10;
1207 if ((ch
>= '0') && (ch
<= '9'))
1218 if (ch
>= 'a' && ch
<= 'f')
1219 return ch
- 'a' + 10;
1220 if (ch
>= '0' && ch
<= '9')
1222 if (ch
>= 'A' && ch
<= 'F')
1223 return ch
- 'A' + 10;
1228 stub_unpack_int (char *buff
, int fieldlength
)
1235 nibble
= stubhex (*buff
++);
1239 retval
= retval
<< 4;
1245 unpack_varlen_hex (char *buff
, /* packet to parse */
1251 while (ishex (*buff
, &nibble
))
1254 retval
= retval
<< 4;
1255 retval
|= nibble
& 0x0f;
1262 unpack_nibble (char *buf
, int *val
)
1264 ishex (*buf
++, val
);
1269 pack_nibble (char *buf
, int nibble
)
1271 *buf
++ = hexchars
[(nibble
& 0x0f)];
1276 pack_hex_byte (char *pkt
, int byte
)
1278 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1279 *pkt
++ = hexchars
[(byte
& 0xf)];
1284 unpack_byte (char *buf
, int *value
)
1286 *value
= stub_unpack_int (buf
, 2);
1291 pack_int (char *buf
, int value
)
1293 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1294 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1295 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1296 buf
= pack_hex_byte (buf
, (value
& 0xff));
1301 unpack_int (char *buf
, int *value
)
1303 *value
= stub_unpack_int (buf
, 8);
1307 #if 0 /* currently unused, uncomment when needed */
1308 static char *pack_string (char *pkt
, char *string
);
1311 pack_string (char *pkt
, char *string
)
1316 len
= strlen (string
);
1318 len
= 200; /* Bigger than most GDB packets, junk??? */
1319 pkt
= pack_hex_byte (pkt
, len
);
1323 if ((ch
== '\0') || (ch
== '#'))
1324 ch
= '*'; /* Protect encapsulation */
1329 #endif /* 0 (unused) */
1332 unpack_string (char *src
, char *dest
, int length
)
1341 pack_threadid (char *pkt
, threadref
*id
)
1344 unsigned char *altid
;
1346 altid
= (unsigned char *) id
;
1347 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1349 pkt
= pack_hex_byte (pkt
, *altid
++);
1355 unpack_threadid (char *inbuf
, threadref
*id
)
1358 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1361 altref
= (char *) id
;
1363 while (inbuf
< limit
)
1365 x
= stubhex (*inbuf
++);
1366 y
= stubhex (*inbuf
++);
1367 *altref
++ = (x
<< 4) | y
;
1372 /* Externally, threadrefs are 64 bits but internally, they are still
1373 ints. This is due to a mismatch of specifications. We would like
1374 to use 64bit thread references internally. This is an adapter
1378 int_to_threadref (threadref
*id
, int value
)
1380 unsigned char *scan
;
1382 scan
= (unsigned char *) id
;
1388 *scan
++ = (value
>> 24) & 0xff;
1389 *scan
++ = (value
>> 16) & 0xff;
1390 *scan
++ = (value
>> 8) & 0xff;
1391 *scan
++ = (value
& 0xff);
1395 threadref_to_int (threadref
*ref
)
1398 unsigned char *scan
;
1400 scan
= (char *) ref
;
1404 value
= (value
<< 8) | ((*scan
++) & 0xff);
1409 copy_threadref (threadref
*dest
, threadref
*src
)
1412 unsigned char *csrc
, *cdest
;
1414 csrc
= (unsigned char *) src
;
1415 cdest
= (unsigned char *) dest
;
1422 threadmatch (threadref
*dest
, threadref
*src
)
1424 /* things are broken right now, so just assume we got a match */
1426 unsigned char *srcp
, *destp
;
1428 srcp
= (char *) src
;
1429 destp
= (char *) dest
;
1433 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1440 threadid:1, # always request threadid
1447 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1450 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1452 *pkt
++ = 'q'; /* Info Query */
1453 *pkt
++ = 'P'; /* process or thread info */
1454 pkt
= pack_int (pkt
, mode
); /* mode */
1455 pkt
= pack_threadid (pkt
, id
); /* threadid */
1456 *pkt
= '\0'; /* terminate */
1460 /* These values tag the fields in a thread info response packet */
1461 /* Tagging the fields allows us to request specific fields and to
1462 add more fields as time goes by */
1464 #define TAG_THREADID 1 /* Echo the thread identifier */
1465 #define TAG_EXISTS 2 /* Is this process defined enough to
1466 fetch registers and its stack */
1467 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1468 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1469 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1473 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1474 struct gdb_ext_thread_info
*info
)
1476 struct remote_state
*rs
= get_remote_state ();
1480 char *limit
= pkt
+ (rs
->remote_packet_size
); /* plausable parsing limit */
1483 /* info->threadid = 0; FIXME: implement zero_threadref */
1485 info
->display
[0] = '\0';
1486 info
->shortname
[0] = '\0';
1487 info
->more_display
[0] = '\0';
1489 /* Assume the characters indicating the packet type have been stripped */
1490 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1491 pkt
= unpack_threadid (pkt
, &ref
);
1494 warning ("Incomplete response to threadinfo request\n");
1495 if (!threadmatch (&ref
, expectedref
))
1496 { /* This is an answer to a different request */
1497 warning ("ERROR RMT Thread info mismatch\n");
1500 copy_threadref (&info
->threadid
, &ref
);
1502 /* Loop on tagged fields , try to bail if somthing goes wrong */
1504 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1506 pkt
= unpack_int (pkt
, &tag
); /* tag */
1507 pkt
= unpack_byte (pkt
, &length
); /* length */
1508 if (!(tag
& mask
)) /* tags out of synch with mask */
1510 warning ("ERROR RMT: threadinfo tag mismatch\n");
1514 if (tag
== TAG_THREADID
)
1518 warning ("ERROR RMT: length of threadid is not 16\n");
1522 pkt
= unpack_threadid (pkt
, &ref
);
1523 mask
= mask
& ~TAG_THREADID
;
1526 if (tag
== TAG_EXISTS
)
1528 info
->active
= stub_unpack_int (pkt
, length
);
1530 mask
= mask
& ~(TAG_EXISTS
);
1533 warning ("ERROR RMT: 'exists' length too long\n");
1539 if (tag
== TAG_THREADNAME
)
1541 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1542 mask
= mask
& ~TAG_THREADNAME
;
1545 if (tag
== TAG_DISPLAY
)
1547 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1548 mask
= mask
& ~TAG_DISPLAY
;
1551 if (tag
== TAG_MOREDISPLAY
)
1553 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1554 mask
= mask
& ~TAG_MOREDISPLAY
;
1557 warning ("ERROR RMT: unknown thread info tag\n");
1558 break; /* Not a tag we know about */
1564 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1565 struct gdb_ext_thread_info
*info
)
1567 struct remote_state
*rs
= get_remote_state ();
1569 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1571 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1572 putpkt (threadinfo_pkt
);
1573 getpkt (threadinfo_pkt
, (rs
->remote_packet_size
), 0);
1574 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1579 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1580 representation of a threadid. */
1583 adapt_remote_get_threadinfo (gdb_threadref
*ref
, int selection
,
1584 struct gdb_ext_thread_info
*info
)
1588 int_to_threadref (&lclref
, *ref
);
1589 return remote_get_threadinfo (&lclref
, selection
, info
);
1592 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1595 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1596 threadref
*nextthread
)
1598 *pkt
++ = 'q'; /* info query packet */
1599 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1600 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1601 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1602 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1607 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1610 parse_threadlist_response (char *pkt
, int result_limit
,
1611 threadref
*original_echo
, threadref
*resultlist
,
1614 struct remote_state
*rs
= get_remote_state ();
1616 int count
, resultcount
, done
;
1619 /* Assume the 'q' and 'M chars have been stripped. */
1620 limit
= pkt
+ ((rs
->remote_packet_size
) - BUF_THREAD_ID_SIZE
); /* done parse past here */
1621 pkt
= unpack_byte (pkt
, &count
); /* count field */
1622 pkt
= unpack_nibble (pkt
, &done
);
1623 /* The first threadid is the argument threadid. */
1624 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1625 while ((count
-- > 0) && (pkt
< limit
))
1627 pkt
= unpack_threadid (pkt
, resultlist
++);
1628 if (resultcount
++ >= result_limit
)
1637 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1638 int *done
, int *result_count
, threadref
*threadlist
)
1640 struct remote_state
*rs
= get_remote_state ();
1641 static threadref echo_nextthread
;
1642 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1643 char *t_response
= alloca (rs
->remote_packet_size
);
1646 /* Trancate result limit to be smaller than the packet size */
1647 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= (rs
->remote_packet_size
))
1648 result_limit
= ((rs
->remote_packet_size
) / BUF_THREAD_ID_SIZE
) - 2;
1650 pack_threadlist_request (threadlist_packet
,
1651 startflag
, result_limit
, nextthread
);
1652 putpkt (threadlist_packet
);
1653 getpkt (t_response
, (rs
->remote_packet_size
), 0);
1656 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1659 if (!threadmatch (&echo_nextthread
, nextthread
))
1661 /* FIXME: This is a good reason to drop the packet */
1662 /* Possably, there is a duplicate response */
1664 retransmit immediatly - race conditions
1665 retransmit after timeout - yes
1667 wait for packet, then exit
1669 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1670 return 0; /* I choose simply exiting */
1672 if (*result_count
<= 0)
1676 warning ("RMT ERROR : failed to get remote thread list\n");
1679 return result
; /* break; */
1681 if (*result_count
> result_limit
)
1684 warning ("RMT ERROR: threadlist response longer than requested\n");
1690 /* This is the interface between remote and threads, remotes upper interface */
1692 /* remote_find_new_threads retrieves the thread list and for each
1693 thread in the list, looks up the thread in GDB's internal list,
1694 ading the thread if it does not already exist. This involves
1695 getting partial thread lists from the remote target so, polling the
1696 quit_flag is required. */
1699 /* About this many threadisds fit in a packet. */
1701 #define MAXTHREADLISTRESULTS 32
1704 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1707 int done
, i
, result_count
;
1711 static threadref nextthread
;
1712 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1717 if (loopcount
++ > looplimit
)
1720 warning ("Remote fetch threadlist -infinite loop-\n");
1723 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1724 &done
, &result_count
, resultthreadlist
))
1729 /* clear for later iterations */
1731 /* Setup to resume next batch of thread references, set nextthread. */
1732 if (result_count
>= 1)
1733 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1735 while (result_count
--)
1736 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1743 remote_newthread_step (threadref
*ref
, void *context
)
1747 ptid
= pid_to_ptid (threadref_to_int (ref
));
1749 if (!in_thread_list (ptid
))
1751 return 1; /* continue iterator */
1754 #define CRAZY_MAX_THREADS 1000
1757 remote_current_thread (ptid_t oldpid
)
1759 struct remote_state
*rs
= get_remote_state ();
1760 char *buf
= alloca (rs
->remote_packet_size
);
1763 getpkt (buf
, (rs
->remote_packet_size
), 0);
1764 if (buf
[0] == 'Q' && buf
[1] == 'C')
1765 return pid_to_ptid (strtol (&buf
[2], NULL
, 16));
1770 /* Find new threads for info threads command.
1771 * Original version, using John Metzler's thread protocol.
1775 remote_find_new_threads (void)
1777 remote_threadlist_iterator (remote_newthread_step
, 0,
1779 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1780 inferior_ptid
= remote_current_thread (inferior_ptid
);
1784 * Find all threads for info threads command.
1785 * Uses new thread protocol contributed by Cisco.
1786 * Falls back and attempts to use the older method (above)
1787 * if the target doesn't respond to the new method.
1791 remote_threads_info (void)
1793 struct remote_state
*rs
= get_remote_state ();
1794 char *buf
= alloca (rs
->remote_packet_size
);
1798 if (remote_desc
== 0) /* paranoia */
1799 error ("Command can only be used when connected to the remote target.");
1801 if (use_threadinfo_query
)
1803 putpkt ("qfThreadInfo");
1805 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1806 if (bufp
[0] != '\0') /* q packet recognized */
1808 while (*bufp
++ == 'm') /* reply contains one or more TID */
1812 tid
= strtol (bufp
, &bufp
, 16);
1813 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1814 add_thread (pid_to_ptid (tid
));
1816 while (*bufp
++ == ','); /* comma-separated list */
1817 putpkt ("qsThreadInfo");
1819 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1825 /* Else fall back to old method based on jmetzler protocol. */
1826 use_threadinfo_query
= 0;
1827 remote_find_new_threads ();
1832 * Collect a descriptive string about the given thread.
1833 * The target may say anything it wants to about the thread
1834 * (typically info about its blocked / runnable state, name, etc.).
1835 * This string will appear in the info threads display.
1837 * Optional: targets are not required to implement this function.
1841 remote_threads_extra_info (struct thread_info
*tp
)
1843 struct remote_state
*rs
= get_remote_state ();
1847 struct gdb_ext_thread_info threadinfo
;
1848 static char display_buf
[100]; /* arbitrary... */
1849 char *bufp
= alloca (rs
->remote_packet_size
);
1850 int n
= 0; /* position in display_buf */
1852 if (remote_desc
== 0) /* paranoia */
1853 internal_error (__FILE__
, __LINE__
,
1854 "remote_threads_extra_info");
1856 if (use_threadextra_query
)
1858 sprintf (bufp
, "qThreadExtraInfo,%x", PIDGET (tp
->ptid
));
1860 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1863 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1864 result
= hex2bin (bufp
, display_buf
, n
);
1865 display_buf
[result
] = '\0';
1870 /* If the above query fails, fall back to the old method. */
1871 use_threadextra_query
= 0;
1872 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1873 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1874 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1875 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1876 if (threadinfo
.active
)
1878 if (*threadinfo
.shortname
)
1879 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1880 if (*threadinfo
.display
)
1881 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1882 if (*threadinfo
.more_display
)
1883 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1884 threadinfo
.more_display
);
1888 /* for purely cosmetic reasons, clear up trailing commas */
1889 if (',' == display_buf
[n
-1])
1890 display_buf
[n
-1] = ' ';
1899 /* Restart the remote side; this is an extended protocol operation. */
1902 extended_remote_restart (void)
1904 struct remote_state
*rs
= get_remote_state ();
1905 char *buf
= alloca (rs
->remote_packet_size
);
1907 /* Send the restart command; for reasons I don't understand the
1908 remote side really expects a number after the "R". */
1910 sprintf (&buf
[1], "%x", 0);
1913 /* Now query for status so this looks just like we restarted
1914 gdbserver from scratch. */
1916 getpkt (buf
, (rs
->remote_packet_size
), 0);
1919 /* Clean up connection to a remote debugger. */
1922 remote_close (int quitting
)
1925 serial_close (remote_desc
);
1929 /* Query the remote side for the text, data and bss offsets. */
1934 struct remote_state
*rs
= get_remote_state ();
1935 char *buf
= alloca (rs
->remote_packet_size
);
1938 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1939 struct section_offsets
*offs
;
1941 putpkt ("qOffsets");
1943 getpkt (buf
, (rs
->remote_packet_size
), 0);
1945 if (buf
[0] == '\000')
1946 return; /* Return silently. Stub doesn't support
1950 warning ("Remote failure reply: %s", buf
);
1954 /* Pick up each field in turn. This used to be done with scanf, but
1955 scanf will make trouble if CORE_ADDR size doesn't match
1956 conversion directives correctly. The following code will work
1957 with any size of CORE_ADDR. */
1958 text_addr
= data_addr
= bss_addr
= 0;
1962 if (strncmp (ptr
, "Text=", 5) == 0)
1965 /* Don't use strtol, could lose on big values. */
1966 while (*ptr
&& *ptr
!= ';')
1967 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1972 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1975 while (*ptr
&& *ptr
!= ';')
1976 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1981 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1984 while (*ptr
&& *ptr
!= ';')
1985 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1991 error ("Malformed response to offset query, %s", buf
);
1993 if (symfile_objfile
== NULL
)
1996 offs
= ((struct section_offsets
*)
1997 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
1998 memcpy (offs
, symfile_objfile
->section_offsets
,
1999 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2001 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2003 /* This is a temporary kludge to force data and bss to use the same offsets
2004 because that's what nlmconv does now. The real solution requires changes
2005 to the stub and remote.c that I don't have time to do right now. */
2007 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2008 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2010 objfile_relocate (symfile_objfile
, offs
);
2014 * Cisco version of section offsets:
2016 * Instead of having GDB query the target for the section offsets,
2017 * Cisco lets the target volunteer the information! It's also in
2018 * a different format, so here are the functions that will decode
2019 * a section offset packet from a Cisco target.
2023 * Function: remote_cisco_section_offsets
2025 * Returns: zero for success, non-zero for failure
2029 remote_cisco_section_offsets (bfd_vma text_addr
,
2032 bfd_signed_vma
*text_offs
,
2033 bfd_signed_vma
*data_offs
,
2034 bfd_signed_vma
*bss_offs
)
2036 bfd_vma text_base
, data_base
, bss_base
;
2037 struct minimal_symbol
*start
;
2042 if (symfile_objfile
== NULL
)
2043 return -1; /* no can do nothin' */
2045 start
= lookup_minimal_symbol ("_start", NULL
, NULL
);
2047 return -1; /* Can't find "_start" symbol */
2049 data_base
= bss_base
= 0;
2050 text_base
= SYMBOL_VALUE_ADDRESS (start
);
2052 abfd
= symfile_objfile
->obfd
;
2053 for (sect
= abfd
->sections
;
2057 const char *p
= bfd_get_section_name (abfd
, sect
);
2059 if (strcmp (p
+ len
- 4, "data") == 0) /* ends in "data" */
2060 if (data_base
== 0 ||
2061 data_base
> bfd_get_section_vma (abfd
, sect
))
2062 data_base
= bfd_get_section_vma (abfd
, sect
);
2063 if (strcmp (p
+ len
- 3, "bss") == 0) /* ends in "bss" */
2064 if (bss_base
== 0 ||
2065 bss_base
> bfd_get_section_vma (abfd
, sect
))
2066 bss_base
= bfd_get_section_vma (abfd
, sect
);
2068 *text_offs
= text_addr
- text_base
;
2069 *data_offs
= data_addr
- data_base
;
2070 *bss_offs
= bss_addr
- bss_base
;
2075 sprintf (tmp
, "VMA: text = 0x");
2076 sprintf_vma (tmp
+ strlen (tmp
), text_addr
);
2077 sprintf (tmp
+ strlen (tmp
), " data = 0x");
2078 sprintf_vma (tmp
+ strlen (tmp
), data_addr
);
2079 sprintf (tmp
+ strlen (tmp
), " bss = 0x");
2080 sprintf_vma (tmp
+ strlen (tmp
), bss_addr
);
2081 fputs_filtered (tmp
, gdb_stdlog
);
2082 fprintf_filtered (gdb_stdlog
,
2083 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
2084 paddr_nz (*text_offs
),
2085 paddr_nz (*data_offs
),
2086 paddr_nz (*bss_offs
));
2093 * Function: remote_cisco_objfile_relocate
2095 * Relocate the symbol file for a remote target.
2099 remote_cisco_objfile_relocate (bfd_signed_vma text_off
, bfd_signed_vma data_off
,
2100 bfd_signed_vma bss_off
)
2102 struct section_offsets
*offs
;
2104 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
2106 /* FIXME: This code assumes gdb-stabs.h is being used; it's
2107 broken for xcoff, dwarf, sdb-coff, etc. But there is no
2108 simple canonical representation for this stuff. */
2110 offs
= (struct section_offsets
*)
2111 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2112 memcpy (offs
, symfile_objfile
->section_offsets
,
2113 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2115 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_off
;
2116 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_off
;
2117 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = bss_off
;
2119 /* First call the standard objfile_relocate. */
2120 objfile_relocate (symfile_objfile
, offs
);
2122 /* Now we need to fix up the section entries already attached to
2123 the exec target. These entries will control memory transfers
2124 from the exec file. */
2126 exec_set_section_offsets (text_off
, data_off
, bss_off
);
2130 /* Stub for catch_errors. */
2133 remote_start_remote_dummy (struct ui_out
*uiout
, void *dummy
)
2135 start_remote (); /* Initialize gdb process mechanisms */
2136 /* NOTE: Return something >=0. A -ve value is reserved for
2137 catch_exceptions. */
2142 remote_start_remote (struct ui_out
*uiout
, void *dummy
)
2144 immediate_quit
++; /* Allow user to interrupt it */
2146 /* Ack any packet which the remote side has already sent. */
2147 serial_write (remote_desc
, "+", 1);
2149 /* Let the stub know that we want it to return the thread. */
2152 inferior_ptid
= remote_current_thread (inferior_ptid
);
2154 get_offsets (); /* Get text, data & bss offsets */
2156 putpkt ("?"); /* initiate a query from remote machine */
2159 /* NOTE: See comment above in remote_start_remote_dummy(). This
2160 function returns something >=0. */
2161 return remote_start_remote_dummy (uiout
, dummy
);
2164 /* Open a connection to a remote debugger.
2165 NAME is the filename used for communication. */
2168 remote_open (char *name
, int from_tty
)
2170 remote_open_1 (name
, from_tty
, &remote_ops
, 0, 0);
2173 /* Just like remote_open, but with asynchronous support. */
2175 remote_async_open (char *name
, int from_tty
)
2177 remote_open_1 (name
, from_tty
, &remote_async_ops
, 0, 1);
2180 /* Open a connection to a remote debugger using the extended
2181 remote gdb protocol. NAME is the filename used for communication. */
2184 extended_remote_open (char *name
, int from_tty
)
2186 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */,
2190 /* Just like extended_remote_open, but with asynchronous support. */
2192 extended_remote_async_open (char *name
, int from_tty
)
2194 remote_open_1 (name
, from_tty
, &extended_async_remote_ops
,
2195 1 /*extended_p */, 1 /* async_p */);
2198 /* Generic code for opening a connection to a remote target. */
2201 init_all_packet_configs (void)
2204 update_packet_config (&remote_protocol_e
);
2205 update_packet_config (&remote_protocol_E
);
2206 update_packet_config (&remote_protocol_P
);
2207 update_packet_config (&remote_protocol_qSymbol
);
2208 update_packet_config (&remote_protocol_vcont
);
2209 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2210 update_packet_config (&remote_protocol_Z
[i
]);
2211 /* Force remote_write_bytes to check whether target supports binary
2213 update_packet_config (&remote_protocol_binary_download
);
2216 /* Symbol look-up. */
2219 remote_check_symbols (struct objfile
*objfile
)
2221 struct remote_state
*rs
= get_remote_state ();
2222 char *msg
, *reply
, *tmp
;
2223 struct minimal_symbol
*sym
;
2226 if (remote_protocol_qSymbol
.support
== PACKET_DISABLE
)
2229 msg
= alloca (rs
->remote_packet_size
);
2230 reply
= alloca (rs
->remote_packet_size
);
2232 /* Invite target to request symbol lookups. */
2234 putpkt ("qSymbol::");
2235 getpkt (reply
, (rs
->remote_packet_size
), 0);
2236 packet_ok (reply
, &remote_protocol_qSymbol
);
2238 while (strncmp (reply
, "qSymbol:", 8) == 0)
2241 end
= hex2bin (tmp
, msg
, strlen (tmp
) / 2);
2243 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2245 sprintf (msg
, "qSymbol::%s", &reply
[8]);
2247 sprintf (msg
, "qSymbol:%s:%s",
2248 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2251 getpkt (reply
, (rs
->remote_packet_size
), 0);
2255 static struct serial
*
2256 remote_serial_open (char *name
)
2258 static int udp_warning
= 0;
2260 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2261 of in ser-tcp.c, because it is the remote protocol assuming that the
2262 serial connection is reliable and not the serial connection promising
2264 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2266 warning ("The remote protocol may be unreliable over UDP.");
2267 warning ("Some events may be lost, rendering further debugging "
2272 return serial_open (name
);
2276 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2277 int extended_p
, int async_p
)
2280 struct remote_state
*rs
= get_remote_state ();
2282 error ("To open a remote debug connection, you need to specify what\n"
2283 "serial device is attached to the remote system\n"
2284 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2286 /* See FIXME above */
2288 wait_forever_enabled_p
= 1;
2290 target_preopen (from_tty
);
2292 unpush_target (target
);
2294 remote_desc
= remote_serial_open (name
);
2296 perror_with_name (name
);
2298 if (baud_rate
!= -1)
2300 if (serial_setbaudrate (remote_desc
, baud_rate
))
2302 /* The requested speed could not be set. Error out to
2303 top level after closing remote_desc. Take care to
2304 set remote_desc to NULL to avoid closing remote_desc
2306 serial_close (remote_desc
);
2308 perror_with_name (name
);
2312 serial_raw (remote_desc
);
2314 /* If there is something sitting in the buffer we might take it as a
2315 response to a command, which would be bad. */
2316 serial_flush_input (remote_desc
);
2320 puts_filtered ("Remote debugging using ");
2321 puts_filtered (name
);
2322 puts_filtered ("\n");
2324 push_target (target
); /* Switch to using remote target now */
2326 init_all_packet_configs ();
2328 general_thread
= -2;
2329 continue_thread
= -2;
2331 /* Probe for ability to use "ThreadInfo" query, as required. */
2332 use_threadinfo_query
= 1;
2333 use_threadextra_query
= 1;
2335 /* Without this, some commands which require an active target (such
2336 as kill) won't work. This variable serves (at least) double duty
2337 as both the pid of the target process (if it has such), and as a
2338 flag indicating that a target is active. These functions should
2339 be split out into seperate variables, especially since GDB will
2340 someday have a notion of debugging several processes. */
2342 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2346 /* With this target we start out by owning the terminal. */
2347 remote_async_terminal_ours_p
= 1;
2349 /* FIXME: cagney/1999-09-23: During the initial connection it is
2350 assumed that the target is already ready and able to respond to
2351 requests. Unfortunately remote_start_remote() eventually calls
2352 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2353 around this. Eventually a mechanism that allows
2354 wait_for_inferior() to expect/get timeouts will be
2356 wait_forever_enabled_p
= 0;
2359 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2360 /* First delete any symbols previously loaded from shared libraries. */
2361 no_shared_libraries (NULL
, 0);
2364 /* Start the remote connection. If error() or QUIT, discard this
2365 target (we'd otherwise be in an inconsistent state) and then
2366 propogate the error on up the exception chain. This ensures that
2367 the caller doesn't stumble along blindly assuming that the
2368 function succeeded. The CLI doesn't have this problem but other
2369 UI's, such as MI do.
2371 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2372 this function should return an error indication letting the
2373 caller restore the previous state. Unfortunately the command
2374 ``target remote'' is directly wired to this function making that
2375 impossible. On a positive note, the CLI side of this problem has
2376 been fixed - the function set_cmd_context() makes it possible for
2377 all the ``target ....'' commands to share a common callback
2378 function. See cli-dump.c. */
2379 ex
= catch_exceptions (uiout
,
2380 remote_start_remote
, NULL
,
2381 "Couldn't establish connection to remote"
2388 wait_forever_enabled_p
= 1;
2389 throw_exception (ex
);
2393 wait_forever_enabled_p
= 1;
2397 /* Tell the remote that we are using the extended protocol. */
2398 char *buf
= alloca (rs
->remote_packet_size
);
2400 getpkt (buf
, (rs
->remote_packet_size
), 0);
2402 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2403 /* FIXME: need a master target_open vector from which all
2404 remote_opens can be called, so that stuff like this can
2405 go there. Failing that, the following code must be copied
2406 to the open function for any remote target that wants to
2407 support svr4 shared libraries. */
2409 /* Set up to detect and load shared libraries. */
2410 if (exec_bfd
) /* No use without an exec file. */
2412 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2413 remote_check_symbols (symfile_objfile
);
2418 /* This takes a program previously attached to and detaches it. After
2419 this is done, GDB can be used to debug some other program. We
2420 better not have left any breakpoints in the target program or it'll
2421 die when it hits one. */
2424 remote_detach (char *args
, int from_tty
)
2426 struct remote_state
*rs
= get_remote_state ();
2427 char *buf
= alloca (rs
->remote_packet_size
);
2430 error ("Argument given to \"detach\" when remotely debugging.");
2432 /* Tell the remote target to detach. */
2434 remote_send (buf
, (rs
->remote_packet_size
));
2436 /* Unregister the file descriptor from the event loop. */
2437 if (target_is_async_p ())
2438 serial_async (remote_desc
, NULL
, 0);
2440 target_mourn_inferior ();
2442 puts_filtered ("Ending remote debugging.\n");
2445 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
2448 remote_disconnect (char *args
, int from_tty
)
2450 struct remote_state
*rs
= get_remote_state ();
2451 char *buf
= alloca (rs
->remote_packet_size
);
2454 error ("Argument given to \"detach\" when remotely debugging.");
2456 /* Unregister the file descriptor from the event loop. */
2457 if (target_is_async_p ())
2458 serial_async (remote_desc
, NULL
, 0);
2460 target_mourn_inferior ();
2462 puts_filtered ("Ending remote debugging.\n");
2465 /* Convert hex digit A to a number. */
2470 if (a
>= '0' && a
<= '9')
2472 else if (a
>= 'a' && a
<= 'f')
2473 return a
- 'a' + 10;
2474 else if (a
>= 'A' && a
<= 'F')
2475 return a
- 'A' + 10;
2477 error ("Reply contains invalid hex digit %d", a
);
2481 hex2bin (const char *hex
, char *bin
, int count
)
2485 for (i
= 0; i
< count
; i
++)
2487 if (hex
[0] == 0 || hex
[1] == 0)
2489 /* Hex string is short, or of uneven length.
2490 Return the count that has been converted so far. */
2493 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2499 /* Convert number NIB to a hex digit. */
2507 return 'a' + nib
- 10;
2511 bin2hex (const char *bin
, char *hex
, int count
)
2514 /* May use a length, or a nul-terminated string as input. */
2516 count
= strlen (bin
);
2518 for (i
= 0; i
< count
; i
++)
2520 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2521 *hex
++ = tohex (*bin
++ & 0xf);
2527 /* Check for the availability of vCont. This function should also check
2531 remote_vcont_probe (struct remote_state
*rs
, char *buf
)
2533 strcpy (buf
, "vCont?");
2535 getpkt (buf
, rs
->remote_packet_size
, 0);
2537 /* Make sure that the features we assume are supported. */
2538 if (strncmp (buf
, "vCont", 5) == 0)
2541 int support_s
, support_S
, support_c
, support_C
;
2547 while (p
&& *p
== ';')
2550 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2552 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2554 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2556 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2559 p
= strchr (p
, ';');
2562 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
2563 BUF will make packet_ok disable the packet. */
2564 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
2568 packet_ok (buf
, &remote_protocol_vcont
);
2571 /* Resume the remote inferior by using a "vCont" packet. The thread
2572 to be resumed is PTID; STEP and SIGGNAL indicate whether the
2573 resumed thread should be single-stepped and/or signalled. If PTID's
2574 PID is -1, then all threads are resumed; the thread to be stepped and/or
2575 signalled is given in the global INFERIOR_PTID. This function returns
2576 non-zero iff it resumes the inferior.
2578 This function issues a strict subset of all possible vCont commands at the
2582 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2584 struct remote_state
*rs
= get_remote_state ();
2585 int pid
= PIDGET (ptid
);
2587 struct cleanup
*old_cleanup
;
2589 buf
= xmalloc (rs
->remote_packet_size
);
2590 old_cleanup
= make_cleanup (xfree
, buf
);
2592 if (remote_protocol_vcont
.support
== PACKET_SUPPORT_UNKNOWN
)
2593 remote_vcont_probe (rs
, buf
);
2595 if (remote_protocol_vcont
.support
== PACKET_DISABLE
)
2597 do_cleanups (old_cleanup
);
2601 /* If we could generate a wider range of packets, we'd have to worry
2602 about overflowing BUF. Should there be a generic
2603 "multi-part-packet" packet? */
2605 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
)
2607 /* MAGIC_NULL_PTID means that we don't have any active threads, so we
2608 don't have any PID numbers the inferior will understand. Make sure
2609 to only send forms that do not specify a PID. */
2610 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2611 sprintf (buf
, "vCont;S%02x", siggnal
);
2613 sprintf (buf
, "vCont;s");
2614 else if (siggnal
!= TARGET_SIGNAL_0
)
2615 sprintf (buf
, "vCont;C%02x", siggnal
);
2617 sprintf (buf
, "vCont;c");
2621 /* Resume all threads, with preference for INFERIOR_PTID. */
2622 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2623 sprintf (buf
, "vCont;S%02x:%x;c", siggnal
, PIDGET (inferior_ptid
));
2625 sprintf (buf
, "vCont;s:%x;c", PIDGET (inferior_ptid
));
2626 else if (siggnal
!= TARGET_SIGNAL_0
)
2627 sprintf (buf
, "vCont;C%02x:%x;c", siggnal
, PIDGET (inferior_ptid
));
2629 sprintf (buf
, "vCont;c");
2633 /* Scheduler locking; resume only PTID. */
2634 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2635 sprintf (buf
, "vCont;S%02x:%x", siggnal
, pid
);
2637 sprintf (buf
, "vCont;s:%x", pid
);
2638 else if (siggnal
!= TARGET_SIGNAL_0
)
2639 sprintf (buf
, "vCont;C%02x:%x", siggnal
, pid
);
2641 sprintf (buf
, "vCont;c:%x", pid
);
2646 do_cleanups (old_cleanup
);
2651 /* Tell the remote machine to resume. */
2653 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2655 static int last_sent_step
;
2658 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2660 struct remote_state
*rs
= get_remote_state ();
2661 char *buf
= alloca (rs
->remote_packet_size
);
2662 int pid
= PIDGET (ptid
);
2665 last_sent_signal
= siggnal
;
2666 last_sent_step
= step
;
2668 /* A hook for when we need to do something at the last moment before
2670 if (target_resume_hook
)
2671 (*target_resume_hook
) ();
2673 /* The vCont packet doesn't need to specify threads via Hc. */
2674 if (remote_vcont_resume (ptid
, step
, siggnal
))
2677 /* All other supported resume packets do use Hc, so call set_thread. */
2679 set_thread (0, 0); /* run any thread */
2681 set_thread (pid
, 0); /* run this thread */
2683 /* The s/S/c/C packets do not return status. So if the target does
2684 not support the S or C packets, the debug agent returns an empty
2685 string which is detected in remote_wait(). This protocol defect
2686 is fixed in the e/E packets. */
2688 if (step
&& step_range_end
)
2690 /* If the target does not support the 'E' packet, we try the 'S'
2691 packet. Ideally we would fall back to the 'e' packet if that
2692 too is not supported. But that would require another copy of
2693 the code to issue the 'e' packet (and fall back to 's' if not
2694 supported) in remote_wait(). */
2696 if (siggnal
!= TARGET_SIGNAL_0
)
2698 if (remote_protocol_E
.support
!= PACKET_DISABLE
)
2702 *p
++ = tohex (((int) siggnal
>> 4) & 0xf);
2703 *p
++ = tohex (((int) siggnal
) & 0xf);
2705 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2707 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2711 getpkt (buf
, (rs
->remote_packet_size
), 0);
2713 if (packet_ok (buf
, &remote_protocol_E
) == PACKET_OK
)
2719 if (remote_protocol_e
.support
!= PACKET_DISABLE
)
2723 p
+= hexnumstr (p
, (ULONGEST
) step_range_start
);
2725 p
+= hexnumstr (p
, (ULONGEST
) step_range_end
);
2729 getpkt (buf
, (rs
->remote_packet_size
), 0);
2731 if (packet_ok (buf
, &remote_protocol_e
) == PACKET_OK
)
2737 if (siggnal
!= TARGET_SIGNAL_0
)
2739 buf
[0] = step
? 'S' : 'C';
2740 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2741 buf
[2] = tohex (((int) siggnal
) & 0xf);
2745 strcpy (buf
, step
? "s" : "c");
2750 /* Same as remote_resume, but with async support. */
2752 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2754 remote_resume (ptid
, step
, siggnal
);
2756 /* We are about to start executing the inferior, let's register it
2757 with the event loop. NOTE: this is the one place where all the
2758 execution commands end up. We could alternatively do this in each
2759 of the execution commands in infcmd.c.*/
2760 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2761 into infcmd.c in order to allow inferior function calls to work
2762 NOT asynchronously. */
2763 if (event_loop_p
&& target_can_async_p ())
2764 target_async (inferior_event_handler
, 0);
2765 /* Tell the world that the target is now executing. */
2766 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2767 this? Instead, should the client of target just assume (for
2768 async targets) that the target is going to start executing? Is
2769 this information already found in the continuation block? */
2770 if (target_is_async_p ())
2771 target_executing
= 1;
2775 /* Set up the signal handler for SIGINT, while the target is
2776 executing, ovewriting the 'regular' SIGINT signal handler. */
2778 initialize_sigint_signal_handler (void)
2780 sigint_remote_token
=
2781 create_async_signal_handler (async_remote_interrupt
, NULL
);
2782 signal (SIGINT
, handle_remote_sigint
);
2785 /* Signal handler for SIGINT, while the target is executing. */
2787 handle_remote_sigint (int sig
)
2789 signal (sig
, handle_remote_sigint_twice
);
2790 sigint_remote_twice_token
=
2791 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2792 mark_async_signal_handler_wrapper (sigint_remote_token
);
2795 /* Signal handler for SIGINT, installed after SIGINT has already been
2796 sent once. It will take effect the second time that the user sends
2799 handle_remote_sigint_twice (int sig
)
2801 signal (sig
, handle_sigint
);
2802 sigint_remote_twice_token
=
2803 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2804 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2807 /* Perform the real interruption of the target execution, in response
2810 async_remote_interrupt (gdb_client_data arg
)
2813 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2818 /* Perform interrupt, if the first attempt did not succeed. Just give
2819 up on the target alltogether. */
2821 async_remote_interrupt_twice (gdb_client_data arg
)
2824 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2825 /* Do something only if the target was not killed by the previous
2827 if (target_executing
)
2830 signal (SIGINT
, handle_remote_sigint
);
2834 /* Reinstall the usual SIGINT handlers, after the target has
2837 cleanup_sigint_signal_handler (void *dummy
)
2839 signal (SIGINT
, handle_sigint
);
2840 if (sigint_remote_twice_token
)
2841 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2842 if (sigint_remote_token
)
2843 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2846 /* Send ^C to target to halt it. Target will respond, and send us a
2848 static void (*ofunc
) (int);
2850 /* The command line interface's stop routine. This function is installed
2851 as a signal handler for SIGINT. The first time a user requests a
2852 stop, we call remote_stop to send a break or ^C. If there is no
2853 response from the target (it didn't stop when the user requested it),
2854 we ask the user if he'd like to detach from the target. */
2856 remote_interrupt (int signo
)
2858 /* If this doesn't work, try more severe steps. */
2859 signal (signo
, remote_interrupt_twice
);
2862 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2867 /* The user typed ^C twice. */
2870 remote_interrupt_twice (int signo
)
2872 signal (signo
, ofunc
);
2874 signal (signo
, remote_interrupt
);
2877 /* This is the generic stop called via the target vector. When a target
2878 interrupt is requested, either by the command line or the GUI, we
2879 will eventually end up here. */
2883 /* Send a break or a ^C, depending on user preference. */
2885 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2888 serial_send_break (remote_desc
);
2890 serial_write (remote_desc
, "\003", 1);
2893 /* Ask the user what to do when an interrupt is received. */
2896 interrupt_query (void)
2898 target_terminal_ours ();
2900 if (query ("Interrupted while waiting for the program.\n\
2901 Give up (and stop debugging it)? "))
2903 target_mourn_inferior ();
2904 throw_exception (RETURN_QUIT
);
2907 target_terminal_inferior ();
2910 /* Enable/disable target terminal ownership. Most targets can use
2911 terminal groups to control terminal ownership. Remote targets are
2912 different in that explicit transfer of ownership to/from GDB/target
2916 remote_async_terminal_inferior (void)
2918 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2919 sync_execution here. This function should only be called when
2920 GDB is resuming the inferior in the forground. A background
2921 resume (``run&'') should leave GDB in control of the terminal and
2922 consequently should not call this code. */
2923 if (!sync_execution
)
2925 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2926 calls target_terminal_*() idenpotent. The event-loop GDB talking
2927 to an asynchronous target with a synchronous command calls this
2928 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2929 stops trying to transfer the terminal to the target when it
2930 shouldn't this guard can go away. */
2931 if (!remote_async_terminal_ours_p
)
2933 delete_file_handler (input_fd
);
2934 remote_async_terminal_ours_p
= 0;
2935 initialize_sigint_signal_handler ();
2936 /* NOTE: At this point we could also register our selves as the
2937 recipient of all input. Any characters typed could then be
2938 passed on down to the target. */
2942 remote_async_terminal_ours (void)
2944 /* See FIXME in remote_async_terminal_inferior. */
2945 if (!sync_execution
)
2947 /* See FIXME in remote_async_terminal_inferior. */
2948 if (remote_async_terminal_ours_p
)
2950 cleanup_sigint_signal_handler (NULL
);
2951 add_file_handler (input_fd
, stdin_event_handler
, 0);
2952 remote_async_terminal_ours_p
= 1;
2955 /* If nonzero, ignore the next kill. */
2960 remote_console_output (char *msg
)
2964 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2967 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2970 fputs_unfiltered (tb
, gdb_stdtarg
);
2972 gdb_flush (gdb_stdtarg
);
2975 /* Wait until the remote machine stops, then return,
2976 storing status in STATUS just as `wait' would.
2977 Returns "pid", which in the case of a multi-threaded
2978 remote OS, is the thread-id. */
2981 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2983 struct remote_state
*rs
= get_remote_state ();
2984 unsigned char *buf
= alloca (rs
->remote_packet_size
);
2985 ULONGEST thread_num
= -1;
2988 status
->kind
= TARGET_WAITKIND_EXITED
;
2989 status
->value
.integer
= 0;
2995 ofunc
= signal (SIGINT
, remote_interrupt
);
2996 getpkt (buf
, (rs
->remote_packet_size
), 1);
2997 signal (SIGINT
, ofunc
);
2999 /* This is a hook for when we need to do something (perhaps the
3000 collection of trace data) every time the target stops. */
3001 if (target_wait_loop_hook
)
3002 (*target_wait_loop_hook
) ();
3004 remote_stopped_by_watchpoint_p
= 0;
3008 case 'E': /* Error of some sort */
3009 warning ("Remote failure reply: %s", buf
);
3011 case 'F': /* File-I/O request */
3012 remote_fileio_request (buf
);
3014 case 'T': /* Status with PC, SP, FP, ... */
3017 char regs
[MAX_REGISTER_SIZE
];
3019 /* Expedited reply, containing Signal, {regno, reg} repeat */
3020 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3022 n... = register number
3023 r... = register contents
3025 p
= &buf
[3]; /* after Txx */
3034 /* If the packet contains a register number save it in pnum
3035 and set p1 to point to the character following it.
3036 Otherwise p1 points to p. */
3038 /* If this packet is an awatch packet, don't parse the 'a'
3039 as a register number. */
3041 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
3043 /* Read the ``P'' register number. */
3044 pnum
= strtol (p
, &p_temp
, 16);
3045 p1
= (unsigned char *) p_temp
;
3050 if (p1
== p
) /* No register number present here */
3052 p1
= (unsigned char *) strchr (p
, ':');
3054 warning ("Malformed packet(a) (missing colon): %s\n\
3057 if (strncmp (p
, "thread", p1
- p
) == 0)
3059 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3060 record_currthread (thread_num
);
3061 p
= (unsigned char *) p_temp
;
3063 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3064 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3065 || (strncmp (p
, "awatch", p1
- p
) == 0))
3067 remote_stopped_by_watchpoint_p
= 1;
3068 p
= unpack_varlen_hex (++p1
, &addr
);
3069 remote_watch_data_address
= (CORE_ADDR
)addr
;
3073 /* Silently skip unknown optional info. */
3074 p_temp
= strchr (p1
+ 1, ';');
3076 p
= (unsigned char *) p_temp
;
3081 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3085 error ("Malformed packet(b) (missing colon): %s\nPacket: '%s'\n",
3089 error ("Remote sent bad register number %s: %s\nPacket: '%s'\n",
3090 phex_nz (pnum
, 0), p
, buf
);
3092 fieldsize
= hex2bin (p
, regs
, DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
));
3094 if (fieldsize
< DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
))
3095 warning ("Remote reply is too short: %s", buf
);
3096 supply_register (reg
->regnum
, regs
);
3100 error ("Remote register badly formatted: %s\nhere: %s", buf
, p
);
3104 case 'S': /* Old style status, just signal only */
3105 status
->kind
= TARGET_WAITKIND_STOPPED
;
3106 status
->value
.sig
= (enum target_signal
)
3107 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3111 /* Export Cisco kernel mode as a convenience variable
3112 (so that it can be used in the GDB prompt if desired). */
3114 if (cisco_kernel_mode
== 1)
3115 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3116 value_from_string ("PDEBUG-"));
3117 cisco_kernel_mode
= 0;
3118 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3119 record_currthread (thread_num
);
3121 else if (buf
[3] == 'k')
3123 /* Export Cisco kernel mode as a convenience variable
3124 (so that it can be used in the GDB prompt if desired). */
3126 if (cisco_kernel_mode
== 1)
3127 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3128 value_from_string ("KDEBUG-"));
3129 cisco_kernel_mode
= 1;
3132 case 'N': /* Cisco special: status and offsets */
3134 bfd_vma text_addr
, data_addr
, bss_addr
;
3135 bfd_signed_vma text_off
, data_off
, bss_off
;
3138 status
->kind
= TARGET_WAITKIND_STOPPED
;
3139 status
->value
.sig
= (enum target_signal
)
3140 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3142 if (symfile_objfile
== NULL
)
3144 warning ("Relocation packet received with no symbol file. \
3149 /* Relocate object file. Buffer format is NAATT;DD;BB
3150 * where AA is the signal number, TT is the new text
3151 * address, DD * is the new data address, and BB is the
3152 * new bss address. */
3155 text_addr
= strtoul (p
, (char **) &p1
, 16);
3156 if (p1
== p
|| *p1
!= ';')
3157 warning ("Malformed relocation packet: Packet '%s'", buf
);
3159 data_addr
= strtoul (p
, (char **) &p1
, 16);
3160 if (p1
== p
|| *p1
!= ';')
3161 warning ("Malformed relocation packet: Packet '%s'", buf
);
3163 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3165 warning ("Malformed relocation packet: Packet '%s'", buf
);
3167 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3168 &text_off
, &data_off
, &bss_off
)
3170 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3171 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3175 case 'W': /* Target exited */
3177 /* The remote process exited. */
3178 status
->kind
= TARGET_WAITKIND_EXITED
;
3179 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3183 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3184 status
->value
.sig
= (enum target_signal
)
3185 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3189 case 'O': /* Console output */
3190 remote_console_output (buf
+ 1);
3193 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3195 /* Zero length reply means that we tried 'S' or 'C' and
3196 the remote system doesn't support it. */
3197 target_terminal_ours_for_output ();
3199 ("Can't send signals to this remote system. %s not sent.\n",
3200 target_signal_to_name (last_sent_signal
));
3201 last_sent_signal
= TARGET_SIGNAL_0
;
3202 target_terminal_inferior ();
3204 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3205 putpkt ((char *) buf
);
3208 /* else fallthrough */
3210 warning ("Invalid remote reply: %s", buf
);
3215 if (thread_num
!= -1)
3217 return pid_to_ptid (thread_num
);
3219 return inferior_ptid
;
3222 /* Async version of remote_wait. */
3224 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3226 struct remote_state
*rs
= get_remote_state ();
3227 unsigned char *buf
= alloca (rs
->remote_packet_size
);
3228 ULONGEST thread_num
= -1;
3231 status
->kind
= TARGET_WAITKIND_EXITED
;
3232 status
->value
.integer
= 0;
3234 remote_stopped_by_watchpoint_p
= 0;
3240 if (!target_is_async_p ())
3241 ofunc
= signal (SIGINT
, remote_interrupt
);
3242 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3243 _never_ wait for ever -> test on target_is_async_p().
3244 However, before we do that we need to ensure that the caller
3245 knows how to take the target into/out of async mode. */
3246 getpkt (buf
, (rs
->remote_packet_size
), wait_forever_enabled_p
);
3247 if (!target_is_async_p ())
3248 signal (SIGINT
, ofunc
);
3250 /* This is a hook for when we need to do something (perhaps the
3251 collection of trace data) every time the target stops. */
3252 if (target_wait_loop_hook
)
3253 (*target_wait_loop_hook
) ();
3257 case 'E': /* Error of some sort */
3258 warning ("Remote failure reply: %s", buf
);
3260 case 'F': /* File-I/O request */
3261 remote_fileio_request (buf
);
3263 case 'T': /* Status with PC, SP, FP, ... */
3266 char regs
[MAX_REGISTER_SIZE
];
3268 /* Expedited reply, containing Signal, {regno, reg} repeat */
3269 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3271 n... = register number
3272 r... = register contents
3274 p
= &buf
[3]; /* after Txx */
3283 /* If the packet contains a register number, save it in pnum
3284 and set p1 to point to the character following it.
3285 Otherwise p1 points to p. */
3287 /* If this packet is an awatch packet, don't parse the 'a'
3288 as a register number. */
3290 if (!strncmp (p
, "awatch", strlen ("awatch")) != 0)
3292 /* Read the register number. */
3293 pnum
= strtol (p
, &p_temp
, 16);
3294 p1
= (unsigned char *) p_temp
;
3299 if (p1
== p
) /* No register number present here */
3301 p1
= (unsigned char *) strchr (p
, ':');
3303 error ("Malformed packet(a) (missing colon): %s\nPacket: '%s'\n",
3305 if (strncmp (p
, "thread", p1
- p
) == 0)
3307 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3308 record_currthread (thread_num
);
3309 p
= (unsigned char *) p_temp
;
3311 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3312 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3313 || (strncmp (p
, "awatch", p1
- p
) == 0))
3315 remote_stopped_by_watchpoint_p
= 1;
3316 p
= unpack_varlen_hex (++p1
, &addr
);
3317 remote_watch_data_address
= (CORE_ADDR
)addr
;
3321 /* Silently skip unknown optional info. */
3322 p_temp
= (unsigned char *) strchr (p1
+ 1, ';');
3330 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3333 error ("Malformed packet(b) (missing colon): %s\nPacket: '%s'\n",
3337 error ("Remote sent bad register number %ld: %s\nPacket: '%s'\n",
3340 fieldsize
= hex2bin (p
, regs
, DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
));
3342 if (fieldsize
< DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
))
3343 warning ("Remote reply is too short: %s", buf
);
3344 supply_register (reg
->regnum
, regs
);
3348 error ("Remote register badly formatted: %s\nhere: %s",
3353 case 'S': /* Old style status, just signal only */
3354 status
->kind
= TARGET_WAITKIND_STOPPED
;
3355 status
->value
.sig
= (enum target_signal
)
3356 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3360 /* Export Cisco kernel mode as a convenience variable
3361 (so that it can be used in the GDB prompt if desired). */
3363 if (cisco_kernel_mode
== 1)
3364 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3365 value_from_string ("PDEBUG-"));
3366 cisco_kernel_mode
= 0;
3367 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3368 record_currthread (thread_num
);
3370 else if (buf
[3] == 'k')
3372 /* Export Cisco kernel mode as a convenience variable
3373 (so that it can be used in the GDB prompt if desired). */
3375 if (cisco_kernel_mode
== 1)
3376 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
3377 value_from_string ("KDEBUG-"));
3378 cisco_kernel_mode
= 1;
3381 case 'N': /* Cisco special: status and offsets */
3383 bfd_vma text_addr
, data_addr
, bss_addr
;
3384 bfd_signed_vma text_off
, data_off
, bss_off
;
3387 status
->kind
= TARGET_WAITKIND_STOPPED
;
3388 status
->value
.sig
= (enum target_signal
)
3389 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3391 if (symfile_objfile
== NULL
)
3393 warning ("Relocation packet recieved with no symbol file. \
3398 /* Relocate object file. Buffer format is NAATT;DD;BB
3399 * where AA is the signal number, TT is the new text
3400 * address, DD * is the new data address, and BB is the
3401 * new bss address. */
3404 text_addr
= strtoul (p
, (char **) &p1
, 16);
3405 if (p1
== p
|| *p1
!= ';')
3406 warning ("Malformed relocation packet: Packet '%s'", buf
);
3408 data_addr
= strtoul (p
, (char **) &p1
, 16);
3409 if (p1
== p
|| *p1
!= ';')
3410 warning ("Malformed relocation packet: Packet '%s'", buf
);
3412 bss_addr
= strtoul (p
, (char **) &p1
, 16);
3414 warning ("Malformed relocation packet: Packet '%s'", buf
);
3416 if (remote_cisco_section_offsets (text_addr
, data_addr
, bss_addr
,
3417 &text_off
, &data_off
, &bss_off
)
3419 if (text_off
!= 0 || data_off
!= 0 || bss_off
!= 0)
3420 remote_cisco_objfile_relocate (text_off
, data_off
, bss_off
);
3424 case 'W': /* Target exited */
3426 /* The remote process exited. */
3427 status
->kind
= TARGET_WAITKIND_EXITED
;
3428 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3432 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3433 status
->value
.sig
= (enum target_signal
)
3434 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3438 case 'O': /* Console output */
3439 remote_console_output (buf
+ 1);
3440 /* Return immediately to the event loop. The event loop will
3441 still be waiting on the inferior afterwards. */
3442 status
->kind
= TARGET_WAITKIND_IGNORE
;
3445 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3447 /* Zero length reply means that we tried 'S' or 'C' and
3448 the remote system doesn't support it. */
3449 target_terminal_ours_for_output ();
3451 ("Can't send signals to this remote system. %s not sent.\n",
3452 target_signal_to_name (last_sent_signal
));
3453 last_sent_signal
= TARGET_SIGNAL_0
;
3454 target_terminal_inferior ();
3456 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3457 putpkt ((char *) buf
);
3460 /* else fallthrough */
3462 warning ("Invalid remote reply: %s", buf
);
3467 if (thread_num
!= -1)
3469 return pid_to_ptid (thread_num
);
3471 return inferior_ptid
;
3474 /* Number of bytes of registers this stub implements. */
3476 static int register_bytes_found
;
3478 /* Read the remote registers into the block REGS. */
3479 /* Currently we just read all the registers, so we don't use regnum. */
3482 remote_fetch_registers (int regnum
)
3484 struct remote_state
*rs
= get_remote_state ();
3485 char *buf
= alloca (rs
->remote_packet_size
);
3488 char *regs
= alloca (rs
->sizeof_g_packet
);
3490 set_thread (PIDGET (inferior_ptid
), 1);
3494 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3495 gdb_assert (reg
!= NULL
);
3496 if (!reg
->in_g_packet
)
3497 internal_error (__FILE__
, __LINE__
,
3498 "Attempt to fetch a non G-packet register when this "
3499 "remote.c does not support the p-packet.");
3503 remote_send (buf
, (rs
->remote_packet_size
));
3505 /* Save the size of the packet sent to us by the target. Its used
3506 as a heuristic when determining the max size of packets that the
3507 target can safely receive. */
3508 if ((rs
->actual_register_packet_size
) == 0)
3509 (rs
->actual_register_packet_size
) = strlen (buf
);
3511 /* Unimplemented registers read as all bits zero. */
3512 memset (regs
, 0, rs
->sizeof_g_packet
);
3514 /* We can get out of synch in various cases. If the first character
3515 in the buffer is not a hex character, assume that has happened
3516 and try to fetch another packet to read. */
3517 while ((buf
[0] < '0' || buf
[0] > '9')
3518 && (buf
[0] < 'a' || buf
[0] > 'f')
3519 && buf
[0] != 'x') /* New: unavailable register value */
3522 fprintf_unfiltered (gdb_stdlog
,
3523 "Bad register packet; fetching a new packet\n");
3524 getpkt (buf
, (rs
->remote_packet_size
), 0);
3527 /* Reply describes registers byte by byte, each byte encoded as two
3528 hex characters. Suck them all up, then supply them to the
3529 register cacheing/storage mechanism. */
3532 for (i
= 0; i
< rs
->sizeof_g_packet
; i
++)
3538 warning ("Remote reply is of odd length: %s", buf
);
3539 /* Don't change register_bytes_found in this case, and don't
3540 print a second warning. */
3543 if (p
[0] == 'x' && p
[1] == 'x')
3544 regs
[i
] = 0; /* 'x' */
3546 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3550 if (i
!= register_bytes_found
)
3552 register_bytes_found
= i
;
3553 if (REGISTER_BYTES_OK_P ()
3554 && !REGISTER_BYTES_OK (i
))
3555 warning ("Remote reply is too short: %s", buf
);
3561 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3563 struct packet_reg
*r
= &rs
->regs
[i
];
3566 if (r
->offset
* 2 >= strlen (buf
))
3567 /* A short packet that didn't include the register's
3568 value, this implies that the register is zero (and
3569 not that the register is unavailable). Supply that
3571 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3572 else if (buf
[r
->offset
* 2] == 'x')
3574 gdb_assert (r
->offset
* 2 < strlen (buf
));
3575 /* The register isn't available, mark it as such (at
3576 the same time setting the value to zero). */
3577 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3578 set_register_cached (i
, -1);
3581 regcache_raw_supply (current_regcache
, r
->regnum
,
3588 /* Prepare to store registers. Since we may send them all (using a
3589 'G' request), we have to read out the ones we don't want to change
3593 remote_prepare_to_store (void)
3595 struct remote_state
*rs
= get_remote_state ();
3597 char buf
[MAX_REGISTER_SIZE
];
3599 /* Make sure the entire registers array is valid. */
3600 switch (remote_protocol_P
.support
)
3602 case PACKET_DISABLE
:
3603 case PACKET_SUPPORT_UNKNOWN
:
3604 /* Make sure all the necessary registers are cached. */
3605 for (i
= 0; i
< NUM_REGS
; i
++)
3606 if (rs
->regs
[i
].in_g_packet
)
3607 regcache_raw_read (current_regcache
, rs
->regs
[i
].regnum
, buf
);
3614 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3615 packet was not recognized. */
3618 store_register_using_P (int regnum
)
3620 struct remote_state
*rs
= get_remote_state ();
3621 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3622 /* Try storing a single register. */
3623 char *buf
= alloca (rs
->remote_packet_size
);
3624 char regp
[MAX_REGISTER_SIZE
];
3628 sprintf (buf
, "P%s=", phex_nz (reg
->pnum
, 0));
3629 p
= buf
+ strlen (buf
);
3630 regcache_collect (reg
->regnum
, regp
);
3631 bin2hex (regp
, p
, DEPRECATED_REGISTER_RAW_SIZE (reg
->regnum
));
3632 remote_send (buf
, rs
->remote_packet_size
);
3634 return buf
[0] != '\0';
3638 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
3639 of the register cache buffer. FIXME: ignores errors. */
3642 remote_store_registers (int regnum
)
3644 struct remote_state
*rs
= get_remote_state ();
3650 set_thread (PIDGET (inferior_ptid
), 1);
3654 switch (remote_protocol_P
.support
)
3656 case PACKET_DISABLE
:
3659 if (store_register_using_P (regnum
))
3662 error ("Protocol error: P packet not recognized by stub");
3663 case PACKET_SUPPORT_UNKNOWN
:
3664 if (store_register_using_P (regnum
))
3666 /* The stub recognized the 'P' packet. Remember this. */
3667 remote_protocol_P
.support
= PACKET_ENABLE
;
3672 /* The stub does not support the 'P' packet. Use 'G'
3673 instead, and don't try using 'P' in the future (it
3674 will just waste our time). */
3675 remote_protocol_P
.support
= PACKET_DISABLE
;
3681 /* Extract all the registers in the regcache copying them into a
3685 regs
= alloca (rs
->sizeof_g_packet
);
3686 memset (regs
, rs
->sizeof_g_packet
, 0);
3687 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3689 struct packet_reg
*r
= &rs
->regs
[i
];
3691 regcache_collect (r
->regnum
, regs
+ r
->offset
);
3695 /* Command describes registers byte by byte,
3696 each byte encoded as two hex characters. */
3697 buf
= alloca (rs
->remote_packet_size
);
3700 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3701 bin2hex (regs
, p
, register_bytes_found
);
3702 remote_send (buf
, (rs
->remote_packet_size
));
3706 /* Return the number of hex digits in num. */
3709 hexnumlen (ULONGEST num
)
3713 for (i
= 0; num
!= 0; i
++)
3719 /* Set BUF to the minimum number of hex digits representing NUM. */
3722 hexnumstr (char *buf
, ULONGEST num
)
3724 int len
= hexnumlen (num
);
3725 return hexnumnstr (buf
, num
, len
);
3729 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3732 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3738 for (i
= width
- 1; i
>= 0; i
--)
3740 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3747 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3750 remote_address_masked (CORE_ADDR addr
)
3752 if (remote_address_size
> 0
3753 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3755 /* Only create a mask when that mask can safely be constructed
3756 in a ULONGEST variable. */
3758 mask
= (mask
<< remote_address_size
) - 1;
3764 /* Determine whether the remote target supports binary downloading.
3765 This is accomplished by sending a no-op memory write of zero length
3766 to the target at the specified address. It does not suffice to send
3767 the whole packet, since many stubs strip the eighth bit and subsequently
3768 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3770 NOTE: This can still lose if the serial line is not eight-bit
3771 clean. In cases like this, the user should clear "remote
3775 check_binary_download (CORE_ADDR addr
)
3777 struct remote_state
*rs
= get_remote_state ();
3778 switch (remote_protocol_binary_download
.support
)
3780 case PACKET_DISABLE
:
3784 case PACKET_SUPPORT_UNKNOWN
:
3786 char *buf
= alloca (rs
->remote_packet_size
);
3791 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3793 p
+= hexnumstr (p
, (ULONGEST
) 0);
3797 putpkt_binary (buf
, (int) (p
- buf
));
3798 getpkt (buf
, (rs
->remote_packet_size
), 0);
3803 fprintf_unfiltered (gdb_stdlog
,
3804 "binary downloading NOT suppported by target\n");
3805 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3810 fprintf_unfiltered (gdb_stdlog
,
3811 "binary downloading suppported by target\n");
3812 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3819 /* Write memory data directly to the remote machine.
3820 This does not inform the data cache; the data cache uses this.
3821 MEMADDR is the address in the remote memory space.
3822 MYADDR is the address of the buffer in our space.
3823 LEN is the number of bytes.
3825 Returns number of bytes transferred, or 0 (setting errno) for
3826 error. Only transfer a single packet. */
3829 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3833 unsigned char *plen
;
3839 unsigned char *payload_start
;
3841 /* Verify that the target can support a binary download. */
3842 check_binary_download (memaddr
);
3844 /* Compute the size, and then allocate space for the largest
3845 possible packet. Include space for an extra trailing NUL. */
3846 sizeof_buf
= get_memory_write_packet_size () + 1;
3847 buf
= alloca (sizeof_buf
);
3849 /* Compute the size of the actual payload by subtracting out the
3850 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
3851 payload_size
= (get_memory_write_packet_size () - (strlen ("$M,:#NN")
3852 + hexnumlen (memaddr
)
3853 + hexnumlen (len
)));
3855 /* Construct the packet header: "[MX]<memaddr>,<len>:". */
3857 /* Append "[XM]". Compute a best guess of the number of bytes
3858 actually transfered. */
3860 switch (remote_protocol_binary_download
.support
)
3864 /* Best guess at number of bytes that will fit. */
3865 todo
= min (len
, payload_size
);
3867 case PACKET_DISABLE
:
3869 /* num bytes that will fit */
3870 todo
= min (len
, payload_size
/ 2);
3872 case PACKET_SUPPORT_UNKNOWN
:
3873 internal_error (__FILE__
, __LINE__
,
3874 "remote_write_bytes: bad internal state");
3876 internal_error (__FILE__
, __LINE__
, "bad switch");
3879 /* Append "<memaddr>". */
3880 memaddr
= remote_address_masked (memaddr
);
3881 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3886 /* Append <len>. Retain the location/size of <len>. It may need to
3887 be adjusted once the packet body has been created. */
3889 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3896 /* Append the packet body. */
3898 switch (remote_protocol_binary_download
.support
)
3901 /* Binary mode. Send target system values byte by byte, in
3902 increasing byte addresses. Only escape certain critical
3905 (nr_bytes
< todo
) && (p
- payload_start
) < payload_size
;
3908 switch (myaddr
[nr_bytes
] & 0xff)
3913 /* These must be escaped */
3915 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3918 *p
++ = myaddr
[nr_bytes
] & 0xff;
3922 if (nr_bytes
< todo
)
3924 /* Escape chars have filled up the buffer prematurely,
3925 and we have actually sent fewer bytes than planned.
3926 Fix-up the length field of the packet. Use the same
3927 number of characters as before. */
3928 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3929 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3932 case PACKET_DISABLE
:
3933 /* Normal mode: Send target system values byte by byte, in
3934 increasing byte addresses. Each byte is encoded as a two hex
3936 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3939 case PACKET_SUPPORT_UNKNOWN
:
3940 internal_error (__FILE__
, __LINE__
,
3941 "remote_write_bytes: bad internal state");
3943 internal_error (__FILE__
, __LINE__
, "bad switch");
3946 putpkt_binary (buf
, (int) (p
- buf
));
3947 getpkt (buf
, sizeof_buf
, 0);
3951 /* There is no correspondance between what the remote protocol
3952 uses for errors and errno codes. We would like a cleaner way
3953 of representing errors (big enough to include errno codes,
3954 bfd_error codes, and others). But for now just return EIO. */
3959 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3960 bytes than we'd planned. */
3964 /* Read memory data directly from the remote machine.
3965 This does not use the data cache; the data cache uses this.
3966 MEMADDR is the address in the remote memory space.
3967 MYADDR is the address of the buffer in our space.
3968 LEN is the number of bytes.
3970 Returns number of bytes transferred, or 0 for error. */
3972 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3973 remote targets) shouldn't attempt to read the entire buffer.
3974 Instead it should read a single packet worth of data and then
3975 return the byte size of that packet to the caller. The caller (its
3976 caller and its callers caller ;-) already contains code for
3977 handling partial reads. */
3980 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3983 int max_buf_size
; /* Max size of packet output buffer */
3987 /* Create a buffer big enough for this packet. */
3988 max_buf_size
= get_memory_read_packet_size ();
3989 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3990 buf
= alloca (sizeof_buf
);
3999 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
4001 /* construct "m"<memaddr>","<len>" */
4002 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
4003 memaddr
= remote_address_masked (memaddr
);
4006 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
4008 p
+= hexnumstr (p
, (ULONGEST
) todo
);
4012 getpkt (buf
, sizeof_buf
, 0);
4015 && isxdigit (buf
[1]) && isxdigit (buf
[2])
4018 /* There is no correspondance between what the remote protocol uses
4019 for errors and errno codes. We would like a cleaner way of
4020 representing errors (big enough to include errno codes, bfd_error
4021 codes, and others). But for now just return EIO. */
4026 /* Reply describes memory byte by byte,
4027 each byte encoded as two hex characters. */
4030 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
4032 /* Reply is short. This means that we were able to read
4033 only part of what we wanted to. */
4034 return i
+ (origlen
- len
);
4043 /* Read or write LEN bytes from inferior memory at MEMADDR,
4044 transferring to or from debugger address BUFFER. Write to inferior if
4045 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
4046 for error. TARGET is unused. */
4049 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
4050 int should_write
, struct mem_attrib
*attrib
,
4051 struct target_ops
*target
)
4053 CORE_ADDR targ_addr
;
4057 /* Should this be the selected frame? */
4058 gdbarch_remote_translate_xfer_address (current_gdbarch
, current_regcache
,
4060 &targ_addr
, &targ_len
);
4065 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
4067 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
4073 remote_files_info (struct target_ops
*ignore
)
4075 puts_filtered ("Debugging a target over a serial line.\n");
4078 /* Stuff for dealing with the packets which are part of this protocol.
4079 See comment at top of file for details. */
4081 /* Read a single character from the remote end, masking it down to 7 bits. */
4084 readchar (int timeout
)
4088 ch
= serial_readchar (remote_desc
, timeout
);
4093 switch ((enum serial_rc
) ch
)
4096 target_mourn_inferior ();
4097 error ("Remote connection closed");
4100 perror_with_name ("Remote communication error");
4102 case SERIAL_TIMEOUT
:
4108 /* Send the command in BUF to the remote machine, and read the reply
4109 into BUF. Report an error if we get an error reply. */
4112 remote_send (char *buf
,
4116 getpkt (buf
, sizeof_buf
, 0);
4119 error ("Remote failure reply: %s", buf
);
4122 /* Display a null-terminated packet on stdout, for debugging, using C
4126 print_packet (char *buf
)
4128 puts_filtered ("\"");
4129 fputstr_filtered (buf
, '"', gdb_stdout
);
4130 puts_filtered ("\"");
4136 return putpkt_binary (buf
, strlen (buf
));
4139 /* Send a packet to the remote machine, with error checking. The data
4140 of the packet is in BUF. The string in BUF can be at most (rs->remote_packet_size) - 5
4141 to account for the $, # and checksum, and for a possible /0 if we are
4142 debugging (remote_debug) and want to print the sent packet as a string */
4145 putpkt_binary (char *buf
, int cnt
)
4147 struct remote_state
*rs
= get_remote_state ();
4149 unsigned char csum
= 0;
4150 char *buf2
= alloca (cnt
+ 6);
4151 long sizeof_junkbuf
= (rs
->remote_packet_size
);
4152 char *junkbuf
= alloca (sizeof_junkbuf
);
4158 /* Copy the packet into buffer BUF2, encapsulating it
4159 and giving it a checksum. */
4164 for (i
= 0; i
< cnt
; i
++)
4170 *p
++ = tohex ((csum
>> 4) & 0xf);
4171 *p
++ = tohex (csum
& 0xf);
4173 /* Send it over and over until we get a positive ack. */
4177 int started_error_output
= 0;
4182 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4183 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4184 fprintf_unfiltered (gdb_stdlog
, "...");
4185 gdb_flush (gdb_stdlog
);
4187 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4188 perror_with_name ("putpkt: write failed");
4190 /* read until either a timeout occurs (-2) or '+' is read */
4193 ch
= readchar (remote_timeout
);
4201 case SERIAL_TIMEOUT
:
4203 if (started_error_output
)
4205 putchar_unfiltered ('\n');
4206 started_error_output
= 0;
4215 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4219 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4220 case SERIAL_TIMEOUT
:
4224 break; /* Retransmit buffer */
4228 fprintf_unfiltered (gdb_stdlog
, "Packet instead of Ack, ignoring it\n");
4229 /* It's probably an old response, and we're out of sync.
4230 Just gobble up the packet and ignore it. */
4231 read_frame (junkbuf
, sizeof_junkbuf
);
4232 continue; /* Now, go look for + */
4237 if (!started_error_output
)
4239 started_error_output
= 1;
4240 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4242 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4246 break; /* Here to retransmit */
4250 /* This is wrong. If doing a long backtrace, the user should be
4251 able to get out next time we call QUIT, without anything as
4252 violent as interrupt_query. If we want to provide a way out of
4253 here without getting to the next QUIT, it should be based on
4254 hitting ^C twice as in remote_wait. */
4264 static int remote_cisco_mode
;
4266 /* Come here after finding the start of the frame. Collect the rest
4267 into BUF, verifying the checksum, length, and handling run-length
4268 compression. No more than sizeof_buf-1 characters are read so that
4269 the buffer can be NUL terminated.
4271 Returns -1 on error, number of characters in buffer (ignoring the
4272 trailing NULL) on success. (could be extended to return one of the
4273 SERIAL status indications). */
4276 read_frame (char *buf
,
4288 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
4289 c
= readchar (remote_timeout
);
4292 case SERIAL_TIMEOUT
:
4294 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4298 fputs_filtered ("Saw new packet start in middle of old one\n",
4300 return -1; /* Start a new packet, count retries */
4303 unsigned char pktcsum
;
4309 check_0
= readchar (remote_timeout
);
4311 check_1
= readchar (remote_timeout
);
4313 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4316 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog
);
4319 else if (check_0
< 0 || check_1
< 0)
4322 fputs_filtered ("Communication error in checksum\n", gdb_stdlog
);
4326 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4327 if (csum
== pktcsum
)
4332 fprintf_filtered (gdb_stdlog
,
4333 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4335 fputs_filtered (buf
, gdb_stdlog
);
4336 fputs_filtered ("\n", gdb_stdlog
);
4338 /* Number of characters in buffer ignoring trailing
4342 case '*': /* Run length encoding */
4347 if (remote_cisco_mode
== 0)
4349 c
= readchar (remote_timeout
);
4351 repeat
= c
- ' ' + 3; /* Compute repeat count */
4355 /* Cisco's run-length encoding variant uses two
4356 hex chars to represent the repeat count. */
4358 c
= readchar (remote_timeout
);
4360 repeat
= fromhex (c
) << 4;
4361 c
= readchar (remote_timeout
);
4363 repeat
+= fromhex (c
);
4366 /* The character before ``*'' is repeated. */
4368 if (repeat
> 0 && repeat
<= 255
4370 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4372 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4378 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
4379 puts_filtered (buf
);
4380 puts_filtered ("\n");
4384 if (bc
< sizeof_buf
- 1)
4392 puts_filtered ("Remote packet too long: ");
4393 puts_filtered (buf
);
4394 puts_filtered ("\n");
4401 /* Read a packet from the remote machine, with error checking, and
4402 store it in BUF. If FOREVER, wait forever rather than timing out;
4403 this is used (in synchronous mode) to wait for a target that is is
4404 executing user code to stop. */
4405 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4406 don't have to change all the calls to getpkt to deal with the
4407 return value, because at the moment I don't know what the right
4408 thing to do it for those. */
4416 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4420 /* Read a packet from the remote machine, with error checking, and
4421 store it in BUF. If FOREVER, wait forever rather than timing out;
4422 this is used (in synchronous mode) to wait for a target that is is
4423 executing user code to stop. If FOREVER == 0, this function is
4424 allowed to time out gracefully and return an indication of this to
4427 getpkt_sane (char *buf
,
4436 strcpy (buf
, "timeout");
4440 timeout
= watchdog
> 0 ? watchdog
: -1;
4444 timeout
= remote_timeout
;
4448 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4450 /* This can loop forever if the remote side sends us characters
4451 continuously, but if it pauses, we'll get a zero from readchar
4452 because of timeout. Then we'll count that as a retry. */
4454 /* Note that we will only wait forever prior to the start of a packet.
4455 After that, we expect characters to arrive at a brisk pace. They
4456 should show up within remote_timeout intervals. */
4460 c
= readchar (timeout
);
4462 if (c
== SERIAL_TIMEOUT
)
4464 if (forever
) /* Watchdog went off? Kill the target. */
4467 target_mourn_inferior ();
4468 error ("Watchdog has expired. Target detached.\n");
4471 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4477 /* We've found the start of a packet, now collect the data. */
4479 val
= read_frame (buf
, sizeof_buf
);
4485 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4486 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4487 fprintf_unfiltered (gdb_stdlog
, "\n");
4489 serial_write (remote_desc
, "+", 1);
4493 /* Try the whole thing again. */
4495 serial_write (remote_desc
, "-", 1);
4498 /* We have tried hard enough, and just can't receive the packet. Give up. */
4500 printf_unfiltered ("Ignoring packet error, continuing...\n");
4501 serial_write (remote_desc
, "+", 1);
4508 /* For some mysterious reason, wait_for_inferior calls kill instead of
4509 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4513 target_mourn_inferior ();
4517 /* Use catch_errors so the user can quit from gdb even when we aren't on
4518 speaking terms with the remote system. */
4519 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4521 /* Don't wait for it to die. I'm not really sure it matters whether
4522 we do or not. For the existing stubs, kill is a noop. */
4523 target_mourn_inferior ();
4526 /* Async version of remote_kill. */
4528 remote_async_kill (void)
4530 /* Unregister the file descriptor from the event loop. */
4531 if (target_is_async_p ())
4532 serial_async (remote_desc
, NULL
, 0);
4534 /* For some mysterious reason, wait_for_inferior calls kill instead of
4535 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4539 target_mourn_inferior ();
4543 /* Use catch_errors so the user can quit from gdb even when we aren't on
4544 speaking terms with the remote system. */
4545 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4547 /* Don't wait for it to die. I'm not really sure it matters whether
4548 we do or not. For the existing stubs, kill is a noop. */
4549 target_mourn_inferior ();
4555 remote_mourn_1 (&remote_ops
);
4559 remote_async_mourn (void)
4561 remote_mourn_1 (&remote_async_ops
);
4565 extended_remote_mourn (void)
4567 /* We do _not_ want to mourn the target like this; this will
4568 remove the extended remote target from the target stack,
4569 and the next time the user says "run" it'll fail.
4571 FIXME: What is the right thing to do here? */
4573 remote_mourn_1 (&extended_remote_ops
);
4577 /* Worker function for remote_mourn. */
4579 remote_mourn_1 (struct target_ops
*target
)
4581 unpush_target (target
);
4582 generic_mourn_inferior ();
4585 /* In the extended protocol we want to be able to do things like
4586 "run" and have them basically work as expected. So we need
4587 a special create_inferior function.
4589 FIXME: One day add support for changing the exec file
4590 we're debugging, arguments and an environment. */
4593 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
)
4595 /* Rip out the breakpoints; we'll reinsert them after restarting
4596 the remote server. */
4597 remove_breakpoints ();
4599 /* Now restart the remote server. */
4600 extended_remote_restart ();
4602 /* Now put the breakpoints back in. This way we're safe if the
4603 restart function works via a unix fork on the remote side. */
4604 insert_breakpoints ();
4606 /* Clean up from the last time we were running. */
4607 clear_proceed_status ();
4609 /* Let the remote process run. */
4610 proceed (-1, TARGET_SIGNAL_0
, 0);
4613 /* Async version of extended_remote_create_inferior. */
4615 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
)
4617 /* Rip out the breakpoints; we'll reinsert them after restarting
4618 the remote server. */
4619 remove_breakpoints ();
4621 /* If running asynchronously, register the target file descriptor
4622 with the event loop. */
4623 if (event_loop_p
&& target_can_async_p ())
4624 target_async (inferior_event_handler
, 0);
4626 /* Now restart the remote server. */
4627 extended_remote_restart ();
4629 /* Now put the breakpoints back in. This way we're safe if the
4630 restart function works via a unix fork on the remote side. */
4631 insert_breakpoints ();
4633 /* Clean up from the last time we were running. */
4634 clear_proceed_status ();
4636 /* Let the remote process run. */
4637 proceed (-1, TARGET_SIGNAL_0
, 0);
4641 /* On some machines, e.g. 68k, we may use a different breakpoint
4642 instruction than other targets; in those use
4643 DEPRECATED_REMOTE_BREAKPOINT instead of just BREAKPOINT_FROM_PC.
4644 Also, bi-endian targets may define
4645 DEPRECATED_LITTLE_REMOTE_BREAKPOINT and
4646 DEPRECATED_BIG_REMOTE_BREAKPOINT. If none of these are defined, we
4647 just call the standard routines that are in mem-break.c. */
4649 /* NOTE: cagney/2003-06-08: This is silly. A remote and simulator
4650 target should use an identical BREAKPOINT_FROM_PC. As for native,
4651 the ARCH-OS-tdep.c code can override the default. */
4653 #if defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) && !defined(DEPRECATED_REMOTE_BREAKPOINT)
4654 #define DEPRECATED_REMOTE_BREAKPOINT
4657 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4659 /* If the target isn't bi-endian, just pretend it is. */
4660 #if !defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && !defined (DEPRECATED_BIG_REMOTE_BREAKPOINT)
4661 #define DEPRECATED_LITTLE_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4662 #define DEPRECATED_BIG_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4665 static unsigned char big_break_insn
[] = DEPRECATED_BIG_REMOTE_BREAKPOINT
;
4666 static unsigned char little_break_insn
[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT
;
4668 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4670 /* Insert a breakpoint on targets that don't have any better
4671 breakpoint support. We read the contents of the target location
4672 and stash it, then overwrite it with a breakpoint instruction.
4673 ADDR is the target location in the target machine. CONTENTS_CACHE
4674 is a pointer to memory allocated for saving the target contents.
4675 It is guaranteed by the caller to be long enough to save the number
4676 of bytes returned by BREAKPOINT_FROM_PC. */
4679 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4681 struct remote_state
*rs
= get_remote_state ();
4682 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4687 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4688 If it succeeds, then set the support to PACKET_ENABLE. If it
4689 fails, and the user has explicitly requested the Z support then
4690 report an error, otherwise, mark it disabled and go on. */
4692 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4694 char *buf
= alloca (rs
->remote_packet_size
);
4697 addr
= remote_address_masked (addr
);
4701 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4702 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4703 sprintf (p
, ",%d", bp_size
);
4706 getpkt (buf
, (rs
->remote_packet_size
), 0);
4708 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4714 case PACKET_UNKNOWN
:
4719 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4720 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4724 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4725 val
= target_write_memory (addr
, (char *) big_break_insn
,
4726 sizeof big_break_insn
);
4728 val
= target_write_memory (addr
, (char *) little_break_insn
,
4729 sizeof little_break_insn
);
4734 return memory_insert_breakpoint (addr
, contents_cache
);
4735 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4739 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4741 struct remote_state
*rs
= get_remote_state ();
4744 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4746 char *buf
= alloca (rs
->remote_packet_size
);
4753 addr
= remote_address_masked (addr
);
4754 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4755 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4756 sprintf (p
, ",%d", bp_size
);
4759 getpkt (buf
, (rs
->remote_packet_size
), 0);
4761 return (buf
[0] == 'E');
4764 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4765 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4767 return memory_remove_breakpoint (addr
, contents_cache
);
4768 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4772 watchpoint_to_Z_packet (int type
)
4786 internal_error (__FILE__
, __LINE__
,
4787 "hw_bp_to_z: bad watchpoint type %d", type
);
4792 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4794 struct remote_state
*rs
= get_remote_state ();
4795 char *buf
= alloca (rs
->remote_packet_size
);
4797 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4799 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4800 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4801 remote_protocol_Z
[packet
].name
,
4802 remote_protocol_Z
[packet
].title
);
4804 sprintf (buf
, "Z%x,", packet
);
4805 p
= strchr (buf
, '\0');
4806 addr
= remote_address_masked (addr
);
4807 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4808 sprintf (p
, ",%x", len
);
4811 getpkt (buf
, (rs
->remote_packet_size
), 0);
4813 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4816 case PACKET_UNKNOWN
:
4821 internal_error (__FILE__
, __LINE__
,
4822 "remote_insert_watchpoint: reached end of function");
4827 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4829 struct remote_state
*rs
= get_remote_state ();
4830 char *buf
= alloca (rs
->remote_packet_size
);
4832 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4834 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4835 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4836 remote_protocol_Z
[packet
].name
,
4837 remote_protocol_Z
[packet
].title
);
4839 sprintf (buf
, "z%x,", packet
);
4840 p
= strchr (buf
, '\0');
4841 addr
= remote_address_masked (addr
);
4842 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4843 sprintf (p
, ",%x", len
);
4845 getpkt (buf
, (rs
->remote_packet_size
), 0);
4847 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4850 case PACKET_UNKNOWN
:
4855 internal_error (__FILE__
, __LINE__
,
4856 "remote_remove_watchpoint: reached end of function");
4860 int remote_hw_watchpoint_limit
= -1;
4861 int remote_hw_breakpoint_limit
= -1;
4864 remote_check_watch_resources (int type
, int cnt
, int ot
)
4866 if (type
== bp_hardware_breakpoint
)
4868 if (remote_hw_breakpoint_limit
== 0)
4870 else if (remote_hw_breakpoint_limit
< 0)
4872 else if (cnt
<= remote_hw_breakpoint_limit
)
4877 if (remote_hw_watchpoint_limit
== 0)
4879 else if (remote_hw_watchpoint_limit
< 0)
4883 else if (cnt
<= remote_hw_watchpoint_limit
)
4890 remote_stopped_by_watchpoint (void)
4892 return remote_stopped_by_watchpoint_p
;
4896 remote_stopped_data_address (void)
4898 if (remote_stopped_by_watchpoint ())
4899 return remote_watch_data_address
;
4900 return (CORE_ADDR
)0;
4905 remote_insert_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4908 struct remote_state
*rs
= get_remote_state ();
4909 char *buf
= alloca (rs
->remote_packet_size
);
4912 /* The length field should be set to the size of a breakpoint
4915 BREAKPOINT_FROM_PC (&addr
, &len
);
4917 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4918 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4919 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4920 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4926 addr
= remote_address_masked (addr
);
4927 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4928 sprintf (p
, ",%x", len
);
4931 getpkt (buf
, (rs
->remote_packet_size
), 0);
4933 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4936 case PACKET_UNKNOWN
:
4941 internal_error (__FILE__
, __LINE__
,
4942 "remote_insert_hw_breakpoint: reached end of function");
4947 remote_remove_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4950 struct remote_state
*rs
= get_remote_state ();
4951 char *buf
= alloca (rs
->remote_packet_size
);
4954 /* The length field should be set to the size of a breakpoint
4957 BREAKPOINT_FROM_PC (&addr
, &len
);
4959 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4960 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
4961 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4962 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4968 addr
= remote_address_masked (addr
);
4969 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4970 sprintf (p
, ",%x", len
);
4973 getpkt (buf
, (rs
->remote_packet_size
), 0);
4975 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4978 case PACKET_UNKNOWN
:
4983 internal_error (__FILE__
, __LINE__
,
4984 "remote_remove_hw_breakpoint: reached end of function");
4987 /* Some targets are only capable of doing downloads, and afterwards
4988 they switch to the remote serial protocol. This function provides
4989 a clean way to get from the download target to the remote target.
4990 It's basically just a wrapper so that we don't have to expose any
4991 of the internal workings of remote.c.
4993 Prior to calling this routine, you should shutdown the current
4994 target code, else you will get the "A program is being debugged
4995 already..." message. Usually a call to pop_target() suffices. */
4998 push_remote_target (char *name
, int from_tty
)
5000 printf_filtered ("Switching to remote protocol\n");
5001 remote_open (name
, from_tty
);
5004 /* Table used by the crc32 function to calcuate the checksum. */
5006 static unsigned long crc32_table
[256] =
5009 static unsigned long
5010 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
5012 if (!crc32_table
[1])
5014 /* Initialize the CRC table and the decoding table. */
5018 for (i
= 0; i
< 256; i
++)
5020 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
5021 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
5028 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
5034 /* compare-sections command
5036 With no arguments, compares each loadable section in the exec bfd
5037 with the same memory range on the target, and reports mismatches.
5038 Useful for verifying the image on the target against the exec file.
5039 Depends on the target understanding the new "qCRC:" request. */
5041 /* FIXME: cagney/1999-10-26: This command should be broken down into a
5042 target method (target verify memory) and generic version of the
5043 actual command. This will allow other high-level code (especially
5044 generic_load()) to make use of this target functionality. */
5047 compare_sections_command (char *args
, int from_tty
)
5049 struct remote_state
*rs
= get_remote_state ();
5051 unsigned long host_crc
, target_crc
;
5052 extern bfd
*exec_bfd
;
5053 struct cleanup
*old_chain
;
5056 const char *sectname
;
5057 char *buf
= alloca (rs
->remote_packet_size
);
5064 error ("command cannot be used without an exec file");
5065 if (!current_target
.to_shortname
||
5066 strcmp (current_target
.to_shortname
, "remote") != 0)
5067 error ("command can only be used with remote target");
5069 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
5071 if (!(s
->flags
& SEC_LOAD
))
5072 continue; /* skip non-loadable section */
5074 size
= bfd_get_section_size_before_reloc (s
);
5076 continue; /* skip zero-length section */
5078 sectname
= bfd_get_section_name (exec_bfd
, s
);
5079 if (args
&& strcmp (args
, sectname
) != 0)
5080 continue; /* not the section selected by user */
5082 matched
= 1; /* do this section */
5084 /* FIXME: assumes lma can fit into long */
5085 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
5088 /* be clever; compute the host_crc before waiting for target reply */
5089 sectdata
= xmalloc (size
);
5090 old_chain
= make_cleanup (xfree
, sectdata
);
5091 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
5092 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
5094 getpkt (buf
, (rs
->remote_packet_size
), 0);
5096 error ("target memory fault, section %s, range 0x%s -- 0x%s",
5097 sectname
, paddr (lma
), paddr (lma
+ size
));
5099 error ("remote target does not support this operation");
5101 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
5102 target_crc
= target_crc
* 16 + fromhex (*tmp
);
5104 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
5105 sectname
, paddr (lma
), paddr (lma
+ size
));
5106 if (host_crc
== target_crc
)
5107 printf_filtered ("matched.\n");
5110 printf_filtered ("MIS-MATCHED!\n");
5114 do_cleanups (old_chain
);
5117 warning ("One or more sections of the remote executable does not match\n\
5118 the loaded file\n");
5119 if (args
&& !matched
)
5120 printf_filtered ("No loaded section named '%s'.\n", args
);
5124 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
5125 const char *annex
, void *readbuf
, const void *writebuf
,
5126 ULONGEST offset
, LONGEST len
)
5128 struct remote_state
*rs
= get_remote_state ();
5130 char *buf2
= alloca (rs
->remote_packet_size
);
5131 char *p2
= &buf2
[0];
5134 /* Only handle reads. */
5135 if (writebuf
!= NULL
|| readbuf
== NULL
)
5138 /* Map pre-existing objects onto letters. DO NOT do this for new
5139 objects!!! Instead specify new query packets. */
5142 case TARGET_OBJECT_KOD
:
5145 case TARGET_OBJECT_AVR
:
5152 /* Note: a zero OFFSET and LEN can be used to query the minimum
5154 if (offset
== 0 && len
== 0)
5155 return (rs
->remote_packet_size
);
5156 /* Minimum outbuf size is (rs->remote_packet_size) - if bufsiz is
5157 not large enough let the caller. */
5158 if (len
< (rs
->remote_packet_size
))
5160 len
= rs
->remote_packet_size
;
5162 /* except for querying the minimum buffer size, target must be open */
5164 error ("remote query is only available after target open");
5166 gdb_assert (annex
!= NULL
);
5167 gdb_assert (readbuf
!= NULL
);
5172 /* we used one buffer char for the remote protocol q command and another
5173 for the query type. As the remote protocol encapsulation uses 4 chars
5174 plus one extra in case we are debugging (remote_debug),
5175 we have PBUFZIZ - 7 left to pack the query string */
5177 while (annex
[i
] && (i
< ((rs
->remote_packet_size
) - 8)))
5179 /* Bad caller may have sent forbidden characters. */
5180 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
5185 gdb_assert (annex
[i
] == '\0');
5191 getpkt (readbuf
, len
, 0);
5193 return strlen (readbuf
);
5197 remote_rcmd (char *command
,
5198 struct ui_file
*outbuf
)
5200 struct remote_state
*rs
= get_remote_state ();
5202 char *buf
= alloca (rs
->remote_packet_size
);
5206 error ("remote rcmd is only available after target open");
5208 /* Send a NULL command across as an empty command */
5209 if (command
== NULL
)
5212 /* The query prefix */
5213 strcpy (buf
, "qRcmd,");
5214 p
= strchr (buf
, '\0');
5216 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > (rs
->remote_packet_size
))
5217 error ("\"monitor\" command ``%s'' is too long\n", command
);
5219 /* Encode the actual command */
5220 bin2hex (command
, p
, 0);
5222 if (putpkt (buf
) < 0)
5223 error ("Communication problem with target\n");
5225 /* get/display the response */
5228 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
5230 getpkt (buf
, (rs
->remote_packet_size
), 0);
5232 error ("Target does not support this command\n");
5233 if (buf
[0] == 'O' && buf
[1] != 'K')
5235 remote_console_output (buf
+ 1); /* 'O' message from stub */
5238 if (strcmp (buf
, "OK") == 0)
5240 if (strlen (buf
) == 3 && buf
[0] == 'E'
5241 && isdigit (buf
[1]) && isdigit (buf
[2]))
5243 error ("Protocol error with Rcmd");
5245 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5247 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5248 fputc_unfiltered (c
, outbuf
);
5255 packet_command (char *args
, int from_tty
)
5257 struct remote_state
*rs
= get_remote_state ();
5258 char *buf
= alloca (rs
->remote_packet_size
);
5261 error ("command can only be used with remote target");
5264 error ("remote-packet command requires packet text as argument");
5266 puts_filtered ("sending: ");
5267 print_packet (args
);
5268 puts_filtered ("\n");
5271 getpkt (buf
, (rs
->remote_packet_size
), 0);
5272 puts_filtered ("received: ");
5274 puts_filtered ("\n");
5278 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
5280 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5282 static void threadset_test_cmd (char *cmd
, int tty
);
5284 static void threadalive_test (char *cmd
, int tty
);
5286 static void threadlist_test_cmd (char *cmd
, int tty
);
5288 int get_and_display_threadinfo (threadref
* ref
);
5290 static void threadinfo_test_cmd (char *cmd
, int tty
);
5292 static int thread_display_step (threadref
* ref
, void *context
);
5294 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5296 static void init_remote_threadtests (void);
5298 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
5301 threadset_test_cmd (char *cmd
, int tty
)
5303 int sample_thread
= SAMPLE_THREAD
;
5305 printf_filtered ("Remote threadset test\n");
5306 set_thread (sample_thread
, 1);
5311 threadalive_test (char *cmd
, int tty
)
5313 int sample_thread
= SAMPLE_THREAD
;
5315 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5316 printf_filtered ("PASS: Thread alive test\n");
5318 printf_filtered ("FAIL: Thread alive test\n");
5321 void output_threadid (char *title
, threadref
* ref
);
5324 output_threadid (char *title
, threadref
*ref
)
5328 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
5330 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5334 threadlist_test_cmd (char *cmd
, int tty
)
5337 threadref nextthread
;
5338 int done
, result_count
;
5339 threadref threadlist
[3];
5341 printf_filtered ("Remote Threadlist test\n");
5342 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5343 &result_count
, &threadlist
[0]))
5344 printf_filtered ("FAIL: threadlist test\n");
5347 threadref
*scan
= threadlist
;
5348 threadref
*limit
= scan
+ result_count
;
5350 while (scan
< limit
)
5351 output_threadid (" thread ", scan
++);
5356 display_thread_info (struct gdb_ext_thread_info
*info
)
5358 output_threadid ("Threadid: ", &info
->threadid
);
5359 printf_filtered ("Name: %s\n ", info
->shortname
);
5360 printf_filtered ("State: %s\n", info
->display
);
5361 printf_filtered ("other: %s\n\n", info
->more_display
);
5365 get_and_display_threadinfo (threadref
*ref
)
5369 struct gdb_ext_thread_info threadinfo
;
5371 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5372 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5373 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5374 display_thread_info (&threadinfo
);
5379 threadinfo_test_cmd (char *cmd
, int tty
)
5381 int athread
= SAMPLE_THREAD
;
5385 int_to_threadref (&thread
, athread
);
5386 printf_filtered ("Remote Threadinfo test\n");
5387 if (!get_and_display_threadinfo (&thread
))
5388 printf_filtered ("FAIL cannot get thread info\n");
5392 thread_display_step (threadref
*ref
, void *context
)
5394 /* output_threadid(" threadstep ",ref); *//* simple test */
5395 return get_and_display_threadinfo (ref
);
5399 threadlist_update_test_cmd (char *cmd
, int tty
)
5401 printf_filtered ("Remote Threadlist update test\n");
5402 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5406 init_remote_threadtests (void)
5408 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
5409 "Fetch and print the remote list of thread identifiers, one pkt only");
5410 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5411 "Fetch and display info about one thread");
5412 add_com ("tset", class_obscure
, threadset_test_cmd
,
5413 "Test setting to a different thread");
5414 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5415 "Iterate through updating all remote thread info");
5416 add_com ("talive", class_obscure
, threadalive_test
,
5417 " Remote thread alive test ");
5422 /* Convert a thread ID to a string. Returns the string in a static
5426 remote_pid_to_str (ptid_t ptid
)
5428 static char buf
[30];
5430 sprintf (buf
, "Thread %d", PIDGET (ptid
));
5435 init_remote_ops (void)
5437 remote_ops
.to_shortname
= "remote";
5438 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5440 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5441 Specify the serial device it is connected to\n\
5442 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5443 remote_ops
.to_open
= remote_open
;
5444 remote_ops
.to_close
= remote_close
;
5445 remote_ops
.to_detach
= remote_detach
;
5446 remote_ops
.to_disconnect
= remote_disconnect
;
5447 remote_ops
.to_resume
= remote_resume
;
5448 remote_ops
.to_wait
= remote_wait
;
5449 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5450 remote_ops
.to_store_registers
= remote_store_registers
;
5451 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5452 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
5453 remote_ops
.to_files_info
= remote_files_info
;
5454 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5455 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5456 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5457 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5458 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5459 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5460 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5461 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5462 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5463 remote_ops
.to_kill
= remote_kill
;
5464 remote_ops
.to_load
= generic_load
;
5465 remote_ops
.to_mourn_inferior
= remote_mourn
;
5466 remote_ops
.to_thread_alive
= remote_thread_alive
;
5467 remote_ops
.to_find_new_threads
= remote_threads_info
;
5468 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5469 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5470 remote_ops
.to_stop
= remote_stop
;
5471 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
5472 remote_ops
.to_rcmd
= remote_rcmd
;
5473 remote_ops
.to_stratum
= process_stratum
;
5474 remote_ops
.to_has_all_memory
= 1;
5475 remote_ops
.to_has_memory
= 1;
5476 remote_ops
.to_has_stack
= 1;
5477 remote_ops
.to_has_registers
= 1;
5478 remote_ops
.to_has_execution
= 1;
5479 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5480 remote_ops
.to_magic
= OPS_MAGIC
;
5483 /* Set up the extended remote vector by making a copy of the standard
5484 remote vector and adding to it. */
5487 init_extended_remote_ops (void)
5489 extended_remote_ops
= remote_ops
;
5491 extended_remote_ops
.to_shortname
= "extended-remote";
5492 extended_remote_ops
.to_longname
=
5493 "Extended remote serial target in gdb-specific protocol";
5494 extended_remote_ops
.to_doc
=
5495 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5496 Specify the serial device it is connected to (e.g. /dev/ttya).",
5497 extended_remote_ops
.to_open
= extended_remote_open
;
5498 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5499 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5503 * Command: info remote-process
5505 * This implements Cisco's version of the "info proc" command.
5507 * This query allows the target stub to return an arbitrary string
5508 * (or strings) giving arbitrary information about the target process.
5509 * This is optional; the target stub isn't required to implement it.
5511 * Syntax: qfProcessInfo request first string
5512 * qsProcessInfo request subsequent string
5513 * reply: 'O'<hex-encoded-string>
5514 * 'l' last reply (empty)
5518 remote_info_process (char *args
, int from_tty
)
5520 struct remote_state
*rs
= get_remote_state ();
5521 char *buf
= alloca (rs
->remote_packet_size
);
5523 if (remote_desc
== 0)
5524 error ("Command can only be used when connected to the remote target.");
5526 putpkt ("qfProcessInfo");
5527 getpkt (buf
, (rs
->remote_packet_size
), 0);
5529 return; /* Silently: target does not support this feature. */
5532 error ("info proc: target error.");
5534 while (buf
[0] == 'O') /* Capitol-O packet */
5536 remote_console_output (&buf
[1]);
5537 putpkt ("qsProcessInfo");
5538 getpkt (buf
, (rs
->remote_packet_size
), 0);
5547 remote_cisco_open (char *name
, int from_tty
)
5551 error ("To open a remote debug connection, you need to specify what \n"
5552 "device is attached to the remote system (e.g. host:port).");
5554 /* See FIXME above */
5555 wait_forever_enabled_p
= 1;
5557 target_preopen (from_tty
);
5559 unpush_target (&remote_cisco_ops
);
5561 remote_desc
= remote_serial_open (name
);
5563 perror_with_name (name
);
5566 * If a baud rate was specified on the gdb command line it will
5567 * be greater than the initial value of -1. If it is, use it otherwise
5571 baud_rate
= (baud_rate
> 0) ? baud_rate
: 9600;
5572 if (serial_setbaudrate (remote_desc
, baud_rate
))
5574 /* The requested speed could not be set. Error out to
5575 top level after closing remote_desc. Take care to
5576 set remote_desc to NULL to avoid closing remote_desc
5578 serial_close (remote_desc
);
5580 perror_with_name (name
);
5583 serial_raw (remote_desc
);
5585 /* If there is something sitting in the buffer we might take it as a
5586 response to a command, which would be bad. */
5587 serial_flush_input (remote_desc
);
5591 puts_filtered ("Remote debugging using ");
5592 puts_filtered (name
);
5593 puts_filtered ("\n");
5596 remote_cisco_mode
= 1;
5598 push_target (&remote_cisco_ops
); /* Switch to using cisco target now */
5600 init_all_packet_configs ();
5602 general_thread
= -2;
5603 continue_thread
= -2;
5605 /* Probe for ability to use "ThreadInfo" query, as required. */
5606 use_threadinfo_query
= 1;
5607 use_threadextra_query
= 1;
5609 /* Without this, some commands which require an active target (such
5610 as kill) won't work. This variable serves (at least) double duty
5611 as both the pid of the target process (if it has such), and as a
5612 flag indicating that a target is active. These functions should
5613 be split out into seperate variables, especially since GDB will
5614 someday have a notion of debugging several processes. */
5615 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
5617 /* Start the remote connection; if error, discard this target. See
5618 the comments in remote_open_1() for further details such as the
5619 need to re-throw the exception. */
5620 ex
= catch_exceptions (uiout
,
5621 remote_start_remote_dummy
, NULL
,
5622 "Couldn't establish connection to remote"
5628 throw_exception (ex
);
5633 remote_cisco_close (int quitting
)
5635 remote_cisco_mode
= 0;
5636 remote_close (quitting
);
5640 remote_cisco_mourn (void)
5642 remote_mourn_1 (&remote_cisco_ops
);
5654 /* Shared between readsocket() and readtty(). The size is arbitrary,
5655 however all targets are known to support a 400 character packet. */
5656 static char tty_input
[400];
5658 static int escape_count
;
5659 static int echo_check
;
5660 extern int quit_flag
;
5667 /* Loop until the socket doesn't have any more data */
5669 while ((data
= readchar (0)) >= 0)
5671 /* Check for the escape sequence */
5674 /* If this is the fourth escape, get out */
5675 if (++escape_count
== 4)
5680 { /* This is a '|', but not the fourth in a row.
5681 Continue without echoing it. If it isn't actually
5682 one of four in a row, it'll be echoed later. */
5689 /* Ensure any pending '|'s are flushed. */
5691 for (; escape_count
> 0; escape_count
--)
5695 if (data
== '\r') /* If this is a return character, */
5696 continue; /* - just supress it. */
5698 if (echo_check
!= -1) /* Check for echo of user input. */
5700 if (tty_input
[echo_check
] == data
)
5702 gdb_assert (echo_check
<= sizeof (tty_input
));
5703 echo_check
++; /* Character matched user input: */
5704 continue; /* Continue without echoing it. */
5706 else if ((data
== '\n') && (tty_input
[echo_check
] == '\r'))
5707 { /* End of the line (and of echo checking). */
5708 echo_check
= -1; /* No more echo supression */
5709 continue; /* Continue without echoing. */
5712 { /* Failed check for echo of user input.
5713 We now have some suppressed output to flush! */
5716 for (j
= 0; j
< echo_check
; j
++)
5717 putchar (tty_input
[j
]);
5721 putchar (data
); /* Default case: output the char. */
5724 if (data
== SERIAL_TIMEOUT
) /* Timeout returned from readchar. */
5725 return READ_MORE
; /* Try to read some more */
5727 return FATAL_ERROR
; /* Trouble, bail out */
5735 /* First, read a buffer full from the terminal */
5736 tty_bytecount
= read (fileno (stdin
), tty_input
, sizeof (tty_input
) - 1);
5737 if (tty_bytecount
== -1)
5739 perror ("readtty: read failed");
5743 /* Remove a quoted newline. */
5744 if (tty_input
[tty_bytecount
- 1] == '\n' &&
5745 tty_input
[tty_bytecount
- 2] == '\\') /* line ending in backslash */
5747 tty_input
[--tty_bytecount
] = 0; /* remove newline */
5748 tty_input
[--tty_bytecount
] = 0; /* remove backslash */
5751 /* Turn trailing newlines into returns */
5752 if (tty_input
[tty_bytecount
- 1] == '\n')
5753 tty_input
[tty_bytecount
- 1] = '\r';
5755 /* If the line consists of a ~, enter debugging mode. */
5756 if ((tty_input
[0] == '~') && (tty_bytecount
== 2))
5759 /* Make this a zero terminated string and write it out */
5760 tty_input
[tty_bytecount
] = 0;
5761 if (serial_write (remote_desc
, tty_input
, tty_bytecount
))
5763 perror_with_name ("readtty: write failed");
5773 fd_set input
; /* file descriptors for select */
5774 int tablesize
; /* max number of FDs for select */
5781 tablesize
= 8 * sizeof (input
);
5785 /* Check for anything from our socket - doesn't block. Note that
5786 this must be done *before* the select as there may be
5787 buffered I/O waiting to be processed. */
5789 if ((status
= readsocket ()) == FATAL_ERROR
)
5791 error ("Debugging terminated by communications error");
5793 else if (status
!= READ_MORE
)
5798 fflush (stdout
); /* Flush output before blocking */
5800 /* Now block on more socket input or TTY input */
5803 FD_SET (fileno (stdin
), &input
);
5804 FD_SET (deprecated_serial_fd (remote_desc
), &input
);
5806 status
= select (tablesize
, &input
, 0, 0, 0);
5807 if ((status
== -1) && (errno
!= EINTR
))
5809 error ("Communications error on select %d", errno
);
5812 /* Handle Control-C typed */
5816 if ((++quit_count
) == 2)
5818 if (query ("Interrupt GDB? "))
5820 printf_filtered ("Interrupted by user.\n");
5821 throw_exception (RETURN_QUIT
);
5828 serial_send_break (remote_desc
);
5830 serial_write (remote_desc
, "\003", 1);
5835 /* Handle console input */
5837 if (FD_ISSET (fileno (stdin
), &input
))
5841 status
= readtty ();
5842 if (status
== READ_MORE
)
5845 return status
; /* telnet session ended */
5851 remote_cisco_wait (ptid_t ptid
, struct target_waitstatus
*status
)
5853 if (minitelnet () != ENTER_DEBUG
)
5855 error ("Debugging session terminated by protocol error");
5858 return remote_wait (ptid
, status
);
5862 init_remote_cisco_ops (void)
5864 remote_cisco_ops
.to_shortname
= "cisco";
5865 remote_cisco_ops
.to_longname
= "Remote serial target in cisco-specific protocol";
5866 remote_cisco_ops
.to_doc
=
5867 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5868 Specify the serial device it is connected to (e.g. host:2020).";
5869 remote_cisco_ops
.to_open
= remote_cisco_open
;
5870 remote_cisco_ops
.to_close
= remote_cisco_close
;
5871 remote_cisco_ops
.to_detach
= remote_detach
;
5872 remote_cisco_ops
.to_disconnect
= remote_disconnect
;
5873 remote_cisco_ops
.to_resume
= remote_resume
;
5874 remote_cisco_ops
.to_wait
= remote_cisco_wait
;
5875 remote_cisco_ops
.to_fetch_registers
= remote_fetch_registers
;
5876 remote_cisco_ops
.to_store_registers
= remote_store_registers
;
5877 remote_cisco_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5878 remote_cisco_ops
.to_xfer_memory
= remote_xfer_memory
;
5879 remote_cisco_ops
.to_files_info
= remote_files_info
;
5880 remote_cisco_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5881 remote_cisco_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5882 remote_cisco_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5883 remote_cisco_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5884 remote_cisco_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5885 remote_cisco_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5886 remote_cisco_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5887 remote_cisco_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5888 remote_cisco_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5889 remote_cisco_ops
.to_kill
= remote_kill
;
5890 remote_cisco_ops
.to_load
= generic_load
;
5891 remote_cisco_ops
.to_mourn_inferior
= remote_cisco_mourn
;
5892 remote_cisco_ops
.to_thread_alive
= remote_thread_alive
;
5893 remote_cisco_ops
.to_find_new_threads
= remote_threads_info
;
5894 remote_cisco_ops
.to_pid_to_str
= remote_pid_to_str
;
5895 remote_cisco_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5896 remote_cisco_ops
.to_stratum
= process_stratum
;
5897 remote_cisco_ops
.to_has_all_memory
= 1;
5898 remote_cisco_ops
.to_has_memory
= 1;
5899 remote_cisco_ops
.to_has_stack
= 1;
5900 remote_cisco_ops
.to_has_registers
= 1;
5901 remote_cisco_ops
.to_has_execution
= 1;
5902 remote_cisco_ops
.to_magic
= OPS_MAGIC
;
5906 remote_can_async_p (void)
5908 /* We're async whenever the serial device is. */
5909 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5913 remote_is_async_p (void)
5915 /* We're async whenever the serial device is. */
5916 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5919 /* Pass the SERIAL event on and up to the client. One day this code
5920 will be able to delay notifying the client of an event until the
5921 point where an entire packet has been received. */
5923 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5924 static void *async_client_context
;
5925 static serial_event_ftype remote_async_serial_handler
;
5928 remote_async_serial_handler (struct serial
*scb
, void *context
)
5930 /* Don't propogate error information up to the client. Instead let
5931 the client find out about the error by querying the target. */
5932 async_client_callback (INF_REG_EVENT
, async_client_context
);
5936 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5938 if (current_target
.to_async_mask_value
== 0)
5939 internal_error (__FILE__
, __LINE__
,
5940 "Calling remote_async when async is masked");
5942 if (callback
!= NULL
)
5944 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5945 async_client_callback
= callback
;
5946 async_client_context
= context
;
5949 serial_async (remote_desc
, NULL
, NULL
);
5952 /* Target async and target extended-async.
5954 This are temporary targets, until it is all tested. Eventually
5955 async support will be incorporated int the usual 'remote'
5959 init_remote_async_ops (void)
5961 remote_async_ops
.to_shortname
= "async";
5962 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5963 remote_async_ops
.to_doc
=
5964 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5965 Specify the serial device it is connected to (e.g. /dev/ttya).";
5966 remote_async_ops
.to_open
= remote_async_open
;
5967 remote_async_ops
.to_close
= remote_close
;
5968 remote_async_ops
.to_detach
= remote_detach
;
5969 remote_async_ops
.to_disconnect
= remote_disconnect
;
5970 remote_async_ops
.to_resume
= remote_async_resume
;
5971 remote_async_ops
.to_wait
= remote_async_wait
;
5972 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5973 remote_async_ops
.to_store_registers
= remote_store_registers
;
5974 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5975 remote_async_ops
.to_xfer_memory
= remote_xfer_memory
;
5976 remote_async_ops
.to_files_info
= remote_files_info
;
5977 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5978 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5979 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5980 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5981 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5982 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5983 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5984 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5985 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5986 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5987 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5988 remote_async_ops
.to_kill
= remote_async_kill
;
5989 remote_async_ops
.to_load
= generic_load
;
5990 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5991 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5992 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5993 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
5994 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5995 remote_async_ops
.to_stop
= remote_stop
;
5996 remote_async_ops
.to_xfer_partial
= remote_xfer_partial
;
5997 remote_async_ops
.to_rcmd
= remote_rcmd
;
5998 remote_async_ops
.to_stratum
= process_stratum
;
5999 remote_async_ops
.to_has_all_memory
= 1;
6000 remote_async_ops
.to_has_memory
= 1;
6001 remote_async_ops
.to_has_stack
= 1;
6002 remote_async_ops
.to_has_registers
= 1;
6003 remote_async_ops
.to_has_execution
= 1;
6004 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
6005 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
6006 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
6007 remote_async_ops
.to_async
= remote_async
;
6008 remote_async_ops
.to_async_mask_value
= 1;
6009 remote_async_ops
.to_magic
= OPS_MAGIC
;
6012 /* Set up the async extended remote vector by making a copy of the standard
6013 remote vector and adding to it. */
6016 init_extended_async_remote_ops (void)
6018 extended_async_remote_ops
= remote_async_ops
;
6020 extended_async_remote_ops
.to_shortname
= "extended-async";
6021 extended_async_remote_ops
.to_longname
=
6022 "Extended remote serial target in async gdb-specific protocol";
6023 extended_async_remote_ops
.to_doc
=
6024 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
6025 Specify the serial device it is connected to (e.g. /dev/ttya).",
6026 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
6027 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
6028 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
6032 set_remote_cmd (char *args
, int from_tty
)
6037 show_remote_cmd (char *args
, int from_tty
)
6039 /* FIXME: cagney/2002-06-15: This function should iterate over
6040 remote_show_cmdlist for a list of sub commands to show. */
6041 show_remote_protocol_Z_packet_cmd (args
, from_tty
, NULL
);
6042 show_remote_protocol_e_packet_cmd (args
, from_tty
, NULL
);
6043 show_remote_protocol_E_packet_cmd (args
, from_tty
, NULL
);
6044 show_remote_protocol_P_packet_cmd (args
, from_tty
, NULL
);
6045 show_remote_protocol_qSymbol_packet_cmd (args
, from_tty
, NULL
);
6046 show_remote_protocol_vcont_packet_cmd (args
, from_tty
, NULL
);
6047 show_remote_protocol_binary_download_cmd (args
, from_tty
, NULL
);
6051 build_remote_gdbarch_data (void)
6053 remote_address_size
= TARGET_ADDR_BIT
;
6056 /* Saved pointer to previous owner of the new_objfile event. */
6057 static void (*remote_new_objfile_chain
) (struct objfile
*);
6059 /* Function to be called whenever a new objfile (shlib) is detected. */
6061 remote_new_objfile (struct objfile
*objfile
)
6063 if (remote_desc
!= 0) /* Have a remote connection */
6065 remote_check_symbols (objfile
);
6067 /* Call predecessor on chain, if any. */
6068 if (remote_new_objfile_chain
!= 0 &&
6070 remote_new_objfile_chain (objfile
);
6074 _initialize_remote (void)
6076 static struct cmd_list_element
*remote_set_cmdlist
;
6077 static struct cmd_list_element
*remote_show_cmdlist
;
6078 struct cmd_list_element
*tmpcmd
;
6080 /* architecture specific data */
6081 remote_gdbarch_data_handle
= register_gdbarch_data (init_remote_state
);
6083 /* Old tacky stuff. NOTE: This comes after the remote protocol so
6084 that the remote protocol has been initialized. */
6085 register_gdbarch_swap (&remote_address_size
,
6086 sizeof (&remote_address_size
), NULL
);
6087 register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
6090 add_target (&remote_ops
);
6092 init_extended_remote_ops ();
6093 add_target (&extended_remote_ops
);
6095 init_remote_async_ops ();
6096 add_target (&remote_async_ops
);
6098 init_extended_async_remote_ops ();
6099 add_target (&extended_async_remote_ops
);
6101 init_remote_cisco_ops ();
6102 add_target (&remote_cisco_ops
);
6104 /* Hook into new objfile notification. */
6105 remote_new_objfile_chain
= target_new_objfile_hook
;
6106 target_new_objfile_hook
= remote_new_objfile
;
6109 init_remote_threadtests ();
6112 /* set/show remote ... */
6114 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
6115 Remote protocol specific variables\n\
6116 Configure various remote-protocol specific variables such as\n\
6117 the packets being used",
6118 &remote_set_cmdlist
, "set remote ",
6119 0/*allow-unknown*/, &setlist
);
6120 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, "\
6121 Remote protocol specific variables\n\
6122 Configure various remote-protocol specific variables such as\n\
6123 the packets being used",
6124 &remote_show_cmdlist
, "show remote ",
6125 0/*allow-unknown*/, &showlist
);
6127 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
6128 "Compare section data on target to the exec file.\n\
6129 Argument is a single section name (default: all loaded sections).",
6132 add_cmd ("packet", class_maintenance
, packet_command
,
6133 "Send an arbitrary packet to a remote target.\n\
6134 maintenance packet TEXT\n\
6135 If GDB is talking to an inferior via the GDB serial protocol, then\n\
6136 this command sends the string TEXT to the inferior, and displays the\n\
6137 response packet. GDB supplies the initial `$' character, and the\n\
6138 terminating `#' character and checksum.",
6141 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
,
6142 "Set whether to send break if interrupted.\n",
6143 "Show whether to send break if interrupted.\n",
6145 &setlist
, &showlist
);
6147 /* Install commands for configuring memory read/write packets. */
6149 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
6150 "Set the maximum number of bytes per memory write packet (deprecated).\n",
6152 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
,
6153 "Show the maximum number of bytes per memory write packet (deprecated).\n",
6155 add_cmd ("memory-write-packet-size", no_class
,
6156 set_memory_write_packet_size
,
6157 "Set the maximum number of bytes per memory-write packet.\n"
6158 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6159 "default packet size. The actual limit is further reduced\n"
6160 "dependent on the target. Specify ``fixed'' to disable the\n"
6161 "further restriction and ``limit'' to enable that restriction\n",
6162 &remote_set_cmdlist
);
6163 add_cmd ("memory-read-packet-size", no_class
,
6164 set_memory_read_packet_size
,
6165 "Set the maximum number of bytes per memory-read packet.\n"
6166 "Specify the number of bytes in a packet or 0 (zero) for the\n"
6167 "default packet size. The actual limit is further reduced\n"
6168 "dependent on the target. Specify ``fixed'' to disable the\n"
6169 "further restriction and ``limit'' to enable that restriction\n",
6170 &remote_set_cmdlist
);
6171 add_cmd ("memory-write-packet-size", no_class
,
6172 show_memory_write_packet_size
,
6173 "Show the maximum number of bytes per memory-write packet.\n",
6174 &remote_show_cmdlist
);
6175 add_cmd ("memory-read-packet-size", no_class
,
6176 show_memory_read_packet_size
,
6177 "Show the maximum number of bytes per memory-read packet.\n",
6178 &remote_show_cmdlist
);
6180 add_setshow_cmd ("hardware-watchpoint-limit", no_class
,
6181 var_zinteger
, &remote_hw_watchpoint_limit
, "\
6182 Set the maximum number of target hardware watchpoints.\n\
6183 Specify a negative limit for unlimited.", "\
6184 Show the maximum number of target hardware watchpoints.\n",
6185 NULL
, NULL
, &remote_set_cmdlist
, &remote_show_cmdlist
);
6186 add_setshow_cmd ("hardware-breakpoint-limit", no_class
,
6187 var_zinteger
, &remote_hw_breakpoint_limit
, "\
6188 Set the maximum number of target hardware breakpoints.\n\
6189 Specify a negative limit for unlimited.", "\
6190 Show the maximum number of target hardware breakpoints.\n",
6191 NULL
, NULL
, &remote_set_cmdlist
, &remote_show_cmdlist
);
6194 (add_set_cmd ("remoteaddresssize", class_obscure
,
6195 var_integer
, (char *) &remote_address_size
,
6196 "Set the maximum size of the address (in bits) \
6197 in a memory packet.\n",
6201 add_packet_config_cmd (&remote_protocol_binary_download
,
6202 "X", "binary-download",
6203 set_remote_protocol_binary_download_cmd
,
6204 show_remote_protocol_binary_download_cmd
,
6205 &remote_set_cmdlist
, &remote_show_cmdlist
,
6208 /* XXXX - should ``set remotebinarydownload'' be retained for
6211 (add_set_cmd ("remotebinarydownload", no_class
,
6212 var_boolean
, (char *) &remote_binary_download
,
6213 "Set binary downloads.\n", &setlist
),
6217 add_info ("remote-process", remote_info_process
,
6218 "Query the remote system for process info.");
6220 add_packet_config_cmd (&remote_protocol_vcont
,
6221 "vCont", "verbose-resume",
6222 set_remote_protocol_vcont_packet_cmd
,
6223 show_remote_protocol_vcont_packet_cmd
,
6224 &remote_set_cmdlist
, &remote_show_cmdlist
,
6227 add_packet_config_cmd (&remote_protocol_qSymbol
,
6228 "qSymbol", "symbol-lookup",
6229 set_remote_protocol_qSymbol_packet_cmd
,
6230 show_remote_protocol_qSymbol_packet_cmd
,
6231 &remote_set_cmdlist
, &remote_show_cmdlist
,
6234 add_packet_config_cmd (&remote_protocol_e
,
6235 "e", "step-over-range",
6236 set_remote_protocol_e_packet_cmd
,
6237 show_remote_protocol_e_packet_cmd
,
6238 &remote_set_cmdlist
, &remote_show_cmdlist
,
6240 /* Disable by default. The ``e'' packet has nasty interactions with
6241 the threading code - it relies on global state. */
6242 remote_protocol_e
.detect
= AUTO_BOOLEAN_FALSE
;
6243 update_packet_config (&remote_protocol_e
);
6245 add_packet_config_cmd (&remote_protocol_E
,
6246 "E", "step-over-range-w-signal",
6247 set_remote_protocol_E_packet_cmd
,
6248 show_remote_protocol_E_packet_cmd
,
6249 &remote_set_cmdlist
, &remote_show_cmdlist
,
6251 /* Disable by default. The ``e'' packet has nasty interactions with
6252 the threading code - it relies on global state. */
6253 remote_protocol_E
.detect
= AUTO_BOOLEAN_FALSE
;
6254 update_packet_config (&remote_protocol_E
);
6256 add_packet_config_cmd (&remote_protocol_P
,
6257 "P", "set-register",
6258 set_remote_protocol_P_packet_cmd
,
6259 show_remote_protocol_P_packet_cmd
,
6260 &remote_set_cmdlist
, &remote_show_cmdlist
,
6263 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
6264 "Z0", "software-breakpoint",
6265 set_remote_protocol_Z_software_bp_packet_cmd
,
6266 show_remote_protocol_Z_software_bp_packet_cmd
,
6267 &remote_set_cmdlist
, &remote_show_cmdlist
,
6270 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
6271 "Z1", "hardware-breakpoint",
6272 set_remote_protocol_Z_hardware_bp_packet_cmd
,
6273 show_remote_protocol_Z_hardware_bp_packet_cmd
,
6274 &remote_set_cmdlist
, &remote_show_cmdlist
,
6277 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
6278 "Z2", "write-watchpoint",
6279 set_remote_protocol_Z_write_wp_packet_cmd
,
6280 show_remote_protocol_Z_write_wp_packet_cmd
,
6281 &remote_set_cmdlist
, &remote_show_cmdlist
,
6284 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
6285 "Z3", "read-watchpoint",
6286 set_remote_protocol_Z_read_wp_packet_cmd
,
6287 show_remote_protocol_Z_read_wp_packet_cmd
,
6288 &remote_set_cmdlist
, &remote_show_cmdlist
,
6291 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
6292 "Z4", "access-watchpoint",
6293 set_remote_protocol_Z_access_wp_packet_cmd
,
6294 show_remote_protocol_Z_access_wp_packet_cmd
,
6295 &remote_set_cmdlist
, &remote_show_cmdlist
,
6298 /* Keep the old ``set remote Z-packet ...'' working. */
6299 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
6300 &remote_Z_packet_detect
, "\
6301 Set use of remote protocol `Z' packets",
6302 "Show use of remote protocol `Z' packets ",
6303 set_remote_protocol_Z_packet_cmd
,
6304 show_remote_protocol_Z_packet_cmd
,
6305 &remote_set_cmdlist
, &remote_show_cmdlist
);
6307 /* Eventually initialize fileio. See fileio.c */
6308 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);