1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
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 3 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, see <http://www.gnu.org/licenses/>. */
22 /* See the GDB User Guide for details of the GDB remote protocol. */
25 #include "gdb_string.h"
31 #include "exceptions.h"
33 /*#include "terminal.h" */
36 #include "gdb-stabs.h"
37 #include "gdbthread.h"
41 #include "gdb_assert.h"
44 #include "cli/cli-decode.h"
45 #include "cli/cli-setshow.h"
46 #include "target-descriptions.h"
51 #include "event-loop.h"
52 #include "event-top.h"
58 #include "gdbcore.h" /* for exec_bfd */
60 #include "remote-fileio.h"
61 #include "gdb/fileio.h"
63 #include "memory-map.h"
65 /* The size to align memory write packets, when practical. The protocol
66 does not guarantee any alignment, and gdb will generate short
67 writes and unaligned writes, but even as a best-effort attempt this
68 can improve bulk transfers. For instance, if a write is misaligned
69 relative to the target's data bus, the stub may need to make an extra
70 round trip fetching data from the target. This doesn't make a
71 huge difference, but it's easy to do, so we try to be helpful.
73 The alignment chosen is arbitrary; usually data bus width is
74 important here, not the possibly larger cache line size. */
75 enum { REMOTE_ALIGN_WRITES
= 16 };
77 /* Prototypes for local functions. */
78 static void cleanup_sigint_signal_handler (void *dummy
);
79 static void initialize_sigint_signal_handler (void);
80 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
82 static void handle_remote_sigint (int);
83 static void handle_remote_sigint_twice (int);
84 static void async_remote_interrupt (gdb_client_data
);
85 void async_remote_interrupt_twice (gdb_client_data
);
87 static void remote_files_info (struct target_ops
*ignore
);
89 static void remote_prepare_to_store (struct regcache
*regcache
);
91 static void remote_fetch_registers (struct regcache
*regcache
, int regno
);
93 static void remote_resume (ptid_t ptid
, int step
,
94 enum target_signal siggnal
);
95 static void remote_async_resume (ptid_t ptid
, int step
,
96 enum target_signal siggnal
);
97 static void remote_open (char *name
, int from_tty
);
98 static void remote_async_open (char *name
, int from_tty
);
100 static void extended_remote_open (char *name
, int from_tty
);
101 static void extended_remote_async_open (char *name
, int from_tty
);
103 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
,
106 static void remote_close (int quitting
);
108 static void remote_store_registers (struct regcache
*regcache
, int regno
);
110 static void remote_mourn (void);
111 static void remote_async_mourn (void);
113 static void extended_remote_restart (void);
115 static void extended_remote_mourn (void);
117 static void remote_mourn_1 (struct target_ops
*);
119 static void remote_send (char **buf
, long *sizeof_buf_p
);
121 static int readchar (int timeout
);
123 static ptid_t
remote_wait (ptid_t ptid
,
124 struct target_waitstatus
*status
);
125 static ptid_t
remote_async_wait (ptid_t ptid
,
126 struct target_waitstatus
*status
);
128 static void remote_kill (void);
129 static void remote_async_kill (void);
131 static int tohex (int nib
);
133 static void remote_detach (char *args
, int from_tty
);
135 static void remote_interrupt (int signo
);
137 static void remote_interrupt_twice (int signo
);
139 static void interrupt_query (void);
141 static void set_thread (int, int);
143 static int remote_thread_alive (ptid_t
);
145 static void get_offsets (void);
147 static void skip_frame (void);
149 static long read_frame (char **buf_p
, long *sizeof_buf
);
151 static int hexnumlen (ULONGEST num
);
153 static void init_remote_ops (void);
155 static void init_extended_remote_ops (void);
157 static void remote_stop (void);
159 static int ishex (int ch
, int *val
);
161 static int stubhex (int ch
);
163 static int hexnumstr (char *, ULONGEST
);
165 static int hexnumnstr (char *, ULONGEST
, int);
167 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
169 static void print_packet (char *);
171 static unsigned long crc32 (unsigned char *, int, unsigned int);
173 static void compare_sections_command (char *, int);
175 static void packet_command (char *, int);
177 static int stub_unpack_int (char *buff
, int fieldlength
);
179 static ptid_t
remote_current_thread (ptid_t oldptid
);
181 static void remote_find_new_threads (void);
183 static void record_currthread (int currthread
);
185 static int fromhex (int a
);
187 static int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
189 static int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
191 static int putpkt_binary (char *buf
, int cnt
);
193 static void check_binary_download (CORE_ADDR addr
);
195 struct packet_config
;
197 static void show_packet_config_cmd (struct packet_config
*config
);
199 static void update_packet_config (struct packet_config
*config
);
201 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
202 struct cmd_list_element
*c
);
204 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
206 struct cmd_list_element
*c
,
209 void _initialize_remote (void);
213 static struct cmd_list_element
*remote_cmdlist
;
215 /* For "set remote" and "show remote". */
217 static struct cmd_list_element
*remote_set_cmdlist
;
218 static struct cmd_list_element
*remote_show_cmdlist
;
220 /* Description of the remote protocol state for the currently
221 connected target. This is per-target state, and independent of the
222 selected architecture. */
226 /* A buffer to use for incoming packets, and its current size. The
227 buffer is grown dynamically for larger incoming packets.
228 Outgoing packets may also be constructed in this buffer.
229 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
230 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
235 /* If we negotiated packet size explicitly (and thus can bypass
236 heuristics for the largest packet size that will not overflow
237 a buffer in the stub), this will be set to that packet size.
238 Otherwise zero, meaning to use the guessed size. */
239 long explicit_packet_size
;
241 /* remote_wait is normally called when the target is running and
242 waits for a stop reply packet. But sometimes we need to call it
243 when the target is already stopped. We can send a "?" packet
244 and have remote_wait read the response. Or, if we already have
245 the response, we can stash it in BUF and tell remote_wait to
246 skip calling getpkt. This flag is set when BUF contains a
247 stop reply packet and the target is not waiting. */
248 int cached_wait_status
;
251 /* This data could be associated with a target, but we do not always
252 have access to the current target when we need it, so for now it is
253 static. This will be fine for as long as only one target is in use
255 static struct remote_state remote_state
;
257 static struct remote_state
*
258 get_remote_state_raw (void)
260 return &remote_state
;
263 /* Description of the remote protocol for a given architecture. */
267 long offset
; /* Offset into G packet. */
268 long regnum
; /* GDB's internal register number. */
269 LONGEST pnum
; /* Remote protocol register number. */
270 int in_g_packet
; /* Always part of G packet. */
271 /* long size in bytes; == register_size (current_gdbarch, regnum);
273 /* char *name; == gdbarch_register_name (current_gdbarch, regnum);
277 struct remote_arch_state
279 /* Description of the remote protocol registers. */
280 long sizeof_g_packet
;
282 /* Description of the remote protocol registers indexed by REGNUM
283 (making an array gdbarch_num_regs in size). */
284 struct packet_reg
*regs
;
286 /* This is the size (in chars) of the first response to the ``g''
287 packet. It is used as a heuristic when determining the maximum
288 size of memory-read and memory-write packets. A target will
289 typically only reserve a buffer large enough to hold the ``g''
290 packet. The size does not include packet overhead (headers and
292 long actual_register_packet_size
;
294 /* This is the maximum size (in chars) of a non read/write packet.
295 It is also used as a cap on the size of read/write packets. */
296 long remote_packet_size
;
300 /* Handle for retreving the remote protocol data from gdbarch. */
301 static struct gdbarch_data
*remote_gdbarch_data_handle
;
303 static struct remote_arch_state
*
304 get_remote_arch_state (void)
306 return gdbarch_data (current_gdbarch
, remote_gdbarch_data_handle
);
309 /* Fetch the global remote target state. */
311 static struct remote_state
*
312 get_remote_state (void)
314 /* Make sure that the remote architecture state has been
315 initialized, because doing so might reallocate rs->buf. Any
316 function which calls getpkt also needs to be mindful of changes
317 to rs->buf, but this call limits the number of places which run
319 get_remote_arch_state ();
321 return get_remote_state_raw ();
325 compare_pnums (const void *lhs_
, const void *rhs_
)
327 const struct packet_reg
* const *lhs
= lhs_
;
328 const struct packet_reg
* const *rhs
= rhs_
;
330 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
332 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
339 init_remote_state (struct gdbarch
*gdbarch
)
341 int regnum
, num_remote_regs
, offset
;
342 struct remote_state
*rs
= get_remote_state_raw ();
343 struct remote_arch_state
*rsa
;
344 struct packet_reg
**remote_regs
;
346 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
348 /* Use the architecture to build a regnum<->pnum table, which will be
349 1:1 unless a feature set specifies otherwise. */
350 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
351 gdbarch_num_regs (gdbarch
),
353 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
355 struct packet_reg
*r
= &rsa
->regs
[regnum
];
357 if (register_size (gdbarch
, regnum
) == 0)
358 /* Do not try to fetch zero-sized (placeholder) registers. */
361 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
366 /* Define the g/G packet format as the contents of each register
367 with a remote protocol number, in order of ascending protocol
370 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
371 * sizeof (struct packet_reg
*));
372 for (num_remote_regs
= 0, regnum
= 0;
373 regnum
< gdbarch_num_regs (gdbarch
);
375 if (rsa
->regs
[regnum
].pnum
!= -1)
376 remote_regs
[num_remote_regs
++] = &rsa
->regs
[regnum
];
378 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
381 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
383 remote_regs
[regnum
]->in_g_packet
= 1;
384 remote_regs
[regnum
]->offset
= offset
;
385 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
388 /* Record the maximum possible size of the g packet - it may turn out
390 rsa
->sizeof_g_packet
= offset
;
392 /* Default maximum number of characters in a packet body. Many
393 remote stubs have a hardwired buffer size of 400 bytes
394 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
395 as the maximum packet-size to ensure that the packet and an extra
396 NUL character can always fit in the buffer. This stops GDB
397 trashing stubs that try to squeeze an extra NUL into what is
398 already a full buffer (As of 1999-12-04 that was most stubs). */
399 rsa
->remote_packet_size
= 400 - 1;
401 /* This one is filled in when a ``g'' packet is received. */
402 rsa
->actual_register_packet_size
= 0;
404 /* Should rsa->sizeof_g_packet needs more space than the
405 default, adjust the size accordingly. Remember that each byte is
406 encoded as two characters. 32 is the overhead for the packet
407 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
408 (``$NN:G...#NN'') is a better guess, the below has been padded a
410 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
411 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
413 /* Make sure that the packet buffer is plenty big enough for
414 this architecture. */
415 if (rs
->buf_size
< rsa
->remote_packet_size
)
417 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
418 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
424 /* Return the current allowed size of a remote packet. This is
425 inferred from the current architecture, and should be used to
426 limit the length of outgoing packets. */
428 get_remote_packet_size (void)
430 struct remote_state
*rs
= get_remote_state ();
431 struct remote_arch_state
*rsa
= get_remote_arch_state ();
433 if (rs
->explicit_packet_size
)
434 return rs
->explicit_packet_size
;
436 return rsa
->remote_packet_size
;
439 static struct packet_reg
*
440 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
442 if (regnum
< 0 && regnum
>= gdbarch_num_regs (current_gdbarch
))
446 struct packet_reg
*r
= &rsa
->regs
[regnum
];
447 gdb_assert (r
->regnum
== regnum
);
452 static struct packet_reg
*
453 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
456 for (i
= 0; i
< gdbarch_num_regs (current_gdbarch
); i
++)
458 struct packet_reg
*r
= &rsa
->regs
[i
];
465 /* FIXME: graces/2002-08-08: These variables should eventually be
466 bound to an instance of the target object (as in gdbarch-tdep()),
467 when such a thing exists. */
469 /* This is set to the data address of the access causing the target
470 to stop for a watchpoint. */
471 static CORE_ADDR remote_watch_data_address
;
473 /* This is non-zero if target stopped for a watchpoint. */
474 static int remote_stopped_by_watchpoint_p
;
476 static struct target_ops remote_ops
;
478 static struct target_ops extended_remote_ops
;
480 /* Temporary target ops. Just like the remote_ops and
481 extended_remote_ops, but with asynchronous support. */
482 static struct target_ops remote_async_ops
;
484 static struct target_ops extended_async_remote_ops
;
486 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
487 ``forever'' still use the normal timeout mechanism. This is
488 currently used by the ASYNC code to guarentee that target reads
489 during the initial connect always time-out. Once getpkt has been
490 modified to return a timeout indication and, in turn
491 remote_wait()/wait_for_inferior() have gained a timeout parameter
493 static int wait_forever_enabled_p
= 1;
496 /* This variable chooses whether to send a ^C or a break when the user
497 requests program interruption. Although ^C is usually what remote
498 systems expect, and that is the default here, sometimes a break is
499 preferable instead. */
501 static int remote_break
;
503 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
504 remote_open knows that we don't have a file open when the program
506 static struct serial
*remote_desc
= NULL
;
508 /* This variable sets the number of bits in an address that are to be
509 sent in a memory ("M" or "m") packet. Normally, after stripping
510 leading zeros, the entire address would be sent. This variable
511 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
512 initial implementation of remote.c restricted the address sent in
513 memory packets to ``host::sizeof long'' bytes - (typically 32
514 bits). Consequently, for 64 bit targets, the upper 32 bits of an
515 address was never sent. Since fixing this bug may cause a break in
516 some remote targets this variable is principly provided to
517 facilitate backward compatibility. */
519 static int remote_address_size
;
521 /* Tempoary to track who currently owns the terminal. See
522 target_async_terminal_* for more details. */
524 static int remote_async_terminal_ours_p
;
526 /* The executable file to use for "run" on the remote side. */
528 static char *remote_exec_file
= "";
531 /* User configurable variables for the number of characters in a
532 memory read/write packet. MIN (rsa->remote_packet_size,
533 rsa->sizeof_g_packet) is the default. Some targets need smaller
534 values (fifo overruns, et.al.) and some users need larger values
535 (speed up transfers). The variables ``preferred_*'' (the user
536 request), ``current_*'' (what was actually set) and ``forced_*''
537 (Positive - a soft limit, negative - a hard limit). */
539 struct memory_packet_config
546 /* Compute the current size of a read/write packet. Since this makes
547 use of ``actual_register_packet_size'' the computation is dynamic. */
550 get_memory_packet_size (struct memory_packet_config
*config
)
552 struct remote_state
*rs
= get_remote_state ();
553 struct remote_arch_state
*rsa
= get_remote_arch_state ();
555 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
556 law?) that some hosts don't cope very well with large alloca()
557 calls. Eventually the alloca() code will be replaced by calls to
558 xmalloc() and make_cleanups() allowing this restriction to either
559 be lifted or removed. */
560 #ifndef MAX_REMOTE_PACKET_SIZE
561 #define MAX_REMOTE_PACKET_SIZE 16384
563 /* NOTE: 20 ensures we can write at least one byte. */
564 #ifndef MIN_REMOTE_PACKET_SIZE
565 #define MIN_REMOTE_PACKET_SIZE 20
570 if (config
->size
<= 0)
571 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
573 what_they_get
= config
->size
;
577 what_they_get
= get_remote_packet_size ();
578 /* Limit the packet to the size specified by the user. */
580 && what_they_get
> config
->size
)
581 what_they_get
= config
->size
;
583 /* Limit it to the size of the targets ``g'' response unless we have
584 permission from the stub to use a larger packet size. */
585 if (rs
->explicit_packet_size
== 0
586 && rsa
->actual_register_packet_size
> 0
587 && what_they_get
> rsa
->actual_register_packet_size
)
588 what_they_get
= rsa
->actual_register_packet_size
;
590 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
591 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
592 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
593 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
595 /* Make sure there is room in the global buffer for this packet
596 (including its trailing NUL byte). */
597 if (rs
->buf_size
< what_they_get
+ 1)
599 rs
->buf_size
= 2 * what_they_get
;
600 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
603 return what_they_get
;
606 /* Update the size of a read/write packet. If they user wants
607 something really big then do a sanity check. */
610 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
612 int fixed_p
= config
->fixed_p
;
613 long size
= config
->size
;
615 error (_("Argument required (integer, `fixed' or `limited')."));
616 else if (strcmp (args
, "hard") == 0
617 || strcmp (args
, "fixed") == 0)
619 else if (strcmp (args
, "soft") == 0
620 || strcmp (args
, "limit") == 0)
625 size
= strtoul (args
, &end
, 0);
627 error (_("Invalid %s (bad syntax)."), config
->name
);
629 /* Instead of explicitly capping the size of a packet to
630 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
631 instead allowed to set the size to something arbitrarily
633 if (size
> MAX_REMOTE_PACKET_SIZE
)
634 error (_("Invalid %s (too large)."), config
->name
);
638 if (fixed_p
&& !config
->fixed_p
)
640 if (! query (_("The target may not be able to correctly handle a %s\n"
641 "of %ld bytes. Change the packet size? "),
643 error (_("Packet size not changed."));
645 /* Update the config. */
646 config
->fixed_p
= fixed_p
;
651 show_memory_packet_size (struct memory_packet_config
*config
)
653 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
655 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
656 get_memory_packet_size (config
));
658 printf_filtered (_("Packets are limited to %ld bytes.\n"),
659 get_memory_packet_size (config
));
662 static struct memory_packet_config memory_write_packet_config
=
664 "memory-write-packet-size",
668 set_memory_write_packet_size (char *args
, int from_tty
)
670 set_memory_packet_size (args
, &memory_write_packet_config
);
674 show_memory_write_packet_size (char *args
, int from_tty
)
676 show_memory_packet_size (&memory_write_packet_config
);
680 get_memory_write_packet_size (void)
682 return get_memory_packet_size (&memory_write_packet_config
);
685 static struct memory_packet_config memory_read_packet_config
=
687 "memory-read-packet-size",
691 set_memory_read_packet_size (char *args
, int from_tty
)
693 set_memory_packet_size (args
, &memory_read_packet_config
);
697 show_memory_read_packet_size (char *args
, int from_tty
)
699 show_memory_packet_size (&memory_read_packet_config
);
703 get_memory_read_packet_size (void)
705 long size
= get_memory_packet_size (&memory_read_packet_config
);
706 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
707 extra buffer size argument before the memory read size can be
708 increased beyond this. */
709 if (size
> get_remote_packet_size ())
710 size
= get_remote_packet_size ();
715 /* Generic configuration support for packets the stub optionally
716 supports. Allows the user to specify the use of the packet as well
717 as allowing GDB to auto-detect support in the remote stub. */
721 PACKET_SUPPORT_UNKNOWN
= 0,
730 enum auto_boolean detect
;
731 enum packet_support support
;
734 /* Analyze a packet's return value and update the packet config
745 update_packet_config (struct packet_config
*config
)
747 switch (config
->detect
)
749 case AUTO_BOOLEAN_TRUE
:
750 config
->support
= PACKET_ENABLE
;
752 case AUTO_BOOLEAN_FALSE
:
753 config
->support
= PACKET_DISABLE
;
755 case AUTO_BOOLEAN_AUTO
:
756 config
->support
= PACKET_SUPPORT_UNKNOWN
;
762 show_packet_config_cmd (struct packet_config
*config
)
764 char *support
= "internal-error";
765 switch (config
->support
)
771 support
= "disabled";
773 case PACKET_SUPPORT_UNKNOWN
:
777 switch (config
->detect
)
779 case AUTO_BOOLEAN_AUTO
:
780 printf_filtered (_("Support for the `%s' packet is auto-detected, currently %s.\n"),
781 config
->name
, support
);
783 case AUTO_BOOLEAN_TRUE
:
784 case AUTO_BOOLEAN_FALSE
:
785 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
786 config
->name
, support
);
792 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
793 const char *title
, int legacy
)
800 config
->title
= title
;
801 config
->detect
= AUTO_BOOLEAN_AUTO
;
802 config
->support
= PACKET_SUPPORT_UNKNOWN
;
803 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
805 show_doc
= xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
807 /* set/show TITLE-packet {auto,on,off} */
808 cmd_name
= xstrprintf ("%s-packet", title
);
809 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
810 &config
->detect
, set_doc
, show_doc
, NULL
, /* help_doc */
811 set_remote_protocol_packet_cmd
,
812 show_remote_protocol_packet_cmd
,
813 &remote_set_cmdlist
, &remote_show_cmdlist
);
814 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
818 legacy_name
= xstrprintf ("%s-packet", name
);
819 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
820 &remote_set_cmdlist
);
821 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
822 &remote_show_cmdlist
);
826 static enum packet_result
827 packet_check_result (const char *buf
)
831 /* The stub recognized the packet request. Check that the
832 operation succeeded. */
834 && isxdigit (buf
[1]) && isxdigit (buf
[2])
836 /* "Enn" - definitly an error. */
839 /* Always treat "E." as an error. This will be used for
840 more verbose error messages, such as E.memtypes. */
841 if (buf
[0] == 'E' && buf
[1] == '.')
844 /* The packet may or may not be OK. Just assume it is. */
848 /* The stub does not support the packet. */
849 return PACKET_UNKNOWN
;
852 static enum packet_result
853 packet_ok (const char *buf
, struct packet_config
*config
)
855 enum packet_result result
;
857 result
= packet_check_result (buf
);
862 /* The stub recognized the packet request. */
863 switch (config
->support
)
865 case PACKET_SUPPORT_UNKNOWN
:
867 fprintf_unfiltered (gdb_stdlog
,
868 "Packet %s (%s) is supported\n",
869 config
->name
, config
->title
);
870 config
->support
= PACKET_ENABLE
;
873 internal_error (__FILE__
, __LINE__
,
874 _("packet_ok: attempt to use a disabled packet"));
881 /* The stub does not support the packet. */
882 switch (config
->support
)
885 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
886 /* If the stub previously indicated that the packet was
887 supported then there is a protocol error.. */
888 error (_("Protocol error: %s (%s) conflicting enabled responses."),
889 config
->name
, config
->title
);
891 /* The user set it wrong. */
892 error (_("Enabled packet %s (%s) not recognized by stub"),
893 config
->name
, config
->title
);
895 case PACKET_SUPPORT_UNKNOWN
:
897 fprintf_unfiltered (gdb_stdlog
,
898 "Packet %s (%s) is NOT supported\n",
899 config
->name
, config
->title
);
900 config
->support
= PACKET_DISABLE
;
928 PACKET_qXfer_features
,
929 PACKET_qXfer_libraries
,
930 PACKET_qXfer_memory_map
,
931 PACKET_qXfer_spu_read
,
932 PACKET_qXfer_spu_write
,
941 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
944 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
945 struct cmd_list_element
*c
)
947 struct packet_config
*packet
;
949 for (packet
= remote_protocol_packets
;
950 packet
< &remote_protocol_packets
[PACKET_MAX
];
953 if (&packet
->detect
== c
->var
)
955 update_packet_config (packet
);
959 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
964 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
965 struct cmd_list_element
*c
,
968 struct packet_config
*packet
;
970 for (packet
= remote_protocol_packets
;
971 packet
< &remote_protocol_packets
[PACKET_MAX
];
974 if (&packet
->detect
== c
->var
)
976 show_packet_config_cmd (packet
);
980 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
984 /* Should we try one of the 'Z' requests? */
988 Z_PACKET_SOFTWARE_BP
,
989 Z_PACKET_HARDWARE_BP
,
996 /* For compatibility with older distributions. Provide a ``set remote
997 Z-packet ...'' command that updates all the Z packet types. */
999 static enum auto_boolean remote_Z_packet_detect
;
1002 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1003 struct cmd_list_element
*c
)
1006 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1008 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1009 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1014 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1015 struct cmd_list_element
*c
,
1019 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1021 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1025 /* Should we try the 'ThreadInfo' query packet?
1027 This variable (NOT available to the user: auto-detect only!)
1028 determines whether GDB will use the new, simpler "ThreadInfo"
1029 query or the older, more complex syntax for thread queries.
1030 This is an auto-detect variable (set to true at each connect,
1031 and set to false when the target fails to recognize it). */
1033 static int use_threadinfo_query
;
1034 static int use_threadextra_query
;
1036 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1037 static struct async_signal_handler
*sigint_remote_twice_token
;
1038 static struct async_signal_handler
*sigint_remote_token
;
1040 /* These are pointers to hook functions that may be set in order to
1041 modify resume/wait behavior for a particular architecture. */
1043 void (*deprecated_target_resume_hook
) (void);
1044 void (*deprecated_target_wait_loop_hook
) (void);
1048 /* These are the threads which we last sent to the remote system.
1049 -1 for all or -2 for not sent yet. */
1050 static int general_thread
;
1051 static int continue_thread
;
1053 /* Call this function as a result of
1054 1) A halt indication (T packet) containing a thread id
1055 2) A direct query of currthread
1056 3) Successful execution of set thread
1060 record_currthread (int currthread
)
1062 general_thread
= currthread
;
1064 /* If this is a new thread, add it to GDB's thread list.
1065 If we leave it up to WFI to do this, bad things will happen. */
1066 if (!in_thread_list (pid_to_ptid (currthread
)))
1067 add_thread (pid_to_ptid (currthread
));
1070 static char *last_pass_packet
;
1072 /* If 'QPassSignals' is supported, tell the remote stub what signals
1073 it can simply pass through to the inferior without reporting. */
1076 remote_pass_signals (void)
1078 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1080 char *pass_packet
, *p
;
1081 int numsigs
= (int) TARGET_SIGNAL_LAST
;
1084 gdb_assert (numsigs
< 256);
1085 for (i
= 0; i
< numsigs
; i
++)
1087 if (signal_stop_state (i
) == 0
1088 && signal_print_state (i
) == 0
1089 && signal_pass_state (i
) == 1)
1092 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1093 strcpy (pass_packet
, "QPassSignals:");
1094 p
= pass_packet
+ strlen (pass_packet
);
1095 for (i
= 0; i
< numsigs
; i
++)
1097 if (signal_stop_state (i
) == 0
1098 && signal_print_state (i
) == 0
1099 && signal_pass_state (i
) == 1)
1102 *p
++ = tohex (i
>> 4);
1103 *p
++ = tohex (i
& 15);
1112 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1114 struct remote_state
*rs
= get_remote_state ();
1115 char *buf
= rs
->buf
;
1117 putpkt (pass_packet
);
1118 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1119 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1120 if (last_pass_packet
)
1121 xfree (last_pass_packet
);
1122 last_pass_packet
= pass_packet
;
1125 xfree (pass_packet
);
1129 #define MAGIC_NULL_PID 42000
1132 set_thread (int th
, int gen
)
1134 struct remote_state
*rs
= get_remote_state ();
1135 char *buf
= rs
->buf
;
1136 int state
= gen
? general_thread
: continue_thread
;
1142 buf
[1] = gen
? 'g' : 'c';
1143 if (th
== MAGIC_NULL_PID
)
1149 xsnprintf (&buf
[2], get_remote_packet_size () - 2, "-%x", -th
);
1151 xsnprintf (&buf
[2], get_remote_packet_size () - 2, "%x", th
);
1153 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1155 general_thread
= th
;
1157 continue_thread
= th
;
1160 /* Return nonzero if the thread TH is still alive on the remote system. */
1163 remote_thread_alive (ptid_t ptid
)
1165 struct remote_state
*rs
= get_remote_state ();
1166 int tid
= PIDGET (ptid
);
1169 xsnprintf (rs
->buf
, get_remote_packet_size (), "T-%08x", -tid
);
1171 xsnprintf (rs
->buf
, get_remote_packet_size (), "T%08x", tid
);
1173 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1174 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1177 /* About these extended threadlist and threadinfo packets. They are
1178 variable length packets but, the fields within them are often fixed
1179 length. They are redundent enough to send over UDP as is the
1180 remote protocol in general. There is a matching unit test module
1183 #define OPAQUETHREADBYTES 8
1185 /* a 64 bit opaque identifier */
1186 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1188 /* WARNING: This threadref data structure comes from the remote O.S.,
1189 libstub protocol encoding, and remote.c. it is not particularly
1192 /* Right now, the internal structure is int. We want it to be bigger.
1196 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1198 /* gdb_ext_thread_info is an internal GDB data structure which is
1199 equivalent to the reply of the remote threadinfo packet. */
1201 struct gdb_ext_thread_info
1203 threadref threadid
; /* External form of thread reference. */
1204 int active
; /* Has state interesting to GDB?
1206 char display
[256]; /* Brief state display, name,
1207 blocked/suspended. */
1208 char shortname
[32]; /* To be used to name threads. */
1209 char more_display
[256]; /* Long info, statistics, queue depth,
1213 /* The volume of remote transfers can be limited by submitting
1214 a mask containing bits specifying the desired information.
1215 Use a union of these values as the 'selection' parameter to
1216 get_thread_info. FIXME: Make these TAG names more thread specific.
1219 #define TAG_THREADID 1
1220 #define TAG_EXISTS 2
1221 #define TAG_DISPLAY 4
1222 #define TAG_THREADNAME 8
1223 #define TAG_MOREDISPLAY 16
1225 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1227 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1229 static char *unpack_nibble (char *buf
, int *val
);
1231 static char *pack_nibble (char *buf
, int nibble
);
1233 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1235 static char *unpack_byte (char *buf
, int *value
);
1237 static char *pack_int (char *buf
, int value
);
1239 static char *unpack_int (char *buf
, int *value
);
1241 static char *unpack_string (char *src
, char *dest
, int length
);
1243 static char *pack_threadid (char *pkt
, threadref
*id
);
1245 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1247 void int_to_threadref (threadref
*id
, int value
);
1249 static int threadref_to_int (threadref
*ref
);
1251 static void copy_threadref (threadref
*dest
, threadref
*src
);
1253 static int threadmatch (threadref
*dest
, threadref
*src
);
1255 static char *pack_threadinfo_request (char *pkt
, int mode
,
1258 static int remote_unpack_thread_info_response (char *pkt
,
1259 threadref
*expectedref
,
1260 struct gdb_ext_thread_info
1264 static int remote_get_threadinfo (threadref
*threadid
,
1265 int fieldset
, /*TAG mask */
1266 struct gdb_ext_thread_info
*info
);
1268 static char *pack_threadlist_request (char *pkt
, int startflag
,
1270 threadref
*nextthread
);
1272 static int parse_threadlist_response (char *pkt
,
1274 threadref
*original_echo
,
1275 threadref
*resultlist
,
1278 static int remote_get_threadlist (int startflag
,
1279 threadref
*nextthread
,
1283 threadref
*threadlist
);
1285 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1287 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1288 void *context
, int looplimit
);
1290 static int remote_newthread_step (threadref
*ref
, void *context
);
1292 /* Encode 64 bits in 16 chars of hex. */
1294 static const char hexchars
[] = "0123456789abcdef";
1297 ishex (int ch
, int *val
)
1299 if ((ch
>= 'a') && (ch
<= 'f'))
1301 *val
= ch
- 'a' + 10;
1304 if ((ch
>= 'A') && (ch
<= 'F'))
1306 *val
= ch
- 'A' + 10;
1309 if ((ch
>= '0') && (ch
<= '9'))
1320 if (ch
>= 'a' && ch
<= 'f')
1321 return ch
- 'a' + 10;
1322 if (ch
>= '0' && ch
<= '9')
1324 if (ch
>= 'A' && ch
<= 'F')
1325 return ch
- 'A' + 10;
1330 stub_unpack_int (char *buff
, int fieldlength
)
1337 nibble
= stubhex (*buff
++);
1341 retval
= retval
<< 4;
1347 unpack_varlen_hex (char *buff
, /* packet to parse */
1351 ULONGEST retval
= 0;
1353 while (ishex (*buff
, &nibble
))
1356 retval
= retval
<< 4;
1357 retval
|= nibble
& 0x0f;
1364 unpack_nibble (char *buf
, int *val
)
1366 *val
= fromhex (*buf
++);
1371 pack_nibble (char *buf
, int nibble
)
1373 *buf
++ = hexchars
[(nibble
& 0x0f)];
1378 pack_hex_byte (char *pkt
, int byte
)
1380 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1381 *pkt
++ = hexchars
[(byte
& 0xf)];
1386 unpack_byte (char *buf
, int *value
)
1388 *value
= stub_unpack_int (buf
, 2);
1393 pack_int (char *buf
, int value
)
1395 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1396 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1397 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1398 buf
= pack_hex_byte (buf
, (value
& 0xff));
1403 unpack_int (char *buf
, int *value
)
1405 *value
= stub_unpack_int (buf
, 8);
1409 #if 0 /* Currently unused, uncomment when needed. */
1410 static char *pack_string (char *pkt
, char *string
);
1413 pack_string (char *pkt
, char *string
)
1418 len
= strlen (string
);
1420 len
= 200; /* Bigger than most GDB packets, junk??? */
1421 pkt
= pack_hex_byte (pkt
, len
);
1425 if ((ch
== '\0') || (ch
== '#'))
1426 ch
= '*'; /* Protect encapsulation. */
1431 #endif /* 0 (unused) */
1434 unpack_string (char *src
, char *dest
, int length
)
1443 pack_threadid (char *pkt
, threadref
*id
)
1446 unsigned char *altid
;
1448 altid
= (unsigned char *) id
;
1449 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1451 pkt
= pack_hex_byte (pkt
, *altid
++);
1457 unpack_threadid (char *inbuf
, threadref
*id
)
1460 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1463 altref
= (char *) id
;
1465 while (inbuf
< limit
)
1467 x
= stubhex (*inbuf
++);
1468 y
= stubhex (*inbuf
++);
1469 *altref
++ = (x
<< 4) | y
;
1474 /* Externally, threadrefs are 64 bits but internally, they are still
1475 ints. This is due to a mismatch of specifications. We would like
1476 to use 64bit thread references internally. This is an adapter
1480 int_to_threadref (threadref
*id
, int value
)
1482 unsigned char *scan
;
1484 scan
= (unsigned char *) id
;
1490 *scan
++ = (value
>> 24) & 0xff;
1491 *scan
++ = (value
>> 16) & 0xff;
1492 *scan
++ = (value
>> 8) & 0xff;
1493 *scan
++ = (value
& 0xff);
1497 threadref_to_int (threadref
*ref
)
1500 unsigned char *scan
;
1506 value
= (value
<< 8) | ((*scan
++) & 0xff);
1511 copy_threadref (threadref
*dest
, threadref
*src
)
1514 unsigned char *csrc
, *cdest
;
1516 csrc
= (unsigned char *) src
;
1517 cdest
= (unsigned char *) dest
;
1524 threadmatch (threadref
*dest
, threadref
*src
)
1526 /* Things are broken right now, so just assume we got a match. */
1528 unsigned char *srcp
, *destp
;
1530 srcp
= (char *) src
;
1531 destp
= (char *) dest
;
1535 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1542 threadid:1, # always request threadid
1549 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1552 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1554 *pkt
++ = 'q'; /* Info Query */
1555 *pkt
++ = 'P'; /* process or thread info */
1556 pkt
= pack_int (pkt
, mode
); /* mode */
1557 pkt
= pack_threadid (pkt
, id
); /* threadid */
1558 *pkt
= '\0'; /* terminate */
1562 /* These values tag the fields in a thread info response packet. */
1563 /* Tagging the fields allows us to request specific fields and to
1564 add more fields as time goes by. */
1566 #define TAG_THREADID 1 /* Echo the thread identifier. */
1567 #define TAG_EXISTS 2 /* Is this process defined enough to
1568 fetch registers and its stack? */
1569 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1570 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
1571 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1575 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1576 struct gdb_ext_thread_info
*info
)
1578 struct remote_state
*rs
= get_remote_state ();
1582 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
1585 /* info->threadid = 0; FIXME: implement zero_threadref. */
1587 info
->display
[0] = '\0';
1588 info
->shortname
[0] = '\0';
1589 info
->more_display
[0] = '\0';
1591 /* Assume the characters indicating the packet type have been
1593 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1594 pkt
= unpack_threadid (pkt
, &ref
);
1597 warning (_("Incomplete response to threadinfo request."));
1598 if (!threadmatch (&ref
, expectedref
))
1599 { /* This is an answer to a different request. */
1600 warning (_("ERROR RMT Thread info mismatch."));
1603 copy_threadref (&info
->threadid
, &ref
);
1605 /* Loop on tagged fields , try to bail if somthing goes wrong. */
1607 /* Packets are terminated with nulls. */
1608 while ((pkt
< limit
) && mask
&& *pkt
)
1610 pkt
= unpack_int (pkt
, &tag
); /* tag */
1611 pkt
= unpack_byte (pkt
, &length
); /* length */
1612 if (!(tag
& mask
)) /* Tags out of synch with mask. */
1614 warning (_("ERROR RMT: threadinfo tag mismatch."));
1618 if (tag
== TAG_THREADID
)
1622 warning (_("ERROR RMT: length of threadid is not 16."));
1626 pkt
= unpack_threadid (pkt
, &ref
);
1627 mask
= mask
& ~TAG_THREADID
;
1630 if (tag
== TAG_EXISTS
)
1632 info
->active
= stub_unpack_int (pkt
, length
);
1634 mask
= mask
& ~(TAG_EXISTS
);
1637 warning (_("ERROR RMT: 'exists' length too long."));
1643 if (tag
== TAG_THREADNAME
)
1645 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1646 mask
= mask
& ~TAG_THREADNAME
;
1649 if (tag
== TAG_DISPLAY
)
1651 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1652 mask
= mask
& ~TAG_DISPLAY
;
1655 if (tag
== TAG_MOREDISPLAY
)
1657 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1658 mask
= mask
& ~TAG_MOREDISPLAY
;
1661 warning (_("ERROR RMT: unknown thread info tag."));
1662 break; /* Not a tag we know about. */
1668 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1669 struct gdb_ext_thread_info
*info
)
1671 struct remote_state
*rs
= get_remote_state ();
1674 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
1676 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1677 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
1682 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1685 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1686 threadref
*nextthread
)
1688 *pkt
++ = 'q'; /* info query packet */
1689 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1690 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1691 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1692 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1697 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1700 parse_threadlist_response (char *pkt
, int result_limit
,
1701 threadref
*original_echo
, threadref
*resultlist
,
1704 struct remote_state
*rs
= get_remote_state ();
1706 int count
, resultcount
, done
;
1709 /* Assume the 'q' and 'M chars have been stripped. */
1710 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
1711 /* done parse past here */
1712 pkt
= unpack_byte (pkt
, &count
); /* count field */
1713 pkt
= unpack_nibble (pkt
, &done
);
1714 /* The first threadid is the argument threadid. */
1715 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1716 while ((count
-- > 0) && (pkt
< limit
))
1718 pkt
= unpack_threadid (pkt
, resultlist
++);
1719 if (resultcount
++ >= result_limit
)
1728 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1729 int *done
, int *result_count
, threadref
*threadlist
)
1731 struct remote_state
*rs
= get_remote_state ();
1732 static threadref echo_nextthread
;
1735 /* Trancate result limit to be smaller than the packet size. */
1736 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= get_remote_packet_size ())
1737 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
1739 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
1741 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1743 if (*rs
->buf
== '\0')
1747 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
1750 if (!threadmatch (&echo_nextthread
, nextthread
))
1752 /* FIXME: This is a good reason to drop the packet. */
1753 /* Possably, there is a duplicate response. */
1755 retransmit immediatly - race conditions
1756 retransmit after timeout - yes
1758 wait for packet, then exit
1760 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
1761 return 0; /* I choose simply exiting. */
1763 if (*result_count
<= 0)
1767 warning (_("RMT ERROR : failed to get remote thread list."));
1770 return result
; /* break; */
1772 if (*result_count
> result_limit
)
1775 warning (_("RMT ERROR: threadlist response longer than requested."));
1781 /* This is the interface between remote and threads, remotes upper
1784 /* remote_find_new_threads retrieves the thread list and for each
1785 thread in the list, looks up the thread in GDB's internal list,
1786 ading the thread if it does not already exist. This involves
1787 getting partial thread lists from the remote target so, polling the
1788 quit_flag is required. */
1791 /* About this many threadisds fit in a packet. */
1793 #define MAXTHREADLISTRESULTS 32
1796 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1799 int done
, i
, result_count
;
1803 static threadref nextthread
;
1804 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1809 if (loopcount
++ > looplimit
)
1812 warning (_("Remote fetch threadlist -infinite loop-."));
1815 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1816 &done
, &result_count
, resultthreadlist
))
1821 /* Clear for later iterations. */
1823 /* Setup to resume next batch of thread references, set nextthread. */
1824 if (result_count
>= 1)
1825 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1827 while (result_count
--)
1828 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1835 remote_newthread_step (threadref
*ref
, void *context
)
1839 ptid
= pid_to_ptid (threadref_to_int (ref
));
1841 if (!in_thread_list (ptid
))
1843 return 1; /* continue iterator */
1846 #define CRAZY_MAX_THREADS 1000
1849 remote_current_thread (ptid_t oldpid
)
1851 struct remote_state
*rs
= get_remote_state ();
1854 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1855 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
1856 /* Use strtoul here, so we'll correctly parse values whose highest
1857 bit is set. The protocol carries them as a simple series of
1858 hex digits; in the absence of a sign, strtol will see such
1859 values as positive numbers out of range for signed 'long', and
1860 return LONG_MAX to indicate an overflow. */
1861 return pid_to_ptid (strtoul (&rs
->buf
[2], NULL
, 16));
1866 /* Find new threads for info threads command.
1867 * Original version, using John Metzler's thread protocol.
1871 remote_find_new_threads (void)
1873 remote_threadlist_iterator (remote_newthread_step
, 0,
1875 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1876 inferior_ptid
= remote_current_thread (inferior_ptid
);
1880 * Find all threads for info threads command.
1881 * Uses new thread protocol contributed by Cisco.
1882 * Falls back and attempts to use the older method (above)
1883 * if the target doesn't respond to the new method.
1887 remote_threads_info (void)
1889 struct remote_state
*rs
= get_remote_state ();
1893 if (remote_desc
== 0) /* paranoia */
1894 error (_("Command can only be used when connected to the remote target."));
1896 if (use_threadinfo_query
)
1898 putpkt ("qfThreadInfo");
1899 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1901 if (bufp
[0] != '\0') /* q packet recognized */
1903 while (*bufp
++ == 'm') /* reply contains one or more TID */
1907 /* Use strtoul here, so we'll correctly parse values
1908 whose highest bit is set. The protocol carries
1909 them as a simple series of hex digits; in the
1910 absence of a sign, strtol will see such values as
1911 positive numbers out of range for signed 'long',
1912 and return LONG_MAX to indicate an overflow. */
1913 tid
= strtoul (bufp
, &bufp
, 16);
1914 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1915 add_thread (pid_to_ptid (tid
));
1917 while (*bufp
++ == ','); /* comma-separated list */
1918 putpkt ("qsThreadInfo");
1919 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1926 /* Else fall back to old method based on jmetzler protocol. */
1927 use_threadinfo_query
= 0;
1928 remote_find_new_threads ();
1933 * Collect a descriptive string about the given thread.
1934 * The target may say anything it wants to about the thread
1935 * (typically info about its blocked / runnable state, name, etc.).
1936 * This string will appear in the info threads display.
1938 * Optional: targets are not required to implement this function.
1942 remote_threads_extra_info (struct thread_info
*tp
)
1944 struct remote_state
*rs
= get_remote_state ();
1948 struct gdb_ext_thread_info threadinfo
;
1949 static char display_buf
[100]; /* arbitrary... */
1950 int n
= 0; /* position in display_buf */
1952 if (remote_desc
== 0) /* paranoia */
1953 internal_error (__FILE__
, __LINE__
,
1954 _("remote_threads_extra_info"));
1956 if (use_threadextra_query
)
1958 xsnprintf (rs
->buf
, get_remote_packet_size (), "qThreadExtraInfo,%x",
1961 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1962 if (rs
->buf
[0] != 0)
1964 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
1965 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
1966 display_buf
[result
] = '\0';
1971 /* If the above query fails, fall back to the old method. */
1972 use_threadextra_query
= 0;
1973 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1974 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1975 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1976 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1977 if (threadinfo
.active
)
1979 if (*threadinfo
.shortname
)
1980 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
1981 " Name: %s,", threadinfo
.shortname
);
1982 if (*threadinfo
.display
)
1983 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
1984 " State: %s,", threadinfo
.display
);
1985 if (*threadinfo
.more_display
)
1986 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
1987 " Priority: %s", threadinfo
.more_display
);
1991 /* For purely cosmetic reasons, clear up trailing commas. */
1992 if (',' == display_buf
[n
-1])
1993 display_buf
[n
-1] = ' ';
2001 /* Restart the remote side; this is an extended protocol operation. */
2004 extended_remote_restart (void)
2006 struct remote_state
*rs
= get_remote_state ();
2008 /* Send the restart command; for reasons I don't understand the
2009 remote side really expects a number after the "R". */
2010 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2013 remote_fileio_reset ();
2016 /* Clean up connection to a remote debugger. */
2019 remote_close (int quitting
)
2022 serial_close (remote_desc
);
2026 /* Query the remote side for the text, data and bss offsets. */
2031 struct remote_state
*rs
= get_remote_state ();
2034 int lose
, num_segments
= 0, do_sections
, do_segments
;
2035 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
2036 struct section_offsets
*offs
;
2037 struct symfile_segment_data
*data
;
2039 if (symfile_objfile
== NULL
)
2042 putpkt ("qOffsets");
2043 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2046 if (buf
[0] == '\000')
2047 return; /* Return silently. Stub doesn't support
2051 warning (_("Remote failure reply: %s"), buf
);
2055 /* Pick up each field in turn. This used to be done with scanf, but
2056 scanf will make trouble if CORE_ADDR size doesn't match
2057 conversion directives correctly. The following code will work
2058 with any size of CORE_ADDR. */
2059 text_addr
= data_addr
= bss_addr
= 0;
2063 if (strncmp (ptr
, "Text=", 5) == 0)
2066 /* Don't use strtol, could lose on big values. */
2067 while (*ptr
&& *ptr
!= ';')
2068 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2070 if (strncmp (ptr
, ";Data=", 6) == 0)
2073 while (*ptr
&& *ptr
!= ';')
2074 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2079 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
2082 while (*ptr
&& *ptr
!= ';')
2083 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
2085 if (bss_addr
!= data_addr
)
2086 warning (_("Target reported unsupported offsets: %s"), buf
);
2091 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
2094 /* Don't use strtol, could lose on big values. */
2095 while (*ptr
&& *ptr
!= ';')
2096 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2099 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
2102 while (*ptr
&& *ptr
!= ';')
2103 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2111 error (_("Malformed response to offset query, %s"), buf
);
2112 else if (*ptr
!= '\0')
2113 warning (_("Target reported unsupported offsets: %s"), buf
);
2115 offs
= ((struct section_offsets
*)
2116 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
2117 memcpy (offs
, symfile_objfile
->section_offsets
,
2118 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2120 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
2121 do_segments
= (data
!= NULL
);
2122 do_sections
= num_segments
== 0;
2124 if (num_segments
> 0)
2126 segments
[0] = text_addr
;
2127 segments
[1] = data_addr
;
2129 /* If we have two segments, we can still try to relocate everything
2130 by assuming that the .text and .data offsets apply to the whole
2131 text and data segments. Convert the offsets given in the packet
2132 to base addresses for symfile_map_offsets_to_segments. */
2133 else if (data
&& data
->num_segments
== 2)
2135 segments
[0] = data
->segment_bases
[0] + text_addr
;
2136 segments
[1] = data
->segment_bases
[1] + data_addr
;
2139 /* There's no way to relocate by segment. */
2145 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
2146 offs
, num_segments
, segments
);
2148 if (ret
== 0 && !do_sections
)
2149 error (_("Can not handle qOffsets TextSeg response with this symbol file"));
2156 free_symfile_segment_data (data
);
2160 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2162 /* This is a temporary kludge to force data and bss to use the same offsets
2163 because that's what nlmconv does now. The real solution requires changes
2164 to the stub and remote.c that I don't have time to do right now. */
2166 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2167 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2170 objfile_relocate (symfile_objfile
, offs
);
2173 /* Stub for catch_exception. */
2175 struct start_remote_args
2179 /* The current target. */
2180 struct target_ops
*target
;
2182 /* Non-zero if this is an extended-remote target. */
2187 remote_start_remote (struct ui_out
*uiout
, void *opaque
)
2189 struct remote_state
*rs
= get_remote_state ();
2190 struct start_remote_args
*args
= opaque
;
2191 char *wait_status
= NULL
;
2193 immediate_quit
++; /* Allow user to interrupt it. */
2195 /* Ack any packet which the remote side has already sent. */
2196 serial_write (remote_desc
, "+", 1);
2198 /* Check whether the target is running now. */
2200 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2202 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
2204 if (args
->extended_p
)
2206 /* We're connected, but not running. Drop out before we
2207 call start_remote. */
2208 target_mark_exited (args
->target
);
2212 error (_("The target is not running (try extended-remote?)"));
2216 if (args
->extended_p
)
2217 target_mark_running (args
->target
);
2219 /* Save the reply for later. */
2220 wait_status
= alloca (strlen (rs
->buf
) + 1);
2221 strcpy (wait_status
, rs
->buf
);
2224 /* Let the stub know that we want it to return the thread. */
2227 /* Without this, some commands which require an active target
2228 (such as kill) won't work. This variable serves (at least)
2229 double duty as both the pid of the target process (if it has
2230 such), and as a flag indicating that a target is active.
2231 These functions should be split out into seperate variables,
2232 especially since GDB will someday have a notion of debugging
2233 several processes. */
2234 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2236 /* Now, if we have thread information, update inferior_ptid. */
2237 inferior_ptid
= remote_current_thread (inferior_ptid
);
2239 get_offsets (); /* Get text, data & bss offsets. */
2241 /* Use the previously fetched status. */
2242 gdb_assert (wait_status
!= NULL
);
2243 strcpy (rs
->buf
, wait_status
);
2244 rs
->cached_wait_status
= 1;
2247 start_remote (args
->from_tty
); /* Initialize gdb process mechanisms. */
2250 /* Open a connection to a remote debugger.
2251 NAME is the filename used for communication. */
2254 remote_open (char *name
, int from_tty
)
2256 remote_open_1 (name
, from_tty
, &remote_ops
, 0, 0);
2259 /* Just like remote_open, but with asynchronous support. */
2261 remote_async_open (char *name
, int from_tty
)
2263 remote_open_1 (name
, from_tty
, &remote_async_ops
, 0, 1);
2266 /* Open a connection to a remote debugger using the extended
2267 remote gdb protocol. NAME is the filename used for communication. */
2270 extended_remote_open (char *name
, int from_tty
)
2272 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */,
2276 /* Just like extended_remote_open, but with asynchronous support. */
2278 extended_remote_async_open (char *name
, int from_tty
)
2280 remote_open_1 (name
, from_tty
, &extended_async_remote_ops
,
2281 1 /*extended_p */, 1 /* async_p */);
2284 /* Generic code for opening a connection to a remote target. */
2287 init_all_packet_configs (void)
2290 for (i
= 0; i
< PACKET_MAX
; i
++)
2291 update_packet_config (&remote_protocol_packets
[i
]);
2294 /* Symbol look-up. */
2297 remote_check_symbols (struct objfile
*objfile
)
2299 struct remote_state
*rs
= get_remote_state ();
2300 char *msg
, *reply
, *tmp
;
2301 struct minimal_symbol
*sym
;
2304 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
2307 /* Allocate a message buffer. We can't reuse the input buffer in RS,
2308 because we need both at the same time. */
2309 msg
= alloca (get_remote_packet_size ());
2311 /* Invite target to request symbol lookups. */
2313 putpkt ("qSymbol::");
2314 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2315 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
2318 while (strncmp (reply
, "qSymbol:", 8) == 0)
2321 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
2323 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2325 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
2328 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
2330 /* If this is a function address, return the start of code
2331 instead of any data function descriptor. */
2332 sym_addr
= gdbarch_convert_from_func_ptr_addr (current_gdbarch
,
2336 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
2337 paddr_nz (sym_addr
), &reply
[8]);
2341 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2346 static struct serial
*
2347 remote_serial_open (char *name
)
2349 static int udp_warning
= 0;
2351 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2352 of in ser-tcp.c, because it is the remote protocol assuming that the
2353 serial connection is reliable and not the serial connection promising
2355 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2358 The remote protocol may be unreliable over UDP.\n\
2359 Some events may be lost, rendering further debugging impossible."));
2363 return serial_open (name
);
2366 /* This type describes each known response to the qSupported
2368 struct protocol_feature
2370 /* The name of this protocol feature. */
2373 /* The default for this protocol feature. */
2374 enum packet_support default_support
;
2376 /* The function to call when this feature is reported, or after
2377 qSupported processing if the feature is not supported.
2378 The first argument points to this structure. The second
2379 argument indicates whether the packet requested support be
2380 enabled, disabled, or probed (or the default, if this function
2381 is being called at the end of processing and this feature was
2382 not reported). The third argument may be NULL; if not NULL, it
2383 is a NUL-terminated string taken from the packet following
2384 this feature's name and an equals sign. */
2385 void (*func
) (const struct protocol_feature
*, enum packet_support
,
2388 /* The corresponding packet for this feature. Only used if
2389 FUNC is remote_supported_packet. */
2394 remote_supported_packet (const struct protocol_feature
*feature
,
2395 enum packet_support support
,
2396 const char *argument
)
2400 warning (_("Remote qSupported response supplied an unexpected value for"
2401 " \"%s\"."), feature
->name
);
2405 if (remote_protocol_packets
[feature
->packet
].support
2406 == PACKET_SUPPORT_UNKNOWN
)
2407 remote_protocol_packets
[feature
->packet
].support
= support
;
2411 remote_packet_size (const struct protocol_feature
*feature
,
2412 enum packet_support support
, const char *value
)
2414 struct remote_state
*rs
= get_remote_state ();
2419 if (support
!= PACKET_ENABLE
)
2422 if (value
== NULL
|| *value
== '\0')
2424 warning (_("Remote target reported \"%s\" without a size."),
2430 packet_size
= strtol (value
, &value_end
, 16);
2431 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
2433 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
2434 feature
->name
, value
);
2438 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
2440 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
2441 packet_size
, MAX_REMOTE_PACKET_SIZE
);
2442 packet_size
= MAX_REMOTE_PACKET_SIZE
;
2445 /* Record the new maximum packet size. */
2446 rs
->explicit_packet_size
= packet_size
;
2449 static struct protocol_feature remote_protocol_features
[] = {
2450 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
2451 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
2452 PACKET_qXfer_auxv
},
2453 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
2454 PACKET_qXfer_features
},
2455 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
2456 PACKET_qXfer_libraries
},
2457 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
2458 PACKET_qXfer_memory_map
},
2459 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
2460 PACKET_qXfer_spu_read
},
2461 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
2462 PACKET_qXfer_spu_write
},
2463 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
2464 PACKET_QPassSignals
},
2468 remote_query_supported (void)
2470 struct remote_state
*rs
= get_remote_state ();
2473 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
2475 /* The packet support flags are handled differently for this packet
2476 than for most others. We treat an error, a disabled packet, and
2477 an empty response identically: any features which must be reported
2478 to be used will be automatically disabled. An empty buffer
2479 accomplishes this, since that is also the representation for a list
2480 containing no features. */
2483 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
2485 putpkt ("qSupported");
2486 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2488 /* If an error occured, warn, but do not return - just reset the
2489 buffer to empty and go on to disable features. */
2490 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
2493 warning (_("Remote failure reply: %s"), rs
->buf
);
2498 memset (seen
, 0, sizeof (seen
));
2503 enum packet_support is_supported
;
2504 char *p
, *end
, *name_end
, *value
;
2506 /* First separate out this item from the rest of the packet. If
2507 there's another item after this, we overwrite the separator
2508 (terminated strings are much easier to work with). */
2510 end
= strchr (p
, ';');
2513 end
= p
+ strlen (p
);
2523 warning (_("empty item in \"qSupported\" response"));
2528 name_end
= strchr (p
, '=');
2531 /* This is a name=value entry. */
2532 is_supported
= PACKET_ENABLE
;
2533 value
= name_end
+ 1;
2542 is_supported
= PACKET_ENABLE
;
2546 is_supported
= PACKET_DISABLE
;
2550 is_supported
= PACKET_SUPPORT_UNKNOWN
;
2554 warning (_("unrecognized item \"%s\" in \"qSupported\" response"), p
);
2560 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
2561 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
2563 const struct protocol_feature
*feature
;
2566 feature
= &remote_protocol_features
[i
];
2567 feature
->func (feature
, is_supported
, value
);
2572 /* If we increased the packet size, make sure to increase the global
2573 buffer size also. We delay this until after parsing the entire
2574 qSupported packet, because this is the same buffer we were
2576 if (rs
->buf_size
< rs
->explicit_packet_size
)
2578 rs
->buf_size
= rs
->explicit_packet_size
;
2579 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
2582 /* Handle the defaults for unmentioned features. */
2583 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
2586 const struct protocol_feature
*feature
;
2588 feature
= &remote_protocol_features
[i
];
2589 feature
->func (feature
, feature
->default_support
, NULL
);
2595 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2596 int extended_p
, int async_p
)
2598 struct remote_state
*rs
= get_remote_state ();
2600 error (_("To open a remote debug connection, you need to specify what\n"
2601 "serial device is attached to the remote system\n"
2602 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
2604 /* See FIXME above. */
2606 wait_forever_enabled_p
= 1;
2608 /* If we're connected to a running target, target_preopen will kill it.
2609 But if we're connected to a target system with no running process,
2610 then we will still be connected when it returns. Ask this question
2611 first, before target_preopen has a chance to kill anything. */
2612 if (remote_desc
!= NULL
&& !target_has_execution
)
2615 || query (_("Already connected to a remote target. Disconnect? ")))
2618 error (_("Still connected."));
2621 target_preopen (from_tty
);
2623 unpush_target (target
);
2625 /* This time without a query. If we were connected to an
2626 extended-remote target and target_preopen killed the running
2627 process, we may still be connected. If we are starting "target
2628 remote" now, the extended-remote target will not have been
2629 removed by unpush_target. */
2630 if (remote_desc
!= NULL
&& !target_has_execution
)
2633 /* Make sure we send the passed signals list the next time we resume. */
2634 xfree (last_pass_packet
);
2635 last_pass_packet
= NULL
;
2637 remote_fileio_reset ();
2638 reopen_exec_file ();
2641 remote_desc
= remote_serial_open (name
);
2643 perror_with_name (name
);
2645 if (baud_rate
!= -1)
2647 if (serial_setbaudrate (remote_desc
, baud_rate
))
2649 /* The requested speed could not be set. Error out to
2650 top level after closing remote_desc. Take care to
2651 set remote_desc to NULL to avoid closing remote_desc
2653 serial_close (remote_desc
);
2655 perror_with_name (name
);
2659 serial_raw (remote_desc
);
2661 /* If there is something sitting in the buffer we might take it as a
2662 response to a command, which would be bad. */
2663 serial_flush_input (remote_desc
);
2667 puts_filtered ("Remote debugging using ");
2668 puts_filtered (name
);
2669 puts_filtered ("\n");
2671 push_target (target
); /* Switch to using remote target now. */
2673 /* Assume that the target is running, unless we learn otherwise. */
2674 target_mark_running (target
);
2676 /* Reset the target state; these things will be queried either by
2677 remote_query_supported or as they are needed. */
2678 init_all_packet_configs ();
2679 rs
->explicit_packet_size
= 0;
2681 general_thread
= -2;
2682 continue_thread
= -2;
2684 /* Probe for ability to use "ThreadInfo" query, as required. */
2685 use_threadinfo_query
= 1;
2686 use_threadextra_query
= 1;
2688 /* The first packet we send to the target is the optional "supported
2689 packets" request. If the target can answer this, it will tell us
2690 which later probes to skip. */
2691 remote_query_supported ();
2693 /* Next, if the target can specify a description, read it. We do
2694 this before anything involving memory or registers. */
2695 target_find_description ();
2699 /* With this target we start out by owning the terminal. */
2700 remote_async_terminal_ours_p
= 1;
2702 /* FIXME: cagney/1999-09-23: During the initial connection it is
2703 assumed that the target is already ready and able to respond to
2704 requests. Unfortunately remote_start_remote() eventually calls
2705 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2706 around this. Eventually a mechanism that allows
2707 wait_for_inferior() to expect/get timeouts will be
2709 wait_forever_enabled_p
= 0;
2712 /* First delete any symbols previously loaded from shared libraries. */
2713 no_shared_libraries (NULL
, 0);
2715 /* Start the remote connection. If error() or QUIT, discard this
2716 target (we'd otherwise be in an inconsistent state) and then
2717 propogate the error on up the exception chain. This ensures that
2718 the caller doesn't stumble along blindly assuming that the
2719 function succeeded. The CLI doesn't have this problem but other
2720 UI's, such as MI do.
2722 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2723 this function should return an error indication letting the
2724 caller restore the previous state. Unfortunately the command
2725 ``target remote'' is directly wired to this function making that
2726 impossible. On a positive note, the CLI side of this problem has
2727 been fixed - the function set_cmd_context() makes it possible for
2728 all the ``target ....'' commands to share a common callback
2729 function. See cli-dump.c. */
2731 struct gdb_exception ex
;
2732 struct start_remote_args args
;
2734 args
.from_tty
= from_tty
;
2735 args
.target
= target
;
2736 args
.extended_p
= extended_p
;
2738 ex
= catch_exception (uiout
, remote_start_remote
, &args
, RETURN_MASK_ALL
);
2743 wait_forever_enabled_p
= 1;
2744 throw_exception (ex
);
2749 wait_forever_enabled_p
= 1;
2753 /* Tell the remote that we are using the extended protocol. */
2755 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2758 /* If we connected to a live target, do some additional setup. */
2759 if (target_has_execution
)
2761 if (exec_bfd
) /* No use without an exec file. */
2762 remote_check_symbols (symfile_objfile
);
2766 /* This takes a program previously attached to and detaches it. After
2767 this is done, GDB can be used to debug some other program. We
2768 better not have left any breakpoints in the target program or it'll
2769 die when it hits one. */
2772 remote_detach_1 (char *args
, int from_tty
, int extended
)
2774 struct remote_state
*rs
= get_remote_state ();
2777 error (_("Argument given to \"detach\" when remotely debugging."));
2779 if (!target_has_execution
)
2780 error (_("No process to detach from."));
2782 /* Tell the remote target to detach. */
2783 strcpy (rs
->buf
, "D");
2785 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2787 if (rs
->buf
[0] == 'E')
2788 error (_("Can't detach process."));
2790 /* Unregister the file descriptor from the event loop. */
2791 if (target_is_async_p ())
2792 serial_async (remote_desc
, NULL
, 0);
2794 target_mourn_inferior ();
2798 puts_filtered ("Detached from remote process.\n");
2800 puts_filtered ("Ending remote debugging.\n");
2805 remote_detach (char *args
, int from_tty
)
2807 remote_detach_1 (args
, from_tty
, 0);
2811 extended_remote_detach (char *args
, int from_tty
)
2813 remote_detach_1 (args
, from_tty
, 1);
2816 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
2819 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
2822 error (_("Argument given to \"disconnect\" when remotely debugging."));
2824 /* Unregister the file descriptor from the event loop. */
2825 if (target_is_async_p ())
2826 serial_async (remote_desc
, NULL
, 0);
2828 /* Make sure we unpush even the extended remote targets; mourn
2829 won't do it. So call remote_mourn_1 directly instead of
2830 target_mourn_inferior. */
2831 remote_mourn_1 (target
);
2834 puts_filtered ("Ending remote debugging.\n");
2837 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
2838 be chatty about it. */
2841 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
2843 struct remote_state
*rs
= get_remote_state ();
2848 error_no_arg (_("process-id to attach"));
2851 pid
= strtol (args
, &dummy
, 0);
2852 /* Some targets don't set errno on errors, grrr! */
2853 if (pid
== 0 && args
== dummy
)
2854 error (_("Illegal process-id: %s."), args
);
2856 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
2857 error (_("This target does not support attaching to a process"));
2859 sprintf (rs
->buf
, "vAttach;%x", pid
);
2861 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2863 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
2866 printf_unfiltered (_("Attached to %s\n"),
2867 target_pid_to_str (pid_to_ptid (pid
)));
2869 /* We have a wait response; reuse it. */
2870 rs
->cached_wait_status
= 1;
2872 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
2873 error (_("This target does not support attaching to a process"));
2875 error (_("Attaching to %s failed"),
2876 target_pid_to_str (pid_to_ptid (pid
)));
2878 target_mark_running (target
);
2879 inferior_ptid
= pid_to_ptid (pid
);
2884 extended_remote_attach (char *args
, int from_tty
)
2886 extended_remote_attach_1 (&extended_remote_ops
, args
, from_tty
);
2890 extended_async_remote_attach (char *args
, int from_tty
)
2892 extended_remote_attach_1 (&extended_async_remote_ops
, args
, from_tty
);
2895 /* Convert hex digit A to a number. */
2900 if (a
>= '0' && a
<= '9')
2902 else if (a
>= 'a' && a
<= 'f')
2903 return a
- 'a' + 10;
2904 else if (a
>= 'A' && a
<= 'F')
2905 return a
- 'A' + 10;
2907 error (_("Reply contains invalid hex digit %d"), a
);
2911 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
2915 for (i
= 0; i
< count
; i
++)
2917 if (hex
[0] == 0 || hex
[1] == 0)
2919 /* Hex string is short, or of uneven length.
2920 Return the count that has been converted so far. */
2923 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2929 /* Convert number NIB to a hex digit. */
2937 return 'a' + nib
- 10;
2941 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
2944 /* May use a length, or a nul-terminated string as input. */
2946 count
= strlen ((char *) bin
);
2948 for (i
= 0; i
< count
; i
++)
2950 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2951 *hex
++ = tohex (*bin
++ & 0xf);
2957 /* Check for the availability of vCont. This function should also check
2961 remote_vcont_probe (struct remote_state
*rs
)
2965 strcpy (rs
->buf
, "vCont?");
2967 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2970 /* Make sure that the features we assume are supported. */
2971 if (strncmp (buf
, "vCont", 5) == 0)
2974 int support_s
, support_S
, support_c
, support_C
;
2980 while (p
&& *p
== ';')
2983 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2985 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2987 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2989 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2992 p
= strchr (p
, ';');
2995 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
2996 BUF will make packet_ok disable the packet. */
2997 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
3001 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
3004 /* Resume the remote inferior by using a "vCont" packet. The thread
3005 to be resumed is PTID; STEP and SIGGNAL indicate whether the
3006 resumed thread should be single-stepped and/or signalled. If PTID's
3007 PID is -1, then all threads are resumed; the thread to be stepped and/or
3008 signalled is given in the global INFERIOR_PTID. This function returns
3009 non-zero iff it resumes the inferior.
3011 This function issues a strict subset of all possible vCont commands at the
3015 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
3017 struct remote_state
*rs
= get_remote_state ();
3018 int pid
= PIDGET (ptid
);
3020 struct cleanup
*old_cleanup
;
3022 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
3023 remote_vcont_probe (rs
);
3025 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
3028 /* If we could generate a wider range of packets, we'd have to worry
3029 about overflowing BUF. Should there be a generic
3030 "multi-part-packet" packet? */
3032 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
)
3034 /* MAGIC_NULL_PTID means that we don't have any active threads, so we
3035 don't have any PID numbers the inferior will understand. Make sure
3036 to only send forms that do not specify a PID. */
3037 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
3038 outbuf
= xstrprintf ("vCont;S%02x", siggnal
);
3040 outbuf
= xstrprintf ("vCont;s");
3041 else if (siggnal
!= TARGET_SIGNAL_0
)
3042 outbuf
= xstrprintf ("vCont;C%02x", siggnal
);
3044 outbuf
= xstrprintf ("vCont;c");
3048 /* Resume all threads, with preference for INFERIOR_PTID. */
3049 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
3050 outbuf
= xstrprintf ("vCont;S%02x:%x;c", siggnal
,
3051 PIDGET (inferior_ptid
));
3053 outbuf
= xstrprintf ("vCont;s:%x;c", PIDGET (inferior_ptid
));
3054 else if (siggnal
!= TARGET_SIGNAL_0
)
3055 outbuf
= xstrprintf ("vCont;C%02x:%x;c", siggnal
,
3056 PIDGET (inferior_ptid
));
3058 outbuf
= xstrprintf ("vCont;c");
3062 /* Scheduler locking; resume only PTID. */
3063 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
3064 outbuf
= xstrprintf ("vCont;S%02x:%x", siggnal
, pid
);
3066 outbuf
= xstrprintf ("vCont;s:%x", pid
);
3067 else if (siggnal
!= TARGET_SIGNAL_0
)
3068 outbuf
= xstrprintf ("vCont;C%02x:%x", siggnal
, pid
);
3070 outbuf
= xstrprintf ("vCont;c:%x", pid
);
3073 gdb_assert (outbuf
&& strlen (outbuf
) < get_remote_packet_size ());
3074 old_cleanup
= make_cleanup (xfree
, outbuf
);
3078 do_cleanups (old_cleanup
);
3083 /* Tell the remote machine to resume. */
3085 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
3087 static int last_sent_step
;
3090 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
3092 struct remote_state
*rs
= get_remote_state ();
3094 int pid
= PIDGET (ptid
);
3096 last_sent_signal
= siggnal
;
3097 last_sent_step
= step
;
3099 /* A hook for when we need to do something at the last moment before
3101 if (deprecated_target_resume_hook
)
3102 (*deprecated_target_resume_hook
) ();
3104 /* Update the inferior on signals to silently pass, if they've changed. */
3105 remote_pass_signals ();
3107 /* The vCont packet doesn't need to specify threads via Hc. */
3108 if (remote_vcont_resume (ptid
, step
, siggnal
))
3111 /* All other supported resume packets do use Hc, so call set_thread. */
3113 set_thread (0, 0); /* Run any thread. */
3115 set_thread (pid
, 0); /* Run this thread. */
3118 if (siggnal
!= TARGET_SIGNAL_0
)
3120 buf
[0] = step
? 'S' : 'C';
3121 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
3122 buf
[2] = tohex (((int) siggnal
) & 0xf);
3126 strcpy (buf
, step
? "s" : "c");
3131 /* Same as remote_resume, but with async support. */
3133 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
3135 remote_resume (ptid
, step
, siggnal
);
3137 /* We are about to start executing the inferior, let's register it
3138 with the event loop. NOTE: this is the one place where all the
3139 execution commands end up. We could alternatively do this in each
3140 of the execution commands in infcmd.c. */
3141 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
3142 into infcmd.c in order to allow inferior function calls to work
3143 NOT asynchronously. */
3144 if (target_can_async_p ())
3145 target_async (inferior_event_handler
, 0);
3146 /* Tell the world that the target is now executing. */
3147 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
3148 this? Instead, should the client of target just assume (for
3149 async targets) that the target is going to start executing? Is
3150 this information already found in the continuation block? */
3151 if (target_is_async_p ())
3152 target_executing
= 1;
3156 /* Set up the signal handler for SIGINT, while the target is
3157 executing, ovewriting the 'regular' SIGINT signal handler. */
3159 initialize_sigint_signal_handler (void)
3161 signal (SIGINT
, handle_remote_sigint
);
3164 /* Signal handler for SIGINT, while the target is executing. */
3166 handle_remote_sigint (int sig
)
3168 signal (sig
, handle_remote_sigint_twice
);
3169 mark_async_signal_handler_wrapper (sigint_remote_token
);
3172 /* Signal handler for SIGINT, installed after SIGINT has already been
3173 sent once. It will take effect the second time that the user sends
3176 handle_remote_sigint_twice (int sig
)
3178 signal (sig
, handle_remote_sigint
);
3179 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
3182 /* Perform the real interruption of the target execution, in response
3185 async_remote_interrupt (gdb_client_data arg
)
3188 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
3193 /* Perform interrupt, if the first attempt did not succeed. Just give
3194 up on the target alltogether. */
3196 async_remote_interrupt_twice (gdb_client_data arg
)
3199 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
3204 /* Reinstall the usual SIGINT handlers, after the target has
3207 cleanup_sigint_signal_handler (void *dummy
)
3209 signal (SIGINT
, handle_sigint
);
3212 /* Send ^C to target to halt it. Target will respond, and send us a
3214 static void (*ofunc
) (int);
3216 /* The command line interface's stop routine. This function is installed
3217 as a signal handler for SIGINT. The first time a user requests a
3218 stop, we call remote_stop to send a break or ^C. If there is no
3219 response from the target (it didn't stop when the user requested it),
3220 we ask the user if he'd like to detach from the target. */
3222 remote_interrupt (int signo
)
3224 /* If this doesn't work, try more severe steps. */
3225 signal (signo
, remote_interrupt_twice
);
3227 gdb_call_async_signal_handler (sigint_remote_token
, 1);
3230 /* The user typed ^C twice. */
3233 remote_interrupt_twice (int signo
)
3235 signal (signo
, ofunc
);
3236 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
3237 signal (signo
, remote_interrupt
);
3240 /* This is the generic stop called via the target vector. When a target
3241 interrupt is requested, either by the command line or the GUI, we
3242 will eventually end up here. */
3246 /* Send a break or a ^C, depending on user preference. */
3248 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
3251 serial_send_break (remote_desc
);
3253 serial_write (remote_desc
, "\003", 1);
3256 /* Ask the user what to do when an interrupt is received. */
3259 interrupt_query (void)
3261 target_terminal_ours ();
3263 if (query ("Interrupted while waiting for the program.\n\
3264 Give up (and stop debugging it)? "))
3266 target_mourn_inferior ();
3267 signal (SIGINT
, handle_sigint
);
3268 deprecated_throw_reason (RETURN_QUIT
);
3271 target_terminal_inferior ();
3274 /* Enable/disable target terminal ownership. Most targets can use
3275 terminal groups to control terminal ownership. Remote targets are
3276 different in that explicit transfer of ownership to/from GDB/target
3280 remote_async_terminal_inferior (void)
3282 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
3283 sync_execution here. This function should only be called when
3284 GDB is resuming the inferior in the forground. A background
3285 resume (``run&'') should leave GDB in control of the terminal and
3286 consequently should not call this code. */
3287 if (!sync_execution
)
3289 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
3290 calls target_terminal_*() idenpotent. The event-loop GDB talking
3291 to an asynchronous target with a synchronous command calls this
3292 function from both event-top.c and infrun.c/infcmd.c. Once GDB
3293 stops trying to transfer the terminal to the target when it
3294 shouldn't this guard can go away. */
3295 if (!remote_async_terminal_ours_p
)
3297 delete_file_handler (input_fd
);
3298 remote_async_terminal_ours_p
= 0;
3299 initialize_sigint_signal_handler ();
3300 /* NOTE: At this point we could also register our selves as the
3301 recipient of all input. Any characters typed could then be
3302 passed on down to the target. */
3306 remote_async_terminal_ours (void)
3308 /* See FIXME in remote_async_terminal_inferior. */
3309 if (!sync_execution
)
3311 /* See FIXME in remote_async_terminal_inferior. */
3312 if (remote_async_terminal_ours_p
)
3314 cleanup_sigint_signal_handler (NULL
);
3315 add_file_handler (input_fd
, stdin_event_handler
, 0);
3316 remote_async_terminal_ours_p
= 1;
3319 /* If nonzero, ignore the next kill. */
3324 remote_console_output (char *msg
)
3328 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
3331 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
3334 fputs_unfiltered (tb
, gdb_stdtarg
);
3336 gdb_flush (gdb_stdtarg
);
3339 /* Wait until the remote machine stops, then return,
3340 storing status in STATUS just as `wait' would.
3341 Returns "pid", which in the case of a multi-threaded
3342 remote OS, is the thread-id. */
3345 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3347 struct remote_state
*rs
= get_remote_state ();
3348 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3349 ULONGEST thread_num
= -1;
3351 int solibs_changed
= 0;
3353 status
->kind
= TARGET_WAITKIND_EXITED
;
3354 status
->value
.integer
= 0;
3360 if (rs
->cached_wait_status
)
3361 /* Use the cached wait status, but only once. */
3362 rs
->cached_wait_status
= 0;
3365 ofunc
= signal (SIGINT
, remote_interrupt
);
3366 /* If the user hit C-c before this packet, or between packets,
3367 pretend that it was hit right here. */
3371 remote_interrupt (SIGINT
);
3373 getpkt (&rs
->buf
, &rs
->buf_size
, 1);
3374 signal (SIGINT
, ofunc
);
3379 /* This is a hook for when we need to do something (perhaps the
3380 collection of trace data) every time the target stops. */
3381 if (deprecated_target_wait_loop_hook
)
3382 (*deprecated_target_wait_loop_hook
) ();
3384 remote_stopped_by_watchpoint_p
= 0;
3388 case 'E': /* Error of some sort. */
3389 /* We're out of sync with the target now. Did it continue or not?
3390 Not is more likely, so report a stop. */
3391 warning (_("Remote failure reply: %s"), buf
);
3392 status
->kind
= TARGET_WAITKIND_STOPPED
;
3393 status
->value
.sig
= TARGET_SIGNAL_0
;
3395 case 'F': /* File-I/O request. */
3396 remote_fileio_request (buf
);
3398 case 'T': /* Status with PC, SP, FP, ... */
3400 gdb_byte regs
[MAX_REGISTER_SIZE
];
3402 /* Expedited reply, containing Signal, {regno, reg} repeat. */
3403 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3405 n... = register number
3406 r... = register contents
3408 p
= &buf
[3]; /* after Txx */
3417 /* If the packet contains a register number save it in
3418 pnum and set p1 to point to the character following
3419 it. Otherwise p1 points to p. */
3421 /* If this packet is an awatch packet, don't parse the
3422 'a' as a register number. */
3424 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
3426 /* Read the ``P'' register number. */
3427 pnum
= strtol (p
, &p_temp
, 16);
3433 if (p1
== p
) /* No register number present here. */
3435 p1
= strchr (p
, ':');
3437 error (_("Malformed packet(a) (missing colon): %s\n\
3440 if (strncmp (p
, "thread", p1
- p
) == 0)
3442 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3443 record_currthread (thread_num
);
3446 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3447 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3448 || (strncmp (p
, "awatch", p1
- p
) == 0))
3450 remote_stopped_by_watchpoint_p
= 1;
3451 p
= unpack_varlen_hex (++p1
, &addr
);
3452 remote_watch_data_address
= (CORE_ADDR
)addr
;
3454 else if (strncmp (p
, "library", p1
- p
) == 0)
3458 while (*p_temp
&& *p_temp
!= ';')
3466 /* Silently skip unknown optional info. */
3467 p_temp
= strchr (p1
+ 1, ';');
3474 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
3478 error (_("Malformed packet(b) (missing colon): %s\n\
3483 error (_("Remote sent bad register number %s: %s\n\
3485 phex_nz (pnum
, 0), p
, buf
);
3487 fieldsize
= hex2bin (p
, regs
,
3488 register_size (current_gdbarch
,
3491 if (fieldsize
< register_size (current_gdbarch
,
3493 warning (_("Remote reply is too short: %s"), buf
);
3494 regcache_raw_supply (get_current_regcache (),
3499 error (_("Remote register badly formatted: %s\nhere: %s"),
3504 case 'S': /* Old style status, just signal only. */
3506 status
->kind
= TARGET_WAITKIND_LOADED
;
3509 status
->kind
= TARGET_WAITKIND_STOPPED
;
3510 status
->value
.sig
= (enum target_signal
)
3511 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3516 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3517 record_currthread (thread_num
);
3520 case 'W': /* Target exited. */
3522 /* The remote process exited. */
3523 status
->kind
= TARGET_WAITKIND_EXITED
;
3524 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3528 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3529 status
->value
.sig
= (enum target_signal
)
3530 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3534 case 'O': /* Console output. */
3535 remote_console_output (buf
+ 1);
3538 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3540 /* Zero length reply means that we tried 'S' or 'C' and
3541 the remote system doesn't support it. */
3542 target_terminal_ours_for_output ();
3544 ("Can't send signals to this remote system. %s not sent.\n",
3545 target_signal_to_name (last_sent_signal
));
3546 last_sent_signal
= TARGET_SIGNAL_0
;
3547 target_terminal_inferior ();
3549 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3550 putpkt ((char *) buf
);
3553 /* else fallthrough */
3555 warning (_("Invalid remote reply: %s"), buf
);
3560 if (thread_num
!= -1)
3562 return pid_to_ptid (thread_num
);
3564 return inferior_ptid
;
3567 /* Async version of remote_wait. */
3569 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3571 struct remote_state
*rs
= get_remote_state ();
3572 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3573 ULONGEST thread_num
= -1;
3575 int solibs_changed
= 0;
3577 status
->kind
= TARGET_WAITKIND_EXITED
;
3578 status
->value
.integer
= 0;
3580 remote_stopped_by_watchpoint_p
= 0;
3586 if (rs
->cached_wait_status
)
3587 /* Use the cached wait status, but only once. */
3588 rs
->cached_wait_status
= 0;
3591 if (!target_is_async_p ())
3593 ofunc
= signal (SIGINT
, remote_interrupt
);
3594 /* If the user hit C-c before this packet, or between packets,
3595 pretend that it was hit right here. */
3599 remote_interrupt (SIGINT
);
3602 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3603 _never_ wait for ever -> test on target_is_async_p().
3604 However, before we do that we need to ensure that the caller
3605 knows how to take the target into/out of async mode. */
3606 getpkt (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
3607 if (!target_is_async_p ())
3608 signal (SIGINT
, ofunc
);
3613 /* This is a hook for when we need to do something (perhaps the
3614 collection of trace data) every time the target stops. */
3615 if (deprecated_target_wait_loop_hook
)
3616 (*deprecated_target_wait_loop_hook
) ();
3620 case 'E': /* Error of some sort. */
3621 /* We're out of sync with the target now. Did it continue or not?
3622 Not is more likely, so report a stop. */
3623 warning (_("Remote failure reply: %s"), buf
);
3624 status
->kind
= TARGET_WAITKIND_STOPPED
;
3625 status
->value
.sig
= TARGET_SIGNAL_0
;
3627 case 'F': /* File-I/O request. */
3628 remote_fileio_request (buf
);
3630 case 'T': /* Status with PC, SP, FP, ... */
3632 gdb_byte regs
[MAX_REGISTER_SIZE
];
3634 /* Expedited reply, containing Signal, {regno, reg} repeat. */
3635 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3637 n... = register number
3638 r... = register contents
3640 p
= &buf
[3]; /* after Txx */
3649 /* If the packet contains a register number, save it
3650 in pnum and set p1 to point to the character
3651 following it. Otherwise p1 points to p. */
3653 /* If this packet is an awatch packet, don't parse the 'a'
3654 as a register number. */
3656 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
3658 /* Read the register number. */
3659 pnum
= strtol (p
, &p_temp
, 16);
3665 if (p1
== p
) /* No register number present here. */
3667 p1
= strchr (p
, ':');
3669 error (_("Malformed packet(a) (missing colon): %s\n\
3672 if (strncmp (p
, "thread", p1
- p
) == 0)
3674 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3675 record_currthread (thread_num
);
3678 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3679 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3680 || (strncmp (p
, "awatch", p1
- p
) == 0))
3682 remote_stopped_by_watchpoint_p
= 1;
3683 p
= unpack_varlen_hex (++p1
, &addr
);
3684 remote_watch_data_address
= (CORE_ADDR
)addr
;
3686 else if (strncmp (p
, "library", p1
- p
) == 0)
3690 while (*p_temp
&& *p_temp
!= ';')
3698 /* Silently skip unknown optional info. */
3699 p_temp
= strchr (p1
+ 1, ';');
3707 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
3710 error (_("Malformed packet(b) (missing colon): %s\n\
3715 error (_("Remote sent bad register number %ld: %s\n\
3719 fieldsize
= hex2bin (p
, regs
,
3720 register_size (current_gdbarch
,
3723 if (fieldsize
< register_size (current_gdbarch
,
3725 warning (_("Remote reply is too short: %s"), buf
);
3726 regcache_raw_supply (get_current_regcache (),
3731 error (_("Remote register badly formatted: %s\nhere: %s"),
3736 case 'S': /* Old style status, just signal only. */
3738 status
->kind
= TARGET_WAITKIND_LOADED
;
3741 status
->kind
= TARGET_WAITKIND_STOPPED
;
3742 status
->value
.sig
= (enum target_signal
)
3743 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3748 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3749 record_currthread (thread_num
);
3752 case 'W': /* Target exited. */
3754 /* The remote process exited. */
3755 status
->kind
= TARGET_WAITKIND_EXITED
;
3756 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3760 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3761 status
->value
.sig
= (enum target_signal
)
3762 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3766 case 'O': /* Console output. */
3767 remote_console_output (buf
+ 1);
3768 /* Return immediately to the event loop. The event loop will
3769 still be waiting on the inferior afterwards. */
3770 status
->kind
= TARGET_WAITKIND_IGNORE
;
3773 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3775 /* Zero length reply means that we tried 'S' or 'C' and
3776 the remote system doesn't support it. */
3777 target_terminal_ours_for_output ();
3779 ("Can't send signals to this remote system. %s not sent.\n",
3780 target_signal_to_name (last_sent_signal
));
3781 last_sent_signal
= TARGET_SIGNAL_0
;
3782 target_terminal_inferior ();
3784 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3785 putpkt ((char *) buf
);
3788 /* else fallthrough */
3790 warning (_("Invalid remote reply: %s"), buf
);
3795 if (thread_num
!= -1)
3797 return pid_to_ptid (thread_num
);
3799 return inferior_ptid
;
3802 /* Fetch a single register using a 'p' packet. */
3805 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
3807 struct remote_state
*rs
= get_remote_state ();
3809 char regp
[MAX_REGISTER_SIZE
];
3812 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
3815 if (reg
->pnum
== -1)
3820 p
+= hexnumstr (p
, reg
->pnum
);
3822 remote_send (&rs
->buf
, &rs
->buf_size
);
3826 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
3830 case PACKET_UNKNOWN
:
3833 error (_("Could not fetch register \"%s\""),
3834 gdbarch_register_name (get_regcache_arch (regcache
), reg
->regnum
));
3837 /* If this register is unfetchable, tell the regcache. */
3840 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
3844 /* Otherwise, parse and supply the value. */
3850 error (_("fetch_register_using_p: early buf termination"));
3852 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3855 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
3859 /* Fetch the registers included in the target's 'g' packet. */
3862 send_g_packet (void)
3864 struct remote_state
*rs
= get_remote_state ();
3869 sprintf (rs
->buf
, "g");
3870 remote_send (&rs
->buf
, &rs
->buf_size
);
3872 /* We can get out of synch in various cases. If the first character
3873 in the buffer is not a hex character, assume that has happened
3874 and try to fetch another packet to read. */
3875 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
3876 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
3877 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
3878 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
3881 fprintf_unfiltered (gdb_stdlog
,
3882 "Bad register packet; fetching a new packet\n");
3883 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3886 buf_len
= strlen (rs
->buf
);
3888 /* Sanity check the received packet. */
3889 if (buf_len
% 2 != 0)
3890 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
3896 process_g_packet (struct regcache
*regcache
)
3898 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3899 struct remote_state
*rs
= get_remote_state ();
3900 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3905 buf_len
= strlen (rs
->buf
);
3907 /* Further sanity checks, with knowledge of the architecture. */
3908 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
3909 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
3911 /* Save the size of the packet sent to us by the target. It is used
3912 as a heuristic when determining the max size of packets that the
3913 target can safely receive. */
3914 if (rsa
->actual_register_packet_size
== 0)
3915 rsa
->actual_register_packet_size
= buf_len
;
3917 /* If this is smaller than we guessed the 'g' packet would be,
3918 update our records. A 'g' reply that doesn't include a register's
3919 value implies either that the register is not available, or that
3920 the 'p' packet must be used. */
3921 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
3923 rsa
->sizeof_g_packet
= buf_len
/ 2;
3925 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
3927 if (rsa
->regs
[i
].pnum
== -1)
3930 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
3931 rsa
->regs
[i
].in_g_packet
= 0;
3933 rsa
->regs
[i
].in_g_packet
= 1;
3937 regs
= alloca (rsa
->sizeof_g_packet
);
3939 /* Unimplemented registers read as all bits zero. */
3940 memset (regs
, 0, rsa
->sizeof_g_packet
);
3942 /* Reply describes registers byte by byte, each byte encoded as two
3943 hex characters. Suck them all up, then supply them to the
3944 register cacheing/storage mechanism. */
3947 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
3949 if (p
[0] == 0 || p
[1] == 0)
3950 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
3951 internal_error (__FILE__
, __LINE__
,
3952 "unexpected end of 'g' packet reply");
3954 if (p
[0] == 'x' && p
[1] == 'x')
3955 regs
[i
] = 0; /* 'x' */
3957 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3963 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
3965 struct packet_reg
*r
= &rsa
->regs
[i
];
3968 if (r
->offset
* 2 >= strlen (rs
->buf
))
3969 /* This shouldn't happen - we adjusted in_g_packet above. */
3970 internal_error (__FILE__
, __LINE__
,
3971 "unexpected end of 'g' packet reply");
3972 else if (rs
->buf
[r
->offset
* 2] == 'x')
3974 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
3975 /* The register isn't available, mark it as such (at
3976 the same time setting the value to zero). */
3977 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
3980 regcache_raw_supply (regcache
, r
->regnum
,
3988 fetch_registers_using_g (struct regcache
*regcache
)
3991 process_g_packet (regcache
);
3995 remote_fetch_registers (struct regcache
*regcache
, int regnum
)
3997 struct remote_state
*rs
= get_remote_state ();
3998 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4001 set_thread (PIDGET (inferior_ptid
), 1);
4005 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
4006 gdb_assert (reg
!= NULL
);
4008 /* If this register might be in the 'g' packet, try that first -
4009 we are likely to read more than one register. If this is the
4010 first 'g' packet, we might be overly optimistic about its
4011 contents, so fall back to 'p'. */
4012 if (reg
->in_g_packet
)
4014 fetch_registers_using_g (regcache
);
4015 if (reg
->in_g_packet
)
4019 if (fetch_register_using_p (regcache
, reg
))
4022 /* This register is not available. */
4023 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
4028 fetch_registers_using_g (regcache
);
4030 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
4031 if (!rsa
->regs
[i
].in_g_packet
)
4032 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
4034 /* This register is not available. */
4035 regcache_raw_supply (regcache
, i
, NULL
);
4039 /* Prepare to store registers. Since we may send them all (using a
4040 'G' request), we have to read out the ones we don't want to change
4044 remote_prepare_to_store (struct regcache
*regcache
)
4046 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4048 gdb_byte buf
[MAX_REGISTER_SIZE
];
4050 /* Make sure the entire registers array is valid. */
4051 switch (remote_protocol_packets
[PACKET_P
].support
)
4053 case PACKET_DISABLE
:
4054 case PACKET_SUPPORT_UNKNOWN
:
4055 /* Make sure all the necessary registers are cached. */
4056 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
4057 if (rsa
->regs
[i
].in_g_packet
)
4058 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
4065 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
4066 packet was not recognized. */
4069 store_register_using_P (const struct regcache
*regcache
, struct packet_reg
*reg
)
4071 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
4072 struct remote_state
*rs
= get_remote_state ();
4073 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4074 /* Try storing a single register. */
4075 char *buf
= rs
->buf
;
4076 gdb_byte regp
[MAX_REGISTER_SIZE
];
4079 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
4082 if (reg
->pnum
== -1)
4085 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
4086 p
= buf
+ strlen (buf
);
4087 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
4088 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
4089 remote_send (&rs
->buf
, &rs
->buf_size
);
4091 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
4096 error (_("Could not write register \"%s\""),
4097 gdbarch_register_name (gdbarch
, reg
->regnum
));
4098 case PACKET_UNKNOWN
:
4101 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
4105 /* Store register REGNUM, or all registers if REGNUM == -1, from the
4106 contents of the register cache buffer. FIXME: ignores errors. */
4109 store_registers_using_G (const struct regcache
*regcache
)
4111 struct remote_state
*rs
= get_remote_state ();
4112 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4116 /* Extract all the registers in the regcache copying them into a
4120 regs
= alloca (rsa
->sizeof_g_packet
);
4121 memset (regs
, 0, rsa
->sizeof_g_packet
);
4122 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
4124 struct packet_reg
*r
= &rsa
->regs
[i
];
4126 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
4130 /* Command describes registers byte by byte,
4131 each byte encoded as two hex characters. */
4134 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
4136 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
4137 remote_send (&rs
->buf
, &rs
->buf_size
);
4140 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
4141 of the register cache buffer. FIXME: ignores errors. */
4144 remote_store_registers (struct regcache
*regcache
, int regnum
)
4146 struct remote_state
*rs
= get_remote_state ();
4147 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4150 set_thread (PIDGET (inferior_ptid
), 1);
4154 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
4155 gdb_assert (reg
!= NULL
);
4157 /* Always prefer to store registers using the 'P' packet if
4158 possible; we often change only a small number of registers.
4159 Sometimes we change a larger number; we'd need help from a
4160 higher layer to know to use 'G'. */
4161 if (store_register_using_P (regcache
, reg
))
4164 /* For now, don't complain if we have no way to write the
4165 register. GDB loses track of unavailable registers too
4166 easily. Some day, this may be an error. We don't have
4167 any way to read the register, either... */
4168 if (!reg
->in_g_packet
)
4171 store_registers_using_G (regcache
);
4175 store_registers_using_G (regcache
);
4177 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
4178 if (!rsa
->regs
[i
].in_g_packet
)
4179 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
4180 /* See above for why we do not issue an error here. */
4185 /* Return the number of hex digits in num. */
4188 hexnumlen (ULONGEST num
)
4192 for (i
= 0; num
!= 0; i
++)
4198 /* Set BUF to the minimum number of hex digits representing NUM. */
4201 hexnumstr (char *buf
, ULONGEST num
)
4203 int len
= hexnumlen (num
);
4204 return hexnumnstr (buf
, num
, len
);
4208 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
4211 hexnumnstr (char *buf
, ULONGEST num
, int width
)
4217 for (i
= width
- 1; i
>= 0; i
--)
4219 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
4226 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
4229 remote_address_masked (CORE_ADDR addr
)
4231 int address_size
= remote_address_size
;
4232 /* If "remoteaddresssize" was not set, default to target address size. */
4234 address_size
= gdbarch_addr_bit (current_gdbarch
);
4236 if (address_size
> 0
4237 && address_size
< (sizeof (ULONGEST
) * 8))
4239 /* Only create a mask when that mask can safely be constructed
4240 in a ULONGEST variable. */
4242 mask
= (mask
<< address_size
) - 1;
4248 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
4249 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
4250 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
4251 (which may be more than *OUT_LEN due to escape characters). The
4252 total number of bytes in the output buffer will be at most
4256 remote_escape_output (const gdb_byte
*buffer
, int len
,
4257 gdb_byte
*out_buf
, int *out_len
,
4260 int input_index
, output_index
;
4263 for (input_index
= 0; input_index
< len
; input_index
++)
4265 gdb_byte b
= buffer
[input_index
];
4267 if (b
== '$' || b
== '#' || b
== '}')
4269 /* These must be escaped. */
4270 if (output_index
+ 2 > out_maxlen
)
4272 out_buf
[output_index
++] = '}';
4273 out_buf
[output_index
++] = b
^ 0x20;
4277 if (output_index
+ 1 > out_maxlen
)
4279 out_buf
[output_index
++] = b
;
4283 *out_len
= input_index
;
4284 return output_index
;
4287 /* Convert BUFFER, escaped data LEN bytes long, into binary data
4288 in OUT_BUF. Return the number of bytes written to OUT_BUF.
4289 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
4291 This function reverses remote_escape_output. It allows more
4292 escaped characters than that function does, in particular because
4293 '*' must be escaped to avoid the run-length encoding processing
4294 in reading packets. */
4297 remote_unescape_input (const gdb_byte
*buffer
, int len
,
4298 gdb_byte
*out_buf
, int out_maxlen
)
4300 int input_index
, output_index
;
4305 for (input_index
= 0; input_index
< len
; input_index
++)
4307 gdb_byte b
= buffer
[input_index
];
4309 if (output_index
+ 1 > out_maxlen
)
4311 warning (_("Received too much data from remote target;"
4312 " ignoring overflow."));
4313 return output_index
;
4318 out_buf
[output_index
++] = b
^ 0x20;
4324 out_buf
[output_index
++] = b
;
4328 error (_("Unmatched escape character in target response."));
4330 return output_index
;
4333 /* Determine whether the remote target supports binary downloading.
4334 This is accomplished by sending a no-op memory write of zero length
4335 to the target at the specified address. It does not suffice to send
4336 the whole packet, since many stubs strip the eighth bit and
4337 subsequently compute a wrong checksum, which causes real havoc with
4340 NOTE: This can still lose if the serial line is not eight-bit
4341 clean. In cases like this, the user should clear "remote
4345 check_binary_download (CORE_ADDR addr
)
4347 struct remote_state
*rs
= get_remote_state ();
4349 switch (remote_protocol_packets
[PACKET_X
].support
)
4351 case PACKET_DISABLE
:
4355 case PACKET_SUPPORT_UNKNOWN
:
4361 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4363 p
+= hexnumstr (p
, (ULONGEST
) 0);
4367 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
4368 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4370 if (rs
->buf
[0] == '\0')
4373 fprintf_unfiltered (gdb_stdlog
,
4374 "binary downloading NOT suppported by target\n");
4375 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
4380 fprintf_unfiltered (gdb_stdlog
,
4381 "binary downloading suppported by target\n");
4382 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
4389 /* Write memory data directly to the remote machine.
4390 This does not inform the data cache; the data cache uses this.
4391 HEADER is the starting part of the packet.
4392 MEMADDR is the address in the remote memory space.
4393 MYADDR is the address of the buffer in our space.
4394 LEN is the number of bytes.
4395 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
4396 should send data as binary ('X'), or hex-encoded ('M').
4398 The function creates packet of the form
4399 <HEADER><ADDRESS>,<LENGTH>:<DATA>
4401 where encoding of <DATA> is termined by PACKET_FORMAT.
4403 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
4406 Returns the number of bytes transferred, or 0 (setting errno) for
4407 error. Only transfer a single packet. */
4410 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
4411 const gdb_byte
*myaddr
, int len
,
4412 char packet_format
, int use_length
)
4414 struct remote_state
*rs
= get_remote_state ();
4424 if (packet_format
!= 'X' && packet_format
!= 'M')
4425 internal_error (__FILE__
, __LINE__
,
4426 "remote_write_bytes_aux: bad packet format");
4431 payload_size
= get_memory_write_packet_size ();
4433 /* The packet buffer will be large enough for the payload;
4434 get_memory_packet_size ensures this. */
4437 /* Compute the size of the actual payload by subtracting out the
4438 packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
4440 payload_size
-= strlen ("$,:#NN");
4442 /* The comma won't be used. */
4444 header_length
= strlen (header
);
4445 payload_size
-= header_length
;
4446 payload_size
-= hexnumlen (memaddr
);
4448 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
4450 strcat (rs
->buf
, header
);
4451 p
= rs
->buf
+ strlen (header
);
4453 /* Compute a best guess of the number of bytes actually transfered. */
4454 if (packet_format
== 'X')
4456 /* Best guess at number of bytes that will fit. */
4457 todo
= min (len
, payload_size
);
4459 payload_size
-= hexnumlen (todo
);
4460 todo
= min (todo
, payload_size
);
4464 /* Num bytes that will fit. */
4465 todo
= min (len
, payload_size
/ 2);
4467 payload_size
-= hexnumlen (todo
);
4468 todo
= min (todo
, payload_size
/ 2);
4472 internal_error (__FILE__
, __LINE__
,
4473 _("minumum packet size too small to write data"));
4475 /* If we already need another packet, then try to align the end
4476 of this packet to a useful boundary. */
4477 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
4478 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
4480 /* Append "<memaddr>". */
4481 memaddr
= remote_address_masked (memaddr
);
4482 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
4489 /* Append <len>. Retain the location/size of <len>. It may need to
4490 be adjusted once the packet body has been created. */
4492 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
4500 /* Append the packet body. */
4501 if (packet_format
== 'X')
4503 /* Binary mode. Send target system values byte by byte, in
4504 increasing byte addresses. Only escape certain critical
4506 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
4509 /* If not all TODO bytes fit, then we'll need another packet. Make
4510 a second try to keep the end of the packet aligned. Don't do
4511 this if the packet is tiny. */
4512 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
4516 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
4518 if (new_nr_bytes
!= nr_bytes
)
4519 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
4524 p
+= payload_length
;
4525 if (use_length
&& nr_bytes
< todo
)
4527 /* Escape chars have filled up the buffer prematurely,
4528 and we have actually sent fewer bytes than planned.
4529 Fix-up the length field of the packet. Use the same
4530 number of characters as before. */
4531 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
4532 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
4537 /* Normal mode: Send target system values byte by byte, in
4538 increasing byte addresses. Each byte is encoded as a two hex
4540 nr_bytes
= bin2hex (myaddr
, p
, todo
);
4544 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
4545 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4547 if (rs
->buf
[0] == 'E')
4549 /* There is no correspondance between what the remote protocol
4550 uses for errors and errno codes. We would like a cleaner way
4551 of representing errors (big enough to include errno codes,
4552 bfd_error codes, and others). But for now just return EIO. */
4557 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
4558 fewer bytes than we'd planned. */
4562 /* Write memory data directly to the remote machine.
4563 This does not inform the data cache; the data cache uses this.
4564 MEMADDR is the address in the remote memory space.
4565 MYADDR is the address of the buffer in our space.
4566 LEN is the number of bytes.
4568 Returns number of bytes transferred, or 0 (setting errno) for
4569 error. Only transfer a single packet. */
4572 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
4574 char *packet_format
= 0;
4576 /* Check whether the target supports binary download. */
4577 check_binary_download (memaddr
);
4579 switch (remote_protocol_packets
[PACKET_X
].support
)
4582 packet_format
= "X";
4584 case PACKET_DISABLE
:
4585 packet_format
= "M";
4587 case PACKET_SUPPORT_UNKNOWN
:
4588 internal_error (__FILE__
, __LINE__
,
4589 _("remote_write_bytes: bad internal state"));
4591 internal_error (__FILE__
, __LINE__
, _("bad switch"));
4594 return remote_write_bytes_aux (packet_format
,
4595 memaddr
, myaddr
, len
, packet_format
[0], 1);
4598 /* Read memory data directly from the remote machine.
4599 This does not use the data cache; the data cache uses this.
4600 MEMADDR is the address in the remote memory space.
4601 MYADDR is the address of the buffer in our space.
4602 LEN is the number of bytes.
4604 Returns number of bytes transferred, or 0 for error. */
4606 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
4607 remote targets) shouldn't attempt to read the entire buffer.
4608 Instead it should read a single packet worth of data and then
4609 return the byte size of that packet to the caller. The caller (its
4610 caller and its callers caller ;-) already contains code for
4611 handling partial reads. */
4614 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
4616 struct remote_state
*rs
= get_remote_state ();
4617 int max_buf_size
; /* Max size of packet output buffer. */
4623 max_buf_size
= get_memory_read_packet_size ();
4624 /* The packet buffer will be large enough for the payload;
4625 get_memory_packet_size ensures this. */
4634 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
4636 /* construct "m"<memaddr>","<len>" */
4637 /* sprintf (rs->buf, "m%lx,%x", (unsigned long) memaddr, todo); */
4638 memaddr
= remote_address_masked (memaddr
);
4641 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
4643 p
+= hexnumstr (p
, (ULONGEST
) todo
);
4647 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4649 if (rs
->buf
[0] == 'E'
4650 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
4651 && rs
->buf
[3] == '\0')
4653 /* There is no correspondance between what the remote
4654 protocol uses for errors and errno codes. We would like
4655 a cleaner way of representing errors (big enough to
4656 include errno codes, bfd_error codes, and others). But
4657 for now just return EIO. */
4662 /* Reply describes memory byte by byte,
4663 each byte encoded as two hex characters. */
4666 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
4668 /* Reply is short. This means that we were able to read
4669 only part of what we wanted to. */
4670 return i
+ (origlen
- len
);
4679 /* Read or write LEN bytes from inferior memory at MEMADDR,
4680 transferring to or from debugger address BUFFER. Write to inferior
4681 if SHOULD_WRITE is nonzero. Returns length of data written or
4682 read; 0 for error. TARGET is unused. */
4685 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
4686 int should_write
, struct mem_attrib
*attrib
,
4687 struct target_ops
*target
)
4692 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
4694 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
4699 /* Sends a packet with content determined by the printf format string
4700 FORMAT and the remaining arguments, then gets the reply. Returns
4701 whether the packet was a success, a failure, or unknown. */
4704 remote_send_printf (const char *format
, ...)
4706 struct remote_state
*rs
= get_remote_state ();
4707 int max_size
= get_remote_packet_size ();
4710 va_start (ap
, format
);
4713 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
4714 internal_error (__FILE__
, __LINE__
, "Too long remote packet.");
4716 if (putpkt (rs
->buf
) < 0)
4717 error (_("Communication problem with target."));
4720 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4722 return packet_check_result (rs
->buf
);
4726 restore_remote_timeout (void *p
)
4728 int value
= *(int *)p
;
4729 remote_timeout
= value
;
4732 /* Flash writing can take quite some time. We'll set
4733 effectively infinite timeout for flash operations.
4734 In future, we'll need to decide on a better approach. */
4735 static const int remote_flash_timeout
= 1000;
4738 remote_flash_erase (struct target_ops
*ops
,
4739 ULONGEST address
, LONGEST length
)
4741 int saved_remote_timeout
= remote_timeout
;
4742 enum packet_result ret
;
4744 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
4745 &saved_remote_timeout
);
4746 remote_timeout
= remote_flash_timeout
;
4748 ret
= remote_send_printf ("vFlashErase:%s,%s",
4753 case PACKET_UNKNOWN
:
4754 error (_("Remote target does not support flash erase"));
4756 error (_("Error erasing flash with vFlashErase packet"));
4761 do_cleanups (back_to
);
4765 remote_flash_write (struct target_ops
*ops
,
4766 ULONGEST address
, LONGEST length
,
4767 const gdb_byte
*data
)
4769 int saved_remote_timeout
= remote_timeout
;
4771 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
4772 &saved_remote_timeout
);
4774 remote_timeout
= remote_flash_timeout
;
4775 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
4776 do_cleanups (back_to
);
4782 remote_flash_done (struct target_ops
*ops
)
4784 int saved_remote_timeout
= remote_timeout
;
4786 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
4787 &saved_remote_timeout
);
4789 remote_timeout
= remote_flash_timeout
;
4790 ret
= remote_send_printf ("vFlashDone");
4791 do_cleanups (back_to
);
4795 case PACKET_UNKNOWN
:
4796 error (_("Remote target does not support vFlashDone"));
4798 error (_("Error finishing flash operation"));
4805 remote_files_info (struct target_ops
*ignore
)
4807 puts_filtered ("Debugging a target over a serial line.\n");
4810 /* Stuff for dealing with the packets which are part of this protocol.
4811 See comment at top of file for details. */
4813 /* Read a single character from the remote end. */
4816 readchar (int timeout
)
4820 ch
= serial_readchar (remote_desc
, timeout
);
4825 switch ((enum serial_rc
) ch
)
4828 target_mourn_inferior ();
4829 error (_("Remote connection closed"));
4832 perror_with_name (_("Remote communication error"));
4834 case SERIAL_TIMEOUT
:
4840 /* Send the command in *BUF to the remote machine, and read the reply
4841 into *BUF. Report an error if we get an error reply. Resize
4842 *BUF using xrealloc if necessary to hold the result, and update
4846 remote_send (char **buf
,
4850 getpkt (buf
, sizeof_buf
, 0);
4852 if ((*buf
)[0] == 'E')
4853 error (_("Remote failure reply: %s"), *buf
);
4856 /* Display a null-terminated packet on stdout, for debugging, using C
4860 print_packet (char *buf
)
4862 puts_filtered ("\"");
4863 fputstr_filtered (buf
, '"', gdb_stdout
);
4864 puts_filtered ("\"");
4870 return putpkt_binary (buf
, strlen (buf
));
4873 /* Send a packet to the remote machine, with error checking. The data
4874 of the packet is in BUF. The string in BUF can be at most
4875 get_remote_packet_size () - 5 to account for the $, # and checksum,
4876 and for a possible /0 if we are debugging (remote_debug) and want
4877 to print the sent packet as a string. */
4880 putpkt_binary (char *buf
, int cnt
)
4882 struct remote_state
*rs
= get_remote_state ();
4884 unsigned char csum
= 0;
4885 char *buf2
= alloca (cnt
+ 6);
4891 /* We're sending out a new packet. Make sure we don't look at a
4892 stale cached response. */
4893 rs
->cached_wait_status
= 0;
4895 /* Copy the packet into buffer BUF2, encapsulating it
4896 and giving it a checksum. */
4901 for (i
= 0; i
< cnt
; i
++)
4907 *p
++ = tohex ((csum
>> 4) & 0xf);
4908 *p
++ = tohex (csum
& 0xf);
4910 /* Send it over and over until we get a positive ack. */
4914 int started_error_output
= 0;
4919 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4920 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4921 fprintf_unfiltered (gdb_stdlog
, "...");
4922 gdb_flush (gdb_stdlog
);
4924 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4925 perror_with_name (_("putpkt: write failed"));
4927 /* Read until either a timeout occurs (-2) or '+' is read. */
4930 ch
= readchar (remote_timeout
);
4938 case SERIAL_TIMEOUT
:
4940 if (started_error_output
)
4942 putchar_unfiltered ('\n');
4943 started_error_output
= 0;
4952 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4956 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4957 case SERIAL_TIMEOUT
:
4961 break; /* Retransmit buffer. */
4965 fprintf_unfiltered (gdb_stdlog
,
4966 "Packet instead of Ack, ignoring it\n");
4967 /* It's probably an old response sent because an ACK
4968 was lost. Gobble up the packet and ack it so it
4969 doesn't get retransmitted when we resend this
4972 serial_write (remote_desc
, "+", 1);
4973 continue; /* Now, go look for +. */
4978 if (!started_error_output
)
4980 started_error_output
= 1;
4981 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4983 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4987 break; /* Here to retransmit. */
4991 /* This is wrong. If doing a long backtrace, the user should be
4992 able to get out next time we call QUIT, without anything as
4993 violent as interrupt_query. If we want to provide a way out of
4994 here without getting to the next QUIT, it should be based on
4995 hitting ^C twice as in remote_wait. */
5005 /* Come here after finding the start of a frame when we expected an
5006 ack. Do our best to discard the rest of this packet. */
5015 c
= readchar (remote_timeout
);
5018 case SERIAL_TIMEOUT
:
5019 /* Nothing we can do. */
5022 /* Discard the two bytes of checksum and stop. */
5023 c
= readchar (remote_timeout
);
5025 c
= readchar (remote_timeout
);
5028 case '*': /* Run length encoding. */
5029 /* Discard the repeat count. */
5030 c
= readchar (remote_timeout
);
5035 /* A regular character. */
5041 /* Come here after finding the start of the frame. Collect the rest
5042 into *BUF, verifying the checksum, length, and handling run-length
5043 compression. NUL terminate the buffer. If there is not enough room,
5044 expand *BUF using xrealloc.
5046 Returns -1 on error, number of characters in buffer (ignoring the
5047 trailing NULL) on success. (could be extended to return one of the
5048 SERIAL status indications). */
5051 read_frame (char **buf_p
,
5064 c
= readchar (remote_timeout
);
5067 case SERIAL_TIMEOUT
:
5069 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
5073 fputs_filtered ("Saw new packet start in middle of old one\n",
5075 return -1; /* Start a new packet, count retries. */
5078 unsigned char pktcsum
;
5084 check_0
= readchar (remote_timeout
);
5086 check_1
= readchar (remote_timeout
);
5088 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
5091 fputs_filtered ("Timeout in checksum, retrying\n",
5095 else if (check_0
< 0 || check_1
< 0)
5098 fputs_filtered ("Communication error in checksum\n",
5103 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
5104 if (csum
== pktcsum
)
5109 fprintf_filtered (gdb_stdlog
,
5110 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
5112 fputstrn_filtered (buf
, bc
, 0, gdb_stdlog
);
5113 fputs_filtered ("\n", gdb_stdlog
);
5115 /* Number of characters in buffer ignoring trailing
5119 case '*': /* Run length encoding. */
5124 c
= readchar (remote_timeout
);
5126 repeat
= c
- ' ' + 3; /* Compute repeat count. */
5128 /* The character before ``*'' is repeated. */
5130 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
5132 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
5134 /* Make some more room in the buffer. */
5135 *sizeof_buf
+= repeat
;
5136 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
5140 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
5146 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
5150 if (bc
>= *sizeof_buf
- 1)
5152 /* Make some more room in the buffer. */
5154 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
5165 /* Read a packet from the remote machine, with error checking, and
5166 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
5167 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
5168 rather than timing out; this is used (in synchronous mode) to wait
5169 for a target that is is executing user code to stop. */
5170 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
5171 don't have to change all the calls to getpkt to deal with the
5172 return value, because at the moment I don't know what the right
5173 thing to do it for those. */
5181 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
5185 /* Read a packet from the remote machine, with error checking, and
5186 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
5187 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
5188 rather than timing out; this is used (in synchronous mode) to wait
5189 for a target that is is executing user code to stop. If FOREVER ==
5190 0, this function is allowed to time out gracefully and return an
5191 indication of this to the caller. Otherwise return the number
5194 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
5196 struct remote_state
*rs
= get_remote_state ();
5202 /* We're reading a new response. Make sure we don't look at a
5203 previously cached response. */
5204 rs
->cached_wait_status
= 0;
5206 strcpy (*buf
, "timeout");
5210 timeout
= watchdog
> 0 ? watchdog
: -1;
5214 timeout
= remote_timeout
;
5218 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
5220 /* This can loop forever if the remote side sends us characters
5221 continuously, but if it pauses, we'll get a zero from
5222 readchar because of timeout. Then we'll count that as a
5225 /* Note that we will only wait forever prior to the start of a
5226 packet. After that, we expect characters to arrive at a
5227 brisk pace. They should show up within remote_timeout
5232 c
= readchar (timeout
);
5234 if (c
== SERIAL_TIMEOUT
)
5236 if (forever
) /* Watchdog went off? Kill the target. */
5239 target_mourn_inferior ();
5240 error (_("Watchdog timeout has expired. Target detached."));
5243 fputs_filtered ("Timed out.\n", gdb_stdlog
);
5249 /* We've found the start of a packet, now collect the data. */
5251 val
= read_frame (buf
, sizeof_buf
);
5257 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
5258 fputstrn_unfiltered (*buf
, val
, 0, gdb_stdlog
);
5259 fprintf_unfiltered (gdb_stdlog
, "\n");
5261 serial_write (remote_desc
, "+", 1);
5265 /* Try the whole thing again. */
5267 serial_write (remote_desc
, "-", 1);
5270 /* We have tried hard enough, and just can't receive the packet.
5273 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
5274 serial_write (remote_desc
, "+", 1);
5281 /* For some mysterious reason, wait_for_inferior calls kill instead of
5282 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
5286 target_mourn_inferior ();
5290 /* Use catch_errors so the user can quit from gdb even when we aren't on
5291 speaking terms with the remote system. */
5292 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
5294 /* Don't wait for it to die. I'm not really sure it matters whether
5295 we do or not. For the existing stubs, kill is a noop. */
5296 target_mourn_inferior ();
5299 /* Async version of remote_kill. */
5301 remote_async_kill (void)
5303 /* Unregister the file descriptor from the event loop. */
5304 if (target_is_async_p ())
5305 serial_async (remote_desc
, NULL
, 0);
5307 /* For some mysterious reason, wait_for_inferior calls kill instead of
5308 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
5312 target_mourn_inferior ();
5316 /* Use catch_errors so the user can quit from gdb even when we
5317 aren't on speaking terms with the remote system. */
5318 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
5320 /* Don't wait for it to die. I'm not really sure it matters whether
5321 we do or not. For the existing stubs, kill is a noop. */
5322 target_mourn_inferior ();
5328 remote_mourn_1 (&remote_ops
);
5332 remote_async_mourn (void)
5334 remote_mourn_1 (&remote_async_ops
);
5337 /* Worker function for remote_mourn. */
5339 remote_mourn_1 (struct target_ops
*target
)
5341 unpush_target (target
);
5342 generic_mourn_inferior ();
5346 extended_remote_mourn_1 (struct target_ops
*target
)
5348 struct remote_state
*rs
= get_remote_state ();
5350 /* Unlike "target remote", we do not want to unpush the target; then
5351 the next time the user says "run", we won't be connected. */
5353 /* Call common code to mark the inferior as not running. */
5354 generic_mourn_inferior ();
5356 /* Check whether the target is running now - some remote stubs
5357 automatically restart after kill. */
5359 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5361 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
5363 /* Assume that the target has been restarted. Set inferior_ptid
5364 so that bits of core GDB realizes there's something here, e.g.,
5365 so that the user can say "kill" again. */
5366 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
5370 /* Mark this (still pushed) target as not executable until we
5372 target_mark_exited (target
);
5377 extended_remote_mourn (void)
5379 extended_remote_mourn_1 (&extended_remote_ops
);
5383 extended_async_remote_mourn (void)
5385 extended_remote_mourn_1 (&extended_async_remote_ops
);
5389 extended_remote_run (char *args
)
5391 struct remote_state
*rs
= get_remote_state ();
5395 /* If the user has disabled vRun support, or we have detected that
5396 support is not available, do not try it. */
5397 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
5400 strcpy (rs
->buf
, "vRun;");
5401 len
= strlen (rs
->buf
);
5403 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
5404 error (_("Remote file name too long for run packet"));
5405 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
5409 struct cleanup
*back_to
;
5413 argv
= buildargv (args
);
5414 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
5415 for (i
= 0; argv
[i
] != NULL
; i
++)
5417 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
5418 error (_("Argument list too long for run packet"));
5419 rs
->buf
[len
++] = ';';
5420 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
5422 do_cleanups (back_to
);
5425 rs
->buf
[len
++] = '\0';
5428 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5430 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
5432 /* We have a wait response; we don't need it, though. All is well. */
5435 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
5436 /* It wasn't disabled before, but it is now. */
5440 if (remote_exec_file
[0] == '\0')
5441 error (_("Running the default executable on the remote target failed; "
5442 "try \"set remote exec-file\"?"));
5444 error (_("Running \"%s\" on the remote target failed"),
5449 /* In the extended protocol we want to be able to do things like
5450 "run" and have them basically work as expected. So we need
5451 a special create_inferior function. We support changing the
5452 executable file and the command line arguments, but not the
5456 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
5457 char **env
, int from_tty
,
5460 /* If running asynchronously, register the target file descriptor
5461 with the event loop. */
5462 if (async_p
&& target_can_async_p ())
5463 target_async (inferior_event_handler
, 0);
5465 /* Now restart the remote server. */
5466 if (extended_remote_run (args
) == -1)
5468 /* vRun was not supported. Fail if we need it to do what the
5470 if (remote_exec_file
[0])
5471 error (_("Remote target does not support \"set remote exec-file\""));
5473 error (_("Remote target does not support \"set args\" or run <ARGS>"));
5475 /* Fall back to "R". */
5476 extended_remote_restart ();
5479 /* Now mark the inferior as running before we do anything else. */
5481 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
5483 target_mark_running (&extended_async_remote_ops
);
5485 target_mark_running (&extended_remote_ops
);
5487 /* Get updated offsets, if the stub uses qOffsets. */
5490 /* Clean up from the last time we were running. */
5491 init_thread_list ();
5492 init_wait_for_inferior ();
5496 extended_remote_create_inferior (char *exec_file
, char *args
,
5497 char **env
, int from_tty
)
5499 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
, 0);
5503 extended_remote_async_create_inferior (char *exec_file
, char *args
,
5504 char **env
, int from_tty
)
5506 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
, 1);
5510 /* Insert a breakpoint. On targets that have software breakpoint
5511 support, we ask the remote target to do the work; on targets
5512 which don't, we insert a traditional memory breakpoint. */
5515 remote_insert_breakpoint (struct bp_target_info
*bp_tgt
)
5517 CORE_ADDR addr
= bp_tgt
->placed_address
;
5518 struct remote_state
*rs
= get_remote_state ();
5520 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
5521 If it succeeds, then set the support to PACKET_ENABLE. If it
5522 fails, and the user has explicitly requested the Z support then
5523 report an error, otherwise, mark it disabled and go on. */
5525 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
5532 gdbarch_breakpoint_from_pc
5533 (current_gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
5534 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
5535 p
+= hexnumstr (p
, addr
);
5536 sprintf (p
, ",%d", bp_tgt
->placed_size
);
5539 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5541 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
5547 case PACKET_UNKNOWN
:
5552 return memory_insert_breakpoint (bp_tgt
);
5556 remote_remove_breakpoint (struct bp_target_info
*bp_tgt
)
5558 CORE_ADDR addr
= bp_tgt
->placed_address
;
5559 struct remote_state
*rs
= get_remote_state ();
5562 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
5570 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
5571 p
+= hexnumstr (p
, addr
);
5572 sprintf (p
, ",%d", bp_tgt
->placed_size
);
5575 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5577 return (rs
->buf
[0] == 'E');
5580 return memory_remove_breakpoint (bp_tgt
);
5584 watchpoint_to_Z_packet (int type
)
5589 return Z_PACKET_WRITE_WP
;
5592 return Z_PACKET_READ_WP
;
5595 return Z_PACKET_ACCESS_WP
;
5598 internal_error (__FILE__
, __LINE__
,
5599 _("hw_bp_to_z: bad watchpoint type %d"), type
);
5604 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
5606 struct remote_state
*rs
= get_remote_state ();
5608 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
5610 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
5613 sprintf (rs
->buf
, "Z%x,", packet
);
5614 p
= strchr (rs
->buf
, '\0');
5615 addr
= remote_address_masked (addr
);
5616 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5617 sprintf (p
, ",%x", len
);
5620 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5622 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
5625 case PACKET_UNKNOWN
:
5630 internal_error (__FILE__
, __LINE__
,
5631 _("remote_insert_watchpoint: reached end of function"));
5636 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
5638 struct remote_state
*rs
= get_remote_state ();
5640 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
5642 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
5645 sprintf (rs
->buf
, "z%x,", packet
);
5646 p
= strchr (rs
->buf
, '\0');
5647 addr
= remote_address_masked (addr
);
5648 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5649 sprintf (p
, ",%x", len
);
5651 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5653 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
5656 case PACKET_UNKNOWN
:
5661 internal_error (__FILE__
, __LINE__
,
5662 _("remote_remove_watchpoint: reached end of function"));
5666 int remote_hw_watchpoint_limit
= -1;
5667 int remote_hw_breakpoint_limit
= -1;
5670 remote_check_watch_resources (int type
, int cnt
, int ot
)
5672 if (type
== bp_hardware_breakpoint
)
5674 if (remote_hw_breakpoint_limit
== 0)
5676 else if (remote_hw_breakpoint_limit
< 0)
5678 else if (cnt
<= remote_hw_breakpoint_limit
)
5683 if (remote_hw_watchpoint_limit
== 0)
5685 else if (remote_hw_watchpoint_limit
< 0)
5689 else if (cnt
<= remote_hw_watchpoint_limit
)
5696 remote_stopped_by_watchpoint (void)
5698 return remote_stopped_by_watchpoint_p
;
5702 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
5705 if (remote_stopped_by_watchpoint ())
5707 *addr_p
= remote_watch_data_address
;
5716 remote_insert_hw_breakpoint (struct bp_target_info
*bp_tgt
)
5719 struct remote_state
*rs
= get_remote_state ();
5722 /* The length field should be set to the size of a breakpoint
5723 instruction, even though we aren't inserting one ourselves. */
5725 gdbarch_breakpoint_from_pc
5726 (current_gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
5728 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
5735 addr
= remote_address_masked (bp_tgt
->placed_address
);
5736 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5737 sprintf (p
, ",%x", bp_tgt
->placed_size
);
5740 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5742 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
5745 case PACKET_UNKNOWN
:
5750 internal_error (__FILE__
, __LINE__
,
5751 _("remote_insert_hw_breakpoint: reached end of function"));
5756 remote_remove_hw_breakpoint (struct bp_target_info
*bp_tgt
)
5759 struct remote_state
*rs
= get_remote_state ();
5762 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
5769 addr
= remote_address_masked (bp_tgt
->placed_address
);
5770 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5771 sprintf (p
, ",%x", bp_tgt
->placed_size
);
5774 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5776 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
5779 case PACKET_UNKNOWN
:
5784 internal_error (__FILE__
, __LINE__
,
5785 _("remote_remove_hw_breakpoint: reached end of function"));
5788 /* Some targets are only capable of doing downloads, and afterwards
5789 they switch to the remote serial protocol. This function provides
5790 a clean way to get from the download target to the remote target.
5791 It's basically just a wrapper so that we don't have to expose any
5792 of the internal workings of remote.c.
5794 Prior to calling this routine, you should shutdown the current
5795 target code, else you will get the "A program is being debugged
5796 already..." message. Usually a call to pop_target() suffices. */
5799 push_remote_target (char *name
, int from_tty
)
5801 printf_filtered (_("Switching to remote protocol\n"));
5802 remote_open (name
, from_tty
);
5805 /* Table used by the crc32 function to calcuate the checksum. */
5807 static unsigned long crc32_table
[256] =
5810 static unsigned long
5811 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
5813 if (!crc32_table
[1])
5815 /* Initialize the CRC table and the decoding table. */
5819 for (i
= 0; i
< 256; i
++)
5821 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
5822 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
5829 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
5835 /* compare-sections command
5837 With no arguments, compares each loadable section in the exec bfd
5838 with the same memory range on the target, and reports mismatches.
5839 Useful for verifying the image on the target against the exec file.
5840 Depends on the target understanding the new "qCRC:" request. */
5842 /* FIXME: cagney/1999-10-26: This command should be broken down into a
5843 target method (target verify memory) and generic version of the
5844 actual command. This will allow other high-level code (especially
5845 generic_load()) to make use of this target functionality. */
5848 compare_sections_command (char *args
, int from_tty
)
5850 struct remote_state
*rs
= get_remote_state ();
5852 unsigned long host_crc
, target_crc
;
5853 extern bfd
*exec_bfd
;
5854 struct cleanup
*old_chain
;
5857 const char *sectname
;
5864 error (_("command cannot be used without an exec file"));
5865 if (!current_target
.to_shortname
||
5866 strcmp (current_target
.to_shortname
, "remote") != 0)
5867 error (_("command can only be used with remote target"));
5869 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
5871 if (!(s
->flags
& SEC_LOAD
))
5872 continue; /* skip non-loadable section */
5874 size
= bfd_get_section_size (s
);
5876 continue; /* skip zero-length section */
5878 sectname
= bfd_get_section_name (exec_bfd
, s
);
5879 if (args
&& strcmp (args
, sectname
) != 0)
5880 continue; /* not the section selected by user */
5882 matched
= 1; /* do this section */
5884 /* FIXME: assumes lma can fit into long. */
5885 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
5886 (long) lma
, (long) size
);
5889 /* Be clever; compute the host_crc before waiting for target
5891 sectdata
= xmalloc (size
);
5892 old_chain
= make_cleanup (xfree
, sectdata
);
5893 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
5894 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
5896 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5897 if (rs
->buf
[0] == 'E')
5898 error (_("target memory fault, section %s, range 0x%s -- 0x%s"),
5899 sectname
, paddr (lma
), paddr (lma
+ size
));
5900 if (rs
->buf
[0] != 'C')
5901 error (_("remote target does not support this operation"));
5903 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
5904 target_crc
= target_crc
* 16 + fromhex (*tmp
);
5906 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
5907 sectname
, paddr (lma
), paddr (lma
+ size
));
5908 if (host_crc
== target_crc
)
5909 printf_filtered ("matched.\n");
5912 printf_filtered ("MIS-MATCHED!\n");
5916 do_cleanups (old_chain
);
5919 warning (_("One or more sections of the remote executable does not match\n\
5920 the loaded file\n"));
5921 if (args
&& !matched
)
5922 printf_filtered (_("No loaded section named '%s'.\n"), args
);
5925 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
5926 into remote target. The number of bytes written to the remote
5927 target is returned, or -1 for error. */
5930 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
5931 const char *annex
, const gdb_byte
*writebuf
,
5932 ULONGEST offset
, LONGEST len
,
5933 struct packet_config
*packet
)
5938 struct remote_state
*rs
= get_remote_state ();
5939 int max_size
= get_memory_write_packet_size ();
5941 if (packet
->support
== PACKET_DISABLE
)
5944 /* Insert header. */
5945 i
= snprintf (rs
->buf
, max_size
,
5946 "qXfer:%s:write:%s:%s:",
5947 object_name
, annex
? annex
: "",
5948 phex_nz (offset
, sizeof offset
));
5949 max_size
-= (i
+ 1);
5951 /* Escape as much data as fits into rs->buf. */
5952 buf_len
= remote_escape_output
5953 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
5955 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
5956 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
5957 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
5960 unpack_varlen_hex (rs
->buf
, &n
);
5964 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
5965 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
5966 number of bytes read is returned, or 0 for EOF, or -1 for error.
5967 The number of bytes read may be less than LEN without indicating an
5968 EOF. PACKET is checked and updated to indicate whether the remote
5969 target supports this object. */
5972 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
5974 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
5975 struct packet_config
*packet
)
5977 static char *finished_object
;
5978 static char *finished_annex
;
5979 static ULONGEST finished_offset
;
5981 struct remote_state
*rs
= get_remote_state ();
5982 unsigned int total
= 0;
5983 LONGEST i
, n
, packet_len
;
5985 if (packet
->support
== PACKET_DISABLE
)
5988 /* Check whether we've cached an end-of-object packet that matches
5990 if (finished_object
)
5992 if (strcmp (object_name
, finished_object
) == 0
5993 && strcmp (annex
? annex
: "", finished_annex
) == 0
5994 && offset
== finished_offset
)
5997 /* Otherwise, we're now reading something different. Discard
5999 xfree (finished_object
);
6000 xfree (finished_annex
);
6001 finished_object
= NULL
;
6002 finished_annex
= NULL
;
6005 /* Request only enough to fit in a single packet. The actual data
6006 may not, since we don't know how much of it will need to be escaped;
6007 the target is free to respond with slightly less data. We subtract
6008 five to account for the response type and the protocol frame. */
6009 n
= min (get_remote_packet_size () - 5, len
);
6010 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
6011 object_name
, annex
? annex
: "",
6012 phex_nz (offset
, sizeof offset
),
6013 phex_nz (n
, sizeof n
));
6014 i
= putpkt (rs
->buf
);
6019 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
6020 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
6023 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
6024 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
6026 /* 'm' means there is (or at least might be) more data after this
6027 batch. That does not make sense unless there's at least one byte
6028 of data in this reply. */
6029 if (rs
->buf
[0] == 'm' && packet_len
== 1)
6030 error (_("Remote qXfer reply contained no data."));
6032 /* Got some data. */
6033 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
6035 /* 'l' is an EOF marker, possibly including a final block of data,
6036 or possibly empty. If we have the final block of a non-empty
6037 object, record this fact to bypass a subsequent partial read. */
6038 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
6040 finished_object
= xstrdup (object_name
);
6041 finished_annex
= xstrdup (annex
? annex
: "");
6042 finished_offset
= offset
+ i
;
6049 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
6050 const char *annex
, gdb_byte
*readbuf
,
6051 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
6053 struct remote_state
*rs
= get_remote_state ();
6058 /* Handle memory using the standard memory routines. */
6059 if (object
== TARGET_OBJECT_MEMORY
)
6064 /* If the remote target is connected but not running, we should
6065 pass this request down to a lower stratum (e.g. the executable
6067 if (!target_has_execution
)
6070 if (writebuf
!= NULL
)
6071 xfered
= remote_write_bytes (offset
, writebuf
, len
);
6073 xfered
= remote_read_bytes (offset
, readbuf
, len
);
6077 else if (xfered
== 0 && errno
== 0)
6083 /* Handle SPU memory using qxfer packets. */
6084 if (object
== TARGET_OBJECT_SPU
)
6087 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
6088 &remote_protocol_packets
6089 [PACKET_qXfer_spu_read
]);
6091 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
6092 &remote_protocol_packets
6093 [PACKET_qXfer_spu_write
]);
6096 /* Only handle flash writes. */
6097 if (writebuf
!= NULL
)
6103 case TARGET_OBJECT_FLASH
:
6104 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
6108 else if (xfered
== 0 && errno
== 0)
6118 /* Map pre-existing objects onto letters. DO NOT do this for new
6119 objects!!! Instead specify new query packets. */
6122 case TARGET_OBJECT_AVR
:
6126 case TARGET_OBJECT_AUXV
:
6127 gdb_assert (annex
== NULL
);
6128 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
6129 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
6131 case TARGET_OBJECT_AVAILABLE_FEATURES
:
6132 return remote_read_qxfer
6133 (ops
, "features", annex
, readbuf
, offset
, len
,
6134 &remote_protocol_packets
[PACKET_qXfer_features
]);
6136 case TARGET_OBJECT_LIBRARIES
:
6137 return remote_read_qxfer
6138 (ops
, "libraries", annex
, readbuf
, offset
, len
,
6139 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
6141 case TARGET_OBJECT_MEMORY_MAP
:
6142 gdb_assert (annex
== NULL
);
6143 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
6144 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
6150 /* Note: a zero OFFSET and LEN can be used to query the minimum
6152 if (offset
== 0 && len
== 0)
6153 return (get_remote_packet_size ());
6154 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
6155 large enough let the caller deal with it. */
6156 if (len
< get_remote_packet_size ())
6158 len
= get_remote_packet_size ();
6160 /* Except for querying the minimum buffer size, target must be open. */
6162 error (_("remote query is only available after target open"));
6164 gdb_assert (annex
!= NULL
);
6165 gdb_assert (readbuf
!= NULL
);
6171 /* We used one buffer char for the remote protocol q command and
6172 another for the query type. As the remote protocol encapsulation
6173 uses 4 chars plus one extra in case we are debugging
6174 (remote_debug), we have PBUFZIZ - 7 left to pack the query
6177 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
6179 /* Bad caller may have sent forbidden characters. */
6180 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
6185 gdb_assert (annex
[i
] == '\0');
6187 i
= putpkt (rs
->buf
);
6191 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6192 strcpy ((char *) readbuf
, rs
->buf
);
6194 return strlen ((char *) readbuf
);
6198 remote_rcmd (char *command
,
6199 struct ui_file
*outbuf
)
6201 struct remote_state
*rs
= get_remote_state ();
6205 error (_("remote rcmd is only available after target open"));
6207 /* Send a NULL command across as an empty command. */
6208 if (command
== NULL
)
6211 /* The query prefix. */
6212 strcpy (rs
->buf
, "qRcmd,");
6213 p
= strchr (rs
->buf
, '\0');
6215 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/) > get_remote_packet_size ())
6216 error (_("\"monitor\" command ``%s'' is too long."), command
);
6218 /* Encode the actual command. */
6219 bin2hex ((gdb_byte
*) command
, p
, 0);
6221 if (putpkt (rs
->buf
) < 0)
6222 error (_("Communication problem with target."));
6224 /* get/display the response */
6229 /* XXX - see also tracepoint.c:remote_get_noisy_reply(). */
6231 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6234 error (_("Target does not support this command."));
6235 if (buf
[0] == 'O' && buf
[1] != 'K')
6237 remote_console_output (buf
+ 1); /* 'O' message from stub. */
6240 if (strcmp (buf
, "OK") == 0)
6242 if (strlen (buf
) == 3 && buf
[0] == 'E'
6243 && isdigit (buf
[1]) && isdigit (buf
[2]))
6245 error (_("Protocol error with Rcmd"));
6247 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
6249 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
6250 fputc_unfiltered (c
, outbuf
);
6256 static VEC(mem_region_s
) *
6257 remote_memory_map (struct target_ops
*ops
)
6259 VEC(mem_region_s
) *result
= NULL
;
6260 char *text
= target_read_stralloc (¤t_target
,
6261 TARGET_OBJECT_MEMORY_MAP
, NULL
);
6265 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
6266 result
= parse_memory_map (text
);
6267 do_cleanups (back_to
);
6274 packet_command (char *args
, int from_tty
)
6276 struct remote_state
*rs
= get_remote_state ();
6279 error (_("command can only be used with remote target"));
6282 error (_("remote-packet command requires packet text as argument"));
6284 puts_filtered ("sending: ");
6285 print_packet (args
);
6286 puts_filtered ("\n");
6289 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6290 puts_filtered ("received: ");
6291 print_packet (rs
->buf
);
6292 puts_filtered ("\n");
6296 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
6298 static void display_thread_info (struct gdb_ext_thread_info
*info
);
6300 static void threadset_test_cmd (char *cmd
, int tty
);
6302 static void threadalive_test (char *cmd
, int tty
);
6304 static void threadlist_test_cmd (char *cmd
, int tty
);
6306 int get_and_display_threadinfo (threadref
*ref
);
6308 static void threadinfo_test_cmd (char *cmd
, int tty
);
6310 static int thread_display_step (threadref
*ref
, void *context
);
6312 static void threadlist_update_test_cmd (char *cmd
, int tty
);
6314 static void init_remote_threadtests (void);
6316 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
6319 threadset_test_cmd (char *cmd
, int tty
)
6321 int sample_thread
= SAMPLE_THREAD
;
6323 printf_filtered (_("Remote threadset test\n"));
6324 set_thread (sample_thread
, 1);
6329 threadalive_test (char *cmd
, int tty
)
6331 int sample_thread
= SAMPLE_THREAD
;
6333 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
6334 printf_filtered ("PASS: Thread alive test\n");
6336 printf_filtered ("FAIL: Thread alive test\n");
6339 void output_threadid (char *title
, threadref
*ref
);
6342 output_threadid (char *title
, threadref
*ref
)
6346 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
6348 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
6352 threadlist_test_cmd (char *cmd
, int tty
)
6355 threadref nextthread
;
6356 int done
, result_count
;
6357 threadref threadlist
[3];
6359 printf_filtered ("Remote Threadlist test\n");
6360 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
6361 &result_count
, &threadlist
[0]))
6362 printf_filtered ("FAIL: threadlist test\n");
6365 threadref
*scan
= threadlist
;
6366 threadref
*limit
= scan
+ result_count
;
6368 while (scan
< limit
)
6369 output_threadid (" thread ", scan
++);
6374 display_thread_info (struct gdb_ext_thread_info
*info
)
6376 output_threadid ("Threadid: ", &info
->threadid
);
6377 printf_filtered ("Name: %s\n ", info
->shortname
);
6378 printf_filtered ("State: %s\n", info
->display
);
6379 printf_filtered ("other: %s\n\n", info
->more_display
);
6383 get_and_display_threadinfo (threadref
*ref
)
6387 struct gdb_ext_thread_info threadinfo
;
6389 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
6390 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
6391 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
6392 display_thread_info (&threadinfo
);
6397 threadinfo_test_cmd (char *cmd
, int tty
)
6399 int athread
= SAMPLE_THREAD
;
6403 int_to_threadref (&thread
, athread
);
6404 printf_filtered ("Remote Threadinfo test\n");
6405 if (!get_and_display_threadinfo (&thread
))
6406 printf_filtered ("FAIL cannot get thread info\n");
6410 thread_display_step (threadref
*ref
, void *context
)
6412 /* output_threadid(" threadstep ",ref); *//* simple test */
6413 return get_and_display_threadinfo (ref
);
6417 threadlist_update_test_cmd (char *cmd
, int tty
)
6419 printf_filtered ("Remote Threadlist update test\n");
6420 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
6424 init_remote_threadtests (void)
6426 add_com ("tlist", class_obscure
, threadlist_test_cmd
, _("\
6427 Fetch and print the remote list of thread identifiers, one pkt only"));
6428 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
6429 _("Fetch and display info about one thread"));
6430 add_com ("tset", class_obscure
, threadset_test_cmd
,
6431 _("Test setting to a different thread"));
6432 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
6433 _("Iterate through updating all remote thread info"));
6434 add_com ("talive", class_obscure
, threadalive_test
,
6435 _(" Remote thread alive test "));
6440 /* Convert a thread ID to a string. Returns the string in a static
6444 remote_pid_to_str (ptid_t ptid
)
6446 static char buf
[32];
6448 xsnprintf (buf
, sizeof buf
, "Thread %d", ptid_get_pid (ptid
));
6452 /* Get the address of the thread local variable in OBJFILE which is
6453 stored at OFFSET within the thread local storage for thread PTID. */
6456 remote_get_thread_local_address (ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
6458 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
6460 struct remote_state
*rs
= get_remote_state ();
6462 enum packet_result result
;
6464 strcpy (p
, "qGetTLSAddr:");
6466 p
+= hexnumstr (p
, PIDGET (ptid
));
6468 p
+= hexnumstr (p
, offset
);
6470 p
+= hexnumstr (p
, lm
);
6474 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6475 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
6476 if (result
== PACKET_OK
)
6480 unpack_varlen_hex (rs
->buf
, &result
);
6483 else if (result
== PACKET_UNKNOWN
)
6484 throw_error (TLS_GENERIC_ERROR
,
6485 _("Remote target doesn't support qGetTLSAddr packet"));
6487 throw_error (TLS_GENERIC_ERROR
,
6488 _("Remote target failed to process qGetTLSAddr request"));
6491 throw_error (TLS_GENERIC_ERROR
,
6492 _("TLS not supported or disabled on this target"));
6497 /* Support for inferring a target description based on the current
6498 architecture and the size of a 'g' packet. While the 'g' packet
6499 can have any size (since optional registers can be left off the
6500 end), some sizes are easily recognizable given knowledge of the
6501 approximate architecture. */
6503 struct remote_g_packet_guess
6506 const struct target_desc
*tdesc
;
6508 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
6509 DEF_VEC_O(remote_g_packet_guess_s
);
6511 struct remote_g_packet_data
6513 VEC(remote_g_packet_guess_s
) *guesses
;
6516 static struct gdbarch_data
*remote_g_packet_data_handle
;
6519 remote_g_packet_data_init (struct obstack
*obstack
)
6521 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
6525 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
6526 const struct target_desc
*tdesc
)
6528 struct remote_g_packet_data
*data
6529 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
6530 struct remote_g_packet_guess new_guess
, *guess
;
6533 gdb_assert (tdesc
!= NULL
);
6536 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
6538 if (guess
->bytes
== bytes
)
6539 internal_error (__FILE__
, __LINE__
,
6540 "Duplicate g packet description added for size %d",
6543 new_guess
.bytes
= bytes
;
6544 new_guess
.tdesc
= tdesc
;
6545 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
6548 static const struct target_desc
*
6549 remote_read_description (struct target_ops
*target
)
6551 struct remote_g_packet_data
*data
6552 = gdbarch_data (current_gdbarch
, remote_g_packet_data_handle
);
6554 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
6556 struct remote_g_packet_guess
*guess
;
6558 int bytes
= send_g_packet ();
6561 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
6563 if (guess
->bytes
== bytes
)
6564 return guess
->tdesc
;
6566 /* We discard the g packet. A minor optimization would be to
6567 hold on to it, and fill the register cache once we have selected
6568 an architecture, but it's too tricky to do safely. */
6574 /* Remote file transfer support. This is host-initiated I/O, not
6575 target-initiated; for target-initiated, see remote-fileio.c. */
6577 /* If *LEFT is at least the length of STRING, copy STRING to
6578 *BUFFER, update *BUFFER to point to the new end of the buffer, and
6579 decrease *LEFT. Otherwise raise an error. */
6582 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
6584 int len
= strlen (string
);
6587 error (_("Packet too long for target."));
6589 memcpy (*buffer
, string
, len
);
6593 /* NUL-terminate the buffer as a convenience, if there is
6599 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
6600 *BUFFER, update *BUFFER to point to the new end of the buffer, and
6601 decrease *LEFT. Otherwise raise an error. */
6604 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
6607 if (2 * len
> *left
)
6608 error (_("Packet too long for target."));
6610 bin2hex (bytes
, *buffer
, len
);
6614 /* NUL-terminate the buffer as a convenience, if there is
6620 /* If *LEFT is large enough, convert VALUE to hex and add it to
6621 *BUFFER, update *BUFFER to point to the new end of the buffer, and
6622 decrease *LEFT. Otherwise raise an error. */
6625 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
6627 int len
= hexnumlen (value
);
6630 error (_("Packet too long for target."));
6632 hexnumstr (*buffer
, value
);
6636 /* NUL-terminate the buffer as a convenience, if there is
6642 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
6643 value, *REMOTE_ERRNO to the remote error number or zero if none
6644 was included, and *ATTACHMENT to point to the start of the annex
6645 if any. The length of the packet isn't needed here; there may
6646 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
6648 Return 0 if the packet could be parsed, -1 if it could not. If
6649 -1 is returned, the other variables may not be initialized. */
6652 remote_hostio_parse_result (char *buffer
, int *retcode
,
6653 int *remote_errno
, char **attachment
)
6660 if (buffer
[0] != 'F')
6664 *retcode
= strtol (&buffer
[1], &p
, 16);
6665 if (errno
!= 0 || p
== &buffer
[1])
6668 /* Check for ",errno". */
6672 *remote_errno
= strtol (p
+ 1, &p2
, 16);
6673 if (errno
!= 0 || p
+ 1 == p2
)
6678 /* Check for ";attachment". If there is no attachment, the
6679 packet should end here. */
6682 *attachment
= p
+ 1;
6685 else if (*p
== '\0')
6691 /* Send a prepared I/O packet to the target and read its response.
6692 The prepared packet is in the global RS->BUF before this function
6693 is called, and the answer is there when we return.
6695 COMMAND_BYTES is the length of the request to send, which may include
6696 binary data. WHICH_PACKET is the packet configuration to check
6697 before attempting a packet. If an error occurs, *REMOTE_ERRNO
6698 is set to the error number and -1 is returned. Otherwise the value
6699 returned by the function is returned.
6701 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
6702 attachment is expected; an error will be reported if there's a
6703 mismatch. If one is found, *ATTACHMENT will be set to point into
6704 the packet buffer and *ATTACHMENT_LEN will be set to the
6705 attachment's length. */
6708 remote_hostio_send_command (int command_bytes
, int which_packet
,
6709 int *remote_errno
, char **attachment
,
6710 int *attachment_len
)
6712 struct remote_state
*rs
= get_remote_state ();
6713 int ret
, bytes_read
;
6714 char *attachment_tmp
;
6716 if (remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
6718 *remote_errno
= FILEIO_ENOSYS
;
6722 putpkt_binary (rs
->buf
, command_bytes
);
6723 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
6725 /* If it timed out, something is wrong. Don't try to parse the
6729 *remote_errno
= FILEIO_EINVAL
;
6733 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
6736 *remote_errno
= FILEIO_EINVAL
;
6738 case PACKET_UNKNOWN
:
6739 *remote_errno
= FILEIO_ENOSYS
;
6745 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
6748 *remote_errno
= FILEIO_EINVAL
;
6752 /* Make sure we saw an attachment if and only if we expected one. */
6753 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
6754 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
6756 *remote_errno
= FILEIO_EINVAL
;
6760 /* If an attachment was found, it must point into the packet buffer;
6761 work out how many bytes there were. */
6762 if (attachment_tmp
!= NULL
)
6764 *attachment
= attachment_tmp
;
6765 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
6771 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
6772 remote file descriptor, or -1 if an error occurs (and set
6776 remote_hostio_open (const char *filename
, int flags
, int mode
,
6779 struct remote_state
*rs
= get_remote_state ();
6781 int left
= get_remote_packet_size () - 1;
6783 remote_buffer_add_string (&p
, &left
, "vFile:open:");
6785 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
6787 remote_buffer_add_string (&p
, &left
, ",");
6789 remote_buffer_add_int (&p
, &left
, flags
);
6790 remote_buffer_add_string (&p
, &left
, ",");
6792 remote_buffer_add_int (&p
, &left
, mode
);
6794 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
6795 remote_errno
, NULL
, NULL
);
6798 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
6799 Return the number of bytes written, or -1 if an error occurs (and
6800 set *REMOTE_ERRNO). */
6803 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
6804 ULONGEST offset
, int *remote_errno
)
6806 struct remote_state
*rs
= get_remote_state ();
6808 int left
= get_remote_packet_size ();
6811 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
6813 remote_buffer_add_int (&p
, &left
, fd
);
6814 remote_buffer_add_string (&p
, &left
, ",");
6816 remote_buffer_add_int (&p
, &left
, offset
);
6817 remote_buffer_add_string (&p
, &left
, ",");
6819 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
6820 get_remote_packet_size () - (p
- rs
->buf
));
6822 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
6823 remote_errno
, NULL
, NULL
);
6826 /* Read up to LEN bytes FD on the remote target into READ_BUF
6827 Return the number of bytes read, or -1 if an error occurs (and
6828 set *REMOTE_ERRNO). */
6831 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
6832 ULONGEST offset
, int *remote_errno
)
6834 struct remote_state
*rs
= get_remote_state ();
6837 int left
= get_remote_packet_size ();
6838 int ret
, attachment_len
;
6841 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
6843 remote_buffer_add_int (&p
, &left
, fd
);
6844 remote_buffer_add_string (&p
, &left
, ",");
6846 remote_buffer_add_int (&p
, &left
, len
);
6847 remote_buffer_add_string (&p
, &left
, ",");
6849 remote_buffer_add_int (&p
, &left
, offset
);
6851 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
6852 remote_errno
, &attachment
,
6858 read_len
= remote_unescape_input (attachment
, attachment_len
,
6860 if (read_len
!= ret
)
6861 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
6866 /* Close FD on the remote target. Return 0, or -1 if an error occurs
6867 (and set *REMOTE_ERRNO). */
6870 remote_hostio_close (int fd
, int *remote_errno
)
6872 struct remote_state
*rs
= get_remote_state ();
6874 int left
= get_remote_packet_size () - 1;
6876 remote_buffer_add_string (&p
, &left
, "vFile:close:");
6878 remote_buffer_add_int (&p
, &left
, fd
);
6880 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
6881 remote_errno
, NULL
, NULL
);
6884 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
6885 occurs (and set *REMOTE_ERRNO). */
6888 remote_hostio_unlink (const char *filename
, int *remote_errno
)
6890 struct remote_state
*rs
= get_remote_state ();
6892 int left
= get_remote_packet_size () - 1;
6894 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
6896 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
6899 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
6900 remote_errno
, NULL
, NULL
);
6904 remote_fileio_errno_to_host (int errnum
)
6928 case FILEIO_ENOTDIR
:
6948 case FILEIO_ENAMETOOLONG
:
6949 return ENAMETOOLONG
;
6955 remote_hostio_error (int errnum
)
6957 int host_error
= remote_fileio_errno_to_host (errnum
);
6959 if (host_error
== -1)
6960 error (_("Unknown remote I/O error %d"), errnum
);
6962 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
6966 fclose_cleanup (void *file
)
6972 remote_hostio_close_cleanup (void *opaque
)
6974 int fd
= *(int *) opaque
;
6977 remote_hostio_close (fd
, &remote_errno
);
6981 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
6983 struct cleanup
*back_to
, *close_cleanup
;
6984 int retcode
, fd
, remote_errno
, bytes
, io_size
;
6987 int bytes_in_buffer
;
6992 error (_("command can only be used with remote target"));
6994 file
= fopen (local_file
, "rb");
6996 perror_with_name (local_file
);
6997 back_to
= make_cleanup (fclose_cleanup
, file
);
6999 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
7001 0700, &remote_errno
);
7003 remote_hostio_error (remote_errno
);
7005 /* Send up to this many bytes at once. They won't all fit in the
7006 remote packet limit, so we'll transfer slightly fewer. */
7007 io_size
= get_remote_packet_size ();
7008 buffer
= xmalloc (io_size
);
7009 make_cleanup (xfree
, buffer
);
7011 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
7013 bytes_in_buffer
= 0;
7016 while (bytes_in_buffer
|| !saw_eof
)
7020 bytes
= fread (buffer
+ bytes_in_buffer
, 1, io_size
- bytes_in_buffer
,
7025 error (_("Error reading %s."), local_file
);
7028 /* EOF. Unless there is something still in the
7029 buffer from the last iteration, we are done. */
7031 if (bytes_in_buffer
== 0)
7039 bytes
+= bytes_in_buffer
;
7040 bytes_in_buffer
= 0;
7042 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
, offset
, &remote_errno
);
7045 remote_hostio_error (remote_errno
);
7046 else if (retcode
== 0)
7047 error (_("Remote write of %d bytes returned 0!"), bytes
);
7048 else if (retcode
< bytes
)
7050 /* Short write. Save the rest of the read data for the next
7052 bytes_in_buffer
= bytes
- retcode
;
7053 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
7059 discard_cleanups (close_cleanup
);
7060 if (remote_hostio_close (fd
, &remote_errno
))
7061 remote_hostio_error (remote_errno
);
7064 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
7065 do_cleanups (back_to
);
7069 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
7071 struct cleanup
*back_to
, *close_cleanup
;
7072 int retcode
, fd
, remote_errno
, bytes
, io_size
;
7078 error (_("command can only be used with remote target"));
7080 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
7082 remote_hostio_error (remote_errno
);
7084 file
= fopen (local_file
, "wb");
7086 perror_with_name (local_file
);
7087 back_to
= make_cleanup (fclose_cleanup
, file
);
7089 /* Send up to this many bytes at once. They won't all fit in the
7090 remote packet limit, so we'll transfer slightly fewer. */
7091 io_size
= get_remote_packet_size ();
7092 buffer
= xmalloc (io_size
);
7093 make_cleanup (xfree
, buffer
);
7095 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
7100 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
7102 /* Success, but no bytes, means end-of-file. */
7105 remote_hostio_error (remote_errno
);
7109 bytes
= fwrite (buffer
, 1, bytes
, file
);
7111 perror_with_name (local_file
);
7114 discard_cleanups (close_cleanup
);
7115 if (remote_hostio_close (fd
, &remote_errno
))
7116 remote_hostio_error (remote_errno
);
7119 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
7120 do_cleanups (back_to
);
7124 remote_file_delete (const char *remote_file
, int from_tty
)
7126 int retcode
, remote_errno
;
7129 error (_("command can only be used with remote target"));
7131 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
7133 remote_hostio_error (remote_errno
);
7136 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
7140 remote_put_command (char *args
, int from_tty
)
7142 struct cleanup
*back_to
;
7145 argv
= buildargv (args
);
7148 back_to
= make_cleanup_freeargv (argv
);
7149 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
7150 error (_("Invalid parameters to remote put"));
7152 remote_file_put (argv
[0], argv
[1], from_tty
);
7154 do_cleanups (back_to
);
7158 remote_get_command (char *args
, int from_tty
)
7160 struct cleanup
*back_to
;
7163 argv
= buildargv (args
);
7166 back_to
= make_cleanup_freeargv (argv
);
7167 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
7168 error (_("Invalid parameters to remote get"));
7170 remote_file_get (argv
[0], argv
[1], from_tty
);
7172 do_cleanups (back_to
);
7176 remote_delete_command (char *args
, int from_tty
)
7178 struct cleanup
*back_to
;
7181 argv
= buildargv (args
);
7184 back_to
= make_cleanup_freeargv (argv
);
7185 if (argv
[0] == NULL
|| argv
[1] != NULL
)
7186 error (_("Invalid parameters to remote delete"));
7188 remote_file_delete (argv
[0], from_tty
);
7190 do_cleanups (back_to
);
7194 remote_command (char *args
, int from_tty
)
7196 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
7200 init_remote_ops (void)
7202 remote_ops
.to_shortname
= "remote";
7203 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
7205 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
7206 Specify the serial device it is connected to\n\
7207 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
7208 remote_ops
.to_open
= remote_open
;
7209 remote_ops
.to_close
= remote_close
;
7210 remote_ops
.to_detach
= remote_detach
;
7211 remote_ops
.to_disconnect
= remote_disconnect
;
7212 remote_ops
.to_resume
= remote_resume
;
7213 remote_ops
.to_wait
= remote_wait
;
7214 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
7215 remote_ops
.to_store_registers
= remote_store_registers
;
7216 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
7217 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
7218 remote_ops
.to_files_info
= remote_files_info
;
7219 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
7220 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
7221 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
7222 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
7223 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
7224 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
7225 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
7226 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
7227 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
7228 remote_ops
.to_kill
= remote_kill
;
7229 remote_ops
.to_load
= generic_load
;
7230 remote_ops
.to_mourn_inferior
= remote_mourn
;
7231 remote_ops
.to_thread_alive
= remote_thread_alive
;
7232 remote_ops
.to_find_new_threads
= remote_threads_info
;
7233 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
7234 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
7235 remote_ops
.to_stop
= remote_stop
;
7236 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
7237 remote_ops
.to_rcmd
= remote_rcmd
;
7238 remote_ops
.to_log_command
= serial_log_command
;
7239 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
7240 remote_ops
.to_stratum
= process_stratum
;
7241 remote_ops
.to_has_all_memory
= 1;
7242 remote_ops
.to_has_memory
= 1;
7243 remote_ops
.to_has_stack
= 1;
7244 remote_ops
.to_has_registers
= 1;
7245 remote_ops
.to_has_execution
= 1;
7246 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
7247 remote_ops
.to_magic
= OPS_MAGIC
;
7248 remote_ops
.to_memory_map
= remote_memory_map
;
7249 remote_ops
.to_flash_erase
= remote_flash_erase
;
7250 remote_ops
.to_flash_done
= remote_flash_done
;
7251 remote_ops
.to_read_description
= remote_read_description
;
7254 /* Set up the extended remote vector by making a copy of the standard
7255 remote vector and adding to it. */
7258 init_extended_remote_ops (void)
7260 extended_remote_ops
= remote_ops
;
7262 extended_remote_ops
.to_shortname
= "extended-remote";
7263 extended_remote_ops
.to_longname
=
7264 "Extended remote serial target in gdb-specific protocol";
7265 extended_remote_ops
.to_doc
=
7266 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
7267 Specify the serial device it is connected to (e.g. /dev/ttya).",
7268 extended_remote_ops
.to_open
= extended_remote_open
;
7269 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
7270 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
7271 extended_remote_ops
.to_detach
= extended_remote_detach
;
7272 extended_remote_ops
.to_attach
= extended_remote_attach
;
7276 remote_can_async_p (void)
7278 /* We're async whenever the serial device is. */
7279 return (current_target
.to_async_mask_value
) && serial_can_async_p (remote_desc
);
7283 remote_is_async_p (void)
7285 /* We're async whenever the serial device is. */
7286 return (current_target
.to_async_mask_value
) && serial_is_async_p (remote_desc
);
7289 /* Pass the SERIAL event on and up to the client. One day this code
7290 will be able to delay notifying the client of an event until the
7291 point where an entire packet has been received. */
7293 static void (*async_client_callback
) (enum inferior_event_type event_type
,
7295 static void *async_client_context
;
7296 static serial_event_ftype remote_async_serial_handler
;
7299 remote_async_serial_handler (struct serial
*scb
, void *context
)
7301 /* Don't propogate error information up to the client. Instead let
7302 the client find out about the error by querying the target. */
7303 async_client_callback (INF_REG_EVENT
, async_client_context
);
7307 remote_async (void (*callback
) (enum inferior_event_type event_type
,
7308 void *context
), void *context
)
7310 if (current_target
.to_async_mask_value
== 0)
7311 internal_error (__FILE__
, __LINE__
,
7312 _("Calling remote_async when async is masked"));
7314 if (callback
!= NULL
)
7316 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
7317 async_client_callback
= callback
;
7318 async_client_context
= context
;
7321 serial_async (remote_desc
, NULL
, NULL
);
7324 /* Target async and target extended-async.
7326 This are temporary targets, until it is all tested. Eventually
7327 async support will be incorporated int the usual 'remote'
7331 init_remote_async_ops (void)
7333 remote_async_ops
.to_shortname
= "async";
7334 remote_async_ops
.to_longname
=
7335 "Remote serial target in async version of the gdb-specific protocol";
7336 remote_async_ops
.to_doc
=
7337 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
7338 Specify the serial device it is connected to (e.g. /dev/ttya).";
7339 remote_async_ops
.to_open
= remote_async_open
;
7340 remote_async_ops
.to_close
= remote_close
;
7341 remote_async_ops
.to_detach
= remote_detach
;
7342 remote_async_ops
.to_disconnect
= remote_disconnect
;
7343 remote_async_ops
.to_resume
= remote_async_resume
;
7344 remote_async_ops
.to_wait
= remote_async_wait
;
7345 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
7346 remote_async_ops
.to_store_registers
= remote_store_registers
;
7347 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
7348 remote_async_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
7349 remote_async_ops
.to_files_info
= remote_files_info
;
7350 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
7351 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
7352 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
7353 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
7354 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
7355 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
7356 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
7357 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
7358 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
7359 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
7360 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
7361 remote_async_ops
.to_kill
= remote_async_kill
;
7362 remote_async_ops
.to_load
= generic_load
;
7363 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
7364 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
7365 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
7366 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
7367 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
7368 remote_async_ops
.to_stop
= remote_stop
;
7369 remote_async_ops
.to_xfer_partial
= remote_xfer_partial
;
7370 remote_async_ops
.to_rcmd
= remote_rcmd
;
7371 remote_async_ops
.to_stratum
= process_stratum
;
7372 remote_async_ops
.to_has_all_memory
= 1;
7373 remote_async_ops
.to_has_memory
= 1;
7374 remote_async_ops
.to_has_stack
= 1;
7375 remote_async_ops
.to_has_registers
= 1;
7376 remote_async_ops
.to_has_execution
= 1;
7377 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
7378 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
7379 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
7380 remote_async_ops
.to_async
= remote_async
;
7381 remote_async_ops
.to_async_mask_value
= 1;
7382 remote_async_ops
.to_magic
= OPS_MAGIC
;
7383 remote_async_ops
.to_memory_map
= remote_memory_map
;
7384 remote_async_ops
.to_flash_erase
= remote_flash_erase
;
7385 remote_async_ops
.to_flash_done
= remote_flash_done
;
7386 remote_async_ops
.to_read_description
= remote_read_description
;
7389 /* Set up the async extended remote vector by making a copy of the standard
7390 remote vector and adding to it. */
7393 init_extended_async_remote_ops (void)
7395 extended_async_remote_ops
= remote_async_ops
;
7397 extended_async_remote_ops
.to_shortname
= "extended-async";
7398 extended_async_remote_ops
.to_longname
=
7399 "Extended remote serial target in async gdb-specific protocol";
7400 extended_async_remote_ops
.to_doc
=
7401 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
7402 Specify the serial device it is connected to (e.g. /dev/ttya).",
7403 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
7404 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
7405 extended_async_remote_ops
.to_mourn_inferior
= extended_async_remote_mourn
;
7406 extended_async_remote_ops
.to_detach
= extended_remote_detach
;
7407 extended_async_remote_ops
.to_attach
= extended_async_remote_attach
;
7411 set_remote_cmd (char *args
, int from_tty
)
7413 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
7417 show_remote_cmd (char *args
, int from_tty
)
7419 /* We can't just use cmd_show_list here, because we want to skip
7420 the redundant "show remote Z-packet" and the legacy aliases. */
7421 struct cleanup
*showlist_chain
;
7422 struct cmd_list_element
*list
= remote_show_cmdlist
;
7424 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
7425 for (; list
!= NULL
; list
= list
->next
)
7426 if (strcmp (list
->name
, "Z-packet") == 0)
7428 else if (list
->type
== not_set_cmd
)
7429 /* Alias commands are exactly like the original, except they
7430 don't have the normal type. */
7434 struct cleanup
*option_chain
7435 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
7436 ui_out_field_string (uiout
, "name", list
->name
);
7437 ui_out_text (uiout
, ": ");
7438 if (list
->type
== show_cmd
)
7439 do_setshow_command ((char *) NULL
, from_tty
, list
);
7441 cmd_func (list
, NULL
, from_tty
);
7442 /* Close the tuple. */
7443 do_cleanups (option_chain
);
7446 /* Close the tuple. */
7447 do_cleanups (showlist_chain
);
7451 /* Function to be called whenever a new objfile (shlib) is detected. */
7453 remote_new_objfile (struct objfile
*objfile
)
7455 if (remote_desc
!= 0) /* Have a remote connection. */
7456 remote_check_symbols (objfile
);
7460 _initialize_remote (void)
7462 struct remote_state
*rs
;
7464 /* architecture specific data */
7465 remote_gdbarch_data_handle
=
7466 gdbarch_data_register_post_init (init_remote_state
);
7467 remote_g_packet_data_handle
=
7468 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
7470 /* Initialize the per-target state. At the moment there is only one
7471 of these, not one per target. Only one target is active at a
7472 time. The default buffer size is unimportant; it will be expanded
7473 whenever a larger buffer is needed. */
7474 rs
= get_remote_state_raw ();
7476 rs
->buf
= xmalloc (rs
->buf_size
);
7479 add_target (&remote_ops
);
7481 init_extended_remote_ops ();
7482 add_target (&extended_remote_ops
);
7484 init_remote_async_ops ();
7485 add_target (&remote_async_ops
);
7487 init_extended_async_remote_ops ();
7488 add_target (&extended_async_remote_ops
);
7490 /* Hook into new objfile notification. */
7491 observer_attach_new_objfile (remote_new_objfile
);
7493 /* Set up signal handlers. */
7494 sigint_remote_token
=
7495 create_async_signal_handler (async_remote_interrupt
, NULL
);
7496 sigint_remote_twice_token
=
7497 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
7500 init_remote_threadtests ();
7503 /* set/show remote ... */
7505 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
7506 Remote protocol specific variables\n\
7507 Configure various remote-protocol specific variables such as\n\
7508 the packets being used"),
7509 &remote_set_cmdlist
, "set remote ",
7510 0 /* allow-unknown */, &setlist
);
7511 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
7512 Remote protocol specific variables\n\
7513 Configure various remote-protocol specific variables such as\n\
7514 the packets being used"),
7515 &remote_show_cmdlist
, "show remote ",
7516 0 /* allow-unknown */, &showlist
);
7518 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
7519 Compare section data on target to the exec file.\n\
7520 Argument is a single section name (default: all loaded sections)."),
7523 add_cmd ("packet", class_maintenance
, packet_command
, _("\
7524 Send an arbitrary packet to a remote target.\n\
7525 maintenance packet TEXT\n\
7526 If GDB is talking to an inferior via the GDB serial protocol, then\n\
7527 this command sends the string TEXT to the inferior, and displays the\n\
7528 response packet. GDB supplies the initial `$' character, and the\n\
7529 terminating `#' character and checksum."),
7532 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
7533 Set whether to send break if interrupted."), _("\
7534 Show whether to send break if interrupted."), _("\
7535 If set, a break, instead of a cntrl-c, is sent to the remote target."),
7536 NULL
, NULL
, /* FIXME: i18n: Whether to send break if interrupted is %s. */
7537 &setlist
, &showlist
);
7539 /* Install commands for configuring memory read/write packets. */
7541 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
7542 Set the maximum number of bytes per memory write packet (deprecated)."),
7544 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
7545 Show the maximum number of bytes per memory write packet (deprecated)."),
7547 add_cmd ("memory-write-packet-size", no_class
,
7548 set_memory_write_packet_size
, _("\
7549 Set the maximum number of bytes per memory-write packet.\n\
7550 Specify the number of bytes in a packet or 0 (zero) for the\n\
7551 default packet size. The actual limit is further reduced\n\
7552 dependent on the target. Specify ``fixed'' to disable the\n\
7553 further restriction and ``limit'' to enable that restriction."),
7554 &remote_set_cmdlist
);
7555 add_cmd ("memory-read-packet-size", no_class
,
7556 set_memory_read_packet_size
, _("\
7557 Set the maximum number of bytes per memory-read packet.\n\
7558 Specify the number of bytes in a packet or 0 (zero) for the\n\
7559 default packet size. The actual limit is further reduced\n\
7560 dependent on the target. Specify ``fixed'' to disable the\n\
7561 further restriction and ``limit'' to enable that restriction."),
7562 &remote_set_cmdlist
);
7563 add_cmd ("memory-write-packet-size", no_class
,
7564 show_memory_write_packet_size
,
7565 _("Show the maximum number of bytes per memory-write packet."),
7566 &remote_show_cmdlist
);
7567 add_cmd ("memory-read-packet-size", no_class
,
7568 show_memory_read_packet_size
,
7569 _("Show the maximum number of bytes per memory-read packet."),
7570 &remote_show_cmdlist
);
7572 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
7573 &remote_hw_watchpoint_limit
, _("\
7574 Set the maximum number of target hardware watchpoints."), _("\
7575 Show the maximum number of target hardware watchpoints."), _("\
7576 Specify a negative limit for unlimited."),
7577 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */
7578 &remote_set_cmdlist
, &remote_show_cmdlist
);
7579 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
7580 &remote_hw_breakpoint_limit
, _("\
7581 Set the maximum number of target hardware breakpoints."), _("\
7582 Show the maximum number of target hardware breakpoints."), _("\
7583 Specify a negative limit for unlimited."),
7584 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */
7585 &remote_set_cmdlist
, &remote_show_cmdlist
);
7587 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
7588 &remote_address_size
, _("\
7589 Set the maximum size of the address (in bits) in a memory packet."), _("\
7590 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
7592 NULL
, /* FIXME: i18n: */
7593 &setlist
, &showlist
);
7595 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
7596 "X", "binary-download", 1);
7598 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
7599 "vCont", "verbose-resume", 0);
7601 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
7602 "QPassSignals", "pass-signals", 0);
7604 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
7605 "qSymbol", "symbol-lookup", 0);
7607 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
7608 "P", "set-register", 1);
7610 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
7611 "p", "fetch-register", 1);
7613 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
7614 "Z0", "software-breakpoint", 0);
7616 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
7617 "Z1", "hardware-breakpoint", 0);
7619 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
7620 "Z2", "write-watchpoint", 0);
7622 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
7623 "Z3", "read-watchpoint", 0);
7625 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
7626 "Z4", "access-watchpoint", 0);
7628 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
7629 "qXfer:auxv:read", "read-aux-vector", 0);
7631 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
7632 "qXfer:features:read", "target-features", 0);
7634 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
7635 "qXfer:libraries:read", "library-info", 0);
7637 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
7638 "qXfer:memory-map:read", "memory-map", 0);
7640 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
7641 "qXfer:spu:read", "read-spu-object", 0);
7643 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
7644 "qXfer:spu:write", "write-spu-object", 0);
7646 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
7647 "qGetTLSAddr", "get-thread-local-storage-address",
7650 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
7651 "qSupported", "supported-packets", 0);
7653 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
7654 "vFile:open", "hostio-open", 0);
7656 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
7657 "vFile:pread", "hostio-pread", 0);
7659 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
7660 "vFile:pwrite", "hostio-pwrite", 0);
7662 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
7663 "vFile:close", "hostio-close", 0);
7665 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
7666 "vFile:unlink", "hostio-unlink", 0);
7668 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
7669 "vAttach", "attach", 0);
7671 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
7674 /* Keep the old ``set remote Z-packet ...'' working. Each individual
7675 Z sub-packet has its own set and show commands, but users may
7676 have sets to this variable in their .gdbinit files (or in their
7678 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
7679 &remote_Z_packet_detect
, _("\
7680 Set use of remote protocol `Z' packets"), _("\
7681 Show use of remote protocol `Z' packets "), _("\
7682 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
7684 set_remote_protocol_Z_packet_cmd
,
7685 show_remote_protocol_Z_packet_cmd
, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */
7686 &remote_set_cmdlist
, &remote_show_cmdlist
);
7688 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
7689 Manipulate files on the remote system\n\
7690 Transfer files to and from the remote target system."),
7691 &remote_cmdlist
, "remote ",
7692 0 /* allow-unknown */, &cmdlist
);
7694 add_cmd ("put", class_files
, remote_put_command
,
7695 _("Copy a local file to the remote system."),
7698 add_cmd ("get", class_files
, remote_get_command
,
7699 _("Copy a remote file to the local system."),
7702 add_cmd ("delete", class_files
, remote_delete_command
,
7703 _("Delete a remote file."),
7706 remote_exec_file
= xstrdup ("");
7707 add_setshow_string_noescape_cmd ("exec-file", class_files
,
7708 &remote_exec_file
, _("\
7709 Set the remote pathname for \"run\""), _("\
7710 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
7711 &remote_set_cmdlist
, &remote_show_cmdlist
);
7713 /* Eventually initialize fileio. See fileio.c */
7714 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);