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, 2009,
5 2010 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* See the GDB User Guide for details of the GDB remote protocol. */
25 #include "gdb_string.h"
31 #include "exceptions.h"
33 /*#include "terminal.h" */
36 #include "gdb-stabs.h"
37 #include "gdbthread.h"
41 #include "gdb_assert.h"
44 #include "cli/cli-decode.h"
45 #include "cli/cli-setshow.h"
46 #include "target-descriptions.h"
51 #include "event-loop.h"
52 #include "event-top.h"
58 #include "gdbcore.h" /* for exec_bfd */
60 #include "remote-fileio.h"
61 #include "gdb/fileio.h"
63 #include "xml-support.h"
65 #include "memory-map.h"
67 #include "tracepoint.h"
71 /* temp hacks for tracepoint encoding migration */
72 static char *target_buf
;
73 static long target_buf_size
;
75 encode_actions (struct breakpoint
*t
, char ***tdp_actions
,
76 char ***stepping_actions
);
78 /* The size to align memory write packets, when practical. The protocol
79 does not guarantee any alignment, and gdb will generate short
80 writes and unaligned writes, but even as a best-effort attempt this
81 can improve bulk transfers. For instance, if a write is misaligned
82 relative to the target's data bus, the stub may need to make an extra
83 round trip fetching data from the target. This doesn't make a
84 huge difference, but it's easy to do, so we try to be helpful.
86 The alignment chosen is arbitrary; usually data bus width is
87 important here, not the possibly larger cache line size. */
88 enum { REMOTE_ALIGN_WRITES
= 16 };
90 /* Prototypes for local functions. */
91 static void cleanup_sigint_signal_handler (void *dummy
);
92 static void initialize_sigint_signal_handler (void);
93 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
94 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
97 static void handle_remote_sigint (int);
98 static void handle_remote_sigint_twice (int);
99 static void async_remote_interrupt (gdb_client_data
);
100 void async_remote_interrupt_twice (gdb_client_data
);
102 static void remote_files_info (struct target_ops
*ignore
);
104 static void remote_prepare_to_store (struct regcache
*regcache
);
106 static void remote_open (char *name
, int from_tty
);
108 static void extended_remote_open (char *name
, int from_tty
);
110 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
112 static void remote_close (int quitting
);
114 static void remote_mourn (struct target_ops
*ops
);
116 static void extended_remote_restart (void);
118 static void extended_remote_mourn (struct target_ops
*);
120 static void remote_mourn_1 (struct target_ops
*);
122 static void remote_send (char **buf
, long *sizeof_buf_p
);
124 static int readchar (int timeout
);
126 static void remote_kill (struct target_ops
*ops
);
128 static int tohex (int nib
);
130 static int remote_can_async_p (void);
132 static int remote_is_async_p (void);
134 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
135 void *context
), void *context
);
137 static int remote_async_mask (int new_mask
);
139 static void remote_detach (struct target_ops
*ops
, char *args
, int from_tty
);
141 static void remote_interrupt (int signo
);
143 static void remote_interrupt_twice (int signo
);
145 static void interrupt_query (void);
147 static void set_general_thread (struct ptid ptid
);
148 static void set_continue_thread (struct ptid ptid
);
150 static void get_offsets (void);
152 static void skip_frame (void);
154 static long read_frame (char **buf_p
, long *sizeof_buf
);
156 static int hexnumlen (ULONGEST num
);
158 static void init_remote_ops (void);
160 static void init_extended_remote_ops (void);
162 static void remote_stop (ptid_t
);
164 static int ishex (int ch
, int *val
);
166 static int stubhex (int ch
);
168 static int hexnumstr (char *, ULONGEST
);
170 static int hexnumnstr (char *, ULONGEST
, int);
172 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
174 static void print_packet (char *);
176 static unsigned long crc32 (unsigned char *, int, unsigned int);
178 static void compare_sections_command (char *, int);
180 static void packet_command (char *, int);
182 static int stub_unpack_int (char *buff
, int fieldlength
);
184 static ptid_t
remote_current_thread (ptid_t oldptid
);
186 static void remote_find_new_threads (void);
188 static void record_currthread (ptid_t currthread
);
190 static int fromhex (int a
);
192 extern int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
194 extern int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
196 static int putpkt_binary (char *buf
, int cnt
);
198 static void check_binary_download (CORE_ADDR addr
);
200 struct packet_config
;
202 static void show_packet_config_cmd (struct packet_config
*config
);
204 static void update_packet_config (struct packet_config
*config
);
206 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
207 struct cmd_list_element
*c
);
209 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
211 struct cmd_list_element
*c
,
214 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
215 static ptid_t
read_ptid (char *buf
, char **obuf
);
218 static int remote_get_trace_status (struct trace_status
*ts
);
220 static int remote_upload_tracepoints (struct uploaded_tp
**utpp
);
222 static int remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
);
224 static void remote_query_supported (void);
226 static void remote_check_symbols (struct objfile
*objfile
);
228 void _initialize_remote (void);
231 static struct stop_reply
*stop_reply_xmalloc (void);
232 static void stop_reply_xfree (struct stop_reply
*);
233 static void do_stop_reply_xfree (void *arg
);
234 static void remote_parse_stop_reply (char *buf
, struct stop_reply
*);
235 static void push_stop_reply (struct stop_reply
*);
236 static void remote_get_pending_stop_replies (void);
237 static void discard_pending_stop_replies (int pid
);
238 static int peek_stop_reply (ptid_t ptid
);
240 static void remote_async_inferior_event_handler (gdb_client_data
);
241 static void remote_async_get_pending_events_handler (gdb_client_data
);
243 static void remote_terminal_ours (void);
245 static int remote_read_description_p (struct target_ops
*target
);
247 /* The non-stop remote protocol provisions for one pending stop reply.
248 This is where we keep it until it is acknowledged. */
250 static struct stop_reply
*pending_stop_reply
= NULL
;
254 static struct cmd_list_element
*remote_cmdlist
;
256 /* For "set remote" and "show remote". */
258 static struct cmd_list_element
*remote_set_cmdlist
;
259 static struct cmd_list_element
*remote_show_cmdlist
;
261 /* Description of the remote protocol state for the currently
262 connected target. This is per-target state, and independent of the
263 selected architecture. */
267 /* A buffer to use for incoming packets, and its current size. The
268 buffer is grown dynamically for larger incoming packets.
269 Outgoing packets may also be constructed in this buffer.
270 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
271 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
276 /* If we negotiated packet size explicitly (and thus can bypass
277 heuristics for the largest packet size that will not overflow
278 a buffer in the stub), this will be set to that packet size.
279 Otherwise zero, meaning to use the guessed size. */
280 long explicit_packet_size
;
282 /* remote_wait is normally called when the target is running and
283 waits for a stop reply packet. But sometimes we need to call it
284 when the target is already stopped. We can send a "?" packet
285 and have remote_wait read the response. Or, if we already have
286 the response, we can stash it in BUF and tell remote_wait to
287 skip calling getpkt. This flag is set when BUF contains a
288 stop reply packet and the target is not waiting. */
289 int cached_wait_status
;
291 /* True, if in no ack mode. That is, neither GDB nor the stub will
292 expect acks from each other. The connection is assumed to be
296 /* True if we're connected in extended remote mode. */
299 /* True if the stub reported support for multi-process
301 int multi_process_aware
;
303 /* True if we resumed the target and we're waiting for the target to
304 stop. In the mean time, we can't start another command/query.
305 The remote server wouldn't be ready to process it, so we'd
306 timeout waiting for a reply that would never come and eventually
307 we'd close the connection. This can happen in asynchronous mode
308 because we allow GDB commands while the target is running. */
309 int waiting_for_stop_reply
;
311 /* True if the stub reports support for non-stop mode. */
314 /* True if the stub reports support for vCont;t. */
317 /* True if the stub reports support for conditional tracepoints. */
318 int cond_tracepoints
;
320 /* True if the stub reports support for fast tracepoints. */
321 int fast_tracepoints
;
323 /* True if the stub can continue running a trace while GDB is
325 int disconnected_tracing
;
327 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
328 responded to that. */
332 /* Private data that we'll store in (struct thread_info)->private. */
333 struct private_thread_info
340 free_private_thread_info (struct private_thread_info
*info
)
346 /* Returns true if the multi-process extensions are in effect. */
348 remote_multi_process_p (struct remote_state
*rs
)
350 return rs
->extended
&& rs
->multi_process_aware
;
353 /* This data could be associated with a target, but we do not always
354 have access to the current target when we need it, so for now it is
355 static. This will be fine for as long as only one target is in use
357 static struct remote_state remote_state
;
359 static struct remote_state
*
360 get_remote_state_raw (void)
362 return &remote_state
;
365 /* Description of the remote protocol for a given architecture. */
369 long offset
; /* Offset into G packet. */
370 long regnum
; /* GDB's internal register number. */
371 LONGEST pnum
; /* Remote protocol register number. */
372 int in_g_packet
; /* Always part of G packet. */
373 /* long size in bytes; == register_size (target_gdbarch, regnum);
375 /* char *name; == gdbarch_register_name (target_gdbarch, regnum);
379 struct remote_arch_state
381 /* Description of the remote protocol registers. */
382 long sizeof_g_packet
;
384 /* Description of the remote protocol registers indexed by REGNUM
385 (making an array gdbarch_num_regs in size). */
386 struct packet_reg
*regs
;
388 /* This is the size (in chars) of the first response to the ``g''
389 packet. It is used as a heuristic when determining the maximum
390 size of memory-read and memory-write packets. A target will
391 typically only reserve a buffer large enough to hold the ``g''
392 packet. The size does not include packet overhead (headers and
394 long actual_register_packet_size
;
396 /* This is the maximum size (in chars) of a non read/write packet.
397 It is also used as a cap on the size of read/write packets. */
398 long remote_packet_size
;
401 long sizeof_pkt
= 2000;
403 /* Utility: generate error from an incoming stub packet. */
405 trace_error (char *buf
)
408 return; /* not an error msg */
411 case '1': /* malformed packet error */
412 if (*++buf
== '0') /* general case: */
413 error (_("remote.c: error in outgoing packet."));
415 error (_("remote.c: error in outgoing packet at field #%ld."),
416 strtol (buf
, NULL
, 16));
418 error (_("trace API error 0x%s."), ++buf
);
420 error (_("Target returns error code '%s'."), buf
);
424 /* Utility: wait for reply from stub, while accepting "O" packets. */
426 remote_get_noisy_reply (char **buf_p
,
429 do /* Loop on reply from remote stub. */
432 QUIT
; /* allow user to bail out with ^C */
433 getpkt (buf_p
, sizeof_buf
, 0);
436 error (_("Target does not support this command."));
437 else if (buf
[0] == 'E')
439 else if (buf
[0] == 'O' &&
441 remote_console_output (buf
+ 1); /* 'O' message from stub */
443 return buf
; /* here's the actual reply */
448 /* Handle for retreving the remote protocol data from gdbarch. */
449 static struct gdbarch_data
*remote_gdbarch_data_handle
;
451 static struct remote_arch_state
*
452 get_remote_arch_state (void)
454 return gdbarch_data (target_gdbarch
, remote_gdbarch_data_handle
);
457 /* Fetch the global remote target state. */
459 static struct remote_state
*
460 get_remote_state (void)
462 /* Make sure that the remote architecture state has been
463 initialized, because doing so might reallocate rs->buf. Any
464 function which calls getpkt also needs to be mindful of changes
465 to rs->buf, but this call limits the number of places which run
467 get_remote_arch_state ();
469 return get_remote_state_raw ();
473 compare_pnums (const void *lhs_
, const void *rhs_
)
475 const struct packet_reg
* const *lhs
= lhs_
;
476 const struct packet_reg
* const *rhs
= rhs_
;
478 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
480 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
487 init_remote_state (struct gdbarch
*gdbarch
)
489 int regnum
, num_remote_regs
, offset
;
490 struct remote_state
*rs
= get_remote_state_raw ();
491 struct remote_arch_state
*rsa
;
492 struct packet_reg
**remote_regs
;
494 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
496 /* Use the architecture to build a regnum<->pnum table, which will be
497 1:1 unless a feature set specifies otherwise. */
498 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
499 gdbarch_num_regs (gdbarch
),
501 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
503 struct packet_reg
*r
= &rsa
->regs
[regnum
];
505 if (register_size (gdbarch
, regnum
) == 0)
506 /* Do not try to fetch zero-sized (placeholder) registers. */
509 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
514 /* Define the g/G packet format as the contents of each register
515 with a remote protocol number, in order of ascending protocol
518 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
519 * sizeof (struct packet_reg
*));
520 for (num_remote_regs
= 0, regnum
= 0;
521 regnum
< gdbarch_num_regs (gdbarch
);
523 if (rsa
->regs
[regnum
].pnum
!= -1)
524 remote_regs
[num_remote_regs
++] = &rsa
->regs
[regnum
];
526 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
529 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
531 remote_regs
[regnum
]->in_g_packet
= 1;
532 remote_regs
[regnum
]->offset
= offset
;
533 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
536 /* Record the maximum possible size of the g packet - it may turn out
538 rsa
->sizeof_g_packet
= offset
;
540 /* Default maximum number of characters in a packet body. Many
541 remote stubs have a hardwired buffer size of 400 bytes
542 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
543 as the maximum packet-size to ensure that the packet and an extra
544 NUL character can always fit in the buffer. This stops GDB
545 trashing stubs that try to squeeze an extra NUL into what is
546 already a full buffer (As of 1999-12-04 that was most stubs). */
547 rsa
->remote_packet_size
= 400 - 1;
549 /* This one is filled in when a ``g'' packet is received. */
550 rsa
->actual_register_packet_size
= 0;
552 /* Should rsa->sizeof_g_packet needs more space than the
553 default, adjust the size accordingly. Remember that each byte is
554 encoded as two characters. 32 is the overhead for the packet
555 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
556 (``$NN:G...#NN'') is a better guess, the below has been padded a
558 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
559 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
561 /* Make sure that the packet buffer is plenty big enough for
562 this architecture. */
563 if (rs
->buf_size
< rsa
->remote_packet_size
)
565 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
566 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
572 /* Return the current allowed size of a remote packet. This is
573 inferred from the current architecture, and should be used to
574 limit the length of outgoing packets. */
576 get_remote_packet_size (void)
578 struct remote_state
*rs
= get_remote_state ();
579 struct remote_arch_state
*rsa
= get_remote_arch_state ();
581 if (rs
->explicit_packet_size
)
582 return rs
->explicit_packet_size
;
584 return rsa
->remote_packet_size
;
587 static struct packet_reg
*
588 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
590 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch
))
594 struct packet_reg
*r
= &rsa
->regs
[regnum
];
595 gdb_assert (r
->regnum
== regnum
);
600 static struct packet_reg
*
601 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
604 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch
); i
++)
606 struct packet_reg
*r
= &rsa
->regs
[i
];
613 /* FIXME: graces/2002-08-08: These variables should eventually be
614 bound to an instance of the target object (as in gdbarch-tdep()),
615 when such a thing exists. */
617 /* This is set to the data address of the access causing the target
618 to stop for a watchpoint. */
619 static CORE_ADDR remote_watch_data_address
;
621 /* This is non-zero if target stopped for a watchpoint. */
622 static int remote_stopped_by_watchpoint_p
;
624 static struct target_ops remote_ops
;
626 static struct target_ops extended_remote_ops
;
628 static int remote_async_mask_value
= 1;
630 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
631 ``forever'' still use the normal timeout mechanism. This is
632 currently used by the ASYNC code to guarentee that target reads
633 during the initial connect always time-out. Once getpkt has been
634 modified to return a timeout indication and, in turn
635 remote_wait()/wait_for_inferior() have gained a timeout parameter
637 static int wait_forever_enabled_p
= 1;
639 /* Allow the user to specify what sequence to send to the remote
640 when he requests a program interruption: Although ^C is usually
641 what remote systems expect (this is the default, here), it is
642 sometimes preferable to send a break. On other systems such
643 as the Linux kernel, a break followed by g, which is Magic SysRq g
644 is required in order to interrupt the execution. */
645 const char interrupt_sequence_control_c
[] = "Ctrl-C";
646 const char interrupt_sequence_break
[] = "BREAK";
647 const char interrupt_sequence_break_g
[] = "BREAK-g";
648 static const char *interrupt_sequence_modes
[] =
650 interrupt_sequence_control_c
,
651 interrupt_sequence_break
,
652 interrupt_sequence_break_g
,
655 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
658 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
659 struct cmd_list_element
*c
,
662 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
663 fprintf_filtered (file
,
664 _("Send the ASCII ETX character (Ctrl-c) "
665 "to the remote target to interrupt the "
666 "execution of the program.\n"));
667 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
668 fprintf_filtered (file
,
669 _("send a break signal to the remote target "
670 "to interrupt the execution of the program.\n"));
671 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
672 fprintf_filtered (file
,
673 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
674 "the remote target to interrupt the execution "
675 "of Linux kernel.\n"));
677 internal_error (__FILE__
, __LINE__
,
678 _("Invalid value for interrupt_sequence_mode: %s."),
679 interrupt_sequence_mode
);
682 /* This boolean variable specifies whether interrupt_sequence is sent
683 to the remote target when gdb connects to it.
684 This is mostly needed when you debug the Linux kernel: The Linux kernel
685 expects BREAK g which is Magic SysRq g for connecting gdb. */
686 static int interrupt_on_connect
= 0;
688 /* This variable is used to implement the "set/show remotebreak" commands.
689 Since these commands are now deprecated in favor of "set/show remote
690 interrupt-sequence", it no longer has any effect on the code. */
691 static int remote_break
;
694 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
697 interrupt_sequence_mode
= interrupt_sequence_break
;
699 interrupt_sequence_mode
= interrupt_sequence_control_c
;
703 show_remotebreak (struct ui_file
*file
, int from_tty
,
704 struct cmd_list_element
*c
,
709 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
710 remote_open knows that we don't have a file open when the program
712 static struct serial
*remote_desc
= NULL
;
714 /* This variable sets the number of bits in an address that are to be
715 sent in a memory ("M" or "m") packet. Normally, after stripping
716 leading zeros, the entire address would be sent. This variable
717 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
718 initial implementation of remote.c restricted the address sent in
719 memory packets to ``host::sizeof long'' bytes - (typically 32
720 bits). Consequently, for 64 bit targets, the upper 32 bits of an
721 address was never sent. Since fixing this bug may cause a break in
722 some remote targets this variable is principly provided to
723 facilitate backward compatibility. */
725 static int remote_address_size
;
727 /* Temporary to track who currently owns the terminal. See
728 remote_terminal_* for more details. */
730 static int remote_async_terminal_ours_p
;
732 /* The executable file to use for "run" on the remote side. */
734 static char *remote_exec_file
= "";
737 /* User configurable variables for the number of characters in a
738 memory read/write packet. MIN (rsa->remote_packet_size,
739 rsa->sizeof_g_packet) is the default. Some targets need smaller
740 values (fifo overruns, et.al.) and some users need larger values
741 (speed up transfers). The variables ``preferred_*'' (the user
742 request), ``current_*'' (what was actually set) and ``forced_*''
743 (Positive - a soft limit, negative - a hard limit). */
745 struct memory_packet_config
752 /* Compute the current size of a read/write packet. Since this makes
753 use of ``actual_register_packet_size'' the computation is dynamic. */
756 get_memory_packet_size (struct memory_packet_config
*config
)
758 struct remote_state
*rs
= get_remote_state ();
759 struct remote_arch_state
*rsa
= get_remote_arch_state ();
761 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
762 law?) that some hosts don't cope very well with large alloca()
763 calls. Eventually the alloca() code will be replaced by calls to
764 xmalloc() and make_cleanups() allowing this restriction to either
765 be lifted or removed. */
766 #ifndef MAX_REMOTE_PACKET_SIZE
767 #define MAX_REMOTE_PACKET_SIZE 16384
769 /* NOTE: 20 ensures we can write at least one byte. */
770 #ifndef MIN_REMOTE_PACKET_SIZE
771 #define MIN_REMOTE_PACKET_SIZE 20
776 if (config
->size
<= 0)
777 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
779 what_they_get
= config
->size
;
783 what_they_get
= get_remote_packet_size ();
784 /* Limit the packet to the size specified by the user. */
786 && what_they_get
> config
->size
)
787 what_they_get
= config
->size
;
789 /* Limit it to the size of the targets ``g'' response unless we have
790 permission from the stub to use a larger packet size. */
791 if (rs
->explicit_packet_size
== 0
792 && rsa
->actual_register_packet_size
> 0
793 && what_they_get
> rsa
->actual_register_packet_size
)
794 what_they_get
= rsa
->actual_register_packet_size
;
796 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
797 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
798 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
799 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
801 /* Make sure there is room in the global buffer for this packet
802 (including its trailing NUL byte). */
803 if (rs
->buf_size
< what_they_get
+ 1)
805 rs
->buf_size
= 2 * what_they_get
;
806 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
809 return what_they_get
;
812 /* Update the size of a read/write packet. If they user wants
813 something really big then do a sanity check. */
816 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
818 int fixed_p
= config
->fixed_p
;
819 long size
= config
->size
;
821 error (_("Argument required (integer, `fixed' or `limited')."));
822 else if (strcmp (args
, "hard") == 0
823 || strcmp (args
, "fixed") == 0)
825 else if (strcmp (args
, "soft") == 0
826 || strcmp (args
, "limit") == 0)
831 size
= strtoul (args
, &end
, 0);
833 error (_("Invalid %s (bad syntax)."), config
->name
);
835 /* Instead of explicitly capping the size of a packet to
836 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
837 instead allowed to set the size to something arbitrarily
839 if (size
> MAX_REMOTE_PACKET_SIZE
)
840 error (_("Invalid %s (too large)."), config
->name
);
844 if (fixed_p
&& !config
->fixed_p
)
846 if (! query (_("The target may not be able to correctly handle a %s\n"
847 "of %ld bytes. Change the packet size? "),
849 error (_("Packet size not changed."));
851 /* Update the config. */
852 config
->fixed_p
= fixed_p
;
857 show_memory_packet_size (struct memory_packet_config
*config
)
859 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
861 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
862 get_memory_packet_size (config
));
864 printf_filtered (_("Packets are limited to %ld bytes.\n"),
865 get_memory_packet_size (config
));
868 static struct memory_packet_config memory_write_packet_config
=
870 "memory-write-packet-size",
874 set_memory_write_packet_size (char *args
, int from_tty
)
876 set_memory_packet_size (args
, &memory_write_packet_config
);
880 show_memory_write_packet_size (char *args
, int from_tty
)
882 show_memory_packet_size (&memory_write_packet_config
);
886 get_memory_write_packet_size (void)
888 return get_memory_packet_size (&memory_write_packet_config
);
891 static struct memory_packet_config memory_read_packet_config
=
893 "memory-read-packet-size",
897 set_memory_read_packet_size (char *args
, int from_tty
)
899 set_memory_packet_size (args
, &memory_read_packet_config
);
903 show_memory_read_packet_size (char *args
, int from_tty
)
905 show_memory_packet_size (&memory_read_packet_config
);
909 get_memory_read_packet_size (void)
911 long size
= get_memory_packet_size (&memory_read_packet_config
);
912 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
913 extra buffer size argument before the memory read size can be
914 increased beyond this. */
915 if (size
> get_remote_packet_size ())
916 size
= get_remote_packet_size ();
921 /* Generic configuration support for packets the stub optionally
922 supports. Allows the user to specify the use of the packet as well
923 as allowing GDB to auto-detect support in the remote stub. */
927 PACKET_SUPPORT_UNKNOWN
= 0,
936 enum auto_boolean detect
;
937 enum packet_support support
;
940 /* Analyze a packet's return value and update the packet config
951 update_packet_config (struct packet_config
*config
)
953 switch (config
->detect
)
955 case AUTO_BOOLEAN_TRUE
:
956 config
->support
= PACKET_ENABLE
;
958 case AUTO_BOOLEAN_FALSE
:
959 config
->support
= PACKET_DISABLE
;
961 case AUTO_BOOLEAN_AUTO
:
962 config
->support
= PACKET_SUPPORT_UNKNOWN
;
968 show_packet_config_cmd (struct packet_config
*config
)
970 char *support
= "internal-error";
971 switch (config
->support
)
977 support
= "disabled";
979 case PACKET_SUPPORT_UNKNOWN
:
983 switch (config
->detect
)
985 case AUTO_BOOLEAN_AUTO
:
986 printf_filtered (_("Support for the `%s' packet is auto-detected, currently %s.\n"),
987 config
->name
, support
);
989 case AUTO_BOOLEAN_TRUE
:
990 case AUTO_BOOLEAN_FALSE
:
991 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
992 config
->name
, support
);
998 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
999 const char *title
, int legacy
)
1005 config
->name
= name
;
1006 config
->title
= title
;
1007 config
->detect
= AUTO_BOOLEAN_AUTO
;
1008 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1009 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1011 show_doc
= xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
1013 /* set/show TITLE-packet {auto,on,off} */
1014 cmd_name
= xstrprintf ("%s-packet", title
);
1015 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1016 &config
->detect
, set_doc
, show_doc
, NULL
, /* help_doc */
1017 set_remote_protocol_packet_cmd
,
1018 show_remote_protocol_packet_cmd
,
1019 &remote_set_cmdlist
, &remote_show_cmdlist
);
1020 /* The command code copies the documentation strings. */
1023 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1027 legacy_name
= xstrprintf ("%s-packet", name
);
1028 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1029 &remote_set_cmdlist
);
1030 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1031 &remote_show_cmdlist
);
1035 static enum packet_result
1036 packet_check_result (const char *buf
)
1040 /* The stub recognized the packet request. Check that the
1041 operation succeeded. */
1043 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1045 /* "Enn" - definitly an error. */
1046 return PACKET_ERROR
;
1048 /* Always treat "E." as an error. This will be used for
1049 more verbose error messages, such as E.memtypes. */
1050 if (buf
[0] == 'E' && buf
[1] == '.')
1051 return PACKET_ERROR
;
1053 /* The packet may or may not be OK. Just assume it is. */
1057 /* The stub does not support the packet. */
1058 return PACKET_UNKNOWN
;
1061 static enum packet_result
1062 packet_ok (const char *buf
, struct packet_config
*config
)
1064 enum packet_result result
;
1066 result
= packet_check_result (buf
);
1071 /* The stub recognized the packet request. */
1072 switch (config
->support
)
1074 case PACKET_SUPPORT_UNKNOWN
:
1076 fprintf_unfiltered (gdb_stdlog
,
1077 "Packet %s (%s) is supported\n",
1078 config
->name
, config
->title
);
1079 config
->support
= PACKET_ENABLE
;
1081 case PACKET_DISABLE
:
1082 internal_error (__FILE__
, __LINE__
,
1083 _("packet_ok: attempt to use a disabled packet"));
1089 case PACKET_UNKNOWN
:
1090 /* The stub does not support the packet. */
1091 switch (config
->support
)
1094 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1095 /* If the stub previously indicated that the packet was
1096 supported then there is a protocol error.. */
1097 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1098 config
->name
, config
->title
);
1100 /* The user set it wrong. */
1101 error (_("Enabled packet %s (%s) not recognized by stub"),
1102 config
->name
, config
->title
);
1104 case PACKET_SUPPORT_UNKNOWN
:
1106 fprintf_unfiltered (gdb_stdlog
,
1107 "Packet %s (%s) is NOT supported\n",
1108 config
->name
, config
->title
);
1109 config
->support
= PACKET_DISABLE
;
1111 case PACKET_DISABLE
:
1133 PACKET_vFile_pwrite
,
1135 PACKET_vFile_unlink
,
1137 PACKET_qXfer_features
,
1138 PACKET_qXfer_libraries
,
1139 PACKET_qXfer_memory_map
,
1140 PACKET_qXfer_spu_read
,
1141 PACKET_qXfer_spu_write
,
1142 PACKET_qXfer_osdata
,
1143 PACKET_qXfer_threads
,
1146 PACKET_QPassSignals
,
1147 PACKET_qSearch_memory
,
1150 PACKET_QStartNoAckMode
,
1152 PACKET_qXfer_siginfo_read
,
1153 PACKET_qXfer_siginfo_write
,
1155 PACKET_ConditionalTracepoints
,
1156 PACKET_FastTracepoints
,
1162 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1165 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1166 struct cmd_list_element
*c
)
1168 struct packet_config
*packet
;
1170 for (packet
= remote_protocol_packets
;
1171 packet
< &remote_protocol_packets
[PACKET_MAX
];
1174 if (&packet
->detect
== c
->var
)
1176 update_packet_config (packet
);
1180 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
1185 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1186 struct cmd_list_element
*c
,
1189 struct packet_config
*packet
;
1191 for (packet
= remote_protocol_packets
;
1192 packet
< &remote_protocol_packets
[PACKET_MAX
];
1195 if (&packet
->detect
== c
->var
)
1197 show_packet_config_cmd (packet
);
1201 internal_error (__FILE__
, __LINE__
, "Could not find config for %s",
1205 /* Should we try one of the 'Z' requests? */
1209 Z_PACKET_SOFTWARE_BP
,
1210 Z_PACKET_HARDWARE_BP
,
1217 /* For compatibility with older distributions. Provide a ``set remote
1218 Z-packet ...'' command that updates all the Z packet types. */
1220 static enum auto_boolean remote_Z_packet_detect
;
1223 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1224 struct cmd_list_element
*c
)
1227 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1229 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1230 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1235 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1236 struct cmd_list_element
*c
,
1240 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1242 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1246 /* Should we try the 'ThreadInfo' query packet?
1248 This variable (NOT available to the user: auto-detect only!)
1249 determines whether GDB will use the new, simpler "ThreadInfo"
1250 query or the older, more complex syntax for thread queries.
1251 This is an auto-detect variable (set to true at each connect,
1252 and set to false when the target fails to recognize it). */
1254 static int use_threadinfo_query
;
1255 static int use_threadextra_query
;
1257 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1258 static struct async_signal_handler
*sigint_remote_twice_token
;
1259 static struct async_signal_handler
*sigint_remote_token
;
1262 /* Asynchronous signal handle registered as event loop source for
1263 when we have pending events ready to be passed to the core. */
1265 static struct async_event_handler
*remote_async_inferior_event_token
;
1267 /* Asynchronous signal handle registered as event loop source for when
1268 the remote sent us a %Stop notification. The registered callback
1269 will do a vStopped sequence to pull the rest of the events out of
1270 the remote side into our event queue. */
1272 static struct async_event_handler
*remote_async_get_pending_events_token
;
1275 static ptid_t magic_null_ptid
;
1276 static ptid_t not_sent_ptid
;
1277 static ptid_t any_thread_ptid
;
1279 /* These are the threads which we last sent to the remote system. The
1280 TID member will be -1 for all or -2 for not sent yet. */
1282 static ptid_t general_thread
;
1283 static ptid_t continue_thread
;
1285 /* Find out if the stub attached to PID (and hence GDB should offer to
1286 detach instead of killing it when bailing out). */
1289 remote_query_attached (int pid
)
1291 struct remote_state
*rs
= get_remote_state ();
1293 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1296 if (remote_multi_process_p (rs
))
1297 sprintf (rs
->buf
, "qAttached:%x", pid
);
1299 sprintf (rs
->buf
, "qAttached");
1302 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1304 switch (packet_ok (rs
->buf
,
1305 &remote_protocol_packets
[PACKET_qAttached
]))
1308 if (strcmp (rs
->buf
, "1") == 0)
1312 warning (_("Remote failure reply: %s"), rs
->buf
);
1314 case PACKET_UNKNOWN
:
1321 /* Add PID to GDB's inferior table. Since we can be connected to a
1322 remote system before before knowing about any inferior, mark the
1323 target with execution when we find the first inferior. If ATTACHED
1324 is 1, then we had just attached to this inferior. If it is 0, then
1325 we just created this inferior. If it is -1, then try querying the
1326 remote stub to find out if it had attached to the inferior or
1329 static struct inferior
*
1330 remote_add_inferior (int pid
, int attached
)
1332 struct inferior
*inf
;
1334 /* Check whether this process we're learning about is to be
1335 considered attached, or if is to be considered to have been
1336 spawned by the stub. */
1338 attached
= remote_query_attached (pid
);
1340 if (gdbarch_has_global_solist (target_gdbarch
))
1342 /* If the target shares code across all inferiors, then every
1343 attach adds a new inferior. */
1344 inf
= add_inferior (pid
);
1346 /* ... and every inferior is bound to the same program space.
1347 However, each inferior may still have its own address
1349 inf
->aspace
= maybe_new_address_space ();
1350 inf
->pspace
= current_program_space
;
1354 /* In the traditional debugging scenario, there's a 1-1 match
1355 between program/address spaces. We simply bind the inferior
1356 to the program space's address space. */
1357 inf
= current_inferior ();
1358 inferior_appeared (inf
, pid
);
1361 inf
->attach_flag
= attached
;
1366 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1367 according to RUNNING. */
1370 remote_add_thread (ptid_t ptid
, int running
)
1374 set_executing (ptid
, running
);
1375 set_running (ptid
, running
);
1378 /* Come here when we learn about a thread id from the remote target.
1379 It may be the first time we hear about such thread, so take the
1380 opportunity to add it to GDB's thread list. In case this is the
1381 first time we're noticing its corresponding inferior, add it to
1382 GDB's inferior list as well. */
1385 remote_notice_new_inferior (ptid_t currthread
, int running
)
1387 /* If this is a new thread, add it to GDB's thread list.
1388 If we leave it up to WFI to do this, bad things will happen. */
1390 if (in_thread_list (currthread
) && is_exited (currthread
))
1392 /* We're seeing an event on a thread id we knew had exited.
1393 This has to be a new thread reusing the old id. Add it. */
1394 remote_add_thread (currthread
, running
);
1398 if (!in_thread_list (currthread
))
1400 struct inferior
*inf
= NULL
;
1401 int pid
= ptid_get_pid (currthread
);
1403 if (ptid_is_pid (inferior_ptid
)
1404 && pid
== ptid_get_pid (inferior_ptid
))
1406 /* inferior_ptid has no thread member yet. This can happen
1407 with the vAttach -> remote_wait,"TAAthread:" path if the
1408 stub doesn't support qC. This is the first stop reported
1409 after an attach, so this is the main thread. Update the
1410 ptid in the thread list. */
1411 if (in_thread_list (pid_to_ptid (pid
)))
1412 thread_change_ptid (inferior_ptid
, currthread
);
1415 remote_add_thread (currthread
, running
);
1416 inferior_ptid
= currthread
;
1421 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1423 /* inferior_ptid is not set yet. This can happen with the
1424 vRun -> remote_wait,"TAAthread:" path if the stub
1425 doesn't support qC. This is the first stop reported
1426 after an attach, so this is the main thread. Update the
1427 ptid in the thread list. */
1428 thread_change_ptid (inferior_ptid
, currthread
);
1432 /* When connecting to a target remote, or to a target
1433 extended-remote which already was debugging an inferior, we
1434 may not know about it yet. Add it before adding its child
1435 thread, so notifications are emitted in a sensible order. */
1436 if (!in_inferior_list (ptid_get_pid (currthread
)))
1437 inf
= remote_add_inferior (ptid_get_pid (currthread
), -1);
1439 /* This is really a new thread. Add it. */
1440 remote_add_thread (currthread
, running
);
1442 /* If we found a new inferior, let the common code do whatever
1443 it needs to with it (e.g., read shared libraries, insert
1446 notice_new_inferior (currthread
, running
, 0);
1450 /* Return the private thread data, creating it if necessary. */
1452 struct private_thread_info
*
1453 demand_private_info (ptid_t ptid
)
1455 struct thread_info
*info
= find_thread_ptid (ptid
);
1461 info
->private = xmalloc (sizeof (*(info
->private)));
1462 info
->private_dtor
= free_private_thread_info
;
1463 info
->private->core
= -1;
1464 info
->private->extra
= 0;
1467 return info
->private;
1470 /* Call this function as a result of
1471 1) A halt indication (T packet) containing a thread id
1472 2) A direct query of currthread
1473 3) Successful execution of set thread
1477 record_currthread (ptid_t currthread
)
1479 general_thread
= currthread
;
1482 static char *last_pass_packet
;
1484 /* If 'QPassSignals' is supported, tell the remote stub what signals
1485 it can simply pass through to the inferior without reporting. */
1488 remote_pass_signals (void)
1490 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1492 char *pass_packet
, *p
;
1493 int numsigs
= (int) TARGET_SIGNAL_LAST
;
1496 gdb_assert (numsigs
< 256);
1497 for (i
= 0; i
< numsigs
; i
++)
1499 if (signal_stop_state (i
) == 0
1500 && signal_print_state (i
) == 0
1501 && signal_pass_state (i
) == 1)
1504 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1505 strcpy (pass_packet
, "QPassSignals:");
1506 p
= pass_packet
+ strlen (pass_packet
);
1507 for (i
= 0; i
< numsigs
; i
++)
1509 if (signal_stop_state (i
) == 0
1510 && signal_print_state (i
) == 0
1511 && signal_pass_state (i
) == 1)
1514 *p
++ = tohex (i
>> 4);
1515 *p
++ = tohex (i
& 15);
1524 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1526 struct remote_state
*rs
= get_remote_state ();
1527 char *buf
= rs
->buf
;
1529 putpkt (pass_packet
);
1530 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1531 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1532 if (last_pass_packet
)
1533 xfree (last_pass_packet
);
1534 last_pass_packet
= pass_packet
;
1537 xfree (pass_packet
);
1541 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1542 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1543 thread. If GEN is set, set the general thread, if not, then set
1544 the step/continue thread. */
1546 set_thread (struct ptid ptid
, int gen
)
1548 struct remote_state
*rs
= get_remote_state ();
1549 ptid_t state
= gen
? general_thread
: continue_thread
;
1550 char *buf
= rs
->buf
;
1551 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1553 if (ptid_equal (state
, ptid
))
1557 *buf
++ = gen
? 'g' : 'c';
1558 if (ptid_equal (ptid
, magic_null_ptid
))
1559 xsnprintf (buf
, endbuf
- buf
, "0");
1560 else if (ptid_equal (ptid
, any_thread_ptid
))
1561 xsnprintf (buf
, endbuf
- buf
, "0");
1562 else if (ptid_equal (ptid
, minus_one_ptid
))
1563 xsnprintf (buf
, endbuf
- buf
, "-1");
1565 write_ptid (buf
, endbuf
, ptid
);
1567 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1569 general_thread
= ptid
;
1571 continue_thread
= ptid
;
1575 set_general_thread (struct ptid ptid
)
1577 set_thread (ptid
, 1);
1581 set_continue_thread (struct ptid ptid
)
1583 set_thread (ptid
, 0);
1586 /* Change the remote current process. Which thread within the process
1587 ends up selected isn't important, as long as it is the same process
1588 as what INFERIOR_PTID points to.
1590 This comes from that fact that there is no explicit notion of
1591 "selected process" in the protocol. The selected process for
1592 general operations is the process the selected general thread
1596 set_general_process (void)
1598 struct remote_state
*rs
= get_remote_state ();
1600 /* If the remote can't handle multiple processes, don't bother. */
1601 if (!remote_multi_process_p (rs
))
1604 /* We only need to change the remote current thread if it's pointing
1605 at some other process. */
1606 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1607 set_general_thread (inferior_ptid
);
1611 /* Return nonzero if the thread PTID is still alive on the remote
1615 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1617 struct remote_state
*rs
= get_remote_state ();
1620 if (ptid_equal (ptid
, magic_null_ptid
))
1621 /* The main thread is always alive. */
1624 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1625 /* The main thread is always alive. This can happen after a
1626 vAttach, if the remote side doesn't support
1631 endp
= rs
->buf
+ get_remote_packet_size ();
1634 write_ptid (p
, endp
, ptid
);
1637 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1638 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1641 /* About these extended threadlist and threadinfo packets. They are
1642 variable length packets but, the fields within them are often fixed
1643 length. They are redundent enough to send over UDP as is the
1644 remote protocol in general. There is a matching unit test module
1647 #define OPAQUETHREADBYTES 8
1649 /* a 64 bit opaque identifier */
1650 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1652 /* WARNING: This threadref data structure comes from the remote O.S.,
1653 libstub protocol encoding, and remote.c. it is not particularly
1656 /* Right now, the internal structure is int. We want it to be bigger.
1660 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1662 /* gdb_ext_thread_info is an internal GDB data structure which is
1663 equivalent to the reply of the remote threadinfo packet. */
1665 struct gdb_ext_thread_info
1667 threadref threadid
; /* External form of thread reference. */
1668 int active
; /* Has state interesting to GDB?
1670 char display
[256]; /* Brief state display, name,
1671 blocked/suspended. */
1672 char shortname
[32]; /* To be used to name threads. */
1673 char more_display
[256]; /* Long info, statistics, queue depth,
1677 /* The volume of remote transfers can be limited by submitting
1678 a mask containing bits specifying the desired information.
1679 Use a union of these values as the 'selection' parameter to
1680 get_thread_info. FIXME: Make these TAG names more thread specific.
1683 #define TAG_THREADID 1
1684 #define TAG_EXISTS 2
1685 #define TAG_DISPLAY 4
1686 #define TAG_THREADNAME 8
1687 #define TAG_MOREDISPLAY 16
1689 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1691 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1693 static char *unpack_nibble (char *buf
, int *val
);
1695 static char *pack_nibble (char *buf
, int nibble
);
1697 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1699 static char *unpack_byte (char *buf
, int *value
);
1701 static char *pack_int (char *buf
, int value
);
1703 static char *unpack_int (char *buf
, int *value
);
1705 static char *unpack_string (char *src
, char *dest
, int length
);
1707 static char *pack_threadid (char *pkt
, threadref
*id
);
1709 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1711 void int_to_threadref (threadref
*id
, int value
);
1713 static int threadref_to_int (threadref
*ref
);
1715 static void copy_threadref (threadref
*dest
, threadref
*src
);
1717 static int threadmatch (threadref
*dest
, threadref
*src
);
1719 static char *pack_threadinfo_request (char *pkt
, int mode
,
1722 static int remote_unpack_thread_info_response (char *pkt
,
1723 threadref
*expectedref
,
1724 struct gdb_ext_thread_info
1728 static int remote_get_threadinfo (threadref
*threadid
,
1729 int fieldset
, /*TAG mask */
1730 struct gdb_ext_thread_info
*info
);
1732 static char *pack_threadlist_request (char *pkt
, int startflag
,
1734 threadref
*nextthread
);
1736 static int parse_threadlist_response (char *pkt
,
1738 threadref
*original_echo
,
1739 threadref
*resultlist
,
1742 static int remote_get_threadlist (int startflag
,
1743 threadref
*nextthread
,
1747 threadref
*threadlist
);
1749 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1751 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1752 void *context
, int looplimit
);
1754 static int remote_newthread_step (threadref
*ref
, void *context
);
1757 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1758 buffer we're allowed to write to. Returns
1759 BUF+CHARACTERS_WRITTEN. */
1762 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1765 struct remote_state
*rs
= get_remote_state ();
1767 if (remote_multi_process_p (rs
))
1769 pid
= ptid_get_pid (ptid
);
1771 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1773 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1775 tid
= ptid_get_tid (ptid
);
1777 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1779 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1784 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1785 passed the last parsed char. Returns null_ptid on error. */
1788 read_ptid (char *buf
, char **obuf
)
1792 ULONGEST pid
= 0, tid
= 0;
1796 /* Multi-process ptid. */
1797 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1799 error (_("invalid remote ptid: %s\n"), p
);
1802 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1805 return ptid_build (pid
, 0, tid
);
1808 /* No multi-process. Just a tid. */
1809 pp
= unpack_varlen_hex (p
, &tid
);
1811 /* Since the stub is not sending a process id, then default to
1812 what's in inferior_ptid, unless it's null at this point. If so,
1813 then since there's no way to know the pid of the reported
1814 threads, use the magic number. */
1815 if (ptid_equal (inferior_ptid
, null_ptid
))
1816 pid
= ptid_get_pid (magic_null_ptid
);
1818 pid
= ptid_get_pid (inferior_ptid
);
1822 return ptid_build (pid
, 0, tid
);
1825 /* Encode 64 bits in 16 chars of hex. */
1827 static const char hexchars
[] = "0123456789abcdef";
1830 ishex (int ch
, int *val
)
1832 if ((ch
>= 'a') && (ch
<= 'f'))
1834 *val
= ch
- 'a' + 10;
1837 if ((ch
>= 'A') && (ch
<= 'F'))
1839 *val
= ch
- 'A' + 10;
1842 if ((ch
>= '0') && (ch
<= '9'))
1853 if (ch
>= 'a' && ch
<= 'f')
1854 return ch
- 'a' + 10;
1855 if (ch
>= '0' && ch
<= '9')
1857 if (ch
>= 'A' && ch
<= 'F')
1858 return ch
- 'A' + 10;
1863 stub_unpack_int (char *buff
, int fieldlength
)
1870 nibble
= stubhex (*buff
++);
1874 retval
= retval
<< 4;
1880 unpack_varlen_hex (char *buff
, /* packet to parse */
1884 ULONGEST retval
= 0;
1886 while (ishex (*buff
, &nibble
))
1889 retval
= retval
<< 4;
1890 retval
|= nibble
& 0x0f;
1897 unpack_nibble (char *buf
, int *val
)
1899 *val
= fromhex (*buf
++);
1904 pack_nibble (char *buf
, int nibble
)
1906 *buf
++ = hexchars
[(nibble
& 0x0f)];
1911 pack_hex_byte (char *pkt
, int byte
)
1913 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
1914 *pkt
++ = hexchars
[(byte
& 0xf)];
1919 unpack_byte (char *buf
, int *value
)
1921 *value
= stub_unpack_int (buf
, 2);
1926 pack_int (char *buf
, int value
)
1928 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
1929 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
1930 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
1931 buf
= pack_hex_byte (buf
, (value
& 0xff));
1936 unpack_int (char *buf
, int *value
)
1938 *value
= stub_unpack_int (buf
, 8);
1942 #if 0 /* Currently unused, uncomment when needed. */
1943 static char *pack_string (char *pkt
, char *string
);
1946 pack_string (char *pkt
, char *string
)
1951 len
= strlen (string
);
1953 len
= 200; /* Bigger than most GDB packets, junk??? */
1954 pkt
= pack_hex_byte (pkt
, len
);
1958 if ((ch
== '\0') || (ch
== '#'))
1959 ch
= '*'; /* Protect encapsulation. */
1964 #endif /* 0 (unused) */
1967 unpack_string (char *src
, char *dest
, int length
)
1976 pack_threadid (char *pkt
, threadref
*id
)
1979 unsigned char *altid
;
1981 altid
= (unsigned char *) id
;
1982 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
1984 pkt
= pack_hex_byte (pkt
, *altid
++);
1990 unpack_threadid (char *inbuf
, threadref
*id
)
1993 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
1996 altref
= (char *) id
;
1998 while (inbuf
< limit
)
2000 x
= stubhex (*inbuf
++);
2001 y
= stubhex (*inbuf
++);
2002 *altref
++ = (x
<< 4) | y
;
2007 /* Externally, threadrefs are 64 bits but internally, they are still
2008 ints. This is due to a mismatch of specifications. We would like
2009 to use 64bit thread references internally. This is an adapter
2013 int_to_threadref (threadref
*id
, int value
)
2015 unsigned char *scan
;
2017 scan
= (unsigned char *) id
;
2023 *scan
++ = (value
>> 24) & 0xff;
2024 *scan
++ = (value
>> 16) & 0xff;
2025 *scan
++ = (value
>> 8) & 0xff;
2026 *scan
++ = (value
& 0xff);
2030 threadref_to_int (threadref
*ref
)
2033 unsigned char *scan
;
2039 value
= (value
<< 8) | ((*scan
++) & 0xff);
2044 copy_threadref (threadref
*dest
, threadref
*src
)
2047 unsigned char *csrc
, *cdest
;
2049 csrc
= (unsigned char *) src
;
2050 cdest
= (unsigned char *) dest
;
2057 threadmatch (threadref
*dest
, threadref
*src
)
2059 /* Things are broken right now, so just assume we got a match. */
2061 unsigned char *srcp
, *destp
;
2063 srcp
= (char *) src
;
2064 destp
= (char *) dest
;
2068 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2075 threadid:1, # always request threadid
2082 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2085 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2087 *pkt
++ = 'q'; /* Info Query */
2088 *pkt
++ = 'P'; /* process or thread info */
2089 pkt
= pack_int (pkt
, mode
); /* mode */
2090 pkt
= pack_threadid (pkt
, id
); /* threadid */
2091 *pkt
= '\0'; /* terminate */
2095 /* These values tag the fields in a thread info response packet. */
2096 /* Tagging the fields allows us to request specific fields and to
2097 add more fields as time goes by. */
2099 #define TAG_THREADID 1 /* Echo the thread identifier. */
2100 #define TAG_EXISTS 2 /* Is this process defined enough to
2101 fetch registers and its stack? */
2102 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2103 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2104 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2108 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2109 struct gdb_ext_thread_info
*info
)
2111 struct remote_state
*rs
= get_remote_state ();
2115 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2118 /* info->threadid = 0; FIXME: implement zero_threadref. */
2120 info
->display
[0] = '\0';
2121 info
->shortname
[0] = '\0';
2122 info
->more_display
[0] = '\0';
2124 /* Assume the characters indicating the packet type have been
2126 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2127 pkt
= unpack_threadid (pkt
, &ref
);
2130 warning (_("Incomplete response to threadinfo request."));
2131 if (!threadmatch (&ref
, expectedref
))
2132 { /* This is an answer to a different request. */
2133 warning (_("ERROR RMT Thread info mismatch."));
2136 copy_threadref (&info
->threadid
, &ref
);
2138 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2140 /* Packets are terminated with nulls. */
2141 while ((pkt
< limit
) && mask
&& *pkt
)
2143 pkt
= unpack_int (pkt
, &tag
); /* tag */
2144 pkt
= unpack_byte (pkt
, &length
); /* length */
2145 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2147 warning (_("ERROR RMT: threadinfo tag mismatch."));
2151 if (tag
== TAG_THREADID
)
2155 warning (_("ERROR RMT: length of threadid is not 16."));
2159 pkt
= unpack_threadid (pkt
, &ref
);
2160 mask
= mask
& ~TAG_THREADID
;
2163 if (tag
== TAG_EXISTS
)
2165 info
->active
= stub_unpack_int (pkt
, length
);
2167 mask
= mask
& ~(TAG_EXISTS
);
2170 warning (_("ERROR RMT: 'exists' length too long."));
2176 if (tag
== TAG_THREADNAME
)
2178 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2179 mask
= mask
& ~TAG_THREADNAME
;
2182 if (tag
== TAG_DISPLAY
)
2184 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2185 mask
= mask
& ~TAG_DISPLAY
;
2188 if (tag
== TAG_MOREDISPLAY
)
2190 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2191 mask
= mask
& ~TAG_MOREDISPLAY
;
2194 warning (_("ERROR RMT: unknown thread info tag."));
2195 break; /* Not a tag we know about. */
2201 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2202 struct gdb_ext_thread_info
*info
)
2204 struct remote_state
*rs
= get_remote_state ();
2207 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2209 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2211 if (rs
->buf
[0] == '\0')
2214 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2219 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2222 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2223 threadref
*nextthread
)
2225 *pkt
++ = 'q'; /* info query packet */
2226 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2227 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2228 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2229 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2234 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2237 parse_threadlist_response (char *pkt
, int result_limit
,
2238 threadref
*original_echo
, threadref
*resultlist
,
2241 struct remote_state
*rs
= get_remote_state ();
2243 int count
, resultcount
, done
;
2246 /* Assume the 'q' and 'M chars have been stripped. */
2247 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2248 /* done parse past here */
2249 pkt
= unpack_byte (pkt
, &count
); /* count field */
2250 pkt
= unpack_nibble (pkt
, &done
);
2251 /* The first threadid is the argument threadid. */
2252 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2253 while ((count
-- > 0) && (pkt
< limit
))
2255 pkt
= unpack_threadid (pkt
, resultlist
++);
2256 if (resultcount
++ >= result_limit
)
2265 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2266 int *done
, int *result_count
, threadref
*threadlist
)
2268 struct remote_state
*rs
= get_remote_state ();
2269 static threadref echo_nextthread
;
2272 /* Trancate result limit to be smaller than the packet size. */
2273 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= get_remote_packet_size ())
2274 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2276 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2278 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2280 if (*rs
->buf
== '\0')
2284 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2287 if (!threadmatch (&echo_nextthread
, nextthread
))
2289 /* FIXME: This is a good reason to drop the packet. */
2290 /* Possably, there is a duplicate response. */
2292 retransmit immediatly - race conditions
2293 retransmit after timeout - yes
2295 wait for packet, then exit
2297 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2298 return 0; /* I choose simply exiting. */
2300 if (*result_count
<= 0)
2304 warning (_("RMT ERROR : failed to get remote thread list."));
2307 return result
; /* break; */
2309 if (*result_count
> result_limit
)
2312 warning (_("RMT ERROR: threadlist response longer than requested."));
2318 /* This is the interface between remote and threads, remotes upper
2321 /* remote_find_new_threads retrieves the thread list and for each
2322 thread in the list, looks up the thread in GDB's internal list,
2323 adding the thread if it does not already exist. This involves
2324 getting partial thread lists from the remote target so, polling the
2325 quit_flag is required. */
2328 /* About this many threadisds fit in a packet. */
2330 #define MAXTHREADLISTRESULTS 32
2333 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2336 int done
, i
, result_count
;
2340 static threadref nextthread
;
2341 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2346 if (loopcount
++ > looplimit
)
2349 warning (_("Remote fetch threadlist -infinite loop-."));
2352 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2353 &done
, &result_count
, resultthreadlist
))
2358 /* Clear for later iterations. */
2360 /* Setup to resume next batch of thread references, set nextthread. */
2361 if (result_count
>= 1)
2362 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2364 while (result_count
--)
2365 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2372 remote_newthread_step (threadref
*ref
, void *context
)
2374 int pid
= ptid_get_pid (inferior_ptid
);
2375 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2377 if (!in_thread_list (ptid
))
2379 return 1; /* continue iterator */
2382 #define CRAZY_MAX_THREADS 1000
2385 remote_current_thread (ptid_t oldpid
)
2387 struct remote_state
*rs
= get_remote_state ();
2390 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2391 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2392 return read_ptid (&rs
->buf
[2], NULL
);
2397 /* Find new threads for info threads command.
2398 * Original version, using John Metzler's thread protocol.
2402 remote_find_new_threads (void)
2404 remote_threadlist_iterator (remote_newthread_step
, 0,
2408 #if defined(HAVE_LIBEXPAT)
2410 typedef struct thread_item
2416 DEF_VEC_O(thread_item_t
);
2418 struct threads_parsing_context
2420 VEC (thread_item_t
) *items
;
2424 start_thread (struct gdb_xml_parser
*parser
,
2425 const struct gdb_xml_element
*element
,
2426 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2428 struct threads_parsing_context
*data
= user_data
;
2430 struct thread_item item
;
2433 id
= VEC_index (gdb_xml_value_s
, attributes
, 0)->value
;
2434 item
.ptid
= read_ptid (id
, NULL
);
2436 if (VEC_length (gdb_xml_value_s
, attributes
) > 1)
2437 item
.core
= *(ULONGEST
*) VEC_index (gdb_xml_value_s
, attributes
, 1)->value
;
2443 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2447 end_thread (struct gdb_xml_parser
*parser
,
2448 const struct gdb_xml_element
*element
,
2449 void *user_data
, const char *body_text
)
2451 struct threads_parsing_context
*data
= user_data
;
2453 if (body_text
&& *body_text
)
2454 VEC_last (thread_item_t
, data
->items
)->extra
= strdup (body_text
);
2457 const struct gdb_xml_attribute thread_attributes
[] = {
2458 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2459 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2460 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2463 const struct gdb_xml_element thread_children
[] = {
2464 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2467 const struct gdb_xml_element threads_children
[] = {
2468 { "thread", thread_attributes
, thread_children
,
2469 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2470 start_thread
, end_thread
},
2471 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2474 const struct gdb_xml_element threads_elements
[] = {
2475 { "threads", NULL
, threads_children
,
2476 GDB_XML_EF_NONE
, NULL
, NULL
},
2477 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2483 * Find all threads for info threads command.
2484 * Uses new thread protocol contributed by Cisco.
2485 * Falls back and attempts to use the older method (above)
2486 * if the target doesn't respond to the new method.
2490 remote_threads_info (struct target_ops
*ops
)
2492 struct remote_state
*rs
= get_remote_state ();
2496 if (remote_desc
== 0) /* paranoia */
2497 error (_("Command can only be used when connected to the remote target."));
2499 #if defined(HAVE_LIBEXPAT)
2500 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2502 char *xml
= target_read_stralloc (¤t_target
,
2503 TARGET_OBJECT_THREADS
, NULL
);
2505 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2508 struct gdb_xml_parser
*parser
;
2509 struct threads_parsing_context context
;
2510 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2513 parser
= gdb_xml_create_parser_and_cleanup (_("threads"),
2517 gdb_xml_use_dtd (parser
, "threads.dtd");
2519 if (gdb_xml_parse (parser
, xml
) == 0)
2522 struct thread_item
*item
;
2524 for (i
= 0; VEC_iterate (thread_item_t
, context
.items
, i
, item
); ++i
)
2526 if (!ptid_equal (item
->ptid
, null_ptid
))
2528 struct private_thread_info
*info
;
2529 /* In non-stop mode, we assume new found threads
2530 are running until proven otherwise with a
2531 stop reply. In all-stop, we can only get
2532 here if all threads are stopped. */
2533 int running
= non_stop
? 1 : 0;
2535 remote_notice_new_inferior (item
->ptid
, running
);
2537 info
= demand_private_info (item
->ptid
);
2538 info
->core
= item
->core
;
2539 info
->extra
= item
->extra
;
2542 xfree (item
->extra
);
2546 VEC_free (thread_item_t
, context
.items
);
2549 do_cleanups (back_to
);
2554 if (use_threadinfo_query
)
2556 putpkt ("qfThreadInfo");
2557 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2559 if (bufp
[0] != '\0') /* q packet recognized */
2561 while (*bufp
++ == 'm') /* reply contains one or more TID */
2565 new_thread
= read_ptid (bufp
, &bufp
);
2566 if (!ptid_equal (new_thread
, null_ptid
))
2568 /* In non-stop mode, we assume new found threads
2569 are running until proven otherwise with a
2570 stop reply. In all-stop, we can only get
2571 here if all threads are stopped. */
2572 int running
= non_stop
? 1 : 0;
2574 remote_notice_new_inferior (new_thread
, running
);
2577 while (*bufp
++ == ','); /* comma-separated list */
2578 putpkt ("qsThreadInfo");
2579 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2586 /* Only qfThreadInfo is supported in non-stop mode. */
2590 /* Else fall back to old method based on jmetzler protocol. */
2591 use_threadinfo_query
= 0;
2592 remote_find_new_threads ();
2597 * Collect a descriptive string about the given thread.
2598 * The target may say anything it wants to about the thread
2599 * (typically info about its blocked / runnable state, name, etc.).
2600 * This string will appear in the info threads display.
2602 * Optional: targets are not required to implement this function.
2606 remote_threads_extra_info (struct thread_info
*tp
)
2608 struct remote_state
*rs
= get_remote_state ();
2612 struct gdb_ext_thread_info threadinfo
;
2613 static char display_buf
[100]; /* arbitrary... */
2614 int n
= 0; /* position in display_buf */
2616 if (remote_desc
== 0) /* paranoia */
2617 internal_error (__FILE__
, __LINE__
,
2618 _("remote_threads_extra_info"));
2620 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2621 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2622 /* This is the main thread which was added by GDB. The remote
2623 server doesn't know about it. */
2626 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2628 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2629 if (info
&& info
->private)
2630 return info
->private->extra
;
2635 if (use_threadextra_query
)
2638 char *endb
= rs
->buf
+ get_remote_packet_size ();
2640 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2642 write_ptid (b
, endb
, tp
->ptid
);
2645 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2646 if (rs
->buf
[0] != 0)
2648 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2649 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2650 display_buf
[result
] = '\0';
2655 /* If the above query fails, fall back to the old method. */
2656 use_threadextra_query
= 0;
2657 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2658 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2659 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2660 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2661 if (threadinfo
.active
)
2663 if (*threadinfo
.shortname
)
2664 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2665 " Name: %s,", threadinfo
.shortname
);
2666 if (*threadinfo
.display
)
2667 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2668 " State: %s,", threadinfo
.display
);
2669 if (*threadinfo
.more_display
)
2670 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2671 " Priority: %s", threadinfo
.more_display
);
2675 /* For purely cosmetic reasons, clear up trailing commas. */
2676 if (',' == display_buf
[n
-1])
2677 display_buf
[n
-1] = ' ';
2685 /* Restart the remote side; this is an extended protocol operation. */
2688 extended_remote_restart (void)
2690 struct remote_state
*rs
= get_remote_state ();
2692 /* Send the restart command; for reasons I don't understand the
2693 remote side really expects a number after the "R". */
2694 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2697 remote_fileio_reset ();
2700 /* Clean up connection to a remote debugger. */
2703 remote_close (int quitting
)
2705 if (remote_desc
== NULL
)
2706 return; /* already closed */
2708 /* Make sure we leave stdin registered in the event loop, and we
2709 don't leave the async SIGINT signal handler installed. */
2710 remote_terminal_ours ();
2712 serial_close (remote_desc
);
2715 /* We don't have a connection to the remote stub anymore. Get rid
2716 of all the inferiors and their threads we were controlling. */
2717 discard_all_inferiors ();
2719 /* We're no longer interested in any of these events. */
2720 discard_pending_stop_replies (-1);
2722 if (remote_async_inferior_event_token
)
2723 delete_async_event_handler (&remote_async_inferior_event_token
);
2724 if (remote_async_get_pending_events_token
)
2725 delete_async_event_handler (&remote_async_get_pending_events_token
);
2728 /* Query the remote side for the text, data and bss offsets. */
2733 struct remote_state
*rs
= get_remote_state ();
2736 int lose
, num_segments
= 0, do_sections
, do_segments
;
2737 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
2738 struct section_offsets
*offs
;
2739 struct symfile_segment_data
*data
;
2741 if (symfile_objfile
== NULL
)
2744 putpkt ("qOffsets");
2745 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2748 if (buf
[0] == '\000')
2749 return; /* Return silently. Stub doesn't support
2753 warning (_("Remote failure reply: %s"), buf
);
2757 /* Pick up each field in turn. This used to be done with scanf, but
2758 scanf will make trouble if CORE_ADDR size doesn't match
2759 conversion directives correctly. The following code will work
2760 with any size of CORE_ADDR. */
2761 text_addr
= data_addr
= bss_addr
= 0;
2765 if (strncmp (ptr
, "Text=", 5) == 0)
2768 /* Don't use strtol, could lose on big values. */
2769 while (*ptr
&& *ptr
!= ';')
2770 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2772 if (strncmp (ptr
, ";Data=", 6) == 0)
2775 while (*ptr
&& *ptr
!= ';')
2776 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2781 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
2784 while (*ptr
&& *ptr
!= ';')
2785 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
2787 if (bss_addr
!= data_addr
)
2788 warning (_("Target reported unsupported offsets: %s"), buf
);
2793 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
2796 /* Don't use strtol, could lose on big values. */
2797 while (*ptr
&& *ptr
!= ';')
2798 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
2801 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
2804 while (*ptr
&& *ptr
!= ';')
2805 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
2813 error (_("Malformed response to offset query, %s"), buf
);
2814 else if (*ptr
!= '\0')
2815 warning (_("Target reported unsupported offsets: %s"), buf
);
2817 offs
= ((struct section_offsets
*)
2818 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
2819 memcpy (offs
, symfile_objfile
->section_offsets
,
2820 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
2822 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
2823 do_segments
= (data
!= NULL
);
2824 do_sections
= num_segments
== 0;
2826 if (num_segments
> 0)
2828 segments
[0] = text_addr
;
2829 segments
[1] = data_addr
;
2831 /* If we have two segments, we can still try to relocate everything
2832 by assuming that the .text and .data offsets apply to the whole
2833 text and data segments. Convert the offsets given in the packet
2834 to base addresses for symfile_map_offsets_to_segments. */
2835 else if (data
&& data
->num_segments
== 2)
2837 segments
[0] = data
->segment_bases
[0] + text_addr
;
2838 segments
[1] = data
->segment_bases
[1] + data_addr
;
2841 /* If the object file has only one segment, assume that it is text
2842 rather than data; main programs with no writable data are rare,
2843 but programs with no code are useless. Of course the code might
2844 have ended up in the data segment... to detect that we would need
2845 the permissions here. */
2846 else if (data
&& data
->num_segments
== 1)
2848 segments
[0] = data
->segment_bases
[0] + text_addr
;
2851 /* There's no way to relocate by segment. */
2857 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
2858 offs
, num_segments
, segments
);
2860 if (ret
== 0 && !do_sections
)
2861 error (_("Can not handle qOffsets TextSeg response with this symbol file"));
2868 free_symfile_segment_data (data
);
2872 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
2874 /* This is a temporary kludge to force data and bss to use the same offsets
2875 because that's what nlmconv does now. The real solution requires changes
2876 to the stub and remote.c that I don't have time to do right now. */
2878 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
2879 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
2882 objfile_relocate (symfile_objfile
, offs
);
2885 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
2886 threads we know are stopped already. This is used during the
2887 initial remote connection in non-stop mode --- threads that are
2888 reported as already being stopped are left stopped. */
2891 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
2893 /* If we have a stop reply for this thread, it must be stopped. */
2894 if (peek_stop_reply (thread
->ptid
))
2895 set_stop_requested (thread
->ptid
, 1);
2900 /* Stub for catch_exception. */
2902 struct start_remote_args
2906 /* The current target. */
2907 struct target_ops
*target
;
2909 /* Non-zero if this is an extended-remote target. */
2913 /* Send interrupt_sequence to remote target. */
2915 send_interrupt_sequence ()
2917 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
2918 serial_write (remote_desc
, "\x03", 1);
2919 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
2920 serial_send_break (remote_desc
);
2921 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
2923 serial_send_break (remote_desc
);
2924 serial_write (remote_desc
, "g", 1);
2927 internal_error (__FILE__
, __LINE__
,
2928 _("Invalid value for interrupt_sequence_mode: %s."),
2929 interrupt_sequence_mode
);
2933 remote_start_remote (struct ui_out
*uiout
, void *opaque
)
2935 struct start_remote_args
*args
= opaque
;
2936 struct remote_state
*rs
= get_remote_state ();
2937 struct packet_config
*noack_config
;
2938 char *wait_status
= NULL
;
2940 immediate_quit
++; /* Allow user to interrupt it. */
2942 /* Ack any packet which the remote side has already sent. */
2943 serial_write (remote_desc
, "+", 1);
2945 if (interrupt_on_connect
)
2946 send_interrupt_sequence ();
2948 /* The first packet we send to the target is the optional "supported
2949 packets" request. If the target can answer this, it will tell us
2950 which later probes to skip. */
2951 remote_query_supported ();
2953 /* Next, we possibly activate noack mode.
2955 If the QStartNoAckMode packet configuration is set to AUTO,
2956 enable noack mode if the stub reported a wish for it with
2959 If set to TRUE, then enable noack mode even if the stub didn't
2960 report it in qSupported. If the stub doesn't reply OK, the
2961 session ends with an error.
2963 If FALSE, then don't activate noack mode, regardless of what the
2964 stub claimed should be the default with qSupported. */
2966 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
2968 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
2969 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
2970 && noack_config
->support
== PACKET_ENABLE
))
2972 putpkt ("QStartNoAckMode");
2973 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2974 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
2978 if (args
->extended_p
)
2980 /* Tell the remote that we are using the extended protocol. */
2982 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2985 /* Next, if the target can specify a description, read it. We do
2986 this before anything involving memory or registers. */
2987 target_find_description ();
2989 /* Next, now that we know something about the target, update the
2990 address spaces in the program spaces. */
2991 update_address_spaces ();
2993 /* On OSs where the list of libraries is global to all
2994 processes, we fetch them early. */
2995 if (gdbarch_has_global_solist (target_gdbarch
))
2996 solib_add (NULL
, args
->from_tty
, args
->target
, auto_solib_add
);
3000 if (!rs
->non_stop_aware
)
3001 error (_("Non-stop mode requested, but remote does not support non-stop"));
3003 putpkt ("QNonStop:1");
3004 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3006 if (strcmp (rs
->buf
, "OK") != 0)
3007 error ("Remote refused setting non-stop mode with: %s", rs
->buf
);
3009 /* Find about threads and processes the stub is already
3010 controlling. We default to adding them in the running state.
3011 The '?' query below will then tell us about which threads are
3013 remote_threads_info (args
->target
);
3015 else if (rs
->non_stop_aware
)
3017 /* Don't assume that the stub can operate in all-stop mode.
3018 Request it explicitely. */
3019 putpkt ("QNonStop:0");
3020 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3022 if (strcmp (rs
->buf
, "OK") != 0)
3023 error ("Remote refused setting all-stop mode with: %s", rs
->buf
);
3026 /* Check whether the target is running now. */
3028 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3032 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3034 if (!args
->extended_p
)
3035 error (_("The target is not running (try extended-remote?)"));
3037 /* We're connected, but not running. Drop out before we
3038 call start_remote. */
3043 /* Save the reply for later. */
3044 wait_status
= alloca (strlen (rs
->buf
) + 1);
3045 strcpy (wait_status
, rs
->buf
);
3048 /* Let the stub know that we want it to return the thread. */
3049 set_continue_thread (minus_one_ptid
);
3051 /* Without this, some commands which require an active target
3052 (such as kill) won't work. This variable serves (at least)
3053 double duty as both the pid of the target process (if it has
3054 such), and as a flag indicating that a target is active.
3055 These functions should be split out into seperate variables,
3056 especially since GDB will someday have a notion of debugging
3057 several processes. */
3058 inferior_ptid
= magic_null_ptid
;
3060 /* Now, if we have thread information, update inferior_ptid. */
3061 inferior_ptid
= remote_current_thread (inferior_ptid
);
3063 remote_add_inferior (ptid_get_pid (inferior_ptid
), -1);
3065 /* Always add the main thread. */
3066 add_thread_silent (inferior_ptid
);
3068 get_offsets (); /* Get text, data & bss offsets. */
3070 /* If we could not find a description using qXfer, and we know
3071 how to do it some other way, try again. This is not
3072 supported for non-stop; it could be, but it is tricky if
3073 there are no stopped threads when we connect. */
3074 if (remote_read_description_p (args
->target
)
3075 && gdbarch_target_desc (target_gdbarch
) == NULL
)
3077 target_clear_description ();
3078 target_find_description ();
3081 /* Use the previously fetched status. */
3082 gdb_assert (wait_status
!= NULL
);
3083 strcpy (rs
->buf
, wait_status
);
3084 rs
->cached_wait_status
= 1;
3087 start_remote (args
->from_tty
); /* Initialize gdb process mechanisms. */
3091 /* Clear WFI global state. Do this before finding about new
3092 threads and inferiors, and setting the current inferior.
3093 Otherwise we would clear the proceed status of the current
3094 inferior when we want its stop_soon state to be preserved
3095 (see notice_new_inferior). */
3096 init_wait_for_inferior ();
3098 /* In non-stop, we will either get an "OK", meaning that there
3099 are no stopped threads at this time; or, a regular stop
3100 reply. In the latter case, there may be more than one thread
3101 stopped --- we pull them all out using the vStopped
3103 if (strcmp (rs
->buf
, "OK") != 0)
3105 struct stop_reply
*stop_reply
;
3106 struct cleanup
*old_chain
;
3108 stop_reply
= stop_reply_xmalloc ();
3109 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3111 remote_parse_stop_reply (rs
->buf
, stop_reply
);
3112 discard_cleanups (old_chain
);
3114 /* get_pending_stop_replies acks this one, and gets the rest
3116 pending_stop_reply
= stop_reply
;
3117 remote_get_pending_stop_replies ();
3119 /* Make sure that threads that were stopped remain
3121 iterate_over_threads (set_stop_requested_callback
, NULL
);
3124 if (target_can_async_p ())
3125 target_async (inferior_event_handler
, 0);
3127 if (thread_count () == 0)
3129 if (!args
->extended_p
)
3130 error (_("The target is not running (try extended-remote?)"));
3132 /* We're connected, but not running. Drop out before we
3133 call start_remote. */
3137 /* Let the stub know that we want it to return the thread. */
3139 /* Force the stub to choose a thread. */
3140 set_general_thread (null_ptid
);
3143 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3144 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3145 error (_("remote didn't report the current thread in non-stop mode"));
3147 get_offsets (); /* Get text, data & bss offsets. */
3149 /* In non-stop mode, any cached wait status will be stored in
3150 the stop reply queue. */
3151 gdb_assert (wait_status
== NULL
);
3154 /* If we connected to a live target, do some additional setup. */
3155 if (target_has_execution
)
3157 if (exec_bfd
) /* No use without an exec file. */
3158 remote_check_symbols (symfile_objfile
);
3161 /* Possibly the target has been engaged in a trace run started
3162 previously; find out where things are at. */
3163 if (rs
->disconnected_tracing
)
3165 struct uploaded_tp
*uploaded_tps
= NULL
;
3166 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3168 remote_get_trace_status (current_trace_status ());
3169 if (current_trace_status ()->running
)
3170 printf_filtered (_("Trace is already running on the target.\n"));
3172 /* Get trace state variables first, they may be checked when
3173 parsing uploaded commands. */
3175 remote_upload_trace_state_variables (&uploaded_tsvs
);
3177 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3179 remote_upload_tracepoints (&uploaded_tps
);
3181 merge_uploaded_tracepoints (&uploaded_tps
);
3184 /* If breakpoints are global, insert them now. */
3185 if (gdbarch_has_global_breakpoints (target_gdbarch
)
3186 && breakpoints_always_inserted_mode ())
3187 insert_breakpoints ();
3190 /* Open a connection to a remote debugger.
3191 NAME is the filename used for communication. */
3194 remote_open (char *name
, int from_tty
)
3196 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3199 /* Open a connection to a remote debugger using the extended
3200 remote gdb protocol. NAME is the filename used for communication. */
3203 extended_remote_open (char *name
, int from_tty
)
3205 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3208 /* Generic code for opening a connection to a remote target. */
3211 init_all_packet_configs (void)
3214 for (i
= 0; i
< PACKET_MAX
; i
++)
3215 update_packet_config (&remote_protocol_packets
[i
]);
3218 /* Symbol look-up. */
3221 remote_check_symbols (struct objfile
*objfile
)
3223 struct remote_state
*rs
= get_remote_state ();
3224 char *msg
, *reply
, *tmp
;
3225 struct minimal_symbol
*sym
;
3228 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3231 /* Make sure the remote is pointing at the right process. */
3232 set_general_process ();
3234 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3235 because we need both at the same time. */
3236 msg
= alloca (get_remote_packet_size ());
3238 /* Invite target to request symbol lookups. */
3240 putpkt ("qSymbol::");
3241 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3242 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3245 while (strncmp (reply
, "qSymbol:", 8) == 0)
3248 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3250 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3252 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3255 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
3256 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3258 /* If this is a function address, return the start of code
3259 instead of any data function descriptor. */
3260 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch
,
3264 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3265 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3269 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3274 static struct serial
*
3275 remote_serial_open (char *name
)
3277 static int udp_warning
= 0;
3279 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3280 of in ser-tcp.c, because it is the remote protocol assuming that the
3281 serial connection is reliable and not the serial connection promising
3283 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3286 The remote protocol may be unreliable over UDP.\n\
3287 Some events may be lost, rendering further debugging impossible."));
3291 return serial_open (name
);
3294 /* This type describes each known response to the qSupported
3296 struct protocol_feature
3298 /* The name of this protocol feature. */
3301 /* The default for this protocol feature. */
3302 enum packet_support default_support
;
3304 /* The function to call when this feature is reported, or after
3305 qSupported processing if the feature is not supported.
3306 The first argument points to this structure. The second
3307 argument indicates whether the packet requested support be
3308 enabled, disabled, or probed (or the default, if this function
3309 is being called at the end of processing and this feature was
3310 not reported). The third argument may be NULL; if not NULL, it
3311 is a NUL-terminated string taken from the packet following
3312 this feature's name and an equals sign. */
3313 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3316 /* The corresponding packet for this feature. Only used if
3317 FUNC is remote_supported_packet. */
3322 remote_supported_packet (const struct protocol_feature
*feature
,
3323 enum packet_support support
,
3324 const char *argument
)
3328 warning (_("Remote qSupported response supplied an unexpected value for"
3329 " \"%s\"."), feature
->name
);
3333 if (remote_protocol_packets
[feature
->packet
].support
3334 == PACKET_SUPPORT_UNKNOWN
)
3335 remote_protocol_packets
[feature
->packet
].support
= support
;
3339 remote_packet_size (const struct protocol_feature
*feature
,
3340 enum packet_support support
, const char *value
)
3342 struct remote_state
*rs
= get_remote_state ();
3347 if (support
!= PACKET_ENABLE
)
3350 if (value
== NULL
|| *value
== '\0')
3352 warning (_("Remote target reported \"%s\" without a size."),
3358 packet_size
= strtol (value
, &value_end
, 16);
3359 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3361 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3362 feature
->name
, value
);
3366 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3368 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3369 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3370 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3373 /* Record the new maximum packet size. */
3374 rs
->explicit_packet_size
= packet_size
;
3378 remote_multi_process_feature (const struct protocol_feature
*feature
,
3379 enum packet_support support
, const char *value
)
3381 struct remote_state
*rs
= get_remote_state ();
3382 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3386 remote_non_stop_feature (const struct protocol_feature
*feature
,
3387 enum packet_support support
, const char *value
)
3389 struct remote_state
*rs
= get_remote_state ();
3390 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3394 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3395 enum packet_support support
,
3398 struct remote_state
*rs
= get_remote_state ();
3399 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3403 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3404 enum packet_support support
,
3407 struct remote_state
*rs
= get_remote_state ();
3408 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3412 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3413 enum packet_support support
,
3416 struct remote_state
*rs
= get_remote_state ();
3417 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3420 static struct protocol_feature remote_protocol_features
[] = {
3421 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3422 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3423 PACKET_qXfer_auxv
},
3424 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3425 PACKET_qXfer_features
},
3426 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3427 PACKET_qXfer_libraries
},
3428 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3429 PACKET_qXfer_memory_map
},
3430 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3431 PACKET_qXfer_spu_read
},
3432 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3433 PACKET_qXfer_spu_write
},
3434 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3435 PACKET_qXfer_osdata
},
3436 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3437 PACKET_qXfer_threads
},
3438 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3439 PACKET_QPassSignals
},
3440 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3441 PACKET_QStartNoAckMode
},
3442 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3443 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3444 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3445 PACKET_qXfer_siginfo_read
},
3446 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3447 PACKET_qXfer_siginfo_write
},
3448 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3449 PACKET_ConditionalTracepoints
},
3450 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3451 PACKET_FastTracepoints
},
3452 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3454 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3456 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3461 remote_query_supported (void)
3463 struct remote_state
*rs
= get_remote_state ();
3466 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
3468 /* The packet support flags are handled differently for this packet
3469 than for most others. We treat an error, a disabled packet, and
3470 an empty response identically: any features which must be reported
3471 to be used will be automatically disabled. An empty buffer
3472 accomplishes this, since that is also the representation for a list
3473 containing no features. */
3476 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
3478 const char *qsupported
= gdbarch_qsupported (target_gdbarch
);
3483 q
= concat ("qSupported:multiprocess+;", qsupported
, NULL
);
3485 q
= concat ("qSupported:", qsupported
, NULL
);
3492 putpkt ("qSupported:multiprocess+");
3494 putpkt ("qSupported");
3497 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3499 /* If an error occured, warn, but do not return - just reset the
3500 buffer to empty and go on to disable features. */
3501 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
3504 warning (_("Remote failure reply: %s"), rs
->buf
);
3509 memset (seen
, 0, sizeof (seen
));
3514 enum packet_support is_supported
;
3515 char *p
, *end
, *name_end
, *value
;
3517 /* First separate out this item from the rest of the packet. If
3518 there's another item after this, we overwrite the separator
3519 (terminated strings are much easier to work with). */
3521 end
= strchr (p
, ';');
3524 end
= p
+ strlen (p
);
3534 warning (_("empty item in \"qSupported\" response"));
3539 name_end
= strchr (p
, '=');
3542 /* This is a name=value entry. */
3543 is_supported
= PACKET_ENABLE
;
3544 value
= name_end
+ 1;
3553 is_supported
= PACKET_ENABLE
;
3557 is_supported
= PACKET_DISABLE
;
3561 is_supported
= PACKET_SUPPORT_UNKNOWN
;
3565 warning (_("unrecognized item \"%s\" in \"qSupported\" response"), p
);
3571 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3572 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
3574 const struct protocol_feature
*feature
;
3577 feature
= &remote_protocol_features
[i
];
3578 feature
->func (feature
, is_supported
, value
);
3583 /* If we increased the packet size, make sure to increase the global
3584 buffer size also. We delay this until after parsing the entire
3585 qSupported packet, because this is the same buffer we were
3587 if (rs
->buf_size
< rs
->explicit_packet_size
)
3589 rs
->buf_size
= rs
->explicit_packet_size
;
3590 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
3593 /* Handle the defaults for unmentioned features. */
3594 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
3597 const struct protocol_feature
*feature
;
3599 feature
= &remote_protocol_features
[i
];
3600 feature
->func (feature
, feature
->default_support
, NULL
);
3606 remote_open_1 (char *name
, int from_tty
, struct target_ops
*target
, int extended_p
)
3608 struct remote_state
*rs
= get_remote_state ();
3611 error (_("To open a remote debug connection, you need to specify what\n"
3612 "serial device is attached to the remote system\n"
3613 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
3615 /* See FIXME above. */
3616 if (!target_async_permitted
)
3617 wait_forever_enabled_p
= 1;
3619 /* If we're connected to a running target, target_preopen will kill it.
3620 But if we're connected to a target system with no running process,
3621 then we will still be connected when it returns. Ask this question
3622 first, before target_preopen has a chance to kill anything. */
3623 if (remote_desc
!= NULL
&& !have_inferiors ())
3626 || query (_("Already connected to a remote target. Disconnect? ")))
3629 error (_("Still connected."));
3632 target_preopen (from_tty
);
3634 unpush_target (target
);
3636 /* This time without a query. If we were connected to an
3637 extended-remote target and target_preopen killed the running
3638 process, we may still be connected. If we are starting "target
3639 remote" now, the extended-remote target will not have been
3640 removed by unpush_target. */
3641 if (remote_desc
!= NULL
&& !have_inferiors ())
3644 /* Make sure we send the passed signals list the next time we resume. */
3645 xfree (last_pass_packet
);
3646 last_pass_packet
= NULL
;
3648 remote_fileio_reset ();
3649 reopen_exec_file ();
3652 remote_desc
= remote_serial_open (name
);
3654 perror_with_name (name
);
3656 if (baud_rate
!= -1)
3658 if (serial_setbaudrate (remote_desc
, baud_rate
))
3660 /* The requested speed could not be set. Error out to
3661 top level after closing remote_desc. Take care to
3662 set remote_desc to NULL to avoid closing remote_desc
3664 serial_close (remote_desc
);
3666 perror_with_name (name
);
3670 serial_raw (remote_desc
);
3672 /* If there is something sitting in the buffer we might take it as a
3673 response to a command, which would be bad. */
3674 serial_flush_input (remote_desc
);
3678 puts_filtered ("Remote debugging using ");
3679 puts_filtered (name
);
3680 puts_filtered ("\n");
3682 push_target (target
); /* Switch to using remote target now. */
3684 /* Register extra event sources in the event loop. */
3685 remote_async_inferior_event_token
3686 = create_async_event_handler (remote_async_inferior_event_handler
,
3688 remote_async_get_pending_events_token
3689 = create_async_event_handler (remote_async_get_pending_events_handler
,
3692 /* Reset the target state; these things will be queried either by
3693 remote_query_supported or as they are needed. */
3694 init_all_packet_configs ();
3695 rs
->cached_wait_status
= 0;
3696 rs
->explicit_packet_size
= 0;
3698 rs
->multi_process_aware
= 0;
3699 rs
->extended
= extended_p
;
3700 rs
->non_stop_aware
= 0;
3701 rs
->waiting_for_stop_reply
= 0;
3702 rs
->ctrlc_pending_p
= 0;
3704 general_thread
= not_sent_ptid
;
3705 continue_thread
= not_sent_ptid
;
3707 /* Probe for ability to use "ThreadInfo" query, as required. */
3708 use_threadinfo_query
= 1;
3709 use_threadextra_query
= 1;
3711 if (target_async_permitted
)
3713 /* With this target we start out by owning the terminal. */
3714 remote_async_terminal_ours_p
= 1;
3716 /* FIXME: cagney/1999-09-23: During the initial connection it is
3717 assumed that the target is already ready and able to respond to
3718 requests. Unfortunately remote_start_remote() eventually calls
3719 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
3720 around this. Eventually a mechanism that allows
3721 wait_for_inferior() to expect/get timeouts will be
3723 wait_forever_enabled_p
= 0;
3726 /* First delete any symbols previously loaded from shared libraries. */
3727 no_shared_libraries (NULL
, 0);
3730 init_thread_list ();
3732 /* Start the remote connection. If error() or QUIT, discard this
3733 target (we'd otherwise be in an inconsistent state) and then
3734 propogate the error on up the exception chain. This ensures that
3735 the caller doesn't stumble along blindly assuming that the
3736 function succeeded. The CLI doesn't have this problem but other
3737 UI's, such as MI do.
3739 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
3740 this function should return an error indication letting the
3741 caller restore the previous state. Unfortunately the command
3742 ``target remote'' is directly wired to this function making that
3743 impossible. On a positive note, the CLI side of this problem has
3744 been fixed - the function set_cmd_context() makes it possible for
3745 all the ``target ....'' commands to share a common callback
3746 function. See cli-dump.c. */
3748 struct gdb_exception ex
;
3749 struct start_remote_args args
;
3751 args
.from_tty
= from_tty
;
3752 args
.target
= target
;
3753 args
.extended_p
= extended_p
;
3755 ex
= catch_exception (uiout
, remote_start_remote
, &args
, RETURN_MASK_ALL
);
3758 /* Pop the partially set up target - unless something else did
3759 already before throwing the exception. */
3760 if (remote_desc
!= NULL
)
3762 if (target_async_permitted
)
3763 wait_forever_enabled_p
= 1;
3764 throw_exception (ex
);
3768 if (target_async_permitted
)
3769 wait_forever_enabled_p
= 1;
3772 /* This takes a program previously attached to and detaches it. After
3773 this is done, GDB can be used to debug some other program. We
3774 better not have left any breakpoints in the target program or it'll
3775 die when it hits one. */
3778 remote_detach_1 (char *args
, int from_tty
, int extended
)
3780 int pid
= ptid_get_pid (inferior_ptid
);
3781 struct remote_state
*rs
= get_remote_state ();
3784 error (_("Argument given to \"detach\" when remotely debugging."));
3786 if (!target_has_execution
)
3787 error (_("No process to detach from."));
3789 /* Tell the remote target to detach. */
3790 if (remote_multi_process_p (rs
))
3791 sprintf (rs
->buf
, "D;%x", pid
);
3793 strcpy (rs
->buf
, "D");
3796 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3798 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
3800 else if (rs
->buf
[0] == '\0')
3801 error (_("Remote doesn't know how to detach"));
3803 error (_("Can't detach process."));
3807 if (remote_multi_process_p (rs
))
3808 printf_filtered (_("Detached from remote %s.\n"),
3809 target_pid_to_str (pid_to_ptid (pid
)));
3813 puts_filtered (_("Detached from remote process.\n"));
3815 puts_filtered (_("Ending remote debugging.\n"));
3819 discard_pending_stop_replies (pid
);
3820 target_mourn_inferior ();
3824 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
3826 remote_detach_1 (args
, from_tty
, 0);
3830 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
3832 remote_detach_1 (args
, from_tty
, 1);
3835 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
3838 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
3841 error (_("Argument given to \"disconnect\" when remotely debugging."));
3843 /* Make sure we unpush even the extended remote targets; mourn
3844 won't do it. So call remote_mourn_1 directly instead of
3845 target_mourn_inferior. */
3846 remote_mourn_1 (target
);
3849 puts_filtered ("Ending remote debugging.\n");
3852 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
3853 be chatty about it. */
3856 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
3858 struct remote_state
*rs
= get_remote_state ();
3861 char *wait_status
= NULL
;
3864 error_no_arg (_("process-id to attach"));
3867 pid
= strtol (args
, &dummy
, 0);
3868 /* Some targets don't set errno on errors, grrr! */
3869 if (pid
== 0 && args
== dummy
)
3870 error (_("Illegal process-id: %s."), args
);
3872 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
3873 error (_("This target does not support attaching to a process"));
3875 sprintf (rs
->buf
, "vAttach;%x", pid
);
3877 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3879 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
3882 printf_unfiltered (_("Attached to %s\n"),
3883 target_pid_to_str (pid_to_ptid (pid
)));
3887 /* Save the reply for later. */
3888 wait_status
= alloca (strlen (rs
->buf
) + 1);
3889 strcpy (wait_status
, rs
->buf
);
3891 else if (strcmp (rs
->buf
, "OK") != 0)
3892 error (_("Attaching to %s failed with: %s"),
3893 target_pid_to_str (pid_to_ptid (pid
)),
3896 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
3897 error (_("This target does not support attaching to a process"));
3899 error (_("Attaching to %s failed"),
3900 target_pid_to_str (pid_to_ptid (pid
)));
3902 set_current_inferior (remote_add_inferior (pid
, 1));
3904 inferior_ptid
= pid_to_ptid (pid
);
3908 struct thread_info
*thread
;
3910 /* Get list of threads. */
3911 remote_threads_info (target
);
3913 thread
= first_thread_of_process (pid
);
3915 inferior_ptid
= thread
->ptid
;
3917 inferior_ptid
= pid_to_ptid (pid
);
3919 /* Invalidate our notion of the remote current thread. */
3920 record_currthread (minus_one_ptid
);
3924 /* Now, if we have thread information, update inferior_ptid. */
3925 inferior_ptid
= remote_current_thread (inferior_ptid
);
3927 /* Add the main thread to the thread list. */
3928 add_thread_silent (inferior_ptid
);
3931 /* Next, if the target can specify a description, read it. We do
3932 this before anything involving memory or registers. */
3933 target_find_description ();
3937 /* Use the previously fetched status. */
3938 gdb_assert (wait_status
!= NULL
);
3940 if (target_can_async_p ())
3942 struct stop_reply
*stop_reply
;
3943 struct cleanup
*old_chain
;
3945 stop_reply
= stop_reply_xmalloc ();
3946 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3947 remote_parse_stop_reply (wait_status
, stop_reply
);
3948 discard_cleanups (old_chain
);
3949 push_stop_reply (stop_reply
);
3951 target_async (inferior_event_handler
, 0);
3955 gdb_assert (wait_status
!= NULL
);
3956 strcpy (rs
->buf
, wait_status
);
3957 rs
->cached_wait_status
= 1;
3961 gdb_assert (wait_status
== NULL
);
3965 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
3967 extended_remote_attach_1 (ops
, args
, from_tty
);
3970 /* Convert hex digit A to a number. */
3975 if (a
>= '0' && a
<= '9')
3977 else if (a
>= 'a' && a
<= 'f')
3978 return a
- 'a' + 10;
3979 else if (a
>= 'A' && a
<= 'F')
3980 return a
- 'A' + 10;
3982 error (_("Reply contains invalid hex digit %d"), a
);
3986 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
3990 for (i
= 0; i
< count
; i
++)
3992 if (hex
[0] == 0 || hex
[1] == 0)
3994 /* Hex string is short, or of uneven length.
3995 Return the count that has been converted so far. */
3998 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4004 /* Convert number NIB to a hex digit. */
4012 return 'a' + nib
- 10;
4016 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4019 /* May use a length, or a nul-terminated string as input. */
4021 count
= strlen ((char *) bin
);
4023 for (i
= 0; i
< count
; i
++)
4025 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4026 *hex
++ = tohex (*bin
++ & 0xf);
4032 /* Check for the availability of vCont. This function should also check
4036 remote_vcont_probe (struct remote_state
*rs
)
4040 strcpy (rs
->buf
, "vCont?");
4042 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4045 /* Make sure that the features we assume are supported. */
4046 if (strncmp (buf
, "vCont", 5) == 0)
4049 int support_s
, support_S
, support_c
, support_C
;
4055 rs
->support_vCont_t
= 0;
4056 while (p
&& *p
== ';')
4059 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4061 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4063 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4065 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4067 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4068 rs
->support_vCont_t
= 1;
4070 p
= strchr (p
, ';');
4073 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4074 BUF will make packet_ok disable the packet. */
4075 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4079 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4082 /* Helper function for building "vCont" resumptions. Write a
4083 resumption to P. ENDP points to one-passed-the-end of the buffer
4084 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4085 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4086 resumed thread should be single-stepped and/or signalled. If PTID
4087 equals minus_one_ptid, then all threads are resumed; if PTID
4088 represents a process, then all threads of the process are resumed;
4089 the thread to be stepped and/or signalled is given in the global
4093 append_resumption (char *p
, char *endp
,
4094 ptid_t ptid
, int step
, enum target_signal siggnal
)
4096 struct remote_state
*rs
= get_remote_state ();
4098 if (step
&& siggnal
!= TARGET_SIGNAL_0
)
4099 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4101 p
+= xsnprintf (p
, endp
- p
, ";s");
4102 else if (siggnal
!= TARGET_SIGNAL_0
)
4103 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4105 p
+= xsnprintf (p
, endp
- p
, ";c");
4107 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4111 /* All (-1) threads of process. */
4112 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4114 p
+= xsnprintf (p
, endp
- p
, ":");
4115 p
= write_ptid (p
, endp
, nptid
);
4117 else if (!ptid_equal (ptid
, minus_one_ptid
))
4119 p
+= xsnprintf (p
, endp
- p
, ":");
4120 p
= write_ptid (p
, endp
, ptid
);
4126 /* Resume the remote inferior by using a "vCont" packet. The thread
4127 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4128 resumed thread should be single-stepped and/or signalled. If PTID
4129 equals minus_one_ptid, then all threads are resumed; the thread to
4130 be stepped and/or signalled is given in the global INFERIOR_PTID.
4131 This function returns non-zero iff it resumes the inferior.
4133 This function issues a strict subset of all possible vCont commands at the
4137 remote_vcont_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
4139 struct remote_state
*rs
= get_remote_state ();
4143 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4144 remote_vcont_probe (rs
);
4146 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4150 endp
= rs
->buf
+ get_remote_packet_size ();
4152 /* If we could generate a wider range of packets, we'd have to worry
4153 about overflowing BUF. Should there be a generic
4154 "multi-part-packet" packet? */
4156 p
+= xsnprintf (p
, endp
- p
, "vCont");
4158 if (ptid_equal (ptid
, magic_null_ptid
))
4160 /* MAGIC_NULL_PTID means that we don't have any active threads,
4161 so we don't have any TID numbers the inferior will
4162 understand. Make sure to only send forms that do not specify
4164 p
= append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4166 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4168 /* Resume all threads (of all processes, or of a single
4169 process), with preference for INFERIOR_PTID. This assumes
4170 inferior_ptid belongs to the set of all threads we are about
4172 if (step
|| siggnal
!= TARGET_SIGNAL_0
)
4174 /* Step inferior_ptid, with or without signal. */
4175 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4178 /* And continue others without a signal. */
4179 p
= append_resumption (p
, endp
, ptid
, /*step=*/ 0, TARGET_SIGNAL_0
);
4183 /* Scheduler locking; resume only PTID. */
4184 p
= append_resumption (p
, endp
, ptid
, step
, siggnal
);
4187 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4192 /* In non-stop, the stub replies to vCont with "OK". The stop
4193 reply will be reported asynchronously by means of a `%Stop'
4195 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4196 if (strcmp (rs
->buf
, "OK") != 0)
4197 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4203 /* Tell the remote machine to resume. */
4205 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
4207 static int last_sent_step
;
4210 remote_resume (struct target_ops
*ops
,
4211 ptid_t ptid
, int step
, enum target_signal siggnal
)
4213 struct remote_state
*rs
= get_remote_state ();
4216 last_sent_signal
= siggnal
;
4217 last_sent_step
= step
;
4219 /* Update the inferior on signals to silently pass, if they've changed. */
4220 remote_pass_signals ();
4222 /* The vCont packet doesn't need to specify threads via Hc. */
4223 /* No reverse support (yet) for vCont. */
4224 if (execution_direction
!= EXEC_REVERSE
)
4225 if (remote_vcont_resume (ptid
, step
, siggnal
))
4228 /* All other supported resume packets do use Hc, so set the continue
4230 if (ptid_equal (ptid
, minus_one_ptid
))
4231 set_continue_thread (any_thread_ptid
);
4233 set_continue_thread (ptid
);
4236 if (execution_direction
== EXEC_REVERSE
)
4238 /* We don't pass signals to the target in reverse exec mode. */
4239 if (info_verbose
&& siggnal
!= TARGET_SIGNAL_0
)
4240 warning (" - Can't pass signal %d to target in reverse: ignored.\n",
4244 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4245 error (_("Remote reverse-step not supported."));
4247 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4248 error (_("Remote reverse-continue not supported."));
4250 strcpy (buf
, step
? "bs" : "bc");
4252 else if (siggnal
!= TARGET_SIGNAL_0
)
4254 buf
[0] = step
? 'S' : 'C';
4255 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4256 buf
[2] = tohex (((int) siggnal
) & 0xf);
4260 strcpy (buf
, step
? "s" : "c");
4265 /* We are about to start executing the inferior, let's register it
4266 with the event loop. NOTE: this is the one place where all the
4267 execution commands end up. We could alternatively do this in each
4268 of the execution commands in infcmd.c. */
4269 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4270 into infcmd.c in order to allow inferior function calls to work
4271 NOT asynchronously. */
4272 if (target_can_async_p ())
4273 target_async (inferior_event_handler
, 0);
4275 /* We've just told the target to resume. The remote server will
4276 wait for the inferior to stop, and then send a stop reply. In
4277 the mean time, we can't start another command/query ourselves
4278 because the stub wouldn't be ready to process it. This applies
4279 only to the base all-stop protocol, however. In non-stop (which
4280 only supports vCont), the stub replies with an "OK", and is
4281 immediate able to process further serial input. */
4283 rs
->waiting_for_stop_reply
= 1;
4287 /* Set up the signal handler for SIGINT, while the target is
4288 executing, ovewriting the 'regular' SIGINT signal handler. */
4290 initialize_sigint_signal_handler (void)
4292 signal (SIGINT
, handle_remote_sigint
);
4295 /* Signal handler for SIGINT, while the target is executing. */
4297 handle_remote_sigint (int sig
)
4299 signal (sig
, handle_remote_sigint_twice
);
4300 mark_async_signal_handler_wrapper (sigint_remote_token
);
4303 /* Signal handler for SIGINT, installed after SIGINT has already been
4304 sent once. It will take effect the second time that the user sends
4307 handle_remote_sigint_twice (int sig
)
4309 signal (sig
, handle_remote_sigint
);
4310 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
4313 /* Perform the real interruption of the target execution, in response
4316 async_remote_interrupt (gdb_client_data arg
)
4319 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
4321 target_stop (inferior_ptid
);
4324 /* Perform interrupt, if the first attempt did not succeed. Just give
4325 up on the target alltogether. */
4327 async_remote_interrupt_twice (gdb_client_data arg
)
4330 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt_twice called\n");
4335 /* Reinstall the usual SIGINT handlers, after the target has
4338 cleanup_sigint_signal_handler (void *dummy
)
4340 signal (SIGINT
, handle_sigint
);
4343 /* Send ^C to target to halt it. Target will respond, and send us a
4345 static void (*ofunc
) (int);
4347 /* The command line interface's stop routine. This function is installed
4348 as a signal handler for SIGINT. The first time a user requests a
4349 stop, we call remote_stop to send a break or ^C. If there is no
4350 response from the target (it didn't stop when the user requested it),
4351 we ask the user if he'd like to detach from the target. */
4353 remote_interrupt (int signo
)
4355 /* If this doesn't work, try more severe steps. */
4356 signal (signo
, remote_interrupt_twice
);
4358 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4361 /* The user typed ^C twice. */
4364 remote_interrupt_twice (int signo
)
4366 signal (signo
, ofunc
);
4367 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4368 signal (signo
, remote_interrupt
);
4371 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4372 thread, all threads of a remote process, or all threads of all
4376 remote_stop_ns (ptid_t ptid
)
4378 struct remote_state
*rs
= get_remote_state ();
4380 char *endp
= rs
->buf
+ get_remote_packet_size ();
4382 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4383 remote_vcont_probe (rs
);
4385 if (!rs
->support_vCont_t
)
4386 error (_("Remote server does not support stopping threads"));
4388 if (ptid_equal (ptid
, minus_one_ptid
)
4389 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4390 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
4395 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
4397 if (ptid_is_pid (ptid
))
4398 /* All (-1) threads of process. */
4399 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4402 /* Small optimization: if we already have a stop reply for
4403 this thread, no use in telling the stub we want this
4405 if (peek_stop_reply (ptid
))
4411 p
= write_ptid (p
, endp
, nptid
);
4414 /* In non-stop, we get an immediate OK reply. The stop reply will
4415 come in asynchronously by notification. */
4417 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4418 if (strcmp (rs
->buf
, "OK") != 0)
4419 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
4422 /* All-stop version of target_stop. Sends a break or a ^C to stop the
4423 remote target. It is undefined which thread of which process
4424 reports the stop. */
4427 remote_stop_as (ptid_t ptid
)
4429 struct remote_state
*rs
= get_remote_state ();
4431 rs
->ctrlc_pending_p
= 1;
4433 /* If the inferior is stopped already, but the core didn't know
4434 about it yet, just ignore the request. The cached wait status
4435 will be collected in remote_wait. */
4436 if (rs
->cached_wait_status
)
4439 /* Send interrupt_sequence to remote target. */
4440 send_interrupt_sequence ();
4443 /* This is the generic stop called via the target vector. When a target
4444 interrupt is requested, either by the command line or the GUI, we
4445 will eventually end up here. */
4448 remote_stop (ptid_t ptid
)
4451 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
4454 remote_stop_ns (ptid
);
4456 remote_stop_as (ptid
);
4459 /* Ask the user what to do when an interrupt is received. */
4462 interrupt_query (void)
4464 target_terminal_ours ();
4466 if (target_can_async_p ())
4468 signal (SIGINT
, handle_sigint
);
4469 deprecated_throw_reason (RETURN_QUIT
);
4473 if (query (_("Interrupted while waiting for the program.\n\
4474 Give up (and stop debugging it)? ")))
4477 deprecated_throw_reason (RETURN_QUIT
);
4481 target_terminal_inferior ();
4484 /* Enable/disable target terminal ownership. Most targets can use
4485 terminal groups to control terminal ownership. Remote targets are
4486 different in that explicit transfer of ownership to/from GDB/target
4490 remote_terminal_inferior (void)
4492 if (!target_async_permitted
)
4493 /* Nothing to do. */
4496 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
4497 idempotent. The event-loop GDB talking to an asynchronous target
4498 with a synchronous command calls this function from both
4499 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
4500 transfer the terminal to the target when it shouldn't this guard
4502 if (!remote_async_terminal_ours_p
)
4504 delete_file_handler (input_fd
);
4505 remote_async_terminal_ours_p
= 0;
4506 initialize_sigint_signal_handler ();
4507 /* NOTE: At this point we could also register our selves as the
4508 recipient of all input. Any characters typed could then be
4509 passed on down to the target. */
4513 remote_terminal_ours (void)
4515 if (!target_async_permitted
)
4516 /* Nothing to do. */
4519 /* See FIXME in remote_terminal_inferior. */
4520 if (remote_async_terminal_ours_p
)
4522 cleanup_sigint_signal_handler (NULL
);
4523 add_file_handler (input_fd
, stdin_event_handler
, 0);
4524 remote_async_terminal_ours_p
= 1;
4528 remote_console_output (char *msg
)
4532 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
4535 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
4538 fputs_unfiltered (tb
, gdb_stdtarg
);
4540 gdb_flush (gdb_stdtarg
);
4543 typedef struct cached_reg
4546 gdb_byte data
[MAX_REGISTER_SIZE
];
4549 DEF_VEC_O(cached_reg_t
);
4553 struct stop_reply
*next
;
4557 struct target_waitstatus ws
;
4559 VEC(cached_reg_t
) *regcache
;
4561 int stopped_by_watchpoint_p
;
4562 CORE_ADDR watch_data_address
;
4570 /* The list of already fetched and acknowledged stop events. */
4571 static struct stop_reply
*stop_reply_queue
;
4573 static struct stop_reply
*
4574 stop_reply_xmalloc (void)
4576 struct stop_reply
*r
= XMALLOC (struct stop_reply
);
4582 stop_reply_xfree (struct stop_reply
*r
)
4586 VEC_free (cached_reg_t
, r
->regcache
);
4591 /* Discard all pending stop replies of inferior PID. If PID is -1,
4592 discard everything. */
4595 discard_pending_stop_replies (int pid
)
4597 struct stop_reply
*prev
= NULL
, *reply
, *next
;
4599 /* Discard the in-flight notification. */
4600 if (pending_stop_reply
!= NULL
4602 || ptid_get_pid (pending_stop_reply
->ptid
) == pid
))
4604 stop_reply_xfree (pending_stop_reply
);
4605 pending_stop_reply
= NULL
;
4608 /* Discard the stop replies we have already pulled with
4610 for (reply
= stop_reply_queue
; reply
; reply
= next
)
4614 || ptid_get_pid (reply
->ptid
) == pid
)
4616 if (reply
== stop_reply_queue
)
4617 stop_reply_queue
= reply
->next
;
4619 prev
->next
= reply
->next
;
4621 stop_reply_xfree (reply
);
4628 /* Cleanup wrapper. */
4631 do_stop_reply_xfree (void *arg
)
4633 struct stop_reply
*r
= arg
;
4634 stop_reply_xfree (r
);
4637 /* Look for a queued stop reply belonging to PTID. If one is found,
4638 remove it from the queue, and return it. Returns NULL if none is
4639 found. If there are still queued events left to process, tell the
4640 event loop to get back to target_wait soon. */
4642 static struct stop_reply
*
4643 queued_stop_reply (ptid_t ptid
)
4645 struct stop_reply
*it
, *prev
;
4646 struct stop_reply head
;
4648 head
.next
= stop_reply_queue
;
4653 if (!ptid_equal (ptid
, minus_one_ptid
))
4654 for (; it
; prev
= it
, it
= it
->next
)
4655 if (ptid_equal (ptid
, it
->ptid
))
4660 prev
->next
= it
->next
;
4664 stop_reply_queue
= head
.next
;
4666 if (stop_reply_queue
)
4667 /* There's still at least an event left. */
4668 mark_async_event_handler (remote_async_inferior_event_token
);
4673 /* Push a fully parsed stop reply in the stop reply queue. Since we
4674 know that we now have at least one queued event left to pass to the
4675 core side, tell the event loop to get back to target_wait soon. */
4678 push_stop_reply (struct stop_reply
*new_event
)
4680 struct stop_reply
*event
;
4682 if (stop_reply_queue
)
4684 for (event
= stop_reply_queue
;
4685 event
&& event
->next
;
4686 event
= event
->next
)
4689 event
->next
= new_event
;
4692 stop_reply_queue
= new_event
;
4694 mark_async_event_handler (remote_async_inferior_event_token
);
4697 /* Returns true if we have a stop reply for PTID. */
4700 peek_stop_reply (ptid_t ptid
)
4702 struct stop_reply
*it
;
4704 for (it
= stop_reply_queue
; it
; it
= it
->next
)
4705 if (ptid_equal (ptid
, it
->ptid
))
4707 if (it
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
4714 /* Parse the stop reply in BUF. Either the function succeeds, and the
4715 result is stored in EVENT, or throws an error. */
4718 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
4720 struct remote_arch_state
*rsa
= get_remote_arch_state ();
4724 event
->ptid
= null_ptid
;
4725 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
4726 event
->ws
.value
.integer
= 0;
4727 event
->solibs_changed
= 0;
4728 event
->replay_event
= 0;
4729 event
->stopped_by_watchpoint_p
= 0;
4730 event
->regcache
= NULL
;
4735 case 'T': /* Status with PC, SP, FP, ... */
4736 /* Expedited reply, containing Signal, {regno, reg} repeat. */
4737 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
4739 n... = register number
4740 r... = register contents
4743 p
= &buf
[3]; /* after Txx */
4751 /* If the packet contains a register number, save it in
4752 pnum and set p1 to point to the character following it.
4753 Otherwise p1 points to p. */
4755 /* If this packet is an awatch packet, don't parse the 'a'
4756 as a register number. */
4758 if (strncmp (p
, "awatch", strlen("awatch")) != 0
4759 && strncmp (p
, "core", strlen ("core") != 0))
4761 /* Read the ``P'' register number. */
4762 pnum
= strtol (p
, &p_temp
, 16);
4768 if (p1
== p
) /* No register number present here. */
4770 p1
= strchr (p
, ':');
4772 error (_("Malformed packet(a) (missing colon): %s\n\
4775 if (strncmp (p
, "thread", p1
- p
) == 0)
4776 event
->ptid
= read_ptid (++p1
, &p
);
4777 else if ((strncmp (p
, "watch", p1
- p
) == 0)
4778 || (strncmp (p
, "rwatch", p1
- p
) == 0)
4779 || (strncmp (p
, "awatch", p1
- p
) == 0))
4781 event
->stopped_by_watchpoint_p
= 1;
4782 p
= unpack_varlen_hex (++p1
, &addr
);
4783 event
->watch_data_address
= (CORE_ADDR
) addr
;
4785 else if (strncmp (p
, "library", p1
- p
) == 0)
4789 while (*p_temp
&& *p_temp
!= ';')
4792 event
->solibs_changed
= 1;
4795 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
4797 /* NO_HISTORY event.
4798 p1 will indicate "begin" or "end", but
4799 it makes no difference for now, so ignore it. */
4800 event
->replay_event
= 1;
4801 p_temp
= strchr (p1
+ 1, ';');
4805 else if (strncmp (p
, "core", p1
- p
) == 0)
4808 p
= unpack_varlen_hex (++p1
, &c
);
4813 /* Silently skip unknown optional info. */
4814 p_temp
= strchr (p1
+ 1, ';');
4821 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
4822 cached_reg_t cached_reg
;
4827 error (_("Malformed packet(b) (missing colon): %s\n\
4833 error (_("Remote sent bad register number %s: %s\n\
4835 phex_nz (pnum
, 0), p
, buf
);
4837 cached_reg
.num
= reg
->regnum
;
4839 fieldsize
= hex2bin (p
, cached_reg
.data
,
4840 register_size (target_gdbarch
,
4843 if (fieldsize
< register_size (target_gdbarch
,
4845 warning (_("Remote reply is too short: %s"), buf
);
4847 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
4851 error (_("Remote register badly formatted: %s\nhere: %s"),
4856 case 'S': /* Old style status, just signal only. */
4857 if (event
->solibs_changed
)
4858 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
4859 else if (event
->replay_event
)
4860 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
4863 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
4864 event
->ws
.value
.sig
= (enum target_signal
)
4865 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
4868 case 'W': /* Target exited. */
4875 /* GDB used to accept only 2 hex chars here. Stubs should
4876 only send more if they detect GDB supports multi-process
4878 p
= unpack_varlen_hex (&buf
[1], &value
);
4882 /* The remote process exited. */
4883 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
4884 event
->ws
.value
.integer
= value
;
4888 /* The remote process exited with a signal. */
4889 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
4890 event
->ws
.value
.sig
= (enum target_signal
) value
;
4893 /* If no process is specified, assume inferior_ptid. */
4894 pid
= ptid_get_pid (inferior_ptid
);
4903 else if (strncmp (p
,
4904 "process:", sizeof ("process:") - 1) == 0)
4907 p
+= sizeof ("process:") - 1;
4908 unpack_varlen_hex (p
, &upid
);
4912 error (_("unknown stop reply packet: %s"), buf
);
4915 error (_("unknown stop reply packet: %s"), buf
);
4916 event
->ptid
= pid_to_ptid (pid
);
4921 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
4922 error (_("No process or thread specified in stop reply: %s"), buf
);
4925 /* When the stub wants to tell GDB about a new stop reply, it sends a
4926 stop notification (%Stop). Those can come it at any time, hence,
4927 we have to make sure that any pending putpkt/getpkt sequence we're
4928 making is finished, before querying the stub for more events with
4929 vStopped. E.g., if we started a vStopped sequence immediatelly
4930 upon receiving the %Stop notification, something like this could
4938 1.6) <-- (registers reply to step #1.3)
4940 Obviously, the reply in step #1.6 would be unexpected to a vStopped
4943 To solve this, whenever we parse a %Stop notification sucessfully,
4944 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
4945 doing whatever we were doing:
4951 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
4952 2.5) <-- (registers reply to step #2.3)
4954 Eventualy after step #2.5, we return to the event loop, which
4955 notices there's an event on the
4956 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
4957 associated callback --- the function below. At this point, we're
4958 always safe to start a vStopped sequence. :
4961 2.7) <-- T05 thread:2
4967 remote_get_pending_stop_replies (void)
4969 struct remote_state
*rs
= get_remote_state ();
4971 if (pending_stop_reply
)
4974 putpkt ("vStopped");
4976 /* Now we can rely on it. */
4977 push_stop_reply (pending_stop_reply
);
4978 pending_stop_reply
= NULL
;
4982 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4983 if (strcmp (rs
->buf
, "OK") == 0)
4987 struct cleanup
*old_chain
;
4988 struct stop_reply
*stop_reply
= stop_reply_xmalloc ();
4990 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
4991 remote_parse_stop_reply (rs
->buf
, stop_reply
);
4994 putpkt ("vStopped");
4996 if (stop_reply
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
4998 /* Now we can rely on it. */
4999 discard_cleanups (old_chain
);
5000 push_stop_reply (stop_reply
);
5003 /* We got an unknown stop reply. */
5004 do_cleanups (old_chain
);
5011 /* Called when it is decided that STOP_REPLY holds the info of the
5012 event that is to be returned to the core. This function always
5013 destroys STOP_REPLY. */
5016 process_stop_reply (struct stop_reply
*stop_reply
,
5017 struct target_waitstatus
*status
)
5020 struct thread_info
*info
;
5022 *status
= stop_reply
->ws
;
5023 ptid
= stop_reply
->ptid
;
5025 /* If no thread/process was reported by the stub, assume the current
5027 if (ptid_equal (ptid
, null_ptid
))
5028 ptid
= inferior_ptid
;
5030 if (status
->kind
!= TARGET_WAITKIND_EXITED
5031 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5033 /* Expedited registers. */
5034 if (stop_reply
->regcache
)
5036 struct regcache
*regcache
5037 = get_thread_arch_regcache (ptid
, target_gdbarch
);
5042 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5044 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5045 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5048 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5049 remote_watch_data_address
= stop_reply
->watch_data_address
;
5051 remote_notice_new_inferior (ptid
, 0);
5052 demand_private_info (ptid
)->core
= stop_reply
->core
;
5055 stop_reply_xfree (stop_reply
);
5059 /* The non-stop mode version of target_wait. */
5062 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5064 struct remote_state
*rs
= get_remote_state ();
5065 struct stop_reply
*stop_reply
;
5068 /* If in non-stop mode, get out of getpkt even if a
5069 notification is received. */
5071 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5078 case 'E': /* Error of some sort. */
5079 /* We're out of sync with the target now. Did it continue
5080 or not? We can't tell which thread it was in non-stop,
5081 so just ignore this. */
5082 warning (_("Remote failure reply: %s"), rs
->buf
);
5084 case 'O': /* Console output. */
5085 remote_console_output (rs
->buf
+ 1);
5088 warning (_("Invalid remote reply: %s"), rs
->buf
);
5092 /* Acknowledge a pending stop reply that may have arrived in the
5094 if (pending_stop_reply
!= NULL
)
5095 remote_get_pending_stop_replies ();
5097 /* If indeed we noticed a stop reply, we're done. */
5098 stop_reply
= queued_stop_reply (ptid
);
5099 if (stop_reply
!= NULL
)
5100 return process_stop_reply (stop_reply
, status
);
5102 /* Still no event. If we're just polling for an event, then
5103 return to the event loop. */
5104 if (options
& TARGET_WNOHANG
)
5106 status
->kind
= TARGET_WAITKIND_IGNORE
;
5107 return minus_one_ptid
;
5110 /* Otherwise do a blocking wait. */
5111 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5116 /* Wait until the remote machine stops, then return, storing status in
5117 STATUS just as `wait' would. */
5120 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5122 struct remote_state
*rs
= get_remote_state ();
5123 ptid_t event_ptid
= null_ptid
;
5125 struct stop_reply
*stop_reply
;
5129 status
->kind
= TARGET_WAITKIND_IGNORE
;
5130 status
->value
.integer
= 0;
5132 stop_reply
= queued_stop_reply (ptid
);
5133 if (stop_reply
!= NULL
)
5134 return process_stop_reply (stop_reply
, status
);
5136 if (rs
->cached_wait_status
)
5137 /* Use the cached wait status, but only once. */
5138 rs
->cached_wait_status
= 0;
5143 if (!target_is_async_p ())
5145 ofunc
= signal (SIGINT
, remote_interrupt
);
5146 /* If the user hit C-c before this packet, or between packets,
5147 pretend that it was hit right here. */
5151 remote_interrupt (SIGINT
);
5155 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5156 _never_ wait for ever -> test on target_is_async_p().
5157 However, before we do that we need to ensure that the caller
5158 knows how to take the target into/out of async mode. */
5159 ret
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
5160 if (!target_is_async_p ())
5161 signal (SIGINT
, ofunc
);
5166 remote_stopped_by_watchpoint_p
= 0;
5168 /* We got something. */
5169 rs
->waiting_for_stop_reply
= 0;
5171 /* Assume that the target has acknowledged Ctrl-C unless we receive
5172 an 'F' or 'O' packet. */
5173 if (buf
[0] != 'F' && buf
[0] != 'O')
5174 rs
->ctrlc_pending_p
= 0;
5178 case 'E': /* Error of some sort. */
5179 /* We're out of sync with the target now. Did it continue or
5180 not? Not is more likely, so report a stop. */
5181 warning (_("Remote failure reply: %s"), buf
);
5182 status
->kind
= TARGET_WAITKIND_STOPPED
;
5183 status
->value
.sig
= TARGET_SIGNAL_0
;
5185 case 'F': /* File-I/O request. */
5186 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5187 rs
->ctrlc_pending_p
= 0;
5189 case 'T': case 'S': case 'X': case 'W':
5191 struct stop_reply
*stop_reply
;
5192 struct cleanup
*old_chain
;
5194 stop_reply
= stop_reply_xmalloc ();
5195 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5196 remote_parse_stop_reply (buf
, stop_reply
);
5197 discard_cleanups (old_chain
);
5198 event_ptid
= process_stop_reply (stop_reply
, status
);
5201 case 'O': /* Console output. */
5202 remote_console_output (buf
+ 1);
5204 /* The target didn't really stop; keep waiting. */
5205 rs
->waiting_for_stop_reply
= 1;
5209 if (last_sent_signal
!= TARGET_SIGNAL_0
)
5211 /* Zero length reply means that we tried 'S' or 'C' and the
5212 remote system doesn't support it. */
5213 target_terminal_ours_for_output ();
5215 ("Can't send signals to this remote system. %s not sent.\n",
5216 target_signal_to_name (last_sent_signal
));
5217 last_sent_signal
= TARGET_SIGNAL_0
;
5218 target_terminal_inferior ();
5220 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5221 putpkt ((char *) buf
);
5223 /* We just told the target to resume, so a stop reply is in
5225 rs
->waiting_for_stop_reply
= 1;
5228 /* else fallthrough */
5230 warning (_("Invalid remote reply: %s"), buf
);
5232 rs
->waiting_for_stop_reply
= 1;
5236 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5238 /* Nothing interesting happened. If we're doing a non-blocking
5239 poll, we're done. Otherwise, go back to waiting. */
5240 if (options
& TARGET_WNOHANG
)
5241 return minus_one_ptid
;
5245 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5246 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5248 if (!ptid_equal (event_ptid
, null_ptid
))
5249 record_currthread (event_ptid
);
5251 event_ptid
= inferior_ptid
;
5254 /* A process exit. Invalidate our notion of current thread. */
5255 record_currthread (minus_one_ptid
);
5260 /* Wait until the remote machine stops, then return, storing status in
5261 STATUS just as `wait' would. */
5264 remote_wait (struct target_ops
*ops
,
5265 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5270 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5272 event_ptid
= remote_wait_as (ptid
, status
, options
);
5274 if (target_can_async_p ())
5276 /* If there are are events left in the queue tell the event loop
5278 if (stop_reply_queue
)
5279 mark_async_event_handler (remote_async_inferior_event_token
);
5285 /* Fetch a single register using a 'p' packet. */
5288 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
5290 struct remote_state
*rs
= get_remote_state ();
5292 char regp
[MAX_REGISTER_SIZE
];
5295 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
5298 if (reg
->pnum
== -1)
5303 p
+= hexnumstr (p
, reg
->pnum
);
5306 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5310 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
5314 case PACKET_UNKNOWN
:
5317 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
5318 gdbarch_register_name (get_regcache_arch (regcache
),
5323 /* If this register is unfetchable, tell the regcache. */
5326 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5330 /* Otherwise, parse and supply the value. */
5336 error (_("fetch_register_using_p: early buf termination"));
5338 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5341 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
5345 /* Fetch the registers included in the target's 'g' packet. */
5348 send_g_packet (void)
5350 struct remote_state
*rs
= get_remote_state ();
5353 sprintf (rs
->buf
, "g");
5354 remote_send (&rs
->buf
, &rs
->buf_size
);
5356 /* We can get out of synch in various cases. If the first character
5357 in the buffer is not a hex character, assume that has happened
5358 and try to fetch another packet to read. */
5359 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
5360 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
5361 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
5362 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
5365 fprintf_unfiltered (gdb_stdlog
,
5366 "Bad register packet; fetching a new packet\n");
5367 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5370 buf_len
= strlen (rs
->buf
);
5372 /* Sanity check the received packet. */
5373 if (buf_len
% 2 != 0)
5374 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
5380 process_g_packet (struct regcache
*regcache
)
5382 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5383 struct remote_state
*rs
= get_remote_state ();
5384 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5389 buf_len
= strlen (rs
->buf
);
5391 /* Further sanity checks, with knowledge of the architecture. */
5392 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
5393 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
5395 /* Save the size of the packet sent to us by the target. It is used
5396 as a heuristic when determining the max size of packets that the
5397 target can safely receive. */
5398 if (rsa
->actual_register_packet_size
== 0)
5399 rsa
->actual_register_packet_size
= buf_len
;
5401 /* If this is smaller than we guessed the 'g' packet would be,
5402 update our records. A 'g' reply that doesn't include a register's
5403 value implies either that the register is not available, or that
5404 the 'p' packet must be used. */
5405 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
5407 rsa
->sizeof_g_packet
= buf_len
/ 2;
5409 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5411 if (rsa
->regs
[i
].pnum
== -1)
5414 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
5415 rsa
->regs
[i
].in_g_packet
= 0;
5417 rsa
->regs
[i
].in_g_packet
= 1;
5421 regs
= alloca (rsa
->sizeof_g_packet
);
5423 /* Unimplemented registers read as all bits zero. */
5424 memset (regs
, 0, rsa
->sizeof_g_packet
);
5426 /* Reply describes registers byte by byte, each byte encoded as two
5427 hex characters. Suck them all up, then supply them to the
5428 register cacheing/storage mechanism. */
5431 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
5433 if (p
[0] == 0 || p
[1] == 0)
5434 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
5435 internal_error (__FILE__
, __LINE__
,
5436 "unexpected end of 'g' packet reply");
5438 if (p
[0] == 'x' && p
[1] == 'x')
5439 regs
[i
] = 0; /* 'x' */
5441 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5447 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5449 struct packet_reg
*r
= &rsa
->regs
[i
];
5452 if (r
->offset
* 2 >= strlen (rs
->buf
))
5453 /* This shouldn't happen - we adjusted in_g_packet above. */
5454 internal_error (__FILE__
, __LINE__
,
5455 "unexpected end of 'g' packet reply");
5456 else if (rs
->buf
[r
->offset
* 2] == 'x')
5458 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
5459 /* The register isn't available, mark it as such (at
5460 the same time setting the value to zero). */
5461 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
5464 regcache_raw_supply (regcache
, r
->regnum
,
5472 fetch_registers_using_g (struct regcache
*regcache
)
5475 process_g_packet (regcache
);
5479 remote_fetch_registers (struct target_ops
*ops
,
5480 struct regcache
*regcache
, int regnum
)
5482 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5485 set_general_thread (inferior_ptid
);
5489 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5490 gdb_assert (reg
!= NULL
);
5492 /* If this register might be in the 'g' packet, try that first -
5493 we are likely to read more than one register. If this is the
5494 first 'g' packet, we might be overly optimistic about its
5495 contents, so fall back to 'p'. */
5496 if (reg
->in_g_packet
)
5498 fetch_registers_using_g (regcache
);
5499 if (reg
->in_g_packet
)
5503 if (fetch_register_using_p (regcache
, reg
))
5506 /* This register is not available. */
5507 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5512 fetch_registers_using_g (regcache
);
5514 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5515 if (!rsa
->regs
[i
].in_g_packet
)
5516 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
5518 /* This register is not available. */
5519 regcache_raw_supply (regcache
, i
, NULL
);
5523 /* Prepare to store registers. Since we may send them all (using a
5524 'G' request), we have to read out the ones we don't want to change
5528 remote_prepare_to_store (struct regcache
*regcache
)
5530 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5532 gdb_byte buf
[MAX_REGISTER_SIZE
];
5534 /* Make sure the entire registers array is valid. */
5535 switch (remote_protocol_packets
[PACKET_P
].support
)
5537 case PACKET_DISABLE
:
5538 case PACKET_SUPPORT_UNKNOWN
:
5539 /* Make sure all the necessary registers are cached. */
5540 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5541 if (rsa
->regs
[i
].in_g_packet
)
5542 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
5549 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
5550 packet was not recognized. */
5553 store_register_using_P (const struct regcache
*regcache
,
5554 struct packet_reg
*reg
)
5556 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5557 struct remote_state
*rs
= get_remote_state ();
5558 /* Try storing a single register. */
5559 char *buf
= rs
->buf
;
5560 gdb_byte regp
[MAX_REGISTER_SIZE
];
5563 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
5566 if (reg
->pnum
== -1)
5569 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
5570 p
= buf
+ strlen (buf
);
5571 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
5572 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
5574 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5576 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
5581 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
5582 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
5583 case PACKET_UNKNOWN
:
5586 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
5590 /* Store register REGNUM, or all registers if REGNUM == -1, from the
5591 contents of the register cache buffer. FIXME: ignores errors. */
5594 store_registers_using_G (const struct regcache
*regcache
)
5596 struct remote_state
*rs
= get_remote_state ();
5597 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5601 /* Extract all the registers in the regcache copying them into a
5605 regs
= alloca (rsa
->sizeof_g_packet
);
5606 memset (regs
, 0, rsa
->sizeof_g_packet
);
5607 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5609 struct packet_reg
*r
= &rsa
->regs
[i
];
5611 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
5615 /* Command describes registers byte by byte,
5616 each byte encoded as two hex characters. */
5619 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
5621 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
5623 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5624 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
5625 error (_("Could not write registers; remote failure reply '%s'"),
5629 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
5630 of the register cache buffer. FIXME: ignores errors. */
5633 remote_store_registers (struct target_ops
*ops
,
5634 struct regcache
*regcache
, int regnum
)
5636 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5639 set_general_thread (inferior_ptid
);
5643 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
5644 gdb_assert (reg
!= NULL
);
5646 /* Always prefer to store registers using the 'P' packet if
5647 possible; we often change only a small number of registers.
5648 Sometimes we change a larger number; we'd need help from a
5649 higher layer to know to use 'G'. */
5650 if (store_register_using_P (regcache
, reg
))
5653 /* For now, don't complain if we have no way to write the
5654 register. GDB loses track of unavailable registers too
5655 easily. Some day, this may be an error. We don't have
5656 any way to read the register, either... */
5657 if (!reg
->in_g_packet
)
5660 store_registers_using_G (regcache
);
5664 store_registers_using_G (regcache
);
5666 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
5667 if (!rsa
->regs
[i
].in_g_packet
)
5668 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
5669 /* See above for why we do not issue an error here. */
5674 /* Return the number of hex digits in num. */
5677 hexnumlen (ULONGEST num
)
5681 for (i
= 0; num
!= 0; i
++)
5687 /* Set BUF to the minimum number of hex digits representing NUM. */
5690 hexnumstr (char *buf
, ULONGEST num
)
5692 int len
= hexnumlen (num
);
5693 return hexnumnstr (buf
, num
, len
);
5697 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
5700 hexnumnstr (char *buf
, ULONGEST num
, int width
)
5706 for (i
= width
- 1; i
>= 0; i
--)
5708 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
5715 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
5718 remote_address_masked (CORE_ADDR addr
)
5720 int address_size
= remote_address_size
;
5721 /* If "remoteaddresssize" was not set, default to target address size. */
5723 address_size
= gdbarch_addr_bit (target_gdbarch
);
5725 if (address_size
> 0
5726 && address_size
< (sizeof (ULONGEST
) * 8))
5728 /* Only create a mask when that mask can safely be constructed
5729 in a ULONGEST variable. */
5731 mask
= (mask
<< address_size
) - 1;
5737 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
5738 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
5739 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
5740 (which may be more than *OUT_LEN due to escape characters). The
5741 total number of bytes in the output buffer will be at most
5745 remote_escape_output (const gdb_byte
*buffer
, int len
,
5746 gdb_byte
*out_buf
, int *out_len
,
5749 int input_index
, output_index
;
5752 for (input_index
= 0; input_index
< len
; input_index
++)
5754 gdb_byte b
= buffer
[input_index
];
5756 if (b
== '$' || b
== '#' || b
== '}')
5758 /* These must be escaped. */
5759 if (output_index
+ 2 > out_maxlen
)
5761 out_buf
[output_index
++] = '}';
5762 out_buf
[output_index
++] = b
^ 0x20;
5766 if (output_index
+ 1 > out_maxlen
)
5768 out_buf
[output_index
++] = b
;
5772 *out_len
= input_index
;
5773 return output_index
;
5776 /* Convert BUFFER, escaped data LEN bytes long, into binary data
5777 in OUT_BUF. Return the number of bytes written to OUT_BUF.
5778 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
5780 This function reverses remote_escape_output. It allows more
5781 escaped characters than that function does, in particular because
5782 '*' must be escaped to avoid the run-length encoding processing
5783 in reading packets. */
5786 remote_unescape_input (const gdb_byte
*buffer
, int len
,
5787 gdb_byte
*out_buf
, int out_maxlen
)
5789 int input_index
, output_index
;
5794 for (input_index
= 0; input_index
< len
; input_index
++)
5796 gdb_byte b
= buffer
[input_index
];
5798 if (output_index
+ 1 > out_maxlen
)
5800 warning (_("Received too much data from remote target;"
5801 " ignoring overflow."));
5802 return output_index
;
5807 out_buf
[output_index
++] = b
^ 0x20;
5813 out_buf
[output_index
++] = b
;
5817 error (_("Unmatched escape character in target response."));
5819 return output_index
;
5822 /* Determine whether the remote target supports binary downloading.
5823 This is accomplished by sending a no-op memory write of zero length
5824 to the target at the specified address. It does not suffice to send
5825 the whole packet, since many stubs strip the eighth bit and
5826 subsequently compute a wrong checksum, which causes real havoc with
5829 NOTE: This can still lose if the serial line is not eight-bit
5830 clean. In cases like this, the user should clear "remote
5834 check_binary_download (CORE_ADDR addr
)
5836 struct remote_state
*rs
= get_remote_state ();
5838 switch (remote_protocol_packets
[PACKET_X
].support
)
5840 case PACKET_DISABLE
:
5844 case PACKET_SUPPORT_UNKNOWN
:
5850 p
+= hexnumstr (p
, (ULONGEST
) addr
);
5852 p
+= hexnumstr (p
, (ULONGEST
) 0);
5856 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
5857 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5859 if (rs
->buf
[0] == '\0')
5862 fprintf_unfiltered (gdb_stdlog
,
5863 "binary downloading NOT suppported by target\n");
5864 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
5869 fprintf_unfiltered (gdb_stdlog
,
5870 "binary downloading suppported by target\n");
5871 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
5878 /* Write memory data directly to the remote machine.
5879 This does not inform the data cache; the data cache uses this.
5880 HEADER is the starting part of the packet.
5881 MEMADDR is the address in the remote memory space.
5882 MYADDR is the address of the buffer in our space.
5883 LEN is the number of bytes.
5884 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
5885 should send data as binary ('X'), or hex-encoded ('M').
5887 The function creates packet of the form
5888 <HEADER><ADDRESS>,<LENGTH>:<DATA>
5890 where encoding of <DATA> is termined by PACKET_FORMAT.
5892 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
5895 Returns the number of bytes transferred, or 0 (setting errno) for
5896 error. Only transfer a single packet. */
5899 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
5900 const gdb_byte
*myaddr
, int len
,
5901 char packet_format
, int use_length
)
5903 struct remote_state
*rs
= get_remote_state ();
5913 if (packet_format
!= 'X' && packet_format
!= 'M')
5914 internal_error (__FILE__
, __LINE__
,
5915 "remote_write_bytes_aux: bad packet format");
5920 payload_size
= get_memory_write_packet_size ();
5922 /* The packet buffer will be large enough for the payload;
5923 get_memory_packet_size ensures this. */
5926 /* Compute the size of the actual payload by subtracting out the
5927 packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
5929 payload_size
-= strlen ("$,:#NN");
5931 /* The comma won't be used. */
5933 header_length
= strlen (header
);
5934 payload_size
-= header_length
;
5935 payload_size
-= hexnumlen (memaddr
);
5937 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
5939 strcat (rs
->buf
, header
);
5940 p
= rs
->buf
+ strlen (header
);
5942 /* Compute a best guess of the number of bytes actually transfered. */
5943 if (packet_format
== 'X')
5945 /* Best guess at number of bytes that will fit. */
5946 todo
= min (len
, payload_size
);
5948 payload_size
-= hexnumlen (todo
);
5949 todo
= min (todo
, payload_size
);
5953 /* Num bytes that will fit. */
5954 todo
= min (len
, payload_size
/ 2);
5956 payload_size
-= hexnumlen (todo
);
5957 todo
= min (todo
, payload_size
/ 2);
5961 internal_error (__FILE__
, __LINE__
,
5962 _("minumum packet size too small to write data"));
5964 /* If we already need another packet, then try to align the end
5965 of this packet to a useful boundary. */
5966 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
5967 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
5969 /* Append "<memaddr>". */
5970 memaddr
= remote_address_masked (memaddr
);
5971 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
5978 /* Append <len>. Retain the location/size of <len>. It may need to
5979 be adjusted once the packet body has been created. */
5981 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
5989 /* Append the packet body. */
5990 if (packet_format
== 'X')
5992 /* Binary mode. Send target system values byte by byte, in
5993 increasing byte addresses. Only escape certain critical
5995 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
5998 /* If not all TODO bytes fit, then we'll need another packet. Make
5999 a second try to keep the end of the packet aligned. Don't do
6000 this if the packet is tiny. */
6001 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6005 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6007 if (new_nr_bytes
!= nr_bytes
)
6008 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6013 p
+= payload_length
;
6014 if (use_length
&& nr_bytes
< todo
)
6016 /* Escape chars have filled up the buffer prematurely,
6017 and we have actually sent fewer bytes than planned.
6018 Fix-up the length field of the packet. Use the same
6019 number of characters as before. */
6020 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6021 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6026 /* Normal mode: Send target system values byte by byte, in
6027 increasing byte addresses. Each byte is encoded as a two hex
6029 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6033 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6034 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6036 if (rs
->buf
[0] == 'E')
6038 /* There is no correspondance between what the remote protocol
6039 uses for errors and errno codes. We would like a cleaner way
6040 of representing errors (big enough to include errno codes,
6041 bfd_error codes, and others). But for now just return EIO. */
6046 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6047 fewer bytes than we'd planned. */
6051 /* Write memory data directly to the remote machine.
6052 This does not inform the data cache; the data cache uses this.
6053 MEMADDR is the address in the remote memory space.
6054 MYADDR is the address of the buffer in our space.
6055 LEN is the number of bytes.
6057 Returns number of bytes transferred, or 0 (setting errno) for
6058 error. Only transfer a single packet. */
6061 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
6063 char *packet_format
= 0;
6065 /* Check whether the target supports binary download. */
6066 check_binary_download (memaddr
);
6068 switch (remote_protocol_packets
[PACKET_X
].support
)
6071 packet_format
= "X";
6073 case PACKET_DISABLE
:
6074 packet_format
= "M";
6076 case PACKET_SUPPORT_UNKNOWN
:
6077 internal_error (__FILE__
, __LINE__
,
6078 _("remote_write_bytes: bad internal state"));
6080 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6083 return remote_write_bytes_aux (packet_format
,
6084 memaddr
, myaddr
, len
, packet_format
[0], 1);
6087 /* Read memory data directly from the remote machine.
6088 This does not use the data cache; the data cache uses this.
6089 MEMADDR is the address in the remote memory space.
6090 MYADDR is the address of the buffer in our space.
6091 LEN is the number of bytes.
6093 Returns number of bytes transferred, or 0 for error. */
6095 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
6096 remote targets) shouldn't attempt to read the entire buffer.
6097 Instead it should read a single packet worth of data and then
6098 return the byte size of that packet to the caller. The caller (its
6099 caller and its callers caller ;-) already contains code for
6100 handling partial reads. */
6103 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6105 struct remote_state
*rs
= get_remote_state ();
6106 int max_buf_size
; /* Max size of packet output buffer. */
6112 max_buf_size
= get_memory_read_packet_size ();
6113 /* The packet buffer will be large enough for the payload;
6114 get_memory_packet_size ensures this. */
6123 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
6125 /* construct "m"<memaddr>","<len>" */
6126 /* sprintf (rs->buf, "m%lx,%x", (unsigned long) memaddr, todo); */
6127 memaddr
= remote_address_masked (memaddr
);
6130 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6132 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6136 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6138 if (rs
->buf
[0] == 'E'
6139 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6140 && rs
->buf
[3] == '\0')
6142 /* There is no correspondance between what the remote
6143 protocol uses for errors and errno codes. We would like
6144 a cleaner way of representing errors (big enough to
6145 include errno codes, bfd_error codes, and others). But
6146 for now just return EIO. */
6151 /* Reply describes memory byte by byte,
6152 each byte encoded as two hex characters. */
6155 if ((i
= hex2bin (p
, myaddr
, todo
)) < todo
)
6157 /* Reply is short. This means that we were able to read
6158 only part of what we wanted to. */
6159 return i
+ (origlen
- len
);
6169 /* Remote notification handler. */
6172 handle_notification (char *buf
, size_t length
)
6174 if (strncmp (buf
, "Stop:", 5) == 0)
6176 if (pending_stop_reply
)
6177 /* We've already parsed the in-flight stop-reply, but the stub
6178 for some reason thought we didn't, possibly due to timeout
6179 on its side. Just ignore it. */
6183 struct cleanup
*old_chain
;
6184 struct stop_reply
*reply
= stop_reply_xmalloc ();
6185 old_chain
= make_cleanup (do_stop_reply_xfree
, reply
);
6187 remote_parse_stop_reply (buf
+ 5, reply
);
6189 discard_cleanups (old_chain
);
6191 /* Be careful to only set it after parsing, since an error
6192 may be thrown then. */
6193 pending_stop_reply
= reply
;
6195 /* Notify the event loop there's a stop reply to acknowledge
6196 and that there may be more events to fetch. */
6197 mark_async_event_handler (remote_async_get_pending_events_token
);
6201 /* We ignore notifications we don't recognize, for compatibility
6202 with newer stubs. */
6207 /* Read or write LEN bytes from inferior memory at MEMADDR,
6208 transferring to or from debugger address BUFFER. Write to inferior
6209 if SHOULD_WRITE is nonzero. Returns length of data written or
6210 read; 0 for error. TARGET is unused. */
6213 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6214 int should_write
, struct mem_attrib
*attrib
,
6215 struct target_ops
*target
)
6219 set_general_thread (inferior_ptid
);
6222 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6224 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6229 /* Sends a packet with content determined by the printf format string
6230 FORMAT and the remaining arguments, then gets the reply. Returns
6231 whether the packet was a success, a failure, or unknown. */
6233 static enum packet_result
6234 remote_send_printf (const char *format
, ...)
6236 struct remote_state
*rs
= get_remote_state ();
6237 int max_size
= get_remote_packet_size ();
6240 va_start (ap
, format
);
6243 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6244 internal_error (__FILE__
, __LINE__
, "Too long remote packet.");
6246 if (putpkt (rs
->buf
) < 0)
6247 error (_("Communication problem with target."));
6250 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6252 return packet_check_result (rs
->buf
);
6256 restore_remote_timeout (void *p
)
6258 int value
= *(int *)p
;
6259 remote_timeout
= value
;
6262 /* Flash writing can take quite some time. We'll set
6263 effectively infinite timeout for flash operations.
6264 In future, we'll need to decide on a better approach. */
6265 static const int remote_flash_timeout
= 1000;
6268 remote_flash_erase (struct target_ops
*ops
,
6269 ULONGEST address
, LONGEST length
)
6271 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
6272 int saved_remote_timeout
= remote_timeout
;
6273 enum packet_result ret
;
6275 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6276 &saved_remote_timeout
);
6277 remote_timeout
= remote_flash_timeout
;
6279 ret
= remote_send_printf ("vFlashErase:%s,%s",
6280 phex (address
, addr_size
),
6284 case PACKET_UNKNOWN
:
6285 error (_("Remote target does not support flash erase"));
6287 error (_("Error erasing flash with vFlashErase packet"));
6292 do_cleanups (back_to
);
6296 remote_flash_write (struct target_ops
*ops
,
6297 ULONGEST address
, LONGEST length
,
6298 const gdb_byte
*data
)
6300 int saved_remote_timeout
= remote_timeout
;
6302 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6303 &saved_remote_timeout
);
6305 remote_timeout
= remote_flash_timeout
;
6306 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6307 do_cleanups (back_to
);
6313 remote_flash_done (struct target_ops
*ops
)
6315 int saved_remote_timeout
= remote_timeout
;
6317 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6318 &saved_remote_timeout
);
6320 remote_timeout
= remote_flash_timeout
;
6321 ret
= remote_send_printf ("vFlashDone");
6322 do_cleanups (back_to
);
6326 case PACKET_UNKNOWN
:
6327 error (_("Remote target does not support vFlashDone"));
6329 error (_("Error finishing flash operation"));
6336 remote_files_info (struct target_ops
*ignore
)
6338 puts_filtered ("Debugging a target over a serial line.\n");
6341 /* Stuff for dealing with the packets which are part of this protocol.
6342 See comment at top of file for details. */
6344 /* Read a single character from the remote end. */
6347 readchar (int timeout
)
6351 ch
= serial_readchar (remote_desc
, timeout
);
6356 switch ((enum serial_rc
) ch
)
6360 error (_("Remote connection closed"));
6363 perror_with_name (_("Remote communication error"));
6365 case SERIAL_TIMEOUT
:
6371 /* Send the command in *BUF to the remote machine, and read the reply
6372 into *BUF. Report an error if we get an error reply. Resize
6373 *BUF using xrealloc if necessary to hold the result, and update
6377 remote_send (char **buf
,
6381 getpkt (buf
, sizeof_buf
, 0);
6383 if ((*buf
)[0] == 'E')
6384 error (_("Remote failure reply: %s"), *buf
);
6387 /* Return a pointer to an xmalloc'ed string representing an escaped
6388 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
6389 etc. The caller is responsible for releasing the returned
6393 escape_buffer (const char *buf
, int n
)
6395 struct cleanup
*old_chain
;
6396 struct ui_file
*stb
;
6399 stb
= mem_fileopen ();
6400 old_chain
= make_cleanup_ui_file_delete (stb
);
6402 fputstrn_unfiltered (buf
, n
, 0, stb
);
6403 str
= ui_file_xstrdup (stb
, NULL
);
6404 do_cleanups (old_chain
);
6408 /* Display a null-terminated packet on stdout, for debugging, using C
6412 print_packet (char *buf
)
6414 puts_filtered ("\"");
6415 fputstr_filtered (buf
, '"', gdb_stdout
);
6416 puts_filtered ("\"");
6422 return putpkt_binary (buf
, strlen (buf
));
6425 /* Send a packet to the remote machine, with error checking. The data
6426 of the packet is in BUF. The string in BUF can be at most
6427 get_remote_packet_size () - 5 to account for the $, # and checksum,
6428 and for a possible /0 if we are debugging (remote_debug) and want
6429 to print the sent packet as a string. */
6432 putpkt_binary (char *buf
, int cnt
)
6434 struct remote_state
*rs
= get_remote_state ();
6436 unsigned char csum
= 0;
6437 char *buf2
= alloca (cnt
+ 6);
6443 /* Catch cases like trying to read memory or listing threads while
6444 we're waiting for a stop reply. The remote server wouldn't be
6445 ready to handle this request, so we'd hang and timeout. We don't
6446 have to worry about this in synchronous mode, because in that
6447 case it's not possible to issue a command while the target is
6448 running. This is not a problem in non-stop mode, because in that
6449 case, the stub is always ready to process serial input. */
6450 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
6451 error (_("Cannot execute this command while the target is running."));
6453 /* We're sending out a new packet. Make sure we don't look at a
6454 stale cached response. */
6455 rs
->cached_wait_status
= 0;
6457 /* Copy the packet into buffer BUF2, encapsulating it
6458 and giving it a checksum. */
6463 for (i
= 0; i
< cnt
; i
++)
6469 *p
++ = tohex ((csum
>> 4) & 0xf);
6470 *p
++ = tohex (csum
& 0xf);
6472 /* Send it over and over until we get a positive ack. */
6476 int started_error_output
= 0;
6480 struct cleanup
*old_chain
;
6484 str
= escape_buffer (buf2
, p
- buf2
);
6485 old_chain
= make_cleanup (xfree
, str
);
6486 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
6487 gdb_flush (gdb_stdlog
);
6488 do_cleanups (old_chain
);
6490 if (serial_write (remote_desc
, buf2
, p
- buf2
))
6491 perror_with_name (_("putpkt: write failed"));
6493 /* If this is a no acks version of the remote protocol, send the
6494 packet and move on. */
6498 /* Read until either a timeout occurs (-2) or '+' is read.
6499 Handle any notification that arrives in the mean time. */
6502 ch
= readchar (remote_timeout
);
6510 case SERIAL_TIMEOUT
:
6513 if (started_error_output
)
6515 putchar_unfiltered ('\n');
6516 started_error_output
= 0;
6525 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
6529 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
6530 case SERIAL_TIMEOUT
:
6534 break; /* Retransmit buffer. */
6538 fprintf_unfiltered (gdb_stdlog
,
6539 "Packet instead of Ack, ignoring it\n");
6540 /* It's probably an old response sent because an ACK
6541 was lost. Gobble up the packet and ack it so it
6542 doesn't get retransmitted when we resend this
6545 serial_write (remote_desc
, "+", 1);
6546 continue; /* Now, go look for +. */
6553 /* If we got a notification, handle it, and go back to looking
6555 /* We've found the start of a notification. Now
6556 collect the data. */
6557 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
6562 struct cleanup
*old_chain
;
6565 str
= escape_buffer (rs
->buf
, val
);
6566 old_chain
= make_cleanup (xfree
, str
);
6567 fprintf_unfiltered (gdb_stdlog
,
6568 " Notification received: %s\n",
6570 do_cleanups (old_chain
);
6572 handle_notification (rs
->buf
, val
);
6573 /* We're in sync now, rewait for the ack. */
6580 if (!started_error_output
)
6582 started_error_output
= 1;
6583 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6585 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6586 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
6595 if (!started_error_output
)
6597 started_error_output
= 1;
6598 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
6600 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
6604 break; /* Here to retransmit. */
6608 /* This is wrong. If doing a long backtrace, the user should be
6609 able to get out next time we call QUIT, without anything as
6610 violent as interrupt_query. If we want to provide a way out of
6611 here without getting to the next QUIT, it should be based on
6612 hitting ^C twice as in remote_wait. */
6623 /* Come here after finding the start of a frame when we expected an
6624 ack. Do our best to discard the rest of this packet. */
6633 c
= readchar (remote_timeout
);
6636 case SERIAL_TIMEOUT
:
6637 /* Nothing we can do. */
6640 /* Discard the two bytes of checksum and stop. */
6641 c
= readchar (remote_timeout
);
6643 c
= readchar (remote_timeout
);
6646 case '*': /* Run length encoding. */
6647 /* Discard the repeat count. */
6648 c
= readchar (remote_timeout
);
6653 /* A regular character. */
6659 /* Come here after finding the start of the frame. Collect the rest
6660 into *BUF, verifying the checksum, length, and handling run-length
6661 compression. NUL terminate the buffer. If there is not enough room,
6662 expand *BUF using xrealloc.
6664 Returns -1 on error, number of characters in buffer (ignoring the
6665 trailing NULL) on success. (could be extended to return one of the
6666 SERIAL status indications). */
6669 read_frame (char **buf_p
,
6676 struct remote_state
*rs
= get_remote_state ();
6683 c
= readchar (remote_timeout
);
6686 case SERIAL_TIMEOUT
:
6688 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
6692 fputs_filtered ("Saw new packet start in middle of old one\n",
6694 return -1; /* Start a new packet, count retries. */
6697 unsigned char pktcsum
;
6703 check_0
= readchar (remote_timeout
);
6705 check_1
= readchar (remote_timeout
);
6707 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
6710 fputs_filtered ("Timeout in checksum, retrying\n",
6714 else if (check_0
< 0 || check_1
< 0)
6717 fputs_filtered ("Communication error in checksum\n",
6722 /* Don't recompute the checksum; with no ack packets we
6723 don't have any way to indicate a packet retransmission
6728 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
6729 if (csum
== pktcsum
)
6734 struct cleanup
*old_chain
;
6737 str
= escape_buffer (buf
, bc
);
6738 old_chain
= make_cleanup (xfree
, str
);
6739 fprintf_unfiltered (gdb_stdlog
,
6741 Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
6742 pktcsum
, csum
, str
);
6743 do_cleanups (old_chain
);
6745 /* Number of characters in buffer ignoring trailing
6749 case '*': /* Run length encoding. */
6754 c
= readchar (remote_timeout
);
6756 repeat
= c
- ' ' + 3; /* Compute repeat count. */
6758 /* The character before ``*'' is repeated. */
6760 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
6762 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
6764 /* Make some more room in the buffer. */
6765 *sizeof_buf
+= repeat
;
6766 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
6770 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
6776 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
6780 if (bc
>= *sizeof_buf
- 1)
6782 /* Make some more room in the buffer. */
6784 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
6795 /* Read a packet from the remote machine, with error checking, and
6796 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
6797 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
6798 rather than timing out; this is used (in synchronous mode) to wait
6799 for a target that is is executing user code to stop. */
6800 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
6801 don't have to change all the calls to getpkt to deal with the
6802 return value, because at the moment I don't know what the right
6803 thing to do it for those. */
6811 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
6815 /* Read a packet from the remote machine, with error checking, and
6816 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
6817 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
6818 rather than timing out; this is used (in synchronous mode) to wait
6819 for a target that is is executing user code to stop. If FOREVER ==
6820 0, this function is allowed to time out gracefully and return an
6821 indication of this to the caller. Otherwise return the number of
6822 bytes read. If EXPECTING_NOTIF, consider receiving a notification
6823 enough reason to return to the caller. */
6826 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
6827 int expecting_notif
)
6829 struct remote_state
*rs
= get_remote_state ();
6835 /* We're reading a new response. Make sure we don't look at a
6836 previously cached response. */
6837 rs
->cached_wait_status
= 0;
6839 strcpy (*buf
, "timeout");
6842 timeout
= watchdog
> 0 ? watchdog
: -1;
6843 else if (expecting_notif
)
6844 timeout
= 0; /* There should already be a char in the buffer. If
6847 timeout
= remote_timeout
;
6851 /* Process any number of notifications, and then return when
6855 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
6857 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
6859 /* This can loop forever if the remote side sends us
6860 characters continuously, but if it pauses, we'll get
6861 SERIAL_TIMEOUT from readchar because of timeout. Then
6862 we'll count that as a retry.
6864 Note that even when forever is set, we will only wait
6865 forever prior to the start of a packet. After that, we
6866 expect characters to arrive at a brisk pace. They should
6867 show up within remote_timeout intervals. */
6869 c
= readchar (timeout
);
6870 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
6872 if (c
== SERIAL_TIMEOUT
)
6874 if (expecting_notif
)
6875 return -1; /* Don't complain, it's normal to not get
6876 anything in this case. */
6878 if (forever
) /* Watchdog went off? Kill the target. */
6882 error (_("Watchdog timeout has expired. Target detached."));
6885 fputs_filtered ("Timed out.\n", gdb_stdlog
);
6889 /* We've found the start of a packet or notification.
6890 Now collect the data. */
6891 val
= read_frame (buf
, sizeof_buf
);
6896 serial_write (remote_desc
, "-", 1);
6899 if (tries
> MAX_TRIES
)
6901 /* We have tried hard enough, and just can't receive the
6902 packet/notification. Give up. */
6903 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
6905 /* Skip the ack char if we're in no-ack mode. */
6906 if (!rs
->noack_mode
)
6907 serial_write (remote_desc
, "+", 1);
6911 /* If we got an ordinary packet, return that to our caller. */
6916 struct cleanup
*old_chain
;
6919 str
= escape_buffer (*buf
, val
);
6920 old_chain
= make_cleanup (xfree
, str
);
6921 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
6922 do_cleanups (old_chain
);
6925 /* Skip the ack char if we're in no-ack mode. */
6926 if (!rs
->noack_mode
)
6927 serial_write (remote_desc
, "+", 1);
6931 /* If we got a notification, handle it, and go back to looking
6935 gdb_assert (c
== '%');
6939 struct cleanup
*old_chain
;
6942 str
= escape_buffer (*buf
, val
);
6943 old_chain
= make_cleanup (xfree
, str
);
6944 fprintf_unfiltered (gdb_stdlog
,
6945 " Notification received: %s\n",
6947 do_cleanups (old_chain
);
6950 handle_notification (*buf
, val
);
6952 /* Notifications require no acknowledgement. */
6954 if (expecting_notif
)
6961 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
6963 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0);
6967 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
)
6969 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1);
6974 remote_kill (struct target_ops
*ops
)
6976 /* Use catch_errors so the user can quit from gdb even when we
6977 aren't on speaking terms with the remote system. */
6978 catch_errors ((catch_errors_ftype
*) putpkt
, "k", "", RETURN_MASK_ERROR
);
6980 /* Don't wait for it to die. I'm not really sure it matters whether
6981 we do or not. For the existing stubs, kill is a noop. */
6982 target_mourn_inferior ();
6986 remote_vkill (int pid
, struct remote_state
*rs
)
6988 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
6991 /* Tell the remote target to detach. */
6992 sprintf (rs
->buf
, "vKill;%x", pid
);
6994 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6996 if (packet_ok (rs
->buf
,
6997 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
6999 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7006 extended_remote_kill (struct target_ops
*ops
)
7009 int pid
= ptid_get_pid (inferior_ptid
);
7010 struct remote_state
*rs
= get_remote_state ();
7012 res
= remote_vkill (pid
, rs
);
7013 if (res
== -1 && !remote_multi_process_p (rs
))
7015 /* Don't try 'k' on a multi-process aware stub -- it has no way
7016 to specify the pid. */
7020 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7021 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7024 /* Don't wait for it to die. I'm not really sure it matters whether
7025 we do or not. For the existing stubs, kill is a noop. */
7031 error (_("Can't kill process"));
7033 target_mourn_inferior ();
7037 remote_mourn (struct target_ops
*ops
)
7039 remote_mourn_1 (ops
);
7042 /* Worker function for remote_mourn. */
7044 remote_mourn_1 (struct target_ops
*target
)
7046 unpush_target (target
);
7048 /* remote_close takes care of doing most of the clean up. */
7049 generic_mourn_inferior ();
7053 extended_remote_mourn_1 (struct target_ops
*target
)
7055 struct remote_state
*rs
= get_remote_state ();
7057 /* In case we got here due to an error, but we're going to stay
7059 rs
->waiting_for_stop_reply
= 0;
7061 /* We're no longer interested in these events. */
7062 discard_pending_stop_replies (ptid_get_pid (inferior_ptid
));
7064 /* If the current general thread belonged to the process we just
7065 detached from or has exited, the remote side current general
7066 thread becomes undefined. Considering a case like this:
7068 - We just got here due to a detach.
7069 - The process that we're detaching from happens to immediately
7070 report a global breakpoint being hit in non-stop mode, in the
7071 same thread we had selected before.
7072 - GDB attaches to this process again.
7073 - This event happens to be the next event we handle.
7075 GDB would consider that the current general thread didn't need to
7076 be set on the stub side (with Hg), since for all it knew,
7077 GENERAL_THREAD hadn't changed.
7079 Notice that although in all-stop mode, the remote server always
7080 sets the current thread to the thread reporting the stop event,
7081 that doesn't happen in non-stop mode; in non-stop, the stub *must
7082 not* change the current thread when reporting a breakpoint hit,
7083 due to the decoupling of event reporting and event handling.
7085 To keep things simple, we always invalidate our notion of the
7087 record_currthread (minus_one_ptid
);
7089 /* Unlike "target remote", we do not want to unpush the target; then
7090 the next time the user says "run", we won't be connected. */
7092 /* Call common code to mark the inferior as not running. */
7093 generic_mourn_inferior ();
7095 if (!have_inferiors ())
7097 if (!remote_multi_process_p (rs
))
7099 /* Check whether the target is running now - some remote stubs
7100 automatically restart after kill. */
7102 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7104 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7106 /* Assume that the target has been restarted. Set inferior_ptid
7107 so that bits of core GDB realizes there's something here, e.g.,
7108 so that the user can say "kill" again. */
7109 inferior_ptid
= magic_null_ptid
;
7116 extended_remote_mourn (struct target_ops
*ops
)
7118 extended_remote_mourn_1 (ops
);
7122 extended_remote_run (char *args
)
7124 struct remote_state
*rs
= get_remote_state ();
7127 /* If the user has disabled vRun support, or we have detected that
7128 support is not available, do not try it. */
7129 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7132 strcpy (rs
->buf
, "vRun;");
7133 len
= strlen (rs
->buf
);
7135 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7136 error (_("Remote file name too long for run packet"));
7137 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7139 gdb_assert (args
!= NULL
);
7142 struct cleanup
*back_to
;
7146 argv
= gdb_buildargv (args
);
7147 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7148 for (i
= 0; argv
[i
] != NULL
; i
++)
7150 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7151 error (_("Argument list too long for run packet"));
7152 rs
->buf
[len
++] = ';';
7153 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7155 do_cleanups (back_to
);
7158 rs
->buf
[len
++] = '\0';
7161 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7163 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7165 /* We have a wait response; we don't need it, though. All is well. */
7168 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7169 /* It wasn't disabled before, but it is now. */
7173 if (remote_exec_file
[0] == '\0')
7174 error (_("Running the default executable on the remote target failed; "
7175 "try \"set remote exec-file\"?"));
7177 error (_("Running \"%s\" on the remote target failed"),
7182 /* In the extended protocol we want to be able to do things like
7183 "run" and have them basically work as expected. So we need
7184 a special create_inferior function. We support changing the
7185 executable file and the command line arguments, but not the
7189 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7190 char **env
, int from_tty
)
7192 /* If running asynchronously, register the target file descriptor
7193 with the event loop. */
7194 if (target_can_async_p ())
7195 target_async (inferior_event_handler
, 0);
7197 /* Now restart the remote server. */
7198 if (extended_remote_run (args
) == -1)
7200 /* vRun was not supported. Fail if we need it to do what the
7202 if (remote_exec_file
[0])
7203 error (_("Remote target does not support \"set remote exec-file\""));
7205 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7207 /* Fall back to "R". */
7208 extended_remote_restart ();
7211 if (!have_inferiors ())
7213 /* Clean up from the last time we ran, before we mark the target
7214 running again. This will mark breakpoints uninserted, and
7215 get_offsets may insert breakpoints. */
7216 init_thread_list ();
7217 init_wait_for_inferior ();
7220 /* Now mark the inferior as running before we do anything else. */
7221 inferior_ptid
= magic_null_ptid
;
7223 /* Now, if we have thread information, update inferior_ptid. */
7224 inferior_ptid
= remote_current_thread (inferior_ptid
);
7226 remote_add_inferior (ptid_get_pid (inferior_ptid
), 0);
7227 add_thread_silent (inferior_ptid
);
7229 /* Get updated offsets, if the stub uses qOffsets. */
7234 extended_remote_create_inferior (struct target_ops
*ops
,
7235 char *exec_file
, char *args
,
7236 char **env
, int from_tty
)
7238 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7242 /* Insert a breakpoint. On targets that have software breakpoint
7243 support, we ask the remote target to do the work; on targets
7244 which don't, we insert a traditional memory breakpoint. */
7247 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
7248 struct bp_target_info
*bp_tgt
)
7250 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
7251 If it succeeds, then set the support to PACKET_ENABLE. If it
7252 fails, and the user has explicitly requested the Z support then
7253 report an error, otherwise, mark it disabled and go on. */
7255 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7257 CORE_ADDR addr
= bp_tgt
->placed_address
;
7258 struct remote_state
*rs
;
7262 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
7264 rs
= get_remote_state ();
7270 addr
= (ULONGEST
) remote_address_masked (addr
);
7271 p
+= hexnumstr (p
, addr
);
7272 sprintf (p
, ",%d", bpsize
);
7275 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7277 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
7282 bp_tgt
->placed_address
= addr
;
7283 bp_tgt
->placed_size
= bpsize
;
7285 case PACKET_UNKNOWN
:
7290 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
7294 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
7295 struct bp_target_info
*bp_tgt
)
7297 CORE_ADDR addr
= bp_tgt
->placed_address
;
7298 struct remote_state
*rs
= get_remote_state ();
7300 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7308 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
7309 p
+= hexnumstr (p
, addr
);
7310 sprintf (p
, ",%d", bp_tgt
->placed_size
);
7313 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7315 return (rs
->buf
[0] == 'E');
7318 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
7322 watchpoint_to_Z_packet (int type
)
7327 return Z_PACKET_WRITE_WP
;
7330 return Z_PACKET_READ_WP
;
7333 return Z_PACKET_ACCESS_WP
;
7336 internal_error (__FILE__
, __LINE__
,
7337 _("hw_bp_to_z: bad watchpoint type %d"), type
);
7342 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
7344 struct remote_state
*rs
= get_remote_state ();
7346 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7348 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7351 sprintf (rs
->buf
, "Z%x,", packet
);
7352 p
= strchr (rs
->buf
, '\0');
7353 addr
= remote_address_masked (addr
);
7354 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7355 sprintf (p
, ",%x", len
);
7358 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7360 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7363 case PACKET_UNKNOWN
:
7368 internal_error (__FILE__
, __LINE__
,
7369 _("remote_insert_watchpoint: reached end of function"));
7374 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
7376 struct remote_state
*rs
= get_remote_state ();
7378 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
7380 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
7383 sprintf (rs
->buf
, "z%x,", packet
);
7384 p
= strchr (rs
->buf
, '\0');
7385 addr
= remote_address_masked (addr
);
7386 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7387 sprintf (p
, ",%x", len
);
7389 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7391 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
7394 case PACKET_UNKNOWN
:
7399 internal_error (__FILE__
, __LINE__
,
7400 _("remote_remove_watchpoint: reached end of function"));
7404 int remote_hw_watchpoint_limit
= -1;
7405 int remote_hw_breakpoint_limit
= -1;
7408 remote_check_watch_resources (int type
, int cnt
, int ot
)
7410 if (type
== bp_hardware_breakpoint
)
7412 if (remote_hw_breakpoint_limit
== 0)
7414 else if (remote_hw_breakpoint_limit
< 0)
7416 else if (cnt
<= remote_hw_breakpoint_limit
)
7421 if (remote_hw_watchpoint_limit
== 0)
7423 else if (remote_hw_watchpoint_limit
< 0)
7427 else if (cnt
<= remote_hw_watchpoint_limit
)
7434 remote_stopped_by_watchpoint (void)
7436 return remote_stopped_by_watchpoint_p
;
7440 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
7443 if (remote_stopped_by_watchpoint ())
7445 *addr_p
= remote_watch_data_address
;
7454 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
7455 struct bp_target_info
*bp_tgt
)
7458 struct remote_state
*rs
;
7461 /* The length field should be set to the size of a breakpoint
7462 instruction, even though we aren't inserting one ourselves. */
7464 gdbarch_remote_breakpoint_from_pc
7465 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
7467 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7470 rs
= get_remote_state ();
7477 addr
= remote_address_masked (bp_tgt
->placed_address
);
7478 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7479 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7482 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7484 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7487 case PACKET_UNKNOWN
:
7492 internal_error (__FILE__
, __LINE__
,
7493 _("remote_insert_hw_breakpoint: reached end of function"));
7498 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
7499 struct bp_target_info
*bp_tgt
)
7502 struct remote_state
*rs
= get_remote_state ();
7505 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
7512 addr
= remote_address_masked (bp_tgt
->placed_address
);
7513 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7514 sprintf (p
, ",%x", bp_tgt
->placed_size
);
7517 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7519 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
7522 case PACKET_UNKNOWN
:
7527 internal_error (__FILE__
, __LINE__
,
7528 _("remote_remove_hw_breakpoint: reached end of function"));
7531 /* Table used by the crc32 function to calcuate the checksum. */
7533 static unsigned long crc32_table
[256] =
7536 static unsigned long
7537 crc32 (unsigned char *buf
, int len
, unsigned int crc
)
7539 if (!crc32_table
[1])
7541 /* Initialize the CRC table and the decoding table. */
7545 for (i
= 0; i
< 256; i
++)
7547 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
7548 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
7555 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
7561 /* compare-sections command
7563 With no arguments, compares each loadable section in the exec bfd
7564 with the same memory range on the target, and reports mismatches.
7565 Useful for verifying the image on the target against the exec file.
7566 Depends on the target understanding the new "qCRC:" request. */
7568 /* FIXME: cagney/1999-10-26: This command should be broken down into a
7569 target method (target verify memory) and generic version of the
7570 actual command. This will allow other high-level code (especially
7571 generic_load()) to make use of this target functionality. */
7574 compare_sections_command (char *args
, int from_tty
)
7576 struct remote_state
*rs
= get_remote_state ();
7578 unsigned long host_crc
, target_crc
;
7579 struct cleanup
*old_chain
;
7582 const char *sectname
;
7589 error (_("command cannot be used without an exec file"));
7590 if (!current_target
.to_shortname
||
7591 strcmp (current_target
.to_shortname
, "remote") != 0)
7592 error (_("command can only be used with remote target"));
7594 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
7596 if (!(s
->flags
& SEC_LOAD
))
7597 continue; /* skip non-loadable section */
7599 size
= bfd_get_section_size (s
);
7601 continue; /* skip zero-length section */
7603 sectname
= bfd_get_section_name (exec_bfd
, s
);
7604 if (args
&& strcmp (args
, sectname
) != 0)
7605 continue; /* not the section selected by user */
7607 matched
= 1; /* do this section */
7609 /* FIXME: assumes lma can fit into long. */
7610 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
7611 (long) lma
, (long) size
);
7614 /* Be clever; compute the host_crc before waiting for target
7616 sectdata
= xmalloc (size
);
7617 old_chain
= make_cleanup (xfree
, sectdata
);
7618 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
7619 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
7621 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7622 if (rs
->buf
[0] == 'E')
7623 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
7624 paddress (target_gdbarch
, lma
),
7625 paddress (target_gdbarch
, lma
+ size
));
7626 if (rs
->buf
[0] != 'C')
7627 error (_("remote target does not support this operation"));
7629 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
7630 target_crc
= target_crc
* 16 + fromhex (*tmp
);
7632 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
7633 paddress (target_gdbarch
, lma
),
7634 paddress (target_gdbarch
, lma
+ size
));
7635 if (host_crc
== target_crc
)
7636 printf_filtered ("matched.\n");
7639 printf_filtered ("MIS-MATCHED!\n");
7643 do_cleanups (old_chain
);
7646 warning (_("One or more sections of the remote executable does not match\n\
7647 the loaded file\n"));
7648 if (args
&& !matched
)
7649 printf_filtered (_("No loaded section named '%s'.\n"), args
);
7652 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
7653 into remote target. The number of bytes written to the remote
7654 target is returned, or -1 for error. */
7657 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
7658 const char *annex
, const gdb_byte
*writebuf
,
7659 ULONGEST offset
, LONGEST len
,
7660 struct packet_config
*packet
)
7664 struct remote_state
*rs
= get_remote_state ();
7665 int max_size
= get_memory_write_packet_size ();
7667 if (packet
->support
== PACKET_DISABLE
)
7670 /* Insert header. */
7671 i
= snprintf (rs
->buf
, max_size
,
7672 "qXfer:%s:write:%s:%s:",
7673 object_name
, annex
? annex
: "",
7674 phex_nz (offset
, sizeof offset
));
7675 max_size
-= (i
+ 1);
7677 /* Escape as much data as fits into rs->buf. */
7678 buf_len
= remote_escape_output
7679 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
7681 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
7682 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
7683 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
7686 unpack_varlen_hex (rs
->buf
, &n
);
7690 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
7691 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
7692 number of bytes read is returned, or 0 for EOF, or -1 for error.
7693 The number of bytes read may be less than LEN without indicating an
7694 EOF. PACKET is checked and updated to indicate whether the remote
7695 target supports this object. */
7698 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
7700 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
7701 struct packet_config
*packet
)
7703 static char *finished_object
;
7704 static char *finished_annex
;
7705 static ULONGEST finished_offset
;
7707 struct remote_state
*rs
= get_remote_state ();
7708 LONGEST i
, n
, packet_len
;
7710 if (packet
->support
== PACKET_DISABLE
)
7713 /* Check whether we've cached an end-of-object packet that matches
7715 if (finished_object
)
7717 if (strcmp (object_name
, finished_object
) == 0
7718 && strcmp (annex
? annex
: "", finished_annex
) == 0
7719 && offset
== finished_offset
)
7722 /* Otherwise, we're now reading something different. Discard
7724 xfree (finished_object
);
7725 xfree (finished_annex
);
7726 finished_object
= NULL
;
7727 finished_annex
= NULL
;
7730 /* Request only enough to fit in a single packet. The actual data
7731 may not, since we don't know how much of it will need to be escaped;
7732 the target is free to respond with slightly less data. We subtract
7733 five to account for the response type and the protocol frame. */
7734 n
= min (get_remote_packet_size () - 5, len
);
7735 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
7736 object_name
, annex
? annex
: "",
7737 phex_nz (offset
, sizeof offset
),
7738 phex_nz (n
, sizeof n
));
7739 i
= putpkt (rs
->buf
);
7744 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
7745 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
7748 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
7749 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
7751 /* 'm' means there is (or at least might be) more data after this
7752 batch. That does not make sense unless there's at least one byte
7753 of data in this reply. */
7754 if (rs
->buf
[0] == 'm' && packet_len
== 1)
7755 error (_("Remote qXfer reply contained no data."));
7757 /* Got some data. */
7758 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
7760 /* 'l' is an EOF marker, possibly including a final block of data,
7761 or possibly empty. If we have the final block of a non-empty
7762 object, record this fact to bypass a subsequent partial read. */
7763 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
7765 finished_object
= xstrdup (object_name
);
7766 finished_annex
= xstrdup (annex
? annex
: "");
7767 finished_offset
= offset
+ i
;
7774 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
7775 const char *annex
, gdb_byte
*readbuf
,
7776 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
7778 struct remote_state
*rs
;
7783 set_general_thread (inferior_ptid
);
7785 rs
= get_remote_state ();
7787 /* Handle memory using the standard memory routines. */
7788 if (object
== TARGET_OBJECT_MEMORY
)
7793 /* If the remote target is connected but not running, we should
7794 pass this request down to a lower stratum (e.g. the executable
7796 if (!target_has_execution
)
7799 if (writebuf
!= NULL
)
7800 xfered
= remote_write_bytes (offset
, writebuf
, len
);
7802 xfered
= remote_read_bytes (offset
, readbuf
, len
);
7806 else if (xfered
== 0 && errno
== 0)
7812 /* Handle SPU memory using qxfer packets. */
7813 if (object
== TARGET_OBJECT_SPU
)
7816 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
7817 &remote_protocol_packets
7818 [PACKET_qXfer_spu_read
]);
7820 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
7821 &remote_protocol_packets
7822 [PACKET_qXfer_spu_write
]);
7825 /* Handle extra signal info using qxfer packets. */
7826 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
7829 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
7830 &remote_protocol_packets
7831 [PACKET_qXfer_siginfo_read
]);
7833 return remote_write_qxfer (ops
, "siginfo", annex
, writebuf
, offset
, len
,
7834 &remote_protocol_packets
7835 [PACKET_qXfer_siginfo_write
]);
7838 /* Only handle flash writes. */
7839 if (writebuf
!= NULL
)
7845 case TARGET_OBJECT_FLASH
:
7846 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
7850 else if (xfered
== 0 && errno
== 0)
7860 /* Map pre-existing objects onto letters. DO NOT do this for new
7861 objects!!! Instead specify new query packets. */
7864 case TARGET_OBJECT_AVR
:
7868 case TARGET_OBJECT_AUXV
:
7869 gdb_assert (annex
== NULL
);
7870 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
7871 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
7873 case TARGET_OBJECT_AVAILABLE_FEATURES
:
7874 return remote_read_qxfer
7875 (ops
, "features", annex
, readbuf
, offset
, len
,
7876 &remote_protocol_packets
[PACKET_qXfer_features
]);
7878 case TARGET_OBJECT_LIBRARIES
:
7879 return remote_read_qxfer
7880 (ops
, "libraries", annex
, readbuf
, offset
, len
,
7881 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
7883 case TARGET_OBJECT_MEMORY_MAP
:
7884 gdb_assert (annex
== NULL
);
7885 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
7886 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
7888 case TARGET_OBJECT_OSDATA
:
7889 /* Should only get here if we're connected. */
7890 gdb_assert (remote_desc
);
7891 return remote_read_qxfer
7892 (ops
, "osdata", annex
, readbuf
, offset
, len
,
7893 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
7895 case TARGET_OBJECT_THREADS
:
7896 gdb_assert (annex
== NULL
);
7897 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
7898 &remote_protocol_packets
[PACKET_qXfer_threads
]);
7904 /* Note: a zero OFFSET and LEN can be used to query the minimum
7906 if (offset
== 0 && len
== 0)
7907 return (get_remote_packet_size ());
7908 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
7909 large enough let the caller deal with it. */
7910 if (len
< get_remote_packet_size ())
7912 len
= get_remote_packet_size ();
7914 /* Except for querying the minimum buffer size, target must be open. */
7916 error (_("remote query is only available after target open"));
7918 gdb_assert (annex
!= NULL
);
7919 gdb_assert (readbuf
!= NULL
);
7925 /* We used one buffer char for the remote protocol q command and
7926 another for the query type. As the remote protocol encapsulation
7927 uses 4 chars plus one extra in case we are debugging
7928 (remote_debug), we have PBUFZIZ - 7 left to pack the query
7931 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
7933 /* Bad caller may have sent forbidden characters. */
7934 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
7939 gdb_assert (annex
[i
] == '\0');
7941 i
= putpkt (rs
->buf
);
7945 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7946 strcpy ((char *) readbuf
, rs
->buf
);
7948 return strlen ((char *) readbuf
);
7952 remote_search_memory (struct target_ops
* ops
,
7953 CORE_ADDR start_addr
, ULONGEST search_space_len
,
7954 const gdb_byte
*pattern
, ULONGEST pattern_len
,
7955 CORE_ADDR
*found_addrp
)
7957 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
7958 struct remote_state
*rs
= get_remote_state ();
7959 int max_size
= get_memory_write_packet_size ();
7960 struct packet_config
*packet
=
7961 &remote_protocol_packets
[PACKET_qSearch_memory
];
7962 /* number of packet bytes used to encode the pattern,
7963 this could be more than PATTERN_LEN due to escape characters */
7964 int escaped_pattern_len
;
7965 /* amount of pattern that was encodable in the packet */
7966 int used_pattern_len
;
7969 ULONGEST found_addr
;
7971 /* Don't go to the target if we don't have to.
7972 This is done before checking packet->support to avoid the possibility that
7973 a success for this edge case means the facility works in general. */
7974 if (pattern_len
> search_space_len
)
7976 if (pattern_len
== 0)
7978 *found_addrp
= start_addr
;
7982 /* If we already know the packet isn't supported, fall back to the simple
7983 way of searching memory. */
7985 if (packet
->support
== PACKET_DISABLE
)
7987 /* Target doesn't provided special support, fall back and use the
7988 standard support (copy memory and do the search here). */
7989 return simple_search_memory (ops
, start_addr
, search_space_len
,
7990 pattern
, pattern_len
, found_addrp
);
7993 /* Insert header. */
7994 i
= snprintf (rs
->buf
, max_size
,
7995 "qSearch:memory:%s;%s;",
7996 phex_nz (start_addr
, addr_size
),
7997 phex_nz (search_space_len
, sizeof (search_space_len
)));
7998 max_size
-= (i
+ 1);
8000 /* Escape as much data as fits into rs->buf. */
8001 escaped_pattern_len
=
8002 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8003 &used_pattern_len
, max_size
);
8005 /* Bail if the pattern is too large. */
8006 if (used_pattern_len
!= pattern_len
)
8007 error ("Pattern is too large to transmit to remote target.");
8009 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8010 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8011 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8013 /* The request may not have worked because the command is not
8014 supported. If so, fall back to the simple way. */
8015 if (packet
->support
== PACKET_DISABLE
)
8017 return simple_search_memory (ops
, start_addr
, search_space_len
,
8018 pattern
, pattern_len
, found_addrp
);
8023 if (rs
->buf
[0] == '0')
8025 else if (rs
->buf
[0] == '1')
8028 if (rs
->buf
[1] != ',')
8029 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8030 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8031 *found_addrp
= found_addr
;
8034 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8040 remote_rcmd (char *command
,
8041 struct ui_file
*outbuf
)
8043 struct remote_state
*rs
= get_remote_state ();
8047 error (_("remote rcmd is only available after target open"));
8049 /* Send a NULL command across as an empty command. */
8050 if (command
== NULL
)
8053 /* The query prefix. */
8054 strcpy (rs
->buf
, "qRcmd,");
8055 p
= strchr (rs
->buf
, '\0');
8057 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/) > get_remote_packet_size ())
8058 error (_("\"monitor\" command ``%s'' is too long."), command
);
8060 /* Encode the actual command. */
8061 bin2hex ((gdb_byte
*) command
, p
, 0);
8063 if (putpkt (rs
->buf
) < 0)
8064 error (_("Communication problem with target."));
8066 /* get/display the response */
8071 /* XXX - see also remote_get_noisy_reply(). */
8073 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8076 error (_("Target does not support this command."));
8077 if (buf
[0] == 'O' && buf
[1] != 'K')
8079 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8082 if (strcmp (buf
, "OK") == 0)
8084 if (strlen (buf
) == 3 && buf
[0] == 'E'
8085 && isdigit (buf
[1]) && isdigit (buf
[2]))
8087 error (_("Protocol error with Rcmd"));
8089 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
8091 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
8092 fputc_unfiltered (c
, outbuf
);
8098 static VEC(mem_region_s
) *
8099 remote_memory_map (struct target_ops
*ops
)
8101 VEC(mem_region_s
) *result
= NULL
;
8102 char *text
= target_read_stralloc (¤t_target
,
8103 TARGET_OBJECT_MEMORY_MAP
, NULL
);
8107 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
8108 result
= parse_memory_map (text
);
8109 do_cleanups (back_to
);
8116 packet_command (char *args
, int from_tty
)
8118 struct remote_state
*rs
= get_remote_state ();
8121 error (_("command can only be used with remote target"));
8124 error (_("remote-packet command requires packet text as argument"));
8126 puts_filtered ("sending: ");
8127 print_packet (args
);
8128 puts_filtered ("\n");
8131 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8132 puts_filtered ("received: ");
8133 print_packet (rs
->buf
);
8134 puts_filtered ("\n");
8138 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
8140 static void display_thread_info (struct gdb_ext_thread_info
*info
);
8142 static void threadset_test_cmd (char *cmd
, int tty
);
8144 static void threadalive_test (char *cmd
, int tty
);
8146 static void threadlist_test_cmd (char *cmd
, int tty
);
8148 int get_and_display_threadinfo (threadref
*ref
);
8150 static void threadinfo_test_cmd (char *cmd
, int tty
);
8152 static int thread_display_step (threadref
*ref
, void *context
);
8154 static void threadlist_update_test_cmd (char *cmd
, int tty
);
8156 static void init_remote_threadtests (void);
8158 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
8161 threadset_test_cmd (char *cmd
, int tty
)
8163 int sample_thread
= SAMPLE_THREAD
;
8165 printf_filtered (_("Remote threadset test\n"));
8166 set_general_thread (sample_thread
);
8171 threadalive_test (char *cmd
, int tty
)
8173 int sample_thread
= SAMPLE_THREAD
;
8174 int pid
= ptid_get_pid (inferior_ptid
);
8175 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
8177 if (remote_thread_alive (ptid
))
8178 printf_filtered ("PASS: Thread alive test\n");
8180 printf_filtered ("FAIL: Thread alive test\n");
8183 void output_threadid (char *title
, threadref
*ref
);
8186 output_threadid (char *title
, threadref
*ref
)
8190 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
8192 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
8196 threadlist_test_cmd (char *cmd
, int tty
)
8199 threadref nextthread
;
8200 int done
, result_count
;
8201 threadref threadlist
[3];
8203 printf_filtered ("Remote Threadlist test\n");
8204 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
8205 &result_count
, &threadlist
[0]))
8206 printf_filtered ("FAIL: threadlist test\n");
8209 threadref
*scan
= threadlist
;
8210 threadref
*limit
= scan
+ result_count
;
8212 while (scan
< limit
)
8213 output_threadid (" thread ", scan
++);
8218 display_thread_info (struct gdb_ext_thread_info
*info
)
8220 output_threadid ("Threadid: ", &info
->threadid
);
8221 printf_filtered ("Name: %s\n ", info
->shortname
);
8222 printf_filtered ("State: %s\n", info
->display
);
8223 printf_filtered ("other: %s\n\n", info
->more_display
);
8227 get_and_display_threadinfo (threadref
*ref
)
8231 struct gdb_ext_thread_info threadinfo
;
8233 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
8234 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
8235 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
8236 display_thread_info (&threadinfo
);
8241 threadinfo_test_cmd (char *cmd
, int tty
)
8243 int athread
= SAMPLE_THREAD
;
8247 int_to_threadref (&thread
, athread
);
8248 printf_filtered ("Remote Threadinfo test\n");
8249 if (!get_and_display_threadinfo (&thread
))
8250 printf_filtered ("FAIL cannot get thread info\n");
8254 thread_display_step (threadref
*ref
, void *context
)
8256 /* output_threadid(" threadstep ",ref); *//* simple test */
8257 return get_and_display_threadinfo (ref
);
8261 threadlist_update_test_cmd (char *cmd
, int tty
)
8263 printf_filtered ("Remote Threadlist update test\n");
8264 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
8268 init_remote_threadtests (void)
8270 add_com ("tlist", class_obscure
, threadlist_test_cmd
, _("\
8271 Fetch and print the remote list of thread identifiers, one pkt only"));
8272 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
8273 _("Fetch and display info about one thread"));
8274 add_com ("tset", class_obscure
, threadset_test_cmd
,
8275 _("Test setting to a different thread"));
8276 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
8277 _("Iterate through updating all remote thread info"));
8278 add_com ("talive", class_obscure
, threadalive_test
,
8279 _(" Remote thread alive test "));
8284 /* Convert a thread ID to a string. Returns the string in a static
8288 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
8290 static char buf
[64];
8291 struct remote_state
*rs
= get_remote_state ();
8293 if (ptid_is_pid (ptid
))
8295 /* Printing an inferior target id. */
8297 /* When multi-process extensions are off, there's no way in the
8298 remote protocol to know the remote process id, if there's any
8299 at all. There's one exception --- when we're connected with
8300 target extended-remote, and we manually attached to a process
8301 with "attach PID". We don't record anywhere a flag that
8302 allows us to distinguish that case from the case of
8303 connecting with extended-remote and the stub already being
8304 attached to a process, and reporting yes to qAttached, hence
8305 no smart special casing here. */
8306 if (!remote_multi_process_p (rs
))
8308 xsnprintf (buf
, sizeof buf
, "Remote target");
8312 return normal_pid_to_str (ptid
);
8316 if (ptid_equal (magic_null_ptid
, ptid
))
8317 xsnprintf (buf
, sizeof buf
, "Thread <main>");
8318 else if (remote_multi_process_p (rs
))
8319 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
8320 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
8322 xsnprintf (buf
, sizeof buf
, "Thread %ld",
8323 ptid_get_tid (ptid
));
8328 /* Get the address of the thread local variable in OBJFILE which is
8329 stored at OFFSET within the thread local storage for thread PTID. */
8332 remote_get_thread_local_address (struct target_ops
*ops
,
8333 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
8335 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
8337 struct remote_state
*rs
= get_remote_state ();
8339 char *endp
= rs
->buf
+ get_remote_packet_size ();
8340 enum packet_result result
;
8342 strcpy (p
, "qGetTLSAddr:");
8344 p
= write_ptid (p
, endp
, ptid
);
8346 p
+= hexnumstr (p
, offset
);
8348 p
+= hexnumstr (p
, lm
);
8352 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8353 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
8354 if (result
== PACKET_OK
)
8358 unpack_varlen_hex (rs
->buf
, &result
);
8361 else if (result
== PACKET_UNKNOWN
)
8362 throw_error (TLS_GENERIC_ERROR
,
8363 _("Remote target doesn't support qGetTLSAddr packet"));
8365 throw_error (TLS_GENERIC_ERROR
,
8366 _("Remote target failed to process qGetTLSAddr request"));
8369 throw_error (TLS_GENERIC_ERROR
,
8370 _("TLS not supported or disabled on this target"));
8375 /* Support for inferring a target description based on the current
8376 architecture and the size of a 'g' packet. While the 'g' packet
8377 can have any size (since optional registers can be left off the
8378 end), some sizes are easily recognizable given knowledge of the
8379 approximate architecture. */
8381 struct remote_g_packet_guess
8384 const struct target_desc
*tdesc
;
8386 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
8387 DEF_VEC_O(remote_g_packet_guess_s
);
8389 struct remote_g_packet_data
8391 VEC(remote_g_packet_guess_s
) *guesses
;
8394 static struct gdbarch_data
*remote_g_packet_data_handle
;
8397 remote_g_packet_data_init (struct obstack
*obstack
)
8399 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
8403 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
8404 const struct target_desc
*tdesc
)
8406 struct remote_g_packet_data
*data
8407 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
8408 struct remote_g_packet_guess new_guess
, *guess
;
8411 gdb_assert (tdesc
!= NULL
);
8414 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8416 if (guess
->bytes
== bytes
)
8417 internal_error (__FILE__
, __LINE__
,
8418 "Duplicate g packet description added for size %d",
8421 new_guess
.bytes
= bytes
;
8422 new_guess
.tdesc
= tdesc
;
8423 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
8426 /* Return 1 if remote_read_description would do anything on this target
8427 and architecture, 0 otherwise. */
8430 remote_read_description_p (struct target_ops
*target
)
8432 struct remote_g_packet_data
*data
8433 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8435 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8441 static const struct target_desc
*
8442 remote_read_description (struct target_ops
*target
)
8444 struct remote_g_packet_data
*data
8445 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
8447 /* Do not try this during initial connection, when we do not know
8448 whether there is a running but stopped thread. */
8449 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
8452 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
8454 struct remote_g_packet_guess
*guess
;
8456 int bytes
= send_g_packet ();
8459 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
8461 if (guess
->bytes
== bytes
)
8462 return guess
->tdesc
;
8464 /* We discard the g packet. A minor optimization would be to
8465 hold on to it, and fill the register cache once we have selected
8466 an architecture, but it's too tricky to do safely. */
8472 /* Remote file transfer support. This is host-initiated I/O, not
8473 target-initiated; for target-initiated, see remote-fileio.c. */
8475 /* If *LEFT is at least the length of STRING, copy STRING to
8476 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8477 decrease *LEFT. Otherwise raise an error. */
8480 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
8482 int len
= strlen (string
);
8485 error (_("Packet too long for target."));
8487 memcpy (*buffer
, string
, len
);
8491 /* NUL-terminate the buffer as a convenience, if there is
8497 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
8498 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8499 decrease *LEFT. Otherwise raise an error. */
8502 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
8505 if (2 * len
> *left
)
8506 error (_("Packet too long for target."));
8508 bin2hex (bytes
, *buffer
, len
);
8512 /* NUL-terminate the buffer as a convenience, if there is
8518 /* If *LEFT is large enough, convert VALUE to hex and add it to
8519 *BUFFER, update *BUFFER to point to the new end of the buffer, and
8520 decrease *LEFT. Otherwise raise an error. */
8523 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
8525 int len
= hexnumlen (value
);
8528 error (_("Packet too long for target."));
8530 hexnumstr (*buffer
, value
);
8534 /* NUL-terminate the buffer as a convenience, if there is
8540 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
8541 value, *REMOTE_ERRNO to the remote error number or zero if none
8542 was included, and *ATTACHMENT to point to the start of the annex
8543 if any. The length of the packet isn't needed here; there may
8544 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
8546 Return 0 if the packet could be parsed, -1 if it could not. If
8547 -1 is returned, the other variables may not be initialized. */
8550 remote_hostio_parse_result (char *buffer
, int *retcode
,
8551 int *remote_errno
, char **attachment
)
8558 if (buffer
[0] != 'F')
8562 *retcode
= strtol (&buffer
[1], &p
, 16);
8563 if (errno
!= 0 || p
== &buffer
[1])
8566 /* Check for ",errno". */
8570 *remote_errno
= strtol (p
+ 1, &p2
, 16);
8571 if (errno
!= 0 || p
+ 1 == p2
)
8576 /* Check for ";attachment". If there is no attachment, the
8577 packet should end here. */
8580 *attachment
= p
+ 1;
8583 else if (*p
== '\0')
8589 /* Send a prepared I/O packet to the target and read its response.
8590 The prepared packet is in the global RS->BUF before this function
8591 is called, and the answer is there when we return.
8593 COMMAND_BYTES is the length of the request to send, which may include
8594 binary data. WHICH_PACKET is the packet configuration to check
8595 before attempting a packet. If an error occurs, *REMOTE_ERRNO
8596 is set to the error number and -1 is returned. Otherwise the value
8597 returned by the function is returned.
8599 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
8600 attachment is expected; an error will be reported if there's a
8601 mismatch. If one is found, *ATTACHMENT will be set to point into
8602 the packet buffer and *ATTACHMENT_LEN will be set to the
8603 attachment's length. */
8606 remote_hostio_send_command (int command_bytes
, int which_packet
,
8607 int *remote_errno
, char **attachment
,
8608 int *attachment_len
)
8610 struct remote_state
*rs
= get_remote_state ();
8611 int ret
, bytes_read
;
8612 char *attachment_tmp
;
8615 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
8617 *remote_errno
= FILEIO_ENOSYS
;
8621 putpkt_binary (rs
->buf
, command_bytes
);
8622 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8624 /* If it timed out, something is wrong. Don't try to parse the
8628 *remote_errno
= FILEIO_EINVAL
;
8632 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
8635 *remote_errno
= FILEIO_EINVAL
;
8637 case PACKET_UNKNOWN
:
8638 *remote_errno
= FILEIO_ENOSYS
;
8644 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
8647 *remote_errno
= FILEIO_EINVAL
;
8651 /* Make sure we saw an attachment if and only if we expected one. */
8652 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
8653 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
8655 *remote_errno
= FILEIO_EINVAL
;
8659 /* If an attachment was found, it must point into the packet buffer;
8660 work out how many bytes there were. */
8661 if (attachment_tmp
!= NULL
)
8663 *attachment
= attachment_tmp
;
8664 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
8670 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
8671 remote file descriptor, or -1 if an error occurs (and set
8675 remote_hostio_open (const char *filename
, int flags
, int mode
,
8678 struct remote_state
*rs
= get_remote_state ();
8680 int left
= get_remote_packet_size () - 1;
8682 remote_buffer_add_string (&p
, &left
, "vFile:open:");
8684 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
8686 remote_buffer_add_string (&p
, &left
, ",");
8688 remote_buffer_add_int (&p
, &left
, flags
);
8689 remote_buffer_add_string (&p
, &left
, ",");
8691 remote_buffer_add_int (&p
, &left
, mode
);
8693 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
8694 remote_errno
, NULL
, NULL
);
8697 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
8698 Return the number of bytes written, or -1 if an error occurs (and
8699 set *REMOTE_ERRNO). */
8702 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
8703 ULONGEST offset
, int *remote_errno
)
8705 struct remote_state
*rs
= get_remote_state ();
8707 int left
= get_remote_packet_size ();
8710 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
8712 remote_buffer_add_int (&p
, &left
, fd
);
8713 remote_buffer_add_string (&p
, &left
, ",");
8715 remote_buffer_add_int (&p
, &left
, offset
);
8716 remote_buffer_add_string (&p
, &left
, ",");
8718 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
8719 get_remote_packet_size () - (p
- rs
->buf
));
8721 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
8722 remote_errno
, NULL
, NULL
);
8725 /* Read up to LEN bytes FD on the remote target into READ_BUF
8726 Return the number of bytes read, or -1 if an error occurs (and
8727 set *REMOTE_ERRNO). */
8730 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
8731 ULONGEST offset
, int *remote_errno
)
8733 struct remote_state
*rs
= get_remote_state ();
8736 int left
= get_remote_packet_size ();
8737 int ret
, attachment_len
;
8740 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
8742 remote_buffer_add_int (&p
, &left
, fd
);
8743 remote_buffer_add_string (&p
, &left
, ",");
8745 remote_buffer_add_int (&p
, &left
, len
);
8746 remote_buffer_add_string (&p
, &left
, ",");
8748 remote_buffer_add_int (&p
, &left
, offset
);
8750 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
8751 remote_errno
, &attachment
,
8757 read_len
= remote_unescape_input (attachment
, attachment_len
,
8759 if (read_len
!= ret
)
8760 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
8765 /* Close FD on the remote target. Return 0, or -1 if an error occurs
8766 (and set *REMOTE_ERRNO). */
8769 remote_hostio_close (int fd
, int *remote_errno
)
8771 struct remote_state
*rs
= get_remote_state ();
8773 int left
= get_remote_packet_size () - 1;
8775 remote_buffer_add_string (&p
, &left
, "vFile:close:");
8777 remote_buffer_add_int (&p
, &left
, fd
);
8779 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
8780 remote_errno
, NULL
, NULL
);
8783 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
8784 occurs (and set *REMOTE_ERRNO). */
8787 remote_hostio_unlink (const char *filename
, int *remote_errno
)
8789 struct remote_state
*rs
= get_remote_state ();
8791 int left
= get_remote_packet_size () - 1;
8793 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
8795 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
8798 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
8799 remote_errno
, NULL
, NULL
);
8803 remote_fileio_errno_to_host (int errnum
)
8827 case FILEIO_ENOTDIR
:
8847 case FILEIO_ENAMETOOLONG
:
8848 return ENAMETOOLONG
;
8854 remote_hostio_error (int errnum
)
8856 int host_error
= remote_fileio_errno_to_host (errnum
);
8858 if (host_error
== -1)
8859 error (_("Unknown remote I/O error %d"), errnum
);
8861 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
8865 remote_hostio_close_cleanup (void *opaque
)
8867 int fd
= *(int *) opaque
;
8870 remote_hostio_close (fd
, &remote_errno
);
8875 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
8877 const char *filename
= bfd_get_filename (abfd
);
8878 int fd
, remote_errno
;
8881 gdb_assert (remote_filename_p (filename
));
8883 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
8886 errno
= remote_fileio_errno_to_host (remote_errno
);
8887 bfd_set_error (bfd_error_system_call
);
8891 stream
= xmalloc (sizeof (int));
8897 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
8899 int fd
= *(int *)stream
;
8904 /* Ignore errors on close; these may happen if the remote
8905 connection was already torn down. */
8906 remote_hostio_close (fd
, &remote_errno
);
8912 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
8913 file_ptr nbytes
, file_ptr offset
)
8915 int fd
= *(int *)stream
;
8917 file_ptr pos
, bytes
;
8920 while (nbytes
> pos
)
8922 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
8923 offset
+ pos
, &remote_errno
);
8925 /* Success, but no bytes, means end-of-file. */
8929 errno
= remote_fileio_errno_to_host (remote_errno
);
8930 bfd_set_error (bfd_error_system_call
);
8941 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
8943 /* FIXME: We should probably implement remote_hostio_stat. */
8944 sb
->st_size
= INT_MAX
;
8949 remote_filename_p (const char *filename
)
8951 return strncmp (filename
, "remote:", 7) == 0;
8955 remote_bfd_open (const char *remote_file
, const char *target
)
8957 return bfd_openr_iovec (remote_file
, target
,
8958 remote_bfd_iovec_open
, NULL
,
8959 remote_bfd_iovec_pread
,
8960 remote_bfd_iovec_close
,
8961 remote_bfd_iovec_stat
);
8965 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
8967 struct cleanup
*back_to
, *close_cleanup
;
8968 int retcode
, fd
, remote_errno
, bytes
, io_size
;
8971 int bytes_in_buffer
;
8976 error (_("command can only be used with remote target"));
8978 file
= fopen (local_file
, "rb");
8980 perror_with_name (local_file
);
8981 back_to
= make_cleanup_fclose (file
);
8983 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
8985 0700, &remote_errno
);
8987 remote_hostio_error (remote_errno
);
8989 /* Send up to this many bytes at once. They won't all fit in the
8990 remote packet limit, so we'll transfer slightly fewer. */
8991 io_size
= get_remote_packet_size ();
8992 buffer
= xmalloc (io_size
);
8993 make_cleanup (xfree
, buffer
);
8995 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
8997 bytes_in_buffer
= 0;
9000 while (bytes_in_buffer
|| !saw_eof
)
9004 bytes
= fread (buffer
+ bytes_in_buffer
, 1, io_size
- bytes_in_buffer
,
9009 error (_("Error reading %s."), local_file
);
9012 /* EOF. Unless there is something still in the
9013 buffer from the last iteration, we are done. */
9015 if (bytes_in_buffer
== 0)
9023 bytes
+= bytes_in_buffer
;
9024 bytes_in_buffer
= 0;
9026 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
, offset
, &remote_errno
);
9029 remote_hostio_error (remote_errno
);
9030 else if (retcode
== 0)
9031 error (_("Remote write of %d bytes returned 0!"), bytes
);
9032 else if (retcode
< bytes
)
9034 /* Short write. Save the rest of the read data for the next
9036 bytes_in_buffer
= bytes
- retcode
;
9037 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
9043 discard_cleanups (close_cleanup
);
9044 if (remote_hostio_close (fd
, &remote_errno
))
9045 remote_hostio_error (remote_errno
);
9048 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
9049 do_cleanups (back_to
);
9053 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
9055 struct cleanup
*back_to
, *close_cleanup
;
9056 int fd
, remote_errno
, bytes
, io_size
;
9062 error (_("command can only be used with remote target"));
9064 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
9066 remote_hostio_error (remote_errno
);
9068 file
= fopen (local_file
, "wb");
9070 perror_with_name (local_file
);
9071 back_to
= make_cleanup_fclose (file
);
9073 /* Send up to this many bytes at once. They won't all fit in the
9074 remote packet limit, so we'll transfer slightly fewer. */
9075 io_size
= get_remote_packet_size ();
9076 buffer
= xmalloc (io_size
);
9077 make_cleanup (xfree
, buffer
);
9079 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9084 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
9086 /* Success, but no bytes, means end-of-file. */
9089 remote_hostio_error (remote_errno
);
9093 bytes
= fwrite (buffer
, 1, bytes
, file
);
9095 perror_with_name (local_file
);
9098 discard_cleanups (close_cleanup
);
9099 if (remote_hostio_close (fd
, &remote_errno
))
9100 remote_hostio_error (remote_errno
);
9103 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
9104 do_cleanups (back_to
);
9108 remote_file_delete (const char *remote_file
, int from_tty
)
9110 int retcode
, remote_errno
;
9113 error (_("command can only be used with remote target"));
9115 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
9117 remote_hostio_error (remote_errno
);
9120 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
9124 remote_put_command (char *args
, int from_tty
)
9126 struct cleanup
*back_to
;
9130 error_no_arg (_("file to put"));
9132 argv
= gdb_buildargv (args
);
9133 back_to
= make_cleanup_freeargv (argv
);
9134 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9135 error (_("Invalid parameters to remote put"));
9137 remote_file_put (argv
[0], argv
[1], from_tty
);
9139 do_cleanups (back_to
);
9143 remote_get_command (char *args
, int from_tty
)
9145 struct cleanup
*back_to
;
9149 error_no_arg (_("file to get"));
9151 argv
= gdb_buildargv (args
);
9152 back_to
= make_cleanup_freeargv (argv
);
9153 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
9154 error (_("Invalid parameters to remote get"));
9156 remote_file_get (argv
[0], argv
[1], from_tty
);
9158 do_cleanups (back_to
);
9162 remote_delete_command (char *args
, int from_tty
)
9164 struct cleanup
*back_to
;
9168 error_no_arg (_("file to delete"));
9170 argv
= gdb_buildargv (args
);
9171 back_to
= make_cleanup_freeargv (argv
);
9172 if (argv
[0] == NULL
|| argv
[1] != NULL
)
9173 error (_("Invalid parameters to remote delete"));
9175 remote_file_delete (argv
[0], from_tty
);
9177 do_cleanups (back_to
);
9181 remote_command (char *args
, int from_tty
)
9183 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
9187 remote_can_execute_reverse (void)
9189 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
9190 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
9197 remote_supports_non_stop (void)
9203 remote_supports_multi_process (void)
9205 struct remote_state
*rs
= get_remote_state ();
9206 return remote_multi_process_p (rs
);
9210 remote_supports_cond_tracepoints (void)
9212 struct remote_state
*rs
= get_remote_state ();
9213 return rs
->cond_tracepoints
;
9217 remote_supports_fast_tracepoints (void)
9219 struct remote_state
*rs
= get_remote_state ();
9220 return rs
->fast_tracepoints
;
9224 remote_trace_init ()
9227 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9228 if (strcmp (target_buf
, "OK"))
9229 error (_("Target does not support this command."));
9232 static void free_actions_list (char **actions_list
);
9233 static void free_actions_list_cleanup_wrapper (void *);
9235 free_actions_list_cleanup_wrapper (void *al
)
9237 free_actions_list (al
);
9241 free_actions_list (char **actions_list
)
9245 if (actions_list
== 0)
9248 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
9249 xfree (actions_list
[ndx
]);
9251 xfree (actions_list
);
9255 remote_download_tracepoint (struct breakpoint
*t
)
9261 char **stepping_actions
;
9263 struct cleanup
*old_chain
= NULL
;
9264 struct agent_expr
*aexpr
;
9265 struct cleanup
*aexpr_chain
= NULL
;
9268 encode_actions (t
, &tdp_actions
, &stepping_actions
);
9269 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
9271 (void) make_cleanup (free_actions_list_cleanup_wrapper
, stepping_actions
);
9273 tpaddr
= t
->loc
->address
;
9274 sprintf_vma (tmp
, (t
->loc
? tpaddr
: 0));
9275 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
9277 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
9278 t
->step_count
, t
->pass_count
);
9279 /* Fast tracepoints are mostly handled by the target, but we can
9280 tell the target how big of an instruction block should be moved
9282 if (t
->type
== bp_fast_tracepoint
)
9284 /* Only test for support at download time; we may not know
9285 target capabilities at definition time. */
9286 if (remote_supports_fast_tracepoints ())
9290 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch
,
9291 tpaddr
, &isize
, NULL
))
9292 sprintf (buf
+ strlen (buf
), ":F%x", isize
);
9294 /* If it passed validation at definition but fails now,
9295 something is very wrong. */
9296 internal_error (__FILE__
, __LINE__
,
9297 "Fast tracepoint not valid during download");
9300 /* Fast tracepoints are functionally identical to regular
9301 tracepoints, so don't take lack of support as a reason to
9302 give up on the trace run. */
9303 warning (_("Target does not support fast tracepoints, downloading %d as regular tracepoint"), t
->number
);
9305 /* If the tracepoint has a conditional, make it into an agent
9306 expression and append to the definition. */
9309 /* Only test support at download time, we may not know target
9310 capabilities at definition time. */
9311 if (remote_supports_cond_tracepoints ())
9313 aexpr
= gen_eval_for_expr (t
->loc
->address
, t
->loc
->cond
);
9314 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
9315 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
9316 pkt
= buf
+ strlen (buf
);
9317 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
9318 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
9320 do_cleanups (aexpr_chain
);
9323 warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t
->number
);
9326 if (t
->actions
|| *default_collect
)
9329 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9330 if (strcmp (target_buf
, "OK"))
9331 error (_("Target does not support tracepoints."));
9333 if (!t
->actions
&& !*default_collect
)
9336 /* do_single_steps (t); */
9339 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
9341 QUIT
; /* allow user to bail out with ^C */
9342 sprintf (buf
, "QTDP:-%x:%s:%s%c",
9343 t
->number
, tmp
, /* address */
9345 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
9348 remote_get_noisy_reply (&target_buf
,
9350 if (strcmp (target_buf
, "OK"))
9351 error (_("Error on target while setting tracepoints."));
9354 if (stepping_actions
)
9356 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
9358 QUIT
; /* allow user to bail out with ^C */
9359 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
9360 t
->number
, tmp
, /* address */
9361 ((ndx
== 0) ? "S" : ""),
9362 stepping_actions
[ndx
],
9363 (stepping_actions
[ndx
+ 1] ? "-" : ""));
9365 remote_get_noisy_reply (&target_buf
,
9367 if (strcmp (target_buf
, "OK"))
9368 error (_("Error on target while setting tracepoints."));
9371 do_cleanups (old_chain
);
9376 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
9378 struct remote_state
*rs
= get_remote_state ();
9381 sprintf (rs
->buf
, "QTDV:%x:%s:%x:",
9382 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8), tsv
->builtin
);
9383 p
= rs
->buf
+ strlen (rs
->buf
);
9384 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
9385 error (_("Trace state variable name too long for tsv definition packet"));
9386 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
9389 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9393 remote_trace_set_readonly_regions ()
9401 return; /* No information to give. */
9403 strcpy (target_buf
, "QTro");
9404 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9406 char tmp1
[40], tmp2
[40];
9408 if ((s
->flags
& SEC_LOAD
) == 0 ||
9409 /* (s->flags & SEC_CODE) == 0 || */
9410 (s
->flags
& SEC_READONLY
) == 0)
9415 size
= bfd_get_section_size (s
);
9416 sprintf_vma (tmp1
, lma
);
9417 sprintf_vma (tmp2
, lma
+ size
);
9418 sprintf (target_buf
+ strlen (target_buf
),
9419 ":%s,%s", tmp1
, tmp2
);
9423 putpkt (target_buf
);
9424 getpkt (&target_buf
, &target_buf_size
, 0);
9429 remote_trace_start ()
9432 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9433 if (strcmp (target_buf
, "OK"))
9434 error (_("Bogus reply from target: %s"), target_buf
);
9438 remote_get_trace_status (struct trace_status
*ts
)
9440 char *p
, *p1
, *p_temp
;
9442 /* FIXME we need to get register block size some other way */
9443 extern int trace_regblock_size
;
9444 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
9446 putpkt ("qTStatus");
9447 getpkt (&target_buf
, &target_buf_size
, 0);
9448 /* FIXME should handle more variety of replies */
9452 /* If the remote target doesn't do tracing, flag it. */
9456 /* We're working with a live target. */
9459 /* Set some defaults. */
9460 ts
->running_known
= 0;
9461 ts
->stop_reason
= trace_stop_reason_unknown
;
9462 ts
->traceframe_count
= -1;
9463 ts
->buffer_free
= 0;
9466 error (_("Bogus trace status reply from target: %s"), target_buf
);
9468 parse_trace_status (p
, ts
);
9474 remote_trace_stop ()
9477 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9478 if (strcmp (target_buf
, "OK"))
9479 error (_("Bogus reply from target: %s"), target_buf
);
9483 remote_trace_find (enum trace_find_type type
, int num
,
9484 ULONGEST addr1
, ULONGEST addr2
,
9487 struct remote_state
*rs
= get_remote_state ();
9489 int target_frameno
= -1, target_tracept
= -1;
9492 strcpy (p
, "QTFrame:");
9493 p
= strchr (p
, '\0');
9497 sprintf (p
, "%x", num
);
9500 sprintf (p
, "pc:%s", phex_nz (addr1
, 0));
9503 sprintf (p
, "tdp:%x", num
);
9506 sprintf (p
, "range:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
9509 sprintf (p
, "outside:%s:%s", phex_nz (addr1
, 0), phex_nz (addr2
, 0));
9512 error ("Unknown trace find type %d", type
);
9516 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
9518 while (reply
&& *reply
)
9522 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
9523 error (_("Target failed to find requested trace frame."));
9526 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
9527 error (_("Target failed to find requested trace frame."));
9529 case 'O': /* "OK"? */
9530 if (reply
[1] == 'K' && reply
[2] == '\0')
9533 error (_("Bogus reply from target: %s"), reply
);
9536 error (_("Bogus reply from target: %s"), reply
);
9539 *tpp
= target_tracept
;
9540 return target_frameno
;
9544 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
9546 struct remote_state
*rs
= get_remote_state ();
9550 sprintf (rs
->buf
, "qTV:%x", tsvnum
);
9552 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9553 if (reply
&& *reply
)
9557 unpack_varlen_hex (reply
+ 1, &uval
);
9558 *val
= (LONGEST
) uval
;
9566 remote_save_trace_data (char *filename
)
9568 struct remote_state
*rs
= get_remote_state ();
9572 strcpy (p
, "QTSave:");
9574 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
9575 error (_("Remote file name too long for trace save packet"));
9576 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
9579 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9583 /* This is basically a memory transfer, but needs to be its own packet
9584 because we don't know how the target actually organizes its trace
9585 memory, plus we want to be able to ask for as much as possible, but
9586 not be unhappy if we don't get as much as we ask for. */
9589 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
9591 struct remote_state
*rs
= get_remote_state ();
9597 strcpy (p
, "qTBuffer:");
9599 p
+= hexnumstr (p
, offset
);
9601 p
+= hexnumstr (p
, len
);
9605 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9606 if (reply
&& *reply
)
9608 /* 'l' by itself means we're at the end of the buffer and
9609 there is nothing more to get. */
9613 /* Convert the reply into binary. Limit the number of bytes to
9614 convert according to our passed-in buffer size, rather than
9615 what was returned in the packet; if the target is
9616 unexpectedly generous and gives us a bigger reply than we
9617 asked for, we don't want to crash. */
9618 rslt
= hex2bin (target_buf
, buf
, len
);
9622 /* Something went wrong, flag as an error. */
9627 remote_set_disconnected_tracing (int val
)
9629 struct remote_state
*rs
= get_remote_state ();
9631 sprintf (rs
->buf
, "QTDisconnected:%x", val
);
9633 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9634 if (strcmp (target_buf
, "OK"))
9635 error (_("Target does not support this command."));
9639 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
9641 struct thread_info
*info
= find_thread_ptid (ptid
);
9642 if (info
&& info
->private)
9643 return info
->private->core
;
9648 init_remote_ops (void)
9650 remote_ops
.to_shortname
= "remote";
9651 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
9653 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
9654 Specify the serial device it is connected to\n\
9655 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
9656 remote_ops
.to_open
= remote_open
;
9657 remote_ops
.to_close
= remote_close
;
9658 remote_ops
.to_detach
= remote_detach
;
9659 remote_ops
.to_disconnect
= remote_disconnect
;
9660 remote_ops
.to_resume
= remote_resume
;
9661 remote_ops
.to_wait
= remote_wait
;
9662 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
9663 remote_ops
.to_store_registers
= remote_store_registers
;
9664 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
9665 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
9666 remote_ops
.to_files_info
= remote_files_info
;
9667 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
9668 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
9669 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
9670 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
9671 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
9672 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
9673 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
9674 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
9675 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
9676 remote_ops
.to_kill
= remote_kill
;
9677 remote_ops
.to_load
= generic_load
;
9678 remote_ops
.to_mourn_inferior
= remote_mourn
;
9679 remote_ops
.to_thread_alive
= remote_thread_alive
;
9680 remote_ops
.to_find_new_threads
= remote_threads_info
;
9681 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
9682 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
9683 remote_ops
.to_stop
= remote_stop
;
9684 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
9685 remote_ops
.to_rcmd
= remote_rcmd
;
9686 remote_ops
.to_log_command
= serial_log_command
;
9687 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
9688 remote_ops
.to_stratum
= process_stratum
;
9689 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
9690 remote_ops
.to_has_memory
= default_child_has_memory
;
9691 remote_ops
.to_has_stack
= default_child_has_stack
;
9692 remote_ops
.to_has_registers
= default_child_has_registers
;
9693 remote_ops
.to_has_execution
= default_child_has_execution
;
9694 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
9695 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
9696 remote_ops
.to_magic
= OPS_MAGIC
;
9697 remote_ops
.to_memory_map
= remote_memory_map
;
9698 remote_ops
.to_flash_erase
= remote_flash_erase
;
9699 remote_ops
.to_flash_done
= remote_flash_done
;
9700 remote_ops
.to_read_description
= remote_read_description
;
9701 remote_ops
.to_search_memory
= remote_search_memory
;
9702 remote_ops
.to_can_async_p
= remote_can_async_p
;
9703 remote_ops
.to_is_async_p
= remote_is_async_p
;
9704 remote_ops
.to_async
= remote_async
;
9705 remote_ops
.to_async_mask
= remote_async_mask
;
9706 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
9707 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
9708 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
9709 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
9710 remote_ops
.to_trace_init
= remote_trace_init
;
9711 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
9712 remote_ops
.to_download_trace_state_variable
= remote_download_trace_state_variable
;
9713 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
9714 remote_ops
.to_trace_start
= remote_trace_start
;
9715 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
9716 remote_ops
.to_trace_stop
= remote_trace_stop
;
9717 remote_ops
.to_trace_find
= remote_trace_find
;
9718 remote_ops
.to_get_trace_state_variable_value
= remote_get_trace_state_variable_value
;
9719 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
9720 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
9721 remote_ops
.to_upload_trace_state_variables
= remote_upload_trace_state_variables
;
9722 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
9723 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
9724 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
9727 /* Set up the extended remote vector by making a copy of the standard
9728 remote vector and adding to it. */
9731 init_extended_remote_ops (void)
9733 extended_remote_ops
= remote_ops
;
9735 extended_remote_ops
.to_shortname
= "extended-remote";
9736 extended_remote_ops
.to_longname
=
9737 "Extended remote serial target in gdb-specific protocol";
9738 extended_remote_ops
.to_doc
=
9739 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
9740 Specify the serial device it is connected to (e.g. /dev/ttya).";
9741 extended_remote_ops
.to_open
= extended_remote_open
;
9742 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
9743 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
9744 extended_remote_ops
.to_detach
= extended_remote_detach
;
9745 extended_remote_ops
.to_attach
= extended_remote_attach
;
9746 extended_remote_ops
.to_kill
= extended_remote_kill
;
9750 remote_can_async_p (void)
9752 if (!target_async_permitted
)
9753 /* We only enable async when the user specifically asks for it. */
9756 /* We're async whenever the serial device is. */
9757 return remote_async_mask_value
&& serial_can_async_p (remote_desc
);
9761 remote_is_async_p (void)
9763 if (!target_async_permitted
)
9764 /* We only enable async when the user specifically asks for it. */
9767 /* We're async whenever the serial device is. */
9768 return remote_async_mask_value
&& serial_is_async_p (remote_desc
);
9771 /* Pass the SERIAL event on and up to the client. One day this code
9772 will be able to delay notifying the client of an event until the
9773 point where an entire packet has been received. */
9775 static void (*async_client_callback
) (enum inferior_event_type event_type
,
9777 static void *async_client_context
;
9778 static serial_event_ftype remote_async_serial_handler
;
9781 remote_async_serial_handler (struct serial
*scb
, void *context
)
9783 /* Don't propogate error information up to the client. Instead let
9784 the client find out about the error by querying the target. */
9785 async_client_callback (INF_REG_EVENT
, async_client_context
);
9789 remote_async_inferior_event_handler (gdb_client_data data
)
9791 inferior_event_handler (INF_REG_EVENT
, NULL
);
9795 remote_async_get_pending_events_handler (gdb_client_data data
)
9797 remote_get_pending_stop_replies ();
9801 remote_async (void (*callback
) (enum inferior_event_type event_type
,
9802 void *context
), void *context
)
9804 if (remote_async_mask_value
== 0)
9805 internal_error (__FILE__
, __LINE__
,
9806 _("Calling remote_async when async is masked"));
9808 if (callback
!= NULL
)
9810 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
9811 async_client_callback
= callback
;
9812 async_client_context
= context
;
9815 serial_async (remote_desc
, NULL
, NULL
);
9819 remote_async_mask (int new_mask
)
9821 int curr_mask
= remote_async_mask_value
;
9822 remote_async_mask_value
= new_mask
;
9827 set_remote_cmd (char *args
, int from_tty
)
9829 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
9833 show_remote_cmd (char *args
, int from_tty
)
9835 /* We can't just use cmd_show_list here, because we want to skip
9836 the redundant "show remote Z-packet" and the legacy aliases. */
9837 struct cleanup
*showlist_chain
;
9838 struct cmd_list_element
*list
= remote_show_cmdlist
;
9840 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
9841 for (; list
!= NULL
; list
= list
->next
)
9842 if (strcmp (list
->name
, "Z-packet") == 0)
9844 else if (list
->type
== not_set_cmd
)
9845 /* Alias commands are exactly like the original, except they
9846 don't have the normal type. */
9850 struct cleanup
*option_chain
9851 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
9852 ui_out_field_string (uiout
, "name", list
->name
);
9853 ui_out_text (uiout
, ": ");
9854 if (list
->type
== show_cmd
)
9855 do_setshow_command ((char *) NULL
, from_tty
, list
);
9857 cmd_func (list
, NULL
, from_tty
);
9858 /* Close the tuple. */
9859 do_cleanups (option_chain
);
9862 /* Close the tuple. */
9863 do_cleanups (showlist_chain
);
9867 /* Function to be called whenever a new objfile (shlib) is detected. */
9869 remote_new_objfile (struct objfile
*objfile
)
9871 if (remote_desc
!= 0) /* Have a remote connection. */
9872 remote_check_symbols (objfile
);
9875 /* Pull all the tracepoints defined on the target and create local
9876 data structures representing them. We don't want to create real
9877 tracepoints yet, we don't want to mess up the user's existing
9881 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
9883 struct remote_state
*rs
= get_remote_state ();
9886 /* Ask for a first packet of tracepoint definition. */
9888 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9890 while (*p
&& *p
!= 'l')
9892 parse_tracepoint_definition (p
, utpp
);
9893 /* Ask for another packet of tracepoint definition. */
9895 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9902 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
9904 struct remote_state
*rs
= get_remote_state ();
9907 /* Ask for a first packet of variable definition. */
9909 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9911 while (*p
&& *p
!= 'l')
9913 parse_tsv_definition (p
, utsvp
);
9914 /* Ask for another packet of variable definition. */
9916 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9923 _initialize_remote (void)
9925 struct remote_state
*rs
;
9926 struct cmd_list_element
*cmd
;
9929 /* architecture specific data */
9930 remote_gdbarch_data_handle
=
9931 gdbarch_data_register_post_init (init_remote_state
);
9932 remote_g_packet_data_handle
=
9933 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
9935 /* Initialize the per-target state. At the moment there is only one
9936 of these, not one per target. Only one target is active at a
9937 time. The default buffer size is unimportant; it will be expanded
9938 whenever a larger buffer is needed. */
9939 rs
= get_remote_state_raw ();
9941 rs
->buf
= xmalloc (rs
->buf_size
);
9944 add_target (&remote_ops
);
9946 init_extended_remote_ops ();
9947 add_target (&extended_remote_ops
);
9949 /* Hook into new objfile notification. */
9950 observer_attach_new_objfile (remote_new_objfile
);
9952 /* Set up signal handlers. */
9953 sigint_remote_token
=
9954 create_async_signal_handler (async_remote_interrupt
, NULL
);
9955 sigint_remote_twice_token
=
9956 create_async_signal_handler (inferior_event_handler_wrapper
, NULL
);
9959 init_remote_threadtests ();
9962 /* set/show remote ... */
9964 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
9965 Remote protocol specific variables\n\
9966 Configure various remote-protocol specific variables such as\n\
9967 the packets being used"),
9968 &remote_set_cmdlist
, "set remote ",
9969 0 /* allow-unknown */, &setlist
);
9970 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
9971 Remote protocol specific variables\n\
9972 Configure various remote-protocol specific variables such as\n\
9973 the packets being used"),
9974 &remote_show_cmdlist
, "show remote ",
9975 0 /* allow-unknown */, &showlist
);
9977 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
9978 Compare section data on target to the exec file.\n\
9979 Argument is a single section name (default: all loaded sections)."),
9982 add_cmd ("packet", class_maintenance
, packet_command
, _("\
9983 Send an arbitrary packet to a remote target.\n\
9984 maintenance packet TEXT\n\
9985 If GDB is talking to an inferior via the GDB serial protocol, then\n\
9986 this command sends the string TEXT to the inferior, and displays the\n\
9987 response packet. GDB supplies the initial `$' character, and the\n\
9988 terminating `#' character and checksum."),
9991 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
9992 Set whether to send break if interrupted."), _("\
9993 Show whether to send break if interrupted."), _("\
9994 If set, a break, instead of a cntrl-c, is sent to the remote target."),
9995 set_remotebreak
, show_remotebreak
,
9996 &setlist
, &showlist
);
9997 cmd_name
= "remotebreak";
9998 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
9999 deprecate_cmd (cmd
, "set remote interrupt-sequence");
10000 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
10001 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
10002 deprecate_cmd (cmd
, "show remote interrupt-sequence");
10004 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
10005 interrupt_sequence_modes
, &interrupt_sequence_mode
, _("\
10006 Set interrupt sequence to remote target."), _("\
10007 Show interrupt sequence to remote target."), _("\
10008 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
10009 NULL
, show_interrupt_sequence
,
10010 &remote_set_cmdlist
,
10011 &remote_show_cmdlist
);
10013 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
10014 &interrupt_on_connect
, _("\
10015 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10016 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
10017 If set, interrupt sequence is sent to remote target."),
10019 &remote_set_cmdlist
, &remote_show_cmdlist
);
10021 /* Install commands for configuring memory read/write packets. */
10023 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
10024 Set the maximum number of bytes per memory write packet (deprecated)."),
10026 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
10027 Show the maximum number of bytes per memory write packet (deprecated)."),
10029 add_cmd ("memory-write-packet-size", no_class
,
10030 set_memory_write_packet_size
, _("\
10031 Set the maximum number of bytes per memory-write packet.\n\
10032 Specify the number of bytes in a packet or 0 (zero) for the\n\
10033 default packet size. The actual limit is further reduced\n\
10034 dependent on the target. Specify ``fixed'' to disable the\n\
10035 further restriction and ``limit'' to enable that restriction."),
10036 &remote_set_cmdlist
);
10037 add_cmd ("memory-read-packet-size", no_class
,
10038 set_memory_read_packet_size
, _("\
10039 Set the maximum number of bytes per memory-read packet.\n\
10040 Specify the number of bytes in a packet or 0 (zero) for the\n\
10041 default packet size. The actual limit is further reduced\n\
10042 dependent on the target. Specify ``fixed'' to disable the\n\
10043 further restriction and ``limit'' to enable that restriction."),
10044 &remote_set_cmdlist
);
10045 add_cmd ("memory-write-packet-size", no_class
,
10046 show_memory_write_packet_size
,
10047 _("Show the maximum number of bytes per memory-write packet."),
10048 &remote_show_cmdlist
);
10049 add_cmd ("memory-read-packet-size", no_class
,
10050 show_memory_read_packet_size
,
10051 _("Show the maximum number of bytes per memory-read packet."),
10052 &remote_show_cmdlist
);
10054 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
10055 &remote_hw_watchpoint_limit
, _("\
10056 Set the maximum number of target hardware watchpoints."), _("\
10057 Show the maximum number of target hardware watchpoints."), _("\
10058 Specify a negative limit for unlimited."),
10059 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s. */
10060 &remote_set_cmdlist
, &remote_show_cmdlist
);
10061 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
10062 &remote_hw_breakpoint_limit
, _("\
10063 Set the maximum number of target hardware breakpoints."), _("\
10064 Show the maximum number of target hardware breakpoints."), _("\
10065 Specify a negative limit for unlimited."),
10066 NULL
, NULL
, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s. */
10067 &remote_set_cmdlist
, &remote_show_cmdlist
);
10069 add_setshow_integer_cmd ("remoteaddresssize", class_obscure
,
10070 &remote_address_size
, _("\
10071 Set the maximum size of the address (in bits) in a memory packet."), _("\
10072 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
10074 NULL
, /* FIXME: i18n: */
10075 &setlist
, &showlist
);
10077 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
10078 "X", "binary-download", 1);
10080 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
10081 "vCont", "verbose-resume", 0);
10083 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
10084 "QPassSignals", "pass-signals", 0);
10086 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
10087 "qSymbol", "symbol-lookup", 0);
10089 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
10090 "P", "set-register", 1);
10092 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
10093 "p", "fetch-register", 1);
10095 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
10096 "Z0", "software-breakpoint", 0);
10098 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
10099 "Z1", "hardware-breakpoint", 0);
10101 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
10102 "Z2", "write-watchpoint", 0);
10104 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
10105 "Z3", "read-watchpoint", 0);
10107 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
10108 "Z4", "access-watchpoint", 0);
10110 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
10111 "qXfer:auxv:read", "read-aux-vector", 0);
10113 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
10114 "qXfer:features:read", "target-features", 0);
10116 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
10117 "qXfer:libraries:read", "library-info", 0);
10119 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
10120 "qXfer:memory-map:read", "memory-map", 0);
10122 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
10123 "qXfer:spu:read", "read-spu-object", 0);
10125 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
10126 "qXfer:spu:write", "write-spu-object", 0);
10128 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
10129 "qXfer:osdata:read", "osdata", 0);
10131 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
10132 "qXfer:threads:read", "threads", 0);
10134 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
10135 "qXfer:siginfo:read", "read-siginfo-object", 0);
10137 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
10138 "qXfer:siginfo:write", "write-siginfo-object", 0);
10140 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
10141 "qGetTLSAddr", "get-thread-local-storage-address",
10144 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
10145 "bc", "reverse-continue", 0);
10147 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
10148 "bs", "reverse-step", 0);
10150 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
10151 "qSupported", "supported-packets", 0);
10153 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
10154 "qSearch:memory", "search-memory", 0);
10156 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
10157 "vFile:open", "hostio-open", 0);
10159 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
10160 "vFile:pread", "hostio-pread", 0);
10162 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
10163 "vFile:pwrite", "hostio-pwrite", 0);
10165 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
10166 "vFile:close", "hostio-close", 0);
10168 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
10169 "vFile:unlink", "hostio-unlink", 0);
10171 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
10172 "vAttach", "attach", 0);
10174 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
10177 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
10178 "QStartNoAckMode", "noack", 0);
10180 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
10181 "vKill", "kill", 0);
10183 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
10184 "qAttached", "query-attached", 0);
10186 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
10187 "ConditionalTracepoints", "conditional-tracepoints", 0);
10188 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
10189 "FastTracepoints", "fast-tracepoints", 0);
10191 /* Keep the old ``set remote Z-packet ...'' working. Each individual
10192 Z sub-packet has its own set and show commands, but users may
10193 have sets to this variable in their .gdbinit files (or in their
10195 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
10196 &remote_Z_packet_detect
, _("\
10197 Set use of remote protocol `Z' packets"), _("\
10198 Show use of remote protocol `Z' packets "), _("\
10199 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
10201 set_remote_protocol_Z_packet_cmd
,
10202 show_remote_protocol_Z_packet_cmd
, /* FIXME: i18n: Use of remote protocol `Z' packets is %s. */
10203 &remote_set_cmdlist
, &remote_show_cmdlist
);
10205 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
10206 Manipulate files on the remote system\n\
10207 Transfer files to and from the remote target system."),
10208 &remote_cmdlist
, "remote ",
10209 0 /* allow-unknown */, &cmdlist
);
10211 add_cmd ("put", class_files
, remote_put_command
,
10212 _("Copy a local file to the remote system."),
10215 add_cmd ("get", class_files
, remote_get_command
,
10216 _("Copy a remote file to the local system."),
10219 add_cmd ("delete", class_files
, remote_delete_command
,
10220 _("Delete a remote file."),
10223 remote_exec_file
= xstrdup ("");
10224 add_setshow_string_noescape_cmd ("exec-file", class_files
,
10225 &remote_exec_file
, _("\
10226 Set the remote pathname for \"run\""), _("\
10227 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
10228 &remote_set_cmdlist
, &remote_show_cmdlist
);
10230 /* Eventually initialize fileio. See fileio.c */
10231 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
10233 /* Take advantage of the fact that the LWP field is not used, to tag
10234 special ptids with it set to != 0. */
10235 magic_null_ptid
= ptid_build (42000, 1, -1);
10236 not_sent_ptid
= ptid_build (42000, 1, -2);
10237 any_thread_ptid
= ptid_build (42000, 1, 0);
10239 target_buf_size
= 2048;
10240 target_buf
= xmalloc (target_buf_size
);