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_p
);
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 void skip_frame (void);
137 static long read_frame (char **buf_p
, long *sizeof_buf
);
139 static int hexnumlen (ULONGEST num
);
141 static void init_remote_ops (void);
143 static void init_extended_remote_ops (void);
145 static void remote_stop (void);
147 static int ishex (int ch
, int *val
);
149 static int stubhex (int ch
);
151 static int hexnumstr (char *, ULONGEST
);
153 static int hexnumnstr (char *, ULONGEST
, int);
155 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
157 static void print_packet (char *);
159 static unsigned long crc32 (unsigned char *, int, unsigned int);
161 static void compare_sections_command (char *, int);
163 static void packet_command (char *, int);
165 static int stub_unpack_int (char *buff
, int fieldlength
);
167 static ptid_t
remote_current_thread (ptid_t oldptid
);
169 static void remote_find_new_threads (void);
171 static void record_currthread (int currthread
);
173 static int fromhex (int a
);
175 static int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
177 static int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
179 static int putpkt_binary (char *buf
, int cnt
);
181 static void check_binary_download (CORE_ADDR addr
);
183 struct packet_config
;
185 static void show_packet_config_cmd (struct packet_config
*config
);
187 static void update_packet_config (struct packet_config
*config
);
189 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
190 struct cmd_list_element
*c
);
192 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
194 struct cmd_list_element
*c
,
197 void _initialize_remote (void);
199 /* For "set remote" and "show remote". */
201 static struct cmd_list_element
*remote_set_cmdlist
;
202 static struct cmd_list_element
*remote_show_cmdlist
;
204 /* Description of the remote protocol state for the currently
205 connected target. This is per-target state, and independent of the
206 selected architecture. */
210 /* A buffer to use for incoming packets, and its current size. The
211 buffer is grown dynamically for larger incoming packets.
212 Outgoing packets may also be constructed in this buffer.
213 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
214 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
219 /* If we negotiated packet size explicitly (and thus can bypass
220 heuristics for the largest packet size that will not overflow
221 a buffer in the stub), this will be set to that packet size.
222 Otherwise zero, meaning to use the guessed size. */
223 long explicit_packet_size
;
226 /* This data could be associated with a target, but we do not always
227 have access to the current target when we need it, so for now it is
228 static. This will be fine for as long as only one target is in use
230 static struct remote_state remote_state
;
232 static struct remote_state
*
233 get_remote_state (void)
235 return &remote_state
;
238 /* Description of the remote protocol for a given architecture. */
242 long offset
; /* Offset into G packet. */
243 long regnum
; /* GDB's internal register number. */
244 LONGEST pnum
; /* Remote protocol register number. */
245 int in_g_packet
; /* Always part of G packet. */
246 /* long size in bytes; == register_size (current_gdbarch, regnum);
248 /* char *name; == REGISTER_NAME (regnum); at present. */
251 struct remote_arch_state
253 /* Description of the remote protocol registers. */
254 long sizeof_g_packet
;
256 /* Description of the remote protocol registers indexed by REGNUM
257 (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
258 struct packet_reg
*regs
;
260 /* This is the size (in chars) of the first response to the ``g''
261 packet. It is used as a heuristic when determining the maximum
262 size of memory-read and memory-write packets. A target will
263 typically only reserve a buffer large enough to hold the ``g''
264 packet. The size does not include packet overhead (headers and
266 long actual_register_packet_size
;
268 /* This is the maximum size (in chars) of a non read/write packet.
269 It is also used as a cap on the size of read/write packets. */
270 long remote_packet_size
;
274 /* Handle for retreving the remote protocol data from gdbarch. */
275 static struct gdbarch_data
*remote_gdbarch_data_handle
;
277 static struct remote_arch_state
*
278 get_remote_arch_state (void)
280 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
284 init_remote_state (struct gdbarch
*gdbarch
)
287 struct remote_state
*rs
= get_remote_state ();
288 struct remote_arch_state
*rsa
;
290 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
292 rsa
->sizeof_g_packet
= 0;
294 /* Assume a 1:1 regnum<->pnum table. */
295 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
, NUM_REGS
+ NUM_PSEUDO_REGS
,
297 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
299 struct packet_reg
*r
= &rsa
->regs
[regnum
];
302 r
->offset
= DEPRECATED_REGISTER_BYTE (regnum
);
303 r
->in_g_packet
= (regnum
< NUM_REGS
);
304 /* ...name = REGISTER_NAME (regnum); */
306 /* Compute packet size by accumulating the size of all registers. */
307 if (regnum
< NUM_REGS
)
308 rsa
->sizeof_g_packet
+= register_size (current_gdbarch
, regnum
);
311 /* Default maximum number of characters in a packet body. Many
312 remote stubs have a hardwired buffer size of 400 bytes
313 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
314 as the maximum packet-size to ensure that the packet and an extra
315 NUL character can always fit in the buffer. This stops GDB
316 trashing stubs that try to squeeze an extra NUL into what is
317 already a full buffer (As of 1999-12-04 that was most stubs). */
318 rsa
->remote_packet_size
= 400 - 1;
320 /* This one is filled in when a ``g'' packet is received. */
321 rsa
->actual_register_packet_size
= 0;
323 /* Should rsa->sizeof_g_packet needs more space than the
324 default, adjust the size accordingly. Remember that each byte is
325 encoded as two characters. 32 is the overhead for the packet
326 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
327 (``$NN:G...#NN'') is a better guess, the below has been padded a
329 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
330 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
332 /* Make sure that the packet buffer is plenty big enough for
333 this architecture. */
334 if (rs
->buf_size
< rsa
->remote_packet_size
)
336 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
337 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
343 /* Return the current allowed size of a remote packet. This is
344 inferred from the current architecture, and should be used to
345 limit the length of outgoing packets. */
347 get_remote_packet_size (void)
349 struct remote_state
*rs
= get_remote_state ();
350 struct remote_arch_state
*rsa
= get_remote_arch_state ();
352 if (rs
->explicit_packet_size
)
353 return rs
->explicit_packet_size
;
355 return rsa
->remote_packet_size
;
358 static struct packet_reg
*
359 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
361 if (regnum
< 0 && regnum
>= NUM_REGS
+ NUM_PSEUDO_REGS
)
365 struct packet_reg
*r
= &rsa
->regs
[regnum
];
366 gdb_assert (r
->regnum
== regnum
);
371 static struct packet_reg
*
372 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
375 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
377 struct packet_reg
*r
= &rsa
->regs
[i
];
384 /* FIXME: graces/2002-08-08: These variables should eventually be
385 bound to an instance of the target object (as in gdbarch-tdep()),
386 when such a thing exists. */
388 /* This is set to the data address of the access causing the target
389 to stop for a watchpoint. */
390 static CORE_ADDR remote_watch_data_address
;
392 /* This is non-zero if target stopped for a watchpoint. */
393 static int remote_stopped_by_watchpoint_p
;
395 static struct target_ops remote_ops
;
397 static struct target_ops extended_remote_ops
;
399 /* Temporary target ops. Just like the remote_ops and
400 extended_remote_ops, but with asynchronous support. */
401 static struct target_ops remote_async_ops
;
403 static struct target_ops extended_async_remote_ops
;
405 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
406 ``forever'' still use the normal timeout mechanism. This is
407 currently used by the ASYNC code to guarentee that target reads
408 during the initial connect always time-out. Once getpkt has been
409 modified to return a timeout indication and, in turn
410 remote_wait()/wait_for_inferior() have gained a timeout parameter
412 static int wait_forever_enabled_p
= 1;
415 /* This variable chooses whether to send a ^C or a break when the user
416 requests program interruption. Although ^C is usually what remote
417 systems expect, and that is the default here, sometimes a break is
418 preferable instead. */
420 static int remote_break
;
422 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
423 remote_open knows that we don't have a file open when the program
425 static struct serial
*remote_desc
= NULL
;
427 /* This variable sets the number of bits in an address that are to be
428 sent in a memory ("M" or "m") packet. Normally, after stripping
429 leading zeros, the entire address would be sent. This variable
430 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
431 initial implementation of remote.c restricted the address sent in
432 memory packets to ``host::sizeof long'' bytes - (typically 32
433 bits). Consequently, for 64 bit targets, the upper 32 bits of an
434 address was never sent. Since fixing this bug may cause a break in
435 some remote targets this variable is principly provided to
436 facilitate backward compatibility. */
438 static int remote_address_size
;
440 /* Tempoary to track who currently owns the terminal. See
441 target_async_terminal_* for more details. */
443 static int remote_async_terminal_ours_p
;
446 /* User configurable variables for the number of characters in a
447 memory read/write packet. MIN (rsa->remote_packet_size,
448 rsa->sizeof_g_packet) is the default. Some targets need smaller
449 values (fifo overruns, et.al.) and some users need larger values
450 (speed up transfers). The variables ``preferred_*'' (the user
451 request), ``current_*'' (what was actually set) and ``forced_*''
452 (Positive - a soft limit, negative - a hard limit). */
454 struct memory_packet_config
461 /* Compute the current size of a read/write packet. Since this makes
462 use of ``actual_register_packet_size'' the computation is dynamic. */
465 get_memory_packet_size (struct memory_packet_config
*config
)
467 struct remote_state
*rs
= get_remote_state ();
468 struct remote_arch_state
*rsa
= get_remote_arch_state ();
470 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
471 law?) that some hosts don't cope very well with large alloca()
472 calls. Eventually the alloca() code will be replaced by calls to
473 xmalloc() and make_cleanups() allowing this restriction to either
474 be lifted or removed. */
475 #ifndef MAX_REMOTE_PACKET_SIZE
476 #define MAX_REMOTE_PACKET_SIZE 16384
478 /* NOTE: 20 ensures we can write at least one byte. */
479 #ifndef MIN_REMOTE_PACKET_SIZE
480 #define MIN_REMOTE_PACKET_SIZE 20
485 if (config
->size
<= 0)
486 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
488 what_they_get
= config
->size
;
492 what_they_get
= get_remote_packet_size ();
493 /* Limit the packet to the size specified by the user. */
495 && what_they_get
> config
->size
)
496 what_they_get
= config
->size
;
498 /* Limit it to the size of the targets ``g'' response unless we have
499 permission from the stub to use a larger packet size. */
500 if (rs
->explicit_packet_size
== 0
501 && rsa
->actual_register_packet_size
> 0
502 && what_they_get
> rsa
->actual_register_packet_size
)
503 what_they_get
= rsa
->actual_register_packet_size
;
505 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
506 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
507 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
508 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
510 /* Make sure there is room in the global buffer for this packet
511 (including its trailing NUL byte). */
512 if (rs
->buf_size
< what_they_get
+ 1)
514 rs
->buf_size
= 2 * what_they_get
;
515 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
518 return what_they_get
;
521 /* Update the size of a read/write packet. If they user wants
522 something really big then do a sanity check. */
525 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
527 int fixed_p
= config
->fixed_p
;
528 long size
= config
->size
;
530 error (_("Argument required (integer, `fixed' or `limited')."));
531 else if (strcmp (args
, "hard") == 0
532 || strcmp (args
, "fixed") == 0)
534 else if (strcmp (args
, "soft") == 0
535 || strcmp (args
, "limit") == 0)
540 size
= strtoul (args
, &end
, 0);
542 error (_("Invalid %s (bad syntax)."), config
->name
);
544 /* Instead of explicitly capping the size of a packet to
545 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
546 instead allowed to set the size to something arbitrarily
548 if (size
> MAX_REMOTE_PACKET_SIZE
)
549 error (_("Invalid %s (too large)."), config
->name
);
553 if (fixed_p
&& !config
->fixed_p
)
555 if (! query (_("The target may not be able to correctly handle a %s\n"
556 "of %ld bytes. Change the packet size? "),
558 error (_("Packet size not changed."));
560 /* Update the config. */
561 config
->fixed_p
= fixed_p
;
566 show_memory_packet_size (struct memory_packet_config
*config
)
568 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
570 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
571 get_memory_packet_size (config
));
573 printf_filtered (_("Packets are limited to %ld bytes.\n"),
574 get_memory_packet_size (config
));
577 static struct memory_packet_config memory_write_packet_config
=
579 "memory-write-packet-size",
583 set_memory_write_packet_size (char *args
, int from_tty
)
585 set_memory_packet_size (args
, &memory_write_packet_config
);
589 show_memory_write_packet_size (char *args
, int from_tty
)
591 show_memory_packet_size (&memory_write_packet_config
);
595 get_memory_write_packet_size (void)
597 return get_memory_packet_size (&memory_write_packet_config
);
600 static struct memory_packet_config memory_read_packet_config
=
602 "memory-read-packet-size",
606 set_memory_read_packet_size (char *args
, int from_tty
)
608 set_memory_packet_size (args
, &memory_read_packet_config
);
612 show_memory_read_packet_size (char *args
, int from_tty
)
614 show_memory_packet_size (&memory_read_packet_config
);
618 get_memory_read_packet_size (void)
620 long size
= get_memory_packet_size (&memory_read_packet_config
);
621 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
622 extra buffer size argument before the memory read size can be
623 increased beyond this. */
624 if (size
> get_remote_packet_size ())
625 size
= get_remote_packet_size ();
630 /* Generic configuration support for packets the stub optionally
631 supports. Allows the user to specify the use of the packet as well
632 as allowing GDB to auto-detect support in the remote stub. */
636 PACKET_SUPPORT_UNKNOWN
= 0,
645 enum auto_boolean detect
;
646 enum packet_support support
;
649 /* Analyze a packet's return value and update the packet config
660 update_packet_config (struct packet_config
*config
)
662 switch (config
->detect
)
664 case AUTO_BOOLEAN_TRUE
:
665 config
->support
= PACKET_ENABLE
;
667 case AUTO_BOOLEAN_FALSE
:
668 config
->support
= PACKET_DISABLE
;
670 case AUTO_BOOLEAN_AUTO
:
671 config
->support
= PACKET_SUPPORT_UNKNOWN
;
677 show_packet_config_cmd (struct packet_config
*config
)
679 char *support
= "internal-error";
680 switch (config
->support
)
686 support
= "disabled";
688 case PACKET_SUPPORT_UNKNOWN
:
692 switch (config
->detect
)
694 case AUTO_BOOLEAN_AUTO
:
695 printf_filtered (_("Support for the `%s' packet is auto-detected, currently %s.\n"),
696 config
->name
, support
);
698 case AUTO_BOOLEAN_TRUE
:
699 case AUTO_BOOLEAN_FALSE
:
700 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
701 config
->name
, support
);
707 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
708 const char *title
, int legacy
)
715 config
->title
= title
;
716 config
->detect
= AUTO_BOOLEAN_AUTO
;
717 config
->support
= PACKET_SUPPORT_UNKNOWN
;
718 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
720 show_doc
= xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
722 /* set/show TITLE-packet {auto,on,off} */
723 cmd_name
= xstrprintf ("%s-packet", title
);
724 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
725 &config
->detect
, set_doc
, show_doc
, NULL
, /* help_doc */
726 set_remote_protocol_packet_cmd
,
727 show_remote_protocol_packet_cmd
,
728 &remote_set_cmdlist
, &remote_show_cmdlist
);
729 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
733 legacy_name
= xstrprintf ("%s-packet", name
);
734 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
735 &remote_set_cmdlist
);
736 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
737 &remote_show_cmdlist
);
741 static enum packet_result
742 packet_ok (const char *buf
, struct packet_config
*config
)
746 /* The stub recognized the packet request. Check that the
747 operation succeeded. */
748 switch (config
->support
)
750 case PACKET_SUPPORT_UNKNOWN
:
752 fprintf_unfiltered (gdb_stdlog
,
753 "Packet %s (%s) is supported\n",
754 config
->name
, config
->title
);
755 config
->support
= PACKET_ENABLE
;
758 internal_error (__FILE__
, __LINE__
,
759 _("packet_ok: attempt to use a disabled packet"));
764 if (buf
[0] == 'O' && buf
[1] == 'K' && buf
[2] == '\0')
765 /* "OK" - definitly OK. */
768 && isxdigit (buf
[1]) && isxdigit (buf
[2])
770 /* "Enn" - definitly an error. */
772 /* The packet may or may not be OK. Just assume it is. */
777 /* The stub does not support the packet. */
778 switch (config
->support
)
781 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
782 /* If the stub previously indicated that the packet was
783 supported then there is a protocol error.. */
784 error (_("Protocol error: %s (%s) conflicting enabled responses."),
785 config
->name
, config
->title
);
787 /* The user set it wrong. */
788 error (_("Enabled packet %s (%s) not recognized by stub"),
789 config
->name
, config
->title
);
791 case PACKET_SUPPORT_UNKNOWN
:
793 fprintf_unfiltered (gdb_stdlog
,
794 "Packet %s (%s) is NOT supported\n",
795 config
->name
, config
->title
);
796 config
->support
= PACKET_DISABLE
;
801 return PACKET_UNKNOWN
;
822 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
825 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
826 struct cmd_list_element
*c
)
828 struct packet_config
*packet
;
830 for (packet
= remote_protocol_packets
;
831 packet
< &remote_protocol_packets
[PACKET_MAX
];
834 if (&packet
->detect
== c
->var
)
836 update_packet_config (packet
);
840 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
845 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
846 struct cmd_list_element
*c
,
849 struct packet_config
*packet
;
851 for (packet
= remote_protocol_packets
;
852 packet
< &remote_protocol_packets
[PACKET_MAX
];
855 if (&packet
->detect
== c
->var
)
857 show_packet_config_cmd (packet
);
861 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
865 /* Should we try one of the 'Z' requests? */
869 Z_PACKET_SOFTWARE_BP
,
870 Z_PACKET_HARDWARE_BP
,
877 /* For compatibility with older distributions. Provide a ``set remote
878 Z-packet ...'' command that updates all the Z packet types. */
880 static enum auto_boolean remote_Z_packet_detect
;
883 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
884 struct cmd_list_element
*c
)
887 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
889 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
890 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
895 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
896 struct cmd_list_element
*c
,
900 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
902 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
906 /* Should we try the 'ThreadInfo' query packet?
908 This variable (NOT available to the user: auto-detect only!)
909 determines whether GDB will use the new, simpler "ThreadInfo"
910 query or the older, more complex syntax for thread queries.
911 This is an auto-detect variable (set to true at each connect,
912 and set to false when the target fails to recognize it). */
914 static int use_threadinfo_query
;
915 static int use_threadextra_query
;
917 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
918 static void *sigint_remote_twice_token
;
919 static void *sigint_remote_token
;
921 /* These are pointers to hook functions that may be set in order to
922 modify resume/wait behavior for a particular architecture. */
924 void (*deprecated_target_resume_hook
) (void);
925 void (*deprecated_target_wait_loop_hook
) (void);
929 /* These are the threads which we last sent to the remote system.
930 -1 for all or -2 for not sent yet. */
931 static int general_thread
;
932 static int continue_thread
;
934 /* Call this function as a result of
935 1) A halt indication (T packet) containing a thread id
936 2) A direct query of currthread
937 3) Successful execution of set thread
941 record_currthread (int currthread
)
943 general_thread
= currthread
;
945 /* If this is a new thread, add it to GDB's thread list.
946 If we leave it up to WFI to do this, bad things will happen. */
947 if (!in_thread_list (pid_to_ptid (currthread
)))
949 add_thread (pid_to_ptid (currthread
));
950 ui_out_text (uiout
, "[New ");
951 ui_out_text (uiout
, target_pid_to_str (pid_to_ptid (currthread
)));
952 ui_out_text (uiout
, "]\n");
956 #define MAGIC_NULL_PID 42000
959 set_thread (int th
, int gen
)
961 struct remote_state
*rs
= get_remote_state ();
963 int state
= gen
? general_thread
: continue_thread
;
969 buf
[1] = gen
? 'g' : 'c';
970 if (th
== MAGIC_NULL_PID
)
976 xsnprintf (&buf
[2], get_remote_packet_size () - 2, "-%x", -th
);
978 xsnprintf (&buf
[2], get_remote_packet_size () - 2, "%x", th
);
980 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
984 continue_thread
= th
;
987 /* Return nonzero if the thread TH is still alive on the remote system. */
990 remote_thread_alive (ptid_t ptid
)
992 struct remote_state
*rs
= get_remote_state ();
993 int tid
= PIDGET (ptid
);
997 xsnprintf (buf
, get_remote_packet_size (), "T-%08x", -tid
);
999 xsnprintf (buf
, get_remote_packet_size (), "T%08x", tid
);
1001 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1002 return (buf
[0] == 'O' && buf
[1] == 'K');
1005 /* About these extended threadlist and threadinfo packets. They are
1006 variable length packets but, the fields within them are often fixed
1007 length. They are redundent enough to send over UDP as is the
1008 remote protocol in general. There is a matching unit test module
1011 #define OPAQUETHREADBYTES 8
1013 /* a 64 bit opaque identifier */
1014 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1016 /* WARNING: This threadref data structure comes from the remote O.S.,
1017 libstub protocol encoding, and remote.c. it is not particularly
1020 /* Right now, the internal structure is int. We want it to be bigger.
1024 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1026 /* gdb_ext_thread_info is an internal GDB data structure which is
1027 equivalent to the reply of the remote threadinfo packet. */
1029 struct gdb_ext_thread_info
1031 threadref threadid
; /* External form of thread reference. */
1032 int active
; /* Has state interesting to GDB?
1034 char display
[256]; /* Brief state display, name,
1035 blocked/suspended. */
1036 char shortname
[32]; /* To be used to name threads. */
1037 char more_display
[256]; /* Long info, statistics, queue depth,
1041 /* The volume of remote transfers can be limited by submitting
1042 a mask containing bits specifying the desired information.
1043 Use a union of these values as the 'selection' parameter to
1044 get_thread_info. FIXME: Make these TAG names more thread specific.
1047 #define TAG_THREADID 1
1048 #define TAG_EXISTS 2
1049 #define TAG_DISPLAY 4
1050 #define TAG_THREADNAME 8
1051 #define TAG_MOREDISPLAY 16
1053 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1055 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1057 static char *unpack_nibble (char *buf
, int *val
);
1059 static char *pack_nibble (char *buf
, int nibble
);
1061 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1063 static char *unpack_byte (char *buf
, int *value
);
1065 static char *pack_int (char *buf
, int value
);
1067 static char *unpack_int (char *buf
, int *value
);
1069 static char *unpack_string (char *src
, char *dest
, int length
);
1071 static char *pack_threadid (char *pkt
, threadref
*id
);
1073 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1075 void int_to_threadref (threadref
*id
, int value
);
1077 static int threadref_to_int (threadref
*ref
);
1079 static void copy_threadref (threadref
*dest
, threadref
*src
);
1081 static int threadmatch (threadref
*dest
, threadref
*src
);
1083 static char *pack_threadinfo_request (char *pkt
, int mode
,
1086 static int remote_unpack_thread_info_response (char *pkt
,
1087 threadref
*expectedref
,
1088 struct gdb_ext_thread_info
1092 static int remote_get_threadinfo (threadref
*threadid
,
1093 int fieldset
, /*TAG mask */
1094 struct gdb_ext_thread_info
*info
);
1096 static char *pack_threadlist_request (char *pkt
, int startflag
,
1098 threadref
*nextthread
);
1100 static int parse_threadlist_response (char *pkt
,
1102 threadref
*original_echo
,
1103 threadref
*resultlist
,
1106 static int remote_get_threadlist (int startflag
,
1107 threadref
*nextthread
,
1111 threadref
*threadlist
);
1113 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1115 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1116 void *context
, int looplimit
);
1118 static int remote_newthread_step (threadref
*ref
, void *context
);
1120 /* Encode 64 bits in 16 chars of hex. */
1122 static const char hexchars
[] = "0123456789abcdef";
1125 ishex (int ch
, int *val
)
1127 if ((ch
>= 'a') && (ch
<= 'f'))
1129 *val
= ch
- 'a' + 10;
1132 if ((ch
>= 'A') && (ch
<= 'F'))
1134 *val
= ch
- 'A' + 10;
1137 if ((ch
>= '0') && (ch
<= '9'))
1148 if (ch
>= 'a' && ch
<= 'f')
1149 return ch
- 'a' + 10;
1150 if (ch
>= '0' && ch
<= '9')
1152 if (ch
>= 'A' && ch
<= 'F')
1153 return ch
- 'A' + 10;
1158 stub_unpack_int (char *buff
, int fieldlength
)
1165 nibble
= stubhex (*buff
++);
1169 retval
= retval
<< 4;
1175 unpack_varlen_hex (char *buff
, /* packet to parse */
1181 while (ishex (*buff
, &nibble
))
1184 retval
= retval
<< 4;
1185 retval
|= nibble
& 0x0f;
1192 unpack_nibble (char *buf
, int *val
)
1194 ishex (*buf
++, val
);
1199 pack_nibble (char *buf
, int nibble
)
1201 *buf
++ = hexchars
[(nibble
& 0x0f)];
1206 pack_hex_byte (char *pkt
, int byte
)
1208 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1209 *pkt
++ = hexchars
[(byte
& 0xf)];
1214 unpack_byte (char *buf
, int *value
)
1216 *value
= stub_unpack_int (buf
, 2);
1221 pack_int (char *buf
, int value
)
1223 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1224 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1225 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1226 buf
= pack_hex_byte (buf
, (value
& 0xff));
1231 unpack_int (char *buf
, int *value
)
1233 *value
= stub_unpack_int (buf
, 8);
1237 #if 0 /* Currently unused, uncomment when needed. */
1238 static char *pack_string (char *pkt
, char *string
);
1241 pack_string (char *pkt
, char *string
)
1246 len
= strlen (string
);
1248 len
= 200; /* Bigger than most GDB packets, junk??? */
1249 pkt
= pack_hex_byte (pkt
, len
);
1253 if ((ch
== '\0') || (ch
== '#'))
1254 ch
= '*'; /* Protect encapsulation. */
1259 #endif /* 0 (unused) */
1262 unpack_string (char *src
, char *dest
, int length
)
1271 pack_threadid (char *pkt
, threadref
*id
)
1274 unsigned char *altid
;
1276 altid
= (unsigned char *) id
;
1277 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1279 pkt
= pack_hex_byte (pkt
, *altid
++);
1285 unpack_threadid (char *inbuf
, threadref
*id
)
1288 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1291 altref
= (char *) id
;
1293 while (inbuf
< limit
)
1295 x
= stubhex (*inbuf
++);
1296 y
= stubhex (*inbuf
++);
1297 *altref
++ = (x
<< 4) | y
;
1302 /* Externally, threadrefs are 64 bits but internally, they are still
1303 ints. This is due to a mismatch of specifications. We would like
1304 to use 64bit thread references internally. This is an adapter
1308 int_to_threadref (threadref
*id
, int value
)
1310 unsigned char *scan
;
1312 scan
= (unsigned char *) id
;
1318 *scan
++ = (value
>> 24) & 0xff;
1319 *scan
++ = (value
>> 16) & 0xff;
1320 *scan
++ = (value
>> 8) & 0xff;
1321 *scan
++ = (value
& 0xff);
1325 threadref_to_int (threadref
*ref
)
1328 unsigned char *scan
;
1334 value
= (value
<< 8) | ((*scan
++) & 0xff);
1339 copy_threadref (threadref
*dest
, threadref
*src
)
1342 unsigned char *csrc
, *cdest
;
1344 csrc
= (unsigned char *) src
;
1345 cdest
= (unsigned char *) dest
;
1352 threadmatch (threadref
*dest
, threadref
*src
)
1354 /* Things are broken right now, so just assume we got a match. */
1356 unsigned char *srcp
, *destp
;
1358 srcp
= (char *) src
;
1359 destp
= (char *) dest
;
1363 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1370 threadid:1, # always request threadid
1377 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1380 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1382 *pkt
++ = 'q'; /* Info Query */
1383 *pkt
++ = 'P'; /* process or thread info */
1384 pkt
= pack_int (pkt
, mode
); /* mode */
1385 pkt
= pack_threadid (pkt
, id
); /* threadid */
1386 *pkt
= '\0'; /* terminate */
1390 /* These values tag the fields in a thread info response packet. */
1391 /* Tagging the fields allows us to request specific fields and to
1392 add more fields as time goes by. */
1394 #define TAG_THREADID 1 /* Echo the thread identifier. */
1395 #define TAG_EXISTS 2 /* Is this process defined enough to
1396 fetch registers and its stack? */
1397 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1398 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
1399 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1403 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1404 struct gdb_ext_thread_info
*info
)
1406 struct remote_state
*rs
= get_remote_state ();
1410 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
1413 /* info->threadid = 0; FIXME: implement zero_threadref. */
1415 info
->display
[0] = '\0';
1416 info
->shortname
[0] = '\0';
1417 info
->more_display
[0] = '\0';
1419 /* Assume the characters indicating the packet type have been
1421 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1422 pkt
= unpack_threadid (pkt
, &ref
);
1425 warning (_("Incomplete response to threadinfo request."));
1426 if (!threadmatch (&ref
, expectedref
))
1427 { /* This is an answer to a different request. */
1428 warning (_("ERROR RMT Thread info mismatch."));
1431 copy_threadref (&info
->threadid
, &ref
);
1433 /* Loop on tagged fields , try to bail if somthing goes wrong. */
1435 /* Packets are terminated with nulls. */
1436 while ((pkt
< limit
) && mask
&& *pkt
)
1438 pkt
= unpack_int (pkt
, &tag
); /* tag */
1439 pkt
= unpack_byte (pkt
, &length
); /* length */
1440 if (!(tag
& mask
)) /* Tags out of synch with mask. */
1442 warning (_("ERROR RMT: threadinfo tag mismatch."));
1446 if (tag
== TAG_THREADID
)
1450 warning (_("ERROR RMT: length of threadid is not 16."));
1454 pkt
= unpack_threadid (pkt
, &ref
);
1455 mask
= mask
& ~TAG_THREADID
;
1458 if (tag
== TAG_EXISTS
)
1460 info
->active
= stub_unpack_int (pkt
, length
);
1462 mask
= mask
& ~(TAG_EXISTS
);
1465 warning (_("ERROR RMT: 'exists' length too long."));
1471 if (tag
== TAG_THREADNAME
)
1473 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1474 mask
= mask
& ~TAG_THREADNAME
;
1477 if (tag
== TAG_DISPLAY
)
1479 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1480 mask
= mask
& ~TAG_DISPLAY
;
1483 if (tag
== TAG_MOREDISPLAY
)
1485 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1486 mask
= mask
& ~TAG_MOREDISPLAY
;
1489 warning (_("ERROR RMT: unknown thread info tag."));
1490 break; /* Not a tag we know about. */
1496 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1497 struct gdb_ext_thread_info
*info
)
1499 struct remote_state
*rs
= get_remote_state ();
1501 char *threadinfo_pkt
= rs
->buf
;
1503 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1504 putpkt (threadinfo_pkt
);
1505 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1506 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2,
1511 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1514 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1515 threadref
*nextthread
)
1517 *pkt
++ = 'q'; /* info query packet */
1518 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1519 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1520 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1521 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1526 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1529 parse_threadlist_response (char *pkt
, int result_limit
,
1530 threadref
*original_echo
, threadref
*resultlist
,
1533 struct remote_state
*rs
= get_remote_state ();
1535 int count
, resultcount
, done
;
1538 /* Assume the 'q' and 'M chars have been stripped. */
1539 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
1540 /* done parse past here */
1541 pkt
= unpack_byte (pkt
, &count
); /* count field */
1542 pkt
= unpack_nibble (pkt
, &done
);
1543 /* The first threadid is the argument threadid. */
1544 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1545 while ((count
-- > 0) && (pkt
< limit
))
1547 pkt
= unpack_threadid (pkt
, resultlist
++);
1548 if (resultcount
++ >= result_limit
)
1557 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1558 int *done
, int *result_count
, threadref
*threadlist
)
1560 struct remote_state
*rs
= get_remote_state ();
1561 static threadref echo_nextthread
;
1562 char *threadlist_packet
= rs
->buf
;
1565 /* Trancate result limit to be smaller than the packet size. */
1566 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= get_remote_packet_size ())
1567 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
1569 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
1571 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1574 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
1577 if (!threadmatch (&echo_nextthread
, nextthread
))
1579 /* FIXME: This is a good reason to drop the packet. */
1580 /* Possably, there is a duplicate response. */
1582 retransmit immediatly - race conditions
1583 retransmit after timeout - yes
1585 wait for packet, then exit
1587 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
1588 return 0; /* I choose simply exiting. */
1590 if (*result_count
<= 0)
1594 warning (_("RMT ERROR : failed to get remote thread list."));
1597 return result
; /* break; */
1599 if (*result_count
> result_limit
)
1602 warning (_("RMT ERROR: threadlist response longer than requested."));
1608 /* This is the interface between remote and threads, remotes upper
1611 /* remote_find_new_threads retrieves the thread list and for each
1612 thread in the list, looks up the thread in GDB's internal list,
1613 ading the thread if it does not already exist. This involves
1614 getting partial thread lists from the remote target so, polling the
1615 quit_flag is required. */
1618 /* About this many threadisds fit in a packet. */
1620 #define MAXTHREADLISTRESULTS 32
1623 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1626 int done
, i
, result_count
;
1630 static threadref nextthread
;
1631 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1636 if (loopcount
++ > looplimit
)
1639 warning (_("Remote fetch threadlist -infinite loop-."));
1642 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1643 &done
, &result_count
, resultthreadlist
))
1648 /* Clear for later iterations. */
1650 /* Setup to resume next batch of thread references, set nextthread. */
1651 if (result_count
>= 1)
1652 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1654 while (result_count
--)
1655 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1662 remote_newthread_step (threadref
*ref
, void *context
)
1666 ptid
= pid_to_ptid (threadref_to_int (ref
));
1668 if (!in_thread_list (ptid
))
1670 return 1; /* continue iterator */
1673 #define CRAZY_MAX_THREADS 1000
1676 remote_current_thread (ptid_t oldpid
)
1678 struct remote_state
*rs
= get_remote_state ();
1679 char *buf
= rs
->buf
;
1682 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1683 if (buf
[0] == 'Q' && buf
[1] == 'C')
1684 /* Use strtoul here, so we'll correctly parse values whose highest
1685 bit is set. The protocol carries them as a simple series of
1686 hex digits; in the absence of a sign, strtol will see such
1687 values as positive numbers out of range for signed 'long', and
1688 return LONG_MAX to indicate an overflow. */
1689 return pid_to_ptid (strtoul (&buf
[2], NULL
, 16));
1694 /* Find new threads for info threads command.
1695 * Original version, using John Metzler's thread protocol.
1699 remote_find_new_threads (void)
1701 remote_threadlist_iterator (remote_newthread_step
, 0,
1703 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1704 inferior_ptid
= remote_current_thread (inferior_ptid
);
1708 * Find all threads for info threads command.
1709 * Uses new thread protocol contributed by Cisco.
1710 * Falls back and attempts to use the older method (above)
1711 * if the target doesn't respond to the new method.
1715 remote_threads_info (void)
1717 struct remote_state
*rs
= get_remote_state ();
1721 if (remote_desc
== 0) /* paranoia */
1722 error (_("Command can only be used when connected to the remote target."));
1724 if (use_threadinfo_query
)
1726 putpkt ("qfThreadInfo");
1728 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1729 if (bufp
[0] != '\0') /* q packet recognized */
1731 while (*bufp
++ == 'm') /* reply contains one or more TID */
1735 /* Use strtoul here, so we'll correctly parse values
1736 whose highest bit is set. The protocol carries
1737 them as a simple series of hex digits; in the
1738 absence of a sign, strtol will see such values as
1739 positive numbers out of range for signed 'long',
1740 and return LONG_MAX to indicate an overflow. */
1741 tid
= strtoul (bufp
, &bufp
, 16);
1742 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1743 add_thread (pid_to_ptid (tid
));
1745 while (*bufp
++ == ','); /* comma-separated list */
1746 putpkt ("qsThreadInfo");
1748 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1754 /* Else fall back to old method based on jmetzler protocol. */
1755 use_threadinfo_query
= 0;
1756 remote_find_new_threads ();
1761 * Collect a descriptive string about the given thread.
1762 * The target may say anything it wants to about the thread
1763 * (typically info about its blocked / runnable state, name, etc.).
1764 * This string will appear in the info threads display.
1766 * Optional: targets are not required to implement this function.
1770 remote_threads_extra_info (struct thread_info
*tp
)
1772 struct remote_state
*rs
= get_remote_state ();
1776 struct gdb_ext_thread_info threadinfo
;
1777 static char display_buf
[100]; /* arbitrary... */
1778 int n
= 0; /* position in display_buf */
1780 if (remote_desc
== 0) /* paranoia */
1781 internal_error (__FILE__
, __LINE__
,
1782 _("remote_threads_extra_info"));
1784 if (use_threadextra_query
)
1786 char *bufp
= rs
->buf
;
1788 xsnprintf (bufp
, get_remote_packet_size (), "qThreadExtraInfo,%x",
1791 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1794 n
= min (strlen (bufp
) / 2, sizeof (display_buf
));
1795 result
= hex2bin (bufp
, (gdb_byte
*) display_buf
, n
);
1796 display_buf
[result
] = '\0';
1801 /* If the above query fails, fall back to the old method. */
1802 use_threadextra_query
= 0;
1803 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1804 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1805 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1806 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1807 if (threadinfo
.active
)
1809 if (*threadinfo
.shortname
)
1810 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
1811 " Name: %s,", threadinfo
.shortname
);
1812 if (*threadinfo
.display
)
1813 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
1814 " State: %s,", threadinfo
.display
);
1815 if (*threadinfo
.more_display
)
1816 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
1817 " Priority: %s", threadinfo
.more_display
);
1821 /* For purely cosmetic reasons, clear up trailing commas. */
1822 if (',' == display_buf
[n
-1])
1823 display_buf
[n
-1] = ' ';
1831 /* Restart the remote side; this is an extended protocol operation. */
1834 extended_remote_restart (void)
1836 struct remote_state
*rs
= get_remote_state ();
1838 /* Send the restart command; for reasons I don't understand the
1839 remote side really expects a number after the "R". */
1840 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
1843 remote_fileio_reset ();
1845 /* Now query for status so this looks just like we restarted
1846 gdbserver from scratch. */
1848 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1851 /* Clean up connection to a remote debugger. */
1854 remote_close (int quitting
)
1857 serial_close (remote_desc
);
1861 /* Query the remote side for the text, data and bss offsets. */
1866 struct remote_state
*rs
= get_remote_state ();
1867 char *buf
= rs
->buf
;
1870 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1871 struct section_offsets
*offs
;
1873 putpkt ("qOffsets");
1874 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1876 if (buf
[0] == '\000')
1877 return; /* Return silently. Stub doesn't support
1881 warning (_("Remote failure reply: %s"), buf
);
1885 /* Pick up each field in turn. This used to be done with scanf, but
1886 scanf will make trouble if CORE_ADDR size doesn't match
1887 conversion directives correctly. The following code will work
1888 with any size of CORE_ADDR. */
1889 text_addr
= data_addr
= bss_addr
= 0;
1893 if (strncmp (ptr
, "Text=", 5) == 0)
1896 /* Don't use strtol, could lose on big values. */
1897 while (*ptr
&& *ptr
!= ';')
1898 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1903 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1906 while (*ptr
&& *ptr
!= ';')
1907 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1912 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1915 while (*ptr
&& *ptr
!= ';')
1916 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1922 error (_("Malformed response to offset query, %s"), buf
);
1924 if (symfile_objfile
== NULL
)
1927 offs
= ((struct section_offsets
*)
1928 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
1929 memcpy (offs
, symfile_objfile
->section_offsets
,
1930 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
1932 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
1934 /* This is a temporary kludge to force data and bss to use the same offsets
1935 because that's what nlmconv does now. The real solution requires changes
1936 to the stub and remote.c that I don't have time to do right now. */
1938 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
1939 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
1941 objfile_relocate (symfile_objfile
, offs
);
1944 /* Stub for catch_errors. */
1947 remote_start_remote_dummy (struct ui_out
*uiout
, void *dummy
)
1949 start_remote (); /* Initialize gdb process mechanisms. */
1950 /* NOTE: Return something >=0. A -ve value is reserved for
1951 catch_exceptions. */
1956 remote_start_remote (struct ui_out
*uiout
, void *dummy
)
1958 immediate_quit
++; /* Allow user to interrupt it. */
1960 /* Ack any packet which the remote side has already sent. */
1961 serial_write (remote_desc
, "+", 1);
1963 /* Let the stub know that we want it to return the thread. */
1966 inferior_ptid
= remote_current_thread (inferior_ptid
);
1968 get_offsets (); /* Get text, data & bss offsets. */
1970 putpkt ("?"); /* Initiate a query from remote machine. */
1973 remote_start_remote_dummy (uiout
, dummy
);
1976 /* Open a connection to a remote debugger.
1977 NAME is the filename used for communication. */
1980 remote_open (char *name
, int from_tty
)
1982 remote_open_1 (name
, from_tty
, &remote_ops
, 0, 0);
1985 /* Just like remote_open, but with asynchronous support. */
1987 remote_async_open (char *name
, int from_tty
)
1989 remote_open_1 (name
, from_tty
, &remote_async_ops
, 0, 1);
1992 /* Open a connection to a remote debugger using the extended
1993 remote gdb protocol. NAME is the filename used for communication. */
1996 extended_remote_open (char *name
, int from_tty
)
1998 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */,
2002 /* Just like extended_remote_open, but with asynchronous support. */
2004 extended_remote_async_open (char *name
, int from_tty
)
2006 remote_open_1 (name
, from_tty
, &extended_async_remote_ops
,
2007 1 /*extended_p */, 1 /* async_p */);
2010 /* Generic code for opening a connection to a remote target. */
2013 init_all_packet_configs (void)
2016 for (i
= 0; i
< PACKET_MAX
; i
++)
2017 update_packet_config (&remote_protocol_packets
[i
]);
2020 /* Symbol look-up. */
2023 remote_check_symbols (struct objfile
*objfile
)
2025 struct remote_state
*rs
= get_remote_state ();
2026 char *msg
, *reply
, *tmp
;
2027 struct minimal_symbol
*sym
;
2030 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
2033 /* Allocate a message buffer. We can't reuse the input buffer in RS,
2034 because we need both at the same time. */
2035 msg
= alloca (get_remote_packet_size ());
2039 /* Invite target to request symbol lookups. */
2041 putpkt ("qSymbol::");
2042 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2043 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
2045 while (strncmp (reply
, "qSymbol:", 8) == 0)
2048 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
2050 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2052 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
2054 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
2055 paddr_nz (SYMBOL_VALUE_ADDRESS (sym
)),
2058 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2062 static struct serial
*
2063 remote_serial_open (char *name
)
2065 static int udp_warning
= 0;
2067 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2068 of in ser-tcp.c, because it is the remote protocol assuming that the
2069 serial connection is reliable and not the serial connection promising
2071 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2074 The remote protocol may be unreliable over UDP.\n\
2075 Some events may be lost, rendering further debugging impossible."));
2079 return serial_open (name
);
2082 /* This type describes each known response to the qSupported
2084 struct protocol_feature
2086 /* The name of this protocol feature. */
2089 /* The default for this protocol feature. */
2090 enum packet_support default_support
;
2092 /* The function to call when this feature is reported, or after
2093 qSupported processing if the feature is not supported.
2094 The first argument points to this structure. The second
2095 argument indicates whether the packet requested support be
2096 enabled, disabled, or probed (or the default, if this function
2097 is being called at the end of processing and this feature was
2098 not reported). The third argument may be NULL; if not NULL, it
2099 is a NUL-terminated string taken from the packet following
2100 this feature's name and an equals sign. */
2101 void (*func
) (const struct protocol_feature
*, enum packet_support
,
2104 /* The corresponding packet for this feature. Only used if
2105 FUNC is remote_supported_packet. */
2111 remote_supported_packet (const struct protocol_feature
*feature
,
2112 enum packet_support support
,
2113 const char *argument
)
2117 warning (_("Remote qSupported response supplied an unexpected value for"
2118 " \"%s\"."), feature
->name
);
2122 if (remote_protocol_packets
[feature
->packet
].support
2123 == PACKET_SUPPORT_UNKNOWN
)
2124 remote_protocol_packets
[feature
->packet
].support
= support
;
2129 remote_packet_size (const struct protocol_feature
*feature
,
2130 enum packet_support support
, const char *value
)
2132 struct remote_state
*rs
= get_remote_state ();
2137 if (support
!= PACKET_ENABLE
)
2140 if (value
== NULL
|| *value
== '\0')
2142 warning (_("Remote target reported \"%s\" without a size."),
2148 packet_size
= strtol (value
, &value_end
, 16);
2149 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
2151 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
2152 feature
->name
, value
);
2156 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
2158 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
2159 packet_size
, MAX_REMOTE_PACKET_SIZE
);
2160 packet_size
= MAX_REMOTE_PACKET_SIZE
;
2163 /* Record the new maximum packet size. */
2164 rs
->explicit_packet_size
= packet_size
;
2167 static struct protocol_feature remote_protocol_features
[] = {
2168 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 }
2172 remote_query_supported (void)
2174 struct remote_state
*rs
= get_remote_state ();
2177 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
2179 /* The packet support flags are handled differently for this packet
2180 than for most others. We treat an error, a disabled packet, and
2181 an empty response identically: any features which must be reported
2182 to be used will be automatically disabled. An empty buffer
2183 accomplishes this, since that is also the representation for a list
2184 containing no features. */
2187 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
2189 putpkt ("qSupported");
2190 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2192 /* If an error occured, warn, but do not return - just reset the
2193 buffer to empty and go on to disable features. */
2194 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
2197 warning (_("Remote failure reply: %s"), rs
->buf
);
2202 memset (seen
, 0, sizeof (seen
));
2207 enum packet_support is_supported
;
2208 char *p
, *end
, *name_end
, *value
;
2210 /* First separate out this item from the rest of the packet. If
2211 there's another item after this, we overwrite the separator
2212 (terminated strings are much easier to work with). */
2214 end
= strchr (p
, ';');
2217 end
= p
+ strlen (p
);
2224 warning (_("empty item in \"qSupported\" response"));
2232 name_end
= strchr (p
, '=');
2235 /* This is a name=value entry. */
2236 is_supported
= PACKET_ENABLE
;
2237 value
= name_end
+ 1;
2246 is_supported
= PACKET_ENABLE
;
2250 is_supported
= PACKET_DISABLE
;
2254 is_supported
= PACKET_SUPPORT_UNKNOWN
;
2258 warning (_("unrecognized item \"%s\" in \"qSupported\" response"), p
);
2264 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
2265 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
2267 const struct protocol_feature
*feature
;
2270 feature
= &remote_protocol_features
[i
];
2271 feature
->func (feature
, is_supported
, value
);
2276 /* If we increased the packet size, make sure to increase the global
2277 buffer size also. We delay this until after parsing the entire
2278 qSupported packet, because this is the same buffer we were
2280 if (rs
->buf_size
< rs
->explicit_packet_size
)
2282 rs
->buf_size
= rs
->explicit_packet_size
;
2283 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
2286 /* Handle the defaults for unmentioned features. */
2287 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
2290 const struct protocol_feature
*feature
;
2292 feature
= &remote_protocol_features
[i
];
2293 feature
->func (feature
, feature
->default_support
, NULL
);
2299 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2300 int extended_p
, int async_p
)
2302 struct remote_state
*rs
= get_remote_state ();
2304 error (_("To open a remote debug connection, you need to specify what\n"
2305 "serial device is attached to the remote system\n"
2306 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
2308 /* See FIXME above. */
2310 wait_forever_enabled_p
= 1;
2312 target_preopen (from_tty
);
2314 unpush_target (target
);
2316 remote_fileio_reset ();
2317 reopen_exec_file ();
2320 remote_desc
= remote_serial_open (name
);
2322 perror_with_name (name
);
2324 if (baud_rate
!= -1)
2326 if (serial_setbaudrate (remote_desc
, baud_rate
))
2328 /* The requested speed could not be set. Error out to
2329 top level after closing remote_desc. Take care to
2330 set remote_desc to NULL to avoid closing remote_desc
2332 serial_close (remote_desc
);
2334 perror_with_name (name
);
2338 serial_raw (remote_desc
);
2340 /* If there is something sitting in the buffer we might take it as a
2341 response to a command, which would be bad. */
2342 serial_flush_input (remote_desc
);
2346 puts_filtered ("Remote debugging using ");
2347 puts_filtered (name
);
2348 puts_filtered ("\n");
2350 push_target (target
); /* Switch to using remote target now. */
2352 /* Reset the target state; these things will be queried either by
2353 remote_query_supported or as they are needed. */
2354 init_all_packet_configs ();
2355 rs
->explicit_packet_size
= 0;
2357 general_thread
= -2;
2358 continue_thread
= -2;
2360 /* Probe for ability to use "ThreadInfo" query, as required. */
2361 use_threadinfo_query
= 1;
2362 use_threadextra_query
= 1;
2364 /* The first packet we send to the target is the optional "supported
2365 packets" request. If the target can answer this, it will tell us
2366 which later probes to skip. */
2367 remote_query_supported ();
2369 /* Without this, some commands which require an active target (such
2370 as kill) won't work. This variable serves (at least) double duty
2371 as both the pid of the target process (if it has such), and as a
2372 flag indicating that a target is active. These functions should
2373 be split out into seperate variables, especially since GDB will
2374 someday have a notion of debugging several processes. */
2376 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2380 /* With this target we start out by owning the terminal. */
2381 remote_async_terminal_ours_p
= 1;
2383 /* FIXME: cagney/1999-09-23: During the initial connection it is
2384 assumed that the target is already ready and able to respond to
2385 requests. Unfortunately remote_start_remote() eventually calls
2386 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2387 around this. Eventually a mechanism that allows
2388 wait_for_inferior() to expect/get timeouts will be
2390 wait_forever_enabled_p
= 0;
2393 /* First delete any symbols previously loaded from shared libraries. */
2394 no_shared_libraries (NULL
, 0);
2396 /* Start the remote connection. If error() or QUIT, discard this
2397 target (we'd otherwise be in an inconsistent state) and then
2398 propogate the error on up the exception chain. This ensures that
2399 the caller doesn't stumble along blindly assuming that the
2400 function succeeded. The CLI doesn't have this problem but other
2401 UI's, such as MI do.
2403 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2404 this function should return an error indication letting the
2405 caller restore the previous state. Unfortunately the command
2406 ``target remote'' is directly wired to this function making that
2407 impossible. On a positive note, the CLI side of this problem has
2408 been fixed - the function set_cmd_context() makes it possible for
2409 all the ``target ....'' commands to share a common callback
2410 function. See cli-dump.c. */
2412 struct gdb_exception ex
2413 = catch_exception (uiout
, remote_start_remote
, NULL
, RETURN_MASK_ALL
);
2418 wait_forever_enabled_p
= 1;
2419 throw_exception (ex
);
2424 wait_forever_enabled_p
= 1;
2428 /* Tell the remote that we are using the extended protocol. */
2430 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2433 post_create_inferior (¤t_target
, from_tty
);
2435 if (exec_bfd
) /* No use without an exec file. */
2436 remote_check_symbols (symfile_objfile
);
2439 /* This takes a program previously attached to and detaches it. After
2440 this is done, GDB can be used to debug some other program. We
2441 better not have left any breakpoints in the target program or it'll
2442 die when it hits one. */
2445 remote_detach (char *args
, int from_tty
)
2447 struct remote_state
*rs
= get_remote_state ();
2450 error (_("Argument given to \"detach\" when remotely debugging."));
2452 /* Tell the remote target to detach. */
2453 strcpy (rs
->buf
, "D");
2454 remote_send (&rs
->buf
, &rs
->buf_size
);
2456 /* Unregister the file descriptor from the event loop. */
2457 if (target_is_async_p ())
2458 serial_async (remote_desc
, NULL
, 0);
2460 target_mourn_inferior ();
2462 puts_filtered ("Ending remote debugging.\n");
2465 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
2468 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
2471 error (_("Argument given to \"detach\" when remotely debugging."));
2473 /* Unregister the file descriptor from the event loop. */
2474 if (target_is_async_p ())
2475 serial_async (remote_desc
, NULL
, 0);
2477 target_mourn_inferior ();
2479 puts_filtered ("Ending remote debugging.\n");
2482 /* Convert hex digit A to a number. */
2487 if (a
>= '0' && a
<= '9')
2489 else if (a
>= 'a' && a
<= 'f')
2490 return a
- 'a' + 10;
2491 else if (a
>= 'A' && a
<= 'F')
2492 return a
- 'A' + 10;
2494 error (_("Reply contains invalid hex digit %d"), a
);
2498 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
2502 for (i
= 0; i
< count
; i
++)
2504 if (hex
[0] == 0 || hex
[1] == 0)
2506 /* Hex string is short, or of uneven length.
2507 Return the count that has been converted so far. */
2510 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2516 /* Convert number NIB to a hex digit. */
2524 return 'a' + nib
- 10;
2528 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
2531 /* May use a length, or a nul-terminated string as input. */
2533 count
= strlen ((char *) bin
);
2535 for (i
= 0; i
< count
; i
++)
2537 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2538 *hex
++ = tohex (*bin
++ & 0xf);
2544 /* Check for the availability of vCont. This function should also check
2548 remote_vcont_probe (struct remote_state
*rs
)
2550 char *buf
= rs
->buf
;
2552 strcpy (buf
, "vCont?");
2554 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2556 /* Make sure that the features we assume are supported. */
2557 if (strncmp (buf
, "vCont", 5) == 0)
2560 int support_s
, support_S
, support_c
, support_C
;
2566 while (p
&& *p
== ';')
2569 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2571 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2573 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2575 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2578 p
= strchr (p
, ';');
2581 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
2582 BUF will make packet_ok disable the packet. */
2583 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
2587 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
2590 /* Resume the remote inferior by using a "vCont" packet. The thread
2591 to be resumed is PTID; STEP and SIGGNAL indicate whether the
2592 resumed thread should be single-stepped and/or signalled. If PTID's
2593 PID is -1, then all threads are resumed; the thread to be stepped and/or
2594 signalled is given in the global INFERIOR_PTID. This function returns
2595 non-zero iff it resumes the inferior.
2597 This function issues a strict subset of all possible vCont commands at the
2601 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2603 struct remote_state
*rs
= get_remote_state ();
2604 int pid
= PIDGET (ptid
);
2605 char *buf
= NULL
, *outbuf
;
2606 struct cleanup
*old_cleanup
;
2608 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
2609 remote_vcont_probe (rs
);
2611 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
2614 /* If we could generate a wider range of packets, we'd have to worry
2615 about overflowing BUF. Should there be a generic
2616 "multi-part-packet" packet? */
2618 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
)
2620 /* MAGIC_NULL_PTID means that we don't have any active threads, so we
2621 don't have any PID numbers the inferior will understand. Make sure
2622 to only send forms that do not specify a PID. */
2623 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2624 outbuf
= xstrprintf ("vCont;S%02x", siggnal
);
2626 outbuf
= xstrprintf ("vCont;s");
2627 else if (siggnal
!= TARGET_SIGNAL_0
)
2628 outbuf
= xstrprintf ("vCont;C%02x", siggnal
);
2630 outbuf
= xstrprintf ("vCont;c");
2634 /* Resume all threads, with preference for INFERIOR_PTID. */
2635 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2636 outbuf
= xstrprintf ("vCont;S%02x:%x;c", siggnal
,
2637 PIDGET (inferior_ptid
));
2639 outbuf
= xstrprintf ("vCont;s:%x;c", PIDGET (inferior_ptid
));
2640 else if (siggnal
!= TARGET_SIGNAL_0
)
2641 outbuf
= xstrprintf ("vCont;C%02x:%x;c", siggnal
,
2642 PIDGET (inferior_ptid
));
2644 outbuf
= xstrprintf ("vCont;c");
2648 /* Scheduler locking; resume only PTID. */
2649 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
2650 outbuf
= xstrprintf ("vCont;S%02x:%x", siggnal
, pid
);
2652 outbuf
= xstrprintf ("vCont;s:%x", pid
);
2653 else if (siggnal
!= TARGET_SIGNAL_0
)
2654 outbuf
= xstrprintf ("vCont;C%02x:%x", siggnal
, pid
);
2656 outbuf
= xstrprintf ("vCont;c:%x", pid
);
2659 gdb_assert (outbuf
&& strlen (outbuf
) < get_remote_packet_size ());
2660 old_cleanup
= make_cleanup (xfree
, outbuf
);
2664 do_cleanups (old_cleanup
);
2669 /* Tell the remote machine to resume. */
2671 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
2673 static int last_sent_step
;
2676 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2678 struct remote_state
*rs
= get_remote_state ();
2679 char *buf
= rs
->buf
;
2680 int pid
= PIDGET (ptid
);
2682 last_sent_signal
= siggnal
;
2683 last_sent_step
= step
;
2685 /* A hook for when we need to do something at the last moment before
2687 if (deprecated_target_resume_hook
)
2688 (*deprecated_target_resume_hook
) ();
2690 /* The vCont packet doesn't need to specify threads via Hc. */
2691 if (remote_vcont_resume (ptid
, step
, siggnal
))
2694 /* All other supported resume packets do use Hc, so call set_thread. */
2696 set_thread (0, 0); /* Run any thread. */
2698 set_thread (pid
, 0); /* Run this thread. */
2700 if (siggnal
!= TARGET_SIGNAL_0
)
2702 buf
[0] = step
? 'S' : 'C';
2703 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
2704 buf
[2] = tohex (((int) siggnal
) & 0xf);
2708 strcpy (buf
, step
? "s" : "c");
2713 /* Same as remote_resume, but with async support. */
2715 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2717 remote_resume (ptid
, step
, siggnal
);
2719 /* We are about to start executing the inferior, let's register it
2720 with the event loop. NOTE: this is the one place where all the
2721 execution commands end up. We could alternatively do this in each
2722 of the execution commands in infcmd.c. */
2723 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2724 into infcmd.c in order to allow inferior function calls to work
2725 NOT asynchronously. */
2726 if (target_can_async_p ())
2727 target_async (inferior_event_handler
, 0);
2728 /* Tell the world that the target is now executing. */
2729 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2730 this? Instead, should the client of target just assume (for
2731 async targets) that the target is going to start executing? Is
2732 this information already found in the continuation block? */
2733 if (target_is_async_p ())
2734 target_executing
= 1;
2738 /* Set up the signal handler for SIGINT, while the target is
2739 executing, ovewriting the 'regular' SIGINT signal handler. */
2741 initialize_sigint_signal_handler (void)
2743 sigint_remote_token
=
2744 create_async_signal_handler (async_remote_interrupt
, NULL
);
2745 signal (SIGINT
, handle_remote_sigint
);
2748 /* Signal handler for SIGINT, while the target is executing. */
2750 handle_remote_sigint (int sig
)
2752 signal (sig
, handle_remote_sigint_twice
);
2753 sigint_remote_twice_token
=
2754 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
2755 mark_async_signal_handler_wrapper (sigint_remote_token
);
2758 /* Signal handler for SIGINT, installed after SIGINT has already been
2759 sent once. It will take effect the second time that the user sends
2762 handle_remote_sigint_twice (int sig
)
2764 signal (sig
, handle_sigint
);
2765 sigint_remote_twice_token
=
2766 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
2767 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
2770 /* Perform the real interruption of the target execution, in response
2773 async_remote_interrupt (gdb_client_data arg
)
2776 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2781 /* Perform interrupt, if the first attempt did not succeed. Just give
2782 up on the target alltogether. */
2784 async_remote_interrupt_twice (gdb_client_data arg
)
2787 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
2788 /* Do something only if the target was not killed by the previous
2790 if (target_executing
)
2793 signal (SIGINT
, handle_remote_sigint
);
2797 /* Reinstall the usual SIGINT handlers, after the target has
2800 cleanup_sigint_signal_handler (void *dummy
)
2802 signal (SIGINT
, handle_sigint
);
2803 if (sigint_remote_twice_token
)
2804 delete_async_signal_handler ((struct async_signal_handler
**)
2805 &sigint_remote_twice_token
);
2806 if (sigint_remote_token
)
2807 delete_async_signal_handler ((struct async_signal_handler
**)
2808 &sigint_remote_token
);
2811 /* Send ^C to target to halt it. Target will respond, and send us a
2813 static void (*ofunc
) (int);
2815 /* The command line interface's stop routine. This function is installed
2816 as a signal handler for SIGINT. The first time a user requests a
2817 stop, we call remote_stop to send a break or ^C. If there is no
2818 response from the target (it didn't stop when the user requested it),
2819 we ask the user if he'd like to detach from the target. */
2821 remote_interrupt (int signo
)
2823 /* If this doesn't work, try more severe steps. */
2824 signal (signo
, remote_interrupt_twice
);
2827 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
2832 /* The user typed ^C twice. */
2835 remote_interrupt_twice (int signo
)
2837 signal (signo
, ofunc
);
2839 signal (signo
, remote_interrupt
);
2842 /* This is the generic stop called via the target vector. When a target
2843 interrupt is requested, either by the command line or the GUI, we
2844 will eventually end up here. */
2848 /* Send a break or a ^C, depending on user preference. */
2850 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
2853 serial_send_break (remote_desc
);
2855 serial_write (remote_desc
, "\003", 1);
2858 /* Ask the user what to do when an interrupt is received. */
2861 interrupt_query (void)
2863 target_terminal_ours ();
2865 if (query ("Interrupted while waiting for the program.\n\
2866 Give up (and stop debugging it)? "))
2868 target_mourn_inferior ();
2869 deprecated_throw_reason (RETURN_QUIT
);
2872 target_terminal_inferior ();
2875 /* Enable/disable target terminal ownership. Most targets can use
2876 terminal groups to control terminal ownership. Remote targets are
2877 different in that explicit transfer of ownership to/from GDB/target
2881 remote_async_terminal_inferior (void)
2883 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2884 sync_execution here. This function should only be called when
2885 GDB is resuming the inferior in the forground. A background
2886 resume (``run&'') should leave GDB in control of the terminal and
2887 consequently should not call this code. */
2888 if (!sync_execution
)
2890 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2891 calls target_terminal_*() idenpotent. The event-loop GDB talking
2892 to an asynchronous target with a synchronous command calls this
2893 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2894 stops trying to transfer the terminal to the target when it
2895 shouldn't this guard can go away. */
2896 if (!remote_async_terminal_ours_p
)
2898 delete_file_handler (input_fd
);
2899 remote_async_terminal_ours_p
= 0;
2900 initialize_sigint_signal_handler ();
2901 /* NOTE: At this point we could also register our selves as the
2902 recipient of all input. Any characters typed could then be
2903 passed on down to the target. */
2907 remote_async_terminal_ours (void)
2909 /* See FIXME in remote_async_terminal_inferior. */
2910 if (!sync_execution
)
2912 /* See FIXME in remote_async_terminal_inferior. */
2913 if (remote_async_terminal_ours_p
)
2915 cleanup_sigint_signal_handler (NULL
);
2916 add_file_handler (input_fd
, stdin_event_handler
, 0);
2917 remote_async_terminal_ours_p
= 1;
2920 /* If nonzero, ignore the next kill. */
2925 remote_console_output (char *msg
)
2929 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
2932 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
2935 fputs_unfiltered (tb
, gdb_stdtarg
);
2937 gdb_flush (gdb_stdtarg
);
2940 /* Wait until the remote machine stops, then return,
2941 storing status in STATUS just as `wait' would.
2942 Returns "pid", which in the case of a multi-threaded
2943 remote OS, is the thread-id. */
2946 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2948 struct remote_state
*rs
= get_remote_state ();
2949 struct remote_arch_state
*rsa
= get_remote_arch_state ();
2950 char *buf
= rs
->buf
;
2951 ULONGEST thread_num
= -1;
2954 status
->kind
= TARGET_WAITKIND_EXITED
;
2955 status
->value
.integer
= 0;
2961 ofunc
= signal (SIGINT
, remote_interrupt
);
2962 getpkt (&rs
->buf
, &rs
->buf_size
, 1);
2963 signal (SIGINT
, ofunc
);
2965 /* This is a hook for when we need to do something (perhaps the
2966 collection of trace data) every time the target stops. */
2967 if (deprecated_target_wait_loop_hook
)
2968 (*deprecated_target_wait_loop_hook
) ();
2970 remote_stopped_by_watchpoint_p
= 0;
2974 case 'E': /* Error of some sort. */
2975 warning (_("Remote failure reply: %s"), buf
);
2977 case 'F': /* File-I/O request. */
2978 remote_fileio_request (buf
);
2980 case 'T': /* Status with PC, SP, FP, ... */
2982 gdb_byte regs
[MAX_REGISTER_SIZE
];
2984 /* Expedited reply, containing Signal, {regno, reg} repeat. */
2985 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2987 n... = register number
2988 r... = register contents
2990 p
= &buf
[3]; /* after Txx */
2999 /* If the packet contains a register number save it in
3000 pnum and set p1 to point to the character following
3001 it. Otherwise p1 points to p. */
3003 /* If this packet is an awatch packet, don't parse the
3004 'a' as a register number. */
3006 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
3008 /* Read the ``P'' register number. */
3009 pnum
= strtol (p
, &p_temp
, 16);
3015 if (p1
== p
) /* No register number present here. */
3017 p1
= strchr (p
, ':');
3019 error (_("Malformed packet(a) (missing colon): %s\n\
3022 if (strncmp (p
, "thread", p1
- p
) == 0)
3024 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3025 record_currthread (thread_num
);
3028 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3029 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3030 || (strncmp (p
, "awatch", p1
- p
) == 0))
3032 remote_stopped_by_watchpoint_p
= 1;
3033 p
= unpack_varlen_hex (++p1
, &addr
);
3034 remote_watch_data_address
= (CORE_ADDR
)addr
;
3038 /* Silently skip unknown optional info. */
3039 p_temp
= strchr (p1
+ 1, ';');
3046 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
3050 error (_("Malformed packet(b) (missing colon): %s\n\
3055 error (_("Remote sent bad register number %s: %s\n\
3057 phex_nz (pnum
, 0), p
, buf
);
3059 fieldsize
= hex2bin (p
, regs
,
3060 register_size (current_gdbarch
,
3063 if (fieldsize
< register_size (current_gdbarch
,
3065 warning (_("Remote reply is too short: %s"), buf
);
3066 regcache_raw_supply (current_regcache
,
3071 error (_("Remote register badly formatted: %s\nhere: %s"),
3076 case 'S': /* Old style status, just signal only. */
3077 status
->kind
= TARGET_WAITKIND_STOPPED
;
3078 status
->value
.sig
= (enum target_signal
)
3079 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3083 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3084 record_currthread (thread_num
);
3087 case 'W': /* Target exited. */
3089 /* The remote process exited. */
3090 status
->kind
= TARGET_WAITKIND_EXITED
;
3091 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3095 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3096 status
->value
.sig
= (enum target_signal
)
3097 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3101 case 'O': /* Console output. */
3102 remote_console_output (buf
+ 1);
3105 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3107 /* Zero length reply means that we tried 'S' or 'C' and
3108 the remote system doesn't support it. */
3109 target_terminal_ours_for_output ();
3111 ("Can't send signals to this remote system. %s not sent.\n",
3112 target_signal_to_name (last_sent_signal
));
3113 last_sent_signal
= TARGET_SIGNAL_0
;
3114 target_terminal_inferior ();
3116 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3117 putpkt ((char *) buf
);
3120 /* else fallthrough */
3122 warning (_("Invalid remote reply: %s"), buf
);
3127 if (thread_num
!= -1)
3129 return pid_to_ptid (thread_num
);
3131 return inferior_ptid
;
3134 /* Async version of remote_wait. */
3136 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3138 struct remote_state
*rs
= get_remote_state ();
3139 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3140 char *buf
= rs
->buf
;
3141 ULONGEST thread_num
= -1;
3144 status
->kind
= TARGET_WAITKIND_EXITED
;
3145 status
->value
.integer
= 0;
3147 remote_stopped_by_watchpoint_p
= 0;
3153 if (!target_is_async_p ())
3154 ofunc
= signal (SIGINT
, remote_interrupt
);
3155 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3156 _never_ wait for ever -> test on target_is_async_p().
3157 However, before we do that we need to ensure that the caller
3158 knows how to take the target into/out of async mode. */
3159 getpkt (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
3160 if (!target_is_async_p ())
3161 signal (SIGINT
, ofunc
);
3163 /* This is a hook for when we need to do something (perhaps the
3164 collection of trace data) every time the target stops. */
3165 if (deprecated_target_wait_loop_hook
)
3166 (*deprecated_target_wait_loop_hook
) ();
3170 case 'E': /* Error of some sort. */
3171 warning (_("Remote failure reply: %s"), buf
);
3173 case 'F': /* File-I/O request. */
3174 remote_fileio_request (buf
);
3176 case 'T': /* Status with PC, SP, FP, ... */
3178 gdb_byte regs
[MAX_REGISTER_SIZE
];
3180 /* Expedited reply, containing Signal, {regno, reg} repeat. */
3181 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3183 n... = register number
3184 r... = register contents
3186 p
= &buf
[3]; /* after Txx */
3195 /* If the packet contains a register number, save it
3196 in pnum and set p1 to point to the character
3197 following it. Otherwise p1 points to p. */
3199 /* If this packet is an awatch packet, don't parse the 'a'
3200 as a register number. */
3202 if (!strncmp (p
, "awatch", strlen ("awatch")) != 0)
3204 /* Read the register number. */
3205 pnum
= strtol (p
, &p_temp
, 16);
3211 if (p1
== p
) /* No register number present here. */
3213 p1
= strchr (p
, ':');
3215 error (_("Malformed packet(a) (missing colon): %s\n\
3218 if (strncmp (p
, "thread", p1
- p
) == 0)
3220 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3221 record_currthread (thread_num
);
3224 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3225 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3226 || (strncmp (p
, "awatch", p1
- p
) == 0))
3228 remote_stopped_by_watchpoint_p
= 1;
3229 p
= unpack_varlen_hex (++p1
, &addr
);
3230 remote_watch_data_address
= (CORE_ADDR
)addr
;
3234 /* Silently skip unknown optional info. */
3235 p_temp
= strchr (p1
+ 1, ';');
3243 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
3246 error (_("Malformed packet(b) (missing colon): %s\n\
3251 error (_("Remote sent bad register number %ld: %s\n\
3255 fieldsize
= hex2bin (p
, regs
,
3256 register_size (current_gdbarch
,
3259 if (fieldsize
< register_size (current_gdbarch
,
3261 warning (_("Remote reply is too short: %s"), buf
);
3262 regcache_raw_supply (current_regcache
, reg
->regnum
, regs
);
3266 error (_("Remote register badly formatted: %s\nhere: %s"),
3271 case 'S': /* Old style status, just signal only. */
3272 status
->kind
= TARGET_WAITKIND_STOPPED
;
3273 status
->value
.sig
= (enum target_signal
)
3274 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3278 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3279 record_currthread (thread_num
);
3282 case 'W': /* Target exited. */
3284 /* The remote process exited. */
3285 status
->kind
= TARGET_WAITKIND_EXITED
;
3286 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3290 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3291 status
->value
.sig
= (enum target_signal
)
3292 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3296 case 'O': /* Console output. */
3297 remote_console_output (buf
+ 1);
3298 /* Return immediately to the event loop. The event loop will
3299 still be waiting on the inferior afterwards. */
3300 status
->kind
= TARGET_WAITKIND_IGNORE
;
3303 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3305 /* Zero length reply means that we tried 'S' or 'C' and
3306 the remote system doesn't support it. */
3307 target_terminal_ours_for_output ();
3309 ("Can't send signals to this remote system. %s not sent.\n",
3310 target_signal_to_name (last_sent_signal
));
3311 last_sent_signal
= TARGET_SIGNAL_0
;
3312 target_terminal_inferior ();
3314 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3315 putpkt ((char *) buf
);
3318 /* else fallthrough */
3320 warning (_("Invalid remote reply: %s"), buf
);
3325 if (thread_num
!= -1)
3327 return pid_to_ptid (thread_num
);
3329 return inferior_ptid
;
3332 /* Number of bytes of registers this stub implements. */
3334 static int register_bytes_found
;
3336 /* Read the remote registers into the block REGS. */
3337 /* Currently we just read all the registers, so we don't use regnum. */
3340 fetch_register_using_p (int regnum
)
3342 struct remote_state
*rs
= get_remote_state ();
3343 char *buf
= rs
->buf
, *p
;
3344 char regp
[MAX_REGISTER_SIZE
];
3349 p
+= hexnumstr (p
, regnum
);
3351 remote_send (&rs
->buf
, &rs
->buf_size
);
3353 /* If the stub didn't recognize the packet, or if we got an error,
3355 if (buf
[0] == '\0' || buf
[0] == 'E')
3358 /* If this register is unfetchable, tell the regcache. */
3361 regcache_raw_supply (current_regcache
, regnum
, NULL
);
3362 set_register_cached (regnum
, -1);
3366 /* Otherwise, parse and supply the value. */
3373 error (_("fetch_register_using_p: early buf termination"));
3377 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3380 regcache_raw_supply (current_regcache
, regnum
, regp
);
3385 remote_fetch_registers (int regnum
)
3387 struct remote_state
*rs
= get_remote_state ();
3388 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3389 char *buf
= rs
->buf
;
3392 char *regs
= alloca (rsa
->sizeof_g_packet
);
3394 set_thread (PIDGET (inferior_ptid
), 1);
3398 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
3399 gdb_assert (reg
!= NULL
);
3400 if (!reg
->in_g_packet
)
3401 internal_error (__FILE__
, __LINE__
,
3402 _("Attempt to fetch a non G-packet register when this "
3403 "remote.c does not support the p-packet."));
3405 switch (remote_protocol_packets
[PACKET_p
].support
)
3407 case PACKET_DISABLE
:
3410 if (fetch_register_using_p (regnum
))
3413 error (_("Protocol error: p packet not recognized by stub"));
3414 case PACKET_SUPPORT_UNKNOWN
:
3415 if (fetch_register_using_p (regnum
))
3417 /* The stub recognized the 'p' packet. Remember this. */
3418 remote_protocol_packets
[PACKET_p
].support
= PACKET_ENABLE
;
3423 /* The stub does not support the 'P' packet. Use 'G'
3424 instead, and don't try using 'P' in the future (it
3425 will just waste our time). */
3426 remote_protocol_packets
[PACKET_p
].support
= PACKET_DISABLE
;
3432 remote_send (&rs
->buf
, &rs
->buf_size
);
3434 /* Save the size of the packet sent to us by the target. Its used
3435 as a heuristic when determining the max size of packets that the
3436 target can safely receive. */
3437 if ((rsa
->actual_register_packet_size
) == 0)
3438 (rsa
->actual_register_packet_size
) = strlen (buf
);
3440 /* Unimplemented registers read as all bits zero. */
3441 memset (regs
, 0, rsa
->sizeof_g_packet
);
3443 /* We can get out of synch in various cases. If the first character
3444 in the buffer is not a hex character, assume that has happened
3445 and try to fetch another packet to read. */
3446 while ((buf
[0] < '0' || buf
[0] > '9')
3447 && (buf
[0] < 'A' || buf
[0] > 'F')
3448 && (buf
[0] < 'a' || buf
[0] > 'f')
3449 && buf
[0] != 'x') /* New: unavailable register value. */
3452 fprintf_unfiltered (gdb_stdlog
,
3453 "Bad register packet; fetching a new packet\n");
3454 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3457 /* Reply describes registers byte by byte, each byte encoded as two
3458 hex characters. Suck them all up, then supply them to the
3459 register cacheing/storage mechanism. */
3462 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
3468 warning (_("Remote reply is of odd length: %s"), buf
);
3469 /* Don't change register_bytes_found in this case, and don't
3470 print a second warning. */
3473 if (p
[0] == 'x' && p
[1] == 'x')
3474 regs
[i
] = 0; /* 'x' */
3476 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3480 if (i
!= register_bytes_found
)
3482 register_bytes_found
= i
;
3483 if (REGISTER_BYTES_OK_P ()
3484 && !REGISTER_BYTES_OK (i
))
3485 warning (_("Remote reply is too short: %s"), buf
);
3491 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3493 struct packet_reg
*r
= &rsa
->regs
[i
];
3496 if (r
->offset
* 2 >= strlen (buf
))
3497 /* A short packet that didn't include the register's
3498 value, this implies that the register is zero (and
3499 not that the register is unavailable). Supply that
3501 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3502 else if (buf
[r
->offset
* 2] == 'x')
3504 gdb_assert (r
->offset
* 2 < strlen (buf
));
3505 /* The register isn't available, mark it as such (at
3506 the same time setting the value to zero). */
3507 regcache_raw_supply (current_regcache
, r
->regnum
, NULL
);
3508 set_register_cached (i
, -1);
3511 regcache_raw_supply (current_regcache
, r
->regnum
,
3518 /* Prepare to store registers. Since we may send them all (using a
3519 'G' request), we have to read out the ones we don't want to change
3523 remote_prepare_to_store (void)
3525 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3527 gdb_byte buf
[MAX_REGISTER_SIZE
];
3529 /* Make sure the entire registers array is valid. */
3530 switch (remote_protocol_packets
[PACKET_P
].support
)
3532 case PACKET_DISABLE
:
3533 case PACKET_SUPPORT_UNKNOWN
:
3534 /* Make sure all the necessary registers are cached. */
3535 for (i
= 0; i
< NUM_REGS
; i
++)
3536 if (rsa
->regs
[i
].in_g_packet
)
3537 regcache_raw_read (current_regcache
, rsa
->regs
[i
].regnum
, buf
);
3544 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
3545 packet was not recognized. */
3548 store_register_using_P (int regnum
)
3550 struct remote_state
*rs
= get_remote_state ();
3551 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3552 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
3553 /* Try storing a single register. */
3554 char *buf
= rs
->buf
;
3555 gdb_byte regp
[MAX_REGISTER_SIZE
];
3558 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
3559 p
= buf
+ strlen (buf
);
3560 regcache_raw_collect (current_regcache
, reg
->regnum
, regp
);
3561 bin2hex (regp
, p
, register_size (current_gdbarch
, reg
->regnum
));
3562 remote_send (&rs
->buf
, &rs
->buf_size
);
3564 return buf
[0] != '\0';
3568 /* Store register REGNUM, or all registers if REGNUM == -1, from the
3569 contents of the register cache buffer. FIXME: ignores errors. */
3572 remote_store_registers (int regnum
)
3574 struct remote_state
*rs
= get_remote_state ();
3575 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3579 set_thread (PIDGET (inferior_ptid
), 1);
3583 switch (remote_protocol_packets
[PACKET_P
].support
)
3585 case PACKET_DISABLE
:
3588 if (store_register_using_P (regnum
))
3591 error (_("Protocol error: P packet not recognized by stub"));
3592 case PACKET_SUPPORT_UNKNOWN
:
3593 if (store_register_using_P (regnum
))
3595 /* The stub recognized the 'P' packet. Remember this. */
3596 remote_protocol_packets
[PACKET_P
].support
= PACKET_ENABLE
;
3601 /* The stub does not support the 'P' packet. Use 'G'
3602 instead, and don't try using 'P' in the future (it
3603 will just waste our time). */
3604 remote_protocol_packets
[PACKET_P
].support
= PACKET_DISABLE
;
3610 /* Extract all the registers in the regcache copying them into a
3614 regs
= alloca (rsa
->sizeof_g_packet
);
3615 memset (regs
, 0, rsa
->sizeof_g_packet
);
3616 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
3618 struct packet_reg
*r
= &rsa
->regs
[i
];
3620 regcache_raw_collect (current_regcache
, r
->regnum
, regs
+ r
->offset
);
3624 /* Command describes registers byte by byte,
3625 each byte encoded as two hex characters. */
3628 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3629 bin2hex (regs
, p
, register_bytes_found
);
3630 remote_send (&rs
->buf
, &rs
->buf_size
);
3634 /* Return the number of hex digits in num. */
3637 hexnumlen (ULONGEST num
)
3641 for (i
= 0; num
!= 0; i
++)
3647 /* Set BUF to the minimum number of hex digits representing NUM. */
3650 hexnumstr (char *buf
, ULONGEST num
)
3652 int len
= hexnumlen (num
);
3653 return hexnumnstr (buf
, num
, len
);
3657 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3660 hexnumnstr (char *buf
, ULONGEST num
, int width
)
3666 for (i
= width
- 1; i
>= 0; i
--)
3668 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
3675 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3678 remote_address_masked (CORE_ADDR addr
)
3680 if (remote_address_size
> 0
3681 && remote_address_size
< (sizeof (ULONGEST
) * 8))
3683 /* Only create a mask when that mask can safely be constructed
3684 in a ULONGEST variable. */
3686 mask
= (mask
<< remote_address_size
) - 1;
3692 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
3693 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
3694 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
3695 (which may be more than *OUT_LEN due to escape characters). The
3696 total number of bytes in the output buffer will be at most
3700 remote_escape_output (const gdb_byte
*buffer
, int len
,
3701 gdb_byte
*out_buf
, int *out_len
,
3704 int input_index
, output_index
;
3707 for (input_index
= 0; input_index
< len
; input_index
++)
3709 gdb_byte b
= buffer
[input_index
];
3711 if (b
== '$' || b
== '#' || b
== '}')
3713 /* These must be escaped. */
3714 if (output_index
+ 2 > out_maxlen
)
3716 out_buf
[output_index
++] = '}';
3717 out_buf
[output_index
++] = b
^ 0x20;
3721 if (output_index
+ 1 > out_maxlen
)
3723 out_buf
[output_index
++] = b
;
3727 *out_len
= input_index
;
3728 return output_index
;
3731 /* Determine whether the remote target supports binary downloading.
3732 This is accomplished by sending a no-op memory write of zero length
3733 to the target at the specified address. It does not suffice to send
3734 the whole packet, since many stubs strip the eighth bit and
3735 subsequently compute a wrong checksum, which causes real havoc with
3738 NOTE: This can still lose if the serial line is not eight-bit
3739 clean. In cases like this, the user should clear "remote
3743 check_binary_download (CORE_ADDR addr
)
3745 struct remote_state
*rs
= get_remote_state ();
3747 switch (remote_protocol_packets
[PACKET_X
].support
)
3749 case PACKET_DISABLE
:
3753 case PACKET_SUPPORT_UNKNOWN
:
3755 char *buf
= rs
->buf
;
3760 p
+= hexnumstr (p
, (ULONGEST
) addr
);
3762 p
+= hexnumstr (p
, (ULONGEST
) 0);
3766 putpkt_binary (buf
, (int) (p
- buf
));
3767 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3772 fprintf_unfiltered (gdb_stdlog
,
3773 "binary downloading NOT suppported by target\n");
3774 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
3779 fprintf_unfiltered (gdb_stdlog
,
3780 "binary downloading suppported by target\n");
3781 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
3788 /* Write memory data directly to the remote machine.
3789 This does not inform the data cache; the data cache uses this.
3790 MEMADDR is the address in the remote memory space.
3791 MYADDR is the address of the buffer in our space.
3792 LEN is the number of bytes.
3794 Returns number of bytes transferred, or 0 (setting errno) for
3795 error. Only transfer a single packet. */
3798 remote_write_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
3800 struct remote_state
*rs
= get_remote_state ();
3808 char *payload_start
;
3810 /* Verify that the target can support a binary download. */
3811 check_binary_download (memaddr
);
3813 payload_size
= get_memory_write_packet_size ();
3815 /* The packet buffer will be large enough for the payload;
3816 get_memory_packet_size ensures this. */
3819 /* Compute the size of the actual payload by subtracting out the
3820 packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
3822 payload_size
-= strlen ("$M,:#NN");
3823 payload_size
-= hexnumlen (memaddr
);
3825 /* Construct the packet header: "[MX]<memaddr>,<len>:". */
3827 /* Append "[XM]". Compute a best guess of the number of bytes
3828 actually transfered. */
3830 switch (remote_protocol_packets
[PACKET_X
].support
)
3834 /* Best guess at number of bytes that will fit. */
3835 todo
= min (len
, payload_size
);
3836 payload_size
-= hexnumlen (todo
);
3837 todo
= min (todo
, payload_size
);
3839 case PACKET_DISABLE
:
3841 /* Num bytes that will fit. */
3842 todo
= min (len
, payload_size
/ 2);
3843 payload_size
-= hexnumlen (todo
);
3844 todo
= min (todo
, payload_size
/ 2);
3846 case PACKET_SUPPORT_UNKNOWN
:
3847 internal_error (__FILE__
, __LINE__
,
3848 _("remote_write_bytes: bad internal state"));
3850 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3853 internal_error (__FILE__
, __LINE__
,
3854 _("minumum packet size too small to write data"));
3856 /* Append "<memaddr>". */
3857 memaddr
= remote_address_masked (memaddr
);
3858 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3863 /* Append <len>. Retain the location/size of <len>. It may need to
3864 be adjusted once the packet body has been created. */
3866 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
3873 /* Append the packet body. */
3875 switch (remote_protocol_packets
[PACKET_X
].support
)
3878 /* Binary mode. Send target system values byte by byte, in
3879 increasing byte addresses. Only escape certain critical
3881 p
+= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
, payload_size
);
3882 if (nr_bytes
< todo
)
3884 /* Escape chars have filled up the buffer prematurely,
3885 and we have actually sent fewer bytes than planned.
3886 Fix-up the length field of the packet. Use the same
3887 number of characters as before. */
3888 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
3889 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
3892 case PACKET_DISABLE
:
3893 /* Normal mode: Send target system values byte by byte, in
3894 increasing byte addresses. Each byte is encoded as a two hex
3896 nr_bytes
= bin2hex (myaddr
, p
, todo
);
3899 case PACKET_SUPPORT_UNKNOWN
:
3900 internal_error (__FILE__
, __LINE__
,
3901 _("remote_write_bytes: bad internal state"));
3903 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3906 putpkt_binary (buf
, (int) (p
- buf
));
3907 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3911 /* There is no correspondance between what the remote protocol
3912 uses for errors and errno codes. We would like a cleaner way
3913 of representing errors (big enough to include errno codes,
3914 bfd_error codes, and others). But for now just return EIO. */
3919 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
3920 fewer bytes than we'd planned. */
3924 /* Read memory data directly from the remote machine.
3925 This does not use the data cache; the data cache uses this.
3926 MEMADDR is the address in the remote memory space.
3927 MYADDR is the address of the buffer in our space.
3928 LEN is the number of bytes.
3930 Returns number of bytes transferred, or 0 for error. */
3932 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3933 remote targets) shouldn't attempt to read the entire buffer.
3934 Instead it should read a single packet worth of data and then
3935 return the byte size of that packet to the caller. The caller (its
3936 caller and its callers caller ;-) already contains code for
3937 handling partial reads. */
3940 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
3942 struct remote_state
*rs
= get_remote_state ();
3944 int max_buf_size
; /* Max size of packet output buffer. */
3947 max_buf_size
= get_memory_read_packet_size ();
3948 /* The packet buffer will be large enough for the payload;
3949 get_memory_packet_size ensures this. */
3959 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
3961 /* construct "m"<memaddr>","<len>" */
3962 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3963 memaddr
= remote_address_masked (memaddr
);
3966 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
3968 p
+= hexnumstr (p
, (ULONGEST
) todo
);
3972 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3975 && isxdigit (buf
[1]) && isxdigit (buf
[2])
3978 /* There is no correspondance between what the remote
3979 protocol uses for errors and errno codes. We would like
3980 a cleaner way of representing errors (big enough to
3981 include errno codes, bfd_error codes, and others). But
3982 for now just return EIO. */
3987 /* Reply describes memory byte by byte,
3988 each byte encoded as two hex characters. */
3991 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
3993 /* Reply is short. This means that we were able to read
3994 only part of what we wanted to. */
3995 return i
+ (origlen
- len
);
4004 /* Read or write LEN bytes from inferior memory at MEMADDR,
4005 transferring to or from debugger address BUFFER. Write to inferior
4006 if SHOULD_WRITE is nonzero. Returns length of data written or
4007 read; 0 for error. TARGET is unused. */
4010 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
4011 int should_write
, struct mem_attrib
*attrib
,
4012 struct target_ops
*target
)
4014 CORE_ADDR targ_addr
;
4018 /* Should this be the selected frame? */
4019 gdbarch_remote_translate_xfer_address (current_gdbarch
,
4022 &targ_addr
, &targ_len
);
4027 res
= remote_write_bytes (targ_addr
, buffer
, targ_len
);
4029 res
= remote_read_bytes (targ_addr
, buffer
, targ_len
);
4035 remote_files_info (struct target_ops
*ignore
)
4037 puts_filtered ("Debugging a target over a serial line.\n");
4040 /* Stuff for dealing with the packets which are part of this protocol.
4041 See comment at top of file for details. */
4043 /* Read a single character from the remote end, masking it down to 7
4047 readchar (int timeout
)
4051 ch
= serial_readchar (remote_desc
, timeout
);
4056 switch ((enum serial_rc
) ch
)
4059 target_mourn_inferior ();
4060 error (_("Remote connection closed"));
4063 perror_with_name (_("Remote communication error"));
4065 case SERIAL_TIMEOUT
:
4071 /* Send the command in *BUF to the remote machine, and read the reply
4072 into *BUF. Report an error if we get an error reply. Resize
4073 *BUF using xrealloc if necessary to hold the result, and update
4077 remote_send (char **buf
,
4081 getpkt (buf
, sizeof_buf
, 0);
4083 if ((*buf
)[0] == 'E')
4084 error (_("Remote failure reply: %s"), *buf
);
4087 /* Display a null-terminated packet on stdout, for debugging, using C
4091 print_packet (char *buf
)
4093 puts_filtered ("\"");
4094 fputstr_filtered (buf
, '"', gdb_stdout
);
4095 puts_filtered ("\"");
4101 return putpkt_binary (buf
, strlen (buf
));
4104 /* Send a packet to the remote machine, with error checking. The data
4105 of the packet is in BUF. The string in BUF can be at most
4106 get_remote_packet_size () - 5 to account for the $, # and checksum,
4107 and for a possible /0 if we are debugging (remote_debug) and want
4108 to print the sent packet as a string. */
4111 putpkt_binary (char *buf
, int cnt
)
4114 unsigned char csum
= 0;
4115 char *buf2
= alloca (cnt
+ 6);
4121 /* Copy the packet into buffer BUF2, encapsulating it
4122 and giving it a checksum. */
4127 for (i
= 0; i
< cnt
; i
++)
4133 *p
++ = tohex ((csum
>> 4) & 0xf);
4134 *p
++ = tohex (csum
& 0xf);
4136 /* Send it over and over until we get a positive ack. */
4140 int started_error_output
= 0;
4145 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4146 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4147 fprintf_unfiltered (gdb_stdlog
, "...");
4148 gdb_flush (gdb_stdlog
);
4150 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4151 perror_with_name (_("putpkt: write failed"));
4153 /* Read until either a timeout occurs (-2) or '+' is read. */
4156 ch
= readchar (remote_timeout
);
4164 case SERIAL_TIMEOUT
:
4166 if (started_error_output
)
4168 putchar_unfiltered ('\n');
4169 started_error_output
= 0;
4178 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4182 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4183 case SERIAL_TIMEOUT
:
4187 break; /* Retransmit buffer. */
4191 fprintf_unfiltered (gdb_stdlog
,
4192 "Packet instead of Ack, ignoring it\n");
4193 /* It's probably an old response sent because an ACK
4194 was lost. Gobble up the packet and ack it so it
4195 doesn't get retransmitted when we resend this
4198 serial_write (remote_desc
, "+", 1);
4199 continue; /* Now, go look for +. */
4204 if (!started_error_output
)
4206 started_error_output
= 1;
4207 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4209 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4213 break; /* Here to retransmit. */
4217 /* This is wrong. If doing a long backtrace, the user should be
4218 able to get out next time we call QUIT, without anything as
4219 violent as interrupt_query. If we want to provide a way out of
4220 here without getting to the next QUIT, it should be based on
4221 hitting ^C twice as in remote_wait. */
4231 /* Come here after finding the start of a frame when we expected an
4232 ack. Do our best to discard the rest of this packet. */
4241 c
= readchar (remote_timeout
);
4244 case SERIAL_TIMEOUT
:
4245 /* Nothing we can do. */
4248 /* Discard the two bytes of checksum and stop. */
4249 c
= readchar (remote_timeout
);
4251 c
= readchar (remote_timeout
);
4254 case '*': /* Run length encoding. */
4255 /* Discard the repeat count. */
4256 c
= readchar (remote_timeout
);
4261 /* A regular character. */
4267 /* Come here after finding the start of the frame. Collect the rest
4268 into *BUF, verifying the checksum, length, and handling run-length
4269 compression. NUL terminate the buffer. If there is not enough room,
4270 expand *BUF using xrealloc.
4272 Returns -1 on error, number of characters in buffer (ignoring the
4273 trailing NULL) on success. (could be extended to return one of the
4274 SERIAL status indications). */
4277 read_frame (char **buf_p
,
4290 c
= readchar (remote_timeout
);
4293 case SERIAL_TIMEOUT
:
4295 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
4299 fputs_filtered ("Saw new packet start in middle of old one\n",
4301 return -1; /* Start a new packet, count retries. */
4304 unsigned char pktcsum
;
4310 check_0
= readchar (remote_timeout
);
4312 check_1
= readchar (remote_timeout
);
4314 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
4317 fputs_filtered ("Timeout in checksum, retrying\n",
4321 else if (check_0
< 0 || check_1
< 0)
4324 fputs_filtered ("Communication error in checksum\n",
4329 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
4330 if (csum
== pktcsum
)
4335 fprintf_filtered (gdb_stdlog
,
4336 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
4338 fputs_filtered (buf
, gdb_stdlog
);
4339 fputs_filtered ("\n", gdb_stdlog
);
4341 /* Number of characters in buffer ignoring trailing
4345 case '*': /* Run length encoding. */
4350 c
= readchar (remote_timeout
);
4352 repeat
= c
- ' ' + 3; /* Compute repeat count. */
4354 /* The character before ``*'' is repeated. */
4356 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
4358 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
4360 /* Make some more room in the buffer. */
4361 *sizeof_buf
+= repeat
;
4362 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
4366 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
4372 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
4376 if (bc
>= *sizeof_buf
- 1)
4378 /* Make some more room in the buffer. */
4380 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
4391 /* Read a packet from the remote machine, with error checking, and
4392 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
4393 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
4394 rather than timing out; this is used (in synchronous mode) to wait
4395 for a target that is is executing user code to stop. */
4396 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4397 don't have to change all the calls to getpkt to deal with the
4398 return value, because at the moment I don't know what the right
4399 thing to do it for those. */
4407 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
4411 /* Read a packet from the remote machine, with error checking, and
4412 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
4413 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
4414 rather than timing out; this is used (in synchronous mode) to wait
4415 for a target that is is executing user code to stop. If FOREVER ==
4416 0, this function is allowed to time out gracefully and return an
4417 indication of this to the caller. */
4419 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
4426 strcpy (*buf
, "timeout");
4430 timeout
= watchdog
> 0 ? watchdog
: -1;
4434 timeout
= remote_timeout
;
4438 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
4440 /* This can loop forever if the remote side sends us characters
4441 continuously, but if it pauses, we'll get a zero from
4442 readchar because of timeout. Then we'll count that as a
4445 /* Note that we will only wait forever prior to the start of a
4446 packet. After that, we expect characters to arrive at a
4447 brisk pace. They should show up within remote_timeout
4452 c
= readchar (timeout
);
4454 if (c
== SERIAL_TIMEOUT
)
4456 if (forever
) /* Watchdog went off? Kill the target. */
4459 target_mourn_inferior ();
4460 error (_("Watchdog has expired. Target detached."));
4463 fputs_filtered ("Timed out.\n", gdb_stdlog
);
4469 /* We've found the start of a packet, now collect the data. */
4471 val
= read_frame (buf
, sizeof_buf
);
4477 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
4478 fputstr_unfiltered (*buf
, 0, gdb_stdlog
);
4479 fprintf_unfiltered (gdb_stdlog
, "\n");
4481 serial_write (remote_desc
, "+", 1);
4485 /* Try the whole thing again. */
4487 serial_write (remote_desc
, "-", 1);
4490 /* We have tried hard enough, and just can't receive the packet.
4493 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
4494 serial_write (remote_desc
, "+", 1);
4501 /* For some mysterious reason, wait_for_inferior calls kill instead of
4502 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4506 target_mourn_inferior ();
4510 /* Use catch_errors so the user can quit from gdb even when we aren't on
4511 speaking terms with the remote system. */
4512 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4514 /* Don't wait for it to die. I'm not really sure it matters whether
4515 we do or not. For the existing stubs, kill is a noop. */
4516 target_mourn_inferior ();
4519 /* Async version of remote_kill. */
4521 remote_async_kill (void)
4523 /* Unregister the file descriptor from the event loop. */
4524 if (target_is_async_p ())
4525 serial_async (remote_desc
, NULL
, 0);
4527 /* For some mysterious reason, wait_for_inferior calls kill instead of
4528 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4532 target_mourn_inferior ();
4536 /* Use catch_errors so the user can quit from gdb even when we
4537 aren't on speaking terms with the remote system. */
4538 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
4540 /* Don't wait for it to die. I'm not really sure it matters whether
4541 we do or not. For the existing stubs, kill is a noop. */
4542 target_mourn_inferior ();
4548 remote_mourn_1 (&remote_ops
);
4552 remote_async_mourn (void)
4554 remote_mourn_1 (&remote_async_ops
);
4558 extended_remote_mourn (void)
4560 /* We do _not_ want to mourn the target like this; this will
4561 remove the extended remote target from the target stack,
4562 and the next time the user says "run" it'll fail.
4564 FIXME: What is the right thing to do here? */
4566 remote_mourn_1 (&extended_remote_ops
);
4570 /* Worker function for remote_mourn. */
4572 remote_mourn_1 (struct target_ops
*target
)
4574 unpush_target (target
);
4575 generic_mourn_inferior ();
4578 /* In the extended protocol we want to be able to do things like
4579 "run" and have them basically work as expected. So we need
4580 a special create_inferior function.
4582 FIXME: One day add support for changing the exec file
4583 we're debugging, arguments and an environment. */
4586 extended_remote_create_inferior (char *exec_file
, char *args
,
4587 char **env
, int from_tty
)
4589 /* Rip out the breakpoints; we'll reinsert them after restarting
4590 the remote server. */
4591 remove_breakpoints ();
4593 /* Now restart the remote server. */
4594 extended_remote_restart ();
4596 /* Now put the breakpoints back in. This way we're safe if the
4597 restart function works via a unix fork on the remote side. */
4598 insert_breakpoints ();
4600 /* Clean up from the last time we were running. */
4601 clear_proceed_status ();
4604 /* Async version of extended_remote_create_inferior. */
4606 extended_remote_async_create_inferior (char *exec_file
, char *args
,
4607 char **env
, int from_tty
)
4609 /* Rip out the breakpoints; we'll reinsert them after restarting
4610 the remote server. */
4611 remove_breakpoints ();
4613 /* If running asynchronously, register the target file descriptor
4614 with the event loop. */
4615 if (target_can_async_p ())
4616 target_async (inferior_event_handler
, 0);
4618 /* Now restart the remote server. */
4619 extended_remote_restart ();
4621 /* Now put the breakpoints back in. This way we're safe if the
4622 restart function works via a unix fork on the remote side. */
4623 insert_breakpoints ();
4625 /* Clean up from the last time we were running. */
4626 clear_proceed_status ();
4630 /* On some machines, e.g. 68k, we may use a different breakpoint
4631 instruction than other targets; in those use
4632 DEPRECATED_REMOTE_BREAKPOINT instead of just BREAKPOINT_FROM_PC.
4633 Also, bi-endian targets may define
4634 DEPRECATED_LITTLE_REMOTE_BREAKPOINT and
4635 DEPRECATED_BIG_REMOTE_BREAKPOINT. If none of these are defined, we
4636 just call the standard routines that are in mem-break.c. */
4638 /* NOTE: cagney/2003-06-08: This is silly. A remote and simulator
4639 target should use an identical BREAKPOINT_FROM_PC. As for native,
4640 the ARCH-OS-tdep.c code can override the default. */
4642 #if defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) && !defined(DEPRECATED_REMOTE_BREAKPOINT)
4643 #define DEPRECATED_REMOTE_BREAKPOINT
4646 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4648 /* If the target isn't bi-endian, just pretend it is. */
4649 #if !defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && !defined (DEPRECATED_BIG_REMOTE_BREAKPOINT)
4650 #define DEPRECATED_LITTLE_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4651 #define DEPRECATED_BIG_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
4654 static unsigned char big_break_insn
[] = DEPRECATED_BIG_REMOTE_BREAKPOINT
;
4655 static unsigned char little_break_insn
[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT
;
4657 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4659 /* Insert a breakpoint. On targets that have software breakpoint
4660 support, we ask the remote target to do the work; on targets
4661 which don't, we insert a traditional memory breakpoint. */
4664 remote_insert_breakpoint (struct bp_target_info
*bp_tgt
)
4666 CORE_ADDR addr
= bp_tgt
->placed_address
;
4667 struct remote_state
*rs
= get_remote_state ();
4668 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4672 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4673 If it succeeds, then set the support to PACKET_ENABLE. If it
4674 fails, and the user has explicitly requested the Z support then
4675 report an error, otherwise, mark it disabled and go on. */
4677 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
4684 BREAKPOINT_FROM_PC (&bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
4685 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
4686 p
+= hexnumstr (p
, addr
);
4687 sprintf (p
, ",%d", bp_tgt
->placed_size
);
4690 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4692 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
4698 case PACKET_UNKNOWN
:
4703 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4704 bp_tgt
->placed_size
= bp_tgt
->shadow_len
= sizeof big_break_insn
;
4705 val
= target_read_memory (addr
, bp_tgt
->shadow_contents
, bp_tgt
->shadow_len
);
4709 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
4710 val
= target_write_memory (addr
, (char *) big_break_insn
,
4711 sizeof big_break_insn
);
4713 val
= target_write_memory (addr
, (char *) little_break_insn
,
4714 sizeof little_break_insn
);
4719 return memory_insert_breakpoint (bp_tgt
);
4720 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4724 remote_remove_breakpoint (struct bp_target_info
*bp_tgt
)
4726 CORE_ADDR addr
= bp_tgt
->placed_address
;
4727 struct remote_state
*rs
= get_remote_state ();
4730 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
4738 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
4739 p
+= hexnumstr (p
, addr
);
4740 sprintf (p
, ",%d", bp_tgt
->placed_size
);
4743 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4745 return (rs
->buf
[0] == 'E');
4748 #ifdef DEPRECATED_REMOTE_BREAKPOINT
4749 return target_write_memory (bp_tgt
->placed_address
, bp_tgt
->shadow_contents
,
4750 bp_tgt
->shadow_len
);
4752 return memory_remove_breakpoint (bp_tgt
);
4753 #endif /* DEPRECATED_REMOTE_BREAKPOINT */
4757 watchpoint_to_Z_packet (int type
)
4762 return Z_PACKET_WRITE_WP
;
4765 return Z_PACKET_READ_WP
;
4768 return Z_PACKET_ACCESS_WP
;
4771 internal_error (__FILE__
, __LINE__
,
4772 _("hw_bp_to_z: bad watchpoint type %d"), type
);
4777 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
4779 struct remote_state
*rs
= get_remote_state ();
4781 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4783 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
4786 sprintf (rs
->buf
, "Z%x,", packet
);
4787 p
= strchr (rs
->buf
, '\0');
4788 addr
= remote_address_masked (addr
);
4789 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4790 sprintf (p
, ",%x", len
);
4793 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4795 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
4798 case PACKET_UNKNOWN
:
4803 internal_error (__FILE__
, __LINE__
,
4804 _("remote_insert_watchpoint: reached end of function"));
4809 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
4811 struct remote_state
*rs
= get_remote_state ();
4813 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
4815 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
4818 sprintf (rs
->buf
, "z%x,", packet
);
4819 p
= strchr (rs
->buf
, '\0');
4820 addr
= remote_address_masked (addr
);
4821 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4822 sprintf (p
, ",%x", len
);
4824 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4826 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
4829 case PACKET_UNKNOWN
:
4834 internal_error (__FILE__
, __LINE__
,
4835 _("remote_remove_watchpoint: reached end of function"));
4839 int remote_hw_watchpoint_limit
= -1;
4840 int remote_hw_breakpoint_limit
= -1;
4843 remote_check_watch_resources (int type
, int cnt
, int ot
)
4845 if (type
== bp_hardware_breakpoint
)
4847 if (remote_hw_breakpoint_limit
== 0)
4849 else if (remote_hw_breakpoint_limit
< 0)
4851 else if (cnt
<= remote_hw_breakpoint_limit
)
4856 if (remote_hw_watchpoint_limit
== 0)
4858 else if (remote_hw_watchpoint_limit
< 0)
4862 else if (cnt
<= remote_hw_watchpoint_limit
)
4869 remote_stopped_by_watchpoint (void)
4871 return remote_stopped_by_watchpoint_p
;
4874 extern int stepped_after_stopped_by_watchpoint
;
4877 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
4880 if (remote_stopped_by_watchpoint ()
4881 || stepped_after_stopped_by_watchpoint
)
4883 *addr_p
= remote_watch_data_address
;
4892 remote_insert_hw_breakpoint (struct bp_target_info
*bp_tgt
)
4895 struct remote_state
*rs
= get_remote_state ();
4898 /* The length field should be set to the size of a breakpoint
4899 instruction, even though we aren't inserting one ourselves. */
4901 BREAKPOINT_FROM_PC (&bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
4903 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
4910 addr
= remote_address_masked (bp_tgt
->placed_address
);
4911 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4912 sprintf (p
, ",%x", bp_tgt
->placed_size
);
4915 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4917 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
4920 case PACKET_UNKNOWN
:
4925 internal_error (__FILE__
, __LINE__
,
4926 _("remote_insert_hw_breakpoint: reached end of function"));
4931 remote_remove_hw_breakpoint (struct bp_target_info
*bp_tgt
)
4934 struct remote_state
*rs
= get_remote_state ();
4937 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
4944 addr
= remote_address_masked (bp_tgt
->placed_address
);
4945 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4946 sprintf (p
, ",%x", bp_tgt
->placed_size
);
4949 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4951 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
4954 case PACKET_UNKNOWN
:
4959 internal_error (__FILE__
, __LINE__
,
4960 _("remote_remove_hw_breakpoint: reached end of function"));
4963 /* Some targets are only capable of doing downloads, and afterwards
4964 they switch to the remote serial protocol. This function provides
4965 a clean way to get from the download target to the remote target.
4966 It's basically just a wrapper so that we don't have to expose any
4967 of the internal workings of remote.c.
4969 Prior to calling this routine, you should shutdown the current
4970 target code, else you will get the "A program is being debugged
4971 already..." message. Usually a call to pop_target() suffices. */
4974 push_remote_target (char *name
, int from_tty
)
4976 printf_filtered (_("Switching to remote protocol\n"));
4977 remote_open (name
, from_tty
);
4980 /* Table used by the crc32 function to calcuate the checksum. */
4982 static unsigned long crc32_table
[256] =
4985 static unsigned long
4986 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
4988 if (!crc32_table
[1])
4990 /* Initialize the CRC table and the decoding table. */
4994 for (i
= 0; i
< 256; i
++)
4996 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
4997 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
5004 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
5010 /* compare-sections command
5012 With no arguments, compares each loadable section in the exec bfd
5013 with the same memory range on the target, and reports mismatches.
5014 Useful for verifying the image on the target against the exec file.
5015 Depends on the target understanding the new "qCRC:" request. */
5017 /* FIXME: cagney/1999-10-26: This command should be broken down into a
5018 target method (target verify memory) and generic version of the
5019 actual command. This will allow other high-level code (especially
5020 generic_load()) to make use of this target functionality. */
5023 compare_sections_command (char *args
, int from_tty
)
5025 struct remote_state
*rs
= get_remote_state ();
5027 unsigned long host_crc
, target_crc
;
5028 extern bfd
*exec_bfd
;
5029 struct cleanup
*old_chain
;
5032 const char *sectname
;
5039 error (_("command cannot be used without an exec file"));
5040 if (!current_target
.to_shortname
||
5041 strcmp (current_target
.to_shortname
, "remote") != 0)
5042 error (_("command can only be used with remote target"));
5044 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
5046 if (!(s
->flags
& SEC_LOAD
))
5047 continue; /* skip non-loadable section */
5049 size
= bfd_get_section_size (s
);
5051 continue; /* skip zero-length section */
5053 sectname
= bfd_get_section_name (exec_bfd
, s
);
5054 if (args
&& strcmp (args
, sectname
) != 0)
5055 continue; /* not the section selected by user */
5057 matched
= 1; /* do this section */
5059 /* FIXME: assumes lma can fit into long. */
5060 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
5061 (long) lma
, (long) size
);
5064 /* Be clever; compute the host_crc before waiting for target
5066 sectdata
= xmalloc (size
);
5067 old_chain
= make_cleanup (xfree
, sectdata
);
5068 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
5069 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
5071 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5072 if (rs
->buf
[0] == 'E')
5073 error (_("target memory fault, section %s, range 0x%s -- 0x%s"),
5074 sectname
, paddr (lma
), paddr (lma
+ size
));
5075 if (rs
->buf
[0] != 'C')
5076 error (_("remote target does not support this operation"));
5078 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
5079 target_crc
= target_crc
* 16 + fromhex (*tmp
);
5081 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
5082 sectname
, paddr (lma
), paddr (lma
+ size
));
5083 if (host_crc
== target_crc
)
5084 printf_filtered ("matched.\n");
5087 printf_filtered ("MIS-MATCHED!\n");
5091 do_cleanups (old_chain
);
5094 warning (_("One or more sections of the remote executable does not match\n\
5095 the loaded file\n"));
5096 if (args
&& !matched
)
5097 printf_filtered (_("No loaded section named '%s'.\n"), args
);
5101 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
5102 const char *annex
, gdb_byte
*readbuf
,
5103 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
5105 struct remote_state
*rs
= get_remote_state ();
5110 /* Handle memory using remote_xfer_memory. */
5111 if (object
== TARGET_OBJECT_MEMORY
)
5116 if (writebuf
!= NULL
)
5118 void *buffer
= xmalloc (len
);
5119 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
5120 memcpy (buffer
, writebuf
, len
);
5121 xfered
= remote_xfer_memory (offset
, buffer
, len
, 1, NULL
, ops
);
5122 do_cleanups (cleanup
);
5125 xfered
= remote_xfer_memory (offset
, readbuf
, len
, 0, NULL
, ops
);
5129 else if (xfered
== 0 && errno
== 0)
5135 /* Only handle reads. */
5136 if (writebuf
!= NULL
|| readbuf
== NULL
)
5139 /* Map pre-existing objects onto letters. DO NOT do this for new
5140 objects!!! Instead specify new query packets. */
5143 case TARGET_OBJECT_AVR
:
5147 case TARGET_OBJECT_AUXV
:
5148 if (remote_protocol_packets
[PACKET_qPart_auxv
].support
!= PACKET_DISABLE
)
5150 LONGEST n
= min ((get_remote_packet_size () - 2) / 2, len
);
5151 snprintf (rs
->buf
, get_remote_packet_size (),
5152 "qPart:auxv:read::%s,%s",
5153 phex_nz (offset
, sizeof offset
),
5154 phex_nz (n
, sizeof n
));
5155 i
= putpkt (rs
->buf
);
5159 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5160 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qPart_auxv
])
5163 if (strcmp (rs
->buf
, "OK") == 0)
5164 return 0; /* Got EOF indicator. */
5165 /* Got some data. */
5166 return hex2bin (rs
->buf
, readbuf
, len
);
5174 /* Note: a zero OFFSET and LEN can be used to query the minimum
5176 if (offset
== 0 && len
== 0)
5177 return (get_remote_packet_size ());
5178 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
5179 large enough let the caller deal with it. */
5180 if (len
< get_remote_packet_size ())
5182 len
= get_remote_packet_size ();
5184 /* Except for querying the minimum buffer size, target must be open. */
5186 error (_("remote query is only available after target open"));
5188 gdb_assert (annex
!= NULL
);
5189 gdb_assert (readbuf
!= NULL
);
5195 /* We used one buffer char for the remote protocol q command and
5196 another for the query type. As the remote protocol encapsulation
5197 uses 4 chars plus one extra in case we are debugging
5198 (remote_debug), we have PBUFZIZ - 7 left to pack the query
5201 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
5203 /* Bad caller may have sent forbidden characters. */
5204 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
5209 gdb_assert (annex
[i
] == '\0');
5211 i
= putpkt (rs
->buf
);
5215 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5216 strcpy ((char *) readbuf
, rs
->buf
);
5218 return strlen ((char *) readbuf
);
5222 remote_rcmd (char *command
,
5223 struct ui_file
*outbuf
)
5225 struct remote_state
*rs
= get_remote_state ();
5226 char *buf
= rs
->buf
;
5230 error (_("remote rcmd is only available after target open"));
5232 /* Send a NULL command across as an empty command. */
5233 if (command
== NULL
)
5236 /* The query prefix. */
5237 strcpy (buf
, "qRcmd,");
5238 p
= strchr (buf
, '\0');
5240 if ((strlen (buf
) + strlen (command
) * 2 + 8/*misc*/) > get_remote_packet_size ())
5241 error (_("\"monitor\" command ``%s'' is too long."), command
);
5243 /* Encode the actual command. */
5244 bin2hex ((gdb_byte
*) command
, p
, 0);
5246 if (putpkt (rs
->buf
) < 0)
5247 error (_("Communication problem with target."));
5249 /* get/display the response */
5252 /* XXX - see also tracepoint.c:remote_get_noisy_reply(). */
5254 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5256 error (_("Target does not support this command."));
5257 if (buf
[0] == 'O' && buf
[1] != 'K')
5259 remote_console_output (buf
+ 1); /* 'O' message from stub. */
5262 if (strcmp (buf
, "OK") == 0)
5264 if (strlen (buf
) == 3 && buf
[0] == 'E'
5265 && isdigit (buf
[1]) && isdigit (buf
[2]))
5267 error (_("Protocol error with Rcmd"));
5269 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
5271 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
5272 fputc_unfiltered (c
, outbuf
);
5279 packet_command (char *args
, int from_tty
)
5281 struct remote_state
*rs
= get_remote_state ();
5284 error (_("command can only be used with remote target"));
5287 error (_("remote-packet command requires packet text as argument"));
5289 puts_filtered ("sending: ");
5290 print_packet (args
);
5291 puts_filtered ("\n");
5294 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5295 puts_filtered ("received: ");
5296 print_packet (rs
->buf
);
5297 puts_filtered ("\n");
5301 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
5303 static void display_thread_info (struct gdb_ext_thread_info
*info
);
5305 static void threadset_test_cmd (char *cmd
, int tty
);
5307 static void threadalive_test (char *cmd
, int tty
);
5309 static void threadlist_test_cmd (char *cmd
, int tty
);
5311 int get_and_display_threadinfo (threadref
*ref
);
5313 static void threadinfo_test_cmd (char *cmd
, int tty
);
5315 static int thread_display_step (threadref
*ref
, void *context
);
5317 static void threadlist_update_test_cmd (char *cmd
, int tty
);
5319 static void init_remote_threadtests (void);
5321 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
5324 threadset_test_cmd (char *cmd
, int tty
)
5326 int sample_thread
= SAMPLE_THREAD
;
5328 printf_filtered (_("Remote threadset test\n"));
5329 set_thread (sample_thread
, 1);
5334 threadalive_test (char *cmd
, int tty
)
5336 int sample_thread
= SAMPLE_THREAD
;
5338 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
5339 printf_filtered ("PASS: Thread alive test\n");
5341 printf_filtered ("FAIL: Thread alive test\n");
5344 void output_threadid (char *title
, threadref
*ref
);
5347 output_threadid (char *title
, threadref
*ref
)
5351 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
5353 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
5357 threadlist_test_cmd (char *cmd
, int tty
)
5360 threadref nextthread
;
5361 int done
, result_count
;
5362 threadref threadlist
[3];
5364 printf_filtered ("Remote Threadlist test\n");
5365 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
5366 &result_count
, &threadlist
[0]))
5367 printf_filtered ("FAIL: threadlist test\n");
5370 threadref
*scan
= threadlist
;
5371 threadref
*limit
= scan
+ result_count
;
5373 while (scan
< limit
)
5374 output_threadid (" thread ", scan
++);
5379 display_thread_info (struct gdb_ext_thread_info
*info
)
5381 output_threadid ("Threadid: ", &info
->threadid
);
5382 printf_filtered ("Name: %s\n ", info
->shortname
);
5383 printf_filtered ("State: %s\n", info
->display
);
5384 printf_filtered ("other: %s\n\n", info
->more_display
);
5388 get_and_display_threadinfo (threadref
*ref
)
5392 struct gdb_ext_thread_info threadinfo
;
5394 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
5395 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
5396 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
5397 display_thread_info (&threadinfo
);
5402 threadinfo_test_cmd (char *cmd
, int tty
)
5404 int athread
= SAMPLE_THREAD
;
5408 int_to_threadref (&thread
, athread
);
5409 printf_filtered ("Remote Threadinfo test\n");
5410 if (!get_and_display_threadinfo (&thread
))
5411 printf_filtered ("FAIL cannot get thread info\n");
5415 thread_display_step (threadref
*ref
, void *context
)
5417 /* output_threadid(" threadstep ",ref); *//* simple test */
5418 return get_and_display_threadinfo (ref
);
5422 threadlist_update_test_cmd (char *cmd
, int tty
)
5424 printf_filtered ("Remote Threadlist update test\n");
5425 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
5429 init_remote_threadtests (void)
5431 add_com ("tlist", class_obscure
, threadlist_test_cmd
, _("\
5432 Fetch and print the remote list of thread identifiers, one pkt only"));
5433 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
5434 _("Fetch and display info about one thread"));
5435 add_com ("tset", class_obscure
, threadset_test_cmd
,
5436 _("Test setting to a different thread"));
5437 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
5438 _("Iterate through updating all remote thread info"));
5439 add_com ("talive", class_obscure
, threadalive_test
,
5440 _(" Remote thread alive test "));
5445 /* Convert a thread ID to a string. Returns the string in a static
5449 remote_pid_to_str (ptid_t ptid
)
5451 static char buf
[32];
5453 xsnprintf (buf
, sizeof buf
, "thread %d", ptid_get_pid (ptid
));
5457 /* Get the address of the thread local variable in OBJFILE which is
5458 stored at OFFSET within the thread local storage for thread PTID. */
5461 remote_get_thread_local_address (ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
5463 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
5465 struct remote_state
*rs
= get_remote_state ();
5467 enum packet_result result
;
5469 strcpy (p
, "qGetTLSAddr:");
5471 p
+= hexnumstr (p
, PIDGET (ptid
));
5473 p
+= hexnumstr (p
, offset
);
5475 p
+= hexnumstr (p
, lm
);
5479 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5480 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
5481 if (result
== PACKET_OK
)
5485 unpack_varlen_hex (rs
->buf
, &result
);
5488 else if (result
== PACKET_UNKNOWN
)
5489 throw_error (TLS_GENERIC_ERROR
,
5490 _("Remote target doesn't support qGetTLSAddr packet"));
5492 throw_error (TLS_GENERIC_ERROR
,
5493 _("Remote target failed to process qGetTLSAddr request"));
5496 throw_error (TLS_GENERIC_ERROR
,
5497 _("TLS not supported or disabled on this target"));
5503 init_remote_ops (void)
5505 remote_ops
.to_shortname
= "remote";
5506 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
5508 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5509 Specify the serial device it is connected to\n\
5510 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
5511 remote_ops
.to_open
= remote_open
;
5512 remote_ops
.to_close
= remote_close
;
5513 remote_ops
.to_detach
= remote_detach
;
5514 remote_ops
.to_disconnect
= remote_disconnect
;
5515 remote_ops
.to_resume
= remote_resume
;
5516 remote_ops
.to_wait
= remote_wait
;
5517 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
5518 remote_ops
.to_store_registers
= remote_store_registers
;
5519 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5520 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
5521 remote_ops
.to_files_info
= remote_files_info
;
5522 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5523 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5524 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5525 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5526 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5527 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5528 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5529 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5530 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5531 remote_ops
.to_kill
= remote_kill
;
5532 remote_ops
.to_load
= generic_load
;
5533 remote_ops
.to_mourn_inferior
= remote_mourn
;
5534 remote_ops
.to_thread_alive
= remote_thread_alive
;
5535 remote_ops
.to_find_new_threads
= remote_threads_info
;
5536 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
5537 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5538 remote_ops
.to_stop
= remote_stop
;
5539 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
5540 remote_ops
.to_rcmd
= remote_rcmd
;
5541 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
5542 remote_ops
.to_stratum
= process_stratum
;
5543 remote_ops
.to_has_all_memory
= 1;
5544 remote_ops
.to_has_memory
= 1;
5545 remote_ops
.to_has_stack
= 1;
5546 remote_ops
.to_has_registers
= 1;
5547 remote_ops
.to_has_execution
= 1;
5548 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5549 remote_ops
.to_magic
= OPS_MAGIC
;
5552 /* Set up the extended remote vector by making a copy of the standard
5553 remote vector and adding to it. */
5556 init_extended_remote_ops (void)
5558 extended_remote_ops
= remote_ops
;
5560 extended_remote_ops
.to_shortname
= "extended-remote";
5561 extended_remote_ops
.to_longname
=
5562 "Extended remote serial target in gdb-specific protocol";
5563 extended_remote_ops
.to_doc
=
5564 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5565 Specify the serial device it is connected to (e.g. /dev/ttya).",
5566 extended_remote_ops
.to_open
= extended_remote_open
;
5567 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
5568 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5572 remote_can_async_p (void)
5574 /* We're async whenever the serial device is. */
5575 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
5579 remote_is_async_p (void)
5581 /* We're async whenever the serial device is. */
5582 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
5585 /* Pass the SERIAL event on and up to the client. One day this code
5586 will be able to delay notifying the client of an event until the
5587 point where an entire packet has been received. */
5589 static void (*async_client_callback
) (enum inferior_event_type event_type
,
5591 static void *async_client_context
;
5592 static serial_event_ftype remote_async_serial_handler
;
5595 remote_async_serial_handler (struct serial
*scb
, void *context
)
5597 /* Don't propogate error information up to the client. Instead let
5598 the client find out about the error by querying the target. */
5599 async_client_callback (INF_REG_EVENT
, async_client_context
);
5603 remote_async (void (*callback
) (enum inferior_event_type event_type
,
5604 void *context
), void *context
)
5606 if (current_target
.to_async_mask_value
== 0)
5607 internal_error (__FILE__
, __LINE__
,
5608 _("Calling remote_async when async is masked"));
5610 if (callback
!= NULL
)
5612 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
5613 async_client_callback
= callback
;
5614 async_client_context
= context
;
5617 serial_async (remote_desc
, NULL
, NULL
);
5620 /* Target async and target extended-async.
5622 This are temporary targets, until it is all tested. Eventually
5623 async support will be incorporated int the usual 'remote'
5627 init_remote_async_ops (void)
5629 remote_async_ops
.to_shortname
= "async";
5630 remote_async_ops
.to_longname
=
5631 "Remote serial target in async version of the gdb-specific protocol";
5632 remote_async_ops
.to_doc
=
5633 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5634 Specify the serial device it is connected to (e.g. /dev/ttya).";
5635 remote_async_ops
.to_open
= remote_async_open
;
5636 remote_async_ops
.to_close
= remote_close
;
5637 remote_async_ops
.to_detach
= remote_detach
;
5638 remote_async_ops
.to_disconnect
= remote_disconnect
;
5639 remote_async_ops
.to_resume
= remote_async_resume
;
5640 remote_async_ops
.to_wait
= remote_async_wait
;
5641 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
5642 remote_async_ops
.to_store_registers
= remote_store_registers
;
5643 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
5644 remote_async_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
5645 remote_async_ops
.to_files_info
= remote_files_info
;
5646 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
5647 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
5648 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
5649 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
5650 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
5651 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
5652 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
5653 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
5654 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
5655 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
5656 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
5657 remote_async_ops
.to_kill
= remote_async_kill
;
5658 remote_async_ops
.to_load
= generic_load
;
5659 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
5660 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
5661 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
5662 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
5663 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
5664 remote_async_ops
.to_stop
= remote_stop
;
5665 remote_async_ops
.to_xfer_partial
= remote_xfer_partial
;
5666 remote_async_ops
.to_rcmd
= remote_rcmd
;
5667 remote_async_ops
.to_stratum
= process_stratum
;
5668 remote_async_ops
.to_has_all_memory
= 1;
5669 remote_async_ops
.to_has_memory
= 1;
5670 remote_async_ops
.to_has_stack
= 1;
5671 remote_async_ops
.to_has_registers
= 1;
5672 remote_async_ops
.to_has_execution
= 1;
5673 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
5674 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
5675 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
5676 remote_async_ops
.to_async
= remote_async
;
5677 remote_async_ops
.to_async_mask_value
= 1;
5678 remote_async_ops
.to_magic
= OPS_MAGIC
;
5681 /* Set up the async extended remote vector by making a copy of the standard
5682 remote vector and adding to it. */
5685 init_extended_async_remote_ops (void)
5687 extended_async_remote_ops
= remote_async_ops
;
5689 extended_async_remote_ops
.to_shortname
= "extended-async";
5690 extended_async_remote_ops
.to_longname
=
5691 "Extended remote serial target in async gdb-specific protocol";
5692 extended_async_remote_ops
.to_doc
=
5693 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5694 Specify the serial device it is connected to (e.g. /dev/ttya).",
5695 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
5696 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
5697 extended_async_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
5701 set_remote_cmd (char *args
, int from_tty
)
5706 show_remote_cmd (char *args
, int from_tty
)
5708 /* We can't just use cmd_show_list here, because we want to skip
5709 the redundant "show remote Z-packet". */
5710 struct cleanup
*showlist_chain
;
5711 struct cmd_list_element
*list
= remote_show_cmdlist
;
5713 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
5714 for (; list
!= NULL
; list
= list
->next
)
5715 if (strcmp (list
->name
, "Z-packet") == 0)
5717 else if (list
->type
== show_cmd
)
5719 struct cleanup
*option_chain
5720 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
5721 ui_out_field_string (uiout
, "name", list
->name
);
5722 ui_out_text (uiout
, ": ");
5723 do_setshow_command ((char *) NULL
, from_tty
, list
);
5724 /* Close the tuple. */
5725 do_cleanups (option_chain
);
5730 build_remote_gdbarch_data (void)
5732 remote_address_size
= TARGET_ADDR_BIT
;
5735 /* Saved pointer to previous owner of the new_objfile event. */
5736 static void (*remote_new_objfile_chain
) (struct objfile
*);
5738 /* Function to be called whenever a new objfile (shlib) is detected. */
5740 remote_new_objfile (struct objfile
*objfile
)
5742 if (remote_desc
!= 0) /* Have a remote connection. */
5744 remote_check_symbols (objfile
);
5746 /* Call predecessor on chain, if any. */
5747 if (remote_new_objfile_chain
!= 0 &&
5749 remote_new_objfile_chain (objfile
);
5753 _initialize_remote (void)
5755 struct remote_state
*rs
;
5757 /* architecture specific data */
5758 remote_gdbarch_data_handle
=
5759 gdbarch_data_register_post_init (init_remote_state
);
5761 /* Old tacky stuff. NOTE: This comes after the remote protocol so
5762 that the remote protocol has been initialized. */
5763 DEPRECATED_REGISTER_GDBARCH_SWAP (remote_address_size
);
5764 deprecated_register_gdbarch_swap (NULL
, 0, build_remote_gdbarch_data
);
5766 /* Initialize the per-target state. At the moment there is only one
5767 of these, not one per target. Only one target is active at a
5768 time. The default buffer size is unimportant; it will be expanded
5769 whenever a larger buffer is needed. */
5770 rs
= get_remote_state ();
5772 rs
->buf
= xmalloc (rs
->buf_size
);
5775 add_target (&remote_ops
);
5777 init_extended_remote_ops ();
5778 add_target (&extended_remote_ops
);
5780 init_remote_async_ops ();
5781 add_target (&remote_async_ops
);
5783 init_extended_async_remote_ops ();
5784 add_target (&extended_async_remote_ops
);
5786 /* Hook into new objfile notification. */
5787 remote_new_objfile_chain
= deprecated_target_new_objfile_hook
;
5788 deprecated_target_new_objfile_hook
= remote_new_objfile
;
5791 init_remote_threadtests ();
5794 /* set/show remote ... */
5796 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
5797 Remote protocol specific variables\n\
5798 Configure various remote-protocol specific variables such as\n\
5799 the packets being used"),
5800 &remote_set_cmdlist
, "set remote ",
5801 0 /* allow-unknown */, &setlist
);
5802 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
5803 Remote protocol specific variables\n\
5804 Configure various remote-protocol specific variables such as\n\
5805 the packets being used"),
5806 &remote_show_cmdlist
, "show remote ",
5807 0 /* allow-unknown */, &showlist
);
5809 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
5810 Compare section data on target to the exec file.\n\
5811 Argument is a single section name (default: all loaded sections)."),
5814 add_cmd ("packet", class_maintenance
, packet_command
, _("\
5815 Send an arbitrary packet to a remote target.\n\
5816 maintenance packet TEXT\n\
5817 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5818 this command sends the string TEXT to the inferior, and displays the\n\
5819 response packet. GDB supplies the initial `$' character, and the\n\
5820 terminating `#' character and checksum."),
5823 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
5824 Set whether to send break if interrupted."), _("\
5825 Show whether to send break if interrupted."), _("\
5826 If set, a break, instead of a cntrl-c, is sent to the remote target."),
5827 NULL
, NULL
, /* FIXME: i18n: Whether to send break if interrupted is %s. */
5828 &setlist
, &showlist
);
5830 /* Install commands for configuring memory read/write packets. */
5832 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
5833 Set the maximum number of bytes per memory write packet (deprecated)."),
5835 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
5836 Show the maximum number of bytes per memory write packet (deprecated)."),
5838 add_cmd ("memory-write-packet-size", no_class
,
5839 set_memory_write_packet_size
, _("\
5840 Set the maximum number of bytes per memory-write packet.\n\
5841 Specify the number of bytes in a packet or 0 (zero) for the\n\
5842 default packet size. The actual limit is further reduced\n\
5843 dependent on the target. Specify ``fixed'' to disable the\n\
5844 further restriction and ``limit'' to enable that restriction."),
5845 &remote_set_cmdlist
);
5846 add_cmd ("memory-read-packet-size", no_class
,
5847 set_memory_read_packet_size
, _("\
5848 Set the maximum number of bytes per memory-read packet.\n\
5849 Specify the number of bytes in a packet or 0 (zero) for the\n\
5850 default packet size. The actual limit is further reduced\n\
5851 dependent on the target. Specify ``fixed'' to disable the\n\
5852 further restriction and ``limit'' to enable that restriction."),
5853 &remote_set_cmdlist
);
5854 add_cmd ("memory-write-packet-size", no_class
,
5855 show_memory_write_packet_size
,
5856 _("Show the maximum number of bytes per memory-write packet."),
5857 &remote_show_cmdlist
);
5858 add_cmd ("memory-read-packet-size", no_class
,
5859 show_memory_read_packet_size
,
5860 _("Show the maximum number of bytes per memory-read packet."),
5861 &remote_show_cmdlist
);
5863 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
5864 &remote_hw_watchpoint_limit
, _("\
5865 Set the maximum number of target hardware watchpoints."), _("\
5866 Show the maximum number of target hardware watchpoints."), _("\
5867 Specify a negative limit for unlimited."),
5868 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */
5869 &remote_set_cmdlist
, &remote_show_cmdlist
);
5870 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
5871 &remote_hw_breakpoint_limit
, _("\
5872 Set the maximum number of target hardware breakpoints."), _("\
5873 Show the maximum number of target hardware breakpoints."), _("\
5874 Specify a negative limit for unlimited."),
5875 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */
5876 &remote_set_cmdlist
, &remote_show_cmdlist
);
5878 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
5879 &remote_address_size
, _("\
5880 Set the maximum size of the address (in bits) in a memory packet."), _("\
5881 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
5883 NULL
, /* FIXME: i18n: */
5884 &setlist
, &showlist
);
5886 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
5887 "X", "binary-download", 1);
5889 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
5890 "vCont", "verbose-resume", 0);
5892 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
5893 "qSymbol", "symbol-lookup", 0);
5895 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
5896 "P", "set-register", 1);
5898 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
5899 "p", "fetch-register", 1);
5901 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
5902 "Z0", "software-breakpoint", 0);
5904 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
5905 "Z1", "hardware-breakpoint", 0);
5907 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
5908 "Z2", "write-watchpoint", 0);
5910 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
5911 "Z3", "read-watchpoint", 0);
5913 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
5914 "Z4", "access-watchpoint", 0);
5916 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qPart_auxv
],
5917 "qPart:auxv", "read-aux-vector", 0);
5919 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
5920 "qGetTLSAddr", "get-thread-local-storage-address",
5923 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
5924 "qSupported", "supported-packets", 0);
5926 /* Keep the old ``set remote Z-packet ...'' working. Each individual
5927 Z sub-packet has its own set and show commands, but users may
5928 have sets to this variable in their .gdbinit files (or in their
5930 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
5931 &remote_Z_packet_detect
, _("\
5932 Set use of remote protocol `Z' packets"), _("\
5933 Show use of remote protocol `Z' packets "), _("\
5934 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
5936 set_remote_protocol_Z_packet_cmd
,
5937 show_remote_protocol_Z_packet_cmd
, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */
5938 &remote_set_cmdlist
, &remote_show_cmdlist
);
5940 /* Eventually initialize fileio. See fileio.c */
5941 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);