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"
64 #include "memory-map.h"
66 /* The size to align memory write packets, when practical. The protocol
67 does not guarantee any alignment, and gdb will generate short
68 writes and unaligned writes, but even as a best-effort attempt this
69 can improve bulk transfers. For instance, if a write is misaligned
70 relative to the target's data bus, the stub may need to make an extra
71 round trip fetching data from the target. This doesn't make a
72 huge difference, but it's easy to do, so we try to be helpful.
74 The alignment chosen is arbitrary; usually data bus width is
75 important here, not the possibly larger cache line size. */
76 enum { REMOTE_ALIGN_WRITES
= 16 };
78 /* Prototypes for local functions. */
79 static void cleanup_sigint_signal_handler (void *dummy
);
80 static void initialize_sigint_signal_handler (void);
81 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
83 static void handle_remote_sigint (int);
84 static void handle_remote_sigint_twice (int);
85 static void async_remote_interrupt (gdb_client_data
);
86 void async_remote_interrupt_twice (gdb_client_data
);
88 static void remote_files_info (struct target_ops
*ignore
);
90 static void remote_prepare_to_store (struct regcache
*regcache
);
92 static void remote_fetch_registers (struct regcache
*regcache
, int regno
);
94 static void remote_resume (ptid_t ptid
, int step
,
95 enum target_signal siggnal
);
96 static void remote_open (char *name
, int from_tty
);
98 static void extended_remote_open (char *name
, int from_tty
);
100 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
102 static void remote_close (int quitting
);
104 static void remote_store_registers (struct regcache
*regcache
, int regno
);
106 static void remote_mourn (void);
108 static void extended_remote_restart (void);
110 static void extended_remote_mourn (void);
112 static void remote_mourn_1 (struct target_ops
*);
114 static void remote_send (char **buf
, long *sizeof_buf_p
);
116 static int readchar (int timeout
);
118 static ptid_t
remote_wait (ptid_t ptid
,
119 struct target_waitstatus
*status
);
121 static void remote_kill (void);
123 static int tohex (int nib
);
125 static int remote_can_async_p (void);
127 static int remote_is_async_p (void);
129 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
130 void *context
), void *context
);
132 static int remote_async_mask (int new_mask
);
134 static void remote_detach (char *args
, int from_tty
);
136 static void remote_interrupt (int signo
);
138 static void remote_interrupt_twice (int signo
);
140 static void interrupt_query (void);
142 static void set_general_thread (struct ptid ptid
);
143 static void set_continue_thread (struct ptid ptid
);
145 static int remote_thread_alive (ptid_t
);
147 static void get_offsets (void);
149 static void skip_frame (void);
151 static long read_frame (char **buf_p
, long *sizeof_buf
);
153 static int hexnumlen (ULONGEST num
);
155 static void init_remote_ops (void);
157 static void init_extended_remote_ops (void);
159 static void remote_stop (ptid_t
);
161 static int ishex (int ch
, int *val
);
163 static int stubhex (int ch
);
165 static int hexnumstr (char *, ULONGEST
);
167 static int hexnumnstr (char *, ULONGEST
, int);
169 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
171 static void print_packet (char *);
173 static unsigned long crc32 (unsigned char *, int, unsigned int);
175 static void compare_sections_command (char *, int);
177 static void packet_command (char *, int);
179 static int stub_unpack_int (char *buff
, int fieldlength
);
181 static ptid_t
remote_current_thread (ptid_t oldptid
);
183 static void remote_find_new_threads (void);
185 static void record_currthread (ptid_t currthread
);
187 static int fromhex (int a
);
189 static int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
191 static int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
193 static int putpkt_binary (char *buf
, int cnt
);
195 static void check_binary_download (CORE_ADDR addr
);
197 struct packet_config
;
199 static void show_packet_config_cmd (struct packet_config
*config
);
201 static void update_packet_config (struct packet_config
*config
);
203 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
204 struct cmd_list_element
*c
);
206 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
208 struct cmd_list_element
*c
,
211 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
212 static ptid_t
read_ptid (char *buf
, char **obuf
);
214 void _initialize_remote (void);
218 static struct cmd_list_element
*remote_cmdlist
;
220 /* For "set remote" and "show remote". */
222 static struct cmd_list_element
*remote_set_cmdlist
;
223 static struct cmd_list_element
*remote_show_cmdlist
;
225 /* Description of the remote protocol state for the currently
226 connected target. This is per-target state, and independent of the
227 selected architecture. */
231 /* A buffer to use for incoming packets, and its current size. The
232 buffer is grown dynamically for larger incoming packets.
233 Outgoing packets may also be constructed in this buffer.
234 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
235 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
240 /* If we negotiated packet size explicitly (and thus can bypass
241 heuristics for the largest packet size that will not overflow
242 a buffer in the stub), this will be set to that packet size.
243 Otherwise zero, meaning to use the guessed size. */
244 long explicit_packet_size
;
246 /* remote_wait is normally called when the target is running and
247 waits for a stop reply packet. But sometimes we need to call it
248 when the target is already stopped. We can send a "?" packet
249 and have remote_wait read the response. Or, if we already have
250 the response, we can stash it in BUF and tell remote_wait to
251 skip calling getpkt. This flag is set when BUF contains a
252 stop reply packet and the target is not waiting. */
253 int cached_wait_status
;
255 /* True, if in no ack mode. That is, neither GDB nor the stub will
256 expect acks from each other. The connection is assumed to be
260 /* True if we're connected in extended remote mode. */
263 /* True if the stub reported support for multi-process
265 int multi_process_aware
;
268 /* Returns true if the multi-process extensions are in effect. */
270 remote_multi_process_p (struct remote_state
*rs
)
272 return rs
->extended
&& rs
->multi_process_aware
;
275 /* This data could be associated with a target, but we do not always
276 have access to the current target when we need it, so for now it is
277 static. This will be fine for as long as only one target is in use
279 static struct remote_state remote_state
;
281 static struct remote_state
*
282 get_remote_state_raw (void)
284 return &remote_state
;
287 /* Description of the remote protocol for a given architecture. */
291 long offset
; /* Offset into G packet. */
292 long regnum
; /* GDB's internal register number. */
293 LONGEST pnum
; /* Remote protocol register number. */
294 int in_g_packet
; /* Always part of G packet. */
295 /* long size in bytes; == register_size (target_gdbarch, regnum);
297 /* char *name; == gdbarch_register_name (target_gdbarch, regnum);
301 struct remote_arch_state
303 /* Description of the remote protocol registers. */
304 long sizeof_g_packet
;
306 /* Description of the remote protocol registers indexed by REGNUM
307 (making an array gdbarch_num_regs in size). */
308 struct packet_reg
*regs
;
310 /* This is the size (in chars) of the first response to the ``g''
311 packet. It is used as a heuristic when determining the maximum
312 size of memory-read and memory-write packets. A target will
313 typically only reserve a buffer large enough to hold the ``g''
314 packet. The size does not include packet overhead (headers and
316 long actual_register_packet_size
;
318 /* This is the maximum size (in chars) of a non read/write packet.
319 It is also used as a cap on the size of read/write packets. */
320 long remote_packet_size
;
324 /* Handle for retreving the remote protocol data from gdbarch. */
325 static struct gdbarch_data
*remote_gdbarch_data_handle
;
327 static struct remote_arch_state
*
328 get_remote_arch_state (void)
330 return gdbarch_data (target_gdbarch
, remote_gdbarch_data_handle
);
333 /* Fetch the global remote target state. */
335 static struct remote_state
*
336 get_remote_state (void)
338 /* Make sure that the remote architecture state has been
339 initialized, because doing so might reallocate rs->buf. Any
340 function which calls getpkt also needs to be mindful of changes
341 to rs->buf, but this call limits the number of places which run
343 get_remote_arch_state ();
345 return get_remote_state_raw ();
349 compare_pnums (const void *lhs_
, const void *rhs_
)
351 const struct packet_reg
* const *lhs
= lhs_
;
352 const struct packet_reg
* const *rhs
= rhs_
;
354 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
356 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
363 init_remote_state (struct gdbarch
*gdbarch
)
365 int regnum
, num_remote_regs
, offset
;
366 struct remote_state
*rs
= get_remote_state_raw ();
367 struct remote_arch_state
*rsa
;
368 struct packet_reg
**remote_regs
;
370 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
372 /* Use the architecture to build a regnum<->pnum table, which will be
373 1:1 unless a feature set specifies otherwise. */
374 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
375 gdbarch_num_regs (gdbarch
),
377 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
379 struct packet_reg
*r
= &rsa
->regs
[regnum
];
381 if (register_size (gdbarch
, regnum
) == 0)
382 /* Do not try to fetch zero-sized (placeholder) registers. */
385 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
390 /* Define the g/G packet format as the contents of each register
391 with a remote protocol number, in order of ascending protocol
394 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
395 * sizeof (struct packet_reg
*));
396 for (num_remote_regs
= 0, regnum
= 0;
397 regnum
< gdbarch_num_regs (gdbarch
);
399 if (rsa
->regs
[regnum
].pnum
!= -1)
400 remote_regs
[num_remote_regs
++] = &rsa
->regs
[regnum
];
402 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
405 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
407 remote_regs
[regnum
]->in_g_packet
= 1;
408 remote_regs
[regnum
]->offset
= offset
;
409 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
412 /* Record the maximum possible size of the g packet - it may turn out
414 rsa
->sizeof_g_packet
= offset
;
416 /* Default maximum number of characters in a packet body. Many
417 remote stubs have a hardwired buffer size of 400 bytes
418 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
419 as the maximum packet-size to ensure that the packet and an extra
420 NUL character can always fit in the buffer. This stops GDB
421 trashing stubs that try to squeeze an extra NUL into what is
422 already a full buffer (As of 1999-12-04 that was most stubs). */
423 rsa
->remote_packet_size
= 400 - 1;
425 /* This one is filled in when a ``g'' packet is received. */
426 rsa
->actual_register_packet_size
= 0;
428 /* Should rsa->sizeof_g_packet needs more space than the
429 default, adjust the size accordingly. Remember that each byte is
430 encoded as two characters. 32 is the overhead for the packet
431 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
432 (``$NN:G...#NN'') is a better guess, the below has been padded a
434 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
435 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
437 /* Make sure that the packet buffer is plenty big enough for
438 this architecture. */
439 if (rs
->buf_size
< rsa
->remote_packet_size
)
441 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
442 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
448 /* Return the current allowed size of a remote packet. This is
449 inferred from the current architecture, and should be used to
450 limit the length of outgoing packets. */
452 get_remote_packet_size (void)
454 struct remote_state
*rs
= get_remote_state ();
455 struct remote_arch_state
*rsa
= get_remote_arch_state ();
457 if (rs
->explicit_packet_size
)
458 return rs
->explicit_packet_size
;
460 return rsa
->remote_packet_size
;
463 static struct packet_reg
*
464 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
466 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch
))
470 struct packet_reg
*r
= &rsa
->regs
[regnum
];
471 gdb_assert (r
->regnum
== regnum
);
476 static struct packet_reg
*
477 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
480 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch
); i
++)
482 struct packet_reg
*r
= &rsa
->regs
[i
];
489 /* FIXME: graces/2002-08-08: These variables should eventually be
490 bound to an instance of the target object (as in gdbarch-tdep()),
491 when such a thing exists. */
493 /* This is set to the data address of the access causing the target
494 to stop for a watchpoint. */
495 static CORE_ADDR remote_watch_data_address
;
497 /* This is non-zero if target stopped for a watchpoint. */
498 static int remote_stopped_by_watchpoint_p
;
500 static struct target_ops remote_ops
;
502 static struct target_ops extended_remote_ops
;
504 static int remote_async_mask_value
= 1;
506 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
507 ``forever'' still use the normal timeout mechanism. This is
508 currently used by the ASYNC code to guarentee that target reads
509 during the initial connect always time-out. Once getpkt has been
510 modified to return a timeout indication and, in turn
511 remote_wait()/wait_for_inferior() have gained a timeout parameter
513 static int wait_forever_enabled_p
= 1;
516 /* This variable chooses whether to send a ^C or a break when the user
517 requests program interruption. Although ^C is usually what remote
518 systems expect, and that is the default here, sometimes a break is
519 preferable instead. */
521 static int remote_break
;
523 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
524 remote_open knows that we don't have a file open when the program
526 static struct serial
*remote_desc
= NULL
;
528 /* This variable sets the number of bits in an address that are to be
529 sent in a memory ("M" or "m") packet. Normally, after stripping
530 leading zeros, the entire address would be sent. This variable
531 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
532 initial implementation of remote.c restricted the address sent in
533 memory packets to ``host::sizeof long'' bytes - (typically 32
534 bits). Consequently, for 64 bit targets, the upper 32 bits of an
535 address was never sent. Since fixing this bug may cause a break in
536 some remote targets this variable is principly provided to
537 facilitate backward compatibility. */
539 static int remote_address_size
;
541 /* Temporary to track who currently owns the terminal. See
542 remote_terminal_* for more details. */
544 static int remote_async_terminal_ours_p
;
546 /* The executable file to use for "run" on the remote side. */
548 static char *remote_exec_file
= "";
551 /* User configurable variables for the number of characters in a
552 memory read/write packet. MIN (rsa->remote_packet_size,
553 rsa->sizeof_g_packet) is the default. Some targets need smaller
554 values (fifo overruns, et.al.) and some users need larger values
555 (speed up transfers). The variables ``preferred_*'' (the user
556 request), ``current_*'' (what was actually set) and ``forced_*''
557 (Positive - a soft limit, negative - a hard limit). */
559 struct memory_packet_config
566 /* Compute the current size of a read/write packet. Since this makes
567 use of ``actual_register_packet_size'' the computation is dynamic. */
570 get_memory_packet_size (struct memory_packet_config
*config
)
572 struct remote_state
*rs
= get_remote_state ();
573 struct remote_arch_state
*rsa
= get_remote_arch_state ();
575 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
576 law?) that some hosts don't cope very well with large alloca()
577 calls. Eventually the alloca() code will be replaced by calls to
578 xmalloc() and make_cleanups() allowing this restriction to either
579 be lifted or removed. */
580 #ifndef MAX_REMOTE_PACKET_SIZE
581 #define MAX_REMOTE_PACKET_SIZE 16384
583 /* NOTE: 20 ensures we can write at least one byte. */
584 #ifndef MIN_REMOTE_PACKET_SIZE
585 #define MIN_REMOTE_PACKET_SIZE 20
590 if (config
->size
<= 0)
591 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
593 what_they_get
= config
->size
;
597 what_they_get
= get_remote_packet_size ();
598 /* Limit the packet to the size specified by the user. */
600 && what_they_get
> config
->size
)
601 what_they_get
= config
->size
;
603 /* Limit it to the size of the targets ``g'' response unless we have
604 permission from the stub to use a larger packet size. */
605 if (rs
->explicit_packet_size
== 0
606 && rsa
->actual_register_packet_size
> 0
607 && what_they_get
> rsa
->actual_register_packet_size
)
608 what_they_get
= rsa
->actual_register_packet_size
;
610 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
611 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
612 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
613 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
615 /* Make sure there is room in the global buffer for this packet
616 (including its trailing NUL byte). */
617 if (rs
->buf_size
< what_they_get
+ 1)
619 rs
->buf_size
= 2 * what_they_get
;
620 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
623 return what_they_get
;
626 /* Update the size of a read/write packet. If they user wants
627 something really big then do a sanity check. */
630 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
632 int fixed_p
= config
->fixed_p
;
633 long size
= config
->size
;
635 error (_("Argument required (integer, `fixed' or `limited')."));
636 else if (strcmp (args
, "hard") == 0
637 || strcmp (args
, "fixed") == 0)
639 else if (strcmp (args
, "soft") == 0
640 || strcmp (args
, "limit") == 0)
645 size
= strtoul (args
, &end
, 0);
647 error (_("Invalid %s (bad syntax)."), config
->name
);
649 /* Instead of explicitly capping the size of a packet to
650 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
651 instead allowed to set the size to something arbitrarily
653 if (size
> MAX_REMOTE_PACKET_SIZE
)
654 error (_("Invalid %s (too large)."), config
->name
);
658 if (fixed_p
&& !config
->fixed_p
)
660 if (! query (_("The target may not be able to correctly handle a %s\n"
661 "of %ld bytes. Change the packet size? "),
663 error (_("Packet size not changed."));
665 /* Update the config. */
666 config
->fixed_p
= fixed_p
;
671 show_memory_packet_size (struct memory_packet_config
*config
)
673 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
675 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
676 get_memory_packet_size (config
));
678 printf_filtered (_("Packets are limited to %ld bytes.\n"),
679 get_memory_packet_size (config
));
682 static struct memory_packet_config memory_write_packet_config
=
684 "memory-write-packet-size",
688 set_memory_write_packet_size (char *args
, int from_tty
)
690 set_memory_packet_size (args
, &memory_write_packet_config
);
694 show_memory_write_packet_size (char *args
, int from_tty
)
696 show_memory_packet_size (&memory_write_packet_config
);
700 get_memory_write_packet_size (void)
702 return get_memory_packet_size (&memory_write_packet_config
);
705 static struct memory_packet_config memory_read_packet_config
=
707 "memory-read-packet-size",
711 set_memory_read_packet_size (char *args
, int from_tty
)
713 set_memory_packet_size (args
, &memory_read_packet_config
);
717 show_memory_read_packet_size (char *args
, int from_tty
)
719 show_memory_packet_size (&memory_read_packet_config
);
723 get_memory_read_packet_size (void)
725 long size
= get_memory_packet_size (&memory_read_packet_config
);
726 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
727 extra buffer size argument before the memory read size can be
728 increased beyond this. */
729 if (size
> get_remote_packet_size ())
730 size
= get_remote_packet_size ();
735 /* Generic configuration support for packets the stub optionally
736 supports. Allows the user to specify the use of the packet as well
737 as allowing GDB to auto-detect support in the remote stub. */
741 PACKET_SUPPORT_UNKNOWN
= 0,
750 enum auto_boolean detect
;
751 enum packet_support support
;
754 /* Analyze a packet's return value and update the packet config
765 update_packet_config (struct packet_config
*config
)
767 switch (config
->detect
)
769 case AUTO_BOOLEAN_TRUE
:
770 config
->support
= PACKET_ENABLE
;
772 case AUTO_BOOLEAN_FALSE
:
773 config
->support
= PACKET_DISABLE
;
775 case AUTO_BOOLEAN_AUTO
:
776 config
->support
= PACKET_SUPPORT_UNKNOWN
;
782 show_packet_config_cmd (struct packet_config
*config
)
784 char *support
= "internal-error";
785 switch (config
->support
)
791 support
= "disabled";
793 case PACKET_SUPPORT_UNKNOWN
:
797 switch (config
->detect
)
799 case AUTO_BOOLEAN_AUTO
:
800 printf_filtered (_("Support for the `%s' packet is auto-detected, currently %s.\n"),
801 config
->name
, support
);
803 case AUTO_BOOLEAN_TRUE
:
804 case AUTO_BOOLEAN_FALSE
:
805 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
806 config
->name
, support
);
812 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
813 const char *title
, int legacy
)
820 config
->title
= title
;
821 config
->detect
= AUTO_BOOLEAN_AUTO
;
822 config
->support
= PACKET_SUPPORT_UNKNOWN
;
823 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
825 show_doc
= xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
827 /* set/show TITLE-packet {auto,on,off} */
828 cmd_name
= xstrprintf ("%s-packet", title
);
829 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
830 &config
->detect
, set_doc
, show_doc
, NULL
, /* help_doc */
831 set_remote_protocol_packet_cmd
,
832 show_remote_protocol_packet_cmd
,
833 &remote_set_cmdlist
, &remote_show_cmdlist
);
834 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
838 legacy_name
= xstrprintf ("%s-packet", name
);
839 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
840 &remote_set_cmdlist
);
841 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
842 &remote_show_cmdlist
);
846 static enum packet_result
847 packet_check_result (const char *buf
)
851 /* The stub recognized the packet request. Check that the
852 operation succeeded. */
854 && isxdigit (buf
[1]) && isxdigit (buf
[2])
856 /* "Enn" - definitly an error. */
859 /* Always treat "E." as an error. This will be used for
860 more verbose error messages, such as E.memtypes. */
861 if (buf
[0] == 'E' && buf
[1] == '.')
864 /* The packet may or may not be OK. Just assume it is. */
868 /* The stub does not support the packet. */
869 return PACKET_UNKNOWN
;
872 static enum packet_result
873 packet_ok (const char *buf
, struct packet_config
*config
)
875 enum packet_result result
;
877 result
= packet_check_result (buf
);
882 /* The stub recognized the packet request. */
883 switch (config
->support
)
885 case PACKET_SUPPORT_UNKNOWN
:
887 fprintf_unfiltered (gdb_stdlog
,
888 "Packet %s (%s) is supported\n",
889 config
->name
, config
->title
);
890 config
->support
= PACKET_ENABLE
;
893 internal_error (__FILE__
, __LINE__
,
894 _("packet_ok: attempt to use a disabled packet"));
901 /* The stub does not support the packet. */
902 switch (config
->support
)
905 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
906 /* If the stub previously indicated that the packet was
907 supported then there is a protocol error.. */
908 error (_("Protocol error: %s (%s) conflicting enabled responses."),
909 config
->name
, config
->title
);
911 /* The user set it wrong. */
912 error (_("Enabled packet %s (%s) not recognized by stub"),
913 config
->name
, config
->title
);
915 case PACKET_SUPPORT_UNKNOWN
:
917 fprintf_unfiltered (gdb_stdlog
,
918 "Packet %s (%s) is NOT supported\n",
919 config
->name
, config
->title
);
920 config
->support
= PACKET_DISABLE
;
948 PACKET_qXfer_features
,
949 PACKET_qXfer_libraries
,
950 PACKET_qXfer_memory_map
,
951 PACKET_qXfer_spu_read
,
952 PACKET_qXfer_spu_write
,
956 PACKET_qSearch_memory
,
959 PACKET_QStartNoAckMode
,
964 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
967 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
968 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 update_packet_config (packet
);
982 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
987 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
988 struct cmd_list_element
*c
,
991 struct packet_config
*packet
;
993 for (packet
= remote_protocol_packets
;
994 packet
< &remote_protocol_packets
[PACKET_MAX
];
997 if (&packet
->detect
== c
->var
)
999 show_packet_config_cmd (packet
);
1003 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
1007 /* Should we try one of the 'Z' requests? */
1011 Z_PACKET_SOFTWARE_BP
,
1012 Z_PACKET_HARDWARE_BP
,
1019 /* For compatibility with older distributions. Provide a ``set remote
1020 Z-packet ...'' command that updates all the Z packet types. */
1022 static enum auto_boolean remote_Z_packet_detect
;
1025 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1026 struct cmd_list_element
*c
)
1029 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1031 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1032 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1037 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1038 struct cmd_list_element
*c
,
1042 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1044 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1048 /* Should we try the 'ThreadInfo' query packet?
1050 This variable (NOT available to the user: auto-detect only!)
1051 determines whether GDB will use the new, simpler "ThreadInfo"
1052 query or the older, more complex syntax for thread queries.
1053 This is an auto-detect variable (set to true at each connect,
1054 and set to false when the target fails to recognize it). */
1056 static int use_threadinfo_query
;
1057 static int use_threadextra_query
;
1059 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1060 static struct async_signal_handler
*sigint_remote_twice_token
;
1061 static struct async_signal_handler
*sigint_remote_token
;
1065 static ptid_t magic_null_ptid
;
1066 static ptid_t not_sent_ptid
;
1067 static ptid_t any_thread_ptid
;
1069 /* These are the threads which we last sent to the remote system. The
1070 TID member will be -1 for all or -2 for not sent yet. */
1072 static ptid_t general_thread
;
1073 static ptid_t continue_thread
;
1076 /* Call this function as a result of
1077 1) A halt indication (T packet) containing a thread id
1078 2) A direct query of currthread
1079 3) Successful execution of set thread
1083 record_currthread (ptid_t currthread
)
1085 general_thread
= currthread
;
1087 /* If this is a new thread, add it to GDB's thread list.
1088 If we leave it up to WFI to do this, bad things will happen. */
1090 if (in_thread_list (currthread
) && is_exited (currthread
))
1092 /* We're seeing an event on a thread id we knew had exited.
1093 This has to be a new thread reusing the old id. Add it. */
1094 add_thread (currthread
);
1098 if (!in_thread_list (currthread
))
1100 if (ptid_equal (pid_to_ptid (ptid_get_pid (currthread
)), inferior_ptid
))
1102 /* inferior_ptid has no thread member yet. This can happen
1103 with the vAttach -> remote_wait,"TAAthread:" path if the
1104 stub doesn't support qC. This is the first stop reported
1105 after an attach, so this is the main thread. Update the
1106 ptid in the thread list. */
1107 thread_change_ptid (inferior_ptid
, currthread
);
1111 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1113 /* inferior_ptid is not set yet. This can happen with the
1114 vRun -> remote_wait,"TAAthread:" path if the stub
1115 doesn't support qC. This is the first stop reported
1116 after an attach, so this is the main thread. Update the
1117 ptid in the thread list. */
1118 thread_change_ptid (inferior_ptid
, currthread
);
1122 /* This is really a new thread. Add it. */
1123 add_thread (currthread
);
1126 if (!in_inferior_list (ptid_get_pid (currthread
)))
1127 /* When connecting to a target remote, or to a target
1128 extended-remote which already was debugging an inferior, we may
1129 not know about it yet --- add it. */
1130 add_inferior (ptid_get_pid (currthread
));
1133 static char *last_pass_packet
;
1135 /* If 'QPassSignals' is supported, tell the remote stub what signals
1136 it can simply pass through to the inferior without reporting. */
1139 remote_pass_signals (void)
1141 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1143 char *pass_packet
, *p
;
1144 int numsigs
= (int) TARGET_SIGNAL_LAST
;
1147 gdb_assert (numsigs
< 256);
1148 for (i
= 0; i
< numsigs
; i
++)
1150 if (signal_stop_state (i
) == 0
1151 && signal_print_state (i
) == 0
1152 && signal_pass_state (i
) == 1)
1155 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1156 strcpy (pass_packet
, "QPassSignals:");
1157 p
= pass_packet
+ strlen (pass_packet
);
1158 for (i
= 0; i
< numsigs
; i
++)
1160 if (signal_stop_state (i
) == 0
1161 && signal_print_state (i
) == 0
1162 && signal_pass_state (i
) == 1)
1165 *p
++ = tohex (i
>> 4);
1166 *p
++ = tohex (i
& 15);
1175 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1177 struct remote_state
*rs
= get_remote_state ();
1178 char *buf
= rs
->buf
;
1180 putpkt (pass_packet
);
1181 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1182 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1183 if (last_pass_packet
)
1184 xfree (last_pass_packet
);
1185 last_pass_packet
= pass_packet
;
1188 xfree (pass_packet
);
1192 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1193 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1194 thread. If GEN is set, set the general thread, if not, then set
1195 the step/continue thread. */
1197 set_thread (struct ptid ptid
, int gen
)
1199 struct remote_state
*rs
= get_remote_state ();
1200 ptid_t state
= gen
? general_thread
: continue_thread
;
1201 char *buf
= rs
->buf
;
1202 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1204 if (ptid_equal (state
, ptid
))
1208 *buf
++ = gen
? 'g' : 'c';
1209 if (ptid_equal (ptid
, magic_null_ptid
))
1210 xsnprintf (buf
, endbuf
- buf
, "0");
1211 else if (ptid_equal (ptid
, any_thread_ptid
))
1212 xsnprintf (buf
, endbuf
- buf
, "0");
1213 else if (ptid_equal (ptid
, minus_one_ptid
))
1214 xsnprintf (buf
, endbuf
- buf
, "-1");
1216 write_ptid (buf
, endbuf
, ptid
);
1218 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1220 general_thread
= ptid
;
1222 continue_thread
= ptid
;
1226 set_general_thread (struct ptid ptid
)
1228 set_thread (ptid
, 1);
1232 set_continue_thread (struct ptid ptid
)
1234 set_thread (ptid
, 0);
1238 /* Return nonzero if the thread PTID is still alive on the remote
1242 remote_thread_alive (ptid_t ptid
)
1244 struct remote_state
*rs
= get_remote_state ();
1245 int tid
= ptid_get_tid (ptid
);
1248 if (ptid_equal (ptid
, magic_null_ptid
))
1249 /* The main thread is always alive. */
1252 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1253 /* The main thread is always alive. This can happen after a
1254 vAttach, if the remote side doesn't support
1259 endp
= rs
->buf
+ get_remote_packet_size ();
1262 write_ptid (p
, endp
, ptid
);
1265 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1266 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1269 /* About these extended threadlist and threadinfo packets. They are
1270 variable length packets but, the fields within them are often fixed
1271 length. They are redundent enough to send over UDP as is the
1272 remote protocol in general. There is a matching unit test module
1275 #define OPAQUETHREADBYTES 8
1277 /* a 64 bit opaque identifier */
1278 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1280 /* WARNING: This threadref data structure comes from the remote O.S.,
1281 libstub protocol encoding, and remote.c. it is not particularly
1284 /* Right now, the internal structure is int. We want it to be bigger.
1288 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1290 /* gdb_ext_thread_info is an internal GDB data structure which is
1291 equivalent to the reply of the remote threadinfo packet. */
1293 struct gdb_ext_thread_info
1295 threadref threadid
; /* External form of thread reference. */
1296 int active
; /* Has state interesting to GDB?
1298 char display
[256]; /* Brief state display, name,
1299 blocked/suspended. */
1300 char shortname
[32]; /* To be used to name threads. */
1301 char more_display
[256]; /* Long info, statistics, queue depth,
1305 /* The volume of remote transfers can be limited by submitting
1306 a mask containing bits specifying the desired information.
1307 Use a union of these values as the 'selection' parameter to
1308 get_thread_info. FIXME: Make these TAG names more thread specific.
1311 #define TAG_THREADID 1
1312 #define TAG_EXISTS 2
1313 #define TAG_DISPLAY 4
1314 #define TAG_THREADNAME 8
1315 #define TAG_MOREDISPLAY 16
1317 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1319 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1321 static char *unpack_nibble (char *buf
, int *val
);
1323 static char *pack_nibble (char *buf
, int nibble
);
1325 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1327 static char *unpack_byte (char *buf
, int *value
);
1329 static char *pack_int (char *buf
, int value
);
1331 static char *unpack_int (char *buf
, int *value
);
1333 static char *unpack_string (char *src
, char *dest
, int length
);
1335 static char *pack_threadid (char *pkt
, threadref
*id
);
1337 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1339 void int_to_threadref (threadref
*id
, int value
);
1341 static int threadref_to_int (threadref
*ref
);
1343 static void copy_threadref (threadref
*dest
, threadref
*src
);
1345 static int threadmatch (threadref
*dest
, threadref
*src
);
1347 static char *pack_threadinfo_request (char *pkt
, int mode
,
1350 static int remote_unpack_thread_info_response (char *pkt
,
1351 threadref
*expectedref
,
1352 struct gdb_ext_thread_info
1356 static int remote_get_threadinfo (threadref
*threadid
,
1357 int fieldset
, /*TAG mask */
1358 struct gdb_ext_thread_info
*info
);
1360 static char *pack_threadlist_request (char *pkt
, int startflag
,
1362 threadref
*nextthread
);
1364 static int parse_threadlist_response (char *pkt
,
1366 threadref
*original_echo
,
1367 threadref
*resultlist
,
1370 static int remote_get_threadlist (int startflag
,
1371 threadref
*nextthread
,
1375 threadref
*threadlist
);
1377 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1379 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1380 void *context
, int looplimit
);
1382 static int remote_newthread_step (threadref
*ref
, void *context
);
1385 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1386 buffer we're allowed to write to. Returns
1387 BUF+CHARACTERS_WRITTEN. */
1390 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1393 struct remote_state
*rs
= get_remote_state ();
1395 if (remote_multi_process_p (rs
))
1397 pid
= ptid_get_pid (ptid
);
1399 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1401 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1403 tid
= ptid_get_tid (ptid
);
1405 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1407 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1412 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1413 passed the last parsed char. Returns null_ptid on error. */
1416 read_ptid (char *buf
, char **obuf
)
1420 ULONGEST pid
= 0, tid
= 0;
1425 /* Multi-process ptid. */
1426 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1428 error (_("invalid remote ptid: %s\n"), p
);
1431 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1434 return ptid_build (pid
, 0, tid
);
1437 /* No multi-process. Just a tid. */
1438 pp
= unpack_varlen_hex (p
, &tid
);
1440 /* Since the stub is not sending a process id, then default to
1441 what's in inferior_ptid. */
1442 pid
= ptid_get_pid (inferior_ptid
);
1446 return ptid_build (pid
, 0, tid
);
1449 /* Encode 64 bits in 16 chars of hex. */
1451 static const char hexchars
[] = "0123456789abcdef";
1454 ishex (int ch
, int *val
)
1456 if ((ch
>= 'a') && (ch
<= 'f'))
1458 *val
= ch
- 'a' + 10;
1461 if ((ch
>= 'A') && (ch
<= 'F'))
1463 *val
= ch
- 'A' + 10;
1466 if ((ch
>= '0') && (ch
<= '9'))
1477 if (ch
>= 'a' && ch
<= 'f')
1478 return ch
- 'a' + 10;
1479 if (ch
>= '0' && ch
<= '9')
1481 if (ch
>= 'A' && ch
<= 'F')
1482 return ch
- 'A' + 10;
1487 stub_unpack_int (char *buff
, int fieldlength
)
1494 nibble
= stubhex (*buff
++);
1498 retval
= retval
<< 4;
1504 unpack_varlen_hex (char *buff
, /* packet to parse */
1508 ULONGEST retval
= 0;
1510 while (ishex (*buff
, &nibble
))
1513 retval
= retval
<< 4;
1514 retval
|= nibble
& 0x0f;
1521 unpack_nibble (char *buf
, int *val
)
1523 *val
= fromhex (*buf
++);
1528 pack_nibble (char *buf
, int nibble
)
1530 *buf
++ = hexchars
[(nibble
& 0x0f)];
1535 pack_hex_byte (char *pkt
, int byte
)
1537 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1538 *pkt
++ = hexchars
[(byte
& 0xf)];
1543 unpack_byte (char *buf
, int *value
)
1545 *value
= stub_unpack_int (buf
, 2);
1550 pack_int (char *buf
, int value
)
1552 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1553 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1554 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1555 buf
= pack_hex_byte (buf
, (value
& 0xff));
1560 unpack_int (char *buf
, int *value
)
1562 *value
= stub_unpack_int (buf
, 8);
1566 #if 0 /* Currently unused, uncomment when needed. */
1567 static char *pack_string (char *pkt
, char *string
);
1570 pack_string (char *pkt
, char *string
)
1575 len
= strlen (string
);
1577 len
= 200; /* Bigger than most GDB packets, junk??? */
1578 pkt
= pack_hex_byte (pkt
, len
);
1582 if ((ch
== '\0') || (ch
== '#'))
1583 ch
= '*'; /* Protect encapsulation. */
1588 #endif /* 0 (unused) */
1591 unpack_string (char *src
, char *dest
, int length
)
1600 pack_threadid (char *pkt
, threadref
*id
)
1603 unsigned char *altid
;
1605 altid
= (unsigned char *) id
;
1606 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1608 pkt
= pack_hex_byte (pkt
, *altid
++);
1614 unpack_threadid (char *inbuf
, threadref
*id
)
1617 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1620 altref
= (char *) id
;
1622 while (inbuf
< limit
)
1624 x
= stubhex (*inbuf
++);
1625 y
= stubhex (*inbuf
++);
1626 *altref
++ = (x
<< 4) | y
;
1631 /* Externally, threadrefs are 64 bits but internally, they are still
1632 ints. This is due to a mismatch of specifications. We would like
1633 to use 64bit thread references internally. This is an adapter
1637 int_to_threadref (threadref
*id
, int value
)
1639 unsigned char *scan
;
1641 scan
= (unsigned char *) id
;
1647 *scan
++ = (value
>> 24) & 0xff;
1648 *scan
++ = (value
>> 16) & 0xff;
1649 *scan
++ = (value
>> 8) & 0xff;
1650 *scan
++ = (value
& 0xff);
1654 threadref_to_int (threadref
*ref
)
1657 unsigned char *scan
;
1663 value
= (value
<< 8) | ((*scan
++) & 0xff);
1668 copy_threadref (threadref
*dest
, threadref
*src
)
1671 unsigned char *csrc
, *cdest
;
1673 csrc
= (unsigned char *) src
;
1674 cdest
= (unsigned char *) dest
;
1681 threadmatch (threadref
*dest
, threadref
*src
)
1683 /* Things are broken right now, so just assume we got a match. */
1685 unsigned char *srcp
, *destp
;
1687 srcp
= (char *) src
;
1688 destp
= (char *) dest
;
1692 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
1699 threadid:1, # always request threadid
1706 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1709 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
1711 *pkt
++ = 'q'; /* Info Query */
1712 *pkt
++ = 'P'; /* process or thread info */
1713 pkt
= pack_int (pkt
, mode
); /* mode */
1714 pkt
= pack_threadid (pkt
, id
); /* threadid */
1715 *pkt
= '\0'; /* terminate */
1719 /* These values tag the fields in a thread info response packet. */
1720 /* Tagging the fields allows us to request specific fields and to
1721 add more fields as time goes by. */
1723 #define TAG_THREADID 1 /* Echo the thread identifier. */
1724 #define TAG_EXISTS 2 /* Is this process defined enough to
1725 fetch registers and its stack? */
1726 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1727 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
1728 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1732 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
1733 struct gdb_ext_thread_info
*info
)
1735 struct remote_state
*rs
= get_remote_state ();
1739 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
1742 /* info->threadid = 0; FIXME: implement zero_threadref. */
1744 info
->display
[0] = '\0';
1745 info
->shortname
[0] = '\0';
1746 info
->more_display
[0] = '\0';
1748 /* Assume the characters indicating the packet type have been
1750 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
1751 pkt
= unpack_threadid (pkt
, &ref
);
1754 warning (_("Incomplete response to threadinfo request."));
1755 if (!threadmatch (&ref
, expectedref
))
1756 { /* This is an answer to a different request. */
1757 warning (_("ERROR RMT Thread info mismatch."));
1760 copy_threadref (&info
->threadid
, &ref
);
1762 /* Loop on tagged fields , try to bail if somthing goes wrong. */
1764 /* Packets are terminated with nulls. */
1765 while ((pkt
< limit
) && mask
&& *pkt
)
1767 pkt
= unpack_int (pkt
, &tag
); /* tag */
1768 pkt
= unpack_byte (pkt
, &length
); /* length */
1769 if (!(tag
& mask
)) /* Tags out of synch with mask. */
1771 warning (_("ERROR RMT: threadinfo tag mismatch."));
1775 if (tag
== TAG_THREADID
)
1779 warning (_("ERROR RMT: length of threadid is not 16."));
1783 pkt
= unpack_threadid (pkt
, &ref
);
1784 mask
= mask
& ~TAG_THREADID
;
1787 if (tag
== TAG_EXISTS
)
1789 info
->active
= stub_unpack_int (pkt
, length
);
1791 mask
= mask
& ~(TAG_EXISTS
);
1794 warning (_("ERROR RMT: 'exists' length too long."));
1800 if (tag
== TAG_THREADNAME
)
1802 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1803 mask
= mask
& ~TAG_THREADNAME
;
1806 if (tag
== TAG_DISPLAY
)
1808 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1809 mask
= mask
& ~TAG_DISPLAY
;
1812 if (tag
== TAG_MOREDISPLAY
)
1814 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1815 mask
= mask
& ~TAG_MOREDISPLAY
;
1818 warning (_("ERROR RMT: unknown thread info tag."));
1819 break; /* Not a tag we know about. */
1825 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
1826 struct gdb_ext_thread_info
*info
)
1828 struct remote_state
*rs
= get_remote_state ();
1831 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
1833 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1835 if (rs
->buf
[0] == '\0')
1838 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
1843 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1846 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
1847 threadref
*nextthread
)
1849 *pkt
++ = 'q'; /* info query packet */
1850 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1851 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1852 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1853 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1858 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1861 parse_threadlist_response (char *pkt
, int result_limit
,
1862 threadref
*original_echo
, threadref
*resultlist
,
1865 struct remote_state
*rs
= get_remote_state ();
1867 int count
, resultcount
, done
;
1870 /* Assume the 'q' and 'M chars have been stripped. */
1871 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
1872 /* done parse past here */
1873 pkt
= unpack_byte (pkt
, &count
); /* count field */
1874 pkt
= unpack_nibble (pkt
, &done
);
1875 /* The first threadid is the argument threadid. */
1876 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1877 while ((count
-- > 0) && (pkt
< limit
))
1879 pkt
= unpack_threadid (pkt
, resultlist
++);
1880 if (resultcount
++ >= result_limit
)
1889 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
1890 int *done
, int *result_count
, threadref
*threadlist
)
1892 struct remote_state
*rs
= get_remote_state ();
1893 static threadref echo_nextthread
;
1896 /* Trancate result limit to be smaller than the packet size. */
1897 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= get_remote_packet_size ())
1898 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
1900 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
1902 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1904 if (*rs
->buf
== '\0')
1908 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
1911 if (!threadmatch (&echo_nextthread
, nextthread
))
1913 /* FIXME: This is a good reason to drop the packet. */
1914 /* Possably, there is a duplicate response. */
1916 retransmit immediatly - race conditions
1917 retransmit after timeout - yes
1919 wait for packet, then exit
1921 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
1922 return 0; /* I choose simply exiting. */
1924 if (*result_count
<= 0)
1928 warning (_("RMT ERROR : failed to get remote thread list."));
1931 return result
; /* break; */
1933 if (*result_count
> result_limit
)
1936 warning (_("RMT ERROR: threadlist response longer than requested."));
1942 /* This is the interface between remote and threads, remotes upper
1945 /* remote_find_new_threads retrieves the thread list and for each
1946 thread in the list, looks up the thread in GDB's internal list,
1947 adding the thread if it does not already exist. This involves
1948 getting partial thread lists from the remote target so, polling the
1949 quit_flag is required. */
1952 /* About this many threadisds fit in a packet. */
1954 #define MAXTHREADLISTRESULTS 32
1957 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
1960 int done
, i
, result_count
;
1964 static threadref nextthread
;
1965 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1970 if (loopcount
++ > looplimit
)
1973 warning (_("Remote fetch threadlist -infinite loop-."));
1976 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
1977 &done
, &result_count
, resultthreadlist
))
1982 /* Clear for later iterations. */
1984 /* Setup to resume next batch of thread references, set nextthread. */
1985 if (result_count
>= 1)
1986 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1988 while (result_count
--)
1989 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1996 remote_newthread_step (threadref
*ref
, void *context
)
1998 int pid
= ptid_get_pid (inferior_ptid
);
1999 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2001 if (!in_thread_list (ptid
))
2003 return 1; /* continue iterator */
2006 #define CRAZY_MAX_THREADS 1000
2009 remote_current_thread (ptid_t oldpid
)
2011 struct remote_state
*rs
= get_remote_state ();
2017 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2018 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2019 return read_ptid (&rs
->buf
[2], NULL
);
2024 /* Find new threads for info threads command.
2025 * Original version, using John Metzler's thread protocol.
2029 remote_find_new_threads (void)
2031 remote_threadlist_iterator (remote_newthread_step
, 0,
2036 * Find all threads for info threads command.
2037 * Uses new thread protocol contributed by Cisco.
2038 * Falls back and attempts to use the older method (above)
2039 * if the target doesn't respond to the new method.
2043 remote_threads_info (void)
2045 struct remote_state
*rs
= get_remote_state ();
2049 if (remote_desc
== 0) /* paranoia */
2050 error (_("Command can only be used when connected to the remote target."));
2052 if (use_threadinfo_query
)
2054 putpkt ("qfThreadInfo");
2055 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2057 if (bufp
[0] != '\0') /* q packet recognized */
2059 while (*bufp
++ == 'm') /* reply contains one or more TID */
2063 new_thread
= read_ptid (bufp
, &bufp
);
2064 if (!ptid_equal (new_thread
, null_ptid
)
2065 && !in_thread_list (new_thread
))
2067 if (!in_inferior_list (ptid_get_pid (new_thread
)))
2068 /* When connected to a multi-process aware
2069 stub, "info threads" may show up threads of
2070 inferiors we didn't know about yet. Add
2072 add_inferior (ptid_get_pid (new_thread
));
2074 add_thread (new_thread
);
2077 while (*bufp
++ == ','); /* comma-separated list */
2078 putpkt ("qsThreadInfo");
2079 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2086 /* Else fall back to old method based on jmetzler protocol. */
2087 use_threadinfo_query
= 0;
2088 remote_find_new_threads ();
2093 * Collect a descriptive string about the given thread.
2094 * The target may say anything it wants to about the thread
2095 * (typically info about its blocked / runnable state, name, etc.).
2096 * This string will appear in the info threads display.
2098 * Optional: targets are not required to implement this function.
2102 remote_threads_extra_info (struct thread_info
*tp
)
2104 struct remote_state
*rs
= get_remote_state ();
2108 struct gdb_ext_thread_info threadinfo
;
2109 static char display_buf
[100]; /* arbitrary... */
2110 int n
= 0; /* position in display_buf */
2112 if (remote_desc
== 0) /* paranoia */
2113 internal_error (__FILE__
, __LINE__
,
2114 _("remote_threads_extra_info"));
2116 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2117 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2118 /* This is the main thread which was added by GDB. The remote
2119 server doesn't know about it. */
2122 if (use_threadextra_query
)
2125 char *endb
= rs
->buf
+ get_remote_packet_size ();
2127 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2129 write_ptid (b
, endb
, tp
->ptid
);
2132 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2133 if (rs
->buf
[0] != 0)
2135 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2136 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2137 display_buf
[result
] = '\0';
2142 /* If the above query fails, fall back to the old method. */
2143 use_threadextra_query
= 0;
2144 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2145 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2146 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2147 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2148 if (threadinfo
.active
)
2150 if (*threadinfo
.shortname
)
2151 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2152 " Name: %s,", threadinfo
.shortname
);
2153 if (*threadinfo
.display
)
2154 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2155 " State: %s,", threadinfo
.display
);
2156 if (*threadinfo
.more_display
)
2157 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2158 " Priority: %s", threadinfo
.more_display
);
2162 /* For purely cosmetic reasons, clear up trailing commas. */
2163 if (',' == display_buf
[n
-1])
2164 display_buf
[n
-1] = ' ';
2172 /* Restart the remote side; this is an extended protocol operation. */
2175 extended_remote_restart (void)
2177 struct remote_state
*rs
= get_remote_state ();
2179 /* Send the restart command; for reasons I don't understand the
2180 remote side really expects a number after the "R". */
2181 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2184 remote_fileio_reset ();
2187 /* Clean up connection to a remote debugger. */
2190 remote_close (int quitting
)
2193 serial_close (remote_desc
);
2197 /* Query the remote side for the text, data and bss offsets. */
2202 struct remote_state
*rs
= get_remote_state ();
2205 int lose
, num_segments
= 0, do_sections
, do_segments
;
2206 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
2207 struct section_offsets
*offs
;
2208 struct symfile_segment_data
*data
;
2210 if (symfile_objfile
== NULL
)
2213 putpkt ("qOffsets");
2214 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2217 if (buf
[0] == '\000')
2218 return; /* Return silently. Stub doesn't support
2222 warning (_("Remote failure reply: %s"), buf
);
2226 /* Pick up each field in turn. This used to be done with scanf, but
2227 scanf will make trouble if CORE_ADDR size doesn't match
2228 conversion directives correctly. The following code will work
2229 with any size of CORE_ADDR. */
2230 text_addr
= data_addr
= bss_addr
= 0;
2234 if (strncmp (ptr
, "Text=", 5) == 0)
2237 /* Don't use strtol, could lose on big values. */
2238 while (*ptr
&& *ptr
!= ';')
2239 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2241 if (strncmp (ptr
, ";Data=", 6) == 0)
2244 while (*ptr
&& *ptr
!= ';')
2245 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2250 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
2253 while (*ptr
&& *ptr
!= ';')
2254 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
2256 if (bss_addr
!= data_addr
)
2257 warning (_("Target reported unsupported offsets: %s"), buf
);
2262 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
2265 /* Don't use strtol, could lose on big values. */
2266 while (*ptr
&& *ptr
!= ';')
2267 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2270 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
2273 while (*ptr
&& *ptr
!= ';')
2274 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2282 error (_("Malformed response to offset query, %s"), buf
);
2283 else if (*ptr
!= '\0')
2284 warning (_("Target reported unsupported offsets: %s"), buf
);
2286 offs
= ((struct section_offsets
*)
2287 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
2288 memcpy (offs
, symfile_objfile
->section_offsets
,
2289 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2291 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
2292 do_segments
= (data
!= NULL
);
2293 do_sections
= num_segments
== 0;
2295 if (num_segments
> 0)
2297 segments
[0] = text_addr
;
2298 segments
[1] = data_addr
;
2300 /* If we have two segments, we can still try to relocate everything
2301 by assuming that the .text and .data offsets apply to the whole
2302 text and data segments. Convert the offsets given in the packet
2303 to base addresses for symfile_map_offsets_to_segments. */
2304 else if (data
&& data
->num_segments
== 2)
2306 segments
[0] = data
->segment_bases
[0] + text_addr
;
2307 segments
[1] = data
->segment_bases
[1] + data_addr
;
2310 /* If the object file has only one segment, assume that it is text
2311 rather than data; main programs with no writable data are rare,
2312 but programs with no code are useless. Of course the code might
2313 have ended up in the data segment... to detect that we would need
2314 the permissions here. */
2315 else if (data
&& data
->num_segments
== 1)
2317 segments
[0] = data
->segment_bases
[0] + text_addr
;
2320 /* There's no way to relocate by segment. */
2326 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
2327 offs
, num_segments
, segments
);
2329 if (ret
== 0 && !do_sections
)
2330 error (_("Can not handle qOffsets TextSeg response with this symbol file"));
2337 free_symfile_segment_data (data
);
2341 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2343 /* This is a temporary kludge to force data and bss to use the same offsets
2344 because that's what nlmconv does now. The real solution requires changes
2345 to the stub and remote.c that I don't have time to do right now. */
2347 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2348 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2351 objfile_relocate (symfile_objfile
, offs
);
2354 /* Stub for catch_exception. */
2356 struct start_remote_args
2360 /* The current target. */
2361 struct target_ops
*target
;
2363 /* Non-zero if this is an extended-remote target. */
2368 remote_start_remote (struct ui_out
*uiout
, void *opaque
)
2370 struct remote_state
*rs
= get_remote_state ();
2371 struct start_remote_args
*args
= opaque
;
2372 char *wait_status
= NULL
;
2374 immediate_quit
++; /* Allow user to interrupt it. */
2376 /* Check whether the target is running now. */
2378 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2380 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
2382 if (args
->extended_p
)
2384 /* We're connected, but not running. Drop out before we
2385 call start_remote. */
2386 target_mark_exited (args
->target
);
2390 error (_("The target is not running (try extended-remote?)"));
2394 if (args
->extended_p
)
2395 target_mark_running (args
->target
);
2397 /* Save the reply for later. */
2398 wait_status
= alloca (strlen (rs
->buf
) + 1);
2399 strcpy (wait_status
, rs
->buf
);
2403 init_thread_list ();
2405 /* Let the stub know that we want it to return the thread. */
2406 set_continue_thread (minus_one_ptid
);
2408 /* Without this, some commands which require an active target
2409 (such as kill) won't work. This variable serves (at least)
2410 double duty as both the pid of the target process (if it has
2411 such), and as a flag indicating that a target is active.
2412 These functions should be split out into seperate variables,
2413 especially since GDB will someday have a notion of debugging
2414 several processes. */
2415 inferior_ptid
= magic_null_ptid
;
2417 /* Now, if we have thread information, update inferior_ptid. */
2418 inferior_ptid
= remote_current_thread (inferior_ptid
);
2420 add_inferior (ptid_get_pid (inferior_ptid
));
2422 /* Always add the main thread. */
2423 add_thread_silent (inferior_ptid
);
2425 get_offsets (); /* Get text, data & bss offsets. */
2427 /* Use the previously fetched status. */
2428 gdb_assert (wait_status
!= NULL
);
2429 strcpy (rs
->buf
, wait_status
);
2430 rs
->cached_wait_status
= 1;
2433 start_remote (args
->from_tty
); /* Initialize gdb process mechanisms. */
2436 /* Open a connection to a remote debugger.
2437 NAME is the filename used for communication. */
2440 remote_open (char *name
, int from_tty
)
2442 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
2445 /* Open a connection to a remote debugger using the extended
2446 remote gdb protocol. NAME is the filename used for communication. */
2449 extended_remote_open (char *name
, int from_tty
)
2451 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
2454 /* Generic code for opening a connection to a remote target. */
2457 init_all_packet_configs (void)
2460 for (i
= 0; i
< PACKET_MAX
; i
++)
2461 update_packet_config (&remote_protocol_packets
[i
]);
2464 /* Symbol look-up. */
2467 remote_check_symbols (struct objfile
*objfile
)
2469 struct remote_state
*rs
= get_remote_state ();
2470 char *msg
, *reply
, *tmp
;
2471 struct minimal_symbol
*sym
;
2474 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
2477 /* Allocate a message buffer. We can't reuse the input buffer in RS,
2478 because we need both at the same time. */
2479 msg
= alloca (get_remote_packet_size ());
2481 /* Invite target to request symbol lookups. */
2483 putpkt ("qSymbol::");
2484 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2485 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
2488 while (strncmp (reply
, "qSymbol:", 8) == 0)
2491 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
2493 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
2495 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
2498 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
2500 /* If this is a function address, return the start of code
2501 instead of any data function descriptor. */
2502 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch
,
2506 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
2507 paddr_nz (sym_addr
), &reply
[8]);
2511 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2516 static struct serial
*
2517 remote_serial_open (char *name
)
2519 static int udp_warning
= 0;
2521 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
2522 of in ser-tcp.c, because it is the remote protocol assuming that the
2523 serial connection is reliable and not the serial connection promising
2525 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
2528 The remote protocol may be unreliable over UDP.\n\
2529 Some events may be lost, rendering further debugging impossible."));
2533 return serial_open (name
);
2536 /* This type describes each known response to the qSupported
2538 struct protocol_feature
2540 /* The name of this protocol feature. */
2543 /* The default for this protocol feature. */
2544 enum packet_support default_support
;
2546 /* The function to call when this feature is reported, or after
2547 qSupported processing if the feature is not supported.
2548 The first argument points to this structure. The second
2549 argument indicates whether the packet requested support be
2550 enabled, disabled, or probed (or the default, if this function
2551 is being called at the end of processing and this feature was
2552 not reported). The third argument may be NULL; if not NULL, it
2553 is a NUL-terminated string taken from the packet following
2554 this feature's name and an equals sign. */
2555 void (*func
) (const struct protocol_feature
*, enum packet_support
,
2558 /* The corresponding packet for this feature. Only used if
2559 FUNC is remote_supported_packet. */
2564 remote_supported_packet (const struct protocol_feature
*feature
,
2565 enum packet_support support
,
2566 const char *argument
)
2570 warning (_("Remote qSupported response supplied an unexpected value for"
2571 " \"%s\"."), feature
->name
);
2575 if (remote_protocol_packets
[feature
->packet
].support
2576 == PACKET_SUPPORT_UNKNOWN
)
2577 remote_protocol_packets
[feature
->packet
].support
= support
;
2581 remote_packet_size (const struct protocol_feature
*feature
,
2582 enum packet_support support
, const char *value
)
2584 struct remote_state
*rs
= get_remote_state ();
2589 if (support
!= PACKET_ENABLE
)
2592 if (value
== NULL
|| *value
== '\0')
2594 warning (_("Remote target reported \"%s\" without a size."),
2600 packet_size
= strtol (value
, &value_end
, 16);
2601 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
2603 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
2604 feature
->name
, value
);
2608 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
2610 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
2611 packet_size
, MAX_REMOTE_PACKET_SIZE
);
2612 packet_size
= MAX_REMOTE_PACKET_SIZE
;
2615 /* Record the new maximum packet size. */
2616 rs
->explicit_packet_size
= packet_size
;
2620 remote_multi_process_feature (const struct protocol_feature
*feature
,
2621 enum packet_support support
, const char *value
)
2623 struct remote_state
*rs
= get_remote_state ();
2624 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
2627 static struct protocol_feature remote_protocol_features
[] = {
2628 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
2629 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
2630 PACKET_qXfer_auxv
},
2631 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
2632 PACKET_qXfer_features
},
2633 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
2634 PACKET_qXfer_libraries
},
2635 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
2636 PACKET_qXfer_memory_map
},
2637 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
2638 PACKET_qXfer_spu_read
},
2639 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
2640 PACKET_qXfer_spu_write
},
2641 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
2642 PACKET_QPassSignals
},
2643 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
2644 PACKET_QStartNoAckMode
},
2645 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
2649 remote_query_supported (void)
2651 struct remote_state
*rs
= get_remote_state ();
2654 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
2656 /* The packet support flags are handled differently for this packet
2657 than for most others. We treat an error, a disabled packet, and
2658 an empty response identically: any features which must be reported
2659 to be used will be automatically disabled. An empty buffer
2660 accomplishes this, since that is also the representation for a list
2661 containing no features. */
2664 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
2667 putpkt ("qSupported:multiprocess+");
2669 putpkt ("qSupported");
2671 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2673 /* If an error occured, warn, but do not return - just reset the
2674 buffer to empty and go on to disable features. */
2675 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
2678 warning (_("Remote failure reply: %s"), rs
->buf
);
2683 memset (seen
, 0, sizeof (seen
));
2688 enum packet_support is_supported
;
2689 char *p
, *end
, *name_end
, *value
;
2691 /* First separate out this item from the rest of the packet. If
2692 there's another item after this, we overwrite the separator
2693 (terminated strings are much easier to work with). */
2695 end
= strchr (p
, ';');
2698 end
= p
+ strlen (p
);
2708 warning (_("empty item in \"qSupported\" response"));
2713 name_end
= strchr (p
, '=');
2716 /* This is a name=value entry. */
2717 is_supported
= PACKET_ENABLE
;
2718 value
= name_end
+ 1;
2727 is_supported
= PACKET_ENABLE
;
2731 is_supported
= PACKET_DISABLE
;
2735 is_supported
= PACKET_SUPPORT_UNKNOWN
;
2739 warning (_("unrecognized item \"%s\" in \"qSupported\" response"), p
);
2745 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
2746 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
2748 const struct protocol_feature
*feature
;
2751 feature
= &remote_protocol_features
[i
];
2752 feature
->func (feature
, is_supported
, value
);
2757 /* If we increased the packet size, make sure to increase the global
2758 buffer size also. We delay this until after parsing the entire
2759 qSupported packet, because this is the same buffer we were
2761 if (rs
->buf_size
< rs
->explicit_packet_size
)
2763 rs
->buf_size
= rs
->explicit_packet_size
;
2764 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
2767 /* Handle the defaults for unmentioned features. */
2768 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
2771 const struct protocol_feature
*feature
;
2773 feature
= &remote_protocol_features
[i
];
2774 feature
->func (feature
, feature
->default_support
, NULL
);
2780 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
, int extended_p
)
2782 struct remote_state
*rs
= get_remote_state ();
2783 struct packet_config
*noack_config
;
2786 error (_("To open a remote debug connection, you need to specify what\n"
2787 "serial device is attached to the remote system\n"
2788 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
2790 /* See FIXME above. */
2791 if (!target_async_permitted
)
2792 wait_forever_enabled_p
= 1;
2794 /* If we're connected to a running target, target_preopen will kill it.
2795 But if we're connected to a target system with no running process,
2796 then we will still be connected when it returns. Ask this question
2797 first, before target_preopen has a chance to kill anything. */
2798 if (remote_desc
!= NULL
&& !target_has_execution
)
2801 || query (_("Already connected to a remote target. Disconnect? ")))
2804 error (_("Still connected."));
2807 target_preopen (from_tty
);
2809 unpush_target (target
);
2811 /* This time without a query. If we were connected to an
2812 extended-remote target and target_preopen killed the running
2813 process, we may still be connected. If we are starting "target
2814 remote" now, the extended-remote target will not have been
2815 removed by unpush_target. */
2816 if (remote_desc
!= NULL
&& !target_has_execution
)
2819 /* Make sure we send the passed signals list the next time we resume. */
2820 xfree (last_pass_packet
);
2821 last_pass_packet
= NULL
;
2823 remote_fileio_reset ();
2824 reopen_exec_file ();
2827 remote_desc
= remote_serial_open (name
);
2829 perror_with_name (name
);
2831 if (baud_rate
!= -1)
2833 if (serial_setbaudrate (remote_desc
, baud_rate
))
2835 /* The requested speed could not be set. Error out to
2836 top level after closing remote_desc. Take care to
2837 set remote_desc to NULL to avoid closing remote_desc
2839 serial_close (remote_desc
);
2841 perror_with_name (name
);
2845 serial_raw (remote_desc
);
2847 /* If there is something sitting in the buffer we might take it as a
2848 response to a command, which would be bad. */
2849 serial_flush_input (remote_desc
);
2853 puts_filtered ("Remote debugging using ");
2854 puts_filtered (name
);
2855 puts_filtered ("\n");
2857 push_target (target
); /* Switch to using remote target now. */
2859 /* Assume that the target is running, unless we learn otherwise. */
2860 target_mark_running (target
);
2862 /* Reset the target state; these things will be queried either by
2863 remote_query_supported or as they are needed. */
2864 init_all_packet_configs ();
2865 rs
->explicit_packet_size
= 0;
2867 rs
->multi_process_aware
= 0;
2868 rs
->extended
= extended_p
;
2870 general_thread
= not_sent_ptid
;
2871 continue_thread
= not_sent_ptid
;
2873 /* Probe for ability to use "ThreadInfo" query, as required. */
2874 use_threadinfo_query
= 1;
2875 use_threadextra_query
= 1;
2877 /* Ack any packet which the remote side has already sent. */
2878 serial_write (remote_desc
, "+", 1);
2880 /* The first packet we send to the target is the optional "supported
2881 packets" request. If the target can answer this, it will tell us
2882 which later probes to skip. */
2883 remote_query_supported ();
2885 /* Next, we possibly activate noack mode.
2887 If the QStartNoAckMode packet configuration is set to AUTO,
2888 enable noack mode if the stub reported a wish for it with
2891 If set to TRUE, then enable noack mode even if the stub didn't
2892 report it in qSupported. If the stub doesn't reply OK, the
2893 session ends with an error.
2895 If FALSE, then don't activate noack mode, regardless of what the
2896 stub claimed should be the default with qSupported. */
2898 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
2900 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
2901 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
2902 && noack_config
->support
== PACKET_ENABLE
))
2904 putpkt ("QStartNoAckMode");
2905 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2906 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
2910 /* Next, if the target can specify a description, read it. We do
2911 this before anything involving memory or registers. */
2912 target_find_description ();
2914 if (target_async_permitted
)
2916 /* With this target we start out by owning the terminal. */
2917 remote_async_terminal_ours_p
= 1;
2919 /* FIXME: cagney/1999-09-23: During the initial connection it is
2920 assumed that the target is already ready and able to respond to
2921 requests. Unfortunately remote_start_remote() eventually calls
2922 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2923 around this. Eventually a mechanism that allows
2924 wait_for_inferior() to expect/get timeouts will be
2926 wait_forever_enabled_p
= 0;
2929 /* First delete any symbols previously loaded from shared libraries. */
2930 no_shared_libraries (NULL
, 0);
2932 /* Start the remote connection. If error() or QUIT, discard this
2933 target (we'd otherwise be in an inconsistent state) and then
2934 propogate the error on up the exception chain. This ensures that
2935 the caller doesn't stumble along blindly assuming that the
2936 function succeeded. The CLI doesn't have this problem but other
2937 UI's, such as MI do.
2939 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
2940 this function should return an error indication letting the
2941 caller restore the previous state. Unfortunately the command
2942 ``target remote'' is directly wired to this function making that
2943 impossible. On a positive note, the CLI side of this problem has
2944 been fixed - the function set_cmd_context() makes it possible for
2945 all the ``target ....'' commands to share a common callback
2946 function. See cli-dump.c. */
2948 struct gdb_exception ex
;
2949 struct start_remote_args args
;
2951 args
.from_tty
= from_tty
;
2952 args
.target
= target
;
2953 args
.extended_p
= extended_p
;
2955 ex
= catch_exception (uiout
, remote_start_remote
, &args
, RETURN_MASK_ALL
);
2959 if (target_async_permitted
)
2960 wait_forever_enabled_p
= 1;
2961 throw_exception (ex
);
2965 if (target_async_permitted
)
2966 wait_forever_enabled_p
= 1;
2970 /* Tell the remote that we are using the extended protocol. */
2972 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2975 /* If we connected to a live target, do some additional setup. */
2976 if (target_has_execution
)
2978 if (exec_bfd
) /* No use without an exec file. */
2979 remote_check_symbols (symfile_objfile
);
2983 /* This takes a program previously attached to and detaches it. After
2984 this is done, GDB can be used to debug some other program. We
2985 better not have left any breakpoints in the target program or it'll
2986 die when it hits one. */
2989 remote_detach_1 (char *args
, int from_tty
, int extended
)
2991 int pid
= ptid_get_pid (inferior_ptid
);
2992 struct remote_state
*rs
= get_remote_state ();
2995 error (_("Argument given to \"detach\" when remotely debugging."));
2997 if (!target_has_execution
)
2998 error (_("No process to detach from."));
3000 /* Tell the remote target to detach. */
3001 if (remote_multi_process_p (rs
))
3002 sprintf (rs
->buf
, "D;%x", pid
);
3004 strcpy (rs
->buf
, "D");
3007 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3009 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
3011 else if (rs
->buf
[0] == '\0')
3012 error (_("Remote doesn't know how to detach"));
3014 error (_("Can't detach process."));
3016 /* Unregister the file descriptor from the event loop. */
3017 if (target_is_async_p ())
3018 serial_async (remote_desc
, NULL
, 0);
3022 if (remote_multi_process_p (rs
))
3023 printf_filtered (_("Detached from remote %s.\n"),
3024 target_pid_to_str (pid_to_ptid (pid
)));
3028 puts_filtered (_("Detached from remote process.\n"));
3030 puts_filtered (_("Ending remote debugging.\n"));
3034 detach_inferior (pid
);
3035 target_mourn_inferior ();
3039 remote_detach (char *args
, int from_tty
)
3041 remote_detach_1 (args
, from_tty
, 0);
3045 extended_remote_detach (char *args
, int from_tty
)
3047 remote_detach_1 (args
, from_tty
, 1);
3050 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
3053 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
3056 error (_("Argument given to \"disconnect\" when remotely debugging."));
3058 /* Unregister the file descriptor from the event loop. */
3059 if (target_is_async_p ())
3060 serial_async (remote_desc
, NULL
, 0);
3062 /* Make sure we unpush even the extended remote targets; mourn
3063 won't do it. So call remote_mourn_1 directly instead of
3064 target_mourn_inferior. */
3065 remote_mourn_1 (target
);
3068 puts_filtered ("Ending remote debugging.\n");
3071 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
3072 be chatty about it. */
3075 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
3077 struct remote_state
*rs
= get_remote_state ();
3080 char *wait_status
= NULL
;
3081 struct inferior
*inf
;
3084 error_no_arg (_("process-id to attach"));
3087 pid
= strtol (args
, &dummy
, 0);
3088 /* Some targets don't set errno on errors, grrr! */
3089 if (pid
== 0 && args
== dummy
)
3090 error (_("Illegal process-id: %s."), args
);
3092 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
3093 error (_("This target does not support attaching to a process"));
3095 sprintf (rs
->buf
, "vAttach;%x", pid
);
3097 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3099 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
3102 printf_unfiltered (_("Attached to %s\n"),
3103 target_pid_to_str (pid_to_ptid (pid
)));
3105 /* Save the reply for later. */
3106 wait_status
= alloca (strlen (rs
->buf
) + 1);
3107 strcpy (wait_status
, rs
->buf
);
3109 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
3110 error (_("This target does not support attaching to a process"));
3112 error (_("Attaching to %s failed"),
3113 target_pid_to_str (pid_to_ptid (pid
)));
3115 target_mark_running (target
);
3116 inferior_ptid
= pid_to_ptid (pid
);
3118 /* Now, if we have thread information, update inferior_ptid. */
3119 inferior_ptid
= remote_current_thread (inferior_ptid
);
3121 inf
= add_inferior (pid
);
3122 inf
->attach_flag
= 1;
3124 /* Now, add the main thread to the thread list. */
3125 add_thread_silent (inferior_ptid
);
3127 /* Next, if the target can specify a description, read it. We do
3128 this before anything involving memory or registers. */
3129 target_find_description ();
3131 /* Use the previously fetched status. */
3132 gdb_assert (wait_status
!= NULL
);
3133 strcpy (rs
->buf
, wait_status
);
3134 rs
->cached_wait_status
= 1;
3138 extended_remote_attach (char *args
, int from_tty
)
3140 extended_remote_attach_1 (&extended_remote_ops
, args
, from_tty
);
3143 /* Convert hex digit A to a number. */
3148 if (a
>= '0' && a
<= '9')
3150 else if (a
>= 'a' && a
<= 'f')
3151 return a
- 'a' + 10;
3152 else if (a
>= 'A' && a
<= 'F')
3153 return a
- 'A' + 10;
3155 error (_("Reply contains invalid hex digit %d"), a
);
3159 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
3163 for (i
= 0; i
< count
; i
++)
3165 if (hex
[0] == 0 || hex
[1] == 0)
3167 /* Hex string is short, or of uneven length.
3168 Return the count that has been converted so far. */
3171 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
3177 /* Convert number NIB to a hex digit. */
3185 return 'a' + nib
- 10;
3189 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
3192 /* May use a length, or a nul-terminated string as input. */
3194 count
= strlen ((char *) bin
);
3196 for (i
= 0; i
< count
; i
++)
3198 *hex
++ = tohex ((*bin
>> 4) & 0xf);
3199 *hex
++ = tohex (*bin
++ & 0xf);
3205 /* Check for the availability of vCont. This function should also check
3209 remote_vcont_probe (struct remote_state
*rs
)
3213 strcpy (rs
->buf
, "vCont?");
3215 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3218 /* Make sure that the features we assume are supported. */
3219 if (strncmp (buf
, "vCont", 5) == 0)
3222 int support_s
, support_S
, support_c
, support_C
;
3228 while (p
&& *p
== ';')
3231 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
3233 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
3235 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
3237 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
3240 p
= strchr (p
, ';');
3243 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
3244 BUF will make packet_ok disable the packet. */
3245 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
3249 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
3252 /* Resume the remote inferior by using a "vCont" packet. The thread
3253 to be resumed is PTID; STEP and SIGGNAL indicate whether the
3254 resumed thread should be single-stepped and/or signalled. If PTID
3255 equals minus_one_ptid, then all threads are resumed; the thread to
3256 be stepped and/or signalled is given in the global INFERIOR_PTID.
3257 This function returns non-zero iff it resumes the inferior.
3259 This function issues a strict subset of all possible vCont commands at the
3263 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
3265 struct remote_state
*rs
= get_remote_state ();
3269 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
3270 remote_vcont_probe (rs
);
3272 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
3276 endp
= rs
->buf
+ get_remote_packet_size ();
3278 /* If we could generate a wider range of packets, we'd have to worry
3279 about overflowing BUF. Should there be a generic
3280 "multi-part-packet" packet? */
3282 if (ptid_equal (ptid
, magic_null_ptid
))
3284 /* MAGIC_NULL_PTID means that we don't have any active threads,
3285 so we don't have any TID numbers the inferior will
3286 understand. Make sure to only send forms that do not specify
3288 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
3289 xsnprintf (p
, endp
- p
, "vCont;S%02x", siggnal
);
3291 xsnprintf (p
, endp
- p
, "vCont;s");
3292 else if (siggnal
!= TARGET_SIGNAL_0
)
3293 xsnprintf (p
, endp
- p
, "vCont;C%02x", siggnal
);
3295 xsnprintf (p
, endp
- p
, "vCont;c");
3297 else if (ptid_equal (ptid
, minus_one_ptid
))
3299 /* Resume all threads, with preference for INFERIOR_PTID. */
3300 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
3302 /* Step inferior_ptid with signal. */
3303 p
+= xsnprintf (p
, endp
- p
, "vCont;S%02x:", siggnal
);
3304 p
= write_ptid (p
, endp
, inferior_ptid
);
3305 /* And continue others. */
3306 p
+= xsnprintf (p
, endp
- p
, ";c");
3310 /* Step inferior_ptid. */
3311 p
+= xsnprintf (p
, endp
- p
, "vCont;s:");
3312 p
= write_ptid (p
, endp
, inferior_ptid
);
3313 /* And continue others. */
3314 p
+= xsnprintf (p
, endp
- p
, ";c");
3316 else if (siggnal
!= TARGET_SIGNAL_0
)
3318 /* Continue inferior_ptid with signal. */
3319 p
+= xsnprintf (p
, endp
- p
, "vCont;C%02x:", siggnal
);
3320 p
= write_ptid (p
, endp
, inferior_ptid
);
3321 /* And continue others. */
3322 p
+= xsnprintf (p
, endp
- p
, ";c");
3325 xsnprintf (p
, endp
- p
, "vCont;c");
3329 /* Scheduler locking; resume only PTID. */
3330 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
3332 /* Step ptid with signal. */
3333 p
+= xsnprintf (p
, endp
- p
, "vCont;S%02x:", siggnal
);
3334 p
= write_ptid (p
, endp
, ptid
);
3339 p
+= xsnprintf (p
, endp
- p
, "vCont;s:");
3340 p
= write_ptid (p
, endp
, ptid
);
3342 else if (siggnal
!= TARGET_SIGNAL_0
)
3344 /* Continue ptid with signal. */
3345 p
+= xsnprintf (p
, endp
- p
, "vCont;C%02x:", siggnal
);
3346 p
= write_ptid (p
, endp
, ptid
);
3350 /* Continue ptid. */
3351 p
+= xsnprintf (p
, endp
- p
, "vCont;c:");
3352 p
= write_ptid (p
, endp
, ptid
);
3356 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
3362 /* Tell the remote machine to resume. */
3364 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
3366 static int last_sent_step
;
3369 remote_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
3371 struct remote_state
*rs
= get_remote_state ();
3374 last_sent_signal
= siggnal
;
3375 last_sent_step
= step
;
3377 /* Update the inferior on signals to silently pass, if they've changed. */
3378 remote_pass_signals ();
3380 /* The vCont packet doesn't need to specify threads via Hc. */
3381 if (remote_vcont_resume (ptid
, step
, siggnal
))
3384 /* All other supported resume packets do use Hc, so set the continue
3386 if (ptid_equal (ptid
, minus_one_ptid
))
3387 set_continue_thread (any_thread_ptid
);
3389 set_continue_thread (ptid
);
3392 if (siggnal
!= TARGET_SIGNAL_0
)
3394 buf
[0] = step
? 'S' : 'C';
3395 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
3396 buf
[2] = tohex (((int) siggnal
) & 0xf);
3400 strcpy (buf
, step
? "s" : "c");
3405 /* We are about to start executing the inferior, let's register it
3406 with the event loop. NOTE: this is the one place where all the
3407 execution commands end up. We could alternatively do this in each
3408 of the execution commands in infcmd.c. */
3409 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
3410 into infcmd.c in order to allow inferior function calls to work
3411 NOT asynchronously. */
3412 if (target_can_async_p ())
3413 target_async (inferior_event_handler
, 0);
3417 /* Set up the signal handler for SIGINT, while the target is
3418 executing, ovewriting the 'regular' SIGINT signal handler. */
3420 initialize_sigint_signal_handler (void)
3422 signal (SIGINT
, handle_remote_sigint
);
3425 /* Signal handler for SIGINT, while the target is executing. */
3427 handle_remote_sigint (int sig
)
3429 signal (sig
, handle_remote_sigint_twice
);
3430 mark_async_signal_handler_wrapper (sigint_remote_token
);
3433 /* Signal handler for SIGINT, installed after SIGINT has already been
3434 sent once. It will take effect the second time that the user sends
3437 handle_remote_sigint_twice (int sig
)
3439 signal (sig
, handle_remote_sigint
);
3440 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
3443 /* Perform the real interruption of the target execution, in response
3446 async_remote_interrupt (gdb_client_data arg
)
3449 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
3451 target_stop (inferior_ptid
);
3454 /* Perform interrupt, if the first attempt did not succeed. Just give
3455 up on the target alltogether. */
3457 async_remote_interrupt_twice (gdb_client_data arg
)
3460 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
3465 /* Reinstall the usual SIGINT handlers, after the target has
3468 cleanup_sigint_signal_handler (void *dummy
)
3470 signal (SIGINT
, handle_sigint
);
3473 /* Send ^C to target to halt it. Target will respond, and send us a
3475 static void (*ofunc
) (int);
3477 /* The command line interface's stop routine. This function is installed
3478 as a signal handler for SIGINT. The first time a user requests a
3479 stop, we call remote_stop to send a break or ^C. If there is no
3480 response from the target (it didn't stop when the user requested it),
3481 we ask the user if he'd like to detach from the target. */
3483 remote_interrupt (int signo
)
3485 /* If this doesn't work, try more severe steps. */
3486 signal (signo
, remote_interrupt_twice
);
3488 gdb_call_async_signal_handler (sigint_remote_token
, 1);
3491 /* The user typed ^C twice. */
3494 remote_interrupt_twice (int signo
)
3496 signal (signo
, ofunc
);
3497 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
3498 signal (signo
, remote_interrupt
);
3501 /* This is the generic stop called via the target vector. When a target
3502 interrupt is requested, either by the command line or the GUI, we
3503 will eventually end up here. */
3505 remote_stop (ptid_t ptid
)
3507 /* Send a break or a ^C, depending on user preference. */
3509 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
3512 serial_send_break (remote_desc
);
3514 serial_write (remote_desc
, "\003", 1);
3517 /* Ask the user what to do when an interrupt is received. */
3520 interrupt_query (void)
3522 target_terminal_ours ();
3524 if (query ("Interrupted while waiting for the program.\n\
3525 Give up (and stop debugging it)? "))
3527 target_mourn_inferior ();
3528 signal (SIGINT
, handle_sigint
);
3529 deprecated_throw_reason (RETURN_QUIT
);
3532 target_terminal_inferior ();
3535 /* Enable/disable target terminal ownership. Most targets can use
3536 terminal groups to control terminal ownership. Remote targets are
3537 different in that explicit transfer of ownership to/from GDB/target
3541 remote_terminal_inferior (void)
3543 if (!target_async_permitted
)
3544 /* Nothing to do. */
3547 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
3548 sync_execution here. This function should only be called when
3549 GDB is resuming the inferior in the forground. A background
3550 resume (``run&'') should leave GDB in control of the terminal and
3551 consequently should not call this code. */
3552 if (!sync_execution
)
3554 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
3555 calls target_terminal_*() idenpotent. The event-loop GDB talking
3556 to an asynchronous target with a synchronous command calls this
3557 function from both event-top.c and infrun.c/infcmd.c. Once GDB
3558 stops trying to transfer the terminal to the target when it
3559 shouldn't this guard can go away. */
3560 if (!remote_async_terminal_ours_p
)
3562 delete_file_handler (input_fd
);
3563 remote_async_terminal_ours_p
= 0;
3564 initialize_sigint_signal_handler ();
3565 /* NOTE: At this point we could also register our selves as the
3566 recipient of all input. Any characters typed could then be
3567 passed on down to the target. */
3571 remote_terminal_ours (void)
3573 if (!target_async_permitted
)
3574 /* Nothing to do. */
3577 /* See FIXME in remote_terminal_inferior. */
3578 if (!sync_execution
)
3580 /* See FIXME in remote_terminal_inferior. */
3581 if (remote_async_terminal_ours_p
)
3583 cleanup_sigint_signal_handler (NULL
);
3584 add_file_handler (input_fd
, stdin_event_handler
, 0);
3585 remote_async_terminal_ours_p
= 1;
3589 remote_console_output (char *msg
)
3593 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
3596 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
3599 fputs_unfiltered (tb
, gdb_stdtarg
);
3601 gdb_flush (gdb_stdtarg
);
3604 /* Wait until the remote machine stops, then return,
3605 storing status in STATUS just as `wait' would. */
3608 remote_wait (ptid_t ptid
, struct target_waitstatus
*status
)
3610 struct remote_state
*rs
= get_remote_state ();
3611 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3612 ptid_t event_ptid
= null_ptid
;
3614 int solibs_changed
= 0;
3616 status
->kind
= TARGET_WAITKIND_EXITED
;
3617 status
->value
.integer
= 0;
3623 if (rs
->cached_wait_status
)
3624 /* Use the cached wait status, but only once. */
3625 rs
->cached_wait_status
= 0;
3628 if (!target_is_async_p ())
3630 ofunc
= signal (SIGINT
, remote_interrupt
);
3631 /* If the user hit C-c before this packet, or between packets,
3632 pretend that it was hit right here. */
3636 remote_interrupt (SIGINT
);
3639 /* FIXME: cagney/1999-09-27: If we're in async mode we should
3640 _never_ wait for ever -> test on target_is_async_p().
3641 However, before we do that we need to ensure that the caller
3642 knows how to take the target into/out of async mode. */
3643 getpkt (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
3644 if (!target_is_async_p ())
3645 signal (SIGINT
, ofunc
);
3650 remote_stopped_by_watchpoint_p
= 0;
3654 case 'E': /* Error of some sort. */
3655 /* We're out of sync with the target now. Did it continue or not?
3656 Not is more likely, so report a stop. */
3657 warning (_("Remote failure reply: %s"), buf
);
3658 status
->kind
= TARGET_WAITKIND_STOPPED
;
3659 status
->value
.sig
= TARGET_SIGNAL_0
;
3661 case 'F': /* File-I/O request. */
3662 remote_fileio_request (buf
);
3664 case 'T': /* Status with PC, SP, FP, ... */
3666 gdb_byte regs
[MAX_REGISTER_SIZE
];
3668 /* Expedited reply, containing Signal, {regno, reg} repeat. */
3669 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
3671 n... = register number
3672 r... = register contents
3674 p
= &buf
[3]; /* after Txx */
3683 /* If the packet contains a register number, save it
3684 in pnum and set p1 to point to the character
3685 following it. Otherwise p1 points to p. */
3687 /* If this packet is an awatch packet, don't parse the
3688 'a' as a register number. */
3690 if (strncmp (p
, "awatch", strlen("awatch")) != 0)
3692 /* Read the ``P'' register number. */
3693 pnum
= strtol (p
, &p_temp
, 16);
3699 if (p1
== p
) /* No register number present here. */
3701 p1
= strchr (p
, ':');
3703 error (_("Malformed packet(a) (missing colon): %s\n\
3706 if (strncmp (p
, "thread", p1
- p
) == 0)
3707 event_ptid
= read_ptid (++p1
, &p
);
3708 else if ((strncmp (p
, "watch", p1
- p
) == 0)
3709 || (strncmp (p
, "rwatch", p1
- p
) == 0)
3710 || (strncmp (p
, "awatch", p1
- p
) == 0))
3712 remote_stopped_by_watchpoint_p
= 1;
3713 p
= unpack_varlen_hex (++p1
, &addr
);
3714 remote_watch_data_address
= (CORE_ADDR
)addr
;
3716 else if (strncmp (p
, "library", p1
- p
) == 0)
3720 while (*p_temp
&& *p_temp
!= ';')
3728 /* Silently skip unknown optional info. */
3729 p_temp
= strchr (p1
+ 1, ';');
3736 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
3740 error (_("Malformed packet(b) (missing colon): %s\n\
3746 error (_("Remote sent bad register number %s: %s\n\
3748 phex_nz (pnum
, 0), p
, buf
);
3750 fieldsize
= hex2bin (p
, regs
,
3751 register_size (target_gdbarch
,
3754 if (fieldsize
< register_size (target_gdbarch
,
3756 warning (_("Remote reply is too short: %s"), buf
);
3757 regcache_raw_supply (get_current_regcache (),
3762 error (_("Remote register badly formatted: %s\nhere: %s"),
3768 case 'S': /* Old style status, just signal only. */
3770 status
->kind
= TARGET_WAITKIND_LOADED
;
3773 status
->kind
= TARGET_WAITKIND_STOPPED
;
3774 status
->value
.sig
= (enum target_signal
)
3775 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
3778 case 'W': /* Target exited. */
3785 /* GDB used to accept only 2 hex chars here. Stubs should
3786 only send more if they detect GDB supports
3787 multi-process support. */
3788 p
= unpack_varlen_hex (&buf
[1], &value
);
3792 /* The remote process exited. */
3793 status
->kind
= TARGET_WAITKIND_EXITED
;
3794 status
->value
.integer
= value
;
3798 /* The remote process exited with a signal. */
3799 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
3800 status
->value
.sig
= (enum target_signal
) value
;
3803 /* If no process is specified, assume inferior_ptid. */
3804 pid
= ptid_get_pid (inferior_ptid
);
3813 else if (strncmp (p
,
3814 "process:", sizeof ("process:") - 1) == 0)
3817 p
+= sizeof ("process:") - 1;
3818 unpack_varlen_hex (p
, &upid
);
3822 error (_("unknown stop reply packet: %s"), buf
);
3825 error (_("unknown stop reply packet: %s"), buf
);
3826 event_ptid
= ptid_build (pid
, 0, 0);
3829 case 'O': /* Console output. */
3830 remote_console_output (buf
+ 1);
3831 if (target_can_async_p ())
3833 /* Return immediately to the event loop. The event loop
3834 will still be waiting on the inferior afterwards. */
3835 status
->kind
= TARGET_WAITKIND_IGNORE
;
3841 if (last_sent_signal
!= TARGET_SIGNAL_0
)
3843 /* Zero length reply means that we tried 'S' or 'C' and
3844 the remote system doesn't support it. */
3845 target_terminal_ours_for_output ();
3847 ("Can't send signals to this remote system. %s not sent.\n",
3848 target_signal_to_name (last_sent_signal
));
3849 last_sent_signal
= TARGET_SIGNAL_0
;
3850 target_terminal_inferior ();
3852 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
3853 putpkt ((char *) buf
);
3856 /* else fallthrough */
3858 warning (_("Invalid remote reply: %s"), buf
);
3863 if (status
->kind
== TARGET_WAITKIND_EXITED
3864 || status
->kind
== TARGET_WAITKIND_SIGNALLED
)
3866 int pid
= ptid_get_pid (event_ptid
);
3867 delete_inferior (pid
);
3871 if (!ptid_equal (event_ptid
, null_ptid
))
3872 record_currthread (event_ptid
);
3874 event_ptid
= inferior_ptid
;
3880 /* Fetch a single register using a 'p' packet. */
3883 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
3885 struct remote_state
*rs
= get_remote_state ();
3887 char regp
[MAX_REGISTER_SIZE
];
3890 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
3893 if (reg
->pnum
== -1)
3898 p
+= hexnumstr (p
, reg
->pnum
);
3900 remote_send (&rs
->buf
, &rs
->buf_size
);
3904 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
3908 case PACKET_UNKNOWN
:
3911 error (_("Could not fetch register \"%s\""),
3912 gdbarch_register_name (get_regcache_arch (regcache
), reg
->regnum
));
3915 /* If this register is unfetchable, tell the regcache. */
3918 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
3922 /* Otherwise, parse and supply the value. */
3928 error (_("fetch_register_using_p: early buf termination"));
3930 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
3933 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
3937 /* Fetch the registers included in the target's 'g' packet. */
3940 send_g_packet (void)
3942 struct remote_state
*rs
= get_remote_state ();
3947 sprintf (rs
->buf
, "g");
3948 remote_send (&rs
->buf
, &rs
->buf_size
);
3950 /* We can get out of synch in various cases. If the first character
3951 in the buffer is not a hex character, assume that has happened
3952 and try to fetch another packet to read. */
3953 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
3954 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
3955 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
3956 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
3959 fprintf_unfiltered (gdb_stdlog
,
3960 "Bad register packet; fetching a new packet\n");
3961 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3964 buf_len
= strlen (rs
->buf
);
3966 /* Sanity check the received packet. */
3967 if (buf_len
% 2 != 0)
3968 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
3974 process_g_packet (struct regcache
*regcache
)
3976 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3977 struct remote_state
*rs
= get_remote_state ();
3978 struct remote_arch_state
*rsa
= get_remote_arch_state ();
3983 buf_len
= strlen (rs
->buf
);
3985 /* Further sanity checks, with knowledge of the architecture. */
3986 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
3987 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
3989 /* Save the size of the packet sent to us by the target. It is used
3990 as a heuristic when determining the max size of packets that the
3991 target can safely receive. */
3992 if (rsa
->actual_register_packet_size
== 0)
3993 rsa
->actual_register_packet_size
= buf_len
;
3995 /* If this is smaller than we guessed the 'g' packet would be,
3996 update our records. A 'g' reply that doesn't include a register's
3997 value implies either that the register is not available, or that
3998 the 'p' packet must be used. */
3999 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
4001 rsa
->sizeof_g_packet
= buf_len
/ 2;
4003 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
4005 if (rsa
->regs
[i
].pnum
== -1)
4008 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
4009 rsa
->regs
[i
].in_g_packet
= 0;
4011 rsa
->regs
[i
].in_g_packet
= 1;
4015 regs
= alloca (rsa
->sizeof_g_packet
);
4017 /* Unimplemented registers read as all bits zero. */
4018 memset (regs
, 0, rsa
->sizeof_g_packet
);
4020 /* Reply describes registers byte by byte, each byte encoded as two
4021 hex characters. Suck them all up, then supply them to the
4022 register cacheing/storage mechanism. */
4025 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
4027 if (p
[0] == 0 || p
[1] == 0)
4028 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
4029 internal_error (__FILE__
, __LINE__
,
4030 "unexpected end of 'g' packet reply");
4032 if (p
[0] == 'x' && p
[1] == 'x')
4033 regs
[i
] = 0; /* 'x' */
4035 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
4041 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
4043 struct packet_reg
*r
= &rsa
->regs
[i
];
4046 if (r
->offset
* 2 >= strlen (rs
->buf
))
4047 /* This shouldn't happen - we adjusted in_g_packet above. */
4048 internal_error (__FILE__
, __LINE__
,
4049 "unexpected end of 'g' packet reply");
4050 else if (rs
->buf
[r
->offset
* 2] == 'x')
4052 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
4053 /* The register isn't available, mark it as such (at
4054 the same time setting the value to zero). */
4055 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
4058 regcache_raw_supply (regcache
, r
->regnum
,
4066 fetch_registers_using_g (struct regcache
*regcache
)
4069 process_g_packet (regcache
);
4073 remote_fetch_registers (struct regcache
*regcache
, int regnum
)
4075 struct remote_state
*rs
= get_remote_state ();
4076 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4079 set_general_thread (inferior_ptid
);
4083 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
4084 gdb_assert (reg
!= NULL
);
4086 /* If this register might be in the 'g' packet, try that first -
4087 we are likely to read more than one register. If this is the
4088 first 'g' packet, we might be overly optimistic about its
4089 contents, so fall back to 'p'. */
4090 if (reg
->in_g_packet
)
4092 fetch_registers_using_g (regcache
);
4093 if (reg
->in_g_packet
)
4097 if (fetch_register_using_p (regcache
, reg
))
4100 /* This register is not available. */
4101 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
4106 fetch_registers_using_g (regcache
);
4108 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
4109 if (!rsa
->regs
[i
].in_g_packet
)
4110 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
4112 /* This register is not available. */
4113 regcache_raw_supply (regcache
, i
, NULL
);
4117 /* Prepare to store registers. Since we may send them all (using a
4118 'G' request), we have to read out the ones we don't want to change
4122 remote_prepare_to_store (struct regcache
*regcache
)
4124 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4126 gdb_byte buf
[MAX_REGISTER_SIZE
];
4128 /* Make sure the entire registers array is valid. */
4129 switch (remote_protocol_packets
[PACKET_P
].support
)
4131 case PACKET_DISABLE
:
4132 case PACKET_SUPPORT_UNKNOWN
:
4133 /* Make sure all the necessary registers are cached. */
4134 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
4135 if (rsa
->regs
[i
].in_g_packet
)
4136 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
4143 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
4144 packet was not recognized. */
4147 store_register_using_P (const struct regcache
*regcache
, struct packet_reg
*reg
)
4149 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
4150 struct remote_state
*rs
= get_remote_state ();
4151 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4152 /* Try storing a single register. */
4153 char *buf
= rs
->buf
;
4154 gdb_byte regp
[MAX_REGISTER_SIZE
];
4157 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
4160 if (reg
->pnum
== -1)
4163 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
4164 p
= buf
+ strlen (buf
);
4165 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
4166 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
4167 remote_send (&rs
->buf
, &rs
->buf_size
);
4169 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
4174 error (_("Could not write register \"%s\""),
4175 gdbarch_register_name (gdbarch
, reg
->regnum
));
4176 case PACKET_UNKNOWN
:
4179 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
4183 /* Store register REGNUM, or all registers if REGNUM == -1, from the
4184 contents of the register cache buffer. FIXME: ignores errors. */
4187 store_registers_using_G (const struct regcache
*regcache
)
4189 struct remote_state
*rs
= get_remote_state ();
4190 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4194 /* Extract all the registers in the regcache copying them into a
4198 regs
= alloca (rsa
->sizeof_g_packet
);
4199 memset (regs
, 0, rsa
->sizeof_g_packet
);
4200 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
4202 struct packet_reg
*r
= &rsa
->regs
[i
];
4204 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
4208 /* Command describes registers byte by byte,
4209 each byte encoded as two hex characters. */
4212 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
4214 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
4215 remote_send (&rs
->buf
, &rs
->buf_size
);
4218 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
4219 of the register cache buffer. FIXME: ignores errors. */
4222 remote_store_registers (struct regcache
*regcache
, int regnum
)
4224 struct remote_state
*rs
= get_remote_state ();
4225 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4228 set_general_thread (inferior_ptid
);
4232 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
4233 gdb_assert (reg
!= NULL
);
4235 /* Always prefer to store registers using the 'P' packet if
4236 possible; we often change only a small number of registers.
4237 Sometimes we change a larger number; we'd need help from a
4238 higher layer to know to use 'G'. */
4239 if (store_register_using_P (regcache
, reg
))
4242 /* For now, don't complain if we have no way to write the
4243 register. GDB loses track of unavailable registers too
4244 easily. Some day, this may be an error. We don't have
4245 any way to read the register, either... */
4246 if (!reg
->in_g_packet
)
4249 store_registers_using_G (regcache
);
4253 store_registers_using_G (regcache
);
4255 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
4256 if (!rsa
->regs
[i
].in_g_packet
)
4257 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
4258 /* See above for why we do not issue an error here. */
4263 /* Return the number of hex digits in num. */
4266 hexnumlen (ULONGEST num
)
4270 for (i
= 0; num
!= 0; i
++)
4276 /* Set BUF to the minimum number of hex digits representing NUM. */
4279 hexnumstr (char *buf
, ULONGEST num
)
4281 int len
= hexnumlen (num
);
4282 return hexnumnstr (buf
, num
, len
);
4286 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
4289 hexnumnstr (char *buf
, ULONGEST num
, int width
)
4295 for (i
= width
- 1; i
>= 0; i
--)
4297 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
4304 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
4307 remote_address_masked (CORE_ADDR addr
)
4309 int address_size
= remote_address_size
;
4310 /* If "remoteaddresssize" was not set, default to target address size. */
4312 address_size
= gdbarch_addr_bit (target_gdbarch
);
4314 if (address_size
> 0
4315 && address_size
< (sizeof (ULONGEST
) * 8))
4317 /* Only create a mask when that mask can safely be constructed
4318 in a ULONGEST variable. */
4320 mask
= (mask
<< address_size
) - 1;
4326 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
4327 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
4328 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
4329 (which may be more than *OUT_LEN due to escape characters). The
4330 total number of bytes in the output buffer will be at most
4334 remote_escape_output (const gdb_byte
*buffer
, int len
,
4335 gdb_byte
*out_buf
, int *out_len
,
4338 int input_index
, output_index
;
4341 for (input_index
= 0; input_index
< len
; input_index
++)
4343 gdb_byte b
= buffer
[input_index
];
4345 if (b
== '$' || b
== '#' || b
== '}')
4347 /* These must be escaped. */
4348 if (output_index
+ 2 > out_maxlen
)
4350 out_buf
[output_index
++] = '}';
4351 out_buf
[output_index
++] = b
^ 0x20;
4355 if (output_index
+ 1 > out_maxlen
)
4357 out_buf
[output_index
++] = b
;
4361 *out_len
= input_index
;
4362 return output_index
;
4365 /* Convert BUFFER, escaped data LEN bytes long, into binary data
4366 in OUT_BUF. Return the number of bytes written to OUT_BUF.
4367 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
4369 This function reverses remote_escape_output. It allows more
4370 escaped characters than that function does, in particular because
4371 '*' must be escaped to avoid the run-length encoding processing
4372 in reading packets. */
4375 remote_unescape_input (const gdb_byte
*buffer
, int len
,
4376 gdb_byte
*out_buf
, int out_maxlen
)
4378 int input_index
, output_index
;
4383 for (input_index
= 0; input_index
< len
; input_index
++)
4385 gdb_byte b
= buffer
[input_index
];
4387 if (output_index
+ 1 > out_maxlen
)
4389 warning (_("Received too much data from remote target;"
4390 " ignoring overflow."));
4391 return output_index
;
4396 out_buf
[output_index
++] = b
^ 0x20;
4402 out_buf
[output_index
++] = b
;
4406 error (_("Unmatched escape character in target response."));
4408 return output_index
;
4411 /* Determine whether the remote target supports binary downloading.
4412 This is accomplished by sending a no-op memory write of zero length
4413 to the target at the specified address. It does not suffice to send
4414 the whole packet, since many stubs strip the eighth bit and
4415 subsequently compute a wrong checksum, which causes real havoc with
4418 NOTE: This can still lose if the serial line is not eight-bit
4419 clean. In cases like this, the user should clear "remote
4423 check_binary_download (CORE_ADDR addr
)
4425 struct remote_state
*rs
= get_remote_state ();
4427 switch (remote_protocol_packets
[PACKET_X
].support
)
4429 case PACKET_DISABLE
:
4433 case PACKET_SUPPORT_UNKNOWN
:
4439 p
+= hexnumstr (p
, (ULONGEST
) addr
);
4441 p
+= hexnumstr (p
, (ULONGEST
) 0);
4445 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
4446 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4448 if (rs
->buf
[0] == '\0')
4451 fprintf_unfiltered (gdb_stdlog
,
4452 "binary downloading NOT suppported by target\n");
4453 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
4458 fprintf_unfiltered (gdb_stdlog
,
4459 "binary downloading suppported by target\n");
4460 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
4467 /* Write memory data directly to the remote machine.
4468 This does not inform the data cache; the data cache uses this.
4469 HEADER is the starting part of the packet.
4470 MEMADDR is the address in the remote memory space.
4471 MYADDR is the address of the buffer in our space.
4472 LEN is the number of bytes.
4473 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
4474 should send data as binary ('X'), or hex-encoded ('M').
4476 The function creates packet of the form
4477 <HEADER><ADDRESS>,<LENGTH>:<DATA>
4479 where encoding of <DATA> is termined by PACKET_FORMAT.
4481 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
4484 Returns the number of bytes transferred, or 0 (setting errno) for
4485 error. Only transfer a single packet. */
4488 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
4489 const gdb_byte
*myaddr
, int len
,
4490 char packet_format
, int use_length
)
4492 struct remote_state
*rs
= get_remote_state ();
4502 if (packet_format
!= 'X' && packet_format
!= 'M')
4503 internal_error (__FILE__
, __LINE__
,
4504 "remote_write_bytes_aux: bad packet format");
4509 payload_size
= get_memory_write_packet_size ();
4511 /* The packet buffer will be large enough for the payload;
4512 get_memory_packet_size ensures this. */
4515 /* Compute the size of the actual payload by subtracting out the
4516 packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
4518 payload_size
-= strlen ("$,:#NN");
4520 /* The comma won't be used. */
4522 header_length
= strlen (header
);
4523 payload_size
-= header_length
;
4524 payload_size
-= hexnumlen (memaddr
);
4526 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
4528 strcat (rs
->buf
, header
);
4529 p
= rs
->buf
+ strlen (header
);
4531 /* Compute a best guess of the number of bytes actually transfered. */
4532 if (packet_format
== 'X')
4534 /* Best guess at number of bytes that will fit. */
4535 todo
= min (len
, payload_size
);
4537 payload_size
-= hexnumlen (todo
);
4538 todo
= min (todo
, payload_size
);
4542 /* Num bytes that will fit. */
4543 todo
= min (len
, payload_size
/ 2);
4545 payload_size
-= hexnumlen (todo
);
4546 todo
= min (todo
, payload_size
/ 2);
4550 internal_error (__FILE__
, __LINE__
,
4551 _("minumum packet size too small to write data"));
4553 /* If we already need another packet, then try to align the end
4554 of this packet to a useful boundary. */
4555 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
4556 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
4558 /* Append "<memaddr>". */
4559 memaddr
= remote_address_masked (memaddr
);
4560 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
4567 /* Append <len>. Retain the location/size of <len>. It may need to
4568 be adjusted once the packet body has been created. */
4570 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
4578 /* Append the packet body. */
4579 if (packet_format
== 'X')
4581 /* Binary mode. Send target system values byte by byte, in
4582 increasing byte addresses. Only escape certain critical
4584 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
4587 /* If not all TODO bytes fit, then we'll need another packet. Make
4588 a second try to keep the end of the packet aligned. Don't do
4589 this if the packet is tiny. */
4590 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
4594 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
4596 if (new_nr_bytes
!= nr_bytes
)
4597 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
4602 p
+= payload_length
;
4603 if (use_length
&& nr_bytes
< todo
)
4605 /* Escape chars have filled up the buffer prematurely,
4606 and we have actually sent fewer bytes than planned.
4607 Fix-up the length field of the packet. Use the same
4608 number of characters as before. */
4609 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
4610 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
4615 /* Normal mode: Send target system values byte by byte, in
4616 increasing byte addresses. Each byte is encoded as a two hex
4618 nr_bytes
= bin2hex (myaddr
, p
, todo
);
4622 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
4623 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4625 if (rs
->buf
[0] == 'E')
4627 /* There is no correspondance between what the remote protocol
4628 uses for errors and errno codes. We would like a cleaner way
4629 of representing errors (big enough to include errno codes,
4630 bfd_error codes, and others). But for now just return EIO. */
4635 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
4636 fewer bytes than we'd planned. */
4640 /* Write memory data directly to the remote machine.
4641 This does not inform the data cache; the data cache uses this.
4642 MEMADDR is the address in the remote memory space.
4643 MYADDR is the address of the buffer in our space.
4644 LEN is the number of bytes.
4646 Returns number of bytes transferred, or 0 (setting errno) for
4647 error. Only transfer a single packet. */
4650 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
4652 char *packet_format
= 0;
4654 /* Check whether the target supports binary download. */
4655 check_binary_download (memaddr
);
4657 switch (remote_protocol_packets
[PACKET_X
].support
)
4660 packet_format
= "X";
4662 case PACKET_DISABLE
:
4663 packet_format
= "M";
4665 case PACKET_SUPPORT_UNKNOWN
:
4666 internal_error (__FILE__
, __LINE__
,
4667 _("remote_write_bytes: bad internal state"));
4669 internal_error (__FILE__
, __LINE__
, _("bad switch"));
4672 return remote_write_bytes_aux (packet_format
,
4673 memaddr
, myaddr
, len
, packet_format
[0], 1);
4676 /* Read memory data directly from the remote machine.
4677 This does not use the data cache; the data cache uses this.
4678 MEMADDR is the address in the remote memory space.
4679 MYADDR is the address of the buffer in our space.
4680 LEN is the number of bytes.
4682 Returns number of bytes transferred, or 0 for error. */
4684 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
4685 remote targets) shouldn't attempt to read the entire buffer.
4686 Instead it should read a single packet worth of data and then
4687 return the byte size of that packet to the caller. The caller (its
4688 caller and its callers caller ;-) already contains code for
4689 handling partial reads. */
4692 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
4694 struct remote_state
*rs
= get_remote_state ();
4695 int max_buf_size
; /* Max size of packet output buffer. */
4701 max_buf_size
= get_memory_read_packet_size ();
4702 /* The packet buffer will be large enough for the payload;
4703 get_memory_packet_size ensures this. */
4712 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
4714 /* construct "m"<memaddr>","<len>" */
4715 /* sprintf (rs->buf, "m%lx,%x", (unsigned long) memaddr, todo); */
4716 memaddr
= remote_address_masked (memaddr
);
4719 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
4721 p
+= hexnumstr (p
, (ULONGEST
) todo
);
4725 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4727 if (rs
->buf
[0] == 'E'
4728 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
4729 && rs
->buf
[3] == '\0')
4731 /* There is no correspondance between what the remote
4732 protocol uses for errors and errno codes. We would like
4733 a cleaner way of representing errors (big enough to
4734 include errno codes, bfd_error codes, and others). But
4735 for now just return EIO. */
4740 /* Reply describes memory byte by byte,
4741 each byte encoded as two hex characters. */
4744 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
4746 /* Reply is short. This means that we were able to read
4747 only part of what we wanted to. */
4748 return i
+ (origlen
- len
);
4757 /* Read or write LEN bytes from inferior memory at MEMADDR,
4758 transferring to or from debugger address BUFFER. Write to inferior
4759 if SHOULD_WRITE is nonzero. Returns length of data written or
4760 read; 0 for error. TARGET is unused. */
4763 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
4764 int should_write
, struct mem_attrib
*attrib
,
4765 struct target_ops
*target
)
4769 set_general_thread (inferior_ptid
);
4772 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
4774 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
4779 /* Sends a packet with content determined by the printf format string
4780 FORMAT and the remaining arguments, then gets the reply. Returns
4781 whether the packet was a success, a failure, or unknown. */
4784 remote_send_printf (const char *format
, ...)
4786 struct remote_state
*rs
= get_remote_state ();
4787 int max_size
= get_remote_packet_size ();
4790 va_start (ap
, format
);
4793 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
4794 internal_error (__FILE__
, __LINE__
, "Too long remote packet.");
4796 if (putpkt (rs
->buf
) < 0)
4797 error (_("Communication problem with target."));
4800 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4802 return packet_check_result (rs
->buf
);
4806 restore_remote_timeout (void *p
)
4808 int value
= *(int *)p
;
4809 remote_timeout
= value
;
4812 /* Flash writing can take quite some time. We'll set
4813 effectively infinite timeout for flash operations.
4814 In future, we'll need to decide on a better approach. */
4815 static const int remote_flash_timeout
= 1000;
4818 remote_flash_erase (struct target_ops
*ops
,
4819 ULONGEST address
, LONGEST length
)
4821 int saved_remote_timeout
= remote_timeout
;
4822 enum packet_result ret
;
4824 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
4825 &saved_remote_timeout
);
4826 remote_timeout
= remote_flash_timeout
;
4828 ret
= remote_send_printf ("vFlashErase:%s,%s",
4833 case PACKET_UNKNOWN
:
4834 error (_("Remote target does not support flash erase"));
4836 error (_("Error erasing flash with vFlashErase packet"));
4841 do_cleanups (back_to
);
4845 remote_flash_write (struct target_ops
*ops
,
4846 ULONGEST address
, LONGEST length
,
4847 const gdb_byte
*data
)
4849 int saved_remote_timeout
= remote_timeout
;
4851 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
4852 &saved_remote_timeout
);
4854 remote_timeout
= remote_flash_timeout
;
4855 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
4856 do_cleanups (back_to
);
4862 remote_flash_done (struct target_ops
*ops
)
4864 int saved_remote_timeout
= remote_timeout
;
4866 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
4867 &saved_remote_timeout
);
4869 remote_timeout
= remote_flash_timeout
;
4870 ret
= remote_send_printf ("vFlashDone");
4871 do_cleanups (back_to
);
4875 case PACKET_UNKNOWN
:
4876 error (_("Remote target does not support vFlashDone"));
4878 error (_("Error finishing flash operation"));
4885 remote_files_info (struct target_ops
*ignore
)
4887 puts_filtered ("Debugging a target over a serial line.\n");
4890 /* Stuff for dealing with the packets which are part of this protocol.
4891 See comment at top of file for details. */
4893 /* Read a single character from the remote end. */
4896 readchar (int timeout
)
4900 ch
= serial_readchar (remote_desc
, timeout
);
4905 switch ((enum serial_rc
) ch
)
4908 target_mourn_inferior ();
4909 error (_("Remote connection closed"));
4912 perror_with_name (_("Remote communication error"));
4914 case SERIAL_TIMEOUT
:
4920 /* Send the command in *BUF to the remote machine, and read the reply
4921 into *BUF. Report an error if we get an error reply. Resize
4922 *BUF using xrealloc if necessary to hold the result, and update
4926 remote_send (char **buf
,
4930 getpkt (buf
, sizeof_buf
, 0);
4932 if ((*buf
)[0] == 'E')
4933 error (_("Remote failure reply: %s"), *buf
);
4936 /* Display a null-terminated packet on stdout, for debugging, using C
4940 print_packet (char *buf
)
4942 puts_filtered ("\"");
4943 fputstr_filtered (buf
, '"', gdb_stdout
);
4944 puts_filtered ("\"");
4950 return putpkt_binary (buf
, strlen (buf
));
4953 /* Send a packet to the remote machine, with error checking. The data
4954 of the packet is in BUF. The string in BUF can be at most
4955 get_remote_packet_size () - 5 to account for the $, # and checksum,
4956 and for a possible /0 if we are debugging (remote_debug) and want
4957 to print the sent packet as a string. */
4960 putpkt_binary (char *buf
, int cnt
)
4962 struct remote_state
*rs
= get_remote_state ();
4964 unsigned char csum
= 0;
4965 char *buf2
= alloca (cnt
+ 6);
4971 /* We're sending out a new packet. Make sure we don't look at a
4972 stale cached response. */
4973 rs
->cached_wait_status
= 0;
4975 /* Copy the packet into buffer BUF2, encapsulating it
4976 and giving it a checksum. */
4981 for (i
= 0; i
< cnt
; i
++)
4987 *p
++ = tohex ((csum
>> 4) & 0xf);
4988 *p
++ = tohex (csum
& 0xf);
4990 /* Send it over and over until we get a positive ack. */
4994 int started_error_output
= 0;
4999 fprintf_unfiltered (gdb_stdlog
, "Sending packet: ");
5000 fputstrn_unfiltered (buf2
, p
- buf2
, 0, gdb_stdlog
);
5001 fprintf_unfiltered (gdb_stdlog
, "...");
5002 gdb_flush (gdb_stdlog
);
5004 if (serial_write (remote_desc
, buf2
, p
- buf2
))
5005 perror_with_name (_("putpkt: write failed"));
5007 /* If this is a no acks version of the remote protocol, send the
5008 packet and move on. */
5012 /* Read until either a timeout occurs (-2) or '+' is read. */
5015 ch
= readchar (remote_timeout
);
5023 case SERIAL_TIMEOUT
:
5025 if (started_error_output
)
5027 putchar_unfiltered ('\n');
5028 started_error_output
= 0;
5037 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
5041 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
5042 case SERIAL_TIMEOUT
:
5046 break; /* Retransmit buffer. */
5050 fprintf_unfiltered (gdb_stdlog
,
5051 "Packet instead of Ack, ignoring it\n");
5052 /* It's probably an old response sent because an ACK
5053 was lost. Gobble up the packet and ack it so it
5054 doesn't get retransmitted when we resend this
5057 serial_write (remote_desc
, "+", 1);
5058 continue; /* Now, go look for +. */
5063 if (!started_error_output
)
5065 started_error_output
= 1;
5066 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
5068 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
5072 break; /* Here to retransmit. */
5076 /* This is wrong. If doing a long backtrace, the user should be
5077 able to get out next time we call QUIT, without anything as
5078 violent as interrupt_query. If we want to provide a way out of
5079 here without getting to the next QUIT, it should be based on
5080 hitting ^C twice as in remote_wait. */
5091 /* Come here after finding the start of a frame when we expected an
5092 ack. Do our best to discard the rest of this packet. */
5101 c
= readchar (remote_timeout
);
5104 case SERIAL_TIMEOUT
:
5105 /* Nothing we can do. */
5108 /* Discard the two bytes of checksum and stop. */
5109 c
= readchar (remote_timeout
);
5111 c
= readchar (remote_timeout
);
5114 case '*': /* Run length encoding. */
5115 /* Discard the repeat count. */
5116 c
= readchar (remote_timeout
);
5121 /* A regular character. */
5127 /* Come here after finding the start of the frame. Collect the rest
5128 into *BUF, verifying the checksum, length, and handling run-length
5129 compression. NUL terminate the buffer. If there is not enough room,
5130 expand *BUF using xrealloc.
5132 Returns -1 on error, number of characters in buffer (ignoring the
5133 trailing NULL) on success. (could be extended to return one of the
5134 SERIAL status indications). */
5137 read_frame (char **buf_p
,
5144 struct remote_state
*rs
= get_remote_state ();
5151 c
= readchar (remote_timeout
);
5154 case SERIAL_TIMEOUT
:
5156 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
5160 fputs_filtered ("Saw new packet start in middle of old one\n",
5162 return -1; /* Start a new packet, count retries. */
5165 unsigned char pktcsum
;
5171 check_0
= readchar (remote_timeout
);
5173 check_1
= readchar (remote_timeout
);
5175 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
5178 fputs_filtered ("Timeout in checksum, retrying\n",
5182 else if (check_0
< 0 || check_1
< 0)
5185 fputs_filtered ("Communication error in checksum\n",
5190 /* Don't recompute the checksum; with no ack packets we
5191 don't have any way to indicate a packet retransmission
5196 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
5197 if (csum
== pktcsum
)
5202 fprintf_filtered (gdb_stdlog
,
5203 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
5205 fputstrn_filtered (buf
, bc
, 0, gdb_stdlog
);
5206 fputs_filtered ("\n", gdb_stdlog
);
5208 /* Number of characters in buffer ignoring trailing
5212 case '*': /* Run length encoding. */
5217 c
= readchar (remote_timeout
);
5219 repeat
= c
- ' ' + 3; /* Compute repeat count. */
5221 /* The character before ``*'' is repeated. */
5223 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
5225 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
5227 /* Make some more room in the buffer. */
5228 *sizeof_buf
+= repeat
;
5229 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
5233 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
5239 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
5243 if (bc
>= *sizeof_buf
- 1)
5245 /* Make some more room in the buffer. */
5247 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
5258 /* Read a packet from the remote machine, with error checking, and
5259 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
5260 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
5261 rather than timing out; this is used (in synchronous mode) to wait
5262 for a target that is is executing user code to stop. */
5263 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
5264 don't have to change all the calls to getpkt to deal with the
5265 return value, because at the moment I don't know what the right
5266 thing to do it for those. */
5274 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
5278 /* Read a packet from the remote machine, with error checking, and
5279 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
5280 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
5281 rather than timing out; this is used (in synchronous mode) to wait
5282 for a target that is is executing user code to stop. If FOREVER ==
5283 0, this function is allowed to time out gracefully and return an
5284 indication of this to the caller. Otherwise return the number
5287 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
5289 struct remote_state
*rs
= get_remote_state ();
5295 /* We're reading a new response. Make sure we don't look at a
5296 previously cached response. */
5297 rs
->cached_wait_status
= 0;
5299 strcpy (*buf
, "timeout");
5303 timeout
= watchdog
> 0 ? watchdog
: -1;
5307 timeout
= remote_timeout
;
5311 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
5313 /* This can loop forever if the remote side sends us characters
5314 continuously, but if it pauses, we'll get a zero from
5315 readchar because of timeout. Then we'll count that as a
5318 /* Note that we will only wait forever prior to the start of a
5319 packet. After that, we expect characters to arrive at a
5320 brisk pace. They should show up within remote_timeout
5325 c
= readchar (timeout
);
5327 if (c
== SERIAL_TIMEOUT
)
5329 if (forever
) /* Watchdog went off? Kill the target. */
5332 target_mourn_inferior ();
5333 error (_("Watchdog timeout has expired. Target detached."));
5336 fputs_filtered ("Timed out.\n", gdb_stdlog
);
5342 /* We've found the start of a packet, now collect the data. */
5344 val
= read_frame (buf
, sizeof_buf
);
5350 fprintf_unfiltered (gdb_stdlog
, "Packet received: ");
5351 fputstrn_unfiltered (*buf
, val
, 0, gdb_stdlog
);
5352 fprintf_unfiltered (gdb_stdlog
, "\n");
5355 /* Skip the ack char if we're in no-ack mode. */
5356 if (!rs
->noack_mode
)
5357 serial_write (remote_desc
, "+", 1);
5361 /* Try the whole thing again. */
5363 /* Skip the nack char if we're in no-ack mode. */
5364 if (!rs
->noack_mode
)
5365 serial_write (remote_desc
, "-", 1);
5368 /* We have tried hard enough, and just can't receive the packet.
5371 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
5373 /* Skip the ack char if we're in no-ack mode. */
5374 if (!rs
->noack_mode
)
5375 serial_write (remote_desc
, "+", 1);
5382 /* Unregister the file descriptor from the event loop. */
5383 if (target_is_async_p ())
5384 serial_async (remote_desc
, NULL
, 0);
5386 /* Use catch_errors so the user can quit from gdb even when we
5387 aren't on speaking terms with the remote system. */
5388 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
5390 /* Don't wait for it to die. I'm not really sure it matters whether
5391 we do or not. For the existing stubs, kill is a noop. */
5392 target_mourn_inferior ();
5396 remote_vkill (int pid
, struct remote_state
*rs
)
5398 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
5401 /* Tell the remote target to detach. */
5402 sprintf (rs
->buf
, "vKill;%x", pid
);
5404 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5406 if (packet_ok (rs
->buf
,
5407 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
5409 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
5416 extended_remote_kill (void)
5419 int pid
= ptid_get_pid (inferior_ptid
);
5420 struct remote_state
*rs
= get_remote_state ();
5422 res
= remote_vkill (pid
, rs
);
5423 if (res
== -1 && !remote_multi_process_p (rs
))
5425 /* Don't try 'k' on a multi-process aware stub -- it has no way
5426 to specify the pid. */
5430 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5431 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
5434 /* Don't wait for it to die. I'm not really sure it matters whether
5435 we do or not. For the existing stubs, kill is a noop. */
5441 error (_("Can't kill process"));
5443 delete_inferior (pid
);
5444 target_mourn_inferior ();
5450 remote_mourn_1 (&remote_ops
);
5453 /* Worker function for remote_mourn. */
5455 remote_mourn_1 (struct target_ops
*target
)
5457 /* Get rid of all the inferiors and their threads we were
5459 discard_all_inferiors ();
5461 unpush_target (target
);
5462 generic_mourn_inferior ();
5466 select_new_thread_callback (struct thread_info
*th
, void* data
)
5468 if (!ptid_equal (th
->ptid
, minus_one_ptid
))
5470 switch_to_thread (th
->ptid
);
5471 printf_filtered (_("[Switching to %s]\n"),
5472 target_pid_to_str (inferior_ptid
));
5479 extended_remote_mourn_1 (struct target_ops
*target
)
5481 struct remote_state
*rs
= get_remote_state ();
5483 /* Unlike "target remote", we do not want to unpush the target; then
5484 the next time the user says "run", we won't be connected. */
5486 if (have_inferiors ())
5488 extern void nullify_last_target_wait_ptid ();
5489 /* Multi-process case. The current process has exited, but
5490 there are other processes to debug. Switch to the first
5492 iterate_over_threads (select_new_thread_callback
, NULL
);
5493 nullify_last_target_wait_ptid ();
5497 struct remote_state
*rs
= get_remote_state ();
5499 /* Call common code to mark the inferior as not running. */
5500 generic_mourn_inferior ();
5501 if (!remote_multi_process_p (rs
))
5503 /* Check whether the target is running now - some remote stubs
5504 automatically restart after kill. */
5506 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5508 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
5510 /* Assume that the target has been restarted. Set inferior_ptid
5511 so that bits of core GDB realizes there's something here, e.g.,
5512 so that the user can say "kill" again. */
5513 inferior_ptid
= magic_null_ptid
;
5517 /* Mark this (still pushed) target as not executable until we
5519 target_mark_exited (target
);
5523 /* Always remove execution if this was the last process. */
5524 target_mark_exited (target
);
5529 extended_remote_mourn (void)
5531 extended_remote_mourn_1 (&extended_remote_ops
);
5535 extended_remote_run (char *args
)
5537 struct remote_state
*rs
= get_remote_state ();
5541 /* If the user has disabled vRun support, or we have detected that
5542 support is not available, do not try it. */
5543 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
5546 strcpy (rs
->buf
, "vRun;");
5547 len
= strlen (rs
->buf
);
5549 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
5550 error (_("Remote file name too long for run packet"));
5551 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
5553 gdb_assert (args
!= NULL
);
5556 struct cleanup
*back_to
;
5560 argv
= gdb_buildargv (args
);
5561 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
5562 for (i
= 0; argv
[i
] != NULL
; i
++)
5564 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
5565 error (_("Argument list too long for run packet"));
5566 rs
->buf
[len
++] = ';';
5567 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
5569 do_cleanups (back_to
);
5572 rs
->buf
[len
++] = '\0';
5575 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5577 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
5579 /* We have a wait response; we don't need it, though. All is well. */
5582 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
5583 /* It wasn't disabled before, but it is now. */
5587 if (remote_exec_file
[0] == '\0')
5588 error (_("Running the default executable on the remote target failed; "
5589 "try \"set remote exec-file\"?"));
5591 error (_("Running \"%s\" on the remote target failed"),
5596 /* In the extended protocol we want to be able to do things like
5597 "run" and have them basically work as expected. So we need
5598 a special create_inferior function. We support changing the
5599 executable file and the command line arguments, but not the
5603 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
5604 char **env
, int from_tty
)
5606 /* If running asynchronously, register the target file descriptor
5607 with the event loop. */
5608 if (target_can_async_p ())
5609 target_async (inferior_event_handler
, 0);
5611 /* Now restart the remote server. */
5612 if (extended_remote_run (args
) == -1)
5614 /* vRun was not supported. Fail if we need it to do what the
5616 if (remote_exec_file
[0])
5617 error (_("Remote target does not support \"set remote exec-file\""));
5619 error (_("Remote target does not support \"set args\" or run <ARGS>"));
5621 /* Fall back to "R". */
5622 extended_remote_restart ();
5625 /* Clean up from the last time we ran, before we mark the target
5626 running again. This will mark breakpoints uninserted, and
5627 get_offsets may insert breakpoints. */
5628 init_thread_list ();
5629 init_wait_for_inferior ();
5631 /* Now mark the inferior as running before we do anything else. */
5632 inferior_ptid
= magic_null_ptid
;
5634 add_inferior (ptid_get_pid (inferior_ptid
));
5635 add_thread_silent (inferior_ptid
);
5637 target_mark_running (&extended_remote_ops
);
5639 /* Get updated offsets, if the stub uses qOffsets. */
5644 extended_remote_create_inferior (char *exec_file
, char *args
,
5645 char **env
, int from_tty
)
5647 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
5651 /* Insert a breakpoint. On targets that have software breakpoint
5652 support, we ask the remote target to do the work; on targets
5653 which don't, we insert a traditional memory breakpoint. */
5656 remote_insert_breakpoint (struct bp_target_info
*bp_tgt
)
5658 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
5659 If it succeeds, then set the support to PACKET_ENABLE. If it
5660 fails, and the user has explicitly requested the Z support then
5661 report an error, otherwise, mark it disabled and go on. */
5663 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
5665 CORE_ADDR addr
= bp_tgt
->placed_address
;
5666 struct remote_state
*rs
;
5670 gdbarch_breakpoint_from_pc (target_gdbarch
, &addr
, &bpsize
);
5672 rs
= get_remote_state ();
5678 addr
= (ULONGEST
) remote_address_masked (addr
);
5679 p
+= hexnumstr (p
, addr
);
5680 sprintf (p
, ",%d", bpsize
);
5683 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5685 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
5690 bp_tgt
->placed_address
= addr
;
5691 bp_tgt
->placed_size
= bpsize
;
5693 case PACKET_UNKNOWN
:
5698 return memory_insert_breakpoint (bp_tgt
);
5702 remote_remove_breakpoint (struct bp_target_info
*bp_tgt
)
5704 CORE_ADDR addr
= bp_tgt
->placed_address
;
5705 struct remote_state
*rs
= get_remote_state ();
5708 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
5716 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
5717 p
+= hexnumstr (p
, addr
);
5718 sprintf (p
, ",%d", bp_tgt
->placed_size
);
5721 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5723 return (rs
->buf
[0] == 'E');
5726 return memory_remove_breakpoint (bp_tgt
);
5730 watchpoint_to_Z_packet (int type
)
5735 return Z_PACKET_WRITE_WP
;
5738 return Z_PACKET_READ_WP
;
5741 return Z_PACKET_ACCESS_WP
;
5744 internal_error (__FILE__
, __LINE__
,
5745 _("hw_bp_to_z: bad watchpoint type %d"), type
);
5750 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
5752 struct remote_state
*rs
= get_remote_state ();
5754 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
5756 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
5759 sprintf (rs
->buf
, "Z%x,", packet
);
5760 p
= strchr (rs
->buf
, '\0');
5761 addr
= remote_address_masked (addr
);
5762 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5763 sprintf (p
, ",%x", len
);
5766 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5768 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
5771 case PACKET_UNKNOWN
:
5776 internal_error (__FILE__
, __LINE__
,
5777 _("remote_insert_watchpoint: reached end of function"));
5782 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
5784 struct remote_state
*rs
= get_remote_state ();
5786 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
5788 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
5791 sprintf (rs
->buf
, "z%x,", packet
);
5792 p
= strchr (rs
->buf
, '\0');
5793 addr
= remote_address_masked (addr
);
5794 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5795 sprintf (p
, ",%x", len
);
5797 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5799 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
5802 case PACKET_UNKNOWN
:
5807 internal_error (__FILE__
, __LINE__
,
5808 _("remote_remove_watchpoint: reached end of function"));
5812 int remote_hw_watchpoint_limit
= -1;
5813 int remote_hw_breakpoint_limit
= -1;
5816 remote_check_watch_resources (int type
, int cnt
, int ot
)
5818 if (type
== bp_hardware_breakpoint
)
5820 if (remote_hw_breakpoint_limit
== 0)
5822 else if (remote_hw_breakpoint_limit
< 0)
5824 else if (cnt
<= remote_hw_breakpoint_limit
)
5829 if (remote_hw_watchpoint_limit
== 0)
5831 else if (remote_hw_watchpoint_limit
< 0)
5835 else if (cnt
<= remote_hw_watchpoint_limit
)
5842 remote_stopped_by_watchpoint (void)
5844 return remote_stopped_by_watchpoint_p
;
5848 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
5851 if (remote_stopped_by_watchpoint ())
5853 *addr_p
= remote_watch_data_address
;
5862 remote_insert_hw_breakpoint (struct bp_target_info
*bp_tgt
)
5865 struct remote_state
*rs
;
5868 /* The length field should be set to the size of a breakpoint
5869 instruction, even though we aren't inserting one ourselves. */
5871 gdbarch_breakpoint_from_pc
5872 (target_gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
5874 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
5877 rs
= get_remote_state ();
5884 addr
= remote_address_masked (bp_tgt
->placed_address
);
5885 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5886 sprintf (p
, ",%x", bp_tgt
->placed_size
);
5889 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5891 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
5894 case PACKET_UNKNOWN
:
5899 internal_error (__FILE__
, __LINE__
,
5900 _("remote_insert_hw_breakpoint: reached end of function"));
5905 remote_remove_hw_breakpoint (struct bp_target_info
*bp_tgt
)
5908 struct remote_state
*rs
= get_remote_state ();
5911 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
5918 addr
= remote_address_masked (bp_tgt
->placed_address
);
5919 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5920 sprintf (p
, ",%x", bp_tgt
->placed_size
);
5923 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5925 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
5928 case PACKET_UNKNOWN
:
5933 internal_error (__FILE__
, __LINE__
,
5934 _("remote_remove_hw_breakpoint: reached end of function"));
5937 /* Some targets are only capable of doing downloads, and afterwards
5938 they switch to the remote serial protocol. This function provides
5939 a clean way to get from the download target to the remote target.
5940 It's basically just a wrapper so that we don't have to expose any
5941 of the internal workings of remote.c.
5943 Prior to calling this routine, you should shutdown the current
5944 target code, else you will get the "A program is being debugged
5945 already..." message. Usually a call to pop_target() suffices. */
5948 push_remote_target (char *name
, int from_tty
)
5950 printf_filtered (_("Switching to remote protocol\n"));
5951 remote_open (name
, from_tty
);
5954 /* Table used by the crc32 function to calcuate the checksum. */
5956 static unsigned long crc32_table
[256] =
5959 static unsigned long
5960 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
5962 if (!crc32_table
[1])
5964 /* Initialize the CRC table and the decoding table. */
5968 for (i
= 0; i
< 256; i
++)
5970 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
5971 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
5978 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
5984 /* compare-sections command
5986 With no arguments, compares each loadable section in the exec bfd
5987 with the same memory range on the target, and reports mismatches.
5988 Useful for verifying the image on the target against the exec file.
5989 Depends on the target understanding the new "qCRC:" request. */
5991 /* FIXME: cagney/1999-10-26: This command should be broken down into a
5992 target method (target verify memory) and generic version of the
5993 actual command. This will allow other high-level code (especially
5994 generic_load()) to make use of this target functionality. */
5997 compare_sections_command (char *args
, int from_tty
)
5999 struct remote_state
*rs
= get_remote_state ();
6001 unsigned long host_crc
, target_crc
;
6002 extern bfd
*exec_bfd
;
6003 struct cleanup
*old_chain
;
6006 const char *sectname
;
6013 error (_("command cannot be used without an exec file"));
6014 if (!current_target
.to_shortname
||
6015 strcmp (current_target
.to_shortname
, "remote") != 0)
6016 error (_("command can only be used with remote target"));
6018 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
6020 if (!(s
->flags
& SEC_LOAD
))
6021 continue; /* skip non-loadable section */
6023 size
= bfd_get_section_size (s
);
6025 continue; /* skip zero-length section */
6027 sectname
= bfd_get_section_name (exec_bfd
, s
);
6028 if (args
&& strcmp (args
, sectname
) != 0)
6029 continue; /* not the section selected by user */
6031 matched
= 1; /* do this section */
6033 /* FIXME: assumes lma can fit into long. */
6034 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
6035 (long) lma
, (long) size
);
6038 /* Be clever; compute the host_crc before waiting for target
6040 sectdata
= xmalloc (size
);
6041 old_chain
= make_cleanup (xfree
, sectdata
);
6042 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
6043 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
6045 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6046 if (rs
->buf
[0] == 'E')
6047 error (_("target memory fault, section %s, range 0x%s -- 0x%s"),
6048 sectname
, paddr (lma
), paddr (lma
+ size
));
6049 if (rs
->buf
[0] != 'C')
6050 error (_("remote target does not support this operation"));
6052 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
6053 target_crc
= target_crc
* 16 + fromhex (*tmp
);
6055 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
6056 sectname
, paddr (lma
), paddr (lma
+ size
));
6057 if (host_crc
== target_crc
)
6058 printf_filtered ("matched.\n");
6061 printf_filtered ("MIS-MATCHED!\n");
6065 do_cleanups (old_chain
);
6068 warning (_("One or more sections of the remote executable does not match\n\
6069 the loaded file\n"));
6070 if (args
&& !matched
)
6071 printf_filtered (_("No loaded section named '%s'.\n"), args
);
6074 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
6075 into remote target. The number of bytes written to the remote
6076 target is returned, or -1 for error. */
6079 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
6080 const char *annex
, const gdb_byte
*writebuf
,
6081 ULONGEST offset
, LONGEST len
,
6082 struct packet_config
*packet
)
6087 struct remote_state
*rs
= get_remote_state ();
6088 int max_size
= get_memory_write_packet_size ();
6090 if (packet
->support
== PACKET_DISABLE
)
6093 /* Insert header. */
6094 i
= snprintf (rs
->buf
, max_size
,
6095 "qXfer:%s:write:%s:%s:",
6096 object_name
, annex
? annex
: "",
6097 phex_nz (offset
, sizeof offset
));
6098 max_size
-= (i
+ 1);
6100 /* Escape as much data as fits into rs->buf. */
6101 buf_len
= remote_escape_output
6102 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
6104 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
6105 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
6106 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
6109 unpack_varlen_hex (rs
->buf
, &n
);
6113 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
6114 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
6115 number of bytes read is returned, or 0 for EOF, or -1 for error.
6116 The number of bytes read may be less than LEN without indicating an
6117 EOF. PACKET is checked and updated to indicate whether the remote
6118 target supports this object. */
6121 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
6123 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
6124 struct packet_config
*packet
)
6126 static char *finished_object
;
6127 static char *finished_annex
;
6128 static ULONGEST finished_offset
;
6130 struct remote_state
*rs
= get_remote_state ();
6131 unsigned int total
= 0;
6132 LONGEST i
, n
, packet_len
;
6134 if (packet
->support
== PACKET_DISABLE
)
6137 /* Check whether we've cached an end-of-object packet that matches
6139 if (finished_object
)
6141 if (strcmp (object_name
, finished_object
) == 0
6142 && strcmp (annex
? annex
: "", finished_annex
) == 0
6143 && offset
== finished_offset
)
6146 /* Otherwise, we're now reading something different. Discard
6148 xfree (finished_object
);
6149 xfree (finished_annex
);
6150 finished_object
= NULL
;
6151 finished_annex
= NULL
;
6154 /* Request only enough to fit in a single packet. The actual data
6155 may not, since we don't know how much of it will need to be escaped;
6156 the target is free to respond with slightly less data. We subtract
6157 five to account for the response type and the protocol frame. */
6158 n
= min (get_remote_packet_size () - 5, len
);
6159 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
6160 object_name
, annex
? annex
: "",
6161 phex_nz (offset
, sizeof offset
),
6162 phex_nz (n
, sizeof n
));
6163 i
= putpkt (rs
->buf
);
6168 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
6169 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
6172 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
6173 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
6175 /* 'm' means there is (or at least might be) more data after this
6176 batch. That does not make sense unless there's at least one byte
6177 of data in this reply. */
6178 if (rs
->buf
[0] == 'm' && packet_len
== 1)
6179 error (_("Remote qXfer reply contained no data."));
6181 /* Got some data. */
6182 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
6184 /* 'l' is an EOF marker, possibly including a final block of data,
6185 or possibly empty. If we have the final block of a non-empty
6186 object, record this fact to bypass a subsequent partial read. */
6187 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
6189 finished_object
= xstrdup (object_name
);
6190 finished_annex
= xstrdup (annex
? annex
: "");
6191 finished_offset
= offset
+ i
;
6198 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
6199 const char *annex
, gdb_byte
*readbuf
,
6200 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
6202 struct remote_state
*rs
;
6207 set_general_thread (inferior_ptid
);
6209 rs
= get_remote_state ();
6211 /* Handle memory using the standard memory routines. */
6212 if (object
== TARGET_OBJECT_MEMORY
)
6217 /* If the remote target is connected but not running, we should
6218 pass this request down to a lower stratum (e.g. the executable
6220 if (!target_has_execution
)
6223 if (writebuf
!= NULL
)
6224 xfered
= remote_write_bytes (offset
, writebuf
, len
);
6226 xfered
= remote_read_bytes (offset
, readbuf
, len
);
6230 else if (xfered
== 0 && errno
== 0)
6236 /* Handle SPU memory using qxfer packets. */
6237 if (object
== TARGET_OBJECT_SPU
)
6240 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
6241 &remote_protocol_packets
6242 [PACKET_qXfer_spu_read
]);
6244 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
6245 &remote_protocol_packets
6246 [PACKET_qXfer_spu_write
]);
6249 /* Only handle flash writes. */
6250 if (writebuf
!= NULL
)
6256 case TARGET_OBJECT_FLASH
:
6257 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
6261 else if (xfered
== 0 && errno
== 0)
6271 /* Map pre-existing objects onto letters. DO NOT do this for new
6272 objects!!! Instead specify new query packets. */
6275 case TARGET_OBJECT_AVR
:
6279 case TARGET_OBJECT_AUXV
:
6280 gdb_assert (annex
== NULL
);
6281 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
6282 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
6284 case TARGET_OBJECT_AVAILABLE_FEATURES
:
6285 return remote_read_qxfer
6286 (ops
, "features", annex
, readbuf
, offset
, len
,
6287 &remote_protocol_packets
[PACKET_qXfer_features
]);
6289 case TARGET_OBJECT_LIBRARIES
:
6290 return remote_read_qxfer
6291 (ops
, "libraries", annex
, readbuf
, offset
, len
,
6292 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
6294 case TARGET_OBJECT_MEMORY_MAP
:
6295 gdb_assert (annex
== NULL
);
6296 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
6297 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
6303 /* Note: a zero OFFSET and LEN can be used to query the minimum
6305 if (offset
== 0 && len
== 0)
6306 return (get_remote_packet_size ());
6307 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
6308 large enough let the caller deal with it. */
6309 if (len
< get_remote_packet_size ())
6311 len
= get_remote_packet_size ();
6313 /* Except for querying the minimum buffer size, target must be open. */
6315 error (_("remote query is only available after target open"));
6317 gdb_assert (annex
!= NULL
);
6318 gdb_assert (readbuf
!= NULL
);
6324 /* We used one buffer char for the remote protocol q command and
6325 another for the query type. As the remote protocol encapsulation
6326 uses 4 chars plus one extra in case we are debugging
6327 (remote_debug), we have PBUFZIZ - 7 left to pack the query
6330 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
6332 /* Bad caller may have sent forbidden characters. */
6333 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
6338 gdb_assert (annex
[i
] == '\0');
6340 i
= putpkt (rs
->buf
);
6344 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6345 strcpy ((char *) readbuf
, rs
->buf
);
6347 return strlen ((char *) readbuf
);
6351 remote_search_memory (struct target_ops
* ops
,
6352 CORE_ADDR start_addr
, ULONGEST search_space_len
,
6353 const gdb_byte
*pattern
, ULONGEST pattern_len
,
6354 CORE_ADDR
*found_addrp
)
6356 struct remote_state
*rs
= get_remote_state ();
6357 int max_size
= get_memory_write_packet_size ();
6358 struct packet_config
*packet
=
6359 &remote_protocol_packets
[PACKET_qSearch_memory
];
6360 /* number of packet bytes used to encode the pattern,
6361 this could be more than PATTERN_LEN due to escape characters */
6362 int escaped_pattern_len
;
6363 /* amount of pattern that was encodable in the packet */
6364 int used_pattern_len
;
6367 ULONGEST found_addr
;
6369 /* Don't go to the target if we don't have to.
6370 This is done before checking packet->support to avoid the possibility that
6371 a success for this edge case means the facility works in general. */
6372 if (pattern_len
> search_space_len
)
6374 if (pattern_len
== 0)
6376 *found_addrp
= start_addr
;
6380 /* If we already know the packet isn't supported, fall back to the simple
6381 way of searching memory. */
6383 if (packet
->support
== PACKET_DISABLE
)
6385 /* Target doesn't provided special support, fall back and use the
6386 standard support (copy memory and do the search here). */
6387 return simple_search_memory (ops
, start_addr
, search_space_len
,
6388 pattern
, pattern_len
, found_addrp
);
6391 /* Insert header. */
6392 i
= snprintf (rs
->buf
, max_size
,
6393 "qSearch:memory:%s;%s;",
6394 paddr_nz (start_addr
),
6395 phex_nz (search_space_len
, sizeof (search_space_len
)));
6396 max_size
-= (i
+ 1);
6398 /* Escape as much data as fits into rs->buf. */
6399 escaped_pattern_len
=
6400 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
6401 &used_pattern_len
, max_size
);
6403 /* Bail if the pattern is too large. */
6404 if (used_pattern_len
!= pattern_len
)
6405 error ("Pattern is too large to transmit to remote target.");
6407 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
6408 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
6409 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
6411 /* The request may not have worked because the command is not
6412 supported. If so, fall back to the simple way. */
6413 if (packet
->support
== PACKET_DISABLE
)
6415 return simple_search_memory (ops
, start_addr
, search_space_len
,
6416 pattern
, pattern_len
, found_addrp
);
6421 if (rs
->buf
[0] == '0')
6423 else if (rs
->buf
[0] == '1')
6426 if (rs
->buf
[1] != ',')
6427 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
6428 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
6429 *found_addrp
= found_addr
;
6432 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
6438 remote_rcmd (char *command
,
6439 struct ui_file
*outbuf
)
6441 struct remote_state
*rs
= get_remote_state ();
6445 error (_("remote rcmd is only available after target open"));
6447 /* Send a NULL command across as an empty command. */
6448 if (command
== NULL
)
6451 /* The query prefix. */
6452 strcpy (rs
->buf
, "qRcmd,");
6453 p
= strchr (rs
->buf
, '\0');
6455 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/) > get_remote_packet_size ())
6456 error (_("\"monitor\" command ``%s'' is too long."), command
);
6458 /* Encode the actual command. */
6459 bin2hex ((gdb_byte
*) command
, p
, 0);
6461 if (putpkt (rs
->buf
) < 0)
6462 error (_("Communication problem with target."));
6464 /* get/display the response */
6469 /* XXX - see also tracepoint.c:remote_get_noisy_reply(). */
6471 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6474 error (_("Target does not support this command."));
6475 if (buf
[0] == 'O' && buf
[1] != 'K')
6477 remote_console_output (buf
+ 1); /* 'O' message from stub. */
6480 if (strcmp (buf
, "OK") == 0)
6482 if (strlen (buf
) == 3 && buf
[0] == 'E'
6483 && isdigit (buf
[1]) && isdigit (buf
[2]))
6485 error (_("Protocol error with Rcmd"));
6487 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
6489 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
6490 fputc_unfiltered (c
, outbuf
);
6496 static VEC(mem_region_s
) *
6497 remote_memory_map (struct target_ops
*ops
)
6499 VEC(mem_region_s
) *result
= NULL
;
6500 char *text
= target_read_stralloc (¤t_target
,
6501 TARGET_OBJECT_MEMORY_MAP
, NULL
);
6505 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
6506 result
= parse_memory_map (text
);
6507 do_cleanups (back_to
);
6514 packet_command (char *args
, int from_tty
)
6516 struct remote_state
*rs
= get_remote_state ();
6519 error (_("command can only be used with remote target"));
6522 error (_("remote-packet command requires packet text as argument"));
6524 puts_filtered ("sending: ");
6525 print_packet (args
);
6526 puts_filtered ("\n");
6529 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6530 puts_filtered ("received: ");
6531 print_packet (rs
->buf
);
6532 puts_filtered ("\n");
6536 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
6538 static void display_thread_info (struct gdb_ext_thread_info
*info
);
6540 static void threadset_test_cmd (char *cmd
, int tty
);
6542 static void threadalive_test (char *cmd
, int tty
);
6544 static void threadlist_test_cmd (char *cmd
, int tty
);
6546 int get_and_display_threadinfo (threadref
*ref
);
6548 static void threadinfo_test_cmd (char *cmd
, int tty
);
6550 static int thread_display_step (threadref
*ref
, void *context
);
6552 static void threadlist_update_test_cmd (char *cmd
, int tty
);
6554 static void init_remote_threadtests (void);
6556 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
6559 threadset_test_cmd (char *cmd
, int tty
)
6561 int sample_thread
= SAMPLE_THREAD
;
6563 printf_filtered (_("Remote threadset test\n"));
6564 set_general_thread (sample_thread
);
6569 threadalive_test (char *cmd
, int tty
)
6571 int sample_thread
= SAMPLE_THREAD
;
6572 int pid
= ptid_get_pid (inferior_ptid
);
6573 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
6575 if (remote_thread_alive (ptid
))
6576 printf_filtered ("PASS: Thread alive test\n");
6578 printf_filtered ("FAIL: Thread alive test\n");
6581 void output_threadid (char *title
, threadref
*ref
);
6584 output_threadid (char *title
, threadref
*ref
)
6588 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
6590 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
6594 threadlist_test_cmd (char *cmd
, int tty
)
6597 threadref nextthread
;
6598 int done
, result_count
;
6599 threadref threadlist
[3];
6601 printf_filtered ("Remote Threadlist test\n");
6602 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
6603 &result_count
, &threadlist
[0]))
6604 printf_filtered ("FAIL: threadlist test\n");
6607 threadref
*scan
= threadlist
;
6608 threadref
*limit
= scan
+ result_count
;
6610 while (scan
< limit
)
6611 output_threadid (" thread ", scan
++);
6616 display_thread_info (struct gdb_ext_thread_info
*info
)
6618 output_threadid ("Threadid: ", &info
->threadid
);
6619 printf_filtered ("Name: %s\n ", info
->shortname
);
6620 printf_filtered ("State: %s\n", info
->display
);
6621 printf_filtered ("other: %s\n\n", info
->more_display
);
6625 get_and_display_threadinfo (threadref
*ref
)
6629 struct gdb_ext_thread_info threadinfo
;
6631 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
6632 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
6633 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
6634 display_thread_info (&threadinfo
);
6639 threadinfo_test_cmd (char *cmd
, int tty
)
6641 int athread
= SAMPLE_THREAD
;
6645 int_to_threadref (&thread
, athread
);
6646 printf_filtered ("Remote Threadinfo test\n");
6647 if (!get_and_display_threadinfo (&thread
))
6648 printf_filtered ("FAIL cannot get thread info\n");
6652 thread_display_step (threadref
*ref
, void *context
)
6654 /* output_threadid(" threadstep ",ref); *//* simple test */
6655 return get_and_display_threadinfo (ref
);
6659 threadlist_update_test_cmd (char *cmd
, int tty
)
6661 printf_filtered ("Remote Threadlist update test\n");
6662 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
6666 init_remote_threadtests (void)
6668 add_com ("tlist", class_obscure
, threadlist_test_cmd
, _("\
6669 Fetch and print the remote list of thread identifiers, one pkt only"));
6670 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
6671 _("Fetch and display info about one thread"));
6672 add_com ("tset", class_obscure
, threadset_test_cmd
,
6673 _("Test setting to a different thread"));
6674 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
6675 _("Iterate through updating all remote thread info"));
6676 add_com ("talive", class_obscure
, threadalive_test
,
6677 _(" Remote thread alive test "));
6682 /* Convert a thread ID to a string. Returns the string in a static
6686 remote_pid_to_str (ptid_t ptid
)
6688 static char buf
[64];
6689 struct remote_state
*rs
= get_remote_state ();
6691 if (ptid_equal (magic_null_ptid
, ptid
))
6693 xsnprintf (buf
, sizeof buf
, "Thread <main>");
6696 else if (remote_multi_process_p (rs
)
6697 && ptid_get_tid (ptid
) != 0 && ptid_get_pid (ptid
) != 0)
6699 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
6700 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
6703 else if (ptid_get_tid (ptid
) != 0)
6705 xsnprintf (buf
, sizeof buf
, "Thread %ld",
6706 ptid_get_tid (ptid
));
6710 return normal_pid_to_str (ptid
);
6713 /* Get the address of the thread local variable in OBJFILE which is
6714 stored at OFFSET within the thread local storage for thread PTID. */
6717 remote_get_thread_local_address (ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
6719 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
6721 struct remote_state
*rs
= get_remote_state ();
6723 char *endp
= rs
->buf
+ get_remote_packet_size ();
6724 enum packet_result result
;
6726 strcpy (p
, "qGetTLSAddr:");
6728 p
= write_ptid (p
, endp
, ptid
);
6730 p
+= hexnumstr (p
, offset
);
6732 p
+= hexnumstr (p
, lm
);
6736 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6737 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
6738 if (result
== PACKET_OK
)
6742 unpack_varlen_hex (rs
->buf
, &result
);
6745 else if (result
== PACKET_UNKNOWN
)
6746 throw_error (TLS_GENERIC_ERROR
,
6747 _("Remote target doesn't support qGetTLSAddr packet"));
6749 throw_error (TLS_GENERIC_ERROR
,
6750 _("Remote target failed to process qGetTLSAddr request"));
6753 throw_error (TLS_GENERIC_ERROR
,
6754 _("TLS not supported or disabled on this target"));
6759 /* Support for inferring a target description based on the current
6760 architecture and the size of a 'g' packet. While the 'g' packet
6761 can have any size (since optional registers can be left off the
6762 end), some sizes are easily recognizable given knowledge of the
6763 approximate architecture. */
6765 struct remote_g_packet_guess
6768 const struct target_desc
*tdesc
;
6770 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
6771 DEF_VEC_O(remote_g_packet_guess_s
);
6773 struct remote_g_packet_data
6775 VEC(remote_g_packet_guess_s
) *guesses
;
6778 static struct gdbarch_data
*remote_g_packet_data_handle
;
6781 remote_g_packet_data_init (struct obstack
*obstack
)
6783 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
6787 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
6788 const struct target_desc
*tdesc
)
6790 struct remote_g_packet_data
*data
6791 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
6792 struct remote_g_packet_guess new_guess
, *guess
;
6795 gdb_assert (tdesc
!= NULL
);
6798 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
6800 if (guess
->bytes
== bytes
)
6801 internal_error (__FILE__
, __LINE__
,
6802 "Duplicate g packet description added for size %d",
6805 new_guess
.bytes
= bytes
;
6806 new_guess
.tdesc
= tdesc
;
6807 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
6810 static const struct target_desc
*
6811 remote_read_description (struct target_ops
*target
)
6813 struct remote_g_packet_data
*data
6814 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
6816 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
6818 struct remote_g_packet_guess
*guess
;
6820 int bytes
= send_g_packet ();
6823 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
6825 if (guess
->bytes
== bytes
)
6826 return guess
->tdesc
;
6828 /* We discard the g packet. A minor optimization would be to
6829 hold on to it, and fill the register cache once we have selected
6830 an architecture, but it's too tricky to do safely. */
6836 /* Remote file transfer support. This is host-initiated I/O, not
6837 target-initiated; for target-initiated, see remote-fileio.c. */
6839 /* If *LEFT is at least the length of STRING, copy STRING to
6840 *BUFFER, update *BUFFER to point to the new end of the buffer, and
6841 decrease *LEFT. Otherwise raise an error. */
6844 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
6846 int len
= strlen (string
);
6849 error (_("Packet too long for target."));
6851 memcpy (*buffer
, string
, len
);
6855 /* NUL-terminate the buffer as a convenience, if there is
6861 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
6862 *BUFFER, update *BUFFER to point to the new end of the buffer, and
6863 decrease *LEFT. Otherwise raise an error. */
6866 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
6869 if (2 * len
> *left
)
6870 error (_("Packet too long for target."));
6872 bin2hex (bytes
, *buffer
, len
);
6876 /* NUL-terminate the buffer as a convenience, if there is
6882 /* If *LEFT is large enough, convert VALUE to hex and add it to
6883 *BUFFER, update *BUFFER to point to the new end of the buffer, and
6884 decrease *LEFT. Otherwise raise an error. */
6887 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
6889 int len
= hexnumlen (value
);
6892 error (_("Packet too long for target."));
6894 hexnumstr (*buffer
, value
);
6898 /* NUL-terminate the buffer as a convenience, if there is
6904 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
6905 value, *REMOTE_ERRNO to the remote error number or zero if none
6906 was included, and *ATTACHMENT to point to the start of the annex
6907 if any. The length of the packet isn't needed here; there may
6908 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
6910 Return 0 if the packet could be parsed, -1 if it could not. If
6911 -1 is returned, the other variables may not be initialized. */
6914 remote_hostio_parse_result (char *buffer
, int *retcode
,
6915 int *remote_errno
, char **attachment
)
6922 if (buffer
[0] != 'F')
6926 *retcode
= strtol (&buffer
[1], &p
, 16);
6927 if (errno
!= 0 || p
== &buffer
[1])
6930 /* Check for ",errno". */
6934 *remote_errno
= strtol (p
+ 1, &p2
, 16);
6935 if (errno
!= 0 || p
+ 1 == p2
)
6940 /* Check for ";attachment". If there is no attachment, the
6941 packet should end here. */
6944 *attachment
= p
+ 1;
6947 else if (*p
== '\0')
6953 /* Send a prepared I/O packet to the target and read its response.
6954 The prepared packet is in the global RS->BUF before this function
6955 is called, and the answer is there when we return.
6957 COMMAND_BYTES is the length of the request to send, which may include
6958 binary data. WHICH_PACKET is the packet configuration to check
6959 before attempting a packet. If an error occurs, *REMOTE_ERRNO
6960 is set to the error number and -1 is returned. Otherwise the value
6961 returned by the function is returned.
6963 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
6964 attachment is expected; an error will be reported if there's a
6965 mismatch. If one is found, *ATTACHMENT will be set to point into
6966 the packet buffer and *ATTACHMENT_LEN will be set to the
6967 attachment's length. */
6970 remote_hostio_send_command (int command_bytes
, int which_packet
,
6971 int *remote_errno
, char **attachment
,
6972 int *attachment_len
)
6974 struct remote_state
*rs
= get_remote_state ();
6975 int ret
, bytes_read
;
6976 char *attachment_tmp
;
6979 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
6981 *remote_errno
= FILEIO_ENOSYS
;
6985 putpkt_binary (rs
->buf
, command_bytes
);
6986 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
6988 /* If it timed out, something is wrong. Don't try to parse the
6992 *remote_errno
= FILEIO_EINVAL
;
6996 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
6999 *remote_errno
= FILEIO_EINVAL
;
7001 case PACKET_UNKNOWN
:
7002 *remote_errno
= FILEIO_ENOSYS
;
7008 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
7011 *remote_errno
= FILEIO_EINVAL
;
7015 /* Make sure we saw an attachment if and only if we expected one. */
7016 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
7017 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
7019 *remote_errno
= FILEIO_EINVAL
;
7023 /* If an attachment was found, it must point into the packet buffer;
7024 work out how many bytes there were. */
7025 if (attachment_tmp
!= NULL
)
7027 *attachment
= attachment_tmp
;
7028 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
7034 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
7035 remote file descriptor, or -1 if an error occurs (and set
7039 remote_hostio_open (const char *filename
, int flags
, int mode
,
7042 struct remote_state
*rs
= get_remote_state ();
7044 int left
= get_remote_packet_size () - 1;
7046 remote_buffer_add_string (&p
, &left
, "vFile:open:");
7048 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
7050 remote_buffer_add_string (&p
, &left
, ",");
7052 remote_buffer_add_int (&p
, &left
, flags
);
7053 remote_buffer_add_string (&p
, &left
, ",");
7055 remote_buffer_add_int (&p
, &left
, mode
);
7057 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
7058 remote_errno
, NULL
, NULL
);
7061 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
7062 Return the number of bytes written, or -1 if an error occurs (and
7063 set *REMOTE_ERRNO). */
7066 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
7067 ULONGEST offset
, int *remote_errno
)
7069 struct remote_state
*rs
= get_remote_state ();
7071 int left
= get_remote_packet_size ();
7074 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
7076 remote_buffer_add_int (&p
, &left
, fd
);
7077 remote_buffer_add_string (&p
, &left
, ",");
7079 remote_buffer_add_int (&p
, &left
, offset
);
7080 remote_buffer_add_string (&p
, &left
, ",");
7082 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
7083 get_remote_packet_size () - (p
- rs
->buf
));
7085 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
7086 remote_errno
, NULL
, NULL
);
7089 /* Read up to LEN bytes FD on the remote target into READ_BUF
7090 Return the number of bytes read, or -1 if an error occurs (and
7091 set *REMOTE_ERRNO). */
7094 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
7095 ULONGEST offset
, int *remote_errno
)
7097 struct remote_state
*rs
= get_remote_state ();
7100 int left
= get_remote_packet_size ();
7101 int ret
, attachment_len
;
7104 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
7106 remote_buffer_add_int (&p
, &left
, fd
);
7107 remote_buffer_add_string (&p
, &left
, ",");
7109 remote_buffer_add_int (&p
, &left
, len
);
7110 remote_buffer_add_string (&p
, &left
, ",");
7112 remote_buffer_add_int (&p
, &left
, offset
);
7114 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
7115 remote_errno
, &attachment
,
7121 read_len
= remote_unescape_input (attachment
, attachment_len
,
7123 if (read_len
!= ret
)
7124 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
7129 /* Close FD on the remote target. Return 0, or -1 if an error occurs
7130 (and set *REMOTE_ERRNO). */
7133 remote_hostio_close (int fd
, int *remote_errno
)
7135 struct remote_state
*rs
= get_remote_state ();
7137 int left
= get_remote_packet_size () - 1;
7139 remote_buffer_add_string (&p
, &left
, "vFile:close:");
7141 remote_buffer_add_int (&p
, &left
, fd
);
7143 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
7144 remote_errno
, NULL
, NULL
);
7147 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
7148 occurs (and set *REMOTE_ERRNO). */
7151 remote_hostio_unlink (const char *filename
, int *remote_errno
)
7153 struct remote_state
*rs
= get_remote_state ();
7155 int left
= get_remote_packet_size () - 1;
7157 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
7159 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
7162 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
7163 remote_errno
, NULL
, NULL
);
7167 remote_fileio_errno_to_host (int errnum
)
7191 case FILEIO_ENOTDIR
:
7211 case FILEIO_ENAMETOOLONG
:
7212 return ENAMETOOLONG
;
7218 remote_hostio_error (int errnum
)
7220 int host_error
= remote_fileio_errno_to_host (errnum
);
7222 if (host_error
== -1)
7223 error (_("Unknown remote I/O error %d"), errnum
);
7225 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
7229 fclose_cleanup (void *file
)
7235 remote_hostio_close_cleanup (void *opaque
)
7237 int fd
= *(int *) opaque
;
7240 remote_hostio_close (fd
, &remote_errno
);
7245 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
7247 const char *filename
= bfd_get_filename (abfd
);
7248 int fd
, remote_errno
;
7251 gdb_assert (remote_filename_p (filename
));
7253 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
7256 errno
= remote_fileio_errno_to_host (remote_errno
);
7257 bfd_set_error (bfd_error_system_call
);
7261 stream
= xmalloc (sizeof (int));
7267 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
7269 int fd
= *(int *)stream
;
7274 /* Ignore errors on close; these may happen if the remote
7275 connection was already torn down. */
7276 remote_hostio_close (fd
, &remote_errno
);
7282 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
7283 file_ptr nbytes
, file_ptr offset
)
7285 int fd
= *(int *)stream
;
7287 file_ptr pos
, bytes
;
7290 while (nbytes
> pos
)
7292 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
7293 offset
+ pos
, &remote_errno
);
7295 /* Success, but no bytes, means end-of-file. */
7299 errno
= remote_fileio_errno_to_host (remote_errno
);
7300 bfd_set_error (bfd_error_system_call
);
7311 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
7313 /* FIXME: We should probably implement remote_hostio_stat. */
7314 sb
->st_size
= INT_MAX
;
7319 remote_filename_p (const char *filename
)
7321 return strncmp (filename
, "remote:", 7) == 0;
7325 remote_bfd_open (const char *remote_file
, const char *target
)
7327 return bfd_openr_iovec (remote_file
, target
,
7328 remote_bfd_iovec_open
, NULL
,
7329 remote_bfd_iovec_pread
,
7330 remote_bfd_iovec_close
,
7331 remote_bfd_iovec_stat
);
7335 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
7337 struct cleanup
*back_to
, *close_cleanup
;
7338 int retcode
, fd
, remote_errno
, bytes
, io_size
;
7341 int bytes_in_buffer
;
7346 error (_("command can only be used with remote target"));
7348 file
= fopen (local_file
, "rb");
7350 perror_with_name (local_file
);
7351 back_to
= make_cleanup (fclose_cleanup
, file
);
7353 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
7355 0700, &remote_errno
);
7357 remote_hostio_error (remote_errno
);
7359 /* Send up to this many bytes at once. They won't all fit in the
7360 remote packet limit, so we'll transfer slightly fewer. */
7361 io_size
= get_remote_packet_size ();
7362 buffer
= xmalloc (io_size
);
7363 make_cleanup (xfree
, buffer
);
7365 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
7367 bytes_in_buffer
= 0;
7370 while (bytes_in_buffer
|| !saw_eof
)
7374 bytes
= fread (buffer
+ bytes_in_buffer
, 1, io_size
- bytes_in_buffer
,
7379 error (_("Error reading %s."), local_file
);
7382 /* EOF. Unless there is something still in the
7383 buffer from the last iteration, we are done. */
7385 if (bytes_in_buffer
== 0)
7393 bytes
+= bytes_in_buffer
;
7394 bytes_in_buffer
= 0;
7396 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
, offset
, &remote_errno
);
7399 remote_hostio_error (remote_errno
);
7400 else if (retcode
== 0)
7401 error (_("Remote write of %d bytes returned 0!"), bytes
);
7402 else if (retcode
< bytes
)
7404 /* Short write. Save the rest of the read data for the next
7406 bytes_in_buffer
= bytes
- retcode
;
7407 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
7413 discard_cleanups (close_cleanup
);
7414 if (remote_hostio_close (fd
, &remote_errno
))
7415 remote_hostio_error (remote_errno
);
7418 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
7419 do_cleanups (back_to
);
7423 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
7425 struct cleanup
*back_to
, *close_cleanup
;
7426 int retcode
, fd
, remote_errno
, bytes
, io_size
;
7432 error (_("command can only be used with remote target"));
7434 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
7436 remote_hostio_error (remote_errno
);
7438 file
= fopen (local_file
, "wb");
7440 perror_with_name (local_file
);
7441 back_to
= make_cleanup (fclose_cleanup
, file
);
7443 /* Send up to this many bytes at once. They won't all fit in the
7444 remote packet limit, so we'll transfer slightly fewer. */
7445 io_size
= get_remote_packet_size ();
7446 buffer
= xmalloc (io_size
);
7447 make_cleanup (xfree
, buffer
);
7449 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
7454 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
7456 /* Success, but no bytes, means end-of-file. */
7459 remote_hostio_error (remote_errno
);
7463 bytes
= fwrite (buffer
, 1, bytes
, file
);
7465 perror_with_name (local_file
);
7468 discard_cleanups (close_cleanup
);
7469 if (remote_hostio_close (fd
, &remote_errno
))
7470 remote_hostio_error (remote_errno
);
7473 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
7474 do_cleanups (back_to
);
7478 remote_file_delete (const char *remote_file
, int from_tty
)
7480 int retcode
, remote_errno
;
7483 error (_("command can only be used with remote target"));
7485 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
7487 remote_hostio_error (remote_errno
);
7490 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
7494 remote_put_command (char *args
, int from_tty
)
7496 struct cleanup
*back_to
;
7500 error_no_arg (_("file to put"));
7502 argv
= gdb_buildargv (args
);
7503 back_to
= make_cleanup_freeargv (argv
);
7504 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
7505 error (_("Invalid parameters to remote put"));
7507 remote_file_put (argv
[0], argv
[1], from_tty
);
7509 do_cleanups (back_to
);
7513 remote_get_command (char *args
, int from_tty
)
7515 struct cleanup
*back_to
;
7519 error_no_arg (_("file to get"));
7521 argv
= gdb_buildargv (args
);
7522 back_to
= make_cleanup_freeargv (argv
);
7523 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
7524 error (_("Invalid parameters to remote get"));
7526 remote_file_get (argv
[0], argv
[1], from_tty
);
7528 do_cleanups (back_to
);
7532 remote_delete_command (char *args
, int from_tty
)
7534 struct cleanup
*back_to
;
7538 error_no_arg (_("file to delete"));
7540 argv
= gdb_buildargv (args
);
7541 back_to
= make_cleanup_freeargv (argv
);
7542 if (argv
[0] == NULL
|| argv
[1] != NULL
)
7543 error (_("Invalid parameters to remote delete"));
7545 remote_file_delete (argv
[0], from_tty
);
7547 do_cleanups (back_to
);
7551 remote_command (char *args
, int from_tty
)
7553 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
7557 init_remote_ops (void)
7559 remote_ops
.to_shortname
= "remote";
7560 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
7562 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
7563 Specify the serial device it is connected to\n\
7564 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
7565 remote_ops
.to_open
= remote_open
;
7566 remote_ops
.to_close
= remote_close
;
7567 remote_ops
.to_detach
= remote_detach
;
7568 remote_ops
.to_disconnect
= remote_disconnect
;
7569 remote_ops
.to_resume
= remote_resume
;
7570 remote_ops
.to_wait
= remote_wait
;
7571 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
7572 remote_ops
.to_store_registers
= remote_store_registers
;
7573 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
7574 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
7575 remote_ops
.to_files_info
= remote_files_info
;
7576 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
7577 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
7578 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
7579 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
7580 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
7581 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
7582 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
7583 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
7584 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
7585 remote_ops
.to_kill
= remote_kill
;
7586 remote_ops
.to_load
= generic_load
;
7587 remote_ops
.to_mourn_inferior
= remote_mourn
;
7588 remote_ops
.to_thread_alive
= remote_thread_alive
;
7589 remote_ops
.to_find_new_threads
= remote_threads_info
;
7590 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
7591 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
7592 remote_ops
.to_stop
= remote_stop
;
7593 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
7594 remote_ops
.to_rcmd
= remote_rcmd
;
7595 remote_ops
.to_log_command
= serial_log_command
;
7596 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
7597 remote_ops
.to_stratum
= process_stratum
;
7598 remote_ops
.to_has_all_memory
= 1;
7599 remote_ops
.to_has_memory
= 1;
7600 remote_ops
.to_has_stack
= 1;
7601 remote_ops
.to_has_registers
= 1;
7602 remote_ops
.to_has_execution
= 1;
7603 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
7604 remote_ops
.to_magic
= OPS_MAGIC
;
7605 remote_ops
.to_memory_map
= remote_memory_map
;
7606 remote_ops
.to_flash_erase
= remote_flash_erase
;
7607 remote_ops
.to_flash_done
= remote_flash_done
;
7608 remote_ops
.to_read_description
= remote_read_description
;
7609 remote_ops
.to_search_memory
= remote_search_memory
;
7610 remote_ops
.to_can_async_p
= remote_can_async_p
;
7611 remote_ops
.to_is_async_p
= remote_is_async_p
;
7612 remote_ops
.to_async
= remote_async
;
7613 remote_ops
.to_async_mask
= remote_async_mask
;
7614 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
7615 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
7618 /* Set up the extended remote vector by making a copy of the standard
7619 remote vector and adding to it. */
7622 init_extended_remote_ops (void)
7624 extended_remote_ops
= remote_ops
;
7626 extended_remote_ops
.to_shortname
= "extended-remote";
7627 extended_remote_ops
.to_longname
=
7628 "Extended remote serial target in gdb-specific protocol";
7629 extended_remote_ops
.to_doc
=
7630 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
7631 Specify the serial device it is connected to (e.g. /dev/ttya).";
7632 extended_remote_ops
.to_open
= extended_remote_open
;
7633 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
7634 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
7635 extended_remote_ops
.to_detach
= extended_remote_detach
;
7636 extended_remote_ops
.to_attach
= extended_remote_attach
;
7637 extended_remote_ops
.to_kill
= extended_remote_kill
;
7641 remote_can_async_p (void)
7643 if (!target_async_permitted
)
7644 /* We only enable async when the user specifically asks for it. */
7647 /* We're async whenever the serial device is. */
7648 return remote_async_mask_value
&& serial_can_async_p (remote_desc
);
7652 remote_is_async_p (void)
7654 if (!target_async_permitted
)
7655 /* We only enable async when the user specifically asks for it. */
7658 /* We're async whenever the serial device is. */
7659 return remote_async_mask_value
&& serial_is_async_p (remote_desc
);
7662 /* Pass the SERIAL event on and up to the client. One day this code
7663 will be able to delay notifying the client of an event until the
7664 point where an entire packet has been received. */
7666 static void (*async_client_callback
) (enum inferior_event_type event_type
,
7668 static void *async_client_context
;
7669 static serial_event_ftype remote_async_serial_handler
;
7672 remote_async_serial_handler (struct serial
*scb
, void *context
)
7674 /* Don't propogate error information up to the client. Instead let
7675 the client find out about the error by querying the target. */
7676 async_client_callback (INF_REG_EVENT
, async_client_context
);
7680 remote_async (void (*callback
) (enum inferior_event_type event_type
,
7681 void *context
), void *context
)
7683 if (remote_async_mask_value
== 0)
7684 internal_error (__FILE__
, __LINE__
,
7685 _("Calling remote_async when async is masked"));
7687 if (callback
!= NULL
)
7689 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
7690 async_client_callback
= callback
;
7691 async_client_context
= context
;
7694 serial_async (remote_desc
, NULL
, NULL
);
7698 remote_async_mask (int new_mask
)
7700 int curr_mask
= remote_async_mask_value
;
7701 remote_async_mask_value
= new_mask
;
7706 set_remote_cmd (char *args
, int from_tty
)
7708 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
7712 show_remote_cmd (char *args
, int from_tty
)
7714 /* We can't just use cmd_show_list here, because we want to skip
7715 the redundant "show remote Z-packet" and the legacy aliases. */
7716 struct cleanup
*showlist_chain
;
7717 struct cmd_list_element
*list
= remote_show_cmdlist
;
7719 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
7720 for (; list
!= NULL
; list
= list
->next
)
7721 if (strcmp (list
->name
, "Z-packet") == 0)
7723 else if (list
->type
== not_set_cmd
)
7724 /* Alias commands are exactly like the original, except they
7725 don't have the normal type. */
7729 struct cleanup
*option_chain
7730 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
7731 ui_out_field_string (uiout
, "name", list
->name
);
7732 ui_out_text (uiout
, ": ");
7733 if (list
->type
== show_cmd
)
7734 do_setshow_command ((char *) NULL
, from_tty
, list
);
7736 cmd_func (list
, NULL
, from_tty
);
7737 /* Close the tuple. */
7738 do_cleanups (option_chain
);
7741 /* Close the tuple. */
7742 do_cleanups (showlist_chain
);
7746 /* Function to be called whenever a new objfile (shlib) is detected. */
7748 remote_new_objfile (struct objfile
*objfile
)
7750 if (remote_desc
!= 0) /* Have a remote connection. */
7751 remote_check_symbols (objfile
);
7755 _initialize_remote (void)
7757 struct remote_state
*rs
;
7759 /* architecture specific data */
7760 remote_gdbarch_data_handle
=
7761 gdbarch_data_register_post_init (init_remote_state
);
7762 remote_g_packet_data_handle
=
7763 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
7765 /* Initialize the per-target state. At the moment there is only one
7766 of these, not one per target. Only one target is active at a
7767 time. The default buffer size is unimportant; it will be expanded
7768 whenever a larger buffer is needed. */
7769 rs
= get_remote_state_raw ();
7771 rs
->buf
= xmalloc (rs
->buf_size
);
7774 add_target (&remote_ops
);
7776 init_extended_remote_ops ();
7777 add_target (&extended_remote_ops
);
7779 /* Hook into new objfile notification. */
7780 observer_attach_new_objfile (remote_new_objfile
);
7782 /* Set up signal handlers. */
7783 sigint_remote_token
=
7784 create_async_signal_handler (async_remote_interrupt
, NULL
);
7785 sigint_remote_twice_token
=
7786 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
7789 init_remote_threadtests ();
7792 /* set/show remote ... */
7794 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
7795 Remote protocol specific variables\n\
7796 Configure various remote-protocol specific variables such as\n\
7797 the packets being used"),
7798 &remote_set_cmdlist
, "set remote ",
7799 0 /* allow-unknown */, &setlist
);
7800 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
7801 Remote protocol specific variables\n\
7802 Configure various remote-protocol specific variables such as\n\
7803 the packets being used"),
7804 &remote_show_cmdlist
, "show remote ",
7805 0 /* allow-unknown */, &showlist
);
7807 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
7808 Compare section data on target to the exec file.\n\
7809 Argument is a single section name (default: all loaded sections)."),
7812 add_cmd ("packet", class_maintenance
, packet_command
, _("\
7813 Send an arbitrary packet to a remote target.\n\
7814 maintenance packet TEXT\n\
7815 If GDB is talking to an inferior via the GDB serial protocol, then\n\
7816 this command sends the string TEXT to the inferior, and displays the\n\
7817 response packet. GDB supplies the initial `$' character, and the\n\
7818 terminating `#' character and checksum."),
7821 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
7822 Set whether to send break if interrupted."), _("\
7823 Show whether to send break if interrupted."), _("\
7824 If set, a break, instead of a cntrl-c, is sent to the remote target."),
7825 NULL
, NULL
, /* FIXME: i18n: Whether to send break if interrupted is %s. */
7826 &setlist
, &showlist
);
7828 /* Install commands for configuring memory read/write packets. */
7830 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
7831 Set the maximum number of bytes per memory write packet (deprecated)."),
7833 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
7834 Show the maximum number of bytes per memory write packet (deprecated)."),
7836 add_cmd ("memory-write-packet-size", no_class
,
7837 set_memory_write_packet_size
, _("\
7838 Set the maximum number of bytes per memory-write packet.\n\
7839 Specify the number of bytes in a packet or 0 (zero) for the\n\
7840 default packet size. The actual limit is further reduced\n\
7841 dependent on the target. Specify ``fixed'' to disable the\n\
7842 further restriction and ``limit'' to enable that restriction."),
7843 &remote_set_cmdlist
);
7844 add_cmd ("memory-read-packet-size", no_class
,
7845 set_memory_read_packet_size
, _("\
7846 Set the maximum number of bytes per memory-read packet.\n\
7847 Specify the number of bytes in a packet or 0 (zero) for the\n\
7848 default packet size. The actual limit is further reduced\n\
7849 dependent on the target. Specify ``fixed'' to disable the\n\
7850 further restriction and ``limit'' to enable that restriction."),
7851 &remote_set_cmdlist
);
7852 add_cmd ("memory-write-packet-size", no_class
,
7853 show_memory_write_packet_size
,
7854 _("Show the maximum number of bytes per memory-write packet."),
7855 &remote_show_cmdlist
);
7856 add_cmd ("memory-read-packet-size", no_class
,
7857 show_memory_read_packet_size
,
7858 _("Show the maximum number of bytes per memory-read packet."),
7859 &remote_show_cmdlist
);
7861 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
7862 &remote_hw_watchpoint_limit
, _("\
7863 Set the maximum number of target hardware watchpoints."), _("\
7864 Show the maximum number of target hardware watchpoints."), _("\
7865 Specify a negative limit for unlimited."),
7866 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */
7867 &remote_set_cmdlist
, &remote_show_cmdlist
);
7868 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
7869 &remote_hw_breakpoint_limit
, _("\
7870 Set the maximum number of target hardware breakpoints."), _("\
7871 Show the maximum number of target hardware breakpoints."), _("\
7872 Specify a negative limit for unlimited."),
7873 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */
7874 &remote_set_cmdlist
, &remote_show_cmdlist
);
7876 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
7877 &remote_address_size
, _("\
7878 Set the maximum size of the address (in bits) in a memory packet."), _("\
7879 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
7881 NULL
, /* FIXME: i18n: */
7882 &setlist
, &showlist
);
7884 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
7885 "X", "binary-download", 1);
7887 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
7888 "vCont", "verbose-resume", 0);
7890 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
7891 "QPassSignals", "pass-signals", 0);
7893 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
7894 "qSymbol", "symbol-lookup", 0);
7896 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
7897 "P", "set-register", 1);
7899 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
7900 "p", "fetch-register", 1);
7902 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
7903 "Z0", "software-breakpoint", 0);
7905 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
7906 "Z1", "hardware-breakpoint", 0);
7908 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
7909 "Z2", "write-watchpoint", 0);
7911 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
7912 "Z3", "read-watchpoint", 0);
7914 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
7915 "Z4", "access-watchpoint", 0);
7917 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
7918 "qXfer:auxv:read", "read-aux-vector", 0);
7920 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
7921 "qXfer:features:read", "target-features", 0);
7923 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
7924 "qXfer:libraries:read", "library-info", 0);
7926 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
7927 "qXfer:memory-map:read", "memory-map", 0);
7929 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
7930 "qXfer:spu:read", "read-spu-object", 0);
7932 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
7933 "qXfer:spu:write", "write-spu-object", 0);
7935 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
7936 "qGetTLSAddr", "get-thread-local-storage-address",
7939 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
7940 "qSupported", "supported-packets", 0);
7942 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
7943 "qSearch:memory", "search-memory", 0);
7945 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
7946 "vFile:open", "hostio-open", 0);
7948 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
7949 "vFile:pread", "hostio-pread", 0);
7951 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
7952 "vFile:pwrite", "hostio-pwrite", 0);
7954 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
7955 "vFile:close", "hostio-close", 0);
7957 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
7958 "vFile:unlink", "hostio-unlink", 0);
7960 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
7961 "vAttach", "attach", 0);
7963 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
7966 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
7967 "QStartNoAckMode", "noack", 0);
7969 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
7970 "vKill", "kill", 0);
7972 /* Keep the old ``set remote Z-packet ...'' working. Each individual
7973 Z sub-packet has its own set and show commands, but users may
7974 have sets to this variable in their .gdbinit files (or in their
7976 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
7977 &remote_Z_packet_detect
, _("\
7978 Set use of remote protocol `Z' packets"), _("\
7979 Show use of remote protocol `Z' packets "), _("\
7980 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
7982 set_remote_protocol_Z_packet_cmd
,
7983 show_remote_protocol_Z_packet_cmd
, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */
7984 &remote_set_cmdlist
, &remote_show_cmdlist
);
7986 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
7987 Manipulate files on the remote system\n\
7988 Transfer files to and from the remote target system."),
7989 &remote_cmdlist
, "remote ",
7990 0 /* allow-unknown */, &cmdlist
);
7992 add_cmd ("put", class_files
, remote_put_command
,
7993 _("Copy a local file to the remote system."),
7996 add_cmd ("get", class_files
, remote_get_command
,
7997 _("Copy a remote file to the local system."),
8000 add_cmd ("delete", class_files
, remote_delete_command
,
8001 _("Delete a remote file."),
8004 remote_exec_file
= xstrdup ("");
8005 add_setshow_string_noescape_cmd ("exec-file", class_files
,
8006 &remote_exec_file
, _("\
8007 Set the remote pathname for \"run\""), _("\
8008 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
8009 &remote_set_cmdlist
, &remote_show_cmdlist
);
8011 /* Eventually initialize fileio. See fileio.c */
8012 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
8014 /* Take advantage of the fact that the LWP field is not used, to tag
8015 special ptids with it set to != 0. */
8016 magic_null_ptid
= ptid_build (42000, 1, -1);
8017 not_sent_ptid
= ptid_build (42000, 1, -2);
8018 any_thread_ptid
= ptid_build (42000, 1, 0);