1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
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., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
24 /* See the GDB User Guide for details of the GDB remote protocol. */
27 #include "gdb_string.h"
33 #include "exceptions.h"
35 /*#include "terminal.h" */
38 #include "gdb-stabs.h"
39 #include "gdbthread.h"
43 #include "gdb_assert.h"
46 #include "cli/cli-decode.h"
47 #include "cli/cli-setshow.h"
52 #include "event-loop.h"
53 #include "event-top.h"
59 #include "gdbcore.h" /* for exec_bfd */
61 #include "remote-fileio.h"
63 /* Prototypes for local functions. */
64 static void cleanup_sigint_signal_handler (void *dummy
);
65 static void initialize_sigint_signal_handler (void);
66 static int getpkt_sane (char *buf
, long sizeof_buf
, int forever
);
68 static void handle_remote_sigint (int);
69 static void handle_remote_sigint_twice (int);
70 static void async_remote_interrupt (gdb_client_data
);
71 void async_remote_interrupt_twice (gdb_client_data
);
73 static void build_remote_gdbarch_data (void);
75 static void remote_files_info (struct target_ops
*ignore
);
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 void remote_open (char *name
, int from_tty
);
86 static void remote_async_open (char *name
, int from_tty
);
88 static void extended_remote_open (char *name
, int from_tty
);
89 static void extended_remote_async_open (char *name
, int from_tty
);
91 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
,
94 static void remote_close (int quitting
);
96 static void remote_store_registers (int regno
);
98 static void remote_mourn (void);
99 static void remote_async_mourn (void);
101 static void extended_remote_restart (void);
103 static void extended_remote_mourn (void);
105 static void remote_mourn_1 (struct target_ops
*);
107 static void remote_send (char *buf
, long sizeof_buf
);
109 static int readchar (int timeout
);
111 static ptid_t
remote_wait (ptid_t ptid
,
112 struct target_waitstatus
*status
);
113 static ptid_t
remote_async_wait (ptid_t ptid
,
114 struct target_waitstatus
*status
);
116 static void remote_kill (void);
117 static void remote_async_kill (void);
119 static int tohex (int nib
);
121 static void remote_detach (char *args
, int from_tty
);
123 static void remote_interrupt (int signo
);
125 static void remote_interrupt_twice (int signo
);
127 static void interrupt_query (void);
129 static void set_thread (int, int);
131 static int remote_thread_alive (ptid_t
);
133 static void get_offsets (void);
135 static long read_frame (char *buf
, long sizeof_buf
);
137 static int remote_insert_breakpoint (CORE_ADDR
, bfd_byte
*);
139 static int remote_remove_breakpoint (CORE_ADDR
, bfd_byte
*);
141 static int hexnumlen (ULONGEST num
);
143 static void init_remote_ops (void);
145 static void init_extended_remote_ops (void);
147 static void remote_stop (void);
149 static int ishex (int ch
, int *val
);
151 static int stubhex (int ch
);
153 static int hexnumstr (char *, ULONGEST
);
155 static int hexnumnstr (char *, ULONGEST
, int);
157 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
159 static void print_packet (char *);
161 static unsigned long crc32 (unsigned char *, int, unsigned int);
163 static void compare_sections_command (char *, int);
165 static void packet_command (char *, int);
167 static int stub_unpack_int (char *buff
, int fieldlength
);
169 static ptid_t
remote_current_thread (ptid_t oldptid
);
171 static void remote_find_new_threads (void);
173 static void record_currthread (int currthread
);
175 static int fromhex (int a
);
177 static int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
179 static int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
181 static int putpkt_binary (char *buf
, int cnt
);
183 static void check_binary_download (CORE_ADDR addr
);
185 struct packet_config
;
187 static void show_packet_config_cmd (struct packet_config
*config
);
189 static void update_packet_config (struct packet_config
*config
);
191 void _initialize_remote (void);
193 /* Description of the remote protocol. Strictly speaking, when the
194 target is open()ed, remote.c should create a per-target description
195 of the remote protocol using that target's architecture.
196 Unfortunately, the target stack doesn't include local state. For
197 the moment keep the information in the target's architecture
202 long offset
; /* Offset into G packet. */
203 long regnum
; /* GDB's internal register number. */
204 LONGEST pnum
; /* Remote protocol register number. */
205 int in_g_packet
; /* Always part of G packet. */
206 /* long size in bytes; == register_size (current_gdbarch, regnum);
208 /* char *name; == REGISTER_NAME (regnum); at present. */
213 /* Description of the remote protocol registers. */
214 long sizeof_g_packet
;
216 /* Description of the remote protocol registers indexed by REGNUM
217 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
218 struct packet_reg
*regs
;
220 /* This is the size (in chars) of the first response to the ``g''
221 packet. It is used as a heuristic when determining the maximum
222 size of memory-read and memory-write packets. A target will
223 typically only reserve a buffer large enough to hold the ``g''
224 packet. The size does not include packet overhead (headers and
226 long actual_register_packet_size
;
228 /* This is the maximum size (in chars) of a non read/write packet.
229 It is also used as a cap on the size of read/write packets. */
230 long remote_packet_size
;
234 /* Handle for retreving the remote protocol data from gdbarch. */
235 static struct gdbarch_data
*remote_gdbarch_data_handle
;
237 static struct remote_state
*
238 get_remote_state (void)
240 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
244 init_remote_state (struct gdbarch
*gdbarch
)
247 struct remote_state
*rs
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_state
);
249 rs
->sizeof_g_packet
= 0;
251 /* Assume a 1:1 regnum<->pnum table. */
252 rs
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
, NUM_REGS
+ NUM_PSEUDO_REGS
,
254 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
256 struct packet_reg
*r
= &rs
->regs
[regnum
];
259 r
->offset
= DEPRECATED_REGISTER_BYTE (regnum
);
260 r
->in_g_packet
= (regnum
< NUM_REGS
);
261 /* ...name = REGISTER_NAME (regnum); */
263 /* Compute packet size by accumulating the size of all registers. */
264 if (regnum
< NUM_REGS
)
265 rs
->sizeof_g_packet
+= register_size (current_gdbarch
, regnum
);
268 /* Default maximum number of characters in a packet body. Many
269 remote stubs have a hardwired buffer size of 400 bytes
270 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
271 as the maximum packet-size to ensure that the packet and an extra
272 NUL character can always fit in the buffer. This stops GDB
273 trashing stubs that try to squeeze an extra NUL into what is
274 already a full buffer (As of 1999-12-04 that was most stubs. */
275 rs
->remote_packet_size
= 400 - 1;
277 /* Should rs->sizeof_g_packet needs more space than the
278 default, adjust the size accordingly. Remember that each byte is
279 encoded as two characters. 32 is the overhead for the packet
280 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
281 (``$NN:G...#NN'') is a better guess, the below has been padded a
283 if (rs
->sizeof_g_packet
> ((rs
->remote_packet_size
- 32) / 2))
284 rs
->remote_packet_size
= (rs
->sizeof_g_packet
* 2 + 32);
286 /* This one is filled in when a ``g'' packet is received. */
287 rs
->actual_register_packet_size
= 0;
292 static struct packet_reg
*
293 packet_reg_from_regnum (struct remote_state
*rs
, long regnum
)
295 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
299 struct packet_reg
*r
= &rs
->regs
[regnum
];
300 gdb_assert (r
->regnum
== regnum
);
305 static struct packet_reg
*
306 packet_reg_from_pnum (struct remote_state
*rs
, LONGEST pnum
)
309 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
311 struct packet_reg
*r
= &rs
->regs
[i
];
318 /* FIXME: graces/2002-08-08: These variables should eventually be
319 bound to an instance of the target object (as in gdbarch-tdep()),
320 when such a thing exists. */
322 /* This is set to the data address of the access causing the target
323 to stop for a watchpoint. */
324 static CORE_ADDR remote_watch_data_address
;
326 /* This is non-zero if taregt stopped for a watchpoint. */
327 static int remote_stopped_by_watchpoint_p
;
330 static struct target_ops remote_ops
;
332 static struct target_ops extended_remote_ops
;
334 /* Temporary target ops. Just like the remote_ops and
335 extended_remote_ops, but with asynchronous support. */
336 static struct target_ops remote_async_ops
;
338 static struct target_ops extended_async_remote_ops
;
340 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
341 ``forever'' still use the normal timeout mechanism. This is
342 currently used by the ASYNC code to guarentee that target reads
343 during the initial connect always time-out. Once getpkt has been
344 modified to return a timeout indication and, in turn
345 remote_wait()/wait_for_inferior() have gained a timeout parameter
347 static int wait_forever_enabled_p
= 1;
350 /* This variable chooses whether to send a ^C or a break when the user
351 requests program interruption. Although ^C is usually what remote
352 systems expect, and that is the default here, sometimes a break is
353 preferable instead. */
355 static int remote_break
;
357 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
358 remote_open knows that we don't have a file open when the program
360 static struct serial
*remote_desc
= NULL
;
362 /* This variable sets the number of bits in an address that are to be
363 sent in a memory ("M" or "m") packet. Normally, after stripping
364 leading zeros, the entire address would be sent. This variable
365 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
366 initial implementation of remote.c restricted the address sent in
367 memory packets to ``host::sizeof long'' bytes - (typically 32
368 bits). Consequently, for 64 bit targets, the upper 32 bits of an
369 address was never sent. Since fixing this bug may cause a break in
370 some remote targets this variable is principly provided to
371 facilitate backward compatibility. */
373 static int remote_address_size
;
375 /* Tempoary to track who currently owns the terminal. See
376 target_async_terminal_* for more details. */
378 static int remote_async_terminal_ours_p
;
381 /* User configurable variables for the number of characters in a
382 memory read/write packet. MIN (rs->remote_packet_size,
383 rs->sizeof_g_packet) is the default. Some targets need smaller
384 values (fifo overruns, et.al.) and some users need larger values
385 (speed up transfers). The variables ``preferred_*'' (the user
386 request), ``current_*'' (what was actually set) and ``forced_*''
387 (Positive - a soft limit, negative - a hard limit). */
389 struct memory_packet_config
396 /* Compute the current size of a read/write packet. Since this makes
397 use of ``actual_register_packet_size'' the computation is dynamic. */
400 get_memory_packet_size (struct memory_packet_config
*config
)
402 struct remote_state
*rs
= get_remote_state ();
403 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
404 law?) that some hosts don't cope very well with large alloca()
405 calls. Eventually the alloca() code will be replaced by calls to
406 xmalloc() and make_cleanups() allowing this restriction to either
407 be lifted or removed. */
408 #ifndef MAX_REMOTE_PACKET_SIZE
409 #define MAX_REMOTE_PACKET_SIZE 16384
411 /* NOTE: 20 ensures we can write at least one byte. */
412 #ifndef MIN_REMOTE_PACKET_SIZE
413 #define MIN_REMOTE_PACKET_SIZE 20
418 if (config
->size
<= 0)
419 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
421 what_they_get
= config
->size
;
425 what_they_get
= rs
->remote_packet_size
;
426 /* Limit the packet to the size specified by the user. */
428 && what_they_get
> config
->size
)
429 what_they_get
= config
->size
;
430 /* Limit it to the size of the targets ``g'' response. */
431 if ((rs
->actual_register_packet_size
) > 0
432 && what_they_get
> (rs
->actual_register_packet_size
))
433 what_they_get
= (rs
->actual_register_packet_size
);
435 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
436 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
437 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
438 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
439 return what_they_get
;
442 /* Update the size of a read/write packet. If they user wants
443 something really big then do a sanity check. */
446 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
448 int fixed_p
= config
->fixed_p
;
449 long size
= config
->size
;
451 error (_("Argument required (integer, `fixed' or `limited')."));
452 else if (strcmp (args
, "hard") == 0
453 || strcmp (args
, "fixed") == 0)
455 else if (strcmp (args
, "soft") == 0
456 || strcmp (args
, "limit") == 0)
461 size
= strtoul (args
, &end
, 0);
463 error (_("Invalid %s (bad syntax)."), config
->name
);
465 /* Instead of explicitly capping the size of a packet to
466 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
467 instead allowed to set the size to something arbitrarily
469 if (size
> MAX_REMOTE_PACKET_SIZE
)
470 error (_("Invalid %s (too large)."), config
->name
);
474 if (fixed_p
&& !config
->fixed_p
)
476 if (! query (_("The target may not be able to correctly handle a %s\n"
477 "of %ld bytes. Change the packet size? "),
479 error (_("Packet size not changed."));
481 /* Update the config. */
482 config
->fixed_p
= fixed_p
;
487 show_memory_packet_size (struct memory_packet_config
*config
)
489 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
491 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
492 get_memory_packet_size (config
));
494 printf_filtered (_("Packets are limited to %ld bytes.\n"),
495 get_memory_packet_size (config
));
498 static struct memory_packet_config memory_write_packet_config
=
500 "memory-write-packet-size",
504 set_memory_write_packet_size (char *args
, int from_tty
)
506 set_memory_packet_size (args
, &memory_write_packet_config
);
510 show_memory_write_packet_size (char *args
, int from_tty
)
512 show_memory_packet_size (&memory_write_packet_config
);
516 get_memory_write_packet_size (void)
518 return get_memory_packet_size (&memory_write_packet_config
);
521 static struct memory_packet_config memory_read_packet_config
=
523 "memory-read-packet-size",
527 set_memory_read_packet_size (char *args
, int from_tty
)
529 set_memory_packet_size (args
, &memory_read_packet_config
);
533 show_memory_read_packet_size (char *args
, int from_tty
)
535 show_memory_packet_size (&memory_read_packet_config
);
539 get_memory_read_packet_size (void)
541 struct remote_state
*rs
= get_remote_state ();
542 long size
= get_memory_packet_size (&memory_read_packet_config
);
543 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
544 extra buffer size argument before the memory read size can be
545 increased beyond RS->remote_packet_size. */
546 if (size
> rs
->remote_packet_size
)
547 size
= rs
->remote_packet_size
;
552 /* Generic configuration support for packets the stub optionally
553 supports. Allows the user to specify the use of the packet as well
554 as allowing GDB to auto-detect support in the remote stub. */
558 PACKET_SUPPORT_UNKNOWN
= 0,
567 enum auto_boolean detect
;
568 enum packet_support support
;
571 /* Analyze a packet's return value and update the packet config
582 update_packet_config (struct packet_config
*config
)
584 switch (config
->detect
)
586 case AUTO_BOOLEAN_TRUE
:
587 config
->support
= PACKET_ENABLE
;
589 case AUTO_BOOLEAN_FALSE
:
590 config
->support
= PACKET_DISABLE
;
592 case AUTO_BOOLEAN_AUTO
:
593 config
->support
= PACKET_SUPPORT_UNKNOWN
;
599 show_packet_config_cmd (struct packet_config
*config
)
601 char *support
= "internal-error";
602 switch (config
->support
)
608 support
= "disabled";
610 case PACKET_SUPPORT_UNKNOWN
:
614 switch (config
->detect
)
616 case AUTO_BOOLEAN_AUTO
:
617 printf_filtered (_("Support for the `%s' packet is auto-detected, currently %s.\n"),
618 config
->name
, support
);
620 case AUTO_BOOLEAN_TRUE
:
621 case AUTO_BOOLEAN_FALSE
:
622 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
623 config
->name
, support
);
629 add_packet_config_cmd (struct packet_config
*config
,
632 cmd_sfunc_ftype
*set_func
,
633 show_value_ftype
*show_func
,
634 struct cmd_list_element
**set_remote_list
,
635 struct cmd_list_element
**show_remote_list
,
643 config
->title
= title
;
644 config
->detect
= AUTO_BOOLEAN_AUTO
;
645 config
->support
= PACKET_SUPPORT_UNKNOWN
;
646 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
648 show_doc
= xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
650 /* set/show TITLE-packet {auto,on,off} */
651 cmd_name
= xstrprintf ("%s-packet", title
);
652 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
653 &config
->detect
, set_doc
, show_doc
, NULL
, /* help_doc */
655 set_remote_list
, show_remote_list
);
656 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
660 legacy_name
= xstrprintf ("%s-packet", name
);
661 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
663 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
668 static enum packet_result
669 packet_ok (const char *buf
, struct packet_config
*config
)
673 /* The stub recognized the packet request. Check that the
674 operation succeeded. */
675 switch (config
->support
)
677 case PACKET_SUPPORT_UNKNOWN
:
679 fprintf_unfiltered (gdb_stdlog
,
680 "Packet %s (%s) is supported\n",
681 config
->name
, config
->title
);
682 config
->support
= PACKET_ENABLE
;
685 internal_error (__FILE__
, __LINE__
,
686 _("packet_ok: attempt to use a disabled packet"));
691 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
692 /* "OK" - definitly OK. */
695 && isxdigit (buf
[1]) && isxdigit (buf
[2])
697 /* "Enn" - definitly an error. */
699 /* The packet may or may not be OK. Just assume it is. */
704 /* The stub does not support the packet. */
705 switch (config
->support
)
708 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
709 /* If the stub previously indicated that the packet was
710 supported then there is a protocol error.. */
711 error (_("Protocol error: %s (%s) conflicting enabled responses."),
712 config
->name
, config
->title
);
714 /* The user set it wrong. */
715 error (_("Enabled packet %s (%s) not recognized by stub"),
716 config
->name
, config
->title
);
718 case PACKET_SUPPORT_UNKNOWN
:
720 fprintf_unfiltered (gdb_stdlog
,
721 "Packet %s (%s) is NOT supported\n",
722 config
->name
, config
->title
);
723 config
->support
= PACKET_DISABLE
;
728 return PACKET_UNKNOWN
;
732 /* Should we try the 'vCont' (descriptive resume) request? */
733 static struct packet_config remote_protocol_vcont
;
736 set_remote_protocol_vcont_packet_cmd (char *args
, int from_tty
,
737 struct cmd_list_element
*c
)
739 update_packet_config (&remote_protocol_vcont
);
743 show_remote_protocol_vcont_packet_cmd (struct ui_file
*file
, int from_tty
,
744 struct cmd_list_element
*c
,
747 show_packet_config_cmd (&remote_protocol_vcont
);
750 /* Should we try the 'qSymbol' (target symbol lookup service) request? */
751 static struct packet_config remote_protocol_qSymbol
;
754 set_remote_protocol_qSymbol_packet_cmd (char *args
, int from_tty
,
755 struct cmd_list_element
*c
)
757 update_packet_config (&remote_protocol_qSymbol
);
761 show_remote_protocol_qSymbol_packet_cmd (struct ui_file
*file
, int from_tty
,
762 struct cmd_list_element
*c
,
765 show_packet_config_cmd (&remote_protocol_qSymbol
);
768 /* Should we try the 'P' (set register) request? */
770 static struct packet_config remote_protocol_P
;
773 set_remote_protocol_P_packet_cmd (char *args
, int from_tty
,
774 struct cmd_list_element
*c
)
776 update_packet_config (&remote_protocol_P
);
780 show_remote_protocol_P_packet_cmd (struct ui_file
*file
, int from_tty
,
781 struct cmd_list_element
*c
,
784 show_packet_config_cmd (&remote_protocol_P
);
787 /* Should we try one of the 'Z' requests? */
791 Z_PACKET_SOFTWARE_BP
,
792 Z_PACKET_HARDWARE_BP
,
799 static struct packet_config remote_protocol_Z
[NR_Z_PACKET_TYPES
];
801 /* FIXME: Instead of having all these boiler plate functions, the
802 command callback should include a context argument. */
805 set_remote_protocol_Z_software_bp_packet_cmd (char *args
, int from_tty
,
806 struct cmd_list_element
*c
)
808 update_packet_config (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
812 show_remote_protocol_Z_software_bp_packet_cmd (struct ui_file
*file
, int from_tty
,
813 struct cmd_list_element
*c
,
816 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]);
820 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args
, int from_tty
,
821 struct cmd_list_element
*c
)
823 update_packet_config (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
827 show_remote_protocol_Z_hardware_bp_packet_cmd (struct ui_file
*file
, int from_tty
,
828 struct cmd_list_element
*c
,
831 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]);
835 set_remote_protocol_Z_write_wp_packet_cmd (char *args
, int from_tty
,
836 struct cmd_list_element
*c
)
838 update_packet_config (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
842 show_remote_protocol_Z_write_wp_packet_cmd (struct ui_file
*file
, int from_tty
,
843 struct cmd_list_element
*c
,
846 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
]);
850 set_remote_protocol_Z_read_wp_packet_cmd (char *args
, int from_tty
,
851 struct cmd_list_element
*c
)
853 update_packet_config (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
857 show_remote_protocol_Z_read_wp_packet_cmd (struct ui_file
*file
, int from_tty
,
858 struct cmd_list_element
*c
,
861 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
]);
865 set_remote_protocol_Z_access_wp_packet_cmd (char *args
, int from_tty
,
866 struct cmd_list_element
*c
)
868 update_packet_config (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
872 show_remote_protocol_Z_access_wp_packet_cmd (struct ui_file
*file
, int from_tty
,
873 struct cmd_list_element
*c
,
876 show_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
]);
879 /* For compatibility with older distributions. Provide a ``set remote
880 Z-packet ...'' command that updates all the Z packet types. */
882 static enum auto_boolean remote_Z_packet_detect
;
885 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
886 struct cmd_list_element
*c
)
889 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
891 remote_protocol_Z
[i
].detect
= remote_Z_packet_detect
;
892 update_packet_config (&remote_protocol_Z
[i
]);
897 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
898 struct cmd_list_element
*c
,
902 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
904 show_packet_config_cmd (&remote_protocol_Z
[i
]);
908 /* Should we try the 'X' (remote binary download) packet?
910 This variable (available to the user via "set remote X-packet")
911 dictates whether downloads are sent in binary (via the 'X' packet).
912 We assume that the stub can, and attempt to do it. This will be
913 cleared if the stub does not understand it. This switch is still
914 needed, though in cases when the packet is supported in the stub,
915 but the connection does not allow it (i.e., 7-bit serial connection
918 static struct packet_config remote_protocol_binary_download
;
920 /* Should we try the 'ThreadInfo' query packet?
922 This variable (NOT available to the user: auto-detect only!)
923 determines whether GDB will use the new, simpler "ThreadInfo"
924 query or the older, more complex syntax for thread queries.
925 This is an auto-detect variable (set to true at each connect,
926 and set to false when the target fails to recognize it). */
928 static int use_threadinfo_query
;
929 static int use_threadextra_query
;
932 set_remote_protocol_binary_download_cmd (char *args
,
934 struct cmd_list_element
*c
)
936 update_packet_config (&remote_protocol_binary_download
);
940 show_remote_protocol_binary_download_cmd (struct ui_file
*file
, int from_tty
,
941 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 (struct ui_file
*file
, int from_tty
,
959 struct cmd_list_element
*c
,
962 show_packet_config_cmd (&remote_protocol_qPart_auxv
);
965 /* Should we try the 'qGetTLSAddr' (Get Thread Local Storage Address) request? */
966 static struct packet_config remote_protocol_qGetTLSAddr
;
969 set_remote_protocol_qGetTLSAddr_packet_cmd (char *args
, int from_tty
,
970 struct cmd_list_element
*c
)
972 update_packet_config (&remote_protocol_qGetTLSAddr
);
976 show_remote_protocol_qGetTLSAddr_packet_cmd (struct ui_file
*file
, int from_tty
,
977 struct cmd_list_element
*c
,
980 show_packet_config_cmd (&remote_protocol_qGetTLSAddr
);
983 static struct packet_config remote_protocol_p
;
986 set_remote_protocol_p_packet_cmd (char *args
, int from_tty
,
987 struct cmd_list_element
*c
)
989 update_packet_config (&remote_protocol_p
);
993 show_remote_protocol_p_packet_cmd (struct ui_file
*file
, int from_tty
,
994 struct cmd_list_element
*c
,
997 show_packet_config_cmd (&remote_protocol_p
);
1002 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1003 static void *sigint_remote_twice_token
;
1004 static void *sigint_remote_token
;
1006 /* These are pointers to hook functions that may be set in order to
1007 modify resume/wait behavior for a particular architecture. */
1009 void (*deprecated_target_resume_hook
) (void);
1010 void (*deprecated_target_wait_loop_hook
) (void);
1014 /* These are the threads which we last sent to the remote system.
1015 -1 for all or -2 for not sent yet. */
1016 static int general_thread
;
1017 static int continue_thread
;
1019 /* Call this function as a result of
1020 1) A halt indication (T packet) containing a thread id
1021 2) A direct query of currthread
1022 3) Successful execution of set thread
1026 record_currthread (int currthread
)
1028 general_thread
= currthread
;
1030 /* If this is a new thread, add it to GDB's thread list.
1031 If we leave it up to WFI to do this, bad things will happen. */
1032 if (!in_thread_list (pid_to_ptid (currthread
)))
1034 add_thread (pid_to_ptid (currthread
));
1035 ui_out_text (uiout
, "[New ");
1036 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
1037 ui_out_text (uiout
, "]\n");
1041 #define MAGIC_NULL_PID 42000
1044 set_thread (int th
, int gen
)
1046 struct remote_state
*rs
= get_remote_state ();
1047 char *buf
= alloca (rs
->remote_packet_size
);
1048 int state
= gen
? general_thread
: continue_thread
;
1054 buf
[1] = gen
? 'g' : 'c';
1055 if (th
== MAGIC_NULL_PID
)
1061 xsnprintf (&buf
[2], rs
->remote_packet_size
- 2, "-%x", -th
);
1063 xsnprintf (&buf
[2], rs
->remote_packet_size
- 2, "%x", th
);
1065 getpkt (buf
, rs
->remote_packet_size
, 0);
1067 general_thread
= th
;
1069 continue_thread
= th
;
1072 /* Return nonzero if the thread TH is still alive on the remote system. */
1075 remote_thread_alive (ptid_t ptid
)
1077 int tid
= PIDGET (ptid
);
1081 xsnprintf (buf
, sizeof (buf
), "T-%08x", -tid
);
1083 xsnprintf (buf
, sizeof (buf
), "T%08x", tid
);
1085 getpkt (buf
, sizeof (buf
), 0);
1086 return (buf
[0] == 'O' && buf
[1] == 'K');
1089 /* About these extended threadlist and threadinfo packets. They are
1090 variable length packets but, the fields within them are often fixed
1091 length. They are redundent enough to send over UDP as is the
1092 remote protocol in general. There is a matching unit test module
1095 #define OPAQUETHREADBYTES 8
1097 /* a 64 bit opaque identifier */
1098 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1100 /* WARNING: This threadref data structure comes from the remote O.S.,
1101 libstub protocol encoding, and remote.c. it is not particularly
1104 /* Right now, the internal structure is int. We want it to be bigger.
1108 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1110 /* gdb_ext_thread_info is an internal GDB data structure which is
1111 equivalint to the reply of the remote threadinfo packet. */
1113 struct gdb_ext_thread_info
1115 threadref threadid
; /* External form of thread reference. */
1116 int active
; /* Has state interesting to GDB?
1118 char display
[256]; /* Brief state display, name,
1119 blocked/suspended. */
1120 char shortname
[32]; /* To be used to name threads. */
1121 char more_display
[256]; /* Long info, statistics, queue depth,
1125 /* The volume of remote transfers can be limited by submitting
1126 a mask containing bits specifying the desired information.
1127 Use a union of these values as the 'selection' parameter to
1128 get_thread_info. FIXME: Make these TAG names more thread specific.
1131 #define TAG_THREADID 1
1132 #define TAG_EXISTS 2
1133 #define TAG_DISPLAY 4
1134 #define TAG_THREADNAME 8
1135 #define TAG_MOREDISPLAY 16
1137 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1139 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1141 static char *unpack_nibble (char *buf
, int *val
);
1143 static char *pack_nibble (char *buf
, int nibble
);
1145 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1147 static char *unpack_byte (char *buf
, int *value
);
1149 static char *pack_int (char *buf
, int value
);
1151 static char *unpack_int (char *buf
, int *value
);
1153 static char *unpack_string (char *src
, char *dest
, int length
);
1155 static char *pack_threadid (char *pkt
, threadref
*id
);
1157 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1159 void int_to_threadref (threadref
*id
, int value
);
1161 static int threadref_to_int (threadref
*ref
);
1163 static void copy_threadref (threadref
*dest
, threadref
*src
);
1165 static int threadmatch (threadref
*dest
, threadref
*src
);
1167 static char *pack_threadinfo_request (char *pkt
, int mode
,
1170 static int remote_unpack_thread_info_response (char *pkt
,
1171 threadref
*expectedref
,
1172 struct gdb_ext_thread_info
1176 static int remote_get_threadinfo (threadref
*threadid
,
1177 int fieldset
, /*TAG mask */
1178 struct gdb_ext_thread_info
*info
);
1180 static char *pack_threadlist_request (char *pkt
, int startflag
,
1182 threadref
*nextthread
);
1184 static int parse_threadlist_response (char *pkt
,
1186 threadref
*original_echo
,
1187 threadref
*resultlist
,
1190 static int remote_get_threadlist (int startflag
,
1191 threadref
*nextthread
,
1195 threadref
*threadlist
);
1197 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1199 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1200 void *context
, int looplimit
);
1202 static int remote_newthread_step (threadref
*ref
, void *context
);
1204 /* Encode 64 bits in 16 chars of hex. */
1206 static const char hexchars
[] = "0123456789abcdef";
1209 ishex (int ch
, int *val
)
1211 if ((ch
>= 'a') && (ch
<= 'f'))
1213 *val
= ch
- 'a' + 10;
1216 if ((ch
>= 'A') && (ch
<= 'F'))
1218 *val
= ch
- 'A' + 10;
1221 if ((ch
>= '0') && (ch
<= '9'))
1232 if (ch
>= 'a' && ch
<= 'f')
1233 return ch
- 'a' + 10;
1234 if (ch
>= '0' && ch
<= '9')
1236 if (ch
>= 'A' && ch
<= 'F')
1237 return ch
- 'A' + 10;
1242 stub_unpack_int (char *buff
, int fieldlength
)
1249 nibble
= stubhex (*buff
++);
1253 retval
= retval
<< 4;
1259 unpack_varlen_hex (char *buff
, /* packet to parse */
1265 while (ishex (*buff
, &nibble
))
1268 retval
= retval
<< 4;
1269 retval
|= nibble
& 0x0f;
1276 unpack_nibble (char *buf
, int *val
)
1278 ishex (*buf
++, val
);
1283 pack_nibble (char *buf
, int nibble
)
1285 *buf
++ = hexchars
[(nibble
& 0x0f)];
1290 pack_hex_byte (char *pkt
, int byte
)
1292 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1293 *pkt
++ = hexchars
[(byte
& 0xf)];
1298 unpack_byte (char *buf
, int *value
)
1300 *value
= stub_unpack_int (buf
, 2);
1305 pack_int (char *buf
, int value
)
1307 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1308 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1309 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1310 buf
= pack_hex_byte (buf
, (value
& 0xff));
1315 unpack_int (char *buf
, int *value
)
1317 *value
= stub_unpack_int (buf
, 8);
1321 #if 0 /* Currently unused, uncomment when needed. */
1322 static char *pack_string (char *pkt
, char *string
);
1325 pack_string (char *pkt
, char *string
)
1330 len
= strlen (string
);
1332 len
= 200; /* Bigger than most GDB packets, junk??? */
1333 pkt
= pack_hex_byte (pkt
, len
);
1337 if ((ch
== '\0') || (ch
== '#'))
1338 ch
= '*'; /* Protect encapsulation. */
1343 #endif /* 0 (unused) */
1346 unpack_string (char *src
, char *dest
, int length
)
1355 pack_threadid (char *pkt
, threadref
*id
)
1358 unsigned char *altid
;
1360 altid
= (unsigned char *) id
;
1361 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1363 pkt
= pack_hex_byte (pkt
, *altid
++);
1369 unpack_threadid (char *inbuf
, threadref
*id
)
1372 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1375 altref
= (char *) id
;
1377 while (inbuf
< limit
)
1379 x
= stubhex (*inbuf
++);
1380 y
= stubhex (*inbuf
++);
1381 *altref
++ = (x
<< 4) | y
;
1386 /* Externally, threadrefs are 64 bits but internally, they are still
1387 ints. This is due to a mismatch of specifications. We would like
1388 to use 64bit thread references internally. This is an adapter
1392 int_to_threadref (threadref
*id
, int value
)
1394 unsigned char *scan
;
1396 scan
= (unsigned char *) id
;
1402 *scan
++ = (value
>> 24) & 0xff;
1403 *scan
++ = (value
>> 16) & 0xff;
1404 *scan
++ = (value
>> 8) & 0xff;
1405 *scan
++ = (value
& 0xff);
1409 threadref_to_int (threadref
*ref
)
1412 unsigned char *scan
;
1418 value
= (value
<< 8) | ((*scan
++) & 0xff);
1423 copy_threadref (threadref
*dest
, threadref
*src
)
1426 unsigned char *csrc
, *cdest
;
1428 csrc
= (unsigned char *) src
;
1429 cdest
= (unsigned char *) dest
;
1436 threadmatch (threadref
*dest
, threadref
*src
)
1438 /* Things are broken right now, so just assume we got a match. */
1440 unsigned char *srcp
, *destp
;
1442 srcp
= (char *) src
;
1443 destp
= (char *) dest
;
1447 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1454 threadid:1, # always request threadid
1461 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1464 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1466 *pkt
++ = 'q'; /* Info Query */
1467 *pkt
++ = 'P'; /* process or thread info */
1468 pkt
= pack_int (pkt
, mode
); /* mode */
1469 pkt
= pack_threadid (pkt
, id
); /* threadid */
1470 *pkt
= '\0'; /* terminate */
1474 /* These values tag the fields in a thread info response packet. */
1475 /* Tagging the fields allows us to request specific fields and to
1476 add more fields as time goes by. */
1478 #define TAG_THREADID 1 /* Echo the thread identifier. */
1479 #define TAG_EXISTS 2 /* Is this process defined enough to
1480 fetch registers and its stack? */
1481 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1482 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
1483 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1487 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1488 struct gdb_ext_thread_info
*info
)
1490 struct remote_state
*rs
= get_remote_state ();
1494 char *limit
= pkt
+ rs
->remote_packet_size
; /* Plausible parsing limit. */
1497 /* info->threadid = 0; FIXME: implement zero_threadref. */
1499 info
->display
[0] = '\0';
1500 info
->shortname
[0] = '\0';
1501 info
->more_display
[0] = '\0';
1503 /* Assume the characters indicating the packet type have been
1505 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1506 pkt
= unpack_threadid (pkt
, &ref
);
1509 warning (_("Incomplete response to threadinfo request."));
1510 if (!threadmatch (&ref
, expectedref
))
1511 { /* This is an answer to a different request. */
1512 warning (_("ERROR RMT Thread info mismatch."));
1515 copy_threadref (&info
->threadid
, &ref
);
1517 /* Loop on tagged fields , try to bail if somthing goes wrong. */
1519 /* Packets are terminated with nulls. */
1520 while ((pkt
< limit
) && mask
&& *pkt
)
1522 pkt
= unpack_int (pkt
, &tag
); /* tag */
1523 pkt
= unpack_byte (pkt
, &length
); /* length */
1524 if (!(tag
& mask
)) /* Tags out of synch with mask. */
1526 warning (_("ERROR RMT: threadinfo tag mismatch."));
1530 if (tag
== TAG_THREADID
)
1534 warning (_("ERROR RMT: length of threadid is not 16."));
1538 pkt
= unpack_threadid (pkt
, &ref
);
1539 mask
= mask
& ~TAG_THREADID
;
1542 if (tag
== TAG_EXISTS
)
1544 info
->active
= stub_unpack_int (pkt
, length
);
1546 mask
= mask
& ~(TAG_EXISTS
);
1549 warning (_("ERROR RMT: 'exists' length too long."));
1555 if (tag
== TAG_THREADNAME
)
1557 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1558 mask
= mask
& ~TAG_THREADNAME
;
1561 if (tag
== TAG_DISPLAY
)
1563 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1564 mask
= mask
& ~TAG_DISPLAY
;
1567 if (tag
== TAG_MOREDISPLAY
)
1569 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1570 mask
= mask
& ~TAG_MOREDISPLAY
;
1573 warning (_("ERROR RMT: unknown thread info tag."));
1574 break; /* Not a tag we know about. */
1580 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1581 struct gdb_ext_thread_info
*info
)
1583 struct remote_state
*rs
= get_remote_state ();
1585 char *threadinfo_pkt
= alloca (rs
->remote_packet_size
);
1587 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1588 putpkt (threadinfo_pkt
);
1589 getpkt (threadinfo_pkt
, rs
->remote_packet_size
, 0);
1590 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2,
1595 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1598 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1599 threadref
*nextthread
)
1601 *pkt
++ = 'q'; /* info query packet */
1602 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1603 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1604 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1605 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1610 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1613 parse_threadlist_response (char *pkt
, int result_limit
,
1614 threadref
*original_echo
, threadref
*resultlist
,
1617 struct remote_state
*rs
= get_remote_state ();
1619 int count
, resultcount
, done
;
1622 /* Assume the 'q' and 'M chars have been stripped. */
1623 limit
= pkt
+ (rs
->remote_packet_size
- BUF_THREAD_ID_SIZE
);
1624 /* done parse past here */
1625 pkt
= unpack_byte (pkt
, &count
); /* count field */
1626 pkt
= unpack_nibble (pkt
, &done
);
1627 /* The first threadid is the argument threadid. */
1628 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1629 while ((count
-- > 0) && (pkt
< limit
))
1631 pkt
= unpack_threadid (pkt
, resultlist
++);
1632 if (resultcount
++ >= result_limit
)
1641 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1642 int *done
, int *result_count
, threadref
*threadlist
)
1644 struct remote_state
*rs
= get_remote_state ();
1645 static threadref echo_nextthread
;
1646 char *threadlist_packet
= alloca (rs
->remote_packet_size
);
1647 char *t_response
= alloca (rs
->remote_packet_size
);
1650 /* Trancate result limit to be smaller than the packet size. */
1651 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= rs
->remote_packet_size
)
1652 result_limit
= (rs
->remote_packet_size
/ BUF_THREAD_ID_SIZE
) - 2;
1654 pack_threadlist_request (threadlist_packet
,
1655 startflag
, result_limit
, nextthread
);
1656 putpkt (threadlist_packet
);
1657 getpkt (t_response
, rs
->remote_packet_size
, 0);
1660 parse_threadlist_response (t_response
+ 2, result_limit
, &echo_nextthread
,
1663 if (!threadmatch (&echo_nextthread
, nextthread
))
1665 /* FIXME: This is a good reason to drop the packet. */
1666 /* Possably, there is a duplicate response. */
1668 retransmit immediatly - race conditions
1669 retransmit after timeout - yes
1671 wait for packet, then exit
1673 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
1674 return 0; /* I choose simply exiting. */
1676 if (*result_count
<= 0)
1680 warning (_("RMT ERROR : failed to get remote thread list."));
1683 return result
; /* break; */
1685 if (*result_count
> result_limit
)
1688 warning (_("RMT ERROR: threadlist response longer than requested."));
1694 /* This is the interface between remote and threads, remotes upper
1697 /* remote_find_new_threads retrieves the thread list and for each
1698 thread in the list, looks up the thread in GDB's internal list,
1699 ading the thread if it does not already exist. This involves
1700 getting partial thread lists from the remote target so, polling the
1701 quit_flag is required. */
1704 /* About this many threadisds fit in a packet. */
1706 #define MAXTHREADLISTRESULTS 32
1709 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1712 int done
, i
, result_count
;
1716 static threadref nextthread
;
1717 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1722 if (loopcount
++ > looplimit
)
1725 warning (_("Remote fetch threadlist -infinite loop-."));
1728 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1729 &done
, &result_count
, resultthreadlist
))
1734 /* Clear for later iterations. */
1736 /* Setup to resume next batch of thread references, set nextthread. */
1737 if (result_count
>= 1)
1738 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1740 while (result_count
--)
1741 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1748 remote_newthread_step (threadref
*ref
, void *context
)
1752 ptid
= pid_to_ptid (threadref_to_int (ref
));
1754 if (!in_thread_list (ptid
))
1756 return 1; /* continue iterator */
1759 #define CRAZY_MAX_THREADS 1000
1762 remote_current_thread (ptid_t oldpid
)
1764 struct remote_state
*rs
= get_remote_state ();
1765 char *buf
= alloca (rs
->remote_packet_size
);
1768 getpkt (buf
, rs
->remote_packet_size
, 0);
1769 if (buf
[0] == 'Q' && buf
[1] == 'C')
1770 /* Use strtoul here, so we'll correctly parse values whose highest
1771 bit is set. The protocol carries them as a simple series of
1772 hex digits; in the absence of a sign, strtol will see such
1773 values as positive numbers out of range for signed 'long', and
1774 return LONG_MAX to indicate an overflow. */
1775 return pid_to_ptid (strtoul (&buf
[2], NULL
, 16));
1780 /* Find new threads for info threads command.
1781 * Original version, using John Metzler's thread protocol.
1785 remote_find_new_threads (void)
1787 remote_threadlist_iterator (remote_newthread_step
, 0,
1789 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1790 inferior_ptid
= remote_current_thread (inferior_ptid
);
1794 * Find all threads for info threads command.
1795 * Uses new thread protocol contributed by Cisco.
1796 * Falls back and attempts to use the older method (above)
1797 * if the target doesn't respond to the new method.
1801 remote_threads_info (void)
1803 struct remote_state
*rs
= get_remote_state ();
1804 char *buf
= alloca (rs
->remote_packet_size
);
1808 if (remote_desc
== 0) /* paranoia */
1809 error (_("Command can only be used when connected to the remote target."));
1811 if (use_threadinfo_query
)
1813 putpkt ("qfThreadInfo");
1815 getpkt (bufp
, rs
->remote_packet_size
, 0);
1816 if (bufp
[0] != '\0') /* q packet recognized */
1818 while (*bufp
++ == 'm') /* reply contains one or more TID */
1822 /* Use strtoul here, so we'll correctly parse values
1823 whose highest bit is set. The protocol carries
1824 them as a simple series of hex digits; in the
1825 absence of a sign, strtol will see such values as
1826 positive numbers out of range for signed 'long',
1827 and return LONG_MAX to indicate an overflow. */
1828 tid
= strtoul (bufp
, &bufp
, 16);
1829 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1830 add_thread (pid_to_ptid (tid
));
1832 while (*bufp
++ == ','); /* comma-separated list */
1833 putpkt ("qsThreadInfo");
1835 getpkt (bufp
, rs
->remote_packet_size
, 0);
1841 /* Else fall back to old method based on jmetzler protocol. */
1842 use_threadinfo_query
= 0;
1843 remote_find_new_threads ();
1848 * Collect a descriptive string about the given thread.
1849 * The target may say anything it wants to about the thread
1850 * (typically info about its blocked / runnable state, name, etc.).
1851 * This string will appear in the info threads display.
1853 * Optional: targets are not required to implement this function.
1857 remote_threads_extra_info (struct thread_info
*tp
)
1859 struct remote_state
*rs
= get_remote_state ();
1863 struct gdb_ext_thread_info threadinfo
;
1864 static char display_buf
[100]; /* arbitrary... */
1865 char *bufp
= alloca (rs
->remote_packet_size
);
1866 int n
= 0; /* position in display_buf */
1868 if (remote_desc
== 0) /* paranoia */
1869 internal_error (__FILE__
, __LINE__
,
1870 _("remote_threads_extra_info"));
1872 if (use_threadextra_query
)
1874 xsnprintf (bufp
, rs
->remote_packet_size
, "qThreadExtraInfo,%x",
1877 getpkt (bufp
, rs
->remote_packet_size
, 0);
1880 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1881 result
= hex2bin (bufp
, (gdb_byte
*) display_buf
, n
);
1882 display_buf
[result
] = '\0';
1887 /* If the above query fails, fall back to the old method. */
1888 use_threadextra_query
= 0;
1889 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1890 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1891 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1892 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1893 if (threadinfo
.active
)
1895 if (*threadinfo
.shortname
)
1896 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
1897 " Name: %s,", threadinfo
.shortname
);
1898 if (*threadinfo
.display
)
1899 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
1900 " State: %s,", threadinfo
.display
);
1901 if (*threadinfo
.more_display
)
1902 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
1903 " Priority: %s", threadinfo
.more_display
);
1907 /* For purely cosmetic reasons, clear up trailing commas. */
1908 if (',' == display_buf
[n
-1])
1909 display_buf
[n
-1] = ' ';
1917 /* Restart the remote side; this is an extended protocol operation. */
1920 extended_remote_restart (void)
1922 struct remote_state
*rs
= get_remote_state ();
1923 char *buf
= alloca (rs
->remote_packet_size
);
1925 /* Send the restart command; for reasons I don't understand the
1926 remote side really expects a number after the "R". */
1927 xsnprintf (buf
, rs
->remote_packet_size
, "R%x", 0);
1930 /* Now query for status so this looks just like we restarted
1931 gdbserver from scratch. */
1933 getpkt (buf
, rs
->remote_packet_size
, 0);
1936 /* Clean up connection to a remote debugger. */
1939 remote_close (int quitting
)
1942 serial_close (remote_desc
);
1946 /* Query the remote side for the text, data and bss offsets. */
1951 struct remote_state
*rs
= get_remote_state ();
1952 char *buf
= alloca (rs
->remote_packet_size
);
1955 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1956 struct section_offsets
*offs
;
1958 putpkt ("qOffsets");
1959 getpkt (buf
, rs
->remote_packet_size
, 0);
1961 if (buf
[0] == '\000')
1962 return; /* Return silently. Stub doesn't support
1966 warning (_("Remote failure reply: %s"), buf
);
1970 /* Pick up each field in turn. This used to be done with scanf, but
1971 scanf will make trouble if CORE_ADDR size doesn't match
1972 conversion directives correctly. The following code will work
1973 with any size of CORE_ADDR. */
1974 text_addr
= data_addr
= bss_addr
= 0;
1978 if (strncmp (ptr
, "Text=", 5) == 0)
1981 /* Don't use strtol, could lose on big values. */
1982 while (*ptr
&& *ptr
!= ';')
1983 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1988 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1991 while (*ptr
&& *ptr
!= ';')
1992 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1997 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
2000 while (*ptr
&& *ptr
!= ';')
2001 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
2007 error (_("Malformed response to offset query, %s"), buf
);
2009 if (symfile_objfile
== NULL
)
2012 offs
= ((struct section_offsets
*)
2013 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
2014 memcpy (offs
, symfile_objfile
->section_offsets
,
2015 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2017 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2019 /* This is a temporary kludge to force data and bss to use the same offsets
2020 because that's what nlmconv does now. The real solution requires changes
2021 to the stub and remote.c that I don't have time to do right now. */
2023 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2024 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2026 objfile_relocate (symfile_objfile
, offs
);
2029 /* Stub for catch_errors. */
2032 remote_start_remote_dummy (struct ui_out
*uiout
, void *dummy
)
2034 start_remote (); /* Initialize gdb process mechanisms. */
2035 /* NOTE: Return something >=0. A -ve value is reserved for
2036 catch_exceptions. */
2041 remote_start_remote (struct ui_out
*uiout
, void *dummy
)
2043 immediate_quit
++; /* Allow user to interrupt it. */
2045 /* Ack any packet which the remote side has already sent. */
2046 serial_write (remote_desc
, "+", 1);
2048 /* Let the stub know that we want it to return the thread. */
2051 inferior_ptid
= remote_current_thread (inferior_ptid
);
2053 get_offsets (); /* Get text, data & bss offsets. */
2055 putpkt ("?"); /* Initiate a query from remote machine. */
2058 remote_start_remote_dummy (uiout
, dummy
);
2061 /* Open a connection to a remote debugger.
2062 NAME is the filename used for communication. */
2065 remote_open (char *name
, int from_tty
)
2067 remote_open_1 (name
, from_tty
, &remote_ops
, 0, 0);
2070 /* Just like remote_open, but with asynchronous support. */
2072 remote_async_open (char *name
, int from_tty
)
2074 remote_open_1 (name
, from_tty
, &remote_async_ops
, 0, 1);
2077 /* Open a connection to a remote debugger using the extended
2078 remote gdb protocol. NAME is the filename used for communication. */
2081 extended_remote_open (char *name
, int from_tty
)
2083 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */,
2087 /* Just like extended_remote_open, but with asynchronous support. */
2089 extended_remote_async_open (char *name
, int from_tty
)
2091 remote_open_1 (name
, from_tty
, &extended_async_remote_ops
,
2092 1 /*extended_p */, 1 /* async_p */);
2095 /* Generic code for opening a connection to a remote target. */
2098 init_all_packet_configs (void)
2101 update_packet_config (&remote_protocol_P
);
2102 update_packet_config (&remote_protocol_p
);
2103 update_packet_config (&remote_protocol_qSymbol
);
2104 update_packet_config (&remote_protocol_vcont
);
2105 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
2106 update_packet_config (&remote_protocol_Z
[i
]);
2107 /* Force remote_write_bytes to check whether target supports binary
2109 update_packet_config (&remote_protocol_binary_download
);
2110 update_packet_config (&remote_protocol_qPart_auxv
);
2111 update_packet_config (&remote_protocol_qGetTLSAddr
);
2114 /* Symbol look-up. */
2117 remote_check_symbols (struct objfile
*objfile
)
2119 struct remote_state
*rs
= get_remote_state ();
2120 char *msg
, *reply
, *tmp
;
2121 struct minimal_symbol
*sym
;
2124 if (remote_protocol_qSymbol
.support
== PACKET_DISABLE
)
2127 msg
= alloca (rs
->remote_packet_size
);
2128 reply
= alloca (rs
->remote_packet_size
);
2130 /* Invite target to request symbol lookups. */
2132 putpkt ("qSymbol::");
2133 getpkt (reply
, rs
->remote_packet_size
, 0);
2134 packet_ok (reply
, &remote_protocol_qSymbol
);
2136 while (strncmp (reply
, "qSymbol:", 8) == 0)
2139 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
2141 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2143 xsnprintf (msg
, rs
->remote_packet_size
, "qSymbol::%s", &reply
[8]);
2145 xsnprintf (msg
, rs
->remote_packet_size
, "qSymbol:%s:%s",
2146 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2149 getpkt (reply
, rs
->remote_packet_size
, 0);
2153 static struct serial
*
2154 remote_serial_open (char *name
)
2156 static int udp_warning
= 0;
2158 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2159 of in ser-tcp.c, because it is the remote protocol assuming that the
2160 serial connection is reliable and not the serial connection promising
2162 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2165 The remote protocol may be unreliable over UDP.\n\
2166 Some events may be lost, rendering further debugging impossible."));
2170 return serial_open (name
);
2174 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2175 int extended_p
, int async_p
)
2177 struct remote_state
*rs
= get_remote_state ();
2179 error (_("To open a remote debug connection, you need to specify what\n"
2180 "serial device is attached to the remote system\n"
2181 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
2183 /* See FIXME above. */
2185 wait_forever_enabled_p
= 1;
2187 reopen_exec_file ();
2190 target_preopen (from_tty
);
2192 unpush_target (target
);
2194 remote_desc
= remote_serial_open (name
);
2196 perror_with_name (name
);
2198 if (baud_rate
!= -1)
2200 if (serial_setbaudrate (remote_desc
, baud_rate
))
2202 /* The requested speed could not be set. Error out to
2203 top level after closing remote_desc. Take care to
2204 set remote_desc to NULL to avoid closing remote_desc
2206 serial_close (remote_desc
);
2208 perror_with_name (name
);
2212 serial_raw (remote_desc
);
2214 /* If there is something sitting in the buffer we might take it as a
2215 response to a command, which would be bad. */
2216 serial_flush_input (remote_desc
);
2220 puts_filtered ("Remote debugging using ");
2221 puts_filtered (name
);
2222 puts_filtered ("\n");
2224 push_target (target
); /* Switch to using remote target now. */
2226 init_all_packet_configs ();
2228 general_thread
= -2;
2229 continue_thread
= -2;
2231 /* Probe for ability to use "ThreadInfo" query, as required. */
2232 use_threadinfo_query
= 1;
2233 use_threadextra_query
= 1;
2235 /* Without this, some commands which require an active target (such
2236 as kill) won't work. This variable serves (at least) double duty
2237 as both the pid of the target process (if it has such), and as a
2238 flag indicating that a target is active. These functions should
2239 be split out into seperate variables, especially since GDB will
2240 someday have a notion of debugging several processes. */
2242 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2246 /* With this target we start out by owning the terminal. */
2247 remote_async_terminal_ours_p
= 1;
2249 /* FIXME: cagney/1999-09-23: During the initial connection it is
2250 assumed that the target is already ready and able to respond to
2251 requests. Unfortunately remote_start_remote() eventually calls
2252 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2253 around this. Eventually a mechanism that allows
2254 wait_for_inferior() to expect/get timeouts will be
2256 wait_forever_enabled_p
= 0;
2259 /* First delete any symbols previously loaded from shared libraries. */
2260 no_shared_libraries (NULL
, 0);
2262 /* Start the remote connection. If error() or QUIT, discard this
2263 target (we'd otherwise be in an inconsistent state) and then
2264 propogate the error on up the exception chain. This ensures that
2265 the caller doesn't stumble along blindly assuming that the
2266 function succeeded. The CLI doesn't have this problem but other
2267 UI's, such as MI do.
2269 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2270 this function should return an error indication letting the
2271 caller restore the previous state. Unfortunately the command
2272 ``target remote'' is directly wired to this function making that
2273 impossible. On a positive note, the CLI side of this problem has
2274 been fixed - the function set_cmd_context() makes it possible for
2275 all the ``target ....'' commands to share a common callback
2276 function. See cli-dump.c. */
2278 struct gdb_exception ex
2279 = catch_exception (uiout
, remote_start_remote
, NULL
, RETURN_MASK_ALL
);
2284 wait_forever_enabled_p
= 1;
2285 throw_exception (ex
);
2290 wait_forever_enabled_p
= 1;
2294 /* Tell the remote that we are using the extended protocol. */
2295 char *buf
= alloca (rs
->remote_packet_size
);
2297 getpkt (buf
, rs
->remote_packet_size
, 0);
2300 post_create_inferior (¤t_target
, from_tty
);
2302 if (exec_bfd
) /* No use without an exec file. */
2303 remote_check_symbols (symfile_objfile
);
2306 /* This takes a program previously attached to and detaches it. After
2307 this is done, GDB can be used to debug some other program. We
2308 better not have left any breakpoints in the target program or it'll
2309 die when it hits one. */
2312 remote_detach (char *args
, int from_tty
)
2314 struct remote_state
*rs
= get_remote_state ();
2315 char *buf
= alloca (rs
->remote_packet_size
);
2318 error (_("Argument given to \"detach\" when remotely debugging."));
2320 /* Tell the remote target to detach. */
2322 remote_send (buf
, rs
->remote_packet_size
);
2324 /* Unregister the file descriptor from the event loop. */
2325 if (target_is_async_p ())
2326 serial_async (remote_desc
, NULL
, 0);
2328 target_mourn_inferior ();
2330 puts_filtered ("Ending remote debugging.\n");
2333 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
2336 remote_disconnect (char *args
, int from_tty
)
2339 error (_("Argument given to \"detach\" when remotely debugging."));
2341 /* Unregister the file descriptor from the event loop. */
2342 if (target_is_async_p ())
2343 serial_async (remote_desc
, NULL
, 0);
2345 target_mourn_inferior ();
2347 puts_filtered ("Ending remote debugging.\n");
2350 /* Convert hex digit A to a number. */
2355 if (a
>= '0' && a
<= '9')
2357 else if (a
>= 'a' && a
<= 'f')
2358 return a
- 'a' + 10;
2359 else if (a
>= 'A' && a
<= 'F')
2360 return a
- 'A' + 10;
2362 error (_("Reply contains invalid hex digit %d"), a
);
2366 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
2370 for (i
= 0; i
< count
; i
++)
2372 if (hex
[0] == 0 || hex
[1] == 0)
2374 /* Hex string is short, or of uneven length.
2375 Return the count that has been converted so far. */
2378 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2384 /* Convert number NIB to a hex digit. */
2392 return 'a' + nib
- 10;
2396 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
2399 /* May use a length, or a nul-terminated string as input. */
2401 count
= strlen ((char *) bin
);
2403 for (i
= 0; i
< count
; i
++)
2405 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2406 *hex
++ = tohex (*bin
++ & 0xf);
2412 /* Check for the availability of vCont. This function should also check
2416 remote_vcont_probe (struct remote_state
*rs
, char *buf
)
2418 strcpy (buf
, "vCont?");
2420 getpkt (buf
, rs
->remote_packet_size
, 0);
2422 /* Make sure that the features we assume are supported. */
2423 if (strncmp (buf
, "vCont", 5) == 0)
2426 int support_s
, support_S
, support_c
, support_C
;
2432 while (p
&& *p
== ';')
2435 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2437 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2439 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2441 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2444 p
= strchr (p
, ';');
2447 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
2448 BUF will make packet_ok disable the packet. */
2449 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
2453 packet_ok (buf
, &remote_protocol_vcont
);
2456 /* Resume the remote inferior by using a "vCont" packet. The thread
2457 to be resumed is PTID; STEP and SIGGNAL indicate whether the
2458 resumed thread should be single-stepped and/or signalled. If PTID's
2459 PID is -1, then all threads are resumed; the thread to be stepped and/or
2460 signalled is given in the global INFERIOR_PTID. This function returns
2461 non-zero iff it resumes the inferior.
2463 This function issues a strict subset of all possible vCont commands at the
2467 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2469 struct remote_state
*rs
= get_remote_state ();
2470 int pid
= PIDGET (ptid
);
2471 char *buf
= NULL
, *outbuf
;
2472 struct cleanup
*old_cleanup
;
2474 buf
= xmalloc (rs
->remote_packet_size
);
2475 old_cleanup
= make_cleanup (xfree
, buf
);
2477 if (remote_protocol_vcont
.support
== PACKET_SUPPORT_UNKNOWN
)
2478 remote_vcont_probe (rs
, buf
);
2480 if (remote_protocol_vcont
.support
== PACKET_DISABLE
)
2482 do_cleanups (old_cleanup
);
2486 /* If we could generate a wider range of packets, we'd have to worry
2487 about overflowing BUF. Should there be a generic
2488 "multi-part-packet" packet? */
2490 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
)
2492 /* MAGIC_NULL_PTID means that we don't have any active threads, so we
2493 don't have any PID numbers the inferior will understand. Make sure
2494 to only send forms that do not specify a PID. */
2495 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2496 outbuf
= xstrprintf ("vCont;S%02x", siggnal
);
2498 outbuf
= xstrprintf ("vCont;s");
2499 else if (siggnal
!= TARGET_SIGNAL_0
)
2500 outbuf
= xstrprintf ("vCont;C%02x", siggnal
);
2502 outbuf
= xstrprintf ("vCont;c");
2506 /* Resume all threads, with preference for INFERIOR_PTID. */
2507 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2508 outbuf
= xstrprintf ("vCont;S%02x:%x;c", siggnal
,
2509 PIDGET (inferior_ptid
));
2511 outbuf
= xstrprintf ("vCont;s:%x;c", PIDGET (inferior_ptid
));
2512 else if (siggnal
!= TARGET_SIGNAL_0
)
2513 outbuf
= xstrprintf ("vCont;C%02x:%x;c", siggnal
,
2514 PIDGET (inferior_ptid
));
2516 outbuf
= xstrprintf ("vCont;c");
2520 /* Scheduler locking; resume only PTID. */
2521 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2522 outbuf
= xstrprintf ("vCont;S%02x:%x", siggnal
, pid
);
2524 outbuf
= xstrprintf ("vCont;s:%x", pid
);
2525 else if (siggnal
!= TARGET_SIGNAL_0
)
2526 outbuf
= xstrprintf ("vCont;C%02x:%x", siggnal
, pid
);
2528 outbuf
= xstrprintf ("vCont;c:%x", pid
);
2531 gdb_assert (outbuf
&& strlen (outbuf
) < rs
->remote_packet_size
);
2532 make_cleanup (xfree
, outbuf
);
2536 do_cleanups (old_cleanup
);
2541 /* Tell the remote machine to resume. */
2543 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2545 static int last_sent_step
;
2548 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2550 struct remote_state
*rs
= get_remote_state ();
2551 char *buf
= alloca (rs
->remote_packet_size
);
2552 int pid
= PIDGET (ptid
);
2554 last_sent_signal
= siggnal
;
2555 last_sent_step
= step
;
2557 /* A hook for when we need to do something at the last moment before
2559 if (deprecated_target_resume_hook
)
2560 (*deprecated_target_resume_hook
) ();
2562 /* The vCont packet doesn't need to specify threads via Hc. */
2563 if (remote_vcont_resume (ptid
, step
, siggnal
))
2566 /* All other supported resume packets do use Hc, so call set_thread. */
2568 set_thread (0, 0); /* Run any thread. */
2570 set_thread (pid
, 0); /* Run this thread. */
2572 if (siggnal
!= TARGET_SIGNAL_0
)
2574 buf
[0] = step
? 'S' : 'C';
2575 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2576 buf
[2] = tohex (((int) siggnal
) & 0xf);
2580 strcpy (buf
, step
? "s" : "c");
2585 /* Same as remote_resume, but with async support. */
2587 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2589 remote_resume (ptid
, step
, siggnal
);
2591 /* We are about to start executing the inferior, let's register it
2592 with the event loop. NOTE: this is the one place where all the
2593 execution commands end up. We could alternatively do this in each
2594 of the execution commands in infcmd.c. */
2595 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2596 into infcmd.c in order to allow inferior function calls to work
2597 NOT asynchronously. */
2598 if (target_can_async_p ())
2599 target_async (inferior_event_handler
, 0);
2600 /* Tell the world that the target is now executing. */
2601 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2602 this? Instead, should the client of target just assume (for
2603 async targets) that the target is going to start executing? Is
2604 this information already found in the continuation block? */
2605 if (target_is_async_p ())
2606 target_executing
= 1;
2610 /* Set up the signal handler for SIGINT, while the target is
2611 executing, ovewriting the 'regular' SIGINT signal handler. */
2613 initialize_sigint_signal_handler (void)
2615 sigint_remote_token
=
2616 create_async_signal_handler (async_remote_interrupt
, NULL
);
2617 signal (SIGINT
, handle_remote_sigint
);
2620 /* Signal handler for SIGINT, while the target is executing. */
2622 handle_remote_sigint (int sig
)
2624 signal (sig
, handle_remote_sigint_twice
);
2625 sigint_remote_twice_token
=
2626 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2627 mark_async_signal_handler_wrapper (sigint_remote_token
);
2630 /* Signal handler for SIGINT, installed after SIGINT has already been
2631 sent once. It will take effect the second time that the user sends
2634 handle_remote_sigint_twice (int sig
)
2636 signal (sig
, handle_sigint
);
2637 sigint_remote_twice_token
=
2638 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2639 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2642 /* Perform the real interruption of the target execution, in response
2645 async_remote_interrupt (gdb_client_data arg
)
2648 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2653 /* Perform interrupt, if the first attempt did not succeed. Just give
2654 up on the target alltogether. */
2656 async_remote_interrupt_twice (gdb_client_data arg
)
2659 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2660 /* Do something only if the target was not killed by the previous
2662 if (target_executing
)
2665 signal (SIGINT
, handle_remote_sigint
);
2669 /* Reinstall the usual SIGINT handlers, after the target has
2672 cleanup_sigint_signal_handler (void *dummy
)
2674 signal (SIGINT
, handle_sigint
);
2675 if (sigint_remote_twice_token
)
2676 delete_async_signal_handler ((struct async_signal_handler
**)
2677 &sigint_remote_twice_token
);
2678 if (sigint_remote_token
)
2679 delete_async_signal_handler ((struct async_signal_handler
**)
2680 &sigint_remote_token
);
2683 /* Send ^C to target to halt it. Target will respond, and send us a
2685 static void (*ofunc
) (int);
2687 /* The command line interface's stop routine. This function is installed
2688 as a signal handler for SIGINT. The first time a user requests a
2689 stop, we call remote_stop to send a break or ^C. If there is no
2690 response from the target (it didn't stop when the user requested it),
2691 we ask the user if he'd like to detach from the target. */
2693 remote_interrupt (int signo
)
2695 /* If this doesn't work, try more severe steps. */
2696 signal (signo
, remote_interrupt_twice
);
2699 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2704 /* The user typed ^C twice. */
2707 remote_interrupt_twice (int signo
)
2709 signal (signo
, ofunc
);
2711 signal (signo
, remote_interrupt
);
2714 /* This is the generic stop called via the target vector. When a target
2715 interrupt is requested, either by the command line or the GUI, we
2716 will eventually end up here. */
2720 /* Send a break or a ^C, depending on user preference. */
2722 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2725 serial_send_break (remote_desc
);
2727 serial_write (remote_desc
, "\003", 1);
2730 /* Ask the user what to do when an interrupt is received. */
2733 interrupt_query (void)
2735 target_terminal_ours ();
2737 if (query ("Interrupted while waiting for the program.\n\
2738 Give up (and stop debugging it)? "))
2740 target_mourn_inferior ();
2741 deprecated_throw_reason (RETURN_QUIT
);
2744 target_terminal_inferior ();
2747 /* Enable/disable target terminal ownership. Most targets can use
2748 terminal groups to control terminal ownership. Remote targets are
2749 different in that explicit transfer of ownership to/from GDB/target
2753 remote_async_terminal_inferior (void)
2755 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2756 sync_execution here. This function should only be called when
2757 GDB is resuming the inferior in the forground. A background
2758 resume (``run&'') should leave GDB in control of the terminal and
2759 consequently should not call this code. */
2760 if (!sync_execution
)
2762 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2763 calls target_terminal_*() idenpotent. The event-loop GDB talking
2764 to an asynchronous target with a synchronous command calls this
2765 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2766 stops trying to transfer the terminal to the target when it
2767 shouldn't this guard can go away. */
2768 if (!remote_async_terminal_ours_p
)
2770 delete_file_handler (input_fd
);
2771 remote_async_terminal_ours_p
= 0;
2772 initialize_sigint_signal_handler ();
2773 /* NOTE: At this point we could also register our selves as the
2774 recipient of all input. Any characters typed could then be
2775 passed on down to the target. */
2779 remote_async_terminal_ours (void)
2781 /* See FIXME in remote_async_terminal_inferior. */
2782 if (!sync_execution
)
2784 /* See FIXME in remote_async_terminal_inferior. */
2785 if (remote_async_terminal_ours_p
)
2787 cleanup_sigint_signal_handler (NULL
);
2788 add_file_handler (input_fd
, stdin_event_handler
, 0);
2789 remote_async_terminal_ours_p
= 1;
2792 /* If nonzero, ignore the next kill. */
2797 remote_console_output (char *msg
)
2801 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2804 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2807 fputs_unfiltered (tb
, gdb_stdtarg
);
2809 gdb_flush (gdb_stdtarg
);
2812 /* Wait until the remote machine stops, then return,
2813 storing status in STATUS just as `wait' would.
2814 Returns "pid", which in the case of a multi-threaded
2815 remote OS, is the thread-id. */
2818 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2820 struct remote_state
*rs
= get_remote_state ();
2821 char *buf
= alloca (rs
->remote_packet_size
);
2822 ULONGEST thread_num
= -1;
2825 status
->kind
= TARGET_WAITKIND_EXITED
;
2826 status
->value
.integer
= 0;
2832 ofunc
= signal (SIGINT
, remote_interrupt
);
2833 getpkt (buf
, rs
->remote_packet_size
, 1);
2834 signal (SIGINT
, ofunc
);
2836 /* This is a hook for when we need to do something (perhaps the
2837 collection of trace data) every time the target stops. */
2838 if (deprecated_target_wait_loop_hook
)
2839 (*deprecated_target_wait_loop_hook
) ();
2841 remote_stopped_by_watchpoint_p
= 0;
2845 case 'E': /* Error of some sort. */
2846 warning (_("Remote failure reply: %s"), buf
);
2848 case 'F': /* File-I/O request. */
2849 remote_fileio_request (buf
);
2851 case 'T': /* Status with PC, SP, FP, ... */
2853 gdb_byte regs
[MAX_REGISTER_SIZE
];
2855 /* Expedited reply, containing Signal, {regno, reg} repeat. */
2856 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2858 n... = register number
2859 r... = register contents
2861 p
= &buf
[3]; /* after Txx */
2870 /* If the packet contains a register number save it in
2871 pnum and set p1 to point to the character following
2872 it. Otherwise p1 points to p. */
2874 /* If this packet is an awatch packet, don't parse the
2875 'a' as a register number. */
2877 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
2879 /* Read the ``P'' register number. */
2880 pnum
= strtol (p
, &p_temp
, 16);
2886 if (p1
== p
) /* No register number present here. */
2888 p1
= strchr (p
, ':');
2890 warning (_("Malformed packet(a) (missing colon): %s\n\
2893 if (strncmp (p
, "thread", p1
- p
) == 0)
2895 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
2896 record_currthread (thread_num
);
2899 else if ((strncmp (p
, "watch", p1
- p
) == 0)
2900 || (strncmp (p
, "rwatch", p1
- p
) == 0)
2901 || (strncmp (p
, "awatch", p1
- p
) == 0))
2903 remote_stopped_by_watchpoint_p
= 1;
2904 p
= unpack_varlen_hex (++p1
, &addr
);
2905 remote_watch_data_address
= (CORE_ADDR
)addr
;
2909 /* Silently skip unknown optional info. */
2910 p_temp
= strchr (p1
+ 1, ';');
2917 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
2921 error (_("Malformed packet(b) (missing colon): %s\n\
2926 error (_("Remote sent bad register number %s: %s\n\
2928 phex_nz (pnum
, 0), p
, buf
);
2930 fieldsize
= hex2bin (p
, regs
,
2931 register_size (current_gdbarch
,
2934 if (fieldsize
< register_size (current_gdbarch
,
2936 warning (_("Remote reply is too short: %s"), buf
);
2937 regcache_raw_supply (current_regcache
,
2942 error (_("Remote register badly formatted: %s\nhere: %s"),
2947 case 'S': /* Old style status, just signal only. */
2948 status
->kind
= TARGET_WAITKIND_STOPPED
;
2949 status
->value
.sig
= (enum target_signal
)
2950 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2954 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
2955 record_currthread (thread_num
);
2958 case 'W': /* Target exited. */
2960 /* The remote process exited. */
2961 status
->kind
= TARGET_WAITKIND_EXITED
;
2962 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2966 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2967 status
->value
.sig
= (enum target_signal
)
2968 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2972 case 'O': /* Console output. */
2973 remote_console_output (buf
+ 1);
2976 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2978 /* Zero length reply means that we tried 'S' or 'C' and
2979 the remote system doesn't support it. */
2980 target_terminal_ours_for_output ();
2982 ("Can't send signals to this remote system. %s not sent.\n",
2983 target_signal_to_name (last_sent_signal
));
2984 last_sent_signal
= TARGET_SIGNAL_0
;
2985 target_terminal_inferior ();
2987 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2988 putpkt ((char *) buf
);
2991 /* else fallthrough */
2993 warning (_("Invalid remote reply: %s"), buf
);
2998 if (thread_num
!= -1)
3000 return pid_to_ptid (thread_num
);
3002 return inferior_ptid
;
3005 /* Async version of remote_wait. */
3007 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3009 struct remote_state
*rs
= get_remote_state ();
3010 char *buf
= alloca (rs
->remote_packet_size
);
3011 ULONGEST thread_num
= -1;
3014 status
->kind
= TARGET_WAITKIND_EXITED
;
3015 status
->value
.integer
= 0;
3017 remote_stopped_by_watchpoint_p
= 0;
3023 if (!target_is_async_p ())
3024 ofunc
= signal (SIGINT
, remote_interrupt
);
3025 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3026 _never_ wait for ever -> test on target_is_async_p().
3027 However, before we do that we need to ensure that the caller
3028 knows how to take the target into/out of async mode. */
3029 getpkt (buf
, rs
->remote_packet_size
, wait_forever_enabled_p
);
3030 if (!target_is_async_p ())
3031 signal (SIGINT
, ofunc
);
3033 /* This is a hook for when we need to do something (perhaps the
3034 collection of trace data) every time the target stops. */
3035 if (deprecated_target_wait_loop_hook
)
3036 (*deprecated_target_wait_loop_hook
) ();
3040 case 'E': /* Error of some sort. */
3041 warning (_("Remote failure reply: %s"), buf
);
3043 case 'F': /* File-I/O request. */
3044 remote_fileio_request (buf
);
3046 case 'T': /* Status with PC, SP, FP, ... */
3048 gdb_byte regs
[MAX_REGISTER_SIZE
];
3050 /* Expedited reply, containing Signal, {regno, reg} repeat. */
3051 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3053 n... = register number
3054 r... = register contents
3056 p
= &buf
[3]; /* after Txx */
3065 /* If the packet contains a register number, save it
3066 in pnum and set p1 to point to the character
3067 following it. Otherwise p1 points to p. */
3069 /* If this packet is an awatch packet, don't parse the 'a'
3070 as a register number. */
3072 if (!strncmp (p
, "awatch", strlen ("awatch")) != 0)
3074 /* Read the register number. */
3075 pnum
= strtol (p
, &p_temp
, 16);
3081 if (p1
== p
) /* No register number present here. */
3083 p1
= strchr (p
, ':');
3085 error (_("Malformed packet(a) (missing colon): %s\n\
3088 if (strncmp (p
, "thread", p1
- p
) == 0)
3090 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3091 record_currthread (thread_num
);
3094 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3095 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3096 || (strncmp (p
, "awatch", p1
- p
) == 0))
3098 remote_stopped_by_watchpoint_p
= 1;
3099 p
= unpack_varlen_hex (++p1
, &addr
);
3100 remote_watch_data_address
= (CORE_ADDR
)addr
;
3104 /* Silently skip unknown optional info. */
3105 p_temp
= strchr (p1
+ 1, ';');
3113 struct packet_reg
*reg
= packet_reg_from_pnum (rs
, pnum
);
3116 error (_("Malformed packet(b) (missing colon): %s\n\
3121 error (_("Remote sent bad register number %ld: %s\n\
3125 fieldsize
= hex2bin (p
, regs
,
3126 register_size (current_gdbarch
,
3129 if (fieldsize
< register_size (current_gdbarch
,
3131 warning (_("Remote reply is too short: %s"), buf
);
3132 regcache_raw_supply (current_regcache
, reg
->regnum
, regs
);
3136 error (_("Remote register badly formatted: %s\nhere: %s"),
3141 case 'S': /* Old style status, just signal only. */
3142 status
->kind
= TARGET_WAITKIND_STOPPED
;
3143 status
->value
.sig
= (enum target_signal
)
3144 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3148 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3149 record_currthread (thread_num
);
3152 case 'W': /* Target exited. */
3154 /* The remote process exited. */
3155 status
->kind
= TARGET_WAITKIND_EXITED
;
3156 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3160 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3161 status
->value
.sig
= (enum target_signal
)
3162 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3166 case 'O': /* Console output. */
3167 remote_console_output (buf
+ 1);
3168 /* Return immediately to the event loop. The event loop will
3169 still be waiting on the inferior afterwards. */
3170 status
->kind
= TARGET_WAITKIND_IGNORE
;
3173 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3175 /* Zero length reply means that we tried 'S' or 'C' and
3176 the remote system doesn't support it. */
3177 target_terminal_ours_for_output ();
3179 ("Can't send signals to this remote system. %s not sent.\n",
3180 target_signal_to_name (last_sent_signal
));
3181 last_sent_signal
= TARGET_SIGNAL_0
;
3182 target_terminal_inferior ();
3184 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3185 putpkt ((char *) buf
);
3188 /* else fallthrough */
3190 warning (_("Invalid remote reply: %s"), buf
);
3195 if (thread_num
!= -1)
3197 return pid_to_ptid (thread_num
);
3199 return inferior_ptid
;
3202 /* Number of bytes of registers this stub implements. */
3204 static int register_bytes_found
;
3206 /* Read the remote registers into the block REGS. */
3207 /* Currently we just read all the registers, so we don't use regnum. */
3210 fetch_register_using_p (int regnum
)
3212 struct remote_state
*rs
= get_remote_state ();
3213 char *buf
= alloca (rs
->remote_packet_size
), *p
;
3214 char regp
[MAX_REGISTER_SIZE
];
3219 p
+= hexnumstr (p
, regnum
);
3221 remote_send (buf
, rs
->remote_packet_size
);
3223 /* If the stub didn't recognize the packet, or if we got an error,
3225 if (buf
[0] == '\0' || buf
[0] == 'E')
3228 /* If this register is unfetchable, tell the regcache. */
3231 regcache_raw_supply (current_regcache
, regnum
, NULL
);
3232 set_register_cached (regnum
, -1);
3236 /* Otherwise, parse and supply the value. */
3243 error (_("fetch_register_using_p: early buf termination"));
3247 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3250 regcache_raw_supply (current_regcache
, regnum
, regp
);
3255 remote_fetch_registers (int regnum
)
3257 struct remote_state
*rs
= get_remote_state ();
3258 char *buf
= alloca (rs
->remote_packet_size
);
3261 char *regs
= alloca (rs
->sizeof_g_packet
);
3263 set_thread (PIDGET (inferior_ptid
), 1);
3267 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3268 gdb_assert (reg
!= NULL
);
3269 if (!reg
->in_g_packet
)
3270 internal_error (__FILE__
, __LINE__
,
3271 _("Attempt to fetch a non G-packet register when this "
3272 "remote.c does not support the p-packet."));
3274 switch (remote_protocol_p
.support
)
3276 case PACKET_DISABLE
:
3279 if (fetch_register_using_p (regnum
))
3282 error (_("Protocol error: p packet not recognized by stub"));
3283 case PACKET_SUPPORT_UNKNOWN
:
3284 if (fetch_register_using_p (regnum
))
3286 /* The stub recognized the 'p' packet. Remember this. */
3287 remote_protocol_p
.support
= PACKET_ENABLE
;
3292 /* The stub does not support the 'P' packet. Use 'G'
3293 instead, and don't try using 'P' in the future (it
3294 will just waste our time). */
3295 remote_protocol_p
.support
= PACKET_DISABLE
;
3301 remote_send (buf
, rs
->remote_packet_size
);
3303 /* Save the size of the packet sent to us by the target. Its used
3304 as a heuristic when determining the max size of packets that the
3305 target can safely receive. */
3306 if ((rs
->actual_register_packet_size
) == 0)
3307 (rs
->actual_register_packet_size
) = strlen (buf
);
3309 /* Unimplemented registers read as all bits zero. */
3310 memset (regs
, 0, rs
->sizeof_g_packet
);
3312 /* We can get out of synch in various cases. If the first character
3313 in the buffer is not a hex character, assume that has happened
3314 and try to fetch another packet to read. */
3315 while ((buf
[0] < '0' || buf
[0] > '9')
3316 && (buf
[0] < 'A' || buf
[0] > 'F')
3317 && (buf
[0] < 'a' || buf
[0] > 'f')
3318 && buf
[0] != 'x') /* New: unavailable register value. */
3321 fprintf_unfiltered (gdb_stdlog
,
3322 "Bad register packet; fetching a new packet\n");
3323 getpkt (buf
, rs
->remote_packet_size
, 0);
3326 /* Reply describes registers byte by byte, each byte encoded as two
3327 hex characters. Suck them all up, then supply them to the
3328 register cacheing/storage mechanism. */
3331 for (i
= 0; i
< rs
->sizeof_g_packet
; i
++)
3337 warning (_("Remote reply is of odd length: %s"), buf
);
3338 /* Don't change register_bytes_found in this case, and don't
3339 print a second warning. */
3342 if (p
[0] == 'x' && p
[1] == 'x')
3343 regs
[i
] = 0; /* 'x' */
3345 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3349 if (i
!= register_bytes_found
)
3351 register_bytes_found
= i
;
3352 if (REGISTER_BYTES_OK_P ()
3353 && !REGISTER_BYTES_OK (i
))
3354 warning (_("Remote reply is too short: %s"), buf
);
3360 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3362 struct packet_reg
*r
= &rs
->regs
[i
];
3365 if (r
->offset
* 2 >= strlen (buf
))
3366 /* A short packet that didn't include the register's
3367 value, this implies that the register is zero (and
3368 not that the register is unavailable). Supply that
3370 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3371 else if (buf
[r
->offset
* 2] == 'x')
3373 gdb_assert (r
->offset
* 2 < strlen (buf
));
3374 /* The register isn't available, mark it as such (at
3375 the same time setting the value to zero). */
3376 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3377 set_register_cached (i
, -1);
3380 regcache_raw_supply (current_regcache
, r
->regnum
,
3387 /* Prepare to store registers. Since we may send them all (using a
3388 'G' request), we have to read out the ones we don't want to change
3392 remote_prepare_to_store (void)
3394 struct remote_state
*rs
= get_remote_state ();
3396 gdb_byte buf
[MAX_REGISTER_SIZE
];
3398 /* Make sure the entire registers array is valid. */
3399 switch (remote_protocol_P
.support
)
3401 case PACKET_DISABLE
:
3402 case PACKET_SUPPORT_UNKNOWN
:
3403 /* Make sure all the necessary registers are cached. */
3404 for (i
= 0; i
< NUM_REGS
; i
++)
3405 if (rs
->regs
[i
].in_g_packet
)
3406 regcache_raw_read (current_regcache
, rs
->regs
[i
].regnum
, buf
);
3413 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3414 packet was not recognized. */
3417 store_register_using_P (int regnum
)
3419 struct remote_state
*rs
= get_remote_state ();
3420 struct packet_reg
*reg
= packet_reg_from_regnum (rs
, regnum
);
3421 /* Try storing a single register. */
3422 char *buf
= alloca (rs
->remote_packet_size
);
3423 gdb_byte regp
[MAX_REGISTER_SIZE
];
3426 xsnprintf (buf
, rs
->remote_packet_size
, "P%s=", phex_nz (reg
->pnum
, 0));
3427 p
= buf
+ strlen (buf
);
3428 regcache_raw_collect (current_regcache
, reg
->regnum
, regp
);
3429 bin2hex (regp
, p
, register_size (current_gdbarch
, reg
->regnum
));
3430 remote_send (buf
, rs
->remote_packet_size
);
3432 return buf
[0] != '\0';
3436 /* Store register REGNUM, or all registers if REGNUM == -1, from the
3437 contents of the register cache buffer. FIXME: ignores errors. */
3440 remote_store_registers (int regnum
)
3442 struct remote_state
*rs
= get_remote_state ();
3447 set_thread (PIDGET (inferior_ptid
), 1);
3451 switch (remote_protocol_P
.support
)
3453 case PACKET_DISABLE
:
3456 if (store_register_using_P (regnum
))
3459 error (_("Protocol error: P packet not recognized by stub"));
3460 case PACKET_SUPPORT_UNKNOWN
:
3461 if (store_register_using_P (regnum
))
3463 /* The stub recognized the 'P' packet. Remember this. */
3464 remote_protocol_P
.support
= PACKET_ENABLE
;
3469 /* The stub does not support the 'P' packet. Use 'G'
3470 instead, and don't try using 'P' in the future (it
3471 will just waste our time). */
3472 remote_protocol_P
.support
= PACKET_DISABLE
;
3478 /* Extract all the registers in the regcache copying them into a
3482 regs
= alloca (rs
->sizeof_g_packet
);
3483 memset (regs
, 0, rs
->sizeof_g_packet
);
3484 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3486 struct packet_reg
*r
= &rs
->regs
[i
];
3488 regcache_raw_collect (current_regcache
, r
->regnum
, regs
+ r
->offset
);
3492 /* Command describes registers byte by byte,
3493 each byte encoded as two hex characters. */
3494 buf
= alloca (rs
->remote_packet_size
);
3497 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3498 bin2hex (regs
, p
, register_bytes_found
);
3499 remote_send (buf
, rs
->remote_packet_size
);
3503 /* Return the number of hex digits in num. */
3506 hexnumlen (ULONGEST num
)
3510 for (i
= 0; num
!= 0; i
++)
3516 /* Set BUF to the minimum number of hex digits representing NUM. */
3519 hexnumstr (char *buf
, ULONGEST num
)
3521 int len
= hexnumlen (num
);
3522 return hexnumnstr (buf
, num
, len
);
3526 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3529 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3535 for (i
= width
- 1; i
>= 0; i
--)
3537 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3544 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3547 remote_address_masked (CORE_ADDR addr
)
3549 if (remote_address_size
> 0
3550 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3552 /* Only create a mask when that mask can safely be constructed
3553 in a ULONGEST variable. */
3555 mask
= (mask
<< remote_address_size
) - 1;
3561 /* Determine whether the remote target supports binary downloading.
3562 This is accomplished by sending a no-op memory write of zero length
3563 to the target at the specified address. It does not suffice to send
3564 the whole packet, since many stubs strip the eighth bit and
3565 subsequently compute a wrong checksum, which causes real havoc with
3568 NOTE: This can still lose if the serial line is not eight-bit
3569 clean. In cases like this, the user should clear "remote
3573 check_binary_download (CORE_ADDR addr
)
3575 struct remote_state
*rs
= get_remote_state ();
3577 switch (remote_protocol_binary_download
.support
)
3579 case PACKET_DISABLE
:
3583 case PACKET_SUPPORT_UNKNOWN
:
3585 char *buf
= alloca (rs
->remote_packet_size
);
3590 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3592 p
+= hexnumstr (p
, (ULONGEST
) 0);
3596 putpkt_binary (buf
, (int) (p
- buf
));
3597 getpkt (buf
, rs
->remote_packet_size
, 0);
3602 fprintf_unfiltered (gdb_stdlog
,
3603 "binary downloading NOT suppported by target\n");
3604 remote_protocol_binary_download
.support
= PACKET_DISABLE
;
3609 fprintf_unfiltered (gdb_stdlog
,
3610 "binary downloading suppported by target\n");
3611 remote_protocol_binary_download
.support
= PACKET_ENABLE
;
3618 /* Write memory data directly to the remote machine.
3619 This does not inform the data cache; the data cache uses this.
3620 MEMADDR is the address in the remote memory space.
3621 MYADDR is the address of the buffer in our space.
3622 LEN is the number of bytes.
3624 Returns number of bytes transferred, or 0 (setting errno) for
3625 error. Only transfer a single packet. */
3628 remote_write_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
3638 char *payload_start
;
3640 /* Verify that the target can support a binary download. */
3641 check_binary_download (memaddr
);
3643 payload_size
= get_memory_write_packet_size ();
3645 /* Compute the size, and then allocate space for the largest
3646 possible packet. Include space for an extra trailing NUL. */
3647 sizeof_buf
= payload_size
+ 1;
3648 buf
= alloca (sizeof_buf
);
3650 /* Compute the size of the actual payload by subtracting out the
3651 packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
3653 payload_size
-= strlen ("$M,:#NN");
3654 payload_size
-= hexnumlen (memaddr
);
3656 /* Construct the packet header: "[MX]<memaddr>,<len>:". */
3658 /* Append "[XM]". Compute a best guess of the number of bytes
3659 actually transfered. */
3661 switch (remote_protocol_binary_download
.support
)
3665 /* Best guess at number of bytes that will fit. */
3666 todo
= min (len
, payload_size
);
3667 payload_size
-= hexnumlen (todo
);
3668 todo
= min (todo
, payload_size
);
3670 case PACKET_DISABLE
:
3672 /* Num bytes that will fit. */
3673 todo
= min (len
, payload_size
/ 2);
3674 payload_size
-= hexnumlen (todo
);
3675 todo
= min (todo
, payload_size
/ 2);
3677 case PACKET_SUPPORT_UNKNOWN
:
3678 internal_error (__FILE__
, __LINE__
,
3679 _("remote_write_bytes: bad internal state"));
3681 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3684 internal_error (__FILE__
, __LINE__
,
3685 _("minumum packet size too small to write data"));
3687 /* Append "<memaddr>". */
3688 memaddr
= remote_address_masked (memaddr
);
3689 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3694 /* Append <len>. Retain the location/size of <len>. It may need to
3695 be adjusted once the packet body has been created. */
3697 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3704 /* Append the packet body. */
3706 switch (remote_protocol_binary_download
.support
)
3709 /* Binary mode. Send target system values byte by byte, in
3710 increasing byte addresses. Only escape certain critical
3713 (nr_bytes
< todo
) && (p
- payload_start
) < payload_size
;
3716 switch (myaddr
[nr_bytes
] & 0xff)
3721 /* These must be escaped. */
3723 *p
++ = (myaddr
[nr_bytes
] & 0xff) ^ 0x20;
3726 *p
++ = myaddr
[nr_bytes
] & 0xff;
3730 if (nr_bytes
< todo
)
3732 /* Escape chars have filled up the buffer prematurely,
3733 and we have actually sent fewer bytes than planned.
3734 Fix-up the length field of the packet. Use the same
3735 number of characters as before. */
3736 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3737 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3740 case PACKET_DISABLE
:
3741 /* Normal mode: Send target system values byte by byte, in
3742 increasing byte addresses. Each byte is encoded as a two hex
3744 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3747 case PACKET_SUPPORT_UNKNOWN
:
3748 internal_error (__FILE__
, __LINE__
,
3749 _("remote_write_bytes: bad internal state"));
3751 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3754 putpkt_binary (buf
, (int) (p
- buf
));
3755 getpkt (buf
, sizeof_buf
, 0);
3759 /* There is no correspondance between what the remote protocol
3760 uses for errors and errno codes. We would like a cleaner way
3761 of representing errors (big enough to include errno codes,
3762 bfd_error codes, and others). But for now just return EIO. */
3767 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
3768 fewer bytes than we'd planned. */
3772 /* Read memory data directly from the remote machine.
3773 This does not use the data cache; the data cache uses this.
3774 MEMADDR is the address in the remote memory space.
3775 MYADDR is the address of the buffer in our space.
3776 LEN is the number of bytes.
3778 Returns number of bytes transferred, or 0 for error. */
3780 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3781 remote targets) shouldn't attempt to read the entire buffer.
3782 Instead it should read a single packet worth of data and then
3783 return the byte size of that packet to the caller. The caller (its
3784 caller and its callers caller ;-) already contains code for
3785 handling partial reads. */
3788 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
3791 int max_buf_size
; /* Max size of packet output buffer. */
3795 /* Create a buffer big enough for this packet. */
3796 max_buf_size
= get_memory_read_packet_size ();
3797 sizeof_buf
= max_buf_size
+ 1; /* Space for trailing NULL. */
3798 buf
= alloca (sizeof_buf
);
3807 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3809 /* construct "m"<memaddr>","<len>" */
3810 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3811 memaddr
= remote_address_masked (memaddr
);
3814 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3816 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3820 getpkt (buf
, sizeof_buf
, 0);
3823 && isxdigit (buf
[1]) && isxdigit (buf
[2])
3826 /* There is no correspondance between what the remote
3827 protocol uses for errors and errno codes. We would like
3828 a cleaner way of representing errors (big enough to
3829 include errno codes, bfd_error codes, and others). But
3830 for now just return EIO. */
3835 /* Reply describes memory byte by byte,
3836 each byte encoded as two hex characters. */
3839 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
3841 /* Reply is short. This means that we were able to read
3842 only part of what we wanted to. */
3843 return i
+ (origlen
- len
);
3852 /* Read or write LEN bytes from inferior memory at MEMADDR,
3853 transferring to or from debugger address BUFFER. Write to inferior
3854 if SHOULD_WRITE is nonzero. Returns length of data written or
3855 read; 0 for error. TARGET is unused. */
3858 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
3859 int should_write
, struct mem_attrib
*attrib
,
3860 struct target_ops
*target
)
3862 CORE_ADDR targ_addr
;
3866 /* Should this be the selected frame? */
3867 gdbarch_remote_translate_xfer_address (current_gdbarch
,
3870 &targ_addr
, &targ_len
);
3875 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
3877 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
3883 remote_files_info (struct target_ops
*ignore
)
3885 puts_filtered ("Debugging a target over a serial line.\n");
3888 /* Stuff for dealing with the packets which are part of this protocol.
3889 See comment at top of file for details. */
3891 /* Read a single character from the remote end, masking it down to 7
3895 readchar (int timeout
)
3899 ch
= serial_readchar (remote_desc
, timeout
);
3904 switch ((enum serial_rc
) ch
)
3907 target_mourn_inferior ();
3908 error (_("Remote connection closed"));
3911 perror_with_name (_("Remote communication error"));
3913 case SERIAL_TIMEOUT
:
3919 /* Send the command in BUF to the remote machine, and read the reply
3920 into BUF. Report an error if we get an error reply. */
3923 remote_send (char *buf
,
3927 getpkt (buf
, sizeof_buf
, 0);
3930 error (_("Remote failure reply: %s"), buf
);
3933 /* Display a null-terminated packet on stdout, for debugging, using C
3937 print_packet (char *buf
)
3939 puts_filtered ("\"");
3940 fputstr_filtered (buf
, '"', gdb_stdout
);
3941 puts_filtered ("\"");
3947 return putpkt_binary (buf
, strlen (buf
));
3950 /* Send a packet to the remote machine, with error checking. The data
3951 of the packet is in BUF. The string in BUF can be at most
3952 RS->remote_packet_size - 5 to account for the $, # and checksum,
3953 and for a possible /0 if we are debugging (remote_debug) and want
3954 to print the sent packet as a string. */
3957 putpkt_binary (char *buf
, int cnt
)
3959 struct remote_state
*rs
= get_remote_state ();
3961 unsigned char csum
= 0;
3962 char *buf2
= alloca (cnt
+ 6);
3963 long sizeof_junkbuf
= rs
->remote_packet_size
;
3964 char *junkbuf
= alloca (sizeof_junkbuf
);
3970 /* Copy the packet into buffer BUF2, encapsulating it
3971 and giving it a checksum. */
3976 for (i
= 0; i
< cnt
; i
++)
3982 *p
++ = tohex ((csum
>> 4) & 0xf);
3983 *p
++ = tohex (csum
& 0xf);
3985 /* Send it over and over until we get a positive ack. */
3989 int started_error_output
= 0;
3994 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
3995 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
3996 fprintf_unfiltered (gdb_stdlog
, "...");
3997 gdb_flush (gdb_stdlog
);
3999 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4000 perror_with_name (_("putpkt: write failed"));
4002 /* Read until either a timeout occurs (-2) or '+' is read. */
4005 ch
= readchar (remote_timeout
);
4013 case SERIAL_TIMEOUT
:
4015 if (started_error_output
)
4017 putchar_unfiltered ('\n');
4018 started_error_output
= 0;
4027 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4031 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4032 case SERIAL_TIMEOUT
:
4036 break; /* Retransmit buffer. */
4040 fprintf_unfiltered (gdb_stdlog
,
4041 "Packet instead of Ack, ignoring it\n");
4042 /* It's probably an old response sent because an ACK
4043 was lost. Gobble up the packet and ack it so it
4044 doesn't get retransmitted when we resend this
4046 read_frame (junkbuf
, sizeof_junkbuf
);
4047 serial_write (remote_desc
, "+", 1);
4048 continue; /* Now, go look for +. */
4053 if (!started_error_output
)
4055 started_error_output
= 1;
4056 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4058 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4062 break; /* Here to retransmit. */
4066 /* This is wrong. If doing a long backtrace, the user should be
4067 able to get out next time we call QUIT, without anything as
4068 violent as interrupt_query. If we want to provide a way out of
4069 here without getting to the next QUIT, it should be based on
4070 hitting ^C twice as in remote_wait. */
4080 /* Come here after finding the start of the frame. Collect the rest
4081 into BUF, verifying the checksum, length, and handling run-length
4082 compression. No more than sizeof_buf-1 characters are read so that
4083 the buffer can be NUL terminated.
4085 Returns -1 on error, number of characters in buffer (ignoring the
4086 trailing NULL) on success. (could be extended to return one of the
4087 SERIAL status indications). */
4090 read_frame (char *buf
,
4102 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NULL. */
4103 c
= readchar (remote_timeout
);
4106 case SERIAL_TIMEOUT
:
4108 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4112 fputs_filtered ("Saw new packet start in middle of old one\n",
4114 return -1; /* Start a new packet, count retries. */
4117 unsigned char pktcsum
;
4123 check_0
= readchar (remote_timeout
);
4125 check_1
= readchar (remote_timeout
);
4127 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4130 fputs_filtered ("Timeout in checksum, retrying\n",
4134 else if (check_0
< 0 || check_1
< 0)
4137 fputs_filtered ("Communication error in checksum\n",
4142 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4143 if (csum
== pktcsum
)
4148 fprintf_filtered (gdb_stdlog
,
4149 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4151 fputs_filtered (buf
, gdb_stdlog
);
4152 fputs_filtered ("\n", gdb_stdlog
);
4154 /* Number of characters in buffer ignoring trailing
4158 case '*': /* Run length encoding. */
4163 c
= readchar (remote_timeout
);
4165 repeat
= c
- ' ' + 3; /* Compute repeat count. */
4167 /* The character before ``*'' is repeated. */
4169 if (repeat
> 0 && repeat
<= 255
4171 && bc
+ repeat
- 1 < sizeof_buf
- 1)
4173 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4179 printf_filtered (_("Repeat count %d too large for buffer: "),
4181 puts_filtered (buf
);
4182 puts_filtered ("\n");
4186 if (bc
< sizeof_buf
- 1)
4194 puts_filtered ("Remote packet too long: ");
4195 puts_filtered (buf
);
4196 puts_filtered ("\n");
4203 /* Read a packet from the remote machine, with error checking, and
4204 store it in BUF. If FOREVER, wait forever rather than timing out;
4205 this is used (in synchronous mode) to wait for a target that is is
4206 executing user code to stop. */
4207 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4208 don't have to change all the calls to getpkt to deal with the
4209 return value, because at the moment I don't know what the right
4210 thing to do it for those. */
4218 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4222 /* Read a packet from the remote machine, with error checking, and
4223 store it in BUF. If FOREVER, wait forever rather than timing out;
4224 this is used (in synchronous mode) to wait for a target that is is
4225 executing user code to stop. If FOREVER == 0, this function is
4226 allowed to time out gracefully and return an indication of this to
4229 getpkt_sane (char *buf
,
4238 strcpy (buf
, "timeout");
4242 timeout
= watchdog
> 0 ? watchdog
: -1;
4246 timeout
= remote_timeout
;
4250 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4252 /* This can loop forever if the remote side sends us characters
4253 continuously, but if it pauses, we'll get a zero from
4254 readchar because of timeout. Then we'll count that as a
4257 /* Note that we will only wait forever prior to the start of a
4258 packet. After that, we expect characters to arrive at a
4259 brisk pace. They should show up within remote_timeout
4264 c
= readchar (timeout
);
4266 if (c
== SERIAL_TIMEOUT
)
4268 if (forever
) /* Watchdog went off? Kill the target. */
4271 target_mourn_inferior ();
4272 error (_("Watchdog has expired. Target detached."));
4275 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4281 /* We've found the start of a packet, now collect the data. */
4283 val
= read_frame (buf
, sizeof_buf
);
4289 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4290 fputstr_unfiltered (buf
, 0, gdb_stdlog
);
4291 fprintf_unfiltered (gdb_stdlog
, "\n");
4293 serial_write (remote_desc
, "+", 1);
4297 /* Try the whole thing again. */
4299 serial_write (remote_desc
, "-", 1);
4302 /* We have tried hard enough, and just can't receive the packet.
4305 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
4306 serial_write (remote_desc
, "+", 1);
4313 /* For some mysterious reason, wait_for_inferior calls kill instead of
4314 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4318 target_mourn_inferior ();
4322 /* Use catch_errors so the user can quit from gdb even when we aren't on
4323 speaking terms with the remote system. */
4324 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4326 /* Don't wait for it to die. I'm not really sure it matters whether
4327 we do or not. For the existing stubs, kill is a noop. */
4328 target_mourn_inferior ();
4331 /* Async version of remote_kill. */
4333 remote_async_kill (void)
4335 /* Unregister the file descriptor from the event loop. */
4336 if (target_is_async_p ())
4337 serial_async (remote_desc
, NULL
, 0);
4339 /* For some mysterious reason, wait_for_inferior calls kill instead of
4340 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4344 target_mourn_inferior ();
4348 /* Use catch_errors so the user can quit from gdb even when we
4349 aren't on speaking terms with the remote system. */
4350 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4352 /* Don't wait for it to die. I'm not really sure it matters whether
4353 we do or not. For the existing stubs, kill is a noop. */
4354 target_mourn_inferior ();
4360 remote_mourn_1 (&remote_ops
);
4364 remote_async_mourn (void)
4366 remote_mourn_1 (&remote_async_ops
);
4370 extended_remote_mourn (void)
4372 /* We do _not_ want to mourn the target like this; this will
4373 remove the extended remote target from the target stack,
4374 and the next time the user says "run" it'll fail.
4376 FIXME: What is the right thing to do here? */
4378 remote_mourn_1 (&extended_remote_ops
);
4382 /* Worker function for remote_mourn. */
4384 remote_mourn_1 (struct target_ops
*target
)
4386 unpush_target (target
);
4387 generic_mourn_inferior ();
4390 /* In the extended protocol we want to be able to do things like
4391 "run" and have them basically work as expected. So we need
4392 a special create_inferior function.
4394 FIXME: One day add support for changing the exec file
4395 we're debugging, arguments and an environment. */
4398 extended_remote_create_inferior (char *exec_file
, char *args
,
4399 char **env
, int from_tty
)
4401 /* Rip out the breakpoints; we'll reinsert them after restarting
4402 the remote server. */
4403 remove_breakpoints ();
4405 /* Now restart the remote server. */
4406 extended_remote_restart ();
4408 /* Now put the breakpoints back in. This way we're safe if the
4409 restart function works via a unix fork on the remote side. */
4410 insert_breakpoints ();
4412 /* Clean up from the last time we were running. */
4413 clear_proceed_status ();
4416 /* Async version of extended_remote_create_inferior. */
4418 extended_remote_async_create_inferior (char *exec_file
, char *args
,
4419 char **env
, int from_tty
)
4421 /* Rip out the breakpoints; we'll reinsert them after restarting
4422 the remote server. */
4423 remove_breakpoints ();
4425 /* If running asynchronously, register the target file descriptor
4426 with the event loop. */
4427 if (target_can_async_p ())
4428 target_async (inferior_event_handler
, 0);
4430 /* Now restart the remote server. */
4431 extended_remote_restart ();
4433 /* Now put the breakpoints back in. This way we're safe if the
4434 restart function works via a unix fork on the remote side. */
4435 insert_breakpoints ();
4437 /* Clean up from the last time we were running. */
4438 clear_proceed_status ();
4442 /* On some machines, e.g. 68k, we may use a different breakpoint
4443 instruction than other targets; in those use
4444 DEPRECATED_REMOTE_BREAKPOINT instead of just BREAKPOINT_FROM_PC.
4445 Also, bi-endian targets may define
4446 DEPRECATED_LITTLE_REMOTE_BREAKPOINT and
4447 DEPRECATED_BIG_REMOTE_BREAKPOINT. If none of these are defined, we
4448 just call the standard routines that are in mem-break.c. */
4450 /* NOTE: cagney/2003-06-08: This is silly. A remote and simulator
4451 target should use an identical BREAKPOINT_FROM_PC. As for native,
4452 the ARCH-OS-tdep.c code can override the default. */
4454 #if defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) && !defined(DEPRECATED_REMOTE_BREAKPOINT)
4455 #define DEPRECATED_REMOTE_BREAKPOINT
4458 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4460 /* If the target isn't bi-endian, just pretend it is. */
4461 #if !defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && !defined (DEPRECATED_BIG_REMOTE_BREAKPOINT)
4462 #define DEPRECATED_LITTLE_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4463 #define DEPRECATED_BIG_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4466 static unsigned char big_break_insn
[] = DEPRECATED_BIG_REMOTE_BREAKPOINT
;
4467 static unsigned char little_break_insn
[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT
;
4469 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4471 /* Insert a breakpoint on targets that don't have any better
4472 breakpoint support. We read the contents of the target location
4473 and stash it, then overwrite it with a breakpoint instruction.
4474 ADDR is the target location in the target machine. CONTENTS_CACHE
4475 is a pointer to memory allocated for saving the target contents.
4476 It is guaranteed by the caller to be long enough to save the number
4477 of bytes returned by BREAKPOINT_FROM_PC. */
4480 remote_insert_breakpoint (CORE_ADDR addr
, bfd_byte
*contents_cache
)
4482 struct remote_state
*rs
= get_remote_state ();
4483 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4488 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4489 If it succeeds, then set the support to PACKET_ENABLE. If it
4490 fails, and the user has explicitly requested the Z support then
4491 report an error, otherwise, mark it disabled and go on. */
4493 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4495 char *buf
= alloca (rs
->remote_packet_size
);
4498 addr
= remote_address_masked (addr
);
4502 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4503 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4504 sprintf (p
, ",%d", bp_size
);
4507 getpkt (buf
, rs
->remote_packet_size
, 0);
4509 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
]))
4515 case PACKET_UNKNOWN
:
4520 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4521 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
4525 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4526 val
= target_write_memory (addr
, (char *) big_break_insn
,
4527 sizeof big_break_insn
);
4529 val
= target_write_memory (addr
, (char *) little_break_insn
,
4530 sizeof little_break_insn
);
4535 return memory_insert_breakpoint (addr
, contents_cache
);
4536 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4540 remote_remove_breakpoint (CORE_ADDR addr
, bfd_byte
*contents_cache
)
4542 struct remote_state
*rs
= get_remote_state ();
4545 if (remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
].support
!= PACKET_DISABLE
)
4547 char *buf
= alloca (rs
->remote_packet_size
);
4554 addr
= remote_address_masked (addr
);
4555 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4556 BREAKPOINT_FROM_PC (&addr
, &bp_size
);
4557 sprintf (p
, ",%d", bp_size
);
4560 getpkt (buf
, rs
->remote_packet_size
, 0);
4562 return (buf
[0] == 'E');
4565 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4566 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
4568 return memory_remove_breakpoint (addr
, contents_cache
);
4569 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4573 watchpoint_to_Z_packet (int type
)
4587 internal_error (__FILE__
, __LINE__
,
4588 _("hw_bp_to_z: bad watchpoint type %d"), type
);
4593 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4595 struct remote_state
*rs
= get_remote_state ();
4596 char *buf
= alloca (rs
->remote_packet_size
);
4598 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4600 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4601 error (_("Can't set hardware watchpoints without the '%s' (%s) packet."),
4602 remote_protocol_Z
[packet
].name
,
4603 remote_protocol_Z
[packet
].title
);
4605 sprintf (buf
, "Z%x,", packet
);
4606 p
= strchr (buf
, '\0');
4607 addr
= remote_address_masked (addr
);
4608 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4609 sprintf (p
, ",%x", len
);
4612 getpkt (buf
, rs
->remote_packet_size
, 0);
4614 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4617 case PACKET_UNKNOWN
:
4622 internal_error (__FILE__
, __LINE__
,
4623 _("remote_insert_watchpoint: reached end of function"));
4628 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4630 struct remote_state
*rs
= get_remote_state ();
4631 char *buf
= alloca (rs
->remote_packet_size
);
4633 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4635 if (remote_protocol_Z
[packet
].support
== PACKET_DISABLE
)
4636 error (_("Can't clear hardware watchpoints without the '%s' (%s) packet."),
4637 remote_protocol_Z
[packet
].name
,
4638 remote_protocol_Z
[packet
].title
);
4640 sprintf (buf
, "z%x,", packet
);
4641 p
= strchr (buf
, '\0');
4642 addr
= remote_address_masked (addr
);
4643 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4644 sprintf (p
, ",%x", len
);
4646 getpkt (buf
, rs
->remote_packet_size
, 0);
4648 switch (packet_ok (buf
, &remote_protocol_Z
[packet
]))
4651 case PACKET_UNKNOWN
:
4656 internal_error (__FILE__
, __LINE__
,
4657 _("remote_remove_watchpoint: reached end of function"));
4661 int remote_hw_watchpoint_limit
= -1;
4662 int remote_hw_breakpoint_limit
= -1;
4665 remote_check_watch_resources (int type
, int cnt
, int ot
)
4667 if (type
== bp_hardware_breakpoint
)
4669 if (remote_hw_breakpoint_limit
== 0)
4671 else if (remote_hw_breakpoint_limit
< 0)
4673 else if (cnt
<= remote_hw_breakpoint_limit
)
4678 if (remote_hw_watchpoint_limit
== 0)
4680 else if (remote_hw_watchpoint_limit
< 0)
4684 else if (cnt
<= remote_hw_watchpoint_limit
)
4691 remote_stopped_by_watchpoint (void)
4693 return remote_stopped_by_watchpoint_p
;
4696 extern int stepped_after_stopped_by_watchpoint
;
4699 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
4702 if (remote_stopped_by_watchpoint ()
4703 || stepped_after_stopped_by_watchpoint
)
4705 *addr_p
= remote_watch_data_address
;
4714 remote_insert_hw_breakpoint (CORE_ADDR addr
, gdb_byte
*shadow
)
4717 struct remote_state
*rs
= get_remote_state ();
4718 char *buf
= alloca (rs
->remote_packet_size
);
4721 /* The length field should be set to the size of a breakpoint
4724 BREAKPOINT_FROM_PC (&addr
, &len
);
4726 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4727 error (_("Can't set hardware breakpoint without the '%s' (%s) packet."),
4728 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4729 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4735 addr
= remote_address_masked (addr
);
4736 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4737 sprintf (p
, ",%x", len
);
4740 getpkt (buf
, rs
->remote_packet_size
, 0);
4742 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4745 case PACKET_UNKNOWN
:
4750 internal_error (__FILE__
, __LINE__
,
4751 _("remote_insert_hw_breakpoint: reached end of function"));
4756 remote_remove_hw_breakpoint (CORE_ADDR addr
, gdb_byte
*shadow
)
4759 struct remote_state
*rs
= get_remote_state ();
4760 char *buf
= alloca (rs
->remote_packet_size
);
4763 /* The length field should be set to the size of a breakpoint
4766 BREAKPOINT_FROM_PC (&addr
, &len
);
4768 if (remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].support
== PACKET_DISABLE
)
4769 error (_("Can't clear hardware breakpoint without the '%s' (%s) packet."),
4770 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].name
,
4771 remote_protocol_Z
[Z_PACKET_HARDWARE_BP
].title
);
4777 addr
= remote_address_masked (addr
);
4778 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4779 sprintf (p
, ",%x", len
);
4782 getpkt (buf
, rs
->remote_packet_size
, 0);
4784 switch (packet_ok (buf
, &remote_protocol_Z
[Z_PACKET_HARDWARE_BP
]))
4787 case PACKET_UNKNOWN
:
4792 internal_error (__FILE__
, __LINE__
,
4793 _("remote_remove_hw_breakpoint: reached end of function"));
4796 /* Some targets are only capable of doing downloads, and afterwards
4797 they switch to the remote serial protocol. This function provides
4798 a clean way to get from the download target to the remote target.
4799 It's basically just a wrapper so that we don't have to expose any
4800 of the internal workings of remote.c.
4802 Prior to calling this routine, you should shutdown the current
4803 target code, else you will get the "A program is being debugged
4804 already..." message. Usually a call to pop_target() suffices. */
4807 push_remote_target (char *name
, int from_tty
)
4809 printf_filtered (_("Switching to remote protocol\n"));
4810 remote_open (name
, from_tty
);
4813 /* Table used by the crc32 function to calcuate the checksum. */
4815 static unsigned long crc32_table
[256] =
4818 static unsigned long
4819 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4821 if (!crc32_table
[1])
4823 /* Initialize the CRC table and the decoding table. */
4827 for (i
= 0; i
< 256; i
++)
4829 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4830 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
4837 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
4843 /* compare-sections command
4845 With no arguments, compares each loadable section in the exec bfd
4846 with the same memory range on the target, and reports mismatches.
4847 Useful for verifying the image on the target against the exec file.
4848 Depends on the target understanding the new "qCRC:" request. */
4850 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4851 target method (target verify memory) and generic version of the
4852 actual command. This will allow other high-level code (especially
4853 generic_load()) to make use of this target functionality. */
4856 compare_sections_command (char *args
, int from_tty
)
4858 struct remote_state
*rs
= get_remote_state ();
4860 unsigned long host_crc
, target_crc
;
4861 extern bfd
*exec_bfd
;
4862 struct cleanup
*old_chain
;
4865 const char *sectname
;
4866 char *buf
= alloca (rs
->remote_packet_size
);
4873 error (_("command cannot be used without an exec file"));
4874 if (!current_target
.to_shortname
||
4875 strcmp (current_target
.to_shortname
, "remote") != 0)
4876 error (_("command can only be used with remote target"));
4878 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4880 if (!(s
->flags
& SEC_LOAD
))
4881 continue; /* skip non-loadable section */
4883 size
= bfd_get_section_size (s
);
4885 continue; /* skip zero-length section */
4887 sectname
= bfd_get_section_name (exec_bfd
, s
);
4888 if (args
&& strcmp (args
, sectname
) != 0)
4889 continue; /* not the section selected by user */
4891 matched
= 1; /* do this section */
4893 /* FIXME: assumes lma can fit into long. */
4894 xsnprintf (buf
, rs
->remote_packet_size
, "qCRC:%lx,%lx",
4895 (long) lma
, (long) size
);
4898 /* Be clever; compute the host_crc before waiting for target
4900 sectdata
= xmalloc (size
);
4901 old_chain
= make_cleanup (xfree
, sectdata
);
4902 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
4903 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
4905 getpkt (buf
, rs
->remote_packet_size
, 0);
4907 error (_("target memory fault, section %s, range 0x%s -- 0x%s"),
4908 sectname
, paddr (lma
), paddr (lma
+ size
));
4910 error (_("remote target does not support this operation"));
4912 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
4913 target_crc
= target_crc
* 16 + fromhex (*tmp
);
4915 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4916 sectname
, paddr (lma
), paddr (lma
+ size
));
4917 if (host_crc
== target_crc
)
4918 printf_filtered ("matched.\n");
4921 printf_filtered ("MIS-MATCHED!\n");
4925 do_cleanups (old_chain
);
4928 warning (_("One or more sections of the remote executable does not match\n\
4929 the loaded file\n"));
4930 if (args
&& !matched
)
4931 printf_filtered (_("No loaded section named '%s'.\n"), args
);
4935 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
4936 const char *annex
, gdb_byte
*readbuf
,
4937 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
4939 struct remote_state
*rs
= get_remote_state ();
4941 char *buf2
= alloca (rs
->remote_packet_size
);
4942 char *p2
= &buf2
[0];
4945 /* Handle memory using remote_xfer_memory. */
4946 if (object
== TARGET_OBJECT_MEMORY
)
4951 if (writebuf
!= NULL
)
4953 void *buffer
= xmalloc (len
);
4954 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
4955 memcpy (buffer
, writebuf
, len
);
4956 xfered
= remote_xfer_memory (offset
, buffer
, len
, 1, NULL
, ops
);
4957 do_cleanups (cleanup
);
4960 xfered
= remote_xfer_memory (offset
, readbuf
, len
, 0, NULL
, ops
);
4964 else if (xfered
== 0 && errno
== 0)
4970 /* Only handle reads. */
4971 if (writebuf
!= NULL
|| readbuf
== NULL
)
4974 /* Map pre-existing objects onto letters. DO NOT do this for new
4975 objects!!! Instead specify new query packets. */
4978 case TARGET_OBJECT_KOD
:
4981 case TARGET_OBJECT_AVR
:
4985 case TARGET_OBJECT_AUXV
:
4986 if (remote_protocol_qPart_auxv
.support
!= PACKET_DISABLE
)
4988 unsigned int total
= 0;
4991 LONGEST n
= min ((rs
->remote_packet_size
- 2) / 2, len
);
4992 snprintf (buf2
, rs
->remote_packet_size
,
4993 "qPart:auxv:read::%s,%s",
4994 phex_nz (offset
, sizeof offset
),
4995 phex_nz (n
, sizeof n
));
4998 return total
> 0 ? total
: i
;
5000 getpkt (buf2
, rs
->remote_packet_size
, 0);
5001 if (packet_ok (buf2
, &remote_protocol_qPart_auxv
) != PACKET_OK
)
5002 return total
> 0 ? total
: -1;
5003 if (buf2
[0] == 'O' && buf2
[1] == 'K' && buf2
[2] == '\0')
5004 break; /* Got EOF indicator. */
5005 /* Got some data. */
5006 i
= hex2bin (buf2
, readbuf
, len
);
5009 readbuf
= (void *) ((char *) readbuf
+ i
);
5023 /* Note: a zero OFFSET and LEN can be used to query the minimum
5025 if (offset
== 0 && len
== 0)
5026 return (rs
->remote_packet_size
);
5027 /* Minimum outbuf size is RS->remote_packet_size. If LEN is not
5028 large enough let the caller deal with it. */
5029 if (len
< rs
->remote_packet_size
)
5031 len
= rs
->remote_packet_size
;
5033 /* Except for querying the minimum buffer size, target must be open. */
5035 error (_("remote query is only available after target open"));
5037 gdb_assert (annex
!= NULL
);
5038 gdb_assert (readbuf
!= NULL
);
5043 /* We used one buffer char for the remote protocol q command and
5044 another for the query type. As the remote protocol encapsulation
5045 uses 4 chars plus one extra in case we are debugging
5046 (remote_debug), we have PBUFZIZ - 7 left to pack the query
5049 while (annex
[i
] && (i
< (rs
->remote_packet_size
- 8)))
5051 /* Bad caller may have sent forbidden characters. */
5052 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
5057 gdb_assert (annex
[i
] == '\0');
5063 getpkt ((char *) readbuf
, len
, 0);
5065 return strlen ((char *) readbuf
);
5069 remote_rcmd (char *command
,
5070 struct ui_file
*outbuf
)
5072 struct remote_state
*rs
= get_remote_state ();
5073 char *buf
= alloca (rs
->remote_packet_size
);
5077 error (_("remote rcmd is only available after target open"));
5079 /* Send a NULL command across as an empty command. */
5080 if (command
== NULL
)
5083 /* The query prefix. */
5084 strcpy (buf
, "qRcmd,");
5085 p
= strchr (buf
, '\0');
5087 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > rs
->remote_packet_size
)
5088 error (_("\"monitor\" command ``%s'' is too long."), command
);
5090 /* Encode the actual command. */
5091 bin2hex ((gdb_byte
*) command
, p
, 0);
5093 if (putpkt (buf
) < 0)
5094 error (_("Communication problem with target."));
5096 /* get/display the response */
5099 /* XXX - see also tracepoint.c:remote_get_noisy_reply(). */
5101 getpkt (buf
, rs
->remote_packet_size
, 0);
5103 error (_("Target does not support this command."));
5104 if (buf
[0] == 'O' && buf
[1] != 'K')
5106 remote_console_output (buf
+ 1); /* 'O' message from stub. */
5109 if (strcmp (buf
, "OK") == 0)
5111 if (strlen (buf
) == 3 && buf
[0] == 'E'
5112 && isdigit (buf
[1]) && isdigit (buf
[2]))
5114 error (_("Protocol error with Rcmd"));
5116 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5118 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5119 fputc_unfiltered (c
, outbuf
);
5126 packet_command (char *args
, int from_tty
)
5128 struct remote_state
*rs
= get_remote_state ();
5129 char *buf
= alloca (rs
->remote_packet_size
);
5132 error (_("command can only be used with remote target"));
5135 error (_("remote-packet command requires packet text as argument"));
5137 puts_filtered ("sending: ");
5138 print_packet (args
);
5139 puts_filtered ("\n");
5142 getpkt (buf
, rs
->remote_packet_size
, 0);
5143 puts_filtered ("received: ");
5145 puts_filtered ("\n");
5149 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
5151 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5153 static void threadset_test_cmd (char *cmd
, int tty
);
5155 static void threadalive_test (char *cmd
, int tty
);
5157 static void threadlist_test_cmd (char *cmd
, int tty
);
5159 int get_and_display_threadinfo (threadref
*ref
);
5161 static void threadinfo_test_cmd (char *cmd
, int tty
);
5163 static int thread_display_step (threadref
*ref
, void *context
);
5165 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5167 static void init_remote_threadtests (void);
5169 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
5172 threadset_test_cmd (char *cmd
, int tty
)
5174 int sample_thread
= SAMPLE_THREAD
;
5176 printf_filtered (_("Remote threadset test\n"));
5177 set_thread (sample_thread
, 1);
5182 threadalive_test (char *cmd
, int tty
)
5184 int sample_thread
= SAMPLE_THREAD
;
5186 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5187 printf_filtered ("PASS: Thread alive test\n");
5189 printf_filtered ("FAIL: Thread alive test\n");
5192 void output_threadid (char *title
, threadref
*ref
);
5195 output_threadid (char *title
, threadref
*ref
)
5199 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
5201 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5205 threadlist_test_cmd (char *cmd
, int tty
)
5208 threadref nextthread
;
5209 int done
, result_count
;
5210 threadref threadlist
[3];
5212 printf_filtered ("Remote Threadlist test\n");
5213 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5214 &result_count
, &threadlist
[0]))
5215 printf_filtered ("FAIL: threadlist test\n");
5218 threadref
*scan
= threadlist
;
5219 threadref
*limit
= scan
+ result_count
;
5221 while (scan
< limit
)
5222 output_threadid (" thread ", scan
++);
5227 display_thread_info (struct gdb_ext_thread_info
*info
)
5229 output_threadid ("Threadid: ", &info
->threadid
);
5230 printf_filtered ("Name: %s\n ", info
->shortname
);
5231 printf_filtered ("State: %s\n", info
->display
);
5232 printf_filtered ("other: %s\n\n", info
->more_display
);
5236 get_and_display_threadinfo (threadref
*ref
)
5240 struct gdb_ext_thread_info threadinfo
;
5242 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5243 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5244 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5245 display_thread_info (&threadinfo
);
5250 threadinfo_test_cmd (char *cmd
, int tty
)
5252 int athread
= SAMPLE_THREAD
;
5256 int_to_threadref (&thread
, athread
);
5257 printf_filtered ("Remote Threadinfo test\n");
5258 if (!get_and_display_threadinfo (&thread
))
5259 printf_filtered ("FAIL cannot get thread info\n");
5263 thread_display_step (threadref
*ref
, void *context
)
5265 /* output_threadid(" threadstep ",ref); *//* simple test */
5266 return get_and_display_threadinfo (ref
);
5270 threadlist_update_test_cmd (char *cmd
, int tty
)
5272 printf_filtered ("Remote Threadlist update test\n");
5273 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5277 init_remote_threadtests (void)
5279 add_com ("tlist", class_obscure
, threadlist_test_cmd
, _("\
5280 Fetch and print the remote list of thread identifiers, one pkt only"));
5281 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5282 _("Fetch and display info about one thread"));
5283 add_com ("tset", class_obscure
, threadset_test_cmd
,
5284 _("Test setting to a different thread"));
5285 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5286 _("Iterate through updating all remote thread info"));
5287 add_com ("talive", class_obscure
, threadalive_test
,
5288 _(" Remote thread alive test "));
5293 /* Convert a thread ID to a string. Returns the string in a static
5297 remote_pid_to_str (ptid_t ptid
)
5299 static char buf
[32];
5301 xsnprintf (buf
, sizeof buf
, "thread %d", ptid_get_pid (ptid
));
5305 /* Get the address of the thread local variable in OBJFILE which is
5306 stored at OFFSET within the thread local storage for thread PTID. */
5309 remote_get_thread_local_address (ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
5311 if (remote_protocol_qGetTLSAddr
.support
!= PACKET_DISABLE
)
5313 struct remote_state
*rs
= get_remote_state ();
5314 char *buf
= alloca (rs
->remote_packet_size
);
5316 enum packet_result result
;
5318 strcpy (p
, "qGetTLSAddr:");
5320 p
+= hexnumstr (p
, PIDGET (ptid
));
5322 p
+= hexnumstr (p
, offset
);
5324 p
+= hexnumstr (p
, lm
);
5328 getpkt (buf
, rs
->remote_packet_size
, 0);
5329 result
= packet_ok (buf
, &remote_protocol_qGetTLSAddr
);
5330 if (result
== PACKET_OK
)
5334 unpack_varlen_hex (buf
, &result
);
5337 else if (result
== PACKET_UNKNOWN
)
5338 throw_error (TLS_GENERIC_ERROR
,
5339 _("Remote target doesn't support qGetTLSAddr packet"));
5341 throw_error (TLS_GENERIC_ERROR
,
5342 _("Remote target failed to process qGetTLSAddr request"));
5345 throw_error (TLS_GENERIC_ERROR
,
5346 _("TLS not supported or disabled on this target"));
5352 init_remote_ops (void)
5354 remote_ops
.to_shortname
= "remote";
5355 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5357 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5358 Specify the serial device it is connected to\n\
5359 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5360 remote_ops
.to_open
= remote_open
;
5361 remote_ops
.to_close
= remote_close
;
5362 remote_ops
.to_detach
= remote_detach
;
5363 remote_ops
.to_disconnect
= remote_disconnect
;
5364 remote_ops
.to_resume
= remote_resume
;
5365 remote_ops
.to_wait
= remote_wait
;
5366 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5367 remote_ops
.to_store_registers
= remote_store_registers
;
5368 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5369 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
5370 remote_ops
.to_files_info
= remote_files_info
;
5371 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5372 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5373 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5374 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5375 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5376 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5377 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5378 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5379 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5380 remote_ops
.to_kill
= remote_kill
;
5381 remote_ops
.to_load
= generic_load
;
5382 remote_ops
.to_mourn_inferior
= remote_mourn
;
5383 remote_ops
.to_thread_alive
= remote_thread_alive
;
5384 remote_ops
.to_find_new_threads
= remote_threads_info
;
5385 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5386 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5387 remote_ops
.to_stop
= remote_stop
;
5388 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
5389 remote_ops
.to_rcmd
= remote_rcmd
;
5390 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
5391 remote_ops
.to_stratum
= process_stratum
;
5392 remote_ops
.to_has_all_memory
= 1;
5393 remote_ops
.to_has_memory
= 1;
5394 remote_ops
.to_has_stack
= 1;
5395 remote_ops
.to_has_registers
= 1;
5396 remote_ops
.to_has_execution
= 1;
5397 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5398 remote_ops
.to_magic
= OPS_MAGIC
;
5401 /* Set up the extended remote vector by making a copy of the standard
5402 remote vector and adding to it. */
5405 init_extended_remote_ops (void)
5407 extended_remote_ops
= remote_ops
;
5409 extended_remote_ops
.to_shortname
= "extended-remote";
5410 extended_remote_ops
.to_longname
=
5411 "Extended remote serial target in gdb-specific protocol";
5412 extended_remote_ops
.to_doc
=
5413 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5414 Specify the serial device it is connected to (e.g. /dev/ttya).",
5415 extended_remote_ops
.to_open
= extended_remote_open
;
5416 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5417 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5421 remote_can_async_p (void)
5423 /* We're async whenever the serial device is. */
5424 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5428 remote_is_async_p (void)
5430 /* We're async whenever the serial device is. */
5431 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5434 /* Pass the SERIAL event on and up to the client. One day this code
5435 will be able to delay notifying the client of an event until the
5436 point where an entire packet has been received. */
5438 static void (*async_client_callback
) (enum inferior_event_type event_type
,
5440 static void *async_client_context
;
5441 static serial_event_ftype remote_async_serial_handler
;
5444 remote_async_serial_handler (struct serial
*scb
, void *context
)
5446 /* Don't propogate error information up to the client. Instead let
5447 the client find out about the error by querying the target. */
5448 async_client_callback (INF_REG_EVENT
, async_client_context
);
5452 remote_async (void (*callback
) (enum inferior_event_type event_type
,
5453 void *context
), void *context
)
5455 if (current_target
.to_async_mask_value
== 0)
5456 internal_error (__FILE__
, __LINE__
,
5457 _("Calling remote_async when async is masked"));
5459 if (callback
!= NULL
)
5461 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5462 async_client_callback
= callback
;
5463 async_client_context
= context
;
5466 serial_async (remote_desc
, NULL
, NULL
);
5469 /* Target async and target extended-async.
5471 This are temporary targets, until it is all tested. Eventually
5472 async support will be incorporated int the usual 'remote'
5476 init_remote_async_ops (void)
5478 remote_async_ops
.to_shortname
= "async";
5479 remote_async_ops
.to_longname
=
5480 "Remote serial target in async version of the gdb-specific protocol";
5481 remote_async_ops
.to_doc
=
5482 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5483 Specify the serial device it is connected to (e.g. /dev/ttya).";
5484 remote_async_ops
.to_open
= remote_async_open
;
5485 remote_async_ops
.to_close
= remote_close
;
5486 remote_async_ops
.to_detach
= remote_detach
;
5487 remote_async_ops
.to_disconnect
= remote_disconnect
;
5488 remote_async_ops
.to_resume
= remote_async_resume
;
5489 remote_async_ops
.to_wait
= remote_async_wait
;
5490 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5491 remote_async_ops
.to_store_registers
= remote_store_registers
;
5492 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5493 remote_async_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
5494 remote_async_ops
.to_files_info
= remote_files_info
;
5495 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5496 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5497 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5498 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5499 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5500 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5501 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5502 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5503 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5504 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5505 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5506 remote_async_ops
.to_kill
= remote_async_kill
;
5507 remote_async_ops
.to_load
= generic_load
;
5508 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5509 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5510 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5511 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
5512 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5513 remote_async_ops
.to_stop
= remote_stop
;
5514 remote_async_ops
.to_xfer_partial
= remote_xfer_partial
;
5515 remote_async_ops
.to_rcmd
= remote_rcmd
;
5516 remote_async_ops
.to_stratum
= process_stratum
;
5517 remote_async_ops
.to_has_all_memory
= 1;
5518 remote_async_ops
.to_has_memory
= 1;
5519 remote_async_ops
.to_has_stack
= 1;
5520 remote_async_ops
.to_has_registers
= 1;
5521 remote_async_ops
.to_has_execution
= 1;
5522 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5523 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5524 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5525 remote_async_ops
.to_async
= remote_async
;
5526 remote_async_ops
.to_async_mask_value
= 1;
5527 remote_async_ops
.to_magic
= OPS_MAGIC
;
5530 /* Set up the async extended remote vector by making a copy of the standard
5531 remote vector and adding to it. */
5534 init_extended_async_remote_ops (void)
5536 extended_async_remote_ops
= remote_async_ops
;
5538 extended_async_remote_ops
.to_shortname
= "extended-async";
5539 extended_async_remote_ops
.to_longname
=
5540 "Extended remote serial target in async gdb-specific protocol";
5541 extended_async_remote_ops
.to_doc
=
5542 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5543 Specify the serial device it is connected to (e.g. /dev/ttya).",
5544 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5545 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5546 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5549 static struct cmd_list_element
*remote_set_cmdlist
;
5550 static struct cmd_list_element
*remote_show_cmdlist
;
5553 set_remote_cmd (char *args
, int from_tty
)
5558 show_remote_cmd (char *args
, int from_tty
)
5560 /* We can't just use cmd_show_list here, because we want to skip
5561 the redundant "show remote Z-packet". */
5562 struct cleanup
*showlist_chain
;
5563 struct cmd_list_element
*list
= remote_show_cmdlist
;
5565 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
5566 for (; list
!= NULL
; list
= list
->next
)
5567 if (strcmp (list
->name
, "Z-packet") == 0)
5569 else if (list
->type
== show_cmd
)
5571 struct cleanup
*option_chain
5572 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
5573 ui_out_field_string (uiout
, "name", list
->name
);
5574 ui_out_text (uiout
, ": ");
5575 do_setshow_command ((char *) NULL
, from_tty
, list
);
5576 /* Close the tuple. */
5577 do_cleanups (option_chain
);
5582 build_remote_gdbarch_data (void)
5584 remote_address_size
= TARGET_ADDR_BIT
;
5587 /* Saved pointer to previous owner of the new_objfile event. */
5588 static void (*remote_new_objfile_chain
) (struct objfile
*);
5590 /* Function to be called whenever a new objfile (shlib) is detected. */
5592 remote_new_objfile (struct objfile
*objfile
)
5594 if (remote_desc
!= 0) /* Have a remote connection. */
5596 remote_check_symbols (objfile
);
5598 /* Call predecessor on chain, if any. */
5599 if (remote_new_objfile_chain
!= 0 &&
5601 remote_new_objfile_chain (objfile
);
5605 _initialize_remote (void)
5607 /* architecture specific data */
5608 remote_gdbarch_data_handle
=
5609 gdbarch_data_register_post_init (init_remote_state
);
5611 /* Old tacky stuff. NOTE: This comes after the remote protocol so
5612 that the remote protocol has been initialized. */
5613 DEPRECATED_REGISTER_GDBARCH_SWAP (remote_address_size
);
5614 deprecated_register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5617 add_target (&remote_ops
);
5619 init_extended_remote_ops ();
5620 add_target (&extended_remote_ops
);
5622 init_remote_async_ops ();
5623 add_target (&remote_async_ops
);
5625 init_extended_async_remote_ops ();
5626 add_target (&extended_async_remote_ops
);
5628 /* Hook into new objfile notification. */
5629 remote_new_objfile_chain
= deprecated_target_new_objfile_hook
;
5630 deprecated_target_new_objfile_hook
= remote_new_objfile
;
5633 init_remote_threadtests ();
5636 /* set/show remote ... */
5638 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
5639 Remote protocol specific variables\n\
5640 Configure various remote-protocol specific variables such as\n\
5641 the packets being used"),
5642 &remote_set_cmdlist
, "set remote ",
5643 0 /* allow-unknown */, &setlist
);
5644 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
5645 Remote protocol specific variables\n\
5646 Configure various remote-protocol specific variables such as\n\
5647 the packets being used"),
5648 &remote_show_cmdlist
, "show remote ",
5649 0 /* allow-unknown */, &showlist
);
5651 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
5652 Compare section data on target to the exec file.\n\
5653 Argument is a single section name (default: all loaded sections)."),
5656 add_cmd ("packet", class_maintenance
, packet_command
, _("\
5657 Send an arbitrary packet to a remote target.\n\
5658 maintenance packet TEXT\n\
5659 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5660 this command sends the string TEXT to the inferior, and displays the\n\
5661 response packet. GDB supplies the initial `$' character, and the\n\
5662 terminating `#' character and checksum."),
5665 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
5666 Set whether to send break if interrupted."), _("\
5667 Show whether to send break if interrupted."), _("\
5668 If set, a break, instead of a cntrl-c, is sent to the remote target."),
5669 NULL
, NULL
, /* FIXME: i18n: Whether to send break if interrupted is %s. */
5670 &setlist
, &showlist
);
5672 /* Install commands for configuring memory read/write packets. */
5674 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
5675 Set the maximum number of bytes per memory write packet (deprecated)."),
5677 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
5678 Show the maximum number of bytes per memory write packet (deprecated)."),
5680 add_cmd ("memory-write-packet-size", no_class
,
5681 set_memory_write_packet_size
, _("\
5682 Set the maximum number of bytes per memory-write packet.\n\
5683 Specify the number of bytes in a packet or 0 (zero) for the\n\
5684 default packet size. The actual limit is further reduced\n\
5685 dependent on the target. Specify ``fixed'' to disable the\n\
5686 further restriction and ``limit'' to enable that restriction."),
5687 &remote_set_cmdlist
);
5688 add_cmd ("memory-read-packet-size", no_class
,
5689 set_memory_read_packet_size
, _("\
5690 Set the maximum number of bytes per memory-read packet.\n\
5691 Specify the number of bytes in a packet or 0 (zero) for the\n\
5692 default packet size. The actual limit is further reduced\n\
5693 dependent on the target. Specify ``fixed'' to disable the\n\
5694 further restriction and ``limit'' to enable that restriction."),
5695 &remote_set_cmdlist
);
5696 add_cmd ("memory-write-packet-size", no_class
,
5697 show_memory_write_packet_size
,
5698 _("Show the maximum number of bytes per memory-write packet."),
5699 &remote_show_cmdlist
);
5700 add_cmd ("memory-read-packet-size", no_class
,
5701 show_memory_read_packet_size
,
5702 _("Show the maximum number of bytes per memory-read packet."),
5703 &remote_show_cmdlist
);
5705 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
5706 &remote_hw_watchpoint_limit
, _("\
5707 Set the maximum number of target hardware watchpoints."), _("\
5708 Show the maximum number of target hardware watchpoints."), _("\
5709 Specify a negative limit for unlimited."),
5710 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */
5711 &remote_set_cmdlist
, &remote_show_cmdlist
);
5712 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
5713 &remote_hw_breakpoint_limit
, _("\
5714 Set the maximum number of target hardware breakpoints."), _("\
5715 Show the maximum number of target hardware breakpoints."), _("\
5716 Specify a negative limit for unlimited."),
5717 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */
5718 &remote_set_cmdlist
, &remote_show_cmdlist
);
5720 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
5721 &remote_address_size
, _("\
5722 Set the maximum size of the address (in bits) in a memory packet."), _("\
5723 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
5725 NULL
, /* FIXME: i18n: */
5726 &setlist
, &showlist
);
5728 add_packet_config_cmd (&remote_protocol_binary_download
,
5729 "X", "binary-download",
5730 set_remote_protocol_binary_download_cmd
,
5731 show_remote_protocol_binary_download_cmd
,
5732 &remote_set_cmdlist
, &remote_show_cmdlist
,
5735 add_packet_config_cmd (&remote_protocol_vcont
,
5736 "vCont", "verbose-resume",
5737 set_remote_protocol_vcont_packet_cmd
,
5738 show_remote_protocol_vcont_packet_cmd
,
5739 &remote_set_cmdlist
, &remote_show_cmdlist
,
5742 add_packet_config_cmd (&remote_protocol_qSymbol
,
5743 "qSymbol", "symbol-lookup",
5744 set_remote_protocol_qSymbol_packet_cmd
,
5745 show_remote_protocol_qSymbol_packet_cmd
,
5746 &remote_set_cmdlist
, &remote_show_cmdlist
,
5749 add_packet_config_cmd (&remote_protocol_P
,
5750 "P", "set-register",
5751 set_remote_protocol_P_packet_cmd
,
5752 show_remote_protocol_P_packet_cmd
,
5753 &remote_set_cmdlist
, &remote_show_cmdlist
,
5756 add_packet_config_cmd (&remote_protocol_p
,
5757 "p", "fetch-register",
5758 set_remote_protocol_p_packet_cmd
,
5759 show_remote_protocol_p_packet_cmd
,
5760 &remote_set_cmdlist
, &remote_show_cmdlist
,
5763 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_SOFTWARE_BP
],
5764 "Z0", "software-breakpoint",
5765 set_remote_protocol_Z_software_bp_packet_cmd
,
5766 show_remote_protocol_Z_software_bp_packet_cmd
,
5767 &remote_set_cmdlist
, &remote_show_cmdlist
,
5770 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_HARDWARE_BP
],
5771 "Z1", "hardware-breakpoint",
5772 set_remote_protocol_Z_hardware_bp_packet_cmd
,
5773 show_remote_protocol_Z_hardware_bp_packet_cmd
,
5774 &remote_set_cmdlist
, &remote_show_cmdlist
,
5777 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_WRITE_WP
],
5778 "Z2", "write-watchpoint",
5779 set_remote_protocol_Z_write_wp_packet_cmd
,
5780 show_remote_protocol_Z_write_wp_packet_cmd
,
5781 &remote_set_cmdlist
, &remote_show_cmdlist
,
5784 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_READ_WP
],
5785 "Z3", "read-watchpoint",
5786 set_remote_protocol_Z_read_wp_packet_cmd
,
5787 show_remote_protocol_Z_read_wp_packet_cmd
,
5788 &remote_set_cmdlist
, &remote_show_cmdlist
,
5791 add_packet_config_cmd (&remote_protocol_Z
[Z_PACKET_ACCESS_WP
],
5792 "Z4", "access-watchpoint",
5793 set_remote_protocol_Z_access_wp_packet_cmd
,
5794 show_remote_protocol_Z_access_wp_packet_cmd
,
5795 &remote_set_cmdlist
, &remote_show_cmdlist
,
5798 add_packet_config_cmd (&remote_protocol_qPart_auxv
,
5799 "qPart_auxv", "read-aux-vector",
5800 set_remote_protocol_qPart_auxv_packet_cmd
,
5801 show_remote_protocol_qPart_auxv_packet_cmd
,
5802 &remote_set_cmdlist
, &remote_show_cmdlist
,
5805 add_packet_config_cmd (&remote_protocol_qGetTLSAddr
,
5806 "qGetTLSAddr", "get-thread-local-storage-address",
5807 set_remote_protocol_qGetTLSAddr_packet_cmd
,
5808 show_remote_protocol_qGetTLSAddr_packet_cmd
,
5809 &remote_set_cmdlist
, &remote_show_cmdlist
,
5812 /* Keep the old ``set remote Z-packet ...'' working. Each individual
5813 Z sub-packet has its own set and show commands, but users may
5814 have sets to this variable in their .gdbinit files (or in their
5816 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
5817 &remote_Z_packet_detect
, _("\
5818 Set use of remote protocol `Z' packets"), _("\
5819 Show use of remote protocol `Z' packets "), _("\
5820 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
5822 set_remote_protocol_Z_packet_cmd
,
5823 show_remote_protocol_Z_packet_cmd
, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */
5824 &remote_set_cmdlist
, &remote_show_cmdlist
);
5826 /* Eventually initialize fileio. See fileio.c */
5827 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);