1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2015 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 "event-loop.h"
51 #include "event-top.h"
57 #include "gdbcore.h" /* for exec_bfd */
59 #include "remote-fileio.h"
60 #include "gdb/fileio.h"
62 #include "xml-support.h"
64 #include "memory-map.h"
66 #include "tracepoint.h"
72 /* Temp hacks for tracepoint encoding migration. */
73 static char *target_buf;
74 static long target_buf_size;
76 /* The size to align memory write packets, when practical. The protocol
77 does not guarantee any alignment, and gdb will generate short
78 writes and unaligned writes, but even as a best-effort attempt this
79 can improve bulk transfers. For instance, if a write is misaligned
80 relative to the target's data bus, the stub may need to make an extra
81 round trip fetching data from the target. This doesn't make a
82 huge difference, but it's easy to do, so we try to be helpful.
84 The alignment chosen is arbitrary; usually data bus width is
85 important here, not the possibly larger cache line size. */
86 enum { REMOTE_ALIGN_WRITES = 16 };
88 /* Prototypes for local functions. */
89 static void async_cleanup_sigint_signal_handler (void *dummy);
90 static int getpkt_sane (char **buf, long *sizeof_buf, int forever);
91 static int getpkt_or_notif_sane (char **buf, long *sizeof_buf,
92 int forever, int *is_notif);
94 static void async_handle_remote_sigint (int);
95 static void async_handle_remote_sigint_twice (int);
97 static void remote_files_info (struct target_ops *ignore);
99 static void remote_prepare_to_store (struct target_ops *self,
100 struct regcache *regcache);
102 static void remote_open_1 (const char *, int, struct target_ops *,
105 static void remote_close (struct target_ops *self);
109 static int remote_vkill (int pid, struct remote_state *rs);
111 static void remote_mourn (struct target_ops *ops);
113 static void extended_remote_restart (void);
115 static void extended_remote_mourn (struct target_ops *);
117 static void remote_send (char **buf, long *sizeof_buf_p);
119 static int readchar (int timeout);
121 static void remote_serial_write (const char *str, int len);
123 static void remote_kill (struct target_ops *ops);
125 static int remote_can_async_p (struct target_ops *);
127 static int remote_is_async_p (struct target_ops *);
129 static void remote_async (struct target_ops *ops, int enable);
131 static void sync_remote_interrupt_twice (int signo);
133 static void interrupt_query (void);
135 static void set_general_thread (struct ptid ptid);
136 static void set_continue_thread (struct ptid ptid);
138 static void get_offsets (void);
140 static void skip_frame (void);
142 static long read_frame (char **buf_p, long *sizeof_buf);
144 static int hexnumlen (ULONGEST num);
146 static void init_remote_ops (void);
148 static void init_extended_remote_ops (void);
150 static void remote_stop (struct target_ops *self, ptid_t);
152 static int stubhex (int ch);
154 static int hexnumstr (char *, ULONGEST);
156 static int hexnumnstr (char *, ULONGEST, int);
158 static CORE_ADDR remote_address_masked (CORE_ADDR);
160 static void print_packet (const char *);
162 static void compare_sections_command (char *, int);
164 static void packet_command (char *, int);
166 static int stub_unpack_int (char *buff, int fieldlength);
168 static ptid_t remote_current_thread (ptid_t oldptid);
170 static int putpkt_binary (const char *buf, int cnt);
172 static void check_binary_download (CORE_ADDR addr);
174 struct packet_config;
176 static void show_packet_config_cmd (struct packet_config *config);
178 static void show_remote_protocol_packet_cmd (struct ui_file *file,
180 struct cmd_list_element *c,
183 static char *write_ptid (char *buf, const char *endbuf, ptid_t ptid);
184 static ptid_t read_ptid (char *buf, char **obuf);
186 static void remote_set_permissions (struct target_ops *self);
188 static int remote_get_trace_status (struct target_ops *self,
189 struct trace_status *ts);
191 static int remote_upload_tracepoints (struct target_ops *self,
192 struct uploaded_tp **utpp);
194 static int remote_upload_trace_state_variables (struct target_ops *self,
195 struct uploaded_tsv **utsvp);
197 static void remote_query_supported (void);
199 static void remote_check_symbols (void);
201 void _initialize_remote (void);
204 static void stop_reply_xfree (struct stop_reply *);
205 static void remote_parse_stop_reply (char *, struct stop_reply *);
206 static void push_stop_reply (struct stop_reply *);
207 static void discard_pending_stop_replies_in_queue (struct remote_state *);
208 static int peek_stop_reply (ptid_t ptid);
210 struct threads_listing_context;
211 static void remove_new_fork_children (struct threads_listing_context *);
213 static void remote_async_inferior_event_handler (gdb_client_data);
215 static void remote_terminal_ours (struct target_ops *self);
217 static int remote_read_description_p (struct target_ops *target);
219 static void remote_console_output (char *msg);
221 static int remote_supports_cond_breakpoints (struct target_ops *self);
223 static int remote_can_run_breakpoint_commands (struct target_ops *self);
225 static void remote_btrace_reset (void);
229 static struct cmd_list_element *remote_cmdlist;
231 /* For "set remote" and "show remote". */
233 static struct cmd_list_element *remote_set_cmdlist;
234 static struct cmd_list_element *remote_show_cmdlist;
236 /* Stub vCont actions support.
238 Each field is a boolean flag indicating whether the stub reports
239 support for the corresponding action. */
241 struct vCont_action_support
250 /* Controls whether GDB is willing to use range stepping. */
252 static int use_range_stepping = 1;
254 #define OPAQUETHREADBYTES 8
256 /* a 64 bit opaque identifier */
257 typedef unsigned char threadref[OPAQUETHREADBYTES];
259 /* About this many threadisds fit in a packet. */
261 #define MAXTHREADLISTRESULTS 32
263 /* Description of the remote protocol state for the currently
264 connected target. This is per-target state, and independent of the
265 selected architecture. */
269 /* A buffer to use for incoming packets, and its current size. The
270 buffer is grown dynamically for larger incoming packets.
271 Outgoing packets may also be constructed in this buffer.
272 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
273 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
278 /* True if we're going through initial connection setup (finding out
279 about the remote side's threads, relocating symbols, etc.). */
282 /* If we negotiated packet size explicitly (and thus can bypass
283 heuristics for the largest packet size that will not overflow
284 a buffer in the stub), this will be set to that packet size.
285 Otherwise zero, meaning to use the guessed size. */
286 long explicit_packet_size;
288 /* remote_wait is normally called when the target is running and
289 waits for a stop reply packet. But sometimes we need to call it
290 when the target is already stopped. We can send a "?" packet
291 and have remote_wait read the response. Or, if we already have
292 the response, we can stash it in BUF and tell remote_wait to
293 skip calling getpkt. This flag is set when BUF contains a
294 stop reply packet and the target is not waiting. */
295 int cached_wait_status;
297 /* True, if in no ack mode. That is, neither GDB nor the stub will
298 expect acks from each other. The connection is assumed to be
302 /* True if we're connected in extended remote mode. */
305 /* True if we resumed the target and we're waiting for the target to
306 stop. In the mean time, we can't start another command/query.
307 The remote server wouldn't be ready to process it, so we'd
308 timeout waiting for a reply that would never come and eventually
309 we'd close the connection. This can happen in asynchronous mode
310 because we allow GDB commands while the target is running. */
311 int waiting_for_stop_reply;
313 /* The status of the stub support for the various vCont actions. */
314 struct vCont_action_support supports_vCont;
316 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
317 responded to that. */
320 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
321 remote_open knows that we don't have a file open when the program
323 struct serial *remote_desc;
325 /* These are the threads which we last sent to the remote system. The
326 TID member will be -1 for all or -2 for not sent yet. */
327 ptid_t general_thread;
328 ptid_t continue_thread;
330 /* This is the traceframe which we last selected on the remote system.
331 It will be -1 if no traceframe is selected. */
332 int remote_traceframe_number;
334 char *last_pass_packet;
336 /* The last QProgramSignals packet sent to the target. We bypass
337 sending a new program signals list down to the target if the new
338 packet is exactly the same as the last we sent. IOW, we only let
339 the target know about program signals list changes. */
340 char *last_program_signals_packet;
342 enum gdb_signal last_sent_signal;
346 char *finished_object;
347 char *finished_annex;
348 ULONGEST finished_offset;
350 /* Should we try the 'ThreadInfo' query packet?
352 This variable (NOT available to the user: auto-detect only!)
353 determines whether GDB will use the new, simpler "ThreadInfo"
354 query or the older, more complex syntax for thread queries.
355 This is an auto-detect variable (set to true at each connect,
356 and set to false when the target fails to recognize it). */
357 int use_threadinfo_query;
358 int use_threadextra_query;
360 /* This is set to the data address of the access causing the target
361 to stop for a watchpoint. */
362 CORE_ADDR remote_watch_data_address;
364 /* Whether the target stopped for a breakpoint/watchpoint. */
365 enum target_stop_reason stop_reason;
367 threadref echo_nextthread;
368 threadref nextthread;
369 threadref resultthreadlist[MAXTHREADLISTRESULTS];
371 /* The state of remote notification. */
372 struct remote_notif_state *notif_state;
374 /* The branch trace configuration. */
375 struct btrace_config btrace_config;
378 /* Private data that we'll store in (struct thread_info)->private. */
379 struct private_thread_info
386 free_private_thread_info (struct private_thread_info *info)
392 /* This data could be associated with a target, but we do not always
393 have access to the current target when we need it, so for now it is
394 static. This will be fine for as long as only one target is in use
396 static struct remote_state *remote_state;
398 static struct remote_state *
399 get_remote_state_raw (void)
404 /* Allocate a new struct remote_state with xmalloc, initialize it, and
407 static struct remote_state *
408 new_remote_state (void)
410 struct remote_state *result = XCNEW (struct remote_state);
412 /* The default buffer size is unimportant; it will be expanded
413 whenever a larger buffer is needed. */
414 result->buf_size = 400;
415 result->buf = xmalloc (result->buf_size);
416 result->remote_traceframe_number = -1;
417 result->last_sent_signal = GDB_SIGNAL_0;
422 /* Description of the remote protocol for a given architecture. */
426 long offset; /* Offset into G packet. */
427 long regnum; /* GDB's internal register number. */
428 LONGEST pnum; /* Remote protocol register number. */
429 int in_g_packet; /* Always part of G packet. */
430 /* long size in bytes; == register_size (target_gdbarch (), regnum);
432 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
436 struct remote_arch_state
438 /* Description of the remote protocol registers. */
439 long sizeof_g_packet;
441 /* Description of the remote protocol registers indexed by REGNUM
442 (making an array gdbarch_num_regs in size). */
443 struct packet_reg *regs;
445 /* This is the size (in chars) of the first response to the ``g''
446 packet. It is used as a heuristic when determining the maximum
447 size of memory-read and memory-write packets. A target will
448 typically only reserve a buffer large enough to hold the ``g''
449 packet. The size does not include packet overhead (headers and
451 long actual_register_packet_size;
453 /* This is the maximum size (in chars) of a non read/write packet.
454 It is also used as a cap on the size of read/write packets. */
455 long remote_packet_size;
458 /* Utility: generate error from an incoming stub packet. */
460 trace_error (char *buf)
463 return; /* not an error msg */
466 case '1': /* malformed packet error */
467 if (*++buf == '0') /* general case: */
468 error (_("remote.c: error in outgoing packet."));
470 error (_("remote.c: error in outgoing packet at field #%ld."),
471 strtol (buf, NULL, 16));
473 error (_("Target returns error code '%s'."), buf);
477 /* Utility: wait for reply from stub, while accepting "O" packets. */
479 remote_get_noisy_reply (char **buf_p,
482 do /* Loop on reply from remote stub. */
486 QUIT; /* Allow user to bail out with ^C. */
487 getpkt (buf_p, sizeof_buf, 0);
491 else if (startswith (buf, "qRelocInsn:"))
494 CORE_ADDR from, to, org_to;
496 int adjusted_size = 0;
499 p = buf + strlen ("qRelocInsn:");
500 pp = unpack_varlen_hex (p, &ul);
502 error (_("invalid qRelocInsn packet: %s"), buf);
506 unpack_varlen_hex (p, &ul);
513 gdbarch_relocate_instruction (target_gdbarch (), &to, from);
516 CATCH (ex, RETURN_MASK_ALL)
518 if (ex.error == MEMORY_ERROR)
520 /* Propagate memory errors silently back to the
521 target. The stub may have limited the range of
522 addresses we can write to, for example. */
526 /* Something unexpectedly bad happened. Be verbose
527 so we can tell what, and propagate the error back
528 to the stub, so it doesn't get stuck waiting for
530 exception_fprintf (gdb_stderr, ex,
531 _("warning: relocating instruction: "));
539 adjusted_size = to - org_to;
541 xsnprintf (buf, *sizeof_buf, "qRelocInsn:%x", adjusted_size);
545 else if (buf[0] == 'O' && buf[1] != 'K')
546 remote_console_output (buf + 1); /* 'O' message from stub */
548 return buf; /* Here's the actual reply. */
553 /* Handle for retreving the remote protocol data from gdbarch. */
554 static struct gdbarch_data *remote_gdbarch_data_handle;
556 static struct remote_arch_state *
557 get_remote_arch_state (void)
559 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle);
562 /* Fetch the global remote target state. */
564 static struct remote_state *
565 get_remote_state (void)
567 /* Make sure that the remote architecture state has been
568 initialized, because doing so might reallocate rs->buf. Any
569 function which calls getpkt also needs to be mindful of changes
570 to rs->buf, but this call limits the number of places which run
572 get_remote_arch_state ();
574 return get_remote_state_raw ();
578 compare_pnums (const void *lhs_, const void *rhs_)
580 const struct packet_reg * const *lhs = lhs_;
581 const struct packet_reg * const *rhs = rhs_;
583 if ((*lhs)->pnum < (*rhs)->pnum)
585 else if ((*lhs)->pnum == (*rhs)->pnum)
592 map_regcache_remote_table (struct gdbarch *gdbarch, struct packet_reg *regs)
594 int regnum, num_remote_regs, offset;
595 struct packet_reg **remote_regs;
597 for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
599 struct packet_reg *r = ®s[regnum];
601 if (register_size (gdbarch, regnum) == 0)
602 /* Do not try to fetch zero-sized (placeholder) registers. */
605 r->pnum = gdbarch_remote_register_number (gdbarch, regnum);
610 /* Define the g/G packet format as the contents of each register
611 with a remote protocol number, in order of ascending protocol
614 remote_regs = alloca (gdbarch_num_regs (gdbarch)
615 * sizeof (struct packet_reg *));
616 for (num_remote_regs = 0, regnum = 0;
617 regnum < gdbarch_num_regs (gdbarch);
619 if (regs[regnum].pnum != -1)
620 remote_regs[num_remote_regs++] = ®s[regnum];
622 qsort (remote_regs, num_remote_regs, sizeof (struct packet_reg *),
625 for (regnum = 0, offset = 0; regnum < num_remote_regs; regnum++)
627 remote_regs[regnum]->in_g_packet = 1;
628 remote_regs[regnum]->offset = offset;
629 offset += register_size (gdbarch, remote_regs[regnum]->regnum);
635 /* Given the architecture described by GDBARCH, return the remote
636 protocol register's number and the register's offset in the g/G
637 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
638 If the target does not have a mapping for REGNUM, return false,
639 otherwise, return true. */
642 remote_register_number_and_offset (struct gdbarch *gdbarch, int regnum,
643 int *pnum, int *poffset)
646 struct packet_reg *regs;
647 struct cleanup *old_chain;
649 gdb_assert (regnum < gdbarch_num_regs (gdbarch));
651 regs = xcalloc (gdbarch_num_regs (gdbarch), sizeof (struct packet_reg));
652 old_chain = make_cleanup (xfree, regs);
654 sizeof_g_packet = map_regcache_remote_table (gdbarch, regs);
656 *pnum = regs[regnum].pnum;
657 *poffset = regs[regnum].offset;
659 do_cleanups (old_chain);
665 init_remote_state (struct gdbarch *gdbarch)
667 struct remote_state *rs = get_remote_state_raw ();
668 struct remote_arch_state *rsa;
670 rsa = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct remote_arch_state);
672 /* Use the architecture to build a regnum<->pnum table, which will be
673 1:1 unless a feature set specifies otherwise. */
674 rsa->regs = GDBARCH_OBSTACK_CALLOC (gdbarch,
675 gdbarch_num_regs (gdbarch),
678 /* Record the maximum possible size of the g packet - it may turn out
680 rsa->sizeof_g_packet = map_regcache_remote_table (gdbarch, rsa->regs);
682 /* Default maximum number of characters in a packet body. Many
683 remote stubs have a hardwired buffer size of 400 bytes
684 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
685 as the maximum packet-size to ensure that the packet and an extra
686 NUL character can always fit in the buffer. This stops GDB
687 trashing stubs that try to squeeze an extra NUL into what is
688 already a full buffer (As of 1999-12-04 that was most stubs). */
689 rsa->remote_packet_size = 400 - 1;
691 /* This one is filled in when a ``g'' packet is received. */
692 rsa->actual_register_packet_size = 0;
694 /* Should rsa->sizeof_g_packet needs more space than the
695 default, adjust the size accordingly. Remember that each byte is
696 encoded as two characters. 32 is the overhead for the packet
697 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
698 (``$NN:G...#NN'') is a better guess, the below has been padded a
700 if (rsa->sizeof_g_packet > ((rsa->remote_packet_size - 32) / 2))
701 rsa->remote_packet_size = (rsa->sizeof_g_packet * 2 + 32);
703 /* Make sure that the packet buffer is plenty big enough for
704 this architecture. */
705 if (rs->buf_size < rsa->remote_packet_size)
707 rs->buf_size = 2 * rsa->remote_packet_size;
708 rs->buf = xrealloc (rs->buf, rs->buf_size);
714 /* Return the current allowed size of a remote packet. This is
715 inferred from the current architecture, and should be used to
716 limit the length of outgoing packets. */
718 get_remote_packet_size (void)
720 struct remote_state *rs = get_remote_state ();
721 struct remote_arch_state *rsa = get_remote_arch_state ();
723 if (rs->explicit_packet_size)
724 return rs->explicit_packet_size;
726 return rsa->remote_packet_size;
729 static struct packet_reg *
730 packet_reg_from_regnum (struct remote_arch_state *rsa, long regnum)
732 if (regnum < 0 && regnum >= gdbarch_num_regs (target_gdbarch ()))
736 struct packet_reg *r = &rsa->regs[regnum];
738 gdb_assert (r->regnum == regnum);
743 static struct packet_reg *
744 packet_reg_from_pnum (struct remote_arch_state *rsa, LONGEST pnum)
748 for (i = 0; i < gdbarch_num_regs (target_gdbarch ()); i++)
750 struct packet_reg *r = &rsa->regs[i];
758 static struct target_ops remote_ops;
760 static struct target_ops extended_remote_ops;
762 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
763 ``forever'' still use the normal timeout mechanism. This is
764 currently used by the ASYNC code to guarentee that target reads
765 during the initial connect always time-out. Once getpkt has been
766 modified to return a timeout indication and, in turn
767 remote_wait()/wait_for_inferior() have gained a timeout parameter
769 static int wait_forever_enabled_p = 1;
771 /* Allow the user to specify what sequence to send to the remote
772 when he requests a program interruption: Although ^C is usually
773 what remote systems expect (this is the default, here), it is
774 sometimes preferable to send a break. On other systems such
775 as the Linux kernel, a break followed by g, which is Magic SysRq g
776 is required in order to interrupt the execution. */
777 const char interrupt_sequence_control_c[] = "Ctrl-C";
778 const char interrupt_sequence_break[] = "BREAK";
779 const char interrupt_sequence_break_g[] = "BREAK-g";
780 static const char *const interrupt_sequence_modes[] =
782 interrupt_sequence_control_c,
783 interrupt_sequence_break,
784 interrupt_sequence_break_g,
787 static const char *interrupt_sequence_mode = interrupt_sequence_control_c;
790 show_interrupt_sequence (struct ui_file *file, int from_tty,
791 struct cmd_list_element *c,
794 if (interrupt_sequence_mode == interrupt_sequence_control_c)
795 fprintf_filtered (file,
796 _("Send the ASCII ETX character (Ctrl-c) "
797 "to the remote target to interrupt the "
798 "execution of the program.\n"));
799 else if (interrupt_sequence_mode == interrupt_sequence_break)
800 fprintf_filtered (file,
801 _("send a break signal to the remote target "
802 "to interrupt the execution of the program.\n"));
803 else if (interrupt_sequence_mode == interrupt_sequence_break_g)
804 fprintf_filtered (file,
805 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
806 "the remote target to interrupt the execution "
807 "of Linux kernel.\n"));
809 internal_error (__FILE__, __LINE__,
810 _("Invalid value for interrupt_sequence_mode: %s."),
811 interrupt_sequence_mode);
814 /* This boolean variable specifies whether interrupt_sequence is sent
815 to the remote target when gdb connects to it.
816 This is mostly needed when you debug the Linux kernel: The Linux kernel
817 expects BREAK g which is Magic SysRq g for connecting gdb. */
818 static int interrupt_on_connect = 0;
820 /* This variable is used to implement the "set/show remotebreak" commands.
821 Since these commands are now deprecated in favor of "set/show remote
822 interrupt-sequence", it no longer has any effect on the code. */
823 static int remote_break;
826 set_remotebreak (char *args, int from_tty, struct cmd_list_element *c)
829 interrupt_sequence_mode = interrupt_sequence_break;
831 interrupt_sequence_mode = interrupt_sequence_control_c;
835 show_remotebreak (struct ui_file *file, int from_tty,
836 struct cmd_list_element *c,
841 /* This variable sets the number of bits in an address that are to be
842 sent in a memory ("M" or "m") packet. Normally, after stripping
843 leading zeros, the entire address would be sent. This variable
844 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
845 initial implementation of remote.c restricted the address sent in
846 memory packets to ``host::sizeof long'' bytes - (typically 32
847 bits). Consequently, for 64 bit targets, the upper 32 bits of an
848 address was never sent. Since fixing this bug may cause a break in
849 some remote targets this variable is principly provided to
850 facilitate backward compatibility. */
852 static unsigned int remote_address_size;
854 /* Temporary to track who currently owns the terminal. See
855 remote_terminal_* for more details. */
857 static int remote_async_terminal_ours_p;
859 /* The executable file to use for "run" on the remote side. */
861 static char *remote_exec_file = "";
864 /* User configurable variables for the number of characters in a
865 memory read/write packet. MIN (rsa->remote_packet_size,
866 rsa->sizeof_g_packet) is the default. Some targets need smaller
867 values (fifo overruns, et.al.) and some users need larger values
868 (speed up transfers). The variables ``preferred_*'' (the user
869 request), ``current_*'' (what was actually set) and ``forced_*''
870 (Positive - a soft limit, negative - a hard limit). */
872 struct memory_packet_config
879 /* Compute the current size of a read/write packet. Since this makes
880 use of ``actual_register_packet_size'' the computation is dynamic. */
883 get_memory_packet_size (struct memory_packet_config *config)
885 struct remote_state *rs = get_remote_state ();
886 struct remote_arch_state *rsa = get_remote_arch_state ();
888 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
889 law?) that some hosts don't cope very well with large alloca()
890 calls. Eventually the alloca() code will be replaced by calls to
891 xmalloc() and make_cleanups() allowing this restriction to either
892 be lifted or removed. */
893 #ifndef MAX_REMOTE_PACKET_SIZE
894 #define MAX_REMOTE_PACKET_SIZE 16384
896 /* NOTE: 20 ensures we can write at least one byte. */
897 #ifndef MIN_REMOTE_PACKET_SIZE
898 #define MIN_REMOTE_PACKET_SIZE 20
903 if (config->size <= 0)
904 what_they_get = MAX_REMOTE_PACKET_SIZE;
906 what_they_get = config->size;
910 what_they_get = get_remote_packet_size ();
911 /* Limit the packet to the size specified by the user. */
913 && what_they_get > config->size)
914 what_they_get = config->size;
916 /* Limit it to the size of the targets ``g'' response unless we have
917 permission from the stub to use a larger packet size. */
918 if (rs->explicit_packet_size == 0
919 && rsa->actual_register_packet_size > 0
920 && what_they_get > rsa->actual_register_packet_size)
921 what_they_get = rsa->actual_register_packet_size;
923 if (what_they_get > MAX_REMOTE_PACKET_SIZE)
924 what_they_get = MAX_REMOTE_PACKET_SIZE;
925 if (what_they_get < MIN_REMOTE_PACKET_SIZE)
926 what_they_get = MIN_REMOTE_PACKET_SIZE;
928 /* Make sure there is room in the global buffer for this packet
929 (including its trailing NUL byte). */
930 if (rs->buf_size < what_they_get + 1)
932 rs->buf_size = 2 * what_they_get;
933 rs->buf = xrealloc (rs->buf, 2 * what_they_get);
936 return what_they_get;
939 /* Update the size of a read/write packet. If they user wants
940 something really big then do a sanity check. */
943 set_memory_packet_size (char *args, struct memory_packet_config *config)
945 int fixed_p = config->fixed_p;
946 long size = config->size;
949 error (_("Argument required (integer, `fixed' or `limited')."));
950 else if (strcmp (args, "hard") == 0
951 || strcmp (args, "fixed") == 0)
953 else if (strcmp (args, "soft") == 0
954 || strcmp (args, "limit") == 0)
960 size = strtoul (args, &end, 0);
962 error (_("Invalid %s (bad syntax)."), config->name);
964 /* Instead of explicitly capping the size of a packet to
965 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
966 instead allowed to set the size to something arbitrarily
968 if (size > MAX_REMOTE_PACKET_SIZE)
969 error (_("Invalid %s (too large)."), config->name);
973 if (fixed_p && !config->fixed_p)
975 if (! query (_("The target may not be able to correctly handle a %s\n"
976 "of %ld bytes. Change the packet size? "),
978 error (_("Packet size not changed."));
980 /* Update the config. */
981 config->fixed_p = fixed_p;
986 show_memory_packet_size (struct memory_packet_config *config)
988 printf_filtered (_("The %s is %ld. "), config->name, config->size);
990 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
991 get_memory_packet_size (config));
993 printf_filtered (_("Packets are limited to %ld bytes.\n"),
994 get_memory_packet_size (config));
997 static struct memory_packet_config memory_write_packet_config =
999 "memory-write-packet-size",
1003 set_memory_write_packet_size (char *args, int from_tty)
1005 set_memory_packet_size (args, &memory_write_packet_config);
1009 show_memory_write_packet_size (char *args, int from_tty)
1011 show_memory_packet_size (&memory_write_packet_config);
1015 get_memory_write_packet_size (void)
1017 return get_memory_packet_size (&memory_write_packet_config);
1020 static struct memory_packet_config memory_read_packet_config =
1022 "memory-read-packet-size",
1026 set_memory_read_packet_size (char *args, int from_tty)
1028 set_memory_packet_size (args, &memory_read_packet_config);
1032 show_memory_read_packet_size (char *args, int from_tty)
1034 show_memory_packet_size (&memory_read_packet_config);
1038 get_memory_read_packet_size (void)
1040 long size = get_memory_packet_size (&memory_read_packet_config);
1042 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1043 extra buffer size argument before the memory read size can be
1044 increased beyond this. */
1045 if (size > get_remote_packet_size ())
1046 size = get_remote_packet_size ();
1051 /* Generic configuration support for packets the stub optionally
1052 supports. Allows the user to specify the use of the packet as well
1053 as allowing GDB to auto-detect support in the remote stub. */
1057 PACKET_SUPPORT_UNKNOWN = 0,
1062 struct packet_config
1067 /* If auto, GDB auto-detects support for this packet or feature,
1068 either through qSupported, or by trying the packet and looking
1069 at the response. If true, GDB assumes the target supports this
1070 packet. If false, the packet is disabled. Configs that don't
1071 have an associated command always have this set to auto. */
1072 enum auto_boolean detect;
1074 /* Does the target support this packet? */
1075 enum packet_support support;
1078 /* Analyze a packet's return value and update the packet config
1088 static enum packet_support packet_config_support (struct packet_config *config);
1089 static enum packet_support packet_support (int packet);
1092 show_packet_config_cmd (struct packet_config *config)
1094 char *support = "internal-error";
1096 switch (packet_config_support (config))
1099 support = "enabled";
1101 case PACKET_DISABLE:
1102 support = "disabled";
1104 case PACKET_SUPPORT_UNKNOWN:
1105 support = "unknown";
1108 switch (config->detect)
1110 case AUTO_BOOLEAN_AUTO:
1111 printf_filtered (_("Support for the `%s' packet "
1112 "is auto-detected, currently %s.\n"),
1113 config->name, support);
1115 case AUTO_BOOLEAN_TRUE:
1116 case AUTO_BOOLEAN_FALSE:
1117 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1118 config->name, support);
1124 add_packet_config_cmd (struct packet_config *config, const char *name,
1125 const char *title, int legacy)
1131 config->name = name;
1132 config->title = title;
1133 set_doc = xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1135 show_doc = xstrprintf ("Show current use of remote "
1136 "protocol `%s' (%s) packet",
1138 /* set/show TITLE-packet {auto,on,off} */
1139 cmd_name = xstrprintf ("%s-packet", title);
1140 add_setshow_auto_boolean_cmd (cmd_name, class_obscure,
1141 &config->detect, set_doc,
1142 show_doc, NULL, /* help_doc */
1144 show_remote_protocol_packet_cmd,
1145 &remote_set_cmdlist, &remote_show_cmdlist);
1146 /* The command code copies the documentation strings. */
1149 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1154 legacy_name = xstrprintf ("%s-packet", name);
1155 add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
1156 &remote_set_cmdlist);
1157 add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
1158 &remote_show_cmdlist);
1162 static enum packet_result
1163 packet_check_result (const char *buf)
1167 /* The stub recognized the packet request. Check that the
1168 operation succeeded. */
1170 && isxdigit (buf[1]) && isxdigit (buf[2])
1172 /* "Enn" - definitly an error. */
1173 return PACKET_ERROR;
1175 /* Always treat "E." as an error. This will be used for
1176 more verbose error messages, such as E.memtypes. */
1177 if (buf[0] == 'E' && buf[1] == '.')
1178 return PACKET_ERROR;
1180 /* The packet may or may not be OK. Just assume it is. */
1184 /* The stub does not support the packet. */
1185 return PACKET_UNKNOWN;
1188 static enum packet_result
1189 packet_ok (const char *buf, struct packet_config *config)
1191 enum packet_result result;
1193 if (config->detect != AUTO_BOOLEAN_TRUE
1194 && config->support == PACKET_DISABLE)
1195 internal_error (__FILE__, __LINE__,
1196 _("packet_ok: attempt to use a disabled packet"));
1198 result = packet_check_result (buf);
1203 /* The stub recognized the packet request. */
1204 if (config->support == PACKET_SUPPORT_UNKNOWN)
1207 fprintf_unfiltered (gdb_stdlog,
1208 "Packet %s (%s) is supported\n",
1209 config->name, config->title);
1210 config->support = PACKET_ENABLE;
1213 case PACKET_UNKNOWN:
1214 /* The stub does not support the packet. */
1215 if (config->detect == AUTO_BOOLEAN_AUTO
1216 && config->support == PACKET_ENABLE)
1218 /* If the stub previously indicated that the packet was
1219 supported then there is a protocol error. */
1220 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1221 config->name, config->title);
1223 else if (config->detect == AUTO_BOOLEAN_TRUE)
1225 /* The user set it wrong. */
1226 error (_("Enabled packet %s (%s) not recognized by stub"),
1227 config->name, config->title);
1231 fprintf_unfiltered (gdb_stdlog,
1232 "Packet %s (%s) is NOT supported\n",
1233 config->name, config->title);
1234 config->support = PACKET_DISABLE;
1254 PACKET_vFile_pwrite,
1256 PACKET_vFile_unlink,
1257 PACKET_vFile_readlink,
1260 PACKET_qXfer_features,
1261 PACKET_qXfer_exec_file,
1262 PACKET_qXfer_libraries,
1263 PACKET_qXfer_libraries_svr4,
1264 PACKET_qXfer_memory_map,
1265 PACKET_qXfer_spu_read,
1266 PACKET_qXfer_spu_write,
1267 PACKET_qXfer_osdata,
1268 PACKET_qXfer_threads,
1269 PACKET_qXfer_statictrace_read,
1270 PACKET_qXfer_traceframe_info,
1276 PACKET_QPassSignals,
1277 PACKET_QProgramSignals,
1279 PACKET_qSearch_memory,
1282 PACKET_QStartNoAckMode,
1284 PACKET_qXfer_siginfo_read,
1285 PACKET_qXfer_siginfo_write,
1288 /* Support for conditional tracepoints. */
1289 PACKET_ConditionalTracepoints,
1291 /* Support for target-side breakpoint conditions. */
1292 PACKET_ConditionalBreakpoints,
1294 /* Support for target-side breakpoint commands. */
1295 PACKET_BreakpointCommands,
1297 /* Support for fast tracepoints. */
1298 PACKET_FastTracepoints,
1300 /* Support for static tracepoints. */
1301 PACKET_StaticTracepoints,
1303 /* Support for installing tracepoints while a trace experiment is
1305 PACKET_InstallInTrace,
1309 PACKET_TracepointSource,
1312 PACKET_QDisableRandomization,
1314 PACKET_QTBuffer_size,
1317 PACKET_qXfer_btrace,
1319 /* Support for the QNonStop packet. */
1322 /* Support for multi-process extensions. */
1323 PACKET_multiprocess_feature,
1325 /* Support for enabling and disabling tracepoints while a trace
1326 experiment is running. */
1327 PACKET_EnableDisableTracepoints_feature,
1329 /* Support for collecting strings using the tracenz bytecode. */
1330 PACKET_tracenz_feature,
1332 /* Support for continuing to run a trace experiment while GDB is
1334 PACKET_DisconnectedTracing_feature,
1336 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1337 PACKET_augmented_libraries_svr4_read_feature,
1339 /* Support for the qXfer:btrace-conf:read packet. */
1340 PACKET_qXfer_btrace_conf,
1342 /* Support for the Qbtrace-conf:bts:size packet. */
1343 PACKET_Qbtrace_conf_bts_size,
1345 /* Support for swbreak+ feature. */
1346 PACKET_swbreak_feature,
1348 /* Support for hwbreak+ feature. */
1349 PACKET_hwbreak_feature,
1351 /* Support for fork events. */
1352 PACKET_fork_event_feature,
1354 /* Support for vfork events. */
1355 PACKET_vfork_event_feature,
1360 static struct packet_config remote_protocol_packets[PACKET_MAX];
1362 /* Returns the packet's corresponding "set remote foo-packet" command
1363 state. See struct packet_config for more details. */
1365 static enum auto_boolean
1366 packet_set_cmd_state (int packet)
1368 return remote_protocol_packets[packet].detect;
1371 /* Returns whether a given packet or feature is supported. This takes
1372 into account the state of the corresponding "set remote foo-packet"
1373 command, which may be used to bypass auto-detection. */
1375 static enum packet_support
1376 packet_config_support (struct packet_config *config)
1378 switch (config->detect)
1380 case AUTO_BOOLEAN_TRUE:
1381 return PACKET_ENABLE;
1382 case AUTO_BOOLEAN_FALSE:
1383 return PACKET_DISABLE;
1384 case AUTO_BOOLEAN_AUTO:
1385 return config->support;
1387 gdb_assert_not_reached (_("bad switch"));
1391 /* Same as packet_config_support, but takes the packet's enum value as
1394 static enum packet_support
1395 packet_support (int packet)
1397 struct packet_config *config = &remote_protocol_packets[packet];
1399 return packet_config_support (config);
1403 show_remote_protocol_packet_cmd (struct ui_file *file, int from_tty,
1404 struct cmd_list_element *c,
1407 struct packet_config *packet;
1409 for (packet = remote_protocol_packets;
1410 packet < &remote_protocol_packets[PACKET_MAX];
1413 if (&packet->detect == c->var)
1415 show_packet_config_cmd (packet);
1419 internal_error (__FILE__, __LINE__, _("Could not find config for %s"),
1423 /* Should we try one of the 'Z' requests? */
1427 Z_PACKET_SOFTWARE_BP,
1428 Z_PACKET_HARDWARE_BP,
1435 /* For compatibility with older distributions. Provide a ``set remote
1436 Z-packet ...'' command that updates all the Z packet types. */
1438 static enum auto_boolean remote_Z_packet_detect;
1441 set_remote_protocol_Z_packet_cmd (char *args, int from_tty,
1442 struct cmd_list_element *c)
1446 for (i = 0; i < NR_Z_PACKET_TYPES; i++)
1447 remote_protocol_packets[PACKET_Z0 + i].detect = remote_Z_packet_detect;
1451 show_remote_protocol_Z_packet_cmd (struct ui_file *file, int from_tty,
1452 struct cmd_list_element *c,
1457 for (i = 0; i < NR_Z_PACKET_TYPES; i++)
1459 show_packet_config_cmd (&remote_protocol_packets[PACKET_Z0 + i]);
1463 /* Returns true if the multi-process extensions are in effect. */
1466 remote_multi_process_p (struct remote_state *rs)
1468 return packet_support (PACKET_multiprocess_feature) == PACKET_ENABLE;
1471 /* Returns true if fork events are supported. */
1474 remote_fork_event_p (struct remote_state *rs)
1476 return packet_support (PACKET_fork_event_feature) == PACKET_ENABLE;
1479 /* Returns true if vfork events are supported. */
1482 remote_vfork_event_p (struct remote_state *rs)
1484 return packet_support (PACKET_vfork_event_feature) == PACKET_ENABLE;
1487 /* Insert fork catchpoint target routine. If fork events are enabled
1488 then return success, nothing more to do. */
1491 remote_insert_fork_catchpoint (struct target_ops *ops, int pid)
1493 struct remote_state *rs = get_remote_state ();
1495 return !remote_fork_event_p (rs);
1498 /* Remove fork catchpoint target routine. Nothing to do, just
1502 remote_remove_fork_catchpoint (struct target_ops *ops, int pid)
1507 /* Insert vfork catchpoint target routine. If vfork events are enabled
1508 then return success, nothing more to do. */
1511 remote_insert_vfork_catchpoint (struct target_ops *ops, int pid)
1513 struct remote_state *rs = get_remote_state ();
1515 return !remote_vfork_event_p (rs);
1518 /* Remove vfork catchpoint target routine. Nothing to do, just
1522 remote_remove_vfork_catchpoint (struct target_ops *ops, int pid)
1527 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1528 static struct async_signal_handler *async_sigint_remote_twice_token;
1529 static struct async_signal_handler *async_sigint_remote_token;
1532 /* Asynchronous signal handle registered as event loop source for
1533 when we have pending events ready to be passed to the core. */
1535 static struct async_event_handler *remote_async_inferior_event_token;
1539 static ptid_t magic_null_ptid;
1540 static ptid_t not_sent_ptid;
1541 static ptid_t any_thread_ptid;
1543 /* Find out if the stub attached to PID (and hence GDB should offer to
1544 detach instead of killing it when bailing out). */
1547 remote_query_attached (int pid)
1549 struct remote_state *rs = get_remote_state ();
1550 size_t size = get_remote_packet_size ();
1552 if (packet_support (PACKET_qAttached) == PACKET_DISABLE)
1555 if (remote_multi_process_p (rs))
1556 xsnprintf (rs->buf, size, "qAttached:%x", pid);
1558 xsnprintf (rs->buf, size, "qAttached");
1561 getpkt (&rs->buf, &rs->buf_size, 0);
1563 switch (packet_ok (rs->buf,
1564 &remote_protocol_packets[PACKET_qAttached]))
1567 if (strcmp (rs->buf, "1") == 0)
1571 warning (_("Remote failure reply: %s"), rs->buf);
1573 case PACKET_UNKNOWN:
1580 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1581 has been invented by GDB, instead of reported by the target. Since
1582 we can be connected to a remote system before before knowing about
1583 any inferior, mark the target with execution when we find the first
1584 inferior. If ATTACHED is 1, then we had just attached to this
1585 inferior. If it is 0, then we just created this inferior. If it
1586 is -1, then try querying the remote stub to find out if it had
1587 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1588 attempt to open this inferior's executable as the main executable
1589 if no main executable is open already. */
1591 static struct inferior *
1592 remote_add_inferior (int fake_pid_p, int pid, int attached,
1595 struct inferior *inf;
1597 /* Check whether this process we're learning about is to be
1598 considered attached, or if is to be considered to have been
1599 spawned by the stub. */
1601 attached = remote_query_attached (pid);
1603 if (gdbarch_has_global_solist (target_gdbarch ()))
1605 /* If the target shares code across all inferiors, then every
1606 attach adds a new inferior. */
1607 inf = add_inferior (pid);
1609 /* ... and every inferior is bound to the same program space.
1610 However, each inferior may still have its own address
1612 inf->aspace = maybe_new_address_space ();
1613 inf->pspace = current_program_space;
1617 /* In the traditional debugging scenario, there's a 1-1 match
1618 between program/address spaces. We simply bind the inferior
1619 to the program space's address space. */
1620 inf = current_inferior ();
1621 inferior_appeared (inf, pid);
1624 inf->attach_flag = attached;
1625 inf->fake_pid_p = fake_pid_p;
1627 /* If no main executable is currently open then attempt to
1628 open the file that was executed to create this inferior. */
1629 if (try_open_exec && get_exec_file (0) == NULL)
1630 exec_file_locate_attach (pid, 1);
1635 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1636 according to RUNNING. */
1639 remote_add_thread (ptid_t ptid, int running)
1641 struct remote_state *rs = get_remote_state ();
1643 /* GDB historically didn't pull threads in the initial connection
1644 setup. If the remote target doesn't even have a concept of
1645 threads (e.g., a bare-metal target), even if internally we
1646 consider that a single-threaded target, mentioning a new thread
1647 might be confusing to the user. Be silent then, preserving the
1648 age old behavior. */
1649 if (rs->starting_up)
1650 add_thread_silent (ptid);
1654 set_executing (ptid, running);
1655 set_running (ptid, running);
1658 /* Come here when we learn about a thread id from the remote target.
1659 It may be the first time we hear about such thread, so take the
1660 opportunity to add it to GDB's thread list. In case this is the
1661 first time we're noticing its corresponding inferior, add it to
1662 GDB's inferior list as well. */
1665 remote_notice_new_inferior (ptid_t currthread, int running)
1667 /* If this is a new thread, add it to GDB's thread list.
1668 If we leave it up to WFI to do this, bad things will happen. */
1670 if (in_thread_list (currthread) && is_exited (currthread))
1672 /* We're seeing an event on a thread id we knew had exited.
1673 This has to be a new thread reusing the old id. Add it. */
1674 remote_add_thread (currthread, running);
1678 if (!in_thread_list (currthread))
1680 struct inferior *inf = NULL;
1681 int pid = ptid_get_pid (currthread);
1683 if (ptid_is_pid (inferior_ptid)
1684 && pid == ptid_get_pid (inferior_ptid))
1686 /* inferior_ptid has no thread member yet. This can happen
1687 with the vAttach -> remote_wait,"TAAthread:" path if the
1688 stub doesn't support qC. This is the first stop reported
1689 after an attach, so this is the main thread. Update the
1690 ptid in the thread list. */
1691 if (in_thread_list (pid_to_ptid (pid)))
1692 thread_change_ptid (inferior_ptid, currthread);
1695 remote_add_thread (currthread, running);
1696 inferior_ptid = currthread;
1701 if (ptid_equal (magic_null_ptid, inferior_ptid))
1703 /* inferior_ptid is not set yet. This can happen with the
1704 vRun -> remote_wait,"TAAthread:" path if the stub
1705 doesn't support qC. This is the first stop reported
1706 after an attach, so this is the main thread. Update the
1707 ptid in the thread list. */
1708 thread_change_ptid (inferior_ptid, currthread);
1712 /* When connecting to a target remote, or to a target
1713 extended-remote which already was debugging an inferior, we
1714 may not know about it yet. Add it before adding its child
1715 thread, so notifications are emitted in a sensible order. */
1716 if (!in_inferior_list (ptid_get_pid (currthread)))
1718 struct remote_state *rs = get_remote_state ();
1719 int fake_pid_p = !remote_multi_process_p (rs);
1721 inf = remote_add_inferior (fake_pid_p,
1722 ptid_get_pid (currthread), -1, 1);
1725 /* This is really a new thread. Add it. */
1726 remote_add_thread (currthread, running);
1728 /* If we found a new inferior, let the common code do whatever
1729 it needs to with it (e.g., read shared libraries, insert
1730 breakpoints), unless we're just setting up an all-stop
1734 struct remote_state *rs = get_remote_state ();
1736 if (non_stop || !rs->starting_up)
1737 notice_new_inferior (currthread, running, 0);
1742 /* Return the private thread data, creating it if necessary. */
1744 static struct private_thread_info *
1745 demand_private_info (ptid_t ptid)
1747 struct thread_info *info = find_thread_ptid (ptid);
1753 info->priv = xmalloc (sizeof (*(info->priv)));
1754 info->private_dtor = free_private_thread_info;
1755 info->priv->core = -1;
1756 info->priv->extra = 0;
1762 /* Call this function as a result of
1763 1) A halt indication (T packet) containing a thread id
1764 2) A direct query of currthread
1765 3) Successful execution of set thread */
1768 record_currthread (struct remote_state *rs, ptid_t currthread)
1770 rs->general_thread = currthread;
1773 /* If 'QPassSignals' is supported, tell the remote stub what signals
1774 it can simply pass through to the inferior without reporting. */
1777 remote_pass_signals (struct target_ops *self,
1778 int numsigs, unsigned char *pass_signals)
1780 if (packet_support (PACKET_QPassSignals) != PACKET_DISABLE)
1782 char *pass_packet, *p;
1784 struct remote_state *rs = get_remote_state ();
1786 gdb_assert (numsigs < 256);
1787 for (i = 0; i < numsigs; i++)
1789 if (pass_signals[i])
1792 pass_packet = xmalloc (count * 3 + strlen ("QPassSignals:") + 1);
1793 strcpy (pass_packet, "QPassSignals:");
1794 p = pass_packet + strlen (pass_packet);
1795 for (i = 0; i < numsigs; i++)
1797 if (pass_signals[i])
1800 *p++ = tohex (i >> 4);
1801 *p++ = tohex (i & 15);
1810 if (!rs->last_pass_packet || strcmp (rs->last_pass_packet, pass_packet))
1812 putpkt (pass_packet);
1813 getpkt (&rs->buf, &rs->buf_size, 0);
1814 packet_ok (rs->buf, &remote_protocol_packets[PACKET_QPassSignals]);
1815 if (rs->last_pass_packet)
1816 xfree (rs->last_pass_packet);
1817 rs->last_pass_packet = pass_packet;
1820 xfree (pass_packet);
1824 /* If 'QProgramSignals' is supported, tell the remote stub what
1825 signals it should pass through to the inferior when detaching. */
1828 remote_program_signals (struct target_ops *self,
1829 int numsigs, unsigned char *signals)
1831 if (packet_support (PACKET_QProgramSignals) != PACKET_DISABLE)
1835 struct remote_state *rs = get_remote_state ();
1837 gdb_assert (numsigs < 256);
1838 for (i = 0; i < numsigs; i++)
1843 packet = xmalloc (count * 3 + strlen ("QProgramSignals:") + 1);
1844 strcpy (packet, "QProgramSignals:");
1845 p = packet + strlen (packet);
1846 for (i = 0; i < numsigs; i++)
1848 if (signal_pass_state (i))
1851 *p++ = tohex (i >> 4);
1852 *p++ = tohex (i & 15);
1861 if (!rs->last_program_signals_packet
1862 || strcmp (rs->last_program_signals_packet, packet) != 0)
1865 getpkt (&rs->buf, &rs->buf_size, 0);
1866 packet_ok (rs->buf, &remote_protocol_packets[PACKET_QProgramSignals]);
1867 xfree (rs->last_program_signals_packet);
1868 rs->last_program_signals_packet = packet;
1875 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1876 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1877 thread. If GEN is set, set the general thread, if not, then set
1878 the step/continue thread. */
1880 set_thread (struct ptid ptid, int gen)
1882 struct remote_state *rs = get_remote_state ();
1883 ptid_t state = gen ? rs->general_thread : rs->continue_thread;
1884 char *buf = rs->buf;
1885 char *endbuf = rs->buf + get_remote_packet_size ();
1887 if (ptid_equal (state, ptid))
1891 *buf++ = gen ? 'g' : 'c';
1892 if (ptid_equal (ptid, magic_null_ptid))
1893 xsnprintf (buf, endbuf - buf, "0");
1894 else if (ptid_equal (ptid, any_thread_ptid))
1895 xsnprintf (buf, endbuf - buf, "0");
1896 else if (ptid_equal (ptid, minus_one_ptid))
1897 xsnprintf (buf, endbuf - buf, "-1");
1899 write_ptid (buf, endbuf, ptid);
1901 getpkt (&rs->buf, &rs->buf_size, 0);
1903 rs->general_thread = ptid;
1905 rs->continue_thread = ptid;
1909 set_general_thread (struct ptid ptid)
1911 set_thread (ptid, 1);
1915 set_continue_thread (struct ptid ptid)
1917 set_thread (ptid, 0);
1920 /* Change the remote current process. Which thread within the process
1921 ends up selected isn't important, as long as it is the same process
1922 as what INFERIOR_PTID points to.
1924 This comes from that fact that there is no explicit notion of
1925 "selected process" in the protocol. The selected process for
1926 general operations is the process the selected general thread
1930 set_general_process (void)
1932 struct remote_state *rs = get_remote_state ();
1934 /* If the remote can't handle multiple processes, don't bother. */
1935 if (!rs->extended || !remote_multi_process_p (rs))
1938 /* We only need to change the remote current thread if it's pointing
1939 at some other process. */
1940 if (ptid_get_pid (rs->general_thread) != ptid_get_pid (inferior_ptid))
1941 set_general_thread (inferior_ptid);
1945 /* Return nonzero if this is the main thread that we made up ourselves
1946 to model non-threaded targets as single-threaded. */
1949 remote_thread_always_alive (struct target_ops *ops, ptid_t ptid)
1951 struct remote_state *rs = get_remote_state ();
1954 if (ptid_equal (ptid, magic_null_ptid))
1955 /* The main thread is always alive. */
1958 if (ptid_get_pid (ptid) != 0 && ptid_get_lwp (ptid) == 0)
1959 /* The main thread is always alive. This can happen after a
1960 vAttach, if the remote side doesn't support
1967 /* Return nonzero if the thread PTID is still alive on the remote
1971 remote_thread_alive (struct target_ops *ops, ptid_t ptid)
1973 struct remote_state *rs = get_remote_state ();
1976 /* Check if this is a thread that we made up ourselves to model
1977 non-threaded targets as single-threaded. */
1978 if (remote_thread_always_alive (ops, ptid))
1982 endp = rs->buf + get_remote_packet_size ();
1985 write_ptid (p, endp, ptid);
1988 getpkt (&rs->buf, &rs->buf_size, 0);
1989 return (rs->buf[0] == 'O' && rs->buf[1] == 'K');
1992 /* About these extended threadlist and threadinfo packets. They are
1993 variable length packets but, the fields within them are often fixed
1994 length. They are redundent enough to send over UDP as is the
1995 remote protocol in general. There is a matching unit test module
1998 /* WARNING: This threadref data structure comes from the remote O.S.,
1999 libstub protocol encoding, and remote.c. It is not particularly
2002 /* Right now, the internal structure is int. We want it to be bigger.
2003 Plan to fix this. */
2005 typedef int gdb_threadref; /* Internal GDB thread reference. */
2007 /* gdb_ext_thread_info is an internal GDB data structure which is
2008 equivalent to the reply of the remote threadinfo packet. */
2010 struct gdb_ext_thread_info
2012 threadref threadid; /* External form of thread reference. */
2013 int active; /* Has state interesting to GDB?
2015 char display[256]; /* Brief state display, name,
2016 blocked/suspended. */
2017 char shortname[32]; /* To be used to name threads. */
2018 char more_display[256]; /* Long info, statistics, queue depth,
2022 /* The volume of remote transfers can be limited by submitting
2023 a mask containing bits specifying the desired information.
2024 Use a union of these values as the 'selection' parameter to
2025 get_thread_info. FIXME: Make these TAG names more thread specific. */
2027 #define TAG_THREADID 1
2028 #define TAG_EXISTS 2
2029 #define TAG_DISPLAY 4
2030 #define TAG_THREADNAME 8
2031 #define TAG_MOREDISPLAY 16
2033 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2035 static char *unpack_nibble (char *buf, int *val);
2037 static char *unpack_byte (char *buf, int *value);
2039 static char *pack_int (char *buf, int value);
2041 static char *unpack_int (char *buf, int *value);
2043 static char *unpack_string (char *src, char *dest, int length);
2045 static char *pack_threadid (char *pkt, threadref *id);
2047 static char *unpack_threadid (char *inbuf, threadref *id);
2049 void int_to_threadref (threadref *id, int value);
2051 static int threadref_to_int (threadref *ref);
2053 static void copy_threadref (threadref *dest, threadref *src);
2055 static int threadmatch (threadref *dest, threadref *src);
2057 static char *pack_threadinfo_request (char *pkt, int mode,
2060 static int remote_unpack_thread_info_response (char *pkt,
2061 threadref *expectedref,
2062 struct gdb_ext_thread_info
2066 static int remote_get_threadinfo (threadref *threadid,
2067 int fieldset, /*TAG mask */
2068 struct gdb_ext_thread_info *info);
2070 static char *pack_threadlist_request (char *pkt, int startflag,
2072 threadref *nextthread);
2074 static int parse_threadlist_response (char *pkt,
2076 threadref *original_echo,
2077 threadref *resultlist,
2080 static int remote_get_threadlist (int startflag,
2081 threadref *nextthread,
2085 threadref *threadlist);
2087 typedef int (*rmt_thread_action) (threadref *ref, void *context);
2089 static int remote_threadlist_iterator (rmt_thread_action stepfunction,
2090 void *context, int looplimit);
2092 static int remote_newthread_step (threadref *ref, void *context);
2095 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2096 buffer we're allowed to write to. Returns
2097 BUF+CHARACTERS_WRITTEN. */
2100 write_ptid (char *buf, const char *endbuf, ptid_t ptid)
2103 struct remote_state *rs = get_remote_state ();
2105 if (remote_multi_process_p (rs))
2107 pid = ptid_get_pid (ptid);
2109 buf += xsnprintf (buf, endbuf - buf, "p-%x.", -pid);
2111 buf += xsnprintf (buf, endbuf - buf, "p%x.", pid);
2113 tid = ptid_get_lwp (ptid);
2115 buf += xsnprintf (buf, endbuf - buf, "-%x", -tid);
2117 buf += xsnprintf (buf, endbuf - buf, "%x", tid);
2122 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2123 passed the last parsed char. Returns null_ptid on error. */
2126 read_ptid (char *buf, char **obuf)
2130 ULONGEST pid = 0, tid = 0;
2134 /* Multi-process ptid. */
2135 pp = unpack_varlen_hex (p + 1, &pid);
2137 error (_("invalid remote ptid: %s"), p);
2140 pp = unpack_varlen_hex (p + 1, &tid);
2143 return ptid_build (pid, tid, 0);
2146 /* No multi-process. Just a tid. */
2147 pp = unpack_varlen_hex (p, &tid);
2149 /* Since the stub is not sending a process id, then default to
2150 what's in inferior_ptid, unless it's null at this point. If so,
2151 then since there's no way to know the pid of the reported
2152 threads, use the magic number. */
2153 if (ptid_equal (inferior_ptid, null_ptid))
2154 pid = ptid_get_pid (magic_null_ptid);
2156 pid = ptid_get_pid (inferior_ptid);
2160 return ptid_build (pid, tid, 0);
2166 if (ch >= 'a' && ch <= 'f')
2167 return ch - 'a' + 10;
2168 if (ch >= '0' && ch <= '9')
2170 if (ch >= 'A' && ch <= 'F')
2171 return ch - 'A' + 10;
2176 stub_unpack_int (char *buff, int fieldlength)
2183 nibble = stubhex (*buff++);
2187 retval = retval << 4;
2193 unpack_nibble (char *buf, int *val)
2195 *val = fromhex (*buf++);
2200 unpack_byte (char *buf, int *value)
2202 *value = stub_unpack_int (buf, 2);
2207 pack_int (char *buf, int value)
2209 buf = pack_hex_byte (buf, (value >> 24) & 0xff);
2210 buf = pack_hex_byte (buf, (value >> 16) & 0xff);
2211 buf = pack_hex_byte (buf, (value >> 8) & 0x0ff);
2212 buf = pack_hex_byte (buf, (value & 0xff));
2217 unpack_int (char *buf, int *value)
2219 *value = stub_unpack_int (buf, 8);
2223 #if 0 /* Currently unused, uncomment when needed. */
2224 static char *pack_string (char *pkt, char *string);
2227 pack_string (char *pkt, char *string)
2232 len = strlen (string);
2234 len = 200; /* Bigger than most GDB packets, junk??? */
2235 pkt = pack_hex_byte (pkt, len);
2239 if ((ch == '\0') || (ch == '#'))
2240 ch = '*'; /* Protect encapsulation. */
2245 #endif /* 0 (unused) */
2248 unpack_string (char *src, char *dest, int length)
2257 pack_threadid (char *pkt, threadref *id)
2260 unsigned char *altid;
2262 altid = (unsigned char *) id;
2263 limit = pkt + BUF_THREAD_ID_SIZE;
2265 pkt = pack_hex_byte (pkt, *altid++);
2271 unpack_threadid (char *inbuf, threadref *id)
2274 char *limit = inbuf + BUF_THREAD_ID_SIZE;
2277 altref = (char *) id;
2279 while (inbuf < limit)
2281 x = stubhex (*inbuf++);
2282 y = stubhex (*inbuf++);
2283 *altref++ = (x << 4) | y;
2288 /* Externally, threadrefs are 64 bits but internally, they are still
2289 ints. This is due to a mismatch of specifications. We would like
2290 to use 64bit thread references internally. This is an adapter
2294 int_to_threadref (threadref *id, int value)
2296 unsigned char *scan;
2298 scan = (unsigned char *) id;
2304 *scan++ = (value >> 24) & 0xff;
2305 *scan++ = (value >> 16) & 0xff;
2306 *scan++ = (value >> 8) & 0xff;
2307 *scan++ = (value & 0xff);
2311 threadref_to_int (threadref *ref)
2314 unsigned char *scan;
2320 value = (value << 8) | ((*scan++) & 0xff);
2325 copy_threadref (threadref *dest, threadref *src)
2328 unsigned char *csrc, *cdest;
2330 csrc = (unsigned char *) src;
2331 cdest = (unsigned char *) dest;
2338 threadmatch (threadref *dest, threadref *src)
2340 /* Things are broken right now, so just assume we got a match. */
2342 unsigned char *srcp, *destp;
2344 srcp = (char *) src;
2345 destp = (char *) dest;
2349 result &= (*srcp++ == *destp++) ? 1 : 0;
2356 threadid:1, # always request threadid
2363 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2366 pack_threadinfo_request (char *pkt, int mode, threadref *id)
2368 *pkt++ = 'q'; /* Info Query */
2369 *pkt++ = 'P'; /* process or thread info */
2370 pkt = pack_int (pkt, mode); /* mode */
2371 pkt = pack_threadid (pkt, id); /* threadid */
2372 *pkt = '\0'; /* terminate */
2376 /* These values tag the fields in a thread info response packet. */
2377 /* Tagging the fields allows us to request specific fields and to
2378 add more fields as time goes by. */
2380 #define TAG_THREADID 1 /* Echo the thread identifier. */
2381 #define TAG_EXISTS 2 /* Is this process defined enough to
2382 fetch registers and its stack? */
2383 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2384 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2385 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2389 remote_unpack_thread_info_response (char *pkt, threadref *expectedref,
2390 struct gdb_ext_thread_info *info)
2392 struct remote_state *rs = get_remote_state ();
2396 char *limit = pkt + rs->buf_size; /* Plausible parsing limit. */
2399 /* info->threadid = 0; FIXME: implement zero_threadref. */
2401 info->display[0] = '\0';
2402 info->shortname[0] = '\0';
2403 info->more_display[0] = '\0';
2405 /* Assume the characters indicating the packet type have been
2407 pkt = unpack_int (pkt, &mask); /* arg mask */
2408 pkt = unpack_threadid (pkt, &ref);
2411 warning (_("Incomplete response to threadinfo request."));
2412 if (!threadmatch (&ref, expectedref))
2413 { /* This is an answer to a different request. */
2414 warning (_("ERROR RMT Thread info mismatch."));
2417 copy_threadref (&info->threadid, &ref);
2419 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2421 /* Packets are terminated with nulls. */
2422 while ((pkt < limit) && mask && *pkt)
2424 pkt = unpack_int (pkt, &tag); /* tag */
2425 pkt = unpack_byte (pkt, &length); /* length */
2426 if (!(tag & mask)) /* Tags out of synch with mask. */
2428 warning (_("ERROR RMT: threadinfo tag mismatch."));
2432 if (tag == TAG_THREADID)
2436 warning (_("ERROR RMT: length of threadid is not 16."));
2440 pkt = unpack_threadid (pkt, &ref);
2441 mask = mask & ~TAG_THREADID;
2444 if (tag == TAG_EXISTS)
2446 info->active = stub_unpack_int (pkt, length);
2448 mask = mask & ~(TAG_EXISTS);
2451 warning (_("ERROR RMT: 'exists' length too long."));
2457 if (tag == TAG_THREADNAME)
2459 pkt = unpack_string (pkt, &info->shortname[0], length);
2460 mask = mask & ~TAG_THREADNAME;
2463 if (tag == TAG_DISPLAY)
2465 pkt = unpack_string (pkt, &info->display[0], length);
2466 mask = mask & ~TAG_DISPLAY;
2469 if (tag == TAG_MOREDISPLAY)
2471 pkt = unpack_string (pkt, &info->more_display[0], length);
2472 mask = mask & ~TAG_MOREDISPLAY;
2475 warning (_("ERROR RMT: unknown thread info tag."));
2476 break; /* Not a tag we know about. */
2482 remote_get_threadinfo (threadref *threadid, int fieldset, /* TAG mask */
2483 struct gdb_ext_thread_info *info)
2485 struct remote_state *rs = get_remote_state ();
2488 pack_threadinfo_request (rs->buf, fieldset, threadid);
2490 getpkt (&rs->buf, &rs->buf_size, 0);
2492 if (rs->buf[0] == '\0')
2495 result = remote_unpack_thread_info_response (rs->buf + 2,
2500 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2503 pack_threadlist_request (char *pkt, int startflag, int threadcount,
2504 threadref *nextthread)
2506 *pkt++ = 'q'; /* info query packet */
2507 *pkt++ = 'L'; /* Process LIST or threadLIST request */
2508 pkt = pack_nibble (pkt, startflag); /* initflag 1 bytes */
2509 pkt = pack_hex_byte (pkt, threadcount); /* threadcount 2 bytes */
2510 pkt = pack_threadid (pkt, nextthread); /* 64 bit thread identifier */
2515 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2518 parse_threadlist_response (char *pkt, int result_limit,
2519 threadref *original_echo, threadref *resultlist,
2522 struct remote_state *rs = get_remote_state ();
2524 int count, resultcount, done;
2527 /* Assume the 'q' and 'M chars have been stripped. */
2528 limit = pkt + (rs->buf_size - BUF_THREAD_ID_SIZE);
2529 /* done parse past here */
2530 pkt = unpack_byte (pkt, &count); /* count field */
2531 pkt = unpack_nibble (pkt, &done);
2532 /* The first threadid is the argument threadid. */
2533 pkt = unpack_threadid (pkt, original_echo); /* should match query packet */
2534 while ((count-- > 0) && (pkt < limit))
2536 pkt = unpack_threadid (pkt, resultlist++);
2537 if (resultcount++ >= result_limit)
2545 /* Fetch the next batch of threads from the remote. Returns -1 if the
2546 qL packet is not supported, 0 on error and 1 on success. */
2549 remote_get_threadlist (int startflag, threadref *nextthread, int result_limit,
2550 int *done, int *result_count, threadref *threadlist)
2552 struct remote_state *rs = get_remote_state ();
2555 /* Trancate result limit to be smaller than the packet size. */
2556 if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10)
2557 >= get_remote_packet_size ())
2558 result_limit = (get_remote_packet_size () / BUF_THREAD_ID_SIZE) - 2;
2560 pack_threadlist_request (rs->buf, startflag, result_limit, nextthread);
2562 getpkt (&rs->buf, &rs->buf_size, 0);
2563 if (*rs->buf == '\0')
2565 /* Packet not supported. */
2570 parse_threadlist_response (rs->buf + 2, result_limit,
2571 &rs->echo_nextthread, threadlist, done);
2573 if (!threadmatch (&rs->echo_nextthread, nextthread))
2575 /* FIXME: This is a good reason to drop the packet. */
2576 /* Possably, there is a duplicate response. */
2578 retransmit immediatly - race conditions
2579 retransmit after timeout - yes
2581 wait for packet, then exit
2583 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2584 return 0; /* I choose simply exiting. */
2586 if (*result_count <= 0)
2590 warning (_("RMT ERROR : failed to get remote thread list."));
2593 return result; /* break; */
2595 if (*result_count > result_limit)
2598 warning (_("RMT ERROR: threadlist response longer than requested."));
2604 /* Fetch the list of remote threads, with the qL packet, and call
2605 STEPFUNCTION for each thread found. Stops iterating and returns 1
2606 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2607 STEPFUNCTION returns false. If the packet is not supported,
2611 remote_threadlist_iterator (rmt_thread_action stepfunction, void *context,
2614 struct remote_state *rs = get_remote_state ();
2615 int done, i, result_count;
2623 if (loopcount++ > looplimit)
2626 warning (_("Remote fetch threadlist -infinite loop-."));
2629 result = remote_get_threadlist (startflag, &rs->nextthread,
2630 MAXTHREADLISTRESULTS,
2631 &done, &result_count,
2632 rs->resultthreadlist);
2635 /* Clear for later iterations. */
2637 /* Setup to resume next batch of thread references, set nextthread. */
2638 if (result_count >= 1)
2639 copy_threadref (&rs->nextthread,
2640 &rs->resultthreadlist[result_count - 1]);
2642 while (result_count--)
2644 if (!(*stepfunction) (&rs->resultthreadlist[i++], context))
2654 /* A thread found on the remote target. */
2656 typedef struct thread_item
2658 /* The thread's PTID. */
2661 /* The thread's extra info. May be NULL. */
2664 /* The core the thread was running on. -1 if not known. */
2667 DEF_VEC_O(thread_item_t);
2669 /* Context passed around to the various methods listing remote
2670 threads. As new threads are found, they're added to the ITEMS
2673 struct threads_listing_context
2675 /* The threads found on the remote target. */
2676 VEC (thread_item_t) *items;
2679 /* Discard the contents of the constructed thread listing context. */
2682 clear_threads_listing_context (void *p)
2684 struct threads_listing_context *context = p;
2686 struct thread_item *item;
2688 for (i = 0; VEC_iterate (thread_item_t, context->items, i, item); ++i)
2689 xfree (item->extra);
2691 VEC_free (thread_item_t, context->items);
2694 /* Remove the thread specified as the related_pid field of WS
2695 from the CONTEXT list. */
2698 threads_listing_context_remove (struct target_waitstatus *ws,
2699 struct threads_listing_context *context)
2701 struct thread_item *item;
2703 ptid_t child_ptid = ws->value.related_pid;
2705 for (i = 0; VEC_iterate (thread_item_t, context->items, i, item); ++i)
2707 if (ptid_equal (item->ptid, child_ptid))
2709 VEC_ordered_remove (thread_item_t, context->items, i);
2716 remote_newthread_step (threadref *ref, void *data)
2718 struct threads_listing_context *context = data;
2719 struct thread_item item;
2720 int pid = ptid_get_pid (inferior_ptid);
2722 item.ptid = ptid_build (pid, threadref_to_int (ref), 0);
2726 VEC_safe_push (thread_item_t, context->items, &item);
2728 return 1; /* continue iterator */
2731 #define CRAZY_MAX_THREADS 1000
2734 remote_current_thread (ptid_t oldpid)
2736 struct remote_state *rs = get_remote_state ();
2739 getpkt (&rs->buf, &rs->buf_size, 0);
2740 if (rs->buf[0] == 'Q' && rs->buf[1] == 'C')
2741 return read_ptid (&rs->buf[2], NULL);
2746 /* List remote threads using the deprecated qL packet. */
2749 remote_get_threads_with_ql (struct target_ops *ops,
2750 struct threads_listing_context *context)
2752 if (remote_threadlist_iterator (remote_newthread_step, context,
2753 CRAZY_MAX_THREADS) >= 0)
2759 #if defined(HAVE_LIBEXPAT)
2762 start_thread (struct gdb_xml_parser *parser,
2763 const struct gdb_xml_element *element,
2764 void *user_data, VEC(gdb_xml_value_s) *attributes)
2766 struct threads_listing_context *data = user_data;
2768 struct thread_item item;
2770 struct gdb_xml_value *attr;
2772 id = xml_find_attribute (attributes, "id")->value;
2773 item.ptid = read_ptid (id, NULL);
2775 attr = xml_find_attribute (attributes, "core");
2777 item.core = *(ULONGEST *) attr->value;
2783 VEC_safe_push (thread_item_t, data->items, &item);
2787 end_thread (struct gdb_xml_parser *parser,
2788 const struct gdb_xml_element *element,
2789 void *user_data, const char *body_text)
2791 struct threads_listing_context *data = user_data;
2793 if (body_text && *body_text)
2794 VEC_last (thread_item_t, data->items)->extra = xstrdup (body_text);
2797 const struct gdb_xml_attribute thread_attributes[] = {
2798 { "id", GDB_XML_AF_NONE, NULL, NULL },
2799 { "core", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL },
2800 { NULL, GDB_XML_AF_NONE, NULL, NULL }
2803 const struct gdb_xml_element thread_children[] = {
2804 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
2807 const struct gdb_xml_element threads_children[] = {
2808 { "thread", thread_attributes, thread_children,
2809 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL,
2810 start_thread, end_thread },
2811 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
2814 const struct gdb_xml_element threads_elements[] = {
2815 { "threads", NULL, threads_children,
2816 GDB_XML_EF_NONE, NULL, NULL },
2817 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
2822 /* List remote threads using qXfer:threads:read. */
2825 remote_get_threads_with_qxfer (struct target_ops *ops,
2826 struct threads_listing_context *context)
2828 #if defined(HAVE_LIBEXPAT)
2829 if (packet_support (PACKET_qXfer_threads) == PACKET_ENABLE)
2831 char *xml = target_read_stralloc (ops, TARGET_OBJECT_THREADS, NULL);
2832 struct cleanup *back_to = make_cleanup (xfree, xml);
2834 if (xml != NULL && *xml != '\0')
2836 gdb_xml_parse_quick (_("threads"), "threads.dtd",
2837 threads_elements, xml, context);
2840 do_cleanups (back_to);
2848 /* List remote threads using qfThreadInfo/qsThreadInfo. */
2851 remote_get_threads_with_qthreadinfo (struct target_ops *ops,
2852 struct threads_listing_context *context)
2854 struct remote_state *rs = get_remote_state ();
2856 if (rs->use_threadinfo_query)
2860 putpkt ("qfThreadInfo");
2861 getpkt (&rs->buf, &rs->buf_size, 0);
2863 if (bufp[0] != '\0') /* q packet recognized */
2865 while (*bufp++ == 'm') /* reply contains one or more TID */
2869 struct thread_item item;
2871 item.ptid = read_ptid (bufp, &bufp);
2875 VEC_safe_push (thread_item_t, context->items, &item);
2877 while (*bufp++ == ','); /* comma-separated list */
2878 putpkt ("qsThreadInfo");
2879 getpkt (&rs->buf, &rs->buf_size, 0);
2886 /* Packet not recognized. */
2887 rs->use_threadinfo_query = 0;
2894 /* Implement the to_update_thread_list function for the remote
2898 remote_update_thread_list (struct target_ops *ops)
2900 struct remote_state *rs = get_remote_state ();
2901 struct threads_listing_context context;
2902 struct cleanup *old_chain;
2905 context.items = NULL;
2906 old_chain = make_cleanup (clear_threads_listing_context, &context);
2908 /* We have a few different mechanisms to fetch the thread list. Try
2909 them all, starting with the most preferred one first, falling
2910 back to older methods. */
2911 if (remote_get_threads_with_qxfer (ops, &context)
2912 || remote_get_threads_with_qthreadinfo (ops, &context)
2913 || remote_get_threads_with_ql (ops, &context))
2916 struct thread_item *item;
2917 struct thread_info *tp, *tmp;
2921 if (VEC_empty (thread_item_t, context.items)
2922 && remote_thread_always_alive (ops, inferior_ptid))
2924 /* Some targets don't really support threads, but still
2925 reply an (empty) thread list in response to the thread
2926 listing packets, instead of replying "packet not
2927 supported". Exit early so we don't delete the main
2929 do_cleanups (old_chain);
2933 /* CONTEXT now holds the current thread list on the remote
2934 target end. Delete GDB-side threads no longer found on the
2936 ALL_THREADS_SAFE (tp, tmp)
2939 VEC_iterate (thread_item_t, context.items, i, item);
2942 if (ptid_equal (item->ptid, tp->ptid))
2946 if (i == VEC_length (thread_item_t, context.items))
2949 delete_thread (tp->ptid);
2953 /* Remove any unreported fork child threads from CONTEXT so
2954 that we don't interfere with follow fork, which is where
2955 creation of such threads is handled. */
2956 remove_new_fork_children (&context);
2958 /* And now add threads we don't know about yet to our list. */
2960 VEC_iterate (thread_item_t, context.items, i, item);
2963 if (!ptid_equal (item->ptid, null_ptid))
2965 struct private_thread_info *info;
2966 /* In non-stop mode, we assume new found threads are
2967 running until proven otherwise with a stop reply. In
2968 all-stop, we can only get here if all threads are
2970 int running = non_stop ? 1 : 0;
2972 remote_notice_new_inferior (item->ptid, running);
2974 info = demand_private_info (item->ptid);
2975 info->core = item->core;
2976 info->extra = item->extra;
2984 /* If no thread listing method is supported, then query whether
2985 each known thread is alive, one by one, with the T packet.
2986 If the target doesn't support threads at all, then this is a
2987 no-op. See remote_thread_alive. */
2991 do_cleanups (old_chain);
2995 * Collect a descriptive string about the given thread.
2996 * The target may say anything it wants to about the thread
2997 * (typically info about its blocked / runnable state, name, etc.).
2998 * This string will appear in the info threads display.
3000 * Optional: targets are not required to implement this function.
3004 remote_threads_extra_info (struct target_ops *self, struct thread_info *tp)
3006 struct remote_state *rs = get_remote_state ();
3010 struct gdb_ext_thread_info threadinfo;
3011 static char display_buf[100]; /* arbitrary... */
3012 int n = 0; /* position in display_buf */
3014 if (rs->remote_desc == 0) /* paranoia */
3015 internal_error (__FILE__, __LINE__,
3016 _("remote_threads_extra_info"));
3018 if (ptid_equal (tp->ptid, magic_null_ptid)
3019 || (ptid_get_pid (tp->ptid) != 0 && ptid_get_lwp (tp->ptid) == 0))
3020 /* This is the main thread which was added by GDB. The remote
3021 server doesn't know about it. */
3024 if (packet_support (PACKET_qXfer_threads) == PACKET_ENABLE)
3026 struct thread_info *info = find_thread_ptid (tp->ptid);
3028 if (info && info->priv)
3029 return info->priv->extra;
3034 if (rs->use_threadextra_query)
3037 char *endb = rs->buf + get_remote_packet_size ();
3039 xsnprintf (b, endb - b, "qThreadExtraInfo,");
3041 write_ptid (b, endb, tp->ptid);
3044 getpkt (&rs->buf, &rs->buf_size, 0);
3045 if (rs->buf[0] != 0)
3047 n = min (strlen (rs->buf) / 2, sizeof (display_buf));
3048 result = hex2bin (rs->buf, (gdb_byte *) display_buf, n);
3049 display_buf [result] = '\0';
3054 /* If the above query fails, fall back to the old method. */
3055 rs->use_threadextra_query = 0;
3056 set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
3057 | TAG_MOREDISPLAY | TAG_DISPLAY;
3058 int_to_threadref (&id, ptid_get_lwp (tp->ptid));
3059 if (remote_get_threadinfo (&id, set, &threadinfo))
3060 if (threadinfo.active)
3062 if (*threadinfo.shortname)
3063 n += xsnprintf (&display_buf[0], sizeof (display_buf) - n,
3064 " Name: %s,", threadinfo.shortname);
3065 if (*threadinfo.display)
3066 n += xsnprintf (&display_buf[n], sizeof (display_buf) - n,
3067 " State: %s,", threadinfo.display);
3068 if (*threadinfo.more_display)
3069 n += xsnprintf (&display_buf[n], sizeof (display_buf) - n,
3070 " Priority: %s", threadinfo.more_display);
3074 /* For purely cosmetic reasons, clear up trailing commas. */
3075 if (',' == display_buf[n-1])
3076 display_buf[n-1] = ' ';
3085 remote_static_tracepoint_marker_at (struct target_ops *self, CORE_ADDR addr,
3086 struct static_tracepoint_marker *marker)
3088 struct remote_state *rs = get_remote_state ();
3091 xsnprintf (p, get_remote_packet_size (), "qTSTMat:");
3093 p += hexnumstr (p, addr);
3095 getpkt (&rs->buf, &rs->buf_size, 0);
3099 error (_("Remote failure reply: %s"), p);
3103 parse_static_tracepoint_marker_definition (p, &p, marker);
3110 static VEC(static_tracepoint_marker_p) *
3111 remote_static_tracepoint_markers_by_strid (struct target_ops *self,
3114 struct remote_state *rs = get_remote_state ();
3115 VEC(static_tracepoint_marker_p) *markers = NULL;
3116 struct static_tracepoint_marker *marker = NULL;
3117 struct cleanup *old_chain;
3120 /* Ask for a first packet of static tracepoint marker
3123 getpkt (&rs->buf, &rs->buf_size, 0);
3126 error (_("Remote failure reply: %s"), p);
3128 old_chain = make_cleanup (free_current_marker, &marker);
3133 marker = XCNEW (struct static_tracepoint_marker);
3137 parse_static_tracepoint_marker_definition (p, &p, marker);
3139 if (strid == NULL || strcmp (strid, marker->str_id) == 0)
3141 VEC_safe_push (static_tracepoint_marker_p,
3147 release_static_tracepoint_marker (marker);
3148 memset (marker, 0, sizeof (*marker));
3151 while (*p++ == ','); /* comma-separated list */
3152 /* Ask for another packet of static tracepoint definition. */
3154 getpkt (&rs->buf, &rs->buf_size, 0);
3158 do_cleanups (old_chain);
3163 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3166 remote_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
3168 return ptid_build (ptid_get_pid (inferior_ptid), lwp, 0);
3172 /* Restart the remote side; this is an extended protocol operation. */
3175 extended_remote_restart (void)
3177 struct remote_state *rs = get_remote_state ();
3179 /* Send the restart command; for reasons I don't understand the
3180 remote side really expects a number after the "R". */
3181 xsnprintf (rs->buf, get_remote_packet_size (), "R%x", 0);
3184 remote_fileio_reset ();
3187 /* Clean up connection to a remote debugger. */
3190 remote_close (struct target_ops *self)
3192 struct remote_state *rs = get_remote_state ();
3194 if (rs->remote_desc == NULL)
3195 return; /* already closed */
3197 /* Make sure we leave stdin registered in the event loop, and we
3198 don't leave the async SIGINT signal handler installed. */
3199 remote_terminal_ours (self);
3201 serial_close (rs->remote_desc);
3202 rs->remote_desc = NULL;
3204 /* We don't have a connection to the remote stub anymore. Get rid
3205 of all the inferiors and their threads we were controlling.
3206 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3207 will be unable to find the thread corresponding to (pid, 0, 0). */
3208 inferior_ptid = null_ptid;
3209 discard_all_inferiors ();
3211 /* We are closing the remote target, so we should discard
3212 everything of this target. */
3213 discard_pending_stop_replies_in_queue (rs);
3215 if (remote_async_inferior_event_token)
3216 delete_async_event_handler (&remote_async_inferior_event_token);
3218 remote_notif_state_xfree (rs->notif_state);
3220 trace_reset_local_state ();
3223 /* Query the remote side for the text, data and bss offsets. */
3228 struct remote_state *rs = get_remote_state ();
3231 int lose, num_segments = 0, do_sections, do_segments;
3232 CORE_ADDR text_addr, data_addr, bss_addr, segments[2];
3233 struct section_offsets *offs;
3234 struct symfile_segment_data *data;
3236 if (symfile_objfile == NULL)
3239 putpkt ("qOffsets");
3240 getpkt (&rs->buf, &rs->buf_size, 0);
3243 if (buf[0] == '\000')
3244 return; /* Return silently. Stub doesn't support
3248 warning (_("Remote failure reply: %s"), buf);
3252 /* Pick up each field in turn. This used to be done with scanf, but
3253 scanf will make trouble if CORE_ADDR size doesn't match
3254 conversion directives correctly. The following code will work
3255 with any size of CORE_ADDR. */
3256 text_addr = data_addr = bss_addr = 0;
3260 if (startswith (ptr, "Text="))
3263 /* Don't use strtol, could lose on big values. */
3264 while (*ptr && *ptr != ';')
3265 text_addr = (text_addr << 4) + fromhex (*ptr++);
3267 if (startswith (ptr, ";Data="))
3270 while (*ptr && *ptr != ';')
3271 data_addr = (data_addr << 4) + fromhex (*ptr++);
3276 if (!lose && startswith (ptr, ";Bss="))
3279 while (*ptr && *ptr != ';')
3280 bss_addr = (bss_addr << 4) + fromhex (*ptr++);
3282 if (bss_addr != data_addr)
3283 warning (_("Target reported unsupported offsets: %s"), buf);
3288 else if (startswith (ptr, "TextSeg="))
3291 /* Don't use strtol, could lose on big values. */
3292 while (*ptr && *ptr != ';')
3293 text_addr = (text_addr << 4) + fromhex (*ptr++);
3296 if (startswith (ptr, ";DataSeg="))
3299 while (*ptr && *ptr != ';')
3300 data_addr = (data_addr << 4) + fromhex (*ptr++);
3308 error (_("Malformed response to offset query, %s"), buf);
3309 else if (*ptr != '\0')
3310 warning (_("Target reported unsupported offsets: %s"), buf);
3312 offs = ((struct section_offsets *)
3313 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile->num_sections)));
3314 memcpy (offs, symfile_objfile->section_offsets,
3315 SIZEOF_N_SECTION_OFFSETS (symfile_objfile->num_sections));
3317 data = get_symfile_segment_data (symfile_objfile->obfd);
3318 do_segments = (data != NULL);
3319 do_sections = num_segments == 0;
3321 if (num_segments > 0)
3323 segments[0] = text_addr;
3324 segments[1] = data_addr;
3326 /* If we have two segments, we can still try to relocate everything
3327 by assuming that the .text and .data offsets apply to the whole
3328 text and data segments. Convert the offsets given in the packet
3329 to base addresses for symfile_map_offsets_to_segments. */
3330 else if (data && data->num_segments == 2)
3332 segments[0] = data->segment_bases[0] + text_addr;
3333 segments[1] = data->segment_bases[1] + data_addr;
3336 /* If the object file has only one segment, assume that it is text
3337 rather than data; main programs with no writable data are rare,
3338 but programs with no code are useless. Of course the code might
3339 have ended up in the data segment... to detect that we would need
3340 the permissions here. */
3341 else if (data && data->num_segments == 1)
3343 segments[0] = data->segment_bases[0] + text_addr;
3346 /* There's no way to relocate by segment. */
3352 int ret = symfile_map_offsets_to_segments (symfile_objfile->obfd, data,
3353 offs, num_segments, segments);
3355 if (ret == 0 && !do_sections)
3356 error (_("Can not handle qOffsets TextSeg "
3357 "response with this symbol file"));
3364 free_symfile_segment_data (data);
3368 offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_addr;
3370 /* This is a temporary kludge to force data and bss to use the
3371 same offsets because that's what nlmconv does now. The real
3372 solution requires changes to the stub and remote.c that I
3373 don't have time to do right now. */
3375 offs->offsets[SECT_OFF_DATA (symfile_objfile)] = data_addr;
3376 offs->offsets[SECT_OFF_BSS (symfile_objfile)] = data_addr;
3379 objfile_relocate (symfile_objfile, offs);
3382 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3383 threads we know are stopped already. This is used during the
3384 initial remote connection in non-stop mode --- threads that are
3385 reported as already being stopped are left stopped. */
3388 set_stop_requested_callback (struct thread_info *thread, void *data)
3390 /* If we have a stop reply for this thread, it must be stopped. */
3391 if (peek_stop_reply (thread->ptid))
3392 set_stop_requested (thread->ptid, 1);
3397 /* Send interrupt_sequence to remote target. */
3399 send_interrupt_sequence (void)
3401 struct remote_state *rs = get_remote_state ();
3403 if (interrupt_sequence_mode == interrupt_sequence_control_c)
3404 remote_serial_write ("\x03", 1);
3405 else if (interrupt_sequence_mode == interrupt_sequence_break)
3406 serial_send_break (rs->remote_desc);
3407 else if (interrupt_sequence_mode == interrupt_sequence_break_g)
3409 serial_send_break (rs->remote_desc);
3410 remote_serial_write ("g", 1);
3413 internal_error (__FILE__, __LINE__,
3414 _("Invalid value for interrupt_sequence_mode: %s."),
3415 interrupt_sequence_mode);
3419 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3420 and extract the PTID. Returns NULL_PTID if not found. */
3423 stop_reply_extract_thread (char *stop_reply)
3425 if (stop_reply[0] == 'T' && strlen (stop_reply) > 3)
3429 /* Txx r:val ; r:val (...) */
3432 /* Look for "register" named "thread". */
3437 p1 = strchr (p, ':');
3441 if (strncmp (p, "thread", p1 - p) == 0)
3442 return read_ptid (++p1, &p);
3444 p1 = strchr (p, ';');
3456 /* Determine the remote side's current thread. If we have a stop
3457 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3458 "thread" register we can extract the current thread from. If not,
3459 ask the remote which is the current thread with qC. The former
3460 method avoids a roundtrip. */
3463 get_current_thread (char *wait_status)
3467 /* Note we don't use remote_parse_stop_reply as that makes use of
3468 the target architecture, which we haven't yet fully determined at
3470 if (wait_status != NULL)
3471 ptid = stop_reply_extract_thread (wait_status);
3472 if (ptid_equal (ptid, null_ptid))
3473 ptid = remote_current_thread (inferior_ptid);
3478 /* Query the remote target for which is the current thread/process,
3479 add it to our tables, and update INFERIOR_PTID. The caller is
3480 responsible for setting the state such that the remote end is ready
3481 to return the current thread.
3483 This function is called after handling the '?' or 'vRun' packets,
3484 whose response is a stop reply from which we can also try
3485 extracting the thread. If the target doesn't support the explicit
3486 qC query, we infer the current thread from that stop reply, passed
3487 in in WAIT_STATUS, which may be NULL. */
3490 add_current_inferior_and_thread (char *wait_status)
3492 struct remote_state *rs = get_remote_state ();
3494 ptid_t ptid = null_ptid;
3496 inferior_ptid = null_ptid;
3498 /* Now, if we have thread information, update inferior_ptid. */
3499 ptid = get_current_thread (wait_status);
3501 if (!ptid_equal (ptid, null_ptid))
3503 if (!remote_multi_process_p (rs))
3506 inferior_ptid = ptid;
3510 /* Without this, some commands which require an active target
3511 (such as kill) won't work. This variable serves (at least)
3512 double duty as both the pid of the target process (if it has
3513 such), and as a flag indicating that a target is active. */
3514 inferior_ptid = magic_null_ptid;
3518 remote_add_inferior (fake_pid_p, ptid_get_pid (inferior_ptid), -1, 1);
3520 /* Add the main thread. */
3521 add_thread_silent (inferior_ptid);
3525 remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
3527 struct remote_state *rs = get_remote_state ();
3528 struct packet_config *noack_config;
3529 char *wait_status = NULL;
3531 immediate_quit++; /* Allow user to interrupt it. */
3534 if (interrupt_on_connect)
3535 send_interrupt_sequence ();
3537 /* Ack any packet which the remote side has already sent. */
3538 serial_write (rs->remote_desc, "+", 1);
3540 /* Signal other parts that we're going through the initial setup,
3541 and so things may not be stable yet. */
3542 rs->starting_up = 1;
3544 /* The first packet we send to the target is the optional "supported
3545 packets" request. If the target can answer this, it will tell us
3546 which later probes to skip. */
3547 remote_query_supported ();
3549 /* If the stub wants to get a QAllow, compose one and send it. */
3550 if (packet_support (PACKET_QAllow) != PACKET_DISABLE)
3551 remote_set_permissions (target);
3553 /* Next, we possibly activate noack mode.
3555 If the QStartNoAckMode packet configuration is set to AUTO,
3556 enable noack mode if the stub reported a wish for it with
3559 If set to TRUE, then enable noack mode even if the stub didn't
3560 report it in qSupported. If the stub doesn't reply OK, the
3561 session ends with an error.
3563 If FALSE, then don't activate noack mode, regardless of what the
3564 stub claimed should be the default with qSupported. */
3566 noack_config = &remote_protocol_packets[PACKET_QStartNoAckMode];
3567 if (packet_config_support (noack_config) != PACKET_DISABLE)
3569 putpkt ("QStartNoAckMode");
3570 getpkt (&rs->buf, &rs->buf_size, 0);
3571 if (packet_ok (rs->buf, noack_config) == PACKET_OK)
3577 /* Tell the remote that we are using the extended protocol. */
3579 getpkt (&rs->buf, &rs->buf_size, 0);
3582 /* Let the target know which signals it is allowed to pass down to
3584 update_signals_program_target ();
3586 /* Next, if the target can specify a description, read it. We do
3587 this before anything involving memory or registers. */
3588 target_find_description ();
3590 /* Next, now that we know something about the target, update the
3591 address spaces in the program spaces. */
3592 update_address_spaces ();
3594 /* On OSs where the list of libraries is global to all
3595 processes, we fetch them early. */
3596 if (gdbarch_has_global_solist (target_gdbarch ()))
3597 solib_add (NULL, from_tty, target, auto_solib_add);
3601 if (packet_support (PACKET_QNonStop) != PACKET_ENABLE)
3602 error (_("Non-stop mode requested, but remote "
3603 "does not support non-stop"));
3605 putpkt ("QNonStop:1");
3606 getpkt (&rs->buf, &rs->buf_size, 0);
3608 if (strcmp (rs->buf, "OK") != 0)
3609 error (_("Remote refused setting non-stop mode with: %s"), rs->buf);
3611 /* Find about threads and processes the stub is already
3612 controlling. We default to adding them in the running state.
3613 The '?' query below will then tell us about which threads are
3615 remote_update_thread_list (target);
3617 else if (packet_support (PACKET_QNonStop) == PACKET_ENABLE)
3619 /* Don't assume that the stub can operate in all-stop mode.
3620 Request it explicitly. */
3621 putpkt ("QNonStop:0");
3622 getpkt (&rs->buf, &rs->buf_size, 0);
3624 if (strcmp (rs->buf, "OK") != 0)
3625 error (_("Remote refused setting all-stop mode with: %s"), rs->buf);
3628 /* Upload TSVs regardless of whether the target is running or not. The
3629 remote stub, such as GDBserver, may have some predefined or builtin
3630 TSVs, even if the target is not running. */
3631 if (remote_get_trace_status (target, current_trace_status ()) != -1)
3633 struct uploaded_tsv *uploaded_tsvs = NULL;
3635 remote_upload_trace_state_variables (target, &uploaded_tsvs);
3636 merge_uploaded_trace_state_variables (&uploaded_tsvs);
3639 /* Check whether the target is running now. */
3641 getpkt (&rs->buf, &rs->buf_size, 0);
3647 struct inferior *inf;
3649 if (rs->buf[0] == 'W' || rs->buf[0] == 'X')
3652 error (_("The target is not running (try extended-remote?)"));
3654 /* We're connected, but not running. Drop out before we
3655 call start_remote. */
3656 rs->starting_up = 0;
3661 /* Save the reply for later. */
3662 wait_status = alloca (strlen (rs->buf) + 1);
3663 strcpy (wait_status, rs->buf);
3666 /* Fetch thread list. */
3667 target_update_thread_list ();
3669 /* Let the stub know that we want it to return the thread. */
3670 set_continue_thread (minus_one_ptid);
3672 if (thread_count () == 0)
3674 /* Target has no concept of threads at all. GDB treats
3675 non-threaded target as single-threaded; add a main
3677 add_current_inferior_and_thread (wait_status);
3681 /* We have thread information; select the thread the target
3682 says should be current. If we're reconnecting to a
3683 multi-threaded program, this will ideally be the thread
3684 that last reported an event before GDB disconnected. */
3685 inferior_ptid = get_current_thread (wait_status);
3686 if (ptid_equal (inferior_ptid, null_ptid))
3688 /* Odd... The target was able to list threads, but not
3689 tell us which thread was current (no "thread"
3690 register in T stop reply?). Just pick the first
3691 thread in the thread list then. */
3692 inferior_ptid = thread_list->ptid;
3696 /* init_wait_for_inferior should be called before get_offsets in order
3697 to manage `inserted' flag in bp loc in a correct state.
3698 breakpoint_init_inferior, called from init_wait_for_inferior, set
3699 `inserted' flag to 0, while before breakpoint_re_set, called from
3700 start_remote, set `inserted' flag to 1. In the initialization of
3701 inferior, breakpoint_init_inferior should be called first, and then
3702 breakpoint_re_set can be called. If this order is broken, state of
3703 `inserted' flag is wrong, and cause some problems on breakpoint
3705 init_wait_for_inferior ();
3707 get_offsets (); /* Get text, data & bss offsets. */
3709 /* If we could not find a description using qXfer, and we know
3710 how to do it some other way, try again. This is not
3711 supported for non-stop; it could be, but it is tricky if
3712 there are no stopped threads when we connect. */
3713 if (remote_read_description_p (target)
3714 && gdbarch_target_desc (target_gdbarch ()) == NULL)
3716 target_clear_description ();
3717 target_find_description ();
3720 /* Use the previously fetched status. */
3721 gdb_assert (wait_status != NULL);
3722 strcpy (rs->buf, wait_status);
3723 rs->cached_wait_status = 1;
3726 start_remote (from_tty); /* Initialize gdb process mechanisms. */
3730 /* Clear WFI global state. Do this before finding about new
3731 threads and inferiors, and setting the current inferior.
3732 Otherwise we would clear the proceed status of the current
3733 inferior when we want its stop_soon state to be preserved
3734 (see notice_new_inferior). */
3735 init_wait_for_inferior ();
3737 /* In non-stop, we will either get an "OK", meaning that there
3738 are no stopped threads at this time; or, a regular stop
3739 reply. In the latter case, there may be more than one thread
3740 stopped --- we pull them all out using the vStopped
3742 if (strcmp (rs->buf, "OK") != 0)
3744 struct notif_client *notif = ¬if_client_stop;
3746 /* remote_notif_get_pending_replies acks this one, and gets
3748 rs->notif_state->pending_event[notif_client_stop.id]
3749 = remote_notif_parse (notif, rs->buf);
3750 remote_notif_get_pending_events (notif);
3752 /* Make sure that threads that were stopped remain
3754 iterate_over_threads (set_stop_requested_callback, NULL);
3757 if (target_can_async_p ())
3760 if (thread_count () == 0)
3763 error (_("The target is not running (try extended-remote?)"));
3765 /* We're connected, but not running. Drop out before we
3766 call start_remote. */
3767 rs->starting_up = 0;
3771 /* Let the stub know that we want it to return the thread. */
3773 /* Force the stub to choose a thread. */
3774 set_general_thread (null_ptid);
3777 inferior_ptid = remote_current_thread (minus_one_ptid);
3778 if (ptid_equal (inferior_ptid, minus_one_ptid))
3779 error (_("remote didn't report the current thread in non-stop mode"));
3781 get_offsets (); /* Get text, data & bss offsets. */
3783 /* In non-stop mode, any cached wait status will be stored in
3784 the stop reply queue. */
3785 gdb_assert (wait_status == NULL);
3787 /* Report all signals during attach/startup. */
3788 remote_pass_signals (target, 0, NULL);
3791 /* If we connected to a live target, do some additional setup. */
3792 if (target_has_execution)
3794 if (symfile_objfile) /* No use without a symbol-file. */
3795 remote_check_symbols ();
3798 /* Possibly the target has been engaged in a trace run started
3799 previously; find out where things are at. */
3800 if (remote_get_trace_status (target, current_trace_status ()) != -1)
3802 struct uploaded_tp *uploaded_tps = NULL;
3804 if (current_trace_status ()->running)
3805 printf_filtered (_("Trace is already running on the target.\n"));
3807 remote_upload_tracepoints (target, &uploaded_tps);
3809 merge_uploaded_tracepoints (&uploaded_tps);
3812 /* The thread and inferior lists are now synchronized with the
3813 target, our symbols have been relocated, and we're merged the
3814 target's tracepoints with ours. We're done with basic start
3816 rs->starting_up = 0;
3818 /* Maybe breakpoints are global and need to be inserted now. */
3819 if (breakpoints_should_be_inserted_now ())
3820 insert_breakpoints ();
3823 /* Open a connection to a remote debugger.
3824 NAME is the filename used for communication. */
3827 remote_open (const char *name, int from_tty)
3829 remote_open_1 (name, from_tty, &remote_ops, 0);
3832 /* Open a connection to a remote debugger using the extended
3833 remote gdb protocol. NAME is the filename used for communication. */
3836 extended_remote_open (const char *name, int from_tty)
3838 remote_open_1 (name, from_tty, &extended_remote_ops, 1 /*extended_p */);
3841 /* Reset all packets back to "unknown support". Called when opening a
3842 new connection to a remote target. */
3845 reset_all_packet_configs_support (void)
3849 for (i = 0; i < PACKET_MAX; i++)
3850 remote_protocol_packets[i].support = PACKET_SUPPORT_UNKNOWN;
3853 /* Initialize all packet configs. */
3856 init_all_packet_configs (void)
3860 for (i = 0; i < PACKET_MAX; i++)
3862 remote_protocol_packets[i].detect = AUTO_BOOLEAN_AUTO;
3863 remote_protocol_packets[i].support = PACKET_SUPPORT_UNKNOWN;
3867 /* Symbol look-up. */
3870 remote_check_symbols (void)
3872 struct remote_state *rs = get_remote_state ();
3873 char *msg, *reply, *tmp;
3874 struct bound_minimal_symbol sym;
3877 /* The remote side has no concept of inferiors that aren't running
3878 yet, it only knows about running processes. If we're connected
3879 but our current inferior is not running, we should not invite the
3880 remote target to request symbol lookups related to its
3881 (unrelated) current process. */
3882 if (!target_has_execution)
3885 if (packet_support (PACKET_qSymbol) == PACKET_DISABLE)
3888 /* Make sure the remote is pointing at the right process. Note
3889 there's no way to select "no process". */
3890 set_general_process ();
3892 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3893 because we need both at the same time. */
3894 msg = alloca (get_remote_packet_size ());
3896 /* Invite target to request symbol lookups. */
3898 putpkt ("qSymbol::");
3899 getpkt (&rs->buf, &rs->buf_size, 0);
3900 packet_ok (rs->buf, &remote_protocol_packets[PACKET_qSymbol]);
3903 while (startswith (reply, "qSymbol:"))
3905 struct bound_minimal_symbol sym;
3908 end = hex2bin (tmp, (gdb_byte *) msg, strlen (tmp) / 2);
3910 sym = lookup_minimal_symbol (msg, NULL, NULL);
3911 if (sym.minsym == NULL)
3912 xsnprintf (msg, get_remote_packet_size (), "qSymbol::%s", &reply[8]);
3915 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
3916 CORE_ADDR sym_addr = BMSYMBOL_VALUE_ADDRESS (sym);
3918 /* If this is a function address, return the start of code
3919 instead of any data function descriptor. */
3920 sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3924 xsnprintf (msg, get_remote_packet_size (), "qSymbol:%s:%s",
3925 phex_nz (sym_addr, addr_size), &reply[8]);
3929 getpkt (&rs->buf, &rs->buf_size, 0);
3934 static struct serial *
3935 remote_serial_open (const char *name)
3937 static int udp_warning = 0;
3939 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3940 of in ser-tcp.c, because it is the remote protocol assuming that the
3941 serial connection is reliable and not the serial connection promising
3943 if (!udp_warning && startswith (name, "udp:"))
3945 warning (_("The remote protocol may be unreliable over UDP.\n"
3946 "Some events may be lost, rendering further debugging "
3951 return serial_open (name);
3954 /* Inform the target of our permission settings. The permission flags
3955 work without this, but if the target knows the settings, it can do
3956 a couple things. First, it can add its own check, to catch cases
3957 that somehow manage to get by the permissions checks in target
3958 methods. Second, if the target is wired to disallow particular
3959 settings (for instance, a system in the field that is not set up to
3960 be able to stop at a breakpoint), it can object to any unavailable
3964 remote_set_permissions (struct target_ops *self)
3966 struct remote_state *rs = get_remote_state ();
3968 xsnprintf (rs->buf, get_remote_packet_size (), "QAllow:"
3969 "WriteReg:%x;WriteMem:%x;"
3970 "InsertBreak:%x;InsertTrace:%x;"
3971 "InsertFastTrace:%x;Stop:%x",
3972 may_write_registers, may_write_memory,
3973 may_insert_breakpoints, may_insert_tracepoints,
3974 may_insert_fast_tracepoints, may_stop);
3976 getpkt (&rs->buf, &rs->buf_size, 0);
3978 /* If the target didn't like the packet, warn the user. Do not try
3979 to undo the user's settings, that would just be maddening. */
3980 if (strcmp (rs->buf, "OK") != 0)
3981 warning (_("Remote refused setting permissions with: %s"), rs->buf);
3984 /* This type describes each known response to the qSupported
3986 struct protocol_feature
3988 /* The name of this protocol feature. */
3991 /* The default for this protocol feature. */
3992 enum packet_support default_support;
3994 /* The function to call when this feature is reported, or after
3995 qSupported processing if the feature is not supported.
3996 The first argument points to this structure. The second
3997 argument indicates whether the packet requested support be
3998 enabled, disabled, or probed (or the default, if this function
3999 is being called at the end of processing and this feature was
4000 not reported). The third argument may be NULL; if not NULL, it
4001 is a NUL-terminated string taken from the packet following
4002 this feature's name and an equals sign. */
4003 void (*func) (const struct protocol_feature *, enum packet_support,
4006 /* The corresponding packet for this feature. Only used if
4007 FUNC is remote_supported_packet. */
4012 remote_supported_packet (const struct protocol_feature *feature,
4013 enum packet_support support,
4014 const char *argument)
4018 warning (_("Remote qSupported response supplied an unexpected value for"
4019 " \"%s\"."), feature->name);
4023 remote_protocol_packets[feature->packet].support = support;
4027 remote_packet_size (const struct protocol_feature *feature,
4028 enum packet_support support, const char *value)
4030 struct remote_state *rs = get_remote_state ();
4035 if (support != PACKET_ENABLE)
4038 if (value == NULL || *value == '\0')
4040 warning (_("Remote target reported \"%s\" without a size."),
4046 packet_size = strtol (value, &value_end, 16);
4047 if (errno != 0 || *value_end != '\0' || packet_size < 0)
4049 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4050 feature->name, value);
4054 if (packet_size > MAX_REMOTE_PACKET_SIZE)
4056 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
4057 packet_size, MAX_REMOTE_PACKET_SIZE);
4058 packet_size = MAX_REMOTE_PACKET_SIZE;
4061 /* Record the new maximum packet size. */
4062 rs->explicit_packet_size = packet_size;
4065 static const struct protocol_feature remote_protocol_features[] = {
4066 { "PacketSize", PACKET_DISABLE, remote_packet_size, -1 },
4067 { "qXfer:auxv:read", PACKET_DISABLE, remote_supported_packet,
4068 PACKET_qXfer_auxv },
4069 { "qXfer:exec-file:read", PACKET_DISABLE, remote_supported_packet,
4070 PACKET_qXfer_exec_file },
4071 { "qXfer:features:read", PACKET_DISABLE, remote_supported_packet,
4072 PACKET_qXfer_features },
4073 { "qXfer:libraries:read", PACKET_DISABLE, remote_supported_packet,
4074 PACKET_qXfer_libraries },
4075 { "qXfer:libraries-svr4:read", PACKET_DISABLE, remote_supported_packet,
4076 PACKET_qXfer_libraries_svr4 },
4077 { "augmented-libraries-svr4-read", PACKET_DISABLE,
4078 remote_supported_packet, PACKET_augmented_libraries_svr4_read_feature },
4079 { "qXfer:memory-map:read", PACKET_DISABLE, remote_supported_packet,
4080 PACKET_qXfer_memory_map },
4081 { "qXfer:spu:read", PACKET_DISABLE, remote_supported_packet,
4082 PACKET_qXfer_spu_read },
4083 { "qXfer:spu:write", PACKET_DISABLE, remote_supported_packet,
4084 PACKET_qXfer_spu_write },
4085 { "qXfer:osdata:read", PACKET_DISABLE, remote_supported_packet,
4086 PACKET_qXfer_osdata },
4087 { "qXfer:threads:read", PACKET_DISABLE, remote_supported_packet,
4088 PACKET_qXfer_threads },
4089 { "qXfer:traceframe-info:read", PACKET_DISABLE, remote_supported_packet,
4090 PACKET_qXfer_traceframe_info },
4091 { "QPassSignals", PACKET_DISABLE, remote_supported_packet,
4092 PACKET_QPassSignals },
4093 { "QProgramSignals", PACKET_DISABLE, remote_supported_packet,
4094 PACKET_QProgramSignals },
4095 { "QStartNoAckMode", PACKET_DISABLE, remote_supported_packet,
4096 PACKET_QStartNoAckMode },
4097 { "multiprocess", PACKET_DISABLE, remote_supported_packet,
4098 PACKET_multiprocess_feature },
4099 { "QNonStop", PACKET_DISABLE, remote_supported_packet, PACKET_QNonStop },
4100 { "qXfer:siginfo:read", PACKET_DISABLE, remote_supported_packet,
4101 PACKET_qXfer_siginfo_read },
4102 { "qXfer:siginfo:write", PACKET_DISABLE, remote_supported_packet,
4103 PACKET_qXfer_siginfo_write },
4104 { "ConditionalTracepoints", PACKET_DISABLE, remote_supported_packet,
4105 PACKET_ConditionalTracepoints },
4106 { "ConditionalBreakpoints", PACKET_DISABLE, remote_supported_packet,
4107 PACKET_ConditionalBreakpoints },
4108 { "BreakpointCommands", PACKET_DISABLE, remote_supported_packet,
4109 PACKET_BreakpointCommands },
4110 { "FastTracepoints", PACKET_DISABLE, remote_supported_packet,
4111 PACKET_FastTracepoints },
4112 { "StaticTracepoints", PACKET_DISABLE, remote_supported_packet,
4113 PACKET_StaticTracepoints },
4114 {"InstallInTrace", PACKET_DISABLE, remote_supported_packet,
4115 PACKET_InstallInTrace},
4116 { "DisconnectedTracing", PACKET_DISABLE, remote_supported_packet,
4117 PACKET_DisconnectedTracing_feature },
4118 { "ReverseContinue", PACKET_DISABLE, remote_supported_packet,
4120 { "ReverseStep", PACKET_DISABLE, remote_supported_packet,
4122 { "TracepointSource", PACKET_DISABLE, remote_supported_packet,
4123 PACKET_TracepointSource },
4124 { "QAllow", PACKET_DISABLE, remote_supported_packet,
4126 { "EnableDisableTracepoints", PACKET_DISABLE, remote_supported_packet,
4127 PACKET_EnableDisableTracepoints_feature },
4128 { "qXfer:fdpic:read", PACKET_DISABLE, remote_supported_packet,
4129 PACKET_qXfer_fdpic },
4130 { "qXfer:uib:read", PACKET_DISABLE, remote_supported_packet,
4132 { "QDisableRandomization", PACKET_DISABLE, remote_supported_packet,
4133 PACKET_QDisableRandomization },
4134 { "QAgent", PACKET_DISABLE, remote_supported_packet, PACKET_QAgent},
4135 { "QTBuffer:size", PACKET_DISABLE,
4136 remote_supported_packet, PACKET_QTBuffer_size},
4137 { "tracenz", PACKET_DISABLE, remote_supported_packet, PACKET_tracenz_feature },
4138 { "Qbtrace:off", PACKET_DISABLE, remote_supported_packet, PACKET_Qbtrace_off },
4139 { "Qbtrace:bts", PACKET_DISABLE, remote_supported_packet, PACKET_Qbtrace_bts },
4140 { "qXfer:btrace:read", PACKET_DISABLE, remote_supported_packet,
4141 PACKET_qXfer_btrace },
4142 { "qXfer:btrace-conf:read", PACKET_DISABLE, remote_supported_packet,
4143 PACKET_qXfer_btrace_conf },
4144 { "Qbtrace-conf:bts:size", PACKET_DISABLE, remote_supported_packet,
4145 PACKET_Qbtrace_conf_bts_size },
4146 { "swbreak", PACKET_DISABLE, remote_supported_packet, PACKET_swbreak_feature },
4147 { "hwbreak", PACKET_DISABLE, remote_supported_packet, PACKET_hwbreak_feature },
4148 { "fork-events", PACKET_DISABLE, remote_supported_packet,
4149 PACKET_fork_event_feature },
4150 { "vfork-events", PACKET_DISABLE, remote_supported_packet,
4151 PACKET_vfork_event_feature },
4154 static char *remote_support_xml;
4156 /* Register string appended to "xmlRegisters=" in qSupported query. */
4159 register_remote_support_xml (const char *xml)
4161 #if defined(HAVE_LIBEXPAT)
4162 if (remote_support_xml == NULL)
4163 remote_support_xml = concat ("xmlRegisters=", xml, (char *) NULL);
4166 char *copy = xstrdup (remote_support_xml + 13);
4167 char *p = strtok (copy, ",");
4171 if (strcmp (p, xml) == 0)
4178 while ((p = strtok (NULL, ",")) != NULL);
4181 remote_support_xml = reconcat (remote_support_xml,
4182 remote_support_xml, ",", xml,
4189 remote_query_supported_append (char *msg, const char *append)
4192 return reconcat (msg, msg, ";", append, (char *) NULL);
4194 return xstrdup (append);
4198 remote_query_supported (void)
4200 struct remote_state *rs = get_remote_state ();
4203 unsigned char seen [ARRAY_SIZE (remote_protocol_features)];
4205 /* The packet support flags are handled differently for this packet
4206 than for most others. We treat an error, a disabled packet, and
4207 an empty response identically: any features which must be reported
4208 to be used will be automatically disabled. An empty buffer
4209 accomplishes this, since that is also the representation for a list
4210 containing no features. */
4213 if (packet_support (PACKET_qSupported) != PACKET_DISABLE)
4216 struct cleanup *old_chain = make_cleanup (free_current_contents, &q);
4218 q = remote_query_supported_append (q, "multiprocess+");
4220 if (packet_set_cmd_state (PACKET_swbreak_feature) != AUTO_BOOLEAN_FALSE)
4221 q = remote_query_supported_append (q, "swbreak+");
4222 if (packet_set_cmd_state (PACKET_hwbreak_feature) != AUTO_BOOLEAN_FALSE)
4223 q = remote_query_supported_append (q, "hwbreak+");
4225 if (remote_support_xml)
4226 q = remote_query_supported_append (q, remote_support_xml);
4228 q = remote_query_supported_append (q, "qRelocInsn+");
4232 if (packet_set_cmd_state (PACKET_fork_event_feature)
4233 != AUTO_BOOLEAN_FALSE)
4234 q = remote_query_supported_append (q, "fork-events+");
4235 if (packet_set_cmd_state (PACKET_vfork_event_feature)
4236 != AUTO_BOOLEAN_FALSE)
4237 q = remote_query_supported_append (q, "vfork-events+");
4240 q = reconcat (q, "qSupported:", q, (char *) NULL);
4243 do_cleanups (old_chain);
4245 getpkt (&rs->buf, &rs->buf_size, 0);
4247 /* If an error occured, warn, but do not return - just reset the
4248 buffer to empty and go on to disable features. */
4249 if (packet_ok (rs->buf, &remote_protocol_packets[PACKET_qSupported])
4252 warning (_("Remote failure reply: %s"), rs->buf);
4257 memset (seen, 0, sizeof (seen));
4262 enum packet_support is_supported;
4263 char *p, *end, *name_end, *value;
4265 /* First separate out this item from the rest of the packet. If
4266 there's another item after this, we overwrite the separator
4267 (terminated strings are much easier to work with). */
4269 end = strchr (p, ';');
4272 end = p + strlen (p);
4282 warning (_("empty item in \"qSupported\" response"));
4287 name_end = strchr (p, '=');
4290 /* This is a name=value entry. */
4291 is_supported = PACKET_ENABLE;
4292 value = name_end + 1;
4301 is_supported = PACKET_ENABLE;
4305 is_supported = PACKET_DISABLE;
4309 is_supported = PACKET_SUPPORT_UNKNOWN;
4313 warning (_("unrecognized item \"%s\" "
4314 "in \"qSupported\" response"), p);
4320 for (i = 0; i < ARRAY_SIZE (remote_protocol_features); i++)
4321 if (strcmp (remote_protocol_features[i].name, p) == 0)
4323 const struct protocol_feature *feature;
4326 feature = &remote_protocol_features[i];
4327 feature->func (feature, is_supported, value);
4332 /* If we increased the packet size, make sure to increase the global
4333 buffer size also. We delay this until after parsing the entire
4334 qSupported packet, because this is the same buffer we were
4336 if (rs->buf_size < rs->explicit_packet_size)
4338 rs->buf_size = rs->explicit_packet_size;
4339 rs->buf = xrealloc (rs->buf, rs->buf_size);
4342 /* Handle the defaults for unmentioned features. */
4343 for (i = 0; i < ARRAY_SIZE (remote_protocol_features); i++)
4346 const struct protocol_feature *feature;
4348 feature = &remote_protocol_features[i];
4349 feature->func (feature, feature->default_support, NULL);
4353 /* Remove any of the remote.c targets from target stack. Upper targets depend
4354 on it so remove them first. */
4357 remote_unpush_target (void)
4359 pop_all_targets_above (process_stratum - 1);
4363 remote_open_1 (const char *name, int from_tty,
4364 struct target_ops *target, int extended_p)
4366 struct remote_state *rs = get_remote_state ();
4369 error (_("To open a remote debug connection, you need to specify what\n"
4370 "serial device is attached to the remote system\n"
4371 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4373 /* See FIXME above. */
4374 if (!target_async_permitted)
4375 wait_forever_enabled_p = 1;
4377 /* If we're connected to a running target, target_preopen will kill it.
4378 Ask this question first, before target_preopen has a chance to kill
4380 if (rs->remote_desc != NULL && !have_inferiors ())
4383 && !query (_("Already connected to a remote target. Disconnect? ")))
4384 error (_("Still connected."));
4387 /* Here the possibly existing remote target gets unpushed. */
4388 target_preopen (from_tty);
4390 /* Make sure we send the passed signals list the next time we resume. */
4391 xfree (rs->last_pass_packet);
4392 rs->last_pass_packet = NULL;
4394 /* Make sure we send the program signals list the next time we
4396 xfree (rs->last_program_signals_packet);
4397 rs->last_program_signals_packet = NULL;
4399 remote_fileio_reset ();
4400 reopen_exec_file ();
4403 rs->remote_desc = remote_serial_open (name);
4404 if (!rs->remote_desc)
4405 perror_with_name (name);
4407 if (baud_rate != -1)
4409 if (serial_setbaudrate (rs->remote_desc, baud_rate))
4411 /* The requested speed could not be set. Error out to
4412 top level after closing remote_desc. Take care to
4413 set remote_desc to NULL to avoid closing remote_desc
4415 serial_close (rs->remote_desc);
4416 rs->remote_desc = NULL;
4417 perror_with_name (name);
4421 serial_setparity (rs->remote_desc, serial_parity);
4422 serial_raw (rs->remote_desc);
4424 /* If there is something sitting in the buffer we might take it as a
4425 response to a command, which would be bad. */
4426 serial_flush_input (rs->remote_desc);
4430 puts_filtered ("Remote debugging using ");
4431 puts_filtered (name);
4432 puts_filtered ("\n");
4434 push_target (target); /* Switch to using remote target now. */
4436 /* Register extra event sources in the event loop. */
4437 remote_async_inferior_event_token
4438 = create_async_event_handler (remote_async_inferior_event_handler,
4440 rs->notif_state = remote_notif_state_allocate ();
4442 /* Reset the target state; these things will be queried either by
4443 remote_query_supported or as they are needed. */
4444 reset_all_packet_configs_support ();
4445 rs->cached_wait_status = 0;
4446 rs->explicit_packet_size = 0;
4448 rs->extended = extended_p;
4449 rs->waiting_for_stop_reply = 0;
4450 rs->ctrlc_pending_p = 0;
4452 rs->general_thread = not_sent_ptid;
4453 rs->continue_thread = not_sent_ptid;
4454 rs->remote_traceframe_number = -1;
4456 /* Probe for ability to use "ThreadInfo" query, as required. */
4457 rs->use_threadinfo_query = 1;
4458 rs->use_threadextra_query = 1;
4460 if (target_async_permitted)
4462 /* With this target we start out by owning the terminal. */
4463 remote_async_terminal_ours_p = 1;
4465 /* FIXME: cagney/1999-09-23: During the initial connection it is
4466 assumed that the target is already ready and able to respond to
4467 requests. Unfortunately remote_start_remote() eventually calls
4468 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4469 around this. Eventually a mechanism that allows
4470 wait_for_inferior() to expect/get timeouts will be
4472 wait_forever_enabled_p = 0;
4475 /* First delete any symbols previously loaded from shared libraries. */
4476 no_shared_libraries (NULL, 0);
4479 init_thread_list ();
4481 /* Start the remote connection. If error() or QUIT, discard this
4482 target (we'd otherwise be in an inconsistent state) and then
4483 propogate the error on up the exception chain. This ensures that
4484 the caller doesn't stumble along blindly assuming that the
4485 function succeeded. The CLI doesn't have this problem but other
4486 UI's, such as MI do.
4488 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4489 this function should return an error indication letting the
4490 caller restore the previous state. Unfortunately the command
4491 ``target remote'' is directly wired to this function making that
4492 impossible. On a positive note, the CLI side of this problem has
4493 been fixed - the function set_cmd_context() makes it possible for
4494 all the ``target ....'' commands to share a common callback
4495 function. See cli-dump.c. */
4500 remote_start_remote (from_tty, target, extended_p);
4502 CATCH (ex, RETURN_MASK_ALL)
4504 /* Pop the partially set up target - unless something else did
4505 already before throwing the exception. */
4506 if (rs->remote_desc != NULL)
4507 remote_unpush_target ();
4508 if (target_async_permitted)
4509 wait_forever_enabled_p = 1;
4510 throw_exception (ex);
4515 remote_btrace_reset ();
4517 if (target_async_permitted)
4518 wait_forever_enabled_p = 1;
4521 /* Detach the specified process. */
4524 remote_detach_pid (int pid)
4526 struct remote_state *rs = get_remote_state ();
4528 if (remote_multi_process_p (rs))
4529 xsnprintf (rs->buf, get_remote_packet_size (), "D;%x", pid);
4531 strcpy (rs->buf, "D");
4534 getpkt (&rs->buf, &rs->buf_size, 0);
4536 if (rs->buf[0] == 'O' && rs->buf[1] == 'K')
4538 else if (rs->buf[0] == '\0')
4539 error (_("Remote doesn't know how to detach"));
4541 error (_("Can't detach process."));
4544 /* This detaches a program to which we previously attached, using
4545 inferior_ptid to identify the process. After this is done, GDB
4546 can be used to debug some other program. We better not have left
4547 any breakpoints in the target program or it'll die when it hits
4551 remote_detach_1 (const char *args, int from_tty)
4553 int pid = ptid_get_pid (inferior_ptid);
4554 struct remote_state *rs = get_remote_state ();
4555 struct thread_info *tp = find_thread_ptid (inferior_ptid);
4559 error (_("Argument given to \"detach\" when remotely debugging."));
4561 if (!target_has_execution)
4562 error (_("No process to detach from."));
4566 char *exec_file = get_exec_file (0);
4567 if (exec_file == NULL)
4569 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file,
4570 target_pid_to_str (pid_to_ptid (pid)));
4571 gdb_flush (gdb_stdout);
4574 /* Tell the remote target to detach. */
4575 remote_detach_pid (pid);
4577 if (from_tty && !rs->extended)
4578 puts_filtered (_("Ending remote debugging.\n"));
4580 /* Check to see if we are detaching a fork parent. Note that if we
4581 are detaching a fork child, tp == NULL. */
4582 is_fork_parent = (tp != NULL
4583 && tp->pending_follow.kind == TARGET_WAITKIND_FORKED);
4585 /* If doing detach-on-fork, we don't mourn, because that will delete
4586 breakpoints that should be available for the followed inferior. */
4587 if (!is_fork_parent)
4588 target_mourn_inferior ();
4591 inferior_ptid = null_ptid;
4592 detach_inferior (pid);
4597 remote_detach (struct target_ops *ops, const char *args, int from_tty)
4599 remote_detach_1 (args, from_tty);
4603 extended_remote_detach (struct target_ops *ops, const char *args, int from_tty)
4605 remote_detach_1 (args, from_tty);
4608 /* Target follow-fork function for remote targets. On entry, and
4609 at return, the current inferior is the fork parent.
4611 Note that although this is currently only used for extended-remote,
4612 it is named remote_follow_fork in anticipation of using it for the
4613 remote target as well. */
4616 remote_follow_fork (struct target_ops *ops, int follow_child,
4619 struct remote_state *rs = get_remote_state ();
4620 enum target_waitkind kind = inferior_thread ()->pending_follow.kind;
4622 if ((kind == TARGET_WAITKIND_FORKED && remote_fork_event_p (rs))
4623 || (kind == TARGET_WAITKIND_VFORKED && remote_vfork_event_p (rs)))
4625 /* When following the parent and detaching the child, we detach
4626 the child here. For the case of following the child and
4627 detaching the parent, the detach is done in the target-
4628 independent follow fork code in infrun.c. We can't use
4629 target_detach when detaching an unfollowed child because
4630 the client side doesn't know anything about the child. */
4631 if (detach_fork && !follow_child)
4633 /* Detach the fork child. */
4637 child_ptid = inferior_thread ()->pending_follow.value.related_pid;
4638 child_pid = ptid_get_pid (child_ptid);
4640 remote_detach_pid (child_pid);
4641 detach_inferior (child_pid);
4647 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4650 remote_disconnect (struct target_ops *target, const char *args, int from_tty)
4653 error (_("Argument given to \"disconnect\" when remotely debugging."));
4655 /* Make sure we unpush even the extended remote targets; mourn
4656 won't do it. So call remote_mourn directly instead of
4657 target_mourn_inferior. */
4658 remote_mourn (target);
4661 puts_filtered ("Ending remote debugging.\n");
4664 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4665 be chatty about it. */
4668 extended_remote_attach (struct target_ops *target, const char *args,
4671 struct remote_state *rs = get_remote_state ();
4673 char *wait_status = NULL;
4675 pid = parse_pid_to_attach (args);
4677 /* Remote PID can be freely equal to getpid, do not check it here the same
4678 way as in other targets. */
4680 if (packet_support (PACKET_vAttach) == PACKET_DISABLE)
4681 error (_("This target does not support attaching to a process"));
4685 char *exec_file = get_exec_file (0);
4688 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
4689 target_pid_to_str (pid_to_ptid (pid)));
4691 printf_unfiltered (_("Attaching to %s\n"),
4692 target_pid_to_str (pid_to_ptid (pid)));
4694 gdb_flush (gdb_stdout);
4697 xsnprintf (rs->buf, get_remote_packet_size (), "vAttach;%x", pid);
4699 getpkt (&rs->buf, &rs->buf_size, 0);
4701 switch (packet_ok (rs->buf,
4702 &remote_protocol_packets[PACKET_vAttach]))
4707 /* Save the reply for later. */
4708 wait_status = alloca (strlen (rs->buf) + 1);
4709 strcpy (wait_status, rs->buf);
4711 else if (strcmp (rs->buf, "OK") != 0)
4712 error (_("Attaching to %s failed with: %s"),
4713 target_pid_to_str (pid_to_ptid (pid)),
4716 case PACKET_UNKNOWN:
4717 error (_("This target does not support attaching to a process"));
4719 error (_("Attaching to %s failed"),
4720 target_pid_to_str (pid_to_ptid (pid)));
4723 set_current_inferior (remote_add_inferior (0, pid, 1, 0));
4725 inferior_ptid = pid_to_ptid (pid);
4729 struct thread_info *thread;
4731 /* Get list of threads. */
4732 remote_update_thread_list (target);
4734 thread = first_thread_of_process (pid);
4736 inferior_ptid = thread->ptid;
4738 inferior_ptid = pid_to_ptid (pid);
4740 /* Invalidate our notion of the remote current thread. */
4741 record_currthread (rs, minus_one_ptid);
4745 /* Now, if we have thread information, update inferior_ptid. */
4746 inferior_ptid = remote_current_thread (inferior_ptid);
4748 /* Add the main thread to the thread list. */
4749 add_thread_silent (inferior_ptid);
4752 /* Next, if the target can specify a description, read it. We do
4753 this before anything involving memory or registers. */
4754 target_find_description ();
4758 /* Use the previously fetched status. */
4759 gdb_assert (wait_status != NULL);
4761 if (target_can_async_p ())
4763 struct notif_event *reply
4764 = remote_notif_parse (¬if_client_stop, wait_status);
4766 push_stop_reply ((struct stop_reply *) reply);
4772 gdb_assert (wait_status != NULL);
4773 strcpy (rs->buf, wait_status);
4774 rs->cached_wait_status = 1;
4778 gdb_assert (wait_status == NULL);
4781 /* Implementation of the to_post_attach method. */
4784 extended_remote_post_attach (struct target_ops *ops, int pid)
4786 /* In certain cases GDB might not have had the chance to start
4787 symbol lookup up until now. This could happen if the debugged
4788 binary is not using shared libraries, the vsyscall page is not
4789 present (on Linux) and the binary itself hadn't changed since the
4790 debugging process was started. */
4791 if (symfile_objfile != NULL)
4792 remote_check_symbols();
4796 /* Check for the availability of vCont. This function should also check
4800 remote_vcont_probe (struct remote_state *rs)
4804 strcpy (rs->buf, "vCont?");
4806 getpkt (&rs->buf, &rs->buf_size, 0);
4809 /* Make sure that the features we assume are supported. */
4810 if (startswith (buf, "vCont"))
4813 int support_s, support_S, support_c, support_C;
4819 rs->supports_vCont.t = 0;
4820 rs->supports_vCont.r = 0;
4821 while (p && *p == ';')
4824 if (*p == 's' && (*(p + 1) == ';' || *(p + 1) == 0))
4826 else if (*p == 'S' && (*(p + 1) == ';' || *(p + 1) == 0))
4828 else if (*p == 'c' && (*(p + 1) == ';' || *(p + 1) == 0))
4830 else if (*p == 'C' && (*(p + 1) == ';' || *(p + 1) == 0))
4832 else if (*p == 't' && (*(p + 1) == ';' || *(p + 1) == 0))
4833 rs->supports_vCont.t = 1;
4834 else if (*p == 'r' && (*(p + 1) == ';' || *(p + 1) == 0))
4835 rs->supports_vCont.r = 1;
4837 p = strchr (p, ';');
4840 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4841 BUF will make packet_ok disable the packet. */
4842 if (!support_s || !support_S || !support_c || !support_C)
4846 packet_ok (buf, &remote_protocol_packets[PACKET_vCont]);
4849 /* Helper function for building "vCont" resumptions. Write a
4850 resumption to P. ENDP points to one-passed-the-end of the buffer
4851 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4852 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4853 resumed thread should be single-stepped and/or signalled. If PTID
4854 equals minus_one_ptid, then all threads are resumed; if PTID
4855 represents a process, then all threads of the process are resumed;
4856 the thread to be stepped and/or signalled is given in the global
4860 append_resumption (char *p, char *endp,
4861 ptid_t ptid, int step, enum gdb_signal siggnal)
4863 struct remote_state *rs = get_remote_state ();
4865 if (step && siggnal != GDB_SIGNAL_0)
4866 p += xsnprintf (p, endp - p, ";S%02x", siggnal);
4868 /* GDB is willing to range step. */
4869 && use_range_stepping
4870 /* Target supports range stepping. */
4871 && rs->supports_vCont.r
4872 /* We don't currently support range stepping multiple
4873 threads with a wildcard (though the protocol allows it,
4874 so stubs shouldn't make an active effort to forbid
4876 && !(remote_multi_process_p (rs) && ptid_is_pid (ptid)))
4878 struct thread_info *tp;
4880 if (ptid_equal (ptid, minus_one_ptid))
4882 /* If we don't know about the target thread's tid, then
4883 we're resuming magic_null_ptid (see caller). */
4884 tp = find_thread_ptid (magic_null_ptid);
4887 tp = find_thread_ptid (ptid);
4888 gdb_assert (tp != NULL);
4890 if (tp->control.may_range_step)
4892 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
4894 p += xsnprintf (p, endp - p, ";r%s,%s",
4895 phex_nz (tp->control.step_range_start,
4897 phex_nz (tp->control.step_range_end,
4901 p += xsnprintf (p, endp - p, ";s");
4904 p += xsnprintf (p, endp - p, ";s");
4905 else if (siggnal != GDB_SIGNAL_0)
4906 p += xsnprintf (p, endp - p, ";C%02x", siggnal);
4908 p += xsnprintf (p, endp - p, ";c");
4910 if (remote_multi_process_p (rs) && ptid_is_pid (ptid))
4914 /* All (-1) threads of process. */
4915 nptid = ptid_build (ptid_get_pid (ptid), -1, 0);
4917 p += xsnprintf (p, endp - p, ":");
4918 p = write_ptid (p, endp, nptid);
4920 else if (!ptid_equal (ptid, minus_one_ptid))
4922 p += xsnprintf (p, endp - p, ":");
4923 p = write_ptid (p, endp, ptid);
4929 /* Append a vCont continue-with-signal action for threads that have a
4930 non-zero stop signal. */
4933 append_pending_thread_resumptions (char *p, char *endp, ptid_t ptid)
4935 struct thread_info *thread;
4937 ALL_NON_EXITED_THREADS (thread)
4938 if (ptid_match (thread->ptid, ptid)
4939 && !ptid_equal (inferior_ptid, thread->ptid)
4940 && thread->suspend.stop_signal != GDB_SIGNAL_0)
4942 p = append_resumption (p, endp, thread->ptid,
4943 0, thread->suspend.stop_signal);
4944 thread->suspend.stop_signal = GDB_SIGNAL_0;
4950 /* Resume the remote inferior by using a "vCont" packet. The thread
4951 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4952 resumed thread should be single-stepped and/or signalled. If PTID
4953 equals minus_one_ptid, then all threads are resumed; the thread to
4954 be stepped and/or signalled is given in the global INFERIOR_PTID.
4955 This function returns non-zero iff it resumes the inferior.
4957 This function issues a strict subset of all possible vCont commands at the
4961 remote_vcont_resume (ptid_t ptid, int step, enum gdb_signal siggnal)
4963 struct remote_state *rs = get_remote_state ();
4967 if (packet_support (PACKET_vCont) == PACKET_SUPPORT_UNKNOWN)
4968 remote_vcont_probe (rs);
4970 if (packet_support (PACKET_vCont) == PACKET_DISABLE)
4974 endp = rs->buf + get_remote_packet_size ();
4976 /* If we could generate a wider range of packets, we'd have to worry
4977 about overflowing BUF. Should there be a generic
4978 "multi-part-packet" packet? */
4980 p += xsnprintf (p, endp - p, "vCont");
4982 if (ptid_equal (ptid, magic_null_ptid))
4984 /* MAGIC_NULL_PTID means that we don't have any active threads,
4985 so we don't have any TID numbers the inferior will
4986 understand. Make sure to only send forms that do not specify
4988 append_resumption (p, endp, minus_one_ptid, step, siggnal);
4990 else if (ptid_equal (ptid, minus_one_ptid) || ptid_is_pid (ptid))
4992 /* Resume all threads (of all processes, or of a single
4993 process), with preference for INFERIOR_PTID. This assumes
4994 inferior_ptid belongs to the set of all threads we are about
4996 if (step || siggnal != GDB_SIGNAL_0)
4998 /* Step inferior_ptid, with or without signal. */
4999 p = append_resumption (p, endp, inferior_ptid, step, siggnal);
5002 /* Also pass down any pending signaled resumption for other
5003 threads not the current. */
5004 p = append_pending_thread_resumptions (p, endp, ptid);
5006 /* And continue others without a signal. */
5007 append_resumption (p, endp, ptid, /*step=*/ 0, GDB_SIGNAL_0);
5011 /* Scheduler locking; resume only PTID. */
5012 append_resumption (p, endp, ptid, step, siggnal);
5015 gdb_assert (strlen (rs->buf) < get_remote_packet_size ());
5020 /* In non-stop, the stub replies to vCont with "OK". The stop
5021 reply will be reported asynchronously by means of a `%Stop'
5023 getpkt (&rs->buf, &rs->buf_size, 0);
5024 if (strcmp (rs->buf, "OK") != 0)
5025 error (_("Unexpected vCont reply in non-stop mode: %s"), rs->buf);
5031 /* Tell the remote machine to resume. */
5034 remote_resume (struct target_ops *ops,
5035 ptid_t ptid, int step, enum gdb_signal siggnal)
5037 struct remote_state *rs = get_remote_state ();
5040 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5041 (explained in remote-notif.c:handle_notification) so
5042 remote_notif_process is not called. We need find a place where
5043 it is safe to start a 'vNotif' sequence. It is good to do it
5044 before resuming inferior, because inferior was stopped and no RSP
5045 traffic at that moment. */
5047 remote_notif_process (rs->notif_state, ¬if_client_stop);
5049 rs->last_sent_signal = siggnal;
5050 rs->last_sent_step = step;
5052 /* The vCont packet doesn't need to specify threads via Hc. */
5053 /* No reverse support (yet) for vCont. */
5054 if (execution_direction != EXEC_REVERSE)
5055 if (remote_vcont_resume (ptid, step, siggnal))
5058 /* All other supported resume packets do use Hc, so set the continue
5060 if (ptid_equal (ptid, minus_one_ptid))
5061 set_continue_thread (any_thread_ptid);
5063 set_continue_thread (ptid);
5066 if (execution_direction == EXEC_REVERSE)
5068 /* We don't pass signals to the target in reverse exec mode. */
5069 if (info_verbose && siggnal != GDB_SIGNAL_0)
5070 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5073 if (step && packet_support (PACKET_bs) == PACKET_DISABLE)
5074 error (_("Remote reverse-step not supported."));
5075 if (!step && packet_support (PACKET_bc) == PACKET_DISABLE)
5076 error (_("Remote reverse-continue not supported."));
5078 strcpy (buf, step ? "bs" : "bc");
5080 else if (siggnal != GDB_SIGNAL_0)
5082 buf[0] = step ? 'S' : 'C';
5083 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
5084 buf[2] = tohex (((int) siggnal) & 0xf);
5088 strcpy (buf, step ? "s" : "c");
5093 /* We are about to start executing the inferior, let's register it
5094 with the event loop. NOTE: this is the one place where all the
5095 execution commands end up. We could alternatively do this in each
5096 of the execution commands in infcmd.c. */
5097 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5098 into infcmd.c in order to allow inferior function calls to work
5099 NOT asynchronously. */
5100 if (target_can_async_p ())
5103 /* We've just told the target to resume. The remote server will
5104 wait for the inferior to stop, and then send a stop reply. In
5105 the mean time, we can't start another command/query ourselves
5106 because the stub wouldn't be ready to process it. This applies
5107 only to the base all-stop protocol, however. In non-stop (which
5108 only supports vCont), the stub replies with an "OK", and is
5109 immediate able to process further serial input. */
5111 rs->waiting_for_stop_reply = 1;
5115 /* Set up the signal handler for SIGINT, while the target is
5116 executing, ovewriting the 'regular' SIGINT signal handler. */
5118 async_initialize_sigint_signal_handler (void)
5120 signal (SIGINT, async_handle_remote_sigint);
5123 /* Signal handler for SIGINT, while the target is executing. */
5125 async_handle_remote_sigint (int sig)
5127 signal (sig, async_handle_remote_sigint_twice);
5128 /* Note we need to go through gdb_call_async_signal_handler in order
5129 to wake up the event loop on Windows. */
5130 gdb_call_async_signal_handler (async_sigint_remote_token, 0);
5133 /* Signal handler for SIGINT, installed after SIGINT has already been
5134 sent once. It will take effect the second time that the user sends
5137 async_handle_remote_sigint_twice (int sig)
5139 signal (sig, async_handle_remote_sigint);
5140 /* See note in async_handle_remote_sigint. */
5141 gdb_call_async_signal_handler (async_sigint_remote_twice_token, 0);
5144 /* Perform the real interruption of the target execution, in response
5147 async_remote_interrupt (gdb_client_data arg)
5150 fprintf_unfiltered (gdb_stdlog, "async_remote_interrupt called\n");
5152 target_stop (inferior_ptid);
5155 /* Perform interrupt, if the first attempt did not succeed. Just give
5156 up on the target alltogether. */
5158 async_remote_interrupt_twice (gdb_client_data arg)
5161 fprintf_unfiltered (gdb_stdlog, "async_remote_interrupt_twice called\n");
5166 /* Reinstall the usual SIGINT handlers, after the target has
5169 async_cleanup_sigint_signal_handler (void *dummy)
5171 signal (SIGINT, handle_sigint);
5174 /* Send ^C to target to halt it. Target will respond, and send us a
5176 static void (*ofunc) (int);
5178 /* The command line interface's stop routine. This function is installed
5179 as a signal handler for SIGINT. The first time a user requests a
5180 stop, we call remote_stop to send a break or ^C. If there is no
5181 response from the target (it didn't stop when the user requested it),
5182 we ask the user if he'd like to detach from the target. */
5184 sync_remote_interrupt (int signo)
5186 /* If this doesn't work, try more severe steps. */
5187 signal (signo, sync_remote_interrupt_twice);
5189 gdb_call_async_signal_handler (async_sigint_remote_token, 1);
5192 /* The user typed ^C twice. */
5195 sync_remote_interrupt_twice (int signo)
5197 signal (signo, ofunc);
5198 gdb_call_async_signal_handler (async_sigint_remote_twice_token, 1);
5199 signal (signo, sync_remote_interrupt);
5202 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5203 thread, all threads of a remote process, or all threads of all
5207 remote_stop_ns (ptid_t ptid)
5209 struct remote_state *rs = get_remote_state ();
5211 char *endp = rs->buf + get_remote_packet_size ();
5213 if (packet_support (PACKET_vCont) == PACKET_SUPPORT_UNKNOWN)
5214 remote_vcont_probe (rs);
5216 if (!rs->supports_vCont.t)
5217 error (_("Remote server does not support stopping threads"));
5219 if (ptid_equal (ptid, minus_one_ptid)
5220 || (!remote_multi_process_p (rs) && ptid_is_pid (ptid)))
5221 p += xsnprintf (p, endp - p, "vCont;t");
5226 p += xsnprintf (p, endp - p, "vCont;t:");
5228 if (ptid_is_pid (ptid))
5229 /* All (-1) threads of process. */
5230 nptid = ptid_build (ptid_get_pid (ptid), -1, 0);
5233 /* Small optimization: if we already have a stop reply for
5234 this thread, no use in telling the stub we want this
5236 if (peek_stop_reply (ptid))
5242 write_ptid (p, endp, nptid);
5245 /* In non-stop, we get an immediate OK reply. The stop reply will
5246 come in asynchronously by notification. */
5248 getpkt (&rs->buf, &rs->buf_size, 0);
5249 if (strcmp (rs->buf, "OK") != 0)
5250 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid), rs->buf);
5253 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5254 remote target. It is undefined which thread of which process
5255 reports the stop. */
5258 remote_stop_as (ptid_t ptid)
5260 struct remote_state *rs = get_remote_state ();
5262 rs->ctrlc_pending_p = 1;
5264 /* If the inferior is stopped already, but the core didn't know
5265 about it yet, just ignore the request. The cached wait status
5266 will be collected in remote_wait. */
5267 if (rs->cached_wait_status)
5270 /* Send interrupt_sequence to remote target. */
5271 send_interrupt_sequence ();
5274 /* This is the generic stop called via the target vector. When a target
5275 interrupt is requested, either by the command line or the GUI, we
5276 will eventually end up here. */
5279 remote_stop (struct target_ops *self, ptid_t ptid)
5282 fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
5285 remote_stop_ns (ptid);
5287 remote_stop_as (ptid);
5290 /* Ask the user what to do when an interrupt is received. */
5293 interrupt_query (void)
5295 target_terminal_ours ();
5297 if (target_is_async_p ())
5299 signal (SIGINT, handle_sigint);
5304 if (query (_("Interrupted while waiting for the program.\n\
5305 Give up (and stop debugging it)? ")))
5307 remote_unpush_target ();
5312 target_terminal_inferior ();
5315 /* Enable/disable target terminal ownership. Most targets can use
5316 terminal groups to control terminal ownership. Remote targets are
5317 different in that explicit transfer of ownership to/from GDB/target
5321 remote_terminal_inferior (struct target_ops *self)
5323 if (!target_async_permitted)
5324 /* Nothing to do. */
5327 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5328 idempotent. The event-loop GDB talking to an asynchronous target
5329 with a synchronous command calls this function from both
5330 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5331 transfer the terminal to the target when it shouldn't this guard
5333 if (!remote_async_terminal_ours_p)
5335 delete_file_handler (input_fd);
5336 remote_async_terminal_ours_p = 0;
5337 async_initialize_sigint_signal_handler ();
5338 /* NOTE: At this point we could also register our selves as the
5339 recipient of all input. Any characters typed could then be
5340 passed on down to the target. */
5344 remote_terminal_ours (struct target_ops *self)
5346 if (!target_async_permitted)
5347 /* Nothing to do. */
5350 /* See FIXME in remote_terminal_inferior. */
5351 if (remote_async_terminal_ours_p)
5353 async_cleanup_sigint_signal_handler (NULL);
5354 add_file_handler (input_fd, stdin_event_handler, 0);
5355 remote_async_terminal_ours_p = 1;
5359 remote_console_output (char *msg)
5363 for (p = msg; p[0] && p[1]; p += 2)
5366 char c = fromhex (p[0]) * 16 + fromhex (p[1]);
5370 fputs_unfiltered (tb, gdb_stdtarg);
5372 gdb_flush (gdb_stdtarg);
5375 typedef struct cached_reg
5378 gdb_byte data[MAX_REGISTER_SIZE];
5381 DEF_VEC_O(cached_reg_t);
5383 typedef struct stop_reply
5385 struct notif_event base;
5387 /* The identifier of the thread about this event */
5390 /* The remote state this event is associated with. When the remote
5391 connection, represented by a remote_state object, is closed,
5392 all the associated stop_reply events should be released. */
5393 struct remote_state *rs;
5395 struct target_waitstatus ws;
5397 /* Expedited registers. This makes remote debugging a bit more
5398 efficient for those targets that provide critical registers as
5399 part of their normal status mechanism (as another roundtrip to
5400 fetch them is avoided). */
5401 VEC(cached_reg_t) *regcache;
5403 enum target_stop_reason stop_reason;
5405 CORE_ADDR watch_data_address;
5410 DECLARE_QUEUE_P (stop_reply_p);
5411 DEFINE_QUEUE_P (stop_reply_p);
5412 /* The list of already fetched and acknowledged stop events. This
5413 queue is used for notification Stop, and other notifications
5414 don't need queue for their events, because the notification events
5415 of Stop can't be consumed immediately, so that events should be
5416 queued first, and be consumed by remote_wait_{ns,as} one per
5417 time. Other notifications can consume their events immediately,
5418 so queue is not needed for them. */
5419 static QUEUE (stop_reply_p) *stop_reply_queue;
5422 stop_reply_xfree (struct stop_reply *r)
5424 notif_event_xfree ((struct notif_event *) r);
5428 remote_notif_stop_parse (struct notif_client *self, char *buf,
5429 struct notif_event *event)
5431 remote_parse_stop_reply (buf, (struct stop_reply *) event);
5435 remote_notif_stop_ack (struct notif_client *self, char *buf,
5436 struct notif_event *event)
5438 struct stop_reply *stop_reply = (struct stop_reply *) event;
5441 putpkt ((char *) self->ack_command);
5443 if (stop_reply->ws.kind == TARGET_WAITKIND_IGNORE)
5444 /* We got an unknown stop reply. */
5445 error (_("Unknown stop reply"));
5447 push_stop_reply (stop_reply);
5451 remote_notif_stop_can_get_pending_events (struct notif_client *self)
5453 /* We can't get pending events in remote_notif_process for
5454 notification stop, and we have to do this in remote_wait_ns
5455 instead. If we fetch all queued events from stub, remote stub
5456 may exit and we have no chance to process them back in
5458 mark_async_event_handler (remote_async_inferior_event_token);
5463 stop_reply_dtr (struct notif_event *event)
5465 struct stop_reply *r = (struct stop_reply *) event;
5467 VEC_free (cached_reg_t, r->regcache);
5470 static struct notif_event *
5471 remote_notif_stop_alloc_reply (void)
5473 struct notif_event *r
5474 = (struct notif_event *) XNEW (struct stop_reply);
5476 r->dtr = stop_reply_dtr;
5481 /* A client of notification Stop. */
5483 struct notif_client notif_client_stop =
5487 remote_notif_stop_parse,
5488 remote_notif_stop_ack,
5489 remote_notif_stop_can_get_pending_events,
5490 remote_notif_stop_alloc_reply,
5494 /* A parameter to pass data in and out. */
5496 struct queue_iter_param
5499 struct stop_reply *output;
5502 /* Determine if THREAD is a pending fork parent thread. ARG contains
5503 the pid of the process that owns the threads we want to check, or
5504 -1 if we want to check all threads. */
5507 is_pending_fork_parent (struct target_waitstatus *ws, int event_pid,
5510 if (ws->kind == TARGET_WAITKIND_FORKED
5511 || ws->kind == TARGET_WAITKIND_VFORKED)
5513 if (event_pid == -1 || event_pid == ptid_get_pid (thread_ptid))
5520 /* Check whether EVENT is a fork event, and if it is, remove the
5521 fork child from the context list passed in DATA. */
5524 remove_child_of_pending_fork (QUEUE (stop_reply_p) *q,
5525 QUEUE_ITER (stop_reply_p) *iter,
5529 struct queue_iter_param *param = data;
5530 struct threads_listing_context *context = param->input;
5532 if (event->ws.kind == TARGET_WAITKIND_FORKED
5533 || event->ws.kind == TARGET_WAITKIND_VFORKED)
5535 threads_listing_context_remove (&event->ws, context);
5541 /* If CONTEXT contains any fork child threads that have not been
5542 reported yet, remove them from the CONTEXT list. If such a
5543 thread exists it is because we are stopped at a fork catchpoint
5544 and have not yet called follow_fork, which will set up the
5545 host-side data structures for the new process. */
5548 remove_new_fork_children (struct threads_listing_context *context)
5550 struct thread_info * thread;
5552 struct notif_client *notif = ¬if_client_stop;
5553 struct queue_iter_param param;
5555 /* For any threads stopped at a fork event, remove the corresponding
5556 fork child threads from the CONTEXT list. */
5557 ALL_NON_EXITED_THREADS (thread)
5559 struct target_waitstatus *ws = &thread->pending_follow;
5561 if (is_pending_fork_parent (ws, pid, thread->ptid))
5563 threads_listing_context_remove (ws, context);
5567 /* Check for any pending fork events (not reported or processed yet)
5568 in process PID and remove those fork child threads from the
5569 CONTEXT list as well. */
5570 remote_notif_get_pending_events (notif);
5571 param.input = context;
5572 param.output = NULL;
5573 QUEUE_iterate (stop_reply_p, stop_reply_queue,
5574 remove_child_of_pending_fork, ¶m);
5577 /* Remove stop replies in the queue if its pid is equal to the given
5581 remove_stop_reply_for_inferior (QUEUE (stop_reply_p) *q,
5582 QUEUE_ITER (stop_reply_p) *iter,
5586 struct queue_iter_param *param = data;
5587 struct inferior *inf = param->input;
5589 if (ptid_get_pid (event->ptid) == inf->pid)
5591 stop_reply_xfree (event);
5592 QUEUE_remove_elem (stop_reply_p, q, iter);
5598 /* Discard all pending stop replies of inferior INF. */
5601 discard_pending_stop_replies (struct inferior *inf)
5604 struct queue_iter_param param;
5605 struct stop_reply *reply;
5606 struct remote_state *rs = get_remote_state ();
5607 struct remote_notif_state *rns = rs->notif_state;
5609 /* This function can be notified when an inferior exists. When the
5610 target is not remote, the notification state is NULL. */
5611 if (rs->remote_desc == NULL)
5614 reply = (struct stop_reply *) rns->pending_event[notif_client_stop.id];
5616 /* Discard the in-flight notification. */
5617 if (reply != NULL && ptid_get_pid (reply->ptid) == inf->pid)
5619 stop_reply_xfree (reply);
5620 rns->pending_event[notif_client_stop.id] = NULL;
5624 param.output = NULL;
5625 /* Discard the stop replies we have already pulled with
5627 QUEUE_iterate (stop_reply_p, stop_reply_queue,
5628 remove_stop_reply_for_inferior, ¶m);
5631 /* If its remote state is equal to the given remote state,
5632 remove EVENT from the stop reply queue. */
5635 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p) *q,
5636 QUEUE_ITER (stop_reply_p) *iter,
5640 struct queue_iter_param *param = data;
5641 struct remote_state *rs = param->input;
5643 if (event->rs == rs)
5645 stop_reply_xfree (event);
5646 QUEUE_remove_elem (stop_reply_p, q, iter);
5652 /* Discard the stop replies for RS in stop_reply_queue. */
5655 discard_pending_stop_replies_in_queue (struct remote_state *rs)
5657 struct queue_iter_param param;
5660 param.output = NULL;
5661 /* Discard the stop replies we have already pulled with
5663 QUEUE_iterate (stop_reply_p, stop_reply_queue,
5664 remove_stop_reply_of_remote_state, ¶m);
5667 /* A parameter to pass data in and out. */
5670 remote_notif_remove_once_on_match (QUEUE (stop_reply_p) *q,
5671 QUEUE_ITER (stop_reply_p) *iter,
5675 struct queue_iter_param *param = data;
5676 ptid_t *ptid = param->input;
5678 if (ptid_match (event->ptid, *ptid))
5680 param->output = event;
5681 QUEUE_remove_elem (stop_reply_p, q, iter);
5688 /* Remove the first reply in 'stop_reply_queue' which matches
5691 static struct stop_reply *
5692 remote_notif_remove_queued_reply (ptid_t ptid)
5694 struct queue_iter_param param;
5696 param.input = &ptid;
5697 param.output = NULL;
5699 QUEUE_iterate (stop_reply_p, stop_reply_queue,
5700 remote_notif_remove_once_on_match, ¶m);
5702 fprintf_unfiltered (gdb_stdlog,
5703 "notif: discard queued event: 'Stop' in %s\n",
5704 target_pid_to_str (ptid));
5706 return param.output;
5709 /* Look for a queued stop reply belonging to PTID. If one is found,
5710 remove it from the queue, and return it. Returns NULL if none is
5711 found. If there are still queued events left to process, tell the
5712 event loop to get back to target_wait soon. */
5714 static struct stop_reply *
5715 queued_stop_reply (ptid_t ptid)
5717 struct stop_reply *r = remote_notif_remove_queued_reply (ptid);
5719 if (!QUEUE_is_empty (stop_reply_p, stop_reply_queue))
5720 /* There's still at least an event left. */
5721 mark_async_event_handler (remote_async_inferior_event_token);
5726 /* Push a fully parsed stop reply in the stop reply queue. Since we
5727 know that we now have at least one queued event left to pass to the
5728 core side, tell the event loop to get back to target_wait soon. */
5731 push_stop_reply (struct stop_reply *new_event)
5733 QUEUE_enque (stop_reply_p, stop_reply_queue, new_event);
5736 fprintf_unfiltered (gdb_stdlog,
5737 "notif: push 'Stop' %s to queue %d\n",
5738 target_pid_to_str (new_event->ptid),
5739 QUEUE_length (stop_reply_p,
5742 mark_async_event_handler (remote_async_inferior_event_token);
5746 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p) *q,
5747 QUEUE_ITER (stop_reply_p) *iter,
5748 struct stop_reply *event,
5751 ptid_t *ptid = data;
5753 return !(ptid_equal (*ptid, event->ptid)
5754 && event->ws.kind == TARGET_WAITKIND_STOPPED);
5757 /* Returns true if we have a stop reply for PTID. */
5760 peek_stop_reply (ptid_t ptid)
5762 return !QUEUE_iterate (stop_reply_p, stop_reply_queue,
5763 stop_reply_match_ptid_and_ws, &ptid);
5766 /* Skip PACKET until the next semi-colon (or end of string). */
5769 skip_to_semicolon (char *p)
5771 while (*p != '\0' && *p != ';')
5776 /* Parse the stop reply in BUF. Either the function succeeds, and the
5777 result is stored in EVENT, or throws an error. */
5780 remote_parse_stop_reply (char *buf, struct stop_reply *event)
5782 struct remote_arch_state *rsa = get_remote_arch_state ();
5786 event->ptid = null_ptid;
5787 event->rs = get_remote_state ();
5788 event->ws.kind = TARGET_WAITKIND_IGNORE;
5789 event->ws.value.integer = 0;
5790 event->stop_reason = TARGET_STOPPED_BY_NO_REASON;
5791 event->regcache = NULL;
5796 case 'T': /* Status with PC, SP, FP, ... */
5797 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5798 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5800 n... = register number
5801 r... = register contents
5804 p = &buf[3]; /* after Txx */
5810 p1 = strchr (p, ':');
5812 error (_("Malformed packet(a) (missing colon): %s\n\
5816 error (_("Malformed packet(a) (missing register number): %s\n\
5820 /* Some "registers" are actually extended stop information.
5821 Note if you're adding a new entry here: GDB 7.9 and
5822 earlier assume that all register "numbers" that start
5823 with an hex digit are real register numbers. Make sure
5824 the server only sends such a packet if it knows the
5825 client understands it. */
5827 if (strncmp (p, "thread", p1 - p) == 0)
5828 event->ptid = read_ptid (++p1, &p);
5829 else if ((strncmp (p, "watch", p1 - p) == 0)
5830 || (strncmp (p, "rwatch", p1 - p) == 0)
5831 || (strncmp (p, "awatch", p1 - p) == 0))
5833 event->stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
5834 p = unpack_varlen_hex (++p1, &addr);
5835 event->watch_data_address = (CORE_ADDR) addr;
5837 else if (strncmp (p, "swbreak", p1 - p) == 0)
5839 event->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
5841 /* Make sure the stub doesn't forget to indicate support
5843 if (packet_support (PACKET_swbreak_feature) != PACKET_ENABLE)
5844 error (_("Unexpected swbreak stop reason"));
5846 /* The value part is documented as "must be empty",
5847 though we ignore it, in case we ever decide to make
5848 use of it in a backward compatible way. */
5849 p = skip_to_semicolon (p1 + 1);
5851 else if (strncmp (p, "hwbreak", p1 - p) == 0)
5853 event->stop_reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
5855 /* Make sure the stub doesn't forget to indicate support
5857 if (packet_support (PACKET_hwbreak_feature) != PACKET_ENABLE)
5858 error (_("Unexpected hwbreak stop reason"));
5861 p = skip_to_semicolon (p1 + 1);
5863 else if (strncmp (p, "library", p1 - p) == 0)
5865 event->ws.kind = TARGET_WAITKIND_LOADED;
5866 p = skip_to_semicolon (p1 + 1);
5868 else if (strncmp (p, "replaylog", p1 - p) == 0)
5870 event->ws.kind = TARGET_WAITKIND_NO_HISTORY;
5871 /* p1 will indicate "begin" or "end", but it makes
5872 no difference for now, so ignore it. */
5873 p = skip_to_semicolon (p1 + 1);
5875 else if (strncmp (p, "core", p1 - p) == 0)
5879 p = unpack_varlen_hex (++p1, &c);
5882 else if (strncmp (p, "fork", p1 - p) == 0)
5884 event->ws.value.related_pid = read_ptid (++p1, &p);
5885 event->ws.kind = TARGET_WAITKIND_FORKED;
5887 else if (strncmp (p, "vfork", p1 - p) == 0)
5889 event->ws.value.related_pid = read_ptid (++p1, &p);
5890 event->ws.kind = TARGET_WAITKIND_VFORKED;
5892 else if (strncmp (p, "vforkdone", p1 - p) == 0)
5894 event->ws.kind = TARGET_WAITKIND_VFORK_DONE;
5895 p = skip_to_semicolon (p1 + 1);
5902 /* Maybe a real ``P'' register number. */
5903 p_temp = unpack_varlen_hex (p, &pnum);
5904 /* If the first invalid character is the colon, we got a
5905 register number. Otherwise, it's an unknown stop
5909 struct packet_reg *reg = packet_reg_from_pnum (rsa, pnum);
5910 cached_reg_t cached_reg;
5913 error (_("Remote sent bad register number %s: %s\n\
5915 hex_string (pnum), p, buf);
5917 cached_reg.num = reg->regnum;
5920 fieldsize = hex2bin (p, cached_reg.data,
5921 register_size (target_gdbarch (),
5924 if (fieldsize < register_size (target_gdbarch (),
5926 warning (_("Remote reply is too short: %s"), buf);
5928 VEC_safe_push (cached_reg_t, event->regcache, &cached_reg);
5932 /* Not a number. Silently skip unknown optional
5934 p = skip_to_semicolon (p1 + 1);
5939 error (_("Remote register badly formatted: %s\nhere: %s"),
5944 if (event->ws.kind != TARGET_WAITKIND_IGNORE)
5948 case 'S': /* Old style status, just signal only. */
5952 event->ws.kind = TARGET_WAITKIND_STOPPED;
5953 sig = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
5954 if (GDB_SIGNAL_FIRST <= sig && sig < GDB_SIGNAL_LAST)
5955 event->ws.value.sig = (enum gdb_signal) sig;
5957 event->ws.value.sig = GDB_SIGNAL_UNKNOWN;
5960 case 'W': /* Target exited. */
5967 /* GDB used to accept only 2 hex chars here. Stubs should
5968 only send more if they detect GDB supports multi-process
5970 p = unpack_varlen_hex (&buf[1], &value);
5974 /* The remote process exited. */
5975 event->ws.kind = TARGET_WAITKIND_EXITED;
5976 event->ws.value.integer = value;
5980 /* The remote process exited with a signal. */
5981 event->ws.kind = TARGET_WAITKIND_SIGNALLED;
5982 if (GDB_SIGNAL_FIRST <= value && value < GDB_SIGNAL_LAST)
5983 event->ws.value.sig = (enum gdb_signal) value;
5985 event->ws.value.sig = GDB_SIGNAL_UNKNOWN;
5988 /* If no process is specified, assume inferior_ptid. */
5989 pid = ptid_get_pid (inferior_ptid);
5998 else if (startswith (p, "process:"))
6002 p += sizeof ("process:") - 1;
6003 unpack_varlen_hex (p, &upid);
6007 error (_("unknown stop reply packet: %s"), buf);
6010 error (_("unknown stop reply packet: %s"), buf);
6011 event->ptid = pid_to_ptid (pid);
6016 if (non_stop && ptid_equal (event->ptid, null_ptid))
6017 error (_("No process or thread specified in stop reply: %s"), buf);
6020 /* When the stub wants to tell GDB about a new notification reply, it
6021 sends a notification (%Stop, for example). Those can come it at
6022 any time, hence, we have to make sure that any pending
6023 putpkt/getpkt sequence we're making is finished, before querying
6024 the stub for more events with the corresponding ack command
6025 (vStopped, for example). E.g., if we started a vStopped sequence
6026 immediately upon receiving the notification, something like this
6034 1.6) <-- (registers reply to step #1.3)
6036 Obviously, the reply in step #1.6 would be unexpected to a vStopped
6039 To solve this, whenever we parse a %Stop notification successfully,
6040 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
6041 doing whatever we were doing:
6047 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
6048 2.5) <-- (registers reply to step #2.3)
6050 Eventualy after step #2.5, we return to the event loop, which
6051 notices there's an event on the
6052 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
6053 associated callback --- the function below. At this point, we're
6054 always safe to start a vStopped sequence. :
6057 2.7) <-- T05 thread:2
6063 remote_notif_get_pending_events (struct notif_client *nc)
6065 struct remote_state *rs = get_remote_state ();
6067 if (rs->notif_state->pending_event[nc->id] != NULL)
6070 fprintf_unfiltered (gdb_stdlog,
6071 "notif: process: '%s' ack pending event\n",
6075 nc->ack (nc, rs->buf, rs->notif_state->pending_event[nc->id]);
6076 rs->notif_state->pending_event[nc->id] = NULL;
6080 getpkt (&rs->buf, &rs->buf_size, 0);
6081 if (strcmp (rs->buf, "OK") == 0)
6084 remote_notif_ack (nc, rs->buf);
6090 fprintf_unfiltered (gdb_stdlog,
6091 "notif: process: '%s' no pending reply\n",
6096 /* Called when it is decided that STOP_REPLY holds the info of the
6097 event that is to be returned to the core. This function always
6098 destroys STOP_REPLY. */
6101 process_stop_reply (struct stop_reply *stop_reply,
6102 struct target_waitstatus *status)
6106 *status = stop_reply->ws;
6107 ptid = stop_reply->ptid;
6109 /* If no thread/process was reported by the stub, assume the current
6111 if (ptid_equal (ptid, null_ptid))
6112 ptid = inferior_ptid;
6114 if (status->kind != TARGET_WAITKIND_EXITED
6115 && status->kind != TARGET_WAITKIND_SIGNALLED)
6117 struct remote_state *rs = get_remote_state ();
6119 /* Expedited registers. */
6120 if (stop_reply->regcache)
6122 struct regcache *regcache
6123 = get_thread_arch_regcache (ptid, target_gdbarch ());
6128 VEC_iterate(cached_reg_t, stop_reply->regcache, ix, reg);
6130 regcache_raw_supply (regcache, reg->num, reg->data);
6131 VEC_free (cached_reg_t, stop_reply->regcache);
6134 rs->stop_reason = stop_reply->stop_reason;
6135 rs->remote_watch_data_address = stop_reply->watch_data_address;
6137 remote_notice_new_inferior (ptid, 0);
6138 demand_private_info (ptid)->core = stop_reply->core;
6141 stop_reply_xfree (stop_reply);
6145 /* The non-stop mode version of target_wait. */
6148 remote_wait_ns (ptid_t ptid, struct target_waitstatus *status, int options)
6150 struct remote_state *rs = get_remote_state ();
6151 struct stop_reply *stop_reply;
6155 /* If in non-stop mode, get out of getpkt even if a
6156 notification is received. */
6158 ret = getpkt_or_notif_sane (&rs->buf, &rs->buf_size,
6159 0 /* forever */, &is_notif);
6162 if (ret != -1 && !is_notif)
6165 case 'E': /* Error of some sort. */
6166 /* We're out of sync with the target now. Did it continue
6167 or not? We can't tell which thread it was in non-stop,
6168 so just ignore this. */
6169 warning (_("Remote failure reply: %s"), rs->buf);
6171 case 'O': /* Console output. */
6172 remote_console_output (rs->buf + 1);
6175 warning (_("Invalid remote reply: %s"), rs->buf);
6179 /* Acknowledge a pending stop reply that may have arrived in the
6181 if (rs->notif_state->pending_event[notif_client_stop.id] != NULL)
6182 remote_notif_get_pending_events (¬if_client_stop);
6184 /* If indeed we noticed a stop reply, we're done. */
6185 stop_reply = queued_stop_reply (ptid);
6186 if (stop_reply != NULL)
6187 return process_stop_reply (stop_reply, status);
6189 /* Still no event. If we're just polling for an event, then
6190 return to the event loop. */
6191 if (options & TARGET_WNOHANG)
6193 status->kind = TARGET_WAITKIND_IGNORE;
6194 return minus_one_ptid;
6197 /* Otherwise do a blocking wait. */
6198 ret = getpkt_or_notif_sane (&rs->buf, &rs->buf_size,
6199 1 /* forever */, &is_notif);
6203 /* Wait until the remote machine stops, then return, storing status in
6204 STATUS just as `wait' would. */
6207 remote_wait_as (ptid_t ptid, struct target_waitstatus *status, int options)
6209 struct remote_state *rs = get_remote_state ();
6210 ptid_t event_ptid = null_ptid;
6212 struct stop_reply *stop_reply;
6216 status->kind = TARGET_WAITKIND_IGNORE;
6217 status->value.integer = 0;
6219 stop_reply = queued_stop_reply (ptid);
6220 if (stop_reply != NULL)
6221 return process_stop_reply (stop_reply, status);
6223 if (rs->cached_wait_status)
6224 /* Use the cached wait status, but only once. */
6225 rs->cached_wait_status = 0;
6231 if (!target_is_async_p ())
6233 ofunc = signal (SIGINT, sync_remote_interrupt);
6234 /* If the user hit C-c before this packet, or between packets,
6235 pretend that it was hit right here. */
6236 if (check_quit_flag ())
6239 sync_remote_interrupt (SIGINT);
6243 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6244 _never_ wait for ever -> test on target_is_async_p().
6245 However, before we do that we need to ensure that the caller
6246 knows how to take the target into/out of async mode. */
6247 ret = getpkt_or_notif_sane (&rs->buf, &rs->buf_size,
6248 wait_forever_enabled_p, &is_notif);
6250 if (!target_is_async_p ())
6251 signal (SIGINT, ofunc);
6253 /* GDB gets a notification. Return to core as this event is
6255 if (ret != -1 && is_notif)
6256 return minus_one_ptid;
6261 rs->stop_reason = TARGET_STOPPED_BY_NO_REASON;
6263 /* We got something. */
6264 rs->waiting_for_stop_reply = 0;
6266 /* Assume that the target has acknowledged Ctrl-C unless we receive
6267 an 'F' or 'O' packet. */
6268 if (buf[0] != 'F' && buf[0] != 'O')
6269 rs->ctrlc_pending_p = 0;
6273 case 'E': /* Error of some sort. */
6274 /* We're out of sync with the target now. Did it continue or
6275 not? Not is more likely, so report a stop. */
6276 warning (_("Remote failure reply: %s"), buf);
6277 status->kind = TARGET_WAITKIND_STOPPED;
6278 status->value.sig = GDB_SIGNAL_0;
6280 case 'F': /* File-I/O request. */
6281 remote_fileio_request (buf, rs->ctrlc_pending_p);
6282 rs->ctrlc_pending_p = 0;
6284 case 'T': case 'S': case 'X': case 'W':
6286 struct stop_reply *stop_reply
6287 = (struct stop_reply *) remote_notif_parse (¬if_client_stop,
6290 event_ptid = process_stop_reply (stop_reply, status);
6293 case 'O': /* Console output. */
6294 remote_console_output (buf + 1);
6296 /* The target didn't really stop; keep waiting. */
6297 rs->waiting_for_stop_reply = 1;
6301 if (rs->last_sent_signal != GDB_SIGNAL_0)
6303 /* Zero length reply means that we tried 'S' or 'C' and the
6304 remote system doesn't support it. */
6305 target_terminal_ours_for_output ();
6307 ("Can't send signals to this remote system. %s not sent.\n",
6308 gdb_signal_to_name (rs->last_sent_signal));
6309 rs->last_sent_signal = GDB_SIGNAL_0;
6310 target_terminal_inferior ();
6312 strcpy ((char *) buf, rs->last_sent_step ? "s" : "c");
6313 putpkt ((char *) buf);
6315 /* We just told the target to resume, so a stop reply is in
6317 rs->waiting_for_stop_reply = 1;
6320 /* else fallthrough */
6322 warning (_("Invalid remote reply: %s"), buf);
6324 rs->waiting_for_stop_reply = 1;
6328 if (status->kind == TARGET_WAITKIND_IGNORE)
6330 /* Nothing interesting happened. If we're doing a non-blocking
6331 poll, we're done. Otherwise, go back to waiting. */
6332 if (options & TARGET_WNOHANG)
6333 return minus_one_ptid;
6337 else if (status->kind != TARGET_WAITKIND_EXITED
6338 && status->kind != TARGET_WAITKIND_SIGNALLED)
6340 if (!ptid_equal (event_ptid, null_ptid))
6341 record_currthread (rs, event_ptid);
6343 event_ptid = inferior_ptid;
6346 /* A process exit. Invalidate our notion of current thread. */
6347 record_currthread (rs, minus_one_ptid);
6352 /* Wait until the remote machine stops, then return, storing status in
6353 STATUS just as `wait' would. */
6356 remote_wait (struct target_ops *ops,
6357 ptid_t ptid, struct target_waitstatus *status, int options)
6362 event_ptid = remote_wait_ns (ptid, status, options);
6364 event_ptid = remote_wait_as (ptid, status, options);
6366 if (target_is_async_p ())
6368 /* If there are are events left in the queue tell the event loop
6370 if (!QUEUE_is_empty (stop_reply_p, stop_reply_queue))
6371 mark_async_event_handler (remote_async_inferior_event_token);
6377 /* Fetch a single register using a 'p' packet. */
6380 fetch_register_using_p (struct regcache *regcache, struct packet_reg *reg)
6382 struct remote_state *rs = get_remote_state ();
6384 char regp[MAX_REGISTER_SIZE];
6387 if (packet_support (PACKET_p) == PACKET_DISABLE)
6390 if (reg->pnum == -1)
6395 p += hexnumstr (p, reg->pnum);
6398 getpkt (&rs->buf, &rs->buf_size, 0);
6402 switch (packet_ok (buf, &remote_protocol_packets[PACKET_p]))
6406 case PACKET_UNKNOWN:
6409 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6410 gdbarch_register_name (get_regcache_arch (regcache),
6415 /* If this register is unfetchable, tell the regcache. */
6418 regcache_raw_supply (regcache, reg->regnum, NULL);
6422 /* Otherwise, parse and supply the value. */
6428 error (_("fetch_register_using_p: early buf termination"));
6430 regp[i++] = fromhex (p[0]) * 16 + fromhex (p[1]);
6433 regcache_raw_supply (regcache, reg->regnum, regp);
6437 /* Fetch the registers included in the target's 'g' packet. */
6440 send_g_packet (void)
6442 struct remote_state *rs = get_remote_state ();
6445 xsnprintf (rs->buf, get_remote_packet_size (), "g");
6446 remote_send (&rs->buf, &rs->buf_size);
6448 /* We can get out of synch in various cases. If the first character
6449 in the buffer is not a hex character, assume that has happened
6450 and try to fetch another packet to read. */
6451 while ((rs->buf[0] < '0' || rs->buf[0] > '9')
6452 && (rs->buf[0] < 'A' || rs->buf[0] > 'F')
6453 && (rs->buf[0] < 'a' || rs->buf[0] > 'f')
6454 && rs->buf[0] != 'x') /* New: unavailable register value. */
6457 fprintf_unfiltered (gdb_stdlog,
6458 "Bad register packet; fetching a new packet\n");
6459 getpkt (&rs->buf, &rs->buf_size, 0);
6462 buf_len = strlen (rs->buf);
6464 /* Sanity check the received packet. */
6465 if (buf_len % 2 != 0)
6466 error (_("Remote 'g' packet reply is of odd length: %s"), rs->buf);
6472 process_g_packet (struct regcache *regcache)
6474 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6475 struct remote_state *rs = get_remote_state ();
6476 struct remote_arch_state *rsa = get_remote_arch_state ();
6481 buf_len = strlen (rs->buf);
6483 /* Further sanity checks, with knowledge of the architecture. */
6484 if (buf_len > 2 * rsa->sizeof_g_packet)
6485 error (_("Remote 'g' packet reply is too long: %s"), rs->buf);
6487 /* Save the size of the packet sent to us by the target. It is used
6488 as a heuristic when determining the max size of packets that the
6489 target can safely receive. */
6490 if (rsa->actual_register_packet_size == 0)
6491 rsa->actual_register_packet_size = buf_len;
6493 /* If this is smaller than we guessed the 'g' packet would be,
6494 update our records. A 'g' reply that doesn't include a register's
6495 value implies either that the register is not available, or that
6496 the 'p' packet must be used. */
6497 if (buf_len < 2 * rsa->sizeof_g_packet)
6499 rsa->sizeof_g_packet = buf_len / 2;
6501 for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
6503 if (rsa->regs[i].pnum == -1)
6506 if (rsa->regs[i].offset >= rsa->sizeof_g_packet)
6507 rsa->regs[i].in_g_packet = 0;
6509 rsa->regs[i].in_g_packet = 1;
6513 regs = alloca (rsa->sizeof_g_packet);
6515 /* Unimplemented registers read as all bits zero. */
6516 memset (regs, 0, rsa->sizeof_g_packet);
6518 /* Reply describes registers byte by byte, each byte encoded as two
6519 hex characters. Suck them all up, then supply them to the
6520 register cacheing/storage mechanism. */
6523 for (i = 0; i < rsa->sizeof_g_packet; i++)
6525 if (p[0] == 0 || p[1] == 0)
6526 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6527 internal_error (__FILE__, __LINE__,
6528 _("unexpected end of 'g' packet reply"));
6530 if (p[0] == 'x' && p[1] == 'x')
6531 regs[i] = 0; /* 'x' */
6533 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
6537 for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
6539 struct packet_reg *r = &rsa->regs[i];
6543 if (r->offset * 2 >= strlen (rs->buf))
6544 /* This shouldn't happen - we adjusted in_g_packet above. */
6545 internal_error (__FILE__, __LINE__,
6546 _("unexpected end of 'g' packet reply"));
6547 else if (rs->buf[r->offset * 2] == 'x')
6549 gdb_assert (r->offset * 2 < strlen (rs->buf));
6550 /* The register isn't available, mark it as such (at
6551 the same time setting the value to zero). */
6552 regcache_raw_supply (regcache, r->regnum, NULL);
6555 regcache_raw_supply (regcache, r->regnum,
6562 fetch_registers_using_g (struct regcache *regcache)
6565 process_g_packet (regcache);
6568 /* Make the remote selected traceframe match GDB's selected
6572 set_remote_traceframe (void)
6575 struct remote_state *rs = get_remote_state ();
6577 if (rs->remote_traceframe_number == get_traceframe_number ())
6580 /* Avoid recursion, remote_trace_find calls us again. */
6581 rs->remote_traceframe_number = get_traceframe_number ();
6583 newnum = target_trace_find (tfind_number,
6584 get_traceframe_number (), 0, 0, NULL);
6586 /* Should not happen. If it does, all bets are off. */
6587 if (newnum != get_traceframe_number ())
6588 warning (_("could not set remote traceframe"));
6592 remote_fetch_registers (struct target_ops *ops,
6593 struct regcache *regcache, int regnum)
6595 struct remote_arch_state *rsa = get_remote_arch_state ();
6598 set_remote_traceframe ();
6599 set_general_thread (inferior_ptid);
6603 struct packet_reg *reg = packet_reg_from_regnum (rsa, regnum);
6605 gdb_assert (reg != NULL);
6607 /* If this register might be in the 'g' packet, try that first -
6608 we are likely to read more than one register. If this is the
6609 first 'g' packet, we might be overly optimistic about its
6610 contents, so fall back to 'p'. */
6611 if (reg->in_g_packet)
6613 fetch_registers_using_g (regcache);
6614 if (reg->in_g_packet)
6618 if (fetch_register_using_p (regcache, reg))
6621 /* This register is not available. */
6622 regcache_raw_supply (regcache, reg->regnum, NULL);
6627 fetch_registers_using_g (regcache);
6629 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
6630 if (!rsa->regs[i].in_g_packet)
6631 if (!fetch_register_using_p (regcache, &rsa->regs[i]))
6633 /* This register is not available. */
6634 regcache_raw_supply (regcache, i, NULL);
6638 /* Prepare to store registers. Since we may send them all (using a
6639 'G' request), we have to read out the ones we don't want to change
6643 remote_prepare_to_store (struct target_ops *self, struct regcache *regcache)
6645 struct remote_arch_state *rsa = get_remote_arch_state ();
6647 gdb_byte buf[MAX_REGISTER_SIZE];
6649 /* Make sure the entire registers array is valid. */
6650 switch (packet_support (PACKET_P))
6652 case PACKET_DISABLE:
6653 case PACKET_SUPPORT_UNKNOWN:
6654 /* Make sure all the necessary registers are cached. */
6655 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
6656 if (rsa->regs[i].in_g_packet)
6657 regcache_raw_read (regcache, rsa->regs[i].regnum, buf);
6664 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6665 packet was not recognized. */
6668 store_register_using_P (const struct regcache *regcache,
6669 struct packet_reg *reg)
6671 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6672 struct remote_state *rs = get_remote_state ();
6673 /* Try storing a single register. */
6674 char *buf = rs->buf;
6675 gdb_byte regp[MAX_REGISTER_SIZE];
6678 if (packet_support (PACKET_P) == PACKET_DISABLE)
6681 if (reg->pnum == -1)
6684 xsnprintf (buf, get_remote_packet_size (), "P%s=", phex_nz (reg->pnum, 0));
6685 p = buf + strlen (buf);
6686 regcache_raw_collect (regcache, reg->regnum, regp);
6687 bin2hex (regp, p, register_size (gdbarch, reg->regnum));
6689 getpkt (&rs->buf, &rs->buf_size, 0);
6691 switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_P]))
6696 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6697 gdbarch_register_name (gdbarch, reg->regnum), rs->buf);
6698 case PACKET_UNKNOWN:
6701 internal_error (__FILE__, __LINE__, _("Bad result from packet_ok"));
6705 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6706 contents of the register cache buffer. FIXME: ignores errors. */
6709 store_registers_using_G (const struct regcache *regcache)
6711 struct remote_state *rs = get_remote_state ();
6712 struct remote_arch_state *rsa = get_remote_arch_state ();
6716 /* Extract all the registers in the regcache copying them into a
6721 regs = alloca (rsa->sizeof_g_packet);
6722 memset (regs, 0, rsa->sizeof_g_packet);
6723 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
6725 struct packet_reg *r = &rsa->regs[i];
6728 regcache_raw_collect (regcache, r->regnum, regs + r->offset);
6732 /* Command describes registers byte by byte,
6733 each byte encoded as two hex characters. */
6736 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6738 bin2hex (regs, p, rsa->sizeof_g_packet);
6740 getpkt (&rs->buf, &rs->buf_size, 0);
6741 if (packet_check_result (rs->buf) == PACKET_ERROR)
6742 error (_("Could not write registers; remote failure reply '%s'"),
6746 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6747 of the register cache buffer. FIXME: ignores errors. */
6750 remote_store_registers (struct target_ops *ops,
6751 struct regcache *regcache, int regnum)
6753 struct remote_arch_state *rsa = get_remote_arch_state ();
6756 set_remote_traceframe ();
6757 set_general_thread (inferior_ptid);
6761 struct packet_reg *reg = packet_reg_from_regnum (rsa, regnum);
6763 gdb_assert (reg != NULL);
6765 /* Always prefer to store registers using the 'P' packet if
6766 possible; we often change only a small number of registers.
6767 Sometimes we change a larger number; we'd need help from a
6768 higher layer to know to use 'G'. */
6769 if (store_register_using_P (regcache, reg))
6772 /* For now, don't complain if we have no way to write the
6773 register. GDB loses track of unavailable registers too
6774 easily. Some day, this may be an error. We don't have
6775 any way to read the register, either... */
6776 if (!reg->in_g_packet)
6779 store_registers_using_G (regcache);
6783 store_registers_using_G (regcache);
6785 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
6786 if (!rsa->regs[i].in_g_packet)
6787 if (!store_register_using_P (regcache, &rsa->regs[i]))
6788 /* See above for why we do not issue an error here. */
6793 /* Return the number of hex digits in num. */
6796 hexnumlen (ULONGEST num)
6800 for (i = 0; num != 0; i++)
6806 /* Set BUF to the minimum number of hex digits representing NUM. */
6809 hexnumstr (char *buf, ULONGEST num)
6811 int len = hexnumlen (num);
6813 return hexnumnstr (buf, num, len);
6817 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6820 hexnumnstr (char *buf, ULONGEST num, int width)
6826 for (i = width - 1; i >= 0; i--)
6828 buf[i] = "0123456789abcdef"[(num & 0xf)];
6835 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6838 remote_address_masked (CORE_ADDR addr)
6840 unsigned int address_size = remote_address_size;
6842 /* If "remoteaddresssize" was not set, default to target address size. */
6844 address_size = gdbarch_addr_bit (target_gdbarch ());
6846 if (address_size > 0
6847 && address_size < (sizeof (ULONGEST) * 8))
6849 /* Only create a mask when that mask can safely be constructed
6850 in a ULONGEST variable. */
6853 mask = (mask << address_size) - 1;
6859 /* Determine whether the remote target supports binary downloading.
6860 This is accomplished by sending a no-op memory write of zero length
6861 to the target at the specified address. It does not suffice to send
6862 the whole packet, since many stubs strip the eighth bit and
6863 subsequently compute a wrong checksum, which causes real havoc with
6866 NOTE: This can still lose if the serial line is not eight-bit
6867 clean. In cases like this, the user should clear "remote
6871 check_binary_download (CORE_ADDR addr)
6873 struct remote_state *rs = get_remote_state ();
6875 switch (packet_support (PACKET_X))
6877 case PACKET_DISABLE:
6881 case PACKET_SUPPORT_UNKNOWN:
6887 p += hexnumstr (p, (ULONGEST) addr);
6889 p += hexnumstr (p, (ULONGEST) 0);
6893 putpkt_binary (rs->buf, (int) (p - rs->buf));
6894 getpkt (&rs->buf, &rs->buf_size, 0);
6896 if (rs->buf[0] == '\0')
6899 fprintf_unfiltered (gdb_stdlog,
6900 "binary downloading NOT "
6901 "supported by target\n");
6902 remote_protocol_packets[PACKET_X].support = PACKET_DISABLE;
6907 fprintf_unfiltered (gdb_stdlog,
6908 "binary downloading supported by target\n");
6909 remote_protocol_packets[PACKET_X].support = PACKET_ENABLE;
6916 /* Write memory data directly to the remote machine.
6917 This does not inform the data cache; the data cache uses this.
6918 HEADER is the starting part of the packet.
6919 MEMADDR is the address in the remote memory space.
6920 MYADDR is the address of the buffer in our space.
6921 LEN is the number of bytes.
6922 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6923 should send data as binary ('X'), or hex-encoded ('M').
6925 The function creates packet of the form
6926 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6928 where encoding of <DATA> is termined by PACKET_FORMAT.
6930 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6933 Return the transferred status, error or OK (an
6934 'enum target_xfer_status' value). Save the number of bytes
6935 transferred in *XFERED_LEN. Only transfer a single packet. */
6937 static enum target_xfer_status
6938 remote_write_bytes_aux (const char *header, CORE_ADDR memaddr,
6939 const gdb_byte *myaddr, ULONGEST len,
6940 ULONGEST *xfered_len, char packet_format,
6943 struct remote_state *rs = get_remote_state ();
6953 if (packet_format != 'X' && packet_format != 'M')
6954 internal_error (__FILE__, __LINE__,
6955 _("remote_write_bytes_aux: bad packet format"));
6958 return TARGET_XFER_EOF;
6960 payload_size = get_memory_write_packet_size ();
6962 /* The packet buffer will be large enough for the payload;
6963 get_memory_packet_size ensures this. */
6966 /* Compute the size of the actual payload by subtracting out the
6967 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6969 payload_size -= strlen ("$,:#NN");
6971 /* The comma won't be used. */
6973 header_length = strlen (header);
6974 payload_size -= header_length;
6975 payload_size -= hexnumlen (memaddr);
6977 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6979 strcat (rs->buf, header);
6980 p = rs->buf + strlen (header);
6982 /* Compute a best guess of the number of bytes actually transfered. */
6983 if (packet_format == 'X')
6985 /* Best guess at number of bytes that will fit. */
6986 todo = min (len, payload_size);
6988 payload_size -= hexnumlen (todo);
6989 todo = min (todo, payload_size);
6993 /* Num bytes that will fit. */
6994 todo = min (len, payload_size / 2);
6996 payload_size -= hexnumlen (todo);
6997 todo = min (todo, payload_size / 2);
7001 internal_error (__FILE__, __LINE__,
7002 _("minimum packet size too small to write data"));
7004 /* If we already need another packet, then try to align the end
7005 of this packet to a useful boundary. */
7006 if (todo > 2 * REMOTE_ALIGN_WRITES && todo < len)
7007 todo = ((memaddr + todo) & ~(REMOTE_ALIGN_WRITES - 1)) - memaddr;
7009 /* Append "<memaddr>". */
7010 memaddr = remote_address_masked (memaddr);
7011 p += hexnumstr (p, (ULONGEST) memaddr);
7018 /* Append <len>. Retain the location/size of <len>. It may need to
7019 be adjusted once the packet body has been created. */
7021 plenlen = hexnumstr (p, (ULONGEST) todo);
7029 /* Append the packet body. */
7030 if (packet_format == 'X')
7032 /* Binary mode. Send target system values byte by byte, in
7033 increasing byte addresses. Only escape certain critical
7035 payload_length = remote_escape_output (myaddr, todo, (gdb_byte *) p,
7036 &nr_bytes, payload_size);
7038 /* If not all TODO bytes fit, then we'll need another packet. Make
7039 a second try to keep the end of the packet aligned. Don't do
7040 this if the packet is tiny. */
7041 if (nr_bytes < todo && nr_bytes > 2 * REMOTE_ALIGN_WRITES)
7045 new_nr_bytes = (((memaddr + nr_bytes) & ~(REMOTE_ALIGN_WRITES - 1))
7047 if (new_nr_bytes != nr_bytes)
7048 payload_length = remote_escape_output (myaddr, new_nr_bytes,
7049 (gdb_byte *) p, &nr_bytes,
7053 p += payload_length;
7054 if (use_length && nr_bytes < todo)
7056 /* Escape chars have filled up the buffer prematurely,
7057 and we have actually sent fewer bytes than planned.
7058 Fix-up the length field of the packet. Use the same
7059 number of characters as before. */
7060 plen += hexnumnstr (plen, (ULONGEST) nr_bytes, plenlen);
7061 *plen = ':'; /* overwrite \0 from hexnumnstr() */
7066 /* Normal mode: Send target system values byte by byte, in
7067 increasing byte addresses. Each byte is encoded as a two hex
7069 nr_bytes = bin2hex (myaddr, p, todo);
7073 putpkt_binary (rs->buf, (int) (p - rs->buf));
7074 getpkt (&rs->buf, &rs->buf_size, 0);
7076 if (rs->buf[0] == 'E')
7077 return TARGET_XFER_E_IO;
7079 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
7080 fewer bytes than we'd planned. */
7081 *xfered_len = (ULONGEST) nr_bytes;
7082 return TARGET_XFER_OK;
7085 /* Write memory data directly to the remote machine.
7086 This does not inform the data cache; the data cache uses this.
7087 MEMADDR is the address in the remote memory space.
7088 MYADDR is the address of the buffer in our space.
7089 LEN is the number of bytes.
7091 Return the transferred status, error or OK (an
7092 'enum target_xfer_status' value). Save the number of bytes
7093 transferred in *XFERED_LEN. Only transfer a single packet. */
7095 static enum target_xfer_status
7096 remote_write_bytes (CORE_ADDR memaddr, const gdb_byte *myaddr, ULONGEST len,
7097 ULONGEST *xfered_len)
7099 char *packet_format = 0;
7101 /* Check whether the target supports binary download. */
7102 check_binary_download (memaddr);
7104 switch (packet_support (PACKET_X))
7107 packet_format = "X";
7109 case PACKET_DISABLE:
7110 packet_format = "M";
7112 case PACKET_SUPPORT_UNKNOWN:
7113 internal_error (__FILE__, __LINE__,
7114 _("remote_write_bytes: bad internal state"));
7116 internal_error (__FILE__, __LINE__, _("bad switch"));
7119 return remote_write_bytes_aux (packet_format,
7120 memaddr, myaddr, len, xfered_len,
7121 packet_format[0], 1);
7124 /* Read memory data directly from the remote machine.
7125 This does not use the data cache; the data cache uses this.
7126 MEMADDR is the address in the remote memory space.
7127 MYADDR is the address of the buffer in our space.
7128 LEN is the number of bytes.
7130 Return the transferred status, error or OK (an
7131 'enum target_xfer_status' value). Save the number of bytes
7132 transferred in *XFERED_LEN. */
7134 static enum target_xfer_status
7135 remote_read_bytes_1 (CORE_ADDR memaddr, gdb_byte *myaddr, ULONGEST len,
7136 ULONGEST *xfered_len)
7138 struct remote_state *rs = get_remote_state ();
7139 int max_buf_size; /* Max size of packet output buffer. */
7144 max_buf_size = get_memory_read_packet_size ();
7145 /* The packet buffer will be large enough for the payload;
7146 get_memory_packet_size ensures this. */
7148 /* Number if bytes that will fit. */
7149 todo = min (len, max_buf_size / 2);
7151 /* Construct "m"<memaddr>","<len>". */
7152 memaddr = remote_address_masked (memaddr);
7155 p += hexnumstr (p, (ULONGEST) memaddr);
7157 p += hexnumstr (p, (ULONGEST) todo);
7160 getpkt (&rs->buf, &rs->buf_size, 0);
7161 if (rs->buf[0] == 'E'
7162 && isxdigit (rs->buf[1]) && isxdigit (rs->buf[2])
7163 && rs->buf[3] == '\0')
7164 return TARGET_XFER_E_IO;
7165 /* Reply describes memory byte by byte, each byte encoded as two hex
7168 i = hex2bin (p, myaddr, todo);
7169 /* Return what we have. Let higher layers handle partial reads. */
7170 *xfered_len = (ULONGEST) i;
7171 return TARGET_XFER_OK;
7174 /* Using the set of read-only target sections of remote, read live
7177 For interface/parameters/return description see target.h,
7180 static enum target_xfer_status
7181 remote_xfer_live_readonly_partial (struct target_ops *ops, gdb_byte *readbuf,
7182 ULONGEST memaddr, ULONGEST len,
7183 ULONGEST *xfered_len)
7185 struct target_section *secp;
7186 struct target_section_table *table;
7188 secp = target_section_by_addr (ops, memaddr);
7190 && (bfd_get_section_flags (secp->the_bfd_section->owner,
7191 secp->the_bfd_section)
7194 struct target_section *p;
7195 ULONGEST memend = memaddr + len;
7197 table = target_get_section_table (ops);
7199 for (p = table->sections; p < table->sections_end; p++)
7201 if (memaddr >= p->addr)
7203 if (memend <= p->endaddr)
7205 /* Entire transfer is within this section. */
7206 return remote_read_bytes_1 (memaddr, readbuf, len,
7209 else if (memaddr >= p->endaddr)
7211 /* This section ends before the transfer starts. */
7216 /* This section overlaps the transfer. Just do half. */
7217 len = p->endaddr - memaddr;
7218 return remote_read_bytes_1 (memaddr, readbuf, len,
7225 return TARGET_XFER_EOF;
7228 /* Similar to remote_read_bytes_1, but it reads from the remote stub
7229 first if the requested memory is unavailable in traceframe.
7230 Otherwise, fall back to remote_read_bytes_1. */
7232 static enum target_xfer_status
7233 remote_read_bytes (struct target_ops *ops, CORE_ADDR memaddr,
7234 gdb_byte *myaddr, ULONGEST len, ULONGEST *xfered_len)
7237 return TARGET_XFER_EOF;
7239 if (get_traceframe_number () != -1)
7241 VEC(mem_range_s) *available;
7243 /* If we fail to get the set of available memory, then the
7244 target does not support querying traceframe info, and so we
7245 attempt reading from the traceframe anyway (assuming the
7246 target implements the old QTro packet then). */
7247 if (traceframe_available_memory (&available, memaddr, len))
7249 struct cleanup *old_chain;
7251 old_chain = make_cleanup (VEC_cleanup(mem_range_s), &available);
7253 if (VEC_empty (mem_range_s, available)
7254 || VEC_index (mem_range_s, available, 0)->start != memaddr)
7256 enum target_xfer_status res;
7258 /* Don't read into the traceframe's available
7260 if (!VEC_empty (mem_range_s, available))
7262 LONGEST oldlen = len;
7264 len = VEC_index (mem_range_s, available, 0)->start - memaddr;
7265 gdb_assert (len <= oldlen);
7268 do_cleanups (old_chain);
7270 /* This goes through the topmost target again. */
7271 res = remote_xfer_live_readonly_partial (ops, myaddr, memaddr,
7273 if (res == TARGET_XFER_OK)
7274 return TARGET_XFER_OK;
7277 /* No use trying further, we know some memory starting
7278 at MEMADDR isn't available. */
7280 return TARGET_XFER_UNAVAILABLE;
7284 /* Don't try to read more than how much is available, in
7285 case the target implements the deprecated QTro packet to
7286 cater for older GDBs (the target's knowledge of read-only
7287 sections may be outdated by now). */
7288 len = VEC_index (mem_range_s, available, 0)->length;
7290 do_cleanups (old_chain);
7294 return remote_read_bytes_1 (memaddr, myaddr, len, xfered_len);
7299 /* Sends a packet with content determined by the printf format string
7300 FORMAT and the remaining arguments, then gets the reply. Returns
7301 whether the packet was a success, a failure, or unknown. */
7303 static enum packet_result remote_send_printf (const char *format, ...)
7304 ATTRIBUTE_PRINTF (1, 2);
7306 static enum packet_result
7307 remote_send_printf (const char *format, ...)
7309 struct remote_state *rs = get_remote_state ();
7310 int max_size = get_remote_packet_size ();
7313 va_start (ap, format);
7316 if (vsnprintf (rs->buf, max_size, format, ap) >= max_size)
7317 internal_error (__FILE__, __LINE__, _("Too long remote packet."));
7319 if (putpkt (rs->buf) < 0)
7320 error (_("Communication problem with target."));
7323 getpkt (&rs->buf, &rs->buf_size, 0);
7325 return packet_check_result (rs->buf);
7329 restore_remote_timeout (void *p)
7331 int value = *(int *)p;
7333 remote_timeout = value;
7336 /* Flash writing can take quite some time. We'll set
7337 effectively infinite timeout for flash operations.
7338 In future, we'll need to decide on a better approach. */
7339 static const int remote_flash_timeout = 1000;
7342 remote_flash_erase (struct target_ops *ops,
7343 ULONGEST address, LONGEST length)
7345 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
7346 int saved_remote_timeout = remote_timeout;
7347 enum packet_result ret;
7348 struct cleanup *back_to = make_cleanup (restore_remote_timeout,
7349 &saved_remote_timeout);
7351 remote_timeout = remote_flash_timeout;
7353 ret = remote_send_printf ("vFlashErase:%s,%s",
7354 phex (address, addr_size),
7358 case PACKET_UNKNOWN:
7359 error (_("Remote target does not support flash erase"));
7361 error (_("Error erasing flash with vFlashErase packet"));
7366 do_cleanups (back_to);
7369 static enum target_xfer_status
7370 remote_flash_write (struct target_ops *ops, ULONGEST address,
7371 ULONGEST length, ULONGEST *xfered_len,
7372 const gdb_byte *data)
7374 int saved_remote_timeout = remote_timeout;
7375 enum target_xfer_status ret;
7376 struct cleanup *back_to = make_cleanup (restore_remote_timeout,
7377 &saved_remote_timeout);
7379 remote_timeout = remote_flash_timeout;
7380 ret = remote_write_bytes_aux ("vFlashWrite:", address, data, length,
7382 do_cleanups (back_to);
7388 remote_flash_done (struct target_ops *ops)
7390 int saved_remote_timeout = remote_timeout;
7392 struct cleanup *back_to = make_cleanup (restore_remote_timeout,
7393 &saved_remote_timeout);
7395 remote_timeout = remote_flash_timeout;
7396 ret = remote_send_printf ("vFlashDone");
7397 do_cleanups (back_to);
7401 case PACKET_UNKNOWN:
7402 error (_("Remote target does not support vFlashDone"));
7404 error (_("Error finishing flash operation"));
7411 remote_files_info (struct target_ops *ignore)
7413 puts_filtered ("Debugging a target over a serial line.\n");
7416 /* Stuff for dealing with the packets which are part of this protocol.
7417 See comment at top of file for details. */
7419 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7420 error to higher layers. Called when a serial error is detected.
7421 The exception message is STRING, followed by a colon and a blank,
7422 the system error message for errno at function entry and final dot
7423 for output compatibility with throw_perror_with_name. */
7426 unpush_and_perror (const char *string)
7428 int saved_errno = errno;
7430 remote_unpush_target ();
7431 throw_error (TARGET_CLOSE_ERROR, "%s: %s.", string,
7432 safe_strerror (saved_errno));
7435 /* Read a single character from the remote end. */
7438 readchar (int timeout)
7441 struct remote_state *rs = get_remote_state ();
7443 ch = serial_readchar (rs->remote_desc, timeout);
7448 switch ((enum serial_rc) ch)
7451 remote_unpush_target ();
7452 throw_error (TARGET_CLOSE_ERROR, _("Remote connection closed"));
7455 unpush_and_perror (_("Remote communication error. "
7456 "Target disconnected."));
7458 case SERIAL_TIMEOUT:
7464 /* Wrapper for serial_write that closes the target and throws if
7468 remote_serial_write (const char *str, int len)
7470 struct remote_state *rs = get_remote_state ();
7472 if (serial_write (rs->remote_desc, str, len))
7474 unpush_and_perror (_("Remote communication error. "
7475 "Target disconnected."));
7479 /* Send the command in *BUF to the remote machine, and read the reply
7480 into *BUF. Report an error if we get an error reply. Resize
7481 *BUF using xrealloc if necessary to hold the result, and update
7485 remote_send (char **buf,
7489 getpkt (buf, sizeof_buf, 0);
7491 if ((*buf)[0] == 'E')
7492 error (_("Remote failure reply: %s"), *buf);
7495 /* Return a pointer to an xmalloc'ed string representing an escaped
7496 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7497 etc. The caller is responsible for releasing the returned
7501 escape_buffer (const char *buf, int n)
7503 struct cleanup *old_chain;
7504 struct ui_file *stb;
7507 stb = mem_fileopen ();
7508 old_chain = make_cleanup_ui_file_delete (stb);
7510 fputstrn_unfiltered (buf, n, '\\', stb);
7511 str = ui_file_xstrdup (stb, NULL);
7512 do_cleanups (old_chain);
7516 /* Display a null-terminated packet on stdout, for debugging, using C
7520 print_packet (const char *buf)
7522 puts_filtered ("\"");
7523 fputstr_filtered (buf, '"', gdb_stdout);
7524 puts_filtered ("\"");
7528 putpkt (const char *buf)
7530 return putpkt_binary (buf, strlen (buf));
7533 /* Send a packet to the remote machine, with error checking. The data
7534 of the packet is in BUF. The string in BUF can be at most
7535 get_remote_packet_size () - 5 to account for the $, # and checksum,
7536 and for a possible /0 if we are debugging (remote_debug) and want
7537 to print the sent packet as a string. */
7540 putpkt_binary (const char *buf, int cnt)
7542 struct remote_state *rs = get_remote_state ();
7544 unsigned char csum = 0;
7545 char *buf2 = alloca (cnt + 6);
7552 /* Catch cases like trying to read memory or listing threads while
7553 we're waiting for a stop reply. The remote server wouldn't be
7554 ready to handle this request, so we'd hang and timeout. We don't
7555 have to worry about this in synchronous mode, because in that
7556 case it's not possible to issue a command while the target is
7557 running. This is not a problem in non-stop mode, because in that
7558 case, the stub is always ready to process serial input. */
7559 if (!non_stop && target_is_async_p () && rs->waiting_for_stop_reply)
7561 error (_("Cannot execute this command while the target is running.\n"
7562 "Use the \"interrupt\" command to stop the target\n"
7563 "and then try again."));
7566 /* We're sending out a new packet. Make sure we don't look at a
7567 stale cached response. */
7568 rs->cached_wait_status = 0;
7570 /* Copy the packet into buffer BUF2, encapsulating it
7571 and giving it a checksum. */
7576 for (i = 0; i < cnt; i++)
7582 *p++ = tohex ((csum >> 4) & 0xf);
7583 *p++ = tohex (csum & 0xf);
7585 /* Send it over and over until we get a positive ack. */
7589 int started_error_output = 0;
7593 struct cleanup *old_chain;
7597 str = escape_buffer (buf2, p - buf2);
7598 old_chain = make_cleanup (xfree, str);
7599 fprintf_unfiltered (gdb_stdlog, "Sending packet: %s...", str);
7600 gdb_flush (gdb_stdlog);
7601 do_cleanups (old_chain);
7603 remote_serial_write (buf2, p - buf2);
7605 /* If this is a no acks version of the remote protocol, send the
7606 packet and move on. */
7610 /* Read until either a timeout occurs (-2) or '+' is read.
7611 Handle any notification that arrives in the mean time. */
7614 ch = readchar (remote_timeout);
7622 case SERIAL_TIMEOUT:
7625 if (started_error_output)
7627 putchar_unfiltered ('\n');
7628 started_error_output = 0;
7637 fprintf_unfiltered (gdb_stdlog, "Ack\n");
7641 fprintf_unfiltered (gdb_stdlog, "Nak\n");
7643 case SERIAL_TIMEOUT:
7647 break; /* Retransmit buffer. */
7651 fprintf_unfiltered (gdb_stdlog,
7652 "Packet instead of Ack, ignoring it\n");
7653 /* It's probably an old response sent because an ACK
7654 was lost. Gobble up the packet and ack it so it
7655 doesn't get retransmitted when we resend this
7658 remote_serial_write ("+", 1);
7659 continue; /* Now, go look for +. */
7666 /* If we got a notification, handle it, and go back to looking
7668 /* We've found the start of a notification. Now
7669 collect the data. */
7670 val = read_frame (&rs->buf, &rs->buf_size);
7675 struct cleanup *old_chain;
7678 str = escape_buffer (rs->buf, val);
7679 old_chain = make_cleanup (xfree, str);
7680 fprintf_unfiltered (gdb_stdlog,
7681 " Notification received: %s\n",
7683 do_cleanups (old_chain);
7685 handle_notification (rs->notif_state, rs->buf);
7686 /* We're in sync now, rewait for the ack. */
7693 if (!started_error_output)
7695 started_error_output = 1;
7696 fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
7698 fputc_unfiltered (ch & 0177, gdb_stdlog);
7699 fprintf_unfiltered (gdb_stdlog, "%s", rs->buf);
7708 if (!started_error_output)
7710 started_error_output = 1;
7711 fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
7713 fputc_unfiltered (ch & 0177, gdb_stdlog);
7717 break; /* Here to retransmit. */
7721 /* This is wrong. If doing a long backtrace, the user should be
7722 able to get out next time we call QUIT, without anything as
7723 violent as interrupt_query. If we want to provide a way out of
7724 here without getting to the next QUIT, it should be based on
7725 hitting ^C twice as in remote_wait. */
7736 /* Come here after finding the start of a frame when we expected an
7737 ack. Do our best to discard the rest of this packet. */
7746 c = readchar (remote_timeout);
7749 case SERIAL_TIMEOUT:
7750 /* Nothing we can do. */
7753 /* Discard the two bytes of checksum and stop. */
7754 c = readchar (remote_timeout);
7756 c = readchar (remote_timeout);
7759 case '*': /* Run length encoding. */
7760 /* Discard the repeat count. */
7761 c = readchar (remote_timeout);
7766 /* A regular character. */
7772 /* Come here after finding the start of the frame. Collect the rest
7773 into *BUF, verifying the checksum, length, and handling run-length
7774 compression. NUL terminate the buffer. If there is not enough room,
7775 expand *BUF using xrealloc.
7777 Returns -1 on error, number of characters in buffer (ignoring the
7778 trailing NULL) on success. (could be extended to return one of the
7779 SERIAL status indications). */
7782 read_frame (char **buf_p,
7789 struct remote_state *rs = get_remote_state ();
7796 c = readchar (remote_timeout);
7799 case SERIAL_TIMEOUT:
7801 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
7805 fputs_filtered ("Saw new packet start in middle of old one\n",
7807 return -1; /* Start a new packet, count retries. */
7810 unsigned char pktcsum;
7816 check_0 = readchar (remote_timeout);
7818 check_1 = readchar (remote_timeout);
7820 if (check_0 == SERIAL_TIMEOUT || check_1 == SERIAL_TIMEOUT)
7823 fputs_filtered ("Timeout in checksum, retrying\n",
7827 else if (check_0 < 0 || check_1 < 0)
7830 fputs_filtered ("Communication error in checksum\n",
7835 /* Don't recompute the checksum; with no ack packets we
7836 don't have any way to indicate a packet retransmission
7841 pktcsum = (fromhex (check_0) << 4) | fromhex (check_1);
7842 if (csum == pktcsum)
7847 struct cleanup *old_chain;
7850 str = escape_buffer (buf, bc);
7851 old_chain = make_cleanup (xfree, str);
7852 fprintf_unfiltered (gdb_stdlog,
7853 "Bad checksum, sentsum=0x%x, "
7854 "csum=0x%x, buf=%s\n",
7855 pktcsum, csum, str);
7856 do_cleanups (old_chain);
7858 /* Number of characters in buffer ignoring trailing
7862 case '*': /* Run length encoding. */
7867 c = readchar (remote_timeout);
7869 repeat = c - ' ' + 3; /* Compute repeat count. */
7871 /* The character before ``*'' is repeated. */
7873 if (repeat > 0 && repeat <= 255 && bc > 0)
7875 if (bc + repeat - 1 >= *sizeof_buf - 1)
7877 /* Make some more room in the buffer. */
7878 *sizeof_buf += repeat;
7879 *buf_p = xrealloc (*buf_p, *sizeof_buf);
7883 memset (&buf[bc], buf[bc - 1], repeat);
7889 printf_filtered (_("Invalid run length encoding: %s\n"), buf);
7893 if (bc >= *sizeof_buf - 1)
7895 /* Make some more room in the buffer. */
7897 *buf_p = xrealloc (*buf_p, *sizeof_buf);
7908 /* Read a packet from the remote machine, with error checking, and
7909 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7910 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7911 rather than timing out; this is used (in synchronous mode) to wait
7912 for a target that is is executing user code to stop. */
7913 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7914 don't have to change all the calls to getpkt to deal with the
7915 return value, because at the moment I don't know what the right
7916 thing to do it for those. */
7924 timed_out = getpkt_sane (buf, sizeof_buf, forever);
7928 /* Read a packet from the remote machine, with error checking, and
7929 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7930 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7931 rather than timing out; this is used (in synchronous mode) to wait
7932 for a target that is is executing user code to stop. If FOREVER ==
7933 0, this function is allowed to time out gracefully and return an
7934 indication of this to the caller. Otherwise return the number of
7935 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7936 enough reason to return to the caller. *IS_NOTIF is an output
7937 boolean that indicates whether *BUF holds a notification or not
7938 (a regular packet). */
7941 getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever,
7942 int expecting_notif, int *is_notif)
7944 struct remote_state *rs = get_remote_state ();
7950 /* We're reading a new response. Make sure we don't look at a
7951 previously cached response. */
7952 rs->cached_wait_status = 0;
7954 strcpy (*buf, "timeout");
7957 timeout = watchdog > 0 ? watchdog : -1;
7958 else if (expecting_notif)
7959 timeout = 0; /* There should already be a char in the buffer. If
7962 timeout = remote_timeout;
7966 /* Process any number of notifications, and then return when
7970 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
7972 for (tries = 1; tries <= MAX_TRIES; tries++)
7974 /* This can loop forever if the remote side sends us
7975 characters continuously, but if it pauses, we'll get
7976 SERIAL_TIMEOUT from readchar because of timeout. Then
7977 we'll count that as a retry.
7979 Note that even when forever is set, we will only wait
7980 forever prior to the start of a packet. After that, we
7981 expect characters to arrive at a brisk pace. They should
7982 show up within remote_timeout intervals. */
7984 c = readchar (timeout);
7985 while (c != SERIAL_TIMEOUT && c != '$' && c != '%');
7987 if (c == SERIAL_TIMEOUT)
7989 if (expecting_notif)
7990 return -1; /* Don't complain, it's normal to not get
7991 anything in this case. */
7993 if (forever) /* Watchdog went off? Kill the target. */
7996 remote_unpush_target ();
7997 throw_error (TARGET_CLOSE_ERROR,
7998 _("Watchdog timeout has expired. "
7999 "Target detached."));
8002 fputs_filtered ("Timed out.\n", gdb_stdlog);
8006 /* We've found the start of a packet or notification.
8007 Now collect the data. */
8008 val = read_frame (buf, sizeof_buf);
8013 remote_serial_write ("-", 1);
8016 if (tries > MAX_TRIES)
8018 /* We have tried hard enough, and just can't receive the
8019 packet/notification. Give up. */
8020 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
8022 /* Skip the ack char if we're in no-ack mode. */
8023 if (!rs->noack_mode)
8024 remote_serial_write ("+", 1);
8028 /* If we got an ordinary packet, return that to our caller. */
8033 struct cleanup *old_chain;
8036 str = escape_buffer (*buf, val);
8037 old_chain = make_cleanup (xfree, str);
8038 fprintf_unfiltered (gdb_stdlog, "Packet received: %s\n", str);
8039 do_cleanups (old_chain);
8042 /* Skip the ack char if we're in no-ack mode. */
8043 if (!rs->noack_mode)
8044 remote_serial_write ("+", 1);
8045 if (is_notif != NULL)
8050 /* If we got a notification, handle it, and go back to looking
8054 gdb_assert (c == '%');
8058 struct cleanup *old_chain;
8061 str = escape_buffer (*buf, val);
8062 old_chain = make_cleanup (xfree, str);
8063 fprintf_unfiltered (gdb_stdlog,
8064 " Notification received: %s\n",
8066 do_cleanups (old_chain);
8068 if (is_notif != NULL)
8071 handle_notification (rs->notif_state, *buf);
8073 /* Notifications require no acknowledgement. */
8075 if (expecting_notif)
8082 getpkt_sane (char **buf, long *sizeof_buf, int forever)
8084 return getpkt_or_notif_sane_1 (buf, sizeof_buf, forever, 0, NULL);
8088 getpkt_or_notif_sane (char **buf, long *sizeof_buf, int forever,
8091 return getpkt_or_notif_sane_1 (buf, sizeof_buf, forever, 1,
8095 /* Check whether EVENT is a fork event for the process specified
8096 by the pid passed in DATA, and if it is, kill the fork child. */
8099 kill_child_of_pending_fork (QUEUE (stop_reply_p) *q,
8100 QUEUE_ITER (stop_reply_p) *iter,
8104 struct queue_iter_param *param = data;
8105 int parent_pid = *(int *) param->input;
8107 if (is_pending_fork_parent (&event->ws, parent_pid, event->ptid))
8109 struct remote_state *rs = get_remote_state ();
8110 int child_pid = ptid_get_pid (event->ws.value.related_pid);
8113 res = remote_vkill (child_pid, rs);
8115 error (_("Can't kill fork child process %d"), child_pid);
8121 /* Kill any new fork children of process PID that haven't been
8122 processed by follow_fork. */
8125 kill_new_fork_children (int pid, struct remote_state *rs)
8127 struct thread_info *thread;
8128 struct notif_client *notif = ¬if_client_stop;
8129 struct queue_iter_param param;
8131 /* Kill the fork child threads of any threads in process PID
8132 that are stopped at a fork event. */
8133 ALL_NON_EXITED_THREADS (thread)
8135 struct target_waitstatus *ws = &thread->pending_follow;
8137 if (is_pending_fork_parent (ws, pid, thread->ptid))
8139 struct remote_state *rs = get_remote_state ();
8140 int child_pid = ptid_get_pid (ws->value.related_pid);
8143 res = remote_vkill (child_pid, rs);
8145 error (_("Can't kill fork child process %d"), child_pid);
8149 /* Check for any pending fork events (not reported or processed yet)
8150 in process PID and kill those fork child threads as well. */
8151 remote_notif_get_pending_events (notif);
8153 param.output = NULL;
8154 QUEUE_iterate (stop_reply_p, stop_reply_queue,
8155 kill_child_of_pending_fork, ¶m);
8160 remote_kill (struct target_ops *ops)
8163 /* Catch errors so the user can quit from gdb even when we
8164 aren't on speaking terms with the remote system. */
8169 CATCH (ex, RETURN_MASK_ERROR)
8171 if (ex.error == TARGET_CLOSE_ERROR)
8173 /* If we got an (EOF) error that caused the target
8174 to go away, then we're done, that's what we wanted.
8175 "k" is susceptible to cause a premature EOF, given
8176 that the remote server isn't actually required to
8177 reply to "k", and it can happen that it doesn't
8178 even get to reply ACK to the "k". */
8182 /* Otherwise, something went wrong. We didn't actually kill
8183 the target. Just propagate the exception, and let the
8184 user or higher layers decide what to do. */
8185 throw_exception (ex);
8189 /* We've killed the remote end, we get to mourn it. Since this is
8190 target remote, single-process, mourning the inferior also
8191 unpushes remote_ops. */
8192 target_mourn_inferior ();
8196 remote_vkill (int pid, struct remote_state *rs)
8198 if (packet_support (PACKET_vKill) == PACKET_DISABLE)
8201 /* Tell the remote target to detach. */
8202 xsnprintf (rs->buf, get_remote_packet_size (), "vKill;%x", pid);
8204 getpkt (&rs->buf, &rs->buf_size, 0);
8206 switch (packet_ok (rs->buf,
8207 &remote_protocol_packets[PACKET_vKill]))
8213 case PACKET_UNKNOWN:
8216 internal_error (__FILE__, __LINE__, _("Bad result from packet_ok"));
8221 extended_remote_kill (struct target_ops *ops)
8224 int pid = ptid_get_pid (inferior_ptid);
8225 struct remote_state *rs = get_remote_state ();
8227 /* If we're stopped while forking and we haven't followed yet, kill the
8228 child task. We need to do this before killing the parent task
8229 because if this is a vfork then the parent will be sleeping. */
8230 kill_new_fork_children (pid, rs);
8232 res = remote_vkill (pid, rs);
8233 if (res == -1 && !(rs->extended && remote_multi_process_p (rs)))
8235 /* Don't try 'k' on a multi-process aware stub -- it has no way
8236 to specify the pid. */
8240 getpkt (&rs->buf, &rs->buf_size, 0);
8241 if (rs->buf[0] != 'O' || rs->buf[0] != 'K')
8244 /* Don't wait for it to die. I'm not really sure it matters whether
8245 we do or not. For the existing stubs, kill is a noop. */
8251 error (_("Can't kill process"));
8253 target_mourn_inferior ();
8257 remote_mourn (struct target_ops *target)
8259 unpush_target (target);
8261 /* remote_close takes care of doing most of the clean up. */
8262 generic_mourn_inferior ();
8266 extended_remote_mourn (struct target_ops *target)
8268 struct remote_state *rs = get_remote_state ();
8270 /* In case we got here due to an error, but we're going to stay
8272 rs->waiting_for_stop_reply = 0;
8274 /* If the current general thread belonged to the process we just
8275 detached from or has exited, the remote side current general
8276 thread becomes undefined. Considering a case like this:
8278 - We just got here due to a detach.
8279 - The process that we're detaching from happens to immediately
8280 report a global breakpoint being hit in non-stop mode, in the
8281 same thread we had selected before.
8282 - GDB attaches to this process again.
8283 - This event happens to be the next event we handle.
8285 GDB would consider that the current general thread didn't need to
8286 be set on the stub side (with Hg), since for all it knew,
8287 GENERAL_THREAD hadn't changed.
8289 Notice that although in all-stop mode, the remote server always
8290 sets the current thread to the thread reporting the stop event,
8291 that doesn't happen in non-stop mode; in non-stop, the stub *must
8292 not* change the current thread when reporting a breakpoint hit,
8293 due to the decoupling of event reporting and event handling.
8295 To keep things simple, we always invalidate our notion of the
8297 record_currthread (rs, minus_one_ptid);
8299 /* Unlike "target remote", we do not want to unpush the target; then
8300 the next time the user says "run", we won't be connected. */
8302 /* Call common code to mark the inferior as not running. */
8303 generic_mourn_inferior ();
8305 if (!have_inferiors ())
8307 if (!remote_multi_process_p (rs))
8309 /* Check whether the target is running now - some remote stubs
8310 automatically restart after kill. */
8312 getpkt (&rs->buf, &rs->buf_size, 0);
8314 if (rs->buf[0] == 'S' || rs->buf[0] == 'T')
8316 /* Assume that the target has been restarted. Set
8317 inferior_ptid so that bits of core GDB realizes
8318 there's something here, e.g., so that the user can
8319 say "kill" again. */
8320 inferior_ptid = magic_null_ptid;
8327 extended_remote_supports_disable_randomization (struct target_ops *self)
8329 return packet_support (PACKET_QDisableRandomization) == PACKET_ENABLE;
8333 extended_remote_disable_randomization (int val)
8335 struct remote_state *rs = get_remote_state ();
8338 xsnprintf (rs->buf, get_remote_packet_size (), "QDisableRandomization:%x",
8341 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
8343 error (_("Target does not support QDisableRandomization."));
8344 if (strcmp (reply, "OK") != 0)
8345 error (_("Bogus QDisableRandomization reply from target: %s"), reply);
8349 extended_remote_run (char *args)
8351 struct remote_state *rs = get_remote_state ();
8354 /* If the user has disabled vRun support, or we have detected that
8355 support is not available, do not try it. */
8356 if (packet_support (PACKET_vRun) == PACKET_DISABLE)
8359 strcpy (rs->buf, "vRun;");
8360 len = strlen (rs->buf);
8362 if (strlen (remote_exec_file) * 2 + len >= get_remote_packet_size ())
8363 error (_("Remote file name too long for run packet"));
8364 len += 2 * bin2hex ((gdb_byte *) remote_exec_file, rs->buf + len,
8365 strlen (remote_exec_file));
8367 gdb_assert (args != NULL);
8370 struct cleanup *back_to;
8374 argv = gdb_buildargv (args);
8375 back_to = make_cleanup_freeargv (argv);
8376 for (i = 0; argv[i] != NULL; i++)
8378 if (strlen (argv[i]) * 2 + 1 + len >= get_remote_packet_size ())
8379 error (_("Argument list too long for run packet"));
8380 rs->buf[len++] = ';';
8381 len += 2 * bin2hex ((gdb_byte *) argv[i], rs->buf + len,
8384 do_cleanups (back_to);
8387 rs->buf[len++] = '\0';
8390 getpkt (&rs->buf, &rs->buf_size, 0);
8392 switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_vRun]))
8395 /* We have a wait response. All is well. */
8397 case PACKET_UNKNOWN:
8400 if (remote_exec_file[0] == '\0')
8401 error (_("Running the default executable on the remote target failed; "
8402 "try \"set remote exec-file\"?"));
8404 error (_("Running \"%s\" on the remote target failed"),
8407 gdb_assert_not_reached (_("bad switch"));
8411 /* In the extended protocol we want to be able to do things like
8412 "run" and have them basically work as expected. So we need
8413 a special create_inferior function. We support changing the
8414 executable file and the command line arguments, but not the
8418 extended_remote_create_inferior (struct target_ops *ops,
8419 char *exec_file, char *args,
8420 char **env, int from_tty)
8424 struct remote_state *rs = get_remote_state ();
8426 /* If running asynchronously, register the target file descriptor
8427 with the event loop. */
8428 if (target_can_async_p ())
8431 /* Disable address space randomization if requested (and supported). */
8432 if (extended_remote_supports_disable_randomization (ops))
8433 extended_remote_disable_randomization (disable_randomization);
8435 /* Now restart the remote server. */
8436 run_worked = extended_remote_run (args) != -1;
8439 /* vRun was not supported. Fail if we need it to do what the
8441 if (remote_exec_file[0])
8442 error (_("Remote target does not support \"set remote exec-file\""));
8444 error (_("Remote target does not support \"set args\" or run <ARGS>"));
8446 /* Fall back to "R". */
8447 extended_remote_restart ();
8450 if (!have_inferiors ())
8452 /* Clean up from the last time we ran, before we mark the target
8453 running again. This will mark breakpoints uninserted, and
8454 get_offsets may insert breakpoints. */
8455 init_thread_list ();
8456 init_wait_for_inferior ();
8459 /* vRun's success return is a stop reply. */
8460 stop_reply = run_worked ? rs->buf : NULL;
8461 add_current_inferior_and_thread (stop_reply);
8463 /* Get updated offsets, if the stub uses qOffsets. */
8468 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8469 the list of conditions (in agent expression bytecode format), if any, the
8470 target needs to evaluate. The output is placed into the packet buffer
8471 started from BUF and ended at BUF_END. */
8474 remote_add_target_side_condition (struct gdbarch *gdbarch,
8475 struct bp_target_info *bp_tgt, char *buf,
8478 struct agent_expr *aexpr = NULL;
8481 char *buf_start = buf;
8483 if (VEC_empty (agent_expr_p, bp_tgt->conditions))
8486 buf += strlen (buf);
8487 xsnprintf (buf, buf_end - buf, "%s", ";");
8490 /* Send conditions to the target and free the vector. */
8492 VEC_iterate (agent_expr_p, bp_tgt->conditions, ix, aexpr);
8495 xsnprintf (buf, buf_end - buf, "X%x,", aexpr->len);
8496 buf += strlen (buf);
8497 for (i = 0; i < aexpr->len; ++i)
8498 buf = pack_hex_byte (buf, aexpr->buf[i]);
8505 remote_add_target_side_commands (struct gdbarch *gdbarch,
8506 struct bp_target_info *bp_tgt, char *buf)
8508 struct agent_expr *aexpr = NULL;
8511 if (VEC_empty (agent_expr_p, bp_tgt->tcommands))
8514 buf += strlen (buf);
8516 sprintf (buf, ";cmds:%x,", bp_tgt->persist);
8517 buf += strlen (buf);
8519 /* Concatenate all the agent expressions that are commands into the
8522 VEC_iterate (agent_expr_p, bp_tgt->tcommands, ix, aexpr);
8525 sprintf (buf, "X%x,", aexpr->len);
8526 buf += strlen (buf);
8527 for (i = 0; i < aexpr->len; ++i)
8528 buf = pack_hex_byte (buf, aexpr->buf[i]);
8533 /* Insert a breakpoint. On targets that have software breakpoint
8534 support, we ask the remote target to do the work; on targets
8535 which don't, we insert a traditional memory breakpoint. */
8538 remote_insert_breakpoint (struct target_ops *ops,
8539 struct gdbarch *gdbarch,
8540 struct bp_target_info *bp_tgt)
8542 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8543 If it succeeds, then set the support to PACKET_ENABLE. If it
8544 fails, and the user has explicitly requested the Z support then
8545 report an error, otherwise, mark it disabled and go on. */
8547 if (packet_support (PACKET_Z0) != PACKET_DISABLE)
8549 CORE_ADDR addr = bp_tgt->reqstd_address;
8550 struct remote_state *rs;
8553 struct condition_list *cond = NULL;
8555 /* Make sure the remote is pointing at the right process, if
8557 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8558 set_general_process ();
8560 gdbarch_remote_breakpoint_from_pc (gdbarch, &addr, &bpsize);
8562 rs = get_remote_state ();
8564 endbuf = rs->buf + get_remote_packet_size ();
8569 addr = (ULONGEST) remote_address_masked (addr);
8570 p += hexnumstr (p, addr);
8571 xsnprintf (p, endbuf - p, ",%d", bpsize);
8573 if (remote_supports_cond_breakpoints (ops))
8574 remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
8576 if (remote_can_run_breakpoint_commands (ops))
8577 remote_add_target_side_commands (gdbarch, bp_tgt, p);
8580 getpkt (&rs->buf, &rs->buf_size, 0);
8582 switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z0]))
8587 bp_tgt->placed_address = addr;
8588 bp_tgt->placed_size = bpsize;
8590 case PACKET_UNKNOWN:
8595 /* If this breakpoint has target-side commands but this stub doesn't
8596 support Z0 packets, throw error. */
8597 if (!VEC_empty (agent_expr_p, bp_tgt->tcommands))
8598 throw_error (NOT_SUPPORTED_ERROR, _("\
8599 Target doesn't support breakpoints that have target side commands."));
8601 return memory_insert_breakpoint (ops, gdbarch, bp_tgt);
8605 remote_remove_breakpoint (struct target_ops *ops,
8606 struct gdbarch *gdbarch,
8607 struct bp_target_info *bp_tgt)
8609 CORE_ADDR addr = bp_tgt->placed_address;
8610 struct remote_state *rs = get_remote_state ();
8612 if (packet_support (PACKET_Z0) != PACKET_DISABLE)
8615 char *endbuf = rs->buf + get_remote_packet_size ();
8617 /* Make sure the remote is pointing at the right process, if
8619 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8620 set_general_process ();
8626 addr = (ULONGEST) remote_address_masked (bp_tgt->placed_address);
8627 p += hexnumstr (p, addr);
8628 xsnprintf (p, endbuf - p, ",%d", bp_tgt->placed_size);
8631 getpkt (&rs->buf, &rs->buf_size, 0);
8633 return (rs->buf[0] == 'E');
8636 return memory_remove_breakpoint (ops, gdbarch, bp_tgt);
8640 watchpoint_to_Z_packet (int type)
8645 return Z_PACKET_WRITE_WP;
8648 return Z_PACKET_READ_WP;
8651 return Z_PACKET_ACCESS_WP;
8654 internal_error (__FILE__, __LINE__,
8655 _("hw_bp_to_z: bad watchpoint type %d"), type);
8660 remote_insert_watchpoint (struct target_ops *self,
8661 CORE_ADDR addr, int len, int type,
8662 struct expression *cond)
8664 struct remote_state *rs = get_remote_state ();
8665 char *endbuf = rs->buf + get_remote_packet_size ();
8667 enum Z_packet_type packet = watchpoint_to_Z_packet (type);
8669 if (packet_support (PACKET_Z0 + packet) == PACKET_DISABLE)
8672 /* Make sure the remote is pointing at the right process, if
8674 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8675 set_general_process ();
8677 xsnprintf (rs->buf, endbuf - rs->buf, "Z%x,", packet);
8678 p = strchr (rs->buf, '\0');
8679 addr = remote_address_masked (addr);
8680 p += hexnumstr (p, (ULONGEST) addr);
8681 xsnprintf (p, endbuf - p, ",%x", len);
8684 getpkt (&rs->buf, &rs->buf_size, 0);
8686 switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z0 + packet]))
8690 case PACKET_UNKNOWN:
8695 internal_error (__FILE__, __LINE__,
8696 _("remote_insert_watchpoint: reached end of function"));
8700 remote_watchpoint_addr_within_range (struct target_ops *target, CORE_ADDR addr,
8701 CORE_ADDR start, int length)
8703 CORE_ADDR diff = remote_address_masked (addr - start);
8705 return diff < length;
8710 remote_remove_watchpoint (struct target_ops *self,
8711 CORE_ADDR addr, int len, int type,
8712 struct expression *cond)
8714 struct remote_state *rs = get_remote_state ();
8715 char *endbuf = rs->buf + get_remote_packet_size ();
8717 enum Z_packet_type packet = watchpoint_to_Z_packet (type);
8719 if (packet_support (PACKET_Z0 + packet) == PACKET_DISABLE)
8722 /* Make sure the remote is pointing at the right process, if
8724 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8725 set_general_process ();
8727 xsnprintf (rs->buf, endbuf - rs->buf, "z%x,", packet);
8728 p = strchr (rs->buf, '\0');
8729 addr = remote_address_masked (addr);
8730 p += hexnumstr (p, (ULONGEST) addr);
8731 xsnprintf (p, endbuf - p, ",%x", len);
8733 getpkt (&rs->buf, &rs->buf_size, 0);
8735 switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z0 + packet]))
8738 case PACKET_UNKNOWN:
8743 internal_error (__FILE__, __LINE__,
8744 _("remote_remove_watchpoint: reached end of function"));
8748 int remote_hw_watchpoint_limit = -1;
8749 int remote_hw_watchpoint_length_limit = -1;
8750 int remote_hw_breakpoint_limit = -1;
8753 remote_region_ok_for_hw_watchpoint (struct target_ops *self,
8754 CORE_ADDR addr, int len)
8756 if (remote_hw_watchpoint_length_limit == 0)
8758 else if (remote_hw_watchpoint_length_limit < 0)
8760 else if (len <= remote_hw_watchpoint_length_limit)
8767 remote_check_watch_resources (struct target_ops *self,
8768 int type, int cnt, int ot)
8770 if (type == bp_hardware_breakpoint)
8772 if (remote_hw_breakpoint_limit == 0)
8774 else if (remote_hw_breakpoint_limit < 0)
8776 else if (cnt <= remote_hw_breakpoint_limit)
8781 if (remote_hw_watchpoint_limit == 0)
8783 else if (remote_hw_watchpoint_limit < 0)
8787 else if (cnt <= remote_hw_watchpoint_limit)
8793 /* The to_stopped_by_sw_breakpoint method of target remote. */
8796 remote_stopped_by_sw_breakpoint (struct target_ops *ops)
8798 struct remote_state *rs = get_remote_state ();
8800 return rs->stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT;
8803 /* The to_supports_stopped_by_sw_breakpoint method of target
8807 remote_supports_stopped_by_sw_breakpoint (struct target_ops *ops)
8809 struct remote_state *rs = get_remote_state ();
8811 return (packet_support (PACKET_swbreak_feature) == PACKET_ENABLE);
8814 /* The to_stopped_by_hw_breakpoint method of target remote. */
8817 remote_stopped_by_hw_breakpoint (struct target_ops *ops)
8819 struct remote_state *rs = get_remote_state ();
8821 return rs->stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT;
8824 /* The to_supports_stopped_by_hw_breakpoint method of target
8828 remote_supports_stopped_by_hw_breakpoint (struct target_ops *ops)
8830 struct remote_state *rs = get_remote_state ();
8832 return (packet_support (PACKET_hwbreak_feature) == PACKET_ENABLE);
8836 remote_stopped_by_watchpoint (struct target_ops *ops)
8838 struct remote_state *rs = get_remote_state ();
8840 return rs->stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
8844 remote_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
8846 struct remote_state *rs = get_remote_state ();
8849 if (remote_stopped_by_watchpoint (target))
8851 *addr_p = rs->remote_watch_data_address;
8860 remote_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
8861 struct bp_target_info *bp_tgt)
8863 CORE_ADDR addr = bp_tgt->reqstd_address;
8864 struct remote_state *rs;
8869 /* The length field should be set to the size of a breakpoint
8870 instruction, even though we aren't inserting one ourselves. */
8872 gdbarch_remote_breakpoint_from_pc (gdbarch, &addr, &bpsize);
8874 if (packet_support (PACKET_Z1) == PACKET_DISABLE)
8877 /* Make sure the remote is pointing at the right process, if
8879 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8880 set_general_process ();
8882 rs = get_remote_state ();
8884 endbuf = rs->buf + get_remote_packet_size ();
8890 addr = remote_address_masked (addr);
8891 p += hexnumstr (p, (ULONGEST) addr);
8892 xsnprintf (p, endbuf - p, ",%x", bpsize);
8894 if (remote_supports_cond_breakpoints (self))
8895 remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
8897 if (remote_can_run_breakpoint_commands (self))
8898 remote_add_target_side_commands (gdbarch, bp_tgt, p);
8901 getpkt (&rs->buf, &rs->buf_size, 0);
8903 switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z1]))
8906 if (rs->buf[1] == '.')
8908 message = strchr (rs->buf + 2, '.');
8910 error (_("Remote failure reply: %s"), message + 1);
8913 case PACKET_UNKNOWN:
8916 bp_tgt->placed_address = addr;
8917 bp_tgt->placed_size = bpsize;
8920 internal_error (__FILE__, __LINE__,
8921 _("remote_insert_hw_breakpoint: reached end of function"));
8926 remote_remove_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
8927 struct bp_target_info *bp_tgt)
8930 struct remote_state *rs = get_remote_state ();
8932 char *endbuf = rs->buf + get_remote_packet_size ();
8934 if (packet_support (PACKET_Z1) == PACKET_DISABLE)
8937 /* Make sure the remote is pointing at the right process, if
8939 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8940 set_general_process ();
8946 addr = remote_address_masked (bp_tgt->placed_address);
8947 p += hexnumstr (p, (ULONGEST) addr);
8948 xsnprintf (p, endbuf - p, ",%x", bp_tgt->placed_size);
8951 getpkt (&rs->buf, &rs->buf_size, 0);
8953 switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z1]))
8956 case PACKET_UNKNOWN:
8961 internal_error (__FILE__, __LINE__,
8962 _("remote_remove_hw_breakpoint: reached end of function"));
8965 /* Verify memory using the "qCRC:" request. */
8968 remote_verify_memory (struct target_ops *ops,
8969 const gdb_byte *data, CORE_ADDR lma, ULONGEST size)
8971 struct remote_state *rs = get_remote_state ();
8972 unsigned long host_crc, target_crc;
8975 /* It doesn't make sense to use qCRC if the remote target is
8976 connected but not running. */
8977 if (target_has_execution && packet_support (PACKET_qCRC) != PACKET_DISABLE)
8979 enum packet_result result;
8981 /* Make sure the remote is pointing at the right process. */
8982 set_general_process ();
8984 /* FIXME: assumes lma can fit into long. */
8985 xsnprintf (rs->buf, get_remote_packet_size (), "qCRC:%lx,%lx",
8986 (long) lma, (long) size);
8989 /* Be clever; compute the host_crc before waiting for target
8991 host_crc = xcrc32 (data, size, 0xffffffff);
8993 getpkt (&rs->buf, &rs->buf_size, 0);
8995 result = packet_ok (rs->buf,
8996 &remote_protocol_packets[PACKET_qCRC]);
8997 if (result == PACKET_ERROR)
8999 else if (result == PACKET_OK)
9001 for (target_crc = 0, tmp = &rs->buf[1]; *tmp; tmp++)
9002 target_crc = target_crc * 16 + fromhex (*tmp);
9004 return (host_crc == target_crc);
9008 return simple_verify_memory (ops, data, lma, size);
9011 /* compare-sections command
9013 With no arguments, compares each loadable section in the exec bfd
9014 with the same memory range on the target, and reports mismatches.
9015 Useful for verifying the image on the target against the exec file. */
9018 compare_sections_command (char *args, int from_tty)
9021 struct cleanup *old_chain;
9023 const char *sectname;
9032 error (_("command cannot be used without an exec file"));
9034 /* Make sure the remote is pointing at the right process. */
9035 set_general_process ();
9037 if (args != NULL && strcmp (args, "-r") == 0)
9043 for (s = exec_bfd->sections; s; s = s->next)
9045 if (!(s->flags & SEC_LOAD))
9046 continue; /* Skip non-loadable section. */
9048 if (read_only && (s->flags & SEC_READONLY) == 0)
9049 continue; /* Skip writeable sections */
9051 size = bfd_get_section_size (s);
9053 continue; /* Skip zero-length section. */
9055 sectname = bfd_get_section_name (exec_bfd, s);
9056 if (args && strcmp (args, sectname) != 0)
9057 continue; /* Not the section selected by user. */
9059 matched = 1; /* Do this section. */
9062 sectdata = xmalloc (size);
9063 old_chain = make_cleanup (xfree, sectdata);
9064 bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
9066 res = target_verify_memory (sectdata, lma, size);
9069 error (_("target memory fault, section %s, range %s -- %s"), sectname,
9070 paddress (target_gdbarch (), lma),
9071 paddress (target_gdbarch (), lma + size));
9073 printf_filtered ("Section %s, range %s -- %s: ", sectname,
9074 paddress (target_gdbarch (), lma),
9075 paddress (target_gdbarch (), lma + size));
9077 printf_filtered ("matched.\n");
9080 printf_filtered ("MIS-MATCHED!\n");
9084 do_cleanups (old_chain);
9087 warning (_("One or more sections of the target image does not match\n\
9088 the loaded file\n"));
9089 if (args && !matched)
9090 printf_filtered (_("No loaded section named '%s'.\n"), args);
9093 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
9094 into remote target. The number of bytes written to the remote
9095 target is returned, or -1 for error. */
9097 static enum target_xfer_status
9098 remote_write_qxfer (struct target_ops *ops, const char *object_name,
9099 const char *annex, const gdb_byte *writebuf,
9100 ULONGEST offset, LONGEST len, ULONGEST *xfered_len,
9101 struct packet_config *packet)
9105 struct remote_state *rs = get_remote_state ();
9106 int max_size = get_memory_write_packet_size ();
9108 if (packet->support == PACKET_DISABLE)
9109 return TARGET_XFER_E_IO;
9111 /* Insert header. */
9112 i = snprintf (rs->buf, max_size,
9113 "qXfer:%s:write:%s:%s:",
9114 object_name, annex ? annex : "",
9115 phex_nz (offset, sizeof offset));
9116 max_size -= (i + 1);
9118 /* Escape as much data as fits into rs->buf. */
9119 buf_len = remote_escape_output
9120 (writebuf, len, (gdb_byte *) rs->buf + i, &max_size, max_size);
9122 if (putpkt_binary (rs->buf, i + buf_len) < 0
9123 || getpkt_sane (&rs->buf, &rs->buf_size, 0) < 0
9124 || packet_ok (rs->buf, packet) != PACKET_OK)
9125 return TARGET_XFER_E_IO;
9127 unpack_varlen_hex (rs->buf, &n);
9130 return TARGET_XFER_OK;
9133 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
9134 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
9135 number of bytes read is returned, or 0 for EOF, or -1 for error.
9136 The number of bytes read may be less than LEN without indicating an
9137 EOF. PACKET is checked and updated to indicate whether the remote
9138 target supports this object. */
9140 static enum target_xfer_status
9141 remote_read_qxfer (struct target_ops *ops, const char *object_name,
9143 gdb_byte *readbuf, ULONGEST offset, LONGEST len,
9144 ULONGEST *xfered_len,
9145 struct packet_config *packet)
9147 struct remote_state *rs = get_remote_state ();
9148 LONGEST i, n, packet_len;
9150 if (packet->support == PACKET_DISABLE)
9151 return TARGET_XFER_E_IO;
9153 /* Check whether we've cached an end-of-object packet that matches
9155 if (rs->finished_object)
9157 if (strcmp (object_name, rs->finished_object) == 0
9158 && strcmp (annex ? annex : "", rs->finished_annex) == 0
9159 && offset == rs->finished_offset)
9160 return TARGET_XFER_EOF;
9163 /* Otherwise, we're now reading something different. Discard
9165 xfree (rs->finished_object);
9166 xfree (rs->finished_annex);
9167 rs->finished_object = NULL;
9168 rs->finished_annex = NULL;
9171 /* Request only enough to fit in a single packet. The actual data
9172 may not, since we don't know how much of it will need to be escaped;
9173 the target is free to respond with slightly less data. We subtract
9174 five to account for the response type and the protocol frame. */
9175 n = min (get_remote_packet_size () - 5, len);
9176 snprintf (rs->buf, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
9177 object_name, annex ? annex : "",
9178 phex_nz (offset, sizeof offset),
9179 phex_nz (n, sizeof n));
9180 i = putpkt (rs->buf);
9182 return TARGET_XFER_E_IO;
9185 packet_len = getpkt_sane (&rs->buf, &rs->buf_size, 0);
9186 if (packet_len < 0 || packet_ok (rs->buf, packet) != PACKET_OK)
9187 return TARGET_XFER_E_IO;
9189 if (rs->buf[0] != 'l' && rs->buf[0] != 'm')
9190 error (_("Unknown remote qXfer reply: %s"), rs->buf);
9192 /* 'm' means there is (or at least might be) more data after this
9193 batch. That does not make sense unless there's at least one byte
9194 of data in this reply. */
9195 if (rs->buf[0] == 'm' && packet_len == 1)
9196 error (_("Remote qXfer reply contained no data."));
9198 /* Got some data. */
9199 i = remote_unescape_input ((gdb_byte *) rs->buf + 1,
9200 packet_len - 1, readbuf, n);
9202 /* 'l' is an EOF marker, possibly including a final block of data,
9203 or possibly empty. If we have the final block of a non-empty
9204 object, record this fact to bypass a subsequent partial read. */
9205 if (rs->buf[0] == 'l' && offset + i > 0)
9207 rs->finished_object = xstrdup (object_name);
9208 rs->finished_annex = xstrdup (annex ? annex : "");
9209 rs->finished_offset = offset + i;
9213 return TARGET_XFER_EOF;
9217 return TARGET_XFER_OK;
9221 static enum target_xfer_status
9222 remote_xfer_partial (struct target_ops *ops, enum target_object object,
9223 const char *annex, gdb_byte *readbuf,
9224 const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
9225 ULONGEST *xfered_len)
9227 struct remote_state *rs;
9232 set_remote_traceframe ();
9233 set_general_thread (inferior_ptid);
9235 rs = get_remote_state ();
9237 /* Handle memory using the standard memory routines. */
9238 if (object == TARGET_OBJECT_MEMORY)
9240 /* If the remote target is connected but not running, we should
9241 pass this request down to a lower stratum (e.g. the executable
9243 if (!target_has_execution)
9244 return TARGET_XFER_EOF;
9246 if (writebuf != NULL)
9247 return remote_write_bytes (offset, writebuf, len, xfered_len);
9249 return remote_read_bytes (ops, offset, readbuf, len, xfered_len);
9252 /* Handle SPU memory using qxfer packets. */
9253 if (object == TARGET_OBJECT_SPU)
9256 return remote_read_qxfer (ops, "spu", annex, readbuf, offset, len,
9257 xfered_len, &remote_protocol_packets
9258 [PACKET_qXfer_spu_read]);
9260 return remote_write_qxfer (ops, "spu", annex, writebuf, offset, len,
9261 xfered_len, &remote_protocol_packets
9262 [PACKET_qXfer_spu_write]);
9265 /* Handle extra signal info using qxfer packets. */
9266 if (object == TARGET_OBJECT_SIGNAL_INFO)
9269 return remote_read_qxfer (ops, "siginfo", annex, readbuf, offset, len,
9270 xfered_len, &remote_protocol_packets
9271 [PACKET_qXfer_siginfo_read]);
9273 return remote_write_qxfer (ops, "siginfo", annex,
9274 writebuf, offset, len, xfered_len,
9275 &remote_protocol_packets
9276 [PACKET_qXfer_siginfo_write]);
9279 if (object == TARGET_OBJECT_STATIC_TRACE_DATA)
9282 return remote_read_qxfer (ops, "statictrace", annex,
9283 readbuf, offset, len, xfered_len,
9284 &remote_protocol_packets
9285 [PACKET_qXfer_statictrace_read]);
9287 return TARGET_XFER_E_IO;
9290 /* Only handle flash writes. */
9291 if (writebuf != NULL)
9297 case TARGET_OBJECT_FLASH:
9298 return remote_flash_write (ops, offset, len, xfered_len,
9302 return TARGET_XFER_E_IO;
9306 /* Map pre-existing objects onto letters. DO NOT do this for new
9307 objects!!! Instead specify new query packets. */
9310 case TARGET_OBJECT_AVR:
9314 case TARGET_OBJECT_AUXV:
9315 gdb_assert (annex == NULL);
9316 return remote_read_qxfer (ops, "auxv", annex, readbuf, offset, len,
9318 &remote_protocol_packets[PACKET_qXfer_auxv]);
9320 case TARGET_OBJECT_AVAILABLE_FEATURES:
9321 return remote_read_qxfer
9322 (ops, "features", annex, readbuf, offset, len, xfered_len,
9323 &remote_protocol_packets[PACKET_qXfer_features]);
9325 case TARGET_OBJECT_LIBRARIES:
9326 return remote_read_qxfer
9327 (ops, "libraries", annex, readbuf, offset, len, xfered_len,
9328 &remote_protocol_packets[PACKET_qXfer_libraries]);
9330 case TARGET_OBJECT_LIBRARIES_SVR4:
9331 return remote_read_qxfer
9332 (ops, "libraries-svr4", annex, readbuf, offset, len, xfered_len,
9333 &remote_protocol_packets[PACKET_qXfer_libraries_svr4]);
9335 case TARGET_OBJECT_MEMORY_MAP:
9336 gdb_assert (annex == NULL);
9337 return remote_read_qxfer (ops, "memory-map", annex, readbuf, offset, len,
9339 &remote_protocol_packets[PACKET_qXfer_memory_map]);
9341 case TARGET_OBJECT_OSDATA:
9342 /* Should only get here if we're connected. */
9343 gdb_assert (rs->remote_desc);
9344 return remote_read_qxfer
9345 (ops, "osdata", annex, readbuf, offset, len, xfered_len,
9346 &remote_protocol_packets[PACKET_qXfer_osdata]);
9348 case TARGET_OBJECT_THREADS:
9349 gdb_assert (annex == NULL);
9350 return remote_read_qxfer (ops, "threads", annex, readbuf, offset, len,
9352 &remote_protocol_packets[PACKET_qXfer_threads]);
9354 case TARGET_OBJECT_TRACEFRAME_INFO:
9355 gdb_assert (annex == NULL);
9356 return remote_read_qxfer
9357 (ops, "traceframe-info", annex, readbuf, offset, len, xfered_len,
9358 &remote_protocol_packets[PACKET_qXfer_traceframe_info]);
9360 case TARGET_OBJECT_FDPIC:
9361 return remote_read_qxfer (ops, "fdpic", annex, readbuf, offset, len,
9363 &remote_protocol_packets[PACKET_qXfer_fdpic]);
9365 case TARGET_OBJECT_OPENVMS_UIB:
9366 return remote_read_qxfer (ops, "uib", annex, readbuf, offset, len,
9368 &remote_protocol_packets[PACKET_qXfer_uib]);
9370 case TARGET_OBJECT_BTRACE:
9371 return remote_read_qxfer (ops, "btrace", annex, readbuf, offset, len,
9373 &remote_protocol_packets[PACKET_qXfer_btrace]);
9375 case TARGET_OBJECT_BTRACE_CONF:
9376 return remote_read_qxfer (ops, "btrace-conf", annex, readbuf, offset,
9378 &remote_protocol_packets[PACKET_qXfer_btrace_conf]);
9380 case TARGET_OBJECT_EXEC_FILE:
9381 return remote_read_qxfer (ops, "exec-file", annex, readbuf, offset,
9383 &remote_protocol_packets[PACKET_qXfer_exec_file]);
9386 return TARGET_XFER_E_IO;
9389 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
9390 large enough let the caller deal with it. */
9391 if (len < get_remote_packet_size ())
9392 return TARGET_XFER_E_IO;
9393 len = get_remote_packet_size ();
9395 /* Except for querying the minimum buffer size, target must be open. */
9396 if (!rs->remote_desc)
9397 error (_("remote query is only available after target open"));
9399 gdb_assert (annex != NULL);
9400 gdb_assert (readbuf != NULL);
9406 /* We used one buffer char for the remote protocol q command and
9407 another for the query type. As the remote protocol encapsulation
9408 uses 4 chars plus one extra in case we are debugging
9409 (remote_debug), we have PBUFZIZ - 7 left to pack the query
9412 while (annex[i] && (i < (get_remote_packet_size () - 8)))
9414 /* Bad caller may have sent forbidden characters. */
9415 gdb_assert (isprint (annex[i]) && annex[i] != '$' && annex[i] != '#');
9420 gdb_assert (annex[i] == '\0');
9422 i = putpkt (rs->buf);
9424 return TARGET_XFER_E_IO;
9426 getpkt (&rs->buf, &rs->buf_size, 0);
9427 strcpy ((char *) readbuf, rs->buf);
9429 *xfered_len = strlen ((char *) readbuf);
9430 return TARGET_XFER_OK;
9434 remote_search_memory (struct target_ops* ops,
9435 CORE_ADDR start_addr, ULONGEST search_space_len,
9436 const gdb_byte *pattern, ULONGEST pattern_len,
9437 CORE_ADDR *found_addrp)
9439 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
9440 struct remote_state *rs = get_remote_state ();
9441 int max_size = get_memory_write_packet_size ();
9442 struct packet_config *packet =
9443 &remote_protocol_packets[PACKET_qSearch_memory];
9444 /* Number of packet bytes used to encode the pattern;
9445 this could be more than PATTERN_LEN due to escape characters. */
9446 int escaped_pattern_len;
9447 /* Amount of pattern that was encodable in the packet. */
9448 int used_pattern_len;
9451 ULONGEST found_addr;
9453 /* Don't go to the target if we don't have to.
9454 This is done before checking packet->support to avoid the possibility that
9455 a success for this edge case means the facility works in general. */
9456 if (pattern_len > search_space_len)
9458 if (pattern_len == 0)
9460 *found_addrp = start_addr;
9464 /* If we already know the packet isn't supported, fall back to the simple
9465 way of searching memory. */
9467 if (packet_config_support (packet) == PACKET_DISABLE)
9469 /* Target doesn't provided special support, fall back and use the
9470 standard support (copy memory and do the search here). */
9471 return simple_search_memory (ops, start_addr, search_space_len,
9472 pattern, pattern_len, found_addrp);
9475 /* Make sure the remote is pointing at the right process. */
9476 set_general_process ();
9478 /* Insert header. */
9479 i = snprintf (rs->buf, max_size,
9480 "qSearch:memory:%s;%s;",
9481 phex_nz (start_addr, addr_size),
9482 phex_nz (search_space_len, sizeof (search_space_len)));
9483 max_size -= (i + 1);
9485 /* Escape as much data as fits into rs->buf. */
9486 escaped_pattern_len =
9487 remote_escape_output (pattern, pattern_len, (gdb_byte *) rs->buf + i,
9488 &used_pattern_len, max_size);
9490 /* Bail if the pattern is too large. */
9491 if (used_pattern_len != pattern_len)
9492 error (_("Pattern is too large to transmit to remote target."));
9494 if (putpkt_binary (rs->buf, i + escaped_pattern_len) < 0
9495 || getpkt_sane (&rs->buf, &rs->buf_size, 0) < 0
9496 || packet_ok (rs->buf, packet) != PACKET_OK)
9498 /* The request may not have worked because the command is not
9499 supported. If so, fall back to the simple way. */
9500 if (packet->support == PACKET_DISABLE)
9502 return simple_search_memory (ops, start_addr, search_space_len,
9503 pattern, pattern_len, found_addrp);
9508 if (rs->buf[0] == '0')
9510 else if (rs->buf[0] == '1')
9513 if (rs->buf[1] != ',')
9514 error (_("Unknown qSearch:memory reply: %s"), rs->buf);
9515 unpack_varlen_hex (rs->buf + 2, &found_addr);
9516 *found_addrp = found_addr;
9519 error (_("Unknown qSearch:memory reply: %s"), rs->buf);
9525 remote_rcmd (struct target_ops *self, const char *command,
9526 struct ui_file *outbuf)
9528 struct remote_state *rs = get_remote_state ();
9531 if (!rs->remote_desc)
9532 error (_("remote rcmd is only available after target open"));
9534 /* Send a NULL command across as an empty command. */
9535 if (command == NULL)
9538 /* The query prefix. */
9539 strcpy (rs->buf, "qRcmd,");
9540 p = strchr (rs->buf, '\0');
9542 if ((strlen (rs->buf) + strlen (command) * 2 + 8/*misc*/)
9543 > get_remote_packet_size ())
9544 error (_("\"monitor\" command ``%s'' is too long."), command);
9546 /* Encode the actual command. */
9547 bin2hex ((const gdb_byte *) command, p, strlen (command));
9549 if (putpkt (rs->buf) < 0)
9550 error (_("Communication problem with target."));
9552 /* get/display the response */
9557 /* XXX - see also remote_get_noisy_reply(). */
9558 QUIT; /* Allow user to bail out with ^C. */
9560 if (getpkt_sane (&rs->buf, &rs->buf_size, 0) == -1)
9562 /* Timeout. Continue to (try to) read responses.
9563 This is better than stopping with an error, assuming the stub
9564 is still executing the (long) monitor command.
9565 If needed, the user can interrupt gdb using C-c, obtaining
9566 an effect similar to stop on timeout. */
9571 error (_("Target does not support this command."));
9572 if (buf[0] == 'O' && buf[1] != 'K')
9574 remote_console_output (buf + 1); /* 'O' message from stub. */
9577 if (strcmp (buf, "OK") == 0)
9579 if (strlen (buf) == 3 && buf[0] == 'E'
9580 && isdigit (buf[1]) && isdigit (buf[2]))
9582 error (_("Protocol error with Rcmd"));
9584 for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
9586 char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
9588 fputc_unfiltered (c, outbuf);
9594 static VEC(mem_region_s) *
9595 remote_memory_map (struct target_ops *ops)
9597 VEC(mem_region_s) *result = NULL;
9598 char *text = target_read_stralloc (¤t_target,
9599 TARGET_OBJECT_MEMORY_MAP, NULL);
9603 struct cleanup *back_to = make_cleanup (xfree, text);
9605 result = parse_memory_map (text);
9606 do_cleanups (back_to);
9613 packet_command (char *args, int from_tty)
9615 struct remote_state *rs = get_remote_state ();
9617 if (!rs->remote_desc)
9618 error (_("command can only be used with remote target"));
9621 error (_("remote-packet command requires packet text as argument"));
9623 puts_filtered ("sending: ");
9624 print_packet (args);
9625 puts_filtered ("\n");
9628 getpkt (&rs->buf, &rs->buf_size, 0);
9629 puts_filtered ("received: ");
9630 print_packet (rs->buf);
9631 puts_filtered ("\n");
9635 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9637 static void display_thread_info (struct gdb_ext_thread_info *info);
9639 static void threadset_test_cmd (char *cmd, int tty);
9641 static void threadalive_test (char *cmd, int tty);
9643 static void threadlist_test_cmd (char *cmd, int tty);
9645 int get_and_display_threadinfo (threadref *ref);
9647 static void threadinfo_test_cmd (char *cmd, int tty);
9649 static int thread_display_step (threadref *ref, void *context);
9651 static void threadlist_update_test_cmd (char *cmd, int tty);
9653 static void init_remote_threadtests (void);
9655 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9658 threadset_test_cmd (char *cmd, int tty)
9660 int sample_thread = SAMPLE_THREAD;
9662 printf_filtered (_("Remote threadset test\n"));
9663 set_general_thread (sample_thread);
9668 threadalive_test (char *cmd, int tty)
9670 int sample_thread = SAMPLE_THREAD;
9671 int pid = ptid_get_pid (inferior_ptid);
9672 ptid_t ptid = ptid_build (pid, sample_thread, 0);
9674 if (remote_thread_alive (ptid))
9675 printf_filtered ("PASS: Thread alive test\n");
9677 printf_filtered ("FAIL: Thread alive test\n");
9680 void output_threadid (char *title, threadref *ref);
9683 output_threadid (char *title, threadref *ref)
9687 pack_threadid (&hexid[0], ref); /* Convert threead id into hex. */
9689 printf_filtered ("%s %s\n", title, (&hexid[0]));
9693 threadlist_test_cmd (char *cmd, int tty)
9696 threadref nextthread;
9697 int done, result_count;
9698 threadref threadlist[3];
9700 printf_filtered ("Remote Threadlist test\n");
9701 if (!remote_get_threadlist (startflag, &nextthread, 3, &done,
9702 &result_count, &threadlist[0]))
9703 printf_filtered ("FAIL: threadlist test\n");
9706 threadref *scan = threadlist;
9707 threadref *limit = scan + result_count;
9709 while (scan < limit)
9710 output_threadid (" thread ", scan++);
9715 display_thread_info (struct gdb_ext_thread_info *info)
9717 output_threadid ("Threadid: ", &info->threadid);
9718 printf_filtered ("Name: %s\n ", info->shortname);
9719 printf_filtered ("State: %s\n", info->display);
9720 printf_filtered ("other: %s\n\n", info->more_display);
9724 get_and_display_threadinfo (threadref *ref)
9728 struct gdb_ext_thread_info threadinfo;
9730 set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
9731 | TAG_MOREDISPLAY | TAG_DISPLAY;
9732 if (0 != (result = remote_get_threadinfo (ref, set, &threadinfo)))
9733 display_thread_info (&threadinfo);
9738 threadinfo_test_cmd (char *cmd, int tty)
9740 int athread = SAMPLE_THREAD;
9744 int_to_threadref (&thread, athread);
9745 printf_filtered ("Remote Threadinfo test\n");
9746 if (!get_and_display_threadinfo (&thread))
9747 printf_filtered ("FAIL cannot get thread info\n");
9751 thread_display_step (threadref *ref, void *context)
9753 /* output_threadid(" threadstep ",ref); *//* simple test */
9754 return get_and_display_threadinfo (ref);
9758 threadlist_update_test_cmd (char *cmd, int tty)
9760 printf_filtered ("Remote Threadlist update test\n");
9761 remote_threadlist_iterator (thread_display_step, 0, CRAZY_MAX_THREADS);
9765 init_remote_threadtests (void)
9767 add_com ("tlist", class_obscure, threadlist_test_cmd,
9768 _("Fetch and print the remote list of "
9769 "thread identifiers, one pkt only"));
9770 add_com ("tinfo", class_obscure, threadinfo_test_cmd,
9771 _("Fetch and display info about one thread"));
9772 add_com ("tset", class_obscure, threadset_test_cmd,
9773 _("Test setting to a different thread"));
9774 add_com ("tupd", class_obscure, threadlist_update_test_cmd,
9775 _("Iterate through updating all remote thread info"));
9776 add_com ("talive", class_obscure, threadalive_test,
9777 _(" Remote thread alive test "));
9782 /* Convert a thread ID to a string. Returns the string in a static
9786 remote_pid_to_str (struct target_ops *ops, ptid_t ptid)
9788 static char buf[64];
9789 struct remote_state *rs = get_remote_state ();
9791 if (ptid_equal (ptid, null_ptid))
9792 return normal_pid_to_str (ptid);
9793 else if (ptid_is_pid (ptid))
9795 /* Printing an inferior target id. */
9797 /* When multi-process extensions are off, there's no way in the
9798 remote protocol to know the remote process id, if there's any
9799 at all. There's one exception --- when we're connected with
9800 target extended-remote, and we manually attached to a process
9801 with "attach PID". We don't record anywhere a flag that
9802 allows us to distinguish that case from the case of
9803 connecting with extended-remote and the stub already being
9804 attached to a process, and reporting yes to qAttached, hence
9805 no smart special casing here. */
9806 if (!remote_multi_process_p (rs))
9808 xsnprintf (buf, sizeof buf, "Remote target");
9812 return normal_pid_to_str (ptid);
9816 if (ptid_equal (magic_null_ptid, ptid))
9817 xsnprintf (buf, sizeof buf, "Thread <main>");
9818 else if (rs->extended && remote_multi_process_p (rs))
9819 if (ptid_get_lwp (ptid) == 0)
9820 return normal_pid_to_str (ptid);
9822 xsnprintf (buf, sizeof buf, "Thread %d.%ld",
9823 ptid_get_pid (ptid), ptid_get_lwp (ptid));
9825 xsnprintf (buf, sizeof buf, "Thread %ld",
9826 ptid_get_lwp (ptid));
9831 /* Get the address of the thread local variable in OBJFILE which is
9832 stored at OFFSET within the thread local storage for thread PTID. */
9835 remote_get_thread_local_address (struct target_ops *ops,
9836 ptid_t ptid, CORE_ADDR lm, CORE_ADDR offset)
9838 if (packet_support (PACKET_qGetTLSAddr) != PACKET_DISABLE)
9840 struct remote_state *rs = get_remote_state ();
9842 char *endp = rs->buf + get_remote_packet_size ();
9843 enum packet_result result;
9845 strcpy (p, "qGetTLSAddr:");
9847 p = write_ptid (p, endp, ptid);
9849 p += hexnumstr (p, offset);
9851 p += hexnumstr (p, lm);
9855 getpkt (&rs->buf, &rs->buf_size, 0);
9856 result = packet_ok (rs->buf,
9857 &remote_protocol_packets[PACKET_qGetTLSAddr]);
9858 if (result == PACKET_OK)
9862 unpack_varlen_hex (rs->buf, &result);
9865 else if (result == PACKET_UNKNOWN)
9866 throw_error (TLS_GENERIC_ERROR,
9867 _("Remote target doesn't support qGetTLSAddr packet"));
9869 throw_error (TLS_GENERIC_ERROR,
9870 _("Remote target failed to process qGetTLSAddr request"));
9873 throw_error (TLS_GENERIC_ERROR,
9874 _("TLS not supported or disabled on this target"));
9879 /* Provide thread local base, i.e. Thread Information Block address.
9880 Returns 1 if ptid is found and thread_local_base is non zero. */
9883 remote_get_tib_address (struct target_ops *self, ptid_t ptid, CORE_ADDR *addr)
9885 if (packet_support (PACKET_qGetTIBAddr) != PACKET_DISABLE)
9887 struct remote_state *rs = get_remote_state ();
9889 char *endp = rs->buf + get_remote_packet_size ();
9890 enum packet_result result;
9892 strcpy (p, "qGetTIBAddr:");
9894 p = write_ptid (p, endp, ptid);
9898 getpkt (&rs->buf, &rs->buf_size, 0);
9899 result = packet_ok (rs->buf,
9900 &remote_protocol_packets[PACKET_qGetTIBAddr]);
9901 if (result == PACKET_OK)
9905 unpack_varlen_hex (rs->buf, &result);
9907 *addr = (CORE_ADDR) result;
9910 else if (result == PACKET_UNKNOWN)
9911 error (_("Remote target doesn't support qGetTIBAddr packet"));
9913 error (_("Remote target failed to process qGetTIBAddr request"));
9916 error (_("qGetTIBAddr not supported or disabled on this target"));
9921 /* Support for inferring a target description based on the current
9922 architecture and the size of a 'g' packet. While the 'g' packet
9923 can have any size (since optional registers can be left off the
9924 end), some sizes are easily recognizable given knowledge of the
9925 approximate architecture. */
9927 struct remote_g_packet_guess
9930 const struct target_desc *tdesc;
9932 typedef struct remote_g_packet_guess remote_g_packet_guess_s;
9933 DEF_VEC_O(remote_g_packet_guess_s);
9935 struct remote_g_packet_data
9937 VEC(remote_g_packet_guess_s) *guesses;
9940 static struct gdbarch_data *remote_g_packet_data_handle;
9943 remote_g_packet_data_init (struct obstack *obstack)
9945 return OBSTACK_ZALLOC (obstack, struct remote_g_packet_data);
9949 register_remote_g_packet_guess (struct gdbarch *gdbarch, int bytes,
9950 const struct target_desc *tdesc)
9952 struct remote_g_packet_data *data
9953 = gdbarch_data (gdbarch, remote_g_packet_data_handle);
9954 struct remote_g_packet_guess new_guess, *guess;
9957 gdb_assert (tdesc != NULL);
9960 VEC_iterate (remote_g_packet_guess_s, data->guesses, ix, guess);
9962 if (guess->bytes == bytes)
9963 internal_error (__FILE__, __LINE__,
9964 _("Duplicate g packet description added for size %d"),
9967 new_guess.bytes = bytes;
9968 new_guess.tdesc = tdesc;
9969 VEC_safe_push (remote_g_packet_guess_s, data->guesses, &new_guess);
9972 /* Return 1 if remote_read_description would do anything on this target
9973 and architecture, 0 otherwise. */
9976 remote_read_description_p (struct target_ops *target)
9978 struct remote_g_packet_data *data
9979 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle);
9981 if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
9987 static const struct target_desc *
9988 remote_read_description (struct target_ops *target)
9990 struct remote_g_packet_data *data
9991 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle);
9993 /* Do not try this during initial connection, when we do not know
9994 whether there is a running but stopped thread. */
9995 if (!target_has_execution || ptid_equal (inferior_ptid, null_ptid))
9996 return target->beneath->to_read_description (target->beneath);
9998 if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
10000 struct remote_g_packet_guess *guess;
10002 int bytes = send_g_packet ();
10005 VEC_iterate (remote_g_packet_guess_s, data->guesses, ix, guess);
10007 if (guess->bytes == bytes)
10008 return guess->tdesc;
10010 /* We discard the g packet. A minor optimization would be to
10011 hold on to it, and fill the register cache once we have selected
10012 an architecture, but it's too tricky to do safely. */
10015 return target->beneath->to_read_description (target->beneath);
10018 /* Remote file transfer support. This is host-initiated I/O, not
10019 target-initiated; for target-initiated, see remote-fileio.c. */
10021 /* If *LEFT is at least the length of STRING, copy STRING to
10022 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10023 decrease *LEFT. Otherwise raise an error. */
10026 remote_buffer_add_string (char **buffer, int *left, char *string)
10028 int len = strlen (string);
10031 error (_("Packet too long for target."));
10033 memcpy (*buffer, string, len);
10037 /* NUL-terminate the buffer as a convenience, if there is
10043 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
10044 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10045 decrease *LEFT. Otherwise raise an error. */
10048 remote_buffer_add_bytes (char **buffer, int *left, const gdb_byte *bytes,
10051 if (2 * len > *left)
10052 error (_("Packet too long for target."));
10054 bin2hex (bytes, *buffer, len);
10055 *buffer += 2 * len;
10058 /* NUL-terminate the buffer as a convenience, if there is
10064 /* If *LEFT is large enough, convert VALUE to hex and add it to
10065 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10066 decrease *LEFT. Otherwise raise an error. */
10069 remote_buffer_add_int (char **buffer, int *left, ULONGEST value)
10071 int len = hexnumlen (value);
10074 error (_("Packet too long for target."));
10076 hexnumstr (*buffer, value);
10080 /* NUL-terminate the buffer as a convenience, if there is
10086 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
10087 value, *REMOTE_ERRNO to the remote error number or zero if none
10088 was included, and *ATTACHMENT to point to the start of the annex
10089 if any. The length of the packet isn't needed here; there may
10090 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
10092 Return 0 if the packet could be parsed, -1 if it could not. If
10093 -1 is returned, the other variables may not be initialized. */
10096 remote_hostio_parse_result (char *buffer, int *retcode,
10097 int *remote_errno, char **attachment)
10102 *attachment = NULL;
10104 if (buffer[0] != 'F')
10108 *retcode = strtol (&buffer[1], &p, 16);
10109 if (errno != 0 || p == &buffer[1])
10112 /* Check for ",errno". */
10116 *remote_errno = strtol (p + 1, &p2, 16);
10117 if (errno != 0 || p + 1 == p2)
10122 /* Check for ";attachment". If there is no attachment, the
10123 packet should end here. */
10126 *attachment = p + 1;
10129 else if (*p == '\0')
10135 /* Send a prepared I/O packet to the target and read its response.
10136 The prepared packet is in the global RS->BUF before this function
10137 is called, and the answer is there when we return.
10139 COMMAND_BYTES is the length of the request to send, which may include
10140 binary data. WHICH_PACKET is the packet configuration to check
10141 before attempting a packet. If an error occurs, *REMOTE_ERRNO
10142 is set to the error number and -1 is returned. Otherwise the value
10143 returned by the function is returned.
10145 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
10146 attachment is expected; an error will be reported if there's a
10147 mismatch. If one is found, *ATTACHMENT will be set to point into
10148 the packet buffer and *ATTACHMENT_LEN will be set to the
10149 attachment's length. */
10152 remote_hostio_send_command (int command_bytes, int which_packet,
10153 int *remote_errno, char **attachment,
10154 int *attachment_len)
10156 struct remote_state *rs = get_remote_state ();
10157 int ret, bytes_read;
10158 char *attachment_tmp;
10160 if (!rs->remote_desc
10161 || packet_support (which_packet) == PACKET_DISABLE)
10163 *remote_errno = FILEIO_ENOSYS;
10167 putpkt_binary (rs->buf, command_bytes);
10168 bytes_read = getpkt_sane (&rs->buf, &rs->buf_size, 0);
10170 /* If it timed out, something is wrong. Don't try to parse the
10172 if (bytes_read < 0)
10174 *remote_errno = FILEIO_EINVAL;
10178 switch (packet_ok (rs->buf, &remote_protocol_packets[which_packet]))
10181 *remote_errno = FILEIO_EINVAL;
10183 case PACKET_UNKNOWN:
10184 *remote_errno = FILEIO_ENOSYS;
10190 if (remote_hostio_parse_result (rs->buf, &ret, remote_errno,
10193 *remote_errno = FILEIO_EINVAL;
10197 /* Make sure we saw an attachment if and only if we expected one. */
10198 if ((attachment_tmp == NULL && attachment != NULL)
10199 || (attachment_tmp != NULL && attachment == NULL))
10201 *remote_errno = FILEIO_EINVAL;
10205 /* If an attachment was found, it must point into the packet buffer;
10206 work out how many bytes there were. */
10207 if (attachment_tmp != NULL)
10209 *attachment = attachment_tmp;
10210 *attachment_len = bytes_read - (*attachment - rs->buf);
10216 /* Implementation of to_fileio_open. */
10219 remote_hostio_open (struct target_ops *self,
10220 const char *filename, int flags, int mode,
10223 struct remote_state *rs = get_remote_state ();
10225 int left = get_remote_packet_size () - 1;
10227 remote_buffer_add_string (&p, &left, "vFile:open:");
10229 remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
10230 strlen (filename));
10231 remote_buffer_add_string (&p, &left, ",");
10233 remote_buffer_add_int (&p, &left, flags);
10234 remote_buffer_add_string (&p, &left, ",");
10236 remote_buffer_add_int (&p, &left, mode);
10238 return remote_hostio_send_command (p - rs->buf, PACKET_vFile_open,
10239 remote_errno, NULL, NULL);
10242 /* Implementation of to_fileio_pwrite. */
10245 remote_hostio_pwrite (struct target_ops *self,
10246 int fd, const gdb_byte *write_buf, int len,
10247 ULONGEST offset, int *remote_errno)
10249 struct remote_state *rs = get_remote_state ();
10251 int left = get_remote_packet_size ();
10254 remote_buffer_add_string (&p, &left, "vFile:pwrite:");
10256 remote_buffer_add_int (&p, &left, fd);
10257 remote_buffer_add_string (&p, &left, ",");
10259 remote_buffer_add_int (&p, &left, offset);
10260 remote_buffer_add_string (&p, &left, ",");
10262 p += remote_escape_output (write_buf, len, (gdb_byte *) p, &out_len,
10263 get_remote_packet_size () - (p - rs->buf));
10265 return remote_hostio_send_command (p - rs->buf, PACKET_vFile_pwrite,
10266 remote_errno, NULL, NULL);
10269 /* Implementation of to_fileio_pread. */
10272 remote_hostio_pread (struct target_ops *self,
10273 int fd, gdb_byte *read_buf, int len,
10274 ULONGEST offset, int *remote_errno)
10276 struct remote_state *rs = get_remote_state ();
10279 int left = get_remote_packet_size ();
10280 int ret, attachment_len;
10283 remote_buffer_add_string (&p, &left, "vFile:pread:");
10285 remote_buffer_add_int (&p, &left, fd);
10286 remote_buffer_add_string (&p, &left, ",");
10288 remote_buffer_add_int (&p, &left, len);
10289 remote_buffer_add_string (&p, &left, ",");
10291 remote_buffer_add_int (&p, &left, offset);
10293 ret = remote_hostio_send_command (p - rs->buf, PACKET_vFile_pread,
10294 remote_errno, &attachment,
10300 read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len,
10302 if (read_len != ret)
10303 error (_("Read returned %d, but %d bytes."), ret, (int) read_len);
10308 /* Implementation of to_fileio_close. */
10311 remote_hostio_close (struct target_ops *self, int fd, int *remote_errno)
10313 struct remote_state *rs = get_remote_state ();
10315 int left = get_remote_packet_size () - 1;
10317 remote_buffer_add_string (&p, &left, "vFile:close:");
10319 remote_buffer_add_int (&p, &left, fd);
10321 return remote_hostio_send_command (p - rs->buf, PACKET_vFile_close,
10322 remote_errno, NULL, NULL);
10325 /* Implementation of to_fileio_unlink. */
10328 remote_hostio_unlink (struct target_ops *self,
10329 const char *filename, int *remote_errno)
10331 struct remote_state *rs = get_remote_state ();
10333 int left = get_remote_packet_size () - 1;
10335 remote_buffer_add_string (&p, &left, "vFile:unlink:");
10337 remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
10338 strlen (filename));
10340 return remote_hostio_send_command (p - rs->buf, PACKET_vFile_unlink,
10341 remote_errno, NULL, NULL);
10344 /* Implementation of to_fileio_readlink. */
10347 remote_hostio_readlink (struct target_ops *self,
10348 const char *filename, int *remote_errno)
10350 struct remote_state *rs = get_remote_state ();
10353 int left = get_remote_packet_size ();
10354 int len, attachment_len;
10358 remote_buffer_add_string (&p, &left, "vFile:readlink:");
10360 remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
10361 strlen (filename));
10363 len = remote_hostio_send_command (p - rs->buf, PACKET_vFile_readlink,
10364 remote_errno, &attachment,
10370 ret = xmalloc (len + 1);
10372 read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len,
10373 (gdb_byte *) ret, len);
10374 if (read_len != len)
10375 error (_("Readlink returned %d, but %d bytes."), len, read_len);
10381 /* Implementation of to_fileio_fstat. */
10384 remote_hostio_fstat (struct target_ops *self,
10385 int fd, struct stat *st,
10388 struct remote_state *rs = get_remote_state ();
10390 int left = get_remote_packet_size ();
10391 int attachment_len, ret;
10393 struct fio_stat fst;
10396 remote_buffer_add_string (&p, &left, "vFile:fstat:");
10398 remote_buffer_add_int (&p, &left, fd);
10400 ret = remote_hostio_send_command (p - rs->buf, PACKET_vFile_fstat,
10401 remote_errno, &attachment,
10405 if (*remote_errno != FILEIO_ENOSYS)
10408 /* Strictly we should return -1, ENOSYS here, but when
10409 "set sysroot remote:" was implemented in August 2008
10410 BFD's need for a stat function was sidestepped with
10411 this hack. This was not remedied until March 2015
10412 so we retain the previous behavior to avoid breaking
10415 Note that the memset is a March 2015 addition; older
10416 GDBs set st_size *and nothing else* so the structure
10417 would have garbage in all other fields. This might
10418 break something but retaining the previous behavior
10419 here would be just too wrong. */
10421 memset (st, 0, sizeof (struct stat));
10422 st->st_size = INT_MAX;
10426 read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len,
10427 (gdb_byte *) &fst, sizeof (fst));
10429 if (read_len != ret)
10430 error (_("vFile:fstat returned %d, but %d bytes."), ret, read_len);
10432 if (read_len != sizeof (fst))
10433 error (_("vFile:fstat returned %d bytes, but expecting %d."),
10434 read_len, (int) sizeof (fst));
10436 remote_fileio_to_host_stat (&fst, st);
10441 /* Implementation of to_filesystem_is_local. */
10444 remote_filesystem_is_local (struct target_ops *self)
10446 /* Valgrind GDB presents itself as a remote target but works
10447 on the local filesystem: it does not implement remote get
10448 and users are not expected to set a sysroot. To handle
10449 this case we treat the remote filesystem as local if the
10450 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
10451 does not support vFile:open. */
10452 if (gdb_sysroot != NULL
10453 && strcmp (gdb_sysroot, TARGET_SYSROOT_PREFIX) == 0)
10455 enum packet_support ps = packet_support (PACKET_vFile_open);
10457 if (ps == PACKET_SUPPORT_UNKNOWN)
10459 int fd, remote_errno;
10461 /* Try opening a file to probe support. The supplied
10462 filename is irrelevant, we only care about whether
10463 the stub recognizes the packet or not. */
10464 fd = remote_hostio_open (self, "just probing",
10465 FILEIO_O_RDONLY, 0700,
10469 remote_hostio_close (self, fd, &remote_errno);
10471 ps = packet_support (PACKET_vFile_open);
10474 if (ps == PACKET_DISABLE)
10476 static int warning_issued = 0;
10478 if (!warning_issued)
10480 warning (_("remote target does not support file"
10481 " transfer, attempting to access files"
10482 " from local filesystem."));
10483 warning_issued = 1;
10494 remote_fileio_errno_to_host (int errnum)
10500 case FILEIO_ENOENT:
10508 case FILEIO_EACCES:
10510 case FILEIO_EFAULT:
10514 case FILEIO_EEXIST:
10516 case FILEIO_ENODEV:
10518 case FILEIO_ENOTDIR:
10520 case FILEIO_EISDIR:
10522 case FILEIO_EINVAL:
10524 case FILEIO_ENFILE:
10526 case FILEIO_EMFILE:
10530 case FILEIO_ENOSPC:
10532 case FILEIO_ESPIPE:
10536 case FILEIO_ENOSYS:
10538 case FILEIO_ENAMETOOLONG:
10539 return ENAMETOOLONG;
10545 remote_hostio_error (int errnum)
10547 int host_error = remote_fileio_errno_to_host (errnum);
10549 if (host_error == -1)
10550 error (_("Unknown remote I/O error %d"), errnum);
10552 error (_("Remote I/O error: %s"), safe_strerror (host_error));
10556 remote_hostio_close_cleanup (void *opaque)
10558 int fd = *(int *) opaque;
10561 remote_hostio_close (find_target_at (process_stratum), fd, &remote_errno);
10565 remote_file_put (const char *local_file, const char *remote_file, int from_tty)
10567 struct cleanup *back_to, *close_cleanup;
10568 int retcode, fd, remote_errno, bytes, io_size;
10571 int bytes_in_buffer;
10574 struct remote_state *rs = get_remote_state ();
10576 if (!rs->remote_desc)
10577 error (_("command can only be used with remote target"));
10579 file = gdb_fopen_cloexec (local_file, "rb");
10581 perror_with_name (local_file);
10582 back_to = make_cleanup_fclose (file);
10584 fd = remote_hostio_open (find_target_at (process_stratum),
10585 remote_file, (FILEIO_O_WRONLY | FILEIO_O_CREAT
10587 0700, &remote_errno);
10589 remote_hostio_error (remote_errno);
10591 /* Send up to this many bytes at once. They won't all fit in the
10592 remote packet limit, so we'll transfer slightly fewer. */
10593 io_size = get_remote_packet_size ();
10594 buffer = xmalloc (io_size);
10595 make_cleanup (xfree, buffer);
10597 close_cleanup = make_cleanup (remote_hostio_close_cleanup, &fd);
10599 bytes_in_buffer = 0;
10602 while (bytes_in_buffer || !saw_eof)
10606 bytes = fread (buffer + bytes_in_buffer, 1,
10607 io_size - bytes_in_buffer,
10612 error (_("Error reading %s."), local_file);
10615 /* EOF. Unless there is something still in the
10616 buffer from the last iteration, we are done. */
10618 if (bytes_in_buffer == 0)
10626 bytes += bytes_in_buffer;
10627 bytes_in_buffer = 0;
10629 retcode = remote_hostio_pwrite (find_target_at (process_stratum),
10631 offset, &remote_errno);
10634 remote_hostio_error (remote_errno);
10635 else if (retcode == 0)
10636 error (_("Remote write of %d bytes returned 0!"), bytes);
10637 else if (retcode < bytes)
10639 /* Short write. Save the rest of the read data for the next
10641 bytes_in_buffer = bytes - retcode;
10642 memmove (buffer, buffer + retcode, bytes_in_buffer);
10648 discard_cleanups (close_cleanup);
10649 if (remote_hostio_close (find_target_at (process_stratum), fd, &remote_errno))
10650 remote_hostio_error (remote_errno);
10653 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file);
10654 do_cleanups (back_to);
10658 remote_file_get (const char *remote_file, const char *local_file, int from_tty)
10660 struct cleanup *back_to, *close_cleanup;
10661 int fd, remote_errno, bytes, io_size;
10665 struct remote_state *rs = get_remote_state ();
10667 if (!rs->remote_desc)
10668 error (_("command can only be used with remote target"));
10670 fd = remote_hostio_open (find_target_at (process_stratum),
10671 remote_file, FILEIO_O_RDONLY, 0, &remote_errno);
10673 remote_hostio_error (remote_errno);
10675 file = gdb_fopen_cloexec (local_file, "wb");
10677 perror_with_name (local_file);
10678 back_to = make_cleanup_fclose (file);
10680 /* Send up to this many bytes at once. They won't all fit in the
10681 remote packet limit, so we'll transfer slightly fewer. */
10682 io_size = get_remote_packet_size ();
10683 buffer = xmalloc (io_size);
10684 make_cleanup (xfree, buffer);
10686 close_cleanup = make_cleanup (remote_hostio_close_cleanup, &fd);
10691 bytes = remote_hostio_pread (find_target_at (process_stratum),
10692 fd, buffer, io_size, offset, &remote_errno);
10694 /* Success, but no bytes, means end-of-file. */
10697 remote_hostio_error (remote_errno);
10701 bytes = fwrite (buffer, 1, bytes, file);
10703 perror_with_name (local_file);
10706 discard_cleanups (close_cleanup);
10707 if (remote_hostio_close (find_target_at (process_stratum), fd, &remote_errno))
10708 remote_hostio_error (remote_errno);
10711 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file);
10712 do_cleanups (back_to);
10716 remote_file_delete (const char *remote_file, int from_tty)
10718 int retcode, remote_errno;
10719 struct remote_state *rs = get_remote_state ();
10721 if (!rs->remote_desc)
10722 error (_("command can only be used with remote target"));
10724 retcode = remote_hostio_unlink (find_target_at (process_stratum),
10725 remote_file, &remote_errno);
10727 remote_hostio_error (remote_errno);
10730 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file);
10734 remote_put_command (char *args, int from_tty)
10736 struct cleanup *back_to;
10740 error_no_arg (_("file to put"));
10742 argv = gdb_buildargv (args);
10743 back_to = make_cleanup_freeargv (argv);
10744 if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
10745 error (_("Invalid parameters to remote put"));
10747 remote_file_put (argv[0], argv[1], from_tty);
10749 do_cleanups (back_to);
10753 remote_get_command (char *args, int from_tty)
10755 struct cleanup *back_to;
10759 error_no_arg (_("file to get"));
10761 argv = gdb_buildargv (args);
10762 back_to = make_cleanup_freeargv (argv);
10763 if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
10764 error (_("Invalid parameters to remote get"));
10766 remote_file_get (argv[0], argv[1], from_tty);
10768 do_cleanups (back_to);
10772 remote_delete_command (char *args, int from_tty)
10774 struct cleanup *back_to;
10778 error_no_arg (_("file to delete"));
10780 argv = gdb_buildargv (args);
10781 back_to = make_cleanup_freeargv (argv);
10782 if (argv[0] == NULL || argv[1] != NULL)
10783 error (_("Invalid parameters to remote delete"));
10785 remote_file_delete (argv[0], from_tty);
10787 do_cleanups (back_to);
10791 remote_command (char *args, int from_tty)
10793 help_list (remote_cmdlist, "remote ", all_commands, gdb_stdout);
10797 remote_can_execute_reverse (struct target_ops *self)
10799 if (packet_support (PACKET_bs) == PACKET_ENABLE
10800 || packet_support (PACKET_bc) == PACKET_ENABLE)
10807 remote_supports_non_stop (struct target_ops *self)
10813 remote_supports_disable_randomization (struct target_ops *self)
10815 /* Only supported in extended mode. */
10820 remote_supports_multi_process (struct target_ops *self)
10822 struct remote_state *rs = get_remote_state ();
10824 /* Only extended-remote handles being attached to multiple
10825 processes, even though plain remote can use the multi-process
10826 thread id extensions, so that GDB knows the target process's
10828 return rs->extended && remote_multi_process_p (rs);
10832 remote_supports_cond_tracepoints (void)
10834 return packet_support (PACKET_ConditionalTracepoints) == PACKET_ENABLE;
10838 remote_supports_cond_breakpoints (struct target_ops *self)
10840 return packet_support (PACKET_ConditionalBreakpoints) == PACKET_ENABLE;
10844 remote_supports_fast_tracepoints (void)
10846 return packet_support (PACKET_FastTracepoints) == PACKET_ENABLE;
10850 remote_supports_static_tracepoints (void)
10852 return packet_support (PACKET_StaticTracepoints) == PACKET_ENABLE;
10856 remote_supports_install_in_trace (void)
10858 return packet_support (PACKET_InstallInTrace) == PACKET_ENABLE;
10862 remote_supports_enable_disable_tracepoint (struct target_ops *self)
10864 return (packet_support (PACKET_EnableDisableTracepoints_feature)
10869 remote_supports_string_tracing (struct target_ops *self)
10871 return packet_support (PACKET_tracenz_feature) == PACKET_ENABLE;
10875 remote_can_run_breakpoint_commands (struct target_ops *self)
10877 return packet_support (PACKET_BreakpointCommands) == PACKET_ENABLE;
10881 remote_trace_init (struct target_ops *self)
10884 remote_get_noisy_reply (&target_buf, &target_buf_size);
10885 if (strcmp (target_buf, "OK") != 0)
10886 error (_("Target does not support this command."));
10889 static void free_actions_list (char **actions_list);
10890 static void free_actions_list_cleanup_wrapper (void *);
10892 free_actions_list_cleanup_wrapper (void *al)
10894 free_actions_list (al);
10898 free_actions_list (char **actions_list)
10902 if (actions_list == 0)
10905 for (ndx = 0; actions_list[ndx]; ndx++)
10906 xfree (actions_list[ndx]);
10908 xfree (actions_list);
10911 /* Recursive routine to walk through command list including loops, and
10912 download packets for each command. */
10915 remote_download_command_source (int num, ULONGEST addr,
10916 struct command_line *cmds)
10918 struct remote_state *rs = get_remote_state ();
10919 struct command_line *cmd;
10921 for (cmd = cmds; cmd; cmd = cmd->next)
10923 QUIT; /* Allow user to bail out with ^C. */
10924 strcpy (rs->buf, "QTDPsrc:");
10925 encode_source_string (num, addr, "cmd", cmd->line,
10926 rs->buf + strlen (rs->buf),
10927 rs->buf_size - strlen (rs->buf));
10929 remote_get_noisy_reply (&target_buf, &target_buf_size);
10930 if (strcmp (target_buf, "OK"))
10931 warning (_("Target does not support source download."));
10933 if (cmd->control_type == while_control
10934 || cmd->control_type == while_stepping_control)
10936 remote_download_command_source (num, addr, *cmd->body_list);
10938 QUIT; /* Allow user to bail out with ^C. */
10939 strcpy (rs->buf, "QTDPsrc:");
10940 encode_source_string (num, addr, "cmd", "end",
10941 rs->buf + strlen (rs->buf),
10942 rs->buf_size - strlen (rs->buf));
10944 remote_get_noisy_reply (&target_buf, &target_buf_size);
10945 if (strcmp (target_buf, "OK"))
10946 warning (_("Target does not support source download."));
10952 remote_download_tracepoint (struct target_ops *self, struct bp_location *loc)
10954 #define BUF_SIZE 2048
10958 char buf[BUF_SIZE];
10959 char **tdp_actions;
10960 char **stepping_actions;
10962 struct cleanup *old_chain = NULL;
10963 struct agent_expr *aexpr;
10964 struct cleanup *aexpr_chain = NULL;
10966 struct breakpoint *b = loc->owner;
10967 struct tracepoint *t = (struct tracepoint *) b;
10969 encode_actions_rsp (loc, &tdp_actions, &stepping_actions);
10970 old_chain = make_cleanup (free_actions_list_cleanup_wrapper,
10972 (void) make_cleanup (free_actions_list_cleanup_wrapper,
10975 tpaddr = loc->address;
10976 sprintf_vma (addrbuf, tpaddr);
10977 xsnprintf (buf, BUF_SIZE, "QTDP:%x:%s:%c:%lx:%x", b->number,
10978 addrbuf, /* address */
10979 (b->enable_state == bp_enabled ? 'E' : 'D'),
10980 t->step_count, t->pass_count);
10981 /* Fast tracepoints are mostly handled by the target, but we can
10982 tell the target how big of an instruction block should be moved
10984 if (b->type == bp_fast_tracepoint)
10986 /* Only test for support at download time; we may not know
10987 target capabilities at definition time. */
10988 if (remote_supports_fast_tracepoints ())
10992 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
10993 tpaddr, &isize, NULL))
10994 xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":F%x",
10997 /* If it passed validation at definition but fails now,
10998 something is very wrong. */
10999 internal_error (__FILE__, __LINE__,
11000 _("Fast tracepoint not "
11001 "valid during download"));
11004 /* Fast tracepoints are functionally identical to regular
11005 tracepoints, so don't take lack of support as a reason to
11006 give up on the trace run. */
11007 warning (_("Target does not support fast tracepoints, "
11008 "downloading %d as regular tracepoint"), b->number);
11010 else if (b->type == bp_static_tracepoint)
11012 /* Only test for support at download time; we may not know
11013 target capabilities at definition time. */
11014 if (remote_supports_static_tracepoints ())
11016 struct static_tracepoint_marker marker;
11018 if (target_static_tracepoint_marker_at (tpaddr, &marker))
11019 strcat (buf, ":S");
11021 error (_("Static tracepoint not valid during download"));
11024 /* Fast tracepoints are functionally identical to regular
11025 tracepoints, so don't take lack of support as a reason
11026 to give up on the trace run. */
11027 error (_("Target does not support static tracepoints"));
11029 /* If the tracepoint has a conditional, make it into an agent
11030 expression and append to the definition. */
11033 /* Only test support at download time, we may not know target
11034 capabilities at definition time. */
11035 if (remote_supports_cond_tracepoints ())
11037 aexpr = gen_eval_for_expr (tpaddr, loc->cond);
11038 aexpr_chain = make_cleanup_free_agent_expr (aexpr);
11039 xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":X%x,",
11041 pkt = buf + strlen (buf);
11042 for (ndx = 0; ndx < aexpr->len; ++ndx)
11043 pkt = pack_hex_byte (pkt, aexpr->buf[ndx]);
11045 do_cleanups (aexpr_chain);
11048 warning (_("Target does not support conditional tracepoints, "
11049 "ignoring tp %d cond"), b->number);
11052 if (b->commands || *default_collect)
11055 remote_get_noisy_reply (&target_buf, &target_buf_size);
11056 if (strcmp (target_buf, "OK"))
11057 error (_("Target does not support tracepoints."));
11059 /* do_single_steps (t); */
11062 for (ndx = 0; tdp_actions[ndx]; ndx++)
11064 QUIT; /* Allow user to bail out with ^C. */
11065 xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%c",
11066 b->number, addrbuf, /* address */
11068 ((tdp_actions[ndx + 1] || stepping_actions)
11071 remote_get_noisy_reply (&target_buf,
11073 if (strcmp (target_buf, "OK"))
11074 error (_("Error on target while setting tracepoints."));
11077 if (stepping_actions)
11079 for (ndx = 0; stepping_actions[ndx]; ndx++)
11081 QUIT; /* Allow user to bail out with ^C. */
11082 xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%s%s",
11083 b->number, addrbuf, /* address */
11084 ((ndx == 0) ? "S" : ""),
11085 stepping_actions[ndx],
11086 (stepping_actions[ndx + 1] ? "-" : ""));
11088 remote_get_noisy_reply (&target_buf,
11090 if (strcmp (target_buf, "OK"))
11091 error (_("Error on target while setting tracepoints."));
11095 if (packet_support (PACKET_TracepointSource) == PACKET_ENABLE)
11097 if (b->addr_string)
11099 strcpy (buf, "QTDPsrc:");
11100 encode_source_string (b->number, loc->address,
11101 "at", b->addr_string, buf + strlen (buf),
11102 2048 - strlen (buf));
11105 remote_get_noisy_reply (&target_buf, &target_buf_size);
11106 if (strcmp (target_buf, "OK"))
11107 warning (_("Target does not support source download."));
11109 if (b->cond_string)
11111 strcpy (buf, "QTDPsrc:");
11112 encode_source_string (b->number, loc->address,
11113 "cond", b->cond_string, buf + strlen (buf),
11114 2048 - strlen (buf));
11116 remote_get_noisy_reply (&target_buf, &target_buf_size);
11117 if (strcmp (target_buf, "OK"))
11118 warning (_("Target does not support source download."));
11120 remote_download_command_source (b->number, loc->address,
11121 breakpoint_commands (b));
11124 do_cleanups (old_chain);
11128 remote_can_download_tracepoint (struct target_ops *self)
11130 struct remote_state *rs = get_remote_state ();
11131 struct trace_status *ts;
11134 /* Don't try to install tracepoints until we've relocated our
11135 symbols, and fetched and merged the target's tracepoint list with
11137 if (rs->starting_up)
11140 ts = current_trace_status ();
11141 status = remote_get_trace_status (self, ts);
11143 if (status == -1 || !ts->running_known || !ts->running)
11146 /* If we are in a tracing experiment, but remote stub doesn't support
11147 installing tracepoint in trace, we have to return. */
11148 if (!remote_supports_install_in_trace ())
11156 remote_download_trace_state_variable (struct target_ops *self,
11157 struct trace_state_variable *tsv)
11159 struct remote_state *rs = get_remote_state ();
11162 xsnprintf (rs->buf, get_remote_packet_size (), "QTDV:%x:%s:%x:",
11163 tsv->number, phex ((ULONGEST) tsv->initial_value, 8),
11165 p = rs->buf + strlen (rs->buf);
11166 if ((p - rs->buf) + strlen (tsv->name) * 2 >= get_remote_packet_size ())
11167 error (_("Trace state variable name too long for tsv definition packet"));
11168 p += 2 * bin2hex ((gdb_byte *) (tsv->name), p, strlen (tsv->name));
11171 remote_get_noisy_reply (&target_buf, &target_buf_size);
11172 if (*target_buf == '\0')
11173 error (_("Target does not support this command."));
11174 if (strcmp (target_buf, "OK") != 0)
11175 error (_("Error on target while downloading trace state variable."));
11179 remote_enable_tracepoint (struct target_ops *self,
11180 struct bp_location *location)
11182 struct remote_state *rs = get_remote_state ();
11185 sprintf_vma (addr_buf, location->address);
11186 xsnprintf (rs->buf, get_remote_packet_size (), "QTEnable:%x:%s",
11187 location->owner->number, addr_buf);
11189 remote_get_noisy_reply (&rs->buf, &rs->buf_size);
11190 if (*rs->buf == '\0')
11191 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
11192 if (strcmp (rs->buf, "OK") != 0)
11193 error (_("Error on target while enabling tracepoint."));
11197 remote_disable_tracepoint (struct target_ops *self,
11198 struct bp_location *location)
11200 struct remote_state *rs = get_remote_state ();
11203 sprintf_vma (addr_buf, location->address);
11204 xsnprintf (rs->buf, get_remote_packet_size (), "QTDisable:%x:%s",
11205 location->owner->number, addr_buf);
11207 remote_get_noisy_reply (&rs->buf, &rs->buf_size);
11208 if (*rs->buf == '\0')
11209 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
11210 if (strcmp (rs->buf, "OK") != 0)
11211 error (_("Error on target while disabling tracepoint."));
11215 remote_trace_set_readonly_regions (struct target_ops *self)
11219 bfd_size_type size;
11225 return; /* No information to give. */
11227 strcpy (target_buf, "QTro");
11228 offset = strlen (target_buf);
11229 for (s = exec_bfd->sections; s; s = s->next)
11231 char tmp1[40], tmp2[40];
11234 if ((s->flags & SEC_LOAD) == 0 ||
11235 /* (s->flags & SEC_CODE) == 0 || */
11236 (s->flags & SEC_READONLY) == 0)
11240 vma = bfd_get_section_vma (abfd, s);
11241 size = bfd_get_section_size (s);
11242 sprintf_vma (tmp1, vma);
11243 sprintf_vma (tmp2, vma + size);
11244 sec_length = 1 + strlen (tmp1) + 1 + strlen (tmp2);
11245 if (offset + sec_length + 1 > target_buf_size)
11247 if (packet_support (PACKET_qXfer_traceframe_info) != PACKET_ENABLE)
11249 Too many sections for read-only sections definition packet."));
11252 xsnprintf (target_buf + offset, target_buf_size - offset, ":%s,%s",
11254 offset += sec_length;
11258 putpkt (target_buf);
11259 getpkt (&target_buf, &target_buf_size, 0);
11264 remote_trace_start (struct target_ops *self)
11266 putpkt ("QTStart");
11267 remote_get_noisy_reply (&target_buf, &target_buf_size);
11268 if (*target_buf == '\0')
11269 error (_("Target does not support this command."));
11270 if (strcmp (target_buf, "OK") != 0)
11271 error (_("Bogus reply from target: %s"), target_buf);
11275 remote_get_trace_status (struct target_ops *self, struct trace_status *ts)
11277 /* Initialize it just to avoid a GCC false warning. */
11279 /* FIXME we need to get register block size some other way. */
11280 extern int trace_regblock_size;
11281 enum packet_result result;
11283 if (packet_support (PACKET_qTStatus) == PACKET_DISABLE)
11286 trace_regblock_size = get_remote_arch_state ()->sizeof_g_packet;
11288 putpkt ("qTStatus");
11292 p = remote_get_noisy_reply (&target_buf, &target_buf_size);
11294 CATCH (ex, RETURN_MASK_ERROR)
11296 if (ex.error != TARGET_CLOSE_ERROR)
11298 exception_fprintf (gdb_stderr, ex, "qTStatus: ");
11301 throw_exception (ex);
11305 result = packet_ok (p, &remote_protocol_packets[PACKET_qTStatus]);
11307 /* If the remote target doesn't do tracing, flag it. */
11308 if (result == PACKET_UNKNOWN)
11311 /* We're working with a live target. */
11312 ts->filename = NULL;
11315 error (_("Bogus trace status reply from target: %s"), target_buf);
11317 /* Function 'parse_trace_status' sets default value of each field of
11318 'ts' at first, so we don't have to do it here. */
11319 parse_trace_status (p, ts);
11321 return ts->running;
11325 remote_get_tracepoint_status (struct target_ops *self, struct breakpoint *bp,
11326 struct uploaded_tp *utp)
11328 struct remote_state *rs = get_remote_state ();
11330 struct bp_location *loc;
11331 struct tracepoint *tp = (struct tracepoint *) bp;
11332 size_t size = get_remote_packet_size ();
11336 tp->base.hit_count = 0;
11337 tp->traceframe_usage = 0;
11338 for (loc = tp->base.loc; loc; loc = loc->next)
11340 /* If the tracepoint was never downloaded, don't go asking for
11342 if (tp->number_on_target == 0)
11344 xsnprintf (rs->buf, size, "qTP:%x:%s", tp->number_on_target,
11345 phex_nz (loc->address, 0));
11347 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
11348 if (reply && *reply)
11351 parse_tracepoint_status (reply + 1, bp, utp);
11357 utp->hit_count = 0;
11358 utp->traceframe_usage = 0;
11359 xsnprintf (rs->buf, size, "qTP:%x:%s", utp->number,
11360 phex_nz (utp->addr, 0));
11362 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
11363 if (reply && *reply)
11366 parse_tracepoint_status (reply + 1, bp, utp);
11372 remote_trace_stop (struct target_ops *self)
11375 remote_get_noisy_reply (&target_buf, &target_buf_size);
11376 if (*target_buf == '\0')
11377 error (_("Target does not support this command."));
11378 if (strcmp (target_buf, "OK") != 0)
11379 error (_("Bogus reply from target: %s"), target_buf);
11383 remote_trace_find (struct target_ops *self,
11384 enum trace_find_type type, int num,
11385 CORE_ADDR addr1, CORE_ADDR addr2,
11388 struct remote_state *rs = get_remote_state ();
11389 char *endbuf = rs->buf + get_remote_packet_size ();
11391 int target_frameno = -1, target_tracept = -1;
11393 /* Lookups other than by absolute frame number depend on the current
11394 trace selected, so make sure it is correct on the remote end
11396 if (type != tfind_number)
11397 set_remote_traceframe ();
11400 strcpy (p, "QTFrame:");
11401 p = strchr (p, '\0');
11405 xsnprintf (p, endbuf - p, "%x", num);
11408 xsnprintf (p, endbuf - p, "pc:%s", phex_nz (addr1, 0));
11411 xsnprintf (p, endbuf - p, "tdp:%x", num);
11414 xsnprintf (p, endbuf - p, "range:%s:%s", phex_nz (addr1, 0),
11415 phex_nz (addr2, 0));
11417 case tfind_outside:
11418 xsnprintf (p, endbuf - p, "outside:%s:%s", phex_nz (addr1, 0),
11419 phex_nz (addr2, 0));
11422 error (_("Unknown trace find type %d"), type);
11426 reply = remote_get_noisy_reply (&(rs->buf), &rs->buf_size);
11427 if (*reply == '\0')
11428 error (_("Target does not support this command."));
11430 while (reply && *reply)
11435 target_frameno = (int) strtol (p, &reply, 16);
11437 error (_("Unable to parse trace frame number"));
11438 /* Don't update our remote traceframe number cache on failure
11439 to select a remote traceframe. */
11440 if (target_frameno == -1)
11445 target_tracept = (int) strtol (p, &reply, 16);
11447 error (_("Unable to parse tracepoint number"));
11449 case 'O': /* "OK"? */
11450 if (reply[1] == 'K' && reply[2] == '\0')
11453 error (_("Bogus reply from target: %s"), reply);
11456 error (_("Bogus reply from target: %s"), reply);
11459 *tpp = target_tracept;
11461 rs->remote_traceframe_number = target_frameno;
11462 return target_frameno;
11466 remote_get_trace_state_variable_value (struct target_ops *self,
11467 int tsvnum, LONGEST *val)
11469 struct remote_state *rs = get_remote_state ();
11473 set_remote_traceframe ();
11475 xsnprintf (rs->buf, get_remote_packet_size (), "qTV:%x", tsvnum);
11477 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
11478 if (reply && *reply)
11482 unpack_varlen_hex (reply + 1, &uval);
11483 *val = (LONGEST) uval;
11491 remote_save_trace_data (struct target_ops *self, const char *filename)
11493 struct remote_state *rs = get_remote_state ();
11497 strcpy (p, "QTSave:");
11499 if ((p - rs->buf) + strlen (filename) * 2 >= get_remote_packet_size ())
11500 error (_("Remote file name too long for trace save packet"));
11501 p += 2 * bin2hex ((gdb_byte *) filename, p, strlen (filename));
11504 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
11505 if (*reply == '\0')
11506 error (_("Target does not support this command."));
11507 if (strcmp (reply, "OK") != 0)
11508 error (_("Bogus reply from target: %s"), reply);
11512 /* This is basically a memory transfer, but needs to be its own packet
11513 because we don't know how the target actually organizes its trace
11514 memory, plus we want to be able to ask for as much as possible, but
11515 not be unhappy if we don't get as much as we ask for. */
11518 remote_get_raw_trace_data (struct target_ops *self,
11519 gdb_byte *buf, ULONGEST offset, LONGEST len)
11521 struct remote_state *rs = get_remote_state ();
11527 strcpy (p, "qTBuffer:");
11529 p += hexnumstr (p, offset);
11531 p += hexnumstr (p, len);
11535 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
11536 if (reply && *reply)
11538 /* 'l' by itself means we're at the end of the buffer and
11539 there is nothing more to get. */
11543 /* Convert the reply into binary. Limit the number of bytes to
11544 convert according to our passed-in buffer size, rather than
11545 what was returned in the packet; if the target is
11546 unexpectedly generous and gives us a bigger reply than we
11547 asked for, we don't want to crash. */
11548 rslt = hex2bin (target_buf, buf, len);
11552 /* Something went wrong, flag as an error. */
11557 remote_set_disconnected_tracing (struct target_ops *self, int val)
11559 struct remote_state *rs = get_remote_state ();
11561 if (packet_support (PACKET_DisconnectedTracing_feature) == PACKET_ENABLE)
11565 xsnprintf (rs->buf, get_remote_packet_size (), "QTDisconnected:%x", val);
11567 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
11568 if (*reply == '\0')
11569 error (_("Target does not support this command."));
11570 if (strcmp (reply, "OK") != 0)
11571 error (_("Bogus reply from target: %s"), reply);
11574 warning (_("Target does not support disconnected tracing."));
11578 remote_core_of_thread (struct target_ops *ops, ptid_t ptid)
11580 struct thread_info *info = find_thread_ptid (ptid);
11582 if (info && info->priv)
11583 return info->priv->core;
11588 remote_set_circular_trace_buffer (struct target_ops *self, int val)
11590 struct remote_state *rs = get_remote_state ();
11593 xsnprintf (rs->buf, get_remote_packet_size (), "QTBuffer:circular:%x", val);
11595 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
11596 if (*reply == '\0')
11597 error (_("Target does not support this command."));
11598 if (strcmp (reply, "OK") != 0)
11599 error (_("Bogus reply from target: %s"), reply);
11602 static struct traceframe_info *
11603 remote_traceframe_info (struct target_ops *self)
11607 text = target_read_stralloc (¤t_target,
11608 TARGET_OBJECT_TRACEFRAME_INFO, NULL);
11611 struct traceframe_info *info;
11612 struct cleanup *back_to = make_cleanup (xfree, text);
11614 info = parse_traceframe_info (text);
11615 do_cleanups (back_to);
11622 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11623 instruction on which a fast tracepoint may be placed. Returns -1
11624 if the packet is not supported, and 0 if the minimum instruction
11625 length is unknown. */
11628 remote_get_min_fast_tracepoint_insn_len (struct target_ops *self)
11630 struct remote_state *rs = get_remote_state ();
11633 /* If we're not debugging a process yet, the IPA can't be
11635 if (!target_has_execution)
11638 /* Make sure the remote is pointing at the right process. */
11639 set_general_process ();
11641 xsnprintf (rs->buf, get_remote_packet_size (), "qTMinFTPILen");
11643 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
11644 if (*reply == '\0')
11648 ULONGEST min_insn_len;
11650 unpack_varlen_hex (reply, &min_insn_len);
11652 return (int) min_insn_len;
11657 remote_set_trace_buffer_size (struct target_ops *self, LONGEST val)
11659 if (packet_support (PACKET_QTBuffer_size) != PACKET_DISABLE)
11661 struct remote_state *rs = get_remote_state ();
11662 char *buf = rs->buf;
11663 char *endbuf = rs->buf + get_remote_packet_size ();
11664 enum packet_result result;
11666 gdb_assert (val >= 0 || val == -1);
11667 buf += xsnprintf (buf, endbuf - buf, "QTBuffer:size:");
11668 /* Send -1 as literal "-1" to avoid host size dependency. */
11672 buf += hexnumstr (buf, (ULONGEST) -val);
11675 buf += hexnumstr (buf, (ULONGEST) val);
11678 remote_get_noisy_reply (&rs->buf, &rs->buf_size);
11679 result = packet_ok (rs->buf,
11680 &remote_protocol_packets[PACKET_QTBuffer_size]);
11682 if (result != PACKET_OK)
11683 warning (_("Bogus reply from target: %s"), rs->buf);
11688 remote_set_trace_notes (struct target_ops *self,
11689 const char *user, const char *notes,
11690 const char *stop_notes)
11692 struct remote_state *rs = get_remote_state ();
11694 char *buf = rs->buf;
11695 char *endbuf = rs->buf + get_remote_packet_size ();
11698 buf += xsnprintf (buf, endbuf - buf, "QTNotes:");
11701 buf += xsnprintf (buf, endbuf - buf, "user:");
11702 nbytes = bin2hex ((gdb_byte *) user, buf, strlen (user));
11708 buf += xsnprintf (buf, endbuf - buf, "notes:");
11709 nbytes = bin2hex ((gdb_byte *) notes, buf, strlen (notes));
11715 buf += xsnprintf (buf, endbuf - buf, "tstop:");
11716 nbytes = bin2hex ((gdb_byte *) stop_notes, buf, strlen (stop_notes));
11720 /* Ensure the buffer is terminated. */
11724 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
11725 if (*reply == '\0')
11728 if (strcmp (reply, "OK") != 0)
11729 error (_("Bogus reply from target: %s"), reply);
11735 remote_use_agent (struct target_ops *self, int use)
11737 if (packet_support (PACKET_QAgent) != PACKET_DISABLE)
11739 struct remote_state *rs = get_remote_state ();
11741 /* If the stub supports QAgent. */
11742 xsnprintf (rs->buf, get_remote_packet_size (), "QAgent:%d", use);
11744 getpkt (&rs->buf, &rs->buf_size, 0);
11746 if (strcmp (rs->buf, "OK") == 0)
11757 remote_can_use_agent (struct target_ops *self)
11759 return (packet_support (PACKET_QAgent) != PACKET_DISABLE);
11762 struct btrace_target_info
11764 /* The ptid of the traced thread. */
11767 /* The obtained branch trace configuration. */
11768 struct btrace_config conf;
11771 /* Reset our idea of our target's btrace configuration. */
11774 remote_btrace_reset (void)
11776 struct remote_state *rs = get_remote_state ();
11778 memset (&rs->btrace_config, 0, sizeof (rs->btrace_config));
11781 /* Check whether the target supports branch tracing. */
11784 remote_supports_btrace (struct target_ops *self, enum btrace_format format)
11786 if (packet_support (PACKET_Qbtrace_off) != PACKET_ENABLE)
11788 if (packet_support (PACKET_qXfer_btrace) != PACKET_ENABLE)
11793 case BTRACE_FORMAT_NONE:
11796 case BTRACE_FORMAT_BTS:
11797 return (packet_support (PACKET_Qbtrace_bts) == PACKET_ENABLE);
11800 internal_error (__FILE__, __LINE__, _("Unknown branch trace format"));
11803 /* Synchronize the configuration with the target. */
11806 btrace_sync_conf (const struct btrace_config *conf)
11808 struct packet_config *packet;
11809 struct remote_state *rs;
11810 char *buf, *pos, *endbuf;
11812 rs = get_remote_state ();
11814 endbuf = buf + get_remote_packet_size ();
11816 packet = &remote_protocol_packets[PACKET_Qbtrace_conf_bts_size];
11817 if (packet_config_support (packet) == PACKET_ENABLE
11818 && conf->bts.size != rs->btrace_config.bts.size)
11821 pos += xsnprintf (pos, endbuf - pos, "%s=0x%x", packet->name,
11825 getpkt (&buf, &rs->buf_size, 0);
11827 if (packet_ok (buf, packet) == PACKET_ERROR)
11829 if (buf[0] == 'E' && buf[1] == '.')
11830 error (_("Failed to configure the BTS buffer size: %s"), buf + 2);
11832 error (_("Failed to configure the BTS buffer size."));
11835 rs->btrace_config.bts.size = conf->bts.size;
11839 /* Read the current thread's btrace configuration from the target and
11840 store it into CONF. */
11843 btrace_read_config (struct btrace_config *conf)
11847 xml = target_read_stralloc (¤t_target,
11848 TARGET_OBJECT_BTRACE_CONF, "");
11851 struct cleanup *cleanup;
11853 cleanup = make_cleanup (xfree, xml);
11854 parse_xml_btrace_conf (conf, xml);
11855 do_cleanups (cleanup);
11859 /* Enable branch tracing. */
11861 static struct btrace_target_info *
11862 remote_enable_btrace (struct target_ops *self, ptid_t ptid,
11863 const struct btrace_config *conf)
11865 struct btrace_target_info *tinfo = NULL;
11866 struct packet_config *packet = &remote_protocol_packets[PACKET_Qbtrace_bts];
11867 struct remote_state *rs = get_remote_state ();
11868 char *buf = rs->buf;
11869 char *endbuf = rs->buf + get_remote_packet_size ();
11871 if (packet_config_support (packet) != PACKET_ENABLE)
11872 error (_("Target does not support branch tracing."));
11874 btrace_sync_conf (conf);
11876 set_general_thread (ptid);
11878 buf += xsnprintf (buf, endbuf - buf, "%s", packet->name);
11880 getpkt (&rs->buf, &rs->buf_size, 0);
11882 if (packet_ok (rs->buf, packet) == PACKET_ERROR)
11884 if (rs->buf[0] == 'E' && rs->buf[1] == '.')
11885 error (_("Could not enable branch tracing for %s: %s"),
11886 target_pid_to_str (ptid), rs->buf + 2);
11888 error (_("Could not enable branch tracing for %s."),
11889 target_pid_to_str (ptid));
11892 tinfo = xzalloc (sizeof (*tinfo));
11893 tinfo->ptid = ptid;
11895 /* If we fail to read the configuration, we lose some information, but the
11896 tracing itself is not impacted. */
11899 btrace_read_config (&tinfo->conf);
11901 CATCH (err, RETURN_MASK_ERROR)
11903 if (err.message != NULL)
11904 warning ("%s", err.message);
11911 /* Disable branch tracing. */
11914 remote_disable_btrace (struct target_ops *self,
11915 struct btrace_target_info *tinfo)
11917 struct packet_config *packet = &remote_protocol_packets[PACKET_Qbtrace_off];
11918 struct remote_state *rs = get_remote_state ();
11919 char *buf = rs->buf;
11920 char *endbuf = rs->buf + get_remote_packet_size ();
11922 if (packet_config_support (packet) != PACKET_ENABLE)
11923 error (_("Target does not support branch tracing."));
11925 set_general_thread (tinfo->ptid);
11927 buf += xsnprintf (buf, endbuf - buf, "%s", packet->name);
11929 getpkt (&rs->buf, &rs->buf_size, 0);
11931 if (packet_ok (rs->buf, packet) == PACKET_ERROR)
11933 if (rs->buf[0] == 'E' && rs->buf[1] == '.')
11934 error (_("Could not disable branch tracing for %s: %s"),
11935 target_pid_to_str (tinfo->ptid), rs->buf + 2);
11937 error (_("Could not disable branch tracing for %s."),
11938 target_pid_to_str (tinfo->ptid));
11944 /* Teardown branch tracing. */
11947 remote_teardown_btrace (struct target_ops *self,
11948 struct btrace_target_info *tinfo)
11950 /* We must not talk to the target during teardown. */
11954 /* Read the branch trace. */
11956 static enum btrace_error
11957 remote_read_btrace (struct target_ops *self,
11958 struct btrace_data *btrace,
11959 struct btrace_target_info *tinfo,
11960 enum btrace_read_type type)
11962 struct packet_config *packet = &remote_protocol_packets[PACKET_qXfer_btrace];
11963 struct remote_state *rs = get_remote_state ();
11964 struct cleanup *cleanup;
11968 if (packet_config_support (packet) != PACKET_ENABLE)
11969 error (_("Target does not support branch tracing."));
11971 #if !defined(HAVE_LIBEXPAT)
11972 error (_("Cannot process branch tracing result. XML parsing not supported."));
11977 case BTRACE_READ_ALL:
11980 case BTRACE_READ_NEW:
11983 case BTRACE_READ_DELTA:
11987 internal_error (__FILE__, __LINE__,
11988 _("Bad branch tracing read type: %u."),
11989 (unsigned int) type);
11992 xml = target_read_stralloc (¤t_target,
11993 TARGET_OBJECT_BTRACE, annex);
11995 return BTRACE_ERR_UNKNOWN;
11997 cleanup = make_cleanup (xfree, xml);
11998 parse_xml_btrace (btrace, xml);
11999 do_cleanups (cleanup);
12001 return BTRACE_ERR_NONE;
12004 static const struct btrace_config *
12005 remote_btrace_conf (struct target_ops *self,
12006 const struct btrace_target_info *tinfo)
12008 return &tinfo->conf;
12012 remote_augmented_libraries_svr4_read (struct target_ops *self)
12014 return (packet_support (PACKET_augmented_libraries_svr4_read_feature)
12018 /* Implementation of to_load. */
12021 remote_load (struct target_ops *self, const char *name, int from_tty)
12023 generic_load (name, from_tty);
12026 /* Accepts an integer PID; returns a string representing a file that
12027 can be opened on the remote side to get the symbols for the child
12028 process. Returns NULL if the operation is not supported. */
12031 remote_pid_to_exec_file (struct target_ops *self, int pid)
12033 static char *filename = NULL;
12034 struct inferior *inf;
12035 char *annex = NULL;
12037 if (packet_support (PACKET_qXfer_exec_file) != PACKET_ENABLE)
12040 if (filename != NULL)
12043 inf = find_inferior_pid (pid);
12045 internal_error (__FILE__, __LINE__,
12046 _("not currently attached to process %d"), pid);
12048 if (!inf->fake_pid_p)
12050 const int annex_size = 9;
12052 annex = alloca (annex_size);
12053 xsnprintf (annex, annex_size, "%x", pid);
12056 filename = target_read_stralloc (¤t_target,
12057 TARGET_OBJECT_EXEC_FILE, annex);
12063 init_remote_ops (void)
12065 remote_ops.to_shortname = "remote";
12066 remote_ops.to_longname = "Remote serial target in gdb-specific protocol";
12067 remote_ops.to_doc =
12068 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12069 Specify the serial device it is connected to\n\
12070 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
12071 remote_ops.to_open = remote_open;
12072 remote_ops.to_close = remote_close;
12073 remote_ops.to_detach = remote_detach;
12074 remote_ops.to_disconnect = remote_disconnect;
12075 remote_ops.to_resume = remote_resume;
12076 remote_ops.to_wait = remote_wait;
12077 remote_ops.to_fetch_registers = remote_fetch_registers;
12078 remote_ops.to_store_registers = remote_store_registers;
12079 remote_ops.to_prepare_to_store = remote_prepare_to_store;
12080 remote_ops.to_files_info = remote_files_info;
12081 remote_ops.to_insert_breakpoint = remote_insert_breakpoint;
12082 remote_ops.to_remove_breakpoint = remote_remove_breakpoint;
12083 remote_ops.to_stopped_by_sw_breakpoint = remote_stopped_by_sw_breakpoint;
12084 remote_ops.to_supports_stopped_by_sw_breakpoint = remote_supports_stopped_by_sw_breakpoint;
12085 remote_ops.to_stopped_by_hw_breakpoint = remote_stopped_by_hw_breakpoint;
12086 remote_ops.to_supports_stopped_by_hw_breakpoint = remote_supports_stopped_by_hw_breakpoint;
12087 remote_ops.to_stopped_by_watchpoint = remote_stopped_by_watchpoint;
12088 remote_ops.to_stopped_data_address = remote_stopped_data_address;
12089 remote_ops.to_watchpoint_addr_within_range =
12090 remote_watchpoint_addr_within_range;
12091 remote_ops.to_can_use_hw_breakpoint = remote_check_watch_resources;
12092 remote_ops.to_insert_hw_breakpoint = remote_insert_hw_breakpoint;
12093 remote_ops.to_remove_hw_breakpoint = remote_remove_hw_breakpoint;
12094 remote_ops.to_region_ok_for_hw_watchpoint
12095 = remote_region_ok_for_hw_watchpoint;
12096 remote_ops.to_insert_watchpoint = remote_insert_watchpoint;
12097 remote_ops.to_remove_watchpoint = remote_remove_watchpoint;
12098 remote_ops.to_kill = remote_kill;
12099 remote_ops.to_load = remote_load;
12100 remote_ops.to_mourn_inferior = remote_mourn;
12101 remote_ops.to_pass_signals = remote_pass_signals;
12102 remote_ops.to_program_signals = remote_program_signals;
12103 remote_ops.to_thread_alive = remote_thread_alive;
12104 remote_ops.to_update_thread_list = remote_update_thread_list;
12105 remote_ops.to_pid_to_str = remote_pid_to_str;
12106 remote_ops.to_extra_thread_info = remote_threads_extra_info;
12107 remote_ops.to_get_ada_task_ptid = remote_get_ada_task_ptid;
12108 remote_ops.to_stop = remote_stop;
12109 remote_ops.to_xfer_partial = remote_xfer_partial;
12110 remote_ops.to_rcmd = remote_rcmd;
12111 remote_ops.to_pid_to_exec_file = remote_pid_to_exec_file;
12112 remote_ops.to_log_command = serial_log_command;
12113 remote_ops.to_get_thread_local_address = remote_get_thread_local_address;
12114 remote_ops.to_stratum = process_stratum;
12115 remote_ops.to_has_all_memory = default_child_has_all_memory;
12116 remote_ops.to_has_memory = default_child_has_memory;
12117 remote_ops.to_has_stack = default_child_has_stack;
12118 remote_ops.to_has_registers = default_child_has_registers;
12119 remote_ops.to_has_execution = default_child_has_execution;
12120 remote_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */
12121 remote_ops.to_can_execute_reverse = remote_can_execute_reverse;
12122 remote_ops.to_magic = OPS_MAGIC;
12123 remote_ops.to_memory_map = remote_memory_map;
12124 remote_ops.to_flash_erase = remote_flash_erase;
12125 remote_ops.to_flash_done = remote_flash_done;
12126 remote_ops.to_read_description = remote_read_description;
12127 remote_ops.to_search_memory = remote_search_memory;
12128 remote_ops.to_can_async_p = remote_can_async_p;
12129 remote_ops.to_is_async_p = remote_is_async_p;
12130 remote_ops.to_async = remote_async;
12131 remote_ops.to_terminal_inferior = remote_terminal_inferior;
12132 remote_ops.to_terminal_ours = remote_terminal_ours;
12133 remote_ops.to_supports_non_stop = remote_supports_non_stop;
12134 remote_ops.to_supports_multi_process = remote_supports_multi_process;
12135 remote_ops.to_supports_disable_randomization
12136 = remote_supports_disable_randomization;
12137 remote_ops.to_filesystem_is_local = remote_filesystem_is_local;
12138 remote_ops.to_fileio_open = remote_hostio_open;
12139 remote_ops.to_fileio_pwrite = remote_hostio_pwrite;
12140 remote_ops.to_fileio_pread = remote_hostio_pread;
12141 remote_ops.to_fileio_fstat = remote_hostio_fstat;
12142 remote_ops.to_fileio_close = remote_hostio_close;
12143 remote_ops.to_fileio_unlink = remote_hostio_unlink;
12144 remote_ops.to_fileio_readlink = remote_hostio_readlink;
12145 remote_ops.to_supports_enable_disable_tracepoint = remote_supports_enable_disable_tracepoint;
12146 remote_ops.to_supports_string_tracing = remote_supports_string_tracing;
12147 remote_ops.to_supports_evaluation_of_breakpoint_conditions = remote_supports_cond_breakpoints;
12148 remote_ops.to_can_run_breakpoint_commands = remote_can_run_breakpoint_commands;
12149 remote_ops.to_trace_init = remote_trace_init;
12150 remote_ops.to_download_tracepoint = remote_download_tracepoint;
12151 remote_ops.to_can_download_tracepoint = remote_can_download_tracepoint;
12152 remote_ops.to_download_trace_state_variable
12153 = remote_download_trace_state_variable;
12154 remote_ops.to_enable_tracepoint = remote_enable_tracepoint;
12155 remote_ops.to_disable_tracepoint = remote_disable_tracepoint;
12156 remote_ops.to_trace_set_readonly_regions = remote_trace_set_readonly_regions;
12157 remote_ops.to_trace_start = remote_trace_start;
12158 remote_ops.to_get_trace_status = remote_get_trace_status;
12159 remote_ops.to_get_tracepoint_status = remote_get_tracepoint_status;
12160 remote_ops.to_trace_stop = remote_trace_stop;
12161 remote_ops.to_trace_find = remote_trace_find;
12162 remote_ops.to_get_trace_state_variable_value
12163 = remote_get_trace_state_variable_value;
12164 remote_ops.to_save_trace_data = remote_save_trace_data;
12165 remote_ops.to_upload_tracepoints = remote_upload_tracepoints;
12166 remote_ops.to_upload_trace_state_variables
12167 = remote_upload_trace_state_variables;
12168 remote_ops.to_get_raw_trace_data = remote_get_raw_trace_data;
12169 remote_ops.to_get_min_fast_tracepoint_insn_len = remote_get_min_fast_tracepoint_insn_len;
12170 remote_ops.to_set_disconnected_tracing = remote_set_disconnected_tracing;
12171 remote_ops.to_set_circular_trace_buffer = remote_set_circular_trace_buffer;
12172 remote_ops.to_set_trace_buffer_size = remote_set_trace_buffer_size;
12173 remote_ops.to_set_trace_notes = remote_set_trace_notes;
12174 remote_ops.to_core_of_thread = remote_core_of_thread;
12175 remote_ops.to_verify_memory = remote_verify_memory;
12176 remote_ops.to_get_tib_address = remote_get_tib_address;
12177 remote_ops.to_set_permissions = remote_set_permissions;
12178 remote_ops.to_static_tracepoint_marker_at
12179 = remote_static_tracepoint_marker_at;
12180 remote_ops.to_static_tracepoint_markers_by_strid
12181 = remote_static_tracepoint_markers_by_strid;
12182 remote_ops.to_traceframe_info = remote_traceframe_info;
12183 remote_ops.to_use_agent = remote_use_agent;
12184 remote_ops.to_can_use_agent = remote_can_use_agent;
12185 remote_ops.to_supports_btrace = remote_supports_btrace;
12186 remote_ops.to_enable_btrace = remote_enable_btrace;
12187 remote_ops.to_disable_btrace = remote_disable_btrace;
12188 remote_ops.to_teardown_btrace = remote_teardown_btrace;
12189 remote_ops.to_read_btrace = remote_read_btrace;
12190 remote_ops.to_btrace_conf = remote_btrace_conf;
12191 remote_ops.to_augmented_libraries_svr4_read =
12192 remote_augmented_libraries_svr4_read;
12195 /* Set up the extended remote vector by making a copy of the standard
12196 remote vector and adding to it. */
12199 init_extended_remote_ops (void)
12201 extended_remote_ops = remote_ops;
12203 extended_remote_ops.to_shortname = "extended-remote";
12204 extended_remote_ops.to_longname =
12205 "Extended remote serial target in gdb-specific protocol";
12206 extended_remote_ops.to_doc =
12207 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12208 Specify the serial device it is connected to (e.g. /dev/ttya).";
12209 extended_remote_ops.to_open = extended_remote_open;
12210 extended_remote_ops.to_create_inferior = extended_remote_create_inferior;
12211 extended_remote_ops.to_mourn_inferior = extended_remote_mourn;
12212 extended_remote_ops.to_detach = extended_remote_detach;
12213 extended_remote_ops.to_attach = extended_remote_attach;
12214 extended_remote_ops.to_post_attach = extended_remote_post_attach;
12215 extended_remote_ops.to_kill = extended_remote_kill;
12216 extended_remote_ops.to_supports_disable_randomization
12217 = extended_remote_supports_disable_randomization;
12218 extended_remote_ops.to_follow_fork = remote_follow_fork;
12219 extended_remote_ops.to_insert_fork_catchpoint
12220 = remote_insert_fork_catchpoint;
12221 extended_remote_ops.to_remove_fork_catchpoint
12222 = remote_remove_fork_catchpoint;
12223 extended_remote_ops.to_insert_vfork_catchpoint
12224 = remote_insert_vfork_catchpoint;
12225 extended_remote_ops.to_remove_vfork_catchpoint
12226 = remote_remove_vfork_catchpoint;
12230 remote_can_async_p (struct target_ops *ops)
12232 struct remote_state *rs = get_remote_state ();
12234 if (!target_async_permitted)
12235 /* We only enable async when the user specifically asks for it. */
12238 /* We're async whenever the serial device is. */
12239 return serial_can_async_p (rs->remote_desc);
12243 remote_is_async_p (struct target_ops *ops)
12245 struct remote_state *rs = get_remote_state ();
12247 if (!target_async_permitted)
12248 /* We only enable async when the user specifically asks for it. */
12251 /* We're async whenever the serial device is. */
12252 return serial_is_async_p (rs->remote_desc);
12255 /* Pass the SERIAL event on and up to the client. One day this code
12256 will be able to delay notifying the client of an event until the
12257 point where an entire packet has been received. */
12259 static serial_event_ftype remote_async_serial_handler;
12262 remote_async_serial_handler (struct serial *scb, void *context)
12264 struct remote_state *rs = context;
12266 /* Don't propogate error information up to the client. Instead let
12267 the client find out about the error by querying the target. */
12268 inferior_event_handler (INF_REG_EVENT, NULL);
12272 remote_async_inferior_event_handler (gdb_client_data data)
12274 inferior_event_handler (INF_REG_EVENT, NULL);
12278 remote_async (struct target_ops *ops, int enable)
12280 struct remote_state *rs = get_remote_state ();
12284 serial_async (rs->remote_desc, remote_async_serial_handler, rs);
12286 /* If there are pending events in the stop reply queue tell the
12287 event loop to process them. */
12288 if (!QUEUE_is_empty (stop_reply_p, stop_reply_queue))
12289 mark_async_event_handler (remote_async_inferior_event_token);
12293 serial_async (rs->remote_desc, NULL, NULL);
12294 clear_async_event_handler (remote_async_inferior_event_token);
12299 set_remote_cmd (char *args, int from_tty)
12301 help_list (remote_set_cmdlist, "set remote ", all_commands, gdb_stdout);
12305 show_remote_cmd (char *args, int from_tty)
12307 /* We can't just use cmd_show_list here, because we want to skip
12308 the redundant "show remote Z-packet" and the legacy aliases. */
12309 struct cleanup *showlist_chain;
12310 struct cmd_list_element *list = remote_show_cmdlist;
12311 struct ui_out *uiout = current_uiout;
12313 showlist_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "showlist");
12314 for (; list != NULL; list = list->next)
12315 if (strcmp (list->name, "Z-packet") == 0)
12317 else if (list->type == not_set_cmd)
12318 /* Alias commands are exactly like the original, except they
12319 don't have the normal type. */
12323 struct cleanup *option_chain
12324 = make_cleanup_ui_out_tuple_begin_end (uiout, "option");
12326 ui_out_field_string (uiout, "name", list->name);
12327 ui_out_text (uiout, ": ");
12328 if (list->type == show_cmd)
12329 do_show_command ((char *) NULL, from_tty, list);
12331 cmd_func (list, NULL, from_tty);
12332 /* Close the tuple. */
12333 do_cleanups (option_chain);
12336 /* Close the tuple. */
12337 do_cleanups (showlist_chain);
12341 /* Function to be called whenever a new objfile (shlib) is detected. */
12343 remote_new_objfile (struct objfile *objfile)
12345 struct remote_state *rs = get_remote_state ();
12347 if (rs->remote_desc != 0) /* Have a remote connection. */
12348 remote_check_symbols ();
12351 /* Pull all the tracepoints defined on the target and create local
12352 data structures representing them. We don't want to create real
12353 tracepoints yet, we don't want to mess up the user's existing
12357 remote_upload_tracepoints (struct target_ops *self, struct uploaded_tp **utpp)
12359 struct remote_state *rs = get_remote_state ();
12362 /* Ask for a first packet of tracepoint definition. */
12364 getpkt (&rs->buf, &rs->buf_size, 0);
12366 while (*p && *p != 'l')
12368 parse_tracepoint_definition (p, utpp);
12369 /* Ask for another packet of tracepoint definition. */
12371 getpkt (&rs->buf, &rs->buf_size, 0);
12378 remote_upload_trace_state_variables (struct target_ops *self,
12379 struct uploaded_tsv **utsvp)
12381 struct remote_state *rs = get_remote_state ();
12384 /* Ask for a first packet of variable definition. */
12386 getpkt (&rs->buf, &rs->buf_size, 0);
12388 while (*p && *p != 'l')
12390 parse_tsv_definition (p, utsvp);
12391 /* Ask for another packet of variable definition. */
12393 getpkt (&rs->buf, &rs->buf_size, 0);
12399 /* The "set/show range-stepping" show hook. */
12402 show_range_stepping (struct ui_file *file, int from_tty,
12403 struct cmd_list_element *c,
12406 fprintf_filtered (file,
12407 _("Debugger's willingness to use range stepping "
12408 "is %s.\n"), value);
12411 /* The "set/show range-stepping" set hook. */
12414 set_range_stepping (char *ignore_args, int from_tty,
12415 struct cmd_list_element *c)
12417 struct remote_state *rs = get_remote_state ();
12419 /* Whene enabling, check whether range stepping is actually
12420 supported by the target, and warn if not. */
12421 if (use_range_stepping)
12423 if (rs->remote_desc != NULL)
12425 if (packet_support (PACKET_vCont) == PACKET_SUPPORT_UNKNOWN)
12426 remote_vcont_probe (rs);
12428 if (packet_support (PACKET_vCont) == PACKET_ENABLE
12429 && rs->supports_vCont.r)
12433 warning (_("Range stepping is not supported by the current target"));
12438 _initialize_remote (void)
12440 struct remote_state *rs;
12441 struct cmd_list_element *cmd;
12442 const char *cmd_name;
12444 /* architecture specific data */
12445 remote_gdbarch_data_handle =
12446 gdbarch_data_register_post_init (init_remote_state);
12447 remote_g_packet_data_handle =
12448 gdbarch_data_register_pre_init (remote_g_packet_data_init);
12450 /* Initialize the per-target state. At the moment there is only one
12451 of these, not one per target. Only one target is active at a
12453 remote_state = new_remote_state ();
12455 init_remote_ops ();
12456 add_target (&remote_ops);
12458 init_extended_remote_ops ();
12459 add_target (&extended_remote_ops);
12461 /* Hook into new objfile notification. */
12462 observer_attach_new_objfile (remote_new_objfile);
12463 /* We're no longer interested in notification events of an inferior
12465 observer_attach_inferior_exit (discard_pending_stop_replies);
12467 /* Set up signal handlers. */
12468 async_sigint_remote_token =
12469 create_async_signal_handler (async_remote_interrupt, NULL);
12470 async_sigint_remote_twice_token =
12471 create_async_signal_handler (async_remote_interrupt_twice, NULL);
12474 init_remote_threadtests ();
12477 stop_reply_queue = QUEUE_alloc (stop_reply_p, stop_reply_xfree);
12478 /* set/show remote ... */
12480 add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, _("\
12481 Remote protocol specific variables\n\
12482 Configure various remote-protocol specific variables such as\n\
12483 the packets being used"),
12484 &remote_set_cmdlist, "set remote ",
12485 0 /* allow-unknown */, &setlist);
12486 add_prefix_cmd ("remote", class_maintenance, show_remote_cmd, _("\
12487 Remote protocol specific variables\n\
12488 Configure various remote-protocol specific variables such as\n\
12489 the packets being used"),
12490 &remote_show_cmdlist, "show remote ",
12491 0 /* allow-unknown */, &showlist);
12493 add_cmd ("compare-sections", class_obscure, compare_sections_command, _("\
12494 Compare section data on target to the exec file.\n\
12495 Argument is a single section name (default: all loaded sections).\n\
12496 To compare only read-only loaded sections, specify the -r option."),
12499 add_cmd ("packet", class_maintenance, packet_command, _("\
12500 Send an arbitrary packet to a remote target.\n\
12501 maintenance packet TEXT\n\
12502 If GDB is talking to an inferior via the GDB serial protocol, then\n\
12503 this command sends the string TEXT to the inferior, and displays the\n\
12504 response packet. GDB supplies the initial `$' character, and the\n\
12505 terminating `#' character and checksum."),
12508 add_setshow_boolean_cmd ("remotebreak", no_class, &remote_break, _("\
12509 Set whether to send break if interrupted."), _("\
12510 Show whether to send break if interrupted."), _("\
12511 If set, a break, instead of a cntrl-c, is sent to the remote target."),
12512 set_remotebreak, show_remotebreak,
12513 &setlist, &showlist);
12514 cmd_name = "remotebreak";
12515 cmd = lookup_cmd (&cmd_name, setlist, "", -1, 1);
12516 deprecate_cmd (cmd, "set remote interrupt-sequence");
12517 cmd_name = "remotebreak"; /* needed because lookup_cmd updates the pointer */
12518 cmd = lookup_cmd (&cmd_name, showlist, "", -1, 1);
12519 deprecate_cmd (cmd, "show remote interrupt-sequence");
12521 add_setshow_enum_cmd ("interrupt-sequence", class_support,
12522 interrupt_sequence_modes, &interrupt_sequence_mode,
12524 Set interrupt sequence to remote target."), _("\
12525 Show interrupt sequence to remote target."), _("\
12526 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
12527 NULL, show_interrupt_sequence,
12528 &remote_set_cmdlist,
12529 &remote_show_cmdlist);
12531 add_setshow_boolean_cmd ("interrupt-on-connect", class_support,
12532 &interrupt_on_connect, _("\
12533 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12534 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12535 If set, interrupt sequence is sent to remote target."),
12537 &remote_set_cmdlist, &remote_show_cmdlist);
12539 /* Install commands for configuring memory read/write packets. */
12541 add_cmd ("remotewritesize", no_class, set_memory_write_packet_size, _("\
12542 Set the maximum number of bytes per memory write packet (deprecated)."),
12544 add_cmd ("remotewritesize", no_class, show_memory_write_packet_size, _("\
12545 Show the maximum number of bytes per memory write packet (deprecated)."),
12547 add_cmd ("memory-write-packet-size", no_class,
12548 set_memory_write_packet_size, _("\
12549 Set the maximum number of bytes per memory-write packet.\n\
12550 Specify the number of bytes in a packet or 0 (zero) for the\n\
12551 default packet size. The actual limit is further reduced\n\
12552 dependent on the target. Specify ``fixed'' to disable the\n\
12553 further restriction and ``limit'' to enable that restriction."),
12554 &remote_set_cmdlist);
12555 add_cmd ("memory-read-packet-size", no_class,
12556 set_memory_read_packet_size, _("\
12557 Set the maximum number of bytes per memory-read packet.\n\
12558 Specify the number of bytes in a packet or 0 (zero) for the\n\
12559 default packet size. The actual limit is further reduced\n\
12560 dependent on the target. Specify ``fixed'' to disable the\n\
12561 further restriction and ``limit'' to enable that restriction."),
12562 &remote_set_cmdlist);
12563 add_cmd ("memory-write-packet-size", no_class,
12564 show_memory_write_packet_size,
12565 _("Show the maximum number of bytes per memory-write packet."),
12566 &remote_show_cmdlist);
12567 add_cmd ("memory-read-packet-size", no_class,
12568 show_memory_read_packet_size,
12569 _("Show the maximum number of bytes per memory-read packet."),
12570 &remote_show_cmdlist);
12572 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class,
12573 &remote_hw_watchpoint_limit, _("\
12574 Set the maximum number of target hardware watchpoints."), _("\
12575 Show the maximum number of target hardware watchpoints."), _("\
12576 Specify a negative limit for unlimited."),
12577 NULL, NULL, /* FIXME: i18n: The maximum
12578 number of target hardware
12579 watchpoints is %s. */
12580 &remote_set_cmdlist, &remote_show_cmdlist);
12581 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class,
12582 &remote_hw_watchpoint_length_limit, _("\
12583 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
12584 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
12585 Specify a negative limit for unlimited."),
12586 NULL, NULL, /* FIXME: i18n: The maximum
12587 length (in bytes) of a target
12588 hardware watchpoint is %s. */
12589 &remote_set_cmdlist, &remote_show_cmdlist);
12590 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class,
12591 &remote_hw_breakpoint_limit, _("\
12592 Set the maximum number of target hardware breakpoints."), _("\
12593 Show the maximum number of target hardware breakpoints."), _("\
12594 Specify a negative limit for unlimited."),
12595 NULL, NULL, /* FIXME: i18n: The maximum
12596 number of target hardware
12597 breakpoints is %s. */
12598 &remote_set_cmdlist, &remote_show_cmdlist);
12600 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure,
12601 &remote_address_size, _("\
12602 Set the maximum size of the address (in bits) in a memory packet."), _("\
12603 Show the maximum size of the address (in bits) in a memory packet."), NULL,
12605 NULL, /* FIXME: i18n: */
12606 &setlist, &showlist);
12608 init_all_packet_configs ();
12610 add_packet_config_cmd (&remote_protocol_packets[PACKET_X],
12611 "X", "binary-download", 1);
12613 add_packet_config_cmd (&remote_protocol_packets[PACKET_vCont],
12614 "vCont", "verbose-resume", 0);
12616 add_packet_config_cmd (&remote_protocol_packets[PACKET_QPassSignals],
12617 "QPassSignals", "pass-signals", 0);
12619 add_packet_config_cmd (&remote_protocol_packets[PACKET_QProgramSignals],
12620 "QProgramSignals", "program-signals", 0);
12622 add_packet_config_cmd (&remote_protocol_packets[PACKET_qSymbol],
12623 "qSymbol", "symbol-lookup", 0);
12625 add_packet_config_cmd (&remote_protocol_packets[PACKET_P],
12626 "P", "set-register", 1);
12628 add_packet_config_cmd (&remote_protocol_packets[PACKET_p],
12629 "p", "fetch-register", 1);
12631 add_packet_config_cmd (&remote_protocol_packets[PACKET_Z0],
12632 "Z0", "software-breakpoint", 0);
12634 add_packet_config_cmd (&remote_protocol_packets[PACKET_Z1],
12635 "Z1", "hardware-breakpoint", 0);
12637 add_packet_config_cmd (&remote_protocol_packets[PACKET_Z2],
12638 "Z2", "write-watchpoint", 0);
12640 add_packet_config_cmd (&remote_protocol_packets[PACKET_Z3],
12641 "Z3", "read-watchpoint", 0);
12643 add_packet_config_cmd (&remote_protocol_packets[PACKET_Z4],
12644 "Z4", "access-watchpoint", 0);
12646 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_auxv],
12647 "qXfer:auxv:read", "read-aux-vector", 0);
12649 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_exec_file],
12650 "qXfer:exec-file:read", "pid-to-exec-file", 0);
12652 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_features],
12653 "qXfer:features:read", "target-features", 0);
12655 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_libraries],
12656 "qXfer:libraries:read", "library-info", 0);
12658 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_libraries_svr4],
12659 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
12661 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_memory_map],
12662 "qXfer:memory-map:read", "memory-map", 0);
12664 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_spu_read],
12665 "qXfer:spu:read", "read-spu-object", 0);
12667 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_spu_write],
12668 "qXfer:spu:write", "write-spu-object", 0);
12670 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_osdata],
12671 "qXfer:osdata:read", "osdata", 0);
12673 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_threads],
12674 "qXfer:threads:read", "threads", 0);
12676 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_siginfo_read],
12677 "qXfer:siginfo:read", "read-siginfo-object", 0);
12679 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_siginfo_write],
12680 "qXfer:siginfo:write", "write-siginfo-object", 0);
12682 add_packet_config_cmd
12683 (&remote_protocol_packets[PACKET_qXfer_traceframe_info],
12684 "qXfer:traceframe-info:read", "traceframe-info", 0);
12686 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_uib],
12687 "qXfer:uib:read", "unwind-info-block", 0);
12689 add_packet_config_cmd (&remote_protocol_packets[PACKET_qGetTLSAddr],
12690 "qGetTLSAddr", "get-thread-local-storage-address",
12693 add_packet_config_cmd (&remote_protocol_packets[PACKET_qGetTIBAddr],
12694 "qGetTIBAddr", "get-thread-information-block-address",
12697 add_packet_config_cmd (&remote_protocol_packets[PACKET_bc],
12698 "bc", "reverse-continue", 0);
12700 add_packet_config_cmd (&remote_protocol_packets[PACKET_bs],
12701 "bs", "reverse-step", 0);
12703 add_packet_config_cmd (&remote_protocol_packets[PACKET_qSupported],
12704 "qSupported", "supported-packets", 0);
12706 add_packet_config_cmd (&remote_protocol_packets[PACKET_qSearch_memory],
12707 "qSearch:memory", "search-memory", 0);
12709 add_packet_config_cmd (&remote_protocol_packets[PACKET_qTStatus],
12710 "qTStatus", "trace-status", 0);
12712 add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_open],
12713 "vFile:open", "hostio-open", 0);
12715 add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_pread],
12716 "vFile:pread", "hostio-pread", 0);
12718 add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_pwrite],
12719 "vFile:pwrite", "hostio-pwrite", 0);
12721 add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_close],
12722 "vFile:close", "hostio-close", 0);
12724 add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_unlink],
12725 "vFile:unlink", "hostio-unlink", 0);
12727 add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_readlink],
12728 "vFile:readlink", "hostio-readlink", 0);
12730 add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_fstat],
12731 "vFile:fstat", "hostio-fstat", 0);
12733 add_packet_config_cmd (&remote_protocol_packets[PACKET_vAttach],
12734 "vAttach", "attach", 0);
12736 add_packet_config_cmd (&remote_protocol_packets[PACKET_vRun],
12739 add_packet_config_cmd (&remote_protocol_packets[PACKET_QStartNoAckMode],
12740 "QStartNoAckMode", "noack", 0);
12742 add_packet_config_cmd (&remote_protocol_packets[PACKET_vKill],
12743 "vKill", "kill", 0);
12745 add_packet_config_cmd (&remote_protocol_packets[PACKET_qAttached],
12746 "qAttached", "query-attached", 0);
12748 add_packet_config_cmd (&remote_protocol_packets[PACKET_ConditionalTracepoints],
12749 "ConditionalTracepoints",
12750 "conditional-tracepoints", 0);
12752 add_packet_config_cmd (&remote_protocol_packets[PACKET_ConditionalBreakpoints],
12753 "ConditionalBreakpoints",
12754 "conditional-breakpoints", 0);
12756 add_packet_config_cmd (&remote_protocol_packets[PACKET_BreakpointCommands],
12757 "BreakpointCommands",
12758 "breakpoint-commands", 0);
12760 add_packet_config_cmd (&remote_protocol_packets[PACKET_FastTracepoints],
12761 "FastTracepoints", "fast-tracepoints", 0);
12763 add_packet_config_cmd (&remote_protocol_packets[PACKET_TracepointSource],
12764 "TracepointSource", "TracepointSource", 0);
12766 add_packet_config_cmd (&remote_protocol_packets[PACKET_QAllow],
12767 "QAllow", "allow", 0);
12769 add_packet_config_cmd (&remote_protocol_packets[PACKET_StaticTracepoints],
12770 "StaticTracepoints", "static-tracepoints", 0);
12772 add_packet_config_cmd (&remote_protocol_packets[PACKET_InstallInTrace],
12773 "InstallInTrace", "install-in-trace", 0);
12775 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_statictrace_read],
12776 "qXfer:statictrace:read", "read-sdata-object", 0);
12778 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_fdpic],
12779 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
12781 add_packet_config_cmd (&remote_protocol_packets[PACKET_QDisableRandomization],
12782 "QDisableRandomization", "disable-randomization", 0);
12784 add_packet_config_cmd (&remote_protocol_packets[PACKET_QAgent],
12785 "QAgent", "agent", 0);
12787 add_packet_config_cmd (&remote_protocol_packets[PACKET_QTBuffer_size],
12788 "QTBuffer:size", "trace-buffer-size", 0);
12790 add_packet_config_cmd (&remote_protocol_packets[PACKET_Qbtrace_off],
12791 "Qbtrace:off", "disable-btrace", 0);
12793 add_packet_config_cmd (&remote_protocol_packets[PACKET_Qbtrace_bts],
12794 "Qbtrace:bts", "enable-btrace", 0);
12796 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_btrace],
12797 "qXfer:btrace", "read-btrace", 0);
12799 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_btrace_conf],
12800 "qXfer:btrace-conf", "read-btrace-conf", 0);
12802 add_packet_config_cmd (&remote_protocol_packets[PACKET_Qbtrace_conf_bts_size],
12803 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
12805 add_packet_config_cmd (&remote_protocol_packets[PACKET_swbreak_feature],
12806 "swbreak-feature", "swbreak-feature", 0);
12808 add_packet_config_cmd (&remote_protocol_packets[PACKET_hwbreak_feature],
12809 "hwbreak-feature", "hwbreak-feature", 0);
12811 add_packet_config_cmd (&remote_protocol_packets[PACKET_fork_event_feature],
12812 "fork-event-feature", "fork-event-feature", 0);
12814 add_packet_config_cmd (&remote_protocol_packets[PACKET_vfork_event_feature],
12815 "vfork-event-feature", "vfork-event-feature", 0);
12817 /* Assert that we've registered "set remote foo-packet" commands
12818 for all packet configs. */
12822 for (i = 0; i < PACKET_MAX; i++)
12824 /* Ideally all configs would have a command associated. Some
12825 still don't though. */
12830 case PACKET_QNonStop:
12831 case PACKET_multiprocess_feature:
12832 case PACKET_EnableDisableTracepoints_feature:
12833 case PACKET_tracenz_feature:
12834 case PACKET_DisconnectedTracing_feature:
12835 case PACKET_augmented_libraries_svr4_read_feature:
12837 /* Additions to this list need to be well justified:
12838 pre-existing packets are OK; new packets are not. */
12846 /* This catches both forgetting to add a config command, and
12847 forgetting to remove a packet from the exception list. */
12848 gdb_assert (excepted == (remote_protocol_packets[i].name == NULL));
12852 /* Keep the old ``set remote Z-packet ...'' working. Each individual
12853 Z sub-packet has its own set and show commands, but users may
12854 have sets to this variable in their .gdbinit files (or in their
12856 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure,
12857 &remote_Z_packet_detect, _("\
12858 Set use of remote protocol `Z' packets"), _("\
12859 Show use of remote protocol `Z' packets "), _("\
12860 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
12862 set_remote_protocol_Z_packet_cmd,
12863 show_remote_protocol_Z_packet_cmd,
12864 /* FIXME: i18n: Use of remote protocol
12865 `Z' packets is %s. */
12866 &remote_set_cmdlist, &remote_show_cmdlist);
12868 add_prefix_cmd ("remote", class_files, remote_command, _("\
12869 Manipulate files on the remote system\n\
12870 Transfer files to and from the remote target system."),
12871 &remote_cmdlist, "remote ",
12872 0 /* allow-unknown */, &cmdlist);
12874 add_cmd ("put", class_files, remote_put_command,
12875 _("Copy a local file to the remote system."),
12878 add_cmd ("get", class_files, remote_get_command,
12879 _("Copy a remote file to the local system."),
12882 add_cmd ("delete", class_files, remote_delete_command,
12883 _("Delete a remote file."),
12886 remote_exec_file = xstrdup ("");
12887 add_setshow_string_noescape_cmd ("exec-file", class_files,
12888 &remote_exec_file, _("\
12889 Set the remote pathname for \"run\""), _("\
12890 Show the remote pathname for \"run\""), NULL, NULL, NULL,
12891 &remote_set_cmdlist, &remote_show_cmdlist);
12893 add_setshow_boolean_cmd ("range-stepping", class_run,
12894 &use_range_stepping, _("\
12895 Enable or disable range stepping."), _("\
12896 Show whether target-assisted range stepping is enabled."), _("\
12897 If on, and the target supports it, when stepping a source line, GDB\n\
12898 tells the target to step the corresponding range of addresses itself instead\n\
12899 of issuing multiple single-steps. This speeds up source level\n\
12900 stepping. If off, GDB always issues single-steps, even if range\n\
12901 stepping is supported by the target. The default is on."),
12902 set_range_stepping,
12903 show_range_stepping,
12907 /* Eventually initialize fileio. See fileio.c */
12908 initialize_remote_fileio (remote_set_cmdlist, remote_show_cmdlist);
12910 /* Take advantage of the fact that the TID field is not used, to tag
12911 special ptids with it set to != 0. */
12912 magic_null_ptid = ptid_build (42000, -1, 1);
12913 not_sent_ptid = ptid_build (42000, -2, 1);
12914 any_thread_ptid = ptid_build (42000, 0, 1);
12916 target_buf_size = 2048;
12917 target_buf = xmalloc (target_buf_size);