1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2018 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* See the GDB User Guide for details of the GDB remote protocol. */
30 /*#include "terminal.h" */
33 #include "gdb-stabs.h"
34 #include "gdbthread.h"
36 #include "remote-notif.h"
39 #include "observable.h"
41 #include "cli/cli-decode.h"
42 #include "cli/cli-setshow.h"
43 #include "target-descriptions.h"
45 #include "filestuff.h"
50 #include "gdb_sys_time.h"
52 #include "event-loop.h"
53 #include "event-top.h"
59 #include "gdbcore.h" /* for exec_bfd */
61 #include "remote-fileio.h"
62 #include "gdb/fileio.h"
64 #include "xml-support.h"
66 #include "memory-map.h"
68 #include "tracepoint.h"
73 #include "record-btrace.h"
75 #include "common/scoped_restore.h"
77 #include "common/byte-vector.h"
78 #include <unordered_map>
80 /* The remote target. */
82 static const char remote_doc
[] = N_("\
83 Use a remote computer via a serial line, using a gdb-specific protocol.\n\
84 Specify the serial device it is connected to\n\
85 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
87 static const target_info remote_target_info
= {
89 N_("Remote serial target in gdb-specific protocol"),
93 class remote_target
: public target_ops
98 to_stratum
= process_stratum
;
101 const target_info
&info () const override
102 { return remote_target_info
; }
104 thread_control_capabilities
get_thread_control_capabilities () override
105 { return tc_schedlock
; }
107 /* Open a remote connection. */
108 static void open (const char *, int);
110 void close () override
;
112 void detach (inferior
*, int) override
;
113 void disconnect (const char *, int) override
;
115 void commit_resume () override
;
116 void resume (ptid_t
, int, enum gdb_signal
) override
;
117 ptid_t
wait (ptid_t
, struct target_waitstatus
*, int) override
;
119 void fetch_registers (struct regcache
*, int) override
;
120 void store_registers (struct regcache
*, int) override
;
121 void prepare_to_store (struct regcache
*) override
;
123 void files_info () override
;
125 int insert_breakpoint (struct gdbarch
*, struct bp_target_info
*) override
;
127 int remove_breakpoint (struct gdbarch
*, struct bp_target_info
*,
128 enum remove_bp_reason
) override
;
131 bool stopped_by_sw_breakpoint () override
;
132 bool supports_stopped_by_sw_breakpoint () override
;
134 bool stopped_by_hw_breakpoint () override
;
136 bool supports_stopped_by_hw_breakpoint () override
;
138 bool stopped_by_watchpoint () override
;
140 bool stopped_data_address (CORE_ADDR
*) override
;
142 bool watchpoint_addr_within_range (CORE_ADDR
, CORE_ADDR
, int) override
;
144 int can_use_hw_breakpoint (enum bptype
, int, int) override
;
146 int insert_hw_breakpoint (struct gdbarch
*, struct bp_target_info
*) override
;
148 int remove_hw_breakpoint (struct gdbarch
*, struct bp_target_info
*) override
;
150 int region_ok_for_hw_watchpoint (CORE_ADDR
, int) override
;
152 int insert_watchpoint (CORE_ADDR
, int, enum target_hw_bp_type
,
153 struct expression
*) override
;
155 int remove_watchpoint (CORE_ADDR
, int, enum target_hw_bp_type
,
156 struct expression
*) override
;
158 void kill () override
;
160 void load (const char *, int) override
;
162 void mourn_inferior () override
;
164 void pass_signals (int, unsigned char *) override
;
166 int set_syscall_catchpoint (int, bool, int,
167 gdb::array_view
<const int>) override
;
169 void program_signals (int, unsigned char *) override
;
171 bool thread_alive (ptid_t ptid
) override
;
173 const char *thread_name (struct thread_info
*) override
;
175 void update_thread_list () override
;
177 const char *pid_to_str (ptid_t
) override
;
179 const char *extra_thread_info (struct thread_info
*) override
;
181 ptid_t
get_ada_task_ptid (long lwp
, long thread
) override
;
183 thread_info
*thread_handle_to_thread_info (const gdb_byte
*thread_handle
,
185 inferior
*inf
) override
;
187 void stop (ptid_t
) override
;
189 void interrupt () override
;
191 void pass_ctrlc () override
;
193 enum target_xfer_status
xfer_partial (enum target_object object
,
196 const gdb_byte
*writebuf
,
197 ULONGEST offset
, ULONGEST len
,
198 ULONGEST
*xfered_len
) override
;
200 ULONGEST
get_memory_xfer_limit () override
;
202 void rcmd (const char *command
, struct ui_file
*output
) override
;
204 char *pid_to_exec_file (int pid
) override
;
206 void log_command (const char *cmd
) override
208 serial_log_command (this, cmd
);
211 CORE_ADDR
get_thread_local_address (ptid_t ptid
,
212 CORE_ADDR load_module_addr
,
213 CORE_ADDR offset
) override
;
215 bool has_all_memory () override
{ return default_child_has_all_memory (); }
216 bool has_memory () override
{ return default_child_has_memory (); }
217 bool has_stack () override
{ return default_child_has_stack (); }
218 bool has_registers () override
{ return default_child_has_registers (); }
219 bool has_execution (ptid_t ptid
) override
{ return default_child_has_execution (ptid
); }
221 bool can_execute_reverse () override
;
223 std::vector
<mem_region
> memory_map () override
;
225 void flash_erase (ULONGEST address
, LONGEST length
) override
;
227 void flash_done () override
;
229 const struct target_desc
*read_description () override
;
231 int search_memory (CORE_ADDR start_addr
, ULONGEST search_space_len
,
232 const gdb_byte
*pattern
, ULONGEST pattern_len
,
233 CORE_ADDR
*found_addrp
) override
;
235 bool can_async_p () override
;
237 bool is_async_p () override
;
239 void async (int) override
;
241 void thread_events (int) override
;
243 int can_do_single_step () override
;
245 void terminal_inferior () override
;
247 void terminal_ours () override
;
249 bool supports_non_stop () override
;
251 bool supports_multi_process () override
;
253 bool supports_disable_randomization () override
;
255 bool filesystem_is_local () override
;
258 int fileio_open (struct inferior
*inf
, const char *filename
,
259 int flags
, int mode
, int warn_if_slow
,
260 int *target_errno
) override
;
262 int fileio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
263 ULONGEST offset
, int *target_errno
) override
;
265 int fileio_pread (int fd
, gdb_byte
*read_buf
, int len
,
266 ULONGEST offset
, int *target_errno
) override
;
268 int fileio_fstat (int fd
, struct stat
*sb
, int *target_errno
) override
;
270 int fileio_close (int fd
, int *target_errno
) override
;
272 int fileio_unlink (struct inferior
*inf
,
273 const char *filename
,
274 int *target_errno
) override
;
276 gdb::optional
<std::string
>
277 fileio_readlink (struct inferior
*inf
,
278 const char *filename
,
279 int *target_errno
) override
;
281 bool supports_enable_disable_tracepoint () override
;
283 bool supports_string_tracing () override
;
285 bool supports_evaluation_of_breakpoint_conditions () override
;
287 bool can_run_breakpoint_commands () override
;
289 void trace_init () override
;
291 void download_tracepoint (struct bp_location
*location
) override
;
293 bool can_download_tracepoint () override
;
295 void download_trace_state_variable (const trace_state_variable
&tsv
) override
;
297 void enable_tracepoint (struct bp_location
*location
) override
;
299 void disable_tracepoint (struct bp_location
*location
) override
;
301 void trace_set_readonly_regions () override
;
303 void trace_start () override
;
305 int get_trace_status (struct trace_status
*ts
) override
;
307 void get_tracepoint_status (struct breakpoint
*tp
, struct uploaded_tp
*utp
)
310 void trace_stop () override
;
312 int trace_find (enum trace_find_type type
, int num
,
313 CORE_ADDR addr1
, CORE_ADDR addr2
, int *tpp
) override
;
315 bool get_trace_state_variable_value (int tsv
, LONGEST
*val
) override
;
317 int save_trace_data (const char *filename
) override
;
319 int upload_tracepoints (struct uploaded_tp
**utpp
) override
;
321 int upload_trace_state_variables (struct uploaded_tsv
**utsvp
) override
;
323 LONGEST
get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
) override
;
325 int get_min_fast_tracepoint_insn_len () override
;
327 void set_disconnected_tracing (int val
) override
;
329 void set_circular_trace_buffer (int val
) override
;
331 void set_trace_buffer_size (LONGEST val
) override
;
333 bool set_trace_notes (const char *user
, const char *notes
,
334 const char *stopnotes
) override
;
336 int core_of_thread (ptid_t ptid
) override
;
338 int verify_memory (const gdb_byte
*data
,
339 CORE_ADDR memaddr
, ULONGEST size
) override
;
342 bool get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
) override
;
344 void set_permissions () override
;
346 bool static_tracepoint_marker_at (CORE_ADDR
,
347 struct static_tracepoint_marker
*marker
)
350 std::vector
<static_tracepoint_marker
>
351 static_tracepoint_markers_by_strid (const char *id
) override
;
353 traceframe_info_up
traceframe_info () override
;
355 bool use_agent (bool use
) override
;
356 bool can_use_agent () override
;
358 struct btrace_target_info
*enable_btrace (ptid_t ptid
,
359 const struct btrace_config
*conf
) override
;
361 void disable_btrace (struct btrace_target_info
*tinfo
) override
;
363 void teardown_btrace (struct btrace_target_info
*tinfo
) override
;
365 enum btrace_error
read_btrace (struct btrace_data
*data
,
366 struct btrace_target_info
*btinfo
,
367 enum btrace_read_type type
) override
;
369 const struct btrace_config
*btrace_conf (const struct btrace_target_info
*) override
;
370 bool augmented_libraries_svr4_read () override
;
371 int follow_fork (int, int) override
;
372 void follow_exec (struct inferior
*, char *) override
;
373 int insert_fork_catchpoint (int) override
;
374 int remove_fork_catchpoint (int) override
;
375 int insert_vfork_catchpoint (int) override
;
376 int remove_vfork_catchpoint (int) override
;
377 int insert_exec_catchpoint (int) override
;
378 int remove_exec_catchpoint (int) override
;
379 enum exec_direction_kind
execution_direction () override
;
382 static void open_1 (const char *name
, int from_tty
, int extended_p
);
383 void start_remote (int from_tty
, int extended_p
);
386 static const target_info extended_remote_target_info
= {
388 N_("Extended remote serial target in gdb-specific protocol"),
392 /* Set up the extended remote target by extending the standard remote
393 target and adding to it. */
395 class extended_remote_target final
: public remote_target
398 const target_info
&info () const override
399 { return extended_remote_target_info
; }
401 /* Open an extended-remote connection. */
402 static void open (const char *, int);
404 bool can_create_inferior () override
{ return true; }
405 void create_inferior (const char *, const std::string
&,
406 char **, int) override
;
408 void detach (inferior
*, int) override
;
410 bool can_attach () override
{ return true; }
411 void attach (const char *, int) override
;
413 void post_attach (int) override
;
414 bool supports_disable_randomization () override
;
417 /* Per-program-space data key. */
418 static const struct program_space_data
*remote_pspace_data
;
420 /* The variable registered as the control variable used by the
421 remote exec-file commands. While the remote exec-file setting is
422 per-program-space, the set/show machinery uses this as the
423 location of the remote exec-file value. */
424 static char *remote_exec_file_var
;
426 /* The size to align memory write packets, when practical. The protocol
427 does not guarantee any alignment, and gdb will generate short
428 writes and unaligned writes, but even as a best-effort attempt this
429 can improve bulk transfers. For instance, if a write is misaligned
430 relative to the target's data bus, the stub may need to make an extra
431 round trip fetching data from the target. This doesn't make a
432 huge difference, but it's easy to do, so we try to be helpful.
434 The alignment chosen is arbitrary; usually data bus width is
435 important here, not the possibly larger cache line size. */
436 enum { REMOTE_ALIGN_WRITES
= 16 };
438 /* Prototypes for local functions. */
439 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
440 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
441 int forever
, int *is_notif
);
445 static int remote_vkill (int pid
, struct remote_state
*rs
);
447 static void remote_kill_k (void);
449 static int readchar (int timeout
);
451 static void remote_serial_write (const char *str
, int len
);
453 static void interrupt_query (void);
455 static void set_general_thread (ptid_t ptid
);
456 static void set_continue_thread (ptid_t ptid
);
458 static void get_offsets (void);
460 static void skip_frame (void);
462 static long read_frame (char **buf_p
, long *sizeof_buf
);
464 static int hexnumlen (ULONGEST num
);
466 static int stubhex (int ch
);
468 static int hexnumstr (char *, ULONGEST
);
470 static int hexnumnstr (char *, ULONGEST
, int);
472 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
474 static void print_packet (const char *);
476 static int stub_unpack_int (char *buff
, int fieldlength
);
478 static ptid_t
remote_current_thread (ptid_t oldptid
);
480 static int putpkt_binary (const char *buf
, int cnt
);
482 static void check_binary_download (CORE_ADDR addr
);
484 struct packet_config
;
486 static void show_packet_config_cmd (struct packet_config
*config
);
488 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
490 struct cmd_list_element
*c
,
493 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
494 static ptid_t
read_ptid (const char *buf
, const char **obuf
);
496 static void remote_query_supported (void);
498 static void remote_check_symbols (void);
501 static void stop_reply_xfree (struct stop_reply
*);
502 static void remote_parse_stop_reply (char *, struct stop_reply
*);
503 static void push_stop_reply (struct stop_reply
*);
504 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
505 static int peek_stop_reply (ptid_t ptid
);
507 struct threads_listing_context
;
508 static void remove_new_fork_children (struct threads_listing_context
*);
510 static void remote_async_inferior_event_handler (gdb_client_data
);
512 static int remote_read_description_p (struct target_ops
*target
);
514 static void remote_console_output (char *msg
);
516 static void remote_btrace_reset (void);
518 static void remote_btrace_maybe_reopen (void);
520 static int stop_reply_queue_length (void);
522 static void remote_unpush_and_throw (void);
524 static struct remote_state
*get_remote_state (void);
528 static struct cmd_list_element
*remote_cmdlist
;
530 /* For "set remote" and "show remote". */
532 static struct cmd_list_element
*remote_set_cmdlist
;
533 static struct cmd_list_element
*remote_show_cmdlist
;
535 /* Stub vCont actions support.
537 Each field is a boolean flag indicating whether the stub reports
538 support for the corresponding action. */
540 struct vCont_action_support
555 /* Controls whether GDB is willing to use range stepping. */
557 static int use_range_stepping
= 1;
559 #define OPAQUETHREADBYTES 8
561 /* a 64 bit opaque identifier */
562 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
564 /* About this many threadisds fit in a packet. */
566 #define MAXTHREADLISTRESULTS 32
568 /* The max number of chars in debug output. The rest of chars are
571 #define REMOTE_DEBUG_MAX_CHAR 512
573 /* Data for the vFile:pread readahead cache. */
575 struct readahead_cache
577 /* Invalidate the readahead cache. */
580 /* Invalidate the readahead cache if it is holding data for FD. */
581 void invalidate_fd (int fd
);
583 /* Serve pread from the readahead cache. Returns number of bytes
584 read, or 0 if the request can't be served from the cache. */
585 int pread (int fd
, gdb_byte
*read_buf
, size_t len
, ULONGEST offset
);
587 /* The file descriptor for the file that is being cached. -1 if the
591 /* The offset into the file that the cache buffer corresponds
595 /* The buffer holding the cache contents. */
596 gdb_byte
*buf
= nullptr;
597 /* The buffer's size. We try to read as much as fits into a packet
601 /* Cache hit and miss counters. */
602 ULONGEST hit_count
= 0;
603 ULONGEST miss_count
= 0;
606 /* Description of the remote protocol for a given architecture. */
610 long offset
; /* Offset into G packet. */
611 long regnum
; /* GDB's internal register number. */
612 LONGEST pnum
; /* Remote protocol register number. */
613 int in_g_packet
; /* Always part of G packet. */
614 /* long size in bytes; == register_size (target_gdbarch (), regnum);
616 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
620 struct remote_arch_state
622 explicit remote_arch_state (struct gdbarch
*gdbarch
);
624 /* Description of the remote protocol registers. */
625 long sizeof_g_packet
;
627 /* Description of the remote protocol registers indexed by REGNUM
628 (making an array gdbarch_num_regs in size). */
629 std::unique_ptr
<packet_reg
[]> regs
;
631 /* This is the size (in chars) of the first response to the ``g''
632 packet. It is used as a heuristic when determining the maximum
633 size of memory-read and memory-write packets. A target will
634 typically only reserve a buffer large enough to hold the ``g''
635 packet. The size does not include packet overhead (headers and
637 long actual_register_packet_size
;
639 /* This is the maximum size (in chars) of a non read/write packet.
640 It is also used as a cap on the size of read/write packets. */
641 long remote_packet_size
;
644 /* Description of the remote protocol state for the currently
645 connected target. This is per-target state, and independent of the
646 selected architecture. */
655 /* Get the remote arch state for GDBARCH. */
656 struct remote_arch_state
*get_remote_arch_state (struct gdbarch
*gdbarch
);
660 /* A buffer to use for incoming packets, and its current size. The
661 buffer is grown dynamically for larger incoming packets.
662 Outgoing packets may also be constructed in this buffer.
663 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
664 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
669 /* True if we're going through initial connection setup (finding out
670 about the remote side's threads, relocating symbols, etc.). */
671 bool starting_up
= false;
673 /* If we negotiated packet size explicitly (and thus can bypass
674 heuristics for the largest packet size that will not overflow
675 a buffer in the stub), this will be set to that packet size.
676 Otherwise zero, meaning to use the guessed size. */
677 long explicit_packet_size
= 0;
679 /* remote_wait is normally called when the target is running and
680 waits for a stop reply packet. But sometimes we need to call it
681 when the target is already stopped. We can send a "?" packet
682 and have remote_wait read the response. Or, if we already have
683 the response, we can stash it in BUF and tell remote_wait to
684 skip calling getpkt. This flag is set when BUF contains a
685 stop reply packet and the target is not waiting. */
686 int cached_wait_status
= 0;
688 /* True, if in no ack mode. That is, neither GDB nor the stub will
689 expect acks from each other. The connection is assumed to be
691 bool noack_mode
= false;
693 /* True if we're connected in extended remote mode. */
694 bool extended
= false;
696 /* True if we resumed the target and we're waiting for the target to
697 stop. In the mean time, we can't start another command/query.
698 The remote server wouldn't be ready to process it, so we'd
699 timeout waiting for a reply that would never come and eventually
700 we'd close the connection. This can happen in asynchronous mode
701 because we allow GDB commands while the target is running. */
702 bool waiting_for_stop_reply
= false;
704 /* The status of the stub support for the various vCont actions. */
705 vCont_action_support supports_vCont
;
707 /* True if the user has pressed Ctrl-C, but the target hasn't
708 responded to that. */
709 bool ctrlc_pending_p
= false;
711 /* True if we saw a Ctrl-C while reading or writing from/to the
712 remote descriptor. At that point it is not safe to send a remote
713 interrupt packet, so we instead remember we saw the Ctrl-C and
714 process it once we're done with sending/receiving the current
715 packet, which should be shortly. If however that takes too long,
716 and the user presses Ctrl-C again, we offer to disconnect. */
717 bool got_ctrlc_during_io
= false;
719 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
720 remote_open knows that we don't have a file open when the program
722 struct serial
*remote_desc
= nullptr;
724 /* These are the threads which we last sent to the remote system. The
725 TID member will be -1 for all or -2 for not sent yet. */
726 ptid_t general_thread
= null_ptid
;
727 ptid_t continue_thread
= null_ptid
;
729 /* This is the traceframe which we last selected on the remote system.
730 It will be -1 if no traceframe is selected. */
731 int remote_traceframe_number
= -1;
733 char *last_pass_packet
= nullptr;
735 /* The last QProgramSignals packet sent to the target. We bypass
736 sending a new program signals list down to the target if the new
737 packet is exactly the same as the last we sent. IOW, we only let
738 the target know about program signals list changes. */
739 char *last_program_signals_packet
= nullptr;
741 gdb_signal last_sent_signal
= GDB_SIGNAL_0
;
743 bool last_sent_step
= false;
745 /* The execution direction of the last resume we got. */
746 exec_direction_kind last_resume_exec_dir
= EXEC_FORWARD
;
748 char *finished_object
= nullptr;
749 char *finished_annex
= nullptr;
750 ULONGEST finished_offset
= 0;
752 /* Should we try the 'ThreadInfo' query packet?
754 This variable (NOT available to the user: auto-detect only!)
755 determines whether GDB will use the new, simpler "ThreadInfo"
756 query or the older, more complex syntax for thread queries.
757 This is an auto-detect variable (set to true at each connect,
758 and set to false when the target fails to recognize it). */
759 bool use_threadinfo_query
= false;
760 bool use_threadextra_query
= false;
762 threadref echo_nextthread
{};
763 threadref nextthread
{};
764 threadref resultthreadlist
[MAXTHREADLISTRESULTS
] {};
766 /* The state of remote notification. */
767 struct remote_notif_state
*notif_state
= nullptr;
769 /* The branch trace configuration. */
770 struct btrace_config btrace_config
{};
772 /* The argument to the last "vFile:setfs:" packet we sent, used
773 to avoid sending repeated unnecessary "vFile:setfs:" packets.
774 Initialized to -1 to indicate that no "vFile:setfs:" packet
775 has yet been sent. */
778 /* A readahead cache for vFile:pread. Often, reading a binary
779 involves a sequence of small reads. E.g., when parsing an ELF
780 file. A readahead cache helps mostly the case of remote
781 debugging on a connection with higher latency, due to the
782 request/reply nature of the RSP. We only cache data for a single
783 file descriptor at a time. */
784 struct readahead_cache readahead_cache
;
787 /* Mapping of remote protocol data for each gdbarch. Usually there
788 is only one entry here, though we may see more with stubs that
789 support multi-process. */
790 std::unordered_map
<struct gdbarch
*, remote_arch_state
>
794 /* Private data that we'll store in (struct thread_info)->priv. */
795 struct remote_thread_info
: public private_thread_info
801 /* Thread handle, perhaps a pthread_t or thread_t value, stored as a
802 sequence of bytes. */
803 gdb::byte_vector thread_handle
;
805 /* Whether the target stopped for a breakpoint/watchpoint. */
806 enum target_stop_reason stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
808 /* This is set to the data address of the access causing the target
809 to stop for a watchpoint. */
810 CORE_ADDR watch_data_address
= 0;
812 /* Fields used by the vCont action coalescing implemented in
813 remote_resume / remote_commit_resume. remote_resume stores each
814 thread's last resume request in these fields, so that a later
815 remote_commit_resume knows which is the proper action for this
816 thread to include in the vCont packet. */
818 /* True if the last target_resume call for this thread was a step
819 request, false if a continue request. */
820 int last_resume_step
= 0;
822 /* The signal specified in the last target_resume call for this
824 gdb_signal last_resume_sig
= GDB_SIGNAL_0
;
826 /* Whether this thread was already vCont-resumed on the remote
828 int vcont_resumed
= 0;
831 remote_state::remote_state ()
833 /* The default buffer size is unimportant; it will be expanded
834 whenever a larger buffer is needed. */
835 this->buf_size
= 400;
836 this->buf
= (char *) xmalloc (this->buf_size
);
839 remote_state::~remote_state ()
841 xfree (this->last_pass_packet
);
842 xfree (this->last_program_signals_packet
);
844 xfree (this->finished_object
);
845 xfree (this->finished_annex
);
848 /* This data could be associated with a target, but we do not always
849 have access to the current target when we need it, so for now it is
850 static. This will be fine for as long as only one target is in use
852 static struct remote_state
*remote_state
;
854 static struct remote_state
*
855 get_remote_state_raw (void)
860 /* Utility: generate error from an incoming stub packet. */
862 trace_error (char *buf
)
865 return; /* not an error msg */
868 case '1': /* malformed packet error */
869 if (*++buf
== '0') /* general case: */
870 error (_("remote.c: error in outgoing packet."));
872 error (_("remote.c: error in outgoing packet at field #%ld."),
873 strtol (buf
, NULL
, 16));
875 error (_("Target returns error code '%s'."), buf
);
879 /* Utility: wait for reply from stub, while accepting "O" packets. */
882 remote_get_noisy_reply ()
884 struct remote_state
*rs
= get_remote_state ();
886 do /* Loop on reply from remote stub. */
890 QUIT
; /* Allow user to bail out with ^C. */
891 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
895 else if (startswith (buf
, "qRelocInsn:"))
898 CORE_ADDR from
, to
, org_to
;
900 int adjusted_size
= 0;
903 p
= buf
+ strlen ("qRelocInsn:");
904 pp
= unpack_varlen_hex (p
, &ul
);
906 error (_("invalid qRelocInsn packet: %s"), buf
);
910 unpack_varlen_hex (p
, &ul
);
917 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
920 CATCH (ex
, RETURN_MASK_ALL
)
922 if (ex
.error
== MEMORY_ERROR
)
924 /* Propagate memory errors silently back to the
925 target. The stub may have limited the range of
926 addresses we can write to, for example. */
930 /* Something unexpectedly bad happened. Be verbose
931 so we can tell what, and propagate the error back
932 to the stub, so it doesn't get stuck waiting for
934 exception_fprintf (gdb_stderr
, ex
,
935 _("warning: relocating instruction: "));
943 adjusted_size
= to
- org_to
;
945 xsnprintf (buf
, rs
->buf_size
, "qRelocInsn:%x", adjusted_size
);
949 else if (buf
[0] == 'O' && buf
[1] != 'K')
950 remote_console_output (buf
+ 1); /* 'O' message from stub */
952 return buf
; /* Here's the actual reply. */
957 struct remote_arch_state
*
958 remote_state::get_remote_arch_state (struct gdbarch
*gdbarch
)
960 remote_arch_state
*rsa
;
962 auto it
= this->m_arch_states
.find (gdbarch
);
963 if (it
== this->m_arch_states
.end ())
965 auto p
= this->m_arch_states
.emplace (std::piecewise_construct
,
966 std::forward_as_tuple (gdbarch
),
967 std::forward_as_tuple (gdbarch
));
968 rsa
= &p
.first
->second
;
970 /* Make sure that the packet buffer is plenty big enough for
971 this architecture. */
972 if (this->buf_size
< rsa
->remote_packet_size
)
974 this->buf_size
= 2 * rsa
->remote_packet_size
;
975 this->buf
= (char *) xrealloc (this->buf
, this->buf_size
);
984 /* Fetch the global remote target state. */
986 static struct remote_state
*
987 get_remote_state (void)
989 struct remote_state
*rs
= get_remote_state_raw ();
991 /* Make sure that the remote architecture state has been
992 initialized, because doing so might reallocate rs->buf. Any
993 function which calls getpkt also needs to be mindful of changes
994 to rs->buf, but this call limits the number of places which run
996 rs
->get_remote_arch_state (target_gdbarch ());
1001 /* Cleanup routine for the remote module's pspace data. */
1004 remote_pspace_data_cleanup (struct program_space
*pspace
, void *arg
)
1006 char *remote_exec_file
= (char *) arg
;
1008 xfree (remote_exec_file
);
1011 /* Fetch the remote exec-file from the current program space. */
1014 get_remote_exec_file (void)
1016 char *remote_exec_file
;
1019 = (char *) program_space_data (current_program_space
,
1020 remote_pspace_data
);
1021 if (remote_exec_file
== NULL
)
1024 return remote_exec_file
;
1027 /* Set the remote exec file for PSPACE. */
1030 set_pspace_remote_exec_file (struct program_space
*pspace
,
1031 char *remote_exec_file
)
1033 char *old_file
= (char *) program_space_data (pspace
, remote_pspace_data
);
1036 set_program_space_data (pspace
, remote_pspace_data
,
1037 xstrdup (remote_exec_file
));
1040 /* The "set/show remote exec-file" set command hook. */
1043 set_remote_exec_file (const char *ignored
, int from_tty
,
1044 struct cmd_list_element
*c
)
1046 gdb_assert (remote_exec_file_var
!= NULL
);
1047 set_pspace_remote_exec_file (current_program_space
, remote_exec_file_var
);
1050 /* The "set/show remote exec-file" show command hook. */
1053 show_remote_exec_file (struct ui_file
*file
, int from_tty
,
1054 struct cmd_list_element
*cmd
, const char *value
)
1056 fprintf_filtered (file
, "%s\n", remote_exec_file_var
);
1060 compare_pnums (const void *lhs_
, const void *rhs_
)
1062 const struct packet_reg
* const *lhs
1063 = (const struct packet_reg
* const *) lhs_
;
1064 const struct packet_reg
* const *rhs
1065 = (const struct packet_reg
* const *) rhs_
;
1067 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
1069 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
1076 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
1078 int regnum
, num_remote_regs
, offset
;
1079 struct packet_reg
**remote_regs
;
1081 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
1083 struct packet_reg
*r
= ®s
[regnum
];
1085 if (register_size (gdbarch
, regnum
) == 0)
1086 /* Do not try to fetch zero-sized (placeholder) registers. */
1089 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
1094 /* Define the g/G packet format as the contents of each register
1095 with a remote protocol number, in order of ascending protocol
1098 remote_regs
= XALLOCAVEC (struct packet_reg
*, gdbarch_num_regs (gdbarch
));
1099 for (num_remote_regs
= 0, regnum
= 0;
1100 regnum
< gdbarch_num_regs (gdbarch
);
1102 if (regs
[regnum
].pnum
!= -1)
1103 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
1105 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
1108 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
1110 remote_regs
[regnum
]->in_g_packet
= 1;
1111 remote_regs
[regnum
]->offset
= offset
;
1112 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
1118 /* Given the architecture described by GDBARCH, return the remote
1119 protocol register's number and the register's offset in the g/G
1120 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
1121 If the target does not have a mapping for REGNUM, return false,
1122 otherwise, return true. */
1125 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
1126 int *pnum
, int *poffset
)
1128 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
1130 std::vector
<packet_reg
> regs (gdbarch_num_regs (gdbarch
));
1132 map_regcache_remote_table (gdbarch
, regs
.data ());
1134 *pnum
= regs
[regnum
].pnum
;
1135 *poffset
= regs
[regnum
].offset
;
1140 remote_arch_state::remote_arch_state (struct gdbarch
*gdbarch
)
1142 /* Use the architecture to build a regnum<->pnum table, which will be
1143 1:1 unless a feature set specifies otherwise. */
1144 this->regs
.reset (new packet_reg
[gdbarch_num_regs (gdbarch
)] ());
1146 /* Record the maximum possible size of the g packet - it may turn out
1148 this->sizeof_g_packet
1149 = map_regcache_remote_table (gdbarch
, this->regs
.get ());
1151 /* Default maximum number of characters in a packet body. Many
1152 remote stubs have a hardwired buffer size of 400 bytes
1153 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
1154 as the maximum packet-size to ensure that the packet and an extra
1155 NUL character can always fit in the buffer. This stops GDB
1156 trashing stubs that try to squeeze an extra NUL into what is
1157 already a full buffer (As of 1999-12-04 that was most stubs). */
1158 this->remote_packet_size
= 400 - 1;
1160 /* This one is filled in when a ``g'' packet is received. */
1161 this->actual_register_packet_size
= 0;
1163 /* Should rsa->sizeof_g_packet needs more space than the
1164 default, adjust the size accordingly. Remember that each byte is
1165 encoded as two characters. 32 is the overhead for the packet
1166 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
1167 (``$NN:G...#NN'') is a better guess, the below has been padded a
1169 if (this->sizeof_g_packet
> ((this->remote_packet_size
- 32) / 2))
1170 this->remote_packet_size
= (this->sizeof_g_packet
* 2 + 32);
1173 /* Return the current allowed size of a remote packet. This is
1174 inferred from the current architecture, and should be used to
1175 limit the length of outgoing packets. */
1177 get_remote_packet_size (void)
1179 struct remote_state
*rs
= get_remote_state ();
1180 remote_arch_state
*rsa
= rs
->get_remote_arch_state (target_gdbarch ());
1182 if (rs
->explicit_packet_size
)
1183 return rs
->explicit_packet_size
;
1185 return rsa
->remote_packet_size
;
1188 static struct packet_reg
*
1189 packet_reg_from_regnum (struct gdbarch
*gdbarch
, struct remote_arch_state
*rsa
,
1192 if (regnum
< 0 && regnum
>= gdbarch_num_regs (gdbarch
))
1196 struct packet_reg
*r
= &rsa
->regs
[regnum
];
1198 gdb_assert (r
->regnum
== regnum
);
1203 static struct packet_reg
*
1204 packet_reg_from_pnum (struct gdbarch
*gdbarch
, struct remote_arch_state
*rsa
,
1209 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
1211 struct packet_reg
*r
= &rsa
->regs
[i
];
1213 if (r
->pnum
== pnum
)
1219 static remote_target remote_ops
;
1221 static extended_remote_target extended_remote_ops
;
1223 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
1224 ``forever'' still use the normal timeout mechanism. This is
1225 currently used by the ASYNC code to guarentee that target reads
1226 during the initial connect always time-out. Once getpkt has been
1227 modified to return a timeout indication and, in turn
1228 remote_wait()/wait_for_inferior() have gained a timeout parameter
1229 this can go away. */
1230 static int wait_forever_enabled_p
= 1;
1232 /* Allow the user to specify what sequence to send to the remote
1233 when he requests a program interruption: Although ^C is usually
1234 what remote systems expect (this is the default, here), it is
1235 sometimes preferable to send a break. On other systems such
1236 as the Linux kernel, a break followed by g, which is Magic SysRq g
1237 is required in order to interrupt the execution. */
1238 const char interrupt_sequence_control_c
[] = "Ctrl-C";
1239 const char interrupt_sequence_break
[] = "BREAK";
1240 const char interrupt_sequence_break_g
[] = "BREAK-g";
1241 static const char *const interrupt_sequence_modes
[] =
1243 interrupt_sequence_control_c
,
1244 interrupt_sequence_break
,
1245 interrupt_sequence_break_g
,
1248 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
1251 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
1252 struct cmd_list_element
*c
,
1255 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
1256 fprintf_filtered (file
,
1257 _("Send the ASCII ETX character (Ctrl-c) "
1258 "to the remote target to interrupt the "
1259 "execution of the program.\n"));
1260 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
1261 fprintf_filtered (file
,
1262 _("send a break signal to the remote target "
1263 "to interrupt the execution of the program.\n"));
1264 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
1265 fprintf_filtered (file
,
1266 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
1267 "the remote target to interrupt the execution "
1268 "of Linux kernel.\n"));
1270 internal_error (__FILE__
, __LINE__
,
1271 _("Invalid value for interrupt_sequence_mode: %s."),
1272 interrupt_sequence_mode
);
1275 /* This boolean variable specifies whether interrupt_sequence is sent
1276 to the remote target when gdb connects to it.
1277 This is mostly needed when you debug the Linux kernel: The Linux kernel
1278 expects BREAK g which is Magic SysRq g for connecting gdb. */
1279 static int interrupt_on_connect
= 0;
1281 /* This variable is used to implement the "set/show remotebreak" commands.
1282 Since these commands are now deprecated in favor of "set/show remote
1283 interrupt-sequence", it no longer has any effect on the code. */
1284 static int remote_break
;
1287 set_remotebreak (const char *args
, int from_tty
, struct cmd_list_element
*c
)
1290 interrupt_sequence_mode
= interrupt_sequence_break
;
1292 interrupt_sequence_mode
= interrupt_sequence_control_c
;
1296 show_remotebreak (struct ui_file
*file
, int from_tty
,
1297 struct cmd_list_element
*c
,
1302 /* This variable sets the number of bits in an address that are to be
1303 sent in a memory ("M" or "m") packet. Normally, after stripping
1304 leading zeros, the entire address would be sent. This variable
1305 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
1306 initial implementation of remote.c restricted the address sent in
1307 memory packets to ``host::sizeof long'' bytes - (typically 32
1308 bits). Consequently, for 64 bit targets, the upper 32 bits of an
1309 address was never sent. Since fixing this bug may cause a break in
1310 some remote targets this variable is principly provided to
1311 facilitate backward compatibility. */
1313 static unsigned int remote_address_size
;
1316 /* User configurable variables for the number of characters in a
1317 memory read/write packet. MIN (rsa->remote_packet_size,
1318 rsa->sizeof_g_packet) is the default. Some targets need smaller
1319 values (fifo overruns, et.al.) and some users need larger values
1320 (speed up transfers). The variables ``preferred_*'' (the user
1321 request), ``current_*'' (what was actually set) and ``forced_*''
1322 (Positive - a soft limit, negative - a hard limit). */
1324 struct memory_packet_config
1331 /* The default max memory-write-packet-size. The 16k is historical.
1332 (It came from older GDB's using alloca for buffers and the
1333 knowledge (folklore?) that some hosts don't cope very well with
1334 large alloca calls.) */
1335 #define DEFAULT_MAX_MEMORY_PACKET_SIZE 16384
1337 /* The minimum remote packet size for memory transfers. Ensures we
1338 can write at least one byte. */
1339 #define MIN_MEMORY_PACKET_SIZE 20
1341 /* Compute the current size of a read/write packet. Since this makes
1342 use of ``actual_register_packet_size'' the computation is dynamic. */
1345 get_memory_packet_size (struct memory_packet_config
*config
)
1347 struct remote_state
*rs
= get_remote_state ();
1348 remote_arch_state
*rsa
= rs
->get_remote_arch_state (target_gdbarch ());
1351 if (config
->fixed_p
)
1353 if (config
->size
<= 0)
1354 what_they_get
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1356 what_they_get
= config
->size
;
1360 what_they_get
= get_remote_packet_size ();
1361 /* Limit the packet to the size specified by the user. */
1362 if (config
->size
> 0
1363 && what_they_get
> config
->size
)
1364 what_they_get
= config
->size
;
1366 /* Limit it to the size of the targets ``g'' response unless we have
1367 permission from the stub to use a larger packet size. */
1368 if (rs
->explicit_packet_size
== 0
1369 && rsa
->actual_register_packet_size
> 0
1370 && what_they_get
> rsa
->actual_register_packet_size
)
1371 what_they_get
= rsa
->actual_register_packet_size
;
1373 if (what_they_get
< MIN_MEMORY_PACKET_SIZE
)
1374 what_they_get
= MIN_MEMORY_PACKET_SIZE
;
1376 /* Make sure there is room in the global buffer for this packet
1377 (including its trailing NUL byte). */
1378 if (rs
->buf_size
< what_they_get
+ 1)
1380 rs
->buf_size
= 2 * what_they_get
;
1381 rs
->buf
= (char *) xrealloc (rs
->buf
, 2 * what_they_get
);
1384 return what_they_get
;
1387 /* Update the size of a read/write packet. If they user wants
1388 something really big then do a sanity check. */
1391 set_memory_packet_size (const char *args
, struct memory_packet_config
*config
)
1393 int fixed_p
= config
->fixed_p
;
1394 long size
= config
->size
;
1397 error (_("Argument required (integer, `fixed' or `limited')."));
1398 else if (strcmp (args
, "hard") == 0
1399 || strcmp (args
, "fixed") == 0)
1401 else if (strcmp (args
, "soft") == 0
1402 || strcmp (args
, "limit") == 0)
1408 size
= strtoul (args
, &end
, 0);
1410 error (_("Invalid %s (bad syntax)."), config
->name
);
1412 /* Instead of explicitly capping the size of a packet to or
1413 disallowing it, the user is allowed to set the size to
1414 something arbitrarily large. */
1417 /* So that the query shows the correct value. */
1419 size
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1422 if (fixed_p
&& !config
->fixed_p
)
1424 if (! query (_("The target may not be able to correctly handle a %s\n"
1425 "of %ld bytes. Change the packet size? "),
1426 config
->name
, size
))
1427 error (_("Packet size not changed."));
1429 /* Update the config. */
1430 config
->fixed_p
= fixed_p
;
1431 config
->size
= size
;
1435 show_memory_packet_size (struct memory_packet_config
*config
)
1437 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1438 if (config
->fixed_p
)
1439 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1440 get_memory_packet_size (config
));
1442 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1443 get_memory_packet_size (config
));
1446 static struct memory_packet_config memory_write_packet_config
=
1448 "memory-write-packet-size",
1452 set_memory_write_packet_size (const char *args
, int from_tty
)
1454 set_memory_packet_size (args
, &memory_write_packet_config
);
1458 show_memory_write_packet_size (const char *args
, int from_tty
)
1460 show_memory_packet_size (&memory_write_packet_config
);
1464 get_memory_write_packet_size (void)
1466 return get_memory_packet_size (&memory_write_packet_config
);
1469 static struct memory_packet_config memory_read_packet_config
=
1471 "memory-read-packet-size",
1475 set_memory_read_packet_size (const char *args
, int from_tty
)
1477 set_memory_packet_size (args
, &memory_read_packet_config
);
1481 show_memory_read_packet_size (const char *args
, int from_tty
)
1483 show_memory_packet_size (&memory_read_packet_config
);
1487 get_memory_read_packet_size (void)
1489 long size
= get_memory_packet_size (&memory_read_packet_config
);
1491 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1492 extra buffer size argument before the memory read size can be
1493 increased beyond this. */
1494 if (size
> get_remote_packet_size ())
1495 size
= get_remote_packet_size ();
1500 /* Generic configuration support for packets the stub optionally
1501 supports. Allows the user to specify the use of the packet as well
1502 as allowing GDB to auto-detect support in the remote stub. */
1506 PACKET_SUPPORT_UNKNOWN
= 0,
1511 struct packet_config
1516 /* If auto, GDB auto-detects support for this packet or feature,
1517 either through qSupported, or by trying the packet and looking
1518 at the response. If true, GDB assumes the target supports this
1519 packet. If false, the packet is disabled. Configs that don't
1520 have an associated command always have this set to auto. */
1521 enum auto_boolean detect
;
1523 /* Does the target support this packet? */
1524 enum packet_support support
;
1527 /* Analyze a packet's return value and update the packet config
1537 static enum packet_support
packet_config_support (struct packet_config
*config
);
1538 static enum packet_support
packet_support (int packet
);
1541 show_packet_config_cmd (struct packet_config
*config
)
1543 const char *support
= "internal-error";
1545 switch (packet_config_support (config
))
1548 support
= "enabled";
1550 case PACKET_DISABLE
:
1551 support
= "disabled";
1553 case PACKET_SUPPORT_UNKNOWN
:
1554 support
= "unknown";
1557 switch (config
->detect
)
1559 case AUTO_BOOLEAN_AUTO
:
1560 printf_filtered (_("Support for the `%s' packet "
1561 "is auto-detected, currently %s.\n"),
1562 config
->name
, support
);
1564 case AUTO_BOOLEAN_TRUE
:
1565 case AUTO_BOOLEAN_FALSE
:
1566 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1567 config
->name
, support
);
1573 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1574 const char *title
, int legacy
)
1580 config
->name
= name
;
1581 config
->title
= title
;
1582 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1584 show_doc
= xstrprintf ("Show current use of remote "
1585 "protocol `%s' (%s) packet",
1587 /* set/show TITLE-packet {auto,on,off} */
1588 cmd_name
= xstrprintf ("%s-packet", title
);
1589 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1590 &config
->detect
, set_doc
,
1591 show_doc
, NULL
, /* help_doc */
1593 show_remote_protocol_packet_cmd
,
1594 &remote_set_cmdlist
, &remote_show_cmdlist
);
1595 /* The command code copies the documentation strings. */
1598 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1603 legacy_name
= xstrprintf ("%s-packet", name
);
1604 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1605 &remote_set_cmdlist
);
1606 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1607 &remote_show_cmdlist
);
1611 static enum packet_result
1612 packet_check_result (const char *buf
)
1616 /* The stub recognized the packet request. Check that the
1617 operation succeeded. */
1619 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1621 /* "Enn" - definitly an error. */
1622 return PACKET_ERROR
;
1624 /* Always treat "E." as an error. This will be used for
1625 more verbose error messages, such as E.memtypes. */
1626 if (buf
[0] == 'E' && buf
[1] == '.')
1627 return PACKET_ERROR
;
1629 /* The packet may or may not be OK. Just assume it is. */
1633 /* The stub does not support the packet. */
1634 return PACKET_UNKNOWN
;
1637 static enum packet_result
1638 packet_ok (const char *buf
, struct packet_config
*config
)
1640 enum packet_result result
;
1642 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1643 && config
->support
== PACKET_DISABLE
)
1644 internal_error (__FILE__
, __LINE__
,
1645 _("packet_ok: attempt to use a disabled packet"));
1647 result
= packet_check_result (buf
);
1652 /* The stub recognized the packet request. */
1653 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1656 fprintf_unfiltered (gdb_stdlog
,
1657 "Packet %s (%s) is supported\n",
1658 config
->name
, config
->title
);
1659 config
->support
= PACKET_ENABLE
;
1662 case PACKET_UNKNOWN
:
1663 /* The stub does not support the packet. */
1664 if (config
->detect
== AUTO_BOOLEAN_AUTO
1665 && config
->support
== PACKET_ENABLE
)
1667 /* If the stub previously indicated that the packet was
1668 supported then there is a protocol error. */
1669 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1670 config
->name
, config
->title
);
1672 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1674 /* The user set it wrong. */
1675 error (_("Enabled packet %s (%s) not recognized by stub"),
1676 config
->name
, config
->title
);
1680 fprintf_unfiltered (gdb_stdlog
,
1681 "Packet %s (%s) is NOT supported\n",
1682 config
->name
, config
->title
);
1683 config
->support
= PACKET_DISABLE
;
1704 PACKET_vFile_pwrite
,
1706 PACKET_vFile_unlink
,
1707 PACKET_vFile_readlink
,
1710 PACKET_qXfer_features
,
1711 PACKET_qXfer_exec_file
,
1712 PACKET_qXfer_libraries
,
1713 PACKET_qXfer_libraries_svr4
,
1714 PACKET_qXfer_memory_map
,
1715 PACKET_qXfer_spu_read
,
1716 PACKET_qXfer_spu_write
,
1717 PACKET_qXfer_osdata
,
1718 PACKET_qXfer_threads
,
1719 PACKET_qXfer_statictrace_read
,
1720 PACKET_qXfer_traceframe_info
,
1726 PACKET_QPassSignals
,
1727 PACKET_QCatchSyscalls
,
1728 PACKET_QProgramSignals
,
1729 PACKET_QSetWorkingDir
,
1730 PACKET_QStartupWithShell
,
1731 PACKET_QEnvironmentHexEncoded
,
1732 PACKET_QEnvironmentReset
,
1733 PACKET_QEnvironmentUnset
,
1735 PACKET_qSearch_memory
,
1738 PACKET_QStartNoAckMode
,
1740 PACKET_qXfer_siginfo_read
,
1741 PACKET_qXfer_siginfo_write
,
1744 /* Support for conditional tracepoints. */
1745 PACKET_ConditionalTracepoints
,
1747 /* Support for target-side breakpoint conditions. */
1748 PACKET_ConditionalBreakpoints
,
1750 /* Support for target-side breakpoint commands. */
1751 PACKET_BreakpointCommands
,
1753 /* Support for fast tracepoints. */
1754 PACKET_FastTracepoints
,
1756 /* Support for static tracepoints. */
1757 PACKET_StaticTracepoints
,
1759 /* Support for installing tracepoints while a trace experiment is
1761 PACKET_InstallInTrace
,
1765 PACKET_TracepointSource
,
1768 PACKET_QDisableRandomization
,
1770 PACKET_QTBuffer_size
,
1774 PACKET_qXfer_btrace
,
1776 /* Support for the QNonStop packet. */
1779 /* Support for the QThreadEvents packet. */
1780 PACKET_QThreadEvents
,
1782 /* Support for multi-process extensions. */
1783 PACKET_multiprocess_feature
,
1785 /* Support for enabling and disabling tracepoints while a trace
1786 experiment is running. */
1787 PACKET_EnableDisableTracepoints_feature
,
1789 /* Support for collecting strings using the tracenz bytecode. */
1790 PACKET_tracenz_feature
,
1792 /* Support for continuing to run a trace experiment while GDB is
1794 PACKET_DisconnectedTracing_feature
,
1796 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1797 PACKET_augmented_libraries_svr4_read_feature
,
1799 /* Support for the qXfer:btrace-conf:read packet. */
1800 PACKET_qXfer_btrace_conf
,
1802 /* Support for the Qbtrace-conf:bts:size packet. */
1803 PACKET_Qbtrace_conf_bts_size
,
1805 /* Support for swbreak+ feature. */
1806 PACKET_swbreak_feature
,
1808 /* Support for hwbreak+ feature. */
1809 PACKET_hwbreak_feature
,
1811 /* Support for fork events. */
1812 PACKET_fork_event_feature
,
1814 /* Support for vfork events. */
1815 PACKET_vfork_event_feature
,
1817 /* Support for the Qbtrace-conf:pt:size packet. */
1818 PACKET_Qbtrace_conf_pt_size
,
1820 /* Support for exec events. */
1821 PACKET_exec_event_feature
,
1823 /* Support for query supported vCont actions. */
1824 PACKET_vContSupported
,
1826 /* Support remote CTRL-C. */
1829 /* Support TARGET_WAITKIND_NO_RESUMED. */
1835 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1837 /* Returns the packet's corresponding "set remote foo-packet" command
1838 state. See struct packet_config for more details. */
1840 static enum auto_boolean
1841 packet_set_cmd_state (int packet
)
1843 return remote_protocol_packets
[packet
].detect
;
1846 /* Returns whether a given packet or feature is supported. This takes
1847 into account the state of the corresponding "set remote foo-packet"
1848 command, which may be used to bypass auto-detection. */
1850 static enum packet_support
1851 packet_config_support (struct packet_config
*config
)
1853 switch (config
->detect
)
1855 case AUTO_BOOLEAN_TRUE
:
1856 return PACKET_ENABLE
;
1857 case AUTO_BOOLEAN_FALSE
:
1858 return PACKET_DISABLE
;
1859 case AUTO_BOOLEAN_AUTO
:
1860 return config
->support
;
1862 gdb_assert_not_reached (_("bad switch"));
1866 /* Same as packet_config_support, but takes the packet's enum value as
1869 static enum packet_support
1870 packet_support (int packet
)
1872 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1874 return packet_config_support (config
);
1878 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1879 struct cmd_list_element
*c
,
1882 struct packet_config
*packet
;
1884 for (packet
= remote_protocol_packets
;
1885 packet
< &remote_protocol_packets
[PACKET_MAX
];
1888 if (&packet
->detect
== c
->var
)
1890 show_packet_config_cmd (packet
);
1894 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1898 /* Should we try one of the 'Z' requests? */
1902 Z_PACKET_SOFTWARE_BP
,
1903 Z_PACKET_HARDWARE_BP
,
1910 /* For compatibility with older distributions. Provide a ``set remote
1911 Z-packet ...'' command that updates all the Z packet types. */
1913 static enum auto_boolean remote_Z_packet_detect
;
1916 set_remote_protocol_Z_packet_cmd (const char *args
, int from_tty
,
1917 struct cmd_list_element
*c
)
1921 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1922 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1926 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1927 struct cmd_list_element
*c
,
1932 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1934 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1938 /* Returns true if the multi-process extensions are in effect. */
1941 remote_multi_process_p (struct remote_state
*rs
)
1943 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1946 /* Returns true if fork events are supported. */
1949 remote_fork_event_p (struct remote_state
*rs
)
1951 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1954 /* Returns true if vfork events are supported. */
1957 remote_vfork_event_p (struct remote_state
*rs
)
1959 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1962 /* Returns true if exec events are supported. */
1965 remote_exec_event_p (struct remote_state
*rs
)
1967 return packet_support (PACKET_exec_event_feature
) == PACKET_ENABLE
;
1970 /* Insert fork catchpoint target routine. If fork events are enabled
1971 then return success, nothing more to do. */
1974 remote_target::insert_fork_catchpoint (int pid
)
1976 struct remote_state
*rs
= get_remote_state ();
1978 return !remote_fork_event_p (rs
);
1981 /* Remove fork catchpoint target routine. Nothing to do, just
1985 remote_target::remove_fork_catchpoint (int pid
)
1990 /* Insert vfork catchpoint target routine. If vfork events are enabled
1991 then return success, nothing more to do. */
1994 remote_target::insert_vfork_catchpoint (int pid
)
1996 struct remote_state
*rs
= get_remote_state ();
1998 return !remote_vfork_event_p (rs
);
2001 /* Remove vfork catchpoint target routine. Nothing to do, just
2005 remote_target::remove_vfork_catchpoint (int pid
)
2010 /* Insert exec catchpoint target routine. If exec events are
2011 enabled, just return success. */
2014 remote_target::insert_exec_catchpoint (int pid
)
2016 struct remote_state
*rs
= get_remote_state ();
2018 return !remote_exec_event_p (rs
);
2021 /* Remove exec catchpoint target routine. Nothing to do, just
2025 remote_target::remove_exec_catchpoint (int pid
)
2031 /* Asynchronous signal handle registered as event loop source for
2032 when we have pending events ready to be passed to the core. */
2034 static struct async_event_handler
*remote_async_inferior_event_token
;
2038 static ptid_t magic_null_ptid
;
2039 static ptid_t not_sent_ptid
;
2040 static ptid_t any_thread_ptid
;
2042 /* Find out if the stub attached to PID (and hence GDB should offer to
2043 detach instead of killing it when bailing out). */
2046 remote_query_attached (int pid
)
2048 struct remote_state
*rs
= get_remote_state ();
2049 size_t size
= get_remote_packet_size ();
2051 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
2054 if (remote_multi_process_p (rs
))
2055 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
2057 xsnprintf (rs
->buf
, size
, "qAttached");
2060 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2062 switch (packet_ok (rs
->buf
,
2063 &remote_protocol_packets
[PACKET_qAttached
]))
2066 if (strcmp (rs
->buf
, "1") == 0)
2070 warning (_("Remote failure reply: %s"), rs
->buf
);
2072 case PACKET_UNKNOWN
:
2079 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
2080 has been invented by GDB, instead of reported by the target. Since
2081 we can be connected to a remote system before before knowing about
2082 any inferior, mark the target with execution when we find the first
2083 inferior. If ATTACHED is 1, then we had just attached to this
2084 inferior. If it is 0, then we just created this inferior. If it
2085 is -1, then try querying the remote stub to find out if it had
2086 attached to the inferior or not. If TRY_OPEN_EXEC is true then
2087 attempt to open this inferior's executable as the main executable
2088 if no main executable is open already. */
2090 static struct inferior
*
2091 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
2094 struct inferior
*inf
;
2096 /* Check whether this process we're learning about is to be
2097 considered attached, or if is to be considered to have been
2098 spawned by the stub. */
2100 attached
= remote_query_attached (pid
);
2102 if (gdbarch_has_global_solist (target_gdbarch ()))
2104 /* If the target shares code across all inferiors, then every
2105 attach adds a new inferior. */
2106 inf
= add_inferior (pid
);
2108 /* ... and every inferior is bound to the same program space.
2109 However, each inferior may still have its own address
2111 inf
->aspace
= maybe_new_address_space ();
2112 inf
->pspace
= current_program_space
;
2116 /* In the traditional debugging scenario, there's a 1-1 match
2117 between program/address spaces. We simply bind the inferior
2118 to the program space's address space. */
2119 inf
= current_inferior ();
2120 inferior_appeared (inf
, pid
);
2123 inf
->attach_flag
= attached
;
2124 inf
->fake_pid_p
= fake_pid_p
;
2126 /* If no main executable is currently open then attempt to
2127 open the file that was executed to create this inferior. */
2128 if (try_open_exec
&& get_exec_file (0) == NULL
)
2129 exec_file_locate_attach (pid
, 0, 1);
2134 static remote_thread_info
*get_remote_thread_info (thread_info
*thread
);
2136 /* Add thread PTID to GDB's thread list. Tag it as executing/running
2137 according to RUNNING. */
2140 remote_add_thread (ptid_t ptid
, int running
, int executing
)
2142 struct remote_state
*rs
= get_remote_state ();
2143 struct thread_info
*thread
;
2145 /* GDB historically didn't pull threads in the initial connection
2146 setup. If the remote target doesn't even have a concept of
2147 threads (e.g., a bare-metal target), even if internally we
2148 consider that a single-threaded target, mentioning a new thread
2149 might be confusing to the user. Be silent then, preserving the
2150 age old behavior. */
2151 if (rs
->starting_up
)
2152 thread
= add_thread_silent (ptid
);
2154 thread
= add_thread (ptid
);
2156 get_remote_thread_info (thread
)->vcont_resumed
= executing
;
2157 set_executing (ptid
, executing
);
2158 set_running (ptid
, running
);
2161 /* Come here when we learn about a thread id from the remote target.
2162 It may be the first time we hear about such thread, so take the
2163 opportunity to add it to GDB's thread list. In case this is the
2164 first time we're noticing its corresponding inferior, add it to
2165 GDB's inferior list as well. EXECUTING indicates whether the
2166 thread is (internally) executing or stopped. */
2169 remote_notice_new_inferior (ptid_t currthread
, int executing
)
2171 /* In non-stop mode, we assume new found threads are (externally)
2172 running until proven otherwise with a stop reply. In all-stop,
2173 we can only get here if all threads are stopped. */
2174 int running
= target_is_non_stop_p () ? 1 : 0;
2176 /* If this is a new thread, add it to GDB's thread list.
2177 If we leave it up to WFI to do this, bad things will happen. */
2179 if (in_thread_list (currthread
) && is_exited (currthread
))
2181 /* We're seeing an event on a thread id we knew had exited.
2182 This has to be a new thread reusing the old id. Add it. */
2183 remote_add_thread (currthread
, running
, executing
);
2187 if (!in_thread_list (currthread
))
2189 struct inferior
*inf
= NULL
;
2190 int pid
= ptid_get_pid (currthread
);
2192 if (ptid_is_pid (inferior_ptid
)
2193 && pid
== ptid_get_pid (inferior_ptid
))
2195 /* inferior_ptid has no thread member yet. This can happen
2196 with the vAttach -> remote_wait,"TAAthread:" path if the
2197 stub doesn't support qC. This is the first stop reported
2198 after an attach, so this is the main thread. Update the
2199 ptid in the thread list. */
2200 if (in_thread_list (pid_to_ptid (pid
)))
2201 thread_change_ptid (inferior_ptid
, currthread
);
2204 remote_add_thread (currthread
, running
, executing
);
2205 inferior_ptid
= currthread
;
2210 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
2212 /* inferior_ptid is not set yet. This can happen with the
2213 vRun -> remote_wait,"TAAthread:" path if the stub
2214 doesn't support qC. This is the first stop reported
2215 after an attach, so this is the main thread. Update the
2216 ptid in the thread list. */
2217 thread_change_ptid (inferior_ptid
, currthread
);
2221 /* When connecting to a target remote, or to a target
2222 extended-remote which already was debugging an inferior, we
2223 may not know about it yet. Add it before adding its child
2224 thread, so notifications are emitted in a sensible order. */
2225 if (!in_inferior_list (ptid_get_pid (currthread
)))
2227 struct remote_state
*rs
= get_remote_state ();
2228 int fake_pid_p
= !remote_multi_process_p (rs
);
2230 inf
= remote_add_inferior (fake_pid_p
,
2231 ptid_get_pid (currthread
), -1, 1);
2234 /* This is really a new thread. Add it. */
2235 remote_add_thread (currthread
, running
, executing
);
2237 /* If we found a new inferior, let the common code do whatever
2238 it needs to with it (e.g., read shared libraries, insert
2239 breakpoints), unless we're just setting up an all-stop
2243 struct remote_state
*rs
= get_remote_state ();
2245 if (!rs
->starting_up
)
2246 notice_new_inferior (currthread
, executing
, 0);
2251 /* Return THREAD's private thread data, creating it if necessary. */
2253 static remote_thread_info
*
2254 get_remote_thread_info (thread_info
*thread
)
2256 gdb_assert (thread
!= NULL
);
2258 if (thread
->priv
== NULL
)
2259 thread
->priv
.reset (new remote_thread_info
);
2261 return static_cast<remote_thread_info
*> (thread
->priv
.get ());
2264 /* Return PTID's private thread data, creating it if necessary. */
2266 static remote_thread_info
*
2267 get_remote_thread_info (ptid_t ptid
)
2269 struct thread_info
*info
= find_thread_ptid (ptid
);
2271 return get_remote_thread_info (info
);
2274 /* Call this function as a result of
2275 1) A halt indication (T packet) containing a thread id
2276 2) A direct query of currthread
2277 3) Successful execution of set thread */
2280 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
2282 rs
->general_thread
= currthread
;
2285 /* If 'QPassSignals' is supported, tell the remote stub what signals
2286 it can simply pass through to the inferior without reporting. */
2289 remote_target::pass_signals (int numsigs
, unsigned char *pass_signals
)
2291 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
2293 char *pass_packet
, *p
;
2295 struct remote_state
*rs
= get_remote_state ();
2297 gdb_assert (numsigs
< 256);
2298 for (i
= 0; i
< numsigs
; i
++)
2300 if (pass_signals
[i
])
2303 pass_packet
= (char *) xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
2304 strcpy (pass_packet
, "QPassSignals:");
2305 p
= pass_packet
+ strlen (pass_packet
);
2306 for (i
= 0; i
< numsigs
; i
++)
2308 if (pass_signals
[i
])
2311 *p
++ = tohex (i
>> 4);
2312 *p
++ = tohex (i
& 15);
2321 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
2323 putpkt (pass_packet
);
2324 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2325 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
2326 if (rs
->last_pass_packet
)
2327 xfree (rs
->last_pass_packet
);
2328 rs
->last_pass_packet
= pass_packet
;
2331 xfree (pass_packet
);
2335 /* If 'QCatchSyscalls' is supported, tell the remote stub
2336 to report syscalls to GDB. */
2339 remote_target::set_syscall_catchpoint (int pid
, bool needed
, int any_count
,
2340 gdb::array_view
<const int> syscall_counts
)
2342 const char *catch_packet
;
2343 enum packet_result result
;
2346 if (packet_support (PACKET_QCatchSyscalls
) == PACKET_DISABLE
)
2348 /* Not supported. */
2352 if (needed
&& any_count
== 0)
2354 /* Count how many syscalls are to be caught. */
2355 for (size_t i
= 0; i
< syscall_counts
.size (); i
++)
2357 if (syscall_counts
[i
] != 0)
2364 fprintf_unfiltered (gdb_stdlog
,
2365 "remote_set_syscall_catchpoint "
2366 "pid %d needed %d any_count %d n_sysno %d\n",
2367 pid
, needed
, any_count
, n_sysno
);
2370 std::string built_packet
;
2373 /* Prepare a packet with the sysno list, assuming max 8+1
2374 characters for a sysno. If the resulting packet size is too
2375 big, fallback on the non-selective packet. */
2376 const int maxpktsz
= strlen ("QCatchSyscalls:1") + n_sysno
* 9 + 1;
2377 built_packet
.reserve (maxpktsz
);
2378 built_packet
= "QCatchSyscalls:1";
2381 /* Add in each syscall to be caught. */
2382 for (size_t i
= 0; i
< syscall_counts
.size (); i
++)
2384 if (syscall_counts
[i
] != 0)
2385 string_appendf (built_packet
, ";%zx", i
);
2388 if (built_packet
.size () > get_remote_packet_size ())
2390 /* catch_packet too big. Fallback to less efficient
2391 non selective mode, with GDB doing the filtering. */
2392 catch_packet
= "QCatchSyscalls:1";
2395 catch_packet
= built_packet
.c_str ();
2398 catch_packet
= "QCatchSyscalls:0";
2400 struct remote_state
*rs
= get_remote_state ();
2402 putpkt (catch_packet
);
2403 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2404 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QCatchSyscalls
]);
2405 if (result
== PACKET_OK
)
2411 /* If 'QProgramSignals' is supported, tell the remote stub what
2412 signals it should pass through to the inferior when detaching. */
2415 remote_target::program_signals (int numsigs
, unsigned char *signals
)
2417 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
2421 struct remote_state
*rs
= get_remote_state ();
2423 gdb_assert (numsigs
< 256);
2424 for (i
= 0; i
< numsigs
; i
++)
2429 packet
= (char *) xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
2430 strcpy (packet
, "QProgramSignals:");
2431 p
= packet
+ strlen (packet
);
2432 for (i
= 0; i
< numsigs
; i
++)
2434 if (signal_pass_state (i
))
2437 *p
++ = tohex (i
>> 4);
2438 *p
++ = tohex (i
& 15);
2447 if (!rs
->last_program_signals_packet
2448 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
2451 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2452 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
2453 xfree (rs
->last_program_signals_packet
);
2454 rs
->last_program_signals_packet
= packet
;
2461 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
2462 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
2463 thread. If GEN is set, set the general thread, if not, then set
2464 the step/continue thread. */
2466 set_thread (ptid_t ptid
, int gen
)
2468 struct remote_state
*rs
= get_remote_state ();
2469 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
2470 char *buf
= rs
->buf
;
2471 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
2473 if (ptid_equal (state
, ptid
))
2477 *buf
++ = gen
? 'g' : 'c';
2478 if (ptid_equal (ptid
, magic_null_ptid
))
2479 xsnprintf (buf
, endbuf
- buf
, "0");
2480 else if (ptid_equal (ptid
, any_thread_ptid
))
2481 xsnprintf (buf
, endbuf
- buf
, "0");
2482 else if (ptid_equal (ptid
, minus_one_ptid
))
2483 xsnprintf (buf
, endbuf
- buf
, "-1");
2485 write_ptid (buf
, endbuf
, ptid
);
2487 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2489 rs
->general_thread
= ptid
;
2491 rs
->continue_thread
= ptid
;
2495 set_general_thread (ptid_t ptid
)
2497 set_thread (ptid
, 1);
2501 set_continue_thread (ptid_t ptid
)
2503 set_thread (ptid
, 0);
2506 /* Change the remote current process. Which thread within the process
2507 ends up selected isn't important, as long as it is the same process
2508 as what INFERIOR_PTID points to.
2510 This comes from that fact that there is no explicit notion of
2511 "selected process" in the protocol. The selected process for
2512 general operations is the process the selected general thread
2516 set_general_process (void)
2518 struct remote_state
*rs
= get_remote_state ();
2520 /* If the remote can't handle multiple processes, don't bother. */
2521 if (!remote_multi_process_p (rs
))
2524 /* We only need to change the remote current thread if it's pointing
2525 at some other process. */
2526 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
2527 set_general_thread (inferior_ptid
);
2531 /* Return nonzero if this is the main thread that we made up ourselves
2532 to model non-threaded targets as single-threaded. */
2535 remote_thread_always_alive (ptid_t ptid
)
2537 if (ptid_equal (ptid
, magic_null_ptid
))
2538 /* The main thread is always alive. */
2541 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
2542 /* The main thread is always alive. This can happen after a
2543 vAttach, if the remote side doesn't support
2550 /* Return nonzero if the thread PTID is still alive on the remote
2554 remote_target::thread_alive (ptid_t ptid
)
2556 struct remote_state
*rs
= get_remote_state ();
2559 /* Check if this is a thread that we made up ourselves to model
2560 non-threaded targets as single-threaded. */
2561 if (remote_thread_always_alive (ptid
))
2565 endp
= rs
->buf
+ get_remote_packet_size ();
2568 write_ptid (p
, endp
, ptid
);
2571 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2572 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2575 /* Return a pointer to a thread name if we know it and NULL otherwise.
2576 The thread_info object owns the memory for the name. */
2579 remote_target::thread_name (struct thread_info
*info
)
2581 if (info
->priv
!= NULL
)
2583 const std::string
&name
= get_remote_thread_info (info
)->name
;
2584 return !name
.empty () ? name
.c_str () : NULL
;
2590 /* About these extended threadlist and threadinfo packets. They are
2591 variable length packets but, the fields within them are often fixed
2592 length. They are redundent enough to send over UDP as is the
2593 remote protocol in general. There is a matching unit test module
2596 /* WARNING: This threadref data structure comes from the remote O.S.,
2597 libstub protocol encoding, and remote.c. It is not particularly
2600 /* Right now, the internal structure is int. We want it to be bigger.
2601 Plan to fix this. */
2603 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2605 /* gdb_ext_thread_info is an internal GDB data structure which is
2606 equivalent to the reply of the remote threadinfo packet. */
2608 struct gdb_ext_thread_info
2610 threadref threadid
; /* External form of thread reference. */
2611 int active
; /* Has state interesting to GDB?
2613 char display
[256]; /* Brief state display, name,
2614 blocked/suspended. */
2615 char shortname
[32]; /* To be used to name threads. */
2616 char more_display
[256]; /* Long info, statistics, queue depth,
2620 /* The volume of remote transfers can be limited by submitting
2621 a mask containing bits specifying the desired information.
2622 Use a union of these values as the 'selection' parameter to
2623 get_thread_info. FIXME: Make these TAG names more thread specific. */
2625 #define TAG_THREADID 1
2626 #define TAG_EXISTS 2
2627 #define TAG_DISPLAY 4
2628 #define TAG_THREADNAME 8
2629 #define TAG_MOREDISPLAY 16
2631 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2633 static char *unpack_nibble (char *buf
, int *val
);
2635 static char *unpack_byte (char *buf
, int *value
);
2637 static char *pack_int (char *buf
, int value
);
2639 static char *unpack_int (char *buf
, int *value
);
2641 static char *unpack_string (char *src
, char *dest
, int length
);
2643 static char *pack_threadid (char *pkt
, threadref
*id
);
2645 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2647 void int_to_threadref (threadref
*id
, int value
);
2649 static int threadref_to_int (threadref
*ref
);
2651 static void copy_threadref (threadref
*dest
, threadref
*src
);
2653 static int threadmatch (threadref
*dest
, threadref
*src
);
2655 static char *pack_threadinfo_request (char *pkt
, int mode
,
2658 static int remote_unpack_thread_info_response (char *pkt
,
2659 threadref
*expectedref
,
2660 struct gdb_ext_thread_info
2664 static int remote_get_threadinfo (threadref
*threadid
,
2665 int fieldset
, /*TAG mask */
2666 struct gdb_ext_thread_info
*info
);
2668 static char *pack_threadlist_request (char *pkt
, int startflag
,
2670 threadref
*nextthread
);
2672 static int parse_threadlist_response (char *pkt
,
2674 threadref
*original_echo
,
2675 threadref
*resultlist
,
2678 static int remote_get_threadlist (int startflag
,
2679 threadref
*nextthread
,
2683 threadref
*threadlist
);
2685 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2687 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2688 void *context
, int looplimit
);
2690 static int remote_newthread_step (threadref
*ref
, void *context
);
2693 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2694 buffer we're allowed to write to. Returns
2695 BUF+CHARACTERS_WRITTEN. */
2698 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2701 struct remote_state
*rs
= get_remote_state ();
2703 if (remote_multi_process_p (rs
))
2705 pid
= ptid_get_pid (ptid
);
2707 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2709 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2711 tid
= ptid_get_lwp (ptid
);
2713 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2715 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2720 /* Extract a PTID from BUF. If non-null, OBUF is set to one past the
2721 last parsed char. Returns null_ptid if no thread id is found, and
2722 throws an error if the thread id has an invalid format. */
2725 read_ptid (const char *buf
, const char **obuf
)
2727 const char *p
= buf
;
2729 ULONGEST pid
= 0, tid
= 0;
2733 /* Multi-process ptid. */
2734 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2736 error (_("invalid remote ptid: %s"), p
);
2739 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2742 return ptid_build (pid
, tid
, 0);
2745 /* No multi-process. Just a tid. */
2746 pp
= unpack_varlen_hex (p
, &tid
);
2748 /* Return null_ptid when no thread id is found. */
2756 /* Since the stub is not sending a process id, then default to
2757 what's in inferior_ptid, unless it's null at this point. If so,
2758 then since there's no way to know the pid of the reported
2759 threads, use the magic number. */
2760 if (ptid_equal (inferior_ptid
, null_ptid
))
2761 pid
= ptid_get_pid (magic_null_ptid
);
2763 pid
= ptid_get_pid (inferior_ptid
);
2767 return ptid_build (pid
, tid
, 0);
2773 if (ch
>= 'a' && ch
<= 'f')
2774 return ch
- 'a' + 10;
2775 if (ch
>= '0' && ch
<= '9')
2777 if (ch
>= 'A' && ch
<= 'F')
2778 return ch
- 'A' + 10;
2783 stub_unpack_int (char *buff
, int fieldlength
)
2790 nibble
= stubhex (*buff
++);
2794 retval
= retval
<< 4;
2800 unpack_nibble (char *buf
, int *val
)
2802 *val
= fromhex (*buf
++);
2807 unpack_byte (char *buf
, int *value
)
2809 *value
= stub_unpack_int (buf
, 2);
2814 pack_int (char *buf
, int value
)
2816 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2817 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2818 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2819 buf
= pack_hex_byte (buf
, (value
& 0xff));
2824 unpack_int (char *buf
, int *value
)
2826 *value
= stub_unpack_int (buf
, 8);
2830 #if 0 /* Currently unused, uncomment when needed. */
2831 static char *pack_string (char *pkt
, char *string
);
2834 pack_string (char *pkt
, char *string
)
2839 len
= strlen (string
);
2841 len
= 200; /* Bigger than most GDB packets, junk??? */
2842 pkt
= pack_hex_byte (pkt
, len
);
2846 if ((ch
== '\0') || (ch
== '#'))
2847 ch
= '*'; /* Protect encapsulation. */
2852 #endif /* 0 (unused) */
2855 unpack_string (char *src
, char *dest
, int length
)
2864 pack_threadid (char *pkt
, threadref
*id
)
2867 unsigned char *altid
;
2869 altid
= (unsigned char *) id
;
2870 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2872 pkt
= pack_hex_byte (pkt
, *altid
++);
2878 unpack_threadid (char *inbuf
, threadref
*id
)
2881 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2884 altref
= (char *) id
;
2886 while (inbuf
< limit
)
2888 x
= stubhex (*inbuf
++);
2889 y
= stubhex (*inbuf
++);
2890 *altref
++ = (x
<< 4) | y
;
2895 /* Externally, threadrefs are 64 bits but internally, they are still
2896 ints. This is due to a mismatch of specifications. We would like
2897 to use 64bit thread references internally. This is an adapter
2901 int_to_threadref (threadref
*id
, int value
)
2903 unsigned char *scan
;
2905 scan
= (unsigned char *) id
;
2911 *scan
++ = (value
>> 24) & 0xff;
2912 *scan
++ = (value
>> 16) & 0xff;
2913 *scan
++ = (value
>> 8) & 0xff;
2914 *scan
++ = (value
& 0xff);
2918 threadref_to_int (threadref
*ref
)
2921 unsigned char *scan
;
2927 value
= (value
<< 8) | ((*scan
++) & 0xff);
2932 copy_threadref (threadref
*dest
, threadref
*src
)
2935 unsigned char *csrc
, *cdest
;
2937 csrc
= (unsigned char *) src
;
2938 cdest
= (unsigned char *) dest
;
2945 threadmatch (threadref
*dest
, threadref
*src
)
2947 /* Things are broken right now, so just assume we got a match. */
2949 unsigned char *srcp
, *destp
;
2951 srcp
= (char *) src
;
2952 destp
= (char *) dest
;
2956 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2963 threadid:1, # always request threadid
2970 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2973 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2975 *pkt
++ = 'q'; /* Info Query */
2976 *pkt
++ = 'P'; /* process or thread info */
2977 pkt
= pack_int (pkt
, mode
); /* mode */
2978 pkt
= pack_threadid (pkt
, id
); /* threadid */
2979 *pkt
= '\0'; /* terminate */
2983 /* These values tag the fields in a thread info response packet. */
2984 /* Tagging the fields allows us to request specific fields and to
2985 add more fields as time goes by. */
2987 #define TAG_THREADID 1 /* Echo the thread identifier. */
2988 #define TAG_EXISTS 2 /* Is this process defined enough to
2989 fetch registers and its stack? */
2990 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2991 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2992 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2996 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2997 struct gdb_ext_thread_info
*info
)
2999 struct remote_state
*rs
= get_remote_state ();
3003 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
3006 /* info->threadid = 0; FIXME: implement zero_threadref. */
3008 info
->display
[0] = '\0';
3009 info
->shortname
[0] = '\0';
3010 info
->more_display
[0] = '\0';
3012 /* Assume the characters indicating the packet type have been
3014 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
3015 pkt
= unpack_threadid (pkt
, &ref
);
3018 warning (_("Incomplete response to threadinfo request."));
3019 if (!threadmatch (&ref
, expectedref
))
3020 { /* This is an answer to a different request. */
3021 warning (_("ERROR RMT Thread info mismatch."));
3024 copy_threadref (&info
->threadid
, &ref
);
3026 /* Loop on tagged fields , try to bail if somthing goes wrong. */
3028 /* Packets are terminated with nulls. */
3029 while ((pkt
< limit
) && mask
&& *pkt
)
3031 pkt
= unpack_int (pkt
, &tag
); /* tag */
3032 pkt
= unpack_byte (pkt
, &length
); /* length */
3033 if (!(tag
& mask
)) /* Tags out of synch with mask. */
3035 warning (_("ERROR RMT: threadinfo tag mismatch."));
3039 if (tag
== TAG_THREADID
)
3043 warning (_("ERROR RMT: length of threadid is not 16."));
3047 pkt
= unpack_threadid (pkt
, &ref
);
3048 mask
= mask
& ~TAG_THREADID
;
3051 if (tag
== TAG_EXISTS
)
3053 info
->active
= stub_unpack_int (pkt
, length
);
3055 mask
= mask
& ~(TAG_EXISTS
);
3058 warning (_("ERROR RMT: 'exists' length too long."));
3064 if (tag
== TAG_THREADNAME
)
3066 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
3067 mask
= mask
& ~TAG_THREADNAME
;
3070 if (tag
== TAG_DISPLAY
)
3072 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
3073 mask
= mask
& ~TAG_DISPLAY
;
3076 if (tag
== TAG_MOREDISPLAY
)
3078 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
3079 mask
= mask
& ~TAG_MOREDISPLAY
;
3082 warning (_("ERROR RMT: unknown thread info tag."));
3083 break; /* Not a tag we know about. */
3089 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
3090 struct gdb_ext_thread_info
*info
)
3092 struct remote_state
*rs
= get_remote_state ();
3095 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
3097 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3099 if (rs
->buf
[0] == '\0')
3102 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
3107 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
3110 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
3111 threadref
*nextthread
)
3113 *pkt
++ = 'q'; /* info query packet */
3114 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
3115 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
3116 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
3117 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
3122 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
3125 parse_threadlist_response (char *pkt
, int result_limit
,
3126 threadref
*original_echo
, threadref
*resultlist
,
3129 struct remote_state
*rs
= get_remote_state ();
3131 int count
, resultcount
, done
;
3134 /* Assume the 'q' and 'M chars have been stripped. */
3135 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
3136 /* done parse past here */
3137 pkt
= unpack_byte (pkt
, &count
); /* count field */
3138 pkt
= unpack_nibble (pkt
, &done
);
3139 /* The first threadid is the argument threadid. */
3140 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
3141 while ((count
-- > 0) && (pkt
< limit
))
3143 pkt
= unpack_threadid (pkt
, resultlist
++);
3144 if (resultcount
++ >= result_limit
)
3152 /* Fetch the next batch of threads from the remote. Returns -1 if the
3153 qL packet is not supported, 0 on error and 1 on success. */
3156 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
3157 int *done
, int *result_count
, threadref
*threadlist
)
3159 struct remote_state
*rs
= get_remote_state ();
3162 /* Trancate result limit to be smaller than the packet size. */
3163 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
3164 >= get_remote_packet_size ())
3165 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
3167 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
3169 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3170 if (*rs
->buf
== '\0')
3172 /* Packet not supported. */
3177 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
3178 &rs
->echo_nextthread
, threadlist
, done
);
3180 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
3182 /* FIXME: This is a good reason to drop the packet. */
3183 /* Possably, there is a duplicate response. */
3185 retransmit immediatly - race conditions
3186 retransmit after timeout - yes
3188 wait for packet, then exit
3190 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
3191 return 0; /* I choose simply exiting. */
3193 if (*result_count
<= 0)
3197 warning (_("RMT ERROR : failed to get remote thread list."));
3200 return result
; /* break; */
3202 if (*result_count
> result_limit
)
3205 warning (_("RMT ERROR: threadlist response longer than requested."));
3211 /* Fetch the list of remote threads, with the qL packet, and call
3212 STEPFUNCTION for each thread found. Stops iterating and returns 1
3213 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
3214 STEPFUNCTION returns false. If the packet is not supported,
3218 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
3221 struct remote_state
*rs
= get_remote_state ();
3222 int done
, i
, result_count
;
3230 if (loopcount
++ > looplimit
)
3233 warning (_("Remote fetch threadlist -infinite loop-."));
3236 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
3237 MAXTHREADLISTRESULTS
,
3238 &done
, &result_count
,
3239 rs
->resultthreadlist
);
3242 /* Clear for later iterations. */
3244 /* Setup to resume next batch of thread references, set nextthread. */
3245 if (result_count
>= 1)
3246 copy_threadref (&rs
->nextthread
,
3247 &rs
->resultthreadlist
[result_count
- 1]);
3249 while (result_count
--)
3251 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
3261 /* A thread found on the remote target. */
3265 explicit thread_item (ptid_t ptid_
)
3269 thread_item (thread_item
&&other
) = default;
3270 thread_item
&operator= (thread_item
&&other
) = default;
3272 DISABLE_COPY_AND_ASSIGN (thread_item
);
3274 /* The thread's PTID. */
3277 /* The thread's extra info. */
3280 /* The thread's name. */
3283 /* The core the thread was running on. -1 if not known. */
3286 /* The thread handle associated with the thread. */
3287 gdb::byte_vector thread_handle
;
3290 /* Context passed around to the various methods listing remote
3291 threads. As new threads are found, they're added to the ITEMS
3294 struct threads_listing_context
3296 /* Return true if this object contains an entry for a thread with ptid
3299 bool contains_thread (ptid_t ptid
) const
3301 auto match_ptid
= [&] (const thread_item
&item
)
3303 return item
.ptid
== ptid
;
3306 auto it
= std::find_if (this->items
.begin (),
3310 return it
!= this->items
.end ();
3313 /* Remove the thread with ptid PTID. */
3315 void remove_thread (ptid_t ptid
)
3317 auto match_ptid
= [&] (const thread_item
&item
)
3319 return item
.ptid
== ptid
;
3322 auto it
= std::remove_if (this->items
.begin (),
3326 if (it
!= this->items
.end ())
3327 this->items
.erase (it
);
3330 /* The threads found on the remote target. */
3331 std::vector
<thread_item
> items
;
3335 remote_newthread_step (threadref
*ref
, void *data
)
3337 struct threads_listing_context
*context
3338 = (struct threads_listing_context
*) data
;
3339 int pid
= inferior_ptid
.pid ();
3340 int lwp
= threadref_to_int (ref
);
3341 ptid_t
ptid (pid
, lwp
);
3343 context
->items
.emplace_back (ptid
);
3345 return 1; /* continue iterator */
3348 #define CRAZY_MAX_THREADS 1000
3351 remote_current_thread (ptid_t oldpid
)
3353 struct remote_state
*rs
= get_remote_state ();
3356 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3357 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
3362 result
= read_ptid (&rs
->buf
[2], &obuf
);
3363 if (*obuf
!= '\0' && remote_debug
)
3364 fprintf_unfiltered (gdb_stdlog
,
3365 "warning: garbage in qC reply\n");
3373 /* List remote threads using the deprecated qL packet. */
3376 remote_get_threads_with_ql (struct target_ops
*ops
,
3377 struct threads_listing_context
*context
)
3379 if (remote_threadlist_iterator (remote_newthread_step
, context
,
3380 CRAZY_MAX_THREADS
) >= 0)
3386 #if defined(HAVE_LIBEXPAT)
3389 start_thread (struct gdb_xml_parser
*parser
,
3390 const struct gdb_xml_element
*element
,
3392 std::vector
<gdb_xml_value
> &attributes
)
3394 struct threads_listing_context
*data
3395 = (struct threads_listing_context
*) user_data
;
3396 struct gdb_xml_value
*attr
;
3398 char *id
= (char *) xml_find_attribute (attributes
, "id")->value
.get ();
3399 ptid_t ptid
= read_ptid (id
, NULL
);
3401 data
->items
.emplace_back (ptid
);
3402 thread_item
&item
= data
->items
.back ();
3404 attr
= xml_find_attribute (attributes
, "core");
3406 item
.core
= *(ULONGEST
*) attr
->value
.get ();
3408 attr
= xml_find_attribute (attributes
, "name");
3410 item
.name
= (const char *) attr
->value
.get ();
3412 attr
= xml_find_attribute (attributes
, "handle");
3414 item
.thread_handle
= hex2bin ((const char *) attr
->value
.get ());
3418 end_thread (struct gdb_xml_parser
*parser
,
3419 const struct gdb_xml_element
*element
,
3420 void *user_data
, const char *body_text
)
3422 struct threads_listing_context
*data
3423 = (struct threads_listing_context
*) user_data
;
3425 if (body_text
!= NULL
&& *body_text
!= '\0')
3426 data
->items
.back ().extra
= body_text
;
3429 const struct gdb_xml_attribute thread_attributes
[] = {
3430 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
3431 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
3432 { "name", GDB_XML_AF_OPTIONAL
, NULL
, NULL
},
3433 { "handle", GDB_XML_AF_OPTIONAL
, NULL
, NULL
},
3434 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
3437 const struct gdb_xml_element thread_children
[] = {
3438 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3441 const struct gdb_xml_element threads_children
[] = {
3442 { "thread", thread_attributes
, thread_children
,
3443 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
3444 start_thread
, end_thread
},
3445 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3448 const struct gdb_xml_element threads_elements
[] = {
3449 { "threads", NULL
, threads_children
,
3450 GDB_XML_EF_NONE
, NULL
, NULL
},
3451 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3456 /* List remote threads using qXfer:threads:read. */
3459 remote_get_threads_with_qxfer (struct target_ops
*ops
,
3460 struct threads_listing_context
*context
)
3462 #if defined(HAVE_LIBEXPAT)
3463 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3465 gdb::optional
<gdb::char_vector
> xml
3466 = target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
3468 if (xml
&& (*xml
)[0] != '\0')
3470 gdb_xml_parse_quick (_("threads"), "threads.dtd",
3471 threads_elements
, xml
->data (), context
);
3481 /* List remote threads using qfThreadInfo/qsThreadInfo. */
3484 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
3485 struct threads_listing_context
*context
)
3487 struct remote_state
*rs
= get_remote_state ();
3489 if (rs
->use_threadinfo_query
)
3493 putpkt ("qfThreadInfo");
3494 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3496 if (bufp
[0] != '\0') /* q packet recognized */
3498 while (*bufp
++ == 'm') /* reply contains one or more TID */
3502 ptid_t ptid
= read_ptid (bufp
, &bufp
);
3503 context
->items
.emplace_back (ptid
);
3505 while (*bufp
++ == ','); /* comma-separated list */
3506 putpkt ("qsThreadInfo");
3507 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3514 /* Packet not recognized. */
3515 rs
->use_threadinfo_query
= 0;
3522 /* Implement the to_update_thread_list function for the remote
3526 remote_target::update_thread_list ()
3528 struct threads_listing_context context
;
3531 /* We have a few different mechanisms to fetch the thread list. Try
3532 them all, starting with the most preferred one first, falling
3533 back to older methods. */
3534 if (remote_get_threads_with_qxfer (this, &context
)
3535 || remote_get_threads_with_qthreadinfo (this, &context
)
3536 || remote_get_threads_with_ql (this, &context
))
3538 struct thread_info
*tp
, *tmp
;
3542 if (context
.items
.empty ()
3543 && remote_thread_always_alive (inferior_ptid
))
3545 /* Some targets don't really support threads, but still
3546 reply an (empty) thread list in response to the thread
3547 listing packets, instead of replying "packet not
3548 supported". Exit early so we don't delete the main
3553 /* CONTEXT now holds the current thread list on the remote
3554 target end. Delete GDB-side threads no longer found on the
3556 ALL_THREADS_SAFE (tp
, tmp
)
3558 if (!context
.contains_thread (tp
->ptid
))
3561 delete_thread (tp
->ptid
);
3565 /* Remove any unreported fork child threads from CONTEXT so
3566 that we don't interfere with follow fork, which is where
3567 creation of such threads is handled. */
3568 remove_new_fork_children (&context
);
3570 /* And now add threads we don't know about yet to our list. */
3571 for (thread_item
&item
: context
.items
)
3573 if (item
.ptid
!= null_ptid
)
3575 /* In non-stop mode, we assume new found threads are
3576 executing until proven otherwise with a stop reply.
3577 In all-stop, we can only get here if all threads are
3579 int executing
= target_is_non_stop_p () ? 1 : 0;
3581 remote_notice_new_inferior (item
.ptid
, executing
);
3583 remote_thread_info
*info
= get_remote_thread_info (item
.ptid
);
3584 info
->core
= item
.core
;
3585 info
->extra
= std::move (item
.extra
);
3586 info
->name
= std::move (item
.name
);
3587 info
->thread_handle
= std::move (item
.thread_handle
);
3594 /* If no thread listing method is supported, then query whether
3595 each known thread is alive, one by one, with the T packet.
3596 If the target doesn't support threads at all, then this is a
3597 no-op. See remote_thread_alive. */
3603 * Collect a descriptive string about the given thread.
3604 * The target may say anything it wants to about the thread
3605 * (typically info about its blocked / runnable state, name, etc.).
3606 * This string will appear in the info threads display.
3608 * Optional: targets are not required to implement this function.
3612 remote_target::extra_thread_info (thread_info
*tp
)
3614 struct remote_state
*rs
= get_remote_state ();
3618 struct gdb_ext_thread_info threadinfo
;
3619 static char display_buf
[100]; /* arbitrary... */
3620 int n
= 0; /* position in display_buf */
3622 if (rs
->remote_desc
== 0) /* paranoia */
3623 internal_error (__FILE__
, __LINE__
,
3624 _("remote_threads_extra_info"));
3626 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3627 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3628 /* This is the main thread which was added by GDB. The remote
3629 server doesn't know about it. */
3632 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3634 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3636 if (info
!= NULL
&& info
->priv
!= NULL
)
3638 const std::string
&extra
= get_remote_thread_info (info
)->extra
;
3639 return !extra
.empty () ? extra
.c_str () : NULL
;
3645 if (rs
->use_threadextra_query
)
3648 char *endb
= rs
->buf
+ get_remote_packet_size ();
3650 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3652 write_ptid (b
, endb
, tp
->ptid
);
3655 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3656 if (rs
->buf
[0] != 0)
3658 n
= std::min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3659 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3660 display_buf
[result
] = '\0';
3665 /* If the above query fails, fall back to the old method. */
3666 rs
->use_threadextra_query
= 0;
3667 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3668 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3669 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3670 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3671 if (threadinfo
.active
)
3673 if (*threadinfo
.shortname
)
3674 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3675 " Name: %s,", threadinfo
.shortname
);
3676 if (*threadinfo
.display
)
3677 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3678 " State: %s,", threadinfo
.display
);
3679 if (*threadinfo
.more_display
)
3680 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3681 " Priority: %s", threadinfo
.more_display
);
3685 /* For purely cosmetic reasons, clear up trailing commas. */
3686 if (',' == display_buf
[n
-1])
3687 display_buf
[n
-1] = ' ';
3696 remote_target::static_tracepoint_marker_at (CORE_ADDR addr
,
3697 struct static_tracepoint_marker
*marker
)
3699 struct remote_state
*rs
= get_remote_state ();
3702 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3704 p
+= hexnumstr (p
, addr
);
3706 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3710 error (_("Remote failure reply: %s"), p
);
3714 parse_static_tracepoint_marker_definition (p
, NULL
, marker
);
3721 std::vector
<static_tracepoint_marker
>
3722 remote_target::static_tracepoint_markers_by_strid (const char *strid
)
3724 struct remote_state
*rs
= get_remote_state ();
3725 std::vector
<static_tracepoint_marker
> markers
;
3727 static_tracepoint_marker marker
;
3729 /* Ask for a first packet of static tracepoint marker
3732 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3735 error (_("Remote failure reply: %s"), p
);
3741 parse_static_tracepoint_marker_definition (p
, &p
, &marker
);
3743 if (strid
== NULL
|| marker
.str_id
== strid
)
3744 markers
.push_back (std::move (marker
));
3746 while (*p
++ == ','); /* comma-separated list */
3747 /* Ask for another packet of static tracepoint definition. */
3749 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3757 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3760 remote_target::get_ada_task_ptid (long lwp
, long thread
)
3762 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3766 /* Restart the remote side; this is an extended protocol operation. */
3769 extended_remote_restart (void)
3771 struct remote_state
*rs
= get_remote_state ();
3773 /* Send the restart command; for reasons I don't understand the
3774 remote side really expects a number after the "R". */
3775 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3778 remote_fileio_reset ();
3781 /* Clean up connection to a remote debugger. */
3784 remote_target::close ()
3786 struct remote_state
*rs
= get_remote_state ();
3788 if (rs
->remote_desc
== NULL
)
3789 return; /* already closed */
3791 /* Make sure we leave stdin registered in the event loop. */
3794 serial_close (rs
->remote_desc
);
3795 rs
->remote_desc
= NULL
;
3797 /* We don't have a connection to the remote stub anymore. Get rid
3798 of all the inferiors and their threads we were controlling.
3799 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3800 will be unable to find the thread corresponding to (pid, 0, 0). */
3801 inferior_ptid
= null_ptid
;
3802 discard_all_inferiors ();
3804 /* We are closing the remote target, so we should discard
3805 everything of this target. */
3806 discard_pending_stop_replies_in_queue (rs
);
3808 if (remote_async_inferior_event_token
)
3809 delete_async_event_handler (&remote_async_inferior_event_token
);
3811 remote_notif_state_xfree (rs
->notif_state
);
3813 trace_reset_local_state ();
3816 /* Query the remote side for the text, data and bss offsets. */
3821 struct remote_state
*rs
= get_remote_state ();
3824 int lose
, num_segments
= 0, do_sections
, do_segments
;
3825 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3826 struct section_offsets
*offs
;
3827 struct symfile_segment_data
*data
;
3829 if (symfile_objfile
== NULL
)
3832 putpkt ("qOffsets");
3833 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3836 if (buf
[0] == '\000')
3837 return; /* Return silently. Stub doesn't support
3841 warning (_("Remote failure reply: %s"), buf
);
3845 /* Pick up each field in turn. This used to be done with scanf, but
3846 scanf will make trouble if CORE_ADDR size doesn't match
3847 conversion directives correctly. The following code will work
3848 with any size of CORE_ADDR. */
3849 text_addr
= data_addr
= bss_addr
= 0;
3853 if (startswith (ptr
, "Text="))
3856 /* Don't use strtol, could lose on big values. */
3857 while (*ptr
&& *ptr
!= ';')
3858 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3860 if (startswith (ptr
, ";Data="))
3863 while (*ptr
&& *ptr
!= ';')
3864 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3869 if (!lose
&& startswith (ptr
, ";Bss="))
3872 while (*ptr
&& *ptr
!= ';')
3873 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3875 if (bss_addr
!= data_addr
)
3876 warning (_("Target reported unsupported offsets: %s"), buf
);
3881 else if (startswith (ptr
, "TextSeg="))
3884 /* Don't use strtol, could lose on big values. */
3885 while (*ptr
&& *ptr
!= ';')
3886 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3889 if (startswith (ptr
, ";DataSeg="))
3892 while (*ptr
&& *ptr
!= ';')
3893 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3901 error (_("Malformed response to offset query, %s"), buf
);
3902 else if (*ptr
!= '\0')
3903 warning (_("Target reported unsupported offsets: %s"), buf
);
3905 offs
= ((struct section_offsets
*)
3906 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3907 memcpy (offs
, symfile_objfile
->section_offsets
,
3908 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3910 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3911 do_segments
= (data
!= NULL
);
3912 do_sections
= num_segments
== 0;
3914 if (num_segments
> 0)
3916 segments
[0] = text_addr
;
3917 segments
[1] = data_addr
;
3919 /* If we have two segments, we can still try to relocate everything
3920 by assuming that the .text and .data offsets apply to the whole
3921 text and data segments. Convert the offsets given in the packet
3922 to base addresses for symfile_map_offsets_to_segments. */
3923 else if (data
&& data
->num_segments
== 2)
3925 segments
[0] = data
->segment_bases
[0] + text_addr
;
3926 segments
[1] = data
->segment_bases
[1] + data_addr
;
3929 /* If the object file has only one segment, assume that it is text
3930 rather than data; main programs with no writable data are rare,
3931 but programs with no code are useless. Of course the code might
3932 have ended up in the data segment... to detect that we would need
3933 the permissions here. */
3934 else if (data
&& data
->num_segments
== 1)
3936 segments
[0] = data
->segment_bases
[0] + text_addr
;
3939 /* There's no way to relocate by segment. */
3945 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3946 offs
, num_segments
, segments
);
3948 if (ret
== 0 && !do_sections
)
3949 error (_("Can not handle qOffsets TextSeg "
3950 "response with this symbol file"));
3957 free_symfile_segment_data (data
);
3961 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3963 /* This is a temporary kludge to force data and bss to use the
3964 same offsets because that's what nlmconv does now. The real
3965 solution requires changes to the stub and remote.c that I
3966 don't have time to do right now. */
3968 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3969 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3972 objfile_relocate (symfile_objfile
, offs
);
3975 /* Send interrupt_sequence to remote target. */
3977 send_interrupt_sequence (void)
3979 struct remote_state
*rs
= get_remote_state ();
3981 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3982 remote_serial_write ("\x03", 1);
3983 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3984 serial_send_break (rs
->remote_desc
);
3985 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3987 serial_send_break (rs
->remote_desc
);
3988 remote_serial_write ("g", 1);
3991 internal_error (__FILE__
, __LINE__
,
3992 _("Invalid value for interrupt_sequence_mode: %s."),
3993 interrupt_sequence_mode
);
3997 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3998 and extract the PTID. Returns NULL_PTID if not found. */
4001 stop_reply_extract_thread (char *stop_reply
)
4003 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
4007 /* Txx r:val ; r:val (...) */
4010 /* Look for "register" named "thread". */
4015 p1
= strchr (p
, ':');
4019 if (strncmp (p
, "thread", p1
- p
) == 0)
4020 return read_ptid (++p1
, &p
);
4022 p1
= strchr (p
, ';');
4034 /* Determine the remote side's current thread. If we have a stop
4035 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
4036 "thread" register we can extract the current thread from. If not,
4037 ask the remote which is the current thread with qC. The former
4038 method avoids a roundtrip. */
4041 get_current_thread (char *wait_status
)
4043 ptid_t ptid
= null_ptid
;
4045 /* Note we don't use remote_parse_stop_reply as that makes use of
4046 the target architecture, which we haven't yet fully determined at
4048 if (wait_status
!= NULL
)
4049 ptid
= stop_reply_extract_thread (wait_status
);
4050 if (ptid_equal (ptid
, null_ptid
))
4051 ptid
= remote_current_thread (inferior_ptid
);
4056 /* Query the remote target for which is the current thread/process,
4057 add it to our tables, and update INFERIOR_PTID. The caller is
4058 responsible for setting the state such that the remote end is ready
4059 to return the current thread.
4061 This function is called after handling the '?' or 'vRun' packets,
4062 whose response is a stop reply from which we can also try
4063 extracting the thread. If the target doesn't support the explicit
4064 qC query, we infer the current thread from that stop reply, passed
4065 in in WAIT_STATUS, which may be NULL. */
4068 add_current_inferior_and_thread (char *wait_status
)
4070 struct remote_state
*rs
= get_remote_state ();
4073 inferior_ptid
= null_ptid
;
4075 /* Now, if we have thread information, update inferior_ptid. */
4076 ptid_t curr_ptid
= get_current_thread (wait_status
);
4078 if (curr_ptid
!= null_ptid
)
4080 if (!remote_multi_process_p (rs
))
4085 /* Without this, some commands which require an active target
4086 (such as kill) won't work. This variable serves (at least)
4087 double duty as both the pid of the target process (if it has
4088 such), and as a flag indicating that a target is active. */
4089 curr_ptid
= magic_null_ptid
;
4093 remote_add_inferior (fake_pid_p
, ptid_get_pid (curr_ptid
), -1, 1);
4095 /* Add the main thread and switch to it. Don't try reading
4096 registers yet, since we haven't fetched the target description
4098 thread_info
*tp
= add_thread_silent (curr_ptid
);
4099 switch_to_thread_no_regs (tp
);
4102 /* Print info about a thread that was found already stopped on
4106 print_one_stopped_thread (struct thread_info
*thread
)
4108 struct target_waitstatus
*ws
= &thread
->suspend
.waitstatus
;
4110 switch_to_thread (thread
->ptid
);
4111 stop_pc
= get_frame_pc (get_current_frame ());
4112 set_current_sal_from_frame (get_current_frame ());
4114 thread
->suspend
.waitstatus_pending_p
= 0;
4116 if (ws
->kind
== TARGET_WAITKIND_STOPPED
)
4118 enum gdb_signal sig
= ws
->value
.sig
;
4120 if (signal_print_state (sig
))
4121 gdb::observers::signal_received
.notify (sig
);
4123 gdb::observers::normal_stop
.notify (NULL
, 1);
4126 /* Process all initial stop replies the remote side sent in response
4127 to the ? packet. These indicate threads that were already stopped
4128 on initial connection. We mark these threads as stopped and print
4129 their current frame before giving the user the prompt. */
4132 process_initial_stop_replies (int from_tty
)
4134 int pending_stop_replies
= stop_reply_queue_length ();
4135 struct inferior
*inf
;
4136 struct thread_info
*thread
;
4137 struct thread_info
*selected
= NULL
;
4138 struct thread_info
*lowest_stopped
= NULL
;
4139 struct thread_info
*first
= NULL
;
4141 /* Consume the initial pending events. */
4142 while (pending_stop_replies
-- > 0)
4144 ptid_t waiton_ptid
= minus_one_ptid
;
4146 struct target_waitstatus ws
;
4147 int ignore_event
= 0;
4148 struct thread_info
*thread
;
4150 memset (&ws
, 0, sizeof (ws
));
4151 event_ptid
= target_wait (waiton_ptid
, &ws
, TARGET_WNOHANG
);
4153 print_target_wait_results (waiton_ptid
, event_ptid
, &ws
);
4157 case TARGET_WAITKIND_IGNORE
:
4158 case TARGET_WAITKIND_NO_RESUMED
:
4159 case TARGET_WAITKIND_SIGNALLED
:
4160 case TARGET_WAITKIND_EXITED
:
4161 /* We shouldn't see these, but if we do, just ignore. */
4163 fprintf_unfiltered (gdb_stdlog
, "remote: event ignored\n");
4167 case TARGET_WAITKIND_EXECD
:
4168 xfree (ws
.value
.execd_pathname
);
4177 thread
= find_thread_ptid (event_ptid
);
4179 if (ws
.kind
== TARGET_WAITKIND_STOPPED
)
4181 enum gdb_signal sig
= ws
.value
.sig
;
4183 /* Stubs traditionally report SIGTRAP as initial signal,
4184 instead of signal 0. Suppress it. */
4185 if (sig
== GDB_SIGNAL_TRAP
)
4187 thread
->suspend
.stop_signal
= sig
;
4191 thread
->suspend
.waitstatus
= ws
;
4193 if (ws
.kind
!= TARGET_WAITKIND_STOPPED
4194 || ws
.value
.sig
!= GDB_SIGNAL_0
)
4195 thread
->suspend
.waitstatus_pending_p
= 1;
4197 set_executing (event_ptid
, 0);
4198 set_running (event_ptid
, 0);
4199 get_remote_thread_info (thread
)->vcont_resumed
= 0;
4202 /* "Notice" the new inferiors before anything related to
4203 registers/memory. */
4209 inf
->needs_setup
= 1;
4213 thread
= any_live_thread_of_process (inf
->pid
);
4214 notice_new_inferior (thread
->ptid
,
4215 thread
->state
== THREAD_RUNNING
,
4220 /* If all-stop on top of non-stop, pause all threads. Note this
4221 records the threads' stop pc, so must be done after "noticing"
4225 stop_all_threads ();
4227 /* If all threads of an inferior were already stopped, we
4228 haven't setup the inferior yet. */
4234 if (inf
->needs_setup
)
4236 thread
= any_live_thread_of_process (inf
->pid
);
4237 switch_to_thread_no_regs (thread
);
4243 /* Now go over all threads that are stopped, and print their current
4244 frame. If all-stop, then if there's a signalled thread, pick
4246 ALL_NON_EXITED_THREADS (thread
)
4252 set_running (thread
->ptid
, 0);
4253 else if (thread
->state
!= THREAD_STOPPED
)
4256 if (selected
== NULL
4257 && thread
->suspend
.waitstatus_pending_p
)
4260 if (lowest_stopped
== NULL
4261 || thread
->inf
->num
< lowest_stopped
->inf
->num
4262 || thread
->per_inf_num
< lowest_stopped
->per_inf_num
)
4263 lowest_stopped
= thread
;
4266 print_one_stopped_thread (thread
);
4269 /* In all-stop, we only print the status of one thread, and leave
4270 others with their status pending. */
4275 thread
= lowest_stopped
;
4279 print_one_stopped_thread (thread
);
4282 /* For "info program". */
4283 thread
= inferior_thread ();
4284 if (thread
->state
== THREAD_STOPPED
)
4285 set_last_target_status (inferior_ptid
, thread
->suspend
.waitstatus
);
4288 /* Start the remote connection and sync state. */
4291 remote_target::start_remote (int from_tty
, int extended_p
)
4293 struct remote_state
*rs
= get_remote_state ();
4294 struct packet_config
*noack_config
;
4295 char *wait_status
= NULL
;
4297 /* Signal other parts that we're going through the initial setup,
4298 and so things may not be stable yet. E.g., we don't try to
4299 install tracepoints until we've relocated symbols. Also, a
4300 Ctrl-C before we're connected and synced up can't interrupt the
4301 target. Instead, it offers to drop the (potentially wedged)
4303 rs
->starting_up
= 1;
4307 if (interrupt_on_connect
)
4308 send_interrupt_sequence ();
4310 /* Ack any packet which the remote side has already sent. */
4311 remote_serial_write ("+", 1);
4313 /* The first packet we send to the target is the optional "supported
4314 packets" request. If the target can answer this, it will tell us
4315 which later probes to skip. */
4316 remote_query_supported ();
4318 /* If the stub wants to get a QAllow, compose one and send it. */
4319 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
4322 /* gdbserver < 7.7 (before its fix from 2013-12-11) did reply to any
4323 unknown 'v' packet with string "OK". "OK" gets interpreted by GDB
4324 as a reply to known packet. For packet "vFile:setfs:" it is an
4325 invalid reply and GDB would return error in
4326 remote_hostio_set_filesystem, making remote files access impossible.
4327 Disable "vFile:setfs:" in such case. Do not disable other 'v' packets as
4328 other "vFile" packets get correctly detected even on gdbserver < 7.7. */
4330 const char v_mustreplyempty
[] = "vMustReplyEmpty";
4332 putpkt (v_mustreplyempty
);
4333 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4334 if (strcmp (rs
->buf
, "OK") == 0)
4335 remote_protocol_packets
[PACKET_vFile_setfs
].support
= PACKET_DISABLE
;
4336 else if (strcmp (rs
->buf
, "") != 0)
4337 error (_("Remote replied unexpectedly to '%s': %s"), v_mustreplyempty
,
4341 /* Next, we possibly activate noack mode.
4343 If the QStartNoAckMode packet configuration is set to AUTO,
4344 enable noack mode if the stub reported a wish for it with
4347 If set to TRUE, then enable noack mode even if the stub didn't
4348 report it in qSupported. If the stub doesn't reply OK, the
4349 session ends with an error.
4351 If FALSE, then don't activate noack mode, regardless of what the
4352 stub claimed should be the default with qSupported. */
4354 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
4355 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
4357 putpkt ("QStartNoAckMode");
4358 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4359 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
4365 /* Tell the remote that we are using the extended protocol. */
4367 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4370 /* Let the target know which signals it is allowed to pass down to
4372 update_signals_program_target ();
4374 /* Next, if the target can specify a description, read it. We do
4375 this before anything involving memory or registers. */
4376 target_find_description ();
4378 /* Next, now that we know something about the target, update the
4379 address spaces in the program spaces. */
4380 update_address_spaces ();
4382 /* On OSs where the list of libraries is global to all
4383 processes, we fetch them early. */
4384 if (gdbarch_has_global_solist (target_gdbarch ()))
4385 solib_add (NULL
, from_tty
, auto_solib_add
);
4387 if (target_is_non_stop_p ())
4389 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
4390 error (_("Non-stop mode requested, but remote "
4391 "does not support non-stop"));
4393 putpkt ("QNonStop:1");
4394 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4396 if (strcmp (rs
->buf
, "OK") != 0)
4397 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
4399 /* Find about threads and processes the stub is already
4400 controlling. We default to adding them in the running state.
4401 The '?' query below will then tell us about which threads are
4403 this->update_thread_list ();
4405 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
4407 /* Don't assume that the stub can operate in all-stop mode.
4408 Request it explicitly. */
4409 putpkt ("QNonStop:0");
4410 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4412 if (strcmp (rs
->buf
, "OK") != 0)
4413 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
4416 /* Upload TSVs regardless of whether the target is running or not. The
4417 remote stub, such as GDBserver, may have some predefined or builtin
4418 TSVs, even if the target is not running. */
4419 if (get_trace_status (current_trace_status ()) != -1)
4421 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
4423 upload_trace_state_variables (&uploaded_tsvs
);
4424 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
4427 /* Check whether the target is running now. */
4429 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4431 if (!target_is_non_stop_p ())
4433 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
4436 error (_("The target is not running (try extended-remote?)"));
4438 /* We're connected, but not running. Drop out before we
4439 call start_remote. */
4440 rs
->starting_up
= 0;
4445 /* Save the reply for later. */
4446 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
4447 strcpy (wait_status
, rs
->buf
);
4450 /* Fetch thread list. */
4451 target_update_thread_list ();
4453 /* Let the stub know that we want it to return the thread. */
4454 set_continue_thread (minus_one_ptid
);
4456 if (thread_count () == 0)
4458 /* Target has no concept of threads at all. GDB treats
4459 non-threaded target as single-threaded; add a main
4461 add_current_inferior_and_thread (wait_status
);
4465 /* We have thread information; select the thread the target
4466 says should be current. If we're reconnecting to a
4467 multi-threaded program, this will ideally be the thread
4468 that last reported an event before GDB disconnected. */
4469 inferior_ptid
= get_current_thread (wait_status
);
4470 if (ptid_equal (inferior_ptid
, null_ptid
))
4472 /* Odd... The target was able to list threads, but not
4473 tell us which thread was current (no "thread"
4474 register in T stop reply?). Just pick the first
4475 thread in the thread list then. */
4478 fprintf_unfiltered (gdb_stdlog
,
4479 "warning: couldn't determine remote "
4480 "current thread; picking first in list.\n");
4482 inferior_ptid
= thread_list
->ptid
;
4486 /* init_wait_for_inferior should be called before get_offsets in order
4487 to manage `inserted' flag in bp loc in a correct state.
4488 breakpoint_init_inferior, called from init_wait_for_inferior, set
4489 `inserted' flag to 0, while before breakpoint_re_set, called from
4490 start_remote, set `inserted' flag to 1. In the initialization of
4491 inferior, breakpoint_init_inferior should be called first, and then
4492 breakpoint_re_set can be called. If this order is broken, state of
4493 `inserted' flag is wrong, and cause some problems on breakpoint
4495 init_wait_for_inferior ();
4497 get_offsets (); /* Get text, data & bss offsets. */
4499 /* If we could not find a description using qXfer, and we know
4500 how to do it some other way, try again. This is not
4501 supported for non-stop; it could be, but it is tricky if
4502 there are no stopped threads when we connect. */
4503 if (remote_read_description_p (this)
4504 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
4506 target_clear_description ();
4507 target_find_description ();
4510 /* Use the previously fetched status. */
4511 gdb_assert (wait_status
!= NULL
);
4512 strcpy (rs
->buf
, wait_status
);
4513 rs
->cached_wait_status
= 1;
4515 ::start_remote (from_tty
); /* Initialize gdb process mechanisms. */
4519 /* Clear WFI global state. Do this before finding about new
4520 threads and inferiors, and setting the current inferior.
4521 Otherwise we would clear the proceed status of the current
4522 inferior when we want its stop_soon state to be preserved
4523 (see notice_new_inferior). */
4524 init_wait_for_inferior ();
4526 /* In non-stop, we will either get an "OK", meaning that there
4527 are no stopped threads at this time; or, a regular stop
4528 reply. In the latter case, there may be more than one thread
4529 stopped --- we pull them all out using the vStopped
4531 if (strcmp (rs
->buf
, "OK") != 0)
4533 struct notif_client
*notif
= ¬if_client_stop
;
4535 /* remote_notif_get_pending_replies acks this one, and gets
4537 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
4538 = remote_notif_parse (notif
, rs
->buf
);
4539 remote_notif_get_pending_events (notif
);
4542 if (thread_count () == 0)
4545 error (_("The target is not running (try extended-remote?)"));
4547 /* We're connected, but not running. Drop out before we
4548 call start_remote. */
4549 rs
->starting_up
= 0;
4553 /* In non-stop mode, any cached wait status will be stored in
4554 the stop reply queue. */
4555 gdb_assert (wait_status
== NULL
);
4557 /* Report all signals during attach/startup. */
4558 pass_signals (0, NULL
);
4560 /* If there are already stopped threads, mark them stopped and
4561 report their stops before giving the prompt to the user. */
4562 process_initial_stop_replies (from_tty
);
4564 if (target_can_async_p ())
4568 /* If we connected to a live target, do some additional setup. */
4569 if (target_has_execution
)
4571 if (symfile_objfile
) /* No use without a symbol-file. */
4572 remote_check_symbols ();
4575 /* Possibly the target has been engaged in a trace run started
4576 previously; find out where things are at. */
4577 if (get_trace_status (current_trace_status ()) != -1)
4579 struct uploaded_tp
*uploaded_tps
= NULL
;
4581 if (current_trace_status ()->running
)
4582 printf_filtered (_("Trace is already running on the target.\n"));
4584 upload_tracepoints (&uploaded_tps
);
4586 merge_uploaded_tracepoints (&uploaded_tps
);
4589 /* Possibly the target has been engaged in a btrace record started
4590 previously; find out where things are at. */
4591 remote_btrace_maybe_reopen ();
4593 /* The thread and inferior lists are now synchronized with the
4594 target, our symbols have been relocated, and we're merged the
4595 target's tracepoints with ours. We're done with basic start
4597 rs
->starting_up
= 0;
4599 /* Maybe breakpoints are global and need to be inserted now. */
4600 if (breakpoints_should_be_inserted_now ())
4601 insert_breakpoints ();
4604 /* Open a connection to a remote debugger.
4605 NAME is the filename used for communication. */
4608 remote_target::open (const char *name
, int from_tty
)
4610 open_1 (name
, from_tty
, 0);
4613 /* Open a connection to a remote debugger using the extended
4614 remote gdb protocol. NAME is the filename used for communication. */
4617 extended_remote_target::open (const char *name
, int from_tty
)
4619 open_1 (name
, from_tty
, 1 /*extended_p */);
4622 /* Reset all packets back to "unknown support". Called when opening a
4623 new connection to a remote target. */
4626 reset_all_packet_configs_support (void)
4630 for (i
= 0; i
< PACKET_MAX
; i
++)
4631 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4634 /* Initialize all packet configs. */
4637 init_all_packet_configs (void)
4641 for (i
= 0; i
< PACKET_MAX
; i
++)
4643 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
4644 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4648 /* Symbol look-up. */
4651 remote_check_symbols (void)
4653 char *msg
, *reply
, *tmp
;
4656 struct cleanup
*old_chain
;
4658 /* The remote side has no concept of inferiors that aren't running
4659 yet, it only knows about running processes. If we're connected
4660 but our current inferior is not running, we should not invite the
4661 remote target to request symbol lookups related to its
4662 (unrelated) current process. */
4663 if (!target_has_execution
)
4666 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
4669 /* Make sure the remote is pointing at the right process. Note
4670 there's no way to select "no process". */
4671 set_general_process ();
4673 /* Allocate a message buffer. We can't reuse the input buffer in RS,
4674 because we need both at the same time. */
4675 msg
= (char *) xmalloc (get_remote_packet_size ());
4676 old_chain
= make_cleanup (xfree
, msg
);
4677 reply
= (char *) xmalloc (get_remote_packet_size ());
4678 make_cleanup (free_current_contents
, &reply
);
4679 reply_size
= get_remote_packet_size ();
4681 /* Invite target to request symbol lookups. */
4683 putpkt ("qSymbol::");
4684 getpkt (&reply
, &reply_size
, 0);
4685 packet_ok (reply
, &remote_protocol_packets
[PACKET_qSymbol
]);
4687 while (startswith (reply
, "qSymbol:"))
4689 struct bound_minimal_symbol sym
;
4692 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
4694 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
4695 if (sym
.minsym
== NULL
)
4696 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
4699 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4700 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
4702 /* If this is a function address, return the start of code
4703 instead of any data function descriptor. */
4704 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
4708 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
4709 phex_nz (sym_addr
, addr_size
), &reply
[8]);
4713 getpkt (&reply
, &reply_size
, 0);
4716 do_cleanups (old_chain
);
4719 static struct serial
*
4720 remote_serial_open (const char *name
)
4722 static int udp_warning
= 0;
4724 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
4725 of in ser-tcp.c, because it is the remote protocol assuming that the
4726 serial connection is reliable and not the serial connection promising
4728 if (!udp_warning
&& startswith (name
, "udp:"))
4730 warning (_("The remote protocol may be unreliable over UDP.\n"
4731 "Some events may be lost, rendering further debugging "
4736 return serial_open (name
);
4739 /* Inform the target of our permission settings. The permission flags
4740 work without this, but if the target knows the settings, it can do
4741 a couple things. First, it can add its own check, to catch cases
4742 that somehow manage to get by the permissions checks in target
4743 methods. Second, if the target is wired to disallow particular
4744 settings (for instance, a system in the field that is not set up to
4745 be able to stop at a breakpoint), it can object to any unavailable
4749 remote_target::set_permissions ()
4751 struct remote_state
*rs
= get_remote_state ();
4753 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4754 "WriteReg:%x;WriteMem:%x;"
4755 "InsertBreak:%x;InsertTrace:%x;"
4756 "InsertFastTrace:%x;Stop:%x",
4757 may_write_registers
, may_write_memory
,
4758 may_insert_breakpoints
, may_insert_tracepoints
,
4759 may_insert_fast_tracepoints
, may_stop
);
4761 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4763 /* If the target didn't like the packet, warn the user. Do not try
4764 to undo the user's settings, that would just be maddening. */
4765 if (strcmp (rs
->buf
, "OK") != 0)
4766 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4769 /* This type describes each known response to the qSupported
4771 struct protocol_feature
4773 /* The name of this protocol feature. */
4776 /* The default for this protocol feature. */
4777 enum packet_support default_support
;
4779 /* The function to call when this feature is reported, or after
4780 qSupported processing if the feature is not supported.
4781 The first argument points to this structure. The second
4782 argument indicates whether the packet requested support be
4783 enabled, disabled, or probed (or the default, if this function
4784 is being called at the end of processing and this feature was
4785 not reported). The third argument may be NULL; if not NULL, it
4786 is a NUL-terminated string taken from the packet following
4787 this feature's name and an equals sign. */
4788 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4791 /* The corresponding packet for this feature. Only used if
4792 FUNC is remote_supported_packet. */
4797 remote_supported_packet (const struct protocol_feature
*feature
,
4798 enum packet_support support
,
4799 const char *argument
)
4803 warning (_("Remote qSupported response supplied an unexpected value for"
4804 " \"%s\"."), feature
->name
);
4808 remote_protocol_packets
[feature
->packet
].support
= support
;
4812 remote_packet_size (const struct protocol_feature
*feature
,
4813 enum packet_support support
, const char *value
)
4815 struct remote_state
*rs
= get_remote_state ();
4820 if (support
!= PACKET_ENABLE
)
4823 if (value
== NULL
|| *value
== '\0')
4825 warning (_("Remote target reported \"%s\" without a size."),
4831 packet_size
= strtol (value
, &value_end
, 16);
4832 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4834 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4835 feature
->name
, value
);
4839 /* Record the new maximum packet size. */
4840 rs
->explicit_packet_size
= packet_size
;
4843 static const struct protocol_feature remote_protocol_features
[] = {
4844 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4845 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4846 PACKET_qXfer_auxv
},
4847 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4848 PACKET_qXfer_exec_file
},
4849 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4850 PACKET_qXfer_features
},
4851 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4852 PACKET_qXfer_libraries
},
4853 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4854 PACKET_qXfer_libraries_svr4
},
4855 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4856 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4857 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4858 PACKET_qXfer_memory_map
},
4859 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4860 PACKET_qXfer_spu_read
},
4861 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4862 PACKET_qXfer_spu_write
},
4863 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4864 PACKET_qXfer_osdata
},
4865 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4866 PACKET_qXfer_threads
},
4867 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4868 PACKET_qXfer_traceframe_info
},
4869 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4870 PACKET_QPassSignals
},
4871 { "QCatchSyscalls", PACKET_DISABLE
, remote_supported_packet
,
4872 PACKET_QCatchSyscalls
},
4873 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4874 PACKET_QProgramSignals
},
4875 { "QSetWorkingDir", PACKET_DISABLE
, remote_supported_packet
,
4876 PACKET_QSetWorkingDir
},
4877 { "QStartupWithShell", PACKET_DISABLE
, remote_supported_packet
,
4878 PACKET_QStartupWithShell
},
4879 { "QEnvironmentHexEncoded", PACKET_DISABLE
, remote_supported_packet
,
4880 PACKET_QEnvironmentHexEncoded
},
4881 { "QEnvironmentReset", PACKET_DISABLE
, remote_supported_packet
,
4882 PACKET_QEnvironmentReset
},
4883 { "QEnvironmentUnset", PACKET_DISABLE
, remote_supported_packet
,
4884 PACKET_QEnvironmentUnset
},
4885 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4886 PACKET_QStartNoAckMode
},
4887 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4888 PACKET_multiprocess_feature
},
4889 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4890 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4891 PACKET_qXfer_siginfo_read
},
4892 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4893 PACKET_qXfer_siginfo_write
},
4894 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4895 PACKET_ConditionalTracepoints
},
4896 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4897 PACKET_ConditionalBreakpoints
},
4898 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4899 PACKET_BreakpointCommands
},
4900 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4901 PACKET_FastTracepoints
},
4902 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4903 PACKET_StaticTracepoints
},
4904 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4905 PACKET_InstallInTrace
},
4906 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4907 PACKET_DisconnectedTracing_feature
},
4908 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4910 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4912 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4913 PACKET_TracepointSource
},
4914 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4916 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4917 PACKET_EnableDisableTracepoints_feature
},
4918 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4919 PACKET_qXfer_fdpic
},
4920 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4922 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4923 PACKET_QDisableRandomization
},
4924 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4925 { "QTBuffer:size", PACKET_DISABLE
,
4926 remote_supported_packet
, PACKET_QTBuffer_size
},
4927 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4928 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4929 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4930 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4931 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4932 PACKET_qXfer_btrace
},
4933 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4934 PACKET_qXfer_btrace_conf
},
4935 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4936 PACKET_Qbtrace_conf_bts_size
},
4937 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4938 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4939 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4940 PACKET_fork_event_feature
},
4941 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4942 PACKET_vfork_event_feature
},
4943 { "exec-events", PACKET_DISABLE
, remote_supported_packet
,
4944 PACKET_exec_event_feature
},
4945 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4946 PACKET_Qbtrace_conf_pt_size
},
4947 { "vContSupported", PACKET_DISABLE
, remote_supported_packet
, PACKET_vContSupported
},
4948 { "QThreadEvents", PACKET_DISABLE
, remote_supported_packet
, PACKET_QThreadEvents
},
4949 { "no-resumed", PACKET_DISABLE
, remote_supported_packet
, PACKET_no_resumed
},
4952 static char *remote_support_xml
;
4954 /* Register string appended to "xmlRegisters=" in qSupported query. */
4957 register_remote_support_xml (const char *xml
)
4959 #if defined(HAVE_LIBEXPAT)
4960 if (remote_support_xml
== NULL
)
4961 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4964 char *copy
= xstrdup (remote_support_xml
+ 13);
4965 char *p
= strtok (copy
, ",");
4969 if (strcmp (p
, xml
) == 0)
4976 while ((p
= strtok (NULL
, ",")) != NULL
);
4979 remote_support_xml
= reconcat (remote_support_xml
,
4980 remote_support_xml
, ",", xml
,
4987 remote_query_supported_append (std::string
*msg
, const char *append
)
4991 msg
->append (append
);
4995 remote_query_supported (void)
4997 struct remote_state
*rs
= get_remote_state ();
5000 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
5002 /* The packet support flags are handled differently for this packet
5003 than for most others. We treat an error, a disabled packet, and
5004 an empty response identically: any features which must be reported
5005 to be used will be automatically disabled. An empty buffer
5006 accomplishes this, since that is also the representation for a list
5007 containing no features. */
5010 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
5014 if (packet_set_cmd_state (PACKET_multiprocess_feature
) != AUTO_BOOLEAN_FALSE
)
5015 remote_query_supported_append (&q
, "multiprocess+");
5017 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
5018 remote_query_supported_append (&q
, "swbreak+");
5019 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
5020 remote_query_supported_append (&q
, "hwbreak+");
5022 remote_query_supported_append (&q
, "qRelocInsn+");
5024 if (packet_set_cmd_state (PACKET_fork_event_feature
)
5025 != AUTO_BOOLEAN_FALSE
)
5026 remote_query_supported_append (&q
, "fork-events+");
5027 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
5028 != AUTO_BOOLEAN_FALSE
)
5029 remote_query_supported_append (&q
, "vfork-events+");
5030 if (packet_set_cmd_state (PACKET_exec_event_feature
)
5031 != AUTO_BOOLEAN_FALSE
)
5032 remote_query_supported_append (&q
, "exec-events+");
5034 if (packet_set_cmd_state (PACKET_vContSupported
) != AUTO_BOOLEAN_FALSE
)
5035 remote_query_supported_append (&q
, "vContSupported+");
5037 if (packet_set_cmd_state (PACKET_QThreadEvents
) != AUTO_BOOLEAN_FALSE
)
5038 remote_query_supported_append (&q
, "QThreadEvents+");
5040 if (packet_set_cmd_state (PACKET_no_resumed
) != AUTO_BOOLEAN_FALSE
)
5041 remote_query_supported_append (&q
, "no-resumed+");
5043 /* Keep this one last to work around a gdbserver <= 7.10 bug in
5044 the qSupported:xmlRegisters=i386 handling. */
5045 if (remote_support_xml
!= NULL
5046 && packet_support (PACKET_qXfer_features
) != PACKET_DISABLE
)
5047 remote_query_supported_append (&q
, remote_support_xml
);
5049 q
= "qSupported:" + q
;
5050 putpkt (q
.c_str ());
5052 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5054 /* If an error occured, warn, but do not return - just reset the
5055 buffer to empty and go on to disable features. */
5056 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
5059 warning (_("Remote failure reply: %s"), rs
->buf
);
5064 memset (seen
, 0, sizeof (seen
));
5069 enum packet_support is_supported
;
5070 char *p
, *end
, *name_end
, *value
;
5072 /* First separate out this item from the rest of the packet. If
5073 there's another item after this, we overwrite the separator
5074 (terminated strings are much easier to work with). */
5076 end
= strchr (p
, ';');
5079 end
= p
+ strlen (p
);
5089 warning (_("empty item in \"qSupported\" response"));
5094 name_end
= strchr (p
, '=');
5097 /* This is a name=value entry. */
5098 is_supported
= PACKET_ENABLE
;
5099 value
= name_end
+ 1;
5108 is_supported
= PACKET_ENABLE
;
5112 is_supported
= PACKET_DISABLE
;
5116 is_supported
= PACKET_SUPPORT_UNKNOWN
;
5120 warning (_("unrecognized item \"%s\" "
5121 "in \"qSupported\" response"), p
);
5127 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
5128 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
5130 const struct protocol_feature
*feature
;
5133 feature
= &remote_protocol_features
[i
];
5134 feature
->func (feature
, is_supported
, value
);
5139 /* If we increased the packet size, make sure to increase the global
5140 buffer size also. We delay this until after parsing the entire
5141 qSupported packet, because this is the same buffer we were
5143 if (rs
->buf_size
< rs
->explicit_packet_size
)
5145 rs
->buf_size
= rs
->explicit_packet_size
;
5146 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
5149 /* Handle the defaults for unmentioned features. */
5150 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
5153 const struct protocol_feature
*feature
;
5155 feature
= &remote_protocol_features
[i
];
5156 feature
->func (feature
, feature
->default_support
, NULL
);
5160 /* Serial QUIT handler for the remote serial descriptor.
5162 Defers handling a Ctrl-C until we're done with the current
5163 command/response packet sequence, unless:
5165 - We're setting up the connection. Don't send a remote interrupt
5166 request, as we're not fully synced yet. Quit immediately
5169 - The target has been resumed in the foreground
5170 (target_terminal::is_ours is false) with a synchronous resume
5171 packet, and we're blocked waiting for the stop reply, thus a
5172 Ctrl-C should be immediately sent to the target.
5174 - We get a second Ctrl-C while still within the same serial read or
5175 write. In that case the serial is seemingly wedged --- offer to
5178 - We see a second Ctrl-C without target response, after having
5179 previously interrupted the target. In that case the target/stub
5180 is probably wedged --- offer to quit/disconnect.
5184 remote_serial_quit_handler (void)
5186 struct remote_state
*rs
= get_remote_state ();
5188 if (check_quit_flag ())
5190 /* If we're starting up, we're not fully synced yet. Quit
5192 if (rs
->starting_up
)
5194 else if (rs
->got_ctrlc_during_io
)
5196 if (query (_("The target is not responding to GDB commands.\n"
5197 "Stop debugging it? ")))
5198 remote_unpush_and_throw ();
5200 /* If ^C has already been sent once, offer to disconnect. */
5201 else if (!target_terminal::is_ours () && rs
->ctrlc_pending_p
)
5203 /* All-stop protocol, and blocked waiting for stop reply. Send
5204 an interrupt request. */
5205 else if (!target_terminal::is_ours () && rs
->waiting_for_stop_reply
)
5206 target_interrupt ();
5208 rs
->got_ctrlc_during_io
= 1;
5212 /* Remove any of the remote.c targets from target stack. Upper targets depend
5213 on it so remove them first. */
5216 remote_unpush_target (void)
5218 pop_all_targets_at_and_above (process_stratum
);
5222 remote_unpush_and_throw (void)
5224 remote_unpush_target ();
5225 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
5229 remote_target::open_1 (const char *name
, int from_tty
, int extended_p
)
5231 struct remote_state
*rs
= get_remote_state ();
5234 error (_("To open a remote debug connection, you need to specify what\n"
5235 "serial device is attached to the remote system\n"
5236 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
5238 /* See FIXME above. */
5239 if (!target_async_permitted
)
5240 wait_forever_enabled_p
= 1;
5242 /* If we're connected to a running target, target_preopen will kill it.
5243 Ask this question first, before target_preopen has a chance to kill
5245 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
5248 && !query (_("Already connected to a remote target. Disconnect? ")))
5249 error (_("Still connected."));
5252 /* Here the possibly existing remote target gets unpushed. */
5253 target_preopen (from_tty
);
5255 /* Make sure we send the passed signals list the next time we resume. */
5256 xfree (rs
->last_pass_packet
);
5257 rs
->last_pass_packet
= NULL
;
5259 /* Make sure we send the program signals list the next time we
5261 xfree (rs
->last_program_signals_packet
);
5262 rs
->last_program_signals_packet
= NULL
;
5264 remote_fileio_reset ();
5265 reopen_exec_file ();
5268 rs
->remote_desc
= remote_serial_open (name
);
5269 if (!rs
->remote_desc
)
5270 perror_with_name (name
);
5272 if (baud_rate
!= -1)
5274 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
5276 /* The requested speed could not be set. Error out to
5277 top level after closing remote_desc. Take care to
5278 set remote_desc to NULL to avoid closing remote_desc
5280 serial_close (rs
->remote_desc
);
5281 rs
->remote_desc
= NULL
;
5282 perror_with_name (name
);
5286 serial_setparity (rs
->remote_desc
, serial_parity
);
5287 serial_raw (rs
->remote_desc
);
5289 /* If there is something sitting in the buffer we might take it as a
5290 response to a command, which would be bad. */
5291 serial_flush_input (rs
->remote_desc
);
5295 puts_filtered ("Remote debugging using ");
5296 puts_filtered (name
);
5297 puts_filtered ("\n");
5300 remote_target
*target
5301 = extended_p
? &extended_remote_ops
: &remote_ops
;
5302 push_target (target
); /* Switch to using remote target now. */
5304 /* Register extra event sources in the event loop. */
5305 remote_async_inferior_event_token
5306 = create_async_event_handler (remote_async_inferior_event_handler
,
5308 rs
->notif_state
= remote_notif_state_allocate ();
5310 /* Reset the target state; these things will be queried either by
5311 remote_query_supported or as they are needed. */
5312 reset_all_packet_configs_support ();
5313 rs
->cached_wait_status
= 0;
5314 rs
->explicit_packet_size
= 0;
5316 rs
->extended
= extended_p
;
5317 rs
->waiting_for_stop_reply
= 0;
5318 rs
->ctrlc_pending_p
= 0;
5319 rs
->got_ctrlc_during_io
= 0;
5321 rs
->general_thread
= not_sent_ptid
;
5322 rs
->continue_thread
= not_sent_ptid
;
5323 rs
->remote_traceframe_number
= -1;
5325 rs
->last_resume_exec_dir
= EXEC_FORWARD
;
5327 /* Probe for ability to use "ThreadInfo" query, as required. */
5328 rs
->use_threadinfo_query
= 1;
5329 rs
->use_threadextra_query
= 1;
5331 rs
->readahead_cache
.invalidate ();
5333 if (target_async_permitted
)
5335 /* FIXME: cagney/1999-09-23: During the initial connection it is
5336 assumed that the target is already ready and able to respond to
5337 requests. Unfortunately remote_start_remote() eventually calls
5338 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
5339 around this. Eventually a mechanism that allows
5340 wait_for_inferior() to expect/get timeouts will be
5342 wait_forever_enabled_p
= 0;
5345 /* First delete any symbols previously loaded from shared libraries. */
5346 no_shared_libraries (NULL
, 0);
5349 init_thread_list ();
5351 /* Start the remote connection. If error() or QUIT, discard this
5352 target (we'd otherwise be in an inconsistent state) and then
5353 propogate the error on up the exception chain. This ensures that
5354 the caller doesn't stumble along blindly assuming that the
5355 function succeeded. The CLI doesn't have this problem but other
5356 UI's, such as MI do.
5358 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
5359 this function should return an error indication letting the
5360 caller restore the previous state. Unfortunately the command
5361 ``target remote'' is directly wired to this function making that
5362 impossible. On a positive note, the CLI side of this problem has
5363 been fixed - the function set_cmd_context() makes it possible for
5364 all the ``target ....'' commands to share a common callback
5365 function. See cli-dump.c. */
5370 target
->start_remote (from_tty
, extended_p
);
5372 CATCH (ex
, RETURN_MASK_ALL
)
5374 /* Pop the partially set up target - unless something else did
5375 already before throwing the exception. */
5376 if (rs
->remote_desc
!= NULL
)
5377 remote_unpush_target ();
5378 if (target_async_permitted
)
5379 wait_forever_enabled_p
= 1;
5380 throw_exception (ex
);
5385 remote_btrace_reset ();
5387 if (target_async_permitted
)
5388 wait_forever_enabled_p
= 1;
5391 /* Detach the specified process. */
5394 remote_detach_pid (int pid
)
5396 struct remote_state
*rs
= get_remote_state ();
5398 if (remote_multi_process_p (rs
))
5399 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
5401 strcpy (rs
->buf
, "D");
5404 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5406 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
5408 else if (rs
->buf
[0] == '\0')
5409 error (_("Remote doesn't know how to detach"));
5411 error (_("Can't detach process."));
5414 /* This detaches a program to which we previously attached, using
5415 inferior_ptid to identify the process. After this is done, GDB
5416 can be used to debug some other program. We better not have left
5417 any breakpoints in the target program or it'll die when it hits
5421 remote_detach_1 (int from_tty
, inferior
*inf
)
5423 int pid
= ptid_get_pid (inferior_ptid
);
5424 struct remote_state
*rs
= get_remote_state ();
5425 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
5428 if (!target_has_execution
)
5429 error (_("No process to detach from."));
5431 target_announce_detach (from_tty
);
5433 /* Tell the remote target to detach. */
5434 remote_detach_pid (pid
);
5436 /* Exit only if this is the only active inferior. */
5437 if (from_tty
&& !rs
->extended
&& number_of_live_inferiors () == 1)
5438 puts_filtered (_("Ending remote debugging.\n"));
5440 /* Check to see if we are detaching a fork parent. Note that if we
5441 are detaching a fork child, tp == NULL. */
5442 is_fork_parent
= (tp
!= NULL
5443 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
5445 /* If doing detach-on-fork, we don't mourn, because that will delete
5446 breakpoints that should be available for the followed inferior. */
5447 if (!is_fork_parent
)
5449 /* Save the pid as a string before mourning, since that will
5450 unpush the remote target, and we need the string after. */
5451 std::string infpid
= target_pid_to_str (pid_to_ptid (pid
));
5453 target_mourn_inferior (inferior_ptid
);
5454 if (print_inferior_events
)
5455 printf_unfiltered (_("[Inferior %d (%s) detached]\n"),
5456 inf
->num
, infpid
.c_str ());
5460 inferior_ptid
= null_ptid
;
5461 detach_inferior (pid
);
5466 remote_target::detach (inferior
*inf
, int from_tty
)
5468 remote_detach_1 (from_tty
, inf
);
5472 extended_remote_target::detach (inferior
*inf
, int from_tty
)
5474 remote_detach_1 (from_tty
, inf
);
5477 /* Target follow-fork function for remote targets. On entry, and
5478 at return, the current inferior is the fork parent.
5480 Note that although this is currently only used for extended-remote,
5481 it is named remote_follow_fork in anticipation of using it for the
5482 remote target as well. */
5485 remote_target::follow_fork (int follow_child
, int detach_fork
)
5487 struct remote_state
*rs
= get_remote_state ();
5488 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
5490 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
5491 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
5493 /* When following the parent and detaching the child, we detach
5494 the child here. For the case of following the child and
5495 detaching the parent, the detach is done in the target-
5496 independent follow fork code in infrun.c. We can't use
5497 target_detach when detaching an unfollowed child because
5498 the client side doesn't know anything about the child. */
5499 if (detach_fork
&& !follow_child
)
5501 /* Detach the fork child. */
5505 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
5506 child_pid
= ptid_get_pid (child_ptid
);
5508 remote_detach_pid (child_pid
);
5514 /* Target follow-exec function for remote targets. Save EXECD_PATHNAME
5515 in the program space of the new inferior. On entry and at return the
5516 current inferior is the exec'ing inferior. INF is the new exec'd
5517 inferior, which may be the same as the exec'ing inferior unless
5518 follow-exec-mode is "new". */
5521 remote_target::follow_exec (struct inferior
*inf
, char *execd_pathname
)
5523 /* We know that this is a target file name, so if it has the "target:"
5524 prefix we strip it off before saving it in the program space. */
5525 if (is_target_filename (execd_pathname
))
5526 execd_pathname
+= strlen (TARGET_SYSROOT_PREFIX
);
5528 set_pspace_remote_exec_file (inf
->pspace
, execd_pathname
);
5531 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
5534 remote_target::disconnect (const char *args
, int from_tty
)
5537 error (_("Argument given to \"disconnect\" when remotely debugging."));
5539 /* Make sure we unpush even the extended remote targets. Calling
5540 target_mourn_inferior won't unpush, and remote_mourn won't
5541 unpush if there is more than one inferior left. */
5542 unpush_target (this);
5543 generic_mourn_inferior ();
5546 puts_filtered ("Ending remote debugging.\n");
5549 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
5550 be chatty about it. */
5553 extended_remote_target::attach (const char *args
, int from_tty
)
5555 struct remote_state
*rs
= get_remote_state ();
5557 char *wait_status
= NULL
;
5559 pid
= parse_pid_to_attach (args
);
5561 /* Remote PID can be freely equal to getpid, do not check it here the same
5562 way as in other targets. */
5564 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
5565 error (_("This target does not support attaching to a process"));
5569 char *exec_file
= get_exec_file (0);
5572 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
5573 target_pid_to_str (pid_to_ptid (pid
)));
5575 printf_unfiltered (_("Attaching to %s\n"),
5576 target_pid_to_str (pid_to_ptid (pid
)));
5578 gdb_flush (gdb_stdout
);
5581 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
5583 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5585 switch (packet_ok (rs
->buf
,
5586 &remote_protocol_packets
[PACKET_vAttach
]))
5589 if (!target_is_non_stop_p ())
5591 /* Save the reply for later. */
5592 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
5593 strcpy (wait_status
, rs
->buf
);
5595 else if (strcmp (rs
->buf
, "OK") != 0)
5596 error (_("Attaching to %s failed with: %s"),
5597 target_pid_to_str (pid_to_ptid (pid
)),
5600 case PACKET_UNKNOWN
:
5601 error (_("This target does not support attaching to a process"));
5603 error (_("Attaching to %s failed"),
5604 target_pid_to_str (pid_to_ptid (pid
)));
5607 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
5609 inferior_ptid
= pid_to_ptid (pid
);
5611 if (target_is_non_stop_p ())
5613 struct thread_info
*thread
;
5615 /* Get list of threads. */
5616 update_thread_list ();
5618 thread
= first_thread_of_process (pid
);
5620 inferior_ptid
= thread
->ptid
;
5622 inferior_ptid
= pid_to_ptid (pid
);
5624 /* Invalidate our notion of the remote current thread. */
5625 record_currthread (rs
, minus_one_ptid
);
5629 /* Now, if we have thread information, update inferior_ptid. */
5630 inferior_ptid
= remote_current_thread (inferior_ptid
);
5632 /* Add the main thread to the thread list. */
5633 thread_info
*thr
= add_thread_silent (inferior_ptid
);
5634 /* Don't consider the thread stopped until we've processed the
5635 saved stop reply. */
5636 set_executing (thr
->ptid
, true);
5639 /* Next, if the target can specify a description, read it. We do
5640 this before anything involving memory or registers. */
5641 target_find_description ();
5643 if (!target_is_non_stop_p ())
5645 /* Use the previously fetched status. */
5646 gdb_assert (wait_status
!= NULL
);
5648 if (target_can_async_p ())
5650 struct notif_event
*reply
5651 = remote_notif_parse (¬if_client_stop
, wait_status
);
5653 push_stop_reply ((struct stop_reply
*) reply
);
5659 gdb_assert (wait_status
!= NULL
);
5660 strcpy (rs
->buf
, wait_status
);
5661 rs
->cached_wait_status
= 1;
5665 gdb_assert (wait_status
== NULL
);
5668 /* Implementation of the to_post_attach method. */
5671 extended_remote_target::post_attach (int pid
)
5673 /* Get text, data & bss offsets. */
5676 /* In certain cases GDB might not have had the chance to start
5677 symbol lookup up until now. This could happen if the debugged
5678 binary is not using shared libraries, the vsyscall page is not
5679 present (on Linux) and the binary itself hadn't changed since the
5680 debugging process was started. */
5681 if (symfile_objfile
!= NULL
)
5682 remote_check_symbols();
5686 /* Check for the availability of vCont. This function should also check
5690 remote_vcont_probe (struct remote_state
*rs
)
5694 strcpy (rs
->buf
, "vCont?");
5696 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5699 /* Make sure that the features we assume are supported. */
5700 if (startswith (buf
, "vCont"))
5703 int support_c
, support_C
;
5705 rs
->supports_vCont
.s
= 0;
5706 rs
->supports_vCont
.S
= 0;
5709 rs
->supports_vCont
.t
= 0;
5710 rs
->supports_vCont
.r
= 0;
5711 while (p
&& *p
== ';')
5714 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5715 rs
->supports_vCont
.s
= 1;
5716 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5717 rs
->supports_vCont
.S
= 1;
5718 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5720 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5722 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5723 rs
->supports_vCont
.t
= 1;
5724 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5725 rs
->supports_vCont
.r
= 1;
5727 p
= strchr (p
, ';');
5730 /* If c, and C are not all supported, we can't use vCont. Clearing
5731 BUF will make packet_ok disable the packet. */
5732 if (!support_c
|| !support_C
)
5736 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
5739 /* Helper function for building "vCont" resumptions. Write a
5740 resumption to P. ENDP points to one-passed-the-end of the buffer
5741 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
5742 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
5743 resumed thread should be single-stepped and/or signalled. If PTID
5744 equals minus_one_ptid, then all threads are resumed; if PTID
5745 represents a process, then all threads of the process are resumed;
5746 the thread to be stepped and/or signalled is given in the global
5750 append_resumption (char *p
, char *endp
,
5751 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5753 struct remote_state
*rs
= get_remote_state ();
5755 if (step
&& siggnal
!= GDB_SIGNAL_0
)
5756 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
5758 /* GDB is willing to range step. */
5759 && use_range_stepping
5760 /* Target supports range stepping. */
5761 && rs
->supports_vCont
.r
5762 /* We don't currently support range stepping multiple
5763 threads with a wildcard (though the protocol allows it,
5764 so stubs shouldn't make an active effort to forbid
5766 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5768 struct thread_info
*tp
;
5770 if (ptid_equal (ptid
, minus_one_ptid
))
5772 /* If we don't know about the target thread's tid, then
5773 we're resuming magic_null_ptid (see caller). */
5774 tp
= find_thread_ptid (magic_null_ptid
);
5777 tp
= find_thread_ptid (ptid
);
5778 gdb_assert (tp
!= NULL
);
5780 if (tp
->control
.may_range_step
)
5782 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
5784 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
5785 phex_nz (tp
->control
.step_range_start
,
5787 phex_nz (tp
->control
.step_range_end
,
5791 p
+= xsnprintf (p
, endp
- p
, ";s");
5794 p
+= xsnprintf (p
, endp
- p
, ";s");
5795 else if (siggnal
!= GDB_SIGNAL_0
)
5796 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
5798 p
+= xsnprintf (p
, endp
- p
, ";c");
5800 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
5804 /* All (-1) threads of process. */
5805 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5807 p
+= xsnprintf (p
, endp
- p
, ":");
5808 p
= write_ptid (p
, endp
, nptid
);
5810 else if (!ptid_equal (ptid
, minus_one_ptid
))
5812 p
+= xsnprintf (p
, endp
- p
, ":");
5813 p
= write_ptid (p
, endp
, ptid
);
5819 /* Clear the thread's private info on resume. */
5822 resume_clear_thread_private_info (struct thread_info
*thread
)
5824 if (thread
->priv
!= NULL
)
5826 remote_thread_info
*priv
= get_remote_thread_info (thread
);
5828 priv
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5829 priv
->watch_data_address
= 0;
5833 /* Append a vCont continue-with-signal action for threads that have a
5834 non-zero stop signal. */
5837 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
5839 struct thread_info
*thread
;
5841 ALL_NON_EXITED_THREADS (thread
)
5842 if (ptid_match (thread
->ptid
, ptid
)
5843 && !ptid_equal (inferior_ptid
, thread
->ptid
)
5844 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
5846 p
= append_resumption (p
, endp
, thread
->ptid
,
5847 0, thread
->suspend
.stop_signal
);
5848 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5849 resume_clear_thread_private_info (thread
);
5855 /* Set the target running, using the packets that use Hc
5859 remote_resume_with_hc (struct target_ops
*ops
,
5860 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5862 struct remote_state
*rs
= get_remote_state ();
5863 struct thread_info
*thread
;
5866 rs
->last_sent_signal
= siggnal
;
5867 rs
->last_sent_step
= step
;
5869 /* The c/s/C/S resume packets use Hc, so set the continue
5871 if (ptid_equal (ptid
, minus_one_ptid
))
5872 set_continue_thread (any_thread_ptid
);
5874 set_continue_thread (ptid
);
5876 ALL_NON_EXITED_THREADS (thread
)
5877 resume_clear_thread_private_info (thread
);
5880 if (execution_direction
== EXEC_REVERSE
)
5882 /* We don't pass signals to the target in reverse exec mode. */
5883 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5884 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5887 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5888 error (_("Remote reverse-step not supported."));
5889 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5890 error (_("Remote reverse-continue not supported."));
5892 strcpy (buf
, step
? "bs" : "bc");
5894 else if (siggnal
!= GDB_SIGNAL_0
)
5896 buf
[0] = step
? 'S' : 'C';
5897 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5898 buf
[2] = tohex (((int) siggnal
) & 0xf);
5902 strcpy (buf
, step
? "s" : "c");
5907 /* Resume the remote inferior by using a "vCont" packet. The thread
5908 to be resumed is PTID; STEP and SIGGNAL indicate whether the
5909 resumed thread should be single-stepped and/or signalled. If PTID
5910 equals minus_one_ptid, then all threads are resumed; the thread to
5911 be stepped and/or signalled is given in the global INFERIOR_PTID.
5912 This function returns non-zero iff it resumes the inferior.
5914 This function issues a strict subset of all possible vCont commands
5918 remote_resume_with_vcont (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5920 struct remote_state
*rs
= get_remote_state ();
5924 /* No reverse execution actions defined for vCont. */
5925 if (execution_direction
== EXEC_REVERSE
)
5928 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5929 remote_vcont_probe (rs
);
5931 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5935 endp
= rs
->buf
+ get_remote_packet_size ();
5937 /* If we could generate a wider range of packets, we'd have to worry
5938 about overflowing BUF. Should there be a generic
5939 "multi-part-packet" packet? */
5941 p
+= xsnprintf (p
, endp
- p
, "vCont");
5943 if (ptid_equal (ptid
, magic_null_ptid
))
5945 /* MAGIC_NULL_PTID means that we don't have any active threads,
5946 so we don't have any TID numbers the inferior will
5947 understand. Make sure to only send forms that do not specify
5949 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5951 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5953 /* Resume all threads (of all processes, or of a single
5954 process), with preference for INFERIOR_PTID. This assumes
5955 inferior_ptid belongs to the set of all threads we are about
5957 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5959 /* Step inferior_ptid, with or without signal. */
5960 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5963 /* Also pass down any pending signaled resumption for other
5964 threads not the current. */
5965 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5967 /* And continue others without a signal. */
5968 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5972 /* Scheduler locking; resume only PTID. */
5973 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5976 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5979 if (target_is_non_stop_p ())
5981 /* In non-stop, the stub replies to vCont with "OK". The stop
5982 reply will be reported asynchronously by means of a `%Stop'
5984 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5985 if (strcmp (rs
->buf
, "OK") != 0)
5986 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5992 /* Tell the remote machine to resume. */
5995 remote_target::resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5997 struct remote_state
*rs
= get_remote_state ();
5999 /* When connected in non-stop mode, the core resumes threads
6000 individually. Resuming remote threads directly in target_resume
6001 would thus result in sending one packet per thread. Instead, to
6002 minimize roundtrip latency, here we just store the resume
6003 request; the actual remote resumption will be done in
6004 target_commit_resume / remote_commit_resume, where we'll be able
6005 to do vCont action coalescing. */
6006 if (target_is_non_stop_p () && ::execution_direction
!= EXEC_REVERSE
)
6008 remote_thread_info
*remote_thr
;
6010 if (ptid_equal (minus_one_ptid
, ptid
) || ptid_is_pid (ptid
))
6011 remote_thr
= get_remote_thread_info (inferior_ptid
);
6013 remote_thr
= get_remote_thread_info (ptid
);
6015 remote_thr
->last_resume_step
= step
;
6016 remote_thr
->last_resume_sig
= siggnal
;
6020 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
6021 (explained in remote-notif.c:handle_notification) so
6022 remote_notif_process is not called. We need find a place where
6023 it is safe to start a 'vNotif' sequence. It is good to do it
6024 before resuming inferior, because inferior was stopped and no RSP
6025 traffic at that moment. */
6026 if (!target_is_non_stop_p ())
6027 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
6029 rs
->last_resume_exec_dir
= ::execution_direction
;
6031 /* Prefer vCont, and fallback to s/c/S/C, which use Hc. */
6032 if (!remote_resume_with_vcont (ptid
, step
, siggnal
))
6033 remote_resume_with_hc (this, ptid
, step
, siggnal
);
6035 /* We are about to start executing the inferior, let's register it
6036 with the event loop. NOTE: this is the one place where all the
6037 execution commands end up. We could alternatively do this in each
6038 of the execution commands in infcmd.c. */
6039 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
6040 into infcmd.c in order to allow inferior function calls to work
6041 NOT asynchronously. */
6042 if (target_can_async_p ())
6045 /* We've just told the target to resume. The remote server will
6046 wait for the inferior to stop, and then send a stop reply. In
6047 the mean time, we can't start another command/query ourselves
6048 because the stub wouldn't be ready to process it. This applies
6049 only to the base all-stop protocol, however. In non-stop (which
6050 only supports vCont), the stub replies with an "OK", and is
6051 immediate able to process further serial input. */
6052 if (!target_is_non_stop_p ())
6053 rs
->waiting_for_stop_reply
= 1;
6056 static void check_pending_events_prevent_wildcard_vcont
6057 (int *may_global_wildcard_vcont
);
6058 static int is_pending_fork_parent_thread (struct thread_info
*thread
);
6060 /* Private per-inferior info for target remote processes. */
6062 struct remote_inferior
: public private_inferior
6064 /* Whether we can send a wildcard vCont for this process. */
6065 bool may_wildcard_vcont
= true;
6068 /* Get the remote private inferior data associated to INF. */
6070 static remote_inferior
*
6071 get_remote_inferior (inferior
*inf
)
6073 if (inf
->priv
== NULL
)
6074 inf
->priv
.reset (new remote_inferior
);
6076 return static_cast<remote_inferior
*> (inf
->priv
.get ());
6079 /* Structure used to track the construction of a vCont packet in the
6080 outgoing packet buffer. This is used to send multiple vCont
6081 packets if we have more actions than would fit a single packet. */
6083 struct vcont_builder
6085 /* Pointer to the first action. P points here if no action has been
6089 /* Where the next action will be appended. */
6092 /* The end of the buffer. Must never write past this. */
6096 /* Prepare the outgoing buffer for a new vCont packet. */
6099 vcont_builder_restart (struct vcont_builder
*builder
)
6101 struct remote_state
*rs
= get_remote_state ();
6103 builder
->p
= rs
->buf
;
6104 builder
->endp
= rs
->buf
+ get_remote_packet_size ();
6105 builder
->p
+= xsnprintf (builder
->p
, builder
->endp
- builder
->p
, "vCont");
6106 builder
->first_action
= builder
->p
;
6109 /* If the vCont packet being built has any action, send it to the
6113 vcont_builder_flush (struct vcont_builder
*builder
)
6115 struct remote_state
*rs
;
6117 if (builder
->p
== builder
->first_action
)
6120 rs
= get_remote_state ();
6122 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6123 if (strcmp (rs
->buf
, "OK") != 0)
6124 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
6127 /* The largest action is range-stepping, with its two addresses. This
6128 is more than sufficient. If a new, bigger action is created, it'll
6129 quickly trigger a failed assertion in append_resumption (and we'll
6131 #define MAX_ACTION_SIZE 200
6133 /* Append a new vCont action in the outgoing packet being built. If
6134 the action doesn't fit the packet along with previous actions, push
6135 what we've got so far to the remote end and start over a new vCont
6136 packet (with the new action). */
6139 vcont_builder_push_action (struct vcont_builder
*builder
,
6140 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
6142 char buf
[MAX_ACTION_SIZE
+ 1];
6146 endp
= append_resumption (buf
, buf
+ sizeof (buf
),
6147 ptid
, step
, siggnal
);
6149 /* Check whether this new action would fit in the vCont packet along
6150 with previous actions. If not, send what we've got so far and
6151 start a new vCont packet. */
6153 if (rsize
> builder
->endp
- builder
->p
)
6155 vcont_builder_flush (builder
);
6156 vcont_builder_restart (builder
);
6158 /* Should now fit. */
6159 gdb_assert (rsize
<= builder
->endp
- builder
->p
);
6162 memcpy (builder
->p
, buf
, rsize
);
6163 builder
->p
+= rsize
;
6167 /* to_commit_resume implementation. */
6170 remote_target::commit_resume ()
6172 struct inferior
*inf
;
6173 struct thread_info
*tp
;
6174 int any_process_wildcard
;
6175 int may_global_wildcard_vcont
;
6176 struct vcont_builder vcont_builder
;
6178 /* If connected in all-stop mode, we'd send the remote resume
6179 request directly from remote_resume. Likewise if
6180 reverse-debugging, as there are no defined vCont actions for
6181 reverse execution. */
6182 if (!target_is_non_stop_p () || ::execution_direction
== EXEC_REVERSE
)
6185 /* Try to send wildcard actions ("vCont;c" or "vCont;c:pPID.-1")
6186 instead of resuming all threads of each process individually.
6187 However, if any thread of a process must remain halted, we can't
6188 send wildcard resumes and must send one action per thread.
6190 Care must be taken to not resume threads/processes the server
6191 side already told us are stopped, but the core doesn't know about
6192 yet, because the events are still in the vStopped notification
6195 #1 => vCont s:p1.1;c
6197 #3 <= %Stopped T05 p1.1
6202 #8 (infrun handles the stop for p1.1 and continues stepping)
6203 #9 => vCont s:p1.1;c
6205 The last vCont above would resume thread p1.2 by mistake, because
6206 the server has no idea that the event for p1.2 had not been
6209 The server side must similarly ignore resume actions for the
6210 thread that has a pending %Stopped notification (and any other
6211 threads with events pending), until GDB acks the notification
6212 with vStopped. Otherwise, e.g., the following case is
6215 #1 => g (or any other packet)
6217 #3 <= %Stopped T05 p1.2
6218 #4 => vCont s:p1.1;c
6221 Above, the server must not resume thread p1.2. GDB can't know
6222 that p1.2 stopped until it acks the %Stopped notification, and
6223 since from GDB's perspective all threads should be running, it
6226 Finally, special care must also be given to handling fork/vfork
6227 events. A (v)fork event actually tells us that two processes
6228 stopped -- the parent and the child. Until we follow the fork,
6229 we must not resume the child. Therefore, if we have a pending
6230 fork follow, we must not send a global wildcard resume action
6231 (vCont;c). We can still send process-wide wildcards though. */
6233 /* Start by assuming a global wildcard (vCont;c) is possible. */
6234 may_global_wildcard_vcont
= 1;
6236 /* And assume every process is individually wildcard-able too. */
6237 ALL_NON_EXITED_INFERIORS (inf
)
6239 remote_inferior
*priv
= get_remote_inferior (inf
);
6241 priv
->may_wildcard_vcont
= true;
6244 /* Check for any pending events (not reported or processed yet) and
6245 disable process and global wildcard resumes appropriately. */
6246 check_pending_events_prevent_wildcard_vcont (&may_global_wildcard_vcont
);
6248 ALL_NON_EXITED_THREADS (tp
)
6250 /* If a thread of a process is not meant to be resumed, then we
6251 can't wildcard that process. */
6254 get_remote_inferior (tp
->inf
)->may_wildcard_vcont
= false;
6256 /* And if we can't wildcard a process, we can't wildcard
6257 everything either. */
6258 may_global_wildcard_vcont
= 0;
6262 /* If a thread is the parent of an unfollowed fork, then we
6263 can't do a global wildcard, as that would resume the fork
6265 if (is_pending_fork_parent_thread (tp
))
6266 may_global_wildcard_vcont
= 0;
6269 /* Now let's build the vCont packet(s). Actions must be appended
6270 from narrower to wider scopes (thread -> process -> global). If
6271 we end up with too many actions for a single packet vcont_builder
6272 flushes the current vCont packet to the remote side and starts a
6274 vcont_builder_restart (&vcont_builder
);
6276 /* Threads first. */
6277 ALL_NON_EXITED_THREADS (tp
)
6279 remote_thread_info
*remote_thr
= get_remote_thread_info (tp
);
6281 if (!tp
->executing
|| remote_thr
->vcont_resumed
)
6284 gdb_assert (!thread_is_in_step_over_chain (tp
));
6286 if (!remote_thr
->last_resume_step
6287 && remote_thr
->last_resume_sig
== GDB_SIGNAL_0
6288 && get_remote_inferior (tp
->inf
)->may_wildcard_vcont
)
6290 /* We'll send a wildcard resume instead. */
6291 remote_thr
->vcont_resumed
= 1;
6295 vcont_builder_push_action (&vcont_builder
, tp
->ptid
,
6296 remote_thr
->last_resume_step
,
6297 remote_thr
->last_resume_sig
);
6298 remote_thr
->vcont_resumed
= 1;
6301 /* Now check whether we can send any process-wide wildcard. This is
6302 to avoid sending a global wildcard in the case nothing is
6303 supposed to be resumed. */
6304 any_process_wildcard
= 0;
6306 ALL_NON_EXITED_INFERIORS (inf
)
6308 if (get_remote_inferior (inf
)->may_wildcard_vcont
)
6310 any_process_wildcard
= 1;
6315 if (any_process_wildcard
)
6317 /* If all processes are wildcard-able, then send a single "c"
6318 action, otherwise, send an "all (-1) threads of process"
6319 continue action for each running process, if any. */
6320 if (may_global_wildcard_vcont
)
6322 vcont_builder_push_action (&vcont_builder
, minus_one_ptid
,
6327 ALL_NON_EXITED_INFERIORS (inf
)
6329 if (get_remote_inferior (inf
)->may_wildcard_vcont
)
6331 vcont_builder_push_action (&vcont_builder
,
6332 pid_to_ptid (inf
->pid
),
6339 vcont_builder_flush (&vcont_builder
);
6344 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
6345 thread, all threads of a remote process, or all threads of all
6349 remote_stop_ns (ptid_t ptid
)
6351 struct remote_state
*rs
= get_remote_state ();
6353 char *endp
= rs
->buf
+ get_remote_packet_size ();
6355 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
6356 remote_vcont_probe (rs
);
6358 if (!rs
->supports_vCont
.t
)
6359 error (_("Remote server does not support stopping threads"));
6361 if (ptid_equal (ptid
, minus_one_ptid
)
6362 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
6363 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
6368 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
6370 if (ptid_is_pid (ptid
))
6371 /* All (-1) threads of process. */
6372 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
6375 /* Small optimization: if we already have a stop reply for
6376 this thread, no use in telling the stub we want this
6378 if (peek_stop_reply (ptid
))
6384 write_ptid (p
, endp
, nptid
);
6387 /* In non-stop, we get an immediate OK reply. The stop reply will
6388 come in asynchronously by notification. */
6390 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6391 if (strcmp (rs
->buf
, "OK") != 0)
6392 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
6395 /* All-stop version of target_interrupt. Sends a break or a ^C to
6396 interrupt the remote target. It is undefined which thread of which
6397 process reports the interrupt. */
6400 remote_interrupt_as (void)
6402 struct remote_state
*rs
= get_remote_state ();
6404 rs
->ctrlc_pending_p
= 1;
6406 /* If the inferior is stopped already, but the core didn't know
6407 about it yet, just ignore the request. The cached wait status
6408 will be collected in remote_wait. */
6409 if (rs
->cached_wait_status
)
6412 /* Send interrupt_sequence to remote target. */
6413 send_interrupt_sequence ();
6416 /* Non-stop version of target_interrupt. Uses `vCtrlC' to interrupt
6417 the remote target. It is undefined which thread of which process
6418 reports the interrupt. Throws an error if the packet is not
6419 supported by the server. */
6422 remote_interrupt_ns (void)
6424 struct remote_state
*rs
= get_remote_state ();
6426 char *endp
= rs
->buf
+ get_remote_packet_size ();
6428 xsnprintf (p
, endp
- p
, "vCtrlC");
6430 /* In non-stop, we get an immediate OK reply. The stop reply will
6431 come in asynchronously by notification. */
6433 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6435 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vCtrlC
]))
6439 case PACKET_UNKNOWN
:
6440 error (_("No support for interrupting the remote target."));
6442 error (_("Interrupting target failed: %s"), rs
->buf
);
6446 /* Implement the to_stop function for the remote targets. */
6449 remote_target::stop (ptid_t ptid
)
6452 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
6454 if (target_is_non_stop_p ())
6455 remote_stop_ns (ptid
);
6458 /* We don't currently have a way to transparently pause the
6459 remote target in all-stop mode. Interrupt it instead. */
6460 remote_interrupt_as ();
6464 /* Implement the to_interrupt function for the remote targets. */
6467 remote_target::interrupt ()
6470 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
6472 if (target_is_non_stop_p ())
6473 remote_interrupt_ns ();
6475 remote_interrupt_as ();
6478 /* Implement the to_pass_ctrlc function for the remote targets. */
6481 remote_target::pass_ctrlc ()
6483 struct remote_state
*rs
= get_remote_state ();
6486 fprintf_unfiltered (gdb_stdlog
, "remote_pass_ctrlc called\n");
6488 /* If we're starting up, we're not fully synced yet. Quit
6490 if (rs
->starting_up
)
6492 /* If ^C has already been sent once, offer to disconnect. */
6493 else if (rs
->ctrlc_pending_p
)
6496 target_interrupt ();
6499 /* Ask the user what to do when an interrupt is received. */
6502 interrupt_query (void)
6504 struct remote_state
*rs
= get_remote_state ();
6506 if (rs
->waiting_for_stop_reply
&& rs
->ctrlc_pending_p
)
6508 if (query (_("The target is not responding to interrupt requests.\n"
6509 "Stop debugging it? ")))
6511 remote_unpush_target ();
6512 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
6517 if (query (_("Interrupted while waiting for the program.\n"
6518 "Give up waiting? ")))
6523 /* Enable/disable target terminal ownership. Most targets can use
6524 terminal groups to control terminal ownership. Remote targets are
6525 different in that explicit transfer of ownership to/from GDB/target
6529 remote_target::terminal_inferior ()
6531 /* NOTE: At this point we could also register our selves as the
6532 recipient of all input. Any characters typed could then be
6533 passed on down to the target. */
6537 remote_target::terminal_ours ()
6542 remote_console_output (char *msg
)
6546 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
6549 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
6553 fputs_unfiltered (tb
, gdb_stdtarg
);
6555 gdb_flush (gdb_stdtarg
);
6558 DEF_VEC_O(cached_reg_t
);
6560 typedef struct stop_reply
6562 struct notif_event base
;
6564 /* The identifier of the thread about this event */
6567 /* The remote state this event is associated with. When the remote
6568 connection, represented by a remote_state object, is closed,
6569 all the associated stop_reply events should be released. */
6570 struct remote_state
*rs
;
6572 struct target_waitstatus ws
;
6574 /* The architecture associated with the expedited registers. */
6577 /* Expedited registers. This makes remote debugging a bit more
6578 efficient for those targets that provide critical registers as
6579 part of their normal status mechanism (as another roundtrip to
6580 fetch them is avoided). */
6581 VEC(cached_reg_t
) *regcache
;
6583 enum target_stop_reason stop_reason
;
6585 CORE_ADDR watch_data_address
;
6590 DECLARE_QUEUE_P (stop_reply_p
);
6591 DEFINE_QUEUE_P (stop_reply_p
);
6592 /* The list of already fetched and acknowledged stop events. This
6593 queue is used for notification Stop, and other notifications
6594 don't need queue for their events, because the notification events
6595 of Stop can't be consumed immediately, so that events should be
6596 queued first, and be consumed by remote_wait_{ns,as} one per
6597 time. Other notifications can consume their events immediately,
6598 so queue is not needed for them. */
6599 static QUEUE (stop_reply_p
) *stop_reply_queue
;
6602 stop_reply_xfree (struct stop_reply
*r
)
6604 notif_event_xfree ((struct notif_event
*) r
);
6607 /* Return the length of the stop reply queue. */
6610 stop_reply_queue_length (void)
6612 return QUEUE_length (stop_reply_p
, stop_reply_queue
);
6616 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
6617 struct notif_event
*event
)
6619 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
6623 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
6624 struct notif_event
*event
)
6626 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
6629 putpkt (self
->ack_command
);
6631 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
6632 /* We got an unknown stop reply. */
6633 error (_("Unknown stop reply"));
6635 push_stop_reply (stop_reply
);
6639 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
6641 /* We can't get pending events in remote_notif_process for
6642 notification stop, and we have to do this in remote_wait_ns
6643 instead. If we fetch all queued events from stub, remote stub
6644 may exit and we have no chance to process them back in
6646 mark_async_event_handler (remote_async_inferior_event_token
);
6651 stop_reply_dtr (struct notif_event
*event
)
6653 struct stop_reply
*r
= (struct stop_reply
*) event
;
6658 VEC_iterate (cached_reg_t
, r
->regcache
, ix
, reg
);
6662 VEC_free (cached_reg_t
, r
->regcache
);
6665 static struct notif_event
*
6666 remote_notif_stop_alloc_reply (void)
6668 /* We cast to a pointer to the "base class". */
6669 struct notif_event
*r
= (struct notif_event
*) XNEW (struct stop_reply
);
6671 r
->dtr
= stop_reply_dtr
;
6676 /* A client of notification Stop. */
6678 struct notif_client notif_client_stop
=
6682 remote_notif_stop_parse
,
6683 remote_notif_stop_ack
,
6684 remote_notif_stop_can_get_pending_events
,
6685 remote_notif_stop_alloc_reply
,
6689 /* A parameter to pass data in and out. */
6691 struct queue_iter_param
6694 struct stop_reply
*output
;
6697 /* Determine if THREAD_PTID is a pending fork parent thread. ARG contains
6698 the pid of the process that owns the threads we want to check, or
6699 -1 if we want to check all threads. */
6702 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
6705 if (ws
->kind
== TARGET_WAITKIND_FORKED
6706 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
6708 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
6715 /* Return the thread's pending status used to determine whether the
6716 thread is a fork parent stopped at a fork event. */
6718 static struct target_waitstatus
*
6719 thread_pending_fork_status (struct thread_info
*thread
)
6721 if (thread
->suspend
.waitstatus_pending_p
)
6722 return &thread
->suspend
.waitstatus
;
6724 return &thread
->pending_follow
;
6727 /* Determine if THREAD is a pending fork parent thread. */
6730 is_pending_fork_parent_thread (struct thread_info
*thread
)
6732 struct target_waitstatus
*ws
= thread_pending_fork_status (thread
);
6735 return is_pending_fork_parent (ws
, pid
, thread
->ptid
);
6738 /* Check whether EVENT is a fork event, and if it is, remove the
6739 fork child from the context list passed in DATA. */
6742 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
6743 QUEUE_ITER (stop_reply_p
) *iter
,
6747 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6748 struct threads_listing_context
*context
6749 = (struct threads_listing_context
*) param
->input
;
6751 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
6752 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
6753 || event
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
6754 context
->remove_thread (event
->ws
.value
.related_pid
);
6759 /* If CONTEXT contains any fork child threads that have not been
6760 reported yet, remove them from the CONTEXT list. If such a
6761 thread exists it is because we are stopped at a fork catchpoint
6762 and have not yet called follow_fork, which will set up the
6763 host-side data structures for the new process. */
6766 remove_new_fork_children (struct threads_listing_context
*context
)
6768 struct thread_info
* thread
;
6770 struct notif_client
*notif
= ¬if_client_stop
;
6771 struct queue_iter_param param
;
6773 /* For any threads stopped at a fork event, remove the corresponding
6774 fork child threads from the CONTEXT list. */
6775 ALL_NON_EXITED_THREADS (thread
)
6777 struct target_waitstatus
*ws
= thread_pending_fork_status (thread
);
6779 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
6780 context
->remove_thread (ws
->value
.related_pid
);
6783 /* Check for any pending fork events (not reported or processed yet)
6784 in process PID and remove those fork child threads from the
6785 CONTEXT list as well. */
6786 remote_notif_get_pending_events (notif
);
6787 param
.input
= context
;
6788 param
.output
= NULL
;
6789 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6790 remove_child_of_pending_fork
, ¶m
);
6793 /* Check whether EVENT would prevent a global or process wildcard
6797 check_pending_event_prevents_wildcard_vcont_callback
6798 (QUEUE (stop_reply_p
) *q
,
6799 QUEUE_ITER (stop_reply_p
) *iter
,
6803 struct inferior
*inf
;
6804 int *may_global_wildcard_vcont
= (int *) data
;
6806 if (event
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
6807 || event
->ws
.kind
== TARGET_WAITKIND_NO_HISTORY
)
6810 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
6811 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
6812 *may_global_wildcard_vcont
= 0;
6814 inf
= find_inferior_ptid (event
->ptid
);
6816 /* This may be the first time we heard about this process.
6817 Regardless, we must not do a global wildcard resume, otherwise
6818 we'd resume this process too. */
6819 *may_global_wildcard_vcont
= 0;
6821 get_remote_inferior (inf
)->may_wildcard_vcont
= false;
6826 /* Check whether any event pending in the vStopped queue would prevent
6827 a global or process wildcard vCont action. Clear
6828 *may_global_wildcard if we can't do a global wildcard (vCont;c),
6829 and clear the event inferior's may_wildcard_vcont flag if we can't
6830 do a process-wide wildcard resume (vCont;c:pPID.-1). */
6833 check_pending_events_prevent_wildcard_vcont (int *may_global_wildcard
)
6835 struct notif_client
*notif
= ¬if_client_stop
;
6837 remote_notif_get_pending_events (notif
);
6838 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6839 check_pending_event_prevents_wildcard_vcont_callback
,
6840 may_global_wildcard
);
6843 /* Remove stop replies in the queue if its pid is equal to the given
6847 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
6848 QUEUE_ITER (stop_reply_p
) *iter
,
6852 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6853 struct inferior
*inf
= (struct inferior
*) param
->input
;
6855 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
6857 stop_reply_xfree (event
);
6858 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6864 /* Discard all pending stop replies of inferior INF. */
6867 discard_pending_stop_replies (struct inferior
*inf
)
6869 struct queue_iter_param param
;
6870 struct stop_reply
*reply
;
6871 struct remote_state
*rs
= get_remote_state ();
6872 struct remote_notif_state
*rns
= rs
->notif_state
;
6874 /* This function can be notified when an inferior exists. When the
6875 target is not remote, the notification state is NULL. */
6876 if (rs
->remote_desc
== NULL
)
6879 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
6881 /* Discard the in-flight notification. */
6882 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
6884 stop_reply_xfree (reply
);
6885 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
6889 param
.output
= NULL
;
6890 /* Discard the stop replies we have already pulled with
6892 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6893 remove_stop_reply_for_inferior
, ¶m
);
6896 /* If its remote state is equal to the given remote state,
6897 remove EVENT from the stop reply queue. */
6900 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
6901 QUEUE_ITER (stop_reply_p
) *iter
,
6905 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6906 struct remote_state
*rs
= (struct remote_state
*) param
->input
;
6908 if (event
->rs
== rs
)
6910 stop_reply_xfree (event
);
6911 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6917 /* Discard the stop replies for RS in stop_reply_queue. */
6920 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
6922 struct queue_iter_param param
;
6925 param
.output
= NULL
;
6926 /* Discard the stop replies we have already pulled with
6928 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6929 remove_stop_reply_of_remote_state
, ¶m
);
6932 /* A parameter to pass data in and out. */
6935 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
6936 QUEUE_ITER (stop_reply_p
) *iter
,
6940 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6941 ptid_t
*ptid
= (ptid_t
*) param
->input
;
6943 if (ptid_match (event
->ptid
, *ptid
))
6945 param
->output
= event
;
6946 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6953 /* Remove the first reply in 'stop_reply_queue' which matches
6956 static struct stop_reply
*
6957 remote_notif_remove_queued_reply (ptid_t ptid
)
6959 struct queue_iter_param param
;
6961 param
.input
= &ptid
;
6962 param
.output
= NULL
;
6964 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6965 remote_notif_remove_once_on_match
, ¶m
);
6967 fprintf_unfiltered (gdb_stdlog
,
6968 "notif: discard queued event: 'Stop' in %s\n",
6969 target_pid_to_str (ptid
));
6971 return param
.output
;
6974 /* Look for a queued stop reply belonging to PTID. If one is found,
6975 remove it from the queue, and return it. Returns NULL if none is
6976 found. If there are still queued events left to process, tell the
6977 event loop to get back to target_wait soon. */
6979 static struct stop_reply
*
6980 queued_stop_reply (ptid_t ptid
)
6982 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
6984 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6985 /* There's still at least an event left. */
6986 mark_async_event_handler (remote_async_inferior_event_token
);
6991 /* Push a fully parsed stop reply in the stop reply queue. Since we
6992 know that we now have at least one queued event left to pass to the
6993 core side, tell the event loop to get back to target_wait soon. */
6996 push_stop_reply (struct stop_reply
*new_event
)
6998 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
7001 fprintf_unfiltered (gdb_stdlog
,
7002 "notif: push 'Stop' %s to queue %d\n",
7003 target_pid_to_str (new_event
->ptid
),
7004 QUEUE_length (stop_reply_p
,
7007 mark_async_event_handler (remote_async_inferior_event_token
);
7011 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
7012 QUEUE_ITER (stop_reply_p
) *iter
,
7013 struct stop_reply
*event
,
7016 ptid_t
*ptid
= (ptid_t
*) data
;
7018 return !(ptid_equal (*ptid
, event
->ptid
)
7019 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
7022 /* Returns true if we have a stop reply for PTID. */
7025 peek_stop_reply (ptid_t ptid
)
7027 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
7028 stop_reply_match_ptid_and_ws
, &ptid
);
7031 /* Helper for remote_parse_stop_reply. Return nonzero if the substring
7032 starting with P and ending with PEND matches PREFIX. */
7035 strprefix (const char *p
, const char *pend
, const char *prefix
)
7037 for ( ; p
< pend
; p
++, prefix
++)
7040 return *prefix
== '\0';
7043 /* Parse the stop reply in BUF. Either the function succeeds, and the
7044 result is stored in EVENT, or throws an error. */
7047 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
7049 remote_arch_state
*rsa
= NULL
;
7054 event
->ptid
= null_ptid
;
7055 event
->rs
= get_remote_state ();
7056 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
7057 event
->ws
.value
.integer
= 0;
7058 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
7059 event
->regcache
= NULL
;
7064 case 'T': /* Status with PC, SP, FP, ... */
7065 /* Expedited reply, containing Signal, {regno, reg} repeat. */
7066 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
7068 n... = register number
7069 r... = register contents
7072 p
= &buf
[3]; /* after Txx */
7078 p1
= strchr (p
, ':');
7080 error (_("Malformed packet(a) (missing colon): %s\n\
7084 error (_("Malformed packet(a) (missing register number): %s\n\
7088 /* Some "registers" are actually extended stop information.
7089 Note if you're adding a new entry here: GDB 7.9 and
7090 earlier assume that all register "numbers" that start
7091 with an hex digit are real register numbers. Make sure
7092 the server only sends such a packet if it knows the
7093 client understands it. */
7095 if (strprefix (p
, p1
, "thread"))
7096 event
->ptid
= read_ptid (++p1
, &p
);
7097 else if (strprefix (p
, p1
, "syscall_entry"))
7101 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_ENTRY
;
7102 p
= unpack_varlen_hex (++p1
, &sysno
);
7103 event
->ws
.value
.syscall_number
= (int) sysno
;
7105 else if (strprefix (p
, p1
, "syscall_return"))
7109 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_RETURN
;
7110 p
= unpack_varlen_hex (++p1
, &sysno
);
7111 event
->ws
.value
.syscall_number
= (int) sysno
;
7113 else if (strprefix (p
, p1
, "watch")
7114 || strprefix (p
, p1
, "rwatch")
7115 || strprefix (p
, p1
, "awatch"))
7117 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
7118 p
= unpack_varlen_hex (++p1
, &addr
);
7119 event
->watch_data_address
= (CORE_ADDR
) addr
;
7121 else if (strprefix (p
, p1
, "swbreak"))
7123 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
7125 /* Make sure the stub doesn't forget to indicate support
7127 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
7128 error (_("Unexpected swbreak stop reason"));
7130 /* The value part is documented as "must be empty",
7131 though we ignore it, in case we ever decide to make
7132 use of it in a backward compatible way. */
7133 p
= strchrnul (p1
+ 1, ';');
7135 else if (strprefix (p
, p1
, "hwbreak"))
7137 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
7139 /* Make sure the stub doesn't forget to indicate support
7141 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
7142 error (_("Unexpected hwbreak stop reason"));
7145 p
= strchrnul (p1
+ 1, ';');
7147 else if (strprefix (p
, p1
, "library"))
7149 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
7150 p
= strchrnul (p1
+ 1, ';');
7152 else if (strprefix (p
, p1
, "replaylog"))
7154 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
7155 /* p1 will indicate "begin" or "end", but it makes
7156 no difference for now, so ignore it. */
7157 p
= strchrnul (p1
+ 1, ';');
7159 else if (strprefix (p
, p1
, "core"))
7163 p
= unpack_varlen_hex (++p1
, &c
);
7166 else if (strprefix (p
, p1
, "fork"))
7168 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
7169 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
7171 else if (strprefix (p
, p1
, "vfork"))
7173 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
7174 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
7176 else if (strprefix (p
, p1
, "vforkdone"))
7178 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
7179 p
= strchrnul (p1
+ 1, ';');
7181 else if (strprefix (p
, p1
, "exec"))
7184 char pathname
[PATH_MAX
];
7187 /* Determine the length of the execd pathname. */
7188 p
= unpack_varlen_hex (++p1
, &ignored
);
7189 pathlen
= (p
- p1
) / 2;
7191 /* Save the pathname for event reporting and for
7192 the next run command. */
7193 hex2bin (p1
, (gdb_byte
*) pathname
, pathlen
);
7194 pathname
[pathlen
] = '\0';
7196 /* This is freed during event handling. */
7197 event
->ws
.value
.execd_pathname
= xstrdup (pathname
);
7198 event
->ws
.kind
= TARGET_WAITKIND_EXECD
;
7200 /* Skip the registers included in this packet, since
7201 they may be for an architecture different from the
7202 one used by the original program. */
7205 else if (strprefix (p
, p1
, "create"))
7207 event
->ws
.kind
= TARGET_WAITKIND_THREAD_CREATED
;
7208 p
= strchrnul (p1
+ 1, ';');
7217 p
= strchrnul (p1
+ 1, ';');
7222 /* Maybe a real ``P'' register number. */
7223 p_temp
= unpack_varlen_hex (p
, &pnum
);
7224 /* If the first invalid character is the colon, we got a
7225 register number. Otherwise, it's an unknown stop
7229 /* If we haven't parsed the event's thread yet, find
7230 it now, in order to find the architecture of the
7231 reported expedited registers. */
7232 if (event
->ptid
== null_ptid
)
7234 const char *thr
= strstr (p1
+ 1, ";thread:");
7236 event
->ptid
= read_ptid (thr
+ strlen (";thread:"),
7240 /* Either the current thread hasn't changed,
7241 or the inferior is not multi-threaded.
7242 The event must be for the thread we last
7243 set as (or learned as being) current. */
7244 event
->ptid
= event
->rs
->general_thread
;
7250 inferior
*inf
= (event
->ptid
== null_ptid
7252 : find_inferior_ptid (event
->ptid
));
7253 /* If this is the first time we learn anything
7254 about this process, skip the registers
7255 included in this packet, since we don't yet
7256 know which architecture to use to parse them.
7257 We'll determine the architecture later when
7258 we process the stop reply and retrieve the
7259 target description, via
7260 remote_notice_new_inferior ->
7261 post_create_inferior. */
7264 p
= strchrnul (p1
+ 1, ';');
7269 event
->arch
= inf
->gdbarch
;
7270 rsa
= event
->rs
->get_remote_arch_state (event
->arch
);
7274 = packet_reg_from_pnum (event
->arch
, rsa
, pnum
);
7275 cached_reg_t cached_reg
;
7278 error (_("Remote sent bad register number %s: %s\n\
7280 hex_string (pnum
), p
, buf
);
7282 cached_reg
.num
= reg
->regnum
;
7283 cached_reg
.data
= (gdb_byte
*)
7284 xmalloc (register_size (event
->arch
, reg
->regnum
));
7287 fieldsize
= hex2bin (p
, cached_reg
.data
,
7288 register_size (event
->arch
, reg
->regnum
));
7290 if (fieldsize
< register_size (event
->arch
, reg
->regnum
))
7291 warning (_("Remote reply is too short: %s"), buf
);
7293 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
7297 /* Not a number. Silently skip unknown optional
7299 p
= strchrnul (p1
+ 1, ';');
7304 error (_("Remote register badly formatted: %s\nhere: %s"),
7309 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
7313 case 'S': /* Old style status, just signal only. */
7317 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
7318 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
7319 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
7320 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
7322 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
7325 case 'w': /* Thread exited. */
7330 event
->ws
.kind
= TARGET_WAITKIND_THREAD_EXITED
;
7331 p
= unpack_varlen_hex (&buf
[1], &value
);
7332 event
->ws
.value
.integer
= value
;
7334 error (_("stop reply packet badly formatted: %s"), buf
);
7335 event
->ptid
= read_ptid (++p
, NULL
);
7338 case 'W': /* Target exited. */
7345 /* GDB used to accept only 2 hex chars here. Stubs should
7346 only send more if they detect GDB supports multi-process
7348 p
= unpack_varlen_hex (&buf
[1], &value
);
7352 /* The remote process exited. */
7353 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
7354 event
->ws
.value
.integer
= value
;
7358 /* The remote process exited with a signal. */
7359 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
7360 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
7361 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
7363 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
7366 /* If no process is specified, assume inferior_ptid. */
7367 pid
= ptid_get_pid (inferior_ptid
);
7376 else if (startswith (p
, "process:"))
7380 p
+= sizeof ("process:") - 1;
7381 unpack_varlen_hex (p
, &upid
);
7385 error (_("unknown stop reply packet: %s"), buf
);
7388 error (_("unknown stop reply packet: %s"), buf
);
7389 event
->ptid
= pid_to_ptid (pid
);
7393 event
->ws
.kind
= TARGET_WAITKIND_NO_RESUMED
;
7394 event
->ptid
= minus_one_ptid
;
7398 if (target_is_non_stop_p () && ptid_equal (event
->ptid
, null_ptid
))
7399 error (_("No process or thread specified in stop reply: %s"), buf
);
7402 /* When the stub wants to tell GDB about a new notification reply, it
7403 sends a notification (%Stop, for example). Those can come it at
7404 any time, hence, we have to make sure that any pending
7405 putpkt/getpkt sequence we're making is finished, before querying
7406 the stub for more events with the corresponding ack command
7407 (vStopped, for example). E.g., if we started a vStopped sequence
7408 immediately upon receiving the notification, something like this
7416 1.6) <-- (registers reply to step #1.3)
7418 Obviously, the reply in step #1.6 would be unexpected to a vStopped
7421 To solve this, whenever we parse a %Stop notification successfully,
7422 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
7423 doing whatever we were doing:
7429 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
7430 2.5) <-- (registers reply to step #2.3)
7432 Eventualy after step #2.5, we return to the event loop, which
7433 notices there's an event on the
7434 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
7435 associated callback --- the function below. At this point, we're
7436 always safe to start a vStopped sequence. :
7439 2.7) <-- T05 thread:2
7445 remote_notif_get_pending_events (struct notif_client
*nc
)
7447 struct remote_state
*rs
= get_remote_state ();
7449 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
7452 fprintf_unfiltered (gdb_stdlog
,
7453 "notif: process: '%s' ack pending event\n",
7457 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
7458 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
7462 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7463 if (strcmp (rs
->buf
, "OK") == 0)
7466 remote_notif_ack (nc
, rs
->buf
);
7472 fprintf_unfiltered (gdb_stdlog
,
7473 "notif: process: '%s' no pending reply\n",
7478 /* Called when it is decided that STOP_REPLY holds the info of the
7479 event that is to be returned to the core. This function always
7480 destroys STOP_REPLY. */
7483 process_stop_reply (struct stop_reply
*stop_reply
,
7484 struct target_waitstatus
*status
)
7488 *status
= stop_reply
->ws
;
7489 ptid
= stop_reply
->ptid
;
7491 /* If no thread/process was reported by the stub, assume the current
7493 if (ptid_equal (ptid
, null_ptid
))
7494 ptid
= inferior_ptid
;
7496 if (status
->kind
!= TARGET_WAITKIND_EXITED
7497 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
7498 && status
->kind
!= TARGET_WAITKIND_NO_RESUMED
)
7500 /* Expedited registers. */
7501 if (stop_reply
->regcache
)
7503 struct regcache
*regcache
7504 = get_thread_arch_regcache (ptid
, stop_reply
->arch
);
7509 VEC_iterate (cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
7512 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
7516 VEC_free (cached_reg_t
, stop_reply
->regcache
);
7519 remote_notice_new_inferior (ptid
, 0);
7520 remote_thread_info
*remote_thr
= get_remote_thread_info (ptid
);
7521 remote_thr
->core
= stop_reply
->core
;
7522 remote_thr
->stop_reason
= stop_reply
->stop_reason
;
7523 remote_thr
->watch_data_address
= stop_reply
->watch_data_address
;
7524 remote_thr
->vcont_resumed
= 0;
7527 stop_reply_xfree (stop_reply
);
7531 /* The non-stop mode version of target_wait. */
7534 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7536 struct remote_state
*rs
= get_remote_state ();
7537 struct stop_reply
*stop_reply
;
7541 /* If in non-stop mode, get out of getpkt even if a
7542 notification is received. */
7544 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
7545 0 /* forever */, &is_notif
);
7548 if (ret
!= -1 && !is_notif
)
7551 case 'E': /* Error of some sort. */
7552 /* We're out of sync with the target now. Did it continue
7553 or not? We can't tell which thread it was in non-stop,
7554 so just ignore this. */
7555 warning (_("Remote failure reply: %s"), rs
->buf
);
7557 case 'O': /* Console output. */
7558 remote_console_output (rs
->buf
+ 1);
7561 warning (_("Invalid remote reply: %s"), rs
->buf
);
7565 /* Acknowledge a pending stop reply that may have arrived in the
7567 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
7568 remote_notif_get_pending_events (¬if_client_stop
);
7570 /* If indeed we noticed a stop reply, we're done. */
7571 stop_reply
= queued_stop_reply (ptid
);
7572 if (stop_reply
!= NULL
)
7573 return process_stop_reply (stop_reply
, status
);
7575 /* Still no event. If we're just polling for an event, then
7576 return to the event loop. */
7577 if (options
& TARGET_WNOHANG
)
7579 status
->kind
= TARGET_WAITKIND_IGNORE
;
7580 return minus_one_ptid
;
7583 /* Otherwise do a blocking wait. */
7584 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
7585 1 /* forever */, &is_notif
);
7589 /* Wait until the remote machine stops, then return, storing status in
7590 STATUS just as `wait' would. */
7593 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7595 struct remote_state
*rs
= get_remote_state ();
7596 ptid_t event_ptid
= null_ptid
;
7598 struct stop_reply
*stop_reply
;
7602 status
->kind
= TARGET_WAITKIND_IGNORE
;
7603 status
->value
.integer
= 0;
7605 stop_reply
= queued_stop_reply (ptid
);
7606 if (stop_reply
!= NULL
)
7607 return process_stop_reply (stop_reply
, status
);
7609 if (rs
->cached_wait_status
)
7610 /* Use the cached wait status, but only once. */
7611 rs
->cached_wait_status
= 0;
7616 int forever
= ((options
& TARGET_WNOHANG
) == 0
7617 && wait_forever_enabled_p
);
7619 if (!rs
->waiting_for_stop_reply
)
7621 status
->kind
= TARGET_WAITKIND_NO_RESUMED
;
7622 return minus_one_ptid
;
7625 /* FIXME: cagney/1999-09-27: If we're in async mode we should
7626 _never_ wait for ever -> test on target_is_async_p().
7627 However, before we do that we need to ensure that the caller
7628 knows how to take the target into/out of async mode. */
7629 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
7630 forever
, &is_notif
);
7632 /* GDB gets a notification. Return to core as this event is
7634 if (ret
!= -1 && is_notif
)
7635 return minus_one_ptid
;
7637 if (ret
== -1 && (options
& TARGET_WNOHANG
) != 0)
7638 return minus_one_ptid
;
7643 /* Assume that the target has acknowledged Ctrl-C unless we receive
7644 an 'F' or 'O' packet. */
7645 if (buf
[0] != 'F' && buf
[0] != 'O')
7646 rs
->ctrlc_pending_p
= 0;
7650 case 'E': /* Error of some sort. */
7651 /* We're out of sync with the target now. Did it continue or
7652 not? Not is more likely, so report a stop. */
7653 rs
->waiting_for_stop_reply
= 0;
7655 warning (_("Remote failure reply: %s"), buf
);
7656 status
->kind
= TARGET_WAITKIND_STOPPED
;
7657 status
->value
.sig
= GDB_SIGNAL_0
;
7659 case 'F': /* File-I/O request. */
7660 /* GDB may access the inferior memory while handling the File-I/O
7661 request, but we don't want GDB accessing memory while waiting
7662 for a stop reply. See the comments in putpkt_binary. Set
7663 waiting_for_stop_reply to 0 temporarily. */
7664 rs
->waiting_for_stop_reply
= 0;
7665 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
7666 rs
->ctrlc_pending_p
= 0;
7667 /* GDB handled the File-I/O request, and the target is running
7668 again. Keep waiting for events. */
7669 rs
->waiting_for_stop_reply
= 1;
7671 case 'N': case 'T': case 'S': case 'X': case 'W':
7673 struct stop_reply
*stop_reply
;
7675 /* There is a stop reply to handle. */
7676 rs
->waiting_for_stop_reply
= 0;
7679 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
7682 event_ptid
= process_stop_reply (stop_reply
, status
);
7685 case 'O': /* Console output. */
7686 remote_console_output (buf
+ 1);
7689 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
7691 /* Zero length reply means that we tried 'S' or 'C' and the
7692 remote system doesn't support it. */
7693 target_terminal::ours_for_output ();
7695 ("Can't send signals to this remote system. %s not sent.\n",
7696 gdb_signal_to_name (rs
->last_sent_signal
));
7697 rs
->last_sent_signal
= GDB_SIGNAL_0
;
7698 target_terminal::inferior ();
7700 strcpy (buf
, rs
->last_sent_step
? "s" : "c");
7706 warning (_("Invalid remote reply: %s"), buf
);
7710 if (status
->kind
== TARGET_WAITKIND_NO_RESUMED
)
7711 return minus_one_ptid
;
7712 else if (status
->kind
== TARGET_WAITKIND_IGNORE
)
7714 /* Nothing interesting happened. If we're doing a non-blocking
7715 poll, we're done. Otherwise, go back to waiting. */
7716 if (options
& TARGET_WNOHANG
)
7717 return minus_one_ptid
;
7721 else if (status
->kind
!= TARGET_WAITKIND_EXITED
7722 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
7724 if (!ptid_equal (event_ptid
, null_ptid
))
7725 record_currthread (rs
, event_ptid
);
7727 event_ptid
= inferior_ptid
;
7730 /* A process exit. Invalidate our notion of current thread. */
7731 record_currthread (rs
, minus_one_ptid
);
7736 /* Wait until the remote machine stops, then return, storing status in
7737 STATUS just as `wait' would. */
7740 remote_target::wait (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7744 if (target_is_non_stop_p ())
7745 event_ptid
= remote_wait_ns (ptid
, status
, options
);
7747 event_ptid
= remote_wait_as (ptid
, status
, options
);
7749 if (target_is_async_p ())
7751 /* If there are are events left in the queue tell the event loop
7753 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
7754 mark_async_event_handler (remote_async_inferior_event_token
);
7760 /* Fetch a single register using a 'p' packet. */
7763 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
7765 struct gdbarch
*gdbarch
= regcache
->arch ();
7766 struct remote_state
*rs
= get_remote_state ();
7768 gdb_byte
*regp
= (gdb_byte
*) alloca (register_size (gdbarch
, reg
->regnum
));
7771 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
7774 if (reg
->pnum
== -1)
7779 p
+= hexnumstr (p
, reg
->pnum
);
7782 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7786 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
7790 case PACKET_UNKNOWN
:
7793 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
7794 gdbarch_register_name (regcache
->arch (),
7799 /* If this register is unfetchable, tell the regcache. */
7802 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7806 /* Otherwise, parse and supply the value. */
7812 error (_("fetch_register_using_p: early buf termination"));
7814 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7817 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
7821 /* Fetch the registers included in the target's 'g' packet. */
7824 send_g_packet (void)
7826 struct remote_state
*rs
= get_remote_state ();
7829 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
7831 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7832 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
7833 error (_("Could not read registers; remote failure reply '%s'"),
7836 /* We can get out of synch in various cases. If the first character
7837 in the buffer is not a hex character, assume that has happened
7838 and try to fetch another packet to read. */
7839 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
7840 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
7841 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
7842 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
7845 fprintf_unfiltered (gdb_stdlog
,
7846 "Bad register packet; fetching a new packet\n");
7847 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7850 buf_len
= strlen (rs
->buf
);
7852 /* Sanity check the received packet. */
7853 if (buf_len
% 2 != 0)
7854 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
7860 process_g_packet (struct regcache
*regcache
)
7862 struct gdbarch
*gdbarch
= regcache
->arch ();
7863 struct remote_state
*rs
= get_remote_state ();
7864 remote_arch_state
*rsa
= rs
->get_remote_arch_state (gdbarch
);
7869 buf_len
= strlen (rs
->buf
);
7871 /* Further sanity checks, with knowledge of the architecture. */
7872 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
7873 error (_("Remote 'g' packet reply is too long (expected %ld bytes, got %d "
7874 "bytes): %s"), rsa
->sizeof_g_packet
, buf_len
/ 2, rs
->buf
);
7876 /* Save the size of the packet sent to us by the target. It is used
7877 as a heuristic when determining the max size of packets that the
7878 target can safely receive. */
7879 if (rsa
->actual_register_packet_size
== 0)
7880 rsa
->actual_register_packet_size
= buf_len
;
7882 /* If this is smaller than we guessed the 'g' packet would be,
7883 update our records. A 'g' reply that doesn't include a register's
7884 value implies either that the register is not available, or that
7885 the 'p' packet must be used. */
7886 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
7888 long sizeof_g_packet
= buf_len
/ 2;
7890 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7892 long offset
= rsa
->regs
[i
].offset
;
7893 long reg_size
= register_size (gdbarch
, i
);
7895 if (rsa
->regs
[i
].pnum
== -1)
7898 if (offset
>= sizeof_g_packet
)
7899 rsa
->regs
[i
].in_g_packet
= 0;
7900 else if (offset
+ reg_size
> sizeof_g_packet
)
7901 error (_("Truncated register %d in remote 'g' packet"), i
);
7903 rsa
->regs
[i
].in_g_packet
= 1;
7906 /* Looks valid enough, we can assume this is the correct length
7907 for a 'g' packet. It's important not to adjust
7908 rsa->sizeof_g_packet if we have truncated registers otherwise
7909 this "if" won't be run the next time the method is called
7910 with a packet of the same size and one of the internal errors
7911 below will trigger instead. */
7912 rsa
->sizeof_g_packet
= sizeof_g_packet
;
7915 regs
= (char *) alloca (rsa
->sizeof_g_packet
);
7917 /* Unimplemented registers read as all bits zero. */
7918 memset (regs
, 0, rsa
->sizeof_g_packet
);
7920 /* Reply describes registers byte by byte, each byte encoded as two
7921 hex characters. Suck them all up, then supply them to the
7922 register cacheing/storage mechanism. */
7925 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
7927 if (p
[0] == 0 || p
[1] == 0)
7928 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
7929 internal_error (__FILE__
, __LINE__
,
7930 _("unexpected end of 'g' packet reply"));
7932 if (p
[0] == 'x' && p
[1] == 'x')
7933 regs
[i
] = 0; /* 'x' */
7935 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7939 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7941 struct packet_reg
*r
= &rsa
->regs
[i
];
7942 long reg_size
= register_size (gdbarch
, i
);
7946 if ((r
->offset
+ reg_size
) * 2 > strlen (rs
->buf
))
7947 /* This shouldn't happen - we adjusted in_g_packet above. */
7948 internal_error (__FILE__
, __LINE__
,
7949 _("unexpected end of 'g' packet reply"));
7950 else if (rs
->buf
[r
->offset
* 2] == 'x')
7952 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
7953 /* The register isn't available, mark it as such (at
7954 the same time setting the value to zero). */
7955 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
7958 regcache_raw_supply (regcache
, r
->regnum
,
7965 fetch_registers_using_g (struct regcache
*regcache
)
7968 process_g_packet (regcache
);
7971 /* Make the remote selected traceframe match GDB's selected
7975 set_remote_traceframe (void)
7978 struct remote_state
*rs
= get_remote_state ();
7980 if (rs
->remote_traceframe_number
== get_traceframe_number ())
7983 /* Avoid recursion, remote_trace_find calls us again. */
7984 rs
->remote_traceframe_number
= get_traceframe_number ();
7986 newnum
= target_trace_find (tfind_number
,
7987 get_traceframe_number (), 0, 0, NULL
);
7989 /* Should not happen. If it does, all bets are off. */
7990 if (newnum
!= get_traceframe_number ())
7991 warning (_("could not set remote traceframe"));
7995 remote_target::fetch_registers (struct regcache
*regcache
, int regnum
)
7997 struct gdbarch
*gdbarch
= regcache
->arch ();
7998 struct remote_state
*rs
= get_remote_state ();
7999 remote_arch_state
*rsa
= rs
->get_remote_arch_state (gdbarch
);
8002 set_remote_traceframe ();
8003 set_general_thread (regcache_get_ptid (regcache
));
8007 packet_reg
*reg
= packet_reg_from_regnum (gdbarch
, rsa
, regnum
);
8009 gdb_assert (reg
!= NULL
);
8011 /* If this register might be in the 'g' packet, try that first -
8012 we are likely to read more than one register. If this is the
8013 first 'g' packet, we might be overly optimistic about its
8014 contents, so fall back to 'p'. */
8015 if (reg
->in_g_packet
)
8017 fetch_registers_using_g (regcache
);
8018 if (reg
->in_g_packet
)
8022 if (fetch_register_using_p (regcache
, reg
))
8025 /* This register is not available. */
8026 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
8031 fetch_registers_using_g (regcache
);
8033 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
8034 if (!rsa
->regs
[i
].in_g_packet
)
8035 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
8037 /* This register is not available. */
8038 regcache_raw_supply (regcache
, i
, NULL
);
8042 /* Prepare to store registers. Since we may send them all (using a
8043 'G' request), we have to read out the ones we don't want to change
8047 remote_target::prepare_to_store (struct regcache
*regcache
)
8049 struct remote_state
*rs
= get_remote_state ();
8050 remote_arch_state
*rsa
= rs
->get_remote_arch_state (regcache
->arch ());
8053 /* Make sure the entire registers array is valid. */
8054 switch (packet_support (PACKET_P
))
8056 case PACKET_DISABLE
:
8057 case PACKET_SUPPORT_UNKNOWN
:
8058 /* Make sure all the necessary registers are cached. */
8059 for (i
= 0; i
< gdbarch_num_regs (regcache
->arch ()); i
++)
8060 if (rsa
->regs
[i
].in_g_packet
)
8061 regcache_raw_update (regcache
, rsa
->regs
[i
].regnum
);
8068 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
8069 packet was not recognized. */
8072 store_register_using_P (const struct regcache
*regcache
,
8073 struct packet_reg
*reg
)
8075 struct gdbarch
*gdbarch
= regcache
->arch ();
8076 struct remote_state
*rs
= get_remote_state ();
8077 /* Try storing a single register. */
8078 char *buf
= rs
->buf
;
8079 gdb_byte
*regp
= (gdb_byte
*) alloca (register_size (gdbarch
, reg
->regnum
));
8082 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
8085 if (reg
->pnum
== -1)
8088 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
8089 p
= buf
+ strlen (buf
);
8090 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
8091 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
8093 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8095 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
8100 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
8101 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
8102 case PACKET_UNKNOWN
:
8105 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
8109 /* Store register REGNUM, or all registers if REGNUM == -1, from the
8110 contents of the register cache buffer. FIXME: ignores errors. */
8113 store_registers_using_G (const struct regcache
*regcache
)
8115 struct remote_state
*rs
= get_remote_state ();
8116 remote_arch_state
*rsa
= rs
->get_remote_arch_state (regcache
->arch ());
8120 /* Extract all the registers in the regcache copying them into a
8125 regs
= (gdb_byte
*) alloca (rsa
->sizeof_g_packet
);
8126 memset (regs
, 0, rsa
->sizeof_g_packet
);
8127 for (i
= 0; i
< gdbarch_num_regs (regcache
->arch ()); i
++)
8129 struct packet_reg
*r
= &rsa
->regs
[i
];
8132 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
8136 /* Command describes registers byte by byte,
8137 each byte encoded as two hex characters. */
8140 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
8142 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8143 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
8144 error (_("Could not write registers; remote failure reply '%s'"),
8148 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
8149 of the register cache buffer. FIXME: ignores errors. */
8152 remote_target::store_registers (struct regcache
*regcache
, int regnum
)
8154 struct gdbarch
*gdbarch
= regcache
->arch ();
8155 struct remote_state
*rs
= get_remote_state ();
8156 remote_arch_state
*rsa
= rs
->get_remote_arch_state (gdbarch
);
8159 set_remote_traceframe ();
8160 set_general_thread (regcache_get_ptid (regcache
));
8164 packet_reg
*reg
= packet_reg_from_regnum (gdbarch
, rsa
, regnum
);
8166 gdb_assert (reg
!= NULL
);
8168 /* Always prefer to store registers using the 'P' packet if
8169 possible; we often change only a small number of registers.
8170 Sometimes we change a larger number; we'd need help from a
8171 higher layer to know to use 'G'. */
8172 if (store_register_using_P (regcache
, reg
))
8175 /* For now, don't complain if we have no way to write the
8176 register. GDB loses track of unavailable registers too
8177 easily. Some day, this may be an error. We don't have
8178 any way to read the register, either... */
8179 if (!reg
->in_g_packet
)
8182 store_registers_using_G (regcache
);
8186 store_registers_using_G (regcache
);
8188 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
8189 if (!rsa
->regs
[i
].in_g_packet
)
8190 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
8191 /* See above for why we do not issue an error here. */
8196 /* Return the number of hex digits in num. */
8199 hexnumlen (ULONGEST num
)
8203 for (i
= 0; num
!= 0; i
++)
8206 return std::max (i
, 1);
8209 /* Set BUF to the minimum number of hex digits representing NUM. */
8212 hexnumstr (char *buf
, ULONGEST num
)
8214 int len
= hexnumlen (num
);
8216 return hexnumnstr (buf
, num
, len
);
8220 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
8223 hexnumnstr (char *buf
, ULONGEST num
, int width
)
8229 for (i
= width
- 1; i
>= 0; i
--)
8231 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
8238 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
8241 remote_address_masked (CORE_ADDR addr
)
8243 unsigned int address_size
= remote_address_size
;
8245 /* If "remoteaddresssize" was not set, default to target address size. */
8247 address_size
= gdbarch_addr_bit (target_gdbarch ());
8249 if (address_size
> 0
8250 && address_size
< (sizeof (ULONGEST
) * 8))
8252 /* Only create a mask when that mask can safely be constructed
8253 in a ULONGEST variable. */
8256 mask
= (mask
<< address_size
) - 1;
8262 /* Determine whether the remote target supports binary downloading.
8263 This is accomplished by sending a no-op memory write of zero length
8264 to the target at the specified address. It does not suffice to send
8265 the whole packet, since many stubs strip the eighth bit and
8266 subsequently compute a wrong checksum, which causes real havoc with
8269 NOTE: This can still lose if the serial line is not eight-bit
8270 clean. In cases like this, the user should clear "remote
8274 check_binary_download (CORE_ADDR addr
)
8276 struct remote_state
*rs
= get_remote_state ();
8278 switch (packet_support (PACKET_X
))
8280 case PACKET_DISABLE
:
8284 case PACKET_SUPPORT_UNKNOWN
:
8290 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8292 p
+= hexnumstr (p
, (ULONGEST
) 0);
8296 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
8297 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8299 if (rs
->buf
[0] == '\0')
8302 fprintf_unfiltered (gdb_stdlog
,
8303 "binary downloading NOT "
8304 "supported by target\n");
8305 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
8310 fprintf_unfiltered (gdb_stdlog
,
8311 "binary downloading supported by target\n");
8312 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
8319 /* Helper function to resize the payload in order to try to get a good
8320 alignment. We try to write an amount of data such that the next write will
8321 start on an address aligned on REMOTE_ALIGN_WRITES. */
8324 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
8326 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
8329 /* Write memory data directly to the remote machine.
8330 This does not inform the data cache; the data cache uses this.
8331 HEADER is the starting part of the packet.
8332 MEMADDR is the address in the remote memory space.
8333 MYADDR is the address of the buffer in our space.
8334 LEN_UNITS is the number of addressable units to write.
8335 UNIT_SIZE is the length in bytes of an addressable unit.
8336 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
8337 should send data as binary ('X'), or hex-encoded ('M').
8339 The function creates packet of the form
8340 <HEADER><ADDRESS>,<LENGTH>:<DATA>
8342 where encoding of <DATA> is terminated by PACKET_FORMAT.
8344 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
8347 Return the transferred status, error or OK (an
8348 'enum target_xfer_status' value). Save the number of addressable units
8349 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
8351 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
8352 exchange between gdb and the stub could look like (?? in place of the
8358 -> $M1000,3:eeeeffffeeee#??
8362 <- eeeeffffeeeedddd */
8364 static enum target_xfer_status
8365 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
8366 const gdb_byte
*myaddr
, ULONGEST len_units
,
8367 int unit_size
, ULONGEST
*xfered_len_units
,
8368 char packet_format
, int use_length
)
8370 struct remote_state
*rs
= get_remote_state ();
8376 int payload_capacity_bytes
;
8377 int payload_length_bytes
;
8379 if (packet_format
!= 'X' && packet_format
!= 'M')
8380 internal_error (__FILE__
, __LINE__
,
8381 _("remote_write_bytes_aux: bad packet format"));
8384 return TARGET_XFER_EOF
;
8386 payload_capacity_bytes
= get_memory_write_packet_size ();
8388 /* The packet buffer will be large enough for the payload;
8389 get_memory_packet_size ensures this. */
8392 /* Compute the size of the actual payload by subtracting out the
8393 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
8395 payload_capacity_bytes
-= strlen ("$,:#NN");
8397 /* The comma won't be used. */
8398 payload_capacity_bytes
+= 1;
8399 payload_capacity_bytes
-= strlen (header
);
8400 payload_capacity_bytes
-= hexnumlen (memaddr
);
8402 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
8404 strcat (rs
->buf
, header
);
8405 p
= rs
->buf
+ strlen (header
);
8407 /* Compute a best guess of the number of bytes actually transfered. */
8408 if (packet_format
== 'X')
8410 /* Best guess at number of bytes that will fit. */
8411 todo_units
= std::min (len_units
,
8412 (ULONGEST
) payload_capacity_bytes
/ unit_size
);
8414 payload_capacity_bytes
-= hexnumlen (todo_units
);
8415 todo_units
= std::min (todo_units
, payload_capacity_bytes
/ unit_size
);
8419 /* Number of bytes that will fit. */
8421 = std::min (len_units
,
8422 (ULONGEST
) (payload_capacity_bytes
/ unit_size
) / 2);
8424 payload_capacity_bytes
-= hexnumlen (todo_units
);
8425 todo_units
= std::min (todo_units
,
8426 (payload_capacity_bytes
/ unit_size
) / 2);
8429 if (todo_units
<= 0)
8430 internal_error (__FILE__
, __LINE__
,
8431 _("minimum packet size too small to write data"));
8433 /* If we already need another packet, then try to align the end
8434 of this packet to a useful boundary. */
8435 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
8436 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
8438 /* Append "<memaddr>". */
8439 memaddr
= remote_address_masked (memaddr
);
8440 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
8447 /* Append the length and retain its location and size. It may need to be
8448 adjusted once the packet body has been created. */
8450 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
8458 /* Append the packet body. */
8459 if (packet_format
== 'X')
8461 /* Binary mode. Send target system values byte by byte, in
8462 increasing byte addresses. Only escape certain critical
8464 payload_length_bytes
=
8465 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
8466 &units_written
, payload_capacity_bytes
);
8468 /* If not all TODO units fit, then we'll need another packet. Make
8469 a second try to keep the end of the packet aligned. Don't do
8470 this if the packet is tiny. */
8471 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
8475 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
8477 if (new_todo_units
!= units_written
)
8478 payload_length_bytes
=
8479 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
8480 (gdb_byte
*) p
, &units_written
,
8481 payload_capacity_bytes
);
8484 p
+= payload_length_bytes
;
8485 if (use_length
&& units_written
< todo_units
)
8487 /* Escape chars have filled up the buffer prematurely,
8488 and we have actually sent fewer units than planned.
8489 Fix-up the length field of the packet. Use the same
8490 number of characters as before. */
8491 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
8493 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
8498 /* Normal mode: Send target system values byte by byte, in
8499 increasing byte addresses. Each byte is encoded as a two hex
8501 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
8502 units_written
= todo_units
;
8505 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
8506 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8508 if (rs
->buf
[0] == 'E')
8509 return TARGET_XFER_E_IO
;
8511 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
8512 send fewer units than we'd planned. */
8513 *xfered_len_units
= (ULONGEST
) units_written
;
8514 return (*xfered_len_units
!= 0) ? TARGET_XFER_OK
: TARGET_XFER_EOF
;
8517 /* Write memory data directly to the remote machine.
8518 This does not inform the data cache; the data cache uses this.
8519 MEMADDR is the address in the remote memory space.
8520 MYADDR is the address of the buffer in our space.
8521 LEN is the number of bytes.
8523 Return the transferred status, error or OK (an
8524 'enum target_xfer_status' value). Save the number of bytes
8525 transferred in *XFERED_LEN. Only transfer a single packet. */
8527 static enum target_xfer_status
8528 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
8529 int unit_size
, ULONGEST
*xfered_len
)
8531 const char *packet_format
= NULL
;
8533 /* Check whether the target supports binary download. */
8534 check_binary_download (memaddr
);
8536 switch (packet_support (PACKET_X
))
8539 packet_format
= "X";
8541 case PACKET_DISABLE
:
8542 packet_format
= "M";
8544 case PACKET_SUPPORT_UNKNOWN
:
8545 internal_error (__FILE__
, __LINE__
,
8546 _("remote_write_bytes: bad internal state"));
8548 internal_error (__FILE__
, __LINE__
, _("bad switch"));
8551 return remote_write_bytes_aux (packet_format
,
8552 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
8553 packet_format
[0], 1);
8556 /* Read memory data directly from the remote machine.
8557 This does not use the data cache; the data cache uses this.
8558 MEMADDR is the address in the remote memory space.
8559 MYADDR is the address of the buffer in our space.
8560 LEN_UNITS is the number of addressable memory units to read..
8561 UNIT_SIZE is the length in bytes of an addressable unit.
8563 Return the transferred status, error or OK (an
8564 'enum target_xfer_status' value). Save the number of bytes
8565 transferred in *XFERED_LEN_UNITS.
8567 See the comment of remote_write_bytes_aux for an example of
8568 memory read/write exchange between gdb and the stub. */
8570 static enum target_xfer_status
8571 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
8572 int unit_size
, ULONGEST
*xfered_len_units
)
8574 struct remote_state
*rs
= get_remote_state ();
8575 int buf_size_bytes
; /* Max size of packet output buffer. */
8580 buf_size_bytes
= get_memory_read_packet_size ();
8581 /* The packet buffer will be large enough for the payload;
8582 get_memory_packet_size ensures this. */
8584 /* Number of units that will fit. */
8585 todo_units
= std::min (len_units
,
8586 (ULONGEST
) (buf_size_bytes
/ unit_size
) / 2);
8588 /* Construct "m"<memaddr>","<len>". */
8589 memaddr
= remote_address_masked (memaddr
);
8592 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
8594 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
8597 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8598 if (rs
->buf
[0] == 'E'
8599 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
8600 && rs
->buf
[3] == '\0')
8601 return TARGET_XFER_E_IO
;
8602 /* Reply describes memory byte by byte, each byte encoded as two hex
8605 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
8606 /* Return what we have. Let higher layers handle partial reads. */
8607 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
8608 return (*xfered_len_units
!= 0) ? TARGET_XFER_OK
: TARGET_XFER_EOF
;
8611 /* Using the set of read-only target sections of remote, read live
8614 For interface/parameters/return description see target.h,
8617 static enum target_xfer_status
8618 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
8619 ULONGEST memaddr
, ULONGEST len
,
8620 int unit_size
, ULONGEST
*xfered_len
)
8622 struct target_section
*secp
;
8623 struct target_section_table
*table
;
8625 secp
= target_section_by_addr (ops
, memaddr
);
8627 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
8628 secp
->the_bfd_section
)
8631 struct target_section
*p
;
8632 ULONGEST memend
= memaddr
+ len
;
8634 table
= target_get_section_table (ops
);
8636 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
8638 if (memaddr
>= p
->addr
)
8640 if (memend
<= p
->endaddr
)
8642 /* Entire transfer is within this section. */
8643 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
8646 else if (memaddr
>= p
->endaddr
)
8648 /* This section ends before the transfer starts. */
8653 /* This section overlaps the transfer. Just do half. */
8654 len
= p
->endaddr
- memaddr
;
8655 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
8662 return TARGET_XFER_EOF
;
8665 /* Similar to remote_read_bytes_1, but it reads from the remote stub
8666 first if the requested memory is unavailable in traceframe.
8667 Otherwise, fall back to remote_read_bytes_1. */
8669 static enum target_xfer_status
8670 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
8671 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
8672 ULONGEST
*xfered_len
)
8675 return TARGET_XFER_EOF
;
8677 if (get_traceframe_number () != -1)
8679 std::vector
<mem_range
> available
;
8681 /* If we fail to get the set of available memory, then the
8682 target does not support querying traceframe info, and so we
8683 attempt reading from the traceframe anyway (assuming the
8684 target implements the old QTro packet then). */
8685 if (traceframe_available_memory (&available
, memaddr
, len
))
8687 if (available
.empty () || available
[0].start
!= memaddr
)
8689 enum target_xfer_status res
;
8691 /* Don't read into the traceframe's available
8693 if (!available
.empty ())
8695 LONGEST oldlen
= len
;
8697 len
= available
[0].start
- memaddr
;
8698 gdb_assert (len
<= oldlen
);
8701 /* This goes through the topmost target again. */
8702 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
8703 len
, unit_size
, xfered_len
);
8704 if (res
== TARGET_XFER_OK
)
8705 return TARGET_XFER_OK
;
8708 /* No use trying further, we know some memory starting
8709 at MEMADDR isn't available. */
8711 return (*xfered_len
!= 0) ?
8712 TARGET_XFER_UNAVAILABLE
: TARGET_XFER_EOF
;
8716 /* Don't try to read more than how much is available, in
8717 case the target implements the deprecated QTro packet to
8718 cater for older GDBs (the target's knowledge of read-only
8719 sections may be outdated by now). */
8720 len
= available
[0].length
;
8724 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
8729 /* Sends a packet with content determined by the printf format string
8730 FORMAT and the remaining arguments, then gets the reply. Returns
8731 whether the packet was a success, a failure, or unknown. */
8733 static enum packet_result
remote_send_printf (const char *format
, ...)
8734 ATTRIBUTE_PRINTF (1, 2);
8736 static enum packet_result
8737 remote_send_printf (const char *format
, ...)
8739 struct remote_state
*rs
= get_remote_state ();
8740 int max_size
= get_remote_packet_size ();
8743 va_start (ap
, format
);
8746 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
8747 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
8749 if (putpkt (rs
->buf
) < 0)
8750 error (_("Communication problem with target."));
8753 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8755 return packet_check_result (rs
->buf
);
8758 /* Flash writing can take quite some time. We'll set
8759 effectively infinite timeout for flash operations.
8760 In future, we'll need to decide on a better approach. */
8761 static const int remote_flash_timeout
= 1000;
8764 remote_target::flash_erase (ULONGEST address
, LONGEST length
)
8766 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8767 enum packet_result ret
;
8768 scoped_restore restore_timeout
8769 = make_scoped_restore (&remote_timeout
, remote_flash_timeout
);
8771 ret
= remote_send_printf ("vFlashErase:%s,%s",
8772 phex (address
, addr_size
),
8776 case PACKET_UNKNOWN
:
8777 error (_("Remote target does not support flash erase"));
8779 error (_("Error erasing flash with vFlashErase packet"));
8785 static enum target_xfer_status
8786 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
8787 ULONGEST length
, ULONGEST
*xfered_len
,
8788 const gdb_byte
*data
)
8790 scoped_restore restore_timeout
8791 = make_scoped_restore (&remote_timeout
, remote_flash_timeout
);
8792 return remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
8797 remote_target::flash_done ()
8801 scoped_restore restore_timeout
8802 = make_scoped_restore (&remote_timeout
, remote_flash_timeout
);
8804 ret
= remote_send_printf ("vFlashDone");
8808 case PACKET_UNKNOWN
:
8809 error (_("Remote target does not support vFlashDone"));
8811 error (_("Error finishing flash operation"));
8818 remote_target::files_info ()
8820 puts_filtered ("Debugging a target over a serial line.\n");
8823 /* Stuff for dealing with the packets which are part of this protocol.
8824 See comment at top of file for details. */
8826 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
8827 error to higher layers. Called when a serial error is detected.
8828 The exception message is STRING, followed by a colon and a blank,
8829 the system error message for errno at function entry and final dot
8830 for output compatibility with throw_perror_with_name. */
8833 unpush_and_perror (const char *string
)
8835 int saved_errno
= errno
;
8837 remote_unpush_target ();
8838 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
8839 safe_strerror (saved_errno
));
8842 /* Read a single character from the remote end. The current quit
8843 handler is overridden to avoid quitting in the middle of packet
8844 sequence, as that would break communication with the remote server.
8845 See remote_serial_quit_handler for more detail. */
8848 readchar (int timeout
)
8851 struct remote_state
*rs
= get_remote_state ();
8854 scoped_restore restore_quit
8855 = make_scoped_restore (&quit_handler
, remote_serial_quit_handler
);
8857 rs
->got_ctrlc_during_io
= 0;
8859 ch
= serial_readchar (rs
->remote_desc
, timeout
);
8861 if (rs
->got_ctrlc_during_io
)
8868 switch ((enum serial_rc
) ch
)
8871 remote_unpush_target ();
8872 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
8875 unpush_and_perror (_("Remote communication error. "
8876 "Target disconnected."));
8878 case SERIAL_TIMEOUT
:
8884 /* Wrapper for serial_write that closes the target and throws if
8885 writing fails. The current quit handler is overridden to avoid
8886 quitting in the middle of packet sequence, as that would break
8887 communication with the remote server. See
8888 remote_serial_quit_handler for more detail. */
8891 remote_serial_write (const char *str
, int len
)
8893 struct remote_state
*rs
= get_remote_state ();
8895 scoped_restore restore_quit
8896 = make_scoped_restore (&quit_handler
, remote_serial_quit_handler
);
8898 rs
->got_ctrlc_during_io
= 0;
8900 if (serial_write (rs
->remote_desc
, str
, len
))
8902 unpush_and_perror (_("Remote communication error. "
8903 "Target disconnected."));
8906 if (rs
->got_ctrlc_during_io
)
8910 /* Return a string representing an escaped version of BUF, of len N.
8911 E.g. \n is converted to \\n, \t to \\t, etc. */
8914 escape_buffer (const char *buf
, int n
)
8918 stb
.putstrn (buf
, n
, '\\');
8919 return std::move (stb
.string ());
8922 /* Display a null-terminated packet on stdout, for debugging, using C
8926 print_packet (const char *buf
)
8928 puts_filtered ("\"");
8929 fputstr_filtered (buf
, '"', gdb_stdout
);
8930 puts_filtered ("\"");
8934 putpkt (const char *buf
)
8936 return putpkt_binary (buf
, strlen (buf
));
8939 /* Send a packet to the remote machine, with error checking. The data
8940 of the packet is in BUF. The string in BUF can be at most
8941 get_remote_packet_size () - 5 to account for the $, # and checksum,
8942 and for a possible /0 if we are debugging (remote_debug) and want
8943 to print the sent packet as a string. */
8946 putpkt_binary (const char *buf
, int cnt
)
8948 struct remote_state
*rs
= get_remote_state ();
8950 unsigned char csum
= 0;
8951 gdb::def_vector
<char> data (cnt
+ 6);
8952 char *buf2
= data
.data ();
8958 /* Catch cases like trying to read memory or listing threads while
8959 we're waiting for a stop reply. The remote server wouldn't be
8960 ready to handle this request, so we'd hang and timeout. We don't
8961 have to worry about this in synchronous mode, because in that
8962 case it's not possible to issue a command while the target is
8963 running. This is not a problem in non-stop mode, because in that
8964 case, the stub is always ready to process serial input. */
8965 if (!target_is_non_stop_p ()
8966 && target_is_async_p ()
8967 && rs
->waiting_for_stop_reply
)
8969 error (_("Cannot execute this command while the target is running.\n"
8970 "Use the \"interrupt\" command to stop the target\n"
8971 "and then try again."));
8974 /* We're sending out a new packet. Make sure we don't look at a
8975 stale cached response. */
8976 rs
->cached_wait_status
= 0;
8978 /* Copy the packet into buffer BUF2, encapsulating it
8979 and giving it a checksum. */
8984 for (i
= 0; i
< cnt
; i
++)
8990 *p
++ = tohex ((csum
>> 4) & 0xf);
8991 *p
++ = tohex (csum
& 0xf);
8993 /* Send it over and over until we get a positive ack. */
8997 int started_error_output
= 0;
9003 int len
= (int) (p
- buf2
);
9006 = escape_buffer (buf2
, std::min (len
, REMOTE_DEBUG_MAX_CHAR
));
9008 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s", str
.c_str ());
9010 if (len
> REMOTE_DEBUG_MAX_CHAR
)
9011 fprintf_unfiltered (gdb_stdlog
, "[%d bytes omitted]",
9012 len
- REMOTE_DEBUG_MAX_CHAR
);
9014 fprintf_unfiltered (gdb_stdlog
, "...");
9016 gdb_flush (gdb_stdlog
);
9018 remote_serial_write (buf2
, p
- buf2
);
9020 /* If this is a no acks version of the remote protocol, send the
9021 packet and move on. */
9025 /* Read until either a timeout occurs (-2) or '+' is read.
9026 Handle any notification that arrives in the mean time. */
9029 ch
= readchar (remote_timeout
);
9037 case SERIAL_TIMEOUT
:
9040 if (started_error_output
)
9042 putchar_unfiltered ('\n');
9043 started_error_output
= 0;
9052 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
9056 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
9058 case SERIAL_TIMEOUT
:
9062 break; /* Retransmit buffer. */
9066 fprintf_unfiltered (gdb_stdlog
,
9067 "Packet instead of Ack, ignoring it\n");
9068 /* It's probably an old response sent because an ACK
9069 was lost. Gobble up the packet and ack it so it
9070 doesn't get retransmitted when we resend this
9073 remote_serial_write ("+", 1);
9074 continue; /* Now, go look for +. */
9081 /* If we got a notification, handle it, and go back to looking
9083 /* We've found the start of a notification. Now
9084 collect the data. */
9085 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
9090 std::string str
= escape_buffer (rs
->buf
, val
);
9092 fprintf_unfiltered (gdb_stdlog
,
9093 " Notification received: %s\n",
9096 handle_notification (rs
->notif_state
, rs
->buf
);
9097 /* We're in sync now, rewait for the ack. */
9104 if (!started_error_output
)
9106 started_error_output
= 1;
9107 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
9109 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
9110 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
9119 if (!started_error_output
)
9121 started_error_output
= 1;
9122 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
9124 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
9128 break; /* Here to retransmit. */
9132 /* This is wrong. If doing a long backtrace, the user should be
9133 able to get out next time we call QUIT, without anything as
9134 violent as interrupt_query. If we want to provide a way out of
9135 here without getting to the next QUIT, it should be based on
9136 hitting ^C twice as in remote_wait. */
9148 /* Come here after finding the start of a frame when we expected an
9149 ack. Do our best to discard the rest of this packet. */
9158 c
= readchar (remote_timeout
);
9161 case SERIAL_TIMEOUT
:
9162 /* Nothing we can do. */
9165 /* Discard the two bytes of checksum and stop. */
9166 c
= readchar (remote_timeout
);
9168 c
= readchar (remote_timeout
);
9171 case '*': /* Run length encoding. */
9172 /* Discard the repeat count. */
9173 c
= readchar (remote_timeout
);
9178 /* A regular character. */
9184 /* Come here after finding the start of the frame. Collect the rest
9185 into *BUF, verifying the checksum, length, and handling run-length
9186 compression. NUL terminate the buffer. If there is not enough room,
9187 expand *BUF using xrealloc.
9189 Returns -1 on error, number of characters in buffer (ignoring the
9190 trailing NULL) on success. (could be extended to return one of the
9191 SERIAL status indications). */
9194 read_frame (char **buf_p
,
9201 struct remote_state
*rs
= get_remote_state ();
9208 c
= readchar (remote_timeout
);
9211 case SERIAL_TIMEOUT
:
9213 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
9217 fputs_filtered ("Saw new packet start in middle of old one\n",
9219 return -1; /* Start a new packet, count retries. */
9222 unsigned char pktcsum
;
9228 check_0
= readchar (remote_timeout
);
9230 check_1
= readchar (remote_timeout
);
9232 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
9235 fputs_filtered ("Timeout in checksum, retrying\n",
9239 else if (check_0
< 0 || check_1
< 0)
9242 fputs_filtered ("Communication error in checksum\n",
9247 /* Don't recompute the checksum; with no ack packets we
9248 don't have any way to indicate a packet retransmission
9253 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
9254 if (csum
== pktcsum
)
9259 std::string str
= escape_buffer (buf
, bc
);
9261 fprintf_unfiltered (gdb_stdlog
,
9262 "Bad checksum, sentsum=0x%x, "
9263 "csum=0x%x, buf=%s\n",
9264 pktcsum
, csum
, str
.c_str ());
9266 /* Number of characters in buffer ignoring trailing
9270 case '*': /* Run length encoding. */
9275 c
= readchar (remote_timeout
);
9277 repeat
= c
- ' ' + 3; /* Compute repeat count. */
9279 /* The character before ``*'' is repeated. */
9281 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
9283 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
9285 /* Make some more room in the buffer. */
9286 *sizeof_buf
+= repeat
;
9287 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
9291 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
9297 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
9301 if (bc
>= *sizeof_buf
- 1)
9303 /* Make some more room in the buffer. */
9305 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
9316 /* Read a packet from the remote machine, with error checking, and
9317 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
9318 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
9319 rather than timing out; this is used (in synchronous mode) to wait
9320 for a target that is is executing user code to stop. */
9321 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
9322 don't have to change all the calls to getpkt to deal with the
9323 return value, because at the moment I don't know what the right
9324 thing to do it for those. */
9330 getpkt_sane (buf
, sizeof_buf
, forever
);
9334 /* Read a packet from the remote machine, with error checking, and
9335 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
9336 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
9337 rather than timing out; this is used (in synchronous mode) to wait
9338 for a target that is is executing user code to stop. If FOREVER ==
9339 0, this function is allowed to time out gracefully and return an
9340 indication of this to the caller. Otherwise return the number of
9341 bytes read. If EXPECTING_NOTIF, consider receiving a notification
9342 enough reason to return to the caller. *IS_NOTIF is an output
9343 boolean that indicates whether *BUF holds a notification or not
9344 (a regular packet). */
9347 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
9348 int expecting_notif
, int *is_notif
)
9350 struct remote_state
*rs
= get_remote_state ();
9356 /* We're reading a new response. Make sure we don't look at a
9357 previously cached response. */
9358 rs
->cached_wait_status
= 0;
9360 strcpy (*buf
, "timeout");
9363 timeout
= watchdog
> 0 ? watchdog
: -1;
9364 else if (expecting_notif
)
9365 timeout
= 0; /* There should already be a char in the buffer. If
9368 timeout
= remote_timeout
;
9372 /* Process any number of notifications, and then return when
9376 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
9378 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
9380 /* This can loop forever if the remote side sends us
9381 characters continuously, but if it pauses, we'll get
9382 SERIAL_TIMEOUT from readchar because of timeout. Then
9383 we'll count that as a retry.
9385 Note that even when forever is set, we will only wait
9386 forever prior to the start of a packet. After that, we
9387 expect characters to arrive at a brisk pace. They should
9388 show up within remote_timeout intervals. */
9390 c
= readchar (timeout
);
9391 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
9393 if (c
== SERIAL_TIMEOUT
)
9395 if (expecting_notif
)
9396 return -1; /* Don't complain, it's normal to not get
9397 anything in this case. */
9399 if (forever
) /* Watchdog went off? Kill the target. */
9401 remote_unpush_target ();
9402 throw_error (TARGET_CLOSE_ERROR
,
9403 _("Watchdog timeout has expired. "
9404 "Target detached."));
9407 fputs_filtered ("Timed out.\n", gdb_stdlog
);
9411 /* We've found the start of a packet or notification.
9412 Now collect the data. */
9413 val
= read_frame (buf
, sizeof_buf
);
9418 remote_serial_write ("-", 1);
9421 if (tries
> MAX_TRIES
)
9423 /* We have tried hard enough, and just can't receive the
9424 packet/notification. Give up. */
9425 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
9427 /* Skip the ack char if we're in no-ack mode. */
9428 if (!rs
->noack_mode
)
9429 remote_serial_write ("+", 1);
9433 /* If we got an ordinary packet, return that to our caller. */
9439 = escape_buffer (*buf
,
9440 std::min (val
, REMOTE_DEBUG_MAX_CHAR
));
9442 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s",
9445 if (val
> REMOTE_DEBUG_MAX_CHAR
)
9446 fprintf_unfiltered (gdb_stdlog
, "[%d bytes omitted]",
9447 val
- REMOTE_DEBUG_MAX_CHAR
);
9449 fprintf_unfiltered (gdb_stdlog
, "\n");
9452 /* Skip the ack char if we're in no-ack mode. */
9453 if (!rs
->noack_mode
)
9454 remote_serial_write ("+", 1);
9455 if (is_notif
!= NULL
)
9460 /* If we got a notification, handle it, and go back to looking
9464 gdb_assert (c
== '%');
9468 std::string str
= escape_buffer (*buf
, val
);
9470 fprintf_unfiltered (gdb_stdlog
,
9471 " Notification received: %s\n",
9474 if (is_notif
!= NULL
)
9477 handle_notification (rs
->notif_state
, *buf
);
9479 /* Notifications require no acknowledgement. */
9481 if (expecting_notif
)
9488 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
9490 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
9494 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
9497 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
9501 /* Check whether EVENT is a fork event for the process specified
9502 by the pid passed in DATA, and if it is, kill the fork child. */
9505 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
9506 QUEUE_ITER (stop_reply_p
) *iter
,
9510 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
9511 int parent_pid
= *(int *) param
->input
;
9513 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
9515 struct remote_state
*rs
= get_remote_state ();
9516 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
9519 res
= remote_vkill (child_pid
, rs
);
9521 error (_("Can't kill fork child process %d"), child_pid
);
9527 /* Kill any new fork children of process PID that haven't been
9528 processed by follow_fork. */
9531 kill_new_fork_children (int pid
, struct remote_state
*rs
)
9533 struct thread_info
*thread
;
9534 struct notif_client
*notif
= ¬if_client_stop
;
9535 struct queue_iter_param param
;
9537 /* Kill the fork child threads of any threads in process PID
9538 that are stopped at a fork event. */
9539 ALL_NON_EXITED_THREADS (thread
)
9541 struct target_waitstatus
*ws
= &thread
->pending_follow
;
9543 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
9545 struct remote_state
*rs
= get_remote_state ();
9546 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
9549 res
= remote_vkill (child_pid
, rs
);
9551 error (_("Can't kill fork child process %d"), child_pid
);
9555 /* Check for any pending fork events (not reported or processed yet)
9556 in process PID and kill those fork child threads as well. */
9557 remote_notif_get_pending_events (notif
);
9559 param
.output
= NULL
;
9560 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
9561 kill_child_of_pending_fork
, ¶m
);
9565 /* Target hook to kill the current inferior. */
9568 remote_target::kill ()
9571 int pid
= ptid_get_pid (inferior_ptid
);
9572 struct remote_state
*rs
= get_remote_state ();
9574 if (packet_support (PACKET_vKill
) != PACKET_DISABLE
)
9576 /* If we're stopped while forking and we haven't followed yet,
9577 kill the child task. We need to do this before killing the
9578 parent task because if this is a vfork then the parent will
9580 kill_new_fork_children (pid
, rs
);
9582 res
= remote_vkill (pid
, rs
);
9585 target_mourn_inferior (inferior_ptid
);
9590 /* If we are in 'target remote' mode and we are killing the only
9591 inferior, then we will tell gdbserver to exit and unpush the
9593 if (res
== -1 && !remote_multi_process_p (rs
)
9594 && number_of_live_inferiors () == 1)
9598 /* We've killed the remote end, we get to mourn it. If we are
9599 not in extended mode, mourning the inferior also unpushes
9600 remote_ops from the target stack, which closes the remote
9602 target_mourn_inferior (inferior_ptid
);
9607 error (_("Can't kill process"));
9610 /* Send a kill request to the target using the 'vKill' packet. */
9613 remote_vkill (int pid
, struct remote_state
*rs
)
9615 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
9618 /* Tell the remote target to detach. */
9619 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
9621 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9623 switch (packet_ok (rs
->buf
,
9624 &remote_protocol_packets
[PACKET_vKill
]))
9630 case PACKET_UNKNOWN
:
9633 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
9637 /* Send a kill request to the target using the 'k' packet. */
9640 remote_kill_k (void)
9642 /* Catch errors so the user can quit from gdb even when we
9643 aren't on speaking terms with the remote system. */
9648 CATCH (ex
, RETURN_MASK_ERROR
)
9650 if (ex
.error
== TARGET_CLOSE_ERROR
)
9652 /* If we got an (EOF) error that caused the target
9653 to go away, then we're done, that's what we wanted.
9654 "k" is susceptible to cause a premature EOF, given
9655 that the remote server isn't actually required to
9656 reply to "k", and it can happen that it doesn't
9657 even get to reply ACK to the "k". */
9661 /* Otherwise, something went wrong. We didn't actually kill
9662 the target. Just propagate the exception, and let the
9663 user or higher layers decide what to do. */
9664 throw_exception (ex
);
9670 remote_target::mourn_inferior ()
9672 struct remote_state
*rs
= get_remote_state ();
9674 /* We're no longer interested in notification events of an inferior
9675 that exited or was killed/detached. */
9676 discard_pending_stop_replies (current_inferior ());
9678 /* In 'target remote' mode with one inferior, we close the connection. */
9679 if (!rs
->extended
&& number_of_live_inferiors () <= 1)
9681 unpush_target (this);
9683 /* remote_close takes care of doing most of the clean up. */
9684 generic_mourn_inferior ();
9688 /* In case we got here due to an error, but we're going to stay
9690 rs
->waiting_for_stop_reply
= 0;
9692 /* If the current general thread belonged to the process we just
9693 detached from or has exited, the remote side current general
9694 thread becomes undefined. Considering a case like this:
9696 - We just got here due to a detach.
9697 - The process that we're detaching from happens to immediately
9698 report a global breakpoint being hit in non-stop mode, in the
9699 same thread we had selected before.
9700 - GDB attaches to this process again.
9701 - This event happens to be the next event we handle.
9703 GDB would consider that the current general thread didn't need to
9704 be set on the stub side (with Hg), since for all it knew,
9705 GENERAL_THREAD hadn't changed.
9707 Notice that although in all-stop mode, the remote server always
9708 sets the current thread to the thread reporting the stop event,
9709 that doesn't happen in non-stop mode; in non-stop, the stub *must
9710 not* change the current thread when reporting a breakpoint hit,
9711 due to the decoupling of event reporting and event handling.
9713 To keep things simple, we always invalidate our notion of the
9715 record_currthread (rs
, minus_one_ptid
);
9717 /* Call common code to mark the inferior as not running. */
9718 generic_mourn_inferior ();
9720 if (!have_inferiors ())
9722 if (!remote_multi_process_p (rs
))
9724 /* Check whether the target is running now - some remote stubs
9725 automatically restart after kill. */
9727 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9729 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
9731 /* Assume that the target has been restarted. Set
9732 inferior_ptid so that bits of core GDB realizes
9733 there's something here, e.g., so that the user can
9734 say "kill" again. */
9735 inferior_ptid
= magic_null_ptid
;
9742 extended_remote_target::supports_disable_randomization ()
9744 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
9748 extended_remote_disable_randomization (int val
)
9750 struct remote_state
*rs
= get_remote_state ();
9753 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
9756 reply
= remote_get_noisy_reply ();
9758 error (_("Target does not support QDisableRandomization."));
9759 if (strcmp (reply
, "OK") != 0)
9760 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
9764 extended_remote_run (const std::string
&args
)
9766 struct remote_state
*rs
= get_remote_state ();
9768 const char *remote_exec_file
= get_remote_exec_file ();
9770 /* If the user has disabled vRun support, or we have detected that
9771 support is not available, do not try it. */
9772 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
9775 strcpy (rs
->buf
, "vRun;");
9776 len
= strlen (rs
->buf
);
9778 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
9779 error (_("Remote file name too long for run packet"));
9780 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
9781 strlen (remote_exec_file
));
9787 gdb_argv
argv (args
.c_str ());
9788 for (i
= 0; argv
[i
] != NULL
; i
++)
9790 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
9791 error (_("Argument list too long for run packet"));
9792 rs
->buf
[len
++] = ';';
9793 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
9798 rs
->buf
[len
++] = '\0';
9801 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9803 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
9806 /* We have a wait response. All is well. */
9808 case PACKET_UNKNOWN
:
9811 if (remote_exec_file
[0] == '\0')
9812 error (_("Running the default executable on the remote target failed; "
9813 "try \"set remote exec-file\"?"));
9815 error (_("Running \"%s\" on the remote target failed"),
9818 gdb_assert_not_reached (_("bad switch"));
9822 /* Helper function to send set/unset environment packets. ACTION is
9823 either "set" or "unset". PACKET is either "QEnvironmentHexEncoded"
9824 or "QEnvironmentUnsetVariable". VALUE is the variable to be
9828 send_environment_packet (struct remote_state
*rs
,
9833 /* Convert the environment variable to an hex string, which
9834 is the best format to be transmitted over the wire. */
9835 std::string encoded_value
= bin2hex ((const gdb_byte
*) value
,
9838 xsnprintf (rs
->buf
, get_remote_packet_size (),
9839 "%s:%s", packet
, encoded_value
.c_str ());
9842 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9843 if (strcmp (rs
->buf
, "OK") != 0)
9844 warning (_("Unable to %s environment variable '%s' on remote."),
9848 /* Helper function to handle the QEnvironment* packets. */
9851 extended_remote_environment_support (struct remote_state
*rs
)
9853 if (packet_support (PACKET_QEnvironmentReset
) != PACKET_DISABLE
)
9855 putpkt ("QEnvironmentReset");
9856 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9857 if (strcmp (rs
->buf
, "OK") != 0)
9858 warning (_("Unable to reset environment on remote."));
9861 gdb_environ
*e
= ¤t_inferior ()->environment
;
9863 if (packet_support (PACKET_QEnvironmentHexEncoded
) != PACKET_DISABLE
)
9864 for (const std::string
&el
: e
->user_set_env ())
9865 send_environment_packet (rs
, "set", "QEnvironmentHexEncoded",
9868 if (packet_support (PACKET_QEnvironmentUnset
) != PACKET_DISABLE
)
9869 for (const std::string
&el
: e
->user_unset_env ())
9870 send_environment_packet (rs
, "unset", "QEnvironmentUnset", el
.c_str ());
9873 /* Helper function to set the current working directory for the
9874 inferior in the remote target. */
9877 extended_remote_set_inferior_cwd (struct remote_state
*rs
)
9879 if (packet_support (PACKET_QSetWorkingDir
) != PACKET_DISABLE
)
9881 const char *inferior_cwd
= get_inferior_cwd ();
9883 if (inferior_cwd
!= NULL
)
9885 std::string hexpath
= bin2hex ((const gdb_byte
*) inferior_cwd
,
9886 strlen (inferior_cwd
));
9888 xsnprintf (rs
->buf
, get_remote_packet_size (),
9889 "QSetWorkingDir:%s", hexpath
.c_str ());
9893 /* An empty inferior_cwd means that the user wants us to
9894 reset the remote server's inferior's cwd. */
9895 xsnprintf (rs
->buf
, get_remote_packet_size (),
9900 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9901 if (packet_ok (rs
->buf
,
9902 &remote_protocol_packets
[PACKET_QSetWorkingDir
])
9905 Remote replied unexpectedly while setting the inferior's working\n\
9912 /* In the extended protocol we want to be able to do things like
9913 "run" and have them basically work as expected. So we need
9914 a special create_inferior function. We support changing the
9915 executable file and the command line arguments, but not the
9919 extended_remote_target::create_inferior (const char *exec_file
,
9920 const std::string
&args
,
9921 char **env
, int from_tty
)
9925 struct remote_state
*rs
= get_remote_state ();
9926 const char *remote_exec_file
= get_remote_exec_file ();
9928 /* If running asynchronously, register the target file descriptor
9929 with the event loop. */
9930 if (target_can_async_p ())
9933 /* Disable address space randomization if requested (and supported). */
9934 if (supports_disable_randomization ())
9935 extended_remote_disable_randomization (disable_randomization
);
9937 /* If startup-with-shell is on, we inform gdbserver to start the
9938 remote inferior using a shell. */
9939 if (packet_support (PACKET_QStartupWithShell
) != PACKET_DISABLE
)
9941 xsnprintf (rs
->buf
, get_remote_packet_size (),
9942 "QStartupWithShell:%d", startup_with_shell
? 1 : 0);
9944 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9945 if (strcmp (rs
->buf
, "OK") != 0)
9947 Remote replied unexpectedly while setting startup-with-shell: %s"),
9951 extended_remote_environment_support (rs
);
9953 extended_remote_set_inferior_cwd (rs
);
9955 /* Now restart the remote server. */
9956 run_worked
= extended_remote_run (args
) != -1;
9959 /* vRun was not supported. Fail if we need it to do what the
9961 if (remote_exec_file
[0])
9962 error (_("Remote target does not support \"set remote exec-file\""));
9964 error (_("Remote target does not support \"set args\" or run <ARGS>"));
9966 /* Fall back to "R". */
9967 extended_remote_restart ();
9970 if (!have_inferiors ())
9972 /* Clean up from the last time we ran, before we mark the target
9973 running again. This will mark breakpoints uninserted, and
9974 get_offsets may insert breakpoints. */
9975 init_thread_list ();
9976 init_wait_for_inferior ();
9979 /* vRun's success return is a stop reply. */
9980 stop_reply
= run_worked
? rs
->buf
: NULL
;
9981 add_current_inferior_and_thread (stop_reply
);
9983 /* Get updated offsets, if the stub uses qOffsets. */
9988 /* Given a location's target info BP_TGT and the packet buffer BUF, output
9989 the list of conditions (in agent expression bytecode format), if any, the
9990 target needs to evaluate. The output is placed into the packet buffer
9991 started from BUF and ended at BUF_END. */
9994 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
9995 struct bp_target_info
*bp_tgt
, char *buf
,
9998 if (bp_tgt
->conditions
.empty ())
10001 buf
+= strlen (buf
);
10002 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
10005 /* Send conditions to the target. */
10006 for (agent_expr
*aexpr
: bp_tgt
->conditions
)
10008 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
10009 buf
+= strlen (buf
);
10010 for (int i
= 0; i
< aexpr
->len
; ++i
)
10011 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
10018 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
10019 struct bp_target_info
*bp_tgt
, char *buf
)
10021 if (bp_tgt
->tcommands
.empty ())
10024 buf
+= strlen (buf
);
10026 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
10027 buf
+= strlen (buf
);
10029 /* Concatenate all the agent expressions that are commands into the
10031 for (agent_expr
*aexpr
: bp_tgt
->tcommands
)
10033 sprintf (buf
, "X%x,", aexpr
->len
);
10034 buf
+= strlen (buf
);
10035 for (int i
= 0; i
< aexpr
->len
; ++i
)
10036 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
10041 /* Insert a breakpoint. On targets that have software breakpoint
10042 support, we ask the remote target to do the work; on targets
10043 which don't, we insert a traditional memory breakpoint. */
10046 remote_target::insert_breakpoint (struct gdbarch
*gdbarch
,
10047 struct bp_target_info
*bp_tgt
)
10049 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
10050 If it succeeds, then set the support to PACKET_ENABLE. If it
10051 fails, and the user has explicitly requested the Z support then
10052 report an error, otherwise, mark it disabled and go on. */
10054 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
10056 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
10057 struct remote_state
*rs
;
10060 /* Make sure the remote is pointing at the right process, if
10062 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
10063 set_general_process ();
10065 rs
= get_remote_state ();
10067 endbuf
= rs
->buf
+ get_remote_packet_size ();
10072 addr
= (ULONGEST
) remote_address_masked (addr
);
10073 p
+= hexnumstr (p
, addr
);
10074 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->kind
);
10076 if (supports_evaluation_of_breakpoint_conditions ())
10077 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
10079 if (can_run_breakpoint_commands ())
10080 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
10083 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10085 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
10091 case PACKET_UNKNOWN
:
10096 /* If this breakpoint has target-side commands but this stub doesn't
10097 support Z0 packets, throw error. */
10098 if (!bp_tgt
->tcommands
.empty ())
10099 throw_error (NOT_SUPPORTED_ERROR
, _("\
10100 Target doesn't support breakpoints that have target side commands."));
10102 return memory_insert_breakpoint (this, gdbarch
, bp_tgt
);
10106 remote_target::remove_breakpoint (struct gdbarch
*gdbarch
,
10107 struct bp_target_info
*bp_tgt
,
10108 enum remove_bp_reason reason
)
10110 CORE_ADDR addr
= bp_tgt
->placed_address
;
10111 struct remote_state
*rs
= get_remote_state ();
10113 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
10116 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10118 /* Make sure the remote is pointing at the right process, if
10120 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
10121 set_general_process ();
10127 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
10128 p
+= hexnumstr (p
, addr
);
10129 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->kind
);
10132 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10134 return (rs
->buf
[0] == 'E');
10137 return memory_remove_breakpoint (this, gdbarch
, bp_tgt
, reason
);
10140 static enum Z_packet_type
10141 watchpoint_to_Z_packet (int type
)
10146 return Z_PACKET_WRITE_WP
;
10149 return Z_PACKET_READ_WP
;
10152 return Z_PACKET_ACCESS_WP
;
10155 internal_error (__FILE__
, __LINE__
,
10156 _("hw_bp_to_z: bad watchpoint type %d"), type
);
10161 remote_target::insert_watchpoint (CORE_ADDR addr
, int len
,
10162 enum target_hw_bp_type type
, struct expression
*cond
)
10164 struct remote_state
*rs
= get_remote_state ();
10165 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10167 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
10169 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
10172 /* Make sure the remote is pointing at the right process, if
10174 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
10175 set_general_process ();
10177 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
10178 p
= strchr (rs
->buf
, '\0');
10179 addr
= remote_address_masked (addr
);
10180 p
+= hexnumstr (p
, (ULONGEST
) addr
);
10181 xsnprintf (p
, endbuf
- p
, ",%x", len
);
10184 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10186 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
10190 case PACKET_UNKNOWN
:
10195 internal_error (__FILE__
, __LINE__
,
10196 _("remote_insert_watchpoint: reached end of function"));
10200 remote_target::watchpoint_addr_within_range (CORE_ADDR addr
,
10201 CORE_ADDR start
, int length
)
10203 CORE_ADDR diff
= remote_address_masked (addr
- start
);
10205 return diff
< length
;
10210 remote_target::remove_watchpoint (CORE_ADDR addr
, int len
,
10211 enum target_hw_bp_type type
, struct expression
*cond
)
10213 struct remote_state
*rs
= get_remote_state ();
10214 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10216 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
10218 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
10221 /* Make sure the remote is pointing at the right process, if
10223 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
10224 set_general_process ();
10226 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
10227 p
= strchr (rs
->buf
, '\0');
10228 addr
= remote_address_masked (addr
);
10229 p
+= hexnumstr (p
, (ULONGEST
) addr
);
10230 xsnprintf (p
, endbuf
- p
, ",%x", len
);
10232 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10234 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
10237 case PACKET_UNKNOWN
:
10242 internal_error (__FILE__
, __LINE__
,
10243 _("remote_remove_watchpoint: reached end of function"));
10247 int remote_hw_watchpoint_limit
= -1;
10248 int remote_hw_watchpoint_length_limit
= -1;
10249 int remote_hw_breakpoint_limit
= -1;
10252 remote_target::region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
10254 if (remote_hw_watchpoint_length_limit
== 0)
10256 else if (remote_hw_watchpoint_length_limit
< 0)
10258 else if (len
<= remote_hw_watchpoint_length_limit
)
10265 remote_target::can_use_hw_breakpoint (enum bptype type
, int cnt
, int ot
)
10267 if (type
== bp_hardware_breakpoint
)
10269 if (remote_hw_breakpoint_limit
== 0)
10271 else if (remote_hw_breakpoint_limit
< 0)
10273 else if (cnt
<= remote_hw_breakpoint_limit
)
10278 if (remote_hw_watchpoint_limit
== 0)
10280 else if (remote_hw_watchpoint_limit
< 0)
10284 else if (cnt
<= remote_hw_watchpoint_limit
)
10290 /* The to_stopped_by_sw_breakpoint method of target remote. */
10293 remote_target::stopped_by_sw_breakpoint ()
10295 struct thread_info
*thread
= inferior_thread ();
10297 return (thread
->priv
!= NULL
10298 && (get_remote_thread_info (thread
)->stop_reason
10299 == TARGET_STOPPED_BY_SW_BREAKPOINT
));
10302 /* The to_supports_stopped_by_sw_breakpoint method of target
10306 remote_target::supports_stopped_by_sw_breakpoint ()
10308 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
10311 /* The to_stopped_by_hw_breakpoint method of target remote. */
10314 remote_target::stopped_by_hw_breakpoint ()
10316 struct thread_info
*thread
= inferior_thread ();
10318 return (thread
->priv
!= NULL
10319 && (get_remote_thread_info (thread
)->stop_reason
10320 == TARGET_STOPPED_BY_HW_BREAKPOINT
));
10323 /* The to_supports_stopped_by_hw_breakpoint method of target
10327 remote_target::supports_stopped_by_hw_breakpoint ()
10329 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
10333 remote_target::stopped_by_watchpoint ()
10335 struct thread_info
*thread
= inferior_thread ();
10337 return (thread
->priv
!= NULL
10338 && (get_remote_thread_info (thread
)->stop_reason
10339 == TARGET_STOPPED_BY_WATCHPOINT
));
10343 remote_target::stopped_data_address (CORE_ADDR
*addr_p
)
10345 struct thread_info
*thread
= inferior_thread ();
10347 if (thread
->priv
!= NULL
10348 && (get_remote_thread_info (thread
)->stop_reason
10349 == TARGET_STOPPED_BY_WATCHPOINT
))
10351 *addr_p
= get_remote_thread_info (thread
)->watch_data_address
;
10360 remote_target::insert_hw_breakpoint (struct gdbarch
*gdbarch
,
10361 struct bp_target_info
*bp_tgt
)
10363 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
10364 struct remote_state
*rs
;
10368 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
10371 /* Make sure the remote is pointing at the right process, if
10373 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
10374 set_general_process ();
10376 rs
= get_remote_state ();
10378 endbuf
= rs
->buf
+ get_remote_packet_size ();
10384 addr
= remote_address_masked (addr
);
10385 p
+= hexnumstr (p
, (ULONGEST
) addr
);
10386 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->kind
);
10388 if (supports_evaluation_of_breakpoint_conditions ())
10389 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
10391 if (can_run_breakpoint_commands ())
10392 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
10395 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10397 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
10400 if (rs
->buf
[1] == '.')
10402 message
= strchr (rs
->buf
+ 2, '.');
10404 error (_("Remote failure reply: %s"), message
+ 1);
10407 case PACKET_UNKNOWN
:
10412 internal_error (__FILE__
, __LINE__
,
10413 _("remote_insert_hw_breakpoint: reached end of function"));
10418 remote_target::remove_hw_breakpoint (struct gdbarch
*gdbarch
,
10419 struct bp_target_info
*bp_tgt
)
10422 struct remote_state
*rs
= get_remote_state ();
10424 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10426 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
10429 /* Make sure the remote is pointing at the right process, if
10431 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
10432 set_general_process ();
10438 addr
= remote_address_masked (bp_tgt
->placed_address
);
10439 p
+= hexnumstr (p
, (ULONGEST
) addr
);
10440 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->kind
);
10443 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10445 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
10448 case PACKET_UNKNOWN
:
10453 internal_error (__FILE__
, __LINE__
,
10454 _("remote_remove_hw_breakpoint: reached end of function"));
10457 /* Verify memory using the "qCRC:" request. */
10460 remote_target::verify_memory (const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
10462 struct remote_state
*rs
= get_remote_state ();
10463 unsigned long host_crc
, target_crc
;
10466 /* It doesn't make sense to use qCRC if the remote target is
10467 connected but not running. */
10468 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
10470 enum packet_result result
;
10472 /* Make sure the remote is pointing at the right process. */
10473 set_general_process ();
10475 /* FIXME: assumes lma can fit into long. */
10476 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
10477 (long) lma
, (long) size
);
10480 /* Be clever; compute the host_crc before waiting for target
10482 host_crc
= xcrc32 (data
, size
, 0xffffffff);
10484 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10486 result
= packet_ok (rs
->buf
,
10487 &remote_protocol_packets
[PACKET_qCRC
]);
10488 if (result
== PACKET_ERROR
)
10490 else if (result
== PACKET_OK
)
10492 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
10493 target_crc
= target_crc
* 16 + fromhex (*tmp
);
10495 return (host_crc
== target_crc
);
10499 return simple_verify_memory (this, data
, lma
, size
);
10502 /* compare-sections command
10504 With no arguments, compares each loadable section in the exec bfd
10505 with the same memory range on the target, and reports mismatches.
10506 Useful for verifying the image on the target against the exec file. */
10509 compare_sections_command (const char *args
, int from_tty
)
10512 const char *sectname
;
10513 bfd_size_type size
;
10516 int mismatched
= 0;
10521 error (_("command cannot be used without an exec file"));
10523 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
10529 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10531 if (!(s
->flags
& SEC_LOAD
))
10532 continue; /* Skip non-loadable section. */
10534 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
10535 continue; /* Skip writeable sections */
10537 size
= bfd_get_section_size (s
);
10539 continue; /* Skip zero-length section. */
10541 sectname
= bfd_get_section_name (exec_bfd
, s
);
10542 if (args
&& strcmp (args
, sectname
) != 0)
10543 continue; /* Not the section selected by user. */
10545 matched
= 1; /* Do this section. */
10548 gdb::byte_vector
sectdata (size
);
10549 bfd_get_section_contents (exec_bfd
, s
, sectdata
.data (), 0, size
);
10551 res
= target_verify_memory (sectdata
.data (), lma
, size
);
10554 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
10555 paddress (target_gdbarch (), lma
),
10556 paddress (target_gdbarch (), lma
+ size
));
10558 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
10559 paddress (target_gdbarch (), lma
),
10560 paddress (target_gdbarch (), lma
+ size
));
10562 printf_filtered ("matched.\n");
10565 printf_filtered ("MIS-MATCHED!\n");
10569 if (mismatched
> 0)
10570 warning (_("One or more sections of the target image does not match\n\
10571 the loaded file\n"));
10572 if (args
&& !matched
)
10573 printf_filtered (_("No loaded section named '%s'.\n"), args
);
10576 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
10577 into remote target. The number of bytes written to the remote
10578 target is returned, or -1 for error. */
10580 static enum target_xfer_status
10581 remote_write_qxfer (const char *object_name
,
10582 const char *annex
, const gdb_byte
*writebuf
,
10583 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
10584 struct packet_config
*packet
)
10588 struct remote_state
*rs
= get_remote_state ();
10589 int max_size
= get_memory_write_packet_size ();
10591 if (packet_config_support (packet
) == PACKET_DISABLE
)
10592 return TARGET_XFER_E_IO
;
10594 /* Insert header. */
10595 i
= snprintf (rs
->buf
, max_size
,
10596 "qXfer:%s:write:%s:%s:",
10597 object_name
, annex
? annex
: "",
10598 phex_nz (offset
, sizeof offset
));
10599 max_size
-= (i
+ 1);
10601 /* Escape as much data as fits into rs->buf. */
10602 buf_len
= remote_escape_output
10603 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
10605 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
10606 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
10607 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10608 return TARGET_XFER_E_IO
;
10610 unpack_varlen_hex (rs
->buf
, &n
);
10613 return (*xfered_len
!= 0) ? TARGET_XFER_OK
: TARGET_XFER_EOF
;
10616 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
10617 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
10618 number of bytes read is returned, or 0 for EOF, or -1 for error.
10619 The number of bytes read may be less than LEN without indicating an
10620 EOF. PACKET is checked and updated to indicate whether the remote
10621 target supports this object. */
10623 static enum target_xfer_status
10624 remote_read_qxfer (const char *object_name
,
10626 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
10627 ULONGEST
*xfered_len
,
10628 struct packet_config
*packet
)
10630 struct remote_state
*rs
= get_remote_state ();
10631 LONGEST i
, n
, packet_len
;
10633 if (packet_config_support (packet
) == PACKET_DISABLE
)
10634 return TARGET_XFER_E_IO
;
10636 /* Check whether we've cached an end-of-object packet that matches
10638 if (rs
->finished_object
)
10640 if (strcmp (object_name
, rs
->finished_object
) == 0
10641 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
10642 && offset
== rs
->finished_offset
)
10643 return TARGET_XFER_EOF
;
10646 /* Otherwise, we're now reading something different. Discard
10648 xfree (rs
->finished_object
);
10649 xfree (rs
->finished_annex
);
10650 rs
->finished_object
= NULL
;
10651 rs
->finished_annex
= NULL
;
10654 /* Request only enough to fit in a single packet. The actual data
10655 may not, since we don't know how much of it will need to be escaped;
10656 the target is free to respond with slightly less data. We subtract
10657 five to account for the response type and the protocol frame. */
10658 n
= std::min
<LONGEST
> (get_remote_packet_size () - 5, len
);
10659 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
10660 object_name
, annex
? annex
: "",
10661 phex_nz (offset
, sizeof offset
),
10662 phex_nz (n
, sizeof n
));
10663 i
= putpkt (rs
->buf
);
10665 return TARGET_XFER_E_IO
;
10668 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10669 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10670 return TARGET_XFER_E_IO
;
10672 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
10673 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
10675 /* 'm' means there is (or at least might be) more data after this
10676 batch. That does not make sense unless there's at least one byte
10677 of data in this reply. */
10678 if (rs
->buf
[0] == 'm' && packet_len
== 1)
10679 error (_("Remote qXfer reply contained no data."));
10681 /* Got some data. */
10682 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
10683 packet_len
- 1, readbuf
, n
);
10685 /* 'l' is an EOF marker, possibly including a final block of data,
10686 or possibly empty. If we have the final block of a non-empty
10687 object, record this fact to bypass a subsequent partial read. */
10688 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
10690 rs
->finished_object
= xstrdup (object_name
);
10691 rs
->finished_annex
= xstrdup (annex
? annex
: "");
10692 rs
->finished_offset
= offset
+ i
;
10696 return TARGET_XFER_EOF
;
10700 return TARGET_XFER_OK
;
10704 enum target_xfer_status
10705 remote_target::xfer_partial (enum target_object object
,
10706 const char *annex
, gdb_byte
*readbuf
,
10707 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
10708 ULONGEST
*xfered_len
)
10710 struct remote_state
*rs
;
10714 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
10716 set_remote_traceframe ();
10717 set_general_thread (inferior_ptid
);
10719 rs
= get_remote_state ();
10721 /* Handle memory using the standard memory routines. */
10722 if (object
== TARGET_OBJECT_MEMORY
)
10724 /* If the remote target is connected but not running, we should
10725 pass this request down to a lower stratum (e.g. the executable
10727 if (!target_has_execution
)
10728 return TARGET_XFER_EOF
;
10730 if (writebuf
!= NULL
)
10731 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
10734 return remote_read_bytes (this, offset
, readbuf
, len
, unit_size
,
10738 /* Handle SPU memory using qxfer packets. */
10739 if (object
== TARGET_OBJECT_SPU
)
10742 return remote_read_qxfer ("spu", annex
, readbuf
, offset
, len
,
10743 xfered_len
, &remote_protocol_packets
10744 [PACKET_qXfer_spu_read
]);
10746 return remote_write_qxfer ("spu", annex
, writebuf
, offset
, len
,
10747 xfered_len
, &remote_protocol_packets
10748 [PACKET_qXfer_spu_write
]);
10751 /* Handle extra signal info using qxfer packets. */
10752 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
10755 return remote_read_qxfer ("siginfo", annex
, readbuf
, offset
, len
,
10756 xfered_len
, &remote_protocol_packets
10757 [PACKET_qXfer_siginfo_read
]);
10759 return remote_write_qxfer ("siginfo", annex
,
10760 writebuf
, offset
, len
, xfered_len
,
10761 &remote_protocol_packets
10762 [PACKET_qXfer_siginfo_write
]);
10765 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
10768 return remote_read_qxfer ("statictrace", annex
,
10769 readbuf
, offset
, len
, xfered_len
,
10770 &remote_protocol_packets
10771 [PACKET_qXfer_statictrace_read
]);
10773 return TARGET_XFER_E_IO
;
10776 /* Only handle flash writes. */
10777 if (writebuf
!= NULL
)
10781 case TARGET_OBJECT_FLASH
:
10782 return remote_flash_write (this, offset
, len
, xfered_len
,
10786 return TARGET_XFER_E_IO
;
10790 /* Map pre-existing objects onto letters. DO NOT do this for new
10791 objects!!! Instead specify new query packets. */
10794 case TARGET_OBJECT_AVR
:
10798 case TARGET_OBJECT_AUXV
:
10799 gdb_assert (annex
== NULL
);
10800 return remote_read_qxfer ("auxv", annex
, readbuf
, offset
, len
,
10802 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
10804 case TARGET_OBJECT_AVAILABLE_FEATURES
:
10805 return remote_read_qxfer
10806 ("features", annex
, readbuf
, offset
, len
, xfered_len
,
10807 &remote_protocol_packets
[PACKET_qXfer_features
]);
10809 case TARGET_OBJECT_LIBRARIES
:
10810 return remote_read_qxfer
10811 ("libraries", annex
, readbuf
, offset
, len
, xfered_len
,
10812 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
10814 case TARGET_OBJECT_LIBRARIES_SVR4
:
10815 return remote_read_qxfer
10816 ("libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
10817 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
10819 case TARGET_OBJECT_MEMORY_MAP
:
10820 gdb_assert (annex
== NULL
);
10821 return remote_read_qxfer ("memory-map", annex
, readbuf
, offset
, len
,
10823 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
10825 case TARGET_OBJECT_OSDATA
:
10826 /* Should only get here if we're connected. */
10827 gdb_assert (rs
->remote_desc
);
10828 return remote_read_qxfer
10829 ("osdata", annex
, readbuf
, offset
, len
, xfered_len
,
10830 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
10832 case TARGET_OBJECT_THREADS
:
10833 gdb_assert (annex
== NULL
);
10834 return remote_read_qxfer ("threads", annex
, readbuf
, offset
, len
,
10836 &remote_protocol_packets
[PACKET_qXfer_threads
]);
10838 case TARGET_OBJECT_TRACEFRAME_INFO
:
10839 gdb_assert (annex
== NULL
);
10840 return remote_read_qxfer
10841 ("traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
10842 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
10844 case TARGET_OBJECT_FDPIC
:
10845 return remote_read_qxfer ("fdpic", annex
, readbuf
, offset
, len
,
10847 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
10849 case TARGET_OBJECT_OPENVMS_UIB
:
10850 return remote_read_qxfer ("uib", annex
, readbuf
, offset
, len
,
10852 &remote_protocol_packets
[PACKET_qXfer_uib
]);
10854 case TARGET_OBJECT_BTRACE
:
10855 return remote_read_qxfer ("btrace", annex
, readbuf
, offset
, len
,
10857 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
10859 case TARGET_OBJECT_BTRACE_CONF
:
10860 return remote_read_qxfer ("btrace-conf", annex
, readbuf
, offset
,
10862 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
10864 case TARGET_OBJECT_EXEC_FILE
:
10865 return remote_read_qxfer ("exec-file", annex
, readbuf
, offset
,
10867 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
10870 return TARGET_XFER_E_IO
;
10873 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
10874 large enough let the caller deal with it. */
10875 if (len
< get_remote_packet_size ())
10876 return TARGET_XFER_E_IO
;
10877 len
= get_remote_packet_size ();
10879 /* Except for querying the minimum buffer size, target must be open. */
10880 if (!rs
->remote_desc
)
10881 error (_("remote query is only available after target open"));
10883 gdb_assert (annex
!= NULL
);
10884 gdb_assert (readbuf
!= NULL
);
10888 *p2
++ = query_type
;
10890 /* We used one buffer char for the remote protocol q command and
10891 another for the query type. As the remote protocol encapsulation
10892 uses 4 chars plus one extra in case we are debugging
10893 (remote_debug), we have PBUFZIZ - 7 left to pack the query
10896 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
10898 /* Bad caller may have sent forbidden characters. */
10899 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
10904 gdb_assert (annex
[i
] == '\0');
10906 i
= putpkt (rs
->buf
);
10908 return TARGET_XFER_E_IO
;
10910 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10911 strcpy ((char *) readbuf
, rs
->buf
);
10913 *xfered_len
= strlen ((char *) readbuf
);
10914 return (*xfered_len
!= 0) ? TARGET_XFER_OK
: TARGET_XFER_EOF
;
10917 /* Implementation of to_get_memory_xfer_limit. */
10920 remote_target::get_memory_xfer_limit ()
10922 return get_memory_write_packet_size ();
10926 remote_target::search_memory (CORE_ADDR start_addr
, ULONGEST search_space_len
,
10927 const gdb_byte
*pattern
, ULONGEST pattern_len
,
10928 CORE_ADDR
*found_addrp
)
10930 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
10931 struct remote_state
*rs
= get_remote_state ();
10932 int max_size
= get_memory_write_packet_size ();
10933 struct packet_config
*packet
=
10934 &remote_protocol_packets
[PACKET_qSearch_memory
];
10935 /* Number of packet bytes used to encode the pattern;
10936 this could be more than PATTERN_LEN due to escape characters. */
10937 int escaped_pattern_len
;
10938 /* Amount of pattern that was encodable in the packet. */
10939 int used_pattern_len
;
10942 ULONGEST found_addr
;
10944 /* Don't go to the target if we don't have to. This is done before
10945 checking packet_config_support to avoid the possibility that a
10946 success for this edge case means the facility works in
10948 if (pattern_len
> search_space_len
)
10950 if (pattern_len
== 0)
10952 *found_addrp
= start_addr
;
10956 /* If we already know the packet isn't supported, fall back to the simple
10957 way of searching memory. */
10959 if (packet_config_support (packet
) == PACKET_DISABLE
)
10961 /* Target doesn't provided special support, fall back and use the
10962 standard support (copy memory and do the search here). */
10963 return simple_search_memory (this, start_addr
, search_space_len
,
10964 pattern
, pattern_len
, found_addrp
);
10967 /* Make sure the remote is pointing at the right process. */
10968 set_general_process ();
10970 /* Insert header. */
10971 i
= snprintf (rs
->buf
, max_size
,
10972 "qSearch:memory:%s;%s;",
10973 phex_nz (start_addr
, addr_size
),
10974 phex_nz (search_space_len
, sizeof (search_space_len
)));
10975 max_size
-= (i
+ 1);
10977 /* Escape as much data as fits into rs->buf. */
10978 escaped_pattern_len
=
10979 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
10980 &used_pattern_len
, max_size
);
10982 /* Bail if the pattern is too large. */
10983 if (used_pattern_len
!= pattern_len
)
10984 error (_("Pattern is too large to transmit to remote target."));
10986 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
10987 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
10988 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10990 /* The request may not have worked because the command is not
10991 supported. If so, fall back to the simple way. */
10992 if (packet_config_support (packet
) == PACKET_DISABLE
)
10994 return simple_search_memory (this, start_addr
, search_space_len
,
10995 pattern
, pattern_len
, found_addrp
);
11000 if (rs
->buf
[0] == '0')
11002 else if (rs
->buf
[0] == '1')
11005 if (rs
->buf
[1] != ',')
11006 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
11007 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
11008 *found_addrp
= found_addr
;
11011 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
11017 remote_target::rcmd (const char *command
, struct ui_file
*outbuf
)
11019 struct remote_state
*rs
= get_remote_state ();
11022 if (!rs
->remote_desc
)
11023 error (_("remote rcmd is only available after target open"));
11025 /* Send a NULL command across as an empty command. */
11026 if (command
== NULL
)
11029 /* The query prefix. */
11030 strcpy (rs
->buf
, "qRcmd,");
11031 p
= strchr (rs
->buf
, '\0');
11033 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
11034 > get_remote_packet_size ())
11035 error (_("\"monitor\" command ``%s'' is too long."), command
);
11037 /* Encode the actual command. */
11038 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
11040 if (putpkt (rs
->buf
) < 0)
11041 error (_("Communication problem with target."));
11043 /* get/display the response */
11048 /* XXX - see also remote_get_noisy_reply(). */
11049 QUIT
; /* Allow user to bail out with ^C. */
11051 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
11053 /* Timeout. Continue to (try to) read responses.
11054 This is better than stopping with an error, assuming the stub
11055 is still executing the (long) monitor command.
11056 If needed, the user can interrupt gdb using C-c, obtaining
11057 an effect similar to stop on timeout. */
11061 if (buf
[0] == '\0')
11062 error (_("Target does not support this command."));
11063 if (buf
[0] == 'O' && buf
[1] != 'K')
11065 remote_console_output (buf
+ 1); /* 'O' message from stub. */
11068 if (strcmp (buf
, "OK") == 0)
11070 if (strlen (buf
) == 3 && buf
[0] == 'E'
11071 && isdigit (buf
[1]) && isdigit (buf
[2]))
11073 error (_("Protocol error with Rcmd"));
11075 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
11077 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
11079 fputc_unfiltered (c
, outbuf
);
11085 std::vector
<mem_region
>
11086 remote_target::memory_map ()
11088 std::vector
<mem_region
> result
;
11089 gdb::optional
<gdb::char_vector
> text
11090 = target_read_stralloc (target_stack
, TARGET_OBJECT_MEMORY_MAP
, NULL
);
11093 result
= parse_memory_map (text
->data ());
11099 packet_command (const char *args
, int from_tty
)
11101 struct remote_state
*rs
= get_remote_state ();
11103 if (!rs
->remote_desc
)
11104 error (_("command can only be used with remote target"));
11107 error (_("remote-packet command requires packet text as argument"));
11109 puts_filtered ("sending: ");
11110 print_packet (args
);
11111 puts_filtered ("\n");
11114 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11115 puts_filtered ("received: ");
11116 print_packet (rs
->buf
);
11117 puts_filtered ("\n");
11121 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
11123 static void display_thread_info (struct gdb_ext_thread_info
*info
);
11125 static void threadset_test_cmd (char *cmd
, int tty
);
11127 static void threadalive_test (char *cmd
, int tty
);
11129 static void threadlist_test_cmd (char *cmd
, int tty
);
11131 int get_and_display_threadinfo (threadref
*ref
);
11133 static void threadinfo_test_cmd (char *cmd
, int tty
);
11135 static int thread_display_step (threadref
*ref
, void *context
);
11137 static void threadlist_update_test_cmd (char *cmd
, int tty
);
11139 static void init_remote_threadtests (void);
11141 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
11144 threadset_test_cmd (const char *cmd
, int tty
)
11146 int sample_thread
= SAMPLE_THREAD
;
11148 printf_filtered (_("Remote threadset test\n"));
11149 set_general_thread (sample_thread
);
11154 threadalive_test (const char *cmd
, int tty
)
11156 int sample_thread
= SAMPLE_THREAD
;
11157 int pid
= ptid_get_pid (inferior_ptid
);
11158 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
11160 if (remote_thread_alive (ptid
))
11161 printf_filtered ("PASS: Thread alive test\n");
11163 printf_filtered ("FAIL: Thread alive test\n");
11166 void output_threadid (char *title
, threadref
*ref
);
11169 output_threadid (char *title
, threadref
*ref
)
11173 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
11175 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
11179 threadlist_test_cmd (const char *cmd
, int tty
)
11182 threadref nextthread
;
11183 int done
, result_count
;
11184 threadref threadlist
[3];
11186 printf_filtered ("Remote Threadlist test\n");
11187 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
11188 &result_count
, &threadlist
[0]))
11189 printf_filtered ("FAIL: threadlist test\n");
11192 threadref
*scan
= threadlist
;
11193 threadref
*limit
= scan
+ result_count
;
11195 while (scan
< limit
)
11196 output_threadid (" thread ", scan
++);
11201 display_thread_info (struct gdb_ext_thread_info
*info
)
11203 output_threadid ("Threadid: ", &info
->threadid
);
11204 printf_filtered ("Name: %s\n ", info
->shortname
);
11205 printf_filtered ("State: %s\n", info
->display
);
11206 printf_filtered ("other: %s\n\n", info
->more_display
);
11210 get_and_display_threadinfo (threadref
*ref
)
11214 struct gdb_ext_thread_info threadinfo
;
11216 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
11217 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
11218 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
11219 display_thread_info (&threadinfo
);
11224 threadinfo_test_cmd (const char *cmd
, int tty
)
11226 int athread
= SAMPLE_THREAD
;
11230 int_to_threadref (&thread
, athread
);
11231 printf_filtered ("Remote Threadinfo test\n");
11232 if (!get_and_display_threadinfo (&thread
))
11233 printf_filtered ("FAIL cannot get thread info\n");
11237 thread_display_step (threadref
*ref
, void *context
)
11239 /* output_threadid(" threadstep ",ref); *//* simple test */
11240 return get_and_display_threadinfo (ref
);
11244 threadlist_update_test_cmd (const char *cmd
, int tty
)
11246 printf_filtered ("Remote Threadlist update test\n");
11247 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
11251 init_remote_threadtests (void)
11253 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
11254 _("Fetch and print the remote list of "
11255 "thread identifiers, one pkt only"));
11256 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
11257 _("Fetch and display info about one thread"));
11258 add_com ("tset", class_obscure
, threadset_test_cmd
,
11259 _("Test setting to a different thread"));
11260 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
11261 _("Iterate through updating all remote thread info"));
11262 add_com ("talive", class_obscure
, threadalive_test
,
11263 _(" Remote thread alive test "));
11268 /* Convert a thread ID to a string. Returns the string in a static
11272 remote_target::pid_to_str (ptid_t ptid
)
11274 static char buf
[64];
11275 struct remote_state
*rs
= get_remote_state ();
11277 if (ptid_equal (ptid
, null_ptid
))
11278 return normal_pid_to_str (ptid
);
11279 else if (ptid_is_pid (ptid
))
11281 /* Printing an inferior target id. */
11283 /* When multi-process extensions are off, there's no way in the
11284 remote protocol to know the remote process id, if there's any
11285 at all. There's one exception --- when we're connected with
11286 target extended-remote, and we manually attached to a process
11287 with "attach PID". We don't record anywhere a flag that
11288 allows us to distinguish that case from the case of
11289 connecting with extended-remote and the stub already being
11290 attached to a process, and reporting yes to qAttached, hence
11291 no smart special casing here. */
11292 if (!remote_multi_process_p (rs
))
11294 xsnprintf (buf
, sizeof buf
, "Remote target");
11298 return normal_pid_to_str (ptid
);
11302 if (ptid_equal (magic_null_ptid
, ptid
))
11303 xsnprintf (buf
, sizeof buf
, "Thread <main>");
11304 else if (remote_multi_process_p (rs
))
11305 if (ptid_get_lwp (ptid
) == 0)
11306 return normal_pid_to_str (ptid
);
11308 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
11309 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
11311 xsnprintf (buf
, sizeof buf
, "Thread %ld",
11312 ptid_get_lwp (ptid
));
11317 /* Get the address of the thread local variable in OBJFILE which is
11318 stored at OFFSET within the thread local storage for thread PTID. */
11321 remote_target::get_thread_local_address (ptid_t ptid
, CORE_ADDR lm
,
11324 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
11326 struct remote_state
*rs
= get_remote_state ();
11328 char *endp
= rs
->buf
+ get_remote_packet_size ();
11329 enum packet_result result
;
11331 strcpy (p
, "qGetTLSAddr:");
11333 p
= write_ptid (p
, endp
, ptid
);
11335 p
+= hexnumstr (p
, offset
);
11337 p
+= hexnumstr (p
, lm
);
11341 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11342 result
= packet_ok (rs
->buf
,
11343 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
11344 if (result
== PACKET_OK
)
11348 unpack_varlen_hex (rs
->buf
, &result
);
11351 else if (result
== PACKET_UNKNOWN
)
11352 throw_error (TLS_GENERIC_ERROR
,
11353 _("Remote target doesn't support qGetTLSAddr packet"));
11355 throw_error (TLS_GENERIC_ERROR
,
11356 _("Remote target failed to process qGetTLSAddr request"));
11359 throw_error (TLS_GENERIC_ERROR
,
11360 _("TLS not supported or disabled on this target"));
11365 /* Provide thread local base, i.e. Thread Information Block address.
11366 Returns 1 if ptid is found and thread_local_base is non zero. */
11369 remote_target::get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
11371 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
11373 struct remote_state
*rs
= get_remote_state ();
11375 char *endp
= rs
->buf
+ get_remote_packet_size ();
11376 enum packet_result result
;
11378 strcpy (p
, "qGetTIBAddr:");
11380 p
= write_ptid (p
, endp
, ptid
);
11384 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11385 result
= packet_ok (rs
->buf
,
11386 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
11387 if (result
== PACKET_OK
)
11391 unpack_varlen_hex (rs
->buf
, &result
);
11393 *addr
= (CORE_ADDR
) result
;
11396 else if (result
== PACKET_UNKNOWN
)
11397 error (_("Remote target doesn't support qGetTIBAddr packet"));
11399 error (_("Remote target failed to process qGetTIBAddr request"));
11402 error (_("qGetTIBAddr not supported or disabled on this target"));
11407 /* Support for inferring a target description based on the current
11408 architecture and the size of a 'g' packet. While the 'g' packet
11409 can have any size (since optional registers can be left off the
11410 end), some sizes are easily recognizable given knowledge of the
11411 approximate architecture. */
11413 struct remote_g_packet_guess
11416 const struct target_desc
*tdesc
;
11418 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
11419 DEF_VEC_O(remote_g_packet_guess_s
);
11421 struct remote_g_packet_data
11423 VEC(remote_g_packet_guess_s
) *guesses
;
11426 static struct gdbarch_data
*remote_g_packet_data_handle
;
11429 remote_g_packet_data_init (struct obstack
*obstack
)
11431 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
11435 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
11436 const struct target_desc
*tdesc
)
11438 struct remote_g_packet_data
*data
11439 = ((struct remote_g_packet_data
*)
11440 gdbarch_data (gdbarch
, remote_g_packet_data_handle
));
11441 struct remote_g_packet_guess new_guess
, *guess
;
11444 gdb_assert (tdesc
!= NULL
);
11447 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
11449 if (guess
->bytes
== bytes
)
11450 internal_error (__FILE__
, __LINE__
,
11451 _("Duplicate g packet description added for size %d"),
11454 new_guess
.bytes
= bytes
;
11455 new_guess
.tdesc
= tdesc
;
11456 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
11459 /* Return 1 if remote_read_description would do anything on this target
11460 and architecture, 0 otherwise. */
11463 remote_read_description_p (struct target_ops
*target
)
11465 struct remote_g_packet_data
*data
11466 = ((struct remote_g_packet_data
*)
11467 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
11469 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
11475 const struct target_desc
*
11476 remote_target::read_description ()
11478 struct remote_g_packet_data
*data
11479 = ((struct remote_g_packet_data
*)
11480 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
11482 /* Do not try this during initial connection, when we do not know
11483 whether there is a running but stopped thread. */
11484 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
11485 return beneath
->read_description ();
11487 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
11489 struct remote_g_packet_guess
*guess
;
11491 int bytes
= send_g_packet ();
11494 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
11496 if (guess
->bytes
== bytes
)
11497 return guess
->tdesc
;
11499 /* We discard the g packet. A minor optimization would be to
11500 hold on to it, and fill the register cache once we have selected
11501 an architecture, but it's too tricky to do safely. */
11504 return beneath
->read_description ();
11507 /* Remote file transfer support. This is host-initiated I/O, not
11508 target-initiated; for target-initiated, see remote-fileio.c. */
11510 /* If *LEFT is at least the length of STRING, copy STRING to
11511 *BUFFER, update *BUFFER to point to the new end of the buffer, and
11512 decrease *LEFT. Otherwise raise an error. */
11515 remote_buffer_add_string (char **buffer
, int *left
, const char *string
)
11517 int len
= strlen (string
);
11520 error (_("Packet too long for target."));
11522 memcpy (*buffer
, string
, len
);
11526 /* NUL-terminate the buffer as a convenience, if there is
11532 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
11533 *BUFFER, update *BUFFER to point to the new end of the buffer, and
11534 decrease *LEFT. Otherwise raise an error. */
11537 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
11540 if (2 * len
> *left
)
11541 error (_("Packet too long for target."));
11543 bin2hex (bytes
, *buffer
, len
);
11544 *buffer
+= 2 * len
;
11547 /* NUL-terminate the buffer as a convenience, if there is
11553 /* If *LEFT is large enough, convert VALUE to hex and add it to
11554 *BUFFER, update *BUFFER to point to the new end of the buffer, and
11555 decrease *LEFT. Otherwise raise an error. */
11558 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
11560 int len
= hexnumlen (value
);
11563 error (_("Packet too long for target."));
11565 hexnumstr (*buffer
, value
);
11569 /* NUL-terminate the buffer as a convenience, if there is
11575 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
11576 value, *REMOTE_ERRNO to the remote error number or zero if none
11577 was included, and *ATTACHMENT to point to the start of the annex
11578 if any. The length of the packet isn't needed here; there may
11579 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
11581 Return 0 if the packet could be parsed, -1 if it could not. If
11582 -1 is returned, the other variables may not be initialized. */
11585 remote_hostio_parse_result (char *buffer
, int *retcode
,
11586 int *remote_errno
, char **attachment
)
11591 *attachment
= NULL
;
11593 if (buffer
[0] != 'F')
11597 *retcode
= strtol (&buffer
[1], &p
, 16);
11598 if (errno
!= 0 || p
== &buffer
[1])
11601 /* Check for ",errno". */
11605 *remote_errno
= strtol (p
+ 1, &p2
, 16);
11606 if (errno
!= 0 || p
+ 1 == p2
)
11611 /* Check for ";attachment". If there is no attachment, the
11612 packet should end here. */
11615 *attachment
= p
+ 1;
11618 else if (*p
== '\0')
11624 /* Send a prepared I/O packet to the target and read its response.
11625 The prepared packet is in the global RS->BUF before this function
11626 is called, and the answer is there when we return.
11628 COMMAND_BYTES is the length of the request to send, which may include
11629 binary data. WHICH_PACKET is the packet configuration to check
11630 before attempting a packet. If an error occurs, *REMOTE_ERRNO
11631 is set to the error number and -1 is returned. Otherwise the value
11632 returned by the function is returned.
11634 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
11635 attachment is expected; an error will be reported if there's a
11636 mismatch. If one is found, *ATTACHMENT will be set to point into
11637 the packet buffer and *ATTACHMENT_LEN will be set to the
11638 attachment's length. */
11641 remote_hostio_send_command (int command_bytes
, int which_packet
,
11642 int *remote_errno
, char **attachment
,
11643 int *attachment_len
)
11645 struct remote_state
*rs
= get_remote_state ();
11646 int ret
, bytes_read
;
11647 char *attachment_tmp
;
11649 if (packet_support (which_packet
) == PACKET_DISABLE
)
11651 *remote_errno
= FILEIO_ENOSYS
;
11655 putpkt_binary (rs
->buf
, command_bytes
);
11656 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
11658 /* If it timed out, something is wrong. Don't try to parse the
11660 if (bytes_read
< 0)
11662 *remote_errno
= FILEIO_EINVAL
;
11666 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
11669 *remote_errno
= FILEIO_EINVAL
;
11671 case PACKET_UNKNOWN
:
11672 *remote_errno
= FILEIO_ENOSYS
;
11678 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
11681 *remote_errno
= FILEIO_EINVAL
;
11685 /* Make sure we saw an attachment if and only if we expected one. */
11686 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
11687 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
11689 *remote_errno
= FILEIO_EINVAL
;
11693 /* If an attachment was found, it must point into the packet buffer;
11694 work out how many bytes there were. */
11695 if (attachment_tmp
!= NULL
)
11697 *attachment
= attachment_tmp
;
11698 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
11704 /* See declaration.h. */
11707 readahead_cache::invalidate ()
11712 /* See declaration.h. */
11715 readahead_cache::invalidate_fd (int fd
)
11717 if (this->fd
== fd
)
11721 /* Set the filesystem remote_hostio functions that take FILENAME
11722 arguments will use. Return 0 on success, or -1 if an error
11723 occurs (and set *REMOTE_ERRNO). */
11726 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
11728 struct remote_state
*rs
= get_remote_state ();
11729 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
11731 int left
= get_remote_packet_size () - 1;
11735 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11738 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
11741 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
11743 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
11744 remote_buffer_add_string (&p
, &left
, arg
);
11746 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
11747 remote_errno
, NULL
, NULL
);
11749 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11753 rs
->fs_pid
= required_pid
;
11758 /* Implementation of to_fileio_open. */
11761 remote_hostio_open (struct target_ops
*self
,
11762 struct inferior
*inf
, const char *filename
,
11763 int flags
, int mode
, int warn_if_slow
,
11766 struct remote_state
*rs
= get_remote_state ();
11768 int left
= get_remote_packet_size () - 1;
11772 static int warning_issued
= 0;
11774 printf_unfiltered (_("Reading %s from remote target...\n"),
11777 if (!warning_issued
)
11779 warning (_("File transfers from remote targets can be slow."
11780 " Use \"set sysroot\" to access files locally"
11782 warning_issued
= 1;
11786 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11789 remote_buffer_add_string (&p
, &left
, "vFile:open:");
11791 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11792 strlen (filename
));
11793 remote_buffer_add_string (&p
, &left
, ",");
11795 remote_buffer_add_int (&p
, &left
, flags
);
11796 remote_buffer_add_string (&p
, &left
, ",");
11798 remote_buffer_add_int (&p
, &left
, mode
);
11800 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
11801 remote_errno
, NULL
, NULL
);
11805 remote_target::fileio_open (struct inferior
*inf
, const char *filename
,
11806 int flags
, int mode
, int warn_if_slow
,
11809 return remote_hostio_open (this, inf
, filename
, flags
, mode
, warn_if_slow
,
11813 /* Implementation of to_fileio_pwrite. */
11816 remote_hostio_pwrite (struct target_ops
*self
,
11817 int fd
, const gdb_byte
*write_buf
, int len
,
11818 ULONGEST offset
, int *remote_errno
)
11820 struct remote_state
*rs
= get_remote_state ();
11822 int left
= get_remote_packet_size ();
11825 rs
->readahead_cache
.invalidate_fd (fd
);
11827 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
11829 remote_buffer_add_int (&p
, &left
, fd
);
11830 remote_buffer_add_string (&p
, &left
, ",");
11832 remote_buffer_add_int (&p
, &left
, offset
);
11833 remote_buffer_add_string (&p
, &left
, ",");
11835 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
11836 get_remote_packet_size () - (p
- rs
->buf
));
11838 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
11839 remote_errno
, NULL
, NULL
);
11843 remote_target::fileio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
11844 ULONGEST offset
, int *remote_errno
)
11846 return remote_hostio_pwrite (this, fd
, write_buf
, len
, offset
, remote_errno
);
11849 /* Helper for the implementation of to_fileio_pread. Read the file
11850 from the remote side with vFile:pread. */
11853 remote_hostio_pread_vFile (struct target_ops
*self
,
11854 int fd
, gdb_byte
*read_buf
, int len
,
11855 ULONGEST offset
, int *remote_errno
)
11857 struct remote_state
*rs
= get_remote_state ();
11860 int left
= get_remote_packet_size ();
11861 int ret
, attachment_len
;
11864 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
11866 remote_buffer_add_int (&p
, &left
, fd
);
11867 remote_buffer_add_string (&p
, &left
, ",");
11869 remote_buffer_add_int (&p
, &left
, len
);
11870 remote_buffer_add_string (&p
, &left
, ",");
11872 remote_buffer_add_int (&p
, &left
, offset
);
11874 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
11875 remote_errno
, &attachment
,
11881 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11883 if (read_len
!= ret
)
11884 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
11889 /* See declaration.h. */
11892 readahead_cache::pread (int fd
, gdb_byte
*read_buf
, size_t len
,
11896 && this->offset
<= offset
11897 && offset
< this->offset
+ this->bufsize
)
11899 ULONGEST max
= this->offset
+ this->bufsize
;
11901 if (offset
+ len
> max
)
11902 len
= max
- offset
;
11904 memcpy (read_buf
, this->buf
+ offset
- this->offset
, len
);
11911 /* Implementation of to_fileio_pread. */
11914 remote_hostio_pread (struct target_ops
*self
,
11915 int fd
, gdb_byte
*read_buf
, int len
,
11916 ULONGEST offset
, int *remote_errno
)
11919 struct remote_state
*rs
= get_remote_state ();
11920 readahead_cache
*cache
= &rs
->readahead_cache
;
11922 ret
= cache
->pread (fd
, read_buf
, len
, offset
);
11925 cache
->hit_count
++;
11928 fprintf_unfiltered (gdb_stdlog
, "readahead cache hit %s\n",
11929 pulongest (cache
->hit_count
));
11933 cache
->miss_count
++;
11935 fprintf_unfiltered (gdb_stdlog
, "readahead cache miss %s\n",
11936 pulongest (cache
->miss_count
));
11939 cache
->offset
= offset
;
11940 cache
->bufsize
= get_remote_packet_size ();
11941 cache
->buf
= (gdb_byte
*) xrealloc (cache
->buf
, cache
->bufsize
);
11943 ret
= remote_hostio_pread_vFile (self
, cache
->fd
, cache
->buf
, cache
->bufsize
,
11944 cache
->offset
, remote_errno
);
11947 cache
->invalidate_fd (fd
);
11951 cache
->bufsize
= ret
;
11952 return cache
->pread (fd
, read_buf
, len
, offset
);
11956 remote_target::fileio_pread (int fd
, gdb_byte
*read_buf
, int len
,
11957 ULONGEST offset
, int *remote_errno
)
11959 return remote_hostio_pread (this, fd
, read_buf
, len
, offset
, remote_errno
);
11962 /* Implementation of to_fileio_close. */
11965 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
11967 struct remote_state
*rs
= get_remote_state ();
11969 int left
= get_remote_packet_size () - 1;
11971 rs
->readahead_cache
.invalidate_fd (fd
);
11973 remote_buffer_add_string (&p
, &left
, "vFile:close:");
11975 remote_buffer_add_int (&p
, &left
, fd
);
11977 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
11978 remote_errno
, NULL
, NULL
);
11982 remote_target::fileio_close (int fd
, int *remote_errno
)
11984 return remote_hostio_close (this, fd
, remote_errno
);
11987 /* Implementation of to_fileio_unlink. */
11990 remote_hostio_unlink (struct target_ops
*self
,
11991 struct inferior
*inf
, const char *filename
,
11994 struct remote_state
*rs
= get_remote_state ();
11996 int left
= get_remote_packet_size () - 1;
11998 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
12001 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
12003 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
12004 strlen (filename
));
12006 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
12007 remote_errno
, NULL
, NULL
);
12011 remote_target::fileio_unlink (struct inferior
*inf
, const char *filename
,
12014 return remote_hostio_unlink (this, inf
, filename
, remote_errno
);
12017 /* Implementation of to_fileio_readlink. */
12019 gdb::optional
<std::string
>
12020 remote_target::fileio_readlink (struct inferior
*inf
, const char *filename
,
12023 struct remote_state
*rs
= get_remote_state ();
12026 int left
= get_remote_packet_size ();
12027 int len
, attachment_len
;
12030 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
12033 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
12035 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
12036 strlen (filename
));
12038 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
12039 remote_errno
, &attachment
,
12045 std::string
ret (len
, '\0');
12047 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
12048 (gdb_byte
*) &ret
[0], len
);
12049 if (read_len
!= len
)
12050 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
12055 /* Implementation of to_fileio_fstat. */
12058 remote_target::fileio_fstat (int fd
, struct stat
*st
, int *remote_errno
)
12060 struct remote_state
*rs
= get_remote_state ();
12062 int left
= get_remote_packet_size ();
12063 int attachment_len
, ret
;
12065 struct fio_stat fst
;
12068 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
12070 remote_buffer_add_int (&p
, &left
, fd
);
12072 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
12073 remote_errno
, &attachment
,
12077 if (*remote_errno
!= FILEIO_ENOSYS
)
12080 /* Strictly we should return -1, ENOSYS here, but when
12081 "set sysroot remote:" was implemented in August 2008
12082 BFD's need for a stat function was sidestepped with
12083 this hack. This was not remedied until March 2015
12084 so we retain the previous behavior to avoid breaking
12087 Note that the memset is a March 2015 addition; older
12088 GDBs set st_size *and nothing else* so the structure
12089 would have garbage in all other fields. This might
12090 break something but retaining the previous behavior
12091 here would be just too wrong. */
12093 memset (st
, 0, sizeof (struct stat
));
12094 st
->st_size
= INT_MAX
;
12098 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
12099 (gdb_byte
*) &fst
, sizeof (fst
));
12101 if (read_len
!= ret
)
12102 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
12104 if (read_len
!= sizeof (fst
))
12105 error (_("vFile:fstat returned %d bytes, but expecting %d."),
12106 read_len
, (int) sizeof (fst
));
12108 remote_fileio_to_host_stat (&fst
, st
);
12113 /* Implementation of to_filesystem_is_local. */
12116 remote_target::filesystem_is_local ()
12118 /* Valgrind GDB presents itself as a remote target but works
12119 on the local filesystem: it does not implement remote get
12120 and users are not expected to set a sysroot. To handle
12121 this case we treat the remote filesystem as local if the
12122 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
12123 does not support vFile:open. */
12124 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
12126 enum packet_support ps
= packet_support (PACKET_vFile_open
);
12128 if (ps
== PACKET_SUPPORT_UNKNOWN
)
12130 int fd
, remote_errno
;
12132 /* Try opening a file to probe support. The supplied
12133 filename is irrelevant, we only care about whether
12134 the stub recognizes the packet or not. */
12135 fd
= remote_hostio_open (this, NULL
, "just probing",
12136 FILEIO_O_RDONLY
, 0700, 0,
12140 remote_hostio_close (this, fd
, &remote_errno
);
12142 ps
= packet_support (PACKET_vFile_open
);
12145 if (ps
== PACKET_DISABLE
)
12147 static int warning_issued
= 0;
12149 if (!warning_issued
)
12151 warning (_("remote target does not support file"
12152 " transfer, attempting to access files"
12153 " from local filesystem."));
12154 warning_issued
= 1;
12165 remote_fileio_errno_to_host (int errnum
)
12171 case FILEIO_ENOENT
:
12179 case FILEIO_EACCES
:
12181 case FILEIO_EFAULT
:
12185 case FILEIO_EEXIST
:
12187 case FILEIO_ENODEV
:
12189 case FILEIO_ENOTDIR
:
12191 case FILEIO_EISDIR
:
12193 case FILEIO_EINVAL
:
12195 case FILEIO_ENFILE
:
12197 case FILEIO_EMFILE
:
12201 case FILEIO_ENOSPC
:
12203 case FILEIO_ESPIPE
:
12207 case FILEIO_ENOSYS
:
12209 case FILEIO_ENAMETOOLONG
:
12210 return ENAMETOOLONG
;
12216 remote_hostio_error (int errnum
)
12218 int host_error
= remote_fileio_errno_to_host (errnum
);
12220 if (host_error
== -1)
12221 error (_("Unknown remote I/O error %d"), errnum
);
12223 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
12226 /* A RAII wrapper around a remote file descriptor. */
12228 class scoped_remote_fd
12231 explicit scoped_remote_fd (int fd
)
12236 ~scoped_remote_fd ()
12243 remote_hostio_close (find_target_at (process_stratum
),
12244 m_fd
, &remote_errno
);
12248 /* Swallow exception before it escapes the dtor. If
12249 something goes wrong, likely the connection is gone,
12250 and there's nothing else that can be done. */
12255 DISABLE_COPY_AND_ASSIGN (scoped_remote_fd
);
12257 /* Release ownership of the file descriptor, and return it. */
12258 int release () noexcept
12265 /* Return the owned file descriptor. */
12266 int get () const noexcept
12272 /* The owned remote I/O file descriptor. */
12277 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
12279 struct cleanup
*back_to
;
12280 int retcode
, remote_errno
, bytes
, io_size
;
12282 int bytes_in_buffer
;
12285 struct remote_state
*rs
= get_remote_state ();
12287 if (!rs
->remote_desc
)
12288 error (_("command can only be used with remote target"));
12290 gdb_file_up file
= gdb_fopen_cloexec (local_file
, "rb");
12292 perror_with_name (local_file
);
12294 scoped_remote_fd fd
12295 (remote_hostio_open (find_target_at (process_stratum
), NULL
,
12296 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
12298 0700, 0, &remote_errno
));
12299 if (fd
.get () == -1)
12300 remote_hostio_error (remote_errno
);
12302 /* Send up to this many bytes at once. They won't all fit in the
12303 remote packet limit, so we'll transfer slightly fewer. */
12304 io_size
= get_remote_packet_size ();
12305 buffer
= (gdb_byte
*) xmalloc (io_size
);
12306 back_to
= make_cleanup (xfree
, buffer
);
12308 bytes_in_buffer
= 0;
12311 while (bytes_in_buffer
|| !saw_eof
)
12315 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
12316 io_size
- bytes_in_buffer
,
12320 if (ferror (file
.get ()))
12321 error (_("Error reading %s."), local_file
);
12324 /* EOF. Unless there is something still in the
12325 buffer from the last iteration, we are done. */
12327 if (bytes_in_buffer
== 0)
12335 bytes
+= bytes_in_buffer
;
12336 bytes_in_buffer
= 0;
12338 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
12339 fd
.get (), buffer
, bytes
,
12340 offset
, &remote_errno
);
12343 remote_hostio_error (remote_errno
);
12344 else if (retcode
== 0)
12345 error (_("Remote write of %d bytes returned 0!"), bytes
);
12346 else if (retcode
< bytes
)
12348 /* Short write. Save the rest of the read data for the next
12350 bytes_in_buffer
= bytes
- retcode
;
12351 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
12357 if (remote_hostio_close (find_target_at (process_stratum
),
12358 fd
.release (), &remote_errno
))
12359 remote_hostio_error (remote_errno
);
12362 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
12363 do_cleanups (back_to
);
12367 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
12369 struct cleanup
*back_to
;
12370 int remote_errno
, bytes
, io_size
;
12373 struct remote_state
*rs
= get_remote_state ();
12375 if (!rs
->remote_desc
)
12376 error (_("command can only be used with remote target"));
12378 scoped_remote_fd fd
12379 (remote_hostio_open (find_target_at (process_stratum
), NULL
,
12380 remote_file
, FILEIO_O_RDONLY
, 0, 0,
12382 if (fd
.get () == -1)
12383 remote_hostio_error (remote_errno
);
12385 gdb_file_up file
= gdb_fopen_cloexec (local_file
, "wb");
12387 perror_with_name (local_file
);
12389 /* Send up to this many bytes at once. They won't all fit in the
12390 remote packet limit, so we'll transfer slightly fewer. */
12391 io_size
= get_remote_packet_size ();
12392 buffer
= (gdb_byte
*) xmalloc (io_size
);
12393 back_to
= make_cleanup (xfree
, buffer
);
12398 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
12399 fd
.get (), buffer
, io_size
, offset
,
12402 /* Success, but no bytes, means end-of-file. */
12405 remote_hostio_error (remote_errno
);
12409 bytes
= fwrite (buffer
, 1, bytes
, file
.get ());
12411 perror_with_name (local_file
);
12414 if (remote_hostio_close (find_target_at (process_stratum
),
12415 fd
.release (), &remote_errno
))
12416 remote_hostio_error (remote_errno
);
12419 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
12420 do_cleanups (back_to
);
12424 remote_file_delete (const char *remote_file
, int from_tty
)
12426 int retcode
, remote_errno
;
12427 struct remote_state
*rs
= get_remote_state ();
12429 if (!rs
->remote_desc
)
12430 error (_("command can only be used with remote target"));
12432 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
12433 NULL
, remote_file
, &remote_errno
);
12435 remote_hostio_error (remote_errno
);
12438 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
12442 remote_put_command (const char *args
, int from_tty
)
12445 error_no_arg (_("file to put"));
12447 gdb_argv
argv (args
);
12448 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
12449 error (_("Invalid parameters to remote put"));
12451 remote_file_put (argv
[0], argv
[1], from_tty
);
12455 remote_get_command (const char *args
, int from_tty
)
12458 error_no_arg (_("file to get"));
12460 gdb_argv
argv (args
);
12461 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
12462 error (_("Invalid parameters to remote get"));
12464 remote_file_get (argv
[0], argv
[1], from_tty
);
12468 remote_delete_command (const char *args
, int from_tty
)
12471 error_no_arg (_("file to delete"));
12473 gdb_argv
argv (args
);
12474 if (argv
[0] == NULL
|| argv
[1] != NULL
)
12475 error (_("Invalid parameters to remote delete"));
12477 remote_file_delete (argv
[0], from_tty
);
12481 remote_command (const char *args
, int from_tty
)
12483 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
12487 remote_target::can_execute_reverse ()
12489 if (packet_support (PACKET_bs
) == PACKET_ENABLE
12490 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
12497 remote_target::supports_non_stop ()
12503 remote_target::supports_disable_randomization ()
12505 /* Only supported in extended mode. */
12510 remote_target::supports_multi_process ()
12512 struct remote_state
*rs
= get_remote_state ();
12514 return remote_multi_process_p (rs
);
12518 remote_supports_cond_tracepoints ()
12520 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
12524 remote_target::supports_evaluation_of_breakpoint_conditions ()
12526 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
12530 remote_supports_fast_tracepoints ()
12532 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
12536 remote_supports_static_tracepoints ()
12538 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
12542 remote_supports_install_in_trace ()
12544 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
12548 remote_target::supports_enable_disable_tracepoint ()
12550 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
12555 remote_target::supports_string_tracing ()
12557 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
12561 remote_target::can_run_breakpoint_commands ()
12563 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
12567 remote_target::trace_init ()
12569 struct remote_state
*rs
= get_remote_state ();
12572 remote_get_noisy_reply ();
12573 if (strcmp (rs
->buf
, "OK") != 0)
12574 error (_("Target does not support this command."));
12577 /* Recursive routine to walk through command list including loops, and
12578 download packets for each command. */
12581 remote_download_command_source (int num
, ULONGEST addr
,
12582 struct command_line
*cmds
)
12584 struct remote_state
*rs
= get_remote_state ();
12585 struct command_line
*cmd
;
12587 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
12589 QUIT
; /* Allow user to bail out with ^C. */
12590 strcpy (rs
->buf
, "QTDPsrc:");
12591 encode_source_string (num
, addr
, "cmd", cmd
->line
,
12592 rs
->buf
+ strlen (rs
->buf
),
12593 rs
->buf_size
- strlen (rs
->buf
));
12595 remote_get_noisy_reply ();
12596 if (strcmp (rs
->buf
, "OK"))
12597 warning (_("Target does not support source download."));
12599 if (cmd
->control_type
== while_control
12600 || cmd
->control_type
== while_stepping_control
)
12602 remote_download_command_source (num
, addr
, cmd
->body_list_0
.get ());
12604 QUIT
; /* Allow user to bail out with ^C. */
12605 strcpy (rs
->buf
, "QTDPsrc:");
12606 encode_source_string (num
, addr
, "cmd", "end",
12607 rs
->buf
+ strlen (rs
->buf
),
12608 rs
->buf_size
- strlen (rs
->buf
));
12610 remote_get_noisy_reply ();
12611 if (strcmp (rs
->buf
, "OK"))
12612 warning (_("Target does not support source download."));
12618 remote_target::download_tracepoint (struct bp_location
*loc
)
12620 #define BUF_SIZE 2048
12624 char buf
[BUF_SIZE
];
12625 std::vector
<std::string
> tdp_actions
;
12626 std::vector
<std::string
> stepping_actions
;
12628 struct breakpoint
*b
= loc
->owner
;
12629 struct tracepoint
*t
= (struct tracepoint
*) b
;
12630 struct remote_state
*rs
= get_remote_state ();
12632 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
12634 tpaddr
= loc
->address
;
12635 sprintf_vma (addrbuf
, tpaddr
);
12636 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
12637 addrbuf
, /* address */
12638 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
12639 t
->step_count
, t
->pass_count
);
12640 /* Fast tracepoints are mostly handled by the target, but we can
12641 tell the target how big of an instruction block should be moved
12643 if (b
->type
== bp_fast_tracepoint
)
12645 /* Only test for support at download time; we may not know
12646 target capabilities at definition time. */
12647 if (remote_supports_fast_tracepoints ())
12649 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
12651 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
12652 gdb_insn_length (loc
->gdbarch
, tpaddr
));
12654 /* If it passed validation at definition but fails now,
12655 something is very wrong. */
12656 internal_error (__FILE__
, __LINE__
,
12657 _("Fast tracepoint not "
12658 "valid during download"));
12661 /* Fast tracepoints are functionally identical to regular
12662 tracepoints, so don't take lack of support as a reason to
12663 give up on the trace run. */
12664 warning (_("Target does not support fast tracepoints, "
12665 "downloading %d as regular tracepoint"), b
->number
);
12667 else if (b
->type
== bp_static_tracepoint
)
12669 /* Only test for support at download time; we may not know
12670 target capabilities at definition time. */
12671 if (remote_supports_static_tracepoints ())
12673 struct static_tracepoint_marker marker
;
12675 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
12676 strcat (buf
, ":S");
12678 error (_("Static tracepoint not valid during download"));
12681 /* Fast tracepoints are functionally identical to regular
12682 tracepoints, so don't take lack of support as a reason
12683 to give up on the trace run. */
12684 error (_("Target does not support static tracepoints"));
12686 /* If the tracepoint has a conditional, make it into an agent
12687 expression and append to the definition. */
12690 /* Only test support at download time, we may not know target
12691 capabilities at definition time. */
12692 if (remote_supports_cond_tracepoints ())
12694 agent_expr_up aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
.get ());
12695 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
12697 pkt
= buf
+ strlen (buf
);
12698 for (int ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
12699 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
12703 warning (_("Target does not support conditional tracepoints, "
12704 "ignoring tp %d cond"), b
->number
);
12707 if (b
->commands
|| *default_collect
)
12710 remote_get_noisy_reply ();
12711 if (strcmp (rs
->buf
, "OK"))
12712 error (_("Target does not support tracepoints."));
12714 /* do_single_steps (t); */
12715 for (auto action_it
= tdp_actions
.begin ();
12716 action_it
!= tdp_actions
.end (); action_it
++)
12718 QUIT
; /* Allow user to bail out with ^C. */
12720 bool has_more
= (action_it
!= tdp_actions
.end ()
12721 || !stepping_actions
.empty ());
12723 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
12724 b
->number
, addrbuf
, /* address */
12725 action_it
->c_str (),
12726 has_more
? '-' : 0);
12728 remote_get_noisy_reply ();
12729 if (strcmp (rs
->buf
, "OK"))
12730 error (_("Error on target while setting tracepoints."));
12733 for (auto action_it
= stepping_actions
.begin ();
12734 action_it
!= stepping_actions
.end (); action_it
++)
12736 QUIT
; /* Allow user to bail out with ^C. */
12738 bool is_first
= action_it
== stepping_actions
.begin ();
12739 bool has_more
= action_it
!= stepping_actions
.end ();
12741 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
12742 b
->number
, addrbuf
, /* address */
12743 is_first
? "S" : "",
12744 action_it
->c_str (),
12745 has_more
? "-" : "");
12747 remote_get_noisy_reply ();
12748 if (strcmp (rs
->buf
, "OK"))
12749 error (_("Error on target while setting tracepoints."));
12752 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
12754 if (b
->location
!= NULL
)
12756 strcpy (buf
, "QTDPsrc:");
12757 encode_source_string (b
->number
, loc
->address
, "at",
12758 event_location_to_string (b
->location
.get ()),
12759 buf
+ strlen (buf
), 2048 - strlen (buf
));
12761 remote_get_noisy_reply ();
12762 if (strcmp (rs
->buf
, "OK"))
12763 warning (_("Target does not support source download."));
12765 if (b
->cond_string
)
12767 strcpy (buf
, "QTDPsrc:");
12768 encode_source_string (b
->number
, loc
->address
,
12769 "cond", b
->cond_string
, buf
+ strlen (buf
),
12770 2048 - strlen (buf
));
12772 remote_get_noisy_reply ();
12773 if (strcmp (rs
->buf
, "OK"))
12774 warning (_("Target does not support source download."));
12776 remote_download_command_source (b
->number
, loc
->address
,
12777 breakpoint_commands (b
));
12782 remote_target::can_download_tracepoint ()
12784 struct remote_state
*rs
= get_remote_state ();
12785 struct trace_status
*ts
;
12788 /* Don't try to install tracepoints until we've relocated our
12789 symbols, and fetched and merged the target's tracepoint list with
12791 if (rs
->starting_up
)
12794 ts
= current_trace_status ();
12795 status
= get_trace_status (ts
);
12797 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
12800 /* If we are in a tracing experiment, but remote stub doesn't support
12801 installing tracepoint in trace, we have to return. */
12802 if (!remote_supports_install_in_trace ())
12810 remote_target::download_trace_state_variable (const trace_state_variable
&tsv
)
12812 struct remote_state
*rs
= get_remote_state ();
12815 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
12816 tsv
.number
, phex ((ULONGEST
) tsv
.initial_value
, 8),
12818 p
= rs
->buf
+ strlen (rs
->buf
);
12819 if ((p
- rs
->buf
) + tsv
.name
.length () * 2 >= get_remote_packet_size ())
12820 error (_("Trace state variable name too long for tsv definition packet"));
12821 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
.name
.data ()), p
, tsv
.name
.length ());
12824 remote_get_noisy_reply ();
12825 if (*rs
->buf
== '\0')
12826 error (_("Target does not support this command."));
12827 if (strcmp (rs
->buf
, "OK") != 0)
12828 error (_("Error on target while downloading trace state variable."));
12832 remote_target::enable_tracepoint (struct bp_location
*location
)
12834 struct remote_state
*rs
= get_remote_state ();
12837 sprintf_vma (addr_buf
, location
->address
);
12838 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
12839 location
->owner
->number
, addr_buf
);
12841 remote_get_noisy_reply ();
12842 if (*rs
->buf
== '\0')
12843 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
12844 if (strcmp (rs
->buf
, "OK") != 0)
12845 error (_("Error on target while enabling tracepoint."));
12849 remote_target::disable_tracepoint (struct bp_location
*location
)
12851 struct remote_state
*rs
= get_remote_state ();
12854 sprintf_vma (addr_buf
, location
->address
);
12855 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
12856 location
->owner
->number
, addr_buf
);
12858 remote_get_noisy_reply ();
12859 if (*rs
->buf
== '\0')
12860 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
12861 if (strcmp (rs
->buf
, "OK") != 0)
12862 error (_("Error on target while disabling tracepoint."));
12866 remote_target::trace_set_readonly_regions ()
12870 bfd_size_type size
;
12876 return; /* No information to give. */
12878 struct remote_state
*rs
= get_remote_state ();
12880 strcpy (rs
->buf
, "QTro");
12881 offset
= strlen (rs
->buf
);
12882 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
12884 char tmp1
[40], tmp2
[40];
12887 if ((s
->flags
& SEC_LOAD
) == 0 ||
12888 /* (s->flags & SEC_CODE) == 0 || */
12889 (s
->flags
& SEC_READONLY
) == 0)
12893 vma
= bfd_get_section_vma (abfd
, s
);
12894 size
= bfd_get_section_size (s
);
12895 sprintf_vma (tmp1
, vma
);
12896 sprintf_vma (tmp2
, vma
+ size
);
12897 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
12898 if (offset
+ sec_length
+ 1 > rs
->buf_size
)
12900 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
12902 Too many sections for read-only sections definition packet."));
12905 xsnprintf (rs
->buf
+ offset
, rs
->buf_size
- offset
, ":%s,%s",
12907 offset
+= sec_length
;
12912 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12917 remote_target::trace_start ()
12919 struct remote_state
*rs
= get_remote_state ();
12921 putpkt ("QTStart");
12922 remote_get_noisy_reply ();
12923 if (*rs
->buf
== '\0')
12924 error (_("Target does not support this command."));
12925 if (strcmp (rs
->buf
, "OK") != 0)
12926 error (_("Bogus reply from target: %s"), rs
->buf
);
12930 remote_target::get_trace_status (struct trace_status
*ts
)
12932 /* Initialize it just to avoid a GCC false warning. */
12934 /* FIXME we need to get register block size some other way. */
12935 extern int trace_regblock_size
;
12936 enum packet_result result
;
12937 struct remote_state
*rs
= get_remote_state ();
12939 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
12942 trace_regblock_size
12943 = rs
->get_remote_arch_state (target_gdbarch ())->sizeof_g_packet
;
12945 putpkt ("qTStatus");
12949 p
= remote_get_noisy_reply ();
12951 CATCH (ex
, RETURN_MASK_ERROR
)
12953 if (ex
.error
!= TARGET_CLOSE_ERROR
)
12955 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
12958 throw_exception (ex
);
12962 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
12964 /* If the remote target doesn't do tracing, flag it. */
12965 if (result
== PACKET_UNKNOWN
)
12968 /* We're working with a live target. */
12969 ts
->filename
= NULL
;
12972 error (_("Bogus trace status reply from target: %s"), rs
->buf
);
12974 /* Function 'parse_trace_status' sets default value of each field of
12975 'ts' at first, so we don't have to do it here. */
12976 parse_trace_status (p
, ts
);
12978 return ts
->running
;
12982 remote_target::get_tracepoint_status (struct breakpoint
*bp
,
12983 struct uploaded_tp
*utp
)
12985 struct remote_state
*rs
= get_remote_state ();
12987 struct bp_location
*loc
;
12988 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
12989 size_t size
= get_remote_packet_size ();
12994 tp
->traceframe_usage
= 0;
12995 for (loc
= tp
->loc
; loc
; loc
= loc
->next
)
12997 /* If the tracepoint was never downloaded, don't go asking for
12999 if (tp
->number_on_target
== 0)
13001 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
13002 phex_nz (loc
->address
, 0));
13004 reply
= remote_get_noisy_reply ();
13005 if (reply
&& *reply
)
13008 parse_tracepoint_status (reply
+ 1, bp
, utp
);
13014 utp
->hit_count
= 0;
13015 utp
->traceframe_usage
= 0;
13016 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
13017 phex_nz (utp
->addr
, 0));
13019 reply
= remote_get_noisy_reply ();
13020 if (reply
&& *reply
)
13023 parse_tracepoint_status (reply
+ 1, bp
, utp
);
13029 remote_target::trace_stop ()
13031 struct remote_state
*rs
= get_remote_state ();
13034 remote_get_noisy_reply ();
13035 if (*rs
->buf
== '\0')
13036 error (_("Target does not support this command."));
13037 if (strcmp (rs
->buf
, "OK") != 0)
13038 error (_("Bogus reply from target: %s"), rs
->buf
);
13042 remote_target::trace_find (enum trace_find_type type
, int num
,
13043 CORE_ADDR addr1
, CORE_ADDR addr2
,
13046 struct remote_state
*rs
= get_remote_state ();
13047 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13049 int target_frameno
= -1, target_tracept
= -1;
13051 /* Lookups other than by absolute frame number depend on the current
13052 trace selected, so make sure it is correct on the remote end
13054 if (type
!= tfind_number
)
13055 set_remote_traceframe ();
13058 strcpy (p
, "QTFrame:");
13059 p
= strchr (p
, '\0');
13063 xsnprintf (p
, endbuf
- p
, "%x", num
);
13066 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
13069 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
13072 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
13073 phex_nz (addr2
, 0));
13075 case tfind_outside
:
13076 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
13077 phex_nz (addr2
, 0));
13080 error (_("Unknown trace find type %d"), type
);
13084 reply
= remote_get_noisy_reply ();
13085 if (*reply
== '\0')
13086 error (_("Target does not support this command."));
13088 while (reply
&& *reply
)
13093 target_frameno
= (int) strtol (p
, &reply
, 16);
13095 error (_("Unable to parse trace frame number"));
13096 /* Don't update our remote traceframe number cache on failure
13097 to select a remote traceframe. */
13098 if (target_frameno
== -1)
13103 target_tracept
= (int) strtol (p
, &reply
, 16);
13105 error (_("Unable to parse tracepoint number"));
13107 case 'O': /* "OK"? */
13108 if (reply
[1] == 'K' && reply
[2] == '\0')
13111 error (_("Bogus reply from target: %s"), reply
);
13114 error (_("Bogus reply from target: %s"), reply
);
13117 *tpp
= target_tracept
;
13119 rs
->remote_traceframe_number
= target_frameno
;
13120 return target_frameno
;
13124 remote_target::get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
13126 struct remote_state
*rs
= get_remote_state ();
13130 set_remote_traceframe ();
13132 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
13134 reply
= remote_get_noisy_reply ();
13135 if (reply
&& *reply
)
13139 unpack_varlen_hex (reply
+ 1, &uval
);
13140 *val
= (LONGEST
) uval
;
13148 remote_target::save_trace_data (const char *filename
)
13150 struct remote_state
*rs
= get_remote_state ();
13154 strcpy (p
, "QTSave:");
13156 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
13157 error (_("Remote file name too long for trace save packet"));
13158 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
13161 reply
= remote_get_noisy_reply ();
13162 if (*reply
== '\0')
13163 error (_("Target does not support this command."));
13164 if (strcmp (reply
, "OK") != 0)
13165 error (_("Bogus reply from target: %s"), reply
);
13169 /* This is basically a memory transfer, but needs to be its own packet
13170 because we don't know how the target actually organizes its trace
13171 memory, plus we want to be able to ask for as much as possible, but
13172 not be unhappy if we don't get as much as we ask for. */
13175 remote_target::get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
13177 struct remote_state
*rs
= get_remote_state ();
13183 strcpy (p
, "qTBuffer:");
13185 p
+= hexnumstr (p
, offset
);
13187 p
+= hexnumstr (p
, len
);
13191 reply
= remote_get_noisy_reply ();
13192 if (reply
&& *reply
)
13194 /* 'l' by itself means we're at the end of the buffer and
13195 there is nothing more to get. */
13199 /* Convert the reply into binary. Limit the number of bytes to
13200 convert according to our passed-in buffer size, rather than
13201 what was returned in the packet; if the target is
13202 unexpectedly generous and gives us a bigger reply than we
13203 asked for, we don't want to crash. */
13204 rslt
= hex2bin (reply
, buf
, len
);
13208 /* Something went wrong, flag as an error. */
13213 remote_target::set_disconnected_tracing (int val
)
13215 struct remote_state
*rs
= get_remote_state ();
13217 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
13221 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
13223 reply
= remote_get_noisy_reply ();
13224 if (*reply
== '\0')
13225 error (_("Target does not support this command."));
13226 if (strcmp (reply
, "OK") != 0)
13227 error (_("Bogus reply from target: %s"), reply
);
13230 warning (_("Target does not support disconnected tracing."));
13234 remote_target::core_of_thread (ptid_t ptid
)
13236 struct thread_info
*info
= find_thread_ptid (ptid
);
13238 if (info
!= NULL
&& info
->priv
!= NULL
)
13239 return get_remote_thread_info (info
)->core
;
13245 remote_target::set_circular_trace_buffer (int val
)
13247 struct remote_state
*rs
= get_remote_state ();
13250 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
13252 reply
= remote_get_noisy_reply ();
13253 if (*reply
== '\0')
13254 error (_("Target does not support this command."));
13255 if (strcmp (reply
, "OK") != 0)
13256 error (_("Bogus reply from target: %s"), reply
);
13260 remote_target::traceframe_info ()
13262 gdb::optional
<gdb::char_vector
> text
13263 = target_read_stralloc (target_stack
, TARGET_OBJECT_TRACEFRAME_INFO
,
13266 return parse_traceframe_info (text
->data ());
13271 /* Handle the qTMinFTPILen packet. Returns the minimum length of
13272 instruction on which a fast tracepoint may be placed. Returns -1
13273 if the packet is not supported, and 0 if the minimum instruction
13274 length is unknown. */
13277 remote_target::get_min_fast_tracepoint_insn_len ()
13279 struct remote_state
*rs
= get_remote_state ();
13282 /* If we're not debugging a process yet, the IPA can't be
13284 if (!target_has_execution
)
13287 /* Make sure the remote is pointing at the right process. */
13288 set_general_process ();
13290 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
13292 reply
= remote_get_noisy_reply ();
13293 if (*reply
== '\0')
13297 ULONGEST min_insn_len
;
13299 unpack_varlen_hex (reply
, &min_insn_len
);
13301 return (int) min_insn_len
;
13306 remote_target::set_trace_buffer_size (LONGEST val
)
13308 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
13310 struct remote_state
*rs
= get_remote_state ();
13311 char *buf
= rs
->buf
;
13312 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13313 enum packet_result result
;
13315 gdb_assert (val
>= 0 || val
== -1);
13316 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
13317 /* Send -1 as literal "-1" to avoid host size dependency. */
13321 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
13324 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
13327 remote_get_noisy_reply ();
13328 result
= packet_ok (rs
->buf
,
13329 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
13331 if (result
!= PACKET_OK
)
13332 warning (_("Bogus reply from target: %s"), rs
->buf
);
13337 remote_target::set_trace_notes (const char *user
, const char *notes
,
13338 const char *stop_notes
)
13340 struct remote_state
*rs
= get_remote_state ();
13342 char *buf
= rs
->buf
;
13343 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13346 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
13349 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
13350 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
13356 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
13357 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
13363 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
13364 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
13368 /* Ensure the buffer is terminated. */
13372 reply
= remote_get_noisy_reply ();
13373 if (*reply
== '\0')
13376 if (strcmp (reply
, "OK") != 0)
13377 error (_("Bogus reply from target: %s"), reply
);
13383 remote_target::use_agent (bool use
)
13385 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
13387 struct remote_state
*rs
= get_remote_state ();
13389 /* If the stub supports QAgent. */
13390 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
13392 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13394 if (strcmp (rs
->buf
, "OK") == 0)
13405 remote_target::can_use_agent ()
13407 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
13410 struct btrace_target_info
13412 /* The ptid of the traced thread. */
13415 /* The obtained branch trace configuration. */
13416 struct btrace_config conf
;
13419 /* Reset our idea of our target's btrace configuration. */
13422 remote_btrace_reset (void)
13424 struct remote_state
*rs
= get_remote_state ();
13426 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
13429 /* Synchronize the configuration with the target. */
13432 btrace_sync_conf (const struct btrace_config
*conf
)
13434 struct packet_config
*packet
;
13435 struct remote_state
*rs
;
13436 char *buf
, *pos
, *endbuf
;
13438 rs
= get_remote_state ();
13440 endbuf
= buf
+ get_remote_packet_size ();
13442 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
13443 if (packet_config_support (packet
) == PACKET_ENABLE
13444 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
13447 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
13451 getpkt (&buf
, &rs
->buf_size
, 0);
13453 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
13455 if (buf
[0] == 'E' && buf
[1] == '.')
13456 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
13458 error (_("Failed to configure the BTS buffer size."));
13461 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
13464 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
13465 if (packet_config_support (packet
) == PACKET_ENABLE
13466 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
13469 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
13473 getpkt (&buf
, &rs
->buf_size
, 0);
13475 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
13477 if (buf
[0] == 'E' && buf
[1] == '.')
13478 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
13480 error (_("Failed to configure the trace buffer size."));
13483 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
13487 /* Read the current thread's btrace configuration from the target and
13488 store it into CONF. */
13491 btrace_read_config (struct btrace_config
*conf
)
13493 gdb::optional
<gdb::char_vector
> xml
13494 = target_read_stralloc (target_stack
, TARGET_OBJECT_BTRACE_CONF
, "");
13496 parse_xml_btrace_conf (conf
, xml
->data ());
13499 /* Maybe reopen target btrace. */
13502 remote_btrace_maybe_reopen (void)
13504 struct remote_state
*rs
= get_remote_state ();
13505 struct thread_info
*tp
;
13506 int btrace_target_pushed
= 0;
13509 scoped_restore_current_thread restore_thread
;
13511 ALL_NON_EXITED_THREADS (tp
)
13513 set_general_thread (tp
->ptid
);
13515 memset (&rs
->btrace_config
, 0x00, sizeof (struct btrace_config
));
13516 btrace_read_config (&rs
->btrace_config
);
13518 if (rs
->btrace_config
.format
== BTRACE_FORMAT_NONE
)
13521 #if !defined (HAVE_LIBIPT)
13522 if (rs
->btrace_config
.format
== BTRACE_FORMAT_PT
)
13527 warning (_("Target is recording using Intel Processor Trace "
13528 "but support was disabled at compile time."));
13533 #endif /* !defined (HAVE_LIBIPT) */
13535 /* Push target, once, but before anything else happens. This way our
13536 changes to the threads will be cleaned up by unpushing the target
13537 in case btrace_read_config () throws. */
13538 if (!btrace_target_pushed
)
13540 btrace_target_pushed
= 1;
13541 record_btrace_push_target ();
13542 printf_filtered (_("Target is recording using %s.\n"),
13543 btrace_format_string (rs
->btrace_config
.format
));
13546 tp
->btrace
.target
= XCNEW (struct btrace_target_info
);
13547 tp
->btrace
.target
->ptid
= tp
->ptid
;
13548 tp
->btrace
.target
->conf
= rs
->btrace_config
;
13552 /* Enable branch tracing. */
13554 struct btrace_target_info
*
13555 remote_target::enable_btrace (ptid_t ptid
, const struct btrace_config
*conf
)
13557 struct btrace_target_info
*tinfo
= NULL
;
13558 struct packet_config
*packet
= NULL
;
13559 struct remote_state
*rs
= get_remote_state ();
13560 char *buf
= rs
->buf
;
13561 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13563 switch (conf
->format
)
13565 case BTRACE_FORMAT_BTS
:
13566 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
13569 case BTRACE_FORMAT_PT
:
13570 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
13574 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
13575 error (_("Target does not support branch tracing."));
13577 btrace_sync_conf (conf
);
13579 set_general_thread (ptid
);
13581 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
13583 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13585 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
13587 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
13588 error (_("Could not enable branch tracing for %s: %s"),
13589 target_pid_to_str (ptid
), rs
->buf
+ 2);
13591 error (_("Could not enable branch tracing for %s."),
13592 target_pid_to_str (ptid
));
13595 tinfo
= XCNEW (struct btrace_target_info
);
13596 tinfo
->ptid
= ptid
;
13598 /* If we fail to read the configuration, we lose some information, but the
13599 tracing itself is not impacted. */
13602 btrace_read_config (&tinfo
->conf
);
13604 CATCH (err
, RETURN_MASK_ERROR
)
13606 if (err
.message
!= NULL
)
13607 warning ("%s", err
.message
);
13614 /* Disable branch tracing. */
13617 remote_target::disable_btrace (struct btrace_target_info
*tinfo
)
13619 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
13620 struct remote_state
*rs
= get_remote_state ();
13621 char *buf
= rs
->buf
;
13622 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13624 if (packet_config_support (packet
) != PACKET_ENABLE
)
13625 error (_("Target does not support branch tracing."));
13627 set_general_thread (tinfo
->ptid
);
13629 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
13631 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13633 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
13635 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
13636 error (_("Could not disable branch tracing for %s: %s"),
13637 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
13639 error (_("Could not disable branch tracing for %s."),
13640 target_pid_to_str (tinfo
->ptid
));
13646 /* Teardown branch tracing. */
13649 remote_target::teardown_btrace (struct btrace_target_info
*tinfo
)
13651 /* We must not talk to the target during teardown. */
13655 /* Read the branch trace. */
13658 remote_target::read_btrace (struct btrace_data
*btrace
,
13659 struct btrace_target_info
*tinfo
,
13660 enum btrace_read_type type
)
13662 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
13665 if (packet_config_support (packet
) != PACKET_ENABLE
)
13666 error (_("Target does not support branch tracing."));
13668 #if !defined(HAVE_LIBEXPAT)
13669 error (_("Cannot process branch tracing result. XML parsing not supported."));
13674 case BTRACE_READ_ALL
:
13677 case BTRACE_READ_NEW
:
13680 case BTRACE_READ_DELTA
:
13684 internal_error (__FILE__
, __LINE__
,
13685 _("Bad branch tracing read type: %u."),
13686 (unsigned int) type
);
13689 gdb::optional
<gdb::char_vector
> xml
13690 = target_read_stralloc (target_stack
, TARGET_OBJECT_BTRACE
, annex
);
13692 return BTRACE_ERR_UNKNOWN
;
13694 parse_xml_btrace (btrace
, xml
->data ());
13696 return BTRACE_ERR_NONE
;
13699 const struct btrace_config
*
13700 remote_target::btrace_conf (const struct btrace_target_info
*tinfo
)
13702 return &tinfo
->conf
;
13706 remote_target::augmented_libraries_svr4_read ()
13708 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
13712 /* Implementation of to_load. */
13715 remote_target::load (const char *name
, int from_tty
)
13717 generic_load (name
, from_tty
);
13720 /* Accepts an integer PID; returns a string representing a file that
13721 can be opened on the remote side to get the symbols for the child
13722 process. Returns NULL if the operation is not supported. */
13725 remote_target::pid_to_exec_file (int pid
)
13727 static gdb::optional
<gdb::char_vector
> filename
;
13728 struct inferior
*inf
;
13729 char *annex
= NULL
;
13731 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
13734 inf
= find_inferior_pid (pid
);
13736 internal_error (__FILE__
, __LINE__
,
13737 _("not currently attached to process %d"), pid
);
13739 if (!inf
->fake_pid_p
)
13741 const int annex_size
= 9;
13743 annex
= (char *) alloca (annex_size
);
13744 xsnprintf (annex
, annex_size
, "%x", pid
);
13747 filename
= target_read_stralloc (target_stack
,
13748 TARGET_OBJECT_EXEC_FILE
, annex
);
13750 return filename
? filename
->data () : nullptr;
13753 /* Implement the to_can_do_single_step target_ops method. */
13756 remote_target::can_do_single_step ()
13758 /* We can only tell whether target supports single step or not by
13759 supported s and S vCont actions if the stub supports vContSupported
13760 feature. If the stub doesn't support vContSupported feature,
13761 we have conservatively to think target doesn't supports single
13763 if (packet_support (PACKET_vContSupported
) == PACKET_ENABLE
)
13765 struct remote_state
*rs
= get_remote_state ();
13767 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13768 remote_vcont_probe (rs
);
13770 return rs
->supports_vCont
.s
&& rs
->supports_vCont
.S
;
13776 /* Implementation of the to_execution_direction method for the remote
13779 enum exec_direction_kind
13780 remote_target::execution_direction ()
13782 struct remote_state
*rs
= get_remote_state ();
13784 return rs
->last_resume_exec_dir
;
13787 /* Return pointer to the thread_info struct which corresponds to
13788 THREAD_HANDLE (having length HANDLE_LEN). */
13791 remote_target::thread_handle_to_thread_info (const gdb_byte
*thread_handle
,
13795 struct thread_info
*tp
;
13797 ALL_NON_EXITED_THREADS (tp
)
13799 remote_thread_info
*priv
= get_remote_thread_info (tp
);
13801 if (tp
->inf
== inf
&& priv
!= NULL
)
13803 if (handle_len
!= priv
->thread_handle
.size ())
13804 error (_("Thread handle size mismatch: %d vs %zu (from remote)"),
13805 handle_len
, priv
->thread_handle
.size ());
13806 if (memcmp (thread_handle
, priv
->thread_handle
.data (),
13816 remote_target::can_async_p ()
13818 struct remote_state
*rs
= get_remote_state ();
13820 /* We don't go async if the user has explicitly prevented it with the
13821 "maint set target-async" command. */
13822 if (!target_async_permitted
)
13825 /* We're async whenever the serial device is. */
13826 return serial_can_async_p (rs
->remote_desc
);
13830 remote_target::is_async_p ()
13832 struct remote_state
*rs
= get_remote_state ();
13834 if (!target_async_permitted
)
13835 /* We only enable async when the user specifically asks for it. */
13838 /* We're async whenever the serial device is. */
13839 return serial_is_async_p (rs
->remote_desc
);
13842 /* Pass the SERIAL event on and up to the client. One day this code
13843 will be able to delay notifying the client of an event until the
13844 point where an entire packet has been received. */
13846 static serial_event_ftype remote_async_serial_handler
;
13849 remote_async_serial_handler (struct serial
*scb
, void *context
)
13851 /* Don't propogate error information up to the client. Instead let
13852 the client find out about the error by querying the target. */
13853 inferior_event_handler (INF_REG_EVENT
, NULL
);
13857 remote_async_inferior_event_handler (gdb_client_data data
)
13859 inferior_event_handler (INF_REG_EVENT
, NULL
);
13863 remote_target::async (int enable
)
13865 struct remote_state
*rs
= get_remote_state ();
13869 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
13871 /* If there are pending events in the stop reply queue tell the
13872 event loop to process them. */
13873 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
13874 mark_async_event_handler (remote_async_inferior_event_token
);
13875 /* For simplicity, below we clear the pending events token
13876 without remembering whether it is marked, so here we always
13877 mark it. If there's actually no pending notification to
13878 process, this ends up being a no-op (other than a spurious
13879 event-loop wakeup). */
13880 if (target_is_non_stop_p ())
13881 mark_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13885 serial_async (rs
->remote_desc
, NULL
, NULL
);
13886 /* If the core is disabling async, it doesn't want to be
13887 disturbed with target events. Clear all async event sources
13889 clear_async_event_handler (remote_async_inferior_event_token
);
13890 if (target_is_non_stop_p ())
13891 clear_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13895 /* Implementation of the to_thread_events method. */
13898 remote_target::thread_events (int enable
)
13900 struct remote_state
*rs
= get_remote_state ();
13901 size_t size
= get_remote_packet_size ();
13903 if (packet_support (PACKET_QThreadEvents
) == PACKET_DISABLE
)
13906 xsnprintf (rs
->buf
, size
, "QThreadEvents:%x", enable
? 1 : 0);
13908 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13910 switch (packet_ok (rs
->buf
,
13911 &remote_protocol_packets
[PACKET_QThreadEvents
]))
13914 if (strcmp (rs
->buf
, "OK") != 0)
13915 error (_("Remote refused setting thread events: %s"), rs
->buf
);
13918 warning (_("Remote failure reply: %s"), rs
->buf
);
13920 case PACKET_UNKNOWN
:
13926 set_remote_cmd (const char *args
, int from_tty
)
13928 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
13932 show_remote_cmd (const char *args
, int from_tty
)
13934 /* We can't just use cmd_show_list here, because we want to skip
13935 the redundant "show remote Z-packet" and the legacy aliases. */
13936 struct cmd_list_element
*list
= remote_show_cmdlist
;
13937 struct ui_out
*uiout
= current_uiout
;
13939 ui_out_emit_tuple
tuple_emitter (uiout
, "showlist");
13940 for (; list
!= NULL
; list
= list
->next
)
13941 if (strcmp (list
->name
, "Z-packet") == 0)
13943 else if (list
->type
== not_set_cmd
)
13944 /* Alias commands are exactly like the original, except they
13945 don't have the normal type. */
13949 ui_out_emit_tuple
option_emitter (uiout
, "option");
13951 uiout
->field_string ("name", list
->name
);
13952 uiout
->text (": ");
13953 if (list
->type
== show_cmd
)
13954 do_show_command (NULL
, from_tty
, list
);
13956 cmd_func (list
, NULL
, from_tty
);
13961 /* Function to be called whenever a new objfile (shlib) is detected. */
13963 remote_new_objfile (struct objfile
*objfile
)
13965 struct remote_state
*rs
= get_remote_state ();
13967 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
13968 remote_check_symbols ();
13971 /* Pull all the tracepoints defined on the target and create local
13972 data structures representing them. We don't want to create real
13973 tracepoints yet, we don't want to mess up the user's existing
13977 remote_target::upload_tracepoints (struct uploaded_tp
**utpp
)
13979 struct remote_state
*rs
= get_remote_state ();
13982 /* Ask for a first packet of tracepoint definition. */
13984 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13986 while (*p
&& *p
!= 'l')
13988 parse_tracepoint_definition (p
, utpp
);
13989 /* Ask for another packet of tracepoint definition. */
13991 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13998 remote_target::upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
14000 struct remote_state
*rs
= get_remote_state ();
14003 /* Ask for a first packet of variable definition. */
14005 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
14007 while (*p
&& *p
!= 'l')
14009 parse_tsv_definition (p
, utsvp
);
14010 /* Ask for another packet of variable definition. */
14012 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
14018 /* The "set/show range-stepping" show hook. */
14021 show_range_stepping (struct ui_file
*file
, int from_tty
,
14022 struct cmd_list_element
*c
,
14025 fprintf_filtered (file
,
14026 _("Debugger's willingness to use range stepping "
14027 "is %s.\n"), value
);
14030 /* The "set/show range-stepping" set hook. */
14033 set_range_stepping (const char *ignore_args
, int from_tty
,
14034 struct cmd_list_element
*c
)
14036 struct remote_state
*rs
= get_remote_state ();
14038 /* Whene enabling, check whether range stepping is actually
14039 supported by the target, and warn if not. */
14040 if (use_range_stepping
)
14042 if (rs
->remote_desc
!= NULL
)
14044 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
14045 remote_vcont_probe (rs
);
14047 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
14048 && rs
->supports_vCont
.r
)
14052 warning (_("Range stepping is not supported by the current target"));
14057 _initialize_remote (void)
14059 struct cmd_list_element
*cmd
;
14060 const char *cmd_name
;
14062 /* architecture specific data */
14063 remote_g_packet_data_handle
=
14064 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
14067 = register_program_space_data_with_cleanup (NULL
,
14068 remote_pspace_data_cleanup
);
14070 /* Initialize the per-target state. At the moment there is only one
14071 of these, not one per target. Only one target is active at a
14073 remote_state
= new struct remote_state ();
14075 add_target (remote_target_info
, remote_target::open
);
14076 add_target (extended_remote_target_info
, extended_remote_target::open
);
14078 /* Hook into new objfile notification. */
14079 gdb::observers::new_objfile
.attach (remote_new_objfile
);
14082 init_remote_threadtests ();
14085 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
14086 /* set/show remote ... */
14088 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
14089 Remote protocol specific variables\n\
14090 Configure various remote-protocol specific variables such as\n\
14091 the packets being used"),
14092 &remote_set_cmdlist
, "set remote ",
14093 0 /* allow-unknown */, &setlist
);
14094 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
14095 Remote protocol specific variables\n\
14096 Configure various remote-protocol specific variables such as\n\
14097 the packets being used"),
14098 &remote_show_cmdlist
, "show remote ",
14099 0 /* allow-unknown */, &showlist
);
14101 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
14102 Compare section data on target to the exec file.\n\
14103 Argument is a single section name (default: all loaded sections).\n\
14104 To compare only read-only loaded sections, specify the -r option."),
14107 add_cmd ("packet", class_maintenance
, packet_command
, _("\
14108 Send an arbitrary packet to a remote target.\n\
14109 maintenance packet TEXT\n\
14110 If GDB is talking to an inferior via the GDB serial protocol, then\n\
14111 this command sends the string TEXT to the inferior, and displays the\n\
14112 response packet. GDB supplies the initial `$' character, and the\n\
14113 terminating `#' character and checksum."),
14116 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
14117 Set whether to send break if interrupted."), _("\
14118 Show whether to send break if interrupted."), _("\
14119 If set, a break, instead of a cntrl-c, is sent to the remote target."),
14120 set_remotebreak
, show_remotebreak
,
14121 &setlist
, &showlist
);
14122 cmd_name
= "remotebreak";
14123 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
14124 deprecate_cmd (cmd
, "set remote interrupt-sequence");
14125 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
14126 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
14127 deprecate_cmd (cmd
, "show remote interrupt-sequence");
14129 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
14130 interrupt_sequence_modes
, &interrupt_sequence_mode
,
14132 Set interrupt sequence to remote target."), _("\
14133 Show interrupt sequence to remote target."), _("\
14134 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
14135 NULL
, show_interrupt_sequence
,
14136 &remote_set_cmdlist
,
14137 &remote_show_cmdlist
);
14139 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
14140 &interrupt_on_connect
, _("\
14141 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
14142 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
14143 If set, interrupt sequence is sent to remote target."),
14145 &remote_set_cmdlist
, &remote_show_cmdlist
);
14147 /* Install commands for configuring memory read/write packets. */
14149 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
14150 Set the maximum number of bytes per memory write packet (deprecated)."),
14152 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
14153 Show the maximum number of bytes per memory write packet (deprecated)."),
14155 add_cmd ("memory-write-packet-size", no_class
,
14156 set_memory_write_packet_size
, _("\
14157 Set the maximum number of bytes per memory-write packet.\n\
14158 Specify the number of bytes in a packet or 0 (zero) for the\n\
14159 default packet size. The actual limit is further reduced\n\
14160 dependent on the target. Specify ``fixed'' to disable the\n\
14161 further restriction and ``limit'' to enable that restriction."),
14162 &remote_set_cmdlist
);
14163 add_cmd ("memory-read-packet-size", no_class
,
14164 set_memory_read_packet_size
, _("\
14165 Set the maximum number of bytes per memory-read packet.\n\
14166 Specify the number of bytes in a packet or 0 (zero) for the\n\
14167 default packet size. The actual limit is further reduced\n\
14168 dependent on the target. Specify ``fixed'' to disable the\n\
14169 further restriction and ``limit'' to enable that restriction."),
14170 &remote_set_cmdlist
);
14171 add_cmd ("memory-write-packet-size", no_class
,
14172 show_memory_write_packet_size
,
14173 _("Show the maximum number of bytes per memory-write packet."),
14174 &remote_show_cmdlist
);
14175 add_cmd ("memory-read-packet-size", no_class
,
14176 show_memory_read_packet_size
,
14177 _("Show the maximum number of bytes per memory-read packet."),
14178 &remote_show_cmdlist
);
14180 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
14181 &remote_hw_watchpoint_limit
, _("\
14182 Set the maximum number of target hardware watchpoints."), _("\
14183 Show the maximum number of target hardware watchpoints."), _("\
14184 Specify a negative limit for unlimited."),
14185 NULL
, NULL
, /* FIXME: i18n: The maximum
14186 number of target hardware
14187 watchpoints is %s. */
14188 &remote_set_cmdlist
, &remote_show_cmdlist
);
14189 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
14190 &remote_hw_watchpoint_length_limit
, _("\
14191 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
14192 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
14193 Specify a negative limit for unlimited."),
14194 NULL
, NULL
, /* FIXME: i18n: The maximum
14195 length (in bytes) of a target
14196 hardware watchpoint is %s. */
14197 &remote_set_cmdlist
, &remote_show_cmdlist
);
14198 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
14199 &remote_hw_breakpoint_limit
, _("\
14200 Set the maximum number of target hardware breakpoints."), _("\
14201 Show the maximum number of target hardware breakpoints."), _("\
14202 Specify a negative limit for unlimited."),
14203 NULL
, NULL
, /* FIXME: i18n: The maximum
14204 number of target hardware
14205 breakpoints is %s. */
14206 &remote_set_cmdlist
, &remote_show_cmdlist
);
14208 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
14209 &remote_address_size
, _("\
14210 Set the maximum size of the address (in bits) in a memory packet."), _("\
14211 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
14213 NULL
, /* FIXME: i18n: */
14214 &setlist
, &showlist
);
14216 init_all_packet_configs ();
14218 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
14219 "X", "binary-download", 1);
14221 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
14222 "vCont", "verbose-resume", 0);
14224 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
14225 "QPassSignals", "pass-signals", 0);
14227 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QCatchSyscalls
],
14228 "QCatchSyscalls", "catch-syscalls", 0);
14230 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
14231 "QProgramSignals", "program-signals", 0);
14233 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QSetWorkingDir
],
14234 "QSetWorkingDir", "set-working-dir", 0);
14236 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartupWithShell
],
14237 "QStartupWithShell", "startup-with-shell", 0);
14239 add_packet_config_cmd (&remote_protocol_packets
14240 [PACKET_QEnvironmentHexEncoded
],
14241 "QEnvironmentHexEncoded", "environment-hex-encoded",
14244 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QEnvironmentReset
],
14245 "QEnvironmentReset", "environment-reset",
14248 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QEnvironmentUnset
],
14249 "QEnvironmentUnset", "environment-unset",
14252 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
14253 "qSymbol", "symbol-lookup", 0);
14255 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
14256 "P", "set-register", 1);
14258 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
14259 "p", "fetch-register", 1);
14261 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
14262 "Z0", "software-breakpoint", 0);
14264 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
14265 "Z1", "hardware-breakpoint", 0);
14267 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
14268 "Z2", "write-watchpoint", 0);
14270 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
14271 "Z3", "read-watchpoint", 0);
14273 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
14274 "Z4", "access-watchpoint", 0);
14276 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
14277 "qXfer:auxv:read", "read-aux-vector", 0);
14279 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
14280 "qXfer:exec-file:read", "pid-to-exec-file", 0);
14282 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
14283 "qXfer:features:read", "target-features", 0);
14285 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
14286 "qXfer:libraries:read", "library-info", 0);
14288 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
14289 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
14291 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
14292 "qXfer:memory-map:read", "memory-map", 0);
14294 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
14295 "qXfer:spu:read", "read-spu-object", 0);
14297 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
14298 "qXfer:spu:write", "write-spu-object", 0);
14300 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
14301 "qXfer:osdata:read", "osdata", 0);
14303 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
14304 "qXfer:threads:read", "threads", 0);
14306 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
14307 "qXfer:siginfo:read", "read-siginfo-object", 0);
14309 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
14310 "qXfer:siginfo:write", "write-siginfo-object", 0);
14312 add_packet_config_cmd
14313 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
14314 "qXfer:traceframe-info:read", "traceframe-info", 0);
14316 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
14317 "qXfer:uib:read", "unwind-info-block", 0);
14319 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
14320 "qGetTLSAddr", "get-thread-local-storage-address",
14323 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
14324 "qGetTIBAddr", "get-thread-information-block-address",
14327 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
14328 "bc", "reverse-continue", 0);
14330 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
14331 "bs", "reverse-step", 0);
14333 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
14334 "qSupported", "supported-packets", 0);
14336 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
14337 "qSearch:memory", "search-memory", 0);
14339 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
14340 "qTStatus", "trace-status", 0);
14342 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
14343 "vFile:setfs", "hostio-setfs", 0);
14345 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
14346 "vFile:open", "hostio-open", 0);
14348 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
14349 "vFile:pread", "hostio-pread", 0);
14351 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
14352 "vFile:pwrite", "hostio-pwrite", 0);
14354 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
14355 "vFile:close", "hostio-close", 0);
14357 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
14358 "vFile:unlink", "hostio-unlink", 0);
14360 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
14361 "vFile:readlink", "hostio-readlink", 0);
14363 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
14364 "vFile:fstat", "hostio-fstat", 0);
14366 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
14367 "vAttach", "attach", 0);
14369 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
14372 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
14373 "QStartNoAckMode", "noack", 0);
14375 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
14376 "vKill", "kill", 0);
14378 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
14379 "qAttached", "query-attached", 0);
14381 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
14382 "ConditionalTracepoints",
14383 "conditional-tracepoints", 0);
14385 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
14386 "ConditionalBreakpoints",
14387 "conditional-breakpoints", 0);
14389 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
14390 "BreakpointCommands",
14391 "breakpoint-commands", 0);
14393 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
14394 "FastTracepoints", "fast-tracepoints", 0);
14396 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
14397 "TracepointSource", "TracepointSource", 0);
14399 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
14400 "QAllow", "allow", 0);
14402 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
14403 "StaticTracepoints", "static-tracepoints", 0);
14405 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
14406 "InstallInTrace", "install-in-trace", 0);
14408 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
14409 "qXfer:statictrace:read", "read-sdata-object", 0);
14411 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
14412 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
14414 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
14415 "QDisableRandomization", "disable-randomization", 0);
14417 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
14418 "QAgent", "agent", 0);
14420 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
14421 "QTBuffer:size", "trace-buffer-size", 0);
14423 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
14424 "Qbtrace:off", "disable-btrace", 0);
14426 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
14427 "Qbtrace:bts", "enable-btrace-bts", 0);
14429 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
14430 "Qbtrace:pt", "enable-btrace-pt", 0);
14432 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
14433 "qXfer:btrace", "read-btrace", 0);
14435 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
14436 "qXfer:btrace-conf", "read-btrace-conf", 0);
14438 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
14439 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
14441 add_packet_config_cmd (&remote_protocol_packets
[PACKET_multiprocess_feature
],
14442 "multiprocess-feature", "multiprocess-feature", 0);
14444 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
14445 "swbreak-feature", "swbreak-feature", 0);
14447 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
14448 "hwbreak-feature", "hwbreak-feature", 0);
14450 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
14451 "fork-event-feature", "fork-event-feature", 0);
14453 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
14454 "vfork-event-feature", "vfork-event-feature", 0);
14456 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
14457 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
14459 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vContSupported
],
14460 "vContSupported", "verbose-resume-supported", 0);
14462 add_packet_config_cmd (&remote_protocol_packets
[PACKET_exec_event_feature
],
14463 "exec-event-feature", "exec-event-feature", 0);
14465 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCtrlC
],
14466 "vCtrlC", "ctrl-c", 0);
14468 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QThreadEvents
],
14469 "QThreadEvents", "thread-events", 0);
14471 add_packet_config_cmd (&remote_protocol_packets
[PACKET_no_resumed
],
14472 "N stop reply", "no-resumed-stop-reply", 0);
14474 /* Assert that we've registered "set remote foo-packet" commands
14475 for all packet configs. */
14479 for (i
= 0; i
< PACKET_MAX
; i
++)
14481 /* Ideally all configs would have a command associated. Some
14482 still don't though. */
14487 case PACKET_QNonStop
:
14488 case PACKET_EnableDisableTracepoints_feature
:
14489 case PACKET_tracenz_feature
:
14490 case PACKET_DisconnectedTracing_feature
:
14491 case PACKET_augmented_libraries_svr4_read_feature
:
14493 /* Additions to this list need to be well justified:
14494 pre-existing packets are OK; new packets are not. */
14502 /* This catches both forgetting to add a config command, and
14503 forgetting to remove a packet from the exception list. */
14504 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
14508 /* Keep the old ``set remote Z-packet ...'' working. Each individual
14509 Z sub-packet has its own set and show commands, but users may
14510 have sets to this variable in their .gdbinit files (or in their
14512 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
14513 &remote_Z_packet_detect
, _("\
14514 Set use of remote protocol `Z' packets"), _("\
14515 Show use of remote protocol `Z' packets "), _("\
14516 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
14518 set_remote_protocol_Z_packet_cmd
,
14519 show_remote_protocol_Z_packet_cmd
,
14520 /* FIXME: i18n: Use of remote protocol
14521 `Z' packets is %s. */
14522 &remote_set_cmdlist
, &remote_show_cmdlist
);
14524 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
14525 Manipulate files on the remote system\n\
14526 Transfer files to and from the remote target system."),
14527 &remote_cmdlist
, "remote ",
14528 0 /* allow-unknown */, &cmdlist
);
14530 add_cmd ("put", class_files
, remote_put_command
,
14531 _("Copy a local file to the remote system."),
14534 add_cmd ("get", class_files
, remote_get_command
,
14535 _("Copy a remote file to the local system."),
14538 add_cmd ("delete", class_files
, remote_delete_command
,
14539 _("Delete a remote file."),
14542 add_setshow_string_noescape_cmd ("exec-file", class_files
,
14543 &remote_exec_file_var
, _("\
14544 Set the remote pathname for \"run\""), _("\
14545 Show the remote pathname for \"run\""), NULL
,
14546 set_remote_exec_file
,
14547 show_remote_exec_file
,
14548 &remote_set_cmdlist
,
14549 &remote_show_cmdlist
);
14551 add_setshow_boolean_cmd ("range-stepping", class_run
,
14552 &use_range_stepping
, _("\
14553 Enable or disable range stepping."), _("\
14554 Show whether target-assisted range stepping is enabled."), _("\
14555 If on, and the target supports it, when stepping a source line, GDB\n\
14556 tells the target to step the corresponding range of addresses itself instead\n\
14557 of issuing multiple single-steps. This speeds up source level\n\
14558 stepping. If off, GDB always issues single-steps, even if range\n\
14559 stepping is supported by the target. The default is on."),
14560 set_range_stepping
,
14561 show_range_stepping
,
14565 /* Eventually initialize fileio. See fileio.c */
14566 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
14568 /* Take advantage of the fact that the TID field is not used, to tag
14569 special ptids with it set to != 0. */
14570 magic_null_ptid
= ptid_build (42000, -1, 1);
14571 not_sent_ptid
= ptid_build (42000, -2, 1);
14572 any_thread_ptid
= ptid_build (42000, 0, 1);