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 int remote_async_mask_value
= 1;
486 static struct target_ops extended_async_remote_ops
;
488 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
489 ``forever'' still use the normal timeout mechanism. This is
490 currently used by the ASYNC code to guarentee that target reads
491 during the initial connect always time-out. Once getpkt has been
492 modified to return a timeout indication and, in turn
493 remote_wait()/wait_for_inferior() have gained a timeout parameter
495 static int wait_forever_enabled_p
= 1;
498 /* This variable chooses whether to send a ^C or a break when the user
499 requests program interruption. Although ^C is usually what remote
500 systems expect, and that is the default here, sometimes a break is
501 preferable instead. */
503 static int remote_break
;
505 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
506 remote_open knows that we don't have a file open when the program
508 static struct serial
*remote_desc
= NULL
;
510 /* This variable sets the number of bits in an address that are to be
511 sent in a memory ("M" or "m") packet. Normally, after stripping
512 leading zeros, the entire address would be sent. This variable
513 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
514 initial implementation of remote.c restricted the address sent in
515 memory packets to ``host::sizeof long'' bytes - (typically 32
516 bits). Consequently, for 64 bit targets, the upper 32 bits of an
517 address was never sent. Since fixing this bug may cause a break in
518 some remote targets this variable is principly provided to
519 facilitate backward compatibility. */
521 static int remote_address_size
;
523 /* Tempoary to track who currently owns the terminal. See
524 target_async_terminal_* for more details. */
526 static int remote_async_terminal_ours_p
;
528 /* The executable file to use for "run" on the remote side. */
530 static char *remote_exec_file
= "";
533 /* User configurable variables for the number of characters in a
534 memory read/write packet. MIN (rsa->remote_packet_size,
535 rsa->sizeof_g_packet) is the default. Some targets need smaller
536 values (fifo overruns, et.al.) and some users need larger values
537 (speed up transfers). The variables ``preferred_*'' (the user
538 request), ``current_*'' (what was actually set) and ``forced_*''
539 (Positive - a soft limit, negative - a hard limit). */
541 struct memory_packet_config
548 /* Compute the current size of a read/write packet. Since this makes
549 use of ``actual_register_packet_size'' the computation is dynamic. */
552 get_memory_packet_size (struct memory_packet_config
*config
)
554 struct remote_state
*rs
= get_remote_state ();
555 struct remote_arch_state
*rsa
= get_remote_arch_state ();
557 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
558 law?) that some hosts don't cope very well with large alloca()
559 calls. Eventually the alloca() code will be replaced by calls to
560 xmalloc() and make_cleanups() allowing this restriction to either
561 be lifted or removed. */
562 #ifndef MAX_REMOTE_PACKET_SIZE
563 #define MAX_REMOTE_PACKET_SIZE 16384
565 /* NOTE: 20 ensures we can write at least one byte. */
566 #ifndef MIN_REMOTE_PACKET_SIZE
567 #define MIN_REMOTE_PACKET_SIZE 20
572 if (config
->size
<= 0)
573 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
575 what_they_get
= config
->size
;
579 what_they_get
= get_remote_packet_size ();
580 /* Limit the packet to the size specified by the user. */
582 && what_they_get
> config
->size
)
583 what_they_get
= config
->size
;
585 /* Limit it to the size of the targets ``g'' response unless we have
586 permission from the stub to use a larger packet size. */
587 if (rs
->explicit_packet_size
== 0
588 && rsa
->actual_register_packet_size
> 0
589 && what_they_get
> rsa
->actual_register_packet_size
)
590 what_they_get
= rsa
->actual_register_packet_size
;
592 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
593 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
594 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
595 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
597 /* Make sure there is room in the global buffer for this packet
598 (including its trailing NUL byte). */
599 if (rs
->buf_size
< what_they_get
+ 1)
601 rs
->buf_size
= 2 * what_they_get
;
602 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
605 return what_they_get
;
608 /* Update the size of a read/write packet. If they user wants
609 something really big then do a sanity check. */
612 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
614 int fixed_p
= config
->fixed_p
;
615 long size
= config
->size
;
617 error (_("Argument required (integer, `fixed' or `limited')."));
618 else if (strcmp (args
, "hard") == 0
619 || strcmp (args
, "fixed") == 0)
621 else if (strcmp (args
, "soft") == 0
622 || strcmp (args
, "limit") == 0)
627 size
= strtoul (args
, &end
, 0);
629 error (_("Invalid %s (bad syntax)."), config
->name
);
631 /* Instead of explicitly capping the size of a packet to
632 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
633 instead allowed to set the size to something arbitrarily
635 if (size
> MAX_REMOTE_PACKET_SIZE
)
636 error (_("Invalid %s (too large)."), config
->name
);
640 if (fixed_p
&& !config
->fixed_p
)
642 if (! query (_("The target may not be able to correctly handle a %s\n"
643 "of %ld bytes. Change the packet size? "),
645 error (_("Packet size not changed."));
647 /* Update the config. */
648 config
->fixed_p
= fixed_p
;
653 show_memory_packet_size (struct memory_packet_config
*config
)
655 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
657 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
658 get_memory_packet_size (config
));
660 printf_filtered (_("Packets are limited to %ld bytes.\n"),
661 get_memory_packet_size (config
));
664 static struct memory_packet_config memory_write_packet_config
=
666 "memory-write-packet-size",
670 set_memory_write_packet_size (char *args
, int from_tty
)
672 set_memory_packet_size (args
, &memory_write_packet_config
);
676 show_memory_write_packet_size (char *args
, int from_tty
)
678 show_memory_packet_size (&memory_write_packet_config
);
682 get_memory_write_packet_size (void)
684 return get_memory_packet_size (&memory_write_packet_config
);
687 static struct memory_packet_config memory_read_packet_config
=
689 "memory-read-packet-size",
693 set_memory_read_packet_size (char *args
, int from_tty
)
695 set_memory_packet_size (args
, &memory_read_packet_config
);
699 show_memory_read_packet_size (char *args
, int from_tty
)
701 show_memory_packet_size (&memory_read_packet_config
);
705 get_memory_read_packet_size (void)
707 long size
= get_memory_packet_size (&memory_read_packet_config
);
708 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
709 extra buffer size argument before the memory read size can be
710 increased beyond this. */
711 if (size
> get_remote_packet_size ())
712 size
= get_remote_packet_size ();
717 /* Generic configuration support for packets the stub optionally
718 supports. Allows the user to specify the use of the packet as well
719 as allowing GDB to auto-detect support in the remote stub. */
723 PACKET_SUPPORT_UNKNOWN
= 0,
732 enum auto_boolean detect
;
733 enum packet_support support
;
736 /* Analyze a packet's return value and update the packet config
747 update_packet_config (struct packet_config
*config
)
749 switch (config
->detect
)
751 case AUTO_BOOLEAN_TRUE
:
752 config
->support
= PACKET_ENABLE
;
754 case AUTO_BOOLEAN_FALSE
:
755 config
->support
= PACKET_DISABLE
;
757 case AUTO_BOOLEAN_AUTO
:
758 config
->support
= PACKET_SUPPORT_UNKNOWN
;
764 show_packet_config_cmd (struct packet_config
*config
)
766 char *support
= "internal-error";
767 switch (config
->support
)
773 support
= "disabled";
775 case PACKET_SUPPORT_UNKNOWN
:
779 switch (config
->detect
)
781 case AUTO_BOOLEAN_AUTO
:
782 printf_filtered (_("Support for the `%s' packet is auto-detected, currently %s.\n"),
783 config
->name
, support
);
785 case AUTO_BOOLEAN_TRUE
:
786 case AUTO_BOOLEAN_FALSE
:
787 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
788 config
->name
, support
);
794 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
795 const char *title
, int legacy
)
802 config
->title
= title
;
803 config
->detect
= AUTO_BOOLEAN_AUTO
;
804 config
->support
= PACKET_SUPPORT_UNKNOWN
;
805 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
807 show_doc
= xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
809 /* set/show TITLE-packet {auto,on,off} */
810 cmd_name
= xstrprintf ("%s-packet", title
);
811 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
812 &config
->detect
, set_doc
, show_doc
, NULL
, /* help_doc */
813 set_remote_protocol_packet_cmd
,
814 show_remote_protocol_packet_cmd
,
815 &remote_set_cmdlist
, &remote_show_cmdlist
);
816 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
820 legacy_name
= xstrprintf ("%s-packet", name
);
821 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
822 &remote_set_cmdlist
);
823 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
824 &remote_show_cmdlist
);
828 static enum packet_result
829 packet_check_result (const char *buf
)
833 /* The stub recognized the packet request. Check that the
834 operation succeeded. */
836 && isxdigit (buf
[1]) && isxdigit (buf
[2])
838 /* "Enn" - definitly an error. */
841 /* Always treat "E." as an error. This will be used for
842 more verbose error messages, such as E.memtypes. */
843 if (buf
[0] == 'E' && buf
[1] == '.')
846 /* The packet may or may not be OK. Just assume it is. */
850 /* The stub does not support the packet. */
851 return PACKET_UNKNOWN
;
854 static enum packet_result
855 packet_ok (const char *buf
, struct packet_config
*config
)
857 enum packet_result result
;
859 result
= packet_check_result (buf
);
864 /* The stub recognized the packet request. */
865 switch (config
->support
)
867 case PACKET_SUPPORT_UNKNOWN
:
869 fprintf_unfiltered (gdb_stdlog
,
870 "Packet %s (%s) is supported\n",
871 config
->name
, config
->title
);
872 config
->support
= PACKET_ENABLE
;
875 internal_error (__FILE__
, __LINE__
,
876 _("packet_ok: attempt to use a disabled packet"));
883 /* The stub does not support the packet. */
884 switch (config
->support
)
887 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
888 /* If the stub previously indicated that the packet was
889 supported then there is a protocol error.. */
890 error (_("Protocol error: %s (%s) conflicting enabled responses."),
891 config
->name
, config
->title
);
893 /* The user set it wrong. */
894 error (_("Enabled packet %s (%s) not recognized by stub"),
895 config
->name
, config
->title
);
897 case PACKET_SUPPORT_UNKNOWN
:
899 fprintf_unfiltered (gdb_stdlog
,
900 "Packet %s (%s) is NOT supported\n",
901 config
->name
, config
->title
);
902 config
->support
= PACKET_DISABLE
;
930 PACKET_qXfer_features
,
931 PACKET_qXfer_libraries
,
932 PACKET_qXfer_memory_map
,
933 PACKET_qXfer_spu_read
,
934 PACKET_qXfer_spu_write
,
943 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
946 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
947 struct cmd_list_element
*c
)
949 struct packet_config
*packet
;
951 for (packet
= remote_protocol_packets
;
952 packet
< &remote_protocol_packets
[PACKET_MAX
];
955 if (&packet
->detect
== c
->var
)
957 update_packet_config (packet
);
961 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
966 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
967 struct cmd_list_element
*c
,
970 struct packet_config
*packet
;
972 for (packet
= remote_protocol_packets
;
973 packet
< &remote_protocol_packets
[PACKET_MAX
];
976 if (&packet
->detect
== c
->var
)
978 show_packet_config_cmd (packet
);
982 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
986 /* Should we try one of the 'Z' requests? */
990 Z_PACKET_SOFTWARE_BP
,
991 Z_PACKET_HARDWARE_BP
,
998 /* For compatibility with older distributions. Provide a ``set remote
999 Z-packet ...'' command that updates all the Z packet types. */
1001 static enum auto_boolean remote_Z_packet_detect
;
1004 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1005 struct cmd_list_element
*c
)
1008 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1010 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1011 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1016 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1017 struct cmd_list_element
*c
,
1021 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1023 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1027 /* Should we try the 'ThreadInfo' query packet?
1029 This variable (NOT available to the user: auto-detect only!)
1030 determines whether GDB will use the new, simpler "ThreadInfo"
1031 query or the older, more complex syntax for thread queries.
1032 This is an auto-detect variable (set to true at each connect,
1033 and set to false when the target fails to recognize it). */
1035 static int use_threadinfo_query
;
1036 static int use_threadextra_query
;
1038 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1039 static struct async_signal_handler
*sigint_remote_twice_token
;
1040 static struct async_signal_handler
*sigint_remote_token
;
1045 /* These are the threads which we last sent to the remote system.
1046 -1 for all or -2 for not sent yet. */
1047 static int general_thread
;
1048 static int continue_thread
;
1050 /* Call this function as a result of
1051 1) A halt indication (T packet) containing a thread id
1052 2) A direct query of currthread
1053 3) Successful execution of set thread
1057 record_currthread (int currthread
)
1059 general_thread
= currthread
;
1061 /* If this is a new thread, add it to GDB's thread list.
1062 If we leave it up to WFI to do this, bad things will happen. */
1063 if (!in_thread_list (pid_to_ptid (currthread
)))
1064 add_thread (pid_to_ptid (currthread
));
1067 static char *last_pass_packet
;
1069 /* If 'QPassSignals' is supported, tell the remote stub what signals
1070 it can simply pass through to the inferior without reporting. */
1073 remote_pass_signals (void)
1075 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1077 char *pass_packet
, *p
;
1078 int numsigs
= (int) TARGET_SIGNAL_LAST
;
1081 gdb_assert (numsigs
< 256);
1082 for (i
= 0; i
< numsigs
; i
++)
1084 if (signal_stop_state (i
) == 0
1085 && signal_print_state (i
) == 0
1086 && signal_pass_state (i
) == 1)
1089 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1090 strcpy (pass_packet
, "QPassSignals:");
1091 p
= pass_packet
+ strlen (pass_packet
);
1092 for (i
= 0; i
< numsigs
; i
++)
1094 if (signal_stop_state (i
) == 0
1095 && signal_print_state (i
) == 0
1096 && signal_pass_state (i
) == 1)
1099 *p
++ = tohex (i
>> 4);
1100 *p
++ = tohex (i
& 15);
1109 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1111 struct remote_state
*rs
= get_remote_state ();
1112 char *buf
= rs
->buf
;
1114 putpkt (pass_packet
);
1115 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1116 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1117 if (last_pass_packet
)
1118 xfree (last_pass_packet
);
1119 last_pass_packet
= pass_packet
;
1122 xfree (pass_packet
);
1126 #define MAGIC_NULL_PID 42000
1129 set_thread (int th
, int gen
)
1131 struct remote_state
*rs
= get_remote_state ();
1132 char *buf
= rs
->buf
;
1133 int state
= gen
? general_thread
: continue_thread
;
1139 buf
[1] = gen
? 'g' : 'c';
1140 if (th
== MAGIC_NULL_PID
)
1146 xsnprintf (&buf
[2], get_remote_packet_size () - 2, "-%x", -th
);
1148 xsnprintf (&buf
[2], get_remote_packet_size () - 2, "%x", th
);
1150 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1152 general_thread
= th
;
1154 continue_thread
= th
;
1157 /* Return nonzero if the thread TH is still alive on the remote system. */
1160 remote_thread_alive (ptid_t ptid
)
1162 struct remote_state
*rs
= get_remote_state ();
1163 int tid
= PIDGET (ptid
);
1166 xsnprintf (rs
->buf
, get_remote_packet_size (), "T-%08x", -tid
);
1168 xsnprintf (rs
->buf
, get_remote_packet_size (), "T%08x", tid
);
1170 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1171 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1174 /* About these extended threadlist and threadinfo packets. They are
1175 variable length packets but, the fields within them are often fixed
1176 length. They are redundent enough to send over UDP as is the
1177 remote protocol in general. There is a matching unit test module
1180 #define OPAQUETHREADBYTES 8
1182 /* a 64 bit opaque identifier */
1183 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1185 /* WARNING: This threadref data structure comes from the remote O.S.,
1186 libstub protocol encoding, and remote.c. it is not particularly
1189 /* Right now, the internal structure is int. We want it to be bigger.
1193 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1195 /* gdb_ext_thread_info is an internal GDB data structure which is
1196 equivalent to the reply of the remote threadinfo packet. */
1198 struct gdb_ext_thread_info
1200 threadref threadid
; /* External form of thread reference. */
1201 int active
; /* Has state interesting to GDB?
1203 char display
[256]; /* Brief state display, name,
1204 blocked/suspended. */
1205 char shortname
[32]; /* To be used to name threads. */
1206 char more_display
[256]; /* Long info, statistics, queue depth,
1210 /* The volume of remote transfers can be limited by submitting
1211 a mask containing bits specifying the desired information.
1212 Use a union of these values as the 'selection' parameter to
1213 get_thread_info. FIXME: Make these TAG names more thread specific.
1216 #define TAG_THREADID 1
1217 #define TAG_EXISTS 2
1218 #define TAG_DISPLAY 4
1219 #define TAG_THREADNAME 8
1220 #define TAG_MOREDISPLAY 16
1222 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1224 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1226 static char *unpack_nibble (char *buf
, int *val
);
1228 static char *pack_nibble (char *buf
, int nibble
);
1230 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1232 static char *unpack_byte (char *buf
, int *value
);
1234 static char *pack_int (char *buf
, int value
);
1236 static char *unpack_int (char *buf
, int *value
);
1238 static char *unpack_string (char *src
, char *dest
, int length
);
1240 static char *pack_threadid (char *pkt
, threadref
*id
);
1242 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1244 void int_to_threadref (threadref
*id
, int value
);
1246 static int threadref_to_int (threadref
*ref
);
1248 static void copy_threadref (threadref
*dest
, threadref
*src
);
1250 static int threadmatch (threadref
*dest
, threadref
*src
);
1252 static char *pack_threadinfo_request (char *pkt
, int mode
,
1255 static int remote_unpack_thread_info_response (char *pkt
,
1256 threadref
*expectedref
,
1257 struct gdb_ext_thread_info
1261 static int remote_get_threadinfo (threadref
*threadid
,
1262 int fieldset
, /*TAG mask */
1263 struct gdb_ext_thread_info
*info
);
1265 static char *pack_threadlist_request (char *pkt
, int startflag
,
1267 threadref
*nextthread
);
1269 static int parse_threadlist_response (char *pkt
,
1271 threadref
*original_echo
,
1272 threadref
*resultlist
,
1275 static int remote_get_threadlist (int startflag
,
1276 threadref
*nextthread
,
1280 threadref
*threadlist
);
1282 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1284 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1285 void *context
, int looplimit
);
1287 static int remote_newthread_step (threadref
*ref
, void *context
);
1289 /* Encode 64 bits in 16 chars of hex. */
1291 static const char hexchars
[] = "0123456789abcdef";
1294 ishex (int ch
, int *val
)
1296 if ((ch
>= 'a') && (ch
<= 'f'))
1298 *val
= ch
- 'a' + 10;
1301 if ((ch
>= 'A') && (ch
<= 'F'))
1303 *val
= ch
- 'A' + 10;
1306 if ((ch
>= '0') && (ch
<= '9'))
1317 if (ch
>= 'a' && ch
<= 'f')
1318 return ch
- 'a' + 10;
1319 if (ch
>= '0' && ch
<= '9')
1321 if (ch
>= 'A' && ch
<= 'F')
1322 return ch
- 'A' + 10;
1327 stub_unpack_int (char *buff
, int fieldlength
)
1334 nibble
= stubhex (*buff
++);
1338 retval
= retval
<< 4;
1344 unpack_varlen_hex (char *buff
, /* packet to parse */
1348 ULONGEST retval
= 0;
1350 while (ishex (*buff
, &nibble
))
1353 retval
= retval
<< 4;
1354 retval
|= nibble
& 0x0f;
1361 unpack_nibble (char *buf
, int *val
)
1363 *val
= fromhex (*buf
++);
1368 pack_nibble (char *buf
, int nibble
)
1370 *buf
++ = hexchars
[(nibble
& 0x0f)];
1375 pack_hex_byte (char *pkt
, int byte
)
1377 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1378 *pkt
++ = hexchars
[(byte
& 0xf)];
1383 unpack_byte (char *buf
, int *value
)
1385 *value
= stub_unpack_int (buf
, 2);
1390 pack_int (char *buf
, int value
)
1392 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1393 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1394 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1395 buf
= pack_hex_byte (buf
, (value
& 0xff));
1400 unpack_int (char *buf
, int *value
)
1402 *value
= stub_unpack_int (buf
, 8);
1406 #if 0 /* Currently unused, uncomment when needed. */
1407 static char *pack_string (char *pkt
, char *string
);
1410 pack_string (char *pkt
, char *string
)
1415 len
= strlen (string
);
1417 len
= 200; /* Bigger than most GDB packets, junk??? */
1418 pkt
= pack_hex_byte (pkt
, len
);
1422 if ((ch
== '\0') || (ch
== '#'))
1423 ch
= '*'; /* Protect encapsulation. */
1428 #endif /* 0 (unused) */
1431 unpack_string (char *src
, char *dest
, int length
)
1440 pack_threadid (char *pkt
, threadref
*id
)
1443 unsigned char *altid
;
1445 altid
= (unsigned char *) id
;
1446 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1448 pkt
= pack_hex_byte (pkt
, *altid
++);
1454 unpack_threadid (char *inbuf
, threadref
*id
)
1457 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1460 altref
= (char *) id
;
1462 while (inbuf
< limit
)
1464 x
= stubhex (*inbuf
++);
1465 y
= stubhex (*inbuf
++);
1466 *altref
++ = (x
<< 4) | y
;
1471 /* Externally, threadrefs are 64 bits but internally, they are still
1472 ints. This is due to a mismatch of specifications. We would like
1473 to use 64bit thread references internally. This is an adapter
1477 int_to_threadref (threadref
*id
, int value
)
1479 unsigned char *scan
;
1481 scan
= (unsigned char *) id
;
1487 *scan
++ = (value
>> 24) & 0xff;
1488 *scan
++ = (value
>> 16) & 0xff;
1489 *scan
++ = (value
>> 8) & 0xff;
1490 *scan
++ = (value
& 0xff);
1494 threadref_to_int (threadref
*ref
)
1497 unsigned char *scan
;
1503 value
= (value
<< 8) | ((*scan
++) & 0xff);
1508 copy_threadref (threadref
*dest
, threadref
*src
)
1511 unsigned char *csrc
, *cdest
;
1513 csrc
= (unsigned char *) src
;
1514 cdest
= (unsigned char *) dest
;
1521 threadmatch (threadref
*dest
, threadref
*src
)
1523 /* Things are broken right now, so just assume we got a match. */
1525 unsigned char *srcp
, *destp
;
1527 srcp
= (char *) src
;
1528 destp
= (char *) dest
;
1532 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1539 threadid:1, # always request threadid
1546 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1549 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1551 *pkt
++ = 'q'; /* Info Query */
1552 *pkt
++ = 'P'; /* process or thread info */
1553 pkt
= pack_int (pkt
, mode
); /* mode */
1554 pkt
= pack_threadid (pkt
, id
); /* threadid */
1555 *pkt
= '\0'; /* terminate */
1559 /* These values tag the fields in a thread info response packet. */
1560 /* Tagging the fields allows us to request specific fields and to
1561 add more fields as time goes by. */
1563 #define TAG_THREADID 1 /* Echo the thread identifier. */
1564 #define TAG_EXISTS 2 /* Is this process defined enough to
1565 fetch registers and its stack? */
1566 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1567 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
1568 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1572 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1573 struct gdb_ext_thread_info
*info
)
1575 struct remote_state
*rs
= get_remote_state ();
1579 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
1582 /* info->threadid = 0; FIXME: implement zero_threadref. */
1584 info
->display
[0] = '\0';
1585 info
->shortname
[0] = '\0';
1586 info
->more_display
[0] = '\0';
1588 /* Assume the characters indicating the packet type have been
1590 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1591 pkt
= unpack_threadid (pkt
, &ref
);
1594 warning (_("Incomplete response to threadinfo request."));
1595 if (!threadmatch (&ref
, expectedref
))
1596 { /* This is an answer to a different request. */
1597 warning (_("ERROR RMT Thread info mismatch."));
1600 copy_threadref (&info
->threadid
, &ref
);
1602 /* Loop on tagged fields , try to bail if somthing goes wrong. */
1604 /* Packets are terminated with nulls. */
1605 while ((pkt
< limit
) && mask
&& *pkt
)
1607 pkt
= unpack_int (pkt
, &tag
); /* tag */
1608 pkt
= unpack_byte (pkt
, &length
); /* length */
1609 if (!(tag
& mask
)) /* Tags out of synch with mask. */
1611 warning (_("ERROR RMT: threadinfo tag mismatch."));
1615 if (tag
== TAG_THREADID
)
1619 warning (_("ERROR RMT: length of threadid is not 16."));
1623 pkt
= unpack_threadid (pkt
, &ref
);
1624 mask
= mask
& ~TAG_THREADID
;
1627 if (tag
== TAG_EXISTS
)
1629 info
->active
= stub_unpack_int (pkt
, length
);
1631 mask
= mask
& ~(TAG_EXISTS
);
1634 warning (_("ERROR RMT: 'exists' length too long."));
1640 if (tag
== TAG_THREADNAME
)
1642 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1643 mask
= mask
& ~TAG_THREADNAME
;
1646 if (tag
== TAG_DISPLAY
)
1648 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1649 mask
= mask
& ~TAG_DISPLAY
;
1652 if (tag
== TAG_MOREDISPLAY
)
1654 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1655 mask
= mask
& ~TAG_MOREDISPLAY
;
1658 warning (_("ERROR RMT: unknown thread info tag."));
1659 break; /* Not a tag we know about. */
1665 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1666 struct gdb_ext_thread_info
*info
)
1668 struct remote_state
*rs
= get_remote_state ();
1671 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
1673 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1674 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
1679 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1682 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1683 threadref
*nextthread
)
1685 *pkt
++ = 'q'; /* info query packet */
1686 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1687 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1688 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1689 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1694 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1697 parse_threadlist_response (char *pkt
, int result_limit
,
1698 threadref
*original_echo
, threadref
*resultlist
,
1701 struct remote_state
*rs
= get_remote_state ();
1703 int count
, resultcount
, done
;
1706 /* Assume the 'q' and 'M chars have been stripped. */
1707 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
1708 /* done parse past here */
1709 pkt
= unpack_byte (pkt
, &count
); /* count field */
1710 pkt
= unpack_nibble (pkt
, &done
);
1711 /* The first threadid is the argument threadid. */
1712 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1713 while ((count
-- > 0) && (pkt
< limit
))
1715 pkt
= unpack_threadid (pkt
, resultlist
++);
1716 if (resultcount
++ >= result_limit
)
1725 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1726 int *done
, int *result_count
, threadref
*threadlist
)
1728 struct remote_state
*rs
= get_remote_state ();
1729 static threadref echo_nextthread
;
1732 /* Trancate result limit to be smaller than the packet size. */
1733 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= get_remote_packet_size ())
1734 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
1736 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
1738 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1740 if (*rs
->buf
== '\0')
1744 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
1747 if (!threadmatch (&echo_nextthread
, nextthread
))
1749 /* FIXME: This is a good reason to drop the packet. */
1750 /* Possably, there is a duplicate response. */
1752 retransmit immediatly - race conditions
1753 retransmit after timeout - yes
1755 wait for packet, then exit
1757 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
1758 return 0; /* I choose simply exiting. */
1760 if (*result_count
<= 0)
1764 warning (_("RMT ERROR : failed to get remote thread list."));
1767 return result
; /* break; */
1769 if (*result_count
> result_limit
)
1772 warning (_("RMT ERROR: threadlist response longer than requested."));
1778 /* This is the interface between remote and threads, remotes upper
1781 /* remote_find_new_threads retrieves the thread list and for each
1782 thread in the list, looks up the thread in GDB's internal list,
1783 ading the thread if it does not already exist. This involves
1784 getting partial thread lists from the remote target so, polling the
1785 quit_flag is required. */
1788 /* About this many threadisds fit in a packet. */
1790 #define MAXTHREADLISTRESULTS 32
1793 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1796 int done
, i
, result_count
;
1800 static threadref nextthread
;
1801 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1806 if (loopcount
++ > looplimit
)
1809 warning (_("Remote fetch threadlist -infinite loop-."));
1812 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1813 &done
, &result_count
, resultthreadlist
))
1818 /* Clear for later iterations. */
1820 /* Setup to resume next batch of thread references, set nextthread. */
1821 if (result_count
>= 1)
1822 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1824 while (result_count
--)
1825 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1832 remote_newthread_step (threadref
*ref
, void *context
)
1836 ptid
= pid_to_ptid (threadref_to_int (ref
));
1838 if (!in_thread_list (ptid
))
1840 return 1; /* continue iterator */
1843 #define CRAZY_MAX_THREADS 1000
1846 remote_current_thread (ptid_t oldpid
)
1848 struct remote_state
*rs
= get_remote_state ();
1851 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1852 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
1853 /* Use strtoul here, so we'll correctly parse values whose highest
1854 bit is set. The protocol carries them as a simple series of
1855 hex digits; in the absence of a sign, strtol will see such
1856 values as positive numbers out of range for signed 'long', and
1857 return LONG_MAX to indicate an overflow. */
1858 return pid_to_ptid (strtoul (&rs
->buf
[2], NULL
, 16));
1863 /* Find new threads for info threads command.
1864 * Original version, using John Metzler's thread protocol.
1868 remote_find_new_threads (void)
1870 remote_threadlist_iterator (remote_newthread_step
, 0,
1872 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
) /* ack ack ack */
1873 inferior_ptid
= remote_current_thread (inferior_ptid
);
1877 * Find all threads for info threads command.
1878 * Uses new thread protocol contributed by Cisco.
1879 * Falls back and attempts to use the older method (above)
1880 * if the target doesn't respond to the new method.
1884 remote_threads_info (void)
1886 struct remote_state
*rs
= get_remote_state ();
1890 if (remote_desc
== 0) /* paranoia */
1891 error (_("Command can only be used when connected to the remote target."));
1893 if (use_threadinfo_query
)
1895 putpkt ("qfThreadInfo");
1896 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1898 if (bufp
[0] != '\0') /* q packet recognized */
1900 while (*bufp
++ == 'm') /* reply contains one or more TID */
1904 /* Use strtoul here, so we'll correctly parse values
1905 whose highest bit is set. The protocol carries
1906 them as a simple series of hex digits; in the
1907 absence of a sign, strtol will see such values as
1908 positive numbers out of range for signed 'long',
1909 and return LONG_MAX to indicate an overflow. */
1910 tid
= strtoul (bufp
, &bufp
, 16);
1911 if (tid
!= 0 && !in_thread_list (pid_to_ptid (tid
)))
1912 add_thread (pid_to_ptid (tid
));
1914 while (*bufp
++ == ','); /* comma-separated list */
1915 putpkt ("qsThreadInfo");
1916 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1923 /* Else fall back to old method based on jmetzler protocol. */
1924 use_threadinfo_query
= 0;
1925 remote_find_new_threads ();
1930 * Collect a descriptive string about the given thread.
1931 * The target may say anything it wants to about the thread
1932 * (typically info about its blocked / runnable state, name, etc.).
1933 * This string will appear in the info threads display.
1935 * Optional: targets are not required to implement this function.
1939 remote_threads_extra_info (struct thread_info
*tp
)
1941 struct remote_state
*rs
= get_remote_state ();
1945 struct gdb_ext_thread_info threadinfo
;
1946 static char display_buf
[100]; /* arbitrary... */
1947 int n
= 0; /* position in display_buf */
1949 if (remote_desc
== 0) /* paranoia */
1950 internal_error (__FILE__
, __LINE__
,
1951 _("remote_threads_extra_info"));
1953 if (use_threadextra_query
)
1955 xsnprintf (rs
->buf
, get_remote_packet_size (), "qThreadExtraInfo,%x",
1958 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1959 if (rs
->buf
[0] != 0)
1961 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
1962 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
1963 display_buf
[result
] = '\0';
1968 /* If the above query fails, fall back to the old method. */
1969 use_threadextra_query
= 0;
1970 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1971 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1972 int_to_threadref (&id
, PIDGET (tp
->ptid
));
1973 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
1974 if (threadinfo
.active
)
1976 if (*threadinfo
.shortname
)
1977 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
1978 " Name: %s,", threadinfo
.shortname
);
1979 if (*threadinfo
.display
)
1980 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
1981 " State: %s,", threadinfo
.display
);
1982 if (*threadinfo
.more_display
)
1983 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
1984 " Priority: %s", threadinfo
.more_display
);
1988 /* For purely cosmetic reasons, clear up trailing commas. */
1989 if (',' == display_buf
[n
-1])
1990 display_buf
[n
-1] = ' ';
1998 /* Restart the remote side; this is an extended protocol operation. */
2001 extended_remote_restart (void)
2003 struct remote_state
*rs
= get_remote_state ();
2005 /* Send the restart command; for reasons I don't understand the
2006 remote side really expects a number after the "R". */
2007 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2010 remote_fileio_reset ();
2013 /* Clean up connection to a remote debugger. */
2016 remote_close (int quitting
)
2019 serial_close (remote_desc
);
2023 /* Query the remote side for the text, data and bss offsets. */
2028 struct remote_state
*rs
= get_remote_state ();
2031 int lose
, num_segments
= 0, do_sections
, do_segments
;
2032 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
2033 struct section_offsets
*offs
;
2034 struct symfile_segment_data
*data
;
2036 if (symfile_objfile
== NULL
)
2039 putpkt ("qOffsets");
2040 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2043 if (buf
[0] == '\000')
2044 return; /* Return silently. Stub doesn't support
2048 warning (_("Remote failure reply: %s"), buf
);
2052 /* Pick up each field in turn. This used to be done with scanf, but
2053 scanf will make trouble if CORE_ADDR size doesn't match
2054 conversion directives correctly. The following code will work
2055 with any size of CORE_ADDR. */
2056 text_addr
= data_addr
= bss_addr
= 0;
2060 if (strncmp (ptr
, "Text=", 5) == 0)
2063 /* Don't use strtol, could lose on big values. */
2064 while (*ptr
&& *ptr
!= ';')
2065 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2067 if (strncmp (ptr
, ";Data=", 6) == 0)
2070 while (*ptr
&& *ptr
!= ';')
2071 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2076 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
2079 while (*ptr
&& *ptr
!= ';')
2080 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
2082 if (bss_addr
!= data_addr
)
2083 warning (_("Target reported unsupported offsets: %s"), buf
);
2088 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
2091 /* Don't use strtol, could lose on big values. */
2092 while (*ptr
&& *ptr
!= ';')
2093 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2096 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
2099 while (*ptr
&& *ptr
!= ';')
2100 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2108 error (_("Malformed response to offset query, %s"), buf
);
2109 else if (*ptr
!= '\0')
2110 warning (_("Target reported unsupported offsets: %s"), buf
);
2112 offs
= ((struct section_offsets
*)
2113 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
2114 memcpy (offs
, symfile_objfile
->section_offsets
,
2115 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2117 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
2118 do_segments
= (data
!= NULL
);
2119 do_sections
= num_segments
== 0;
2121 if (num_segments
> 0)
2123 segments
[0] = text_addr
;
2124 segments
[1] = data_addr
;
2126 /* If we have two segments, we can still try to relocate everything
2127 by assuming that the .text and .data offsets apply to the whole
2128 text and data segments. Convert the offsets given in the packet
2129 to base addresses for symfile_map_offsets_to_segments. */
2130 else if (data
&& data
->num_segments
== 2)
2132 segments
[0] = data
->segment_bases
[0] + text_addr
;
2133 segments
[1] = data
->segment_bases
[1] + data_addr
;
2136 /* There's no way to relocate by segment. */
2142 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
2143 offs
, num_segments
, segments
);
2145 if (ret
== 0 && !do_sections
)
2146 error (_("Can not handle qOffsets TextSeg response with this symbol file"));
2153 free_symfile_segment_data (data
);
2157 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2159 /* This is a temporary kludge to force data and bss to use the same offsets
2160 because that's what nlmconv does now. The real solution requires changes
2161 to the stub and remote.c that I don't have time to do right now. */
2163 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2164 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2167 objfile_relocate (symfile_objfile
, offs
);
2170 /* Stub for catch_exception. */
2172 struct start_remote_args
2176 /* The current target. */
2177 struct target_ops
*target
;
2179 /* Non-zero if this is an extended-remote target. */
2184 remote_start_remote (struct ui_out
*uiout
, void *opaque
)
2186 struct remote_state
*rs
= get_remote_state ();
2187 struct start_remote_args
*args
= opaque
;
2188 char *wait_status
= NULL
;
2190 immediate_quit
++; /* Allow user to interrupt it. */
2192 /* Ack any packet which the remote side has already sent. */
2193 serial_write (remote_desc
, "+", 1);
2195 /* Check whether the target is running now. */
2197 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2199 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
2201 if (args
->extended_p
)
2203 /* We're connected, but not running. Drop out before we
2204 call start_remote. */
2205 target_mark_exited (args
->target
);
2209 error (_("The target is not running (try extended-remote?)"));
2213 if (args
->extended_p
)
2214 target_mark_running (args
->target
);
2216 /* Save the reply for later. */
2217 wait_status
= alloca (strlen (rs
->buf
) + 1);
2218 strcpy (wait_status
, rs
->buf
);
2221 /* Let the stub know that we want it to return the thread. */
2224 /* Without this, some commands which require an active target
2225 (such as kill) won't work. This variable serves (at least)
2226 double duty as both the pid of the target process (if it has
2227 such), and as a flag indicating that a target is active.
2228 These functions should be split out into seperate variables,
2229 especially since GDB will someday have a notion of debugging
2230 several processes. */
2231 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
2233 /* Now, if we have thread information, update inferior_ptid. */
2234 inferior_ptid
= remote_current_thread (inferior_ptid
);
2236 get_offsets (); /* Get text, data & bss offsets. */
2238 /* Use the previously fetched status. */
2239 gdb_assert (wait_status
!= NULL
);
2240 strcpy (rs
->buf
, wait_status
);
2241 rs
->cached_wait_status
= 1;
2244 start_remote (args
->from_tty
); /* Initialize gdb process mechanisms. */
2247 /* Open a connection to a remote debugger.
2248 NAME is the filename used for communication. */
2251 remote_open (char *name
, int from_tty
)
2253 remote_open_1 (name
, from_tty
, &remote_ops
, 0, 0);
2256 /* Just like remote_open, but with asynchronous support. */
2258 remote_async_open (char *name
, int from_tty
)
2260 remote_open_1 (name
, from_tty
, &remote_async_ops
, 0, 1);
2263 /* Open a connection to a remote debugger using the extended
2264 remote gdb protocol. NAME is the filename used for communication. */
2267 extended_remote_open (char *name
, int from_tty
)
2269 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */,
2273 /* Just like extended_remote_open, but with asynchronous support. */
2275 extended_remote_async_open (char *name
, int from_tty
)
2277 remote_open_1 (name
, from_tty
, &extended_async_remote_ops
,
2278 1 /*extended_p */, 1 /* async_p */);
2281 /* Generic code for opening a connection to a remote target. */
2284 init_all_packet_configs (void)
2287 for (i
= 0; i
< PACKET_MAX
; i
++)
2288 update_packet_config (&remote_protocol_packets
[i
]);
2291 /* Symbol look-up. */
2294 remote_check_symbols (struct objfile
*objfile
)
2296 struct remote_state
*rs
= get_remote_state ();
2297 char *msg
, *reply
, *tmp
;
2298 struct minimal_symbol
*sym
;
2301 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
2304 /* Allocate a message buffer. We can't reuse the input buffer in RS,
2305 because we need both at the same time. */
2306 msg
= alloca (get_remote_packet_size ());
2308 /* Invite target to request symbol lookups. */
2310 putpkt ("qSymbol::");
2311 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2312 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
2315 while (strncmp (reply
, "qSymbol:", 8) == 0)
2318 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
2320 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2322 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
2325 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
2327 /* If this is a function address, return the start of code
2328 instead of any data function descriptor. */
2329 sym_addr
= gdbarch_convert_from_func_ptr_addr (current_gdbarch
,
2333 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
2334 paddr_nz (sym_addr
), &reply
[8]);
2338 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2343 static struct serial
*
2344 remote_serial_open (char *name
)
2346 static int udp_warning
= 0;
2348 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2349 of in ser-tcp.c, because it is the remote protocol assuming that the
2350 serial connection is reliable and not the serial connection promising
2352 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2355 The remote protocol may be unreliable over UDP.\n\
2356 Some events may be lost, rendering further debugging impossible."));
2360 return serial_open (name
);
2363 /* This type describes each known response to the qSupported
2365 struct protocol_feature
2367 /* The name of this protocol feature. */
2370 /* The default for this protocol feature. */
2371 enum packet_support default_support
;
2373 /* The function to call when this feature is reported, or after
2374 qSupported processing if the feature is not supported.
2375 The first argument points to this structure. The second
2376 argument indicates whether the packet requested support be
2377 enabled, disabled, or probed (or the default, if this function
2378 is being called at the end of processing and this feature was
2379 not reported). The third argument may be NULL; if not NULL, it
2380 is a NUL-terminated string taken from the packet following
2381 this feature's name and an equals sign. */
2382 void (*func
) (const struct protocol_feature
*, enum packet_support
,
2385 /* The corresponding packet for this feature. Only used if
2386 FUNC is remote_supported_packet. */
2391 remote_supported_packet (const struct protocol_feature
*feature
,
2392 enum packet_support support
,
2393 const char *argument
)
2397 warning (_("Remote qSupported response supplied an unexpected value for"
2398 " \"%s\"."), feature
->name
);
2402 if (remote_protocol_packets
[feature
->packet
].support
2403 == PACKET_SUPPORT_UNKNOWN
)
2404 remote_protocol_packets
[feature
->packet
].support
= support
;
2408 remote_packet_size (const struct protocol_feature
*feature
,
2409 enum packet_support support
, const char *value
)
2411 struct remote_state
*rs
= get_remote_state ();
2416 if (support
!= PACKET_ENABLE
)
2419 if (value
== NULL
|| *value
== '\0')
2421 warning (_("Remote target reported \"%s\" without a size."),
2427 packet_size
= strtol (value
, &value_end
, 16);
2428 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
2430 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
2431 feature
->name
, value
);
2435 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
2437 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
2438 packet_size
, MAX_REMOTE_PACKET_SIZE
);
2439 packet_size
= MAX_REMOTE_PACKET_SIZE
;
2442 /* Record the new maximum packet size. */
2443 rs
->explicit_packet_size
= packet_size
;
2446 static struct protocol_feature remote_protocol_features
[] = {
2447 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
2448 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
2449 PACKET_qXfer_auxv
},
2450 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
2451 PACKET_qXfer_features
},
2452 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
2453 PACKET_qXfer_libraries
},
2454 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
2455 PACKET_qXfer_memory_map
},
2456 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
2457 PACKET_qXfer_spu_read
},
2458 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
2459 PACKET_qXfer_spu_write
},
2460 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
2461 PACKET_QPassSignals
},
2465 remote_query_supported (void)
2467 struct remote_state
*rs
= get_remote_state ();
2470 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
2472 /* The packet support flags are handled differently for this packet
2473 than for most others. We treat an error, a disabled packet, and
2474 an empty response identically: any features which must be reported
2475 to be used will be automatically disabled. An empty buffer
2476 accomplishes this, since that is also the representation for a list
2477 containing no features. */
2480 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
2482 putpkt ("qSupported");
2483 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2485 /* If an error occured, warn, but do not return - just reset the
2486 buffer to empty and go on to disable features. */
2487 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
2490 warning (_("Remote failure reply: %s"), rs
->buf
);
2495 memset (seen
, 0, sizeof (seen
));
2500 enum packet_support is_supported
;
2501 char *p
, *end
, *name_end
, *value
;
2503 /* First separate out this item from the rest of the packet. If
2504 there's another item after this, we overwrite the separator
2505 (terminated strings are much easier to work with). */
2507 end
= strchr (p
, ';');
2510 end
= p
+ strlen (p
);
2520 warning (_("empty item in \"qSupported\" response"));
2525 name_end
= strchr (p
, '=');
2528 /* This is a name=value entry. */
2529 is_supported
= PACKET_ENABLE
;
2530 value
= name_end
+ 1;
2539 is_supported
= PACKET_ENABLE
;
2543 is_supported
= PACKET_DISABLE
;
2547 is_supported
= PACKET_SUPPORT_UNKNOWN
;
2551 warning (_("unrecognized item \"%s\" in \"qSupported\" response"), p
);
2557 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
2558 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
2560 const struct protocol_feature
*feature
;
2563 feature
= &remote_protocol_features
[i
];
2564 feature
->func (feature
, is_supported
, value
);
2569 /* If we increased the packet size, make sure to increase the global
2570 buffer size also. We delay this until after parsing the entire
2571 qSupported packet, because this is the same buffer we were
2573 if (rs
->buf_size
< rs
->explicit_packet_size
)
2575 rs
->buf_size
= rs
->explicit_packet_size
;
2576 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
2579 /* Handle the defaults for unmentioned features. */
2580 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
2583 const struct protocol_feature
*feature
;
2585 feature
= &remote_protocol_features
[i
];
2586 feature
->func (feature
, feature
->default_support
, NULL
);
2592 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
,
2593 int extended_p
, int async_p
)
2595 struct remote_state
*rs
= get_remote_state ();
2597 error (_("To open a remote debug connection, you need to specify what\n"
2598 "serial device is attached to the remote system\n"
2599 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
2601 /* See FIXME above. */
2603 wait_forever_enabled_p
= 1;
2605 /* If we're connected to a running target, target_preopen will kill it.
2606 But if we're connected to a target system with no running process,
2607 then we will still be connected when it returns. Ask this question
2608 first, before target_preopen has a chance to kill anything. */
2609 if (remote_desc
!= NULL
&& !target_has_execution
)
2612 || query (_("Already connected to a remote target. Disconnect? ")))
2615 error (_("Still connected."));
2618 target_preopen (from_tty
);
2620 unpush_target (target
);
2622 /* This time without a query. If we were connected to an
2623 extended-remote target and target_preopen killed the running
2624 process, we may still be connected. If we are starting "target
2625 remote" now, the extended-remote target will not have been
2626 removed by unpush_target. */
2627 if (remote_desc
!= NULL
&& !target_has_execution
)
2630 /* Make sure we send the passed signals list the next time we resume. */
2631 xfree (last_pass_packet
);
2632 last_pass_packet
= NULL
;
2634 remote_fileio_reset ();
2635 reopen_exec_file ();
2638 remote_desc
= remote_serial_open (name
);
2640 perror_with_name (name
);
2642 if (baud_rate
!= -1)
2644 if (serial_setbaudrate (remote_desc
, baud_rate
))
2646 /* The requested speed could not be set. Error out to
2647 top level after closing remote_desc. Take care to
2648 set remote_desc to NULL to avoid closing remote_desc
2650 serial_close (remote_desc
);
2652 perror_with_name (name
);
2656 serial_raw (remote_desc
);
2658 /* If there is something sitting in the buffer we might take it as a
2659 response to a command, which would be bad. */
2660 serial_flush_input (remote_desc
);
2664 puts_filtered ("Remote debugging using ");
2665 puts_filtered (name
);
2666 puts_filtered ("\n");
2668 push_target (target
); /* Switch to using remote target now. */
2670 /* Assume that the target is running, unless we learn otherwise. */
2671 target_mark_running (target
);
2673 /* Reset the target state; these things will be queried either by
2674 remote_query_supported or as they are needed. */
2675 init_all_packet_configs ();
2676 rs
->explicit_packet_size
= 0;
2678 general_thread
= -2;
2679 continue_thread
= -2;
2681 /* Probe for ability to use "ThreadInfo" query, as required. */
2682 use_threadinfo_query
= 1;
2683 use_threadextra_query
= 1;
2685 /* The first packet we send to the target is the optional "supported
2686 packets" request. If the target can answer this, it will tell us
2687 which later probes to skip. */
2688 remote_query_supported ();
2690 /* Next, if the target can specify a description, read it. We do
2691 this before anything involving memory or registers. */
2692 target_find_description ();
2696 /* With this target we start out by owning the terminal. */
2697 remote_async_terminal_ours_p
= 1;
2699 /* FIXME: cagney/1999-09-23: During the initial connection it is
2700 assumed that the target is already ready and able to respond to
2701 requests. Unfortunately remote_start_remote() eventually calls
2702 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2703 around this. Eventually a mechanism that allows
2704 wait_for_inferior() to expect/get timeouts will be
2706 wait_forever_enabled_p
= 0;
2709 /* First delete any symbols previously loaded from shared libraries. */
2710 no_shared_libraries (NULL
, 0);
2712 /* Start the remote connection. If error() or QUIT, discard this
2713 target (we'd otherwise be in an inconsistent state) and then
2714 propogate the error on up the exception chain. This ensures that
2715 the caller doesn't stumble along blindly assuming that the
2716 function succeeded. The CLI doesn't have this problem but other
2717 UI's, such as MI do.
2719 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2720 this function should return an error indication letting the
2721 caller restore the previous state. Unfortunately the command
2722 ``target remote'' is directly wired to this function making that
2723 impossible. On a positive note, the CLI side of this problem has
2724 been fixed - the function set_cmd_context() makes it possible for
2725 all the ``target ....'' commands to share a common callback
2726 function. See cli-dump.c. */
2728 struct gdb_exception ex
;
2729 struct start_remote_args args
;
2731 args
.from_tty
= from_tty
;
2732 args
.target
= target
;
2733 args
.extended_p
= extended_p
;
2735 ex
= catch_exception (uiout
, remote_start_remote
, &args
, RETURN_MASK_ALL
);
2740 wait_forever_enabled_p
= 1;
2741 throw_exception (ex
);
2746 wait_forever_enabled_p
= 1;
2750 /* Tell the remote that we are using the extended protocol. */
2752 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2755 /* If we connected to a live target, do some additional setup. */
2756 if (target_has_execution
)
2758 if (exec_bfd
) /* No use without an exec file. */
2759 remote_check_symbols (symfile_objfile
);
2763 /* This takes a program previously attached to and detaches it. After
2764 this is done, GDB can be used to debug some other program. We
2765 better not have left any breakpoints in the target program or it'll
2766 die when it hits one. */
2769 remote_detach_1 (char *args
, int from_tty
, int extended
)
2771 struct remote_state
*rs
= get_remote_state ();
2774 error (_("Argument given to \"detach\" when remotely debugging."));
2776 if (!target_has_execution
)
2777 error (_("No process to detach from."));
2779 /* Tell the remote target to detach. */
2780 strcpy (rs
->buf
, "D");
2782 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2784 if (rs
->buf
[0] == 'E')
2785 error (_("Can't detach process."));
2787 /* Unregister the file descriptor from the event loop. */
2788 if (target_is_async_p ())
2789 serial_async (remote_desc
, NULL
, 0);
2791 target_mourn_inferior ();
2795 puts_filtered ("Detached from remote process.\n");
2797 puts_filtered ("Ending remote debugging.\n");
2802 remote_detach (char *args
, int from_tty
)
2804 remote_detach_1 (args
, from_tty
, 0);
2808 extended_remote_detach (char *args
, int from_tty
)
2810 remote_detach_1 (args
, from_tty
, 1);
2813 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
2816 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
2819 error (_("Argument given to \"disconnect\" when remotely debugging."));
2821 /* Unregister the file descriptor from the event loop. */
2822 if (target_is_async_p ())
2823 serial_async (remote_desc
, NULL
, 0);
2825 /* Make sure we unpush even the extended remote targets; mourn
2826 won't do it. So call remote_mourn_1 directly instead of
2827 target_mourn_inferior. */
2828 remote_mourn_1 (target
);
2831 puts_filtered ("Ending remote debugging.\n");
2834 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
2835 be chatty about it. */
2838 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
2840 struct remote_state
*rs
= get_remote_state ();
2843 char *wait_status
= NULL
;
2846 error_no_arg (_("process-id to attach"));
2849 pid
= strtol (args
, &dummy
, 0);
2850 /* Some targets don't set errno on errors, grrr! */
2851 if (pid
== 0 && args
== dummy
)
2852 error (_("Illegal process-id: %s."), args
);
2854 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
2855 error (_("This target does not support attaching to a process"));
2857 sprintf (rs
->buf
, "vAttach;%x", pid
);
2859 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2861 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
2864 printf_unfiltered (_("Attached to %s\n"),
2865 target_pid_to_str (pid_to_ptid (pid
)));
2867 /* Save the reply for later. */
2868 wait_status
= alloca (strlen (rs
->buf
) + 1);
2869 strcpy (wait_status
, rs
->buf
);
2871 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
2872 error (_("This target does not support attaching to a process"));
2874 error (_("Attaching to %s failed"),
2875 target_pid_to_str (pid_to_ptid (pid
)));
2877 target_mark_running (target
);
2878 inferior_ptid
= pid_to_ptid (pid
);
2881 /* Next, if the target can specify a description, read it. We do
2882 this before anything involving memory or registers. */
2883 target_find_description ();
2885 /* Use the previously fetched status. */
2886 gdb_assert (wait_status
!= NULL
);
2887 strcpy (rs
->buf
, wait_status
);
2888 rs
->cached_wait_status
= 1;
2892 extended_remote_attach (char *args
, int from_tty
)
2894 extended_remote_attach_1 (&extended_remote_ops
, args
, from_tty
);
2898 extended_async_remote_attach (char *args
, int from_tty
)
2900 extended_remote_attach_1 (&extended_async_remote_ops
, args
, from_tty
);
2903 /* Convert hex digit A to a number. */
2908 if (a
>= '0' && a
<= '9')
2910 else if (a
>= 'a' && a
<= 'f')
2911 return a
- 'a' + 10;
2912 else if (a
>= 'A' && a
<= 'F')
2913 return a
- 'A' + 10;
2915 error (_("Reply contains invalid hex digit %d"), a
);
2919 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
2923 for (i
= 0; i
< count
; i
++)
2925 if (hex
[0] == 0 || hex
[1] == 0)
2927 /* Hex string is short, or of uneven length.
2928 Return the count that has been converted so far. */
2931 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
2937 /* Convert number NIB to a hex digit. */
2945 return 'a' + nib
- 10;
2949 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
2952 /* May use a length, or a nul-terminated string as input. */
2954 count
= strlen ((char *) bin
);
2956 for (i
= 0; i
< count
; i
++)
2958 *hex
++ = tohex ((*bin
>> 4) & 0xf);
2959 *hex
++ = tohex (*bin
++ & 0xf);
2965 /* Check for the availability of vCont. This function should also check
2969 remote_vcont_probe (struct remote_state
*rs
)
2973 strcpy (rs
->buf
, "vCont?");
2975 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2978 /* Make sure that the features we assume are supported. */
2979 if (strncmp (buf
, "vCont", 5) == 0)
2982 int support_s
, support_S
, support_c
, support_C
;
2988 while (p
&& *p
== ';')
2991 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2993 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2995 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
2997 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
3000 p
= strchr (p
, ';');
3003 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
3004 BUF will make packet_ok disable the packet. */
3005 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
3009 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
3012 /* Resume the remote inferior by using a "vCont" packet. The thread
3013 to be resumed is PTID; STEP and SIGGNAL indicate whether the
3014 resumed thread should be single-stepped and/or signalled. If PTID's
3015 PID is -1, then all threads are resumed; the thread to be stepped and/or
3016 signalled is given in the global INFERIOR_PTID. This function returns
3017 non-zero iff it resumes the inferior.
3019 This function issues a strict subset of all possible vCont commands at the
3023 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
3025 struct remote_state
*rs
= get_remote_state ();
3026 int pid
= PIDGET (ptid
);
3028 struct cleanup
*old_cleanup
;
3030 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
3031 remote_vcont_probe (rs
);
3033 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
3036 /* If we could generate a wider range of packets, we'd have to worry
3037 about overflowing BUF. Should there be a generic
3038 "multi-part-packet" packet? */
3040 if (PIDGET (inferior_ptid
) == MAGIC_NULL_PID
)
3042 /* MAGIC_NULL_PTID means that we don't have any active threads, so we
3043 don't have any PID numbers the inferior will understand. Make sure
3044 to only send forms that do not specify a PID. */
3045 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
3046 outbuf
= xstrprintf ("vCont;S%02x", siggnal
);
3048 outbuf
= xstrprintf ("vCont;s");
3049 else if (siggnal
!= TARGET_SIGNAL_0
)
3050 outbuf
= xstrprintf ("vCont;C%02x", siggnal
);
3052 outbuf
= xstrprintf ("vCont;c");
3056 /* Resume all threads, with preference for INFERIOR_PTID. */
3057 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
3058 outbuf
= xstrprintf ("vCont;S%02x:%x;c", siggnal
,
3059 PIDGET (inferior_ptid
));
3061 outbuf
= xstrprintf ("vCont;s:%x;c", PIDGET (inferior_ptid
));
3062 else if (siggnal
!= TARGET_SIGNAL_0
)
3063 outbuf
= xstrprintf ("vCont;C%02x:%x;c", siggnal
,
3064 PIDGET (inferior_ptid
));
3066 outbuf
= xstrprintf ("vCont;c");
3070 /* Scheduler locking; resume only PTID. */
3071 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
3072 outbuf
= xstrprintf ("vCont;S%02x:%x", siggnal
, pid
);
3074 outbuf
= xstrprintf ("vCont;s:%x", pid
);
3075 else if (siggnal
!= TARGET_SIGNAL_0
)
3076 outbuf
= xstrprintf ("vCont;C%02x:%x", siggnal
, pid
);
3078 outbuf
= xstrprintf ("vCont;c:%x", pid
);
3081 gdb_assert (outbuf
&& strlen (outbuf
) < get_remote_packet_size ());
3082 old_cleanup
= make_cleanup (xfree
, outbuf
);
3086 do_cleanups (old_cleanup
);
3091 /* Tell the remote machine to resume. */
3093 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
3095 static int last_sent_step
;
3098 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
3100 struct remote_state
*rs
= get_remote_state ();
3102 int pid
= PIDGET (ptid
);
3104 last_sent_signal
= siggnal
;
3105 last_sent_step
= step
;
3107 /* Update the inferior on signals to silently pass, if they've changed. */
3108 remote_pass_signals ();
3110 /* The vCont packet doesn't need to specify threads via Hc. */
3111 if (remote_vcont_resume (ptid
, step
, siggnal
))
3114 /* All other supported resume packets do use Hc, so call set_thread. */
3116 set_thread (0, 0); /* Run any thread. */
3118 set_thread (pid
, 0); /* Run this thread. */
3121 if (siggnal
!= TARGET_SIGNAL_0
)
3123 buf
[0] = step
? 'S' : 'C';
3124 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
3125 buf
[2] = tohex (((int) siggnal
) & 0xf);
3129 strcpy (buf
, step
? "s" : "c");
3134 /* Same as remote_resume, but with async support. */
3136 remote_async_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
3138 remote_resume (ptid
, step
, siggnal
);
3140 /* We are about to start executing the inferior, let's register it
3141 with the event loop. NOTE: this is the one place where all the
3142 execution commands end up. We could alternatively do this in each
3143 of the execution commands in infcmd.c. */
3144 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
3145 into infcmd.c in order to allow inferior function calls to work
3146 NOT asynchronously. */
3147 if (target_can_async_p ())
3148 target_async (inferior_event_handler
, 0);
3149 /* Tell the world that the target is now executing. */
3150 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
3151 this? Instead, should the client of target just assume (for
3152 async targets) that the target is going to start executing? Is
3153 this information already found in the continuation block? */
3154 if (target_is_async_p ())
3155 target_executing
= 1;
3159 /* Set up the signal handler for SIGINT, while the target is
3160 executing, ovewriting the 'regular' SIGINT signal handler. */
3162 initialize_sigint_signal_handler (void)
3164 signal (SIGINT
, handle_remote_sigint
);
3167 /* Signal handler for SIGINT, while the target is executing. */
3169 handle_remote_sigint (int sig
)
3171 signal (sig
, handle_remote_sigint_twice
);
3172 mark_async_signal_handler_wrapper (sigint_remote_token
);
3175 /* Signal handler for SIGINT, installed after SIGINT has already been
3176 sent once. It will take effect the second time that the user sends
3179 handle_remote_sigint_twice (int sig
)
3181 signal (sig
, handle_remote_sigint
);
3182 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
3185 /* Perform the real interruption of the target execution, in response
3188 async_remote_interrupt (gdb_client_data arg
)
3191 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
3196 /* Perform interrupt, if the first attempt did not succeed. Just give
3197 up on the target alltogether. */
3199 async_remote_interrupt_twice (gdb_client_data arg
)
3202 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
3207 /* Reinstall the usual SIGINT handlers, after the target has
3210 cleanup_sigint_signal_handler (void *dummy
)
3212 signal (SIGINT
, handle_sigint
);
3215 /* Send ^C to target to halt it. Target will respond, and send us a
3217 static void (*ofunc
) (int);
3219 /* The command line interface's stop routine. This function is installed
3220 as a signal handler for SIGINT. The first time a user requests a
3221 stop, we call remote_stop to send a break or ^C. If there is no
3222 response from the target (it didn't stop when the user requested it),
3223 we ask the user if he'd like to detach from the target. */
3225 remote_interrupt (int signo
)
3227 /* If this doesn't work, try more severe steps. */
3228 signal (signo
, remote_interrupt_twice
);
3230 gdb_call_async_signal_handler (sigint_remote_token
, 1);
3233 /* The user typed ^C twice. */
3236 remote_interrupt_twice (int signo
)
3238 signal (signo
, ofunc
);
3239 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
3240 signal (signo
, remote_interrupt
);
3243 /* This is the generic stop called via the target vector. When a target
3244 interrupt is requested, either by the command line or the GUI, we
3245 will eventually end up here. */
3249 /* Send a break or a ^C, depending on user preference. */
3251 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
3254 serial_send_break (remote_desc
);
3256 serial_write (remote_desc
, "\003", 1);
3259 /* Ask the user what to do when an interrupt is received. */
3262 interrupt_query (void)
3264 target_terminal_ours ();
3266 if (query ("Interrupted while waiting for the program.\n\
3267 Give up (and stop debugging it)? "))
3269 target_mourn_inferior ();
3270 signal (SIGINT
, handle_sigint
);
3271 deprecated_throw_reason (RETURN_QUIT
);
3274 target_terminal_inferior ();
3277 /* Enable/disable target terminal ownership. Most targets can use
3278 terminal groups to control terminal ownership. Remote targets are
3279 different in that explicit transfer of ownership to/from GDB/target
3283 remote_async_terminal_inferior (void)
3285 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
3286 sync_execution here. This function should only be called when
3287 GDB is resuming the inferior in the forground. A background
3288 resume (``run&'') should leave GDB in control of the terminal and
3289 consequently should not call this code. */
3290 if (!sync_execution
)
3292 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
3293 calls target_terminal_*() idenpotent. The event-loop GDB talking
3294 to an asynchronous target with a synchronous command calls this
3295 function from both event-top.c and infrun.c/infcmd.c. Once GDB
3296 stops trying to transfer the terminal to the target when it
3297 shouldn't this guard can go away. */
3298 if (!remote_async_terminal_ours_p
)
3300 delete_file_handler (input_fd
);
3301 remote_async_terminal_ours_p
= 0;
3302 initialize_sigint_signal_handler ();
3303 /* NOTE: At this point we could also register our selves as the
3304 recipient of all input. Any characters typed could then be
3305 passed on down to the target. */
3309 remote_async_terminal_ours (void)
3311 /* See FIXME in remote_async_terminal_inferior. */
3312 if (!sync_execution
)
3314 /* See FIXME in remote_async_terminal_inferior. */
3315 if (remote_async_terminal_ours_p
)
3317 cleanup_sigint_signal_handler (NULL
);
3318 add_file_handler (input_fd
, stdin_event_handler
, 0);
3319 remote_async_terminal_ours_p
= 1;
3322 /* If nonzero, ignore the next kill. */
3327 remote_console_output (char *msg
)
3331 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
3334 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
3337 fputs_unfiltered (tb
, gdb_stdtarg
);
3339 gdb_flush (gdb_stdtarg
);
3342 /* Wait until the remote machine stops, then return,
3343 storing status in STATUS just as `wait' would.
3344 Returns "pid", which in the case of a multi-threaded
3345 remote OS, is the thread-id. */
3348 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3350 struct remote_state
*rs
= get_remote_state ();
3351 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3352 ULONGEST thread_num
= -1;
3354 int solibs_changed
= 0;
3356 status
->kind
= TARGET_WAITKIND_EXITED
;
3357 status
->value
.integer
= 0;
3363 if (rs
->cached_wait_status
)
3364 /* Use the cached wait status, but only once. */
3365 rs
->cached_wait_status
= 0;
3368 ofunc
= signal (SIGINT
, remote_interrupt
);
3369 /* If the user hit C-c before this packet, or between packets,
3370 pretend that it was hit right here. */
3374 remote_interrupt (SIGINT
);
3376 getpkt (&rs
->buf
, &rs
->buf_size
, 1);
3377 signal (SIGINT
, ofunc
);
3382 remote_stopped_by_watchpoint_p
= 0;
3386 case 'E': /* Error of some sort. */
3387 /* We're out of sync with the target now. Did it continue or not?
3388 Not is more likely, so report a stop. */
3389 warning (_("Remote failure reply: %s"), buf
);
3390 status
->kind
= TARGET_WAITKIND_STOPPED
;
3391 status
->value
.sig
= TARGET_SIGNAL_0
;
3393 case 'F': /* File-I/O request. */
3394 remote_fileio_request (buf
);
3396 case 'T': /* Status with PC, SP, FP, ... */
3398 gdb_byte regs
[MAX_REGISTER_SIZE
];
3400 /* Expedited reply, containing Signal, {regno, reg} repeat. */
3401 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3403 n... = register number
3404 r... = register contents
3406 p
= &buf
[3]; /* after Txx */
3415 /* If the packet contains a register number save it in
3416 pnum and set p1 to point to the character following
3417 it. Otherwise p1 points to p. */
3419 /* If this packet is an awatch packet, don't parse the
3420 'a' as a register number. */
3422 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
3424 /* Read the ``P'' register number. */
3425 pnum
= strtol (p
, &p_temp
, 16);
3431 if (p1
== p
) /* No register number present here. */
3433 p1
= strchr (p
, ':');
3435 error (_("Malformed packet(a) (missing colon): %s\n\
3438 if (strncmp (p
, "thread", p1
- p
) == 0)
3440 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3441 record_currthread (thread_num
);
3444 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3445 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3446 || (strncmp (p
, "awatch", p1
- p
) == 0))
3448 remote_stopped_by_watchpoint_p
= 1;
3449 p
= unpack_varlen_hex (++p1
, &addr
);
3450 remote_watch_data_address
= (CORE_ADDR
)addr
;
3452 else if (strncmp (p
, "library", p1
- p
) == 0)
3456 while (*p_temp
&& *p_temp
!= ';')
3464 /* Silently skip unknown optional info. */
3465 p_temp
= strchr (p1
+ 1, ';');
3472 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
3476 error (_("Malformed packet(b) (missing colon): %s\n\
3481 error (_("Remote sent bad register number %s: %s\n\
3483 phex_nz (pnum
, 0), p
, buf
);
3485 fieldsize
= hex2bin (p
, regs
,
3486 register_size (current_gdbarch
,
3489 if (fieldsize
< register_size (current_gdbarch
,
3491 warning (_("Remote reply is too short: %s"), buf
);
3492 regcache_raw_supply (get_current_regcache (),
3497 error (_("Remote register badly formatted: %s\nhere: %s"),
3502 case 'S': /* Old style status, just signal only. */
3504 status
->kind
= TARGET_WAITKIND_LOADED
;
3507 status
->kind
= TARGET_WAITKIND_STOPPED
;
3508 status
->value
.sig
= (enum target_signal
)
3509 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3514 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3515 record_currthread (thread_num
);
3518 case 'W': /* Target exited. */
3520 /* The remote process exited. */
3521 status
->kind
= TARGET_WAITKIND_EXITED
;
3522 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3526 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3527 status
->value
.sig
= (enum target_signal
)
3528 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3532 case 'O': /* Console output. */
3533 remote_console_output (buf
+ 1);
3536 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3538 /* Zero length reply means that we tried 'S' or 'C' and
3539 the remote system doesn't support it. */
3540 target_terminal_ours_for_output ();
3542 ("Can't send signals to this remote system. %s not sent.\n",
3543 target_signal_to_name (last_sent_signal
));
3544 last_sent_signal
= TARGET_SIGNAL_0
;
3545 target_terminal_inferior ();
3547 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3548 putpkt ((char *) buf
);
3551 /* else fallthrough */
3553 warning (_("Invalid remote reply: %s"), buf
);
3558 if (thread_num
!= -1)
3560 return pid_to_ptid (thread_num
);
3562 return inferior_ptid
;
3565 /* Async version of remote_wait. */
3567 remote_async_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3569 struct remote_state
*rs
= get_remote_state ();
3570 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3571 ULONGEST thread_num
= -1;
3573 int solibs_changed
= 0;
3575 status
->kind
= TARGET_WAITKIND_EXITED
;
3576 status
->value
.integer
= 0;
3578 remote_stopped_by_watchpoint_p
= 0;
3584 if (rs
->cached_wait_status
)
3585 /* Use the cached wait status, but only once. */
3586 rs
->cached_wait_status
= 0;
3589 if (!target_is_async_p ())
3591 ofunc
= signal (SIGINT
, remote_interrupt
);
3592 /* If the user hit C-c before this packet, or between packets,
3593 pretend that it was hit right here. */
3597 remote_interrupt (SIGINT
);
3600 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3601 _never_ wait for ever -> test on target_is_async_p().
3602 However, before we do that we need to ensure that the caller
3603 knows how to take the target into/out of async mode. */
3604 getpkt (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
3605 if (!target_is_async_p ())
3606 signal (SIGINT
, ofunc
);
3613 case 'E': /* Error of some sort. */
3614 /* We're out of sync with the target now. Did it continue or not?
3615 Not is more likely, so report a stop. */
3616 warning (_("Remote failure reply: %s"), buf
);
3617 status
->kind
= TARGET_WAITKIND_STOPPED
;
3618 status
->value
.sig
= TARGET_SIGNAL_0
;
3620 case 'F': /* File-I/O request. */
3621 remote_fileio_request (buf
);
3623 case 'T': /* Status with PC, SP, FP, ... */
3625 gdb_byte regs
[MAX_REGISTER_SIZE
];
3627 /* Expedited reply, containing Signal, {regno, reg} repeat. */
3628 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3630 n... = register number
3631 r... = register contents
3633 p
= &buf
[3]; /* after Txx */
3642 /* If the packet contains a register number, save it
3643 in pnum and set p1 to point to the character
3644 following it. Otherwise p1 points to p. */
3646 /* If this packet is an awatch packet, don't parse the 'a'
3647 as a register number. */
3649 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
3651 /* Read the register number. */
3652 pnum
= strtol (p
, &p_temp
, 16);
3658 if (p1
== p
) /* No register number present here. */
3660 p1
= strchr (p
, ':');
3662 error (_("Malformed packet(a) (missing colon): %s\n\
3665 if (strncmp (p
, "thread", p1
- p
) == 0)
3667 p_temp
= unpack_varlen_hex (++p1
, &thread_num
);
3668 record_currthread (thread_num
);
3671 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3672 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3673 || (strncmp (p
, "awatch", p1
- p
) == 0))
3675 remote_stopped_by_watchpoint_p
= 1;
3676 p
= unpack_varlen_hex (++p1
, &addr
);
3677 remote_watch_data_address
= (CORE_ADDR
)addr
;
3679 else if (strncmp (p
, "library", p1
- p
) == 0)
3683 while (*p_temp
&& *p_temp
!= ';')
3691 /* Silently skip unknown optional info. */
3692 p_temp
= strchr (p1
+ 1, ';');
3700 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
3703 error (_("Malformed packet(b) (missing colon): %s\n\
3708 error (_("Remote sent bad register number %ld: %s\n\
3712 fieldsize
= hex2bin (p
, regs
,
3713 register_size (current_gdbarch
,
3716 if (fieldsize
< register_size (current_gdbarch
,
3718 warning (_("Remote reply is too short: %s"), buf
);
3719 regcache_raw_supply (get_current_regcache (),
3724 error (_("Remote register badly formatted: %s\nhere: %s"),
3729 case 'S': /* Old style status, just signal only. */
3731 status
->kind
= TARGET_WAITKIND_LOADED
;
3734 status
->kind
= TARGET_WAITKIND_STOPPED
;
3735 status
->value
.sig
= (enum target_signal
)
3736 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3741 thread_num
= strtol ((const char *) &buf
[4], NULL
, 16);
3742 record_currthread (thread_num
);
3745 case 'W': /* Target exited. */
3747 /* The remote process exited. */
3748 status
->kind
= TARGET_WAITKIND_EXITED
;
3749 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
3753 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3754 status
->value
.sig
= (enum target_signal
)
3755 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3759 case 'O': /* Console output. */
3760 remote_console_output (buf
+ 1);
3761 /* Return immediately to the event loop. The event loop will
3762 still be waiting on the inferior afterwards. */
3763 status
->kind
= TARGET_WAITKIND_IGNORE
;
3766 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3768 /* Zero length reply means that we tried 'S' or 'C' and
3769 the remote system doesn't support it. */
3770 target_terminal_ours_for_output ();
3772 ("Can't send signals to this remote system. %s not sent.\n",
3773 target_signal_to_name (last_sent_signal
));
3774 last_sent_signal
= TARGET_SIGNAL_0
;
3775 target_terminal_inferior ();
3777 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3778 putpkt ((char *) buf
);
3781 /* else fallthrough */
3783 warning (_("Invalid remote reply: %s"), buf
);
3788 if (thread_num
!= -1)
3790 return pid_to_ptid (thread_num
);
3792 return inferior_ptid
;
3795 /* Fetch a single register using a 'p' packet. */
3798 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
3800 struct remote_state
*rs
= get_remote_state ();
3802 char regp
[MAX_REGISTER_SIZE
];
3805 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
3808 if (reg
->pnum
== -1)
3813 p
+= hexnumstr (p
, reg
->pnum
);
3815 remote_send (&rs
->buf
, &rs
->buf_size
);
3819 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
3823 case PACKET_UNKNOWN
:
3826 error (_("Could not fetch register \"%s\""),
3827 gdbarch_register_name (get_regcache_arch (regcache
), reg
->regnum
));
3830 /* If this register is unfetchable, tell the regcache. */
3833 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
3837 /* Otherwise, parse and supply the value. */
3843 error (_("fetch_register_using_p: early buf termination"));
3845 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3848 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
3852 /* Fetch the registers included in the target's 'g' packet. */
3855 send_g_packet (void)
3857 struct remote_state
*rs
= get_remote_state ();
3862 sprintf (rs
->buf
, "g");
3863 remote_send (&rs
->buf
, &rs
->buf_size
);
3865 /* We can get out of synch in various cases. If the first character
3866 in the buffer is not a hex character, assume that has happened
3867 and try to fetch another packet to read. */
3868 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
3869 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
3870 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
3871 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
3874 fprintf_unfiltered (gdb_stdlog
,
3875 "Bad register packet; fetching a new packet\n");
3876 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3879 buf_len
= strlen (rs
->buf
);
3881 /* Sanity check the received packet. */
3882 if (buf_len
% 2 != 0)
3883 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
3889 process_g_packet (struct regcache
*regcache
)
3891 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3892 struct remote_state
*rs
= get_remote_state ();
3893 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3898 buf_len
= strlen (rs
->buf
);
3900 /* Further sanity checks, with knowledge of the architecture. */
3901 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
3902 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
3904 /* Save the size of the packet sent to us by the target. It is used
3905 as a heuristic when determining the max size of packets that the
3906 target can safely receive. */
3907 if (rsa
->actual_register_packet_size
== 0)
3908 rsa
->actual_register_packet_size
= buf_len
;
3910 /* If this is smaller than we guessed the 'g' packet would be,
3911 update our records. A 'g' reply that doesn't include a register's
3912 value implies either that the register is not available, or that
3913 the 'p' packet must be used. */
3914 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
3916 rsa
->sizeof_g_packet
= buf_len
/ 2;
3918 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
3920 if (rsa
->regs
[i
].pnum
== -1)
3923 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
3924 rsa
->regs
[i
].in_g_packet
= 0;
3926 rsa
->regs
[i
].in_g_packet
= 1;
3930 regs
= alloca (rsa
->sizeof_g_packet
);
3932 /* Unimplemented registers read as all bits zero. */
3933 memset (regs
, 0, rsa
->sizeof_g_packet
);
3935 /* Reply describes registers byte by byte, each byte encoded as two
3936 hex characters. Suck them all up, then supply them to the
3937 register cacheing/storage mechanism. */
3940 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
3942 if (p
[0] == 0 || p
[1] == 0)
3943 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
3944 internal_error (__FILE__
, __LINE__
,
3945 "unexpected end of 'g' packet reply");
3947 if (p
[0] == 'x' && p
[1] == 'x')
3948 regs
[i
] = 0; /* 'x' */
3950 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3956 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
3958 struct packet_reg
*r
= &rsa
->regs
[i
];
3961 if (r
->offset
* 2 >= strlen (rs
->buf
))
3962 /* This shouldn't happen - we adjusted in_g_packet above. */
3963 internal_error (__FILE__
, __LINE__
,
3964 "unexpected end of 'g' packet reply");
3965 else if (rs
->buf
[r
->offset
* 2] == 'x')
3967 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
3968 /* The register isn't available, mark it as such (at
3969 the same time setting the value to zero). */
3970 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
3973 regcache_raw_supply (regcache
, r
->regnum
,
3981 fetch_registers_using_g (struct regcache
*regcache
)
3984 process_g_packet (regcache
);
3988 remote_fetch_registers (struct regcache
*regcache
, int regnum
)
3990 struct remote_state
*rs
= get_remote_state ();
3991 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3994 set_thread (PIDGET (inferior_ptid
), 1);
3998 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
3999 gdb_assert (reg
!= NULL
);
4001 /* If this register might be in the 'g' packet, try that first -
4002 we are likely to read more than one register. If this is the
4003 first 'g' packet, we might be overly optimistic about its
4004 contents, so fall back to 'p'. */
4005 if (reg
->in_g_packet
)
4007 fetch_registers_using_g (regcache
);
4008 if (reg
->in_g_packet
)
4012 if (fetch_register_using_p (regcache
, reg
))
4015 /* This register is not available. */
4016 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
4021 fetch_registers_using_g (regcache
);
4023 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
4024 if (!rsa
->regs
[i
].in_g_packet
)
4025 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
4027 /* This register is not available. */
4028 regcache_raw_supply (regcache
, i
, NULL
);
4032 /* Prepare to store registers. Since we may send them all (using a
4033 'G' request), we have to read out the ones we don't want to change
4037 remote_prepare_to_store (struct regcache
*regcache
)
4039 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4041 gdb_byte buf
[MAX_REGISTER_SIZE
];
4043 /* Make sure the entire registers array is valid. */
4044 switch (remote_protocol_packets
[PACKET_P
].support
)
4046 case PACKET_DISABLE
:
4047 case PACKET_SUPPORT_UNKNOWN
:
4048 /* Make sure all the necessary registers are cached. */
4049 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
4050 if (rsa
->regs
[i
].in_g_packet
)
4051 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
4058 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
4059 packet was not recognized. */
4062 store_register_using_P (const struct regcache
*regcache
, struct packet_reg
*reg
)
4064 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
4065 struct remote_state
*rs
= get_remote_state ();
4066 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4067 /* Try storing a single register. */
4068 char *buf
= rs
->buf
;
4069 gdb_byte regp
[MAX_REGISTER_SIZE
];
4072 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
4075 if (reg
->pnum
== -1)
4078 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
4079 p
= buf
+ strlen (buf
);
4080 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
4081 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
4082 remote_send (&rs
->buf
, &rs
->buf_size
);
4084 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
4089 error (_("Could not write register \"%s\""),
4090 gdbarch_register_name (gdbarch
, reg
->regnum
));
4091 case PACKET_UNKNOWN
:
4094 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
4098 /* Store register REGNUM, or all registers if REGNUM == -1, from the
4099 contents of the register cache buffer. FIXME: ignores errors. */
4102 store_registers_using_G (const struct regcache
*regcache
)
4104 struct remote_state
*rs
= get_remote_state ();
4105 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4109 /* Extract all the registers in the regcache copying them into a
4113 regs
= alloca (rsa
->sizeof_g_packet
);
4114 memset (regs
, 0, rsa
->sizeof_g_packet
);
4115 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
4117 struct packet_reg
*r
= &rsa
->regs
[i
];
4119 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
4123 /* Command describes registers byte by byte,
4124 each byte encoded as two hex characters. */
4127 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
4129 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
4130 remote_send (&rs
->buf
, &rs
->buf_size
);
4133 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
4134 of the register cache buffer. FIXME: ignores errors. */
4137 remote_store_registers (struct regcache
*regcache
, int regnum
)
4139 struct remote_state
*rs
= get_remote_state ();
4140 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4143 set_thread (PIDGET (inferior_ptid
), 1);
4147 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
4148 gdb_assert (reg
!= NULL
);
4150 /* Always prefer to store registers using the 'P' packet if
4151 possible; we often change only a small number of registers.
4152 Sometimes we change a larger number; we'd need help from a
4153 higher layer to know to use 'G'. */
4154 if (store_register_using_P (regcache
, reg
))
4157 /* For now, don't complain if we have no way to write the
4158 register. GDB loses track of unavailable registers too
4159 easily. Some day, this may be an error. We don't have
4160 any way to read the register, either... */
4161 if (!reg
->in_g_packet
)
4164 store_registers_using_G (regcache
);
4168 store_registers_using_G (regcache
);
4170 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
4171 if (!rsa
->regs
[i
].in_g_packet
)
4172 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
4173 /* See above for why we do not issue an error here. */
4178 /* Return the number of hex digits in num. */
4181 hexnumlen (ULONGEST num
)
4185 for (i
= 0; num
!= 0; i
++)
4191 /* Set BUF to the minimum number of hex digits representing NUM. */
4194 hexnumstr (char *buf
, ULONGEST num
)
4196 int len
= hexnumlen (num
);
4197 return hexnumnstr (buf
, num
, len
);
4201 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
4204 hexnumnstr (char *buf
, ULONGEST num
, int width
)
4210 for (i
= width
- 1; i
>= 0; i
--)
4212 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
4219 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
4222 remote_address_masked (CORE_ADDR addr
)
4224 int address_size
= remote_address_size
;
4225 /* If "remoteaddresssize" was not set, default to target address size. */
4227 address_size
= gdbarch_addr_bit (current_gdbarch
);
4229 if (address_size
> 0
4230 && address_size
< (sizeof (ULONGEST
) * 8))
4232 /* Only create a mask when that mask can safely be constructed
4233 in a ULONGEST variable. */
4235 mask
= (mask
<< address_size
) - 1;
4241 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
4242 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
4243 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
4244 (which may be more than *OUT_LEN due to escape characters). The
4245 total number of bytes in the output buffer will be at most
4249 remote_escape_output (const gdb_byte
*buffer
, int len
,
4250 gdb_byte
*out_buf
, int *out_len
,
4253 int input_index
, output_index
;
4256 for (input_index
= 0; input_index
< len
; input_index
++)
4258 gdb_byte b
= buffer
[input_index
];
4260 if (b
== '$' || b
== '#' || b
== '}')
4262 /* These must be escaped. */
4263 if (output_index
+ 2 > out_maxlen
)
4265 out_buf
[output_index
++] = '}';
4266 out_buf
[output_index
++] = b
^ 0x20;
4270 if (output_index
+ 1 > out_maxlen
)
4272 out_buf
[output_index
++] = b
;
4276 *out_len
= input_index
;
4277 return output_index
;
4280 /* Convert BUFFER, escaped data LEN bytes long, into binary data
4281 in OUT_BUF. Return the number of bytes written to OUT_BUF.
4282 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
4284 This function reverses remote_escape_output. It allows more
4285 escaped characters than that function does, in particular because
4286 '*' must be escaped to avoid the run-length encoding processing
4287 in reading packets. */
4290 remote_unescape_input (const gdb_byte
*buffer
, int len
,
4291 gdb_byte
*out_buf
, int out_maxlen
)
4293 int input_index
, output_index
;
4298 for (input_index
= 0; input_index
< len
; input_index
++)
4300 gdb_byte b
= buffer
[input_index
];
4302 if (output_index
+ 1 > out_maxlen
)
4304 warning (_("Received too much data from remote target;"
4305 " ignoring overflow."));
4306 return output_index
;
4311 out_buf
[output_index
++] = b
^ 0x20;
4317 out_buf
[output_index
++] = b
;
4321 error (_("Unmatched escape character in target response."));
4323 return output_index
;
4326 /* Determine whether the remote target supports binary downloading.
4327 This is accomplished by sending a no-op memory write of zero length
4328 to the target at the specified address. It does not suffice to send
4329 the whole packet, since many stubs strip the eighth bit and
4330 subsequently compute a wrong checksum, which causes real havoc with
4333 NOTE: This can still lose if the serial line is not eight-bit
4334 clean. In cases like this, the user should clear "remote
4338 check_binary_download (CORE_ADDR addr
)
4340 struct remote_state
*rs
= get_remote_state ();
4342 switch (remote_protocol_packets
[PACKET_X
].support
)
4344 case PACKET_DISABLE
:
4348 case PACKET_SUPPORT_UNKNOWN
:
4354 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4356 p
+= hexnumstr (p
, (ULONGEST
) 0);
4360 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
4361 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4363 if (rs
->buf
[0] == '\0')
4366 fprintf_unfiltered (gdb_stdlog
,
4367 "binary downloading NOT suppported by target\n");
4368 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
4373 fprintf_unfiltered (gdb_stdlog
,
4374 "binary downloading suppported by target\n");
4375 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
4382 /* Write memory data directly to the remote machine.
4383 This does not inform the data cache; the data cache uses this.
4384 HEADER is the starting part of the packet.
4385 MEMADDR is the address in the remote memory space.
4386 MYADDR is the address of the buffer in our space.
4387 LEN is the number of bytes.
4388 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
4389 should send data as binary ('X'), or hex-encoded ('M').
4391 The function creates packet of the form
4392 <HEADER><ADDRESS>,<LENGTH>:<DATA>
4394 where encoding of <DATA> is termined by PACKET_FORMAT.
4396 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
4399 Returns the number of bytes transferred, or 0 (setting errno) for
4400 error. Only transfer a single packet. */
4403 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
4404 const gdb_byte
*myaddr
, int len
,
4405 char packet_format
, int use_length
)
4407 struct remote_state
*rs
= get_remote_state ();
4417 if (packet_format
!= 'X' && packet_format
!= 'M')
4418 internal_error (__FILE__
, __LINE__
,
4419 "remote_write_bytes_aux: bad packet format");
4424 payload_size
= get_memory_write_packet_size ();
4426 /* The packet buffer will be large enough for the payload;
4427 get_memory_packet_size ensures this. */
4430 /* Compute the size of the actual payload by subtracting out the
4431 packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
4433 payload_size
-= strlen ("$,:#NN");
4435 /* The comma won't be used. */
4437 header_length
= strlen (header
);
4438 payload_size
-= header_length
;
4439 payload_size
-= hexnumlen (memaddr
);
4441 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
4443 strcat (rs
->buf
, header
);
4444 p
= rs
->buf
+ strlen (header
);
4446 /* Compute a best guess of the number of bytes actually transfered. */
4447 if (packet_format
== 'X')
4449 /* Best guess at number of bytes that will fit. */
4450 todo
= min (len
, payload_size
);
4452 payload_size
-= hexnumlen (todo
);
4453 todo
= min (todo
, payload_size
);
4457 /* Num bytes that will fit. */
4458 todo
= min (len
, payload_size
/ 2);
4460 payload_size
-= hexnumlen (todo
);
4461 todo
= min (todo
, payload_size
/ 2);
4465 internal_error (__FILE__
, __LINE__
,
4466 _("minumum packet size too small to write data"));
4468 /* If we already need another packet, then try to align the end
4469 of this packet to a useful boundary. */
4470 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
4471 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
4473 /* Append "<memaddr>". */
4474 memaddr
= remote_address_masked (memaddr
);
4475 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
4482 /* Append <len>. Retain the location/size of <len>. It may need to
4483 be adjusted once the packet body has been created. */
4485 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
4493 /* Append the packet body. */
4494 if (packet_format
== 'X')
4496 /* Binary mode. Send target system values byte by byte, in
4497 increasing byte addresses. Only escape certain critical
4499 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
4502 /* If not all TODO bytes fit, then we'll need another packet. Make
4503 a second try to keep the end of the packet aligned. Don't do
4504 this if the packet is tiny. */
4505 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
4509 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
4511 if (new_nr_bytes
!= nr_bytes
)
4512 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
4517 p
+= payload_length
;
4518 if (use_length
&& nr_bytes
< todo
)
4520 /* Escape chars have filled up the buffer prematurely,
4521 and we have actually sent fewer bytes than planned.
4522 Fix-up the length field of the packet. Use the same
4523 number of characters as before. */
4524 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
4525 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
4530 /* Normal mode: Send target system values byte by byte, in
4531 increasing byte addresses. Each byte is encoded as a two hex
4533 nr_bytes
= bin2hex (myaddr
, p
, todo
);
4537 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
4538 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4540 if (rs
->buf
[0] == 'E')
4542 /* There is no correspondance between what the remote protocol
4543 uses for errors and errno codes. We would like a cleaner way
4544 of representing errors (big enough to include errno codes,
4545 bfd_error codes, and others). But for now just return EIO. */
4550 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
4551 fewer bytes than we'd planned. */
4555 /* Write memory data directly to the remote machine.
4556 This does not inform the data cache; the data cache uses this.
4557 MEMADDR is the address in the remote memory space.
4558 MYADDR is the address of the buffer in our space.
4559 LEN is the number of bytes.
4561 Returns number of bytes transferred, or 0 (setting errno) for
4562 error. Only transfer a single packet. */
4565 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
4567 char *packet_format
= 0;
4569 /* Check whether the target supports binary download. */
4570 check_binary_download (memaddr
);
4572 switch (remote_protocol_packets
[PACKET_X
].support
)
4575 packet_format
= "X";
4577 case PACKET_DISABLE
:
4578 packet_format
= "M";
4580 case PACKET_SUPPORT_UNKNOWN
:
4581 internal_error (__FILE__
, __LINE__
,
4582 _("remote_write_bytes: bad internal state"));
4584 internal_error (__FILE__
, __LINE__
, _("bad switch"));
4587 return remote_write_bytes_aux (packet_format
,
4588 memaddr
, myaddr
, len
, packet_format
[0], 1);
4591 /* Read memory data directly from the remote machine.
4592 This does not use the data cache; the data cache uses this.
4593 MEMADDR is the address in the remote memory space.
4594 MYADDR is the address of the buffer in our space.
4595 LEN is the number of bytes.
4597 Returns number of bytes transferred, or 0 for error. */
4599 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
4600 remote targets) shouldn't attempt to read the entire buffer.
4601 Instead it should read a single packet worth of data and then
4602 return the byte size of that packet to the caller. The caller (its
4603 caller and its callers caller ;-) already contains code for
4604 handling partial reads. */
4607 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
4609 struct remote_state
*rs
= get_remote_state ();
4610 int max_buf_size
; /* Max size of packet output buffer. */
4616 max_buf_size
= get_memory_read_packet_size ();
4617 /* The packet buffer will be large enough for the payload;
4618 get_memory_packet_size ensures this. */
4627 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
4629 /* construct "m"<memaddr>","<len>" */
4630 /* sprintf (rs->buf, "m%lx,%x", (unsigned long) memaddr, todo); */
4631 memaddr
= remote_address_masked (memaddr
);
4634 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
4636 p
+= hexnumstr (p
, (ULONGEST
) todo
);
4640 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4642 if (rs
->buf
[0] == 'E'
4643 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
4644 && rs
->buf
[3] == '\0')
4646 /* There is no correspondance between what the remote
4647 protocol uses for errors and errno codes. We would like
4648 a cleaner way of representing errors (big enough to
4649 include errno codes, bfd_error codes, and others). But
4650 for now just return EIO. */
4655 /* Reply describes memory byte by byte,
4656 each byte encoded as two hex characters. */
4659 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
4661 /* Reply is short. This means that we were able to read
4662 only part of what we wanted to. */
4663 return i
+ (origlen
- len
);
4672 /* Read or write LEN bytes from inferior memory at MEMADDR,
4673 transferring to or from debugger address BUFFER. Write to inferior
4674 if SHOULD_WRITE is nonzero. Returns length of data written or
4675 read; 0 for error. TARGET is unused. */
4678 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
4679 int should_write
, struct mem_attrib
*attrib
,
4680 struct target_ops
*target
)
4685 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
4687 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
4692 /* Sends a packet with content determined by the printf format string
4693 FORMAT and the remaining arguments, then gets the reply. Returns
4694 whether the packet was a success, a failure, or unknown. */
4697 remote_send_printf (const char *format
, ...)
4699 struct remote_state
*rs
= get_remote_state ();
4700 int max_size
= get_remote_packet_size ();
4703 va_start (ap
, format
);
4706 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
4707 internal_error (__FILE__
, __LINE__
, "Too long remote packet.");
4709 if (putpkt (rs
->buf
) < 0)
4710 error (_("Communication problem with target."));
4713 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4715 return packet_check_result (rs
->buf
);
4719 restore_remote_timeout (void *p
)
4721 int value
= *(int *)p
;
4722 remote_timeout
= value
;
4725 /* Flash writing can take quite some time. We'll set
4726 effectively infinite timeout for flash operations.
4727 In future, we'll need to decide on a better approach. */
4728 static const int remote_flash_timeout
= 1000;
4731 remote_flash_erase (struct target_ops
*ops
,
4732 ULONGEST address
, LONGEST length
)
4734 int saved_remote_timeout
= remote_timeout
;
4735 enum packet_result ret
;
4737 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
4738 &saved_remote_timeout
);
4739 remote_timeout
= remote_flash_timeout
;
4741 ret
= remote_send_printf ("vFlashErase:%s,%s",
4746 case PACKET_UNKNOWN
:
4747 error (_("Remote target does not support flash erase"));
4749 error (_("Error erasing flash with vFlashErase packet"));
4754 do_cleanups (back_to
);
4758 remote_flash_write (struct target_ops
*ops
,
4759 ULONGEST address
, LONGEST length
,
4760 const gdb_byte
*data
)
4762 int saved_remote_timeout
= remote_timeout
;
4764 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
4765 &saved_remote_timeout
);
4767 remote_timeout
= remote_flash_timeout
;
4768 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
4769 do_cleanups (back_to
);
4775 remote_flash_done (struct target_ops
*ops
)
4777 int saved_remote_timeout
= remote_timeout
;
4779 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
4780 &saved_remote_timeout
);
4782 remote_timeout
= remote_flash_timeout
;
4783 ret
= remote_send_printf ("vFlashDone");
4784 do_cleanups (back_to
);
4788 case PACKET_UNKNOWN
:
4789 error (_("Remote target does not support vFlashDone"));
4791 error (_("Error finishing flash operation"));
4798 remote_files_info (struct target_ops
*ignore
)
4800 puts_filtered ("Debugging a target over a serial line.\n");
4803 /* Stuff for dealing with the packets which are part of this protocol.
4804 See comment at top of file for details. */
4806 /* Read a single character from the remote end. */
4809 readchar (int timeout
)
4813 ch
= serial_readchar (remote_desc
, timeout
);
4818 switch ((enum serial_rc
) ch
)
4821 target_mourn_inferior ();
4822 error (_("Remote connection closed"));
4825 perror_with_name (_("Remote communication error"));
4827 case SERIAL_TIMEOUT
:
4833 /* Send the command in *BUF to the remote machine, and read the reply
4834 into *BUF. Report an error if we get an error reply. Resize
4835 *BUF using xrealloc if necessary to hold the result, and update
4839 remote_send (char **buf
,
4843 getpkt (buf
, sizeof_buf
, 0);
4845 if ((*buf
)[0] == 'E')
4846 error (_("Remote failure reply: %s"), *buf
);
4849 /* Display a null-terminated packet on stdout, for debugging, using C
4853 print_packet (char *buf
)
4855 puts_filtered ("\"");
4856 fputstr_filtered (buf
, '"', gdb_stdout
);
4857 puts_filtered ("\"");
4863 return putpkt_binary (buf
, strlen (buf
));
4866 /* Send a packet to the remote machine, with error checking. The data
4867 of the packet is in BUF. The string in BUF can be at most
4868 get_remote_packet_size () - 5 to account for the $, # and checksum,
4869 and for a possible /0 if we are debugging (remote_debug) and want
4870 to print the sent packet as a string. */
4873 putpkt_binary (char *buf
, int cnt
)
4875 struct remote_state
*rs
= get_remote_state ();
4877 unsigned char csum
= 0;
4878 char *buf2
= alloca (cnt
+ 6);
4884 /* We're sending out a new packet. Make sure we don't look at a
4885 stale cached response. */
4886 rs
->cached_wait_status
= 0;
4888 /* Copy the packet into buffer BUF2, encapsulating it
4889 and giving it a checksum. */
4894 for (i
= 0; i
< cnt
; i
++)
4900 *p
++ = tohex ((csum
>> 4) & 0xf);
4901 *p
++ = tohex (csum
& 0xf);
4903 /* Send it over and over until we get a positive ack. */
4907 int started_error_output
= 0;
4912 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
4913 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
4914 fprintf_unfiltered (gdb_stdlog
, "...");
4915 gdb_flush (gdb_stdlog
);
4917 if (serial_write (remote_desc
, buf2
, p
- buf2
))
4918 perror_with_name (_("putpkt: write failed"));
4920 /* Read until either a timeout occurs (-2) or '+' is read. */
4923 ch
= readchar (remote_timeout
);
4931 case SERIAL_TIMEOUT
:
4933 if (started_error_output
)
4935 putchar_unfiltered ('\n');
4936 started_error_output
= 0;
4945 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
4949 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
4950 case SERIAL_TIMEOUT
:
4954 break; /* Retransmit buffer. */
4958 fprintf_unfiltered (gdb_stdlog
,
4959 "Packet instead of Ack, ignoring it\n");
4960 /* It's probably an old response sent because an ACK
4961 was lost. Gobble up the packet and ack it so it
4962 doesn't get retransmitted when we resend this
4965 serial_write (remote_desc
, "+", 1);
4966 continue; /* Now, go look for +. */
4971 if (!started_error_output
)
4973 started_error_output
= 1;
4974 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
4976 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
4980 break; /* Here to retransmit. */
4984 /* This is wrong. If doing a long backtrace, the user should be
4985 able to get out next time we call QUIT, without anything as
4986 violent as interrupt_query. If we want to provide a way out of
4987 here without getting to the next QUIT, it should be based on
4988 hitting ^C twice as in remote_wait. */
4998 /* Come here after finding the start of a frame when we expected an
4999 ack. Do our best to discard the rest of this packet. */
5008 c
= readchar (remote_timeout
);
5011 case SERIAL_TIMEOUT
:
5012 /* Nothing we can do. */
5015 /* Discard the two bytes of checksum and stop. */
5016 c
= readchar (remote_timeout
);
5018 c
= readchar (remote_timeout
);
5021 case '*': /* Run length encoding. */
5022 /* Discard the repeat count. */
5023 c
= readchar (remote_timeout
);
5028 /* A regular character. */
5034 /* Come here after finding the start of the frame. Collect the rest
5035 into *BUF, verifying the checksum, length, and handling run-length
5036 compression. NUL terminate the buffer. If there is not enough room,
5037 expand *BUF using xrealloc.
5039 Returns -1 on error, number of characters in buffer (ignoring the
5040 trailing NULL) on success. (could be extended to return one of the
5041 SERIAL status indications). */
5044 read_frame (char **buf_p
,
5057 c
= readchar (remote_timeout
);
5060 case SERIAL_TIMEOUT
:
5062 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
5066 fputs_filtered ("Saw new packet start in middle of old one\n",
5068 return -1; /* Start a new packet, count retries. */
5071 unsigned char pktcsum
;
5077 check_0
= readchar (remote_timeout
);
5079 check_1
= readchar (remote_timeout
);
5081 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
5084 fputs_filtered ("Timeout in checksum, retrying\n",
5088 else if (check_0
< 0 || check_1
< 0)
5091 fputs_filtered ("Communication error in checksum\n",
5096 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
5097 if (csum
== pktcsum
)
5102 fprintf_filtered (gdb_stdlog
,
5103 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
5105 fputstrn_filtered (buf
, bc
, 0, gdb_stdlog
);
5106 fputs_filtered ("\n", gdb_stdlog
);
5108 /* Number of characters in buffer ignoring trailing
5112 case '*': /* Run length encoding. */
5117 c
= readchar (remote_timeout
);
5119 repeat
= c
- ' ' + 3; /* Compute repeat count. */
5121 /* The character before ``*'' is repeated. */
5123 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
5125 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
5127 /* Make some more room in the buffer. */
5128 *sizeof_buf
+= repeat
;
5129 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
5133 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
5139 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
5143 if (bc
>= *sizeof_buf
- 1)
5145 /* Make some more room in the buffer. */
5147 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
5158 /* Read a packet from the remote machine, with error checking, and
5159 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
5160 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
5161 rather than timing out; this is used (in synchronous mode) to wait
5162 for a target that is is executing user code to stop. */
5163 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
5164 don't have to change all the calls to getpkt to deal with the
5165 return value, because at the moment I don't know what the right
5166 thing to do it for those. */
5174 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
5178 /* Read a packet from the remote machine, with error checking, and
5179 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
5180 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
5181 rather than timing out; this is used (in synchronous mode) to wait
5182 for a target that is is executing user code to stop. If FOREVER ==
5183 0, this function is allowed to time out gracefully and return an
5184 indication of this to the caller. Otherwise return the number
5187 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
5189 struct remote_state
*rs
= get_remote_state ();
5195 /* We're reading a new response. Make sure we don't look at a
5196 previously cached response. */
5197 rs
->cached_wait_status
= 0;
5199 strcpy (*buf
, "timeout");
5203 timeout
= watchdog
> 0 ? watchdog
: -1;
5207 timeout
= remote_timeout
;
5211 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
5213 /* This can loop forever if the remote side sends us characters
5214 continuously, but if it pauses, we'll get a zero from
5215 readchar because of timeout. Then we'll count that as a
5218 /* Note that we will only wait forever prior to the start of a
5219 packet. After that, we expect characters to arrive at a
5220 brisk pace. They should show up within remote_timeout
5225 c
= readchar (timeout
);
5227 if (c
== SERIAL_TIMEOUT
)
5229 if (forever
) /* Watchdog went off? Kill the target. */
5232 target_mourn_inferior ();
5233 error (_("Watchdog timeout has expired. Target detached."));
5236 fputs_filtered ("Timed out.\n", gdb_stdlog
);
5242 /* We've found the start of a packet, now collect the data. */
5244 val
= read_frame (buf
, sizeof_buf
);
5250 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
5251 fputstrn_unfiltered (*buf
, val
, 0, gdb_stdlog
);
5252 fprintf_unfiltered (gdb_stdlog
, "\n");
5254 serial_write (remote_desc
, "+", 1);
5258 /* Try the whole thing again. */
5260 serial_write (remote_desc
, "-", 1);
5263 /* We have tried hard enough, and just can't receive the packet.
5266 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
5267 serial_write (remote_desc
, "+", 1);
5274 /* For some mysterious reason, wait_for_inferior calls kill instead of
5275 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
5279 target_mourn_inferior ();
5283 /* Use catch_errors so the user can quit from gdb even when we aren't on
5284 speaking terms with the remote system. */
5285 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
5287 /* Don't wait for it to die. I'm not really sure it matters whether
5288 we do or not. For the existing stubs, kill is a noop. */
5289 target_mourn_inferior ();
5292 /* Async version of remote_kill. */
5294 remote_async_kill (void)
5296 /* Unregister the file descriptor from the event loop. */
5297 if (target_is_async_p ())
5298 serial_async (remote_desc
, NULL
, 0);
5300 /* For some mysterious reason, wait_for_inferior calls kill instead of
5301 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
5305 target_mourn_inferior ();
5309 /* Use catch_errors so the user can quit from gdb even when we
5310 aren't on speaking terms with the remote system. */
5311 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
5313 /* Don't wait for it to die. I'm not really sure it matters whether
5314 we do or not. For the existing stubs, kill is a noop. */
5315 target_mourn_inferior ();
5321 remote_mourn_1 (&remote_ops
);
5325 remote_async_mourn (void)
5327 remote_mourn_1 (&remote_async_ops
);
5330 /* Worker function for remote_mourn. */
5332 remote_mourn_1 (struct target_ops
*target
)
5334 unpush_target (target
);
5335 generic_mourn_inferior ();
5339 extended_remote_mourn_1 (struct target_ops
*target
)
5341 struct remote_state
*rs
= get_remote_state ();
5343 /* Unlike "target remote", we do not want to unpush the target; then
5344 the next time the user says "run", we won't be connected. */
5346 /* Call common code to mark the inferior as not running. */
5347 generic_mourn_inferior ();
5349 /* Check whether the target is running now - some remote stubs
5350 automatically restart after kill. */
5352 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5354 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
5356 /* Assume that the target has been restarted. Set inferior_ptid
5357 so that bits of core GDB realizes there's something here, e.g.,
5358 so that the user can say "kill" again. */
5359 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
5363 /* Mark this (still pushed) target as not executable until we
5365 target_mark_exited (target
);
5370 extended_remote_mourn (void)
5372 extended_remote_mourn_1 (&extended_remote_ops
);
5376 extended_async_remote_mourn (void)
5378 extended_remote_mourn_1 (&extended_async_remote_ops
);
5382 extended_remote_run (char *args
)
5384 struct remote_state
*rs
= get_remote_state ();
5388 /* If the user has disabled vRun support, or we have detected that
5389 support is not available, do not try it. */
5390 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
5393 strcpy (rs
->buf
, "vRun;");
5394 len
= strlen (rs
->buf
);
5396 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
5397 error (_("Remote file name too long for run packet"));
5398 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
5402 struct cleanup
*back_to
;
5406 argv
= buildargv (args
);
5407 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
5408 for (i
= 0; argv
[i
] != NULL
; i
++)
5410 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
5411 error (_("Argument list too long for run packet"));
5412 rs
->buf
[len
++] = ';';
5413 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
5415 do_cleanups (back_to
);
5418 rs
->buf
[len
++] = '\0';
5421 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5423 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
5425 /* We have a wait response; we don't need it, though. All is well. */
5428 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
5429 /* It wasn't disabled before, but it is now. */
5433 if (remote_exec_file
[0] == '\0')
5434 error (_("Running the default executable on the remote target failed; "
5435 "try \"set remote exec-file\"?"));
5437 error (_("Running \"%s\" on the remote target failed"),
5442 /* In the extended protocol we want to be able to do things like
5443 "run" and have them basically work as expected. So we need
5444 a special create_inferior function. We support changing the
5445 executable file and the command line arguments, but not the
5449 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
5450 char **env
, int from_tty
,
5453 /* If running asynchronously, register the target file descriptor
5454 with the event loop. */
5455 if (async_p
&& target_can_async_p ())
5456 target_async (inferior_event_handler
, 0);
5458 /* Now restart the remote server. */
5459 if (extended_remote_run (args
) == -1)
5461 /* vRun was not supported. Fail if we need it to do what the
5463 if (remote_exec_file
[0])
5464 error (_("Remote target does not support \"set remote exec-file\""));
5466 error (_("Remote target does not support \"set args\" or run <ARGS>"));
5468 /* Fall back to "R". */
5469 extended_remote_restart ();
5472 /* Clean up from the last time we ran, before we mark the target
5473 running again. This will mark breakpoints uninserted, and
5474 get_offsets may insert breakpoints. */
5475 init_thread_list ();
5476 init_wait_for_inferior ();
5478 /* Now mark the inferior as running before we do anything else. */
5480 inferior_ptid
= pid_to_ptid (MAGIC_NULL_PID
);
5482 target_mark_running (&extended_async_remote_ops
);
5484 target_mark_running (&extended_remote_ops
);
5486 /* Get updated offsets, if the stub uses qOffsets. */
5491 extended_remote_create_inferior (char *exec_file
, char *args
,
5492 char **env
, int from_tty
)
5494 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
, 0);
5498 extended_remote_async_create_inferior (char *exec_file
, char *args
,
5499 char **env
, int from_tty
)
5501 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
, 1);
5505 /* Insert a breakpoint. On targets that have software breakpoint
5506 support, we ask the remote target to do the work; on targets
5507 which don't, we insert a traditional memory breakpoint. */
5510 remote_insert_breakpoint (struct bp_target_info
*bp_tgt
)
5512 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
5513 If it succeeds, then set the support to PACKET_ENABLE. If it
5514 fails, and the user has explicitly requested the Z support then
5515 report an error, otherwise, mark it disabled and go on. */
5517 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
5520 struct remote_state
*rs
;
5523 gdbarch_breakpoint_from_pc
5524 (current_gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
5526 rs
= get_remote_state ();
5532 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
5533 p
+= hexnumstr (p
, addr
);
5534 sprintf (p
, ",%d", bp_tgt
->placed_size
);
5537 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5539 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
5545 case PACKET_UNKNOWN
:
5550 return memory_insert_breakpoint (bp_tgt
);
5554 remote_remove_breakpoint (struct bp_target_info
*bp_tgt
)
5556 CORE_ADDR addr
= bp_tgt
->placed_address
;
5557 struct remote_state
*rs
= get_remote_state ();
5560 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
5568 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
5569 p
+= hexnumstr (p
, addr
);
5570 sprintf (p
, ",%d", bp_tgt
->placed_size
);
5573 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5575 return (rs
->buf
[0] == 'E');
5578 return memory_remove_breakpoint (bp_tgt
);
5582 watchpoint_to_Z_packet (int type
)
5587 return Z_PACKET_WRITE_WP
;
5590 return Z_PACKET_READ_WP
;
5593 return Z_PACKET_ACCESS_WP
;
5596 internal_error (__FILE__
, __LINE__
,
5597 _("hw_bp_to_z: bad watchpoint type %d"), type
);
5602 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
5604 struct remote_state
*rs
= get_remote_state ();
5606 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
5608 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
5611 sprintf (rs
->buf
, "Z%x,", packet
);
5612 p
= strchr (rs
->buf
, '\0');
5613 addr
= remote_address_masked (addr
);
5614 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5615 sprintf (p
, ",%x", len
);
5618 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5620 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
5623 case PACKET_UNKNOWN
:
5628 internal_error (__FILE__
, __LINE__
,
5629 _("remote_insert_watchpoint: reached end of function"));
5634 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
5636 struct remote_state
*rs
= get_remote_state ();
5638 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
5640 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
5643 sprintf (rs
->buf
, "z%x,", packet
);
5644 p
= strchr (rs
->buf
, '\0');
5645 addr
= remote_address_masked (addr
);
5646 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5647 sprintf (p
, ",%x", len
);
5649 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5651 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
5654 case PACKET_UNKNOWN
:
5659 internal_error (__FILE__
, __LINE__
,
5660 _("remote_remove_watchpoint: reached end of function"));
5664 int remote_hw_watchpoint_limit
= -1;
5665 int remote_hw_breakpoint_limit
= -1;
5668 remote_check_watch_resources (int type
, int cnt
, int ot
)
5670 if (type
== bp_hardware_breakpoint
)
5672 if (remote_hw_breakpoint_limit
== 0)
5674 else if (remote_hw_breakpoint_limit
< 0)
5676 else if (cnt
<= remote_hw_breakpoint_limit
)
5681 if (remote_hw_watchpoint_limit
== 0)
5683 else if (remote_hw_watchpoint_limit
< 0)
5687 else if (cnt
<= remote_hw_watchpoint_limit
)
5694 remote_stopped_by_watchpoint (void)
5696 return remote_stopped_by_watchpoint_p
;
5700 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
5703 if (remote_stopped_by_watchpoint ())
5705 *addr_p
= remote_watch_data_address
;
5714 remote_insert_hw_breakpoint (struct bp_target_info
*bp_tgt
)
5717 struct remote_state
*rs
;
5720 /* The length field should be set to the size of a breakpoint
5721 instruction, even though we aren't inserting one ourselves. */
5723 gdbarch_breakpoint_from_pc
5724 (current_gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
5726 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
5729 rs
= get_remote_state ();
5736 addr
= remote_address_masked (bp_tgt
->placed_address
);
5737 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5738 sprintf (p
, ",%x", bp_tgt
->placed_size
);
5741 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5743 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
5746 case PACKET_UNKNOWN
:
5751 internal_error (__FILE__
, __LINE__
,
5752 _("remote_insert_hw_breakpoint: reached end of function"));
5757 remote_remove_hw_breakpoint (struct bp_target_info
*bp_tgt
)
5760 struct remote_state
*rs
= get_remote_state ();
5763 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
5770 addr
= remote_address_masked (bp_tgt
->placed_address
);
5771 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5772 sprintf (p
, ",%x", bp_tgt
->placed_size
);
5775 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5777 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
5780 case PACKET_UNKNOWN
:
5785 internal_error (__FILE__
, __LINE__
,
5786 _("remote_remove_hw_breakpoint: reached end of function"));
5789 /* Some targets are only capable of doing downloads, and afterwards
5790 they switch to the remote serial protocol. This function provides
5791 a clean way to get from the download target to the remote target.
5792 It's basically just a wrapper so that we don't have to expose any
5793 of the internal workings of remote.c.
5795 Prior to calling this routine, you should shutdown the current
5796 target code, else you will get the "A program is being debugged
5797 already..." message. Usually a call to pop_target() suffices. */
5800 push_remote_target (char *name
, int from_tty
)
5802 printf_filtered (_("Switching to remote protocol\n"));
5803 remote_open (name
, from_tty
);
5806 /* Table used by the crc32 function to calcuate the checksum. */
5808 static unsigned long crc32_table
[256] =
5811 static unsigned long
5812 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
5814 if (!crc32_table
[1])
5816 /* Initialize the CRC table and the decoding table. */
5820 for (i
= 0; i
< 256; i
++)
5822 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
5823 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
5830 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
5836 /* compare-sections command
5838 With no arguments, compares each loadable section in the exec bfd
5839 with the same memory range on the target, and reports mismatches.
5840 Useful for verifying the image on the target against the exec file.
5841 Depends on the target understanding the new "qCRC:" request. */
5843 /* FIXME: cagney/1999-10-26: This command should be broken down into a
5844 target method (target verify memory) and generic version of the
5845 actual command. This will allow other high-level code (especially
5846 generic_load()) to make use of this target functionality. */
5849 compare_sections_command (char *args
, int from_tty
)
5851 struct remote_state
*rs
= get_remote_state ();
5853 unsigned long host_crc
, target_crc
;
5854 extern bfd
*exec_bfd
;
5855 struct cleanup
*old_chain
;
5858 const char *sectname
;
5865 error (_("command cannot be used without an exec file"));
5866 if (!current_target
.to_shortname
||
5867 strcmp (current_target
.to_shortname
, "remote") != 0)
5868 error (_("command can only be used with remote target"));
5870 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
5872 if (!(s
->flags
& SEC_LOAD
))
5873 continue; /* skip non-loadable section */
5875 size
= bfd_get_section_size (s
);
5877 continue; /* skip zero-length section */
5879 sectname
= bfd_get_section_name (exec_bfd
, s
);
5880 if (args
&& strcmp (args
, sectname
) != 0)
5881 continue; /* not the section selected by user */
5883 matched
= 1; /* do this section */
5885 /* FIXME: assumes lma can fit into long. */
5886 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
5887 (long) lma
, (long) size
);
5890 /* Be clever; compute the host_crc before waiting for target
5892 sectdata
= xmalloc (size
);
5893 old_chain
= make_cleanup (xfree
, sectdata
);
5894 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
5895 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
5897 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5898 if (rs
->buf
[0] == 'E')
5899 error (_("target memory fault, section %s, range 0x%s -- 0x%s"),
5900 sectname
, paddr (lma
), paddr (lma
+ size
));
5901 if (rs
->buf
[0] != 'C')
5902 error (_("remote target does not support this operation"));
5904 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
5905 target_crc
= target_crc
* 16 + fromhex (*tmp
);
5907 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
5908 sectname
, paddr (lma
), paddr (lma
+ size
));
5909 if (host_crc
== target_crc
)
5910 printf_filtered ("matched.\n");
5913 printf_filtered ("MIS-MATCHED!\n");
5917 do_cleanups (old_chain
);
5920 warning (_("One or more sections of the remote executable does not match\n\
5921 the loaded file\n"));
5922 if (args
&& !matched
)
5923 printf_filtered (_("No loaded section named '%s'.\n"), args
);
5926 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
5927 into remote target. The number of bytes written to the remote
5928 target is returned, or -1 for error. */
5931 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
5932 const char *annex
, const gdb_byte
*writebuf
,
5933 ULONGEST offset
, LONGEST len
,
5934 struct packet_config
*packet
)
5939 struct remote_state
*rs
= get_remote_state ();
5940 int max_size
= get_memory_write_packet_size ();
5942 if (packet
->support
== PACKET_DISABLE
)
5945 /* Insert header. */
5946 i
= snprintf (rs
->buf
, max_size
,
5947 "qXfer:%s:write:%s:%s:",
5948 object_name
, annex
? annex
: "",
5949 phex_nz (offset
, sizeof offset
));
5950 max_size
-= (i
+ 1);
5952 /* Escape as much data as fits into rs->buf. */
5953 buf_len
= remote_escape_output
5954 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
5956 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
5957 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
5958 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
5961 unpack_varlen_hex (rs
->buf
, &n
);
5965 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
5966 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
5967 number of bytes read is returned, or 0 for EOF, or -1 for error.
5968 The number of bytes read may be less than LEN without indicating an
5969 EOF. PACKET is checked and updated to indicate whether the remote
5970 target supports this object. */
5973 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
5975 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
5976 struct packet_config
*packet
)
5978 static char *finished_object
;
5979 static char *finished_annex
;
5980 static ULONGEST finished_offset
;
5982 struct remote_state
*rs
= get_remote_state ();
5983 unsigned int total
= 0;
5984 LONGEST i
, n
, packet_len
;
5986 if (packet
->support
== PACKET_DISABLE
)
5989 /* Check whether we've cached an end-of-object packet that matches
5991 if (finished_object
)
5993 if (strcmp (object_name
, finished_object
) == 0
5994 && strcmp (annex
? annex
: "", finished_annex
) == 0
5995 && offset
== finished_offset
)
5998 /* Otherwise, we're now reading something different. Discard
6000 xfree (finished_object
);
6001 xfree (finished_annex
);
6002 finished_object
= NULL
;
6003 finished_annex
= NULL
;
6006 /* Request only enough to fit in a single packet. The actual data
6007 may not, since we don't know how much of it will need to be escaped;
6008 the target is free to respond with slightly less data. We subtract
6009 five to account for the response type and the protocol frame. */
6010 n
= min (get_remote_packet_size () - 5, len
);
6011 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
6012 object_name
, annex
? annex
: "",
6013 phex_nz (offset
, sizeof offset
),
6014 phex_nz (n
, sizeof n
));
6015 i
= putpkt (rs
->buf
);
6020 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
6021 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
6024 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
6025 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
6027 /* 'm' means there is (or at least might be) more data after this
6028 batch. That does not make sense unless there's at least one byte
6029 of data in this reply. */
6030 if (rs
->buf
[0] == 'm' && packet_len
== 1)
6031 error (_("Remote qXfer reply contained no data."));
6033 /* Got some data. */
6034 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
6036 /* 'l' is an EOF marker, possibly including a final block of data,
6037 or possibly empty. If we have the final block of a non-empty
6038 object, record this fact to bypass a subsequent partial read. */
6039 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
6041 finished_object
= xstrdup (object_name
);
6042 finished_annex
= xstrdup (annex
? annex
: "");
6043 finished_offset
= offset
+ i
;
6050 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
6051 const char *annex
, gdb_byte
*readbuf
,
6052 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
6054 struct remote_state
*rs
= get_remote_state ();
6059 /* Handle memory using the standard memory routines. */
6060 if (object
== TARGET_OBJECT_MEMORY
)
6065 /* If the remote target is connected but not running, we should
6066 pass this request down to a lower stratum (e.g. the executable
6068 if (!target_has_execution
)
6071 if (writebuf
!= NULL
)
6072 xfered
= remote_write_bytes (offset
, writebuf
, len
);
6074 xfered
= remote_read_bytes (offset
, readbuf
, len
);
6078 else if (xfered
== 0 && errno
== 0)
6084 /* Handle SPU memory using qxfer packets. */
6085 if (object
== TARGET_OBJECT_SPU
)
6088 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
6089 &remote_protocol_packets
6090 [PACKET_qXfer_spu_read
]);
6092 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
6093 &remote_protocol_packets
6094 [PACKET_qXfer_spu_write
]);
6097 /* Only handle flash writes. */
6098 if (writebuf
!= NULL
)
6104 case TARGET_OBJECT_FLASH
:
6105 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
6109 else if (xfered
== 0 && errno
== 0)
6119 /* Map pre-existing objects onto letters. DO NOT do this for new
6120 objects!!! Instead specify new query packets. */
6123 case TARGET_OBJECT_AVR
:
6127 case TARGET_OBJECT_AUXV
:
6128 gdb_assert (annex
== NULL
);
6129 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
6130 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
6132 case TARGET_OBJECT_AVAILABLE_FEATURES
:
6133 return remote_read_qxfer
6134 (ops
, "features", annex
, readbuf
, offset
, len
,
6135 &remote_protocol_packets
[PACKET_qXfer_features
]);
6137 case TARGET_OBJECT_LIBRARIES
:
6138 return remote_read_qxfer
6139 (ops
, "libraries", annex
, readbuf
, offset
, len
,
6140 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
6142 case TARGET_OBJECT_MEMORY_MAP
:
6143 gdb_assert (annex
== NULL
);
6144 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
6145 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
6151 /* Note: a zero OFFSET and LEN can be used to query the minimum
6153 if (offset
== 0 && len
== 0)
6154 return (get_remote_packet_size ());
6155 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
6156 large enough let the caller deal with it. */
6157 if (len
< get_remote_packet_size ())
6159 len
= get_remote_packet_size ();
6161 /* Except for querying the minimum buffer size, target must be open. */
6163 error (_("remote query is only available after target open"));
6165 gdb_assert (annex
!= NULL
);
6166 gdb_assert (readbuf
!= NULL
);
6172 /* We used one buffer char for the remote protocol q command and
6173 another for the query type. As the remote protocol encapsulation
6174 uses 4 chars plus one extra in case we are debugging
6175 (remote_debug), we have PBUFZIZ - 7 left to pack the query
6178 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
6180 /* Bad caller may have sent forbidden characters. */
6181 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
6186 gdb_assert (annex
[i
] == '\0');
6188 i
= putpkt (rs
->buf
);
6192 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6193 strcpy ((char *) readbuf
, rs
->buf
);
6195 return strlen ((char *) readbuf
);
6199 remote_rcmd (char *command
,
6200 struct ui_file
*outbuf
)
6202 struct remote_state
*rs
= get_remote_state ();
6206 error (_("remote rcmd is only available after target open"));
6208 /* Send a NULL command across as an empty command. */
6209 if (command
== NULL
)
6212 /* The query prefix. */
6213 strcpy (rs
->buf
, "qRcmd,");
6214 p
= strchr (rs
->buf
, '\0');
6216 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/) > get_remote_packet_size ())
6217 error (_("\"monitor\" command ``%s'' is too long."), command
);
6219 /* Encode the actual command. */
6220 bin2hex ((gdb_byte
*) command
, p
, 0);
6222 if (putpkt (rs
->buf
) < 0)
6223 error (_("Communication problem with target."));
6225 /* get/display the response */
6230 /* XXX - see also tracepoint.c:remote_get_noisy_reply(). */
6232 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6235 error (_("Target does not support this command."));
6236 if (buf
[0] == 'O' && buf
[1] != 'K')
6238 remote_console_output (buf
+ 1); /* 'O' message from stub. */
6241 if (strcmp (buf
, "OK") == 0)
6243 if (strlen (buf
) == 3 && buf
[0] == 'E'
6244 && isdigit (buf
[1]) && isdigit (buf
[2]))
6246 error (_("Protocol error with Rcmd"));
6248 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
6250 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
6251 fputc_unfiltered (c
, outbuf
);
6257 static VEC(mem_region_s
) *
6258 remote_memory_map (struct target_ops
*ops
)
6260 VEC(mem_region_s
) *result
= NULL
;
6261 char *text
= target_read_stralloc (¤t_target
,
6262 TARGET_OBJECT_MEMORY_MAP
, NULL
);
6266 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
6267 result
= parse_memory_map (text
);
6268 do_cleanups (back_to
);
6275 packet_command (char *args
, int from_tty
)
6277 struct remote_state
*rs
= get_remote_state ();
6280 error (_("command can only be used with remote target"));
6283 error (_("remote-packet command requires packet text as argument"));
6285 puts_filtered ("sending: ");
6286 print_packet (args
);
6287 puts_filtered ("\n");
6290 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6291 puts_filtered ("received: ");
6292 print_packet (rs
->buf
);
6293 puts_filtered ("\n");
6297 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
6299 static void display_thread_info (struct gdb_ext_thread_info
*info
);
6301 static void threadset_test_cmd (char *cmd
, int tty
);
6303 static void threadalive_test (char *cmd
, int tty
);
6305 static void threadlist_test_cmd (char *cmd
, int tty
);
6307 int get_and_display_threadinfo (threadref
*ref
);
6309 static void threadinfo_test_cmd (char *cmd
, int tty
);
6311 static int thread_display_step (threadref
*ref
, void *context
);
6313 static void threadlist_update_test_cmd (char *cmd
, int tty
);
6315 static void init_remote_threadtests (void);
6317 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
6320 threadset_test_cmd (char *cmd
, int tty
)
6322 int sample_thread
= SAMPLE_THREAD
;
6324 printf_filtered (_("Remote threadset test\n"));
6325 set_thread (sample_thread
, 1);
6330 threadalive_test (char *cmd
, int tty
)
6332 int sample_thread
= SAMPLE_THREAD
;
6334 if (remote_thread_alive (pid_to_ptid (sample_thread
)))
6335 printf_filtered ("PASS: Thread alive test\n");
6337 printf_filtered ("FAIL: Thread alive test\n");
6340 void output_threadid (char *title
, threadref
*ref
);
6343 output_threadid (char *title
, threadref
*ref
)
6347 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
6349 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
6353 threadlist_test_cmd (char *cmd
, int tty
)
6356 threadref nextthread
;
6357 int done
, result_count
;
6358 threadref threadlist
[3];
6360 printf_filtered ("Remote Threadlist test\n");
6361 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
6362 &result_count
, &threadlist
[0]))
6363 printf_filtered ("FAIL: threadlist test\n");
6366 threadref
*scan
= threadlist
;
6367 threadref
*limit
= scan
+ result_count
;
6369 while (scan
< limit
)
6370 output_threadid (" thread ", scan
++);
6375 display_thread_info (struct gdb_ext_thread_info
*info
)
6377 output_threadid ("Threadid: ", &info
->threadid
);
6378 printf_filtered ("Name: %s\n ", info
->shortname
);
6379 printf_filtered ("State: %s\n", info
->display
);
6380 printf_filtered ("other: %s\n\n", info
->more_display
);
6384 get_and_display_threadinfo (threadref
*ref
)
6388 struct gdb_ext_thread_info threadinfo
;
6390 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
6391 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
6392 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
6393 display_thread_info (&threadinfo
);
6398 threadinfo_test_cmd (char *cmd
, int tty
)
6400 int athread
= SAMPLE_THREAD
;
6404 int_to_threadref (&thread
, athread
);
6405 printf_filtered ("Remote Threadinfo test\n");
6406 if (!get_and_display_threadinfo (&thread
))
6407 printf_filtered ("FAIL cannot get thread info\n");
6411 thread_display_step (threadref
*ref
, void *context
)
6413 /* output_threadid(" threadstep ",ref); *//* simple test */
6414 return get_and_display_threadinfo (ref
);
6418 threadlist_update_test_cmd (char *cmd
, int tty
)
6420 printf_filtered ("Remote Threadlist update test\n");
6421 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
6425 init_remote_threadtests (void)
6427 add_com ("tlist", class_obscure
, threadlist_test_cmd
, _("\
6428 Fetch and print the remote list of thread identifiers, one pkt only"));
6429 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
6430 _("Fetch and display info about one thread"));
6431 add_com ("tset", class_obscure
, threadset_test_cmd
,
6432 _("Test setting to a different thread"));
6433 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
6434 _("Iterate through updating all remote thread info"));
6435 add_com ("talive", class_obscure
, threadalive_test
,
6436 _(" Remote thread alive test "));
6441 /* Convert a thread ID to a string. Returns the string in a static
6445 remote_pid_to_str (ptid_t ptid
)
6447 static char buf
[32];
6449 xsnprintf (buf
, sizeof buf
, "Thread %d", ptid_get_pid (ptid
));
6453 /* Get the address of the thread local variable in OBJFILE which is
6454 stored at OFFSET within the thread local storage for thread PTID. */
6457 remote_get_thread_local_address (ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
6459 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
6461 struct remote_state
*rs
= get_remote_state ();
6463 enum packet_result result
;
6465 strcpy (p
, "qGetTLSAddr:");
6467 p
+= hexnumstr (p
, PIDGET (ptid
));
6469 p
+= hexnumstr (p
, offset
);
6471 p
+= hexnumstr (p
, lm
);
6475 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6476 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
6477 if (result
== PACKET_OK
)
6481 unpack_varlen_hex (rs
->buf
, &result
);
6484 else if (result
== PACKET_UNKNOWN
)
6485 throw_error (TLS_GENERIC_ERROR
,
6486 _("Remote target doesn't support qGetTLSAddr packet"));
6488 throw_error (TLS_GENERIC_ERROR
,
6489 _("Remote target failed to process qGetTLSAddr request"));
6492 throw_error (TLS_GENERIC_ERROR
,
6493 _("TLS not supported or disabled on this target"));
6498 /* Support for inferring a target description based on the current
6499 architecture and the size of a 'g' packet. While the 'g' packet
6500 can have any size (since optional registers can be left off the
6501 end), some sizes are easily recognizable given knowledge of the
6502 approximate architecture. */
6504 struct remote_g_packet_guess
6507 const struct target_desc
*tdesc
;
6509 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
6510 DEF_VEC_O(remote_g_packet_guess_s
);
6512 struct remote_g_packet_data
6514 VEC(remote_g_packet_guess_s
) *guesses
;
6517 static struct gdbarch_data
*remote_g_packet_data_handle
;
6520 remote_g_packet_data_init (struct obstack
*obstack
)
6522 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
6526 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
6527 const struct target_desc
*tdesc
)
6529 struct remote_g_packet_data
*data
6530 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
6531 struct remote_g_packet_guess new_guess
, *guess
;
6534 gdb_assert (tdesc
!= NULL
);
6537 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
6539 if (guess
->bytes
== bytes
)
6540 internal_error (__FILE__
, __LINE__
,
6541 "Duplicate g packet description added for size %d",
6544 new_guess
.bytes
= bytes
;
6545 new_guess
.tdesc
= tdesc
;
6546 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
6549 static const struct target_desc
*
6550 remote_read_description (struct target_ops
*target
)
6552 struct remote_g_packet_data
*data
6553 = gdbarch_data (current_gdbarch
, remote_g_packet_data_handle
);
6555 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
6557 struct remote_g_packet_guess
*guess
;
6559 int bytes
= send_g_packet ();
6562 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
6564 if (guess
->bytes
== bytes
)
6565 return guess
->tdesc
;
6567 /* We discard the g packet. A minor optimization would be to
6568 hold on to it, and fill the register cache once we have selected
6569 an architecture, but it's too tricky to do safely. */
6575 /* Remote file transfer support. This is host-initiated I/O, not
6576 target-initiated; for target-initiated, see remote-fileio.c. */
6578 /* If *LEFT is at least the length of STRING, copy STRING to
6579 *BUFFER, update *BUFFER to point to the new end of the buffer, and
6580 decrease *LEFT. Otherwise raise an error. */
6583 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
6585 int len
= strlen (string
);
6588 error (_("Packet too long for target."));
6590 memcpy (*buffer
, string
, len
);
6594 /* NUL-terminate the buffer as a convenience, if there is
6600 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
6601 *BUFFER, update *BUFFER to point to the new end of the buffer, and
6602 decrease *LEFT. Otherwise raise an error. */
6605 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
6608 if (2 * len
> *left
)
6609 error (_("Packet too long for target."));
6611 bin2hex (bytes
, *buffer
, len
);
6615 /* NUL-terminate the buffer as a convenience, if there is
6621 /* If *LEFT is large enough, convert VALUE to hex and add it to
6622 *BUFFER, update *BUFFER to point to the new end of the buffer, and
6623 decrease *LEFT. Otherwise raise an error. */
6626 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
6628 int len
= hexnumlen (value
);
6631 error (_("Packet too long for target."));
6633 hexnumstr (*buffer
, value
);
6637 /* NUL-terminate the buffer as a convenience, if there is
6643 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
6644 value, *REMOTE_ERRNO to the remote error number or zero if none
6645 was included, and *ATTACHMENT to point to the start of the annex
6646 if any. The length of the packet isn't needed here; there may
6647 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
6649 Return 0 if the packet could be parsed, -1 if it could not. If
6650 -1 is returned, the other variables may not be initialized. */
6653 remote_hostio_parse_result (char *buffer
, int *retcode
,
6654 int *remote_errno
, char **attachment
)
6661 if (buffer
[0] != 'F')
6665 *retcode
= strtol (&buffer
[1], &p
, 16);
6666 if (errno
!= 0 || p
== &buffer
[1])
6669 /* Check for ",errno". */
6673 *remote_errno
= strtol (p
+ 1, &p2
, 16);
6674 if (errno
!= 0 || p
+ 1 == p2
)
6679 /* Check for ";attachment". If there is no attachment, the
6680 packet should end here. */
6683 *attachment
= p
+ 1;
6686 else if (*p
== '\0')
6692 /* Send a prepared I/O packet to the target and read its response.
6693 The prepared packet is in the global RS->BUF before this function
6694 is called, and the answer is there when we return.
6696 COMMAND_BYTES is the length of the request to send, which may include
6697 binary data. WHICH_PACKET is the packet configuration to check
6698 before attempting a packet. If an error occurs, *REMOTE_ERRNO
6699 is set to the error number and -1 is returned. Otherwise the value
6700 returned by the function is returned.
6702 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
6703 attachment is expected; an error will be reported if there's a
6704 mismatch. If one is found, *ATTACHMENT will be set to point into
6705 the packet buffer and *ATTACHMENT_LEN will be set to the
6706 attachment's length. */
6709 remote_hostio_send_command (int command_bytes
, int which_packet
,
6710 int *remote_errno
, char **attachment
,
6711 int *attachment_len
)
6713 struct remote_state
*rs
= get_remote_state ();
6714 int ret
, bytes_read
;
6715 char *attachment_tmp
;
6717 if (remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
6719 *remote_errno
= FILEIO_ENOSYS
;
6723 putpkt_binary (rs
->buf
, command_bytes
);
6724 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
6726 /* If it timed out, something is wrong. Don't try to parse the
6730 *remote_errno
= FILEIO_EINVAL
;
6734 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
6737 *remote_errno
= FILEIO_EINVAL
;
6739 case PACKET_UNKNOWN
:
6740 *remote_errno
= FILEIO_ENOSYS
;
6746 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
6749 *remote_errno
= FILEIO_EINVAL
;
6753 /* Make sure we saw an attachment if and only if we expected one. */
6754 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
6755 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
6757 *remote_errno
= FILEIO_EINVAL
;
6761 /* If an attachment was found, it must point into the packet buffer;
6762 work out how many bytes there were. */
6763 if (attachment_tmp
!= NULL
)
6765 *attachment
= attachment_tmp
;
6766 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
6772 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
6773 remote file descriptor, or -1 if an error occurs (and set
6777 remote_hostio_open (const char *filename
, int flags
, int mode
,
6780 struct remote_state
*rs
= get_remote_state ();
6782 int left
= get_remote_packet_size () - 1;
6784 remote_buffer_add_string (&p
, &left
, "vFile:open:");
6786 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
6788 remote_buffer_add_string (&p
, &left
, ",");
6790 remote_buffer_add_int (&p
, &left
, flags
);
6791 remote_buffer_add_string (&p
, &left
, ",");
6793 remote_buffer_add_int (&p
, &left
, mode
);
6795 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
6796 remote_errno
, NULL
, NULL
);
6799 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
6800 Return the number of bytes written, or -1 if an error occurs (and
6801 set *REMOTE_ERRNO). */
6804 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
6805 ULONGEST offset
, int *remote_errno
)
6807 struct remote_state
*rs
= get_remote_state ();
6809 int left
= get_remote_packet_size ();
6812 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
6814 remote_buffer_add_int (&p
, &left
, fd
);
6815 remote_buffer_add_string (&p
, &left
, ",");
6817 remote_buffer_add_int (&p
, &left
, offset
);
6818 remote_buffer_add_string (&p
, &left
, ",");
6820 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
6821 get_remote_packet_size () - (p
- rs
->buf
));
6823 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
6824 remote_errno
, NULL
, NULL
);
6827 /* Read up to LEN bytes FD on the remote target into READ_BUF
6828 Return the number of bytes read, or -1 if an error occurs (and
6829 set *REMOTE_ERRNO). */
6832 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
6833 ULONGEST offset
, int *remote_errno
)
6835 struct remote_state
*rs
= get_remote_state ();
6838 int left
= get_remote_packet_size ();
6839 int ret
, attachment_len
;
6842 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
6844 remote_buffer_add_int (&p
, &left
, fd
);
6845 remote_buffer_add_string (&p
, &left
, ",");
6847 remote_buffer_add_int (&p
, &left
, len
);
6848 remote_buffer_add_string (&p
, &left
, ",");
6850 remote_buffer_add_int (&p
, &left
, offset
);
6852 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
6853 remote_errno
, &attachment
,
6859 read_len
= remote_unescape_input (attachment
, attachment_len
,
6861 if (read_len
!= ret
)
6862 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
6867 /* Close FD on the remote target. Return 0, or -1 if an error occurs
6868 (and set *REMOTE_ERRNO). */
6871 remote_hostio_close (int fd
, int *remote_errno
)
6873 struct remote_state
*rs
= get_remote_state ();
6875 int left
= get_remote_packet_size () - 1;
6877 remote_buffer_add_string (&p
, &left
, "vFile:close:");
6879 remote_buffer_add_int (&p
, &left
, fd
);
6881 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
6882 remote_errno
, NULL
, NULL
);
6885 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
6886 occurs (and set *REMOTE_ERRNO). */
6889 remote_hostio_unlink (const char *filename
, int *remote_errno
)
6891 struct remote_state
*rs
= get_remote_state ();
6893 int left
= get_remote_packet_size () - 1;
6895 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
6897 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
6900 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
6901 remote_errno
, NULL
, NULL
);
6905 remote_fileio_errno_to_host (int errnum
)
6929 case FILEIO_ENOTDIR
:
6949 case FILEIO_ENAMETOOLONG
:
6950 return ENAMETOOLONG
;
6956 remote_hostio_error (int errnum
)
6958 int host_error
= remote_fileio_errno_to_host (errnum
);
6960 if (host_error
== -1)
6961 error (_("Unknown remote I/O error %d"), errnum
);
6963 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
6967 fclose_cleanup (void *file
)
6973 remote_hostio_close_cleanup (void *opaque
)
6975 int fd
= *(int *) opaque
;
6978 remote_hostio_close (fd
, &remote_errno
);
6982 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
6984 struct cleanup
*back_to
, *close_cleanup
;
6985 int retcode
, fd
, remote_errno
, bytes
, io_size
;
6988 int bytes_in_buffer
;
6993 error (_("command can only be used with remote target"));
6995 file
= fopen (local_file
, "rb");
6997 perror_with_name (local_file
);
6998 back_to
= make_cleanup (fclose_cleanup
, file
);
7000 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
7002 0700, &remote_errno
);
7004 remote_hostio_error (remote_errno
);
7006 /* Send up to this many bytes at once. They won't all fit in the
7007 remote packet limit, so we'll transfer slightly fewer. */
7008 io_size
= get_remote_packet_size ();
7009 buffer
= xmalloc (io_size
);
7010 make_cleanup (xfree
, buffer
);
7012 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
7014 bytes_in_buffer
= 0;
7017 while (bytes_in_buffer
|| !saw_eof
)
7021 bytes
= fread (buffer
+ bytes_in_buffer
, 1, io_size
- bytes_in_buffer
,
7026 error (_("Error reading %s."), local_file
);
7029 /* EOF. Unless there is something still in the
7030 buffer from the last iteration, we are done. */
7032 if (bytes_in_buffer
== 0)
7040 bytes
+= bytes_in_buffer
;
7041 bytes_in_buffer
= 0;
7043 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
, offset
, &remote_errno
);
7046 remote_hostio_error (remote_errno
);
7047 else if (retcode
== 0)
7048 error (_("Remote write of %d bytes returned 0!"), bytes
);
7049 else if (retcode
< bytes
)
7051 /* Short write. Save the rest of the read data for the next
7053 bytes_in_buffer
= bytes
- retcode
;
7054 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
7060 discard_cleanups (close_cleanup
);
7061 if (remote_hostio_close (fd
, &remote_errno
))
7062 remote_hostio_error (remote_errno
);
7065 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
7066 do_cleanups (back_to
);
7070 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
7072 struct cleanup
*back_to
, *close_cleanup
;
7073 int retcode
, fd
, remote_errno
, bytes
, io_size
;
7079 error (_("command can only be used with remote target"));
7081 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
7083 remote_hostio_error (remote_errno
);
7085 file
= fopen (local_file
, "wb");
7087 perror_with_name (local_file
);
7088 back_to
= make_cleanup (fclose_cleanup
, file
);
7090 /* Send up to this many bytes at once. They won't all fit in the
7091 remote packet limit, so we'll transfer slightly fewer. */
7092 io_size
= get_remote_packet_size ();
7093 buffer
= xmalloc (io_size
);
7094 make_cleanup (xfree
, buffer
);
7096 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
7101 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
7103 /* Success, but no bytes, means end-of-file. */
7106 remote_hostio_error (remote_errno
);
7110 bytes
= fwrite (buffer
, 1, bytes
, file
);
7112 perror_with_name (local_file
);
7115 discard_cleanups (close_cleanup
);
7116 if (remote_hostio_close (fd
, &remote_errno
))
7117 remote_hostio_error (remote_errno
);
7120 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
7121 do_cleanups (back_to
);
7125 remote_file_delete (const char *remote_file
, int from_tty
)
7127 int retcode
, remote_errno
;
7130 error (_("command can only be used with remote target"));
7132 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
7134 remote_hostio_error (remote_errno
);
7137 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
7141 remote_put_command (char *args
, int from_tty
)
7143 struct cleanup
*back_to
;
7146 argv
= buildargv (args
);
7149 back_to
= make_cleanup_freeargv (argv
);
7150 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
7151 error (_("Invalid parameters to remote put"));
7153 remote_file_put (argv
[0], argv
[1], from_tty
);
7155 do_cleanups (back_to
);
7159 remote_get_command (char *args
, int from_tty
)
7161 struct cleanup
*back_to
;
7164 argv
= buildargv (args
);
7167 back_to
= make_cleanup_freeargv (argv
);
7168 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
7169 error (_("Invalid parameters to remote get"));
7171 remote_file_get (argv
[0], argv
[1], from_tty
);
7173 do_cleanups (back_to
);
7177 remote_delete_command (char *args
, int from_tty
)
7179 struct cleanup
*back_to
;
7182 argv
= buildargv (args
);
7185 back_to
= make_cleanup_freeargv (argv
);
7186 if (argv
[0] == NULL
|| argv
[1] != NULL
)
7187 error (_("Invalid parameters to remote delete"));
7189 remote_file_delete (argv
[0], from_tty
);
7191 do_cleanups (back_to
);
7195 remote_command (char *args
, int from_tty
)
7197 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
7201 remote_return_zero (void)
7207 init_remote_ops (void)
7209 remote_ops
.to_shortname
= "remote";
7210 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
7212 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
7213 Specify the serial device it is connected to\n\
7214 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
7215 remote_ops
.to_open
= remote_open
;
7216 remote_ops
.to_close
= remote_close
;
7217 remote_ops
.to_detach
= remote_detach
;
7218 remote_ops
.to_disconnect
= remote_disconnect
;
7219 remote_ops
.to_resume
= remote_resume
;
7220 remote_ops
.to_wait
= remote_wait
;
7221 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
7222 remote_ops
.to_store_registers
= remote_store_registers
;
7223 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
7224 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
7225 remote_ops
.to_files_info
= remote_files_info
;
7226 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
7227 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
7228 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
7229 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
7230 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
7231 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
7232 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
7233 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
7234 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
7235 remote_ops
.to_kill
= remote_kill
;
7236 remote_ops
.to_load
= generic_load
;
7237 remote_ops
.to_mourn_inferior
= remote_mourn
;
7238 remote_ops
.to_thread_alive
= remote_thread_alive
;
7239 remote_ops
.to_find_new_threads
= remote_threads_info
;
7240 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
7241 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
7242 remote_ops
.to_stop
= remote_stop
;
7243 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
7244 remote_ops
.to_rcmd
= remote_rcmd
;
7245 remote_ops
.to_log_command
= serial_log_command
;
7246 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
7247 remote_ops
.to_stratum
= process_stratum
;
7248 remote_ops
.to_has_all_memory
= 1;
7249 remote_ops
.to_has_memory
= 1;
7250 remote_ops
.to_has_stack
= 1;
7251 remote_ops
.to_has_registers
= 1;
7252 remote_ops
.to_has_execution
= 1;
7253 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
7254 remote_ops
.to_magic
= OPS_MAGIC
;
7255 remote_ops
.to_memory_map
= remote_memory_map
;
7256 remote_ops
.to_flash_erase
= remote_flash_erase
;
7257 remote_ops
.to_flash_done
= remote_flash_done
;
7258 remote_ops
.to_read_description
= remote_read_description
;
7259 remote_ops
.to_can_async_p
= remote_return_zero
;
7260 remote_ops
.to_is_async_p
= remote_return_zero
;
7263 /* Set up the extended remote vector by making a copy of the standard
7264 remote vector and adding to it. */
7267 init_extended_remote_ops (void)
7269 extended_remote_ops
= remote_ops
;
7271 extended_remote_ops
.to_shortname
= "extended-remote";
7272 extended_remote_ops
.to_longname
=
7273 "Extended remote serial target in gdb-specific protocol";
7274 extended_remote_ops
.to_doc
=
7275 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
7276 Specify the serial device it is connected to (e.g. /dev/ttya).",
7277 extended_remote_ops
.to_open
= extended_remote_open
;
7278 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
7279 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
7280 extended_remote_ops
.to_detach
= extended_remote_detach
;
7281 extended_remote_ops
.to_attach
= extended_remote_attach
;
7285 remote_can_async_p (void)
7287 /* We're async whenever the serial device is. */
7288 return remote_async_mask_value
&& serial_can_async_p (remote_desc
);
7292 remote_is_async_p (void)
7294 /* We're async whenever the serial device is. */
7295 return remote_async_mask_value
&& serial_is_async_p (remote_desc
);
7298 /* Pass the SERIAL event on and up to the client. One day this code
7299 will be able to delay notifying the client of an event until the
7300 point where an entire packet has been received. */
7302 static void (*async_client_callback
) (enum inferior_event_type event_type
,
7304 static void *async_client_context
;
7305 static serial_event_ftype remote_async_serial_handler
;
7308 remote_async_serial_handler (struct serial
*scb
, void *context
)
7310 /* Don't propogate error information up to the client. Instead let
7311 the client find out about the error by querying the target. */
7312 async_client_callback (INF_REG_EVENT
, async_client_context
);
7316 remote_async (void (*callback
) (enum inferior_event_type event_type
,
7317 void *context
), void *context
)
7319 if (remote_async_mask_value
== 0)
7320 internal_error (__FILE__
, __LINE__
,
7321 _("Calling remote_async when async is masked"));
7323 if (callback
!= NULL
)
7325 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
7326 async_client_callback
= callback
;
7327 async_client_context
= context
;
7330 serial_async (remote_desc
, NULL
, NULL
);
7334 remote_async_mask (int new_mask
)
7336 int curr_mask
= remote_async_mask_value
;
7337 remote_async_mask_value
= new_mask
;
7341 /* Target async and target extended-async.
7343 This are temporary targets, until it is all tested. Eventually
7344 async support will be incorporated int the usual 'remote'
7348 init_remote_async_ops (void)
7350 remote_async_ops
.to_shortname
= "async";
7351 remote_async_ops
.to_longname
=
7352 "Remote serial target in async version of the gdb-specific protocol";
7353 remote_async_ops
.to_doc
=
7354 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
7355 Specify the serial device it is connected to (e.g. /dev/ttya).";
7356 remote_async_ops
.to_open
= remote_async_open
;
7357 remote_async_ops
.to_close
= remote_close
;
7358 remote_async_ops
.to_detach
= remote_detach
;
7359 remote_async_ops
.to_disconnect
= remote_disconnect
;
7360 remote_async_ops
.to_resume
= remote_async_resume
;
7361 remote_async_ops
.to_wait
= remote_async_wait
;
7362 remote_async_ops
.to_fetch_registers
= remote_fetch_registers
;
7363 remote_async_ops
.to_store_registers
= remote_store_registers
;
7364 remote_async_ops
.to_prepare_to_store
= remote_prepare_to_store
;
7365 remote_async_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
7366 remote_async_ops
.to_files_info
= remote_files_info
;
7367 remote_async_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
7368 remote_async_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
7369 remote_async_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
7370 remote_async_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
7371 remote_async_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
7372 remote_async_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
7373 remote_async_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
7374 remote_async_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
7375 remote_async_ops
.to_stopped_data_address
= remote_stopped_data_address
;
7376 remote_async_ops
.to_terminal_inferior
= remote_async_terminal_inferior
;
7377 remote_async_ops
.to_terminal_ours
= remote_async_terminal_ours
;
7378 remote_async_ops
.to_kill
= remote_async_kill
;
7379 remote_async_ops
.to_load
= generic_load
;
7380 remote_async_ops
.to_mourn_inferior
= remote_async_mourn
;
7381 remote_async_ops
.to_thread_alive
= remote_thread_alive
;
7382 remote_async_ops
.to_find_new_threads
= remote_threads_info
;
7383 remote_async_ops
.to_pid_to_str
= remote_pid_to_str
;
7384 remote_async_ops
.to_extra_thread_info
= remote_threads_extra_info
;
7385 remote_async_ops
.to_stop
= remote_stop
;
7386 remote_async_ops
.to_xfer_partial
= remote_xfer_partial
;
7387 remote_async_ops
.to_rcmd
= remote_rcmd
;
7388 remote_async_ops
.to_get_thread_local_address
7389 = remote_get_thread_local_address
;
7390 remote_async_ops
.to_stratum
= process_stratum
;
7391 remote_async_ops
.to_has_all_memory
= 1;
7392 remote_async_ops
.to_has_memory
= 1;
7393 remote_async_ops
.to_has_stack
= 1;
7394 remote_async_ops
.to_has_registers
= 1;
7395 remote_async_ops
.to_has_execution
= 1;
7396 remote_async_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
7397 remote_async_ops
.to_can_async_p
= remote_can_async_p
;
7398 remote_async_ops
.to_is_async_p
= remote_is_async_p
;
7399 remote_async_ops
.to_async
= remote_async
;
7400 remote_async_ops
.to_async_mask
= remote_async_mask
;
7401 remote_async_ops
.to_magic
= OPS_MAGIC
;
7402 remote_async_ops
.to_memory_map
= remote_memory_map
;
7403 remote_async_ops
.to_flash_erase
= remote_flash_erase
;
7404 remote_async_ops
.to_flash_done
= remote_flash_done
;
7405 remote_async_ops
.to_read_description
= remote_read_description
;
7408 /* Set up the async extended remote vector by making a copy of the standard
7409 remote vector and adding to it. */
7412 init_extended_async_remote_ops (void)
7414 extended_async_remote_ops
= remote_async_ops
;
7416 extended_async_remote_ops
.to_shortname
= "extended-async";
7417 extended_async_remote_ops
.to_longname
=
7418 "Extended remote serial target in async gdb-specific protocol";
7419 extended_async_remote_ops
.to_doc
=
7420 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
7421 Specify the serial device it is connected to (e.g. /dev/ttya).",
7422 extended_async_remote_ops
.to_open
= extended_remote_async_open
;
7423 extended_async_remote_ops
.to_create_inferior
= extended_remote_async_create_inferior
;
7424 extended_async_remote_ops
.to_mourn_inferior
= extended_async_remote_mourn
;
7425 extended_async_remote_ops
.to_detach
= extended_remote_detach
;
7426 extended_async_remote_ops
.to_attach
= extended_async_remote_attach
;
7430 set_remote_cmd (char *args
, int from_tty
)
7432 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
7436 show_remote_cmd (char *args
, int from_tty
)
7438 /* We can't just use cmd_show_list here, because we want to skip
7439 the redundant "show remote Z-packet" and the legacy aliases. */
7440 struct cleanup
*showlist_chain
;
7441 struct cmd_list_element
*list
= remote_show_cmdlist
;
7443 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
7444 for (; list
!= NULL
; list
= list
->next
)
7445 if (strcmp (list
->name
, "Z-packet") == 0)
7447 else if (list
->type
== not_set_cmd
)
7448 /* Alias commands are exactly like the original, except they
7449 don't have the normal type. */
7453 struct cleanup
*option_chain
7454 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
7455 ui_out_field_string (uiout
, "name", list
->name
);
7456 ui_out_text (uiout
, ": ");
7457 if (list
->type
== show_cmd
)
7458 do_setshow_command ((char *) NULL
, from_tty
, list
);
7460 cmd_func (list
, NULL
, from_tty
);
7461 /* Close the tuple. */
7462 do_cleanups (option_chain
);
7465 /* Close the tuple. */
7466 do_cleanups (showlist_chain
);
7470 /* Function to be called whenever a new objfile (shlib) is detected. */
7472 remote_new_objfile (struct objfile
*objfile
)
7474 if (remote_desc
!= 0) /* Have a remote connection. */
7475 remote_check_symbols (objfile
);
7479 _initialize_remote (void)
7481 struct remote_state
*rs
;
7483 /* architecture specific data */
7484 remote_gdbarch_data_handle
=
7485 gdbarch_data_register_post_init (init_remote_state
);
7486 remote_g_packet_data_handle
=
7487 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
7489 /* Initialize the per-target state. At the moment there is only one
7490 of these, not one per target. Only one target is active at a
7491 time. The default buffer size is unimportant; it will be expanded
7492 whenever a larger buffer is needed. */
7493 rs
= get_remote_state_raw ();
7495 rs
->buf
= xmalloc (rs
->buf_size
);
7498 add_target (&remote_ops
);
7500 init_extended_remote_ops ();
7501 add_target (&extended_remote_ops
);
7503 init_remote_async_ops ();
7504 add_target (&remote_async_ops
);
7506 init_extended_async_remote_ops ();
7507 add_target (&extended_async_remote_ops
);
7509 /* Hook into new objfile notification. */
7510 observer_attach_new_objfile (remote_new_objfile
);
7512 /* Set up signal handlers. */
7513 sigint_remote_token
=
7514 create_async_signal_handler (async_remote_interrupt
, NULL
);
7515 sigint_remote_twice_token
=
7516 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
7519 init_remote_threadtests ();
7522 /* set/show remote ... */
7524 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
7525 Remote protocol specific variables\n\
7526 Configure various remote-protocol specific variables such as\n\
7527 the packets being used"),
7528 &remote_set_cmdlist
, "set remote ",
7529 0 /* allow-unknown */, &setlist
);
7530 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
7531 Remote protocol specific variables\n\
7532 Configure various remote-protocol specific variables such as\n\
7533 the packets being used"),
7534 &remote_show_cmdlist
, "show remote ",
7535 0 /* allow-unknown */, &showlist
);
7537 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
7538 Compare section data on target to the exec file.\n\
7539 Argument is a single section name (default: all loaded sections)."),
7542 add_cmd ("packet", class_maintenance
, packet_command
, _("\
7543 Send an arbitrary packet to a remote target.\n\
7544 maintenance packet TEXT\n\
7545 If GDB is talking to an inferior via the GDB serial protocol, then\n\
7546 this command sends the string TEXT to the inferior, and displays the\n\
7547 response packet. GDB supplies the initial `$' character, and the\n\
7548 terminating `#' character and checksum."),
7551 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
7552 Set whether to send break if interrupted."), _("\
7553 Show whether to send break if interrupted."), _("\
7554 If set, a break, instead of a cntrl-c, is sent to the remote target."),
7555 NULL
, NULL
, /* FIXME: i18n: Whether to send break if interrupted is %s. */
7556 &setlist
, &showlist
);
7558 /* Install commands for configuring memory read/write packets. */
7560 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
7561 Set the maximum number of bytes per memory write packet (deprecated)."),
7563 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
7564 Show the maximum number of bytes per memory write packet (deprecated)."),
7566 add_cmd ("memory-write-packet-size", no_class
,
7567 set_memory_write_packet_size
, _("\
7568 Set the maximum number of bytes per memory-write packet.\n\
7569 Specify the number of bytes in a packet or 0 (zero) for the\n\
7570 default packet size. The actual limit is further reduced\n\
7571 dependent on the target. Specify ``fixed'' to disable the\n\
7572 further restriction and ``limit'' to enable that restriction."),
7573 &remote_set_cmdlist
);
7574 add_cmd ("memory-read-packet-size", no_class
,
7575 set_memory_read_packet_size
, _("\
7576 Set the maximum number of bytes per memory-read packet.\n\
7577 Specify the number of bytes in a packet or 0 (zero) for the\n\
7578 default packet size. The actual limit is further reduced\n\
7579 dependent on the target. Specify ``fixed'' to disable the\n\
7580 further restriction and ``limit'' to enable that restriction."),
7581 &remote_set_cmdlist
);
7582 add_cmd ("memory-write-packet-size", no_class
,
7583 show_memory_write_packet_size
,
7584 _("Show the maximum number of bytes per memory-write packet."),
7585 &remote_show_cmdlist
);
7586 add_cmd ("memory-read-packet-size", no_class
,
7587 show_memory_read_packet_size
,
7588 _("Show the maximum number of bytes per memory-read packet."),
7589 &remote_show_cmdlist
);
7591 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
7592 &remote_hw_watchpoint_limit
, _("\
7593 Set the maximum number of target hardware watchpoints."), _("\
7594 Show the maximum number of target hardware watchpoints."), _("\
7595 Specify a negative limit for unlimited."),
7596 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */
7597 &remote_set_cmdlist
, &remote_show_cmdlist
);
7598 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
7599 &remote_hw_breakpoint_limit
, _("\
7600 Set the maximum number of target hardware breakpoints."), _("\
7601 Show the maximum number of target hardware breakpoints."), _("\
7602 Specify a negative limit for unlimited."),
7603 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */
7604 &remote_set_cmdlist
, &remote_show_cmdlist
);
7606 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
7607 &remote_address_size
, _("\
7608 Set the maximum size of the address (in bits) in a memory packet."), _("\
7609 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
7611 NULL
, /* FIXME: i18n: */
7612 &setlist
, &showlist
);
7614 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
7615 "X", "binary-download", 1);
7617 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
7618 "vCont", "verbose-resume", 0);
7620 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
7621 "QPassSignals", "pass-signals", 0);
7623 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
7624 "qSymbol", "symbol-lookup", 0);
7626 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
7627 "P", "set-register", 1);
7629 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
7630 "p", "fetch-register", 1);
7632 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
7633 "Z0", "software-breakpoint", 0);
7635 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
7636 "Z1", "hardware-breakpoint", 0);
7638 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
7639 "Z2", "write-watchpoint", 0);
7641 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
7642 "Z3", "read-watchpoint", 0);
7644 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
7645 "Z4", "access-watchpoint", 0);
7647 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
7648 "qXfer:auxv:read", "read-aux-vector", 0);
7650 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
7651 "qXfer:features:read", "target-features", 0);
7653 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
7654 "qXfer:libraries:read", "library-info", 0);
7656 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
7657 "qXfer:memory-map:read", "memory-map", 0);
7659 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
7660 "qXfer:spu:read", "read-spu-object", 0);
7662 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
7663 "qXfer:spu:write", "write-spu-object", 0);
7665 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
7666 "qGetTLSAddr", "get-thread-local-storage-address",
7669 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
7670 "qSupported", "supported-packets", 0);
7672 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
7673 "vFile:open", "hostio-open", 0);
7675 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
7676 "vFile:pread", "hostio-pread", 0);
7678 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
7679 "vFile:pwrite", "hostio-pwrite", 0);
7681 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
7682 "vFile:close", "hostio-close", 0);
7684 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
7685 "vFile:unlink", "hostio-unlink", 0);
7687 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
7688 "vAttach", "attach", 0);
7690 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
7693 /* Keep the old ``set remote Z-packet ...'' working. Each individual
7694 Z sub-packet has its own set and show commands, but users may
7695 have sets to this variable in their .gdbinit files (or in their
7697 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
7698 &remote_Z_packet_detect
, _("\
7699 Set use of remote protocol `Z' packets"), _("\
7700 Show use of remote protocol `Z' packets "), _("\
7701 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
7703 set_remote_protocol_Z_packet_cmd
,
7704 show_remote_protocol_Z_packet_cmd
, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */
7705 &remote_set_cmdlist
, &remote_show_cmdlist
);
7707 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
7708 Manipulate files on the remote system\n\
7709 Transfer files to and from the remote target system."),
7710 &remote_cmdlist
, "remote ",
7711 0 /* allow-unknown */, &cmdlist
);
7713 add_cmd ("put", class_files
, remote_put_command
,
7714 _("Copy a local file to the remote system."),
7717 add_cmd ("get", class_files
, remote_get_command
,
7718 _("Copy a remote file to the local system."),
7721 add_cmd ("delete", class_files
, remote_delete_command
,
7722 _("Delete a remote file."),
7725 remote_exec_file
= xstrdup ("");
7726 add_setshow_string_noescape_cmd ("exec-file", class_files
,
7727 &remote_exec_file
, _("\
7728 Set the remote pathname for \"run\""), _("\
7729 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
7730 &remote_set_cmdlist
, &remote_show_cmdlist
);
7732 /* Eventually initialize fileio. See fileio.c */
7733 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);