1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 /* See the GDB User Guide for details of the GDB remote protocol. */
27 #include "gdb_string.h"
34 /*#include "terminal.h" */
37 #include "gdb-stabs.h"
38 #include "gdbthread.h"
42 #include "gdb_assert.h"
47 #include "event-loop.h"
48 #include "event-top.h"
54 #include "gdbcore.h" /* for exec_bfd */
56 #include "remote-fileio.h"
58 /* Prototypes for local functions */
59 static void cleanup_sigint_signal_handler (void *dummy
);
60 static void initialize_sigint_signal_handler (void);
61 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
63 static void handle_remote_sigint (int);
64 static void handle_remote_sigint_twice (int);
65 static void async_remote_interrupt (gdb_client_data
);
66 void async_remote_interrupt_twice (gdb_client_data
);
68 static void build_remote_gdbarch_data (void);
70 static void remote_files_info (struct target_ops
*ignore
);
72 static int remote_xfer_memory (CORE_ADDR memaddr
, char *myaddr
,
73 int len
, int should_write
,
74 struct mem_attrib
*attrib
,
75 struct target_ops
*target
);
77 static void remote_prepare_to_store (void);
79 static void remote_fetch_registers (int regno
);
81 static void remote_resume (ptid_t ptid
, int step
,
82 enum target_signal siggnal
);
83 static void remote_async_resume (ptid_t ptid
, int step
,
84 enum target_signal siggnal
);
85 static int remote_start_remote (struct ui_out
*uiout
, void *dummy
);
87 static void remote_open (char *name
, int from_tty
);
88 static void remote_async_open (char *name
, int from_tty
);
90 static void extended_remote_open (char *name
, int from_tty
);
91 static void extended_remote_async_open (char *name
, int from_tty
);
93 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
,
96 static void remote_close (int quitting
);
98 static void remote_store_registers (int regno
);
100 static void remote_mourn (void);
101 static void remote_async_mourn (void);
103 static void extended_remote_restart (void);
105 static void extended_remote_mourn (void);
107 static void remote_mourn_1 (struct target_ops
*);
109 static void remote_send (char *buf
, long sizeof_buf
);
111 static int readchar (int timeout
);
113 static ptid_t
remote_wait (ptid_t ptid
,
114 struct target_waitstatus
*status
);
115 static ptid_t
remote_async_wait (ptid_t ptid
,
116 struct target_waitstatus
*status
);
118 static void remote_kill (void);
119 static void remote_async_kill (void);
121 static int tohex (int nib
);
123 static void remote_detach (char *args
, int from_tty
);
125 static void remote_interrupt (int signo
);
127 static void remote_interrupt_twice (int signo
);
129 static void interrupt_query (void);
131 static void set_thread (int, int);
133 static int remote_thread_alive (ptid_t
);
135 static void get_offsets (void);
137 static long read_frame (char *buf
, long sizeof_buf
);
139 static int remote_insert_breakpoint (CORE_ADDR
, char *);
141 static int remote_remove_breakpoint (CORE_ADDR
, char *);
143 static int hexnumlen (ULONGEST num
);
145 static void init_remote_ops (void);
147 static void init_extended_remote_ops (void);
149 static void remote_stop (void);
151 static int ishex (int ch
, int *val
);
153 static int stubhex (int ch
);
155 static int hexnumstr (char *, ULONGEST
);
157 static int hexnumnstr (char *, ULONGEST
, int);
159 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
161 static void print_packet (char *);
163 static unsigned long crc32 (unsigned char *, int, unsigned int);
165 static void compare_sections_command (char *, int);
167 static void packet_command (char *, int);
169 static int stub_unpack_int (char *buff
, int fieldlength
);
171 static ptid_t
remote_current_thread (ptid_t oldptid
);
173 static void remote_find_new_threads (void);
175 static void record_currthread (int currthread
);
177 static int fromhex (int a
);
179 static int hex2bin (const char *hex
, char *bin
, int count
);
181 static int bin2hex (const char *bin
, char *hex
, int count
);
183 static int putpkt_binary (char *buf
, int cnt
);
185 static void check_binary_download (CORE_ADDR addr
);
187 struct packet_config
;
189 static void show_packet_config_cmd (struct packet_config
*config
);
191 static void update_packet_config (struct packet_config
*config
);
193 void _initialize_remote (void);
195 /* Description of the remote protocol. Strictly speaking, when the
196 target is open()ed, remote.c should create a per-target description
197 of the remote protocol using that target's architecture.
198 Unfortunately, the target stack doesn't include local state. For
199 the moment keep the information in the target's architecture
204 long offset
; /* Offset into G packet. */
205 long regnum
; /* GDB's internal register number. */
206 LONGEST pnum
; /* Remote protocol register number. */
207 int in_g_packet
; /* Always part of G packet. */
208 /* long size in bytes; == register_size (current_gdbarch, regnum); at present. */
209 /* char *name; == REGISTER_NAME (regnum); at present. */
214 /* Description of the remote protocol registers. */
215 long sizeof_g_packet
;
217 /* Description of the remote protocol registers indexed by REGNUM
218 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
219 struct packet_reg
*regs
;
221 /* This is the size (in chars) of the first response to the ``g''
222 packet. It is used as a heuristic when determining the maximum
223 size of memory-read and memory-write packets. A target will
224 typically only reserve a buffer large enough to hold the ``g''
225 packet. The size does not include packet overhead (headers and
227 long actual_register_packet_size
;
229 /* This is the maximum size (in chars) of a non read/write packet.
230 It is also used as a cap on the size of read/write packets. */
231 long remote_packet_size
;
235 /* Handle for retreving the remote protocol data from gdbarch. */
236 static struct gdbarch_data
*remote_gdbarch_data_handle
;
238 static struct remote_state
*
239 get_remote_state (void)
241 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
245 init_remote_state (struct gdbarch
*gdbarch
)
248 struct remote_state
*rs
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_state
);
250 if (deprecated_register_bytes () != 0)
251 rs
->sizeof_g_packet
= deprecated_register_bytes ();
253 rs
->sizeof_g_packet
= 0;
255 /* Assume a 1:1 regnum<->pnum table. */
256 rs
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
, NUM_REGS
+ NUM_PSEUDO_REGS
,
258 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
260 struct packet_reg
*r
= &rs
->regs
[regnum
];
263 r
->offset
= DEPRECATED_REGISTER_BYTE (regnum
);
264 r
->in_g_packet
= (regnum
< NUM_REGS
);
265 /* ...name = REGISTER_NAME (regnum); */
267 /* Compute packet size by accumulating the size of all registers. */
268 if (deprecated_register_bytes () == 0)
269 rs
->sizeof_g_packet
+= register_size (current_gdbarch
, regnum
);
272 /* Default maximum number of characters in a packet body. Many
273 remote stubs have a hardwired buffer size of 400 bytes
274 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
275 as the maximum packet-size to ensure that the packet and an extra
276 NUL character can always fit in the buffer. This stops GDB
277 trashing stubs that try to squeeze an extra NUL into what is
278 already a full buffer (As of 1999-12-04 that was most stubs. */
279 rs
->remote_packet_size
= 400 - 1;
281 /* Should rs->sizeof_g_packet needs more space than the
282 default, adjust the size accordingly. Remember that each byte is
283 encoded as two characters. 32 is the overhead for the packet
284 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
285 (``$NN:G...#NN'') is a better guess, the below has been padded a
287 if (rs
->sizeof_g_packet
> ((rs
->remote_packet_size
- 32) / 2))
288 rs
->remote_packet_size
= (rs
->sizeof_g_packet
* 2 + 32);
290 /* This one is filled in when a ``g'' packet is received. */
291 rs
->actual_register_packet_size
= 0;
296 static struct packet_reg
*
297 packet_reg_from_regnum (struct remote_state
*rs
, long regnum
)
299 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
303 struct packet_reg
*r
= &rs
->regs
[regnum
];
304 gdb_assert (r
->regnum
== regnum
);
309 static struct packet_reg
*
310 packet_reg_from_pnum (struct remote_state
*rs
, LONGEST pnum
)
313 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
315 struct packet_reg
*r
= &rs
->regs
[i
];
322 /* FIXME: graces/2002-08-08: These variables should eventually be
323 bound to an instance of the target object (as in gdbarch-tdep()),
324 when such a thing exists. */
326 /* This is set to the data address of the access causing the target
327 to stop for a watchpoint. */
328 static CORE_ADDR remote_watch_data_address
;
330 /* This is non-zero if taregt stopped for a watchpoint. */
331 static int remote_stopped_by_watchpoint_p
;
334 static struct target_ops remote_ops
;
336 static struct target_ops extended_remote_ops
;
338 /* Temporary target ops. Just like the remote_ops and
339 extended_remote_ops, but with asynchronous support. */
340 static struct target_ops remote_async_ops
;
342 static struct target_ops extended_async_remote_ops
;
344 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
345 ``forever'' still use the normal timeout mechanism. This is
346 currently used by the ASYNC code to guarentee that target reads
347 during the initial connect always time-out. Once getpkt has been
348 modified to return a timeout indication and, in turn
349 remote_wait()/wait_for_inferior() have gained a timeout parameter
351 static int wait_forever_enabled_p
= 1;
354 /* This variable chooses whether to send a ^C or a break when the user
355 requests program interruption. Although ^C is usually what remote
356 systems expect, and that is the default here, sometimes a break is
357 preferable instead. */
359 static int remote_break
;
361 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
362 remote_open knows that we don't have a file open when the program
364 static struct serial
*remote_desc
= NULL
;
366 /* This variable sets the number of bits in an address that are to be
367 sent in a memory ("M" or "m") packet. Normally, after stripping
368 leading zeros, the entire address would be sent. This variable
369 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
370 initial implementation of remote.c restricted the address sent in
371 memory packets to ``host::sizeof long'' bytes - (typically 32
372 bits). Consequently, for 64 bit targets, the upper 32 bits of an
373 address was never sent. Since fixing this bug may cause a break in
374 some remote targets this variable is principly provided to
375 facilitate backward compatibility. */
377 static int remote_address_size
;
379 /* Tempoary to track who currently owns the terminal. See
380 target_async_terminal_* for more details. */
382 static int remote_async_terminal_ours_p
;
385 /* User configurable variables for the number of characters in a
386 memory read/write packet. MIN ((rs->remote_packet_size),
387 rs->sizeof_g_packet) is the default. Some targets need smaller
388 values (fifo overruns, et.al.) and some users need larger values
389 (speed up transfers). The variables ``preferred_*'' (the user
390 request), ``current_*'' (what was actually set) and ``forced_*''
391 (Positive - a soft limit, negative - a hard limit). */
393 struct memory_packet_config
400 /* Compute the current size of a read/write packet. Since this makes
401 use of ``actual_register_packet_size'' the computation is dynamic. */
404 get_memory_packet_size (struct memory_packet_config
*config
)
406 struct remote_state
*rs
= get_remote_state ();
407 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
408 law?) that some hosts don't cope very well with large alloca()
409 calls. Eventually the alloca() code will be replaced by calls to
410 xmalloc() and make_cleanups() allowing this restriction to either
411 be lifted or removed. */
412 #ifndef MAX_REMOTE_PACKET_SIZE
413 #define MAX_REMOTE_PACKET_SIZE 16384
415 /* NOTE: 16 is just chosen at random. */
416 #ifndef MIN_REMOTE_PACKET_SIZE
417 #define MIN_REMOTE_PACKET_SIZE 16
422 if (config
->size
<= 0)
423 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
425 what_they_get
= config
->size
;
429 what_they_get
= (rs
->remote_packet_size
);
430 /* Limit the packet to the size specified by the user. */
432 && what_they_get
> config
->size
)
433 what_they_get
= config
->size
;
434 /* Limit it to the size of the targets ``g'' response. */
435 if ((rs
->actual_register_packet_size
) > 0
436 && what_they_get
> (rs
->actual_register_packet_size
))
437 what_they_get
= (rs
->actual_register_packet_size
);
439 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
440 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
441 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
442 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
443 return what_they_get
;
446 /* Update the size of a read/write packet. If they user wants
447 something really big then do a sanity check. */
450 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
452 int fixed_p
= config
->fixed_p
;
453 long size
= config
->size
;
455 error ("Argument required (integer, `fixed' or `limited').");
456 else if (strcmp (args
, "hard") == 0
457 || strcmp (args
, "fixed") == 0)
459 else if (strcmp (args
, "soft") == 0
460 || strcmp (args
, "limit") == 0)
465 size
= strtoul (args
, &end
, 0);
467 error ("Invalid %s (bad syntax).", config
->name
);
469 /* Instead of explicitly capping the size of a packet to
470 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
471 instead allowed to set the size to something arbitrarily
473 if (size
> MAX_REMOTE_PACKET_SIZE
)
474 error ("Invalid %s (too large).", config
->name
);
478 if (fixed_p
&& !config
->fixed_p
)
480 if (! query ("The target may not be able to correctly handle a %s\n"
481 "of %ld bytes. Change the packet size? ",
483 error ("Packet size not changed.");
485 /* Update the config. */
486 config
->fixed_p
= fixed_p
;
491 show_memory_packet_size (struct memory_packet_config
*config
)
493 printf_filtered ("The %s is %ld. ", config
->name
, config
->size
);
495 printf_filtered ("Packets are fixed at %ld bytes.\n",
496 get_memory_packet_size (config
));
498 printf_filtered ("Packets are limited to %ld bytes.\n",
499 get_memory_packet_size (config
));
502 static struct memory_packet_config memory_write_packet_config
=
504 "memory-write-packet-size",
508 set_memory_write_packet_size (char *args
, int from_tty
)
510 set_memory_packet_size (args
, &memory_write_packet_config
);
514 show_memory_write_packet_size (char *args
, int from_tty
)
516 show_memory_packet_size (&memory_write_packet_config
);
520 get_memory_write_packet_size (void)
522 return get_memory_packet_size (&memory_write_packet_config
);
525 static struct memory_packet_config memory_read_packet_config
=
527 "memory-read-packet-size",
531 set_memory_read_packet_size (char *args
, int from_tty
)
533 set_memory_packet_size (args
, &memory_read_packet_config
);
537 show_memory_read_packet_size (char *args
, int from_tty
)
539 show_memory_packet_size (&memory_read_packet_config
);
543 get_memory_read_packet_size (void)
545 struct remote_state
*rs
= get_remote_state ();
546 long size
= get_memory_packet_size (&memory_read_packet_config
);
547 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
548 extra buffer size argument before the memory read size can be
549 increased beyond (rs->remote_packet_size). */
550 if (size
> (rs
->remote_packet_size
))
551 size
= (rs
->remote_packet_size
);
556 /* Generic configuration support for packets the stub optionally
557 supports. Allows the user to specify the use of the packet as well
558 as allowing GDB to auto-detect support in the remote stub. */
562 PACKET_SUPPORT_UNKNOWN
= 0,
571 enum auto_boolean detect
;
572 enum packet_support support
;
575 /* Analyze a packet's return value and update the packet config
586 update_packet_config (struct packet_config
*config
)
588 switch (config
->detect
)
590 case AUTO_BOOLEAN_TRUE
:
591 config
->support
= PACKET_ENABLE
;
593 case AUTO_BOOLEAN_FALSE
:
594 config
->support
= PACKET_DISABLE
;
596 case AUTO_BOOLEAN_AUTO
:
597 config
->support
= PACKET_SUPPORT_UNKNOWN
;
603 show_packet_config_cmd (struct packet_config
*config
)
605 char *support
= "internal-error";
606 switch (config
->support
)
612 support
= "disabled";
614 case PACKET_SUPPORT_UNKNOWN
:
618 switch (config
->detect
)
620 case AUTO_BOOLEAN_AUTO
:
621 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
622 config
->name
, config
->title
, support
);
624 case AUTO_BOOLEAN_TRUE
:
625 case AUTO_BOOLEAN_FALSE
:
626 printf_filtered ("Support for remote protocol `%s' (%s) packet is currently %s.\n",
627 config
->name
, config
->title
, support
);
633 add_packet_config_cmd (struct packet_config
*config
,
636 cmd_sfunc_ftype
*set_func
,
637 cmd_sfunc_ftype
*show_func
,
638 struct cmd_list_element
**set_remote_list
,
639 struct cmd_list_element
**show_remote_list
,
642 struct cmd_list_element
*set_cmd
;
643 struct cmd_list_element
*show_cmd
;
650 config
->title
= title
;
651 config
->detect
= AUTO_BOOLEAN_AUTO
;
652 config
->support
= PACKET_SUPPORT_UNKNOWN
;
653 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
655 show_doc
= xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
657 print
= xstrprintf ("Current use of remote protocol `%s' (%s) is %%s",
659 /* set/show TITLE-packet {auto,on,off} */
660 cmd_name
= xstrprintf ("%s-packet", title
);
661 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
662 &config
->detect
, set_doc
, show_doc
,
665 set_remote_list
, show_remote_list
);
666 /* set/show remote NAME-packet {auto,on,off} -- legacy */
670 legacy_name
= xstrprintf ("%s-packet", name
);
671 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
673 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
678 static enum packet_result
679 packet_ok (const char *buf
, struct packet_config
*config
)
683 /* The stub recognized the packet request. Check that the
684 operation succeeded. */
685 switch (config
->support
)
687 case PACKET_SUPPORT_UNKNOWN
:
689 fprintf_unfiltered (gdb_stdlog
,
690 "Packet %s (%s) is supported\n",
691 config
->name
, config
->title
);
692 config
->support
= PACKET_ENABLE
;
695 internal_error (__FILE__
, __LINE__
,
696 "packet_ok: attempt to use a disabled packet");
701 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
702 /* "OK" - definitly OK. */
705 && isxdigit (buf
[1]) && isxdigit (buf
[2])
707 /* "Enn" - definitly an error. */
709 /* The packet may or may not be OK. Just assume it is */
714 /* The stub does not support the packet. */
715 switch (config
->support
)
718 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
719 /* If the stub previously indicated that the packet was
720 supported then there is a protocol error.. */
721 error ("Protocol error: %s (%s) conflicting enabled responses.",
722 config
->name
, config
->title
);
724 /* The user set it wrong. */
725 error ("Enabled packet %s (%s) not recognized by stub",
726 config
->name
, config
->title
);
728 case PACKET_SUPPORT_UNKNOWN
:
730 fprintf_unfiltered (gdb_stdlog
,
731 "Packet %s (%s) is NOT supported\n",
732 config
->name
, config
->title
);
733 config
->support
= PACKET_DISABLE
;
738 return PACKET_UNKNOWN
;
742 /* Should we try the 'vCont' (descriptive resume) request? */
743 static struct packet_config remote_protocol_vcont
;
746 set_remote_protocol_vcont_packet_cmd (char *args
, int from_tty
,
747 struct cmd_list_element
*c
)
749 update_packet_config (&remote_protocol_vcont
);
753 show_remote_protocol_vcont_packet_cmd (char *args
, int from_tty
,
754 struct cmd_list_element
*c
)
756 show_packet_config_cmd (&remote_protocol_vcont
);
759 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
760 static struct packet_config remote_protocol_qSymbol
;
763 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
764 struct cmd_list_element
*c
)
766 update_packet_config (&remote_protocol_qSymbol
);
770 show_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
771 struct cmd_list_element
*c
)
773 show_packet_config_cmd (&remote_protocol_qSymbol
);
776 /* Should we try the 'P' (set register) request? */
778 static struct packet_config remote_protocol_P
;
781 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
782 struct cmd_list_element
*c
)
784 update_packet_config (&remote_protocol_P
);
788 show_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
789 struct cmd_list_element
*c
)
791 show_packet_config_cmd (&remote_protocol_P
);
794 /* Should we try one of the 'Z' requests? */
798 Z_PACKET_SOFTWARE_BP
,
799 Z_PACKET_HARDWARE_BP
,
806 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
808 /* FIXME: Instead of having all these boiler plate functions, the
809 command callback should include a context argument. */
812 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
813 struct cmd_list_element
*c
)
815 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
819 show_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
820 struct cmd_list_element
*c
)
822 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
826 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
827 struct cmd_list_element
*c
)
829 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
833 show_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
834 struct cmd_list_element
*c
)
836 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
840 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
841 struct cmd_list_element
*c
)
843 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
847 show_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
848 struct cmd_list_element
*c
)
850 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
854 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
855 struct cmd_list_element
*c
)
857 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
861 show_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
862 struct cmd_list_element
*c
)
864 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
868 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
869 struct cmd_list_element
*c
)
871 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
875 show_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
876 struct cmd_list_element
*c
)
878 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
881 /* For compatibility with older distributions. Provide a ``set remote
882 Z-packet ...'' command that updates all the Z packet types. */
884 static enum auto_boolean remote_Z_packet_detect
;
887 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
888 struct cmd_list_element
*c
)
891 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
893 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
894 update_packet_config (&remote_protocol_Z
[i
]);
899 show_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
900 struct cmd_list_element
*c
)
903 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
905 show_packet_config_cmd (&remote_protocol_Z
[i
]);
909 /* Should we try the 'X' (remote binary download) packet?
911 This variable (available to the user via "set remote X-packet")
912 dictates whether downloads are sent in binary (via the 'X' packet).
913 We assume that the stub can, and attempt to do it. This will be
914 cleared if the stub does not understand it. This switch is still
915 needed, though in cases when the packet is supported in the stub,
916 but the connection does not allow it (i.e., 7-bit serial connection
919 static struct packet_config remote_protocol_binary_download
;
921 /* Should we try the 'ThreadInfo' query packet?
923 This variable (NOT available to the user: auto-detect only!)
924 determines whether GDB will use the new, simpler "ThreadInfo"
925 query or the older, more complex syntax for thread queries.
926 This is an auto-detect variable (set to true at each connect,
927 and set to false when the target fails to recognize it). */
929 static int use_threadinfo_query
;
930 static int use_threadextra_query
;
933 set_remote_protocol_binary_download_cmd (char *args
,
935 struct cmd_list_element
*c
)
937 update_packet_config (&remote_protocol_binary_download
);
941 show_remote_protocol_binary_download_cmd (char *args
, int from_tty
,
942 struct cmd_list_element
*c
)
944 show_packet_config_cmd (&remote_protocol_binary_download
);
947 /* Should we try the 'qPart:auxv' (target auxiliary vector read) request? */
948 static struct packet_config remote_protocol_qPart_auxv
;
951 set_remote_protocol_qPart_auxv_packet_cmd (char *args
, int from_tty
,
952 struct cmd_list_element
*c
)
954 update_packet_config (&remote_protocol_qPart_auxv
);
958 show_remote_protocol_qPart_auxv_packet_cmd (char *args
, int from_tty
,
959 struct cmd_list_element
*c
)
961 show_packet_config_cmd (&remote_protocol_qPart_auxv
);
964 static struct packet_config remote_protocol_p
;
967 set_remote_protocol_p_packet_cmd (char *args
, int from_tty
,
968 struct cmd_list_element
*c
)
970 update_packet_config (&remote_protocol_p
);
974 show_remote_protocol_p_packet_cmd (char *args
, int from_tty
,
975 struct cmd_list_element
*c
)
977 show_packet_config_cmd (&remote_protocol_p
);
982 /* Tokens for use by the asynchronous signal handlers for SIGINT */
983 static void *sigint_remote_twice_token
;
984 static void *sigint_remote_token
;
986 /* These are pointers to hook functions that may be set in order to
987 modify resume/wait behavior for a particular architecture. */
989 void (*deprecated_target_resume_hook
) (void);
990 void (*deprecated_target_wait_loop_hook
) (void);
994 /* These are the threads which we last sent to the remote system.
995 -1 for all or -2 for not sent yet. */
996 static int general_thread
;
997 static int continue_thread
;
999 /* Call this function as a result of
1000 1) A halt indication (T packet) containing a thread id
1001 2) A direct query of currthread
1002 3) Successful execution of set thread
1006 record_currthread (int currthread
)
1008 general_thread
= currthread
;
1010 /* If this is a new thread, add it to GDB's thread list.
1011 If we leave it up to WFI to do this, bad things will happen. */
1012 if (!in_thread_list (pid_to_ptid (currthread
)))
1014 add_thread (pid_to_ptid (currthread
));
1015 ui_out_text (uiout
, "[New ");
1016 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
1017 ui_out_text (uiout
, "]\n");
1021 #define MAGIC_NULL_PID 42000
1024 set_thread (int th
, int gen
)
1026 struct remote_state
*rs
= get_remote_state ();
1027 char *buf
= alloca (rs
->remote_packet_size
);
1028 int state
= gen
? general_thread
: continue_thread
;
1034 buf
[1] = gen
? 'g' : 'c';
1035 if (th
== MAGIC_NULL_PID
)
1041 sprintf (&buf
[2], "-%x", -th
);
1043 sprintf (&buf
[2], "%x", th
);
1045 getpkt (buf
, (rs
->remote_packet_size
), 0);
1047 general_thread
= th
;
1049 continue_thread
= th
;
1052 /* Return nonzero if the thread TH is still alive on the remote system. */
1055 remote_thread_alive (ptid_t ptid
)
1057 int tid
= PIDGET (ptid
);
1061 sprintf (buf
, "T-%08x", -tid
);
1063 sprintf (buf
, "T%08x", tid
);
1065 getpkt (buf
, sizeof (buf
), 0);
1066 return (buf
[0] == 'O' && buf
[1] == 'K');
1069 /* About these extended threadlist and threadinfo packets. They are
1070 variable length packets but, the fields within them are often fixed
1071 length. They are redundent enough to send over UDP as is the
1072 remote protocol in general. There is a matching unit test module
1075 #define OPAQUETHREADBYTES 8
1077 /* a 64 bit opaque identifier */
1078 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1080 /* WARNING: This threadref data structure comes from the remote O.S., libstub
1081 protocol encoding, and remote.c. it is not particularly changable */
1083 /* Right now, the internal structure is int. We want it to be bigger.
1087 typedef int gdb_threadref
; /* internal GDB thread reference */
1089 /* gdb_ext_thread_info is an internal GDB data structure which is
1090 equivalint to the reply of the remote threadinfo packet */
1092 struct gdb_ext_thread_info
1094 threadref threadid
; /* External form of thread reference */
1095 int active
; /* Has state interesting to GDB? , regs, stack */
1096 char display
[256]; /* Brief state display, name, blocked/syspended */
1097 char shortname
[32]; /* To be used to name threads */
1098 char more_display
[256]; /* Long info, statistics, queue depth, whatever */
1101 /* The volume of remote transfers can be limited by submitting
1102 a mask containing bits specifying the desired information.
1103 Use a union of these values as the 'selection' parameter to
1104 get_thread_info. FIXME: Make these TAG names more thread specific.
1107 #define TAG_THREADID 1
1108 #define TAG_EXISTS 2
1109 #define TAG_DISPLAY 4
1110 #define TAG_THREADNAME 8
1111 #define TAG_MOREDISPLAY 16
1113 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
1115 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1117 static char *unpack_nibble (char *buf
, int *val
);
1119 static char *pack_nibble (char *buf
, int nibble
);
1121 static char *pack_hex_byte (char *pkt
, int /*unsigned char */ byte
);
1123 static char *unpack_byte (char *buf
, int *value
);
1125 static char *pack_int (char *buf
, int value
);
1127 static char *unpack_int (char *buf
, int *value
);
1129 static char *unpack_string (char *src
, char *dest
, int length
);
1131 static char *pack_threadid (char *pkt
, threadref
* id
);
1133 static char *unpack_threadid (char *inbuf
, threadref
* id
);
1135 void int_to_threadref (threadref
* id
, int value
);
1137 static int threadref_to_int (threadref
* ref
);
1139 static void copy_threadref (threadref
* dest
, threadref
* src
);
1141 static int threadmatch (threadref
* dest
, threadref
* src
);
1143 static char *pack_threadinfo_request (char *pkt
, int mode
, threadref
* id
);
1145 static int remote_unpack_thread_info_response (char *pkt
,
1146 threadref
* expectedref
,
1147 struct gdb_ext_thread_info
1151 static int remote_get_threadinfo (threadref
* threadid
, int fieldset
, /*TAG mask */
1152 struct gdb_ext_thread_info
*info
);
1154 static char *pack_threadlist_request (char *pkt
, int startflag
,
1156 threadref
* nextthread
);
1158 static int parse_threadlist_response (char *pkt
,
1160 threadref
* original_echo
,
1161 threadref
* resultlist
, int *doneflag
);
1163 static int remote_get_threadlist (int startflag
,
1164 threadref
* nextthread
,
1167 int *result_count
, threadref
* threadlist
);
1169 typedef int (*rmt_thread_action
) (threadref
* ref
, void *context
);
1171 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1172 void *context
, int looplimit
);
1174 static int remote_newthread_step (threadref
* ref
, void *context
);
1176 /* encode 64 bits in 16 chars of hex */
1178 static const char hexchars
[] = "0123456789abcdef";
1181 ishex (int ch
, int *val
)
1183 if ((ch
>= 'a') && (ch
<= 'f'))
1185 *val
= ch
- 'a' + 10;
1188 if ((ch
>= 'A') && (ch
<= 'F'))
1190 *val
= ch
- 'A' + 10;
1193 if ((ch
>= '0') && (ch
<= '9'))
1204 if (ch
>= 'a' && ch
<= 'f')
1205 return ch
- 'a' + 10;
1206 if (ch
>= '0' && ch
<= '9')
1208 if (ch
>= 'A' && ch
<= 'F')
1209 return ch
- 'A' + 10;
1214 stub_unpack_int (char *buff
, int fieldlength
)
1221 nibble
= stubhex (*buff
++);
1225 retval
= retval
<< 4;
1231 unpack_varlen_hex (char *buff
, /* packet to parse */
1237 while (ishex (*buff
, &nibble
))
1240 retval
= retval
<< 4;
1241 retval
|= nibble
& 0x0f;
1248 unpack_nibble (char *buf
, int *val
)
1250 ishex (*buf
++, val
);
1255 pack_nibble (char *buf
, int nibble
)
1257 *buf
++ = hexchars
[(nibble
& 0x0f)];
1262 pack_hex_byte (char *pkt
, int byte
)
1264 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1265 *pkt
++ = hexchars
[(byte
& 0xf)];
1270 unpack_byte (char *buf
, int *value
)
1272 *value
= stub_unpack_int (buf
, 2);
1277 pack_int (char *buf
, int value
)
1279 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1280 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1281 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1282 buf
= pack_hex_byte (buf
, (value
& 0xff));
1287 unpack_int (char *buf
, int *value
)
1289 *value
= stub_unpack_int (buf
, 8);
1293 #if 0 /* currently unused, uncomment when needed */
1294 static char *pack_string (char *pkt
, char *string
);
1297 pack_string (char *pkt
, char *string
)
1302 len
= strlen (string
);
1304 len
= 200; /* Bigger than most GDB packets, junk??? */
1305 pkt
= pack_hex_byte (pkt
, len
);
1309 if ((ch
== '\0') || (ch
== '#'))
1310 ch
= '*'; /* Protect encapsulation */
1315 #endif /* 0 (unused) */
1318 unpack_string (char *src
, char *dest
, int length
)
1327 pack_threadid (char *pkt
, threadref
*id
)
1330 unsigned char *altid
;
1332 altid
= (unsigned char *) id
;
1333 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1335 pkt
= pack_hex_byte (pkt
, *altid
++);
1341 unpack_threadid (char *inbuf
, threadref
*id
)
1344 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1347 altref
= (char *) id
;
1349 while (inbuf
< limit
)
1351 x
= stubhex (*inbuf
++);
1352 y
= stubhex (*inbuf
++);
1353 *altref
++ = (x
<< 4) | y
;
1358 /* Externally, threadrefs are 64 bits but internally, they are still
1359 ints. This is due to a mismatch of specifications. We would like
1360 to use 64bit thread references internally. This is an adapter
1364 int_to_threadref (threadref
*id
, int value
)
1366 unsigned char *scan
;
1368 scan
= (unsigned char *) id
;
1374 *scan
++ = (value
>> 24) & 0xff;
1375 *scan
++ = (value
>> 16) & 0xff;
1376 *scan
++ = (value
>> 8) & 0xff;
1377 *scan
++ = (value
& 0xff);
1381 threadref_to_int (threadref
*ref
)
1384 unsigned char *scan
;
1386 scan
= (char *) ref
;
1390 value
= (value
<< 8) | ((*scan
++) & 0xff);
1395 copy_threadref (threadref
*dest
, threadref
*src
)
1398 unsigned char *csrc
, *cdest
;
1400 csrc
= (unsigned char *) src
;
1401 cdest
= (unsigned char *) dest
;
1408 threadmatch (threadref
*dest
, threadref
*src
)
1410 /* things are broken right now, so just assume we got a match */
1412 unsigned char *srcp
, *destp
;
1414 srcp
= (char *) src
;
1415 destp
= (char *) dest
;
1419 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1426 threadid:1, # always request threadid
1433 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1436 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1438 *pkt
++ = 'q'; /* Info Query */
1439 *pkt
++ = 'P'; /* process or thread info */
1440 pkt
= pack_int (pkt
, mode
); /* mode */
1441 pkt
= pack_threadid (pkt
, id
); /* threadid */
1442 *pkt
= '\0'; /* terminate */
1446 /* These values tag the fields in a thread info response packet */
1447 /* Tagging the fields allows us to request specific fields and to
1448 add more fields as time goes by */
1450 #define TAG_THREADID 1 /* Echo the thread identifier */
1451 #define TAG_EXISTS 2 /* Is this process defined enough to
1452 fetch registers and its stack */
1453 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1454 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1455 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1459 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1460 struct gdb_ext_thread_info
*info
)
1462 struct remote_state
*rs
= get_remote_state ();
1466 char *limit
= pkt
+ (rs
->remote_packet_size
); /* plausable parsing limit */
1469 /* info->threadid = 0; FIXME: implement zero_threadref */
1471 info
->display
[0] = '\0';
1472 info
->shortname
[0] = '\0';
1473 info
->more_display
[0] = '\0';
1475 /* Assume the characters indicating the packet type have been stripped */
1476 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1477 pkt
= unpack_threadid (pkt
, &ref
);
1480 warning ("Incomplete response to threadinfo request\n");
1481 if (!threadmatch (&ref
, expectedref
))
1482 { /* This is an answer to a different request */
1483 warning ("ERROR RMT Thread info mismatch\n");
1486 copy_threadref (&info
->threadid
, &ref
);
1488 /* Loop on tagged fields , try to bail if somthing goes wrong */
1490 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1492 pkt
= unpack_int (pkt
, &tag
); /* tag */
1493 pkt
= unpack_byte (pkt
, &length
); /* length */
1494 if (!(tag
& mask
)) /* tags out of synch with mask */
1496 warning ("ERROR RMT: threadinfo tag mismatch\n");
1500 if (tag
== TAG_THREADID
)
1504 warning ("ERROR RMT: length of threadid is not 16\n");
1508 pkt
= unpack_threadid (pkt
, &ref
);
1509 mask
= mask
& ~TAG_THREADID
;
1512 if (tag
== TAG_EXISTS
)
1514 info
->active
= stub_unpack_int (pkt
, length
);
1516 mask
= mask
& ~(TAG_EXISTS
);
1519 warning ("ERROR RMT: 'exists' length too long\n");
1525 if (tag
== TAG_THREADNAME
)
1527 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1528 mask
= mask
& ~TAG_THREADNAME
;
1531 if (tag
== TAG_DISPLAY
)
1533 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1534 mask
= mask
& ~TAG_DISPLAY
;
1537 if (tag
== TAG_MOREDISPLAY
)
1539 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1540 mask
= mask
& ~TAG_MOREDISPLAY
;
1543 warning ("ERROR RMT: unknown thread info tag\n");
1544 break; /* Not a tag we know about */
1550 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1551 struct gdb_ext_thread_info
*info
)
1553 struct remote_state
*rs
= get_remote_state ();
1555 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1557 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1558 putpkt (threadinfo_pkt
);
1559 getpkt (threadinfo_pkt
, (rs
->remote_packet_size
), 0);
1560 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
,
1565 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1568 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1569 threadref
*nextthread
)
1571 *pkt
++ = 'q'; /* info query packet */
1572 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1573 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1574 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1575 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1580 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1583 parse_threadlist_response (char *pkt
, int result_limit
,
1584 threadref
*original_echo
, threadref
*resultlist
,
1587 struct remote_state
*rs
= get_remote_state ();
1589 int count
, resultcount
, done
;
1592 /* Assume the 'q' and 'M chars have been stripped. */
1593 limit
= pkt
+ ((rs
->remote_packet_size
) - BUF_THREAD_ID_SIZE
); /* done parse past here */
1594 pkt
= unpack_byte (pkt
, &count
); /* count field */
1595 pkt
= unpack_nibble (pkt
, &done
);
1596 /* The first threadid is the argument threadid. */
1597 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1598 while ((count
-- > 0) && (pkt
< limit
))
1600 pkt
= unpack_threadid (pkt
, resultlist
++);
1601 if (resultcount
++ >= result_limit
)
1610 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1611 int *done
, int *result_count
, threadref
*threadlist
)
1613 struct remote_state
*rs
= get_remote_state ();
1614 static threadref echo_nextthread
;
1615 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1616 char *t_response
= alloca (rs
->remote_packet_size
);
1619 /* Trancate result limit to be smaller than the packet size */
1620 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= (rs
->remote_packet_size
))
1621 result_limit
= ((rs
->remote_packet_size
) / BUF_THREAD_ID_SIZE
) - 2;
1623 pack_threadlist_request (threadlist_packet
,
1624 startflag
, result_limit
, nextthread
);
1625 putpkt (threadlist_packet
);
1626 getpkt (t_response
, (rs
->remote_packet_size
), 0);
1629 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1632 if (!threadmatch (&echo_nextthread
, nextthread
))
1634 /* FIXME: This is a good reason to drop the packet */
1635 /* Possably, there is a duplicate response */
1637 retransmit immediatly - race conditions
1638 retransmit after timeout - yes
1640 wait for packet, then exit
1642 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1643 return 0; /* I choose simply exiting */
1645 if (*result_count
<= 0)
1649 warning ("RMT ERROR : failed to get remote thread list\n");
1652 return result
; /* break; */
1654 if (*result_count
> result_limit
)
1657 warning ("RMT ERROR: threadlist response longer than requested\n");
1663 /* This is the interface between remote and threads, remotes upper interface */
1665 /* remote_find_new_threads retrieves the thread list and for each
1666 thread in the list, looks up the thread in GDB's internal list,
1667 ading the thread if it does not already exist. This involves
1668 getting partial thread lists from the remote target so, polling the
1669 quit_flag is required. */
1672 /* About this many threadisds fit in a packet. */
1674 #define MAXTHREADLISTRESULTS 32
1677 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1680 int done
, i
, result_count
;
1684 static threadref nextthread
;
1685 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1690 if (loopcount
++ > looplimit
)
1693 warning ("Remote fetch threadlist -infinite loop-\n");
1696 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1697 &done
, &result_count
, resultthreadlist
))
1702 /* clear for later iterations */
1704 /* Setup to resume next batch of thread references, set nextthread. */
1705 if (result_count
>= 1)
1706 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1708 while (result_count
--)
1709 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1716 remote_newthread_step (threadref
*ref
, void *context
)
1720 ptid
= pid_to_ptid (threadref_to_int (ref
));
1722 if (!in_thread_list (ptid
))
1724 return 1; /* continue iterator */
1727 #define CRAZY_MAX_THREADS 1000
1730 remote_current_thread (ptid_t oldpid
)
1732 struct remote_state
*rs
= get_remote_state ();
1733 char *buf
= alloca (rs
->remote_packet_size
);
1736 getpkt (buf
, (rs
->remote_packet_size
), 0);
1737 if (buf
[0] == 'Q' && buf
[1] == 'C')
1738 return pid_to_ptid (strtol (&buf
[2], NULL
, 16));
1743 /* Find new threads for info threads command.
1744 * Original version, using John Metzler's thread protocol.
1748 remote_find_new_threads (void)
1750 remote_threadlist_iterator (remote_newthread_step
, 0,
1752 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1753 inferior_ptid
= remote_current_thread (inferior_ptid
);
1757 * Find all threads for info threads command.
1758 * Uses new thread protocol contributed by Cisco.
1759 * Falls back and attempts to use the older method (above)
1760 * if the target doesn't respond to the new method.
1764 remote_threads_info (void)
1766 struct remote_state
*rs
= get_remote_state ();
1767 char *buf
= alloca (rs
->remote_packet_size
);
1771 if (remote_desc
== 0) /* paranoia */
1772 error ("Command can only be used when connected to the remote target.");
1774 if (use_threadinfo_query
)
1776 putpkt ("qfThreadInfo");
1778 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1779 if (bufp
[0] != '\0') /* q packet recognized */
1781 while (*bufp
++ == 'm') /* reply contains one or more TID */
1785 tid
= strtol (bufp
, &bufp
, 16);
1786 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1787 add_thread (pid_to_ptid (tid
));
1789 while (*bufp
++ == ','); /* comma-separated list */
1790 putpkt ("qsThreadInfo");
1792 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1798 /* Else fall back to old method based on jmetzler protocol. */
1799 use_threadinfo_query
= 0;
1800 remote_find_new_threads ();
1805 * Collect a descriptive string about the given thread.
1806 * The target may say anything it wants to about the thread
1807 * (typically info about its blocked / runnable state, name, etc.).
1808 * This string will appear in the info threads display.
1810 * Optional: targets are not required to implement this function.
1814 remote_threads_extra_info (struct thread_info
*tp
)
1816 struct remote_state
*rs
= get_remote_state ();
1820 struct gdb_ext_thread_info threadinfo
;
1821 static char display_buf
[100]; /* arbitrary... */
1822 char *bufp
= alloca (rs
->remote_packet_size
);
1823 int n
= 0; /* position in display_buf */
1825 if (remote_desc
== 0) /* paranoia */
1826 internal_error (__FILE__
, __LINE__
,
1827 "remote_threads_extra_info");
1829 if (use_threadextra_query
)
1831 sprintf (bufp
, "qThreadExtraInfo,%x", PIDGET (tp
->ptid
));
1833 getpkt (bufp
, (rs
->remote_packet_size
), 0);
1836 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1837 result
= hex2bin (bufp
, display_buf
, n
);
1838 display_buf
[result
] = '\0';
1843 /* If the above query fails, fall back to the old method. */
1844 use_threadextra_query
= 0;
1845 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1846 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1847 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1848 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1849 if (threadinfo
.active
)
1851 if (*threadinfo
.shortname
)
1852 n
+= sprintf(&display_buf
[0], " Name: %s,", threadinfo
.shortname
);
1853 if (*threadinfo
.display
)
1854 n
+= sprintf(&display_buf
[n
], " State: %s,", threadinfo
.display
);
1855 if (*threadinfo
.more_display
)
1856 n
+= sprintf(&display_buf
[n
], " Priority: %s",
1857 threadinfo
.more_display
);
1861 /* for purely cosmetic reasons, clear up trailing commas */
1862 if (',' == display_buf
[n
-1])
1863 display_buf
[n
-1] = ' ';
1872 /* Restart the remote side; this is an extended protocol operation. */
1875 extended_remote_restart (void)
1877 struct remote_state
*rs
= get_remote_state ();
1878 char *buf
= alloca (rs
->remote_packet_size
);
1880 /* Send the restart command; for reasons I don't understand the
1881 remote side really expects a number after the "R". */
1883 sprintf (&buf
[1], "%x", 0);
1886 /* Now query for status so this looks just like we restarted
1887 gdbserver from scratch. */
1889 getpkt (buf
, (rs
->remote_packet_size
), 0);
1892 /* Clean up connection to a remote debugger. */
1895 remote_close (int quitting
)
1898 serial_close (remote_desc
);
1902 /* Query the remote side for the text, data and bss offsets. */
1907 struct remote_state
*rs
= get_remote_state ();
1908 char *buf
= alloca (rs
->remote_packet_size
);
1911 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1912 struct section_offsets
*offs
;
1914 putpkt ("qOffsets");
1916 getpkt (buf
, (rs
->remote_packet_size
), 0);
1918 if (buf
[0] == '\000')
1919 return; /* Return silently. Stub doesn't support
1923 warning ("Remote failure reply: %s", buf
);
1927 /* Pick up each field in turn. This used to be done with scanf, but
1928 scanf will make trouble if CORE_ADDR size doesn't match
1929 conversion directives correctly. The following code will work
1930 with any size of CORE_ADDR. */
1931 text_addr
= data_addr
= bss_addr
= 0;
1935 if (strncmp (ptr
, "Text=", 5) == 0)
1938 /* Don't use strtol, could lose on big values. */
1939 while (*ptr
&& *ptr
!= ';')
1940 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1945 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1948 while (*ptr
&& *ptr
!= ';')
1949 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1954 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1957 while (*ptr
&& *ptr
!= ';')
1958 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1964 error ("Malformed response to offset query, %s", buf
);
1966 if (symfile_objfile
== NULL
)
1969 offs
= ((struct section_offsets
*)
1970 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
1971 memcpy (offs
, symfile_objfile
->section_offsets
,
1972 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
1974 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
1976 /* This is a temporary kludge to force data and bss to use the same offsets
1977 because that's what nlmconv does now. The real solution requires changes
1978 to the stub and remote.c that I don't have time to do right now. */
1980 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
1981 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
1983 objfile_relocate (symfile_objfile
, offs
);
1986 /* Stub for catch_errors. */
1989 remote_start_remote_dummy (struct ui_out
*uiout
, void *dummy
)
1991 start_remote (); /* Initialize gdb process mechanisms */
1992 /* NOTE: Return something >=0. A -ve value is reserved for
1993 catch_exceptions. */
1998 remote_start_remote (struct ui_out
*uiout
, void *dummy
)
2000 immediate_quit
++; /* Allow user to interrupt it */
2002 /* Ack any packet which the remote side has already sent. */
2003 serial_write (remote_desc
, "+", 1);
2005 /* Let the stub know that we want it to return the thread. */
2008 inferior_ptid
= remote_current_thread (inferior_ptid
);
2010 get_offsets (); /* Get text, data & bss offsets */
2012 putpkt ("?"); /* initiate a query from remote machine */
2015 /* NOTE: See comment above in remote_start_remote_dummy(). This
2016 function returns something >=0. */
2017 return remote_start_remote_dummy (uiout
, dummy
);
2020 /* Open a connection to a remote debugger.
2021 NAME is the filename used for communication. */
2024 remote_open (char *name
, int from_tty
)
2026 remote_open_1 (name
, from_tty
, &remote_ops
, 0, 0);
2029 /* Just like remote_open, but with asynchronous support. */
2031 remote_async_open (char *name
, int from_tty
)
2033 remote_open_1 (name
, from_tty
, &remote_async_ops
, 0, 1);
2036 /* Open a connection to a remote debugger using the extended
2037 remote gdb protocol. NAME is the filename used for communication. */
2040 extended_remote_open (char *name
, int from_tty
)
2042 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */,
2046 /* Just like extended_remote_open, but with asynchronous support. */
2048 extended_remote_async_open (char *name
, int from_tty
)
2050 remote_open_1 (name
, from_tty
, &extended_async_remote_ops
,
2051 1 /*extended_p */, 1 /* async_p */);
2054 /* Generic code for opening a connection to a remote target. */
2057 init_all_packet_configs (void)
2060 update_packet_config (&remote_protocol_P
);
2061 update_packet_config (&remote_protocol_p
);
2062 update_packet_config (&remote_protocol_qSymbol
);
2063 update_packet_config (&remote_protocol_vcont
);
2064 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2065 update_packet_config (&remote_protocol_Z
[i
]);
2066 /* Force remote_write_bytes to check whether target supports binary
2068 update_packet_config (&remote_protocol_binary_download
);
2069 update_packet_config (&remote_protocol_qPart_auxv
);
2072 /* Symbol look-up. */
2075 remote_check_symbols (struct objfile
*objfile
)
2077 struct remote_state
*rs
= get_remote_state ();
2078 char *msg
, *reply
, *tmp
;
2079 struct minimal_symbol
*sym
;
2082 if (remote_protocol_qSymbol
.support
== PACKET_DISABLE
)
2085 msg
= alloca (rs
->remote_packet_size
);
2086 reply
= alloca (rs
->remote_packet_size
);
2088 /* Invite target to request symbol lookups. */
2090 putpkt ("qSymbol::");
2091 getpkt (reply
, (rs
->remote_packet_size
), 0);
2092 packet_ok (reply
, &remote_protocol_qSymbol
);
2094 while (strncmp (reply
, "qSymbol:", 8) == 0)
2097 end
= hex2bin (tmp
, msg
, strlen (tmp
) / 2);
2099 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2101 sprintf (msg
, "qSymbol::%s", &reply
[8]);
2103 sprintf (msg
, "qSymbol:%s:%s",
2104 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2107 getpkt (reply
, (rs
->remote_packet_size
), 0);
2111 static struct serial
*
2112 remote_serial_open (char *name
)
2114 static int udp_warning
= 0;
2116 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2117 of in ser-tcp.c, because it is the remote protocol assuming that the
2118 serial connection is reliable and not the serial connection promising
2120 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2122 warning ("The remote protocol may be unreliable over UDP.");
2123 warning ("Some events may be lost, rendering further debugging "
2128 return serial_open (name
);
2132 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2133 int extended_p
, int async_p
)
2136 struct remote_state
*rs
= get_remote_state ();
2138 error ("To open a remote debug connection, you need to specify what\n"
2139 "serial device is attached to the remote system\n"
2140 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2142 /* See FIXME above */
2144 wait_forever_enabled_p
= 1;
2146 reopen_exec_file ();
2149 target_preopen (from_tty
);
2151 unpush_target (target
);
2153 remote_desc
= remote_serial_open (name
);
2155 perror_with_name (name
);
2157 if (baud_rate
!= -1)
2159 if (serial_setbaudrate (remote_desc
, baud_rate
))
2161 /* The requested speed could not be set. Error out to
2162 top level after closing remote_desc. Take care to
2163 set remote_desc to NULL to avoid closing remote_desc
2165 serial_close (remote_desc
);
2167 perror_with_name (name
);
2171 serial_raw (remote_desc
);
2173 /* If there is something sitting in the buffer we might take it as a
2174 response to a command, which would be bad. */
2175 serial_flush_input (remote_desc
);
2179 puts_filtered ("Remote debugging using ");
2180 puts_filtered (name
);
2181 puts_filtered ("\n");
2183 push_target (target
); /* Switch to using remote target now */
2185 init_all_packet_configs ();
2187 general_thread
= -2;
2188 continue_thread
= -2;
2190 /* Probe for ability to use "ThreadInfo" query, as required. */
2191 use_threadinfo_query
= 1;
2192 use_threadextra_query
= 1;
2194 /* Without this, some commands which require an active target (such
2195 as kill) won't work. This variable serves (at least) double duty
2196 as both the pid of the target process (if it has such), and as a
2197 flag indicating that a target is active. These functions should
2198 be split out into seperate variables, especially since GDB will
2199 someday have a notion of debugging several processes. */
2201 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2205 /* With this target we start out by owning the terminal. */
2206 remote_async_terminal_ours_p
= 1;
2208 /* FIXME: cagney/1999-09-23: During the initial connection it is
2209 assumed that the target is already ready and able to respond to
2210 requests. Unfortunately remote_start_remote() eventually calls
2211 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2212 around this. Eventually a mechanism that allows
2213 wait_for_inferior() to expect/get timeouts will be
2215 wait_forever_enabled_p
= 0;
2218 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2219 /* First delete any symbols previously loaded from shared libraries. */
2220 no_shared_libraries (NULL
, 0);
2223 /* Start the remote connection. If error() or QUIT, discard this
2224 target (we'd otherwise be in an inconsistent state) and then
2225 propogate the error on up the exception chain. This ensures that
2226 the caller doesn't stumble along blindly assuming that the
2227 function succeeded. The CLI doesn't have this problem but other
2228 UI's, such as MI do.
2230 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2231 this function should return an error indication letting the
2232 caller restore the previous state. Unfortunately the command
2233 ``target remote'' is directly wired to this function making that
2234 impossible. On a positive note, the CLI side of this problem has
2235 been fixed - the function set_cmd_context() makes it possible for
2236 all the ``target ....'' commands to share a common callback
2237 function. See cli-dump.c. */
2238 ex
= catch_exceptions (uiout
,
2239 remote_start_remote
, NULL
,
2240 "Couldn't establish connection to remote"
2247 wait_forever_enabled_p
= 1;
2248 throw_exception (ex
);
2252 wait_forever_enabled_p
= 1;
2256 /* Tell the remote that we are using the extended protocol. */
2257 char *buf
= alloca (rs
->remote_packet_size
);
2259 getpkt (buf
, (rs
->remote_packet_size
), 0);
2261 #ifdef SOLIB_CREATE_INFERIOR_HOOK
2262 /* FIXME: need a master target_open vector from which all
2263 remote_opens can be called, so that stuff like this can
2264 go there. Failing that, the following code must be copied
2265 to the open function for any remote target that wants to
2266 support svr4 shared libraries. */
2268 /* Set up to detect and load shared libraries. */
2269 if (exec_bfd
) /* No use without an exec file. */
2271 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
2272 remote_check_symbols (symfile_objfile
);
2277 /* This takes a program previously attached to and detaches it. After
2278 this is done, GDB can be used to debug some other program. We
2279 better not have left any breakpoints in the target program or it'll
2280 die when it hits one. */
2283 remote_detach (char *args
, int from_tty
)
2285 struct remote_state
*rs
= get_remote_state ();
2286 char *buf
= alloca (rs
->remote_packet_size
);
2289 error ("Argument given to \"detach\" when remotely debugging.");
2291 /* Tell the remote target to detach. */
2293 remote_send (buf
, (rs
->remote_packet_size
));
2295 /* Unregister the file descriptor from the event loop. */
2296 if (target_is_async_p ())
2297 serial_async (remote_desc
, NULL
, 0);
2299 target_mourn_inferior ();
2301 puts_filtered ("Ending remote debugging.\n");
2304 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
2307 remote_disconnect (char *args
, int from_tty
)
2309 struct remote_state
*rs
= get_remote_state ();
2310 char *buf
= alloca (rs
->remote_packet_size
);
2313 error ("Argument given to \"detach\" when remotely debugging.");
2315 /* Unregister the file descriptor from the event loop. */
2316 if (target_is_async_p ())
2317 serial_async (remote_desc
, NULL
, 0);
2319 target_mourn_inferior ();
2321 puts_filtered ("Ending remote debugging.\n");
2324 /* Convert hex digit A to a number. */
2329 if (a
>= '0' && a
<= '9')
2331 else if (a
>= 'a' && a
<= 'f')
2332 return a
- 'a' + 10;
2333 else if (a
>= 'A' && a
<= 'F')
2334 return a
- 'A' + 10;
2336 error ("Reply contains invalid hex digit %d", a
);
2340 hex2bin (const char *hex
, char *bin
, int count
)
2344 for (i
= 0; i
< count
; i
++)
2346 if (hex
[0] == 0 || hex
[1] == 0)
2348 /* Hex string is short, or of uneven length.
2349 Return the count that has been converted so far. */
2352 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2358 /* Convert number NIB to a hex digit. */
2366 return 'a' + nib
- 10;
2370 bin2hex (const char *bin
, char *hex
, int count
)
2373 /* May use a length, or a nul-terminated string as input. */
2375 count
= strlen (bin
);
2377 for (i
= 0; i
< count
; i
++)
2379 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2380 *hex
++ = tohex (*bin
++ & 0xf);
2386 /* Check for the availability of vCont. This function should also check
2390 remote_vcont_probe (struct remote_state
*rs
, char *buf
)
2392 strcpy (buf
, "vCont?");
2394 getpkt (buf
, rs
->remote_packet_size
, 0);
2396 /* Make sure that the features we assume are supported. */
2397 if (strncmp (buf
, "vCont", 5) == 0)
2400 int support_s
, support_S
, support_c
, support_C
;
2406 while (p
&& *p
== ';')
2409 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2411 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2413 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2415 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2418 p
= strchr (p
, ';');
2421 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
2422 BUF will make packet_ok disable the packet. */
2423 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
2427 packet_ok (buf
, &remote_protocol_vcont
);
2430 /* Resume the remote inferior by using a "vCont" packet. The thread
2431 to be resumed is PTID; STEP and SIGGNAL indicate whether the
2432 resumed thread should be single-stepped and/or signalled. If PTID's
2433 PID is -1, then all threads are resumed; the thread to be stepped and/or
2434 signalled is given in the global INFERIOR_PTID. This function returns
2435 non-zero iff it resumes the inferior.
2437 This function issues a strict subset of all possible vCont commands at the
2441 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2443 struct remote_state
*rs
= get_remote_state ();
2444 int pid
= PIDGET (ptid
);
2445 char *buf
= NULL
, *outbuf
;
2446 struct cleanup
*old_cleanup
;
2448 buf
= xmalloc (rs
->remote_packet_size
);
2449 old_cleanup
= make_cleanup (xfree
, buf
);
2451 if (remote_protocol_vcont
.support
== PACKET_SUPPORT_UNKNOWN
)
2452 remote_vcont_probe (rs
, buf
);
2454 if (remote_protocol_vcont
.support
== PACKET_DISABLE
)
2456 do_cleanups (old_cleanup
);
2460 /* If we could generate a wider range of packets, we'd have to worry
2461 about overflowing BUF. Should there be a generic
2462 "multi-part-packet" packet? */
2464 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
)
2466 /* MAGIC_NULL_PTID means that we don't have any active threads, so we
2467 don't have any PID numbers the inferior will understand. Make sure
2468 to only send forms that do not specify a PID. */
2469 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2470 outbuf
= xstrprintf ("vCont;S%02x", siggnal
);
2472 outbuf
= xstrprintf ("vCont;s");
2473 else if (siggnal
!= TARGET_SIGNAL_0
)
2474 outbuf
= xstrprintf ("vCont;C%02x", siggnal
);
2476 outbuf
= xstrprintf ("vCont;c");
2480 /* Resume all threads, with preference for INFERIOR_PTID. */
2481 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2482 outbuf
= xstrprintf ("vCont;S%02x:%x;c", siggnal
,
2483 PIDGET (inferior_ptid
));
2485 outbuf
= xstrprintf ("vCont;s:%x;c", PIDGET (inferior_ptid
));
2486 else if (siggnal
!= TARGET_SIGNAL_0
)
2487 outbuf
= xstrprintf ("vCont;C%02x:%x;c", siggnal
,
2488 PIDGET (inferior_ptid
));
2490 outbuf
= xstrprintf ("vCont;c");
2494 /* Scheduler locking; resume only PTID. */
2495 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2496 outbuf
= xstrprintf ("vCont;S%02x:%x", siggnal
, pid
);
2498 outbuf
= xstrprintf ("vCont;s:%x", pid
);
2499 else if (siggnal
!= TARGET_SIGNAL_0
)
2500 outbuf
= xstrprintf ("vCont;C%02x:%x", siggnal
, pid
);
2502 outbuf
= xstrprintf ("vCont;c:%x", pid
);
2505 gdb_assert (outbuf
&& strlen (outbuf
) < rs
->remote_packet_size
);
2506 make_cleanup (xfree
, outbuf
);
2510 do_cleanups (old_cleanup
);
2515 /* Tell the remote machine to resume. */
2517 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2519 static int last_sent_step
;
2522 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2524 struct remote_state
*rs
= get_remote_state ();
2525 char *buf
= alloca (rs
->remote_packet_size
);
2526 int pid
= PIDGET (ptid
);
2529 last_sent_signal
= siggnal
;
2530 last_sent_step
= step
;
2532 /* A hook for when we need to do something at the last moment before
2534 if (deprecated_target_resume_hook
)
2535 (*deprecated_target_resume_hook
) ();
2537 /* The vCont packet doesn't need to specify threads via Hc. */
2538 if (remote_vcont_resume (ptid
, step
, siggnal
))
2541 /* All other supported resume packets do use Hc, so call set_thread. */
2543 set_thread (0, 0); /* run any thread */
2545 set_thread (pid
, 0); /* run this thread */
2547 if (siggnal
!= TARGET_SIGNAL_0
)
2549 buf
[0] = step
? 'S' : 'C';
2550 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2551 buf
[2] = tohex (((int) siggnal
) & 0xf);
2555 strcpy (buf
, step
? "s" : "c");
2560 /* Same as remote_resume, but with async support. */
2562 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2564 remote_resume (ptid
, step
, siggnal
);
2566 /* We are about to start executing the inferior, let's register it
2567 with the event loop. NOTE: this is the one place where all the
2568 execution commands end up. We could alternatively do this in each
2569 of the execution commands in infcmd.c.*/
2570 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2571 into infcmd.c in order to allow inferior function calls to work
2572 NOT asynchronously. */
2573 if (target_can_async_p ())
2574 target_async (inferior_event_handler
, 0);
2575 /* Tell the world that the target is now executing. */
2576 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2577 this? Instead, should the client of target just assume (for
2578 async targets) that the target is going to start executing? Is
2579 this information already found in the continuation block? */
2580 if (target_is_async_p ())
2581 target_executing
= 1;
2585 /* Set up the signal handler for SIGINT, while the target is
2586 executing, ovewriting the 'regular' SIGINT signal handler. */
2588 initialize_sigint_signal_handler (void)
2590 sigint_remote_token
=
2591 create_async_signal_handler (async_remote_interrupt
, NULL
);
2592 signal (SIGINT
, handle_remote_sigint
);
2595 /* Signal handler for SIGINT, while the target is executing. */
2597 handle_remote_sigint (int sig
)
2599 signal (sig
, handle_remote_sigint_twice
);
2600 sigint_remote_twice_token
=
2601 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2602 mark_async_signal_handler_wrapper (sigint_remote_token
);
2605 /* Signal handler for SIGINT, installed after SIGINT has already been
2606 sent once. It will take effect the second time that the user sends
2609 handle_remote_sigint_twice (int sig
)
2611 signal (sig
, handle_sigint
);
2612 sigint_remote_twice_token
=
2613 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2614 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2617 /* Perform the real interruption of the target execution, in response
2620 async_remote_interrupt (gdb_client_data arg
)
2623 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2628 /* Perform interrupt, if the first attempt did not succeed. Just give
2629 up on the target alltogether. */
2631 async_remote_interrupt_twice (gdb_client_data arg
)
2634 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2635 /* Do something only if the target was not killed by the previous
2637 if (target_executing
)
2640 signal (SIGINT
, handle_remote_sigint
);
2644 /* Reinstall the usual SIGINT handlers, after the target has
2647 cleanup_sigint_signal_handler (void *dummy
)
2649 signal (SIGINT
, handle_sigint
);
2650 if (sigint_remote_twice_token
)
2651 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_twice_token
);
2652 if (sigint_remote_token
)
2653 delete_async_signal_handler ((struct async_signal_handler
**) & sigint_remote_token
);
2656 /* Send ^C to target to halt it. Target will respond, and send us a
2658 static void (*ofunc
) (int);
2660 /* The command line interface's stop routine. This function is installed
2661 as a signal handler for SIGINT. The first time a user requests a
2662 stop, we call remote_stop to send a break or ^C. If there is no
2663 response from the target (it didn't stop when the user requested it),
2664 we ask the user if he'd like to detach from the target. */
2666 remote_interrupt (int signo
)
2668 /* If this doesn't work, try more severe steps. */
2669 signal (signo
, remote_interrupt_twice
);
2672 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2677 /* The user typed ^C twice. */
2680 remote_interrupt_twice (int signo
)
2682 signal (signo
, ofunc
);
2684 signal (signo
, remote_interrupt
);
2687 /* This is the generic stop called via the target vector. When a target
2688 interrupt is requested, either by the command line or the GUI, we
2689 will eventually end up here. */
2693 /* Send a break or a ^C, depending on user preference. */
2695 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2698 serial_send_break (remote_desc
);
2700 serial_write (remote_desc
, "\003", 1);
2703 /* Ask the user what to do when an interrupt is received. */
2706 interrupt_query (void)
2708 target_terminal_ours ();
2710 if (query ("Interrupted while waiting for the program.\n\
2711 Give up (and stop debugging it)? "))
2713 target_mourn_inferior ();
2714 throw_exception (RETURN_QUIT
);
2717 target_terminal_inferior ();
2720 /* Enable/disable target terminal ownership. Most targets can use
2721 terminal groups to control terminal ownership. Remote targets are
2722 different in that explicit transfer of ownership to/from GDB/target
2726 remote_async_terminal_inferior (void)
2728 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2729 sync_execution here. This function should only be called when
2730 GDB is resuming the inferior in the forground. A background
2731 resume (``run&'') should leave GDB in control of the terminal and
2732 consequently should not call this code. */
2733 if (!sync_execution
)
2735 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2736 calls target_terminal_*() idenpotent. The event-loop GDB talking
2737 to an asynchronous target with a synchronous command calls this
2738 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2739 stops trying to transfer the terminal to the target when it
2740 shouldn't this guard can go away. */
2741 if (!remote_async_terminal_ours_p
)
2743 delete_file_handler (input_fd
);
2744 remote_async_terminal_ours_p
= 0;
2745 initialize_sigint_signal_handler ();
2746 /* NOTE: At this point we could also register our selves as the
2747 recipient of all input. Any characters typed could then be
2748 passed on down to the target. */
2752 remote_async_terminal_ours (void)
2754 /* See FIXME in remote_async_terminal_inferior. */
2755 if (!sync_execution
)
2757 /* See FIXME in remote_async_terminal_inferior. */
2758 if (remote_async_terminal_ours_p
)
2760 cleanup_sigint_signal_handler (NULL
);
2761 add_file_handler (input_fd
, stdin_event_handler
, 0);
2762 remote_async_terminal_ours_p
= 1;
2765 /* If nonzero, ignore the next kill. */
2770 remote_console_output (char *msg
)
2774 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2777 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2780 fputs_unfiltered (tb
, gdb_stdtarg
);
2782 gdb_flush (gdb_stdtarg
);
2785 /* Wait until the remote machine stops, then return,
2786 storing status in STATUS just as `wait' would.
2787 Returns "pid", which in the case of a multi-threaded
2788 remote OS, is the thread-id. */
2791 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2793 struct remote_state
*rs
= get_remote_state ();
2794 unsigned char *buf
= alloca (rs
->remote_packet_size
);
2795 ULONGEST thread_num
= -1;
2798 status
->kind
= TARGET_WAITKIND_EXITED
;
2799 status
->value
.integer
= 0;
2805 ofunc
= signal (SIGINT
, remote_interrupt
);
2806 getpkt (buf
, (rs
->remote_packet_size
), 1);
2807 signal (SIGINT
, ofunc
);
2809 /* This is a hook for when we need to do something (perhaps the
2810 collection of trace data) every time the target stops. */
2811 if (deprecated_target_wait_loop_hook
)
2812 (*deprecated_target_wait_loop_hook
) ();
2814 remote_stopped_by_watchpoint_p
= 0;
2818 case 'E': /* Error of some sort */
2819 warning ("Remote failure reply: %s", buf
);
2821 case 'F': /* File-I/O request */
2822 remote_fileio_request (buf
);
2824 case 'T': /* Status with PC, SP, FP, ... */
2827 char regs
[MAX_REGISTER_SIZE
];
2829 /* Expedited reply, containing Signal, {regno, reg} repeat */
2830 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2832 n... = register number
2833 r... = register contents
2835 p
= &buf
[3]; /* after Txx */
2844 /* If the packet contains a register number save it in pnum
2845 and set p1 to point to the character following it.
2846 Otherwise p1 points to p. */
2848 /* If this packet is an awatch packet, don't parse the 'a'
2849 as a register number. */
2851 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
2853 /* Read the ``P'' register number. */
2854 pnum
= strtol (p
, &p_temp
, 16);
2855 p1
= (unsigned char *) p_temp
;
2860 if (p1
== p
) /* No register number present here */
2862 p1
= (unsigned char *) strchr (p
, ':');
2864 warning ("Malformed packet(a) (missing colon): %s\n\
2867 if (strncmp (p
, "thread", p1
- p
) == 0)
2869 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2870 record_currthread (thread_num
);
2871 p
= (unsigned char *) p_temp
;
2873 else if ((strncmp (p
, "watch", p1
- p
) == 0)
2874 || (strncmp (p
, "rwatch", p1
- p
) == 0)
2875 || (strncmp (p
, "awatch", p1
- p
) == 0))
2877 remote_stopped_by_watchpoint_p
= 1;
2878 p
= unpack_varlen_hex (++p1
, &addr
);
2879 remote_watch_data_address
= (CORE_ADDR
)addr
;
2883 /* Silently skip unknown optional info. */
2884 p_temp
= strchr (p1
+ 1, ';');
2886 p
= (unsigned char *) p_temp
;
2891 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
2895 error ("Malformed packet(b) (missing colon): %s\nPacket: '%s'\n",
2899 error ("Remote sent bad register number %s: %s\nPacket: '%s'\n",
2900 phex_nz (pnum
, 0), p
, buf
);
2902 fieldsize
= hex2bin (p
, regs
, register_size (current_gdbarch
, reg
->regnum
));
2904 if (fieldsize
< register_size (current_gdbarch
, reg
->regnum
))
2905 warning ("Remote reply is too short: %s", buf
);
2906 regcache_raw_supply (current_regcache
, reg
->regnum
, regs
);
2910 error ("Remote register badly formatted: %s\nhere: %s", buf
, p
);
2914 case 'S': /* Old style status, just signal only */
2915 status
->kind
= TARGET_WAITKIND_STOPPED
;
2916 status
->value
.sig
= (enum target_signal
)
2917 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2921 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2922 record_currthread (thread_num
);
2925 case 'W': /* Target exited */
2927 /* The remote process exited. */
2928 status
->kind
= TARGET_WAITKIND_EXITED
;
2929 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2933 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2934 status
->value
.sig
= (enum target_signal
)
2935 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2939 case 'O': /* Console output */
2940 remote_console_output (buf
+ 1);
2943 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2945 /* Zero length reply means that we tried 'S' or 'C' and
2946 the remote system doesn't support it. */
2947 target_terminal_ours_for_output ();
2949 ("Can't send signals to this remote system. %s not sent.\n",
2950 target_signal_to_name (last_sent_signal
));
2951 last_sent_signal
= TARGET_SIGNAL_0
;
2952 target_terminal_inferior ();
2954 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2955 putpkt ((char *) buf
);
2958 /* else fallthrough */
2960 warning ("Invalid remote reply: %s", buf
);
2965 if (thread_num
!= -1)
2967 return pid_to_ptid (thread_num
);
2969 return inferior_ptid
;
2972 /* Async version of remote_wait. */
2974 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2976 struct remote_state
*rs
= get_remote_state ();
2977 unsigned char *buf
= alloca (rs
->remote_packet_size
);
2978 ULONGEST thread_num
= -1;
2981 status
->kind
= TARGET_WAITKIND_EXITED
;
2982 status
->value
.integer
= 0;
2984 remote_stopped_by_watchpoint_p
= 0;
2990 if (!target_is_async_p ())
2991 ofunc
= signal (SIGINT
, remote_interrupt
);
2992 /* FIXME: cagney/1999-09-27: If we're in async mode we should
2993 _never_ wait for ever -> test on target_is_async_p().
2994 However, before we do that we need to ensure that the caller
2995 knows how to take the target into/out of async mode. */
2996 getpkt (buf
, (rs
->remote_packet_size
), wait_forever_enabled_p
);
2997 if (!target_is_async_p ())
2998 signal (SIGINT
, ofunc
);
3000 /* This is a hook for when we need to do something (perhaps the
3001 collection of trace data) every time the target stops. */
3002 if (deprecated_target_wait_loop_hook
)
3003 (*deprecated_target_wait_loop_hook
) ();
3007 case 'E': /* Error of some sort */
3008 warning ("Remote failure reply: %s", buf
);
3010 case 'F': /* File-I/O request */
3011 remote_fileio_request (buf
);
3013 case 'T': /* Status with PC, SP, FP, ... */
3016 char regs
[MAX_REGISTER_SIZE
];
3018 /* Expedited reply, containing Signal, {regno, reg} repeat */
3019 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3021 n... = register number
3022 r... = register contents
3024 p
= &buf
[3]; /* after Txx */
3033 /* If the packet contains a register number, save it in pnum
3034 and set p1 to point to the character following it.
3035 Otherwise p1 points to p. */
3037 /* If this packet is an awatch packet, don't parse the 'a'
3038 as a register number. */
3040 if (!strncmp (p
, "awatch", strlen ("awatch")) != 0)
3042 /* Read the register number. */
3043 pnum
= strtol (p
, &p_temp
, 16);
3044 p1
= (unsigned char *) p_temp
;
3049 if (p1
== p
) /* No register number present here */
3051 p1
= (unsigned char *) strchr (p
, ':');
3053 error ("Malformed packet(a) (missing colon): %s\nPacket: '%s'\n",
3055 if (strncmp (p
, "thread", p1
- p
) == 0)
3057 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3058 record_currthread (thread_num
);
3059 p
= (unsigned char *) p_temp
;
3061 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3062 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3063 || (strncmp (p
, "awatch", p1
- p
) == 0))
3065 remote_stopped_by_watchpoint_p
= 1;
3066 p
= unpack_varlen_hex (++p1
, &addr
);
3067 remote_watch_data_address
= (CORE_ADDR
)addr
;
3071 /* Silently skip unknown optional info. */
3072 p_temp
= (unsigned char *) strchr (p1
+ 1, ';');
3080 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3083 error ("Malformed packet(b) (missing colon): %s\nPacket: '%s'\n",
3087 error ("Remote sent bad register number %ld: %s\nPacket: '%s'\n",
3090 fieldsize
= hex2bin (p
, regs
, register_size (current_gdbarch
, reg
->regnum
));
3092 if (fieldsize
< register_size (current_gdbarch
, reg
->regnum
))
3093 warning ("Remote reply is too short: %s", buf
);
3094 regcache_raw_supply (current_regcache
, reg
->regnum
, regs
);
3098 error ("Remote register badly formatted: %s\nhere: %s",
3103 case 'S': /* Old style status, just signal only */
3104 status
->kind
= TARGET_WAITKIND_STOPPED
;
3105 status
->value
.sig
= (enum target_signal
)
3106 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3110 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3111 record_currthread (thread_num
);
3114 case 'W': /* Target exited */
3116 /* The remote process exited. */
3117 status
->kind
= TARGET_WAITKIND_EXITED
;
3118 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3122 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3123 status
->value
.sig
= (enum target_signal
)
3124 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3128 case 'O': /* Console output */
3129 remote_console_output (buf
+ 1);
3130 /* Return immediately to the event loop. The event loop will
3131 still be waiting on the inferior afterwards. */
3132 status
->kind
= TARGET_WAITKIND_IGNORE
;
3135 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3137 /* Zero length reply means that we tried 'S' or 'C' and
3138 the remote system doesn't support it. */
3139 target_terminal_ours_for_output ();
3141 ("Can't send signals to this remote system. %s not sent.\n",
3142 target_signal_to_name (last_sent_signal
));
3143 last_sent_signal
= TARGET_SIGNAL_0
;
3144 target_terminal_inferior ();
3146 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3147 putpkt ((char *) buf
);
3150 /* else fallthrough */
3152 warning ("Invalid remote reply: %s", buf
);
3157 if (thread_num
!= -1)
3159 return pid_to_ptid (thread_num
);
3161 return inferior_ptid
;
3164 /* Number of bytes of registers this stub implements. */
3166 static int register_bytes_found
;
3168 /* Read the remote registers into the block REGS. */
3169 /* Currently we just read all the registers, so we don't use regnum. */
3172 fetch_register_using_p (int regnum
)
3174 struct remote_state
*rs
= get_remote_state ();
3175 char *buf
= alloca (rs
->remote_packet_size
), *p
;
3176 char regp
[MAX_REGISTER_SIZE
];
3181 p
+= hexnumstr (p
, regnum
);
3183 remote_send (buf
, rs
->remote_packet_size
);
3184 if (buf
[0] != 0 && buf
[0] != 'E') {
3189 error("fetch_register_using_p: early buf termination");
3192 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3195 regcache_raw_supply (current_regcache
, regnum
, regp
);
3203 remote_fetch_registers (int regnum
)
3205 struct remote_state
*rs
= get_remote_state ();
3206 char *buf
= alloca (rs
->remote_packet_size
);
3209 char *regs
= alloca (rs
->sizeof_g_packet
);
3211 set_thread (PIDGET (inferior_ptid
), 1);
3215 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3216 gdb_assert (reg
!= NULL
);
3217 if (!reg
->in_g_packet
)
3218 internal_error (__FILE__
, __LINE__
,
3219 "Attempt to fetch a non G-packet register when this "
3220 "remote.c does not support the p-packet.");
3222 switch (remote_protocol_p
.support
)
3224 case PACKET_DISABLE
:
3227 if (fetch_register_using_p (regnum
))
3230 error ("Protocol error: p packet not recognized by stub");
3231 case PACKET_SUPPORT_UNKNOWN
:
3232 if (fetch_register_using_p (regnum
))
3234 /* The stub recognized the 'p' packet. Remember this. */
3235 remote_protocol_p
.support
= PACKET_ENABLE
;
3240 /* The stub does not support the 'P' packet. Use 'G'
3241 instead, and don't try using 'P' in the future (it
3242 will just waste our time). */
3243 remote_protocol_p
.support
= PACKET_DISABLE
;
3249 remote_send (buf
, (rs
->remote_packet_size
));
3251 /* Save the size of the packet sent to us by the target. Its used
3252 as a heuristic when determining the max size of packets that the
3253 target can safely receive. */
3254 if ((rs
->actual_register_packet_size
) == 0)
3255 (rs
->actual_register_packet_size
) = strlen (buf
);
3257 /* Unimplemented registers read as all bits zero. */
3258 memset (regs
, 0, rs
->sizeof_g_packet
);
3260 /* We can get out of synch in various cases. If the first character
3261 in the buffer is not a hex character, assume that has happened
3262 and try to fetch another packet to read. */
3263 while ((buf
[0] < '0' || buf
[0] > '9')
3264 && (buf
[0] < 'a' || buf
[0] > 'f')
3265 && buf
[0] != 'x') /* New: unavailable register value */
3268 fprintf_unfiltered (gdb_stdlog
,
3269 "Bad register packet; fetching a new packet\n");
3270 getpkt (buf
, (rs
->remote_packet_size
), 0);
3273 /* Reply describes registers byte by byte, each byte encoded as two
3274 hex characters. Suck them all up, then supply them to the
3275 register cacheing/storage mechanism. */
3278 for (i
= 0; i
< rs
->sizeof_g_packet
; i
++)
3284 warning ("Remote reply is of odd length: %s", buf
);
3285 /* Don't change register_bytes_found in this case, and don't
3286 print a second warning. */
3289 if (p
[0] == 'x' && p
[1] == 'x')
3290 regs
[i
] = 0; /* 'x' */
3292 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3296 if (i
!= register_bytes_found
)
3298 register_bytes_found
= i
;
3299 if (REGISTER_BYTES_OK_P ()
3300 && !REGISTER_BYTES_OK (i
))
3301 warning ("Remote reply is too short: %s", buf
);
3307 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3309 struct packet_reg
*r
= &rs
->regs
[i
];
3312 if (r
->offset
* 2 >= strlen (buf
))
3313 /* A short packet that didn't include the register's
3314 value, this implies that the register is zero (and
3315 not that the register is unavailable). Supply that
3317 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3318 else if (buf
[r
->offset
* 2] == 'x')
3320 gdb_assert (r
->offset
* 2 < strlen (buf
));
3321 /* The register isn't available, mark it as such (at
3322 the same time setting the value to zero). */
3323 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3324 set_register_cached (i
, -1);
3327 regcache_raw_supply (current_regcache
, r
->regnum
,
3334 /* Prepare to store registers. Since we may send them all (using a
3335 'G' request), we have to read out the ones we don't want to change
3339 remote_prepare_to_store (void)
3341 struct remote_state
*rs
= get_remote_state ();
3343 char buf
[MAX_REGISTER_SIZE
];
3345 /* Make sure the entire registers array is valid. */
3346 switch (remote_protocol_P
.support
)
3348 case PACKET_DISABLE
:
3349 case PACKET_SUPPORT_UNKNOWN
:
3350 /* Make sure all the necessary registers are cached. */
3351 for (i
= 0; i
< NUM_REGS
; i
++)
3352 if (rs
->regs
[i
].in_g_packet
)
3353 regcache_raw_read (current_regcache
, rs
->regs
[i
].regnum
, buf
);
3360 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3361 packet was not recognized. */
3364 store_register_using_P (int regnum
)
3366 struct remote_state
*rs
= get_remote_state ();
3367 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3368 /* Try storing a single register. */
3369 char *buf
= alloca (rs
->remote_packet_size
);
3370 char regp
[MAX_REGISTER_SIZE
];
3374 sprintf (buf
, "P%s=", phex_nz (reg
->pnum
, 0));
3375 p
= buf
+ strlen (buf
);
3376 regcache_raw_collect (current_regcache
, reg
->regnum
, regp
);
3377 bin2hex (regp
, p
, register_size (current_gdbarch
, reg
->regnum
));
3378 remote_send (buf
, rs
->remote_packet_size
);
3380 return buf
[0] != '\0';
3384 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
3385 of the register cache buffer. FIXME: ignores errors. */
3388 remote_store_registers (int regnum
)
3390 struct remote_state
*rs
= get_remote_state ();
3396 set_thread (PIDGET (inferior_ptid
), 1);
3400 switch (remote_protocol_P
.support
)
3402 case PACKET_DISABLE
:
3405 if (store_register_using_P (regnum
))
3408 error ("Protocol error: P packet not recognized by stub");
3409 case PACKET_SUPPORT_UNKNOWN
:
3410 if (store_register_using_P (regnum
))
3412 /* The stub recognized the 'P' packet. Remember this. */
3413 remote_protocol_P
.support
= PACKET_ENABLE
;
3418 /* The stub does not support the 'P' packet. Use 'G'
3419 instead, and don't try using 'P' in the future (it
3420 will just waste our time). */
3421 remote_protocol_P
.support
= PACKET_DISABLE
;
3427 /* Extract all the registers in the regcache copying them into a
3431 regs
= alloca (rs
->sizeof_g_packet
);
3432 memset (regs
, rs
->sizeof_g_packet
, 0);
3433 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3435 struct packet_reg
*r
= &rs
->regs
[i
];
3437 regcache_raw_collect (current_regcache
, r
->regnum
, regs
+ r
->offset
);
3441 /* Command describes registers byte by byte,
3442 each byte encoded as two hex characters. */
3443 buf
= alloca (rs
->remote_packet_size
);
3446 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3447 bin2hex (regs
, p
, register_bytes_found
);
3448 remote_send (buf
, (rs
->remote_packet_size
));
3452 /* Return the number of hex digits in num. */
3455 hexnumlen (ULONGEST num
)
3459 for (i
= 0; num
!= 0; i
++)
3465 /* Set BUF to the minimum number of hex digits representing NUM. */
3468 hexnumstr (char *buf
, ULONGEST num
)
3470 int len
= hexnumlen (num
);
3471 return hexnumnstr (buf
, num
, len
);
3475 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3478 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3484 for (i
= width
- 1; i
>= 0; i
--)
3486 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3493 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3496 remote_address_masked (CORE_ADDR addr
)
3498 if (remote_address_size
> 0
3499 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3501 /* Only create a mask when that mask can safely be constructed
3502 in a ULONGEST variable. */
3504 mask
= (mask
<< remote_address_size
) - 1;
3510 /* Determine whether the remote target supports binary downloading.
3511 This is accomplished by sending a no-op memory write of zero length
3512 to the target at the specified address. It does not suffice to send
3513 the whole packet, since many stubs strip the eighth bit and subsequently
3514 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3516 NOTE: This can still lose if the serial line is not eight-bit
3517 clean. In cases like this, the user should clear "remote
3521 check_binary_download (CORE_ADDR addr
)
3523 struct remote_state
*rs
= get_remote_state ();
3524 switch (remote_protocol_binary_download
.support
)
3526 case PACKET_DISABLE
:
3530 case PACKET_SUPPORT_UNKNOWN
:
3532 char *buf
= alloca (rs
->remote_packet_size
);
3537 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3539 p
+= hexnumstr (p
, (ULONGEST
) 0);
3543 putpkt_binary (buf
, (int) (p
- buf
));
3544 getpkt (buf
, (rs
->remote_packet_size
), 0);
3549 fprintf_unfiltered (gdb_stdlog
,
3550 "binary downloading NOT suppported by target\n");
3551 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3556 fprintf_unfiltered (gdb_stdlog
,
3557 "binary downloading suppported by target\n");
3558 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3565 /* Write memory data directly to the remote machine.
3566 This does not inform the data cache; the data cache uses this.
3567 MEMADDR is the address in the remote memory space.
3568 MYADDR is the address of the buffer in our space.
3569 LEN is the number of bytes.
3571 Returns number of bytes transferred, or 0 (setting errno) for
3572 error. Only transfer a single packet. */
3575 remote_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3579 unsigned char *plen
;
3585 unsigned char *payload_start
;
3587 /* Verify that the target can support a binary download. */
3588 check_binary_download (memaddr
);
3590 /* Compute the size, and then allocate space for the largest
3591 possible packet. Include space for an extra trailing NUL. */
3592 sizeof_buf
= get_memory_write_packet_size () + 1;
3593 buf
= alloca (sizeof_buf
);
3595 /* Compute the size of the actual payload by subtracting out the
3596 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
3597 payload_size
= (get_memory_write_packet_size () - (strlen ("$M,:#NN")
3598 + hexnumlen (memaddr
)
3599 + hexnumlen (len
)));
3601 /* Construct the packet header: "[MX]<memaddr>,<len>:". */
3603 /* Append "[XM]". Compute a best guess of the number of bytes
3604 actually transfered. */
3606 switch (remote_protocol_binary_download
.support
)
3610 /* Best guess at number of bytes that will fit. */
3611 todo
= min (len
, payload_size
);
3613 case PACKET_DISABLE
:
3615 /* num bytes that will fit */
3616 todo
= min (len
, payload_size
/ 2);
3618 case PACKET_SUPPORT_UNKNOWN
:
3619 internal_error (__FILE__
, __LINE__
,
3620 "remote_write_bytes: bad internal state");
3622 internal_error (__FILE__
, __LINE__
, "bad switch");
3625 /* Append "<memaddr>". */
3626 memaddr
= remote_address_masked (memaddr
);
3627 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3632 /* Append <len>. Retain the location/size of <len>. It may need to
3633 be adjusted once the packet body has been created. */
3635 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3642 /* Append the packet body. */
3644 switch (remote_protocol_binary_download
.support
)
3647 /* Binary mode. Send target system values byte by byte, in
3648 increasing byte addresses. Only escape certain critical
3651 (nr_bytes
< todo
) && (p
- payload_start
) < payload_size
;
3654 switch (myaddr
[nr_bytes
] & 0xff)
3659 /* These must be escaped */
3661 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3664 *p
++ = myaddr
[nr_bytes
] & 0xff;
3668 if (nr_bytes
< todo
)
3670 /* Escape chars have filled up the buffer prematurely,
3671 and we have actually sent fewer bytes than planned.
3672 Fix-up the length field of the packet. Use the same
3673 number of characters as before. */
3674 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3675 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3678 case PACKET_DISABLE
:
3679 /* Normal mode: Send target system values byte by byte, in
3680 increasing byte addresses. Each byte is encoded as a two hex
3682 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3685 case PACKET_SUPPORT_UNKNOWN
:
3686 internal_error (__FILE__
, __LINE__
,
3687 "remote_write_bytes: bad internal state");
3689 internal_error (__FILE__
, __LINE__
, "bad switch");
3692 putpkt_binary (buf
, (int) (p
- buf
));
3693 getpkt (buf
, sizeof_buf
, 0);
3697 /* There is no correspondance between what the remote protocol
3698 uses for errors and errno codes. We would like a cleaner way
3699 of representing errors (big enough to include errno codes,
3700 bfd_error codes, and others). But for now just return EIO. */
3705 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3706 bytes than we'd planned. */
3710 /* Read memory data directly from the remote machine.
3711 This does not use the data cache; the data cache uses this.
3712 MEMADDR is the address in the remote memory space.
3713 MYADDR is the address of the buffer in our space.
3714 LEN is the number of bytes.
3716 Returns number of bytes transferred, or 0 for error. */
3718 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3719 remote targets) shouldn't attempt to read the entire buffer.
3720 Instead it should read a single packet worth of data and then
3721 return the byte size of that packet to the caller. The caller (its
3722 caller and its callers caller ;-) already contains code for
3723 handling partial reads. */
3726 remote_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
3729 int max_buf_size
; /* Max size of packet output buffer */
3733 /* Create a buffer big enough for this packet. */
3734 max_buf_size
= get_memory_read_packet_size ();
3735 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NUL */
3736 buf
= alloca (sizeof_buf
);
3745 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3747 /* construct "m"<memaddr>","<len>" */
3748 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3749 memaddr
= remote_address_masked (memaddr
);
3752 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3754 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3758 getpkt (buf
, sizeof_buf
, 0);
3761 && isxdigit (buf
[1]) && isxdigit (buf
[2])
3764 /* There is no correspondance between what the remote protocol uses
3765 for errors and errno codes. We would like a cleaner way of
3766 representing errors (big enough to include errno codes, bfd_error
3767 codes, and others). But for now just return EIO. */
3772 /* Reply describes memory byte by byte,
3773 each byte encoded as two hex characters. */
3776 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
3778 /* Reply is short. This means that we were able to read
3779 only part of what we wanted to. */
3780 return i
+ (origlen
- len
);
3789 /* Read or write LEN bytes from inferior memory at MEMADDR,
3790 transferring to or from debugger address BUFFER. Write to inferior if
3791 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3792 for error. TARGET is unused. */
3795 remote_xfer_memory (CORE_ADDR mem_addr
, char *buffer
, int mem_len
,
3796 int should_write
, struct mem_attrib
*attrib
,
3797 struct target_ops
*target
)
3799 CORE_ADDR targ_addr
;
3803 /* Should this be the selected frame? */
3804 gdbarch_remote_translate_xfer_address (current_gdbarch
, current_regcache
,
3806 &targ_addr
, &targ_len
);
3811 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
3813 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
3819 remote_files_info (struct target_ops
*ignore
)
3821 puts_filtered ("Debugging a target over a serial line.\n");
3824 /* Stuff for dealing with the packets which are part of this protocol.
3825 See comment at top of file for details. */
3827 /* Read a single character from the remote end, masking it down to 7 bits. */
3830 readchar (int timeout
)
3834 ch
= serial_readchar (remote_desc
, timeout
);
3839 switch ((enum serial_rc
) ch
)
3842 target_mourn_inferior ();
3843 error ("Remote connection closed");
3846 perror_with_name ("Remote communication error");
3848 case SERIAL_TIMEOUT
:
3854 /* Send the command in BUF to the remote machine, and read the reply
3855 into BUF. Report an error if we get an error reply. */
3858 remote_send (char *buf
,
3862 getpkt (buf
, sizeof_buf
, 0);
3865 error ("Remote failure reply: %s", buf
);
3868 /* Display a null-terminated packet on stdout, for debugging, using C
3872 print_packet (char *buf
)
3874 puts_filtered ("\"");
3875 fputstr_filtered (buf
, '"', gdb_stdout
);
3876 puts_filtered ("\"");
3882 return putpkt_binary (buf
, strlen (buf
));
3885 /* Send a packet to the remote machine, with error checking. The data
3886 of the packet is in BUF. The string in BUF can be at most (rs->remote_packet_size) - 5
3887 to account for the $, # and checksum, and for a possible /0 if we are
3888 debugging (remote_debug) and want to print the sent packet as a string */
3891 putpkt_binary (char *buf
, int cnt
)
3893 struct remote_state
*rs
= get_remote_state ();
3895 unsigned char csum
= 0;
3896 char *buf2
= alloca (cnt
+ 6);
3897 long sizeof_junkbuf
= (rs
->remote_packet_size
);
3898 char *junkbuf
= alloca (sizeof_junkbuf
);
3904 /* Copy the packet into buffer BUF2, encapsulating it
3905 and giving it a checksum. */
3910 for (i
= 0; i
< cnt
; i
++)
3916 *p
++ = tohex ((csum
>> 4) & 0xf);
3917 *p
++ = tohex (csum
& 0xf);
3919 /* Send it over and over until we get a positive ack. */
3923 int started_error_output
= 0;
3928 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
3929 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
3930 fprintf_unfiltered (gdb_stdlog
, "...");
3931 gdb_flush (gdb_stdlog
);
3933 if (serial_write (remote_desc
, buf2
, p
- buf2
))
3934 perror_with_name ("putpkt: write failed");
3936 /* read until either a timeout occurs (-2) or '+' is read */
3939 ch
= readchar (remote_timeout
);
3947 case SERIAL_TIMEOUT
:
3949 if (started_error_output
)
3951 putchar_unfiltered ('\n');
3952 started_error_output
= 0;
3961 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
3965 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
3966 case SERIAL_TIMEOUT
:
3970 break; /* Retransmit buffer */
3974 fprintf_unfiltered (gdb_stdlog
, "Packet instead of Ack, ignoring it\n");
3975 /* It's probably an old response sent because an ACK
3976 was lost. Gobble up the packet and ack it so it
3977 doesn't get retransmitted when we resend this
3979 read_frame (junkbuf
, sizeof_junkbuf
);
3980 serial_write (remote_desc
, "+", 1);
3981 continue; /* Now, go look for + */
3986 if (!started_error_output
)
3988 started_error_output
= 1;
3989 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
3991 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
3995 break; /* Here to retransmit */
3999 /* This is wrong. If doing a long backtrace, the user should be
4000 able to get out next time we call QUIT, without anything as
4001 violent as interrupt_query. If we want to provide a way out of
4002 here without getting to the next QUIT, it should be based on
4003 hitting ^C twice as in remote_wait. */
4013 /* Come here after finding the start of the frame. Collect the rest
4014 into BUF, verifying the checksum, length, and handling run-length
4015 compression. No more than sizeof_buf-1 characters are read so that
4016 the buffer can be NUL terminated.
4018 Returns -1 on error, number of characters in buffer (ignoring the
4019 trailing NULL) on success. (could be extended to return one of the
4020 SERIAL status indications). */
4023 read_frame (char *buf
,
4035 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
4036 c
= readchar (remote_timeout
);
4039 case SERIAL_TIMEOUT
:
4041 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4045 fputs_filtered ("Saw new packet start in middle of old one\n",
4047 return -1; /* Start a new packet, count retries */
4050 unsigned char pktcsum
;
4056 check_0
= readchar (remote_timeout
);
4058 check_1
= readchar (remote_timeout
);
4060 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4063 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog
);
4066 else if (check_0
< 0 || check_1
< 0)
4069 fputs_filtered ("Communication error in checksum\n", gdb_stdlog
);
4073 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4074 if (csum
== pktcsum
)
4079 fprintf_filtered (gdb_stdlog
,
4080 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4082 fputs_filtered (buf
, gdb_stdlog
);
4083 fputs_filtered ("\n", gdb_stdlog
);
4085 /* Number of characters in buffer ignoring trailing
4089 case '*': /* Run length encoding */
4094 c
= readchar (remote_timeout
);
4096 repeat
= c
- ' ' + 3; /* Compute repeat count */
4098 /* The character before ``*'' is repeated. */
4100 if (repeat
> 0 && repeat
<= 255
4102 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4104 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4110 printf_filtered ("Repeat count %d too large for buffer: ", repeat
);
4111 puts_filtered (buf
);
4112 puts_filtered ("\n");
4116 if (bc
< sizeof_buf
- 1)
4124 puts_filtered ("Remote packet too long: ");
4125 puts_filtered (buf
);
4126 puts_filtered ("\n");
4133 /* Read a packet from the remote machine, with error checking, and
4134 store it in BUF. If FOREVER, wait forever rather than timing out;
4135 this is used (in synchronous mode) to wait for a target that is is
4136 executing user code to stop. */
4137 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4138 don't have to change all the calls to getpkt to deal with the
4139 return value, because at the moment I don't know what the right
4140 thing to do it for those. */
4148 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4152 /* Read a packet from the remote machine, with error checking, and
4153 store it in BUF. If FOREVER, wait forever rather than timing out;
4154 this is used (in synchronous mode) to wait for a target that is is
4155 executing user code to stop. If FOREVER == 0, this function is
4156 allowed to time out gracefully and return an indication of this to
4159 getpkt_sane (char *buf
,
4168 strcpy (buf
, "timeout");
4172 timeout
= watchdog
> 0 ? watchdog
: -1;
4176 timeout
= remote_timeout
;
4180 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4182 /* This can loop forever if the remote side sends us characters
4183 continuously, but if it pauses, we'll get a zero from readchar
4184 because of timeout. Then we'll count that as a retry. */
4186 /* Note that we will only wait forever prior to the start of a packet.
4187 After that, we expect characters to arrive at a brisk pace. They
4188 should show up within remote_timeout intervals. */
4192 c
= readchar (timeout
);
4194 if (c
== SERIAL_TIMEOUT
)
4196 if (forever
) /* Watchdog went off? Kill the target. */
4199 target_mourn_inferior ();
4200 error ("Watchdog has expired. Target detached.\n");
4203 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4209 /* We've found the start of a packet, now collect the data. */
4211 val
= read_frame (buf
, sizeof_buf
);
4217 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4218 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4219 fprintf_unfiltered (gdb_stdlog
, "\n");
4221 serial_write (remote_desc
, "+", 1);
4225 /* Try the whole thing again. */
4227 serial_write (remote_desc
, "-", 1);
4230 /* We have tried hard enough, and just can't receive the packet. Give up. */
4232 printf_unfiltered ("Ignoring packet error, continuing...\n");
4233 serial_write (remote_desc
, "+", 1);
4240 /* For some mysterious reason, wait_for_inferior calls kill instead of
4241 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4245 target_mourn_inferior ();
4249 /* Use catch_errors so the user can quit from gdb even when we aren't on
4250 speaking terms with the remote system. */
4251 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4253 /* Don't wait for it to die. I'm not really sure it matters whether
4254 we do or not. For the existing stubs, kill is a noop. */
4255 target_mourn_inferior ();
4258 /* Async version of remote_kill. */
4260 remote_async_kill (void)
4262 /* Unregister the file descriptor from the event loop. */
4263 if (target_is_async_p ())
4264 serial_async (remote_desc
, NULL
, 0);
4266 /* For some mysterious reason, wait_for_inferior calls kill instead of
4267 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4271 target_mourn_inferior ();
4275 /* Use catch_errors so the user can quit from gdb even when we aren't on
4276 speaking terms with the remote system. */
4277 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4279 /* Don't wait for it to die. I'm not really sure it matters whether
4280 we do or not. For the existing stubs, kill is a noop. */
4281 target_mourn_inferior ();
4287 remote_mourn_1 (&remote_ops
);
4291 remote_async_mourn (void)
4293 remote_mourn_1 (&remote_async_ops
);
4297 extended_remote_mourn (void)
4299 /* We do _not_ want to mourn the target like this; this will
4300 remove the extended remote target from the target stack,
4301 and the next time the user says "run" it'll fail.
4303 FIXME: What is the right thing to do here? */
4305 remote_mourn_1 (&extended_remote_ops
);
4309 /* Worker function for remote_mourn. */
4311 remote_mourn_1 (struct target_ops
*target
)
4313 unpush_target (target
);
4314 generic_mourn_inferior ();
4317 /* In the extended protocol we want to be able to do things like
4318 "run" and have them basically work as expected. So we need
4319 a special create_inferior function.
4321 FIXME: One day add support for changing the exec file
4322 we're debugging, arguments and an environment. */
4325 extended_remote_create_inferior (char *exec_file
, char *args
, char **env
,
4328 /* Rip out the breakpoints; we'll reinsert them after restarting
4329 the remote server. */
4330 remove_breakpoints ();
4332 /* Now restart the remote server. */
4333 extended_remote_restart ();
4335 /* Now put the breakpoints back in. This way we're safe if the
4336 restart function works via a unix fork on the remote side. */
4337 insert_breakpoints ();
4339 /* Clean up from the last time we were running. */
4340 clear_proceed_status ();
4342 /* Let the remote process run. */
4343 proceed (-1, TARGET_SIGNAL_0
, 0);
4346 /* Async version of extended_remote_create_inferior. */
4348 extended_remote_async_create_inferior (char *exec_file
, char *args
, char **env
,
4351 /* Rip out the breakpoints; we'll reinsert them after restarting
4352 the remote server. */
4353 remove_breakpoints ();
4355 /* If running asynchronously, register the target file descriptor
4356 with the event loop. */
4357 if (target_can_async_p ())
4358 target_async (inferior_event_handler
, 0);
4360 /* Now restart the remote server. */
4361 extended_remote_restart ();
4363 /* Now put the breakpoints back in. This way we're safe if the
4364 restart function works via a unix fork on the remote side. */
4365 insert_breakpoints ();
4367 /* Clean up from the last time we were running. */
4368 clear_proceed_status ();
4370 /* Let the remote process run. */
4371 proceed (-1, TARGET_SIGNAL_0
, 0);
4375 /* On some machines, e.g. 68k, we may use a different breakpoint
4376 instruction than other targets; in those use
4377 DEPRECATED_REMOTE_BREAKPOINT instead of just BREAKPOINT_FROM_PC.
4378 Also, bi-endian targets may define
4379 DEPRECATED_LITTLE_REMOTE_BREAKPOINT and
4380 DEPRECATED_BIG_REMOTE_BREAKPOINT. If none of these are defined, we
4381 just call the standard routines that are in mem-break.c. */
4383 /* NOTE: cagney/2003-06-08: This is silly. A remote and simulator
4384 target should use an identical BREAKPOINT_FROM_PC. As for native,
4385 the ARCH-OS-tdep.c code can override the default. */
4387 #if defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) && !defined(DEPRECATED_REMOTE_BREAKPOINT)
4388 #define DEPRECATED_REMOTE_BREAKPOINT
4391 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4393 /* If the target isn't bi-endian, just pretend it is. */
4394 #if !defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && !defined (DEPRECATED_BIG_REMOTE_BREAKPOINT)
4395 #define DEPRECATED_LITTLE_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4396 #define DEPRECATED_BIG_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4399 static unsigned char big_break_insn
[] = DEPRECATED_BIG_REMOTE_BREAKPOINT
;
4400 static unsigned char little_break_insn
[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT
;
4402 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4404 /* Insert a breakpoint on targets that don't have any better
4405 breakpoint support. We read the contents of the target location
4406 and stash it, then overwrite it with a breakpoint instruction.
4407 ADDR is the target location in the target machine. CONTENTS_CACHE
4408 is a pointer to memory allocated for saving the target contents.
4409 It is guaranteed by the caller to be long enough to save the number
4410 of bytes returned by BREAKPOINT_FROM_PC. */
4413 remote_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4415 struct remote_state
*rs
= get_remote_state ();
4416 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4421 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4422 If it succeeds, then set the support to PACKET_ENABLE. If it
4423 fails, and the user has explicitly requested the Z support then
4424 report an error, otherwise, mark it disabled and go on. */
4426 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4428 char *buf
= alloca (rs
->remote_packet_size
);
4431 addr
= remote_address_masked (addr
);
4435 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4436 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4437 sprintf (p
, ",%d", bp_size
);
4440 getpkt (buf
, (rs
->remote_packet_size
), 0);
4442 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4448 case PACKET_UNKNOWN
:
4453 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4454 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4458 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4459 val
= target_write_memory (addr
, (char *) big_break_insn
,
4460 sizeof big_break_insn
);
4462 val
= target_write_memory (addr
, (char *) little_break_insn
,
4463 sizeof little_break_insn
);
4468 return memory_insert_breakpoint (addr
, contents_cache
);
4469 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4473 remote_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
4475 struct remote_state
*rs
= get_remote_state ();
4478 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4480 char *buf
= alloca (rs
->remote_packet_size
);
4487 addr
= remote_address_masked (addr
);
4488 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4489 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4490 sprintf (p
, ",%d", bp_size
);
4493 getpkt (buf
, (rs
->remote_packet_size
), 0);
4495 return (buf
[0] == 'E');
4498 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4499 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4501 return memory_remove_breakpoint (addr
, contents_cache
);
4502 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4506 watchpoint_to_Z_packet (int type
)
4520 internal_error (__FILE__
, __LINE__
,
4521 "hw_bp_to_z: bad watchpoint type %d", type
);
4526 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4528 struct remote_state
*rs
= get_remote_state ();
4529 char *buf
= alloca (rs
->remote_packet_size
);
4531 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4533 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4534 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4535 remote_protocol_Z
[packet
].name
,
4536 remote_protocol_Z
[packet
].title
);
4538 sprintf (buf
, "Z%x,", packet
);
4539 p
= strchr (buf
, '\0');
4540 addr
= remote_address_masked (addr
);
4541 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4542 sprintf (p
, ",%x", len
);
4545 getpkt (buf
, (rs
->remote_packet_size
), 0);
4547 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4550 case PACKET_UNKNOWN
:
4555 internal_error (__FILE__
, __LINE__
,
4556 "remote_insert_watchpoint: reached end of function");
4561 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4563 struct remote_state
*rs
= get_remote_state ();
4564 char *buf
= alloca (rs
->remote_packet_size
);
4566 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4568 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4569 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4570 remote_protocol_Z
[packet
].name
,
4571 remote_protocol_Z
[packet
].title
);
4573 sprintf (buf
, "z%x,", packet
);
4574 p
= strchr (buf
, '\0');
4575 addr
= remote_address_masked (addr
);
4576 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4577 sprintf (p
, ",%x", len
);
4579 getpkt (buf
, (rs
->remote_packet_size
), 0);
4581 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4584 case PACKET_UNKNOWN
:
4589 internal_error (__FILE__
, __LINE__
,
4590 "remote_remove_watchpoint: reached end of function");
4594 int remote_hw_watchpoint_limit
= -1;
4595 int remote_hw_breakpoint_limit
= -1;
4598 remote_check_watch_resources (int type
, int cnt
, int ot
)
4600 if (type
== bp_hardware_breakpoint
)
4602 if (remote_hw_breakpoint_limit
== 0)
4604 else if (remote_hw_breakpoint_limit
< 0)
4606 else if (cnt
<= remote_hw_breakpoint_limit
)
4611 if (remote_hw_watchpoint_limit
== 0)
4613 else if (remote_hw_watchpoint_limit
< 0)
4617 else if (cnt
<= remote_hw_watchpoint_limit
)
4624 remote_stopped_by_watchpoint (void)
4626 return remote_stopped_by_watchpoint_p
;
4629 extern int stepped_after_stopped_by_watchpoint
;
4632 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
4635 if (remote_stopped_by_watchpoint ()
4636 || stepped_after_stopped_by_watchpoint
)
4638 *addr_p
= remote_watch_data_address
;
4647 remote_insert_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4650 struct remote_state
*rs
= get_remote_state ();
4651 char *buf
= alloca (rs
->remote_packet_size
);
4654 /* The length field should be set to the size of a breakpoint
4657 BREAKPOINT_FROM_PC (&addr
, &len
);
4659 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4660 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4661 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4662 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4668 addr
= remote_address_masked (addr
);
4669 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4670 sprintf (p
, ",%x", len
);
4673 getpkt (buf
, (rs
->remote_packet_size
), 0);
4675 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4678 case PACKET_UNKNOWN
:
4683 internal_error (__FILE__
, __LINE__
,
4684 "remote_insert_hw_breakpoint: reached end of function");
4689 remote_remove_hw_breakpoint (CORE_ADDR addr
, char *shadow
)
4692 struct remote_state
*rs
= get_remote_state ();
4693 char *buf
= alloca (rs
->remote_packet_size
);
4696 /* The length field should be set to the size of a breakpoint
4699 BREAKPOINT_FROM_PC (&addr
, &len
);
4701 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4702 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
4703 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4704 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4710 addr
= remote_address_masked (addr
);
4711 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4712 sprintf (p
, ",%x", len
);
4715 getpkt (buf
, (rs
->remote_packet_size
), 0);
4717 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4720 case PACKET_UNKNOWN
:
4725 internal_error (__FILE__
, __LINE__
,
4726 "remote_remove_hw_breakpoint: reached end of function");
4729 /* Some targets are only capable of doing downloads, and afterwards
4730 they switch to the remote serial protocol. This function provides
4731 a clean way to get from the download target to the remote target.
4732 It's basically just a wrapper so that we don't have to expose any
4733 of the internal workings of remote.c.
4735 Prior to calling this routine, you should shutdown the current
4736 target code, else you will get the "A program is being debugged
4737 already..." message. Usually a call to pop_target() suffices. */
4740 push_remote_target (char *name
, int from_tty
)
4742 printf_filtered ("Switching to remote protocol\n");
4743 remote_open (name
, from_tty
);
4746 /* Table used by the crc32 function to calcuate the checksum. */
4748 static unsigned long crc32_table
[256] =
4751 static unsigned long
4752 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4754 if (!crc32_table
[1])
4756 /* Initialize the CRC table and the decoding table. */
4760 for (i
= 0; i
< 256; i
++)
4762 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4763 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4770 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4776 /* compare-sections command
4778 With no arguments, compares each loadable section in the exec bfd
4779 with the same memory range on the target, and reports mismatches.
4780 Useful for verifying the image on the target against the exec file.
4781 Depends on the target understanding the new "qCRC:" request. */
4783 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4784 target method (target verify memory) and generic version of the
4785 actual command. This will allow other high-level code (especially
4786 generic_load()) to make use of this target functionality. */
4789 compare_sections_command (char *args
, int from_tty
)
4791 struct remote_state
*rs
= get_remote_state ();
4793 unsigned long host_crc
, target_crc
;
4794 extern bfd
*exec_bfd
;
4795 struct cleanup
*old_chain
;
4798 const char *sectname
;
4799 char *buf
= alloca (rs
->remote_packet_size
);
4806 error ("command cannot be used without an exec file");
4807 if (!current_target
.to_shortname
||
4808 strcmp (current_target
.to_shortname
, "remote") != 0)
4809 error ("command can only be used with remote target");
4811 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4813 if (!(s
->flags
& SEC_LOAD
))
4814 continue; /* skip non-loadable section */
4816 size
= bfd_get_section_size (s
);
4818 continue; /* skip zero-length section */
4820 sectname
= bfd_get_section_name (exec_bfd
, s
);
4821 if (args
&& strcmp (args
, sectname
) != 0)
4822 continue; /* not the section selected by user */
4824 matched
= 1; /* do this section */
4826 /* FIXME: assumes lma can fit into long */
4827 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
4830 /* be clever; compute the host_crc before waiting for target reply */
4831 sectdata
= xmalloc (size
);
4832 old_chain
= make_cleanup (xfree
, sectdata
);
4833 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
4834 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
4836 getpkt (buf
, (rs
->remote_packet_size
), 0);
4838 error ("target memory fault, section %s, range 0x%s -- 0x%s",
4839 sectname
, paddr (lma
), paddr (lma
+ size
));
4841 error ("remote target does not support this operation");
4843 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
4844 target_crc
= target_crc
* 16 + fromhex (*tmp
);
4846 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4847 sectname
, paddr (lma
), paddr (lma
+ size
));
4848 if (host_crc
== target_crc
)
4849 printf_filtered ("matched.\n");
4852 printf_filtered ("MIS-MATCHED!\n");
4856 do_cleanups (old_chain
);
4859 warning ("One or more sections of the remote executable does not match\n\
4860 the loaded file\n");
4861 if (args
&& !matched
)
4862 printf_filtered ("No loaded section named '%s'.\n", args
);
4866 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
4867 const char *annex
, void *readbuf
, const void *writebuf
,
4868 ULONGEST offset
, LONGEST len
)
4870 struct remote_state
*rs
= get_remote_state ();
4872 char *buf2
= alloca (rs
->remote_packet_size
);
4873 char *p2
= &buf2
[0];
4876 /* Handle memory using remote_xfer_memory. */
4877 if (object
== TARGET_OBJECT_MEMORY
)
4882 if (writebuf
!= NULL
)
4884 void *buffer
= xmalloc (len
);
4885 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
4886 memcpy (buffer
, writebuf
, len
);
4887 xfered
= remote_xfer_memory (offset
, buffer
, len
, 1, NULL
, ops
);
4888 do_cleanups (cleanup
);
4891 xfered
= remote_xfer_memory (offset
, readbuf
, len
, 0, NULL
, ops
);
4895 else if (xfered
== 0 && errno
== 0)
4901 /* Only handle reads. */
4902 if (writebuf
!= NULL
|| readbuf
== NULL
)
4905 /* Map pre-existing objects onto letters. DO NOT do this for new
4906 objects!!! Instead specify new query packets. */
4909 case TARGET_OBJECT_KOD
:
4912 case TARGET_OBJECT_AVR
:
4916 case TARGET_OBJECT_AUXV
:
4917 if (remote_protocol_qPart_auxv
.support
!= PACKET_DISABLE
)
4919 unsigned int total
= 0;
4922 LONGEST n
= min ((rs
->remote_packet_size
- 2) / 2, len
);
4923 snprintf (buf2
, rs
->remote_packet_size
,
4924 "qPart:auxv:read::%s,%s",
4925 phex_nz (offset
, sizeof offset
),
4926 phex_nz (n
, sizeof n
));
4929 return total
> 0 ? total
: i
;
4931 getpkt (buf2
, rs
->remote_packet_size
, 0);
4932 if (packet_ok (buf2
, &remote_protocol_qPart_auxv
) != PACKET_OK
)
4933 return total
> 0 ? total
: -1;
4934 if (buf2
[0] == 'O' && buf2
[1] == 'K' && buf2
[2] == '\0')
4935 break; /* Got EOF indicator. */
4936 /* Got some data. */
4937 i
= hex2bin (buf2
, readbuf
, len
);
4940 readbuf
= (void *) ((char *) readbuf
+ i
);
4954 /* Note: a zero OFFSET and LEN can be used to query the minimum
4956 if (offset
== 0 && len
== 0)
4957 return (rs
->remote_packet_size
);
4958 /* Minimum outbuf size is (rs->remote_packet_size) - if bufsiz is
4959 not large enough let the caller. */
4960 if (len
< (rs
->remote_packet_size
))
4962 len
= rs
->remote_packet_size
;
4964 /* except for querying the minimum buffer size, target must be open */
4966 error ("remote query is only available after target open");
4968 gdb_assert (annex
!= NULL
);
4969 gdb_assert (readbuf
!= NULL
);
4974 /* we used one buffer char for the remote protocol q command and another
4975 for the query type. As the remote protocol encapsulation uses 4 chars
4976 plus one extra in case we are debugging (remote_debug),
4977 we have PBUFZIZ - 7 left to pack the query string */
4979 while (annex
[i
] && (i
< ((rs
->remote_packet_size
) - 8)))
4981 /* Bad caller may have sent forbidden characters. */
4982 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
4987 gdb_assert (annex
[i
] == '\0');
4993 getpkt (readbuf
, len
, 0);
4995 return strlen (readbuf
);
4999 remote_rcmd (char *command
,
5000 struct ui_file
*outbuf
)
5002 struct remote_state
*rs
= get_remote_state ();
5004 char *buf
= alloca (rs
->remote_packet_size
);
5008 error ("remote rcmd is only available after target open");
5010 /* Send a NULL command across as an empty command */
5011 if (command
== NULL
)
5014 /* The query prefix */
5015 strcpy (buf
, "qRcmd,");
5016 p
= strchr (buf
, '\0');
5018 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > (rs
->remote_packet_size
))
5019 error ("\"monitor\" command ``%s'' is too long\n", command
);
5021 /* Encode the actual command */
5022 bin2hex (command
, p
, 0);
5024 if (putpkt (buf
) < 0)
5025 error ("Communication problem with target\n");
5027 /* get/display the response */
5030 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
5032 getpkt (buf
, (rs
->remote_packet_size
), 0);
5034 error ("Target does not support this command\n");
5035 if (buf
[0] == 'O' && buf
[1] != 'K')
5037 remote_console_output (buf
+ 1); /* 'O' message from stub */
5040 if (strcmp (buf
, "OK") == 0)
5042 if (strlen (buf
) == 3 && buf
[0] == 'E'
5043 && isdigit (buf
[1]) && isdigit (buf
[2]))
5045 error ("Protocol error with Rcmd");
5047 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5049 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5050 fputc_unfiltered (c
, outbuf
);
5057 packet_command (char *args
, int from_tty
)
5059 struct remote_state
*rs
= get_remote_state ();
5060 char *buf
= alloca (rs
->remote_packet_size
);
5063 error ("command can only be used with remote target");
5066 error ("remote-packet command requires packet text as argument");
5068 puts_filtered ("sending: ");
5069 print_packet (args
);
5070 puts_filtered ("\n");
5073 getpkt (buf
, (rs
->remote_packet_size
), 0);
5074 puts_filtered ("received: ");
5076 puts_filtered ("\n");
5080 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
5082 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5084 static void threadset_test_cmd (char *cmd
, int tty
);
5086 static void threadalive_test (char *cmd
, int tty
);
5088 static void threadlist_test_cmd (char *cmd
, int tty
);
5090 int get_and_display_threadinfo (threadref
* ref
);
5092 static void threadinfo_test_cmd (char *cmd
, int tty
);
5094 static int thread_display_step (threadref
* ref
, void *context
);
5096 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5098 static void init_remote_threadtests (void);
5100 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
5103 threadset_test_cmd (char *cmd
, int tty
)
5105 int sample_thread
= SAMPLE_THREAD
;
5107 printf_filtered ("Remote threadset test\n");
5108 set_thread (sample_thread
, 1);
5113 threadalive_test (char *cmd
, int tty
)
5115 int sample_thread
= SAMPLE_THREAD
;
5117 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5118 printf_filtered ("PASS: Thread alive test\n");
5120 printf_filtered ("FAIL: Thread alive test\n");
5123 void output_threadid (char *title
, threadref
* ref
);
5126 output_threadid (char *title
, threadref
*ref
)
5130 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
5132 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5136 threadlist_test_cmd (char *cmd
, int tty
)
5139 threadref nextthread
;
5140 int done
, result_count
;
5141 threadref threadlist
[3];
5143 printf_filtered ("Remote Threadlist test\n");
5144 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5145 &result_count
, &threadlist
[0]))
5146 printf_filtered ("FAIL: threadlist test\n");
5149 threadref
*scan
= threadlist
;
5150 threadref
*limit
= scan
+ result_count
;
5152 while (scan
< limit
)
5153 output_threadid (" thread ", scan
++);
5158 display_thread_info (struct gdb_ext_thread_info
*info
)
5160 output_threadid ("Threadid: ", &info
->threadid
);
5161 printf_filtered ("Name: %s\n ", info
->shortname
);
5162 printf_filtered ("State: %s\n", info
->display
);
5163 printf_filtered ("other: %s\n\n", info
->more_display
);
5167 get_and_display_threadinfo (threadref
*ref
)
5171 struct gdb_ext_thread_info threadinfo
;
5173 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5174 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5175 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5176 display_thread_info (&threadinfo
);
5181 threadinfo_test_cmd (char *cmd
, int tty
)
5183 int athread
= SAMPLE_THREAD
;
5187 int_to_threadref (&thread
, athread
);
5188 printf_filtered ("Remote Threadinfo test\n");
5189 if (!get_and_display_threadinfo (&thread
))
5190 printf_filtered ("FAIL cannot get thread info\n");
5194 thread_display_step (threadref
*ref
, void *context
)
5196 /* output_threadid(" threadstep ",ref); *//* simple test */
5197 return get_and_display_threadinfo (ref
);
5201 threadlist_update_test_cmd (char *cmd
, int tty
)
5203 printf_filtered ("Remote Threadlist update test\n");
5204 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5208 init_remote_threadtests (void)
5210 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
5211 "Fetch and print the remote list of thread identifiers, one pkt only");
5212 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5213 "Fetch and display info about one thread");
5214 add_com ("tset", class_obscure
, threadset_test_cmd
,
5215 "Test setting to a different thread");
5216 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5217 "Iterate through updating all remote thread info");
5218 add_com ("talive", class_obscure
, threadalive_test
,
5219 " Remote thread alive test ");
5224 /* Convert a thread ID to a string. Returns the string in a static
5228 remote_pid_to_str (ptid_t ptid
)
5230 static char buf
[30];
5232 sprintf (buf
, "Thread %d", PIDGET (ptid
));
5237 init_remote_ops (void)
5239 remote_ops
.to_shortname
= "remote";
5240 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5242 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5243 Specify the serial device it is connected to\n\
5244 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5245 remote_ops
.to_open
= remote_open
;
5246 remote_ops
.to_close
= remote_close
;
5247 remote_ops
.to_detach
= remote_detach
;
5248 remote_ops
.to_disconnect
= remote_disconnect
;
5249 remote_ops
.to_resume
= remote_resume
;
5250 remote_ops
.to_wait
= remote_wait
;
5251 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5252 remote_ops
.to_store_registers
= remote_store_registers
;
5253 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5254 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
5255 remote_ops
.to_files_info
= remote_files_info
;
5256 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5257 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5258 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5259 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5260 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5261 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5262 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5263 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5264 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5265 remote_ops
.to_kill
= remote_kill
;
5266 remote_ops
.to_load
= generic_load
;
5267 remote_ops
.to_mourn_inferior
= remote_mourn
;
5268 remote_ops
.to_thread_alive
= remote_thread_alive
;
5269 remote_ops
.to_find_new_threads
= remote_threads_info
;
5270 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5271 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5272 remote_ops
.to_stop
= remote_stop
;
5273 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
5274 remote_ops
.to_rcmd
= remote_rcmd
;
5275 remote_ops
.to_stratum
= process_stratum
;
5276 remote_ops
.to_has_all_memory
= 1;
5277 remote_ops
.to_has_memory
= 1;
5278 remote_ops
.to_has_stack
= 1;
5279 remote_ops
.to_has_registers
= 1;
5280 remote_ops
.to_has_execution
= 1;
5281 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5282 remote_ops
.to_magic
= OPS_MAGIC
;
5285 /* Set up the extended remote vector by making a copy of the standard
5286 remote vector and adding to it. */
5289 init_extended_remote_ops (void)
5291 extended_remote_ops
= remote_ops
;
5293 extended_remote_ops
.to_shortname
= "extended-remote";
5294 extended_remote_ops
.to_longname
=
5295 "Extended remote serial target in gdb-specific protocol";
5296 extended_remote_ops
.to_doc
=
5297 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5298 Specify the serial device it is connected to (e.g. /dev/ttya).",
5299 extended_remote_ops
.to_open
= extended_remote_open
;
5300 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5301 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5305 remote_can_async_p (void)
5307 /* We're async whenever the serial device is. */
5308 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5312 remote_is_async_p (void)
5314 /* We're async whenever the serial device is. */
5315 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5318 /* Pass the SERIAL event on and up to the client. One day this code
5319 will be able to delay notifying the client of an event until the
5320 point where an entire packet has been received. */
5322 static void (*async_client_callback
) (enum inferior_event_type event_type
, void *context
);
5323 static void *async_client_context
;
5324 static serial_event_ftype remote_async_serial_handler
;
5327 remote_async_serial_handler (struct serial
*scb
, void *context
)
5329 /* Don't propogate error information up to the client. Instead let
5330 the client find out about the error by querying the target. */
5331 async_client_callback (INF_REG_EVENT
, async_client_context
);
5335 remote_async (void (*callback
) (enum inferior_event_type event_type
, void *context
), void *context
)
5337 if (current_target
.to_async_mask_value
== 0)
5338 internal_error (__FILE__
, __LINE__
,
5339 "Calling remote_async when async is masked");
5341 if (callback
!= NULL
)
5343 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5344 async_client_callback
= callback
;
5345 async_client_context
= context
;
5348 serial_async (remote_desc
, NULL
, NULL
);
5351 /* Target async and target extended-async.
5353 This are temporary targets, until it is all tested. Eventually
5354 async support will be incorporated int the usual 'remote'
5358 init_remote_async_ops (void)
5360 remote_async_ops
.to_shortname
= "async";
5361 remote_async_ops
.to_longname
= "Remote serial target in async version of the gdb-specific protocol";
5362 remote_async_ops
.to_doc
=
5363 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5364 Specify the serial device it is connected to (e.g. /dev/ttya).";
5365 remote_async_ops
.to_open
= remote_async_open
;
5366 remote_async_ops
.to_close
= remote_close
;
5367 remote_async_ops
.to_detach
= remote_detach
;
5368 remote_async_ops
.to_disconnect
= remote_disconnect
;
5369 remote_async_ops
.to_resume
= remote_async_resume
;
5370 remote_async_ops
.to_wait
= remote_async_wait
;
5371 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5372 remote_async_ops
.to_store_registers
= remote_store_registers
;
5373 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5374 remote_async_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
5375 remote_async_ops
.to_files_info
= remote_files_info
;
5376 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5377 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5378 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5379 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5380 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5381 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5382 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5383 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5384 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5385 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5386 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5387 remote_async_ops
.to_kill
= remote_async_kill
;
5388 remote_async_ops
.to_load
= generic_load
;
5389 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5390 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5391 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5392 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
5393 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5394 remote_async_ops
.to_stop
= remote_stop
;
5395 remote_async_ops
.to_xfer_partial
= remote_xfer_partial
;
5396 remote_async_ops
.to_rcmd
= remote_rcmd
;
5397 remote_async_ops
.to_stratum
= process_stratum
;
5398 remote_async_ops
.to_has_all_memory
= 1;
5399 remote_async_ops
.to_has_memory
= 1;
5400 remote_async_ops
.to_has_stack
= 1;
5401 remote_async_ops
.to_has_registers
= 1;
5402 remote_async_ops
.to_has_execution
= 1;
5403 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5404 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5405 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5406 remote_async_ops
.to_async
= remote_async
;
5407 remote_async_ops
.to_async_mask_value
= 1;
5408 remote_async_ops
.to_magic
= OPS_MAGIC
;
5411 /* Set up the async extended remote vector by making a copy of the standard
5412 remote vector and adding to it. */
5415 init_extended_async_remote_ops (void)
5417 extended_async_remote_ops
= remote_async_ops
;
5419 extended_async_remote_ops
.to_shortname
= "extended-async";
5420 extended_async_remote_ops
.to_longname
=
5421 "Extended remote serial target in async gdb-specific protocol";
5422 extended_async_remote_ops
.to_doc
=
5423 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5424 Specify the serial device it is connected to (e.g. /dev/ttya).",
5425 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5426 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5427 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5431 set_remote_cmd (char *args
, int from_tty
)
5436 show_remote_cmd (char *args
, int from_tty
)
5438 /* FIXME: cagney/2002-06-15: This function should iterate over
5439 remote_show_cmdlist for a list of sub commands to show. */
5440 show_remote_protocol_Z_packet_cmd (args
, from_tty
, NULL
);
5441 show_remote_protocol_P_packet_cmd (args
, from_tty
, NULL
);
5442 show_remote_protocol_p_packet_cmd (args
, from_tty
, NULL
);
5443 show_remote_protocol_qSymbol_packet_cmd (args
, from_tty
, NULL
);
5444 show_remote_protocol_vcont_packet_cmd (args
, from_tty
, NULL
);
5445 show_remote_protocol_binary_download_cmd (args
, from_tty
, NULL
);
5446 show_remote_protocol_qPart_auxv_packet_cmd (args
, from_tty
, NULL
);
5450 build_remote_gdbarch_data (void)
5452 remote_address_size
= TARGET_ADDR_BIT
;
5455 /* Saved pointer to previous owner of the new_objfile event. */
5456 static void (*remote_new_objfile_chain
) (struct objfile
*);
5458 /* Function to be called whenever a new objfile (shlib) is detected. */
5460 remote_new_objfile (struct objfile
*objfile
)
5462 if (remote_desc
!= 0) /* Have a remote connection */
5464 remote_check_symbols (objfile
);
5466 /* Call predecessor on chain, if any. */
5467 if (remote_new_objfile_chain
!= 0 &&
5469 remote_new_objfile_chain (objfile
);
5473 _initialize_remote (void)
5475 static struct cmd_list_element
*remote_set_cmdlist
;
5476 static struct cmd_list_element
*remote_show_cmdlist
;
5477 struct cmd_list_element
*tmpcmd
;
5479 /* architecture specific data */
5480 remote_gdbarch_data_handle
= gdbarch_data_register_post_init (init_remote_state
);
5482 /* Old tacky stuff. NOTE: This comes after the remote protocol so
5483 that the remote protocol has been initialized. */
5484 DEPRECATED_REGISTER_GDBARCH_SWAP (remote_address_size
);
5485 deprecated_register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5488 add_target (&remote_ops
);
5490 init_extended_remote_ops ();
5491 add_target (&extended_remote_ops
);
5493 init_remote_async_ops ();
5494 add_target (&remote_async_ops
);
5496 init_extended_async_remote_ops ();
5497 add_target (&extended_async_remote_ops
);
5499 /* Hook into new objfile notification. */
5500 remote_new_objfile_chain
= deprecated_target_new_objfile_hook
;
5501 deprecated_target_new_objfile_hook
= remote_new_objfile
;
5504 init_remote_threadtests ();
5507 /* set/show remote ... */
5509 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, "\
5510 Remote protocol specific variables\n\
5511 Configure various remote-protocol specific variables such as\n\
5512 the packets being used",
5513 &remote_set_cmdlist
, "set remote ",
5514 0/*allow-unknown*/, &setlist
);
5515 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, "\
5516 Remote protocol specific variables\n\
5517 Configure various remote-protocol specific variables such as\n\
5518 the packets being used",
5519 &remote_show_cmdlist
, "show remote ",
5520 0/*allow-unknown*/, &showlist
);
5522 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
5523 "Compare section data on target to the exec file.\n\
5524 Argument is a single section name (default: all loaded sections).",
5527 add_cmd ("packet", class_maintenance
, packet_command
,
5528 "Send an arbitrary packet to a remote target.\n\
5529 maintenance packet TEXT\n\
5530 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5531 this command sends the string TEXT to the inferior, and displays the\n\
5532 response packet. GDB supplies the initial `$' character, and the\n\
5533 terminating `#' character and checksum.",
5536 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, "\
5537 Set whether to send break if interrupted.", "\
5538 Show whether to send break if interrupted.", "\
5539 If set, a break, instead of a cntrl-c, is sent to the remote target.", "\
5540 Whether to send break if interrupted is %s.",
5542 &setlist
, &showlist
);
5544 /* Install commands for configuring memory read/write packets. */
5546 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
,
5547 "Set the maximum number of bytes per memory write packet (deprecated).\n",
5549 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
,
5550 "Show the maximum number of bytes per memory write packet (deprecated).\n",
5552 add_cmd ("memory-write-packet-size", no_class
,
5553 set_memory_write_packet_size
,
5554 "Set the maximum number of bytes per memory-write packet.\n"
5555 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5556 "default packet size. The actual limit is further reduced\n"
5557 "dependent on the target. Specify ``fixed'' to disable the\n"
5558 "further restriction and ``limit'' to enable that restriction\n",
5559 &remote_set_cmdlist
);
5560 add_cmd ("memory-read-packet-size", no_class
,
5561 set_memory_read_packet_size
,
5562 "Set the maximum number of bytes per memory-read packet.\n"
5563 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5564 "default packet size. The actual limit is further reduced\n"
5565 "dependent on the target. Specify ``fixed'' to disable the\n"
5566 "further restriction and ``limit'' to enable that restriction\n",
5567 &remote_set_cmdlist
);
5568 add_cmd ("memory-write-packet-size", no_class
,
5569 show_memory_write_packet_size
,
5570 "Show the maximum number of bytes per memory-write packet.\n",
5571 &remote_show_cmdlist
);
5572 add_cmd ("memory-read-packet-size", no_class
,
5573 show_memory_read_packet_size
,
5574 "Show the maximum number of bytes per memory-read packet.\n",
5575 &remote_show_cmdlist
);
5577 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
5578 &remote_hw_watchpoint_limit
, "\
5579 Set the maximum number of target hardware watchpoints.", "\
5580 Show the maximum number of target hardware watchpoints.", "\
5581 Specify a negative limit for unlimited.", "\
5582 The maximum number of target hardware watchpoints is %s.",
5584 &remote_set_cmdlist
, &remote_show_cmdlist
);
5585 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
5586 &remote_hw_breakpoint_limit
, "\
5587 Set the maximum number of target hardware breakpoints.", "\
5588 Show the maximum number of target hardware breakpoints.", "\
5589 Specify a negative limit for unlimited.", "\
5590 The maximum number of target hardware breakpoints is %s.",
5592 &remote_set_cmdlist
, &remote_show_cmdlist
);
5594 deprecated_add_show_from_set
5595 (add_set_cmd ("remoteaddresssize", class_obscure
,
5596 var_integer
, (char *) &remote_address_size
,
5597 "Set the maximum size of the address (in bits) \
5598 in a memory packet.\n",
5602 add_packet_config_cmd (&remote_protocol_binary_download
,
5603 "X", "binary-download",
5604 set_remote_protocol_binary_download_cmd
,
5605 show_remote_protocol_binary_download_cmd
,
5606 &remote_set_cmdlist
, &remote_show_cmdlist
,
5609 /* XXXX - should ``set remotebinarydownload'' be retained for
5611 deprecated_add_show_from_set
5612 (add_set_cmd ("remotebinarydownload", no_class
,
5613 var_boolean
, (char *) &remote_binary_download
,
5614 "Set binary downloads.\n", &setlist
),
5618 add_packet_config_cmd (&remote_protocol_vcont
,
5619 "vCont", "verbose-resume",
5620 set_remote_protocol_vcont_packet_cmd
,
5621 show_remote_protocol_vcont_packet_cmd
,
5622 &remote_set_cmdlist
, &remote_show_cmdlist
,
5625 add_packet_config_cmd (&remote_protocol_qSymbol
,
5626 "qSymbol", "symbol-lookup",
5627 set_remote_protocol_qSymbol_packet_cmd
,
5628 show_remote_protocol_qSymbol_packet_cmd
,
5629 &remote_set_cmdlist
, &remote_show_cmdlist
,
5632 add_packet_config_cmd (&remote_protocol_P
,
5633 "P", "set-register",
5634 set_remote_protocol_P_packet_cmd
,
5635 show_remote_protocol_P_packet_cmd
,
5636 &remote_set_cmdlist
, &remote_show_cmdlist
,
5639 add_packet_config_cmd (&remote_protocol_p
,
5640 "p", "fetch-register",
5641 set_remote_protocol_p_packet_cmd
,
5642 show_remote_protocol_p_packet_cmd
,
5643 &remote_set_cmdlist
, &remote_show_cmdlist
,
5646 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
5647 "Z0", "software-breakpoint",
5648 set_remote_protocol_Z_software_bp_packet_cmd
,
5649 show_remote_protocol_Z_software_bp_packet_cmd
,
5650 &remote_set_cmdlist
, &remote_show_cmdlist
,
5653 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
5654 "Z1", "hardware-breakpoint",
5655 set_remote_protocol_Z_hardware_bp_packet_cmd
,
5656 show_remote_protocol_Z_hardware_bp_packet_cmd
,
5657 &remote_set_cmdlist
, &remote_show_cmdlist
,
5660 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
5661 "Z2", "write-watchpoint",
5662 set_remote_protocol_Z_write_wp_packet_cmd
,
5663 show_remote_protocol_Z_write_wp_packet_cmd
,
5664 &remote_set_cmdlist
, &remote_show_cmdlist
,
5667 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
5668 "Z3", "read-watchpoint",
5669 set_remote_protocol_Z_read_wp_packet_cmd
,
5670 show_remote_protocol_Z_read_wp_packet_cmd
,
5671 &remote_set_cmdlist
, &remote_show_cmdlist
,
5674 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
5675 "Z4", "access-watchpoint",
5676 set_remote_protocol_Z_access_wp_packet_cmd
,
5677 show_remote_protocol_Z_access_wp_packet_cmd
,
5678 &remote_set_cmdlist
, &remote_show_cmdlist
,
5681 add_packet_config_cmd (&remote_protocol_qPart_auxv
,
5682 "qPart_auxv", "read-aux-vector",
5683 set_remote_protocol_qPart_auxv_packet_cmd
,
5684 show_remote_protocol_qPart_auxv_packet_cmd
,
5685 &remote_set_cmdlist
, &remote_show_cmdlist
,
5688 /* Keep the old ``set remote Z-packet ...'' working. */
5689 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
5690 &remote_Z_packet_detect
, "\
5691 Set use of remote protocol `Z' packets", "\
5692 Show use of remote protocol `Z' packets ", "\
5693 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
5695 Use of remote protocol `Z' packets is %s",
5696 set_remote_protocol_Z_packet_cmd
,
5697 show_remote_protocol_Z_packet_cmd
,
5698 &remote_set_cmdlist
, &remote_show_cmdlist
);
5700 /* Eventually initialize fileio. See fileio.c */
5701 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);