1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2016 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"
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"
76 /* Temp hacks for tracepoint encoding migration. */
77 static char *target_buf
;
78 static long target_buf_size
;
80 /* Per-program-space data key. */
81 static const struct program_space_data
*remote_pspace_data
;
83 /* The variable registered as the control variable used by the
84 remote exec-file commands. While the remote exec-file setting is
85 per-program-space, the set/show machinery uses this as the
86 location of the remote exec-file value. */
87 static char *remote_exec_file_var
;
89 /* The size to align memory write packets, when practical. The protocol
90 does not guarantee any alignment, and gdb will generate short
91 writes and unaligned writes, but even as a best-effort attempt this
92 can improve bulk transfers. For instance, if a write is misaligned
93 relative to the target's data bus, the stub may need to make an extra
94 round trip fetching data from the target. This doesn't make a
95 huge difference, but it's easy to do, so we try to be helpful.
97 The alignment chosen is arbitrary; usually data bus width is
98 important here, not the possibly larger cache line size. */
99 enum { REMOTE_ALIGN_WRITES
= 16 };
101 /* Prototypes for local functions. */
102 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
103 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
104 int forever
, int *is_notif
);
106 static void remote_files_info (struct target_ops
*ignore
);
108 static void remote_prepare_to_store (struct target_ops
*self
,
109 struct regcache
*regcache
);
111 static void remote_open_1 (const char *, int, struct target_ops
*,
114 static void remote_close (struct target_ops
*self
);
118 static int remote_vkill (int pid
, struct remote_state
*rs
);
120 static void remote_kill_k (void);
122 static void remote_mourn (struct target_ops
*ops
);
124 static void extended_remote_restart (void);
126 static void remote_send (char **buf
, long *sizeof_buf_p
);
128 static int readchar (int timeout
);
130 static void remote_serial_write (const char *str
, int len
);
132 static void remote_kill (struct target_ops
*ops
);
134 static int remote_can_async_p (struct target_ops
*);
136 static int remote_is_async_p (struct target_ops
*);
138 static void remote_async (struct target_ops
*ops
, int enable
);
140 static void remote_thread_events (struct target_ops
*ops
, int enable
);
142 static void interrupt_query (void);
144 static void set_general_thread (struct ptid ptid
);
145 static void set_continue_thread (struct ptid ptid
);
147 static void get_offsets (void);
149 static void skip_frame (void);
151 static long read_frame (char **buf_p
, long *sizeof_buf
);
153 static int hexnumlen (ULONGEST num
);
155 static void init_remote_ops (void);
157 static void init_extended_remote_ops (void);
159 static void remote_stop (struct target_ops
*self
, ptid_t
);
161 static int stubhex (int ch
);
163 static int hexnumstr (char *, ULONGEST
);
165 static int hexnumnstr (char *, ULONGEST
, int);
167 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
169 static void print_packet (const char *);
171 static void compare_sections_command (char *, int);
173 static void packet_command (char *, int);
175 static int stub_unpack_int (char *buff
, int fieldlength
);
177 static ptid_t
remote_current_thread (ptid_t oldptid
);
179 static int putpkt_binary (const char *buf
, int cnt
);
181 static void check_binary_download (CORE_ADDR addr
);
183 struct packet_config
;
185 static void show_packet_config_cmd (struct packet_config
*config
);
187 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
189 struct cmd_list_element
*c
,
192 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
193 static ptid_t
read_ptid (char *buf
, char **obuf
);
195 static void remote_set_permissions (struct target_ops
*self
);
197 static int remote_get_trace_status (struct target_ops
*self
,
198 struct trace_status
*ts
);
200 static int remote_upload_tracepoints (struct target_ops
*self
,
201 struct uploaded_tp
**utpp
);
203 static int remote_upload_trace_state_variables (struct target_ops
*self
,
204 struct uploaded_tsv
**utsvp
);
206 static void remote_query_supported (void);
208 static void remote_check_symbols (void);
210 void _initialize_remote (void);
213 static void stop_reply_xfree (struct stop_reply
*);
214 static void remote_parse_stop_reply (char *, struct stop_reply
*);
215 static void push_stop_reply (struct stop_reply
*);
216 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
217 static int peek_stop_reply (ptid_t ptid
);
219 struct threads_listing_context
;
220 static void remove_new_fork_children (struct threads_listing_context
*);
222 static void remote_async_inferior_event_handler (gdb_client_data
);
224 static void remote_terminal_ours (struct target_ops
*self
);
226 static int remote_read_description_p (struct target_ops
*target
);
228 static void remote_console_output (char *msg
);
230 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
232 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
234 static void remote_btrace_reset (void);
236 static void remote_btrace_maybe_reopen (void);
238 static int stop_reply_queue_length (void);
240 static void readahead_cache_invalidate (void);
242 static void remote_unpush_and_throw (void);
246 static struct cmd_list_element
*remote_cmdlist
;
248 /* For "set remote" and "show remote". */
250 static struct cmd_list_element
*remote_set_cmdlist
;
251 static struct cmd_list_element
*remote_show_cmdlist
;
253 /* Stub vCont actions support.
255 Each field is a boolean flag indicating whether the stub reports
256 support for the corresponding action. */
258 struct vCont_action_support
273 /* Controls whether GDB is willing to use range stepping. */
275 static int use_range_stepping
= 1;
277 #define OPAQUETHREADBYTES 8
279 /* a 64 bit opaque identifier */
280 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
282 /* About this many threadisds fit in a packet. */
284 #define MAXTHREADLISTRESULTS 32
286 /* Data for the vFile:pread readahead cache. */
288 struct readahead_cache
290 /* The file descriptor for the file that is being cached. -1 if the
294 /* The offset into the file that the cache buffer corresponds
298 /* The buffer holding the cache contents. */
300 /* The buffer's size. We try to read as much as fits into a packet
304 /* Cache hit and miss counters. */
309 /* Description of the remote protocol state for the currently
310 connected target. This is per-target state, and independent of the
311 selected architecture. */
315 /* A buffer to use for incoming packets, and its current size. The
316 buffer is grown dynamically for larger incoming packets.
317 Outgoing packets may also be constructed in this buffer.
318 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
319 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
324 /* True if we're going through initial connection setup (finding out
325 about the remote side's threads, relocating symbols, etc.). */
328 /* If we negotiated packet size explicitly (and thus can bypass
329 heuristics for the largest packet size that will not overflow
330 a buffer in the stub), this will be set to that packet size.
331 Otherwise zero, meaning to use the guessed size. */
332 long explicit_packet_size
;
334 /* remote_wait is normally called when the target is running and
335 waits for a stop reply packet. But sometimes we need to call it
336 when the target is already stopped. We can send a "?" packet
337 and have remote_wait read the response. Or, if we already have
338 the response, we can stash it in BUF and tell remote_wait to
339 skip calling getpkt. This flag is set when BUF contains a
340 stop reply packet and the target is not waiting. */
341 int cached_wait_status
;
343 /* True, if in no ack mode. That is, neither GDB nor the stub will
344 expect acks from each other. The connection is assumed to be
348 /* True if we're connected in extended remote mode. */
351 /* True if we resumed the target and we're waiting for the target to
352 stop. In the mean time, we can't start another command/query.
353 The remote server wouldn't be ready to process it, so we'd
354 timeout waiting for a reply that would never come and eventually
355 we'd close the connection. This can happen in asynchronous mode
356 because we allow GDB commands while the target is running. */
357 int waiting_for_stop_reply
;
359 /* The status of the stub support for the various vCont actions. */
360 struct vCont_action_support supports_vCont
;
362 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
363 responded to that. */
366 /* True if we saw a Ctrl-C while reading or writing from/to the
367 remote descriptor. At that point it is not safe to send a remote
368 interrupt packet, so we instead remember we saw the Ctrl-C and
369 process it once we're done with sending/receiving the current
370 packet, which should be shortly. If however that takes too long,
371 and the user presses Ctrl-C again, we offer to disconnect. */
372 int got_ctrlc_during_io
;
374 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
375 remote_open knows that we don't have a file open when the program
377 struct serial
*remote_desc
;
379 /* These are the threads which we last sent to the remote system. The
380 TID member will be -1 for all or -2 for not sent yet. */
381 ptid_t general_thread
;
382 ptid_t continue_thread
;
384 /* This is the traceframe which we last selected on the remote system.
385 It will be -1 if no traceframe is selected. */
386 int remote_traceframe_number
;
388 char *last_pass_packet
;
390 /* The last QProgramSignals packet sent to the target. We bypass
391 sending a new program signals list down to the target if the new
392 packet is exactly the same as the last we sent. IOW, we only let
393 the target know about program signals list changes. */
394 char *last_program_signals_packet
;
396 enum gdb_signal last_sent_signal
;
400 /* The execution direction of the last resume we got. */
401 enum exec_direction_kind last_resume_exec_dir
;
403 char *finished_object
;
404 char *finished_annex
;
405 ULONGEST finished_offset
;
407 /* Should we try the 'ThreadInfo' query packet?
409 This variable (NOT available to the user: auto-detect only!)
410 determines whether GDB will use the new, simpler "ThreadInfo"
411 query or the older, more complex syntax for thread queries.
412 This is an auto-detect variable (set to true at each connect,
413 and set to false when the target fails to recognize it). */
414 int use_threadinfo_query
;
415 int use_threadextra_query
;
417 threadref echo_nextthread
;
418 threadref nextthread
;
419 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
421 /* The state of remote notification. */
422 struct remote_notif_state
*notif_state
;
424 /* The branch trace configuration. */
425 struct btrace_config btrace_config
;
427 /* The argument to the last "vFile:setfs:" packet we sent, used
428 to avoid sending repeated unnecessary "vFile:setfs:" packets.
429 Initialized to -1 to indicate that no "vFile:setfs:" packet
430 has yet been sent. */
433 /* A readahead cache for vFile:pread. Often, reading a binary
434 involves a sequence of small reads. E.g., when parsing an ELF
435 file. A readahead cache helps mostly the case of remote
436 debugging on a connection with higher latency, due to the
437 request/reply nature of the RSP. We only cache data for a single
438 file descriptor at a time. */
439 struct readahead_cache readahead_cache
;
442 /* Private data that we'll store in (struct thread_info)->private. */
443 struct private_thread_info
449 /* Whether the target stopped for a breakpoint/watchpoint. */
450 enum target_stop_reason stop_reason
;
452 /* This is set to the data address of the access causing the target
453 to stop for a watchpoint. */
454 CORE_ADDR watch_data_address
;
458 free_private_thread_info (struct private_thread_info
*info
)
465 /* This data could be associated with a target, but we do not always
466 have access to the current target when we need it, so for now it is
467 static. This will be fine for as long as only one target is in use
469 static struct remote_state
*remote_state
;
471 static struct remote_state
*
472 get_remote_state_raw (void)
477 /* Allocate a new struct remote_state with xmalloc, initialize it, and
480 static struct remote_state
*
481 new_remote_state (void)
483 struct remote_state
*result
= XCNEW (struct remote_state
);
485 /* The default buffer size is unimportant; it will be expanded
486 whenever a larger buffer is needed. */
487 result
->buf_size
= 400;
488 result
->buf
= (char *) xmalloc (result
->buf_size
);
489 result
->remote_traceframe_number
= -1;
490 result
->last_sent_signal
= GDB_SIGNAL_0
;
491 result
->last_resume_exec_dir
= EXEC_FORWARD
;
497 /* Description of the remote protocol for a given architecture. */
501 long offset
; /* Offset into G packet. */
502 long regnum
; /* GDB's internal register number. */
503 LONGEST pnum
; /* Remote protocol register number. */
504 int in_g_packet
; /* Always part of G packet. */
505 /* long size in bytes; == register_size (target_gdbarch (), regnum);
507 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
511 struct remote_arch_state
513 /* Description of the remote protocol registers. */
514 long sizeof_g_packet
;
516 /* Description of the remote protocol registers indexed by REGNUM
517 (making an array gdbarch_num_regs in size). */
518 struct packet_reg
*regs
;
520 /* This is the size (in chars) of the first response to the ``g''
521 packet. It is used as a heuristic when determining the maximum
522 size of memory-read and memory-write packets. A target will
523 typically only reserve a buffer large enough to hold the ``g''
524 packet. The size does not include packet overhead (headers and
526 long actual_register_packet_size
;
528 /* This is the maximum size (in chars) of a non read/write packet.
529 It is also used as a cap on the size of read/write packets. */
530 long remote_packet_size
;
533 /* Utility: generate error from an incoming stub packet. */
535 trace_error (char *buf
)
538 return; /* not an error msg */
541 case '1': /* malformed packet error */
542 if (*++buf
== '0') /* general case: */
543 error (_("remote.c: error in outgoing packet."));
545 error (_("remote.c: error in outgoing packet at field #%ld."),
546 strtol (buf
, NULL
, 16));
548 error (_("Target returns error code '%s'."), buf
);
552 /* Utility: wait for reply from stub, while accepting "O" packets. */
554 remote_get_noisy_reply (char **buf_p
,
557 do /* Loop on reply from remote stub. */
561 QUIT
; /* Allow user to bail out with ^C. */
562 getpkt (buf_p
, sizeof_buf
, 0);
566 else if (startswith (buf
, "qRelocInsn:"))
569 CORE_ADDR from
, to
, org_to
;
571 int adjusted_size
= 0;
574 p
= buf
+ strlen ("qRelocInsn:");
575 pp
= unpack_varlen_hex (p
, &ul
);
577 error (_("invalid qRelocInsn packet: %s"), buf
);
581 unpack_varlen_hex (p
, &ul
);
588 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
591 CATCH (ex
, RETURN_MASK_ALL
)
593 if (ex
.error
== MEMORY_ERROR
)
595 /* Propagate memory errors silently back to the
596 target. The stub may have limited the range of
597 addresses we can write to, for example. */
601 /* Something unexpectedly bad happened. Be verbose
602 so we can tell what, and propagate the error back
603 to the stub, so it doesn't get stuck waiting for
605 exception_fprintf (gdb_stderr
, ex
,
606 _("warning: relocating instruction: "));
614 adjusted_size
= to
- org_to
;
616 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
620 else if (buf
[0] == 'O' && buf
[1] != 'K')
621 remote_console_output (buf
+ 1); /* 'O' message from stub */
623 return buf
; /* Here's the actual reply. */
628 /* Handle for retreving the remote protocol data from gdbarch. */
629 static struct gdbarch_data
*remote_gdbarch_data_handle
;
631 static struct remote_arch_state
*
632 get_remote_arch_state (void)
634 gdb_assert (target_gdbarch () != NULL
);
635 return ((struct remote_arch_state
*)
636 gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
));
639 /* Fetch the global remote target state. */
641 static struct remote_state
*
642 get_remote_state (void)
644 /* Make sure that the remote architecture state has been
645 initialized, because doing so might reallocate rs->buf. Any
646 function which calls getpkt also needs to be mindful of changes
647 to rs->buf, but this call limits the number of places which run
649 get_remote_arch_state ();
651 return get_remote_state_raw ();
654 /* Cleanup routine for the remote module's pspace data. */
657 remote_pspace_data_cleanup (struct program_space
*pspace
, void *arg
)
659 char *remote_exec_file
= (char *) arg
;
661 xfree (remote_exec_file
);
664 /* Fetch the remote exec-file from the current program space. */
667 get_remote_exec_file (void)
669 char *remote_exec_file
;
672 = (char *) program_space_data (current_program_space
,
674 if (remote_exec_file
== NULL
)
677 return remote_exec_file
;
680 /* Set the remote exec file for PSPACE. */
683 set_pspace_remote_exec_file (struct program_space
*pspace
,
684 char *remote_exec_file
)
686 char *old_file
= (char *) program_space_data (pspace
, remote_pspace_data
);
689 set_program_space_data (pspace
, remote_pspace_data
,
690 xstrdup (remote_exec_file
));
693 /* The "set/show remote exec-file" set command hook. */
696 set_remote_exec_file (char *ignored
, int from_tty
,
697 struct cmd_list_element
*c
)
699 gdb_assert (remote_exec_file_var
!= NULL
);
700 set_pspace_remote_exec_file (current_program_space
, remote_exec_file_var
);
703 /* The "set/show remote exec-file" show command hook. */
706 show_remote_exec_file (struct ui_file
*file
, int from_tty
,
707 struct cmd_list_element
*cmd
, const char *value
)
709 fprintf_filtered (file
, "%s\n", remote_exec_file_var
);
713 compare_pnums (const void *lhs_
, const void *rhs_
)
715 const struct packet_reg
* const *lhs
716 = (const struct packet_reg
* const *) lhs_
;
717 const struct packet_reg
* const *rhs
718 = (const struct packet_reg
* const *) rhs_
;
720 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
722 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
729 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
731 int regnum
, num_remote_regs
, offset
;
732 struct packet_reg
**remote_regs
;
734 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
736 struct packet_reg
*r
= ®s
[regnum
];
738 if (register_size (gdbarch
, regnum
) == 0)
739 /* Do not try to fetch zero-sized (placeholder) registers. */
742 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
747 /* Define the g/G packet format as the contents of each register
748 with a remote protocol number, in order of ascending protocol
751 remote_regs
= XALLOCAVEC (struct packet_reg
*, gdbarch_num_regs (gdbarch
));
752 for (num_remote_regs
= 0, regnum
= 0;
753 regnum
< gdbarch_num_regs (gdbarch
);
755 if (regs
[regnum
].pnum
!= -1)
756 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
758 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
761 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
763 remote_regs
[regnum
]->in_g_packet
= 1;
764 remote_regs
[regnum
]->offset
= offset
;
765 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
771 /* Given the architecture described by GDBARCH, return the remote
772 protocol register's number and the register's offset in the g/G
773 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
774 If the target does not have a mapping for REGNUM, return false,
775 otherwise, return true. */
778 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
779 int *pnum
, int *poffset
)
781 struct packet_reg
*regs
;
782 struct cleanup
*old_chain
;
784 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
786 regs
= XCNEWVEC (struct packet_reg
, gdbarch_num_regs (gdbarch
));
787 old_chain
= make_cleanup (xfree
, regs
);
789 map_regcache_remote_table (gdbarch
, regs
);
791 *pnum
= regs
[regnum
].pnum
;
792 *poffset
= regs
[regnum
].offset
;
794 do_cleanups (old_chain
);
800 init_remote_state (struct gdbarch
*gdbarch
)
802 struct remote_state
*rs
= get_remote_state_raw ();
803 struct remote_arch_state
*rsa
;
805 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
807 /* Use the architecture to build a regnum<->pnum table, which will be
808 1:1 unless a feature set specifies otherwise. */
809 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
810 gdbarch_num_regs (gdbarch
),
813 /* Record the maximum possible size of the g packet - it may turn out
815 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
817 /* Default maximum number of characters in a packet body. Many
818 remote stubs have a hardwired buffer size of 400 bytes
819 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
820 as the maximum packet-size to ensure that the packet and an extra
821 NUL character can always fit in the buffer. This stops GDB
822 trashing stubs that try to squeeze an extra NUL into what is
823 already a full buffer (As of 1999-12-04 that was most stubs). */
824 rsa
->remote_packet_size
= 400 - 1;
826 /* This one is filled in when a ``g'' packet is received. */
827 rsa
->actual_register_packet_size
= 0;
829 /* Should rsa->sizeof_g_packet needs more space than the
830 default, adjust the size accordingly. Remember that each byte is
831 encoded as two characters. 32 is the overhead for the packet
832 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
833 (``$NN:G...#NN'') is a better guess, the below has been padded a
835 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
836 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
838 /* Make sure that the packet buffer is plenty big enough for
839 this architecture. */
840 if (rs
->buf_size
< rsa
->remote_packet_size
)
842 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
843 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
849 /* Return the current allowed size of a remote packet. This is
850 inferred from the current architecture, and should be used to
851 limit the length of outgoing packets. */
853 get_remote_packet_size (void)
855 struct remote_state
*rs
= get_remote_state ();
856 struct remote_arch_state
*rsa
= get_remote_arch_state ();
858 if (rs
->explicit_packet_size
)
859 return rs
->explicit_packet_size
;
861 return rsa
->remote_packet_size
;
864 static struct packet_reg
*
865 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
867 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
871 struct packet_reg
*r
= &rsa
->regs
[regnum
];
873 gdb_assert (r
->regnum
== regnum
);
878 static struct packet_reg
*
879 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
883 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
885 struct packet_reg
*r
= &rsa
->regs
[i
];
893 static struct target_ops remote_ops
;
895 static struct target_ops extended_remote_ops
;
897 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
898 ``forever'' still use the normal timeout mechanism. This is
899 currently used by the ASYNC code to guarentee that target reads
900 during the initial connect always time-out. Once getpkt has been
901 modified to return a timeout indication and, in turn
902 remote_wait()/wait_for_inferior() have gained a timeout parameter
904 static int wait_forever_enabled_p
= 1;
906 /* Allow the user to specify what sequence to send to the remote
907 when he requests a program interruption: Although ^C is usually
908 what remote systems expect (this is the default, here), it is
909 sometimes preferable to send a break. On other systems such
910 as the Linux kernel, a break followed by g, which is Magic SysRq g
911 is required in order to interrupt the execution. */
912 const char interrupt_sequence_control_c
[] = "Ctrl-C";
913 const char interrupt_sequence_break
[] = "BREAK";
914 const char interrupt_sequence_break_g
[] = "BREAK-g";
915 static const char *const interrupt_sequence_modes
[] =
917 interrupt_sequence_control_c
,
918 interrupt_sequence_break
,
919 interrupt_sequence_break_g
,
922 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
925 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
926 struct cmd_list_element
*c
,
929 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
930 fprintf_filtered (file
,
931 _("Send the ASCII ETX character (Ctrl-c) "
932 "to the remote target to interrupt the "
933 "execution of the program.\n"));
934 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
935 fprintf_filtered (file
,
936 _("send a break signal to the remote target "
937 "to interrupt the execution of the program.\n"));
938 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
939 fprintf_filtered (file
,
940 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
941 "the remote target to interrupt the execution "
942 "of Linux kernel.\n"));
944 internal_error (__FILE__
, __LINE__
,
945 _("Invalid value for interrupt_sequence_mode: %s."),
946 interrupt_sequence_mode
);
949 /* This boolean variable specifies whether interrupt_sequence is sent
950 to the remote target when gdb connects to it.
951 This is mostly needed when you debug the Linux kernel: The Linux kernel
952 expects BREAK g which is Magic SysRq g for connecting gdb. */
953 static int interrupt_on_connect
= 0;
955 /* This variable is used to implement the "set/show remotebreak" commands.
956 Since these commands are now deprecated in favor of "set/show remote
957 interrupt-sequence", it no longer has any effect on the code. */
958 static int remote_break
;
961 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
964 interrupt_sequence_mode
= interrupt_sequence_break
;
966 interrupt_sequence_mode
= interrupt_sequence_control_c
;
970 show_remotebreak (struct ui_file
*file
, int from_tty
,
971 struct cmd_list_element
*c
,
976 /* This variable sets the number of bits in an address that are to be
977 sent in a memory ("M" or "m") packet. Normally, after stripping
978 leading zeros, the entire address would be sent. This variable
979 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
980 initial implementation of remote.c restricted the address sent in
981 memory packets to ``host::sizeof long'' bytes - (typically 32
982 bits). Consequently, for 64 bit targets, the upper 32 bits of an
983 address was never sent. Since fixing this bug may cause a break in
984 some remote targets this variable is principly provided to
985 facilitate backward compatibility. */
987 static unsigned int remote_address_size
;
989 /* Temporary to track who currently owns the terminal. See
990 remote_terminal_* for more details. */
992 static int remote_async_terminal_ours_p
;
995 /* User configurable variables for the number of characters in a
996 memory read/write packet. MIN (rsa->remote_packet_size,
997 rsa->sizeof_g_packet) is the default. Some targets need smaller
998 values (fifo overruns, et.al.) and some users need larger values
999 (speed up transfers). The variables ``preferred_*'' (the user
1000 request), ``current_*'' (what was actually set) and ``forced_*''
1001 (Positive - a soft limit, negative - a hard limit). */
1003 struct memory_packet_config
1010 /* The default max memory-write-packet-size. The 16k is historical.
1011 (It came from older GDB's using alloca for buffers and the
1012 knowledge (folklore?) that some hosts don't cope very well with
1013 large alloca calls.) */
1014 #define DEFAULT_MAX_MEMORY_PACKET_SIZE 16384
1016 /* The minimum remote packet size for memory transfers. Ensures we
1017 can write at least one byte. */
1018 #define MIN_MEMORY_PACKET_SIZE 20
1020 /* Compute the current size of a read/write packet. Since this makes
1021 use of ``actual_register_packet_size'' the computation is dynamic. */
1024 get_memory_packet_size (struct memory_packet_config
*config
)
1026 struct remote_state
*rs
= get_remote_state ();
1027 struct remote_arch_state
*rsa
= get_remote_arch_state ();
1030 if (config
->fixed_p
)
1032 if (config
->size
<= 0)
1033 what_they_get
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1035 what_they_get
= config
->size
;
1039 what_they_get
= get_remote_packet_size ();
1040 /* Limit the packet to the size specified by the user. */
1041 if (config
->size
> 0
1042 && what_they_get
> config
->size
)
1043 what_they_get
= config
->size
;
1045 /* Limit it to the size of the targets ``g'' response unless we have
1046 permission from the stub to use a larger packet size. */
1047 if (rs
->explicit_packet_size
== 0
1048 && rsa
->actual_register_packet_size
> 0
1049 && what_they_get
> rsa
->actual_register_packet_size
)
1050 what_they_get
= rsa
->actual_register_packet_size
;
1052 if (what_they_get
< MIN_MEMORY_PACKET_SIZE
)
1053 what_they_get
= MIN_MEMORY_PACKET_SIZE
;
1055 /* Make sure there is room in the global buffer for this packet
1056 (including its trailing NUL byte). */
1057 if (rs
->buf_size
< what_they_get
+ 1)
1059 rs
->buf_size
= 2 * what_they_get
;
1060 rs
->buf
= (char *) xrealloc (rs
->buf
, 2 * what_they_get
);
1063 return what_they_get
;
1066 /* Update the size of a read/write packet. If they user wants
1067 something really big then do a sanity check. */
1070 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
1072 int fixed_p
= config
->fixed_p
;
1073 long size
= config
->size
;
1076 error (_("Argument required (integer, `fixed' or `limited')."));
1077 else if (strcmp (args
, "hard") == 0
1078 || strcmp (args
, "fixed") == 0)
1080 else if (strcmp (args
, "soft") == 0
1081 || strcmp (args
, "limit") == 0)
1087 size
= strtoul (args
, &end
, 0);
1089 error (_("Invalid %s (bad syntax)."), config
->name
);
1091 /* Instead of explicitly capping the size of a packet to or
1092 disallowing it, the user is allowed to set the size to
1093 something arbitrarily large. */
1096 /* So that the query shows the correct value. */
1098 size
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1101 if (fixed_p
&& !config
->fixed_p
)
1103 if (! query (_("The target may not be able to correctly handle a %s\n"
1104 "of %ld bytes. Change the packet size? "),
1105 config
->name
, size
))
1106 error (_("Packet size not changed."));
1108 /* Update the config. */
1109 config
->fixed_p
= fixed_p
;
1110 config
->size
= size
;
1114 show_memory_packet_size (struct memory_packet_config
*config
)
1116 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1117 if (config
->fixed_p
)
1118 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1119 get_memory_packet_size (config
));
1121 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1122 get_memory_packet_size (config
));
1125 static struct memory_packet_config memory_write_packet_config
=
1127 "memory-write-packet-size",
1131 set_memory_write_packet_size (char *args
, int from_tty
)
1133 set_memory_packet_size (args
, &memory_write_packet_config
);
1137 show_memory_write_packet_size (char *args
, int from_tty
)
1139 show_memory_packet_size (&memory_write_packet_config
);
1143 get_memory_write_packet_size (void)
1145 return get_memory_packet_size (&memory_write_packet_config
);
1148 static struct memory_packet_config memory_read_packet_config
=
1150 "memory-read-packet-size",
1154 set_memory_read_packet_size (char *args
, int from_tty
)
1156 set_memory_packet_size (args
, &memory_read_packet_config
);
1160 show_memory_read_packet_size (char *args
, int from_tty
)
1162 show_memory_packet_size (&memory_read_packet_config
);
1166 get_memory_read_packet_size (void)
1168 long size
= get_memory_packet_size (&memory_read_packet_config
);
1170 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1171 extra buffer size argument before the memory read size can be
1172 increased beyond this. */
1173 if (size
> get_remote_packet_size ())
1174 size
= get_remote_packet_size ();
1179 /* Generic configuration support for packets the stub optionally
1180 supports. Allows the user to specify the use of the packet as well
1181 as allowing GDB to auto-detect support in the remote stub. */
1185 PACKET_SUPPORT_UNKNOWN
= 0,
1190 struct packet_config
1195 /* If auto, GDB auto-detects support for this packet or feature,
1196 either through qSupported, or by trying the packet and looking
1197 at the response. If true, GDB assumes the target supports this
1198 packet. If false, the packet is disabled. Configs that don't
1199 have an associated command always have this set to auto. */
1200 enum auto_boolean detect
;
1202 /* Does the target support this packet? */
1203 enum packet_support support
;
1206 /* Analyze a packet's return value and update the packet config
1216 static enum packet_support
packet_config_support (struct packet_config
*config
);
1217 static enum packet_support
packet_support (int packet
);
1220 show_packet_config_cmd (struct packet_config
*config
)
1222 char *support
= "internal-error";
1224 switch (packet_config_support (config
))
1227 support
= "enabled";
1229 case PACKET_DISABLE
:
1230 support
= "disabled";
1232 case PACKET_SUPPORT_UNKNOWN
:
1233 support
= "unknown";
1236 switch (config
->detect
)
1238 case AUTO_BOOLEAN_AUTO
:
1239 printf_filtered (_("Support for the `%s' packet "
1240 "is auto-detected, currently %s.\n"),
1241 config
->name
, support
);
1243 case AUTO_BOOLEAN_TRUE
:
1244 case AUTO_BOOLEAN_FALSE
:
1245 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1246 config
->name
, support
);
1252 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1253 const char *title
, int legacy
)
1259 config
->name
= name
;
1260 config
->title
= title
;
1261 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1263 show_doc
= xstrprintf ("Show current use of remote "
1264 "protocol `%s' (%s) packet",
1266 /* set/show TITLE-packet {auto,on,off} */
1267 cmd_name
= xstrprintf ("%s-packet", title
);
1268 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1269 &config
->detect
, set_doc
,
1270 show_doc
, NULL
, /* help_doc */
1272 show_remote_protocol_packet_cmd
,
1273 &remote_set_cmdlist
, &remote_show_cmdlist
);
1274 /* The command code copies the documentation strings. */
1277 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1282 legacy_name
= xstrprintf ("%s-packet", name
);
1283 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1284 &remote_set_cmdlist
);
1285 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1286 &remote_show_cmdlist
);
1290 static enum packet_result
1291 packet_check_result (const char *buf
)
1295 /* The stub recognized the packet request. Check that the
1296 operation succeeded. */
1298 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1300 /* "Enn" - definitly an error. */
1301 return PACKET_ERROR
;
1303 /* Always treat "E." as an error. This will be used for
1304 more verbose error messages, such as E.memtypes. */
1305 if (buf
[0] == 'E' && buf
[1] == '.')
1306 return PACKET_ERROR
;
1308 /* The packet may or may not be OK. Just assume it is. */
1312 /* The stub does not support the packet. */
1313 return PACKET_UNKNOWN
;
1316 static enum packet_result
1317 packet_ok (const char *buf
, struct packet_config
*config
)
1319 enum packet_result result
;
1321 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1322 && config
->support
== PACKET_DISABLE
)
1323 internal_error (__FILE__
, __LINE__
,
1324 _("packet_ok: attempt to use a disabled packet"));
1326 result
= packet_check_result (buf
);
1331 /* The stub recognized the packet request. */
1332 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1335 fprintf_unfiltered (gdb_stdlog
,
1336 "Packet %s (%s) is supported\n",
1337 config
->name
, config
->title
);
1338 config
->support
= PACKET_ENABLE
;
1341 case PACKET_UNKNOWN
:
1342 /* The stub does not support the packet. */
1343 if (config
->detect
== AUTO_BOOLEAN_AUTO
1344 && config
->support
== PACKET_ENABLE
)
1346 /* If the stub previously indicated that the packet was
1347 supported then there is a protocol error. */
1348 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1349 config
->name
, config
->title
);
1351 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1353 /* The user set it wrong. */
1354 error (_("Enabled packet %s (%s) not recognized by stub"),
1355 config
->name
, config
->title
);
1359 fprintf_unfiltered (gdb_stdlog
,
1360 "Packet %s (%s) is NOT supported\n",
1361 config
->name
, config
->title
);
1362 config
->support
= PACKET_DISABLE
;
1383 PACKET_vFile_pwrite
,
1385 PACKET_vFile_unlink
,
1386 PACKET_vFile_readlink
,
1389 PACKET_qXfer_features
,
1390 PACKET_qXfer_exec_file
,
1391 PACKET_qXfer_libraries
,
1392 PACKET_qXfer_libraries_svr4
,
1393 PACKET_qXfer_memory_map
,
1394 PACKET_qXfer_spu_read
,
1395 PACKET_qXfer_spu_write
,
1396 PACKET_qXfer_osdata
,
1397 PACKET_qXfer_threads
,
1398 PACKET_qXfer_statictrace_read
,
1399 PACKET_qXfer_traceframe_info
,
1405 PACKET_QPassSignals
,
1406 PACKET_QCatchSyscalls
,
1407 PACKET_QProgramSignals
,
1409 PACKET_qSearch_memory
,
1412 PACKET_QStartNoAckMode
,
1414 PACKET_qXfer_siginfo_read
,
1415 PACKET_qXfer_siginfo_write
,
1418 /* Support for conditional tracepoints. */
1419 PACKET_ConditionalTracepoints
,
1421 /* Support for target-side breakpoint conditions. */
1422 PACKET_ConditionalBreakpoints
,
1424 /* Support for target-side breakpoint commands. */
1425 PACKET_BreakpointCommands
,
1427 /* Support for fast tracepoints. */
1428 PACKET_FastTracepoints
,
1430 /* Support for static tracepoints. */
1431 PACKET_StaticTracepoints
,
1433 /* Support for installing tracepoints while a trace experiment is
1435 PACKET_InstallInTrace
,
1439 PACKET_TracepointSource
,
1442 PACKET_QDisableRandomization
,
1444 PACKET_QTBuffer_size
,
1448 PACKET_qXfer_btrace
,
1450 /* Support for the QNonStop packet. */
1453 /* Support for the QThreadEvents packet. */
1454 PACKET_QThreadEvents
,
1456 /* Support for multi-process extensions. */
1457 PACKET_multiprocess_feature
,
1459 /* Support for enabling and disabling tracepoints while a trace
1460 experiment is running. */
1461 PACKET_EnableDisableTracepoints_feature
,
1463 /* Support for collecting strings using the tracenz bytecode. */
1464 PACKET_tracenz_feature
,
1466 /* Support for continuing to run a trace experiment while GDB is
1468 PACKET_DisconnectedTracing_feature
,
1470 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1471 PACKET_augmented_libraries_svr4_read_feature
,
1473 /* Support for the qXfer:btrace-conf:read packet. */
1474 PACKET_qXfer_btrace_conf
,
1476 /* Support for the Qbtrace-conf:bts:size packet. */
1477 PACKET_Qbtrace_conf_bts_size
,
1479 /* Support for swbreak+ feature. */
1480 PACKET_swbreak_feature
,
1482 /* Support for hwbreak+ feature. */
1483 PACKET_hwbreak_feature
,
1485 /* Support for fork events. */
1486 PACKET_fork_event_feature
,
1488 /* Support for vfork events. */
1489 PACKET_vfork_event_feature
,
1491 /* Support for the Qbtrace-conf:pt:size packet. */
1492 PACKET_Qbtrace_conf_pt_size
,
1494 /* Support for exec events. */
1495 PACKET_exec_event_feature
,
1497 /* Support for query supported vCont actions. */
1498 PACKET_vContSupported
,
1500 /* Support remote CTRL-C. */
1503 /* Support TARGET_WAITKIND_NO_RESUMED. */
1509 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1511 /* Returns the packet's corresponding "set remote foo-packet" command
1512 state. See struct packet_config for more details. */
1514 static enum auto_boolean
1515 packet_set_cmd_state (int packet
)
1517 return remote_protocol_packets
[packet
].detect
;
1520 /* Returns whether a given packet or feature is supported. This takes
1521 into account the state of the corresponding "set remote foo-packet"
1522 command, which may be used to bypass auto-detection. */
1524 static enum packet_support
1525 packet_config_support (struct packet_config
*config
)
1527 switch (config
->detect
)
1529 case AUTO_BOOLEAN_TRUE
:
1530 return PACKET_ENABLE
;
1531 case AUTO_BOOLEAN_FALSE
:
1532 return PACKET_DISABLE
;
1533 case AUTO_BOOLEAN_AUTO
:
1534 return config
->support
;
1536 gdb_assert_not_reached (_("bad switch"));
1540 /* Same as packet_config_support, but takes the packet's enum value as
1543 static enum packet_support
1544 packet_support (int packet
)
1546 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1548 return packet_config_support (config
);
1552 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1553 struct cmd_list_element
*c
,
1556 struct packet_config
*packet
;
1558 for (packet
= remote_protocol_packets
;
1559 packet
< &remote_protocol_packets
[PACKET_MAX
];
1562 if (&packet
->detect
== c
->var
)
1564 show_packet_config_cmd (packet
);
1568 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1572 /* Should we try one of the 'Z' requests? */
1576 Z_PACKET_SOFTWARE_BP
,
1577 Z_PACKET_HARDWARE_BP
,
1584 /* For compatibility with older distributions. Provide a ``set remote
1585 Z-packet ...'' command that updates all the Z packet types. */
1587 static enum auto_boolean remote_Z_packet_detect
;
1590 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1591 struct cmd_list_element
*c
)
1595 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1596 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1600 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1601 struct cmd_list_element
*c
,
1606 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1608 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1612 /* Returns true if the multi-process extensions are in effect. */
1615 remote_multi_process_p (struct remote_state
*rs
)
1617 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1620 /* Returns true if fork events are supported. */
1623 remote_fork_event_p (struct remote_state
*rs
)
1625 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1628 /* Returns true if vfork events are supported. */
1631 remote_vfork_event_p (struct remote_state
*rs
)
1633 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1636 /* Returns true if exec events are supported. */
1639 remote_exec_event_p (struct remote_state
*rs
)
1641 return packet_support (PACKET_exec_event_feature
) == PACKET_ENABLE
;
1644 /* Insert fork catchpoint target routine. If fork events are enabled
1645 then return success, nothing more to do. */
1648 remote_insert_fork_catchpoint (struct target_ops
*ops
, int pid
)
1650 struct remote_state
*rs
= get_remote_state ();
1652 return !remote_fork_event_p (rs
);
1655 /* Remove fork catchpoint target routine. Nothing to do, just
1659 remote_remove_fork_catchpoint (struct target_ops
*ops
, int pid
)
1664 /* Insert vfork catchpoint target routine. If vfork events are enabled
1665 then return success, nothing more to do. */
1668 remote_insert_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1670 struct remote_state
*rs
= get_remote_state ();
1672 return !remote_vfork_event_p (rs
);
1675 /* Remove vfork catchpoint target routine. Nothing to do, just
1679 remote_remove_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1684 /* Insert exec catchpoint target routine. If exec events are
1685 enabled, just return success. */
1688 remote_insert_exec_catchpoint (struct target_ops
*ops
, int pid
)
1690 struct remote_state
*rs
= get_remote_state ();
1692 return !remote_exec_event_p (rs
);
1695 /* Remove exec catchpoint target routine. Nothing to do, just
1699 remote_remove_exec_catchpoint (struct target_ops
*ops
, int pid
)
1705 /* Asynchronous signal handle registered as event loop source for
1706 when we have pending events ready to be passed to the core. */
1708 static struct async_event_handler
*remote_async_inferior_event_token
;
1712 static ptid_t magic_null_ptid
;
1713 static ptid_t not_sent_ptid
;
1714 static ptid_t any_thread_ptid
;
1716 /* Find out if the stub attached to PID (and hence GDB should offer to
1717 detach instead of killing it when bailing out). */
1720 remote_query_attached (int pid
)
1722 struct remote_state
*rs
= get_remote_state ();
1723 size_t size
= get_remote_packet_size ();
1725 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1728 if (remote_multi_process_p (rs
))
1729 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1731 xsnprintf (rs
->buf
, size
, "qAttached");
1734 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1736 switch (packet_ok (rs
->buf
,
1737 &remote_protocol_packets
[PACKET_qAttached
]))
1740 if (strcmp (rs
->buf
, "1") == 0)
1744 warning (_("Remote failure reply: %s"), rs
->buf
);
1746 case PACKET_UNKNOWN
:
1753 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1754 has been invented by GDB, instead of reported by the target. Since
1755 we can be connected to a remote system before before knowing about
1756 any inferior, mark the target with execution when we find the first
1757 inferior. If ATTACHED is 1, then we had just attached to this
1758 inferior. If it is 0, then we just created this inferior. If it
1759 is -1, then try querying the remote stub to find out if it had
1760 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1761 attempt to open this inferior's executable as the main executable
1762 if no main executable is open already. */
1764 static struct inferior
*
1765 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1768 struct inferior
*inf
;
1770 /* Check whether this process we're learning about is to be
1771 considered attached, or if is to be considered to have been
1772 spawned by the stub. */
1774 attached
= remote_query_attached (pid
);
1776 if (gdbarch_has_global_solist (target_gdbarch ()))
1778 /* If the target shares code across all inferiors, then every
1779 attach adds a new inferior. */
1780 inf
= add_inferior (pid
);
1782 /* ... and every inferior is bound to the same program space.
1783 However, each inferior may still have its own address
1785 inf
->aspace
= maybe_new_address_space ();
1786 inf
->pspace
= current_program_space
;
1790 /* In the traditional debugging scenario, there's a 1-1 match
1791 between program/address spaces. We simply bind the inferior
1792 to the program space's address space. */
1793 inf
= current_inferior ();
1794 inferior_appeared (inf
, pid
);
1797 inf
->attach_flag
= attached
;
1798 inf
->fake_pid_p
= fake_pid_p
;
1800 /* If no main executable is currently open then attempt to
1801 open the file that was executed to create this inferior. */
1802 if (try_open_exec
&& get_exec_file (0) == NULL
)
1803 exec_file_locate_attach (pid
, 1);
1808 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1809 according to RUNNING. */
1812 remote_add_thread (ptid_t ptid
, int running
, int executing
)
1814 struct remote_state
*rs
= get_remote_state ();
1816 /* GDB historically didn't pull threads in the initial connection
1817 setup. If the remote target doesn't even have a concept of
1818 threads (e.g., a bare-metal target), even if internally we
1819 consider that a single-threaded target, mentioning a new thread
1820 might be confusing to the user. Be silent then, preserving the
1821 age old behavior. */
1822 if (rs
->starting_up
)
1823 add_thread_silent (ptid
);
1827 set_executing (ptid
, executing
);
1828 set_running (ptid
, running
);
1831 /* Come here when we learn about a thread id from the remote target.
1832 It may be the first time we hear about such thread, so take the
1833 opportunity to add it to GDB's thread list. In case this is the
1834 first time we're noticing its corresponding inferior, add it to
1835 GDB's inferior list as well. EXECUTING indicates whether the
1836 thread is (internally) executing or stopped. */
1839 remote_notice_new_inferior (ptid_t currthread
, int executing
)
1841 /* In non-stop mode, we assume new found threads are (externally)
1842 running until proven otherwise with a stop reply. In all-stop,
1843 we can only get here if all threads are stopped. */
1844 int running
= target_is_non_stop_p () ? 1 : 0;
1846 /* If this is a new thread, add it to GDB's thread list.
1847 If we leave it up to WFI to do this, bad things will happen. */
1849 if (in_thread_list (currthread
) && is_exited (currthread
))
1851 /* We're seeing an event on a thread id we knew had exited.
1852 This has to be a new thread reusing the old id. Add it. */
1853 remote_add_thread (currthread
, running
, executing
);
1857 if (!in_thread_list (currthread
))
1859 struct inferior
*inf
= NULL
;
1860 int pid
= ptid_get_pid (currthread
);
1862 if (ptid_is_pid (inferior_ptid
)
1863 && pid
== ptid_get_pid (inferior_ptid
))
1865 /* inferior_ptid has no thread member yet. This can happen
1866 with the vAttach -> remote_wait,"TAAthread:" path if the
1867 stub doesn't support qC. This is the first stop reported
1868 after an attach, so this is the main thread. Update the
1869 ptid in the thread list. */
1870 if (in_thread_list (pid_to_ptid (pid
)))
1871 thread_change_ptid (inferior_ptid
, currthread
);
1874 remote_add_thread (currthread
, running
, executing
);
1875 inferior_ptid
= currthread
;
1880 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1882 /* inferior_ptid is not set yet. This can happen with the
1883 vRun -> remote_wait,"TAAthread:" path if the stub
1884 doesn't support qC. This is the first stop reported
1885 after an attach, so this is the main thread. Update the
1886 ptid in the thread list. */
1887 thread_change_ptid (inferior_ptid
, currthread
);
1891 /* When connecting to a target remote, or to a target
1892 extended-remote which already was debugging an inferior, we
1893 may not know about it yet. Add it before adding its child
1894 thread, so notifications are emitted in a sensible order. */
1895 if (!in_inferior_list (ptid_get_pid (currthread
)))
1897 struct remote_state
*rs
= get_remote_state ();
1898 int fake_pid_p
= !remote_multi_process_p (rs
);
1900 inf
= remote_add_inferior (fake_pid_p
,
1901 ptid_get_pid (currthread
), -1, 1);
1904 /* This is really a new thread. Add it. */
1905 remote_add_thread (currthread
, running
, executing
);
1907 /* If we found a new inferior, let the common code do whatever
1908 it needs to with it (e.g., read shared libraries, insert
1909 breakpoints), unless we're just setting up an all-stop
1913 struct remote_state
*rs
= get_remote_state ();
1915 if (!rs
->starting_up
)
1916 notice_new_inferior (currthread
, executing
, 0);
1921 /* Return the private thread data, creating it if necessary. */
1923 static struct private_thread_info
*
1924 demand_private_info (ptid_t ptid
)
1926 struct thread_info
*info
= find_thread_ptid (ptid
);
1932 info
->priv
= XNEW (struct private_thread_info
);
1933 info
->private_dtor
= free_private_thread_info
;
1934 info
->priv
->core
= -1;
1935 info
->priv
->extra
= NULL
;
1936 info
->priv
->name
= NULL
;
1942 /* Call this function as a result of
1943 1) A halt indication (T packet) containing a thread id
1944 2) A direct query of currthread
1945 3) Successful execution of set thread */
1948 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1950 rs
->general_thread
= currthread
;
1953 /* If 'QPassSignals' is supported, tell the remote stub what signals
1954 it can simply pass through to the inferior without reporting. */
1957 remote_pass_signals (struct target_ops
*self
,
1958 int numsigs
, unsigned char *pass_signals
)
1960 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1962 char *pass_packet
, *p
;
1964 struct remote_state
*rs
= get_remote_state ();
1966 gdb_assert (numsigs
< 256);
1967 for (i
= 0; i
< numsigs
; i
++)
1969 if (pass_signals
[i
])
1972 pass_packet
= (char *) xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1973 strcpy (pass_packet
, "QPassSignals:");
1974 p
= pass_packet
+ strlen (pass_packet
);
1975 for (i
= 0; i
< numsigs
; i
++)
1977 if (pass_signals
[i
])
1980 *p
++ = tohex (i
>> 4);
1981 *p
++ = tohex (i
& 15);
1990 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1992 putpkt (pass_packet
);
1993 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1994 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1995 if (rs
->last_pass_packet
)
1996 xfree (rs
->last_pass_packet
);
1997 rs
->last_pass_packet
= pass_packet
;
2000 xfree (pass_packet
);
2004 /* If 'QCatchSyscalls' is supported, tell the remote stub
2005 to report syscalls to GDB. */
2008 remote_set_syscall_catchpoint (struct target_ops
*self
,
2009 int pid
, int needed
, int any_count
,
2010 int table_size
, int *table
)
2013 enum packet_result result
;
2016 if (packet_support (PACKET_QCatchSyscalls
) == PACKET_DISABLE
)
2018 /* Not supported. */
2022 if (needed
&& !any_count
)
2026 /* Count how many syscalls are to be caught (table[sysno] != 0). */
2027 for (i
= 0; i
< table_size
; i
++)
2036 fprintf_unfiltered (gdb_stdlog
,
2037 "remote_set_syscall_catchpoint "
2038 "pid %d needed %d any_count %d n_sysno %d\n",
2039 pid
, needed
, any_count
, n_sysno
);
2044 /* Prepare a packet with the sysno list, assuming max 8+1
2045 characters for a sysno. If the resulting packet size is too
2046 big, fallback on the non-selective packet. */
2047 const int maxpktsz
= strlen ("QCatchSyscalls:1") + n_sysno
* 9 + 1;
2049 catch_packet
= (char *) xmalloc (maxpktsz
);
2050 strcpy (catch_packet
, "QCatchSyscalls:1");
2059 /* Add in catch_packet each syscall to be caught (table[i] != 0). */
2060 for (i
= 0; i
< table_size
; i
++)
2063 p
+= xsnprintf (p
, catch_packet
+ maxpktsz
- p
, ";%x", i
);
2066 if (strlen (catch_packet
) > get_remote_packet_size ())
2068 /* catch_packet too big. Fallback to less efficient
2069 non selective mode, with GDB doing the filtering. */
2070 catch_packet
[sizeof ("QCatchSyscalls:1") - 1] = 0;
2074 catch_packet
= xstrdup ("QCatchSyscalls:0");
2077 struct cleanup
*old_chain
= make_cleanup (xfree
, catch_packet
);
2078 struct remote_state
*rs
= get_remote_state ();
2080 putpkt (catch_packet
);
2081 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2082 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QCatchSyscalls
]);
2083 do_cleanups (old_chain
);
2084 if (result
== PACKET_OK
)
2091 /* If 'QProgramSignals' is supported, tell the remote stub what
2092 signals it should pass through to the inferior when detaching. */
2095 remote_program_signals (struct target_ops
*self
,
2096 int numsigs
, unsigned char *signals
)
2098 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
2102 struct remote_state
*rs
= get_remote_state ();
2104 gdb_assert (numsigs
< 256);
2105 for (i
= 0; i
< numsigs
; i
++)
2110 packet
= (char *) xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
2111 strcpy (packet
, "QProgramSignals:");
2112 p
= packet
+ strlen (packet
);
2113 for (i
= 0; i
< numsigs
; i
++)
2115 if (signal_pass_state (i
))
2118 *p
++ = tohex (i
>> 4);
2119 *p
++ = tohex (i
& 15);
2128 if (!rs
->last_program_signals_packet
2129 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
2132 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2133 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
2134 xfree (rs
->last_program_signals_packet
);
2135 rs
->last_program_signals_packet
= packet
;
2142 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
2143 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
2144 thread. If GEN is set, set the general thread, if not, then set
2145 the step/continue thread. */
2147 set_thread (struct ptid ptid
, int gen
)
2149 struct remote_state
*rs
= get_remote_state ();
2150 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
2151 char *buf
= rs
->buf
;
2152 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
2154 if (ptid_equal (state
, ptid
))
2158 *buf
++ = gen
? 'g' : 'c';
2159 if (ptid_equal (ptid
, magic_null_ptid
))
2160 xsnprintf (buf
, endbuf
- buf
, "0");
2161 else if (ptid_equal (ptid
, any_thread_ptid
))
2162 xsnprintf (buf
, endbuf
- buf
, "0");
2163 else if (ptid_equal (ptid
, minus_one_ptid
))
2164 xsnprintf (buf
, endbuf
- buf
, "-1");
2166 write_ptid (buf
, endbuf
, ptid
);
2168 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2170 rs
->general_thread
= ptid
;
2172 rs
->continue_thread
= ptid
;
2176 set_general_thread (struct ptid ptid
)
2178 set_thread (ptid
, 1);
2182 set_continue_thread (struct ptid ptid
)
2184 set_thread (ptid
, 0);
2187 /* Change the remote current process. Which thread within the process
2188 ends up selected isn't important, as long as it is the same process
2189 as what INFERIOR_PTID points to.
2191 This comes from that fact that there is no explicit notion of
2192 "selected process" in the protocol. The selected process for
2193 general operations is the process the selected general thread
2197 set_general_process (void)
2199 struct remote_state
*rs
= get_remote_state ();
2201 /* If the remote can't handle multiple processes, don't bother. */
2202 if (!remote_multi_process_p (rs
))
2205 /* We only need to change the remote current thread if it's pointing
2206 at some other process. */
2207 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
2208 set_general_thread (inferior_ptid
);
2212 /* Return nonzero if this is the main thread that we made up ourselves
2213 to model non-threaded targets as single-threaded. */
2216 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
2218 if (ptid_equal (ptid
, magic_null_ptid
))
2219 /* The main thread is always alive. */
2222 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
2223 /* The main thread is always alive. This can happen after a
2224 vAttach, if the remote side doesn't support
2231 /* Return nonzero if the thread PTID is still alive on the remote
2235 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
2237 struct remote_state
*rs
= get_remote_state ();
2240 /* Check if this is a thread that we made up ourselves to model
2241 non-threaded targets as single-threaded. */
2242 if (remote_thread_always_alive (ops
, ptid
))
2246 endp
= rs
->buf
+ get_remote_packet_size ();
2249 write_ptid (p
, endp
, ptid
);
2252 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2253 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2256 /* Return a pointer to a thread name if we know it and NULL otherwise.
2257 The thread_info object owns the memory for the name. */
2260 remote_thread_name (struct target_ops
*ops
, struct thread_info
*info
)
2262 if (info
->priv
!= NULL
)
2263 return info
->priv
->name
;
2268 /* About these extended threadlist and threadinfo packets. They are
2269 variable length packets but, the fields within them are often fixed
2270 length. They are redundent enough to send over UDP as is the
2271 remote protocol in general. There is a matching unit test module
2274 /* WARNING: This threadref data structure comes from the remote O.S.,
2275 libstub protocol encoding, and remote.c. It is not particularly
2278 /* Right now, the internal structure is int. We want it to be bigger.
2279 Plan to fix this. */
2281 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2283 /* gdb_ext_thread_info is an internal GDB data structure which is
2284 equivalent to the reply of the remote threadinfo packet. */
2286 struct gdb_ext_thread_info
2288 threadref threadid
; /* External form of thread reference. */
2289 int active
; /* Has state interesting to GDB?
2291 char display
[256]; /* Brief state display, name,
2292 blocked/suspended. */
2293 char shortname
[32]; /* To be used to name threads. */
2294 char more_display
[256]; /* Long info, statistics, queue depth,
2298 /* The volume of remote transfers can be limited by submitting
2299 a mask containing bits specifying the desired information.
2300 Use a union of these values as the 'selection' parameter to
2301 get_thread_info. FIXME: Make these TAG names more thread specific. */
2303 #define TAG_THREADID 1
2304 #define TAG_EXISTS 2
2305 #define TAG_DISPLAY 4
2306 #define TAG_THREADNAME 8
2307 #define TAG_MOREDISPLAY 16
2309 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2311 static char *unpack_nibble (char *buf
, int *val
);
2313 static char *unpack_byte (char *buf
, int *value
);
2315 static char *pack_int (char *buf
, int value
);
2317 static char *unpack_int (char *buf
, int *value
);
2319 static char *unpack_string (char *src
, char *dest
, int length
);
2321 static char *pack_threadid (char *pkt
, threadref
*id
);
2323 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2325 void int_to_threadref (threadref
*id
, int value
);
2327 static int threadref_to_int (threadref
*ref
);
2329 static void copy_threadref (threadref
*dest
, threadref
*src
);
2331 static int threadmatch (threadref
*dest
, threadref
*src
);
2333 static char *pack_threadinfo_request (char *pkt
, int mode
,
2336 static int remote_unpack_thread_info_response (char *pkt
,
2337 threadref
*expectedref
,
2338 struct gdb_ext_thread_info
2342 static int remote_get_threadinfo (threadref
*threadid
,
2343 int fieldset
, /*TAG mask */
2344 struct gdb_ext_thread_info
*info
);
2346 static char *pack_threadlist_request (char *pkt
, int startflag
,
2348 threadref
*nextthread
);
2350 static int parse_threadlist_response (char *pkt
,
2352 threadref
*original_echo
,
2353 threadref
*resultlist
,
2356 static int remote_get_threadlist (int startflag
,
2357 threadref
*nextthread
,
2361 threadref
*threadlist
);
2363 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2365 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2366 void *context
, int looplimit
);
2368 static int remote_newthread_step (threadref
*ref
, void *context
);
2371 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2372 buffer we're allowed to write to. Returns
2373 BUF+CHARACTERS_WRITTEN. */
2376 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2379 struct remote_state
*rs
= get_remote_state ();
2381 if (remote_multi_process_p (rs
))
2383 pid
= ptid_get_pid (ptid
);
2385 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2387 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2389 tid
= ptid_get_lwp (ptid
);
2391 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2393 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2398 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2399 passed the last parsed char. Returns null_ptid on error. */
2402 read_ptid (char *buf
, char **obuf
)
2406 ULONGEST pid
= 0, tid
= 0;
2410 /* Multi-process ptid. */
2411 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2413 error (_("invalid remote ptid: %s"), p
);
2416 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2419 return ptid_build (pid
, tid
, 0);
2422 /* No multi-process. Just a tid. */
2423 pp
= unpack_varlen_hex (p
, &tid
);
2425 /* Return null_ptid when no thread id is found. */
2433 /* Since the stub is not sending a process id, then default to
2434 what's in inferior_ptid, unless it's null at this point. If so,
2435 then since there's no way to know the pid of the reported
2436 threads, use the magic number. */
2437 if (ptid_equal (inferior_ptid
, null_ptid
))
2438 pid
= ptid_get_pid (magic_null_ptid
);
2440 pid
= ptid_get_pid (inferior_ptid
);
2444 return ptid_build (pid
, tid
, 0);
2450 if (ch
>= 'a' && ch
<= 'f')
2451 return ch
- 'a' + 10;
2452 if (ch
>= '0' && ch
<= '9')
2454 if (ch
>= 'A' && ch
<= 'F')
2455 return ch
- 'A' + 10;
2460 stub_unpack_int (char *buff
, int fieldlength
)
2467 nibble
= stubhex (*buff
++);
2471 retval
= retval
<< 4;
2477 unpack_nibble (char *buf
, int *val
)
2479 *val
= fromhex (*buf
++);
2484 unpack_byte (char *buf
, int *value
)
2486 *value
= stub_unpack_int (buf
, 2);
2491 pack_int (char *buf
, int value
)
2493 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2494 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2495 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2496 buf
= pack_hex_byte (buf
, (value
& 0xff));
2501 unpack_int (char *buf
, int *value
)
2503 *value
= stub_unpack_int (buf
, 8);
2507 #if 0 /* Currently unused, uncomment when needed. */
2508 static char *pack_string (char *pkt
, char *string
);
2511 pack_string (char *pkt
, char *string
)
2516 len
= strlen (string
);
2518 len
= 200; /* Bigger than most GDB packets, junk??? */
2519 pkt
= pack_hex_byte (pkt
, len
);
2523 if ((ch
== '\0') || (ch
== '#'))
2524 ch
= '*'; /* Protect encapsulation. */
2529 #endif /* 0 (unused) */
2532 unpack_string (char *src
, char *dest
, int length
)
2541 pack_threadid (char *pkt
, threadref
*id
)
2544 unsigned char *altid
;
2546 altid
= (unsigned char *) id
;
2547 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2549 pkt
= pack_hex_byte (pkt
, *altid
++);
2555 unpack_threadid (char *inbuf
, threadref
*id
)
2558 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2561 altref
= (char *) id
;
2563 while (inbuf
< limit
)
2565 x
= stubhex (*inbuf
++);
2566 y
= stubhex (*inbuf
++);
2567 *altref
++ = (x
<< 4) | y
;
2572 /* Externally, threadrefs are 64 bits but internally, they are still
2573 ints. This is due to a mismatch of specifications. We would like
2574 to use 64bit thread references internally. This is an adapter
2578 int_to_threadref (threadref
*id
, int value
)
2580 unsigned char *scan
;
2582 scan
= (unsigned char *) id
;
2588 *scan
++ = (value
>> 24) & 0xff;
2589 *scan
++ = (value
>> 16) & 0xff;
2590 *scan
++ = (value
>> 8) & 0xff;
2591 *scan
++ = (value
& 0xff);
2595 threadref_to_int (threadref
*ref
)
2598 unsigned char *scan
;
2604 value
= (value
<< 8) | ((*scan
++) & 0xff);
2609 copy_threadref (threadref
*dest
, threadref
*src
)
2612 unsigned char *csrc
, *cdest
;
2614 csrc
= (unsigned char *) src
;
2615 cdest
= (unsigned char *) dest
;
2622 threadmatch (threadref
*dest
, threadref
*src
)
2624 /* Things are broken right now, so just assume we got a match. */
2626 unsigned char *srcp
, *destp
;
2628 srcp
= (char *) src
;
2629 destp
= (char *) dest
;
2633 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2640 threadid:1, # always request threadid
2647 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2650 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2652 *pkt
++ = 'q'; /* Info Query */
2653 *pkt
++ = 'P'; /* process or thread info */
2654 pkt
= pack_int (pkt
, mode
); /* mode */
2655 pkt
= pack_threadid (pkt
, id
); /* threadid */
2656 *pkt
= '\0'; /* terminate */
2660 /* These values tag the fields in a thread info response packet. */
2661 /* Tagging the fields allows us to request specific fields and to
2662 add more fields as time goes by. */
2664 #define TAG_THREADID 1 /* Echo the thread identifier. */
2665 #define TAG_EXISTS 2 /* Is this process defined enough to
2666 fetch registers and its stack? */
2667 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2668 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2669 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2673 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2674 struct gdb_ext_thread_info
*info
)
2676 struct remote_state
*rs
= get_remote_state ();
2680 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2683 /* info->threadid = 0; FIXME: implement zero_threadref. */
2685 info
->display
[0] = '\0';
2686 info
->shortname
[0] = '\0';
2687 info
->more_display
[0] = '\0';
2689 /* Assume the characters indicating the packet type have been
2691 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2692 pkt
= unpack_threadid (pkt
, &ref
);
2695 warning (_("Incomplete response to threadinfo request."));
2696 if (!threadmatch (&ref
, expectedref
))
2697 { /* This is an answer to a different request. */
2698 warning (_("ERROR RMT Thread info mismatch."));
2701 copy_threadref (&info
->threadid
, &ref
);
2703 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2705 /* Packets are terminated with nulls. */
2706 while ((pkt
< limit
) && mask
&& *pkt
)
2708 pkt
= unpack_int (pkt
, &tag
); /* tag */
2709 pkt
= unpack_byte (pkt
, &length
); /* length */
2710 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2712 warning (_("ERROR RMT: threadinfo tag mismatch."));
2716 if (tag
== TAG_THREADID
)
2720 warning (_("ERROR RMT: length of threadid is not 16."));
2724 pkt
= unpack_threadid (pkt
, &ref
);
2725 mask
= mask
& ~TAG_THREADID
;
2728 if (tag
== TAG_EXISTS
)
2730 info
->active
= stub_unpack_int (pkt
, length
);
2732 mask
= mask
& ~(TAG_EXISTS
);
2735 warning (_("ERROR RMT: 'exists' length too long."));
2741 if (tag
== TAG_THREADNAME
)
2743 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2744 mask
= mask
& ~TAG_THREADNAME
;
2747 if (tag
== TAG_DISPLAY
)
2749 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2750 mask
= mask
& ~TAG_DISPLAY
;
2753 if (tag
== TAG_MOREDISPLAY
)
2755 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2756 mask
= mask
& ~TAG_MOREDISPLAY
;
2759 warning (_("ERROR RMT: unknown thread info tag."));
2760 break; /* Not a tag we know about. */
2766 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2767 struct gdb_ext_thread_info
*info
)
2769 struct remote_state
*rs
= get_remote_state ();
2772 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2774 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2776 if (rs
->buf
[0] == '\0')
2779 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2784 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2787 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2788 threadref
*nextthread
)
2790 *pkt
++ = 'q'; /* info query packet */
2791 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2792 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2793 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2794 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2799 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2802 parse_threadlist_response (char *pkt
, int result_limit
,
2803 threadref
*original_echo
, threadref
*resultlist
,
2806 struct remote_state
*rs
= get_remote_state ();
2808 int count
, resultcount
, done
;
2811 /* Assume the 'q' and 'M chars have been stripped. */
2812 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2813 /* done parse past here */
2814 pkt
= unpack_byte (pkt
, &count
); /* count field */
2815 pkt
= unpack_nibble (pkt
, &done
);
2816 /* The first threadid is the argument threadid. */
2817 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2818 while ((count
-- > 0) && (pkt
< limit
))
2820 pkt
= unpack_threadid (pkt
, resultlist
++);
2821 if (resultcount
++ >= result_limit
)
2829 /* Fetch the next batch of threads from the remote. Returns -1 if the
2830 qL packet is not supported, 0 on error and 1 on success. */
2833 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2834 int *done
, int *result_count
, threadref
*threadlist
)
2836 struct remote_state
*rs
= get_remote_state ();
2839 /* Trancate result limit to be smaller than the packet size. */
2840 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2841 >= get_remote_packet_size ())
2842 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2844 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2846 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2847 if (*rs
->buf
== '\0')
2849 /* Packet not supported. */
2854 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2855 &rs
->echo_nextthread
, threadlist
, done
);
2857 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2859 /* FIXME: This is a good reason to drop the packet. */
2860 /* Possably, there is a duplicate response. */
2862 retransmit immediatly - race conditions
2863 retransmit after timeout - yes
2865 wait for packet, then exit
2867 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2868 return 0; /* I choose simply exiting. */
2870 if (*result_count
<= 0)
2874 warning (_("RMT ERROR : failed to get remote thread list."));
2877 return result
; /* break; */
2879 if (*result_count
> result_limit
)
2882 warning (_("RMT ERROR: threadlist response longer than requested."));
2888 /* Fetch the list of remote threads, with the qL packet, and call
2889 STEPFUNCTION for each thread found. Stops iterating and returns 1
2890 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2891 STEPFUNCTION returns false. If the packet is not supported,
2895 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2898 struct remote_state
*rs
= get_remote_state ();
2899 int done
, i
, result_count
;
2907 if (loopcount
++ > looplimit
)
2910 warning (_("Remote fetch threadlist -infinite loop-."));
2913 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2914 MAXTHREADLISTRESULTS
,
2915 &done
, &result_count
,
2916 rs
->resultthreadlist
);
2919 /* Clear for later iterations. */
2921 /* Setup to resume next batch of thread references, set nextthread. */
2922 if (result_count
>= 1)
2923 copy_threadref (&rs
->nextthread
,
2924 &rs
->resultthreadlist
[result_count
- 1]);
2926 while (result_count
--)
2928 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2938 /* A thread found on the remote target. */
2940 typedef struct thread_item
2942 /* The thread's PTID. */
2945 /* The thread's extra info. May be NULL. */
2948 /* The thread's name. May be NULL. */
2951 /* The core the thread was running on. -1 if not known. */
2954 DEF_VEC_O(thread_item_t
);
2956 /* Context passed around to the various methods listing remote
2957 threads. As new threads are found, they're added to the ITEMS
2960 struct threads_listing_context
2962 /* The threads found on the remote target. */
2963 VEC (thread_item_t
) *items
;
2966 /* Discard the contents of the constructed thread listing context. */
2969 clear_threads_listing_context (void *p
)
2971 struct threads_listing_context
*context
2972 = (struct threads_listing_context
*) p
;
2974 struct thread_item
*item
;
2976 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2978 xfree (item
->extra
);
2982 VEC_free (thread_item_t
, context
->items
);
2985 /* Remove the thread specified as the related_pid field of WS
2986 from the CONTEXT list. */
2989 threads_listing_context_remove (struct target_waitstatus
*ws
,
2990 struct threads_listing_context
*context
)
2992 struct thread_item
*item
;
2994 ptid_t child_ptid
= ws
->value
.related_pid
;
2996 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2998 if (ptid_equal (item
->ptid
, child_ptid
))
3000 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
3007 remote_newthread_step (threadref
*ref
, void *data
)
3009 struct threads_listing_context
*context
3010 = (struct threads_listing_context
*) data
;
3011 struct thread_item item
;
3012 int pid
= ptid_get_pid (inferior_ptid
);
3014 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
3019 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3021 return 1; /* continue iterator */
3024 #define CRAZY_MAX_THREADS 1000
3027 remote_current_thread (ptid_t oldpid
)
3029 struct remote_state
*rs
= get_remote_state ();
3032 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3033 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
3038 result
= read_ptid (&rs
->buf
[2], &obuf
);
3039 if (*obuf
!= '\0' && remote_debug
)
3040 fprintf_unfiltered (gdb_stdlog
,
3041 "warning: garbage in qC reply\n");
3049 /* List remote threads using the deprecated qL packet. */
3052 remote_get_threads_with_ql (struct target_ops
*ops
,
3053 struct threads_listing_context
*context
)
3055 if (remote_threadlist_iterator (remote_newthread_step
, context
,
3056 CRAZY_MAX_THREADS
) >= 0)
3062 #if defined(HAVE_LIBEXPAT)
3065 start_thread (struct gdb_xml_parser
*parser
,
3066 const struct gdb_xml_element
*element
,
3067 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
3069 struct threads_listing_context
*data
3070 = (struct threads_listing_context
*) user_data
;
3072 struct thread_item item
;
3074 struct gdb_xml_value
*attr
;
3076 id
= (char *) xml_find_attribute (attributes
, "id")->value
;
3077 item
.ptid
= read_ptid (id
, NULL
);
3079 attr
= xml_find_attribute (attributes
, "core");
3081 item
.core
= *(ULONGEST
*) attr
->value
;
3085 attr
= xml_find_attribute (attributes
, "name");
3086 item
.name
= attr
!= NULL
? xstrdup ((const char *) attr
->value
) : NULL
;
3090 VEC_safe_push (thread_item_t
, data
->items
, &item
);
3094 end_thread (struct gdb_xml_parser
*parser
,
3095 const struct gdb_xml_element
*element
,
3096 void *user_data
, const char *body_text
)
3098 struct threads_listing_context
*data
3099 = (struct threads_listing_context
*) user_data
;
3101 if (body_text
&& *body_text
)
3102 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
3105 const struct gdb_xml_attribute thread_attributes
[] = {
3106 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
3107 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
3108 { "name", GDB_XML_AF_OPTIONAL
, NULL
, NULL
},
3109 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
3112 const struct gdb_xml_element thread_children
[] = {
3113 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3116 const struct gdb_xml_element threads_children
[] = {
3117 { "thread", thread_attributes
, thread_children
,
3118 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
3119 start_thread
, end_thread
},
3120 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3123 const struct gdb_xml_element threads_elements
[] = {
3124 { "threads", NULL
, threads_children
,
3125 GDB_XML_EF_NONE
, NULL
, NULL
},
3126 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3131 /* List remote threads using qXfer:threads:read. */
3134 remote_get_threads_with_qxfer (struct target_ops
*ops
,
3135 struct threads_listing_context
*context
)
3137 #if defined(HAVE_LIBEXPAT)
3138 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3140 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
3141 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
3143 if (xml
!= NULL
&& *xml
!= '\0')
3145 gdb_xml_parse_quick (_("threads"), "threads.dtd",
3146 threads_elements
, xml
, context
);
3149 do_cleanups (back_to
);
3157 /* List remote threads using qfThreadInfo/qsThreadInfo. */
3160 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
3161 struct threads_listing_context
*context
)
3163 struct remote_state
*rs
= get_remote_state ();
3165 if (rs
->use_threadinfo_query
)
3169 putpkt ("qfThreadInfo");
3170 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3172 if (bufp
[0] != '\0') /* q packet recognized */
3174 while (*bufp
++ == 'm') /* reply contains one or more TID */
3178 struct thread_item item
;
3180 item
.ptid
= read_ptid (bufp
, &bufp
);
3185 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3187 while (*bufp
++ == ','); /* comma-separated list */
3188 putpkt ("qsThreadInfo");
3189 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3196 /* Packet not recognized. */
3197 rs
->use_threadinfo_query
= 0;
3204 /* Implement the to_update_thread_list function for the remote
3208 remote_update_thread_list (struct target_ops
*ops
)
3210 struct threads_listing_context context
;
3211 struct cleanup
*old_chain
;
3214 context
.items
= NULL
;
3215 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
3217 /* We have a few different mechanisms to fetch the thread list. Try
3218 them all, starting with the most preferred one first, falling
3219 back to older methods. */
3220 if (remote_get_threads_with_qxfer (ops
, &context
)
3221 || remote_get_threads_with_qthreadinfo (ops
, &context
)
3222 || remote_get_threads_with_ql (ops
, &context
))
3225 struct thread_item
*item
;
3226 struct thread_info
*tp
, *tmp
;
3230 if (VEC_empty (thread_item_t
, context
.items
)
3231 && remote_thread_always_alive (ops
, inferior_ptid
))
3233 /* Some targets don't really support threads, but still
3234 reply an (empty) thread list in response to the thread
3235 listing packets, instead of replying "packet not
3236 supported". Exit early so we don't delete the main
3238 do_cleanups (old_chain
);
3242 /* CONTEXT now holds the current thread list on the remote
3243 target end. Delete GDB-side threads no longer found on the
3245 ALL_THREADS_SAFE (tp
, tmp
)
3248 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3251 if (ptid_equal (item
->ptid
, tp
->ptid
))
3255 if (i
== VEC_length (thread_item_t
, context
.items
))
3258 delete_thread (tp
->ptid
);
3262 /* Remove any unreported fork child threads from CONTEXT so
3263 that we don't interfere with follow fork, which is where
3264 creation of such threads is handled. */
3265 remove_new_fork_children (&context
);
3267 /* And now add threads we don't know about yet to our list. */
3269 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3272 if (!ptid_equal (item
->ptid
, null_ptid
))
3274 struct private_thread_info
*info
;
3275 /* In non-stop mode, we assume new found threads are
3276 executing until proven otherwise with a stop reply.
3277 In all-stop, we can only get here if all threads are
3279 int executing
= target_is_non_stop_p () ? 1 : 0;
3281 remote_notice_new_inferior (item
->ptid
, executing
);
3283 info
= demand_private_info (item
->ptid
);
3284 info
->core
= item
->core
;
3285 info
->extra
= item
->extra
;
3287 info
->name
= item
->name
;
3295 /* If no thread listing method is supported, then query whether
3296 each known thread is alive, one by one, with the T packet.
3297 If the target doesn't support threads at all, then this is a
3298 no-op. See remote_thread_alive. */
3302 do_cleanups (old_chain
);
3306 * Collect a descriptive string about the given thread.
3307 * The target may say anything it wants to about the thread
3308 * (typically info about its blocked / runnable state, name, etc.).
3309 * This string will appear in the info threads display.
3311 * Optional: targets are not required to implement this function.
3315 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3317 struct remote_state
*rs
= get_remote_state ();
3321 struct gdb_ext_thread_info threadinfo
;
3322 static char display_buf
[100]; /* arbitrary... */
3323 int n
= 0; /* position in display_buf */
3325 if (rs
->remote_desc
== 0) /* paranoia */
3326 internal_error (__FILE__
, __LINE__
,
3327 _("remote_threads_extra_info"));
3329 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3330 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3331 /* This is the main thread which was added by GDB. The remote
3332 server doesn't know about it. */
3335 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3337 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3339 if (info
&& info
->priv
)
3340 return info
->priv
->extra
;
3345 if (rs
->use_threadextra_query
)
3348 char *endb
= rs
->buf
+ get_remote_packet_size ();
3350 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3352 write_ptid (b
, endb
, tp
->ptid
);
3355 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3356 if (rs
->buf
[0] != 0)
3358 n
= std::min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3359 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3360 display_buf
[result
] = '\0';
3365 /* If the above query fails, fall back to the old method. */
3366 rs
->use_threadextra_query
= 0;
3367 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3368 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3369 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3370 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3371 if (threadinfo
.active
)
3373 if (*threadinfo
.shortname
)
3374 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3375 " Name: %s,", threadinfo
.shortname
);
3376 if (*threadinfo
.display
)
3377 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3378 " State: %s,", threadinfo
.display
);
3379 if (*threadinfo
.more_display
)
3380 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3381 " Priority: %s", threadinfo
.more_display
);
3385 /* For purely cosmetic reasons, clear up trailing commas. */
3386 if (',' == display_buf
[n
-1])
3387 display_buf
[n
-1] = ' ';
3396 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3397 struct static_tracepoint_marker
*marker
)
3399 struct remote_state
*rs
= get_remote_state ();
3402 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3404 p
+= hexnumstr (p
, addr
);
3406 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3410 error (_("Remote failure reply: %s"), p
);
3414 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3421 static VEC(static_tracepoint_marker_p
) *
3422 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3425 struct remote_state
*rs
= get_remote_state ();
3426 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3427 struct static_tracepoint_marker
*marker
= NULL
;
3428 struct cleanup
*old_chain
;
3431 /* Ask for a first packet of static tracepoint marker
3434 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3437 error (_("Remote failure reply: %s"), p
);
3439 old_chain
= make_cleanup (free_current_marker
, &marker
);
3444 marker
= XCNEW (struct static_tracepoint_marker
);
3448 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3450 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3452 VEC_safe_push (static_tracepoint_marker_p
,
3458 release_static_tracepoint_marker (marker
);
3459 memset (marker
, 0, sizeof (*marker
));
3462 while (*p
++ == ','); /* comma-separated list */
3463 /* Ask for another packet of static tracepoint definition. */
3465 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3469 do_cleanups (old_chain
);
3474 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3477 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3479 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3483 /* Restart the remote side; this is an extended protocol operation. */
3486 extended_remote_restart (void)
3488 struct remote_state
*rs
= get_remote_state ();
3490 /* Send the restart command; for reasons I don't understand the
3491 remote side really expects a number after the "R". */
3492 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3495 remote_fileio_reset ();
3498 /* Clean up connection to a remote debugger. */
3501 remote_close (struct target_ops
*self
)
3503 struct remote_state
*rs
= get_remote_state ();
3505 if (rs
->remote_desc
== NULL
)
3506 return; /* already closed */
3508 /* Make sure we leave stdin registered in the event loop. */
3509 remote_terminal_ours (self
);
3511 serial_close (rs
->remote_desc
);
3512 rs
->remote_desc
= NULL
;
3514 /* We don't have a connection to the remote stub anymore. Get rid
3515 of all the inferiors and their threads we were controlling.
3516 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3517 will be unable to find the thread corresponding to (pid, 0, 0). */
3518 inferior_ptid
= null_ptid
;
3519 discard_all_inferiors ();
3521 /* We are closing the remote target, so we should discard
3522 everything of this target. */
3523 discard_pending_stop_replies_in_queue (rs
);
3525 if (remote_async_inferior_event_token
)
3526 delete_async_event_handler (&remote_async_inferior_event_token
);
3528 remote_notif_state_xfree (rs
->notif_state
);
3530 trace_reset_local_state ();
3533 /* Query the remote side for the text, data and bss offsets. */
3538 struct remote_state
*rs
= get_remote_state ();
3541 int lose
, num_segments
= 0, do_sections
, do_segments
;
3542 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3543 struct section_offsets
*offs
;
3544 struct symfile_segment_data
*data
;
3546 if (symfile_objfile
== NULL
)
3549 putpkt ("qOffsets");
3550 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3553 if (buf
[0] == '\000')
3554 return; /* Return silently. Stub doesn't support
3558 warning (_("Remote failure reply: %s"), buf
);
3562 /* Pick up each field in turn. This used to be done with scanf, but
3563 scanf will make trouble if CORE_ADDR size doesn't match
3564 conversion directives correctly. The following code will work
3565 with any size of CORE_ADDR. */
3566 text_addr
= data_addr
= bss_addr
= 0;
3570 if (startswith (ptr
, "Text="))
3573 /* Don't use strtol, could lose on big values. */
3574 while (*ptr
&& *ptr
!= ';')
3575 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3577 if (startswith (ptr
, ";Data="))
3580 while (*ptr
&& *ptr
!= ';')
3581 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3586 if (!lose
&& startswith (ptr
, ";Bss="))
3589 while (*ptr
&& *ptr
!= ';')
3590 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3592 if (bss_addr
!= data_addr
)
3593 warning (_("Target reported unsupported offsets: %s"), buf
);
3598 else if (startswith (ptr
, "TextSeg="))
3601 /* Don't use strtol, could lose on big values. */
3602 while (*ptr
&& *ptr
!= ';')
3603 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3606 if (startswith (ptr
, ";DataSeg="))
3609 while (*ptr
&& *ptr
!= ';')
3610 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3618 error (_("Malformed response to offset query, %s"), buf
);
3619 else if (*ptr
!= '\0')
3620 warning (_("Target reported unsupported offsets: %s"), buf
);
3622 offs
= ((struct section_offsets
*)
3623 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3624 memcpy (offs
, symfile_objfile
->section_offsets
,
3625 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3627 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3628 do_segments
= (data
!= NULL
);
3629 do_sections
= num_segments
== 0;
3631 if (num_segments
> 0)
3633 segments
[0] = text_addr
;
3634 segments
[1] = data_addr
;
3636 /* If we have two segments, we can still try to relocate everything
3637 by assuming that the .text and .data offsets apply to the whole
3638 text and data segments. Convert the offsets given in the packet
3639 to base addresses for symfile_map_offsets_to_segments. */
3640 else if (data
&& data
->num_segments
== 2)
3642 segments
[0] = data
->segment_bases
[0] + text_addr
;
3643 segments
[1] = data
->segment_bases
[1] + data_addr
;
3646 /* If the object file has only one segment, assume that it is text
3647 rather than data; main programs with no writable data are rare,
3648 but programs with no code are useless. Of course the code might
3649 have ended up in the data segment... to detect that we would need
3650 the permissions here. */
3651 else if (data
&& data
->num_segments
== 1)
3653 segments
[0] = data
->segment_bases
[0] + text_addr
;
3656 /* There's no way to relocate by segment. */
3662 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3663 offs
, num_segments
, segments
);
3665 if (ret
== 0 && !do_sections
)
3666 error (_("Can not handle qOffsets TextSeg "
3667 "response with this symbol file"));
3674 free_symfile_segment_data (data
);
3678 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3680 /* This is a temporary kludge to force data and bss to use the
3681 same offsets because that's what nlmconv does now. The real
3682 solution requires changes to the stub and remote.c that I
3683 don't have time to do right now. */
3685 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3686 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3689 objfile_relocate (symfile_objfile
, offs
);
3692 /* Send interrupt_sequence to remote target. */
3694 send_interrupt_sequence (void)
3696 struct remote_state
*rs
= get_remote_state ();
3698 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3699 remote_serial_write ("\x03", 1);
3700 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3701 serial_send_break (rs
->remote_desc
);
3702 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3704 serial_send_break (rs
->remote_desc
);
3705 remote_serial_write ("g", 1);
3708 internal_error (__FILE__
, __LINE__
,
3709 _("Invalid value for interrupt_sequence_mode: %s."),
3710 interrupt_sequence_mode
);
3714 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3715 and extract the PTID. Returns NULL_PTID if not found. */
3718 stop_reply_extract_thread (char *stop_reply
)
3720 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3724 /* Txx r:val ; r:val (...) */
3727 /* Look for "register" named "thread". */
3732 p1
= strchr (p
, ':');
3736 if (strncmp (p
, "thread", p1
- p
) == 0)
3737 return read_ptid (++p1
, &p
);
3739 p1
= strchr (p
, ';');
3751 /* Determine the remote side's current thread. If we have a stop
3752 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3753 "thread" register we can extract the current thread from. If not,
3754 ask the remote which is the current thread with qC. The former
3755 method avoids a roundtrip. */
3758 get_current_thread (char *wait_status
)
3760 ptid_t ptid
= null_ptid
;
3762 /* Note we don't use remote_parse_stop_reply as that makes use of
3763 the target architecture, which we haven't yet fully determined at
3765 if (wait_status
!= NULL
)
3766 ptid
= stop_reply_extract_thread (wait_status
);
3767 if (ptid_equal (ptid
, null_ptid
))
3768 ptid
= remote_current_thread (inferior_ptid
);
3773 /* Query the remote target for which is the current thread/process,
3774 add it to our tables, and update INFERIOR_PTID. The caller is
3775 responsible for setting the state such that the remote end is ready
3776 to return the current thread.
3778 This function is called after handling the '?' or 'vRun' packets,
3779 whose response is a stop reply from which we can also try
3780 extracting the thread. If the target doesn't support the explicit
3781 qC query, we infer the current thread from that stop reply, passed
3782 in in WAIT_STATUS, which may be NULL. */
3785 add_current_inferior_and_thread (char *wait_status
)
3787 struct remote_state
*rs
= get_remote_state ();
3791 inferior_ptid
= null_ptid
;
3793 /* Now, if we have thread information, update inferior_ptid. */
3794 ptid
= get_current_thread (wait_status
);
3796 if (!ptid_equal (ptid
, null_ptid
))
3798 if (!remote_multi_process_p (rs
))
3801 inferior_ptid
= ptid
;
3805 /* Without this, some commands which require an active target
3806 (such as kill) won't work. This variable serves (at least)
3807 double duty as both the pid of the target process (if it has
3808 such), and as a flag indicating that a target is active. */
3809 inferior_ptid
= magic_null_ptid
;
3813 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3815 /* Add the main thread. */
3816 add_thread_silent (inferior_ptid
);
3819 /* Print info about a thread that was found already stopped on
3823 print_one_stopped_thread (struct thread_info
*thread
)
3825 struct target_waitstatus
*ws
= &thread
->suspend
.waitstatus
;
3827 switch_to_thread (thread
->ptid
);
3828 stop_pc
= get_frame_pc (get_current_frame ());
3829 set_current_sal_from_frame (get_current_frame ());
3831 thread
->suspend
.waitstatus_pending_p
= 0;
3833 if (ws
->kind
== TARGET_WAITKIND_STOPPED
)
3835 enum gdb_signal sig
= ws
->value
.sig
;
3837 if (signal_print_state (sig
))
3838 observer_notify_signal_received (sig
);
3840 observer_notify_normal_stop (NULL
, 1);
3843 /* Process all initial stop replies the remote side sent in response
3844 to the ? packet. These indicate threads that were already stopped
3845 on initial connection. We mark these threads as stopped and print
3846 their current frame before giving the user the prompt. */
3849 process_initial_stop_replies (int from_tty
)
3851 int pending_stop_replies
= stop_reply_queue_length ();
3852 struct inferior
*inf
;
3853 struct thread_info
*thread
;
3854 struct thread_info
*selected
= NULL
;
3855 struct thread_info
*lowest_stopped
= NULL
;
3856 struct thread_info
*first
= NULL
;
3858 /* Consume the initial pending events. */
3859 while (pending_stop_replies
-- > 0)
3861 ptid_t waiton_ptid
= minus_one_ptid
;
3863 struct target_waitstatus ws
;
3864 int ignore_event
= 0;
3865 struct thread_info
*thread
;
3867 memset (&ws
, 0, sizeof (ws
));
3868 event_ptid
= target_wait (waiton_ptid
, &ws
, TARGET_WNOHANG
);
3870 print_target_wait_results (waiton_ptid
, event_ptid
, &ws
);
3874 case TARGET_WAITKIND_IGNORE
:
3875 case TARGET_WAITKIND_NO_RESUMED
:
3876 case TARGET_WAITKIND_SIGNALLED
:
3877 case TARGET_WAITKIND_EXITED
:
3878 /* We shouldn't see these, but if we do, just ignore. */
3880 fprintf_unfiltered (gdb_stdlog
, "remote: event ignored\n");
3884 case TARGET_WAITKIND_EXECD
:
3885 xfree (ws
.value
.execd_pathname
);
3894 thread
= find_thread_ptid (event_ptid
);
3896 if (ws
.kind
== TARGET_WAITKIND_STOPPED
)
3898 enum gdb_signal sig
= ws
.value
.sig
;
3900 /* Stubs traditionally report SIGTRAP as initial signal,
3901 instead of signal 0. Suppress it. */
3902 if (sig
== GDB_SIGNAL_TRAP
)
3904 thread
->suspend
.stop_signal
= sig
;
3908 thread
->suspend
.waitstatus
= ws
;
3910 if (ws
.kind
!= TARGET_WAITKIND_STOPPED
3911 || ws
.value
.sig
!= GDB_SIGNAL_0
)
3912 thread
->suspend
.waitstatus_pending_p
= 1;
3914 set_executing (event_ptid
, 0);
3915 set_running (event_ptid
, 0);
3918 /* "Notice" the new inferiors before anything related to
3919 registers/memory. */
3925 inf
->needs_setup
= 1;
3929 thread
= any_live_thread_of_process (inf
->pid
);
3930 notice_new_inferior (thread
->ptid
,
3931 thread
->state
== THREAD_RUNNING
,
3936 /* If all-stop on top of non-stop, pause all threads. Note this
3937 records the threads' stop pc, so must be done after "noticing"
3941 stop_all_threads ();
3943 /* If all threads of an inferior were already stopped, we
3944 haven't setup the inferior yet. */
3950 if (inf
->needs_setup
)
3952 thread
= any_live_thread_of_process (inf
->pid
);
3953 switch_to_thread_no_regs (thread
);
3959 /* Now go over all threads that are stopped, and print their current
3960 frame. If all-stop, then if there's a signalled thread, pick
3962 ALL_NON_EXITED_THREADS (thread
)
3968 set_running (thread
->ptid
, 0);
3969 else if (thread
->state
!= THREAD_STOPPED
)
3972 if (selected
== NULL
3973 && thread
->suspend
.waitstatus_pending_p
)
3976 if (lowest_stopped
== NULL
3977 || thread
->inf
->num
< lowest_stopped
->inf
->num
3978 || thread
->per_inf_num
< lowest_stopped
->per_inf_num
)
3979 lowest_stopped
= thread
;
3982 print_one_stopped_thread (thread
);
3985 /* In all-stop, we only print the status of one thread, and leave
3986 others with their status pending. */
3991 thread
= lowest_stopped
;
3995 print_one_stopped_thread (thread
);
3998 /* For "info program". */
3999 thread
= inferior_thread ();
4000 if (thread
->state
== THREAD_STOPPED
)
4001 set_last_target_status (inferior_ptid
, thread
->suspend
.waitstatus
);
4004 /* Start the remote connection and sync state. */
4007 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
4009 struct remote_state
*rs
= get_remote_state ();
4010 struct packet_config
*noack_config
;
4011 char *wait_status
= NULL
;
4013 /* Signal other parts that we're going through the initial setup,
4014 and so things may not be stable yet. E.g., we don't try to
4015 install tracepoints until we've relocated symbols. Also, a
4016 Ctrl-C before we're connected and synced up can't interrupt the
4017 target. Instead, it offers to drop the (potentially wedged)
4019 rs
->starting_up
= 1;
4023 if (interrupt_on_connect
)
4024 send_interrupt_sequence ();
4026 /* Ack any packet which the remote side has already sent. */
4027 remote_serial_write ("+", 1);
4029 /* The first packet we send to the target is the optional "supported
4030 packets" request. If the target can answer this, it will tell us
4031 which later probes to skip. */
4032 remote_query_supported ();
4034 /* If the stub wants to get a QAllow, compose one and send it. */
4035 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
4036 remote_set_permissions (target
);
4038 /* gdbserver < 7.7 (before its fix from 2013-12-11) did reply to any
4039 unknown 'v' packet with string "OK". "OK" gets interpreted by GDB
4040 as a reply to known packet. For packet "vFile:setfs:" it is an
4041 invalid reply and GDB would return error in
4042 remote_hostio_set_filesystem, making remote files access impossible.
4043 Disable "vFile:setfs:" in such case. Do not disable other 'v' packets as
4044 other "vFile" packets get correctly detected even on gdbserver < 7.7. */
4046 const char v_mustreplyempty
[] = "vMustReplyEmpty";
4048 putpkt (v_mustreplyempty
);
4049 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4050 if (strcmp (rs
->buf
, "OK") == 0)
4051 remote_protocol_packets
[PACKET_vFile_setfs
].support
= PACKET_DISABLE
;
4052 else if (strcmp (rs
->buf
, "") != 0)
4053 error (_("Remote replied unexpectedly to '%s': %s"), v_mustreplyempty
,
4057 /* Next, we possibly activate noack mode.
4059 If the QStartNoAckMode packet configuration is set to AUTO,
4060 enable noack mode if the stub reported a wish for it with
4063 If set to TRUE, then enable noack mode even if the stub didn't
4064 report it in qSupported. If the stub doesn't reply OK, the
4065 session ends with an error.
4067 If FALSE, then don't activate noack mode, regardless of what the
4068 stub claimed should be the default with qSupported. */
4070 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
4071 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
4073 putpkt ("QStartNoAckMode");
4074 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4075 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
4081 /* Tell the remote that we are using the extended protocol. */
4083 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4086 /* Let the target know which signals it is allowed to pass down to
4088 update_signals_program_target ();
4090 /* Next, if the target can specify a description, read it. We do
4091 this before anything involving memory or registers. */
4092 target_find_description ();
4094 /* Next, now that we know something about the target, update the
4095 address spaces in the program spaces. */
4096 update_address_spaces ();
4098 /* On OSs where the list of libraries is global to all
4099 processes, we fetch them early. */
4100 if (gdbarch_has_global_solist (target_gdbarch ()))
4101 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
4103 if (target_is_non_stop_p ())
4105 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
4106 error (_("Non-stop mode requested, but remote "
4107 "does not support non-stop"));
4109 putpkt ("QNonStop:1");
4110 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4112 if (strcmp (rs
->buf
, "OK") != 0)
4113 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
4115 /* Find about threads and processes the stub is already
4116 controlling. We default to adding them in the running state.
4117 The '?' query below will then tell us about which threads are
4119 remote_update_thread_list (target
);
4121 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
4123 /* Don't assume that the stub can operate in all-stop mode.
4124 Request it explicitly. */
4125 putpkt ("QNonStop:0");
4126 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4128 if (strcmp (rs
->buf
, "OK") != 0)
4129 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
4132 /* Upload TSVs regardless of whether the target is running or not. The
4133 remote stub, such as GDBserver, may have some predefined or builtin
4134 TSVs, even if the target is not running. */
4135 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4137 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
4139 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
4140 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
4143 /* Check whether the target is running now. */
4145 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4147 if (!target_is_non_stop_p ())
4149 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
4152 error (_("The target is not running (try extended-remote?)"));
4154 /* We're connected, but not running. Drop out before we
4155 call start_remote. */
4156 rs
->starting_up
= 0;
4161 /* Save the reply for later. */
4162 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
4163 strcpy (wait_status
, rs
->buf
);
4166 /* Fetch thread list. */
4167 target_update_thread_list ();
4169 /* Let the stub know that we want it to return the thread. */
4170 set_continue_thread (minus_one_ptid
);
4172 if (thread_count () == 0)
4174 /* Target has no concept of threads at all. GDB treats
4175 non-threaded target as single-threaded; add a main
4177 add_current_inferior_and_thread (wait_status
);
4181 /* We have thread information; select the thread the target
4182 says should be current. If we're reconnecting to a
4183 multi-threaded program, this will ideally be the thread
4184 that last reported an event before GDB disconnected. */
4185 inferior_ptid
= get_current_thread (wait_status
);
4186 if (ptid_equal (inferior_ptid
, null_ptid
))
4188 /* Odd... The target was able to list threads, but not
4189 tell us which thread was current (no "thread"
4190 register in T stop reply?). Just pick the first
4191 thread in the thread list then. */
4194 fprintf_unfiltered (gdb_stdlog
,
4195 "warning: couldn't determine remote "
4196 "current thread; picking first in list.\n");
4198 inferior_ptid
= thread_list
->ptid
;
4202 /* init_wait_for_inferior should be called before get_offsets in order
4203 to manage `inserted' flag in bp loc in a correct state.
4204 breakpoint_init_inferior, called from init_wait_for_inferior, set
4205 `inserted' flag to 0, while before breakpoint_re_set, called from
4206 start_remote, set `inserted' flag to 1. In the initialization of
4207 inferior, breakpoint_init_inferior should be called first, and then
4208 breakpoint_re_set can be called. If this order is broken, state of
4209 `inserted' flag is wrong, and cause some problems on breakpoint
4211 init_wait_for_inferior ();
4213 get_offsets (); /* Get text, data & bss offsets. */
4215 /* If we could not find a description using qXfer, and we know
4216 how to do it some other way, try again. This is not
4217 supported for non-stop; it could be, but it is tricky if
4218 there are no stopped threads when we connect. */
4219 if (remote_read_description_p (target
)
4220 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
4222 target_clear_description ();
4223 target_find_description ();
4226 /* Use the previously fetched status. */
4227 gdb_assert (wait_status
!= NULL
);
4228 strcpy (rs
->buf
, wait_status
);
4229 rs
->cached_wait_status
= 1;
4231 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
4235 /* Clear WFI global state. Do this before finding about new
4236 threads and inferiors, and setting the current inferior.
4237 Otherwise we would clear the proceed status of the current
4238 inferior when we want its stop_soon state to be preserved
4239 (see notice_new_inferior). */
4240 init_wait_for_inferior ();
4242 /* In non-stop, we will either get an "OK", meaning that there
4243 are no stopped threads at this time; or, a regular stop
4244 reply. In the latter case, there may be more than one thread
4245 stopped --- we pull them all out using the vStopped
4247 if (strcmp (rs
->buf
, "OK") != 0)
4249 struct notif_client
*notif
= ¬if_client_stop
;
4251 /* remote_notif_get_pending_replies acks this one, and gets
4253 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
4254 = remote_notif_parse (notif
, rs
->buf
);
4255 remote_notif_get_pending_events (notif
);
4258 if (thread_count () == 0)
4261 error (_("The target is not running (try extended-remote?)"));
4263 /* We're connected, but not running. Drop out before we
4264 call start_remote. */
4265 rs
->starting_up
= 0;
4269 /* In non-stop mode, any cached wait status will be stored in
4270 the stop reply queue. */
4271 gdb_assert (wait_status
== NULL
);
4273 /* Report all signals during attach/startup. */
4274 remote_pass_signals (target
, 0, NULL
);
4276 /* If there are already stopped threads, mark them stopped and
4277 report their stops before giving the prompt to the user. */
4278 process_initial_stop_replies (from_tty
);
4280 if (target_can_async_p ())
4284 /* If we connected to a live target, do some additional setup. */
4285 if (target_has_execution
)
4287 if (symfile_objfile
) /* No use without a symbol-file. */
4288 remote_check_symbols ();
4291 /* Possibly the target has been engaged in a trace run started
4292 previously; find out where things are at. */
4293 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4295 struct uploaded_tp
*uploaded_tps
= NULL
;
4297 if (current_trace_status ()->running
)
4298 printf_filtered (_("Trace is already running on the target.\n"));
4300 remote_upload_tracepoints (target
, &uploaded_tps
);
4302 merge_uploaded_tracepoints (&uploaded_tps
);
4305 /* Possibly the target has been engaged in a btrace record started
4306 previously; find out where things are at. */
4307 remote_btrace_maybe_reopen ();
4309 /* The thread and inferior lists are now synchronized with the
4310 target, our symbols have been relocated, and we're merged the
4311 target's tracepoints with ours. We're done with basic start
4313 rs
->starting_up
= 0;
4315 /* Maybe breakpoints are global and need to be inserted now. */
4316 if (breakpoints_should_be_inserted_now ())
4317 insert_breakpoints ();
4320 /* Open a connection to a remote debugger.
4321 NAME is the filename used for communication. */
4324 remote_open (const char *name
, int from_tty
)
4326 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
4329 /* Open a connection to a remote debugger using the extended
4330 remote gdb protocol. NAME is the filename used for communication. */
4333 extended_remote_open (const char *name
, int from_tty
)
4335 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
4338 /* Reset all packets back to "unknown support". Called when opening a
4339 new connection to a remote target. */
4342 reset_all_packet_configs_support (void)
4346 for (i
= 0; i
< PACKET_MAX
; i
++)
4347 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4350 /* Initialize all packet configs. */
4353 init_all_packet_configs (void)
4357 for (i
= 0; i
< PACKET_MAX
; i
++)
4359 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
4360 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4364 /* Symbol look-up. */
4367 remote_check_symbols (void)
4369 struct remote_state
*rs
= get_remote_state ();
4370 char *msg
, *reply
, *tmp
;
4373 struct cleanup
*old_chain
;
4375 /* The remote side has no concept of inferiors that aren't running
4376 yet, it only knows about running processes. If we're connected
4377 but our current inferior is not running, we should not invite the
4378 remote target to request symbol lookups related to its
4379 (unrelated) current process. */
4380 if (!target_has_execution
)
4383 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
4386 /* Make sure the remote is pointing at the right process. Note
4387 there's no way to select "no process". */
4388 set_general_process ();
4390 /* Allocate a message buffer. We can't reuse the input buffer in RS,
4391 because we need both at the same time. */
4392 msg
= (char *) xmalloc (get_remote_packet_size ());
4393 old_chain
= make_cleanup (xfree
, msg
);
4394 reply
= (char *) xmalloc (get_remote_packet_size ());
4395 make_cleanup (free_current_contents
, &reply
);
4396 reply_size
= get_remote_packet_size ();
4398 /* Invite target to request symbol lookups. */
4400 putpkt ("qSymbol::");
4401 getpkt (&reply
, &reply_size
, 0);
4402 packet_ok (reply
, &remote_protocol_packets
[PACKET_qSymbol
]);
4404 while (startswith (reply
, "qSymbol:"))
4406 struct bound_minimal_symbol sym
;
4409 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
4411 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
4412 if (sym
.minsym
== NULL
)
4413 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
4416 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4417 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
4419 /* If this is a function address, return the start of code
4420 instead of any data function descriptor. */
4421 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
4425 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
4426 phex_nz (sym_addr
, addr_size
), &reply
[8]);
4430 getpkt (&reply
, &reply_size
, 0);
4433 do_cleanups (old_chain
);
4436 static struct serial
*
4437 remote_serial_open (const char *name
)
4439 static int udp_warning
= 0;
4441 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
4442 of in ser-tcp.c, because it is the remote protocol assuming that the
4443 serial connection is reliable and not the serial connection promising
4445 if (!udp_warning
&& startswith (name
, "udp:"))
4447 warning (_("The remote protocol may be unreliable over UDP.\n"
4448 "Some events may be lost, rendering further debugging "
4453 return serial_open (name
);
4456 /* Inform the target of our permission settings. The permission flags
4457 work without this, but if the target knows the settings, it can do
4458 a couple things. First, it can add its own check, to catch cases
4459 that somehow manage to get by the permissions checks in target
4460 methods. Second, if the target is wired to disallow particular
4461 settings (for instance, a system in the field that is not set up to
4462 be able to stop at a breakpoint), it can object to any unavailable
4466 remote_set_permissions (struct target_ops
*self
)
4468 struct remote_state
*rs
= get_remote_state ();
4470 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4471 "WriteReg:%x;WriteMem:%x;"
4472 "InsertBreak:%x;InsertTrace:%x;"
4473 "InsertFastTrace:%x;Stop:%x",
4474 may_write_registers
, may_write_memory
,
4475 may_insert_breakpoints
, may_insert_tracepoints
,
4476 may_insert_fast_tracepoints
, may_stop
);
4478 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4480 /* If the target didn't like the packet, warn the user. Do not try
4481 to undo the user's settings, that would just be maddening. */
4482 if (strcmp (rs
->buf
, "OK") != 0)
4483 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4486 /* This type describes each known response to the qSupported
4488 struct protocol_feature
4490 /* The name of this protocol feature. */
4493 /* The default for this protocol feature. */
4494 enum packet_support default_support
;
4496 /* The function to call when this feature is reported, or after
4497 qSupported processing if the feature is not supported.
4498 The first argument points to this structure. The second
4499 argument indicates whether the packet requested support be
4500 enabled, disabled, or probed (or the default, if this function
4501 is being called at the end of processing and this feature was
4502 not reported). The third argument may be NULL; if not NULL, it
4503 is a NUL-terminated string taken from the packet following
4504 this feature's name and an equals sign. */
4505 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4508 /* The corresponding packet for this feature. Only used if
4509 FUNC is remote_supported_packet. */
4514 remote_supported_packet (const struct protocol_feature
*feature
,
4515 enum packet_support support
,
4516 const char *argument
)
4520 warning (_("Remote qSupported response supplied an unexpected value for"
4521 " \"%s\"."), feature
->name
);
4525 remote_protocol_packets
[feature
->packet
].support
= support
;
4529 remote_packet_size (const struct protocol_feature
*feature
,
4530 enum packet_support support
, const char *value
)
4532 struct remote_state
*rs
= get_remote_state ();
4537 if (support
!= PACKET_ENABLE
)
4540 if (value
== NULL
|| *value
== '\0')
4542 warning (_("Remote target reported \"%s\" without a size."),
4548 packet_size
= strtol (value
, &value_end
, 16);
4549 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4551 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4552 feature
->name
, value
);
4556 /* Record the new maximum packet size. */
4557 rs
->explicit_packet_size
= packet_size
;
4560 static const struct protocol_feature remote_protocol_features
[] = {
4561 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4562 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4563 PACKET_qXfer_auxv
},
4564 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4565 PACKET_qXfer_exec_file
},
4566 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4567 PACKET_qXfer_features
},
4568 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4569 PACKET_qXfer_libraries
},
4570 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4571 PACKET_qXfer_libraries_svr4
},
4572 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4573 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4574 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4575 PACKET_qXfer_memory_map
},
4576 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4577 PACKET_qXfer_spu_read
},
4578 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4579 PACKET_qXfer_spu_write
},
4580 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4581 PACKET_qXfer_osdata
},
4582 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4583 PACKET_qXfer_threads
},
4584 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4585 PACKET_qXfer_traceframe_info
},
4586 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4587 PACKET_QPassSignals
},
4588 { "QCatchSyscalls", PACKET_DISABLE
, remote_supported_packet
,
4589 PACKET_QCatchSyscalls
},
4590 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4591 PACKET_QProgramSignals
},
4592 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4593 PACKET_QStartNoAckMode
},
4594 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4595 PACKET_multiprocess_feature
},
4596 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4597 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4598 PACKET_qXfer_siginfo_read
},
4599 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4600 PACKET_qXfer_siginfo_write
},
4601 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4602 PACKET_ConditionalTracepoints
},
4603 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4604 PACKET_ConditionalBreakpoints
},
4605 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4606 PACKET_BreakpointCommands
},
4607 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4608 PACKET_FastTracepoints
},
4609 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4610 PACKET_StaticTracepoints
},
4611 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4612 PACKET_InstallInTrace
},
4613 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4614 PACKET_DisconnectedTracing_feature
},
4615 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4617 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4619 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4620 PACKET_TracepointSource
},
4621 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4623 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4624 PACKET_EnableDisableTracepoints_feature
},
4625 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4626 PACKET_qXfer_fdpic
},
4627 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4629 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4630 PACKET_QDisableRandomization
},
4631 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4632 { "QTBuffer:size", PACKET_DISABLE
,
4633 remote_supported_packet
, PACKET_QTBuffer_size
},
4634 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4635 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4636 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4637 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4638 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4639 PACKET_qXfer_btrace
},
4640 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4641 PACKET_qXfer_btrace_conf
},
4642 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4643 PACKET_Qbtrace_conf_bts_size
},
4644 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4645 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4646 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4647 PACKET_fork_event_feature
},
4648 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4649 PACKET_vfork_event_feature
},
4650 { "exec-events", PACKET_DISABLE
, remote_supported_packet
,
4651 PACKET_exec_event_feature
},
4652 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4653 PACKET_Qbtrace_conf_pt_size
},
4654 { "vContSupported", PACKET_DISABLE
, remote_supported_packet
, PACKET_vContSupported
},
4655 { "QThreadEvents", PACKET_DISABLE
, remote_supported_packet
, PACKET_QThreadEvents
},
4656 { "no-resumed", PACKET_DISABLE
, remote_supported_packet
, PACKET_no_resumed
},
4659 static char *remote_support_xml
;
4661 /* Register string appended to "xmlRegisters=" in qSupported query. */
4664 register_remote_support_xml (const char *xml
)
4666 #if defined(HAVE_LIBEXPAT)
4667 if (remote_support_xml
== NULL
)
4668 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4671 char *copy
= xstrdup (remote_support_xml
+ 13);
4672 char *p
= strtok (copy
, ",");
4676 if (strcmp (p
, xml
) == 0)
4683 while ((p
= strtok (NULL
, ",")) != NULL
);
4686 remote_support_xml
= reconcat (remote_support_xml
,
4687 remote_support_xml
, ",", xml
,
4694 remote_query_supported_append (char *msg
, const char *append
)
4697 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4699 return xstrdup (append
);
4703 remote_query_supported (void)
4705 struct remote_state
*rs
= get_remote_state ();
4708 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4710 /* The packet support flags are handled differently for this packet
4711 than for most others. We treat an error, a disabled packet, and
4712 an empty response identically: any features which must be reported
4713 to be used will be automatically disabled. An empty buffer
4714 accomplishes this, since that is also the representation for a list
4715 containing no features. */
4718 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4721 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4723 if (packet_set_cmd_state (PACKET_multiprocess_feature
) != AUTO_BOOLEAN_FALSE
)
4724 q
= remote_query_supported_append (q
, "multiprocess+");
4726 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4727 q
= remote_query_supported_append (q
, "swbreak+");
4728 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4729 q
= remote_query_supported_append (q
, "hwbreak+");
4731 q
= remote_query_supported_append (q
, "qRelocInsn+");
4733 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4734 != AUTO_BOOLEAN_FALSE
)
4735 q
= remote_query_supported_append (q
, "fork-events+");
4736 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4737 != AUTO_BOOLEAN_FALSE
)
4738 q
= remote_query_supported_append (q
, "vfork-events+");
4739 if (packet_set_cmd_state (PACKET_exec_event_feature
)
4740 != AUTO_BOOLEAN_FALSE
)
4741 q
= remote_query_supported_append (q
, "exec-events+");
4743 if (packet_set_cmd_state (PACKET_vContSupported
) != AUTO_BOOLEAN_FALSE
)
4744 q
= remote_query_supported_append (q
, "vContSupported+");
4746 if (packet_set_cmd_state (PACKET_QThreadEvents
) != AUTO_BOOLEAN_FALSE
)
4747 q
= remote_query_supported_append (q
, "QThreadEvents+");
4749 if (packet_set_cmd_state (PACKET_no_resumed
) != AUTO_BOOLEAN_FALSE
)
4750 q
= remote_query_supported_append (q
, "no-resumed+");
4752 /* Keep this one last to work around a gdbserver <= 7.10 bug in
4753 the qSupported:xmlRegisters=i386 handling. */
4754 if (remote_support_xml
!= NULL
)
4755 q
= remote_query_supported_append (q
, remote_support_xml
);
4757 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4760 do_cleanups (old_chain
);
4762 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4764 /* If an error occured, warn, but do not return - just reset the
4765 buffer to empty and go on to disable features. */
4766 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4769 warning (_("Remote failure reply: %s"), rs
->buf
);
4774 memset (seen
, 0, sizeof (seen
));
4779 enum packet_support is_supported
;
4780 char *p
, *end
, *name_end
, *value
;
4782 /* First separate out this item from the rest of the packet. If
4783 there's another item after this, we overwrite the separator
4784 (terminated strings are much easier to work with). */
4786 end
= strchr (p
, ';');
4789 end
= p
+ strlen (p
);
4799 warning (_("empty item in \"qSupported\" response"));
4804 name_end
= strchr (p
, '=');
4807 /* This is a name=value entry. */
4808 is_supported
= PACKET_ENABLE
;
4809 value
= name_end
+ 1;
4818 is_supported
= PACKET_ENABLE
;
4822 is_supported
= PACKET_DISABLE
;
4826 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4830 warning (_("unrecognized item \"%s\" "
4831 "in \"qSupported\" response"), p
);
4837 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4838 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4840 const struct protocol_feature
*feature
;
4843 feature
= &remote_protocol_features
[i
];
4844 feature
->func (feature
, is_supported
, value
);
4849 /* If we increased the packet size, make sure to increase the global
4850 buffer size also. We delay this until after parsing the entire
4851 qSupported packet, because this is the same buffer we were
4853 if (rs
->buf_size
< rs
->explicit_packet_size
)
4855 rs
->buf_size
= rs
->explicit_packet_size
;
4856 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
4859 /* Handle the defaults for unmentioned features. */
4860 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4863 const struct protocol_feature
*feature
;
4865 feature
= &remote_protocol_features
[i
];
4866 feature
->func (feature
, feature
->default_support
, NULL
);
4870 /* Serial QUIT handler for the remote serial descriptor.
4872 Defers handling a Ctrl-C until we're done with the current
4873 command/response packet sequence, unless:
4875 - We're setting up the connection. Don't send a remote interrupt
4876 request, as we're not fully synced yet. Quit immediately
4879 - The target has been resumed in the foreground
4880 (target_terminal_is_ours is false) with a synchronous resume
4881 packet, and we're blocked waiting for the stop reply, thus a
4882 Ctrl-C should be immediately sent to the target.
4884 - We get a second Ctrl-C while still within the same serial read or
4885 write. In that case the serial is seemingly wedged --- offer to
4888 - We see a second Ctrl-C without target response, after having
4889 previously interrupted the target. In that case the target/stub
4890 is probably wedged --- offer to quit/disconnect.
4894 remote_serial_quit_handler (void)
4896 struct remote_state
*rs
= get_remote_state ();
4898 if (check_quit_flag ())
4900 /* If we're starting up, we're not fully synced yet. Quit
4902 if (rs
->starting_up
)
4904 else if (rs
->got_ctrlc_during_io
)
4906 if (query (_("The target is not responding to GDB commands.\n"
4907 "Stop debugging it? ")))
4908 remote_unpush_and_throw ();
4910 /* If ^C has already been sent once, offer to disconnect. */
4911 else if (!target_terminal_is_ours () && rs
->ctrlc_pending_p
)
4913 /* All-stop protocol, and blocked waiting for stop reply. Send
4914 an interrupt request. */
4915 else if (!target_terminal_is_ours () && rs
->waiting_for_stop_reply
)
4916 target_interrupt (inferior_ptid
);
4918 rs
->got_ctrlc_during_io
= 1;
4922 /* Remove any of the remote.c targets from target stack. Upper targets depend
4923 on it so remove them first. */
4926 remote_unpush_target (void)
4928 pop_all_targets_at_and_above (process_stratum
);
4932 remote_unpush_and_throw (void)
4934 remote_unpush_target ();
4935 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
4939 remote_open_1 (const char *name
, int from_tty
,
4940 struct target_ops
*target
, int extended_p
)
4942 struct remote_state
*rs
= get_remote_state ();
4945 error (_("To open a remote debug connection, you need to specify what\n"
4946 "serial device is attached to the remote system\n"
4947 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4949 /* See FIXME above. */
4950 if (!target_async_permitted
)
4951 wait_forever_enabled_p
= 1;
4953 /* If we're connected to a running target, target_preopen will kill it.
4954 Ask this question first, before target_preopen has a chance to kill
4956 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4959 && !query (_("Already connected to a remote target. Disconnect? ")))
4960 error (_("Still connected."));
4963 /* Here the possibly existing remote target gets unpushed. */
4964 target_preopen (from_tty
);
4966 /* Make sure we send the passed signals list the next time we resume. */
4967 xfree (rs
->last_pass_packet
);
4968 rs
->last_pass_packet
= NULL
;
4970 /* Make sure we send the program signals list the next time we
4972 xfree (rs
->last_program_signals_packet
);
4973 rs
->last_program_signals_packet
= NULL
;
4975 remote_fileio_reset ();
4976 reopen_exec_file ();
4979 rs
->remote_desc
= remote_serial_open (name
);
4980 if (!rs
->remote_desc
)
4981 perror_with_name (name
);
4983 if (baud_rate
!= -1)
4985 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4987 /* The requested speed could not be set. Error out to
4988 top level after closing remote_desc. Take care to
4989 set remote_desc to NULL to avoid closing remote_desc
4991 serial_close (rs
->remote_desc
);
4992 rs
->remote_desc
= NULL
;
4993 perror_with_name (name
);
4997 serial_setparity (rs
->remote_desc
, serial_parity
);
4998 serial_raw (rs
->remote_desc
);
5000 /* If there is something sitting in the buffer we might take it as a
5001 response to a command, which would be bad. */
5002 serial_flush_input (rs
->remote_desc
);
5006 puts_filtered ("Remote debugging using ");
5007 puts_filtered (name
);
5008 puts_filtered ("\n");
5010 push_target (target
); /* Switch to using remote target now. */
5012 /* Register extra event sources in the event loop. */
5013 remote_async_inferior_event_token
5014 = create_async_event_handler (remote_async_inferior_event_handler
,
5016 rs
->notif_state
= remote_notif_state_allocate ();
5018 /* Reset the target state; these things will be queried either by
5019 remote_query_supported or as they are needed. */
5020 reset_all_packet_configs_support ();
5021 rs
->cached_wait_status
= 0;
5022 rs
->explicit_packet_size
= 0;
5024 rs
->extended
= extended_p
;
5025 rs
->waiting_for_stop_reply
= 0;
5026 rs
->ctrlc_pending_p
= 0;
5027 rs
->got_ctrlc_during_io
= 0;
5029 rs
->general_thread
= not_sent_ptid
;
5030 rs
->continue_thread
= not_sent_ptid
;
5031 rs
->remote_traceframe_number
= -1;
5033 rs
->last_resume_exec_dir
= EXEC_FORWARD
;
5035 /* Probe for ability to use "ThreadInfo" query, as required. */
5036 rs
->use_threadinfo_query
= 1;
5037 rs
->use_threadextra_query
= 1;
5039 readahead_cache_invalidate ();
5041 /* Start out by owning the terminal. */
5042 remote_async_terminal_ours_p
= 1;
5044 if (target_async_permitted
)
5046 /* FIXME: cagney/1999-09-23: During the initial connection it is
5047 assumed that the target is already ready and able to respond to
5048 requests. Unfortunately remote_start_remote() eventually calls
5049 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
5050 around this. Eventually a mechanism that allows
5051 wait_for_inferior() to expect/get timeouts will be
5053 wait_forever_enabled_p
= 0;
5056 /* First delete any symbols previously loaded from shared libraries. */
5057 no_shared_libraries (NULL
, 0);
5060 init_thread_list ();
5062 /* Start the remote connection. If error() or QUIT, discard this
5063 target (we'd otherwise be in an inconsistent state) and then
5064 propogate the error on up the exception chain. This ensures that
5065 the caller doesn't stumble along blindly assuming that the
5066 function succeeded. The CLI doesn't have this problem but other
5067 UI's, such as MI do.
5069 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
5070 this function should return an error indication letting the
5071 caller restore the previous state. Unfortunately the command
5072 ``target remote'' is directly wired to this function making that
5073 impossible. On a positive note, the CLI side of this problem has
5074 been fixed - the function set_cmd_context() makes it possible for
5075 all the ``target ....'' commands to share a common callback
5076 function. See cli-dump.c. */
5081 remote_start_remote (from_tty
, target
, extended_p
);
5083 CATCH (ex
, RETURN_MASK_ALL
)
5085 /* Pop the partially set up target - unless something else did
5086 already before throwing the exception. */
5087 if (rs
->remote_desc
!= NULL
)
5088 remote_unpush_target ();
5089 if (target_async_permitted
)
5090 wait_forever_enabled_p
= 1;
5091 throw_exception (ex
);
5096 remote_btrace_reset ();
5098 if (target_async_permitted
)
5099 wait_forever_enabled_p
= 1;
5102 /* Detach the specified process. */
5105 remote_detach_pid (int pid
)
5107 struct remote_state
*rs
= get_remote_state ();
5109 if (remote_multi_process_p (rs
))
5110 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
5112 strcpy (rs
->buf
, "D");
5115 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5117 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
5119 else if (rs
->buf
[0] == '\0')
5120 error (_("Remote doesn't know how to detach"));
5122 error (_("Can't detach process."));
5125 /* This detaches a program to which we previously attached, using
5126 inferior_ptid to identify the process. After this is done, GDB
5127 can be used to debug some other program. We better not have left
5128 any breakpoints in the target program or it'll die when it hits
5132 remote_detach_1 (const char *args
, int from_tty
)
5134 int pid
= ptid_get_pid (inferior_ptid
);
5135 struct remote_state
*rs
= get_remote_state ();
5136 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
5140 error (_("Argument given to \"detach\" when remotely debugging."));
5142 if (!target_has_execution
)
5143 error (_("No process to detach from."));
5145 target_announce_detach (from_tty
);
5147 /* Tell the remote target to detach. */
5148 remote_detach_pid (pid
);
5150 /* Exit only if this is the only active inferior. */
5151 if (from_tty
&& !rs
->extended
&& number_of_live_inferiors () == 1)
5152 puts_filtered (_("Ending remote debugging.\n"));
5154 /* Check to see if we are detaching a fork parent. Note that if we
5155 are detaching a fork child, tp == NULL. */
5156 is_fork_parent
= (tp
!= NULL
5157 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
5159 /* If doing detach-on-fork, we don't mourn, because that will delete
5160 breakpoints that should be available for the followed inferior. */
5161 if (!is_fork_parent
)
5162 target_mourn_inferior ();
5165 inferior_ptid
= null_ptid
;
5166 detach_inferior (pid
);
5171 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5173 remote_detach_1 (args
, from_tty
);
5177 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5179 remote_detach_1 (args
, from_tty
);
5182 /* Target follow-fork function for remote targets. On entry, and
5183 at return, the current inferior is the fork parent.
5185 Note that although this is currently only used for extended-remote,
5186 it is named remote_follow_fork in anticipation of using it for the
5187 remote target as well. */
5190 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
5193 struct remote_state
*rs
= get_remote_state ();
5194 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
5196 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
5197 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
5199 /* When following the parent and detaching the child, we detach
5200 the child here. For the case of following the child and
5201 detaching the parent, the detach is done in the target-
5202 independent follow fork code in infrun.c. We can't use
5203 target_detach when detaching an unfollowed child because
5204 the client side doesn't know anything about the child. */
5205 if (detach_fork
&& !follow_child
)
5207 /* Detach the fork child. */
5211 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
5212 child_pid
= ptid_get_pid (child_ptid
);
5214 remote_detach_pid (child_pid
);
5215 detach_inferior (child_pid
);
5221 /* Target follow-exec function for remote targets. Save EXECD_PATHNAME
5222 in the program space of the new inferior. On entry and at return the
5223 current inferior is the exec'ing inferior. INF is the new exec'd
5224 inferior, which may be the same as the exec'ing inferior unless
5225 follow-exec-mode is "new". */
5228 remote_follow_exec (struct target_ops
*ops
,
5229 struct inferior
*inf
, char *execd_pathname
)
5231 /* We know that this is a target file name, so if it has the "target:"
5232 prefix we strip it off before saving it in the program space. */
5233 if (is_target_filename (execd_pathname
))
5234 execd_pathname
+= strlen (TARGET_SYSROOT_PREFIX
);
5236 set_pspace_remote_exec_file (inf
->pspace
, execd_pathname
);
5239 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
5242 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
5245 error (_("Argument given to \"disconnect\" when remotely debugging."));
5247 /* Make sure we unpush even the extended remote targets. Calling
5248 target_mourn_inferior won't unpush, and remote_mourn won't
5249 unpush if there is more than one inferior left. */
5250 unpush_target (target
);
5251 generic_mourn_inferior ();
5254 puts_filtered ("Ending remote debugging.\n");
5257 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
5258 be chatty about it. */
5261 extended_remote_attach (struct target_ops
*target
, const char *args
,
5264 struct remote_state
*rs
= get_remote_state ();
5266 char *wait_status
= NULL
;
5268 pid
= parse_pid_to_attach (args
);
5270 /* Remote PID can be freely equal to getpid, do not check it here the same
5271 way as in other targets. */
5273 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
5274 error (_("This target does not support attaching to a process"));
5278 char *exec_file
= get_exec_file (0);
5281 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
5282 target_pid_to_str (pid_to_ptid (pid
)));
5284 printf_unfiltered (_("Attaching to %s\n"),
5285 target_pid_to_str (pid_to_ptid (pid
)));
5287 gdb_flush (gdb_stdout
);
5290 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
5292 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5294 switch (packet_ok (rs
->buf
,
5295 &remote_protocol_packets
[PACKET_vAttach
]))
5298 if (!target_is_non_stop_p ())
5300 /* Save the reply for later. */
5301 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
5302 strcpy (wait_status
, rs
->buf
);
5304 else if (strcmp (rs
->buf
, "OK") != 0)
5305 error (_("Attaching to %s failed with: %s"),
5306 target_pid_to_str (pid_to_ptid (pid
)),
5309 case PACKET_UNKNOWN
:
5310 error (_("This target does not support attaching to a process"));
5312 error (_("Attaching to %s failed"),
5313 target_pid_to_str (pid_to_ptid (pid
)));
5316 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
5318 inferior_ptid
= pid_to_ptid (pid
);
5320 if (target_is_non_stop_p ())
5322 struct thread_info
*thread
;
5324 /* Get list of threads. */
5325 remote_update_thread_list (target
);
5327 thread
= first_thread_of_process (pid
);
5329 inferior_ptid
= thread
->ptid
;
5331 inferior_ptid
= pid_to_ptid (pid
);
5333 /* Invalidate our notion of the remote current thread. */
5334 record_currthread (rs
, minus_one_ptid
);
5338 /* Now, if we have thread information, update inferior_ptid. */
5339 inferior_ptid
= remote_current_thread (inferior_ptid
);
5341 /* Add the main thread to the thread list. */
5342 add_thread_silent (inferior_ptid
);
5345 /* Next, if the target can specify a description, read it. We do
5346 this before anything involving memory or registers. */
5347 target_find_description ();
5349 if (!target_is_non_stop_p ())
5351 /* Use the previously fetched status. */
5352 gdb_assert (wait_status
!= NULL
);
5354 if (target_can_async_p ())
5356 struct notif_event
*reply
5357 = remote_notif_parse (¬if_client_stop
, wait_status
);
5359 push_stop_reply ((struct stop_reply
*) reply
);
5365 gdb_assert (wait_status
!= NULL
);
5366 strcpy (rs
->buf
, wait_status
);
5367 rs
->cached_wait_status
= 1;
5371 gdb_assert (wait_status
== NULL
);
5374 /* Implementation of the to_post_attach method. */
5377 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
5379 /* Get text, data & bss offsets. */
5382 /* In certain cases GDB might not have had the chance to start
5383 symbol lookup up until now. This could happen if the debugged
5384 binary is not using shared libraries, the vsyscall page is not
5385 present (on Linux) and the binary itself hadn't changed since the
5386 debugging process was started. */
5387 if (symfile_objfile
!= NULL
)
5388 remote_check_symbols();
5392 /* Check for the availability of vCont. This function should also check
5396 remote_vcont_probe (struct remote_state
*rs
)
5400 strcpy (rs
->buf
, "vCont?");
5402 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5405 /* Make sure that the features we assume are supported. */
5406 if (startswith (buf
, "vCont"))
5409 int support_c
, support_C
;
5411 rs
->supports_vCont
.s
= 0;
5412 rs
->supports_vCont
.S
= 0;
5415 rs
->supports_vCont
.t
= 0;
5416 rs
->supports_vCont
.r
= 0;
5417 while (p
&& *p
== ';')
5420 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5421 rs
->supports_vCont
.s
= 1;
5422 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5423 rs
->supports_vCont
.S
= 1;
5424 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5426 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5428 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5429 rs
->supports_vCont
.t
= 1;
5430 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5431 rs
->supports_vCont
.r
= 1;
5433 p
= strchr (p
, ';');
5436 /* If c, and C are not all supported, we can't use vCont. Clearing
5437 BUF will make packet_ok disable the packet. */
5438 if (!support_c
|| !support_C
)
5442 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
5445 /* Helper function for building "vCont" resumptions. Write a
5446 resumption to P. ENDP points to one-passed-the-end of the buffer
5447 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
5448 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
5449 resumed thread should be single-stepped and/or signalled. If PTID
5450 equals minus_one_ptid, then all threads are resumed; if PTID
5451 represents a process, then all threads of the process are resumed;
5452 the thread to be stepped and/or signalled is given in the global
5456 append_resumption (char *p
, char *endp
,
5457 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5459 struct remote_state
*rs
= get_remote_state ();
5461 if (step
&& siggnal
!= GDB_SIGNAL_0
)
5462 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
5464 /* GDB is willing to range step. */
5465 && use_range_stepping
5466 /* Target supports range stepping. */
5467 && rs
->supports_vCont
.r
5468 /* We don't currently support range stepping multiple
5469 threads with a wildcard (though the protocol allows it,
5470 so stubs shouldn't make an active effort to forbid
5472 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5474 struct thread_info
*tp
;
5476 if (ptid_equal (ptid
, minus_one_ptid
))
5478 /* If we don't know about the target thread's tid, then
5479 we're resuming magic_null_ptid (see caller). */
5480 tp
= find_thread_ptid (magic_null_ptid
);
5483 tp
= find_thread_ptid (ptid
);
5484 gdb_assert (tp
!= NULL
);
5486 if (tp
->control
.may_range_step
)
5488 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
5490 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
5491 phex_nz (tp
->control
.step_range_start
,
5493 phex_nz (tp
->control
.step_range_end
,
5497 p
+= xsnprintf (p
, endp
- p
, ";s");
5500 p
+= xsnprintf (p
, endp
- p
, ";s");
5501 else if (siggnal
!= GDB_SIGNAL_0
)
5502 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
5504 p
+= xsnprintf (p
, endp
- p
, ";c");
5506 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
5510 /* All (-1) threads of process. */
5511 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5513 p
+= xsnprintf (p
, endp
- p
, ":");
5514 p
= write_ptid (p
, endp
, nptid
);
5516 else if (!ptid_equal (ptid
, minus_one_ptid
))
5518 p
+= xsnprintf (p
, endp
- p
, ":");
5519 p
= write_ptid (p
, endp
, ptid
);
5525 /* Clear the thread's private info on resume. */
5528 resume_clear_thread_private_info (struct thread_info
*thread
)
5530 if (thread
->priv
!= NULL
)
5532 thread
->priv
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5533 thread
->priv
->watch_data_address
= 0;
5537 /* Append a vCont continue-with-signal action for threads that have a
5538 non-zero stop signal. */
5541 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
5543 struct thread_info
*thread
;
5545 ALL_NON_EXITED_THREADS (thread
)
5546 if (ptid_match (thread
->ptid
, ptid
)
5547 && !ptid_equal (inferior_ptid
, thread
->ptid
)
5548 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
5550 p
= append_resumption (p
, endp
, thread
->ptid
,
5551 0, thread
->suspend
.stop_signal
);
5552 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5553 resume_clear_thread_private_info (thread
);
5559 /* Resume the remote inferior by using a "vCont" packet. The thread
5560 to be resumed is PTID; STEP and SIGGNAL indicate whether the
5561 resumed thread should be single-stepped and/or signalled. If PTID
5562 equals minus_one_ptid, then all threads are resumed; the thread to
5563 be stepped and/or signalled is given in the global INFERIOR_PTID.
5564 This function returns non-zero iff it resumes the inferior.
5566 This function issues a strict subset of all possible vCont commands at the
5570 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5572 struct remote_state
*rs
= get_remote_state ();
5576 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5577 remote_vcont_probe (rs
);
5579 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5583 endp
= rs
->buf
+ get_remote_packet_size ();
5585 /* If we could generate a wider range of packets, we'd have to worry
5586 about overflowing BUF. Should there be a generic
5587 "multi-part-packet" packet? */
5589 p
+= xsnprintf (p
, endp
- p
, "vCont");
5591 if (ptid_equal (ptid
, magic_null_ptid
))
5593 /* MAGIC_NULL_PTID means that we don't have any active threads,
5594 so we don't have any TID numbers the inferior will
5595 understand. Make sure to only send forms that do not specify
5597 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5599 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5601 /* Resume all threads (of all processes, or of a single
5602 process), with preference for INFERIOR_PTID. This assumes
5603 inferior_ptid belongs to the set of all threads we are about
5605 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5607 /* Step inferior_ptid, with or without signal. */
5608 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5611 /* Also pass down any pending signaled resumption for other
5612 threads not the current. */
5613 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5615 /* And continue others without a signal. */
5616 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5620 /* Scheduler locking; resume only PTID. */
5621 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5624 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5627 if (target_is_non_stop_p ())
5629 /* In non-stop, the stub replies to vCont with "OK". The stop
5630 reply will be reported asynchronously by means of a `%Stop'
5632 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5633 if (strcmp (rs
->buf
, "OK") != 0)
5634 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5640 /* Tell the remote machine to resume. */
5643 remote_resume (struct target_ops
*ops
,
5644 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5646 struct remote_state
*rs
= get_remote_state ();
5648 struct thread_info
*thread
;
5650 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5651 (explained in remote-notif.c:handle_notification) so
5652 remote_notif_process is not called. We need find a place where
5653 it is safe to start a 'vNotif' sequence. It is good to do it
5654 before resuming inferior, because inferior was stopped and no RSP
5655 traffic at that moment. */
5656 if (!target_is_non_stop_p ())
5657 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5659 rs
->last_sent_signal
= siggnal
;
5660 rs
->last_sent_step
= step
;
5662 rs
->last_resume_exec_dir
= execution_direction
;
5664 /* The vCont packet doesn't need to specify threads via Hc. */
5665 /* No reverse support (yet) for vCont. */
5666 if (execution_direction
!= EXEC_REVERSE
)
5667 if (remote_vcont_resume (ptid
, step
, siggnal
))
5670 /* All other supported resume packets do use Hc, so set the continue
5672 if (ptid_equal (ptid
, minus_one_ptid
))
5673 set_continue_thread (any_thread_ptid
);
5675 set_continue_thread (ptid
);
5677 ALL_NON_EXITED_THREADS (thread
)
5678 resume_clear_thread_private_info (thread
);
5681 if (execution_direction
== EXEC_REVERSE
)
5683 /* We don't pass signals to the target in reverse exec mode. */
5684 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5685 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5688 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5689 error (_("Remote reverse-step not supported."));
5690 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5691 error (_("Remote reverse-continue not supported."));
5693 strcpy (buf
, step
? "bs" : "bc");
5695 else if (siggnal
!= GDB_SIGNAL_0
)
5697 buf
[0] = step
? 'S' : 'C';
5698 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5699 buf
[2] = tohex (((int) siggnal
) & 0xf);
5703 strcpy (buf
, step
? "s" : "c");
5708 /* We are about to start executing the inferior, let's register it
5709 with the event loop. NOTE: this is the one place where all the
5710 execution commands end up. We could alternatively do this in each
5711 of the execution commands in infcmd.c. */
5712 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5713 into infcmd.c in order to allow inferior function calls to work
5714 NOT asynchronously. */
5715 if (target_can_async_p ())
5718 /* We've just told the target to resume. The remote server will
5719 wait for the inferior to stop, and then send a stop reply. In
5720 the mean time, we can't start another command/query ourselves
5721 because the stub wouldn't be ready to process it. This applies
5722 only to the base all-stop protocol, however. In non-stop (which
5723 only supports vCont), the stub replies with an "OK", and is
5724 immediate able to process further serial input. */
5725 if (!target_is_non_stop_p ())
5726 rs
->waiting_for_stop_reply
= 1;
5730 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5731 thread, all threads of a remote process, or all threads of all
5735 remote_stop_ns (ptid_t ptid
)
5737 struct remote_state
*rs
= get_remote_state ();
5739 char *endp
= rs
->buf
+ get_remote_packet_size ();
5741 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5742 remote_vcont_probe (rs
);
5744 if (!rs
->supports_vCont
.t
)
5745 error (_("Remote server does not support stopping threads"));
5747 if (ptid_equal (ptid
, minus_one_ptid
)
5748 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5749 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5754 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5756 if (ptid_is_pid (ptid
))
5757 /* All (-1) threads of process. */
5758 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5761 /* Small optimization: if we already have a stop reply for
5762 this thread, no use in telling the stub we want this
5764 if (peek_stop_reply (ptid
))
5770 write_ptid (p
, endp
, nptid
);
5773 /* In non-stop, we get an immediate OK reply. The stop reply will
5774 come in asynchronously by notification. */
5776 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5777 if (strcmp (rs
->buf
, "OK") != 0)
5778 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5781 /* All-stop version of target_interrupt. Sends a break or a ^C to
5782 interrupt the remote target. It is undefined which thread of which
5783 process reports the interrupt. */
5786 remote_interrupt_as (void)
5788 struct remote_state
*rs
= get_remote_state ();
5790 rs
->ctrlc_pending_p
= 1;
5792 /* If the inferior is stopped already, but the core didn't know
5793 about it yet, just ignore the request. The cached wait status
5794 will be collected in remote_wait. */
5795 if (rs
->cached_wait_status
)
5798 /* Send interrupt_sequence to remote target. */
5799 send_interrupt_sequence ();
5802 /* Non-stop version of target_interrupt. Uses `vCtrlC' to interrupt
5803 the remote target. It is undefined which thread of which process
5804 reports the interrupt. Throws an error if the packet is not
5805 supported by the server. */
5808 remote_interrupt_ns (void)
5810 struct remote_state
*rs
= get_remote_state ();
5812 char *endp
= rs
->buf
+ get_remote_packet_size ();
5814 xsnprintf (p
, endp
- p
, "vCtrlC");
5816 /* In non-stop, we get an immediate OK reply. The stop reply will
5817 come in asynchronously by notification. */
5819 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5821 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vCtrlC
]))
5825 case PACKET_UNKNOWN
:
5826 error (_("No support for interrupting the remote target."));
5828 error (_("Interrupting target failed: %s"), rs
->buf
);
5832 /* Implement the to_stop function for the remote targets. */
5835 remote_stop (struct target_ops
*self
, ptid_t ptid
)
5838 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5840 if (target_is_non_stop_p ())
5841 remote_stop_ns (ptid
);
5844 /* We don't currently have a way to transparently pause the
5845 remote target in all-stop mode. Interrupt it instead. */
5846 remote_interrupt_as ();
5850 /* Implement the to_interrupt function for the remote targets. */
5853 remote_interrupt (struct target_ops
*self
, ptid_t ptid
)
5855 struct remote_state
*rs
= get_remote_state ();
5858 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
5860 if (target_is_non_stop_p ())
5861 remote_interrupt_ns ();
5863 remote_interrupt_as ();
5866 /* Implement the to_pass_ctrlc function for the remote targets. */
5869 remote_pass_ctrlc (struct target_ops
*self
)
5871 struct remote_state
*rs
= get_remote_state ();
5874 fprintf_unfiltered (gdb_stdlog
, "remote_pass_ctrlc called\n");
5876 /* If we're starting up, we're not fully synced yet. Quit
5878 if (rs
->starting_up
)
5880 /* If ^C has already been sent once, offer to disconnect. */
5881 else if (rs
->ctrlc_pending_p
)
5884 target_interrupt (inferior_ptid
);
5887 /* Ask the user what to do when an interrupt is received. */
5890 interrupt_query (void)
5892 struct remote_state
*rs
= get_remote_state ();
5894 if (rs
->waiting_for_stop_reply
&& rs
->ctrlc_pending_p
)
5896 if (query (_("The target is not responding to interrupt requests.\n"
5897 "Stop debugging it? ")))
5899 remote_unpush_target ();
5900 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
5905 if (query (_("Interrupted while waiting for the program.\n"
5906 "Give up waiting? ")))
5911 /* Enable/disable target terminal ownership. Most targets can use
5912 terminal groups to control terminal ownership. Remote targets are
5913 different in that explicit transfer of ownership to/from GDB/target
5917 remote_terminal_inferior (struct target_ops
*self
)
5919 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5920 idempotent. The event-loop GDB talking to an asynchronous target
5921 with a synchronous command calls this function from both
5922 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5923 transfer the terminal to the target when it shouldn't this guard
5925 if (!remote_async_terminal_ours_p
)
5927 remote_async_terminal_ours_p
= 0;
5928 /* NOTE: At this point we could also register our selves as the
5929 recipient of all input. Any characters typed could then be
5930 passed on down to the target. */
5934 remote_terminal_ours (struct target_ops
*self
)
5936 /* See FIXME in remote_terminal_inferior. */
5937 if (remote_async_terminal_ours_p
)
5939 remote_async_terminal_ours_p
= 1;
5943 remote_console_output (char *msg
)
5947 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5950 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5954 fputs_unfiltered (tb
, gdb_stdtarg
);
5956 gdb_flush (gdb_stdtarg
);
5959 typedef struct cached_reg
5962 gdb_byte data
[MAX_REGISTER_SIZE
];
5965 DEF_VEC_O(cached_reg_t
);
5967 typedef struct stop_reply
5969 struct notif_event base
;
5971 /* The identifier of the thread about this event */
5974 /* The remote state this event is associated with. When the remote
5975 connection, represented by a remote_state object, is closed,
5976 all the associated stop_reply events should be released. */
5977 struct remote_state
*rs
;
5979 struct target_waitstatus ws
;
5981 /* Expedited registers. This makes remote debugging a bit more
5982 efficient for those targets that provide critical registers as
5983 part of their normal status mechanism (as another roundtrip to
5984 fetch them is avoided). */
5985 VEC(cached_reg_t
) *regcache
;
5987 enum target_stop_reason stop_reason
;
5989 CORE_ADDR watch_data_address
;
5994 DECLARE_QUEUE_P (stop_reply_p
);
5995 DEFINE_QUEUE_P (stop_reply_p
);
5996 /* The list of already fetched and acknowledged stop events. This
5997 queue is used for notification Stop, and other notifications
5998 don't need queue for their events, because the notification events
5999 of Stop can't be consumed immediately, so that events should be
6000 queued first, and be consumed by remote_wait_{ns,as} one per
6001 time. Other notifications can consume their events immediately,
6002 so queue is not needed for them. */
6003 static QUEUE (stop_reply_p
) *stop_reply_queue
;
6006 stop_reply_xfree (struct stop_reply
*r
)
6008 notif_event_xfree ((struct notif_event
*) r
);
6011 /* Return the length of the stop reply queue. */
6014 stop_reply_queue_length (void)
6016 return QUEUE_length (stop_reply_p
, stop_reply_queue
);
6020 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
6021 struct notif_event
*event
)
6023 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
6027 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
6028 struct notif_event
*event
)
6030 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
6033 putpkt (self
->ack_command
);
6035 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
6036 /* We got an unknown stop reply. */
6037 error (_("Unknown stop reply"));
6039 push_stop_reply (stop_reply
);
6043 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
6045 /* We can't get pending events in remote_notif_process for
6046 notification stop, and we have to do this in remote_wait_ns
6047 instead. If we fetch all queued events from stub, remote stub
6048 may exit and we have no chance to process them back in
6050 mark_async_event_handler (remote_async_inferior_event_token
);
6055 stop_reply_dtr (struct notif_event
*event
)
6057 struct stop_reply
*r
= (struct stop_reply
*) event
;
6059 VEC_free (cached_reg_t
, r
->regcache
);
6062 static struct notif_event
*
6063 remote_notif_stop_alloc_reply (void)
6065 /* We cast to a pointer to the "base class". */
6066 struct notif_event
*r
= (struct notif_event
*) XNEW (struct stop_reply
);
6068 r
->dtr
= stop_reply_dtr
;
6073 /* A client of notification Stop. */
6075 struct notif_client notif_client_stop
=
6079 remote_notif_stop_parse
,
6080 remote_notif_stop_ack
,
6081 remote_notif_stop_can_get_pending_events
,
6082 remote_notif_stop_alloc_reply
,
6086 /* A parameter to pass data in and out. */
6088 struct queue_iter_param
6091 struct stop_reply
*output
;
6094 /* Determine if THREAD is a pending fork parent thread. ARG contains
6095 the pid of the process that owns the threads we want to check, or
6096 -1 if we want to check all threads. */
6099 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
6102 if (ws
->kind
== TARGET_WAITKIND_FORKED
6103 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
6105 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
6112 /* Check whether EVENT is a fork event, and if it is, remove the
6113 fork child from the context list passed in DATA. */
6116 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
6117 QUEUE_ITER (stop_reply_p
) *iter
,
6121 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6122 struct threads_listing_context
*context
6123 = (struct threads_listing_context
*) param
->input
;
6125 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
6126 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
6127 || event
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
6128 threads_listing_context_remove (&event
->ws
, context
);
6133 /* If CONTEXT contains any fork child threads that have not been
6134 reported yet, remove them from the CONTEXT list. If such a
6135 thread exists it is because we are stopped at a fork catchpoint
6136 and have not yet called follow_fork, which will set up the
6137 host-side data structures for the new process. */
6140 remove_new_fork_children (struct threads_listing_context
*context
)
6142 struct thread_info
* thread
;
6144 struct notif_client
*notif
= ¬if_client_stop
;
6145 struct queue_iter_param param
;
6147 /* For any threads stopped at a fork event, remove the corresponding
6148 fork child threads from the CONTEXT list. */
6149 ALL_NON_EXITED_THREADS (thread
)
6151 struct target_waitstatus
*ws
;
6153 if (thread
->suspend
.waitstatus_pending_p
)
6154 ws
= &thread
->suspend
.waitstatus
;
6156 ws
= &thread
->pending_follow
;
6158 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
6160 threads_listing_context_remove (ws
, context
);
6164 /* Check for any pending fork events (not reported or processed yet)
6165 in process PID and remove those fork child threads from the
6166 CONTEXT list as well. */
6167 remote_notif_get_pending_events (notif
);
6168 param
.input
= context
;
6169 param
.output
= NULL
;
6170 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6171 remove_child_of_pending_fork
, ¶m
);
6174 /* Remove stop replies in the queue if its pid is equal to the given
6178 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
6179 QUEUE_ITER (stop_reply_p
) *iter
,
6183 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6184 struct inferior
*inf
= (struct inferior
*) param
->input
;
6186 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
6188 stop_reply_xfree (event
);
6189 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6195 /* Discard all pending stop replies of inferior INF. */
6198 discard_pending_stop_replies (struct inferior
*inf
)
6200 struct queue_iter_param param
;
6201 struct stop_reply
*reply
;
6202 struct remote_state
*rs
= get_remote_state ();
6203 struct remote_notif_state
*rns
= rs
->notif_state
;
6205 /* This function can be notified when an inferior exists. When the
6206 target is not remote, the notification state is NULL. */
6207 if (rs
->remote_desc
== NULL
)
6210 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
6212 /* Discard the in-flight notification. */
6213 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
6215 stop_reply_xfree (reply
);
6216 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
6220 param
.output
= NULL
;
6221 /* Discard the stop replies we have already pulled with
6223 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6224 remove_stop_reply_for_inferior
, ¶m
);
6227 /* If its remote state is equal to the given remote state,
6228 remove EVENT from the stop reply queue. */
6231 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
6232 QUEUE_ITER (stop_reply_p
) *iter
,
6236 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6237 struct remote_state
*rs
= (struct remote_state
*) param
->input
;
6239 if (event
->rs
== rs
)
6241 stop_reply_xfree (event
);
6242 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6248 /* Discard the stop replies for RS in stop_reply_queue. */
6251 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
6253 struct queue_iter_param param
;
6256 param
.output
= NULL
;
6257 /* Discard the stop replies we have already pulled with
6259 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6260 remove_stop_reply_of_remote_state
, ¶m
);
6263 /* A parameter to pass data in and out. */
6266 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
6267 QUEUE_ITER (stop_reply_p
) *iter
,
6271 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6272 ptid_t
*ptid
= (ptid_t
*) param
->input
;
6274 if (ptid_match (event
->ptid
, *ptid
))
6276 param
->output
= event
;
6277 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6284 /* Remove the first reply in 'stop_reply_queue' which matches
6287 static struct stop_reply
*
6288 remote_notif_remove_queued_reply (ptid_t ptid
)
6290 struct queue_iter_param param
;
6292 param
.input
= &ptid
;
6293 param
.output
= NULL
;
6295 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6296 remote_notif_remove_once_on_match
, ¶m
);
6298 fprintf_unfiltered (gdb_stdlog
,
6299 "notif: discard queued event: 'Stop' in %s\n",
6300 target_pid_to_str (ptid
));
6302 return param
.output
;
6305 /* Look for a queued stop reply belonging to PTID. If one is found,
6306 remove it from the queue, and return it. Returns NULL if none is
6307 found. If there are still queued events left to process, tell the
6308 event loop to get back to target_wait soon. */
6310 static struct stop_reply
*
6311 queued_stop_reply (ptid_t ptid
)
6313 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
6315 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6316 /* There's still at least an event left. */
6317 mark_async_event_handler (remote_async_inferior_event_token
);
6322 /* Push a fully parsed stop reply in the stop reply queue. Since we
6323 know that we now have at least one queued event left to pass to the
6324 core side, tell the event loop to get back to target_wait soon. */
6327 push_stop_reply (struct stop_reply
*new_event
)
6329 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
6332 fprintf_unfiltered (gdb_stdlog
,
6333 "notif: push 'Stop' %s to queue %d\n",
6334 target_pid_to_str (new_event
->ptid
),
6335 QUEUE_length (stop_reply_p
,
6338 mark_async_event_handler (remote_async_inferior_event_token
);
6342 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
6343 QUEUE_ITER (stop_reply_p
) *iter
,
6344 struct stop_reply
*event
,
6347 ptid_t
*ptid
= (ptid_t
*) data
;
6349 return !(ptid_equal (*ptid
, event
->ptid
)
6350 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
6353 /* Returns true if we have a stop reply for PTID. */
6356 peek_stop_reply (ptid_t ptid
)
6358 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6359 stop_reply_match_ptid_and_ws
, &ptid
);
6362 /* Helper for remote_parse_stop_reply. Return nonzero if the substring
6363 starting with P and ending with PEND matches PREFIX. */
6366 strprefix (const char *p
, const char *pend
, const char *prefix
)
6368 for ( ; p
< pend
; p
++, prefix
++)
6371 return *prefix
== '\0';
6374 /* Parse the stop reply in BUF. Either the function succeeds, and the
6375 result is stored in EVENT, or throws an error. */
6378 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
6380 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6385 event
->ptid
= null_ptid
;
6386 event
->rs
= get_remote_state ();
6387 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
6388 event
->ws
.value
.integer
= 0;
6389 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6390 event
->regcache
= NULL
;
6395 case 'T': /* Status with PC, SP, FP, ... */
6396 /* Expedited reply, containing Signal, {regno, reg} repeat. */
6397 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
6399 n... = register number
6400 r... = register contents
6403 p
= &buf
[3]; /* after Txx */
6409 p1
= strchr (p
, ':');
6411 error (_("Malformed packet(a) (missing colon): %s\n\
6415 error (_("Malformed packet(a) (missing register number): %s\n\
6419 /* Some "registers" are actually extended stop information.
6420 Note if you're adding a new entry here: GDB 7.9 and
6421 earlier assume that all register "numbers" that start
6422 with an hex digit are real register numbers. Make sure
6423 the server only sends such a packet if it knows the
6424 client understands it. */
6426 if (strprefix (p
, p1
, "thread"))
6427 event
->ptid
= read_ptid (++p1
, &p
);
6428 else if (strprefix (p
, p1
, "syscall_entry"))
6432 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_ENTRY
;
6433 p
= unpack_varlen_hex (++p1
, &sysno
);
6434 event
->ws
.value
.syscall_number
= (int) sysno
;
6436 else if (strprefix (p
, p1
, "syscall_return"))
6440 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_RETURN
;
6441 p
= unpack_varlen_hex (++p1
, &sysno
);
6442 event
->ws
.value
.syscall_number
= (int) sysno
;
6444 else if (strprefix (p
, p1
, "watch")
6445 || strprefix (p
, p1
, "rwatch")
6446 || strprefix (p
, p1
, "awatch"))
6448 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
6449 p
= unpack_varlen_hex (++p1
, &addr
);
6450 event
->watch_data_address
= (CORE_ADDR
) addr
;
6452 else if (strprefix (p
, p1
, "swbreak"))
6454 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
6456 /* Make sure the stub doesn't forget to indicate support
6458 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
6459 error (_("Unexpected swbreak stop reason"));
6461 /* The value part is documented as "must be empty",
6462 though we ignore it, in case we ever decide to make
6463 use of it in a backward compatible way. */
6464 p
= strchrnul (p1
+ 1, ';');
6466 else if (strprefix (p
, p1
, "hwbreak"))
6468 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
6470 /* Make sure the stub doesn't forget to indicate support
6472 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
6473 error (_("Unexpected hwbreak stop reason"));
6476 p
= strchrnul (p1
+ 1, ';');
6478 else if (strprefix (p
, p1
, "library"))
6480 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
6481 p
= strchrnul (p1
+ 1, ';');
6483 else if (strprefix (p
, p1
, "replaylog"))
6485 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
6486 /* p1 will indicate "begin" or "end", but it makes
6487 no difference for now, so ignore it. */
6488 p
= strchrnul (p1
+ 1, ';');
6490 else if (strprefix (p
, p1
, "core"))
6494 p
= unpack_varlen_hex (++p1
, &c
);
6497 else if (strprefix (p
, p1
, "fork"))
6499 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6500 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
6502 else if (strprefix (p
, p1
, "vfork"))
6504 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6505 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
6507 else if (strprefix (p
, p1
, "vforkdone"))
6509 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
6510 p
= strchrnul (p1
+ 1, ';');
6512 else if (strprefix (p
, p1
, "exec"))
6515 char pathname
[PATH_MAX
];
6518 /* Determine the length of the execd pathname. */
6519 p
= unpack_varlen_hex (++p1
, &ignored
);
6520 pathlen
= (p
- p1
) / 2;
6522 /* Save the pathname for event reporting and for
6523 the next run command. */
6524 hex2bin (p1
, (gdb_byte
*) pathname
, pathlen
);
6525 pathname
[pathlen
] = '\0';
6527 /* This is freed during event handling. */
6528 event
->ws
.value
.execd_pathname
= xstrdup (pathname
);
6529 event
->ws
.kind
= TARGET_WAITKIND_EXECD
;
6531 /* Skip the registers included in this packet, since
6532 they may be for an architecture different from the
6533 one used by the original program. */
6536 else if (strprefix (p
, p1
, "create"))
6538 event
->ws
.kind
= TARGET_WAITKIND_THREAD_CREATED
;
6539 p
= strchrnul (p1
+ 1, ';');
6548 p
= strchrnul (p1
+ 1, ';');
6553 /* Maybe a real ``P'' register number. */
6554 p_temp
= unpack_varlen_hex (p
, &pnum
);
6555 /* If the first invalid character is the colon, we got a
6556 register number. Otherwise, it's an unknown stop
6560 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
6561 cached_reg_t cached_reg
;
6564 error (_("Remote sent bad register number %s: %s\n\
6566 hex_string (pnum
), p
, buf
);
6568 cached_reg
.num
= reg
->regnum
;
6571 fieldsize
= hex2bin (p
, cached_reg
.data
,
6572 register_size (target_gdbarch (),
6575 if (fieldsize
< register_size (target_gdbarch (),
6577 warning (_("Remote reply is too short: %s"), buf
);
6579 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
6583 /* Not a number. Silently skip unknown optional
6585 p
= strchrnul (p1
+ 1, ';');
6590 error (_("Remote register badly formatted: %s\nhere: %s"),
6595 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
6599 case 'S': /* Old style status, just signal only. */
6603 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
6604 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
6605 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
6606 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
6608 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6611 case 'w': /* Thread exited. */
6616 event
->ws
.kind
= TARGET_WAITKIND_THREAD_EXITED
;
6617 p
= unpack_varlen_hex (&buf
[1], &value
);
6618 event
->ws
.value
.integer
= value
;
6620 error (_("stop reply packet badly formatted: %s"), buf
);
6621 event
->ptid
= read_ptid (++p
, NULL
);
6624 case 'W': /* Target exited. */
6631 /* GDB used to accept only 2 hex chars here. Stubs should
6632 only send more if they detect GDB supports multi-process
6634 p
= unpack_varlen_hex (&buf
[1], &value
);
6638 /* The remote process exited. */
6639 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
6640 event
->ws
.value
.integer
= value
;
6644 /* The remote process exited with a signal. */
6645 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
6646 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
6647 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
6649 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6652 /* If no process is specified, assume inferior_ptid. */
6653 pid
= ptid_get_pid (inferior_ptid
);
6662 else if (startswith (p
, "process:"))
6666 p
+= sizeof ("process:") - 1;
6667 unpack_varlen_hex (p
, &upid
);
6671 error (_("unknown stop reply packet: %s"), buf
);
6674 error (_("unknown stop reply packet: %s"), buf
);
6675 event
->ptid
= pid_to_ptid (pid
);
6679 event
->ws
.kind
= TARGET_WAITKIND_NO_RESUMED
;
6680 event
->ptid
= minus_one_ptid
;
6684 if (target_is_non_stop_p () && ptid_equal (event
->ptid
, null_ptid
))
6685 error (_("No process or thread specified in stop reply: %s"), buf
);
6688 /* When the stub wants to tell GDB about a new notification reply, it
6689 sends a notification (%Stop, for example). Those can come it at
6690 any time, hence, we have to make sure that any pending
6691 putpkt/getpkt sequence we're making is finished, before querying
6692 the stub for more events with the corresponding ack command
6693 (vStopped, for example). E.g., if we started a vStopped sequence
6694 immediately upon receiving the notification, something like this
6702 1.6) <-- (registers reply to step #1.3)
6704 Obviously, the reply in step #1.6 would be unexpected to a vStopped
6707 To solve this, whenever we parse a %Stop notification successfully,
6708 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
6709 doing whatever we were doing:
6715 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
6716 2.5) <-- (registers reply to step #2.3)
6718 Eventualy after step #2.5, we return to the event loop, which
6719 notices there's an event on the
6720 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
6721 associated callback --- the function below. At this point, we're
6722 always safe to start a vStopped sequence. :
6725 2.7) <-- T05 thread:2
6731 remote_notif_get_pending_events (struct notif_client
*nc
)
6733 struct remote_state
*rs
= get_remote_state ();
6735 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
6738 fprintf_unfiltered (gdb_stdlog
,
6739 "notif: process: '%s' ack pending event\n",
6743 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
6744 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
6748 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6749 if (strcmp (rs
->buf
, "OK") == 0)
6752 remote_notif_ack (nc
, rs
->buf
);
6758 fprintf_unfiltered (gdb_stdlog
,
6759 "notif: process: '%s' no pending reply\n",
6764 /* Called when it is decided that STOP_REPLY holds the info of the
6765 event that is to be returned to the core. This function always
6766 destroys STOP_REPLY. */
6769 process_stop_reply (struct stop_reply
*stop_reply
,
6770 struct target_waitstatus
*status
)
6774 *status
= stop_reply
->ws
;
6775 ptid
= stop_reply
->ptid
;
6777 /* If no thread/process was reported by the stub, assume the current
6779 if (ptid_equal (ptid
, null_ptid
))
6780 ptid
= inferior_ptid
;
6782 if (status
->kind
!= TARGET_WAITKIND_EXITED
6783 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
6784 && status
->kind
!= TARGET_WAITKIND_NO_RESUMED
)
6786 struct private_thread_info
*remote_thr
;
6788 /* Expedited registers. */
6789 if (stop_reply
->regcache
)
6791 struct regcache
*regcache
6792 = get_thread_arch_regcache (ptid
, target_gdbarch ());
6797 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
6799 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
6800 VEC_free (cached_reg_t
, stop_reply
->regcache
);
6803 remote_notice_new_inferior (ptid
, 0);
6804 remote_thr
= demand_private_info (ptid
);
6805 remote_thr
->core
= stop_reply
->core
;
6806 remote_thr
->stop_reason
= stop_reply
->stop_reason
;
6807 remote_thr
->watch_data_address
= stop_reply
->watch_data_address
;
6810 stop_reply_xfree (stop_reply
);
6814 /* The non-stop mode version of target_wait. */
6817 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6819 struct remote_state
*rs
= get_remote_state ();
6820 struct stop_reply
*stop_reply
;
6824 /* If in non-stop mode, get out of getpkt even if a
6825 notification is received. */
6827 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6828 0 /* forever */, &is_notif
);
6831 if (ret
!= -1 && !is_notif
)
6834 case 'E': /* Error of some sort. */
6835 /* We're out of sync with the target now. Did it continue
6836 or not? We can't tell which thread it was in non-stop,
6837 so just ignore this. */
6838 warning (_("Remote failure reply: %s"), rs
->buf
);
6840 case 'O': /* Console output. */
6841 remote_console_output (rs
->buf
+ 1);
6844 warning (_("Invalid remote reply: %s"), rs
->buf
);
6848 /* Acknowledge a pending stop reply that may have arrived in the
6850 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
6851 remote_notif_get_pending_events (¬if_client_stop
);
6853 /* If indeed we noticed a stop reply, we're done. */
6854 stop_reply
= queued_stop_reply (ptid
);
6855 if (stop_reply
!= NULL
)
6856 return process_stop_reply (stop_reply
, status
);
6858 /* Still no event. If we're just polling for an event, then
6859 return to the event loop. */
6860 if (options
& TARGET_WNOHANG
)
6862 status
->kind
= TARGET_WAITKIND_IGNORE
;
6863 return minus_one_ptid
;
6866 /* Otherwise do a blocking wait. */
6867 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6868 1 /* forever */, &is_notif
);
6872 /* Wait until the remote machine stops, then return, storing status in
6873 STATUS just as `wait' would. */
6876 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6878 struct remote_state
*rs
= get_remote_state ();
6879 ptid_t event_ptid
= null_ptid
;
6881 struct stop_reply
*stop_reply
;
6885 status
->kind
= TARGET_WAITKIND_IGNORE
;
6886 status
->value
.integer
= 0;
6888 stop_reply
= queued_stop_reply (ptid
);
6889 if (stop_reply
!= NULL
)
6890 return process_stop_reply (stop_reply
, status
);
6892 if (rs
->cached_wait_status
)
6893 /* Use the cached wait status, but only once. */
6894 rs
->cached_wait_status
= 0;
6899 int forever
= ((options
& TARGET_WNOHANG
) == 0
6900 && wait_forever_enabled_p
);
6902 if (!rs
->waiting_for_stop_reply
)
6904 status
->kind
= TARGET_WAITKIND_NO_RESUMED
;
6905 return minus_one_ptid
;
6908 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6909 _never_ wait for ever -> test on target_is_async_p().
6910 However, before we do that we need to ensure that the caller
6911 knows how to take the target into/out of async mode. */
6912 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6913 forever
, &is_notif
);
6915 /* GDB gets a notification. Return to core as this event is
6917 if (ret
!= -1 && is_notif
)
6918 return minus_one_ptid
;
6920 if (ret
== -1 && (options
& TARGET_WNOHANG
) != 0)
6921 return minus_one_ptid
;
6926 /* Assume that the target has acknowledged Ctrl-C unless we receive
6927 an 'F' or 'O' packet. */
6928 if (buf
[0] != 'F' && buf
[0] != 'O')
6929 rs
->ctrlc_pending_p
= 0;
6933 case 'E': /* Error of some sort. */
6934 /* We're out of sync with the target now. Did it continue or
6935 not? Not is more likely, so report a stop. */
6936 rs
->waiting_for_stop_reply
= 0;
6938 warning (_("Remote failure reply: %s"), buf
);
6939 status
->kind
= TARGET_WAITKIND_STOPPED
;
6940 status
->value
.sig
= GDB_SIGNAL_0
;
6942 case 'F': /* File-I/O request. */
6943 /* GDB may access the inferior memory while handling the File-I/O
6944 request, but we don't want GDB accessing memory while waiting
6945 for a stop reply. See the comments in putpkt_binary. Set
6946 waiting_for_stop_reply to 0 temporarily. */
6947 rs
->waiting_for_stop_reply
= 0;
6948 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6949 rs
->ctrlc_pending_p
= 0;
6950 /* GDB handled the File-I/O request, and the target is running
6951 again. Keep waiting for events. */
6952 rs
->waiting_for_stop_reply
= 1;
6954 case 'N': case 'T': case 'S': case 'X': case 'W':
6956 struct stop_reply
*stop_reply
;
6958 /* There is a stop reply to handle. */
6959 rs
->waiting_for_stop_reply
= 0;
6962 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6965 event_ptid
= process_stop_reply (stop_reply
, status
);
6968 case 'O': /* Console output. */
6969 remote_console_output (buf
+ 1);
6972 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6974 /* Zero length reply means that we tried 'S' or 'C' and the
6975 remote system doesn't support it. */
6976 target_terminal_ours_for_output ();
6978 ("Can't send signals to this remote system. %s not sent.\n",
6979 gdb_signal_to_name (rs
->last_sent_signal
));
6980 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6981 target_terminal_inferior ();
6983 strcpy (buf
, rs
->last_sent_step
? "s" : "c");
6987 /* else fallthrough */
6989 warning (_("Invalid remote reply: %s"), buf
);
6993 if (status
->kind
== TARGET_WAITKIND_NO_RESUMED
)
6994 return minus_one_ptid
;
6995 else if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6997 /* Nothing interesting happened. If we're doing a non-blocking
6998 poll, we're done. Otherwise, go back to waiting. */
6999 if (options
& TARGET_WNOHANG
)
7000 return minus_one_ptid
;
7004 else if (status
->kind
!= TARGET_WAITKIND_EXITED
7005 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
7007 if (!ptid_equal (event_ptid
, null_ptid
))
7008 record_currthread (rs
, event_ptid
);
7010 event_ptid
= inferior_ptid
;
7013 /* A process exit. Invalidate our notion of current thread. */
7014 record_currthread (rs
, minus_one_ptid
);
7019 /* Wait until the remote machine stops, then return, storing status in
7020 STATUS just as `wait' would. */
7023 remote_wait (struct target_ops
*ops
,
7024 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7028 if (target_is_non_stop_p ())
7029 event_ptid
= remote_wait_ns (ptid
, status
, options
);
7031 event_ptid
= remote_wait_as (ptid
, status
, options
);
7033 if (target_is_async_p ())
7035 /* If there are are events left in the queue tell the event loop
7037 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
7038 mark_async_event_handler (remote_async_inferior_event_token
);
7044 /* Fetch a single register using a 'p' packet. */
7047 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
7049 struct remote_state
*rs
= get_remote_state ();
7051 char regp
[MAX_REGISTER_SIZE
];
7054 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
7057 if (reg
->pnum
== -1)
7062 p
+= hexnumstr (p
, reg
->pnum
);
7065 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7069 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
7073 case PACKET_UNKNOWN
:
7076 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
7077 gdbarch_register_name (get_regcache_arch (regcache
),
7082 /* If this register is unfetchable, tell the regcache. */
7085 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7089 /* Otherwise, parse and supply the value. */
7095 error (_("fetch_register_using_p: early buf termination"));
7097 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7100 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
7104 /* Fetch the registers included in the target's 'g' packet. */
7107 send_g_packet (void)
7109 struct remote_state
*rs
= get_remote_state ();
7112 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
7113 remote_send (&rs
->buf
, &rs
->buf_size
);
7115 /* We can get out of synch in various cases. If the first character
7116 in the buffer is not a hex character, assume that has happened
7117 and try to fetch another packet to read. */
7118 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
7119 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
7120 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
7121 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
7124 fprintf_unfiltered (gdb_stdlog
,
7125 "Bad register packet; fetching a new packet\n");
7126 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7129 buf_len
= strlen (rs
->buf
);
7131 /* Sanity check the received packet. */
7132 if (buf_len
% 2 != 0)
7133 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
7139 process_g_packet (struct regcache
*regcache
)
7141 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7142 struct remote_state
*rs
= get_remote_state ();
7143 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7148 buf_len
= strlen (rs
->buf
);
7150 /* Further sanity checks, with knowledge of the architecture. */
7151 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
7152 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
7154 /* Save the size of the packet sent to us by the target. It is used
7155 as a heuristic when determining the max size of packets that the
7156 target can safely receive. */
7157 if (rsa
->actual_register_packet_size
== 0)
7158 rsa
->actual_register_packet_size
= buf_len
;
7160 /* If this is smaller than we guessed the 'g' packet would be,
7161 update our records. A 'g' reply that doesn't include a register's
7162 value implies either that the register is not available, or that
7163 the 'p' packet must be used. */
7164 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
7166 rsa
->sizeof_g_packet
= buf_len
/ 2;
7168 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7170 if (rsa
->regs
[i
].pnum
== -1)
7173 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
7174 rsa
->regs
[i
].in_g_packet
= 0;
7176 rsa
->regs
[i
].in_g_packet
= 1;
7180 regs
= (char *) alloca (rsa
->sizeof_g_packet
);
7182 /* Unimplemented registers read as all bits zero. */
7183 memset (regs
, 0, rsa
->sizeof_g_packet
);
7185 /* Reply describes registers byte by byte, each byte encoded as two
7186 hex characters. Suck them all up, then supply them to the
7187 register cacheing/storage mechanism. */
7190 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
7192 if (p
[0] == 0 || p
[1] == 0)
7193 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
7194 internal_error (__FILE__
, __LINE__
,
7195 _("unexpected end of 'g' packet reply"));
7197 if (p
[0] == 'x' && p
[1] == 'x')
7198 regs
[i
] = 0; /* 'x' */
7200 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7204 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7206 struct packet_reg
*r
= &rsa
->regs
[i
];
7210 if (r
->offset
* 2 >= strlen (rs
->buf
))
7211 /* This shouldn't happen - we adjusted in_g_packet above. */
7212 internal_error (__FILE__
, __LINE__
,
7213 _("unexpected end of 'g' packet reply"));
7214 else if (rs
->buf
[r
->offset
* 2] == 'x')
7216 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
7217 /* The register isn't available, mark it as such (at
7218 the same time setting the value to zero). */
7219 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
7222 regcache_raw_supply (regcache
, r
->regnum
,
7229 fetch_registers_using_g (struct regcache
*regcache
)
7232 process_g_packet (regcache
);
7235 /* Make the remote selected traceframe match GDB's selected
7239 set_remote_traceframe (void)
7242 struct remote_state
*rs
= get_remote_state ();
7244 if (rs
->remote_traceframe_number
== get_traceframe_number ())
7247 /* Avoid recursion, remote_trace_find calls us again. */
7248 rs
->remote_traceframe_number
= get_traceframe_number ();
7250 newnum
= target_trace_find (tfind_number
,
7251 get_traceframe_number (), 0, 0, NULL
);
7253 /* Should not happen. If it does, all bets are off. */
7254 if (newnum
!= get_traceframe_number ())
7255 warning (_("could not set remote traceframe"));
7259 remote_fetch_registers (struct target_ops
*ops
,
7260 struct regcache
*regcache
, int regnum
)
7262 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7265 set_remote_traceframe ();
7266 set_general_thread (inferior_ptid
);
7270 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7272 gdb_assert (reg
!= NULL
);
7274 /* If this register might be in the 'g' packet, try that first -
7275 we are likely to read more than one register. If this is the
7276 first 'g' packet, we might be overly optimistic about its
7277 contents, so fall back to 'p'. */
7278 if (reg
->in_g_packet
)
7280 fetch_registers_using_g (regcache
);
7281 if (reg
->in_g_packet
)
7285 if (fetch_register_using_p (regcache
, reg
))
7288 /* This register is not available. */
7289 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7294 fetch_registers_using_g (regcache
);
7296 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7297 if (!rsa
->regs
[i
].in_g_packet
)
7298 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
7300 /* This register is not available. */
7301 regcache_raw_supply (regcache
, i
, NULL
);
7305 /* Prepare to store registers. Since we may send them all (using a
7306 'G' request), we have to read out the ones we don't want to change
7310 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
7312 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7314 gdb_byte buf
[MAX_REGISTER_SIZE
];
7316 /* Make sure the entire registers array is valid. */
7317 switch (packet_support (PACKET_P
))
7319 case PACKET_DISABLE
:
7320 case PACKET_SUPPORT_UNKNOWN
:
7321 /* Make sure all the necessary registers are cached. */
7322 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7323 if (rsa
->regs
[i
].in_g_packet
)
7324 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
7331 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
7332 packet was not recognized. */
7335 store_register_using_P (const struct regcache
*regcache
,
7336 struct packet_reg
*reg
)
7338 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7339 struct remote_state
*rs
= get_remote_state ();
7340 /* Try storing a single register. */
7341 char *buf
= rs
->buf
;
7342 gdb_byte regp
[MAX_REGISTER_SIZE
];
7345 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
7348 if (reg
->pnum
== -1)
7351 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
7352 p
= buf
+ strlen (buf
);
7353 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
7354 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
7356 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7358 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
7363 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
7364 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
7365 case PACKET_UNKNOWN
:
7368 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
7372 /* Store register REGNUM, or all registers if REGNUM == -1, from the
7373 contents of the register cache buffer. FIXME: ignores errors. */
7376 store_registers_using_G (const struct regcache
*regcache
)
7378 struct remote_state
*rs
= get_remote_state ();
7379 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7383 /* Extract all the registers in the regcache copying them into a
7388 regs
= (gdb_byte
*) alloca (rsa
->sizeof_g_packet
);
7389 memset (regs
, 0, rsa
->sizeof_g_packet
);
7390 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7392 struct packet_reg
*r
= &rsa
->regs
[i
];
7395 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
7399 /* Command describes registers byte by byte,
7400 each byte encoded as two hex characters. */
7403 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
7405 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
7407 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7408 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
7409 error (_("Could not write registers; remote failure reply '%s'"),
7413 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
7414 of the register cache buffer. FIXME: ignores errors. */
7417 remote_store_registers (struct target_ops
*ops
,
7418 struct regcache
*regcache
, int regnum
)
7420 struct remote_arch_state
*rsa
= get_remote_arch_state ();
7423 set_remote_traceframe ();
7424 set_general_thread (inferior_ptid
);
7428 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
7430 gdb_assert (reg
!= NULL
);
7432 /* Always prefer to store registers using the 'P' packet if
7433 possible; we often change only a small number of registers.
7434 Sometimes we change a larger number; we'd need help from a
7435 higher layer to know to use 'G'. */
7436 if (store_register_using_P (regcache
, reg
))
7439 /* For now, don't complain if we have no way to write the
7440 register. GDB loses track of unavailable registers too
7441 easily. Some day, this may be an error. We don't have
7442 any way to read the register, either... */
7443 if (!reg
->in_g_packet
)
7446 store_registers_using_G (regcache
);
7450 store_registers_using_G (regcache
);
7452 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7453 if (!rsa
->regs
[i
].in_g_packet
)
7454 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
7455 /* See above for why we do not issue an error here. */
7460 /* Return the number of hex digits in num. */
7463 hexnumlen (ULONGEST num
)
7467 for (i
= 0; num
!= 0; i
++)
7470 return std::max (i
, 1);
7473 /* Set BUF to the minimum number of hex digits representing NUM. */
7476 hexnumstr (char *buf
, ULONGEST num
)
7478 int len
= hexnumlen (num
);
7480 return hexnumnstr (buf
, num
, len
);
7484 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
7487 hexnumnstr (char *buf
, ULONGEST num
, int width
)
7493 for (i
= width
- 1; i
>= 0; i
--)
7495 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
7502 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
7505 remote_address_masked (CORE_ADDR addr
)
7507 unsigned int address_size
= remote_address_size
;
7509 /* If "remoteaddresssize" was not set, default to target address size. */
7511 address_size
= gdbarch_addr_bit (target_gdbarch ());
7513 if (address_size
> 0
7514 && address_size
< (sizeof (ULONGEST
) * 8))
7516 /* Only create a mask when that mask can safely be constructed
7517 in a ULONGEST variable. */
7520 mask
= (mask
<< address_size
) - 1;
7526 /* Determine whether the remote target supports binary downloading.
7527 This is accomplished by sending a no-op memory write of zero length
7528 to the target at the specified address. It does not suffice to send
7529 the whole packet, since many stubs strip the eighth bit and
7530 subsequently compute a wrong checksum, which causes real havoc with
7533 NOTE: This can still lose if the serial line is not eight-bit
7534 clean. In cases like this, the user should clear "remote
7538 check_binary_download (CORE_ADDR addr
)
7540 struct remote_state
*rs
= get_remote_state ();
7542 switch (packet_support (PACKET_X
))
7544 case PACKET_DISABLE
:
7548 case PACKET_SUPPORT_UNKNOWN
:
7554 p
+= hexnumstr (p
, (ULONGEST
) addr
);
7556 p
+= hexnumstr (p
, (ULONGEST
) 0);
7560 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7561 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7563 if (rs
->buf
[0] == '\0')
7566 fprintf_unfiltered (gdb_stdlog
,
7567 "binary downloading NOT "
7568 "supported by target\n");
7569 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
7574 fprintf_unfiltered (gdb_stdlog
,
7575 "binary downloading supported by target\n");
7576 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
7583 /* Helper function to resize the payload in order to try to get a good
7584 alignment. We try to write an amount of data such that the next write will
7585 start on an address aligned on REMOTE_ALIGN_WRITES. */
7588 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
7590 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
7593 /* Write memory data directly to the remote machine.
7594 This does not inform the data cache; the data cache uses this.
7595 HEADER is the starting part of the packet.
7596 MEMADDR is the address in the remote memory space.
7597 MYADDR is the address of the buffer in our space.
7598 LEN_UNITS is the number of addressable units to write.
7599 UNIT_SIZE is the length in bytes of an addressable unit.
7600 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
7601 should send data as binary ('X'), or hex-encoded ('M').
7603 The function creates packet of the form
7604 <HEADER><ADDRESS>,<LENGTH>:<DATA>
7606 where encoding of <DATA> is terminated by PACKET_FORMAT.
7608 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
7611 Return the transferred status, error or OK (an
7612 'enum target_xfer_status' value). Save the number of addressable units
7613 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
7615 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
7616 exchange between gdb and the stub could look like (?? in place of the
7622 -> $M1000,3:eeeeffffeeee#??
7626 <- eeeeffffeeeedddd */
7628 static enum target_xfer_status
7629 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
7630 const gdb_byte
*myaddr
, ULONGEST len_units
,
7631 int unit_size
, ULONGEST
*xfered_len_units
,
7632 char packet_format
, int use_length
)
7634 struct remote_state
*rs
= get_remote_state ();
7640 int payload_capacity_bytes
;
7641 int payload_length_bytes
;
7643 if (packet_format
!= 'X' && packet_format
!= 'M')
7644 internal_error (__FILE__
, __LINE__
,
7645 _("remote_write_bytes_aux: bad packet format"));
7648 return TARGET_XFER_EOF
;
7650 payload_capacity_bytes
= get_memory_write_packet_size ();
7652 /* The packet buffer will be large enough for the payload;
7653 get_memory_packet_size ensures this. */
7656 /* Compute the size of the actual payload by subtracting out the
7657 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
7659 payload_capacity_bytes
-= strlen ("$,:#NN");
7661 /* The comma won't be used. */
7662 payload_capacity_bytes
+= 1;
7663 payload_capacity_bytes
-= strlen (header
);
7664 payload_capacity_bytes
-= hexnumlen (memaddr
);
7666 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
7668 strcat (rs
->buf
, header
);
7669 p
= rs
->buf
+ strlen (header
);
7671 /* Compute a best guess of the number of bytes actually transfered. */
7672 if (packet_format
== 'X')
7674 /* Best guess at number of bytes that will fit. */
7675 todo_units
= std::min (len_units
,
7676 (ULONGEST
) payload_capacity_bytes
/ unit_size
);
7678 payload_capacity_bytes
-= hexnumlen (todo_units
);
7679 todo_units
= std::min (todo_units
, payload_capacity_bytes
/ unit_size
);
7683 /* Number of bytes that will fit. */
7685 = std::min (len_units
,
7686 (ULONGEST
) (payload_capacity_bytes
/ unit_size
) / 2);
7688 payload_capacity_bytes
-= hexnumlen (todo_units
);
7689 todo_units
= std::min (todo_units
,
7690 (payload_capacity_bytes
/ unit_size
) / 2);
7693 if (todo_units
<= 0)
7694 internal_error (__FILE__
, __LINE__
,
7695 _("minimum packet size too small to write data"));
7697 /* If we already need another packet, then try to align the end
7698 of this packet to a useful boundary. */
7699 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
7700 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
7702 /* Append "<memaddr>". */
7703 memaddr
= remote_address_masked (memaddr
);
7704 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7711 /* Append the length and retain its location and size. It may need to be
7712 adjusted once the packet body has been created. */
7714 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
7722 /* Append the packet body. */
7723 if (packet_format
== 'X')
7725 /* Binary mode. Send target system values byte by byte, in
7726 increasing byte addresses. Only escape certain critical
7728 payload_length_bytes
=
7729 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
7730 &units_written
, payload_capacity_bytes
);
7732 /* If not all TODO units fit, then we'll need another packet. Make
7733 a second try to keep the end of the packet aligned. Don't do
7734 this if the packet is tiny. */
7735 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
7739 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
7741 if (new_todo_units
!= units_written
)
7742 payload_length_bytes
=
7743 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
7744 (gdb_byte
*) p
, &units_written
,
7745 payload_capacity_bytes
);
7748 p
+= payload_length_bytes
;
7749 if (use_length
&& units_written
< todo_units
)
7751 /* Escape chars have filled up the buffer prematurely,
7752 and we have actually sent fewer units than planned.
7753 Fix-up the length field of the packet. Use the same
7754 number of characters as before. */
7755 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
7757 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
7762 /* Normal mode: Send target system values byte by byte, in
7763 increasing byte addresses. Each byte is encoded as a two hex
7765 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
7766 units_written
= todo_units
;
7769 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7770 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7772 if (rs
->buf
[0] == 'E')
7773 return TARGET_XFER_E_IO
;
7775 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
7776 send fewer units than we'd planned. */
7777 *xfered_len_units
= (ULONGEST
) units_written
;
7778 return TARGET_XFER_OK
;
7781 /* Write memory data directly to the remote machine.
7782 This does not inform the data cache; the data cache uses this.
7783 MEMADDR is the address in the remote memory space.
7784 MYADDR is the address of the buffer in our space.
7785 LEN is the number of bytes.
7787 Return the transferred status, error or OK (an
7788 'enum target_xfer_status' value). Save the number of bytes
7789 transferred in *XFERED_LEN. Only transfer a single packet. */
7791 static enum target_xfer_status
7792 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
7793 int unit_size
, ULONGEST
*xfered_len
)
7795 char *packet_format
= 0;
7797 /* Check whether the target supports binary download. */
7798 check_binary_download (memaddr
);
7800 switch (packet_support (PACKET_X
))
7803 packet_format
= "X";
7805 case PACKET_DISABLE
:
7806 packet_format
= "M";
7808 case PACKET_SUPPORT_UNKNOWN
:
7809 internal_error (__FILE__
, __LINE__
,
7810 _("remote_write_bytes: bad internal state"));
7812 internal_error (__FILE__
, __LINE__
, _("bad switch"));
7815 return remote_write_bytes_aux (packet_format
,
7816 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
7817 packet_format
[0], 1);
7820 /* Read memory data directly from the remote machine.
7821 This does not use the data cache; the data cache uses this.
7822 MEMADDR is the address in the remote memory space.
7823 MYADDR is the address of the buffer in our space.
7824 LEN_UNITS is the number of addressable memory units to read..
7825 UNIT_SIZE is the length in bytes of an addressable unit.
7827 Return the transferred status, error or OK (an
7828 'enum target_xfer_status' value). Save the number of bytes
7829 transferred in *XFERED_LEN_UNITS.
7831 See the comment of remote_write_bytes_aux for an example of
7832 memory read/write exchange between gdb and the stub. */
7834 static enum target_xfer_status
7835 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
7836 int unit_size
, ULONGEST
*xfered_len_units
)
7838 struct remote_state
*rs
= get_remote_state ();
7839 int buf_size_bytes
; /* Max size of packet output buffer. */
7844 buf_size_bytes
= get_memory_read_packet_size ();
7845 /* The packet buffer will be large enough for the payload;
7846 get_memory_packet_size ensures this. */
7848 /* Number of units that will fit. */
7849 todo_units
= std::min (len_units
,
7850 (ULONGEST
) (buf_size_bytes
/ unit_size
) / 2);
7852 /* Construct "m"<memaddr>","<len>". */
7853 memaddr
= remote_address_masked (memaddr
);
7856 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7858 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
7861 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7862 if (rs
->buf
[0] == 'E'
7863 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
7864 && rs
->buf
[3] == '\0')
7865 return TARGET_XFER_E_IO
;
7866 /* Reply describes memory byte by byte, each byte encoded as two hex
7869 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
7870 /* Return what we have. Let higher layers handle partial reads. */
7871 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
7872 return TARGET_XFER_OK
;
7875 /* Using the set of read-only target sections of remote, read live
7878 For interface/parameters/return description see target.h,
7881 static enum target_xfer_status
7882 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
7883 ULONGEST memaddr
, ULONGEST len
,
7884 int unit_size
, ULONGEST
*xfered_len
)
7886 struct target_section
*secp
;
7887 struct target_section_table
*table
;
7889 secp
= target_section_by_addr (ops
, memaddr
);
7891 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
7892 secp
->the_bfd_section
)
7895 struct target_section
*p
;
7896 ULONGEST memend
= memaddr
+ len
;
7898 table
= target_get_section_table (ops
);
7900 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
7902 if (memaddr
>= p
->addr
)
7904 if (memend
<= p
->endaddr
)
7906 /* Entire transfer is within this section. */
7907 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7910 else if (memaddr
>= p
->endaddr
)
7912 /* This section ends before the transfer starts. */
7917 /* This section overlaps the transfer. Just do half. */
7918 len
= p
->endaddr
- memaddr
;
7919 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7926 return TARGET_XFER_EOF
;
7929 /* Similar to remote_read_bytes_1, but it reads from the remote stub
7930 first if the requested memory is unavailable in traceframe.
7931 Otherwise, fall back to remote_read_bytes_1. */
7933 static enum target_xfer_status
7934 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
7935 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
7936 ULONGEST
*xfered_len
)
7939 return TARGET_XFER_EOF
;
7941 if (get_traceframe_number () != -1)
7943 VEC(mem_range_s
) *available
;
7945 /* If we fail to get the set of available memory, then the
7946 target does not support querying traceframe info, and so we
7947 attempt reading from the traceframe anyway (assuming the
7948 target implements the old QTro packet then). */
7949 if (traceframe_available_memory (&available
, memaddr
, len
))
7951 struct cleanup
*old_chain
;
7953 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
7955 if (VEC_empty (mem_range_s
, available
)
7956 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
7958 enum target_xfer_status res
;
7960 /* Don't read into the traceframe's available
7962 if (!VEC_empty (mem_range_s
, available
))
7964 LONGEST oldlen
= len
;
7966 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
7967 gdb_assert (len
<= oldlen
);
7970 do_cleanups (old_chain
);
7972 /* This goes through the topmost target again. */
7973 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
7974 len
, unit_size
, xfered_len
);
7975 if (res
== TARGET_XFER_OK
)
7976 return TARGET_XFER_OK
;
7979 /* No use trying further, we know some memory starting
7980 at MEMADDR isn't available. */
7982 return TARGET_XFER_UNAVAILABLE
;
7986 /* Don't try to read more than how much is available, in
7987 case the target implements the deprecated QTro packet to
7988 cater for older GDBs (the target's knowledge of read-only
7989 sections may be outdated by now). */
7990 len
= VEC_index (mem_range_s
, available
, 0)->length
;
7992 do_cleanups (old_chain
);
7996 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
8001 /* Sends a packet with content determined by the printf format string
8002 FORMAT and the remaining arguments, then gets the reply. Returns
8003 whether the packet was a success, a failure, or unknown. */
8005 static enum packet_result
remote_send_printf (const char *format
, ...)
8006 ATTRIBUTE_PRINTF (1, 2);
8008 static enum packet_result
8009 remote_send_printf (const char *format
, ...)
8011 struct remote_state
*rs
= get_remote_state ();
8012 int max_size
= get_remote_packet_size ();
8015 va_start (ap
, format
);
8018 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
8019 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
8021 if (putpkt (rs
->buf
) < 0)
8022 error (_("Communication problem with target."));
8025 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8027 return packet_check_result (rs
->buf
);
8031 restore_remote_timeout (void *p
)
8033 int value
= *(int *)p
;
8035 remote_timeout
= value
;
8038 /* Flash writing can take quite some time. We'll set
8039 effectively infinite timeout for flash operations.
8040 In future, we'll need to decide on a better approach. */
8041 static const int remote_flash_timeout
= 1000;
8044 remote_flash_erase (struct target_ops
*ops
,
8045 ULONGEST address
, LONGEST length
)
8047 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8048 int saved_remote_timeout
= remote_timeout
;
8049 enum packet_result ret
;
8050 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8051 &saved_remote_timeout
);
8053 remote_timeout
= remote_flash_timeout
;
8055 ret
= remote_send_printf ("vFlashErase:%s,%s",
8056 phex (address
, addr_size
),
8060 case PACKET_UNKNOWN
:
8061 error (_("Remote target does not support flash erase"));
8063 error (_("Error erasing flash with vFlashErase packet"));
8068 do_cleanups (back_to
);
8071 static enum target_xfer_status
8072 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
8073 ULONGEST length
, ULONGEST
*xfered_len
,
8074 const gdb_byte
*data
)
8076 int saved_remote_timeout
= remote_timeout
;
8077 enum target_xfer_status ret
;
8078 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8079 &saved_remote_timeout
);
8081 remote_timeout
= remote_flash_timeout
;
8082 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
8084 do_cleanups (back_to
);
8090 remote_flash_done (struct target_ops
*ops
)
8092 int saved_remote_timeout
= remote_timeout
;
8094 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
8095 &saved_remote_timeout
);
8097 remote_timeout
= remote_flash_timeout
;
8098 ret
= remote_send_printf ("vFlashDone");
8099 do_cleanups (back_to
);
8103 case PACKET_UNKNOWN
:
8104 error (_("Remote target does not support vFlashDone"));
8106 error (_("Error finishing flash operation"));
8113 remote_files_info (struct target_ops
*ignore
)
8115 puts_filtered ("Debugging a target over a serial line.\n");
8118 /* Stuff for dealing with the packets which are part of this protocol.
8119 See comment at top of file for details. */
8121 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
8122 error to higher layers. Called when a serial error is detected.
8123 The exception message is STRING, followed by a colon and a blank,
8124 the system error message for errno at function entry and final dot
8125 for output compatibility with throw_perror_with_name. */
8128 unpush_and_perror (const char *string
)
8130 int saved_errno
= errno
;
8132 remote_unpush_target ();
8133 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
8134 safe_strerror (saved_errno
));
8137 /* Read a single character from the remote end. The current quit
8138 handler is overridden to avoid quitting in the middle of packet
8139 sequence, as that would break communication with the remote server.
8140 See remote_serial_quit_handler for more detail. */
8143 readchar (int timeout
)
8146 struct remote_state
*rs
= get_remote_state ();
8147 struct cleanup
*old_chain
;
8149 old_chain
= make_cleanup_override_quit_handler (remote_serial_quit_handler
);
8151 rs
->got_ctrlc_during_io
= 0;
8153 ch
= serial_readchar (rs
->remote_desc
, timeout
);
8155 if (rs
->got_ctrlc_during_io
)
8158 do_cleanups (old_chain
);
8163 switch ((enum serial_rc
) ch
)
8166 remote_unpush_target ();
8167 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
8170 unpush_and_perror (_("Remote communication error. "
8171 "Target disconnected."));
8173 case SERIAL_TIMEOUT
:
8179 /* Wrapper for serial_write that closes the target and throws if
8180 writing fails. The current quit handler is overridden to avoid
8181 quitting in the middle of packet sequence, as that would break
8182 communication with the remote server. See
8183 remote_serial_quit_handler for more detail. */
8186 remote_serial_write (const char *str
, int len
)
8188 struct remote_state
*rs
= get_remote_state ();
8189 struct cleanup
*old_chain
;
8191 old_chain
= make_cleanup_override_quit_handler (remote_serial_quit_handler
);
8193 rs
->got_ctrlc_during_io
= 0;
8195 if (serial_write (rs
->remote_desc
, str
, len
))
8197 unpush_and_perror (_("Remote communication error. "
8198 "Target disconnected."));
8201 if (rs
->got_ctrlc_during_io
)
8204 do_cleanups (old_chain
);
8207 /* Send the command in *BUF to the remote machine, and read the reply
8208 into *BUF. Report an error if we get an error reply. Resize
8209 *BUF using xrealloc if necessary to hold the result, and update
8213 remote_send (char **buf
,
8217 getpkt (buf
, sizeof_buf
, 0);
8219 if ((*buf
)[0] == 'E')
8220 error (_("Remote failure reply: %s"), *buf
);
8223 /* Return a pointer to an xmalloc'ed string representing an escaped
8224 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
8225 etc. The caller is responsible for releasing the returned
8229 escape_buffer (const char *buf
, int n
)
8231 struct cleanup
*old_chain
;
8232 struct ui_file
*stb
;
8235 stb
= mem_fileopen ();
8236 old_chain
= make_cleanup_ui_file_delete (stb
);
8238 fputstrn_unfiltered (buf
, n
, '\\', stb
);
8239 str
= ui_file_xstrdup (stb
, NULL
);
8240 do_cleanups (old_chain
);
8244 /* Display a null-terminated packet on stdout, for debugging, using C
8248 print_packet (const char *buf
)
8250 puts_filtered ("\"");
8251 fputstr_filtered (buf
, '"', gdb_stdout
);
8252 puts_filtered ("\"");
8256 putpkt (const char *buf
)
8258 return putpkt_binary (buf
, strlen (buf
));
8261 /* Send a packet to the remote machine, with error checking. The data
8262 of the packet is in BUF. The string in BUF can be at most
8263 get_remote_packet_size () - 5 to account for the $, # and checksum,
8264 and for a possible /0 if we are debugging (remote_debug) and want
8265 to print the sent packet as a string. */
8268 putpkt_binary (const char *buf
, int cnt
)
8270 struct remote_state
*rs
= get_remote_state ();
8272 unsigned char csum
= 0;
8273 char *buf2
= (char *) xmalloc (cnt
+ 6);
8274 struct cleanup
*old_chain
= make_cleanup (xfree
, buf2
);
8280 /* Catch cases like trying to read memory or listing threads while
8281 we're waiting for a stop reply. The remote server wouldn't be
8282 ready to handle this request, so we'd hang and timeout. We don't
8283 have to worry about this in synchronous mode, because in that
8284 case it's not possible to issue a command while the target is
8285 running. This is not a problem in non-stop mode, because in that
8286 case, the stub is always ready to process serial input. */
8287 if (!target_is_non_stop_p ()
8288 && target_is_async_p ()
8289 && rs
->waiting_for_stop_reply
)
8291 error (_("Cannot execute this command while the target is running.\n"
8292 "Use the \"interrupt\" command to stop the target\n"
8293 "and then try again."));
8296 /* We're sending out a new packet. Make sure we don't look at a
8297 stale cached response. */
8298 rs
->cached_wait_status
= 0;
8300 /* Copy the packet into buffer BUF2, encapsulating it
8301 and giving it a checksum. */
8306 for (i
= 0; i
< cnt
; i
++)
8312 *p
++ = tohex ((csum
>> 4) & 0xf);
8313 *p
++ = tohex (csum
& 0xf);
8315 /* Send it over and over until we get a positive ack. */
8319 int started_error_output
= 0;
8323 struct cleanup
*old_chain
;
8327 str
= escape_buffer (buf2
, p
- buf2
);
8328 old_chain
= make_cleanup (xfree
, str
);
8329 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
8330 gdb_flush (gdb_stdlog
);
8331 do_cleanups (old_chain
);
8333 remote_serial_write (buf2
, p
- buf2
);
8335 /* If this is a no acks version of the remote protocol, send the
8336 packet and move on. */
8340 /* Read until either a timeout occurs (-2) or '+' is read.
8341 Handle any notification that arrives in the mean time. */
8344 ch
= readchar (remote_timeout
);
8352 case SERIAL_TIMEOUT
:
8355 if (started_error_output
)
8357 putchar_unfiltered ('\n');
8358 started_error_output
= 0;
8367 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
8368 do_cleanups (old_chain
);
8372 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
8374 case SERIAL_TIMEOUT
:
8378 do_cleanups (old_chain
);
8381 break; /* Retransmit buffer. */
8385 fprintf_unfiltered (gdb_stdlog
,
8386 "Packet instead of Ack, ignoring it\n");
8387 /* It's probably an old response sent because an ACK
8388 was lost. Gobble up the packet and ack it so it
8389 doesn't get retransmitted when we resend this
8392 remote_serial_write ("+", 1);
8393 continue; /* Now, go look for +. */
8400 /* If we got a notification, handle it, and go back to looking
8402 /* We've found the start of a notification. Now
8403 collect the data. */
8404 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
8409 struct cleanup
*old_chain
;
8412 str
= escape_buffer (rs
->buf
, val
);
8413 old_chain
= make_cleanup (xfree
, str
);
8414 fprintf_unfiltered (gdb_stdlog
,
8415 " Notification received: %s\n",
8417 do_cleanups (old_chain
);
8419 handle_notification (rs
->notif_state
, rs
->buf
);
8420 /* We're in sync now, rewait for the ack. */
8427 if (!started_error_output
)
8429 started_error_output
= 1;
8430 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8432 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8433 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
8442 if (!started_error_output
)
8444 started_error_output
= 1;
8445 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8447 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8451 break; /* Here to retransmit. */
8455 /* This is wrong. If doing a long backtrace, the user should be
8456 able to get out next time we call QUIT, without anything as
8457 violent as interrupt_query. If we want to provide a way out of
8458 here without getting to the next QUIT, it should be based on
8459 hitting ^C twice as in remote_wait. */
8468 do_cleanups (old_chain
);
8472 /* Come here after finding the start of a frame when we expected an
8473 ack. Do our best to discard the rest of this packet. */
8482 c
= readchar (remote_timeout
);
8485 case SERIAL_TIMEOUT
:
8486 /* Nothing we can do. */
8489 /* Discard the two bytes of checksum and stop. */
8490 c
= readchar (remote_timeout
);
8492 c
= readchar (remote_timeout
);
8495 case '*': /* Run length encoding. */
8496 /* Discard the repeat count. */
8497 c
= readchar (remote_timeout
);
8502 /* A regular character. */
8508 /* Come here after finding the start of the frame. Collect the rest
8509 into *BUF, verifying the checksum, length, and handling run-length
8510 compression. NUL terminate the buffer. If there is not enough room,
8511 expand *BUF using xrealloc.
8513 Returns -1 on error, number of characters in buffer (ignoring the
8514 trailing NULL) on success. (could be extended to return one of the
8515 SERIAL status indications). */
8518 read_frame (char **buf_p
,
8525 struct remote_state
*rs
= get_remote_state ();
8532 c
= readchar (remote_timeout
);
8535 case SERIAL_TIMEOUT
:
8537 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
8541 fputs_filtered ("Saw new packet start in middle of old one\n",
8543 return -1; /* Start a new packet, count retries. */
8546 unsigned char pktcsum
;
8552 check_0
= readchar (remote_timeout
);
8554 check_1
= readchar (remote_timeout
);
8556 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
8559 fputs_filtered ("Timeout in checksum, retrying\n",
8563 else if (check_0
< 0 || check_1
< 0)
8566 fputs_filtered ("Communication error in checksum\n",
8571 /* Don't recompute the checksum; with no ack packets we
8572 don't have any way to indicate a packet retransmission
8577 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
8578 if (csum
== pktcsum
)
8583 struct cleanup
*old_chain
;
8586 str
= escape_buffer (buf
, bc
);
8587 old_chain
= make_cleanup (xfree
, str
);
8588 fprintf_unfiltered (gdb_stdlog
,
8589 "Bad checksum, sentsum=0x%x, "
8590 "csum=0x%x, buf=%s\n",
8591 pktcsum
, csum
, str
);
8592 do_cleanups (old_chain
);
8594 /* Number of characters in buffer ignoring trailing
8598 case '*': /* Run length encoding. */
8603 c
= readchar (remote_timeout
);
8605 repeat
= c
- ' ' + 3; /* Compute repeat count. */
8607 /* The character before ``*'' is repeated. */
8609 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
8611 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
8613 /* Make some more room in the buffer. */
8614 *sizeof_buf
+= repeat
;
8615 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
8619 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
8625 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
8629 if (bc
>= *sizeof_buf
- 1)
8631 /* Make some more room in the buffer. */
8633 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
8644 /* Read a packet from the remote machine, with error checking, and
8645 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8646 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8647 rather than timing out; this is used (in synchronous mode) to wait
8648 for a target that is is executing user code to stop. */
8649 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
8650 don't have to change all the calls to getpkt to deal with the
8651 return value, because at the moment I don't know what the right
8652 thing to do it for those. */
8658 getpkt_sane (buf
, sizeof_buf
, forever
);
8662 /* Read a packet from the remote machine, with error checking, and
8663 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8664 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8665 rather than timing out; this is used (in synchronous mode) to wait
8666 for a target that is is executing user code to stop. If FOREVER ==
8667 0, this function is allowed to time out gracefully and return an
8668 indication of this to the caller. Otherwise return the number of
8669 bytes read. If EXPECTING_NOTIF, consider receiving a notification
8670 enough reason to return to the caller. *IS_NOTIF is an output
8671 boolean that indicates whether *BUF holds a notification or not
8672 (a regular packet). */
8675 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
8676 int expecting_notif
, int *is_notif
)
8678 struct remote_state
*rs
= get_remote_state ();
8684 /* We're reading a new response. Make sure we don't look at a
8685 previously cached response. */
8686 rs
->cached_wait_status
= 0;
8688 strcpy (*buf
, "timeout");
8691 timeout
= watchdog
> 0 ? watchdog
: -1;
8692 else if (expecting_notif
)
8693 timeout
= 0; /* There should already be a char in the buffer. If
8696 timeout
= remote_timeout
;
8700 /* Process any number of notifications, and then return when
8704 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
8706 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
8708 /* This can loop forever if the remote side sends us
8709 characters continuously, but if it pauses, we'll get
8710 SERIAL_TIMEOUT from readchar because of timeout. Then
8711 we'll count that as a retry.
8713 Note that even when forever is set, we will only wait
8714 forever prior to the start of a packet. After that, we
8715 expect characters to arrive at a brisk pace. They should
8716 show up within remote_timeout intervals. */
8718 c
= readchar (timeout
);
8719 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
8721 if (c
== SERIAL_TIMEOUT
)
8723 if (expecting_notif
)
8724 return -1; /* Don't complain, it's normal to not get
8725 anything in this case. */
8727 if (forever
) /* Watchdog went off? Kill the target. */
8729 remote_unpush_target ();
8730 throw_error (TARGET_CLOSE_ERROR
,
8731 _("Watchdog timeout has expired. "
8732 "Target detached."));
8735 fputs_filtered ("Timed out.\n", gdb_stdlog
);
8739 /* We've found the start of a packet or notification.
8740 Now collect the data. */
8741 val
= read_frame (buf
, sizeof_buf
);
8746 remote_serial_write ("-", 1);
8749 if (tries
> MAX_TRIES
)
8751 /* We have tried hard enough, and just can't receive the
8752 packet/notification. Give up. */
8753 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
8755 /* Skip the ack char if we're in no-ack mode. */
8756 if (!rs
->noack_mode
)
8757 remote_serial_write ("+", 1);
8761 /* If we got an ordinary packet, return that to our caller. */
8766 struct cleanup
*old_chain
;
8769 str
= escape_buffer (*buf
, val
);
8770 old_chain
= make_cleanup (xfree
, str
);
8771 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
8772 do_cleanups (old_chain
);
8775 /* Skip the ack char if we're in no-ack mode. */
8776 if (!rs
->noack_mode
)
8777 remote_serial_write ("+", 1);
8778 if (is_notif
!= NULL
)
8783 /* If we got a notification, handle it, and go back to looking
8787 gdb_assert (c
== '%');
8791 struct cleanup
*old_chain
;
8794 str
= escape_buffer (*buf
, val
);
8795 old_chain
= make_cleanup (xfree
, str
);
8796 fprintf_unfiltered (gdb_stdlog
,
8797 " Notification received: %s\n",
8799 do_cleanups (old_chain
);
8801 if (is_notif
!= NULL
)
8804 handle_notification (rs
->notif_state
, *buf
);
8806 /* Notifications require no acknowledgement. */
8808 if (expecting_notif
)
8815 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
8817 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
8821 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
8824 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
8828 /* Check whether EVENT is a fork event for the process specified
8829 by the pid passed in DATA, and if it is, kill the fork child. */
8832 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
8833 QUEUE_ITER (stop_reply_p
) *iter
,
8837 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
8838 int parent_pid
= *(int *) param
->input
;
8840 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
8842 struct remote_state
*rs
= get_remote_state ();
8843 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
8846 res
= remote_vkill (child_pid
, rs
);
8848 error (_("Can't kill fork child process %d"), child_pid
);
8854 /* Kill any new fork children of process PID that haven't been
8855 processed by follow_fork. */
8858 kill_new_fork_children (int pid
, struct remote_state
*rs
)
8860 struct thread_info
*thread
;
8861 struct notif_client
*notif
= ¬if_client_stop
;
8862 struct queue_iter_param param
;
8864 /* Kill the fork child threads of any threads in process PID
8865 that are stopped at a fork event. */
8866 ALL_NON_EXITED_THREADS (thread
)
8868 struct target_waitstatus
*ws
= &thread
->pending_follow
;
8870 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
8872 struct remote_state
*rs
= get_remote_state ();
8873 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
8876 res
= remote_vkill (child_pid
, rs
);
8878 error (_("Can't kill fork child process %d"), child_pid
);
8882 /* Check for any pending fork events (not reported or processed yet)
8883 in process PID and kill those fork child threads as well. */
8884 remote_notif_get_pending_events (notif
);
8886 param
.output
= NULL
;
8887 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
8888 kill_child_of_pending_fork
, ¶m
);
8892 /* Target hook to kill the current inferior. */
8895 remote_kill (struct target_ops
*ops
)
8898 int pid
= ptid_get_pid (inferior_ptid
);
8899 struct remote_state
*rs
= get_remote_state ();
8901 if (packet_support (PACKET_vKill
) != PACKET_DISABLE
)
8903 /* If we're stopped while forking and we haven't followed yet,
8904 kill the child task. We need to do this before killing the
8905 parent task because if this is a vfork then the parent will
8907 kill_new_fork_children (pid
, rs
);
8909 res
= remote_vkill (pid
, rs
);
8912 target_mourn_inferior ();
8917 /* If we are in 'target remote' mode and we are killing the only
8918 inferior, then we will tell gdbserver to exit and unpush the
8920 if (res
== -1 && !remote_multi_process_p (rs
)
8921 && number_of_live_inferiors () == 1)
8925 /* We've killed the remote end, we get to mourn it. If we are
8926 not in extended mode, mourning the inferior also unpushes
8927 remote_ops from the target stack, which closes the remote
8929 target_mourn_inferior ();
8934 error (_("Can't kill process"));
8937 /* Send a kill request to the target using the 'vKill' packet. */
8940 remote_vkill (int pid
, struct remote_state
*rs
)
8942 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
8945 /* Tell the remote target to detach. */
8946 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
8948 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8950 switch (packet_ok (rs
->buf
,
8951 &remote_protocol_packets
[PACKET_vKill
]))
8957 case PACKET_UNKNOWN
:
8960 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
8964 /* Send a kill request to the target using the 'k' packet. */
8967 remote_kill_k (void)
8969 /* Catch errors so the user can quit from gdb even when we
8970 aren't on speaking terms with the remote system. */
8975 CATCH (ex
, RETURN_MASK_ERROR
)
8977 if (ex
.error
== TARGET_CLOSE_ERROR
)
8979 /* If we got an (EOF) error that caused the target
8980 to go away, then we're done, that's what we wanted.
8981 "k" is susceptible to cause a premature EOF, given
8982 that the remote server isn't actually required to
8983 reply to "k", and it can happen that it doesn't
8984 even get to reply ACK to the "k". */
8988 /* Otherwise, something went wrong. We didn't actually kill
8989 the target. Just propagate the exception, and let the
8990 user or higher layers decide what to do. */
8991 throw_exception (ex
);
8997 remote_mourn (struct target_ops
*target
)
8999 struct remote_state
*rs
= get_remote_state ();
9001 /* In 'target remote' mode with one inferior, we close the connection. */
9002 if (!rs
->extended
&& number_of_live_inferiors () <= 1)
9004 unpush_target (target
);
9006 /* remote_close takes care of doing most of the clean up. */
9007 generic_mourn_inferior ();
9011 /* In case we got here due to an error, but we're going to stay
9013 rs
->waiting_for_stop_reply
= 0;
9015 /* If the current general thread belonged to the process we just
9016 detached from or has exited, the remote side current general
9017 thread becomes undefined. Considering a case like this:
9019 - We just got here due to a detach.
9020 - The process that we're detaching from happens to immediately
9021 report a global breakpoint being hit in non-stop mode, in the
9022 same thread we had selected before.
9023 - GDB attaches to this process again.
9024 - This event happens to be the next event we handle.
9026 GDB would consider that the current general thread didn't need to
9027 be set on the stub side (with Hg), since for all it knew,
9028 GENERAL_THREAD hadn't changed.
9030 Notice that although in all-stop mode, the remote server always
9031 sets the current thread to the thread reporting the stop event,
9032 that doesn't happen in non-stop mode; in non-stop, the stub *must
9033 not* change the current thread when reporting a breakpoint hit,
9034 due to the decoupling of event reporting and event handling.
9036 To keep things simple, we always invalidate our notion of the
9038 record_currthread (rs
, minus_one_ptid
);
9040 /* Call common code to mark the inferior as not running. */
9041 generic_mourn_inferior ();
9043 if (!have_inferiors ())
9045 if (!remote_multi_process_p (rs
))
9047 /* Check whether the target is running now - some remote stubs
9048 automatically restart after kill. */
9050 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9052 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
9054 /* Assume that the target has been restarted. Set
9055 inferior_ptid so that bits of core GDB realizes
9056 there's something here, e.g., so that the user can
9057 say "kill" again. */
9058 inferior_ptid
= magic_null_ptid
;
9065 extended_remote_supports_disable_randomization (struct target_ops
*self
)
9067 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
9071 extended_remote_disable_randomization (int val
)
9073 struct remote_state
*rs
= get_remote_state ();
9076 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
9079 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
9081 error (_("Target does not support QDisableRandomization."));
9082 if (strcmp (reply
, "OK") != 0)
9083 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
9087 extended_remote_run (char *args
)
9089 struct remote_state
*rs
= get_remote_state ();
9091 const char *remote_exec_file
= get_remote_exec_file ();
9093 /* If the user has disabled vRun support, or we have detected that
9094 support is not available, do not try it. */
9095 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
9098 strcpy (rs
->buf
, "vRun;");
9099 len
= strlen (rs
->buf
);
9101 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
9102 error (_("Remote file name too long for run packet"));
9103 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
9104 strlen (remote_exec_file
));
9106 gdb_assert (args
!= NULL
);
9109 struct cleanup
*back_to
;
9113 argv
= gdb_buildargv (args
);
9114 back_to
= make_cleanup_freeargv (argv
);
9115 for (i
= 0; argv
[i
] != NULL
; i
++)
9117 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
9118 error (_("Argument list too long for run packet"));
9119 rs
->buf
[len
++] = ';';
9120 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
9123 do_cleanups (back_to
);
9126 rs
->buf
[len
++] = '\0';
9129 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9131 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
9134 /* We have a wait response. All is well. */
9136 case PACKET_UNKNOWN
:
9139 if (remote_exec_file
[0] == '\0')
9140 error (_("Running the default executable on the remote target failed; "
9141 "try \"set remote exec-file\"?"));
9143 error (_("Running \"%s\" on the remote target failed"),
9146 gdb_assert_not_reached (_("bad switch"));
9150 /* In the extended protocol we want to be able to do things like
9151 "run" and have them basically work as expected. So we need
9152 a special create_inferior function. We support changing the
9153 executable file and the command line arguments, but not the
9157 extended_remote_create_inferior (struct target_ops
*ops
,
9158 char *exec_file
, char *args
,
9159 char **env
, int from_tty
)
9163 struct remote_state
*rs
= get_remote_state ();
9164 const char *remote_exec_file
= get_remote_exec_file ();
9166 /* If running asynchronously, register the target file descriptor
9167 with the event loop. */
9168 if (target_can_async_p ())
9171 /* Disable address space randomization if requested (and supported). */
9172 if (extended_remote_supports_disable_randomization (ops
))
9173 extended_remote_disable_randomization (disable_randomization
);
9175 /* Now restart the remote server. */
9176 run_worked
= extended_remote_run (args
) != -1;
9179 /* vRun was not supported. Fail if we need it to do what the
9181 if (remote_exec_file
[0])
9182 error (_("Remote target does not support \"set remote exec-file\""));
9184 error (_("Remote target does not support \"set args\" or run <ARGS>"));
9186 /* Fall back to "R". */
9187 extended_remote_restart ();
9190 if (!have_inferiors ())
9192 /* Clean up from the last time we ran, before we mark the target
9193 running again. This will mark breakpoints uninserted, and
9194 get_offsets may insert breakpoints. */
9195 init_thread_list ();
9196 init_wait_for_inferior ();
9199 /* vRun's success return is a stop reply. */
9200 stop_reply
= run_worked
? rs
->buf
: NULL
;
9201 add_current_inferior_and_thread (stop_reply
);
9203 /* Get updated offsets, if the stub uses qOffsets. */
9208 /* Given a location's target info BP_TGT and the packet buffer BUF, output
9209 the list of conditions (in agent expression bytecode format), if any, the
9210 target needs to evaluate. The output is placed into the packet buffer
9211 started from BUF and ended at BUF_END. */
9214 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
9215 struct bp_target_info
*bp_tgt
, char *buf
,
9218 struct agent_expr
*aexpr
= NULL
;
9221 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
9224 buf
+= strlen (buf
);
9225 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
9228 /* Send conditions to the target and free the vector. */
9230 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
9233 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
9234 buf
+= strlen (buf
);
9235 for (i
= 0; i
< aexpr
->len
; ++i
)
9236 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9243 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
9244 struct bp_target_info
*bp_tgt
, char *buf
)
9246 struct agent_expr
*aexpr
= NULL
;
9249 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9252 buf
+= strlen (buf
);
9254 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
9255 buf
+= strlen (buf
);
9257 /* Concatenate all the agent expressions that are commands into the
9260 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
9263 sprintf (buf
, "X%x,", aexpr
->len
);
9264 buf
+= strlen (buf
);
9265 for (i
= 0; i
< aexpr
->len
; ++i
)
9266 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9271 /* Insert a breakpoint. On targets that have software breakpoint
9272 support, we ask the remote target to do the work; on targets
9273 which don't, we insert a traditional memory breakpoint. */
9276 remote_insert_breakpoint (struct target_ops
*ops
,
9277 struct gdbarch
*gdbarch
,
9278 struct bp_target_info
*bp_tgt
)
9280 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
9281 If it succeeds, then set the support to PACKET_ENABLE. If it
9282 fails, and the user has explicitly requested the Z support then
9283 report an error, otherwise, mark it disabled and go on. */
9285 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9287 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9288 struct remote_state
*rs
;
9292 /* Make sure the remote is pointing at the right process, if
9294 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9295 set_general_process ();
9297 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
9299 rs
= get_remote_state ();
9301 endbuf
= rs
->buf
+ get_remote_packet_size ();
9306 addr
= (ULONGEST
) remote_address_masked (addr
);
9307 p
+= hexnumstr (p
, addr
);
9308 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
9310 if (remote_supports_cond_breakpoints (ops
))
9311 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9313 if (remote_can_run_breakpoint_commands (ops
))
9314 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9317 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9319 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
9324 bp_tgt
->placed_address
= addr
;
9325 bp_tgt
->placed_size
= bpsize
;
9327 case PACKET_UNKNOWN
:
9332 /* If this breakpoint has target-side commands but this stub doesn't
9333 support Z0 packets, throw error. */
9334 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
9335 throw_error (NOT_SUPPORTED_ERROR
, _("\
9336 Target doesn't support breakpoints that have target side commands."));
9338 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
9342 remote_remove_breakpoint (struct target_ops
*ops
,
9343 struct gdbarch
*gdbarch
,
9344 struct bp_target_info
*bp_tgt
,
9345 enum remove_bp_reason reason
)
9347 CORE_ADDR addr
= bp_tgt
->placed_address
;
9348 struct remote_state
*rs
= get_remote_state ();
9350 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9353 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9355 /* Make sure the remote is pointing at the right process, if
9357 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9358 set_general_process ();
9364 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
9365 p
+= hexnumstr (p
, addr
);
9366 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
9369 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9371 return (rs
->buf
[0] == 'E');
9374 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
, reason
);
9377 static enum Z_packet_type
9378 watchpoint_to_Z_packet (int type
)
9383 return Z_PACKET_WRITE_WP
;
9386 return Z_PACKET_READ_WP
;
9389 return Z_PACKET_ACCESS_WP
;
9392 internal_error (__FILE__
, __LINE__
,
9393 _("hw_bp_to_z: bad watchpoint type %d"), type
);
9398 remote_insert_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9399 enum target_hw_bp_type type
, struct expression
*cond
)
9401 struct remote_state
*rs
= get_remote_state ();
9402 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9404 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9406 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9409 /* Make sure the remote is pointing at the right process, if
9411 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9412 set_general_process ();
9414 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
9415 p
= strchr (rs
->buf
, '\0');
9416 addr
= remote_address_masked (addr
);
9417 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9418 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9421 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9423 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9427 case PACKET_UNKNOWN
:
9432 internal_error (__FILE__
, __LINE__
,
9433 _("remote_insert_watchpoint: reached end of function"));
9437 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
9438 CORE_ADDR start
, int length
)
9440 CORE_ADDR diff
= remote_address_masked (addr
- start
);
9442 return diff
< length
;
9447 remote_remove_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9448 enum target_hw_bp_type type
, struct expression
*cond
)
9450 struct remote_state
*rs
= get_remote_state ();
9451 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9453 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9455 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9458 /* Make sure the remote is pointing at the right process, if
9460 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9461 set_general_process ();
9463 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
9464 p
= strchr (rs
->buf
, '\0');
9465 addr
= remote_address_masked (addr
);
9466 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9467 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9469 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9471 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
9474 case PACKET_UNKNOWN
:
9479 internal_error (__FILE__
, __LINE__
,
9480 _("remote_remove_watchpoint: reached end of function"));
9484 int remote_hw_watchpoint_limit
= -1;
9485 int remote_hw_watchpoint_length_limit
= -1;
9486 int remote_hw_breakpoint_limit
= -1;
9489 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
9490 CORE_ADDR addr
, int len
)
9492 if (remote_hw_watchpoint_length_limit
== 0)
9494 else if (remote_hw_watchpoint_length_limit
< 0)
9496 else if (len
<= remote_hw_watchpoint_length_limit
)
9503 remote_check_watch_resources (struct target_ops
*self
,
9504 enum bptype type
, int cnt
, int ot
)
9506 if (type
== bp_hardware_breakpoint
)
9508 if (remote_hw_breakpoint_limit
== 0)
9510 else if (remote_hw_breakpoint_limit
< 0)
9512 else if (cnt
<= remote_hw_breakpoint_limit
)
9517 if (remote_hw_watchpoint_limit
== 0)
9519 else if (remote_hw_watchpoint_limit
< 0)
9523 else if (cnt
<= remote_hw_watchpoint_limit
)
9529 /* The to_stopped_by_sw_breakpoint method of target remote. */
9532 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9534 struct thread_info
*thread
= inferior_thread ();
9536 return (thread
->priv
!= NULL
9537 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
);
9540 /* The to_supports_stopped_by_sw_breakpoint method of target
9544 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
9546 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
9549 /* The to_stopped_by_hw_breakpoint method of target remote. */
9552 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9554 struct thread_info
*thread
= inferior_thread ();
9556 return (thread
->priv
!= NULL
9557 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
);
9560 /* The to_supports_stopped_by_hw_breakpoint method of target
9564 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
9566 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
9570 remote_stopped_by_watchpoint (struct target_ops
*ops
)
9572 struct thread_info
*thread
= inferior_thread ();
9574 return (thread
->priv
!= NULL
9575 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
);
9579 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
9581 struct thread_info
*thread
= inferior_thread ();
9583 if (thread
->priv
!= NULL
9584 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
)
9586 *addr_p
= thread
->priv
->watch_data_address
;
9595 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9596 struct bp_target_info
*bp_tgt
)
9598 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9599 struct remote_state
*rs
;
9604 /* The length field should be set to the size of a breakpoint
9605 instruction, even though we aren't inserting one ourselves. */
9607 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
9609 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9612 /* Make sure the remote is pointing at the right process, if
9614 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9615 set_general_process ();
9617 rs
= get_remote_state ();
9619 endbuf
= rs
->buf
+ get_remote_packet_size ();
9625 addr
= remote_address_masked (addr
);
9626 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9627 xsnprintf (p
, endbuf
- p
, ",%x", bpsize
);
9629 if (remote_supports_cond_breakpoints (self
))
9630 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9632 if (remote_can_run_breakpoint_commands (self
))
9633 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9636 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9638 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9641 if (rs
->buf
[1] == '.')
9643 message
= strchr (rs
->buf
+ 2, '.');
9645 error (_("Remote failure reply: %s"), message
+ 1);
9648 case PACKET_UNKNOWN
:
9651 bp_tgt
->placed_address
= addr
;
9652 bp_tgt
->placed_size
= bpsize
;
9655 internal_error (__FILE__
, __LINE__
,
9656 _("remote_insert_hw_breakpoint: reached end of function"));
9661 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
9662 struct bp_target_info
*bp_tgt
)
9665 struct remote_state
*rs
= get_remote_state ();
9667 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9669 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9672 /* Make sure the remote is pointing at the right process, if
9674 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9675 set_general_process ();
9681 addr
= remote_address_masked (bp_tgt
->placed_address
);
9682 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9683 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
9686 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9688 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9691 case PACKET_UNKNOWN
:
9696 internal_error (__FILE__
, __LINE__
,
9697 _("remote_remove_hw_breakpoint: reached end of function"));
9700 /* Verify memory using the "qCRC:" request. */
9703 remote_verify_memory (struct target_ops
*ops
,
9704 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
9706 struct remote_state
*rs
= get_remote_state ();
9707 unsigned long host_crc
, target_crc
;
9710 /* It doesn't make sense to use qCRC if the remote target is
9711 connected but not running. */
9712 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
9714 enum packet_result result
;
9716 /* Make sure the remote is pointing at the right process. */
9717 set_general_process ();
9719 /* FIXME: assumes lma can fit into long. */
9720 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
9721 (long) lma
, (long) size
);
9724 /* Be clever; compute the host_crc before waiting for target
9726 host_crc
= xcrc32 (data
, size
, 0xffffffff);
9728 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9730 result
= packet_ok (rs
->buf
,
9731 &remote_protocol_packets
[PACKET_qCRC
]);
9732 if (result
== PACKET_ERROR
)
9734 else if (result
== PACKET_OK
)
9736 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
9737 target_crc
= target_crc
* 16 + fromhex (*tmp
);
9739 return (host_crc
== target_crc
);
9743 return simple_verify_memory (ops
, data
, lma
, size
);
9746 /* compare-sections command
9748 With no arguments, compares each loadable section in the exec bfd
9749 with the same memory range on the target, and reports mismatches.
9750 Useful for verifying the image on the target against the exec file. */
9753 compare_sections_command (char *args
, int from_tty
)
9756 struct cleanup
*old_chain
;
9758 const char *sectname
;
9767 error (_("command cannot be used without an exec file"));
9769 /* Make sure the remote is pointing at the right process. */
9770 set_general_process ();
9772 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
9778 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9780 if (!(s
->flags
& SEC_LOAD
))
9781 continue; /* Skip non-loadable section. */
9783 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
9784 continue; /* Skip writeable sections */
9786 size
= bfd_get_section_size (s
);
9788 continue; /* Skip zero-length section. */
9790 sectname
= bfd_get_section_name (exec_bfd
, s
);
9791 if (args
&& strcmp (args
, sectname
) != 0)
9792 continue; /* Not the section selected by user. */
9794 matched
= 1; /* Do this section. */
9797 sectdata
= (gdb_byte
*) xmalloc (size
);
9798 old_chain
= make_cleanup (xfree
, sectdata
);
9799 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
9801 res
= target_verify_memory (sectdata
, lma
, size
);
9804 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
9805 paddress (target_gdbarch (), lma
),
9806 paddress (target_gdbarch (), lma
+ size
));
9808 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
9809 paddress (target_gdbarch (), lma
),
9810 paddress (target_gdbarch (), lma
+ size
));
9812 printf_filtered ("matched.\n");
9815 printf_filtered ("MIS-MATCHED!\n");
9819 do_cleanups (old_chain
);
9822 warning (_("One or more sections of the target image does not match\n\
9823 the loaded file\n"));
9824 if (args
&& !matched
)
9825 printf_filtered (_("No loaded section named '%s'.\n"), args
);
9828 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
9829 into remote target. The number of bytes written to the remote
9830 target is returned, or -1 for error. */
9832 static enum target_xfer_status
9833 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
9834 const char *annex
, const gdb_byte
*writebuf
,
9835 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
9836 struct packet_config
*packet
)
9840 struct remote_state
*rs
= get_remote_state ();
9841 int max_size
= get_memory_write_packet_size ();
9843 if (packet
->support
== PACKET_DISABLE
)
9844 return TARGET_XFER_E_IO
;
9846 /* Insert header. */
9847 i
= snprintf (rs
->buf
, max_size
,
9848 "qXfer:%s:write:%s:%s:",
9849 object_name
, annex
? annex
: "",
9850 phex_nz (offset
, sizeof offset
));
9851 max_size
-= (i
+ 1);
9853 /* Escape as much data as fits into rs->buf. */
9854 buf_len
= remote_escape_output
9855 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
9857 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
9858 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9859 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9860 return TARGET_XFER_E_IO
;
9862 unpack_varlen_hex (rs
->buf
, &n
);
9865 return TARGET_XFER_OK
;
9868 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
9869 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
9870 number of bytes read is returned, or 0 for EOF, or -1 for error.
9871 The number of bytes read may be less than LEN without indicating an
9872 EOF. PACKET is checked and updated to indicate whether the remote
9873 target supports this object. */
9875 static enum target_xfer_status
9876 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
9878 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
9879 ULONGEST
*xfered_len
,
9880 struct packet_config
*packet
)
9882 struct remote_state
*rs
= get_remote_state ();
9883 LONGEST i
, n
, packet_len
;
9885 if (packet
->support
== PACKET_DISABLE
)
9886 return TARGET_XFER_E_IO
;
9888 /* Check whether we've cached an end-of-object packet that matches
9890 if (rs
->finished_object
)
9892 if (strcmp (object_name
, rs
->finished_object
) == 0
9893 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
9894 && offset
== rs
->finished_offset
)
9895 return TARGET_XFER_EOF
;
9898 /* Otherwise, we're now reading something different. Discard
9900 xfree (rs
->finished_object
);
9901 xfree (rs
->finished_annex
);
9902 rs
->finished_object
= NULL
;
9903 rs
->finished_annex
= NULL
;
9906 /* Request only enough to fit in a single packet. The actual data
9907 may not, since we don't know how much of it will need to be escaped;
9908 the target is free to respond with slightly less data. We subtract
9909 five to account for the response type and the protocol frame. */
9910 n
= std::min
<LONGEST
> (get_remote_packet_size () - 5, len
);
9911 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
9912 object_name
, annex
? annex
: "",
9913 phex_nz (offset
, sizeof offset
),
9914 phex_nz (n
, sizeof n
));
9915 i
= putpkt (rs
->buf
);
9917 return TARGET_XFER_E_IO
;
9920 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9921 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9922 return TARGET_XFER_E_IO
;
9924 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
9925 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
9927 /* 'm' means there is (or at least might be) more data after this
9928 batch. That does not make sense unless there's at least one byte
9929 of data in this reply. */
9930 if (rs
->buf
[0] == 'm' && packet_len
== 1)
9931 error (_("Remote qXfer reply contained no data."));
9933 /* Got some data. */
9934 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
9935 packet_len
- 1, readbuf
, n
);
9937 /* 'l' is an EOF marker, possibly including a final block of data,
9938 or possibly empty. If we have the final block of a non-empty
9939 object, record this fact to bypass a subsequent partial read. */
9940 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
9942 rs
->finished_object
= xstrdup (object_name
);
9943 rs
->finished_annex
= xstrdup (annex
? annex
: "");
9944 rs
->finished_offset
= offset
+ i
;
9948 return TARGET_XFER_EOF
;
9952 return TARGET_XFER_OK
;
9956 static enum target_xfer_status
9957 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
9958 const char *annex
, gdb_byte
*readbuf
,
9959 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
9960 ULONGEST
*xfered_len
)
9962 struct remote_state
*rs
;
9966 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
9968 set_remote_traceframe ();
9969 set_general_thread (inferior_ptid
);
9971 rs
= get_remote_state ();
9973 /* Handle memory using the standard memory routines. */
9974 if (object
== TARGET_OBJECT_MEMORY
)
9976 /* If the remote target is connected but not running, we should
9977 pass this request down to a lower stratum (e.g. the executable
9979 if (!target_has_execution
)
9980 return TARGET_XFER_EOF
;
9982 if (writebuf
!= NULL
)
9983 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
9986 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
9990 /* Handle SPU memory using qxfer packets. */
9991 if (object
== TARGET_OBJECT_SPU
)
9994 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
9995 xfered_len
, &remote_protocol_packets
9996 [PACKET_qXfer_spu_read
]);
9998 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
9999 xfered_len
, &remote_protocol_packets
10000 [PACKET_qXfer_spu_write
]);
10003 /* Handle extra signal info using qxfer packets. */
10004 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
10007 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
10008 xfered_len
, &remote_protocol_packets
10009 [PACKET_qXfer_siginfo_read
]);
10011 return remote_write_qxfer (ops
, "siginfo", annex
,
10012 writebuf
, offset
, len
, xfered_len
,
10013 &remote_protocol_packets
10014 [PACKET_qXfer_siginfo_write
]);
10017 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
10020 return remote_read_qxfer (ops
, "statictrace", annex
,
10021 readbuf
, offset
, len
, xfered_len
,
10022 &remote_protocol_packets
10023 [PACKET_qXfer_statictrace_read
]);
10025 return TARGET_XFER_E_IO
;
10028 /* Only handle flash writes. */
10029 if (writebuf
!= NULL
)
10033 case TARGET_OBJECT_FLASH
:
10034 return remote_flash_write (ops
, offset
, len
, xfered_len
,
10038 return TARGET_XFER_E_IO
;
10042 /* Map pre-existing objects onto letters. DO NOT do this for new
10043 objects!!! Instead specify new query packets. */
10046 case TARGET_OBJECT_AVR
:
10050 case TARGET_OBJECT_AUXV
:
10051 gdb_assert (annex
== NULL
);
10052 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
10054 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
10056 case TARGET_OBJECT_AVAILABLE_FEATURES
:
10057 return remote_read_qxfer
10058 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
10059 &remote_protocol_packets
[PACKET_qXfer_features
]);
10061 case TARGET_OBJECT_LIBRARIES
:
10062 return remote_read_qxfer
10063 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
10064 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
10066 case TARGET_OBJECT_LIBRARIES_SVR4
:
10067 return remote_read_qxfer
10068 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
10069 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
10071 case TARGET_OBJECT_MEMORY_MAP
:
10072 gdb_assert (annex
== NULL
);
10073 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
10075 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
10077 case TARGET_OBJECT_OSDATA
:
10078 /* Should only get here if we're connected. */
10079 gdb_assert (rs
->remote_desc
);
10080 return remote_read_qxfer
10081 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
10082 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
10084 case TARGET_OBJECT_THREADS
:
10085 gdb_assert (annex
== NULL
);
10086 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
10088 &remote_protocol_packets
[PACKET_qXfer_threads
]);
10090 case TARGET_OBJECT_TRACEFRAME_INFO
:
10091 gdb_assert (annex
== NULL
);
10092 return remote_read_qxfer
10093 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
10094 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
10096 case TARGET_OBJECT_FDPIC
:
10097 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
10099 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
10101 case TARGET_OBJECT_OPENVMS_UIB
:
10102 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
10104 &remote_protocol_packets
[PACKET_qXfer_uib
]);
10106 case TARGET_OBJECT_BTRACE
:
10107 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
10109 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
10111 case TARGET_OBJECT_BTRACE_CONF
:
10112 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
10114 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
10116 case TARGET_OBJECT_EXEC_FILE
:
10117 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
10119 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
10122 return TARGET_XFER_E_IO
;
10125 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
10126 large enough let the caller deal with it. */
10127 if (len
< get_remote_packet_size ())
10128 return TARGET_XFER_E_IO
;
10129 len
= get_remote_packet_size ();
10131 /* Except for querying the minimum buffer size, target must be open. */
10132 if (!rs
->remote_desc
)
10133 error (_("remote query is only available after target open"));
10135 gdb_assert (annex
!= NULL
);
10136 gdb_assert (readbuf
!= NULL
);
10140 *p2
++ = query_type
;
10142 /* We used one buffer char for the remote protocol q command and
10143 another for the query type. As the remote protocol encapsulation
10144 uses 4 chars plus one extra in case we are debugging
10145 (remote_debug), we have PBUFZIZ - 7 left to pack the query
10148 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
10150 /* Bad caller may have sent forbidden characters. */
10151 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
10156 gdb_assert (annex
[i
] == '\0');
10158 i
= putpkt (rs
->buf
);
10160 return TARGET_XFER_E_IO
;
10162 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10163 strcpy ((char *) readbuf
, rs
->buf
);
10165 *xfered_len
= strlen ((char *) readbuf
);
10166 return TARGET_XFER_OK
;
10169 /* Implementation of to_get_memory_xfer_limit. */
10172 remote_get_memory_xfer_limit (struct target_ops
*ops
)
10174 return get_memory_write_packet_size ();
10178 remote_search_memory (struct target_ops
* ops
,
10179 CORE_ADDR start_addr
, ULONGEST search_space_len
,
10180 const gdb_byte
*pattern
, ULONGEST pattern_len
,
10181 CORE_ADDR
*found_addrp
)
10183 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
10184 struct remote_state
*rs
= get_remote_state ();
10185 int max_size
= get_memory_write_packet_size ();
10186 struct packet_config
*packet
=
10187 &remote_protocol_packets
[PACKET_qSearch_memory
];
10188 /* Number of packet bytes used to encode the pattern;
10189 this could be more than PATTERN_LEN due to escape characters. */
10190 int escaped_pattern_len
;
10191 /* Amount of pattern that was encodable in the packet. */
10192 int used_pattern_len
;
10195 ULONGEST found_addr
;
10197 /* Don't go to the target if we don't have to.
10198 This is done before checking packet->support to avoid the possibility that
10199 a success for this edge case means the facility works in general. */
10200 if (pattern_len
> search_space_len
)
10202 if (pattern_len
== 0)
10204 *found_addrp
= start_addr
;
10208 /* If we already know the packet isn't supported, fall back to the simple
10209 way of searching memory. */
10211 if (packet_config_support (packet
) == PACKET_DISABLE
)
10213 /* Target doesn't provided special support, fall back and use the
10214 standard support (copy memory and do the search here). */
10215 return simple_search_memory (ops
, start_addr
, search_space_len
,
10216 pattern
, pattern_len
, found_addrp
);
10219 /* Make sure the remote is pointing at the right process. */
10220 set_general_process ();
10222 /* Insert header. */
10223 i
= snprintf (rs
->buf
, max_size
,
10224 "qSearch:memory:%s;%s;",
10225 phex_nz (start_addr
, addr_size
),
10226 phex_nz (search_space_len
, sizeof (search_space_len
)));
10227 max_size
-= (i
+ 1);
10229 /* Escape as much data as fits into rs->buf. */
10230 escaped_pattern_len
=
10231 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
10232 &used_pattern_len
, max_size
);
10234 /* Bail if the pattern is too large. */
10235 if (used_pattern_len
!= pattern_len
)
10236 error (_("Pattern is too large to transmit to remote target."));
10238 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
10239 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
10240 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10242 /* The request may not have worked because the command is not
10243 supported. If so, fall back to the simple way. */
10244 if (packet
->support
== PACKET_DISABLE
)
10246 return simple_search_memory (ops
, start_addr
, search_space_len
,
10247 pattern
, pattern_len
, found_addrp
);
10252 if (rs
->buf
[0] == '0')
10254 else if (rs
->buf
[0] == '1')
10257 if (rs
->buf
[1] != ',')
10258 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10259 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
10260 *found_addrp
= found_addr
;
10263 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10269 remote_rcmd (struct target_ops
*self
, const char *command
,
10270 struct ui_file
*outbuf
)
10272 struct remote_state
*rs
= get_remote_state ();
10275 if (!rs
->remote_desc
)
10276 error (_("remote rcmd is only available after target open"));
10278 /* Send a NULL command across as an empty command. */
10279 if (command
== NULL
)
10282 /* The query prefix. */
10283 strcpy (rs
->buf
, "qRcmd,");
10284 p
= strchr (rs
->buf
, '\0');
10286 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
10287 > get_remote_packet_size ())
10288 error (_("\"monitor\" command ``%s'' is too long."), command
);
10290 /* Encode the actual command. */
10291 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
10293 if (putpkt (rs
->buf
) < 0)
10294 error (_("Communication problem with target."));
10296 /* get/display the response */
10301 /* XXX - see also remote_get_noisy_reply(). */
10302 QUIT
; /* Allow user to bail out with ^C. */
10304 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
10306 /* Timeout. Continue to (try to) read responses.
10307 This is better than stopping with an error, assuming the stub
10308 is still executing the (long) monitor command.
10309 If needed, the user can interrupt gdb using C-c, obtaining
10310 an effect similar to stop on timeout. */
10314 if (buf
[0] == '\0')
10315 error (_("Target does not support this command."));
10316 if (buf
[0] == 'O' && buf
[1] != 'K')
10318 remote_console_output (buf
+ 1); /* 'O' message from stub. */
10321 if (strcmp (buf
, "OK") == 0)
10323 if (strlen (buf
) == 3 && buf
[0] == 'E'
10324 && isdigit (buf
[1]) && isdigit (buf
[2]))
10326 error (_("Protocol error with Rcmd"));
10328 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
10330 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
10332 fputc_unfiltered (c
, outbuf
);
10338 static VEC(mem_region_s
) *
10339 remote_memory_map (struct target_ops
*ops
)
10341 VEC(mem_region_s
) *result
= NULL
;
10342 char *text
= target_read_stralloc (¤t_target
,
10343 TARGET_OBJECT_MEMORY_MAP
, NULL
);
10347 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10349 result
= parse_memory_map (text
);
10350 do_cleanups (back_to
);
10357 packet_command (char *args
, int from_tty
)
10359 struct remote_state
*rs
= get_remote_state ();
10361 if (!rs
->remote_desc
)
10362 error (_("command can only be used with remote target"));
10365 error (_("remote-packet command requires packet text as argument"));
10367 puts_filtered ("sending: ");
10368 print_packet (args
);
10369 puts_filtered ("\n");
10372 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10373 puts_filtered ("received: ");
10374 print_packet (rs
->buf
);
10375 puts_filtered ("\n");
10379 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
10381 static void display_thread_info (struct gdb_ext_thread_info
*info
);
10383 static void threadset_test_cmd (char *cmd
, int tty
);
10385 static void threadalive_test (char *cmd
, int tty
);
10387 static void threadlist_test_cmd (char *cmd
, int tty
);
10389 int get_and_display_threadinfo (threadref
*ref
);
10391 static void threadinfo_test_cmd (char *cmd
, int tty
);
10393 static int thread_display_step (threadref
*ref
, void *context
);
10395 static void threadlist_update_test_cmd (char *cmd
, int tty
);
10397 static void init_remote_threadtests (void);
10399 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
10402 threadset_test_cmd (char *cmd
, int tty
)
10404 int sample_thread
= SAMPLE_THREAD
;
10406 printf_filtered (_("Remote threadset test\n"));
10407 set_general_thread (sample_thread
);
10412 threadalive_test (char *cmd
, int tty
)
10414 int sample_thread
= SAMPLE_THREAD
;
10415 int pid
= ptid_get_pid (inferior_ptid
);
10416 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
10418 if (remote_thread_alive (ptid
))
10419 printf_filtered ("PASS: Thread alive test\n");
10421 printf_filtered ("FAIL: Thread alive test\n");
10424 void output_threadid (char *title
, threadref
*ref
);
10427 output_threadid (char *title
, threadref
*ref
)
10431 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
10433 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
10437 threadlist_test_cmd (char *cmd
, int tty
)
10440 threadref nextthread
;
10441 int done
, result_count
;
10442 threadref threadlist
[3];
10444 printf_filtered ("Remote Threadlist test\n");
10445 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
10446 &result_count
, &threadlist
[0]))
10447 printf_filtered ("FAIL: threadlist test\n");
10450 threadref
*scan
= threadlist
;
10451 threadref
*limit
= scan
+ result_count
;
10453 while (scan
< limit
)
10454 output_threadid (" thread ", scan
++);
10459 display_thread_info (struct gdb_ext_thread_info
*info
)
10461 output_threadid ("Threadid: ", &info
->threadid
);
10462 printf_filtered ("Name: %s\n ", info
->shortname
);
10463 printf_filtered ("State: %s\n", info
->display
);
10464 printf_filtered ("other: %s\n\n", info
->more_display
);
10468 get_and_display_threadinfo (threadref
*ref
)
10472 struct gdb_ext_thread_info threadinfo
;
10474 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
10475 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
10476 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
10477 display_thread_info (&threadinfo
);
10482 threadinfo_test_cmd (char *cmd
, int tty
)
10484 int athread
= SAMPLE_THREAD
;
10488 int_to_threadref (&thread
, athread
);
10489 printf_filtered ("Remote Threadinfo test\n");
10490 if (!get_and_display_threadinfo (&thread
))
10491 printf_filtered ("FAIL cannot get thread info\n");
10495 thread_display_step (threadref
*ref
, void *context
)
10497 /* output_threadid(" threadstep ",ref); *//* simple test */
10498 return get_and_display_threadinfo (ref
);
10502 threadlist_update_test_cmd (char *cmd
, int tty
)
10504 printf_filtered ("Remote Threadlist update test\n");
10505 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
10509 init_remote_threadtests (void)
10511 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
10512 _("Fetch and print the remote list of "
10513 "thread identifiers, one pkt only"));
10514 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
10515 _("Fetch and display info about one thread"));
10516 add_com ("tset", class_obscure
, threadset_test_cmd
,
10517 _("Test setting to a different thread"));
10518 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
10519 _("Iterate through updating all remote thread info"));
10520 add_com ("talive", class_obscure
, threadalive_test
,
10521 _(" Remote thread alive test "));
10526 /* Convert a thread ID to a string. Returns the string in a static
10530 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
10532 static char buf
[64];
10533 struct remote_state
*rs
= get_remote_state ();
10535 if (ptid_equal (ptid
, null_ptid
))
10536 return normal_pid_to_str (ptid
);
10537 else if (ptid_is_pid (ptid
))
10539 /* Printing an inferior target id. */
10541 /* When multi-process extensions are off, there's no way in the
10542 remote protocol to know the remote process id, if there's any
10543 at all. There's one exception --- when we're connected with
10544 target extended-remote, and we manually attached to a process
10545 with "attach PID". We don't record anywhere a flag that
10546 allows us to distinguish that case from the case of
10547 connecting with extended-remote and the stub already being
10548 attached to a process, and reporting yes to qAttached, hence
10549 no smart special casing here. */
10550 if (!remote_multi_process_p (rs
))
10552 xsnprintf (buf
, sizeof buf
, "Remote target");
10556 return normal_pid_to_str (ptid
);
10560 if (ptid_equal (magic_null_ptid
, ptid
))
10561 xsnprintf (buf
, sizeof buf
, "Thread <main>");
10562 else if (remote_multi_process_p (rs
))
10563 if (ptid_get_lwp (ptid
) == 0)
10564 return normal_pid_to_str (ptid
);
10566 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
10567 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
10569 xsnprintf (buf
, sizeof buf
, "Thread %ld",
10570 ptid_get_lwp (ptid
));
10575 /* Get the address of the thread local variable in OBJFILE which is
10576 stored at OFFSET within the thread local storage for thread PTID. */
10579 remote_get_thread_local_address (struct target_ops
*ops
,
10580 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
10582 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
10584 struct remote_state
*rs
= get_remote_state ();
10586 char *endp
= rs
->buf
+ get_remote_packet_size ();
10587 enum packet_result result
;
10589 strcpy (p
, "qGetTLSAddr:");
10591 p
= write_ptid (p
, endp
, ptid
);
10593 p
+= hexnumstr (p
, offset
);
10595 p
+= hexnumstr (p
, lm
);
10599 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10600 result
= packet_ok (rs
->buf
,
10601 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
10602 if (result
== PACKET_OK
)
10606 unpack_varlen_hex (rs
->buf
, &result
);
10609 else if (result
== PACKET_UNKNOWN
)
10610 throw_error (TLS_GENERIC_ERROR
,
10611 _("Remote target doesn't support qGetTLSAddr packet"));
10613 throw_error (TLS_GENERIC_ERROR
,
10614 _("Remote target failed to process qGetTLSAddr request"));
10617 throw_error (TLS_GENERIC_ERROR
,
10618 _("TLS not supported or disabled on this target"));
10623 /* Provide thread local base, i.e. Thread Information Block address.
10624 Returns 1 if ptid is found and thread_local_base is non zero. */
10627 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
10629 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
10631 struct remote_state
*rs
= get_remote_state ();
10633 char *endp
= rs
->buf
+ get_remote_packet_size ();
10634 enum packet_result result
;
10636 strcpy (p
, "qGetTIBAddr:");
10638 p
= write_ptid (p
, endp
, ptid
);
10642 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10643 result
= packet_ok (rs
->buf
,
10644 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
10645 if (result
== PACKET_OK
)
10649 unpack_varlen_hex (rs
->buf
, &result
);
10651 *addr
= (CORE_ADDR
) result
;
10654 else if (result
== PACKET_UNKNOWN
)
10655 error (_("Remote target doesn't support qGetTIBAddr packet"));
10657 error (_("Remote target failed to process qGetTIBAddr request"));
10660 error (_("qGetTIBAddr not supported or disabled on this target"));
10665 /* Support for inferring a target description based on the current
10666 architecture and the size of a 'g' packet. While the 'g' packet
10667 can have any size (since optional registers can be left off the
10668 end), some sizes are easily recognizable given knowledge of the
10669 approximate architecture. */
10671 struct remote_g_packet_guess
10674 const struct target_desc
*tdesc
;
10676 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
10677 DEF_VEC_O(remote_g_packet_guess_s
);
10679 struct remote_g_packet_data
10681 VEC(remote_g_packet_guess_s
) *guesses
;
10684 static struct gdbarch_data
*remote_g_packet_data_handle
;
10687 remote_g_packet_data_init (struct obstack
*obstack
)
10689 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
10693 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
10694 const struct target_desc
*tdesc
)
10696 struct remote_g_packet_data
*data
10697 = ((struct remote_g_packet_data
*)
10698 gdbarch_data (gdbarch
, remote_g_packet_data_handle
));
10699 struct remote_g_packet_guess new_guess
, *guess
;
10702 gdb_assert (tdesc
!= NULL
);
10705 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10707 if (guess
->bytes
== bytes
)
10708 internal_error (__FILE__
, __LINE__
,
10709 _("Duplicate g packet description added for size %d"),
10712 new_guess
.bytes
= bytes
;
10713 new_guess
.tdesc
= tdesc
;
10714 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
10717 /* Return 1 if remote_read_description would do anything on this target
10718 and architecture, 0 otherwise. */
10721 remote_read_description_p (struct target_ops
*target
)
10723 struct remote_g_packet_data
*data
10724 = ((struct remote_g_packet_data
*)
10725 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
10727 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10733 static const struct target_desc
*
10734 remote_read_description (struct target_ops
*target
)
10736 struct remote_g_packet_data
*data
10737 = ((struct remote_g_packet_data
*)
10738 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
10740 /* Do not try this during initial connection, when we do not know
10741 whether there is a running but stopped thread. */
10742 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
10743 return target
->beneath
->to_read_description (target
->beneath
);
10745 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10747 struct remote_g_packet_guess
*guess
;
10749 int bytes
= send_g_packet ();
10752 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10754 if (guess
->bytes
== bytes
)
10755 return guess
->tdesc
;
10757 /* We discard the g packet. A minor optimization would be to
10758 hold on to it, and fill the register cache once we have selected
10759 an architecture, but it's too tricky to do safely. */
10762 return target
->beneath
->to_read_description (target
->beneath
);
10765 /* Remote file transfer support. This is host-initiated I/O, not
10766 target-initiated; for target-initiated, see remote-fileio.c. */
10768 /* If *LEFT is at least the length of STRING, copy STRING to
10769 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10770 decrease *LEFT. Otherwise raise an error. */
10773 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
10775 int len
= strlen (string
);
10778 error (_("Packet too long for target."));
10780 memcpy (*buffer
, string
, len
);
10784 /* NUL-terminate the buffer as a convenience, if there is
10790 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
10791 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10792 decrease *LEFT. Otherwise raise an error. */
10795 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
10798 if (2 * len
> *left
)
10799 error (_("Packet too long for target."));
10801 bin2hex (bytes
, *buffer
, len
);
10802 *buffer
+= 2 * len
;
10805 /* NUL-terminate the buffer as a convenience, if there is
10811 /* If *LEFT is large enough, convert VALUE to hex and add it to
10812 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10813 decrease *LEFT. Otherwise raise an error. */
10816 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
10818 int len
= hexnumlen (value
);
10821 error (_("Packet too long for target."));
10823 hexnumstr (*buffer
, value
);
10827 /* NUL-terminate the buffer as a convenience, if there is
10833 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
10834 value, *REMOTE_ERRNO to the remote error number or zero if none
10835 was included, and *ATTACHMENT to point to the start of the annex
10836 if any. The length of the packet isn't needed here; there may
10837 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
10839 Return 0 if the packet could be parsed, -1 if it could not. If
10840 -1 is returned, the other variables may not be initialized. */
10843 remote_hostio_parse_result (char *buffer
, int *retcode
,
10844 int *remote_errno
, char **attachment
)
10849 *attachment
= NULL
;
10851 if (buffer
[0] != 'F')
10855 *retcode
= strtol (&buffer
[1], &p
, 16);
10856 if (errno
!= 0 || p
== &buffer
[1])
10859 /* Check for ",errno". */
10863 *remote_errno
= strtol (p
+ 1, &p2
, 16);
10864 if (errno
!= 0 || p
+ 1 == p2
)
10869 /* Check for ";attachment". If there is no attachment, the
10870 packet should end here. */
10873 *attachment
= p
+ 1;
10876 else if (*p
== '\0')
10882 /* Send a prepared I/O packet to the target and read its response.
10883 The prepared packet is in the global RS->BUF before this function
10884 is called, and the answer is there when we return.
10886 COMMAND_BYTES is the length of the request to send, which may include
10887 binary data. WHICH_PACKET is the packet configuration to check
10888 before attempting a packet. If an error occurs, *REMOTE_ERRNO
10889 is set to the error number and -1 is returned. Otherwise the value
10890 returned by the function is returned.
10892 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
10893 attachment is expected; an error will be reported if there's a
10894 mismatch. If one is found, *ATTACHMENT will be set to point into
10895 the packet buffer and *ATTACHMENT_LEN will be set to the
10896 attachment's length. */
10899 remote_hostio_send_command (int command_bytes
, int which_packet
,
10900 int *remote_errno
, char **attachment
,
10901 int *attachment_len
)
10903 struct remote_state
*rs
= get_remote_state ();
10904 int ret
, bytes_read
;
10905 char *attachment_tmp
;
10907 if (!rs
->remote_desc
10908 || packet_support (which_packet
) == PACKET_DISABLE
)
10910 *remote_errno
= FILEIO_ENOSYS
;
10914 putpkt_binary (rs
->buf
, command_bytes
);
10915 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10917 /* If it timed out, something is wrong. Don't try to parse the
10919 if (bytes_read
< 0)
10921 *remote_errno
= FILEIO_EINVAL
;
10925 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
10928 *remote_errno
= FILEIO_EINVAL
;
10930 case PACKET_UNKNOWN
:
10931 *remote_errno
= FILEIO_ENOSYS
;
10937 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
10940 *remote_errno
= FILEIO_EINVAL
;
10944 /* Make sure we saw an attachment if and only if we expected one. */
10945 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
10946 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
10948 *remote_errno
= FILEIO_EINVAL
;
10952 /* If an attachment was found, it must point into the packet buffer;
10953 work out how many bytes there were. */
10954 if (attachment_tmp
!= NULL
)
10956 *attachment
= attachment_tmp
;
10957 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
10963 /* Invalidate the readahead cache. */
10966 readahead_cache_invalidate (void)
10968 struct remote_state
*rs
= get_remote_state ();
10970 rs
->readahead_cache
.fd
= -1;
10973 /* Invalidate the readahead cache if it is holding data for FD. */
10976 readahead_cache_invalidate_fd (int fd
)
10978 struct remote_state
*rs
= get_remote_state ();
10980 if (rs
->readahead_cache
.fd
== fd
)
10981 rs
->readahead_cache
.fd
= -1;
10984 /* Set the filesystem remote_hostio functions that take FILENAME
10985 arguments will use. Return 0 on success, or -1 if an error
10986 occurs (and set *REMOTE_ERRNO). */
10989 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
10991 struct remote_state
*rs
= get_remote_state ();
10992 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
10994 int left
= get_remote_packet_size () - 1;
10998 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11001 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
11004 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
11006 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
11007 remote_buffer_add_string (&p
, &left
, arg
);
11009 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
11010 remote_errno
, NULL
, NULL
);
11012 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11016 rs
->fs_pid
= required_pid
;
11021 /* Implementation of to_fileio_open. */
11024 remote_hostio_open (struct target_ops
*self
,
11025 struct inferior
*inf
, const char *filename
,
11026 int flags
, int mode
, int warn_if_slow
,
11029 struct remote_state
*rs
= get_remote_state ();
11031 int left
= get_remote_packet_size () - 1;
11035 static int warning_issued
= 0;
11037 printf_unfiltered (_("Reading %s from remote target...\n"),
11040 if (!warning_issued
)
11042 warning (_("File transfers from remote targets can be slow."
11043 " Use \"set sysroot\" to access files locally"
11045 warning_issued
= 1;
11049 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11052 remote_buffer_add_string (&p
, &left
, "vFile:open:");
11054 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11055 strlen (filename
));
11056 remote_buffer_add_string (&p
, &left
, ",");
11058 remote_buffer_add_int (&p
, &left
, flags
);
11059 remote_buffer_add_string (&p
, &left
, ",");
11061 remote_buffer_add_int (&p
, &left
, mode
);
11063 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
11064 remote_errno
, NULL
, NULL
);
11067 /* Implementation of to_fileio_pwrite. */
11070 remote_hostio_pwrite (struct target_ops
*self
,
11071 int fd
, const gdb_byte
*write_buf
, int len
,
11072 ULONGEST offset
, int *remote_errno
)
11074 struct remote_state
*rs
= get_remote_state ();
11076 int left
= get_remote_packet_size ();
11079 readahead_cache_invalidate_fd (fd
);
11081 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
11083 remote_buffer_add_int (&p
, &left
, fd
);
11084 remote_buffer_add_string (&p
, &left
, ",");
11086 remote_buffer_add_int (&p
, &left
, offset
);
11087 remote_buffer_add_string (&p
, &left
, ",");
11089 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
11090 get_remote_packet_size () - (p
- rs
->buf
));
11092 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
11093 remote_errno
, NULL
, NULL
);
11096 /* Helper for the implementation of to_fileio_pread. Read the file
11097 from the remote side with vFile:pread. */
11100 remote_hostio_pread_vFile (struct target_ops
*self
,
11101 int fd
, gdb_byte
*read_buf
, int len
,
11102 ULONGEST offset
, int *remote_errno
)
11104 struct remote_state
*rs
= get_remote_state ();
11107 int left
= get_remote_packet_size ();
11108 int ret
, attachment_len
;
11111 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
11113 remote_buffer_add_int (&p
, &left
, fd
);
11114 remote_buffer_add_string (&p
, &left
, ",");
11116 remote_buffer_add_int (&p
, &left
, len
);
11117 remote_buffer_add_string (&p
, &left
, ",");
11119 remote_buffer_add_int (&p
, &left
, offset
);
11121 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
11122 remote_errno
, &attachment
,
11128 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11130 if (read_len
!= ret
)
11131 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
11136 /* Serve pread from the readahead cache. Returns number of bytes
11137 read, or 0 if the request can't be served from the cache. */
11140 remote_hostio_pread_from_cache (struct remote_state
*rs
,
11141 int fd
, gdb_byte
*read_buf
, size_t len
,
11144 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11146 if (cache
->fd
== fd
11147 && cache
->offset
<= offset
11148 && offset
< cache
->offset
+ cache
->bufsize
)
11150 ULONGEST max
= cache
->offset
+ cache
->bufsize
;
11152 if (offset
+ len
> max
)
11153 len
= max
- offset
;
11155 memcpy (read_buf
, cache
->buf
+ offset
- cache
->offset
, len
);
11162 /* Implementation of to_fileio_pread. */
11165 remote_hostio_pread (struct target_ops
*self
,
11166 int fd
, gdb_byte
*read_buf
, int len
,
11167 ULONGEST offset
, int *remote_errno
)
11170 struct remote_state
*rs
= get_remote_state ();
11171 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11173 ret
= remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11176 cache
->hit_count
++;
11179 fprintf_unfiltered (gdb_stdlog
, "readahead cache hit %s\n",
11180 pulongest (cache
->hit_count
));
11184 cache
->miss_count
++;
11186 fprintf_unfiltered (gdb_stdlog
, "readahead cache miss %s\n",
11187 pulongest (cache
->miss_count
));
11190 cache
->offset
= offset
;
11191 cache
->bufsize
= get_remote_packet_size ();
11192 cache
->buf
= (gdb_byte
*) xrealloc (cache
->buf
, cache
->bufsize
);
11194 ret
= remote_hostio_pread_vFile (self
, cache
->fd
, cache
->buf
, cache
->bufsize
,
11195 cache
->offset
, remote_errno
);
11198 readahead_cache_invalidate_fd (fd
);
11202 cache
->bufsize
= ret
;
11203 return remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11206 /* Implementation of to_fileio_close. */
11209 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
11211 struct remote_state
*rs
= get_remote_state ();
11213 int left
= get_remote_packet_size () - 1;
11215 readahead_cache_invalidate_fd (fd
);
11217 remote_buffer_add_string (&p
, &left
, "vFile:close:");
11219 remote_buffer_add_int (&p
, &left
, fd
);
11221 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
11222 remote_errno
, NULL
, NULL
);
11225 /* Implementation of to_fileio_unlink. */
11228 remote_hostio_unlink (struct target_ops
*self
,
11229 struct inferior
*inf
, const char *filename
,
11232 struct remote_state
*rs
= get_remote_state ();
11234 int left
= get_remote_packet_size () - 1;
11236 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11239 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
11241 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11242 strlen (filename
));
11244 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
11245 remote_errno
, NULL
, NULL
);
11248 /* Implementation of to_fileio_readlink. */
11251 remote_hostio_readlink (struct target_ops
*self
,
11252 struct inferior
*inf
, const char *filename
,
11255 struct remote_state
*rs
= get_remote_state ();
11258 int left
= get_remote_packet_size ();
11259 int len
, attachment_len
;
11263 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11266 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
11268 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11269 strlen (filename
));
11271 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
11272 remote_errno
, &attachment
,
11278 ret
= (char *) xmalloc (len
+ 1);
11280 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11281 (gdb_byte
*) ret
, len
);
11282 if (read_len
!= len
)
11283 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
11289 /* Implementation of to_fileio_fstat. */
11292 remote_hostio_fstat (struct target_ops
*self
,
11293 int fd
, struct stat
*st
,
11296 struct remote_state
*rs
= get_remote_state ();
11298 int left
= get_remote_packet_size ();
11299 int attachment_len
, ret
;
11301 struct fio_stat fst
;
11304 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
11306 remote_buffer_add_int (&p
, &left
, fd
);
11308 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
11309 remote_errno
, &attachment
,
11313 if (*remote_errno
!= FILEIO_ENOSYS
)
11316 /* Strictly we should return -1, ENOSYS here, but when
11317 "set sysroot remote:" was implemented in August 2008
11318 BFD's need for a stat function was sidestepped with
11319 this hack. This was not remedied until March 2015
11320 so we retain the previous behavior to avoid breaking
11323 Note that the memset is a March 2015 addition; older
11324 GDBs set st_size *and nothing else* so the structure
11325 would have garbage in all other fields. This might
11326 break something but retaining the previous behavior
11327 here would be just too wrong. */
11329 memset (st
, 0, sizeof (struct stat
));
11330 st
->st_size
= INT_MAX
;
11334 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11335 (gdb_byte
*) &fst
, sizeof (fst
));
11337 if (read_len
!= ret
)
11338 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
11340 if (read_len
!= sizeof (fst
))
11341 error (_("vFile:fstat returned %d bytes, but expecting %d."),
11342 read_len
, (int) sizeof (fst
));
11344 remote_fileio_to_host_stat (&fst
, st
);
11349 /* Implementation of to_filesystem_is_local. */
11352 remote_filesystem_is_local (struct target_ops
*self
)
11354 /* Valgrind GDB presents itself as a remote target but works
11355 on the local filesystem: it does not implement remote get
11356 and users are not expected to set a sysroot. To handle
11357 this case we treat the remote filesystem as local if the
11358 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
11359 does not support vFile:open. */
11360 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
11362 enum packet_support ps
= packet_support (PACKET_vFile_open
);
11364 if (ps
== PACKET_SUPPORT_UNKNOWN
)
11366 int fd
, remote_errno
;
11368 /* Try opening a file to probe support. The supplied
11369 filename is irrelevant, we only care about whether
11370 the stub recognizes the packet or not. */
11371 fd
= remote_hostio_open (self
, NULL
, "just probing",
11372 FILEIO_O_RDONLY
, 0700, 0,
11376 remote_hostio_close (self
, fd
, &remote_errno
);
11378 ps
= packet_support (PACKET_vFile_open
);
11381 if (ps
== PACKET_DISABLE
)
11383 static int warning_issued
= 0;
11385 if (!warning_issued
)
11387 warning (_("remote target does not support file"
11388 " transfer, attempting to access files"
11389 " from local filesystem."));
11390 warning_issued
= 1;
11401 remote_fileio_errno_to_host (int errnum
)
11407 case FILEIO_ENOENT
:
11415 case FILEIO_EACCES
:
11417 case FILEIO_EFAULT
:
11421 case FILEIO_EEXIST
:
11423 case FILEIO_ENODEV
:
11425 case FILEIO_ENOTDIR
:
11427 case FILEIO_EISDIR
:
11429 case FILEIO_EINVAL
:
11431 case FILEIO_ENFILE
:
11433 case FILEIO_EMFILE
:
11437 case FILEIO_ENOSPC
:
11439 case FILEIO_ESPIPE
:
11443 case FILEIO_ENOSYS
:
11445 case FILEIO_ENAMETOOLONG
:
11446 return ENAMETOOLONG
;
11452 remote_hostio_error (int errnum
)
11454 int host_error
= remote_fileio_errno_to_host (errnum
);
11456 if (host_error
== -1)
11457 error (_("Unknown remote I/O error %d"), errnum
);
11459 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
11463 remote_hostio_close_cleanup (void *opaque
)
11465 int fd
= *(int *) opaque
;
11468 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
11472 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
11474 struct cleanup
*back_to
, *close_cleanup
;
11475 int retcode
, fd
, remote_errno
, bytes
, io_size
;
11478 int bytes_in_buffer
;
11481 struct remote_state
*rs
= get_remote_state ();
11483 if (!rs
->remote_desc
)
11484 error (_("command can only be used with remote target"));
11486 file
= gdb_fopen_cloexec (local_file
, "rb");
11488 perror_with_name (local_file
);
11489 back_to
= make_cleanup_fclose (file
);
11491 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11492 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
11494 0700, 0, &remote_errno
);
11496 remote_hostio_error (remote_errno
);
11498 /* Send up to this many bytes at once. They won't all fit in the
11499 remote packet limit, so we'll transfer slightly fewer. */
11500 io_size
= get_remote_packet_size ();
11501 buffer
= (gdb_byte
*) xmalloc (io_size
);
11502 make_cleanup (xfree
, buffer
);
11504 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11506 bytes_in_buffer
= 0;
11509 while (bytes_in_buffer
|| !saw_eof
)
11513 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
11514 io_size
- bytes_in_buffer
,
11519 error (_("Error reading %s."), local_file
);
11522 /* EOF. Unless there is something still in the
11523 buffer from the last iteration, we are done. */
11525 if (bytes_in_buffer
== 0)
11533 bytes
+= bytes_in_buffer
;
11534 bytes_in_buffer
= 0;
11536 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
11538 offset
, &remote_errno
);
11541 remote_hostio_error (remote_errno
);
11542 else if (retcode
== 0)
11543 error (_("Remote write of %d bytes returned 0!"), bytes
);
11544 else if (retcode
< bytes
)
11546 /* Short write. Save the rest of the read data for the next
11548 bytes_in_buffer
= bytes
- retcode
;
11549 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
11555 discard_cleanups (close_cleanup
);
11556 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11557 remote_hostio_error (remote_errno
);
11560 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
11561 do_cleanups (back_to
);
11565 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
11567 struct cleanup
*back_to
, *close_cleanup
;
11568 int fd
, remote_errno
, bytes
, io_size
;
11572 struct remote_state
*rs
= get_remote_state ();
11574 if (!rs
->remote_desc
)
11575 error (_("command can only be used with remote target"));
11577 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
11578 remote_file
, FILEIO_O_RDONLY
, 0, 0,
11581 remote_hostio_error (remote_errno
);
11583 file
= gdb_fopen_cloexec (local_file
, "wb");
11585 perror_with_name (local_file
);
11586 back_to
= make_cleanup_fclose (file
);
11588 /* Send up to this many bytes at once. They won't all fit in the
11589 remote packet limit, so we'll transfer slightly fewer. */
11590 io_size
= get_remote_packet_size ();
11591 buffer
= (gdb_byte
*) xmalloc (io_size
);
11592 make_cleanup (xfree
, buffer
);
11594 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
11599 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
11600 fd
, buffer
, io_size
, offset
, &remote_errno
);
11602 /* Success, but no bytes, means end-of-file. */
11605 remote_hostio_error (remote_errno
);
11609 bytes
= fwrite (buffer
, 1, bytes
, file
);
11611 perror_with_name (local_file
);
11614 discard_cleanups (close_cleanup
);
11615 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
11616 remote_hostio_error (remote_errno
);
11619 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
11620 do_cleanups (back_to
);
11624 remote_file_delete (const char *remote_file
, int from_tty
)
11626 int retcode
, remote_errno
;
11627 struct remote_state
*rs
= get_remote_state ();
11629 if (!rs
->remote_desc
)
11630 error (_("command can only be used with remote target"));
11632 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
11633 NULL
, remote_file
, &remote_errno
);
11635 remote_hostio_error (remote_errno
);
11638 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
11642 remote_put_command (char *args
, int from_tty
)
11644 struct cleanup
*back_to
;
11648 error_no_arg (_("file to put"));
11650 argv
= gdb_buildargv (args
);
11651 back_to
= make_cleanup_freeargv (argv
);
11652 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11653 error (_("Invalid parameters to remote put"));
11655 remote_file_put (argv
[0], argv
[1], from_tty
);
11657 do_cleanups (back_to
);
11661 remote_get_command (char *args
, int from_tty
)
11663 struct cleanup
*back_to
;
11667 error_no_arg (_("file to get"));
11669 argv
= gdb_buildargv (args
);
11670 back_to
= make_cleanup_freeargv (argv
);
11671 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
11672 error (_("Invalid parameters to remote get"));
11674 remote_file_get (argv
[0], argv
[1], from_tty
);
11676 do_cleanups (back_to
);
11680 remote_delete_command (char *args
, int from_tty
)
11682 struct cleanup
*back_to
;
11686 error_no_arg (_("file to delete"));
11688 argv
= gdb_buildargv (args
);
11689 back_to
= make_cleanup_freeargv (argv
);
11690 if (argv
[0] == NULL
|| argv
[1] != NULL
)
11691 error (_("Invalid parameters to remote delete"));
11693 remote_file_delete (argv
[0], from_tty
);
11695 do_cleanups (back_to
);
11699 remote_command (char *args
, int from_tty
)
11701 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
11705 remote_can_execute_reverse (struct target_ops
*self
)
11707 if (packet_support (PACKET_bs
) == PACKET_ENABLE
11708 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
11715 remote_supports_non_stop (struct target_ops
*self
)
11721 remote_supports_disable_randomization (struct target_ops
*self
)
11723 /* Only supported in extended mode. */
11728 remote_supports_multi_process (struct target_ops
*self
)
11730 struct remote_state
*rs
= get_remote_state ();
11732 return remote_multi_process_p (rs
);
11736 remote_supports_cond_tracepoints (void)
11738 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
11742 remote_supports_cond_breakpoints (struct target_ops
*self
)
11744 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
11748 remote_supports_fast_tracepoints (void)
11750 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
11754 remote_supports_static_tracepoints (void)
11756 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
11760 remote_supports_install_in_trace (void)
11762 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
11766 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
11768 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
11773 remote_supports_string_tracing (struct target_ops
*self
)
11775 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
11779 remote_can_run_breakpoint_commands (struct target_ops
*self
)
11781 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
11785 remote_trace_init (struct target_ops
*self
)
11788 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11789 if (strcmp (target_buf
, "OK") != 0)
11790 error (_("Target does not support this command."));
11793 static void free_actions_list (char **actions_list
);
11794 static void free_actions_list_cleanup_wrapper (void *);
11796 free_actions_list_cleanup_wrapper (void *al
)
11798 free_actions_list ((char **) al
);
11802 free_actions_list (char **actions_list
)
11806 if (actions_list
== 0)
11809 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
11810 xfree (actions_list
[ndx
]);
11812 xfree (actions_list
);
11815 /* Recursive routine to walk through command list including loops, and
11816 download packets for each command. */
11819 remote_download_command_source (int num
, ULONGEST addr
,
11820 struct command_line
*cmds
)
11822 struct remote_state
*rs
= get_remote_state ();
11823 struct command_line
*cmd
;
11825 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
11827 QUIT
; /* Allow user to bail out with ^C. */
11828 strcpy (rs
->buf
, "QTDPsrc:");
11829 encode_source_string (num
, addr
, "cmd", cmd
->line
,
11830 rs
->buf
+ strlen (rs
->buf
),
11831 rs
->buf_size
- strlen (rs
->buf
));
11833 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11834 if (strcmp (target_buf
, "OK"))
11835 warning (_("Target does not support source download."));
11837 if (cmd
->control_type
== while_control
11838 || cmd
->control_type
== while_stepping_control
)
11840 remote_download_command_source (num
, addr
, *cmd
->body_list
);
11842 QUIT
; /* Allow user to bail out with ^C. */
11843 strcpy (rs
->buf
, "QTDPsrc:");
11844 encode_source_string (num
, addr
, "cmd", "end",
11845 rs
->buf
+ strlen (rs
->buf
),
11846 rs
->buf_size
- strlen (rs
->buf
));
11848 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11849 if (strcmp (target_buf
, "OK"))
11850 warning (_("Target does not support source download."));
11856 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
11858 #define BUF_SIZE 2048
11862 char buf
[BUF_SIZE
];
11863 char **tdp_actions
;
11864 char **stepping_actions
;
11866 struct cleanup
*old_chain
= NULL
;
11867 struct agent_expr
*aexpr
;
11868 struct cleanup
*aexpr_chain
= NULL
;
11870 struct breakpoint
*b
= loc
->owner
;
11871 struct tracepoint
*t
= (struct tracepoint
*) b
;
11873 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
11874 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
11876 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
11879 tpaddr
= loc
->address
;
11880 sprintf_vma (addrbuf
, tpaddr
);
11881 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
11882 addrbuf
, /* address */
11883 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
11884 t
->step_count
, t
->pass_count
);
11885 /* Fast tracepoints are mostly handled by the target, but we can
11886 tell the target how big of an instruction block should be moved
11888 if (b
->type
== bp_fast_tracepoint
)
11890 /* Only test for support at download time; we may not know
11891 target capabilities at definition time. */
11892 if (remote_supports_fast_tracepoints ())
11894 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
11896 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
11897 gdb_insn_length (loc
->gdbarch
, tpaddr
));
11899 /* If it passed validation at definition but fails now,
11900 something is very wrong. */
11901 internal_error (__FILE__
, __LINE__
,
11902 _("Fast tracepoint not "
11903 "valid during download"));
11906 /* Fast tracepoints are functionally identical to regular
11907 tracepoints, so don't take lack of support as a reason to
11908 give up on the trace run. */
11909 warning (_("Target does not support fast tracepoints, "
11910 "downloading %d as regular tracepoint"), b
->number
);
11912 else if (b
->type
== bp_static_tracepoint
)
11914 /* Only test for support at download time; we may not know
11915 target capabilities at definition time. */
11916 if (remote_supports_static_tracepoints ())
11918 struct static_tracepoint_marker marker
;
11920 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
11921 strcat (buf
, ":S");
11923 error (_("Static tracepoint not valid during download"));
11926 /* Fast tracepoints are functionally identical to regular
11927 tracepoints, so don't take lack of support as a reason
11928 to give up on the trace run. */
11929 error (_("Target does not support static tracepoints"));
11931 /* If the tracepoint has a conditional, make it into an agent
11932 expression and append to the definition. */
11935 /* Only test support at download time, we may not know target
11936 capabilities at definition time. */
11937 if (remote_supports_cond_tracepoints ())
11939 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
11940 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
11941 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
11943 pkt
= buf
+ strlen (buf
);
11944 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
11945 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
11947 do_cleanups (aexpr_chain
);
11950 warning (_("Target does not support conditional tracepoints, "
11951 "ignoring tp %d cond"), b
->number
);
11954 if (b
->commands
|| *default_collect
)
11957 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11958 if (strcmp (target_buf
, "OK"))
11959 error (_("Target does not support tracepoints."));
11961 /* do_single_steps (t); */
11964 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
11966 QUIT
; /* Allow user to bail out with ^C. */
11967 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
11968 b
->number
, addrbuf
, /* address */
11970 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
11973 remote_get_noisy_reply (&target_buf
,
11975 if (strcmp (target_buf
, "OK"))
11976 error (_("Error on target while setting tracepoints."));
11979 if (stepping_actions
)
11981 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
11983 QUIT
; /* Allow user to bail out with ^C. */
11984 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
11985 b
->number
, addrbuf
, /* address */
11986 ((ndx
== 0) ? "S" : ""),
11987 stepping_actions
[ndx
],
11988 (stepping_actions
[ndx
+ 1] ? "-" : ""));
11990 remote_get_noisy_reply (&target_buf
,
11992 if (strcmp (target_buf
, "OK"))
11993 error (_("Error on target while setting tracepoints."));
11997 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
11999 if (b
->location
!= NULL
)
12001 strcpy (buf
, "QTDPsrc:");
12002 encode_source_string (b
->number
, loc
->address
, "at",
12003 event_location_to_string (b
->location
),
12004 buf
+ strlen (buf
), 2048 - strlen (buf
));
12006 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12007 if (strcmp (target_buf
, "OK"))
12008 warning (_("Target does not support source download."));
12010 if (b
->cond_string
)
12012 strcpy (buf
, "QTDPsrc:");
12013 encode_source_string (b
->number
, loc
->address
,
12014 "cond", b
->cond_string
, buf
+ strlen (buf
),
12015 2048 - strlen (buf
));
12017 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12018 if (strcmp (target_buf
, "OK"))
12019 warning (_("Target does not support source download."));
12021 remote_download_command_source (b
->number
, loc
->address
,
12022 breakpoint_commands (b
));
12025 do_cleanups (old_chain
);
12029 remote_can_download_tracepoint (struct target_ops
*self
)
12031 struct remote_state
*rs
= get_remote_state ();
12032 struct trace_status
*ts
;
12035 /* Don't try to install tracepoints until we've relocated our
12036 symbols, and fetched and merged the target's tracepoint list with
12038 if (rs
->starting_up
)
12041 ts
= current_trace_status ();
12042 status
= remote_get_trace_status (self
, ts
);
12044 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
12047 /* If we are in a tracing experiment, but remote stub doesn't support
12048 installing tracepoint in trace, we have to return. */
12049 if (!remote_supports_install_in_trace ())
12057 remote_download_trace_state_variable (struct target_ops
*self
,
12058 struct trace_state_variable
*tsv
)
12060 struct remote_state
*rs
= get_remote_state ();
12063 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
12064 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
12066 p
= rs
->buf
+ strlen (rs
->buf
);
12067 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
12068 error (_("Trace state variable name too long for tsv definition packet"));
12069 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
12072 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12073 if (*target_buf
== '\0')
12074 error (_("Target does not support this command."));
12075 if (strcmp (target_buf
, "OK") != 0)
12076 error (_("Error on target while downloading trace state variable."));
12080 remote_enable_tracepoint (struct target_ops
*self
,
12081 struct bp_location
*location
)
12083 struct remote_state
*rs
= get_remote_state ();
12086 sprintf_vma (addr_buf
, location
->address
);
12087 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
12088 location
->owner
->number
, addr_buf
);
12090 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12091 if (*rs
->buf
== '\0')
12092 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
12093 if (strcmp (rs
->buf
, "OK") != 0)
12094 error (_("Error on target while enabling tracepoint."));
12098 remote_disable_tracepoint (struct target_ops
*self
,
12099 struct bp_location
*location
)
12101 struct remote_state
*rs
= get_remote_state ();
12104 sprintf_vma (addr_buf
, location
->address
);
12105 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
12106 location
->owner
->number
, addr_buf
);
12108 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12109 if (*rs
->buf
== '\0')
12110 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
12111 if (strcmp (rs
->buf
, "OK") != 0)
12112 error (_("Error on target while disabling tracepoint."));
12116 remote_trace_set_readonly_regions (struct target_ops
*self
)
12120 bfd_size_type size
;
12126 return; /* No information to give. */
12128 strcpy (target_buf
, "QTro");
12129 offset
= strlen (target_buf
);
12130 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
12132 char tmp1
[40], tmp2
[40];
12135 if ((s
->flags
& SEC_LOAD
) == 0 ||
12136 /* (s->flags & SEC_CODE) == 0 || */
12137 (s
->flags
& SEC_READONLY
) == 0)
12141 vma
= bfd_get_section_vma (abfd
, s
);
12142 size
= bfd_get_section_size (s
);
12143 sprintf_vma (tmp1
, vma
);
12144 sprintf_vma (tmp2
, vma
+ size
);
12145 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
12146 if (offset
+ sec_length
+ 1 > target_buf_size
)
12148 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
12150 Too many sections for read-only sections definition packet."));
12153 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
12155 offset
+= sec_length
;
12159 putpkt (target_buf
);
12160 getpkt (&target_buf
, &target_buf_size
, 0);
12165 remote_trace_start (struct target_ops
*self
)
12167 putpkt ("QTStart");
12168 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12169 if (*target_buf
== '\0')
12170 error (_("Target does not support this command."));
12171 if (strcmp (target_buf
, "OK") != 0)
12172 error (_("Bogus reply from target: %s"), target_buf
);
12176 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
12178 /* Initialize it just to avoid a GCC false warning. */
12180 /* FIXME we need to get register block size some other way. */
12181 extern int trace_regblock_size
;
12182 enum packet_result result
;
12184 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
12187 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
12189 putpkt ("qTStatus");
12193 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12195 CATCH (ex
, RETURN_MASK_ERROR
)
12197 if (ex
.error
!= TARGET_CLOSE_ERROR
)
12199 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
12202 throw_exception (ex
);
12206 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
12208 /* If the remote target doesn't do tracing, flag it. */
12209 if (result
== PACKET_UNKNOWN
)
12212 /* We're working with a live target. */
12213 ts
->filename
= NULL
;
12216 error (_("Bogus trace status reply from target: %s"), target_buf
);
12218 /* Function 'parse_trace_status' sets default value of each field of
12219 'ts' at first, so we don't have to do it here. */
12220 parse_trace_status (p
, ts
);
12222 return ts
->running
;
12226 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
12227 struct uploaded_tp
*utp
)
12229 struct remote_state
*rs
= get_remote_state ();
12231 struct bp_location
*loc
;
12232 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
12233 size_t size
= get_remote_packet_size ();
12237 tp
->base
.hit_count
= 0;
12238 tp
->traceframe_usage
= 0;
12239 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
12241 /* If the tracepoint was never downloaded, don't go asking for
12243 if (tp
->number_on_target
== 0)
12245 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
12246 phex_nz (loc
->address
, 0));
12248 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12249 if (reply
&& *reply
)
12252 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12258 utp
->hit_count
= 0;
12259 utp
->traceframe_usage
= 0;
12260 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
12261 phex_nz (utp
->addr
, 0));
12263 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12264 if (reply
&& *reply
)
12267 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12273 remote_trace_stop (struct target_ops
*self
)
12276 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12277 if (*target_buf
== '\0')
12278 error (_("Target does not support this command."));
12279 if (strcmp (target_buf
, "OK") != 0)
12280 error (_("Bogus reply from target: %s"), target_buf
);
12284 remote_trace_find (struct target_ops
*self
,
12285 enum trace_find_type type
, int num
,
12286 CORE_ADDR addr1
, CORE_ADDR addr2
,
12289 struct remote_state
*rs
= get_remote_state ();
12290 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12292 int target_frameno
= -1, target_tracept
= -1;
12294 /* Lookups other than by absolute frame number depend on the current
12295 trace selected, so make sure it is correct on the remote end
12297 if (type
!= tfind_number
)
12298 set_remote_traceframe ();
12301 strcpy (p
, "QTFrame:");
12302 p
= strchr (p
, '\0');
12306 xsnprintf (p
, endbuf
- p
, "%x", num
);
12309 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
12312 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
12315 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
12316 phex_nz (addr2
, 0));
12318 case tfind_outside
:
12319 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
12320 phex_nz (addr2
, 0));
12323 error (_("Unknown trace find type %d"), type
);
12327 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
12328 if (*reply
== '\0')
12329 error (_("Target does not support this command."));
12331 while (reply
&& *reply
)
12336 target_frameno
= (int) strtol (p
, &reply
, 16);
12338 error (_("Unable to parse trace frame number"));
12339 /* Don't update our remote traceframe number cache on failure
12340 to select a remote traceframe. */
12341 if (target_frameno
== -1)
12346 target_tracept
= (int) strtol (p
, &reply
, 16);
12348 error (_("Unable to parse tracepoint number"));
12350 case 'O': /* "OK"? */
12351 if (reply
[1] == 'K' && reply
[2] == '\0')
12354 error (_("Bogus reply from target: %s"), reply
);
12357 error (_("Bogus reply from target: %s"), reply
);
12360 *tpp
= target_tracept
;
12362 rs
->remote_traceframe_number
= target_frameno
;
12363 return target_frameno
;
12367 remote_get_trace_state_variable_value (struct target_ops
*self
,
12368 int tsvnum
, LONGEST
*val
)
12370 struct remote_state
*rs
= get_remote_state ();
12374 set_remote_traceframe ();
12376 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
12378 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12379 if (reply
&& *reply
)
12383 unpack_varlen_hex (reply
+ 1, &uval
);
12384 *val
= (LONGEST
) uval
;
12392 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
12394 struct remote_state
*rs
= get_remote_state ();
12398 strcpy (p
, "QTSave:");
12400 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
12401 error (_("Remote file name too long for trace save packet"));
12402 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
12405 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12406 if (*reply
== '\0')
12407 error (_("Target does not support this command."));
12408 if (strcmp (reply
, "OK") != 0)
12409 error (_("Bogus reply from target: %s"), reply
);
12413 /* This is basically a memory transfer, but needs to be its own packet
12414 because we don't know how the target actually organizes its trace
12415 memory, plus we want to be able to ask for as much as possible, but
12416 not be unhappy if we don't get as much as we ask for. */
12419 remote_get_raw_trace_data (struct target_ops
*self
,
12420 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
12422 struct remote_state
*rs
= get_remote_state ();
12428 strcpy (p
, "qTBuffer:");
12430 p
+= hexnumstr (p
, offset
);
12432 p
+= hexnumstr (p
, len
);
12436 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12437 if (reply
&& *reply
)
12439 /* 'l' by itself means we're at the end of the buffer and
12440 there is nothing more to get. */
12444 /* Convert the reply into binary. Limit the number of bytes to
12445 convert according to our passed-in buffer size, rather than
12446 what was returned in the packet; if the target is
12447 unexpectedly generous and gives us a bigger reply than we
12448 asked for, we don't want to crash. */
12449 rslt
= hex2bin (target_buf
, buf
, len
);
12453 /* Something went wrong, flag as an error. */
12458 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
12460 struct remote_state
*rs
= get_remote_state ();
12462 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
12466 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
12468 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12469 if (*reply
== '\0')
12470 error (_("Target does not support this command."));
12471 if (strcmp (reply
, "OK") != 0)
12472 error (_("Bogus reply from target: %s"), reply
);
12475 warning (_("Target does not support disconnected tracing."));
12479 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
12481 struct thread_info
*info
= find_thread_ptid (ptid
);
12483 if (info
&& info
->priv
)
12484 return info
->priv
->core
;
12489 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
12491 struct remote_state
*rs
= get_remote_state ();
12494 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
12496 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12497 if (*reply
== '\0')
12498 error (_("Target does not support this command."));
12499 if (strcmp (reply
, "OK") != 0)
12500 error (_("Bogus reply from target: %s"), reply
);
12503 static struct traceframe_info
*
12504 remote_traceframe_info (struct target_ops
*self
)
12508 text
= target_read_stralloc (¤t_target
,
12509 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
12512 struct traceframe_info
*info
;
12513 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
12515 info
= parse_traceframe_info (text
);
12516 do_cleanups (back_to
);
12523 /* Handle the qTMinFTPILen packet. Returns the minimum length of
12524 instruction on which a fast tracepoint may be placed. Returns -1
12525 if the packet is not supported, and 0 if the minimum instruction
12526 length is unknown. */
12529 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
12531 struct remote_state
*rs
= get_remote_state ();
12534 /* If we're not debugging a process yet, the IPA can't be
12536 if (!target_has_execution
)
12539 /* Make sure the remote is pointing at the right process. */
12540 set_general_process ();
12542 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
12544 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12545 if (*reply
== '\0')
12549 ULONGEST min_insn_len
;
12551 unpack_varlen_hex (reply
, &min_insn_len
);
12553 return (int) min_insn_len
;
12558 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
12560 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
12562 struct remote_state
*rs
= get_remote_state ();
12563 char *buf
= rs
->buf
;
12564 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12565 enum packet_result result
;
12567 gdb_assert (val
>= 0 || val
== -1);
12568 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
12569 /* Send -1 as literal "-1" to avoid host size dependency. */
12573 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
12576 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
12579 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
12580 result
= packet_ok (rs
->buf
,
12581 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
12583 if (result
!= PACKET_OK
)
12584 warning (_("Bogus reply from target: %s"), rs
->buf
);
12589 remote_set_trace_notes (struct target_ops
*self
,
12590 const char *user
, const char *notes
,
12591 const char *stop_notes
)
12593 struct remote_state
*rs
= get_remote_state ();
12595 char *buf
= rs
->buf
;
12596 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12599 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
12602 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
12603 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
12609 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
12610 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
12616 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
12617 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
12621 /* Ensure the buffer is terminated. */
12625 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
12626 if (*reply
== '\0')
12629 if (strcmp (reply
, "OK") != 0)
12630 error (_("Bogus reply from target: %s"), reply
);
12636 remote_use_agent (struct target_ops
*self
, int use
)
12638 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
12640 struct remote_state
*rs
= get_remote_state ();
12642 /* If the stub supports QAgent. */
12643 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
12645 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12647 if (strcmp (rs
->buf
, "OK") == 0)
12658 remote_can_use_agent (struct target_ops
*self
)
12660 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
12663 struct btrace_target_info
12665 /* The ptid of the traced thread. */
12668 /* The obtained branch trace configuration. */
12669 struct btrace_config conf
;
12672 /* Reset our idea of our target's btrace configuration. */
12675 remote_btrace_reset (void)
12677 struct remote_state
*rs
= get_remote_state ();
12679 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
12682 /* Check whether the target supports branch tracing. */
12685 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
12687 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
12689 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
12694 case BTRACE_FORMAT_NONE
:
12697 case BTRACE_FORMAT_BTS
:
12698 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
12700 case BTRACE_FORMAT_PT
:
12701 /* The trace is decoded on the host. Even if our target supports it,
12702 we still need to have libipt to decode the trace. */
12703 #if defined (HAVE_LIBIPT)
12704 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
12705 #else /* !defined (HAVE_LIBIPT) */
12707 #endif /* !defined (HAVE_LIBIPT) */
12710 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
12713 /* Synchronize the configuration with the target. */
12716 btrace_sync_conf (const struct btrace_config
*conf
)
12718 struct packet_config
*packet
;
12719 struct remote_state
*rs
;
12720 char *buf
, *pos
, *endbuf
;
12722 rs
= get_remote_state ();
12724 endbuf
= buf
+ get_remote_packet_size ();
12726 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
12727 if (packet_config_support (packet
) == PACKET_ENABLE
12728 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
12731 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12735 getpkt (&buf
, &rs
->buf_size
, 0);
12737 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12739 if (buf
[0] == 'E' && buf
[1] == '.')
12740 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
12742 error (_("Failed to configure the BTS buffer size."));
12745 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
12748 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
12749 if (packet_config_support (packet
) == PACKET_ENABLE
12750 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
12753 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
12757 getpkt (&buf
, &rs
->buf_size
, 0);
12759 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
12761 if (buf
[0] == 'E' && buf
[1] == '.')
12762 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
12764 error (_("Failed to configure the trace buffer size."));
12767 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
12771 /* Read the current thread's btrace configuration from the target and
12772 store it into CONF. */
12775 btrace_read_config (struct btrace_config
*conf
)
12779 xml
= target_read_stralloc (¤t_target
,
12780 TARGET_OBJECT_BTRACE_CONF
, "");
12783 struct cleanup
*cleanup
;
12785 cleanup
= make_cleanup (xfree
, xml
);
12786 parse_xml_btrace_conf (conf
, xml
);
12787 do_cleanups (cleanup
);
12791 /* Maybe reopen target btrace. */
12794 remote_btrace_maybe_reopen (void)
12796 struct remote_state
*rs
= get_remote_state ();
12797 struct cleanup
*cleanup
;
12798 struct thread_info
*tp
;
12799 int btrace_target_pushed
= 0;
12802 cleanup
= make_cleanup_restore_current_thread ();
12803 ALL_NON_EXITED_THREADS (tp
)
12805 set_general_thread (tp
->ptid
);
12807 memset (&rs
->btrace_config
, 0x00, sizeof (struct btrace_config
));
12808 btrace_read_config (&rs
->btrace_config
);
12810 if (rs
->btrace_config
.format
== BTRACE_FORMAT_NONE
)
12813 #if !defined (HAVE_LIBIPT)
12814 if (rs
->btrace_config
.format
== BTRACE_FORMAT_PT
)
12819 warning (_("GDB does not support Intel Processor Trace. "
12820 "\"record\" will not work in this session."));
12825 #endif /* !defined (HAVE_LIBIPT) */
12827 /* Push target, once, but before anything else happens. This way our
12828 changes to the threads will be cleaned up by unpushing the target
12829 in case btrace_read_config () throws. */
12830 if (!btrace_target_pushed
)
12832 btrace_target_pushed
= 1;
12833 record_btrace_push_target ();
12834 printf_filtered (_("Target is recording using %s.\n"),
12835 btrace_format_string (rs
->btrace_config
.format
));
12838 tp
->btrace
.target
= XCNEW (struct btrace_target_info
);
12839 tp
->btrace
.target
->ptid
= tp
->ptid
;
12840 tp
->btrace
.target
->conf
= rs
->btrace_config
;
12842 do_cleanups (cleanup
);
12845 /* Enable branch tracing. */
12847 static struct btrace_target_info
*
12848 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
12849 const struct btrace_config
*conf
)
12851 struct btrace_target_info
*tinfo
= NULL
;
12852 struct packet_config
*packet
= NULL
;
12853 struct remote_state
*rs
= get_remote_state ();
12854 char *buf
= rs
->buf
;
12855 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12857 switch (conf
->format
)
12859 case BTRACE_FORMAT_BTS
:
12860 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
12863 case BTRACE_FORMAT_PT
:
12864 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
12868 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
12869 error (_("Target does not support branch tracing."));
12871 btrace_sync_conf (conf
);
12873 set_general_thread (ptid
);
12875 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12877 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12879 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12881 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12882 error (_("Could not enable branch tracing for %s: %s"),
12883 target_pid_to_str (ptid
), rs
->buf
+ 2);
12885 error (_("Could not enable branch tracing for %s."),
12886 target_pid_to_str (ptid
));
12889 tinfo
= XCNEW (struct btrace_target_info
);
12890 tinfo
->ptid
= ptid
;
12892 /* If we fail to read the configuration, we lose some information, but the
12893 tracing itself is not impacted. */
12896 btrace_read_config (&tinfo
->conf
);
12898 CATCH (err
, RETURN_MASK_ERROR
)
12900 if (err
.message
!= NULL
)
12901 warning ("%s", err
.message
);
12908 /* Disable branch tracing. */
12911 remote_disable_btrace (struct target_ops
*self
,
12912 struct btrace_target_info
*tinfo
)
12914 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
12915 struct remote_state
*rs
= get_remote_state ();
12916 char *buf
= rs
->buf
;
12917 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12919 if (packet_config_support (packet
) != PACKET_ENABLE
)
12920 error (_("Target does not support branch tracing."));
12922 set_general_thread (tinfo
->ptid
);
12924 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12926 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12928 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12930 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12931 error (_("Could not disable branch tracing for %s: %s"),
12932 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
12934 error (_("Could not disable branch tracing for %s."),
12935 target_pid_to_str (tinfo
->ptid
));
12941 /* Teardown branch tracing. */
12944 remote_teardown_btrace (struct target_ops
*self
,
12945 struct btrace_target_info
*tinfo
)
12947 /* We must not talk to the target during teardown. */
12951 /* Read the branch trace. */
12953 static enum btrace_error
12954 remote_read_btrace (struct target_ops
*self
,
12955 struct btrace_data
*btrace
,
12956 struct btrace_target_info
*tinfo
,
12957 enum btrace_read_type type
)
12959 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
12960 struct cleanup
*cleanup
;
12964 if (packet_config_support (packet
) != PACKET_ENABLE
)
12965 error (_("Target does not support branch tracing."));
12967 #if !defined(HAVE_LIBEXPAT)
12968 error (_("Cannot process branch tracing result. XML parsing not supported."));
12973 case BTRACE_READ_ALL
:
12976 case BTRACE_READ_NEW
:
12979 case BTRACE_READ_DELTA
:
12983 internal_error (__FILE__
, __LINE__
,
12984 _("Bad branch tracing read type: %u."),
12985 (unsigned int) type
);
12988 xml
= target_read_stralloc (¤t_target
,
12989 TARGET_OBJECT_BTRACE
, annex
);
12991 return BTRACE_ERR_UNKNOWN
;
12993 cleanup
= make_cleanup (xfree
, xml
);
12994 parse_xml_btrace (btrace
, xml
);
12995 do_cleanups (cleanup
);
12997 return BTRACE_ERR_NONE
;
13000 static const struct btrace_config
*
13001 remote_btrace_conf (struct target_ops
*self
,
13002 const struct btrace_target_info
*tinfo
)
13004 return &tinfo
->conf
;
13008 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
13010 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
13014 /* Implementation of to_load. */
13017 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
13019 generic_load (name
, from_tty
);
13022 /* Accepts an integer PID; returns a string representing a file that
13023 can be opened on the remote side to get the symbols for the child
13024 process. Returns NULL if the operation is not supported. */
13027 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
13029 static char *filename
= NULL
;
13030 struct inferior
*inf
;
13031 char *annex
= NULL
;
13033 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
13036 if (filename
!= NULL
)
13039 inf
= find_inferior_pid (pid
);
13041 internal_error (__FILE__
, __LINE__
,
13042 _("not currently attached to process %d"), pid
);
13044 if (!inf
->fake_pid_p
)
13046 const int annex_size
= 9;
13048 annex
= (char *) alloca (annex_size
);
13049 xsnprintf (annex
, annex_size
, "%x", pid
);
13052 filename
= target_read_stralloc (¤t_target
,
13053 TARGET_OBJECT_EXEC_FILE
, annex
);
13058 /* Implement the to_can_do_single_step target_ops method. */
13061 remote_can_do_single_step (struct target_ops
*ops
)
13063 /* We can only tell whether target supports single step or not by
13064 supported s and S vCont actions if the stub supports vContSupported
13065 feature. If the stub doesn't support vContSupported feature,
13066 we have conservatively to think target doesn't supports single
13068 if (packet_support (PACKET_vContSupported
) == PACKET_ENABLE
)
13070 struct remote_state
*rs
= get_remote_state ();
13072 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13073 remote_vcont_probe (rs
);
13075 return rs
->supports_vCont
.s
&& rs
->supports_vCont
.S
;
13081 /* Implementation of the to_execution_direction method for the remote
13084 static enum exec_direction_kind
13085 remote_execution_direction (struct target_ops
*self
)
13087 struct remote_state
*rs
= get_remote_state ();
13089 return rs
->last_resume_exec_dir
;
13093 init_remote_ops (void)
13095 remote_ops
.to_shortname
= "remote";
13096 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
13097 remote_ops
.to_doc
=
13098 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13099 Specify the serial device it is connected to\n\
13100 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
13101 remote_ops
.to_open
= remote_open
;
13102 remote_ops
.to_close
= remote_close
;
13103 remote_ops
.to_detach
= remote_detach
;
13104 remote_ops
.to_disconnect
= remote_disconnect
;
13105 remote_ops
.to_resume
= remote_resume
;
13106 remote_ops
.to_wait
= remote_wait
;
13107 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
13108 remote_ops
.to_store_registers
= remote_store_registers
;
13109 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
13110 remote_ops
.to_files_info
= remote_files_info
;
13111 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
13112 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
13113 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
13114 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
13115 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
13116 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
13117 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
13118 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
13119 remote_ops
.to_watchpoint_addr_within_range
=
13120 remote_watchpoint_addr_within_range
;
13121 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
13122 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
13123 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
13124 remote_ops
.to_region_ok_for_hw_watchpoint
13125 = remote_region_ok_for_hw_watchpoint
;
13126 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
13127 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
13128 remote_ops
.to_kill
= remote_kill
;
13129 remote_ops
.to_load
= remote_load
;
13130 remote_ops
.to_mourn_inferior
= remote_mourn
;
13131 remote_ops
.to_pass_signals
= remote_pass_signals
;
13132 remote_ops
.to_set_syscall_catchpoint
= remote_set_syscall_catchpoint
;
13133 remote_ops
.to_program_signals
= remote_program_signals
;
13134 remote_ops
.to_thread_alive
= remote_thread_alive
;
13135 remote_ops
.to_thread_name
= remote_thread_name
;
13136 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
13137 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
13138 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
13139 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
13140 remote_ops
.to_stop
= remote_stop
;
13141 remote_ops
.to_interrupt
= remote_interrupt
;
13142 remote_ops
.to_pass_ctrlc
= remote_pass_ctrlc
;
13143 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
13144 remote_ops
.to_get_memory_xfer_limit
= remote_get_memory_xfer_limit
;
13145 remote_ops
.to_rcmd
= remote_rcmd
;
13146 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
13147 remote_ops
.to_log_command
= serial_log_command
;
13148 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
13149 remote_ops
.to_stratum
= process_stratum
;
13150 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
13151 remote_ops
.to_has_memory
= default_child_has_memory
;
13152 remote_ops
.to_has_stack
= default_child_has_stack
;
13153 remote_ops
.to_has_registers
= default_child_has_registers
;
13154 remote_ops
.to_has_execution
= default_child_has_execution
;
13155 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
13156 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
13157 remote_ops
.to_magic
= OPS_MAGIC
;
13158 remote_ops
.to_memory_map
= remote_memory_map
;
13159 remote_ops
.to_flash_erase
= remote_flash_erase
;
13160 remote_ops
.to_flash_done
= remote_flash_done
;
13161 remote_ops
.to_read_description
= remote_read_description
;
13162 remote_ops
.to_search_memory
= remote_search_memory
;
13163 remote_ops
.to_can_async_p
= remote_can_async_p
;
13164 remote_ops
.to_is_async_p
= remote_is_async_p
;
13165 remote_ops
.to_async
= remote_async
;
13166 remote_ops
.to_thread_events
= remote_thread_events
;
13167 remote_ops
.to_can_do_single_step
= remote_can_do_single_step
;
13168 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
13169 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
13170 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
13171 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
13172 remote_ops
.to_supports_disable_randomization
13173 = remote_supports_disable_randomization
;
13174 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
13175 remote_ops
.to_fileio_open
= remote_hostio_open
;
13176 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
13177 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
13178 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
13179 remote_ops
.to_fileio_close
= remote_hostio_close
;
13180 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
13181 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
13182 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
13183 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
13184 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
13185 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
13186 remote_ops
.to_trace_init
= remote_trace_init
;
13187 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
13188 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
13189 remote_ops
.to_download_trace_state_variable
13190 = remote_download_trace_state_variable
;
13191 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
13192 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
13193 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
13194 remote_ops
.to_trace_start
= remote_trace_start
;
13195 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
13196 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
13197 remote_ops
.to_trace_stop
= remote_trace_stop
;
13198 remote_ops
.to_trace_find
= remote_trace_find
;
13199 remote_ops
.to_get_trace_state_variable_value
13200 = remote_get_trace_state_variable_value
;
13201 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
13202 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
13203 remote_ops
.to_upload_trace_state_variables
13204 = remote_upload_trace_state_variables
;
13205 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
13206 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
13207 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
13208 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
13209 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
13210 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
13211 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
13212 remote_ops
.to_verify_memory
= remote_verify_memory
;
13213 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
13214 remote_ops
.to_set_permissions
= remote_set_permissions
;
13215 remote_ops
.to_static_tracepoint_marker_at
13216 = remote_static_tracepoint_marker_at
;
13217 remote_ops
.to_static_tracepoint_markers_by_strid
13218 = remote_static_tracepoint_markers_by_strid
;
13219 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
13220 remote_ops
.to_use_agent
= remote_use_agent
;
13221 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
13222 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
13223 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
13224 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
13225 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
13226 remote_ops
.to_read_btrace
= remote_read_btrace
;
13227 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
13228 remote_ops
.to_augmented_libraries_svr4_read
=
13229 remote_augmented_libraries_svr4_read
;
13230 remote_ops
.to_follow_fork
= remote_follow_fork
;
13231 remote_ops
.to_follow_exec
= remote_follow_exec
;
13232 remote_ops
.to_insert_fork_catchpoint
= remote_insert_fork_catchpoint
;
13233 remote_ops
.to_remove_fork_catchpoint
= remote_remove_fork_catchpoint
;
13234 remote_ops
.to_insert_vfork_catchpoint
= remote_insert_vfork_catchpoint
;
13235 remote_ops
.to_remove_vfork_catchpoint
= remote_remove_vfork_catchpoint
;
13236 remote_ops
.to_insert_exec_catchpoint
= remote_insert_exec_catchpoint
;
13237 remote_ops
.to_remove_exec_catchpoint
= remote_remove_exec_catchpoint
;
13238 remote_ops
.to_execution_direction
= remote_execution_direction
;
13241 /* Set up the extended remote vector by making a copy of the standard
13242 remote vector and adding to it. */
13245 init_extended_remote_ops (void)
13247 extended_remote_ops
= remote_ops
;
13249 extended_remote_ops
.to_shortname
= "extended-remote";
13250 extended_remote_ops
.to_longname
=
13251 "Extended remote serial target in gdb-specific protocol";
13252 extended_remote_ops
.to_doc
=
13253 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13254 Specify the serial device it is connected to (e.g. /dev/ttya).";
13255 extended_remote_ops
.to_open
= extended_remote_open
;
13256 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
13257 extended_remote_ops
.to_detach
= extended_remote_detach
;
13258 extended_remote_ops
.to_attach
= extended_remote_attach
;
13259 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
13260 extended_remote_ops
.to_supports_disable_randomization
13261 = extended_remote_supports_disable_randomization
;
13265 remote_can_async_p (struct target_ops
*ops
)
13267 struct remote_state
*rs
= get_remote_state ();
13269 if (!target_async_permitted
)
13270 /* We only enable async when the user specifically asks for it. */
13273 /* We're async whenever the serial device is. */
13274 return serial_can_async_p (rs
->remote_desc
);
13278 remote_is_async_p (struct target_ops
*ops
)
13280 struct remote_state
*rs
= get_remote_state ();
13282 if (!target_async_permitted
)
13283 /* We only enable async when the user specifically asks for it. */
13286 /* We're async whenever the serial device is. */
13287 return serial_is_async_p (rs
->remote_desc
);
13290 /* Pass the SERIAL event on and up to the client. One day this code
13291 will be able to delay notifying the client of an event until the
13292 point where an entire packet has been received. */
13294 static serial_event_ftype remote_async_serial_handler
;
13297 remote_async_serial_handler (struct serial
*scb
, void *context
)
13299 /* Don't propogate error information up to the client. Instead let
13300 the client find out about the error by querying the target. */
13301 inferior_event_handler (INF_REG_EVENT
, NULL
);
13305 remote_async_inferior_event_handler (gdb_client_data data
)
13307 inferior_event_handler (INF_REG_EVENT
, NULL
);
13311 remote_async (struct target_ops
*ops
, int enable
)
13313 struct remote_state
*rs
= get_remote_state ();
13317 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
13319 /* If there are pending events in the stop reply queue tell the
13320 event loop to process them. */
13321 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
13322 mark_async_event_handler (remote_async_inferior_event_token
);
13323 /* For simplicity, below we clear the pending events token
13324 without remembering whether it is marked, so here we always
13325 mark it. If there's actually no pending notification to
13326 process, this ends up being a no-op (other than a spurious
13327 event-loop wakeup). */
13328 if (target_is_non_stop_p ())
13329 mark_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13333 serial_async (rs
->remote_desc
, NULL
, NULL
);
13334 /* If the core is disabling async, it doesn't want to be
13335 disturbed with target events. Clear all async event sources
13337 clear_async_event_handler (remote_async_inferior_event_token
);
13338 if (target_is_non_stop_p ())
13339 clear_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13343 /* Implementation of the to_thread_events method. */
13346 remote_thread_events (struct target_ops
*ops
, int enable
)
13348 struct remote_state
*rs
= get_remote_state ();
13349 size_t size
= get_remote_packet_size ();
13351 if (packet_support (PACKET_QThreadEvents
) == PACKET_DISABLE
)
13354 xsnprintf (rs
->buf
, size
, "QThreadEvents:%x", enable
? 1 : 0);
13356 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13358 switch (packet_ok (rs
->buf
,
13359 &remote_protocol_packets
[PACKET_QThreadEvents
]))
13362 if (strcmp (rs
->buf
, "OK") != 0)
13363 error (_("Remote refused setting thread events: %s"), rs
->buf
);
13366 warning (_("Remote failure reply: %s"), rs
->buf
);
13368 case PACKET_UNKNOWN
:
13374 set_remote_cmd (char *args
, int from_tty
)
13376 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
13380 show_remote_cmd (char *args
, int from_tty
)
13382 /* We can't just use cmd_show_list here, because we want to skip
13383 the redundant "show remote Z-packet" and the legacy aliases. */
13384 struct cleanup
*showlist_chain
;
13385 struct cmd_list_element
*list
= remote_show_cmdlist
;
13386 struct ui_out
*uiout
= current_uiout
;
13388 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
13389 for (; list
!= NULL
; list
= list
->next
)
13390 if (strcmp (list
->name
, "Z-packet") == 0)
13392 else if (list
->type
== not_set_cmd
)
13393 /* Alias commands are exactly like the original, except they
13394 don't have the normal type. */
13398 struct cleanup
*option_chain
13399 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
13401 ui_out_field_string (uiout
, "name", list
->name
);
13402 ui_out_text (uiout
, ": ");
13403 if (list
->type
== show_cmd
)
13404 do_show_command (NULL
, from_tty
, list
);
13406 cmd_func (list
, NULL
, from_tty
);
13407 /* Close the tuple. */
13408 do_cleanups (option_chain
);
13411 /* Close the tuple. */
13412 do_cleanups (showlist_chain
);
13416 /* Function to be called whenever a new objfile (shlib) is detected. */
13418 remote_new_objfile (struct objfile
*objfile
)
13420 struct remote_state
*rs
= get_remote_state ();
13422 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
13423 remote_check_symbols ();
13426 /* Pull all the tracepoints defined on the target and create local
13427 data structures representing them. We don't want to create real
13428 tracepoints yet, we don't want to mess up the user's existing
13432 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
13434 struct remote_state
*rs
= get_remote_state ();
13437 /* Ask for a first packet of tracepoint definition. */
13439 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13441 while (*p
&& *p
!= 'l')
13443 parse_tracepoint_definition (p
, utpp
);
13444 /* Ask for another packet of tracepoint definition. */
13446 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13453 remote_upload_trace_state_variables (struct target_ops
*self
,
13454 struct uploaded_tsv
**utsvp
)
13456 struct remote_state
*rs
= get_remote_state ();
13459 /* Ask for a first packet of variable definition. */
13461 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13463 while (*p
&& *p
!= 'l')
13465 parse_tsv_definition (p
, utsvp
);
13466 /* Ask for another packet of variable definition. */
13468 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13474 /* The "set/show range-stepping" show hook. */
13477 show_range_stepping (struct ui_file
*file
, int from_tty
,
13478 struct cmd_list_element
*c
,
13481 fprintf_filtered (file
,
13482 _("Debugger's willingness to use range stepping "
13483 "is %s.\n"), value
);
13486 /* The "set/show range-stepping" set hook. */
13489 set_range_stepping (char *ignore_args
, int from_tty
,
13490 struct cmd_list_element
*c
)
13492 struct remote_state
*rs
= get_remote_state ();
13494 /* Whene enabling, check whether range stepping is actually
13495 supported by the target, and warn if not. */
13496 if (use_range_stepping
)
13498 if (rs
->remote_desc
!= NULL
)
13500 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13501 remote_vcont_probe (rs
);
13503 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
13504 && rs
->supports_vCont
.r
)
13508 warning (_("Range stepping is not supported by the current target"));
13513 _initialize_remote (void)
13515 struct cmd_list_element
*cmd
;
13516 const char *cmd_name
;
13518 /* architecture specific data */
13519 remote_gdbarch_data_handle
=
13520 gdbarch_data_register_post_init (init_remote_state
);
13521 remote_g_packet_data_handle
=
13522 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
13525 = register_program_space_data_with_cleanup (NULL
,
13526 remote_pspace_data_cleanup
);
13528 /* Initialize the per-target state. At the moment there is only one
13529 of these, not one per target. Only one target is active at a
13531 remote_state
= new_remote_state ();
13533 init_remote_ops ();
13534 add_target (&remote_ops
);
13536 init_extended_remote_ops ();
13537 add_target (&extended_remote_ops
);
13539 /* Hook into new objfile notification. */
13540 observer_attach_new_objfile (remote_new_objfile
);
13541 /* We're no longer interested in notification events of an inferior
13543 observer_attach_inferior_exit (discard_pending_stop_replies
);
13546 init_remote_threadtests ();
13549 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
13550 /* set/show remote ... */
13552 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
13553 Remote protocol specific variables\n\
13554 Configure various remote-protocol specific variables such as\n\
13555 the packets being used"),
13556 &remote_set_cmdlist
, "set remote ",
13557 0 /* allow-unknown */, &setlist
);
13558 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
13559 Remote protocol specific variables\n\
13560 Configure various remote-protocol specific variables such as\n\
13561 the packets being used"),
13562 &remote_show_cmdlist
, "show remote ",
13563 0 /* allow-unknown */, &showlist
);
13565 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
13566 Compare section data on target to the exec file.\n\
13567 Argument is a single section name (default: all loaded sections).\n\
13568 To compare only read-only loaded sections, specify the -r option."),
13571 add_cmd ("packet", class_maintenance
, packet_command
, _("\
13572 Send an arbitrary packet to a remote target.\n\
13573 maintenance packet TEXT\n\
13574 If GDB is talking to an inferior via the GDB serial protocol, then\n\
13575 this command sends the string TEXT to the inferior, and displays the\n\
13576 response packet. GDB supplies the initial `$' character, and the\n\
13577 terminating `#' character and checksum."),
13580 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
13581 Set whether to send break if interrupted."), _("\
13582 Show whether to send break if interrupted."), _("\
13583 If set, a break, instead of a cntrl-c, is sent to the remote target."),
13584 set_remotebreak
, show_remotebreak
,
13585 &setlist
, &showlist
);
13586 cmd_name
= "remotebreak";
13587 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
13588 deprecate_cmd (cmd
, "set remote interrupt-sequence");
13589 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
13590 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
13591 deprecate_cmd (cmd
, "show remote interrupt-sequence");
13593 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
13594 interrupt_sequence_modes
, &interrupt_sequence_mode
,
13596 Set interrupt sequence to remote target."), _("\
13597 Show interrupt sequence to remote target."), _("\
13598 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
13599 NULL
, show_interrupt_sequence
,
13600 &remote_set_cmdlist
,
13601 &remote_show_cmdlist
);
13603 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
13604 &interrupt_on_connect
, _("\
13605 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13606 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
13607 If set, interrupt sequence is sent to remote target."),
13609 &remote_set_cmdlist
, &remote_show_cmdlist
);
13611 /* Install commands for configuring memory read/write packets. */
13613 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
13614 Set the maximum number of bytes per memory write packet (deprecated)."),
13616 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
13617 Show the maximum number of bytes per memory write packet (deprecated)."),
13619 add_cmd ("memory-write-packet-size", no_class
,
13620 set_memory_write_packet_size
, _("\
13621 Set the maximum number of bytes per memory-write packet.\n\
13622 Specify the number of bytes in a packet or 0 (zero) for the\n\
13623 default packet size. The actual limit is further reduced\n\
13624 dependent on the target. Specify ``fixed'' to disable the\n\
13625 further restriction and ``limit'' to enable that restriction."),
13626 &remote_set_cmdlist
);
13627 add_cmd ("memory-read-packet-size", no_class
,
13628 set_memory_read_packet_size
, _("\
13629 Set the maximum number of bytes per memory-read packet.\n\
13630 Specify the number of bytes in a packet or 0 (zero) for the\n\
13631 default packet size. The actual limit is further reduced\n\
13632 dependent on the target. Specify ``fixed'' to disable the\n\
13633 further restriction and ``limit'' to enable that restriction."),
13634 &remote_set_cmdlist
);
13635 add_cmd ("memory-write-packet-size", no_class
,
13636 show_memory_write_packet_size
,
13637 _("Show the maximum number of bytes per memory-write packet."),
13638 &remote_show_cmdlist
);
13639 add_cmd ("memory-read-packet-size", no_class
,
13640 show_memory_read_packet_size
,
13641 _("Show the maximum number of bytes per memory-read packet."),
13642 &remote_show_cmdlist
);
13644 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
13645 &remote_hw_watchpoint_limit
, _("\
13646 Set the maximum number of target hardware watchpoints."), _("\
13647 Show the maximum number of target hardware watchpoints."), _("\
13648 Specify a negative limit for unlimited."),
13649 NULL
, NULL
, /* FIXME: i18n: The maximum
13650 number of target hardware
13651 watchpoints is %s. */
13652 &remote_set_cmdlist
, &remote_show_cmdlist
);
13653 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
13654 &remote_hw_watchpoint_length_limit
, _("\
13655 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
13656 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
13657 Specify a negative limit for unlimited."),
13658 NULL
, NULL
, /* FIXME: i18n: The maximum
13659 length (in bytes) of a target
13660 hardware watchpoint is %s. */
13661 &remote_set_cmdlist
, &remote_show_cmdlist
);
13662 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
13663 &remote_hw_breakpoint_limit
, _("\
13664 Set the maximum number of target hardware breakpoints."), _("\
13665 Show the maximum number of target hardware breakpoints."), _("\
13666 Specify a negative limit for unlimited."),
13667 NULL
, NULL
, /* FIXME: i18n: The maximum
13668 number of target hardware
13669 breakpoints is %s. */
13670 &remote_set_cmdlist
, &remote_show_cmdlist
);
13672 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
13673 &remote_address_size
, _("\
13674 Set the maximum size of the address (in bits) in a memory packet."), _("\
13675 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
13677 NULL
, /* FIXME: i18n: */
13678 &setlist
, &showlist
);
13680 init_all_packet_configs ();
13682 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
13683 "X", "binary-download", 1);
13685 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
13686 "vCont", "verbose-resume", 0);
13688 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
13689 "QPassSignals", "pass-signals", 0);
13691 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QCatchSyscalls
],
13692 "QCatchSyscalls", "catch-syscalls", 0);
13694 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
13695 "QProgramSignals", "program-signals", 0);
13697 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
13698 "qSymbol", "symbol-lookup", 0);
13700 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
13701 "P", "set-register", 1);
13703 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
13704 "p", "fetch-register", 1);
13706 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
13707 "Z0", "software-breakpoint", 0);
13709 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
13710 "Z1", "hardware-breakpoint", 0);
13712 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
13713 "Z2", "write-watchpoint", 0);
13715 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
13716 "Z3", "read-watchpoint", 0);
13718 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
13719 "Z4", "access-watchpoint", 0);
13721 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
13722 "qXfer:auxv:read", "read-aux-vector", 0);
13724 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
13725 "qXfer:exec-file:read", "pid-to-exec-file", 0);
13727 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
13728 "qXfer:features:read", "target-features", 0);
13730 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
13731 "qXfer:libraries:read", "library-info", 0);
13733 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
13734 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
13736 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
13737 "qXfer:memory-map:read", "memory-map", 0);
13739 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
13740 "qXfer:spu:read", "read-spu-object", 0);
13742 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
13743 "qXfer:spu:write", "write-spu-object", 0);
13745 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
13746 "qXfer:osdata:read", "osdata", 0);
13748 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
13749 "qXfer:threads:read", "threads", 0);
13751 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
13752 "qXfer:siginfo:read", "read-siginfo-object", 0);
13754 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
13755 "qXfer:siginfo:write", "write-siginfo-object", 0);
13757 add_packet_config_cmd
13758 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
13759 "qXfer:traceframe-info:read", "traceframe-info", 0);
13761 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
13762 "qXfer:uib:read", "unwind-info-block", 0);
13764 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
13765 "qGetTLSAddr", "get-thread-local-storage-address",
13768 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
13769 "qGetTIBAddr", "get-thread-information-block-address",
13772 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
13773 "bc", "reverse-continue", 0);
13775 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
13776 "bs", "reverse-step", 0);
13778 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
13779 "qSupported", "supported-packets", 0);
13781 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
13782 "qSearch:memory", "search-memory", 0);
13784 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
13785 "qTStatus", "trace-status", 0);
13787 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
13788 "vFile:setfs", "hostio-setfs", 0);
13790 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
13791 "vFile:open", "hostio-open", 0);
13793 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
13794 "vFile:pread", "hostio-pread", 0);
13796 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
13797 "vFile:pwrite", "hostio-pwrite", 0);
13799 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
13800 "vFile:close", "hostio-close", 0);
13802 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
13803 "vFile:unlink", "hostio-unlink", 0);
13805 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
13806 "vFile:readlink", "hostio-readlink", 0);
13808 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
13809 "vFile:fstat", "hostio-fstat", 0);
13811 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
13812 "vAttach", "attach", 0);
13814 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
13817 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
13818 "QStartNoAckMode", "noack", 0);
13820 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
13821 "vKill", "kill", 0);
13823 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
13824 "qAttached", "query-attached", 0);
13826 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
13827 "ConditionalTracepoints",
13828 "conditional-tracepoints", 0);
13830 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
13831 "ConditionalBreakpoints",
13832 "conditional-breakpoints", 0);
13834 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
13835 "BreakpointCommands",
13836 "breakpoint-commands", 0);
13838 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
13839 "FastTracepoints", "fast-tracepoints", 0);
13841 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
13842 "TracepointSource", "TracepointSource", 0);
13844 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
13845 "QAllow", "allow", 0);
13847 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
13848 "StaticTracepoints", "static-tracepoints", 0);
13850 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
13851 "InstallInTrace", "install-in-trace", 0);
13853 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
13854 "qXfer:statictrace:read", "read-sdata-object", 0);
13856 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
13857 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
13859 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
13860 "QDisableRandomization", "disable-randomization", 0);
13862 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
13863 "QAgent", "agent", 0);
13865 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
13866 "QTBuffer:size", "trace-buffer-size", 0);
13868 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
13869 "Qbtrace:off", "disable-btrace", 0);
13871 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
13872 "Qbtrace:bts", "enable-btrace-bts", 0);
13874 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
13875 "Qbtrace:pt", "enable-btrace-pt", 0);
13877 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
13878 "qXfer:btrace", "read-btrace", 0);
13880 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
13881 "qXfer:btrace-conf", "read-btrace-conf", 0);
13883 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
13884 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
13886 add_packet_config_cmd (&remote_protocol_packets
[PACKET_multiprocess_feature
],
13887 "multiprocess-feature", "multiprocess-feature", 0);
13889 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
13890 "swbreak-feature", "swbreak-feature", 0);
13892 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
13893 "hwbreak-feature", "hwbreak-feature", 0);
13895 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
13896 "fork-event-feature", "fork-event-feature", 0);
13898 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
13899 "vfork-event-feature", "vfork-event-feature", 0);
13901 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
13902 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
13904 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vContSupported
],
13905 "vContSupported", "verbose-resume-supported", 0);
13907 add_packet_config_cmd (&remote_protocol_packets
[PACKET_exec_event_feature
],
13908 "exec-event-feature", "exec-event-feature", 0);
13910 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCtrlC
],
13911 "vCtrlC", "ctrl-c", 0);
13913 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QThreadEvents
],
13914 "QThreadEvents", "thread-events", 0);
13916 add_packet_config_cmd (&remote_protocol_packets
[PACKET_no_resumed
],
13917 "N stop reply", "no-resumed-stop-reply", 0);
13919 /* Assert that we've registered "set remote foo-packet" commands
13920 for all packet configs. */
13924 for (i
= 0; i
< PACKET_MAX
; i
++)
13926 /* Ideally all configs would have a command associated. Some
13927 still don't though. */
13932 case PACKET_QNonStop
:
13933 case PACKET_EnableDisableTracepoints_feature
:
13934 case PACKET_tracenz_feature
:
13935 case PACKET_DisconnectedTracing_feature
:
13936 case PACKET_augmented_libraries_svr4_read_feature
:
13938 /* Additions to this list need to be well justified:
13939 pre-existing packets are OK; new packets are not. */
13947 /* This catches both forgetting to add a config command, and
13948 forgetting to remove a packet from the exception list. */
13949 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
13953 /* Keep the old ``set remote Z-packet ...'' working. Each individual
13954 Z sub-packet has its own set and show commands, but users may
13955 have sets to this variable in their .gdbinit files (or in their
13957 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
13958 &remote_Z_packet_detect
, _("\
13959 Set use of remote protocol `Z' packets"), _("\
13960 Show use of remote protocol `Z' packets "), _("\
13961 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
13963 set_remote_protocol_Z_packet_cmd
,
13964 show_remote_protocol_Z_packet_cmd
,
13965 /* FIXME: i18n: Use of remote protocol
13966 `Z' packets is %s. */
13967 &remote_set_cmdlist
, &remote_show_cmdlist
);
13969 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
13970 Manipulate files on the remote system\n\
13971 Transfer files to and from the remote target system."),
13972 &remote_cmdlist
, "remote ",
13973 0 /* allow-unknown */, &cmdlist
);
13975 add_cmd ("put", class_files
, remote_put_command
,
13976 _("Copy a local file to the remote system."),
13979 add_cmd ("get", class_files
, remote_get_command
,
13980 _("Copy a remote file to the local system."),
13983 add_cmd ("delete", class_files
, remote_delete_command
,
13984 _("Delete a remote file."),
13987 add_setshow_string_noescape_cmd ("exec-file", class_files
,
13988 &remote_exec_file_var
, _("\
13989 Set the remote pathname for \"run\""), _("\
13990 Show the remote pathname for \"run\""), NULL
,
13991 set_remote_exec_file
,
13992 show_remote_exec_file
,
13993 &remote_set_cmdlist
,
13994 &remote_show_cmdlist
);
13996 add_setshow_boolean_cmd ("range-stepping", class_run
,
13997 &use_range_stepping
, _("\
13998 Enable or disable range stepping."), _("\
13999 Show whether target-assisted range stepping is enabled."), _("\
14000 If on, and the target supports it, when stepping a source line, GDB\n\
14001 tells the target to step the corresponding range of addresses itself instead\n\
14002 of issuing multiple single-steps. This speeds up source level\n\
14003 stepping. If off, GDB always issues single-steps, even if range\n\
14004 stepping is supported by the target. The default is on."),
14005 set_range_stepping
,
14006 show_range_stepping
,
14010 /* Eventually initialize fileio. See fileio.c */
14011 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
14013 /* Take advantage of the fact that the TID field is not used, to tag
14014 special ptids with it set to != 0. */
14015 magic_null_ptid
= ptid_build (42000, -1, 1);
14016 not_sent_ptid
= ptid_build (42000, -2, 1);
14017 any_thread_ptid
= ptid_build (42000, 0, 1);
14019 target_buf_size
= 2048;
14020 target_buf
= (char *) xmalloc (target_buf_size
);