1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2014 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. */
29 #include "exceptions.h"
31 /*#include "terminal.h" */
34 #include "gdb-stabs.h"
35 #include "gdbthread.h"
37 #include "remote-notif.h"
40 #include "gdb_assert.h"
43 #include "cli/cli-decode.h"
44 #include "cli/cli-setshow.h"
45 #include "target-descriptions.h"
47 #include "filestuff.h"
52 #include "event-loop.h"
53 #include "event-top.h"
59 #include "gdbcore.h" /* for exec_bfd */
61 #include "remote-fileio.h"
62 #include "gdb/fileio.h"
64 #include "xml-support.h"
66 #include "memory-map.h"
68 #include "tracepoint.h"
74 /* Temp hacks for tracepoint encoding migration. */
75 static char *target_buf;
76 static long target_buf_size;
78 /* The size to align memory write packets, when practical. The protocol
79 does not guarantee any alignment, and gdb will generate short
80 writes and unaligned writes, but even as a best-effort attempt this
81 can improve bulk transfers. For instance, if a write is misaligned
82 relative to the target's data bus, the stub may need to make an extra
83 round trip fetching data from the target. This doesn't make a
84 huge difference, but it's easy to do, so we try to be helpful.
86 The alignment chosen is arbitrary; usually data bus width is
87 important here, not the possibly larger cache line size. */
88 enum { REMOTE_ALIGN_WRITES = 16 };
90 /* Prototypes for local functions. */
91 static void async_cleanup_sigint_signal_handler (void *dummy);
92 static int getpkt_sane (char **buf, long *sizeof_buf, int forever);
93 static int getpkt_or_notif_sane (char **buf, long *sizeof_buf,
94 int forever, int *is_notif);
96 static void async_handle_remote_sigint (int);
97 static void async_handle_remote_sigint_twice (int);
99 static void remote_files_info (struct target_ops *ignore);
101 static void remote_prepare_to_store (struct target_ops *self,
102 struct regcache *regcache);
104 static void remote_open (char *name, int from_tty);
106 static void extended_remote_open (char *name, int from_tty);
108 static void remote_open_1 (char *, int, struct target_ops *, int extended_p);
110 static void remote_close (struct target_ops *self);
112 static void remote_mourn (struct target_ops *ops);
114 static void extended_remote_restart (void);
116 static void extended_remote_mourn (struct target_ops *);
118 static void remote_mourn_1 (struct target_ops *);
120 static void remote_send (char **buf, long *sizeof_buf_p);
122 static int readchar (int timeout);
124 static void remote_serial_write (const char *str, int len);
126 static void remote_kill (struct target_ops *ops);
128 static int remote_can_async_p (struct target_ops *);
130 static int remote_is_async_p (struct target_ops *);
132 static void remote_async (struct target_ops *ops,
133 void (*callback) (enum inferior_event_type event_type,
137 static void sync_remote_interrupt_twice (int signo);
139 static void interrupt_query (void);
141 static void set_general_thread (struct ptid ptid);
142 static void set_continue_thread (struct ptid ptid);
144 static void get_offsets (void);
146 static void skip_frame (void);
148 static long read_frame (char **buf_p, long *sizeof_buf);
150 static int hexnumlen (ULONGEST num);
152 static void init_remote_ops (void);
154 static void init_extended_remote_ops (void);
156 static void remote_stop (struct target_ops *self, ptid_t);
158 static int stubhex (int ch);
160 static int hexnumstr (char *, ULONGEST);
162 static int hexnumnstr (char *, ULONGEST, int);
164 static CORE_ADDR remote_address_masked (CORE_ADDR);
166 static void print_packet (char *);
168 static void compare_sections_command (char *, int);
170 static void packet_command (char *, int);
172 static int stub_unpack_int (char *buff, int fieldlength);
174 static ptid_t remote_current_thread (ptid_t oldptid);
176 static void remote_find_new_threads (void);
178 static int putpkt_binary (char *buf, int cnt);
180 static void check_binary_download (CORE_ADDR addr);
182 struct packet_config;
184 static void show_packet_config_cmd (struct packet_config *config);
186 static void update_packet_config (struct packet_config *config);
188 static void set_remote_protocol_packet_cmd (char *args, int from_tty,
189 struct cmd_list_element *c);
191 static void show_remote_protocol_packet_cmd (struct ui_file *file,
193 struct cmd_list_element *c,
196 static char *write_ptid (char *buf, const char *endbuf, ptid_t ptid);
197 static ptid_t read_ptid (char *buf, char **obuf);
199 static void remote_set_permissions (void);
202 static int remote_get_trace_status (struct trace_status *ts);
204 static int remote_upload_tracepoints (struct uploaded_tp **utpp);
206 static int remote_upload_trace_state_variables (struct uploaded_tsv **utsvp);
208 static void remote_query_supported (void);
210 static void remote_check_symbols (void);
212 void _initialize_remote (void);
215 static void stop_reply_xfree (struct stop_reply *);
216 static void remote_parse_stop_reply (char *, struct stop_reply *);
217 static void push_stop_reply (struct stop_reply *);
218 static void discard_pending_stop_replies_in_queue (struct remote_state *);
219 static int peek_stop_reply (ptid_t ptid);
221 static void remote_async_inferior_event_handler (gdb_client_data);
223 static void remote_terminal_ours (struct target_ops *self);
225 static int remote_read_description_p (struct target_ops *target);
227 static void remote_console_output (char *msg);
229 static int remote_supports_cond_breakpoints (struct target_ops *self);
231 static int remote_can_run_breakpoint_commands (struct target_ops *self);
235 static struct cmd_list_element *remote_cmdlist;
237 /* For "set remote" and "show remote". */
239 static struct cmd_list_element *remote_set_cmdlist;
240 static struct cmd_list_element *remote_show_cmdlist;
242 /* Stub vCont actions support.
244 Each field is a boolean flag indicating whether the stub reports
245 support for the corresponding action. */
247 struct vCont_action_support
256 /* Controls whether GDB is willing to use range stepping. */
258 static int use_range_stepping = 1;
260 #define OPAQUETHREADBYTES 8
262 /* a 64 bit opaque identifier */
263 typedef unsigned char threadref[OPAQUETHREADBYTES];
265 /* About this many threadisds fit in a packet. */
267 #define MAXTHREADLISTRESULTS 32
269 /* Description of the remote protocol state for the currently
270 connected target. This is per-target state, and independent of the
271 selected architecture. */
275 /* A buffer to use for incoming packets, and its current size. The
276 buffer is grown dynamically for larger incoming packets.
277 Outgoing packets may also be constructed in this buffer.
278 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
279 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
284 /* True if we're going through initial connection setup (finding out
285 about the remote side's threads, relocating symbols, etc.). */
288 /* If we negotiated packet size explicitly (and thus can bypass
289 heuristics for the largest packet size that will not overflow
290 a buffer in the stub), this will be set to that packet size.
291 Otherwise zero, meaning to use the guessed size. */
292 long explicit_packet_size;
294 /* remote_wait is normally called when the target is running and
295 waits for a stop reply packet. But sometimes we need to call it
296 when the target is already stopped. We can send a "?" packet
297 and have remote_wait read the response. Or, if we already have
298 the response, we can stash it in BUF and tell remote_wait to
299 skip calling getpkt. This flag is set when BUF contains a
300 stop reply packet and the target is not waiting. */
301 int cached_wait_status;
303 /* True, if in no ack mode. That is, neither GDB nor the stub will
304 expect acks from each other. The connection is assumed to be
308 /* True if we're connected in extended remote mode. */
311 /* True if the stub reported support for multi-process
313 int multi_process_aware;
315 /* True if we resumed the target and we're waiting for the target to
316 stop. In the mean time, we can't start another command/query.
317 The remote server wouldn't be ready to process it, so we'd
318 timeout waiting for a reply that would never come and eventually
319 we'd close the connection. This can happen in asynchronous mode
320 because we allow GDB commands while the target is running. */
321 int waiting_for_stop_reply;
323 /* True if the stub reports support for non-stop mode. */
326 /* The status of the stub support for the various vCont actions. */
327 struct vCont_action_support supports_vCont;
329 /* True if the stub reports support for conditional tracepoints. */
330 int cond_tracepoints;
332 /* True if the stub reports support for target-side breakpoint
334 int cond_breakpoints;
336 /* True if the stub reports support for target-side breakpoint
338 int breakpoint_commands;
340 /* True if the stub reports support for fast tracepoints. */
341 int fast_tracepoints;
343 /* True if the stub reports support for static tracepoints. */
344 int static_tracepoints;
346 /* True if the stub reports support for installing tracepoint while
348 int install_in_trace;
350 /* True if the stub can continue running a trace while GDB is
352 int disconnected_tracing;
354 /* True if the stub reports support for enabling and disabling
355 tracepoints while a trace experiment is running. */
356 int enable_disable_tracepoints;
358 /* True if the stub can collect strings using tracenz bytecode. */
361 /* True if the stub supports qXfer:libraries-svr4:read with a
363 int augmented_libraries_svr4_read;
365 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
366 responded to that. */
369 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
370 remote_open knows that we don't have a file open when the program
372 struct serial *remote_desc;
374 /* These are the threads which we last sent to the remote system. The
375 TID member will be -1 for all or -2 for not sent yet. */
376 ptid_t general_thread;
377 ptid_t continue_thread;
379 /* This is the traceframe which we last selected on the remote system.
380 It will be -1 if no traceframe is selected. */
381 int remote_traceframe_number;
383 char *last_pass_packet;
385 /* The last QProgramSignals packet sent to the target. We bypass
386 sending a new program signals list down to the target if the new
387 packet is exactly the same as the last we sent. IOW, we only let
388 the target know about program signals list changes. */
389 char *last_program_signals_packet;
391 enum gdb_signal last_sent_signal;
395 char *finished_object;
396 char *finished_annex;
397 ULONGEST finished_offset;
399 /* Should we try the 'ThreadInfo' query packet?
401 This variable (NOT available to the user: auto-detect only!)
402 determines whether GDB will use the new, simpler "ThreadInfo"
403 query or the older, more complex syntax for thread queries.
404 This is an auto-detect variable (set to true at each connect,
405 and set to false when the target fails to recognize it). */
406 int use_threadinfo_query;
407 int use_threadextra_query;
409 void (*async_client_callback) (enum inferior_event_type event_type,
411 void *async_client_context;
413 /* This is set to the data address of the access causing the target
414 to stop for a watchpoint. */
415 CORE_ADDR remote_watch_data_address;
417 /* This is non-zero if target stopped for a watchpoint. */
418 int remote_stopped_by_watchpoint_p;
420 threadref echo_nextthread;
421 threadref nextthread;
422 threadref resultthreadlist[MAXTHREADLISTRESULTS];
424 /* The state of remote notification. */
425 struct remote_notif_state *notif_state;
428 /* Private data that we'll store in (struct thread_info)->private. */
429 struct private_thread_info
436 free_private_thread_info (struct private_thread_info *info)
442 /* Returns true if the multi-process extensions are in effect. */
444 remote_multi_process_p (struct remote_state *rs)
446 return rs->multi_process_aware;
449 /* This data could be associated with a target, but we do not always
450 have access to the current target when we need it, so for now it is
451 static. This will be fine for as long as only one target is in use
453 static struct remote_state *remote_state;
455 static struct remote_state *
456 get_remote_state_raw (void)
461 /* Allocate a new struct remote_state with xmalloc, initialize it, and
464 static struct remote_state *
465 new_remote_state (void)
467 struct remote_state *result = XCNEW (struct remote_state);
469 /* The default buffer size is unimportant; it will be expanded
470 whenever a larger buffer is needed. */
471 result->buf_size = 400;
472 result->buf = xmalloc (result->buf_size);
473 result->remote_traceframe_number = -1;
474 result->last_sent_signal = GDB_SIGNAL_0;
479 /* Description of the remote protocol for a given architecture. */
483 long offset; /* Offset into G packet. */
484 long regnum; /* GDB's internal register number. */
485 LONGEST pnum; /* Remote protocol register number. */
486 int in_g_packet; /* Always part of G packet. */
487 /* long size in bytes; == register_size (target_gdbarch (), regnum);
489 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
493 struct remote_arch_state
495 /* Description of the remote protocol registers. */
496 long sizeof_g_packet;
498 /* Description of the remote protocol registers indexed by REGNUM
499 (making an array gdbarch_num_regs in size). */
500 struct packet_reg *regs;
502 /* This is the size (in chars) of the first response to the ``g''
503 packet. It is used as a heuristic when determining the maximum
504 size of memory-read and memory-write packets. A target will
505 typically only reserve a buffer large enough to hold the ``g''
506 packet. The size does not include packet overhead (headers and
508 long actual_register_packet_size;
510 /* This is the maximum size (in chars) of a non read/write packet.
511 It is also used as a cap on the size of read/write packets. */
512 long remote_packet_size;
515 /* Utility: generate error from an incoming stub packet. */
517 trace_error (char *buf)
520 return; /* not an error msg */
523 case '1': /* malformed packet error */
524 if (*++buf == '0') /* general case: */
525 error (_("remote.c: error in outgoing packet."));
527 error (_("remote.c: error in outgoing packet at field #%ld."),
528 strtol (buf, NULL, 16));
530 error (_("Target returns error code '%s'."), buf);
534 /* Utility: wait for reply from stub, while accepting "O" packets. */
536 remote_get_noisy_reply (char **buf_p,
539 do /* Loop on reply from remote stub. */
543 QUIT; /* Allow user to bail out with ^C. */
544 getpkt (buf_p, sizeof_buf, 0);
548 else if (strncmp (buf, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
551 CORE_ADDR from, to, org_to;
553 int adjusted_size = 0;
554 volatile struct gdb_exception ex;
556 p = buf + strlen ("qRelocInsn:");
557 pp = unpack_varlen_hex (p, &ul);
559 error (_("invalid qRelocInsn packet: %s"), buf);
563 unpack_varlen_hex (p, &ul);
568 TRY_CATCH (ex, RETURN_MASK_ALL)
570 gdbarch_relocate_instruction (target_gdbarch (), &to, from);
574 adjusted_size = to - org_to;
576 xsnprintf (buf, *sizeof_buf, "qRelocInsn:%x", adjusted_size);
579 else if (ex.reason < 0 && ex.error == MEMORY_ERROR)
581 /* Propagate memory errors silently back to the target.
582 The stub may have limited the range of addresses we
583 can write to, for example. */
588 /* Something unexpectedly bad happened. Be verbose so
589 we can tell what, and propagate the error back to the
590 stub, so it doesn't get stuck waiting for a
592 exception_fprintf (gdb_stderr, ex,
593 _("warning: relocating instruction: "));
597 else if (buf[0] == 'O' && buf[1] != 'K')
598 remote_console_output (buf + 1); /* 'O' message from stub */
600 return buf; /* Here's the actual reply. */
605 /* Handle for retreving the remote protocol data from gdbarch. */
606 static struct gdbarch_data *remote_gdbarch_data_handle;
608 static struct remote_arch_state *
609 get_remote_arch_state (void)
611 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle);
614 /* Fetch the global remote target state. */
616 static struct remote_state *
617 get_remote_state (void)
619 /* Make sure that the remote architecture state has been
620 initialized, because doing so might reallocate rs->buf. Any
621 function which calls getpkt also needs to be mindful of changes
622 to rs->buf, but this call limits the number of places which run
624 get_remote_arch_state ();
626 return get_remote_state_raw ();
630 compare_pnums (const void *lhs_, const void *rhs_)
632 const struct packet_reg * const *lhs = lhs_;
633 const struct packet_reg * const *rhs = rhs_;
635 if ((*lhs)->pnum < (*rhs)->pnum)
637 else if ((*lhs)->pnum == (*rhs)->pnum)
644 map_regcache_remote_table (struct gdbarch *gdbarch, struct packet_reg *regs)
646 int regnum, num_remote_regs, offset;
647 struct packet_reg **remote_regs;
649 for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
651 struct packet_reg *r = ®s[regnum];
653 if (register_size (gdbarch, regnum) == 0)
654 /* Do not try to fetch zero-sized (placeholder) registers. */
657 r->pnum = gdbarch_remote_register_number (gdbarch, regnum);
662 /* Define the g/G packet format as the contents of each register
663 with a remote protocol number, in order of ascending protocol
666 remote_regs = alloca (gdbarch_num_regs (gdbarch)
667 * sizeof (struct packet_reg *));
668 for (num_remote_regs = 0, regnum = 0;
669 regnum < gdbarch_num_regs (gdbarch);
671 if (regs[regnum].pnum != -1)
672 remote_regs[num_remote_regs++] = ®s[regnum];
674 qsort (remote_regs, num_remote_regs, sizeof (struct packet_reg *),
677 for (regnum = 0, offset = 0; regnum < num_remote_regs; regnum++)
679 remote_regs[regnum]->in_g_packet = 1;
680 remote_regs[regnum]->offset = offset;
681 offset += register_size (gdbarch, remote_regs[regnum]->regnum);
687 /* Given the architecture described by GDBARCH, return the remote
688 protocol register's number and the register's offset in the g/G
689 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
690 If the target does not have a mapping for REGNUM, return false,
691 otherwise, return true. */
694 remote_register_number_and_offset (struct gdbarch *gdbarch, int regnum,
695 int *pnum, int *poffset)
698 struct packet_reg *regs;
699 struct cleanup *old_chain;
701 gdb_assert (regnum < gdbarch_num_regs (gdbarch));
703 regs = xcalloc (gdbarch_num_regs (gdbarch), sizeof (struct packet_reg));
704 old_chain = make_cleanup (xfree, regs);
706 sizeof_g_packet = map_regcache_remote_table (gdbarch, regs);
708 *pnum = regs[regnum].pnum;
709 *poffset = regs[regnum].offset;
711 do_cleanups (old_chain);
717 init_remote_state (struct gdbarch *gdbarch)
719 struct remote_state *rs = get_remote_state_raw ();
720 struct remote_arch_state *rsa;
722 rsa = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct remote_arch_state);
724 /* Use the architecture to build a regnum<->pnum table, which will be
725 1:1 unless a feature set specifies otherwise. */
726 rsa->regs = GDBARCH_OBSTACK_CALLOC (gdbarch,
727 gdbarch_num_regs (gdbarch),
730 /* Record the maximum possible size of the g packet - it may turn out
732 rsa->sizeof_g_packet = map_regcache_remote_table (gdbarch, rsa->regs);
734 /* Default maximum number of characters in a packet body. Many
735 remote stubs have a hardwired buffer size of 400 bytes
736 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
737 as the maximum packet-size to ensure that the packet and an extra
738 NUL character can always fit in the buffer. This stops GDB
739 trashing stubs that try to squeeze an extra NUL into what is
740 already a full buffer (As of 1999-12-04 that was most stubs). */
741 rsa->remote_packet_size = 400 - 1;
743 /* This one is filled in when a ``g'' packet is received. */
744 rsa->actual_register_packet_size = 0;
746 /* Should rsa->sizeof_g_packet needs more space than the
747 default, adjust the size accordingly. Remember that each byte is
748 encoded as two characters. 32 is the overhead for the packet
749 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
750 (``$NN:G...#NN'') is a better guess, the below has been padded a
752 if (rsa->sizeof_g_packet > ((rsa->remote_packet_size - 32) / 2))
753 rsa->remote_packet_size = (rsa->sizeof_g_packet * 2 + 32);
755 /* Make sure that the packet buffer is plenty big enough for
756 this architecture. */
757 if (rs->buf_size < rsa->remote_packet_size)
759 rs->buf_size = 2 * rsa->remote_packet_size;
760 rs->buf = xrealloc (rs->buf, rs->buf_size);
766 /* Return the current allowed size of a remote packet. This is
767 inferred from the current architecture, and should be used to
768 limit the length of outgoing packets. */
770 get_remote_packet_size (void)
772 struct remote_state *rs = get_remote_state ();
773 struct remote_arch_state *rsa = get_remote_arch_state ();
775 if (rs->explicit_packet_size)
776 return rs->explicit_packet_size;
778 return rsa->remote_packet_size;
781 static struct packet_reg *
782 packet_reg_from_regnum (struct remote_arch_state *rsa, long regnum)
784 if (regnum < 0 && regnum >= gdbarch_num_regs (target_gdbarch ()))
788 struct packet_reg *r = &rsa->regs[regnum];
790 gdb_assert (r->regnum == regnum);
795 static struct packet_reg *
796 packet_reg_from_pnum (struct remote_arch_state *rsa, LONGEST pnum)
800 for (i = 0; i < gdbarch_num_regs (target_gdbarch ()); i++)
802 struct packet_reg *r = &rsa->regs[i];
810 static struct target_ops remote_ops;
812 static struct target_ops extended_remote_ops;
814 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
815 ``forever'' still use the normal timeout mechanism. This is
816 currently used by the ASYNC code to guarentee that target reads
817 during the initial connect always time-out. Once getpkt has been
818 modified to return a timeout indication and, in turn
819 remote_wait()/wait_for_inferior() have gained a timeout parameter
821 static int wait_forever_enabled_p = 1;
823 /* Allow the user to specify what sequence to send to the remote
824 when he requests a program interruption: Although ^C is usually
825 what remote systems expect (this is the default, here), it is
826 sometimes preferable to send a break. On other systems such
827 as the Linux kernel, a break followed by g, which is Magic SysRq g
828 is required in order to interrupt the execution. */
829 const char interrupt_sequence_control_c[] = "Ctrl-C";
830 const char interrupt_sequence_break[] = "BREAK";
831 const char interrupt_sequence_break_g[] = "BREAK-g";
832 static const char *const interrupt_sequence_modes[] =
834 interrupt_sequence_control_c,
835 interrupt_sequence_break,
836 interrupt_sequence_break_g,
839 static const char *interrupt_sequence_mode = interrupt_sequence_control_c;
842 show_interrupt_sequence (struct ui_file *file, int from_tty,
843 struct cmd_list_element *c,
846 if (interrupt_sequence_mode == interrupt_sequence_control_c)
847 fprintf_filtered (file,
848 _("Send the ASCII ETX character (Ctrl-c) "
849 "to the remote target to interrupt the "
850 "execution of the program.\n"));
851 else if (interrupt_sequence_mode == interrupt_sequence_break)
852 fprintf_filtered (file,
853 _("send a break signal to the remote target "
854 "to interrupt the execution of the program.\n"));
855 else if (interrupt_sequence_mode == interrupt_sequence_break_g)
856 fprintf_filtered (file,
857 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
858 "the remote target to interrupt the execution "
859 "of Linux kernel.\n"));
861 internal_error (__FILE__, __LINE__,
862 _("Invalid value for interrupt_sequence_mode: %s."),
863 interrupt_sequence_mode);
866 /* This boolean variable specifies whether interrupt_sequence is sent
867 to the remote target when gdb connects to it.
868 This is mostly needed when you debug the Linux kernel: The Linux kernel
869 expects BREAK g which is Magic SysRq g for connecting gdb. */
870 static int interrupt_on_connect = 0;
872 /* This variable is used to implement the "set/show remotebreak" commands.
873 Since these commands are now deprecated in favor of "set/show remote
874 interrupt-sequence", it no longer has any effect on the code. */
875 static int remote_break;
878 set_remotebreak (char *args, int from_tty, struct cmd_list_element *c)
881 interrupt_sequence_mode = interrupt_sequence_break;
883 interrupt_sequence_mode = interrupt_sequence_control_c;
887 show_remotebreak (struct ui_file *file, int from_tty,
888 struct cmd_list_element *c,
893 /* This variable sets the number of bits in an address that are to be
894 sent in a memory ("M" or "m") packet. Normally, after stripping
895 leading zeros, the entire address would be sent. This variable
896 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
897 initial implementation of remote.c restricted the address sent in
898 memory packets to ``host::sizeof long'' bytes - (typically 32
899 bits). Consequently, for 64 bit targets, the upper 32 bits of an
900 address was never sent. Since fixing this bug may cause a break in
901 some remote targets this variable is principly provided to
902 facilitate backward compatibility. */
904 static unsigned int remote_address_size;
906 /* Temporary to track who currently owns the terminal. See
907 remote_terminal_* for more details. */
909 static int remote_async_terminal_ours_p;
911 /* The executable file to use for "run" on the remote side. */
913 static char *remote_exec_file = "";
916 /* User configurable variables for the number of characters in a
917 memory read/write packet. MIN (rsa->remote_packet_size,
918 rsa->sizeof_g_packet) is the default. Some targets need smaller
919 values (fifo overruns, et.al.) and some users need larger values
920 (speed up transfers). The variables ``preferred_*'' (the user
921 request), ``current_*'' (what was actually set) and ``forced_*''
922 (Positive - a soft limit, negative - a hard limit). */
924 struct memory_packet_config
931 /* Compute the current size of a read/write packet. Since this makes
932 use of ``actual_register_packet_size'' the computation is dynamic. */
935 get_memory_packet_size (struct memory_packet_config *config)
937 struct remote_state *rs = get_remote_state ();
938 struct remote_arch_state *rsa = get_remote_arch_state ();
940 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
941 law?) that some hosts don't cope very well with large alloca()
942 calls. Eventually the alloca() code will be replaced by calls to
943 xmalloc() and make_cleanups() allowing this restriction to either
944 be lifted or removed. */
945 #ifndef MAX_REMOTE_PACKET_SIZE
946 #define MAX_REMOTE_PACKET_SIZE 16384
948 /* NOTE: 20 ensures we can write at least one byte. */
949 #ifndef MIN_REMOTE_PACKET_SIZE
950 #define MIN_REMOTE_PACKET_SIZE 20
955 if (config->size <= 0)
956 what_they_get = MAX_REMOTE_PACKET_SIZE;
958 what_they_get = config->size;
962 what_they_get = get_remote_packet_size ();
963 /* Limit the packet to the size specified by the user. */
965 && what_they_get > config->size)
966 what_they_get = config->size;
968 /* Limit it to the size of the targets ``g'' response unless we have
969 permission from the stub to use a larger packet size. */
970 if (rs->explicit_packet_size == 0
971 && rsa->actual_register_packet_size > 0
972 && what_they_get > rsa->actual_register_packet_size)
973 what_they_get = rsa->actual_register_packet_size;
975 if (what_they_get > MAX_REMOTE_PACKET_SIZE)
976 what_they_get = MAX_REMOTE_PACKET_SIZE;
977 if (what_they_get < MIN_REMOTE_PACKET_SIZE)
978 what_they_get = MIN_REMOTE_PACKET_SIZE;
980 /* Make sure there is room in the global buffer for this packet
981 (including its trailing NUL byte). */
982 if (rs->buf_size < what_they_get + 1)
984 rs->buf_size = 2 * what_they_get;
985 rs->buf = xrealloc (rs->buf, 2 * what_they_get);
988 return what_they_get;
991 /* Update the size of a read/write packet. If they user wants
992 something really big then do a sanity check. */
995 set_memory_packet_size (char *args, struct memory_packet_config *config)
997 int fixed_p = config->fixed_p;
998 long size = config->size;
1001 error (_("Argument required (integer, `fixed' or `limited')."));
1002 else if (strcmp (args, "hard") == 0
1003 || strcmp (args, "fixed") == 0)
1005 else if (strcmp (args, "soft") == 0
1006 || strcmp (args, "limit") == 0)
1012 size = strtoul (args, &end, 0);
1014 error (_("Invalid %s (bad syntax)."), config->name);
1016 /* Instead of explicitly capping the size of a packet to
1017 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
1018 instead allowed to set the size to something arbitrarily
1020 if (size > MAX_REMOTE_PACKET_SIZE)
1021 error (_("Invalid %s (too large)."), config->name);
1025 if (fixed_p && !config->fixed_p)
1027 if (! query (_("The target may not be able to correctly handle a %s\n"
1028 "of %ld bytes. Change the packet size? "),
1029 config->name, size))
1030 error (_("Packet size not changed."));
1032 /* Update the config. */
1033 config->fixed_p = fixed_p;
1034 config->size = size;
1038 show_memory_packet_size (struct memory_packet_config *config)
1040 printf_filtered (_("The %s is %ld. "), config->name, config->size);
1041 if (config->fixed_p)
1042 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1043 get_memory_packet_size (config));
1045 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1046 get_memory_packet_size (config));
1049 static struct memory_packet_config memory_write_packet_config =
1051 "memory-write-packet-size",
1055 set_memory_write_packet_size (char *args, int from_tty)
1057 set_memory_packet_size (args, &memory_write_packet_config);
1061 show_memory_write_packet_size (char *args, int from_tty)
1063 show_memory_packet_size (&memory_write_packet_config);
1067 get_memory_write_packet_size (void)
1069 return get_memory_packet_size (&memory_write_packet_config);
1072 static struct memory_packet_config memory_read_packet_config =
1074 "memory-read-packet-size",
1078 set_memory_read_packet_size (char *args, int from_tty)
1080 set_memory_packet_size (args, &memory_read_packet_config);
1084 show_memory_read_packet_size (char *args, int from_tty)
1086 show_memory_packet_size (&memory_read_packet_config);
1090 get_memory_read_packet_size (void)
1092 long size = get_memory_packet_size (&memory_read_packet_config);
1094 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1095 extra buffer size argument before the memory read size can be
1096 increased beyond this. */
1097 if (size > get_remote_packet_size ())
1098 size = get_remote_packet_size ();
1103 /* Generic configuration support for packets the stub optionally
1104 supports. Allows the user to specify the use of the packet as well
1105 as allowing GDB to auto-detect support in the remote stub. */
1109 PACKET_SUPPORT_UNKNOWN = 0,
1114 struct packet_config
1118 enum auto_boolean detect;
1119 enum packet_support support;
1122 /* Analyze a packet's return value and update the packet config
1133 update_packet_config (struct packet_config *config)
1135 switch (config->detect)
1137 case AUTO_BOOLEAN_TRUE:
1138 config->support = PACKET_ENABLE;
1140 case AUTO_BOOLEAN_FALSE:
1141 config->support = PACKET_DISABLE;
1143 case AUTO_BOOLEAN_AUTO:
1144 config->support = PACKET_SUPPORT_UNKNOWN;
1150 show_packet_config_cmd (struct packet_config *config)
1152 char *support = "internal-error";
1154 switch (config->support)
1157 support = "enabled";
1159 case PACKET_DISABLE:
1160 support = "disabled";
1162 case PACKET_SUPPORT_UNKNOWN:
1163 support = "unknown";
1166 switch (config->detect)
1168 case AUTO_BOOLEAN_AUTO:
1169 printf_filtered (_("Support for the `%s' packet "
1170 "is auto-detected, currently %s.\n"),
1171 config->name, support);
1173 case AUTO_BOOLEAN_TRUE:
1174 case AUTO_BOOLEAN_FALSE:
1175 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1176 config->name, support);
1182 add_packet_config_cmd (struct packet_config *config, const char *name,
1183 const char *title, int legacy)
1189 config->name = name;
1190 config->title = title;
1191 config->detect = AUTO_BOOLEAN_AUTO;
1192 config->support = PACKET_SUPPORT_UNKNOWN;
1193 set_doc = xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1195 show_doc = xstrprintf ("Show current use of remote "
1196 "protocol `%s' (%s) packet",
1198 /* set/show TITLE-packet {auto,on,off} */
1199 cmd_name = xstrprintf ("%s-packet", title);
1200 add_setshow_auto_boolean_cmd (cmd_name, class_obscure,
1201 &config->detect, set_doc,
1202 show_doc, NULL, /* help_doc */
1203 set_remote_protocol_packet_cmd,
1204 show_remote_protocol_packet_cmd,
1205 &remote_set_cmdlist, &remote_show_cmdlist);
1206 /* The command code copies the documentation strings. */
1209 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1214 legacy_name = xstrprintf ("%s-packet", name);
1215 add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
1216 &remote_set_cmdlist);
1217 add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
1218 &remote_show_cmdlist);
1222 static enum packet_result
1223 packet_check_result (const char *buf)
1227 /* The stub recognized the packet request. Check that the
1228 operation succeeded. */
1230 && isxdigit (buf[1]) && isxdigit (buf[2])
1232 /* "Enn" - definitly an error. */
1233 return PACKET_ERROR;
1235 /* Always treat "E." as an error. This will be used for
1236 more verbose error messages, such as E.memtypes. */
1237 if (buf[0] == 'E' && buf[1] == '.')
1238 return PACKET_ERROR;
1240 /* The packet may or may not be OK. Just assume it is. */
1244 /* The stub does not support the packet. */
1245 return PACKET_UNKNOWN;
1248 static enum packet_result
1249 packet_ok (const char *buf, struct packet_config *config)
1251 enum packet_result result;
1253 result = packet_check_result (buf);
1258 /* The stub recognized the packet request. */
1259 switch (config->support)
1261 case PACKET_SUPPORT_UNKNOWN:
1263 fprintf_unfiltered (gdb_stdlog,
1264 "Packet %s (%s) is supported\n",
1265 config->name, config->title);
1266 config->support = PACKET_ENABLE;
1268 case PACKET_DISABLE:
1269 internal_error (__FILE__, __LINE__,
1270 _("packet_ok: attempt to use a disabled packet"));
1276 case PACKET_UNKNOWN:
1277 /* The stub does not support the packet. */
1278 switch (config->support)
1281 if (config->detect == AUTO_BOOLEAN_AUTO)
1282 /* If the stub previously indicated that the packet was
1283 supported then there is a protocol error.. */
1284 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1285 config->name, config->title);
1287 /* The user set it wrong. */
1288 error (_("Enabled packet %s (%s) not recognized by stub"),
1289 config->name, config->title);
1291 case PACKET_SUPPORT_UNKNOWN:
1293 fprintf_unfiltered (gdb_stdlog,
1294 "Packet %s (%s) is NOT supported\n",
1295 config->name, config->title);
1296 config->support = PACKET_DISABLE;
1298 case PACKET_DISABLE:
1320 PACKET_vFile_pwrite,
1322 PACKET_vFile_unlink,
1323 PACKET_vFile_readlink,
1325 PACKET_qXfer_features,
1326 PACKET_qXfer_libraries,
1327 PACKET_qXfer_libraries_svr4,
1328 PACKET_qXfer_memory_map,
1329 PACKET_qXfer_spu_read,
1330 PACKET_qXfer_spu_write,
1331 PACKET_qXfer_osdata,
1332 PACKET_qXfer_threads,
1333 PACKET_qXfer_statictrace_read,
1334 PACKET_qXfer_traceframe_info,
1340 PACKET_QPassSignals,
1341 PACKET_QProgramSignals,
1342 PACKET_qSearch_memory,
1345 PACKET_QStartNoAckMode,
1347 PACKET_qXfer_siginfo_read,
1348 PACKET_qXfer_siginfo_write,
1350 PACKET_ConditionalTracepoints,
1351 PACKET_ConditionalBreakpoints,
1352 PACKET_BreakpointCommands,
1353 PACKET_FastTracepoints,
1354 PACKET_StaticTracepoints,
1355 PACKET_InstallInTrace,
1358 PACKET_TracepointSource,
1361 PACKET_QDisableRandomization,
1363 PACKET_QTBuffer_size,
1366 PACKET_qXfer_btrace,
1370 static struct packet_config remote_protocol_packets[PACKET_MAX];
1373 set_remote_protocol_packet_cmd (char *args, int from_tty,
1374 struct cmd_list_element *c)
1376 struct packet_config *packet;
1378 for (packet = remote_protocol_packets;
1379 packet < &remote_protocol_packets[PACKET_MAX];
1382 if (&packet->detect == c->var)
1384 update_packet_config (packet);
1388 internal_error (__FILE__, __LINE__, _("Could not find config for %s"),
1393 show_remote_protocol_packet_cmd (struct ui_file *file, int from_tty,
1394 struct cmd_list_element *c,
1397 struct packet_config *packet;
1399 for (packet = remote_protocol_packets;
1400 packet < &remote_protocol_packets[PACKET_MAX];
1403 if (&packet->detect == c->var)
1405 show_packet_config_cmd (packet);
1409 internal_error (__FILE__, __LINE__, _("Could not find config for %s"),
1413 /* Should we try one of the 'Z' requests? */
1417 Z_PACKET_SOFTWARE_BP,
1418 Z_PACKET_HARDWARE_BP,
1425 /* For compatibility with older distributions. Provide a ``set remote
1426 Z-packet ...'' command that updates all the Z packet types. */
1428 static enum auto_boolean remote_Z_packet_detect;
1431 set_remote_protocol_Z_packet_cmd (char *args, int from_tty,
1432 struct cmd_list_element *c)
1436 for (i = 0; i < NR_Z_PACKET_TYPES; i++)
1438 remote_protocol_packets[PACKET_Z0 + i].detect = remote_Z_packet_detect;
1439 update_packet_config (&remote_protocol_packets[PACKET_Z0 + i]);
1444 show_remote_protocol_Z_packet_cmd (struct ui_file *file, int from_tty,
1445 struct cmd_list_element *c,
1450 for (i = 0; i < NR_Z_PACKET_TYPES; i++)
1452 show_packet_config_cmd (&remote_protocol_packets[PACKET_Z0 + i]);
1456 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1457 static struct async_signal_handler *async_sigint_remote_twice_token;
1458 static struct async_signal_handler *async_sigint_remote_token;
1461 /* Asynchronous signal handle registered as event loop source for
1462 when we have pending events ready to be passed to the core. */
1464 static struct async_event_handler *remote_async_inferior_event_token;
1468 static ptid_t magic_null_ptid;
1469 static ptid_t not_sent_ptid;
1470 static ptid_t any_thread_ptid;
1472 /* Find out if the stub attached to PID (and hence GDB should offer to
1473 detach instead of killing it when bailing out). */
1476 remote_query_attached (int pid)
1478 struct remote_state *rs = get_remote_state ();
1479 size_t size = get_remote_packet_size ();
1481 if (remote_protocol_packets[PACKET_qAttached].support == PACKET_DISABLE)
1484 if (remote_multi_process_p (rs))
1485 xsnprintf (rs->buf, size, "qAttached:%x", pid);
1487 xsnprintf (rs->buf, size, "qAttached");
1490 getpkt (&rs->buf, &rs->buf_size, 0);
1492 switch (packet_ok (rs->buf,
1493 &remote_protocol_packets[PACKET_qAttached]))
1496 if (strcmp (rs->buf, "1") == 0)
1500 warning (_("Remote failure reply: %s"), rs->buf);
1502 case PACKET_UNKNOWN:
1509 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1510 has been invented by GDB, instead of reported by the target. Since
1511 we can be connected to a remote system before before knowing about
1512 any inferior, mark the target with execution when we find the first
1513 inferior. If ATTACHED is 1, then we had just attached to this
1514 inferior. If it is 0, then we just created this inferior. If it
1515 is -1, then try querying the remote stub to find out if it had
1516 attached to the inferior or not. */
1518 static struct inferior *
1519 remote_add_inferior (int fake_pid_p, int pid, int attached)
1521 struct inferior *inf;
1523 /* Check whether this process we're learning about is to be
1524 considered attached, or if is to be considered to have been
1525 spawned by the stub. */
1527 attached = remote_query_attached (pid);
1529 if (gdbarch_has_global_solist (target_gdbarch ()))
1531 /* If the target shares code across all inferiors, then every
1532 attach adds a new inferior. */
1533 inf = add_inferior (pid);
1535 /* ... and every inferior is bound to the same program space.
1536 However, each inferior may still have its own address
1538 inf->aspace = maybe_new_address_space ();
1539 inf->pspace = current_program_space;
1543 /* In the traditional debugging scenario, there's a 1-1 match
1544 between program/address spaces. We simply bind the inferior
1545 to the program space's address space. */
1546 inf = current_inferior ();
1547 inferior_appeared (inf, pid);
1550 inf->attach_flag = attached;
1551 inf->fake_pid_p = fake_pid_p;
1556 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1557 according to RUNNING. */
1560 remote_add_thread (ptid_t ptid, int running)
1562 struct remote_state *rs = get_remote_state ();
1564 /* GDB historically didn't pull threads in the initial connection
1565 setup. If the remote target doesn't even have a concept of
1566 threads (e.g., a bare-metal target), even if internally we
1567 consider that a single-threaded target, mentioning a new thread
1568 might be confusing to the user. Be silent then, preserving the
1569 age old behavior. */
1570 if (rs->starting_up)
1571 add_thread_silent (ptid);
1575 set_executing (ptid, running);
1576 set_running (ptid, running);
1579 /* Come here when we learn about a thread id from the remote target.
1580 It may be the first time we hear about such thread, so take the
1581 opportunity to add it to GDB's thread list. In case this is the
1582 first time we're noticing its corresponding inferior, add it to
1583 GDB's inferior list as well. */
1586 remote_notice_new_inferior (ptid_t currthread, int running)
1588 /* If this is a new thread, add it to GDB's thread list.
1589 If we leave it up to WFI to do this, bad things will happen. */
1591 if (in_thread_list (currthread) && is_exited (currthread))
1593 /* We're seeing an event on a thread id we knew had exited.
1594 This has to be a new thread reusing the old id. Add it. */
1595 remote_add_thread (currthread, running);
1599 if (!in_thread_list (currthread))
1601 struct inferior *inf = NULL;
1602 int pid = ptid_get_pid (currthread);
1604 if (ptid_is_pid (inferior_ptid)
1605 && pid == ptid_get_pid (inferior_ptid))
1607 /* inferior_ptid has no thread member yet. This can happen
1608 with the vAttach -> remote_wait,"TAAthread:" path if the
1609 stub doesn't support qC. This is the first stop reported
1610 after an attach, so this is the main thread. Update the
1611 ptid in the thread list. */
1612 if (in_thread_list (pid_to_ptid (pid)))
1613 thread_change_ptid (inferior_ptid, currthread);
1616 remote_add_thread (currthread, running);
1617 inferior_ptid = currthread;
1622 if (ptid_equal (magic_null_ptid, inferior_ptid))
1624 /* inferior_ptid is not set yet. This can happen with the
1625 vRun -> remote_wait,"TAAthread:" path if the stub
1626 doesn't support qC. This is the first stop reported
1627 after an attach, so this is the main thread. Update the
1628 ptid in the thread list. */
1629 thread_change_ptid (inferior_ptid, currthread);
1633 /* When connecting to a target remote, or to a target
1634 extended-remote which already was debugging an inferior, we
1635 may not know about it yet. Add it before adding its child
1636 thread, so notifications are emitted in a sensible order. */
1637 if (!in_inferior_list (ptid_get_pid (currthread)))
1639 struct remote_state *rs = get_remote_state ();
1640 int fake_pid_p = !remote_multi_process_p (rs);
1642 inf = remote_add_inferior (fake_pid_p,
1643 ptid_get_pid (currthread), -1);
1646 /* This is really a new thread. Add it. */
1647 remote_add_thread (currthread, running);
1649 /* If we found a new inferior, let the common code do whatever
1650 it needs to with it (e.g., read shared libraries, insert
1651 breakpoints), unless we're just setting up an all-stop
1655 struct remote_state *rs = get_remote_state ();
1657 if (non_stop || !rs->starting_up)
1658 notice_new_inferior (currthread, running, 0);
1663 /* Return the private thread data, creating it if necessary. */
1665 static struct private_thread_info *
1666 demand_private_info (ptid_t ptid)
1668 struct thread_info *info = find_thread_ptid (ptid);
1674 info->private = xmalloc (sizeof (*(info->private)));
1675 info->private_dtor = free_private_thread_info;
1676 info->private->core = -1;
1677 info->private->extra = 0;
1680 return info->private;
1683 /* Call this function as a result of
1684 1) A halt indication (T packet) containing a thread id
1685 2) A direct query of currthread
1686 3) Successful execution of set thread */
1689 record_currthread (struct remote_state *rs, ptid_t currthread)
1691 rs->general_thread = currthread;
1694 /* If 'QPassSignals' is supported, tell the remote stub what signals
1695 it can simply pass through to the inferior without reporting. */
1698 remote_pass_signals (struct target_ops *self,
1699 int numsigs, unsigned char *pass_signals)
1701 if (remote_protocol_packets[PACKET_QPassSignals].support != PACKET_DISABLE)
1703 char *pass_packet, *p;
1705 struct remote_state *rs = get_remote_state ();
1707 gdb_assert (numsigs < 256);
1708 for (i = 0; i < numsigs; i++)
1710 if (pass_signals[i])
1713 pass_packet = xmalloc (count * 3 + strlen ("QPassSignals:") + 1);
1714 strcpy (pass_packet, "QPassSignals:");
1715 p = pass_packet + strlen (pass_packet);
1716 for (i = 0; i < numsigs; i++)
1718 if (pass_signals[i])
1721 *p++ = tohex (i >> 4);
1722 *p++ = tohex (i & 15);
1731 if (!rs->last_pass_packet || strcmp (rs->last_pass_packet, pass_packet))
1733 putpkt (pass_packet);
1734 getpkt (&rs->buf, &rs->buf_size, 0);
1735 packet_ok (rs->buf, &remote_protocol_packets[PACKET_QPassSignals]);
1736 if (rs->last_pass_packet)
1737 xfree (rs->last_pass_packet);
1738 rs->last_pass_packet = pass_packet;
1741 xfree (pass_packet);
1745 /* If 'QProgramSignals' is supported, tell the remote stub what
1746 signals it should pass through to the inferior when detaching. */
1749 remote_program_signals (struct target_ops *self,
1750 int numsigs, unsigned char *signals)
1752 if (remote_protocol_packets[PACKET_QProgramSignals].support != PACKET_DISABLE)
1756 struct remote_state *rs = get_remote_state ();
1758 gdb_assert (numsigs < 256);
1759 for (i = 0; i < numsigs; i++)
1764 packet = xmalloc (count * 3 + strlen ("QProgramSignals:") + 1);
1765 strcpy (packet, "QProgramSignals:");
1766 p = packet + strlen (packet);
1767 for (i = 0; i < numsigs; i++)
1769 if (signal_pass_state (i))
1772 *p++ = tohex (i >> 4);
1773 *p++ = tohex (i & 15);
1782 if (!rs->last_program_signals_packet
1783 || strcmp (rs->last_program_signals_packet, packet) != 0)
1786 getpkt (&rs->buf, &rs->buf_size, 0);
1787 packet_ok (rs->buf, &remote_protocol_packets[PACKET_QProgramSignals]);
1788 xfree (rs->last_program_signals_packet);
1789 rs->last_program_signals_packet = packet;
1796 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1797 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1798 thread. If GEN is set, set the general thread, if not, then set
1799 the step/continue thread. */
1801 set_thread (struct ptid ptid, int gen)
1803 struct remote_state *rs = get_remote_state ();
1804 ptid_t state = gen ? rs->general_thread : rs->continue_thread;
1805 char *buf = rs->buf;
1806 char *endbuf = rs->buf + get_remote_packet_size ();
1808 if (ptid_equal (state, ptid))
1812 *buf++ = gen ? 'g' : 'c';
1813 if (ptid_equal (ptid, magic_null_ptid))
1814 xsnprintf (buf, endbuf - buf, "0");
1815 else if (ptid_equal (ptid, any_thread_ptid))
1816 xsnprintf (buf, endbuf - buf, "0");
1817 else if (ptid_equal (ptid, minus_one_ptid))
1818 xsnprintf (buf, endbuf - buf, "-1");
1820 write_ptid (buf, endbuf, ptid);
1822 getpkt (&rs->buf, &rs->buf_size, 0);
1824 rs->general_thread = ptid;
1826 rs->continue_thread = ptid;
1830 set_general_thread (struct ptid ptid)
1832 set_thread (ptid, 1);
1836 set_continue_thread (struct ptid ptid)
1838 set_thread (ptid, 0);
1841 /* Change the remote current process. Which thread within the process
1842 ends up selected isn't important, as long as it is the same process
1843 as what INFERIOR_PTID points to.
1845 This comes from that fact that there is no explicit notion of
1846 "selected process" in the protocol. The selected process for
1847 general operations is the process the selected general thread
1851 set_general_process (void)
1853 struct remote_state *rs = get_remote_state ();
1855 /* If the remote can't handle multiple processes, don't bother. */
1856 if (!rs->extended || !remote_multi_process_p (rs))
1859 /* We only need to change the remote current thread if it's pointing
1860 at some other process. */
1861 if (ptid_get_pid (rs->general_thread) != ptid_get_pid (inferior_ptid))
1862 set_general_thread (inferior_ptid);
1866 /* Return nonzero if the thread PTID is still alive on the remote
1870 remote_thread_alive (struct target_ops *ops, ptid_t ptid)
1872 struct remote_state *rs = get_remote_state ();
1875 if (ptid_equal (ptid, magic_null_ptid))
1876 /* The main thread is always alive. */
1879 if (ptid_get_pid (ptid) != 0 && ptid_get_tid (ptid) == 0)
1880 /* The main thread is always alive. This can happen after a
1881 vAttach, if the remote side doesn't support
1886 endp = rs->buf + get_remote_packet_size ();
1889 write_ptid (p, endp, ptid);
1892 getpkt (&rs->buf, &rs->buf_size, 0);
1893 return (rs->buf[0] == 'O' && rs->buf[1] == 'K');
1896 /* About these extended threadlist and threadinfo packets. They are
1897 variable length packets but, the fields within them are often fixed
1898 length. They are redundent enough to send over UDP as is the
1899 remote protocol in general. There is a matching unit test module
1902 /* WARNING: This threadref data structure comes from the remote O.S.,
1903 libstub protocol encoding, and remote.c. It is not particularly
1906 /* Right now, the internal structure is int. We want it to be bigger.
1907 Plan to fix this. */
1909 typedef int gdb_threadref; /* Internal GDB thread reference. */
1911 /* gdb_ext_thread_info is an internal GDB data structure which is
1912 equivalent to the reply of the remote threadinfo packet. */
1914 struct gdb_ext_thread_info
1916 threadref threadid; /* External form of thread reference. */
1917 int active; /* Has state interesting to GDB?
1919 char display[256]; /* Brief state display, name,
1920 blocked/suspended. */
1921 char shortname[32]; /* To be used to name threads. */
1922 char more_display[256]; /* Long info, statistics, queue depth,
1926 /* The volume of remote transfers can be limited by submitting
1927 a mask containing bits specifying the desired information.
1928 Use a union of these values as the 'selection' parameter to
1929 get_thread_info. FIXME: Make these TAG names more thread specific. */
1931 #define TAG_THREADID 1
1932 #define TAG_EXISTS 2
1933 #define TAG_DISPLAY 4
1934 #define TAG_THREADNAME 8
1935 #define TAG_MOREDISPLAY 16
1937 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1939 static char *unpack_nibble (char *buf, int *val);
1941 static char *unpack_byte (char *buf, int *value);
1943 static char *pack_int (char *buf, int value);
1945 static char *unpack_int (char *buf, int *value);
1947 static char *unpack_string (char *src, char *dest, int length);
1949 static char *pack_threadid (char *pkt, threadref *id);
1951 static char *unpack_threadid (char *inbuf, threadref *id);
1953 void int_to_threadref (threadref *id, int value);
1955 static int threadref_to_int (threadref *ref);
1957 static void copy_threadref (threadref *dest, threadref *src);
1959 static int threadmatch (threadref *dest, threadref *src);
1961 static char *pack_threadinfo_request (char *pkt, int mode,
1964 static int remote_unpack_thread_info_response (char *pkt,
1965 threadref *expectedref,
1966 struct gdb_ext_thread_info
1970 static int remote_get_threadinfo (threadref *threadid,
1971 int fieldset, /*TAG mask */
1972 struct gdb_ext_thread_info *info);
1974 static char *pack_threadlist_request (char *pkt, int startflag,
1976 threadref *nextthread);
1978 static int parse_threadlist_response (char *pkt,
1980 threadref *original_echo,
1981 threadref *resultlist,
1984 static int remote_get_threadlist (int startflag,
1985 threadref *nextthread,
1989 threadref *threadlist);
1991 typedef int (*rmt_thread_action) (threadref *ref, void *context);
1993 static int remote_threadlist_iterator (rmt_thread_action stepfunction,
1994 void *context, int looplimit);
1996 static int remote_newthread_step (threadref *ref, void *context);
1999 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2000 buffer we're allowed to write to. Returns
2001 BUF+CHARACTERS_WRITTEN. */
2004 write_ptid (char *buf, const char *endbuf, ptid_t ptid)
2007 struct remote_state *rs = get_remote_state ();
2009 if (remote_multi_process_p (rs))
2011 pid = ptid_get_pid (ptid);
2013 buf += xsnprintf (buf, endbuf - buf, "p-%x.", -pid);
2015 buf += xsnprintf (buf, endbuf - buf, "p%x.", pid);
2017 tid = ptid_get_tid (ptid);
2019 buf += xsnprintf (buf, endbuf - buf, "-%x", -tid);
2021 buf += xsnprintf (buf, endbuf - buf, "%x", tid);
2026 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2027 passed the last parsed char. Returns null_ptid on error. */
2030 read_ptid (char *buf, char **obuf)
2034 ULONGEST pid = 0, tid = 0;
2038 /* Multi-process ptid. */
2039 pp = unpack_varlen_hex (p + 1, &pid);
2041 error (_("invalid remote ptid: %s"), p);
2044 pp = unpack_varlen_hex (p + 1, &tid);
2047 return ptid_build (pid, 0, tid);
2050 /* No multi-process. Just a tid. */
2051 pp = unpack_varlen_hex (p, &tid);
2053 /* Since the stub is not sending a process id, then default to
2054 what's in inferior_ptid, unless it's null at this point. If so,
2055 then since there's no way to know the pid of the reported
2056 threads, use the magic number. */
2057 if (ptid_equal (inferior_ptid, null_ptid))
2058 pid = ptid_get_pid (magic_null_ptid);
2060 pid = ptid_get_pid (inferior_ptid);
2064 return ptid_build (pid, 0, tid);
2070 if (ch >= 'a' && ch <= 'f')
2071 return ch - 'a' + 10;
2072 if (ch >= '0' && ch <= '9')
2074 if (ch >= 'A' && ch <= 'F')
2075 return ch - 'A' + 10;
2080 stub_unpack_int (char *buff, int fieldlength)
2087 nibble = stubhex (*buff++);
2091 retval = retval << 4;
2097 unpack_nibble (char *buf, int *val)
2099 *val = fromhex (*buf++);
2104 unpack_byte (char *buf, int *value)
2106 *value = stub_unpack_int (buf, 2);
2111 pack_int (char *buf, int value)
2113 buf = pack_hex_byte (buf, (value >> 24) & 0xff);
2114 buf = pack_hex_byte (buf, (value >> 16) & 0xff);
2115 buf = pack_hex_byte (buf, (value >> 8) & 0x0ff);
2116 buf = pack_hex_byte (buf, (value & 0xff));
2121 unpack_int (char *buf, int *value)
2123 *value = stub_unpack_int (buf, 8);
2127 #if 0 /* Currently unused, uncomment when needed. */
2128 static char *pack_string (char *pkt, char *string);
2131 pack_string (char *pkt, char *string)
2136 len = strlen (string);
2138 len = 200; /* Bigger than most GDB packets, junk??? */
2139 pkt = pack_hex_byte (pkt, len);
2143 if ((ch == '\0') || (ch == '#'))
2144 ch = '*'; /* Protect encapsulation. */
2149 #endif /* 0 (unused) */
2152 unpack_string (char *src, char *dest, int length)
2161 pack_threadid (char *pkt, threadref *id)
2164 unsigned char *altid;
2166 altid = (unsigned char *) id;
2167 limit = pkt + BUF_THREAD_ID_SIZE;
2169 pkt = pack_hex_byte (pkt, *altid++);
2175 unpack_threadid (char *inbuf, threadref *id)
2178 char *limit = inbuf + BUF_THREAD_ID_SIZE;
2181 altref = (char *) id;
2183 while (inbuf < limit)
2185 x = stubhex (*inbuf++);
2186 y = stubhex (*inbuf++);
2187 *altref++ = (x << 4) | y;
2192 /* Externally, threadrefs are 64 bits but internally, they are still
2193 ints. This is due to a mismatch of specifications. We would like
2194 to use 64bit thread references internally. This is an adapter
2198 int_to_threadref (threadref *id, int value)
2200 unsigned char *scan;
2202 scan = (unsigned char *) id;
2208 *scan++ = (value >> 24) & 0xff;
2209 *scan++ = (value >> 16) & 0xff;
2210 *scan++ = (value >> 8) & 0xff;
2211 *scan++ = (value & 0xff);
2215 threadref_to_int (threadref *ref)
2218 unsigned char *scan;
2224 value = (value << 8) | ((*scan++) & 0xff);
2229 copy_threadref (threadref *dest, threadref *src)
2232 unsigned char *csrc, *cdest;
2234 csrc = (unsigned char *) src;
2235 cdest = (unsigned char *) dest;
2242 threadmatch (threadref *dest, threadref *src)
2244 /* Things are broken right now, so just assume we got a match. */
2246 unsigned char *srcp, *destp;
2248 srcp = (char *) src;
2249 destp = (char *) dest;
2253 result &= (*srcp++ == *destp++) ? 1 : 0;
2260 threadid:1, # always request threadid
2267 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2270 pack_threadinfo_request (char *pkt, int mode, threadref *id)
2272 *pkt++ = 'q'; /* Info Query */
2273 *pkt++ = 'P'; /* process or thread info */
2274 pkt = pack_int (pkt, mode); /* mode */
2275 pkt = pack_threadid (pkt, id); /* threadid */
2276 *pkt = '\0'; /* terminate */
2280 /* These values tag the fields in a thread info response packet. */
2281 /* Tagging the fields allows us to request specific fields and to
2282 add more fields as time goes by. */
2284 #define TAG_THREADID 1 /* Echo the thread identifier. */
2285 #define TAG_EXISTS 2 /* Is this process defined enough to
2286 fetch registers and its stack? */
2287 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2288 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2289 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2293 remote_unpack_thread_info_response (char *pkt, threadref *expectedref,
2294 struct gdb_ext_thread_info *info)
2296 struct remote_state *rs = get_remote_state ();
2300 char *limit = pkt + rs->buf_size; /* Plausible parsing limit. */
2303 /* info->threadid = 0; FIXME: implement zero_threadref. */
2305 info->display[0] = '\0';
2306 info->shortname[0] = '\0';
2307 info->more_display[0] = '\0';
2309 /* Assume the characters indicating the packet type have been
2311 pkt = unpack_int (pkt, &mask); /* arg mask */
2312 pkt = unpack_threadid (pkt, &ref);
2315 warning (_("Incomplete response to threadinfo request."));
2316 if (!threadmatch (&ref, expectedref))
2317 { /* This is an answer to a different request. */
2318 warning (_("ERROR RMT Thread info mismatch."));
2321 copy_threadref (&info->threadid, &ref);
2323 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2325 /* Packets are terminated with nulls. */
2326 while ((pkt < limit) && mask && *pkt)
2328 pkt = unpack_int (pkt, &tag); /* tag */
2329 pkt = unpack_byte (pkt, &length); /* length */
2330 if (!(tag & mask)) /* Tags out of synch with mask. */
2332 warning (_("ERROR RMT: threadinfo tag mismatch."));
2336 if (tag == TAG_THREADID)
2340 warning (_("ERROR RMT: length of threadid is not 16."));
2344 pkt = unpack_threadid (pkt, &ref);
2345 mask = mask & ~TAG_THREADID;
2348 if (tag == TAG_EXISTS)
2350 info->active = stub_unpack_int (pkt, length);
2352 mask = mask & ~(TAG_EXISTS);
2355 warning (_("ERROR RMT: 'exists' length too long."));
2361 if (tag == TAG_THREADNAME)
2363 pkt = unpack_string (pkt, &info->shortname[0], length);
2364 mask = mask & ~TAG_THREADNAME;
2367 if (tag == TAG_DISPLAY)
2369 pkt = unpack_string (pkt, &info->display[0], length);
2370 mask = mask & ~TAG_DISPLAY;
2373 if (tag == TAG_MOREDISPLAY)
2375 pkt = unpack_string (pkt, &info->more_display[0], length);
2376 mask = mask & ~TAG_MOREDISPLAY;
2379 warning (_("ERROR RMT: unknown thread info tag."));
2380 break; /* Not a tag we know about. */
2386 remote_get_threadinfo (threadref *threadid, int fieldset, /* TAG mask */
2387 struct gdb_ext_thread_info *info)
2389 struct remote_state *rs = get_remote_state ();
2392 pack_threadinfo_request (rs->buf, fieldset, threadid);
2394 getpkt (&rs->buf, &rs->buf_size, 0);
2396 if (rs->buf[0] == '\0')
2399 result = remote_unpack_thread_info_response (rs->buf + 2,
2404 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2407 pack_threadlist_request (char *pkt, int startflag, int threadcount,
2408 threadref *nextthread)
2410 *pkt++ = 'q'; /* info query packet */
2411 *pkt++ = 'L'; /* Process LIST or threadLIST request */
2412 pkt = pack_nibble (pkt, startflag); /* initflag 1 bytes */
2413 pkt = pack_hex_byte (pkt, threadcount); /* threadcount 2 bytes */
2414 pkt = pack_threadid (pkt, nextthread); /* 64 bit thread identifier */
2419 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2422 parse_threadlist_response (char *pkt, int result_limit,
2423 threadref *original_echo, threadref *resultlist,
2426 struct remote_state *rs = get_remote_state ();
2428 int count, resultcount, done;
2431 /* Assume the 'q' and 'M chars have been stripped. */
2432 limit = pkt + (rs->buf_size - BUF_THREAD_ID_SIZE);
2433 /* done parse past here */
2434 pkt = unpack_byte (pkt, &count); /* count field */
2435 pkt = unpack_nibble (pkt, &done);
2436 /* The first threadid is the argument threadid. */
2437 pkt = unpack_threadid (pkt, original_echo); /* should match query packet */
2438 while ((count-- > 0) && (pkt < limit))
2440 pkt = unpack_threadid (pkt, resultlist++);
2441 if (resultcount++ >= result_limit)
2450 remote_get_threadlist (int startflag, threadref *nextthread, int result_limit,
2451 int *done, int *result_count, threadref *threadlist)
2453 struct remote_state *rs = get_remote_state ();
2456 /* Trancate result limit to be smaller than the packet size. */
2457 if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10)
2458 >= get_remote_packet_size ())
2459 result_limit = (get_remote_packet_size () / BUF_THREAD_ID_SIZE) - 2;
2461 pack_threadlist_request (rs->buf, startflag, result_limit, nextthread);
2463 getpkt (&rs->buf, &rs->buf_size, 0);
2465 if (*rs->buf == '\0')
2469 parse_threadlist_response (rs->buf + 2, result_limit,
2470 &rs->echo_nextthread, threadlist, done);
2472 if (!threadmatch (&rs->echo_nextthread, nextthread))
2474 /* FIXME: This is a good reason to drop the packet. */
2475 /* Possably, there is a duplicate response. */
2477 retransmit immediatly - race conditions
2478 retransmit after timeout - yes
2480 wait for packet, then exit
2482 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2483 return 0; /* I choose simply exiting. */
2485 if (*result_count <= 0)
2489 warning (_("RMT ERROR : failed to get remote thread list."));
2492 return result; /* break; */
2494 if (*result_count > result_limit)
2497 warning (_("RMT ERROR: threadlist response longer than requested."));
2503 /* This is the interface between remote and threads, remotes upper
2506 /* remote_find_new_threads retrieves the thread list and for each
2507 thread in the list, looks up the thread in GDB's internal list,
2508 adding the thread if it does not already exist. This involves
2509 getting partial thread lists from the remote target so, polling the
2510 quit_flag is required. */
2514 remote_threadlist_iterator (rmt_thread_action stepfunction, void *context,
2517 struct remote_state *rs = get_remote_state ();
2518 int done, i, result_count;
2526 if (loopcount++ > looplimit)
2529 warning (_("Remote fetch threadlist -infinite loop-."));
2532 if (!remote_get_threadlist (startflag, &rs->nextthread,
2533 MAXTHREADLISTRESULTS,
2534 &done, &result_count, rs->resultthreadlist))
2539 /* Clear for later iterations. */
2541 /* Setup to resume next batch of thread references, set nextthread. */
2542 if (result_count >= 1)
2543 copy_threadref (&rs->nextthread,
2544 &rs->resultthreadlist[result_count - 1]);
2546 while (result_count--)
2547 if (!(result = (*stepfunction) (&rs->resultthreadlist[i++], context)))
2554 remote_newthread_step (threadref *ref, void *context)
2556 int pid = ptid_get_pid (inferior_ptid);
2557 ptid_t ptid = ptid_build (pid, 0, threadref_to_int (ref));
2559 if (!in_thread_list (ptid))
2561 return 1; /* continue iterator */
2564 #define CRAZY_MAX_THREADS 1000
2567 remote_current_thread (ptid_t oldpid)
2569 struct remote_state *rs = get_remote_state ();
2572 getpkt (&rs->buf, &rs->buf_size, 0);
2573 if (rs->buf[0] == 'Q' && rs->buf[1] == 'C')
2574 return read_ptid (&rs->buf[2], NULL);
2579 /* Find new threads for info threads command.
2580 * Original version, using John Metzler's thread protocol.
2584 remote_find_new_threads (void)
2586 remote_threadlist_iterator (remote_newthread_step, 0,
2590 #if defined(HAVE_LIBEXPAT)
2592 typedef struct thread_item
2598 DEF_VEC_O(thread_item_t);
2600 struct threads_parsing_context
2602 VEC (thread_item_t) *items;
2606 start_thread (struct gdb_xml_parser *parser,
2607 const struct gdb_xml_element *element,
2608 void *user_data, VEC(gdb_xml_value_s) *attributes)
2610 struct threads_parsing_context *data = user_data;
2612 struct thread_item item;
2614 struct gdb_xml_value *attr;
2616 id = xml_find_attribute (attributes, "id")->value;
2617 item.ptid = read_ptid (id, NULL);
2619 attr = xml_find_attribute (attributes, "core");
2621 item.core = *(ULONGEST *) attr->value;
2627 VEC_safe_push (thread_item_t, data->items, &item);
2631 end_thread (struct gdb_xml_parser *parser,
2632 const struct gdb_xml_element *element,
2633 void *user_data, const char *body_text)
2635 struct threads_parsing_context *data = user_data;
2637 if (body_text && *body_text)
2638 VEC_last (thread_item_t, data->items)->extra = xstrdup (body_text);
2641 const struct gdb_xml_attribute thread_attributes[] = {
2642 { "id", GDB_XML_AF_NONE, NULL, NULL },
2643 { "core", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL },
2644 { NULL, GDB_XML_AF_NONE, NULL, NULL }
2647 const struct gdb_xml_element thread_children[] = {
2648 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
2651 const struct gdb_xml_element threads_children[] = {
2652 { "thread", thread_attributes, thread_children,
2653 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL,
2654 start_thread, end_thread },
2655 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
2658 const struct gdb_xml_element threads_elements[] = {
2659 { "threads", NULL, threads_children,
2660 GDB_XML_EF_NONE, NULL, NULL },
2661 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
2664 /* Discard the contents of the constructed thread info context. */
2667 clear_threads_parsing_context (void *p)
2669 struct threads_parsing_context *context = p;
2671 struct thread_item *item;
2673 for (i = 0; VEC_iterate (thread_item_t, context->items, i, item); ++i)
2674 xfree (item->extra);
2676 VEC_free (thread_item_t, context->items);
2682 * Find all threads for info threads command.
2683 * Uses new thread protocol contributed by Cisco.
2684 * Falls back and attempts to use the older method (above)
2685 * if the target doesn't respond to the new method.
2689 remote_threads_info (struct target_ops *ops)
2691 struct remote_state *rs = get_remote_state ();
2695 if (rs->remote_desc == 0) /* paranoia */
2696 error (_("Command can only be used when connected to the remote target."));
2698 #if defined(HAVE_LIBEXPAT)
2699 if (remote_protocol_packets[PACKET_qXfer_threads].support == PACKET_ENABLE)
2701 char *xml = target_read_stralloc (¤t_target,
2702 TARGET_OBJECT_THREADS, NULL);
2704 struct cleanup *back_to = make_cleanup (xfree, xml);
2708 struct threads_parsing_context context;
2710 context.items = NULL;
2711 make_cleanup (clear_threads_parsing_context, &context);
2713 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2714 threads_elements, xml, &context) == 0)
2717 struct thread_item *item;
2720 VEC_iterate (thread_item_t, context.items, i, item);
2723 if (!ptid_equal (item->ptid, null_ptid))
2725 struct private_thread_info *info;
2726 /* In non-stop mode, we assume new found threads
2727 are running until proven otherwise with a
2728 stop reply. In all-stop, we can only get
2729 here if all threads are stopped. */
2730 int running = non_stop ? 1 : 0;
2732 remote_notice_new_inferior (item->ptid, running);
2734 info = demand_private_info (item->ptid);
2735 info->core = item->core;
2736 info->extra = item->extra;
2743 do_cleanups (back_to);
2748 if (rs->use_threadinfo_query)
2750 putpkt ("qfThreadInfo");
2751 getpkt (&rs->buf, &rs->buf_size, 0);
2753 if (bufp[0] != '\0') /* q packet recognized */
2755 struct cleanup *old_chain;
2758 /* remote_notice_new_inferior (in the loop below) may make
2759 new RSP calls, which clobber rs->buf. Work with a
2761 bufp = saved_reply = xstrdup (rs->buf);
2762 old_chain = make_cleanup (free_current_contents, &saved_reply);
2764 while (*bufp++ == 'm') /* reply contains one or more TID */
2768 new_thread = read_ptid (bufp, &bufp);
2769 if (!ptid_equal (new_thread, null_ptid))
2771 /* In non-stop mode, we assume new found threads
2772 are running until proven otherwise with a
2773 stop reply. In all-stop, we can only get
2774 here if all threads are stopped. */
2775 int running = non_stop ? 1 : 0;
2777 remote_notice_new_inferior (new_thread, running);
2780 while (*bufp++ == ','); /* comma-separated list */
2781 free_current_contents (&saved_reply);
2782 putpkt ("qsThreadInfo");
2783 getpkt (&rs->buf, &rs->buf_size, 0);
2784 bufp = saved_reply = xstrdup (rs->buf);
2786 do_cleanups (old_chain);
2791 /* Only qfThreadInfo is supported in non-stop mode. */
2795 /* Else fall back to old method based on jmetzler protocol. */
2796 rs->use_threadinfo_query = 0;
2797 remote_find_new_threads ();
2802 * Collect a descriptive string about the given thread.
2803 * The target may say anything it wants to about the thread
2804 * (typically info about its blocked / runnable state, name, etc.).
2805 * This string will appear in the info threads display.
2807 * Optional: targets are not required to implement this function.
2811 remote_threads_extra_info (struct target_ops *self, struct thread_info *tp)
2813 struct remote_state *rs = get_remote_state ();
2817 struct gdb_ext_thread_info threadinfo;
2818 static char display_buf[100]; /* arbitrary... */
2819 int n = 0; /* position in display_buf */
2821 if (rs->remote_desc == 0) /* paranoia */
2822 internal_error (__FILE__, __LINE__,
2823 _("remote_threads_extra_info"));
2825 if (ptid_equal (tp->ptid, magic_null_ptid)
2826 || (ptid_get_pid (tp->ptid) != 0 && ptid_get_tid (tp->ptid) == 0))
2827 /* This is the main thread which was added by GDB. The remote
2828 server doesn't know about it. */
2831 if (remote_protocol_packets[PACKET_qXfer_threads].support == PACKET_ENABLE)
2833 struct thread_info *info = find_thread_ptid (tp->ptid);
2835 if (info && info->private)
2836 return info->private->extra;
2841 if (rs->use_threadextra_query)
2844 char *endb = rs->buf + get_remote_packet_size ();
2846 xsnprintf (b, endb - b, "qThreadExtraInfo,");
2848 write_ptid (b, endb, tp->ptid);
2851 getpkt (&rs->buf, &rs->buf_size, 0);
2852 if (rs->buf[0] != 0)
2854 n = min (strlen (rs->buf) / 2, sizeof (display_buf));
2855 result = hex2bin (rs->buf, (gdb_byte *) display_buf, n);
2856 display_buf [result] = '\0';
2861 /* If the above query fails, fall back to the old method. */
2862 rs->use_threadextra_query = 0;
2863 set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
2864 | TAG_MOREDISPLAY | TAG_DISPLAY;
2865 int_to_threadref (&id, ptid_get_tid (tp->ptid));
2866 if (remote_get_threadinfo (&id, set, &threadinfo))
2867 if (threadinfo.active)
2869 if (*threadinfo.shortname)
2870 n += xsnprintf (&display_buf[0], sizeof (display_buf) - n,
2871 " Name: %s,", threadinfo.shortname);
2872 if (*threadinfo.display)
2873 n += xsnprintf (&display_buf[n], sizeof (display_buf) - n,
2874 " State: %s,", threadinfo.display);
2875 if (*threadinfo.more_display)
2876 n += xsnprintf (&display_buf[n], sizeof (display_buf) - n,
2877 " Priority: %s", threadinfo.more_display);
2881 /* For purely cosmetic reasons, clear up trailing commas. */
2882 if (',' == display_buf[n-1])
2883 display_buf[n-1] = ' ';
2892 remote_static_tracepoint_marker_at (CORE_ADDR addr,
2893 struct static_tracepoint_marker *marker)
2895 struct remote_state *rs = get_remote_state ();
2898 xsnprintf (p, get_remote_packet_size (), "qTSTMat:");
2900 p += hexnumstr (p, addr);
2902 getpkt (&rs->buf, &rs->buf_size, 0);
2906 error (_("Remote failure reply: %s"), p);
2910 parse_static_tracepoint_marker_definition (p, &p, marker);
2917 static VEC(static_tracepoint_marker_p) *
2918 remote_static_tracepoint_markers_by_strid (const char *strid)
2920 struct remote_state *rs = get_remote_state ();
2921 VEC(static_tracepoint_marker_p) *markers = NULL;
2922 struct static_tracepoint_marker *marker = NULL;
2923 struct cleanup *old_chain;
2926 /* Ask for a first packet of static tracepoint marker
2929 getpkt (&rs->buf, &rs->buf_size, 0);
2932 error (_("Remote failure reply: %s"), p);
2934 old_chain = make_cleanup (free_current_marker, &marker);
2939 marker = XCNEW (struct static_tracepoint_marker);
2943 parse_static_tracepoint_marker_definition (p, &p, marker);
2945 if (strid == NULL || strcmp (strid, marker->str_id) == 0)
2947 VEC_safe_push (static_tracepoint_marker_p,
2953 release_static_tracepoint_marker (marker);
2954 memset (marker, 0, sizeof (*marker));
2957 while (*p++ == ','); /* comma-separated list */
2958 /* Ask for another packet of static tracepoint definition. */
2960 getpkt (&rs->buf, &rs->buf_size, 0);
2964 do_cleanups (old_chain);
2969 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2972 remote_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
2974 return ptid_build (ptid_get_pid (inferior_ptid), 0, lwp);
2978 /* Restart the remote side; this is an extended protocol operation. */
2981 extended_remote_restart (void)
2983 struct remote_state *rs = get_remote_state ();
2985 /* Send the restart command; for reasons I don't understand the
2986 remote side really expects a number after the "R". */
2987 xsnprintf (rs->buf, get_remote_packet_size (), "R%x", 0);
2990 remote_fileio_reset ();
2993 /* Clean up connection to a remote debugger. */
2996 remote_close (struct target_ops *self)
2998 struct remote_state *rs = get_remote_state ();
3000 if (rs->remote_desc == NULL)
3001 return; /* already closed */
3003 /* Make sure we leave stdin registered in the event loop, and we
3004 don't leave the async SIGINT signal handler installed. */
3005 remote_terminal_ours (self);
3007 serial_close (rs->remote_desc);
3008 rs->remote_desc = NULL;
3010 /* We don't have a connection to the remote stub anymore. Get rid
3011 of all the inferiors and their threads we were controlling.
3012 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3013 will be unable to find the thread corresponding to (pid, 0, 0). */
3014 inferior_ptid = null_ptid;
3015 discard_all_inferiors ();
3017 /* We are closing the remote target, so we should discard
3018 everything of this target. */
3019 discard_pending_stop_replies_in_queue (rs);
3021 if (remote_async_inferior_event_token)
3022 delete_async_event_handler (&remote_async_inferior_event_token);
3024 remote_notif_state_xfree (rs->notif_state);
3026 trace_reset_local_state ();
3029 /* Query the remote side for the text, data and bss offsets. */
3034 struct remote_state *rs = get_remote_state ();
3037 int lose, num_segments = 0, do_sections, do_segments;
3038 CORE_ADDR text_addr, data_addr, bss_addr, segments[2];
3039 struct section_offsets *offs;
3040 struct symfile_segment_data *data;
3042 if (symfile_objfile == NULL)
3045 putpkt ("qOffsets");
3046 getpkt (&rs->buf, &rs->buf_size, 0);
3049 if (buf[0] == '\000')
3050 return; /* Return silently. Stub doesn't support
3054 warning (_("Remote failure reply: %s"), buf);
3058 /* Pick up each field in turn. This used to be done with scanf, but
3059 scanf will make trouble if CORE_ADDR size doesn't match
3060 conversion directives correctly. The following code will work
3061 with any size of CORE_ADDR. */
3062 text_addr = data_addr = bss_addr = 0;
3066 if (strncmp (ptr, "Text=", 5) == 0)
3069 /* Don't use strtol, could lose on big values. */
3070 while (*ptr && *ptr != ';')
3071 text_addr = (text_addr << 4) + fromhex (*ptr++);
3073 if (strncmp (ptr, ";Data=", 6) == 0)
3076 while (*ptr && *ptr != ';')
3077 data_addr = (data_addr << 4) + fromhex (*ptr++);
3082 if (!lose && strncmp (ptr, ";Bss=", 5) == 0)
3085 while (*ptr && *ptr != ';')
3086 bss_addr = (bss_addr << 4) + fromhex (*ptr++);
3088 if (bss_addr != data_addr)
3089 warning (_("Target reported unsupported offsets: %s"), buf);
3094 else if (strncmp (ptr, "TextSeg=", 8) == 0)
3097 /* Don't use strtol, could lose on big values. */
3098 while (*ptr && *ptr != ';')
3099 text_addr = (text_addr << 4) + fromhex (*ptr++);
3102 if (strncmp (ptr, ";DataSeg=", 9) == 0)
3105 while (*ptr && *ptr != ';')
3106 data_addr = (data_addr << 4) + fromhex (*ptr++);
3114 error (_("Malformed response to offset query, %s"), buf);
3115 else if (*ptr != '\0')
3116 warning (_("Target reported unsupported offsets: %s"), buf);
3118 offs = ((struct section_offsets *)
3119 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile->num_sections)));
3120 memcpy (offs, symfile_objfile->section_offsets,
3121 SIZEOF_N_SECTION_OFFSETS (symfile_objfile->num_sections));
3123 data = get_symfile_segment_data (symfile_objfile->obfd);
3124 do_segments = (data != NULL);
3125 do_sections = num_segments == 0;
3127 if (num_segments > 0)
3129 segments[0] = text_addr;
3130 segments[1] = data_addr;
3132 /* If we have two segments, we can still try to relocate everything
3133 by assuming that the .text and .data offsets apply to the whole
3134 text and data segments. Convert the offsets given in the packet
3135 to base addresses for symfile_map_offsets_to_segments. */
3136 else if (data && data->num_segments == 2)
3138 segments[0] = data->segment_bases[0] + text_addr;
3139 segments[1] = data->segment_bases[1] + data_addr;
3142 /* If the object file has only one segment, assume that it is text
3143 rather than data; main programs with no writable data are rare,
3144 but programs with no code are useless. Of course the code might
3145 have ended up in the data segment... to detect that we would need
3146 the permissions here. */
3147 else if (data && data->num_segments == 1)
3149 segments[0] = data->segment_bases[0] + text_addr;
3152 /* There's no way to relocate by segment. */
3158 int ret = symfile_map_offsets_to_segments (symfile_objfile->obfd, data,
3159 offs, num_segments, segments);
3161 if (ret == 0 && !do_sections)
3162 error (_("Can not handle qOffsets TextSeg "
3163 "response with this symbol file"));
3170 free_symfile_segment_data (data);
3174 offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_addr;
3176 /* This is a temporary kludge to force data and bss to use the
3177 same offsets because that's what nlmconv does now. The real
3178 solution requires changes to the stub and remote.c that I
3179 don't have time to do right now. */
3181 offs->offsets[SECT_OFF_DATA (symfile_objfile)] = data_addr;
3182 offs->offsets[SECT_OFF_BSS (symfile_objfile)] = data_addr;
3185 objfile_relocate (symfile_objfile, offs);
3188 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3189 threads we know are stopped already. This is used during the
3190 initial remote connection in non-stop mode --- threads that are
3191 reported as already being stopped are left stopped. */
3194 set_stop_requested_callback (struct thread_info *thread, void *data)
3196 /* If we have a stop reply for this thread, it must be stopped. */
3197 if (peek_stop_reply (thread->ptid))
3198 set_stop_requested (thread->ptid, 1);
3203 /* Send interrupt_sequence to remote target. */
3205 send_interrupt_sequence (void)
3207 struct remote_state *rs = get_remote_state ();
3209 if (interrupt_sequence_mode == interrupt_sequence_control_c)
3210 remote_serial_write ("\x03", 1);
3211 else if (interrupt_sequence_mode == interrupt_sequence_break)
3212 serial_send_break (rs->remote_desc);
3213 else if (interrupt_sequence_mode == interrupt_sequence_break_g)
3215 serial_send_break (rs->remote_desc);
3216 remote_serial_write ("g", 1);
3219 internal_error (__FILE__, __LINE__,
3220 _("Invalid value for interrupt_sequence_mode: %s."),
3221 interrupt_sequence_mode);
3225 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3226 and extract the PTID. Returns NULL_PTID if not found. */
3229 stop_reply_extract_thread (char *stop_reply)
3231 if (stop_reply[0] == 'T' && strlen (stop_reply) > 3)
3235 /* Txx r:val ; r:val (...) */
3238 /* Look for "register" named "thread". */
3243 p1 = strchr (p, ':');
3247 if (strncmp (p, "thread", p1 - p) == 0)
3248 return read_ptid (++p1, &p);
3250 p1 = strchr (p, ';');
3262 /* Determine the remote side's current thread. If we have a stop
3263 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3264 "thread" register we can extract the current thread from. If not,
3265 ask the remote which is the current thread with qC. The former
3266 method avoids a roundtrip. */
3269 get_current_thread (char *wait_status)
3273 /* Note we don't use remote_parse_stop_reply as that makes use of
3274 the target architecture, which we haven't yet fully determined at
3276 if (wait_status != NULL)
3277 ptid = stop_reply_extract_thread (wait_status);
3278 if (ptid_equal (ptid, null_ptid))
3279 ptid = remote_current_thread (inferior_ptid);
3284 /* Query the remote target for which is the current thread/process,
3285 add it to our tables, and update INFERIOR_PTID. The caller is
3286 responsible for setting the state such that the remote end is ready
3287 to return the current thread.
3289 This function is called after handling the '?' or 'vRun' packets,
3290 whose response is a stop reply from which we can also try
3291 extracting the thread. If the target doesn't support the explicit
3292 qC query, we infer the current thread from that stop reply, passed
3293 in in WAIT_STATUS, which may be NULL. */
3296 add_current_inferior_and_thread (char *wait_status)
3298 struct remote_state *rs = get_remote_state ();
3300 ptid_t ptid = null_ptid;
3302 inferior_ptid = null_ptid;
3304 /* Now, if we have thread information, update inferior_ptid. */
3305 ptid = get_current_thread (wait_status);
3307 if (!ptid_equal (ptid, null_ptid))
3309 if (!remote_multi_process_p (rs))
3312 inferior_ptid = ptid;
3316 /* Without this, some commands which require an active target
3317 (such as kill) won't work. This variable serves (at least)
3318 double duty as both the pid of the target process (if it has
3319 such), and as a flag indicating that a target is active. */
3320 inferior_ptid = magic_null_ptid;
3324 remote_add_inferior (fake_pid_p, ptid_get_pid (inferior_ptid), -1);
3326 /* Add the main thread. */
3327 add_thread_silent (inferior_ptid);
3331 remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
3333 struct remote_state *rs = get_remote_state ();
3334 struct packet_config *noack_config;
3335 char *wait_status = NULL;
3337 immediate_quit++; /* Allow user to interrupt it. */
3340 if (interrupt_on_connect)
3341 send_interrupt_sequence ();
3343 /* Ack any packet which the remote side has already sent. */
3344 serial_write (rs->remote_desc, "+", 1);
3346 /* Signal other parts that we're going through the initial setup,
3347 and so things may not be stable yet. */
3348 rs->starting_up = 1;
3350 /* The first packet we send to the target is the optional "supported
3351 packets" request. If the target can answer this, it will tell us
3352 which later probes to skip. */
3353 remote_query_supported ();
3355 /* If the stub wants to get a QAllow, compose one and send it. */
3356 if (remote_protocol_packets[PACKET_QAllow].support != PACKET_DISABLE)
3357 remote_set_permissions ();
3359 /* Next, we possibly activate noack mode.
3361 If the QStartNoAckMode packet configuration is set to AUTO,
3362 enable noack mode if the stub reported a wish for it with
3365 If set to TRUE, then enable noack mode even if the stub didn't
3366 report it in qSupported. If the stub doesn't reply OK, the
3367 session ends with an error.
3369 If FALSE, then don't activate noack mode, regardless of what the
3370 stub claimed should be the default with qSupported. */
3372 noack_config = &remote_protocol_packets[PACKET_QStartNoAckMode];
3374 if (noack_config->detect == AUTO_BOOLEAN_TRUE
3375 || (noack_config->detect == AUTO_BOOLEAN_AUTO
3376 && noack_config->support == PACKET_ENABLE))
3378 putpkt ("QStartNoAckMode");
3379 getpkt (&rs->buf, &rs->buf_size, 0);
3380 if (packet_ok (rs->buf, noack_config) == PACKET_OK)
3386 /* Tell the remote that we are using the extended protocol. */
3388 getpkt (&rs->buf, &rs->buf_size, 0);
3391 /* Let the target know which signals it is allowed to pass down to
3393 update_signals_program_target ();
3395 /* Next, if the target can specify a description, read it. We do
3396 this before anything involving memory or registers. */
3397 target_find_description ();
3399 /* Next, now that we know something about the target, update the
3400 address spaces in the program spaces. */
3401 update_address_spaces ();
3403 /* On OSs where the list of libraries is global to all
3404 processes, we fetch them early. */
3405 if (gdbarch_has_global_solist (target_gdbarch ()))
3406 solib_add (NULL, from_tty, target, auto_solib_add);
3410 if (!rs->non_stop_aware)
3411 error (_("Non-stop mode requested, but remote "
3412 "does not support non-stop"));
3414 putpkt ("QNonStop:1");
3415 getpkt (&rs->buf, &rs->buf_size, 0);
3417 if (strcmp (rs->buf, "OK") != 0)
3418 error (_("Remote refused setting non-stop mode with: %s"), rs->buf);
3420 /* Find about threads and processes the stub is already
3421 controlling. We default to adding them in the running state.
3422 The '?' query below will then tell us about which threads are
3424 remote_threads_info (target);
3426 else if (rs->non_stop_aware)
3428 /* Don't assume that the stub can operate in all-stop mode.
3429 Request it explicitly. */
3430 putpkt ("QNonStop:0");
3431 getpkt (&rs->buf, &rs->buf_size, 0);
3433 if (strcmp (rs->buf, "OK") != 0)
3434 error (_("Remote refused setting all-stop mode with: %s"), rs->buf);
3437 /* Upload TSVs regardless of whether the target is running or not. The
3438 remote stub, such as GDBserver, may have some predefined or builtin
3439 TSVs, even if the target is not running. */
3440 if (remote_get_trace_status (current_trace_status ()) != -1)
3442 struct uploaded_tsv *uploaded_tsvs = NULL;
3444 remote_upload_trace_state_variables (&uploaded_tsvs);
3445 merge_uploaded_trace_state_variables (&uploaded_tsvs);
3448 /* Check whether the target is running now. */
3450 getpkt (&rs->buf, &rs->buf_size, 0);
3456 struct inferior *inf;
3458 if (rs->buf[0] == 'W' || rs->buf[0] == 'X')
3461 error (_("The target is not running (try extended-remote?)"));
3463 /* We're connected, but not running. Drop out before we
3464 call start_remote. */
3465 rs->starting_up = 0;
3470 /* Save the reply for later. */
3471 wait_status = alloca (strlen (rs->buf) + 1);
3472 strcpy (wait_status, rs->buf);
3475 /* Fetch thread list. */
3476 target_find_new_threads ();
3478 /* Let the stub know that we want it to return the thread. */
3479 set_continue_thread (minus_one_ptid);
3481 if (thread_count () == 0)
3483 /* Target has no concept of threads at all. GDB treats
3484 non-threaded target as single-threaded; add a main
3486 add_current_inferior_and_thread (wait_status);
3490 /* We have thread information; select the thread the target
3491 says should be current. If we're reconnecting to a
3492 multi-threaded program, this will ideally be the thread
3493 that last reported an event before GDB disconnected. */
3494 inferior_ptid = get_current_thread (wait_status);
3495 if (ptid_equal (inferior_ptid, null_ptid))
3497 /* Odd... The target was able to list threads, but not
3498 tell us which thread was current (no "thread"
3499 register in T stop reply?). Just pick the first
3500 thread in the thread list then. */
3501 inferior_ptid = thread_list->ptid;
3505 /* init_wait_for_inferior should be called before get_offsets in order
3506 to manage `inserted' flag in bp loc in a correct state.
3507 breakpoint_init_inferior, called from init_wait_for_inferior, set
3508 `inserted' flag to 0, while before breakpoint_re_set, called from
3509 start_remote, set `inserted' flag to 1. In the initialization of
3510 inferior, breakpoint_init_inferior should be called first, and then
3511 breakpoint_re_set can be called. If this order is broken, state of
3512 `inserted' flag is wrong, and cause some problems on breakpoint
3514 init_wait_for_inferior ();
3516 get_offsets (); /* Get text, data & bss offsets. */
3518 /* If we could not find a description using qXfer, and we know
3519 how to do it some other way, try again. This is not
3520 supported for non-stop; it could be, but it is tricky if
3521 there are no stopped threads when we connect. */
3522 if (remote_read_description_p (target)
3523 && gdbarch_target_desc (target_gdbarch ()) == NULL)
3525 target_clear_description ();
3526 target_find_description ();
3529 /* Use the previously fetched status. */
3530 gdb_assert (wait_status != NULL);
3531 strcpy (rs->buf, wait_status);
3532 rs->cached_wait_status = 1;
3535 start_remote (from_tty); /* Initialize gdb process mechanisms. */
3539 /* Clear WFI global state. Do this before finding about new
3540 threads and inferiors, and setting the current inferior.
3541 Otherwise we would clear the proceed status of the current
3542 inferior when we want its stop_soon state to be preserved
3543 (see notice_new_inferior). */
3544 init_wait_for_inferior ();
3546 /* In non-stop, we will either get an "OK", meaning that there
3547 are no stopped threads at this time; or, a regular stop
3548 reply. In the latter case, there may be more than one thread
3549 stopped --- we pull them all out using the vStopped
3551 if (strcmp (rs->buf, "OK") != 0)
3553 struct notif_client *notif = ¬if_client_stop;
3555 /* remote_notif_get_pending_replies acks this one, and gets
3557 rs->notif_state->pending_event[notif_client_stop.id]
3558 = remote_notif_parse (notif, rs->buf);
3559 remote_notif_get_pending_events (notif);
3561 /* Make sure that threads that were stopped remain
3563 iterate_over_threads (set_stop_requested_callback, NULL);
3566 if (target_can_async_p ())
3567 target_async (inferior_event_handler, 0);
3569 if (thread_count () == 0)
3572 error (_("The target is not running (try extended-remote?)"));
3574 /* We're connected, but not running. Drop out before we
3575 call start_remote. */
3576 rs->starting_up = 0;
3580 /* Let the stub know that we want it to return the thread. */
3582 /* Force the stub to choose a thread. */
3583 set_general_thread (null_ptid);
3586 inferior_ptid = remote_current_thread (minus_one_ptid);
3587 if (ptid_equal (inferior_ptid, minus_one_ptid))
3588 error (_("remote didn't report the current thread in non-stop mode"));
3590 get_offsets (); /* Get text, data & bss offsets. */
3592 /* In non-stop mode, any cached wait status will be stored in
3593 the stop reply queue. */
3594 gdb_assert (wait_status == NULL);
3596 /* Report all signals during attach/startup. */
3597 remote_pass_signals (target, 0, NULL);
3600 /* If we connected to a live target, do some additional setup. */
3601 if (target_has_execution)
3603 if (symfile_objfile) /* No use without a symbol-file. */
3604 remote_check_symbols ();
3607 /* Possibly the target has been engaged in a trace run started
3608 previously; find out where things are at. */
3609 if (remote_get_trace_status (current_trace_status ()) != -1)
3611 struct uploaded_tp *uploaded_tps = NULL;
3613 if (current_trace_status ()->running)
3614 printf_filtered (_("Trace is already running on the target.\n"));
3616 remote_upload_tracepoints (&uploaded_tps);
3618 merge_uploaded_tracepoints (&uploaded_tps);
3621 /* The thread and inferior lists are now synchronized with the
3622 target, our symbols have been relocated, and we're merged the
3623 target's tracepoints with ours. We're done with basic start
3625 rs->starting_up = 0;
3627 /* If breakpoints are global, insert them now. */
3628 if (gdbarch_has_global_breakpoints (target_gdbarch ())
3629 && breakpoints_always_inserted_mode ())
3630 insert_breakpoints ();
3633 /* Open a connection to a remote debugger.
3634 NAME is the filename used for communication. */
3637 remote_open (char *name, int from_tty)
3639 remote_open_1 (name, from_tty, &remote_ops, 0);
3642 /* Open a connection to a remote debugger using the extended
3643 remote gdb protocol. NAME is the filename used for communication. */
3646 extended_remote_open (char *name, int from_tty)
3648 remote_open_1 (name, from_tty, &extended_remote_ops, 1 /*extended_p */);
3651 /* Generic code for opening a connection to a remote target. */
3654 init_all_packet_configs (void)
3658 for (i = 0; i < PACKET_MAX; i++)
3659 update_packet_config (&remote_protocol_packets[i]);
3662 /* Symbol look-up. */
3665 remote_check_symbols (void)
3667 struct remote_state *rs = get_remote_state ();
3668 char *msg, *reply, *tmp;
3669 struct minimal_symbol *sym;
3672 /* The remote side has no concept of inferiors that aren't running
3673 yet, it only knows about running processes. If we're connected
3674 but our current inferior is not running, we should not invite the
3675 remote target to request symbol lookups related to its
3676 (unrelated) current process. */
3677 if (!target_has_execution)
3680 if (remote_protocol_packets[PACKET_qSymbol].support == PACKET_DISABLE)
3683 /* Make sure the remote is pointing at the right process. Note
3684 there's no way to select "no process". */
3685 set_general_process ();
3687 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3688 because we need both at the same time. */
3689 msg = alloca (get_remote_packet_size ());
3691 /* Invite target to request symbol lookups. */
3693 putpkt ("qSymbol::");
3694 getpkt (&rs->buf, &rs->buf_size, 0);
3695 packet_ok (rs->buf, &remote_protocol_packets[PACKET_qSymbol]);
3698 while (strncmp (reply, "qSymbol:", 8) == 0)
3701 end = hex2bin (tmp, (gdb_byte *) msg, strlen (tmp) / 2);
3703 sym = lookup_minimal_symbol (msg, NULL, NULL);
3705 xsnprintf (msg, get_remote_packet_size (), "qSymbol::%s", &reply[8]);
3708 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
3709 CORE_ADDR sym_addr = SYMBOL_VALUE_ADDRESS (sym);
3711 /* If this is a function address, return the start of code
3712 instead of any data function descriptor. */
3713 sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3717 xsnprintf (msg, get_remote_packet_size (), "qSymbol:%s:%s",
3718 phex_nz (sym_addr, addr_size), &reply[8]);
3722 getpkt (&rs->buf, &rs->buf_size, 0);
3727 static struct serial *
3728 remote_serial_open (char *name)
3730 static int udp_warning = 0;
3732 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3733 of in ser-tcp.c, because it is the remote protocol assuming that the
3734 serial connection is reliable and not the serial connection promising
3736 if (!udp_warning && strncmp (name, "udp:", 4) == 0)
3738 warning (_("The remote protocol may be unreliable over UDP.\n"
3739 "Some events may be lost, rendering further debugging "
3744 return serial_open (name);
3747 /* Inform the target of our permission settings. The permission flags
3748 work without this, but if the target knows the settings, it can do
3749 a couple things. First, it can add its own check, to catch cases
3750 that somehow manage to get by the permissions checks in target
3751 methods. Second, if the target is wired to disallow particular
3752 settings (for instance, a system in the field that is not set up to
3753 be able to stop at a breakpoint), it can object to any unavailable
3757 remote_set_permissions (void)
3759 struct remote_state *rs = get_remote_state ();
3761 xsnprintf (rs->buf, get_remote_packet_size (), "QAllow:"
3762 "WriteReg:%x;WriteMem:%x;"
3763 "InsertBreak:%x;InsertTrace:%x;"
3764 "InsertFastTrace:%x;Stop:%x",
3765 may_write_registers, may_write_memory,
3766 may_insert_breakpoints, may_insert_tracepoints,
3767 may_insert_fast_tracepoints, may_stop);
3769 getpkt (&rs->buf, &rs->buf_size, 0);
3771 /* If the target didn't like the packet, warn the user. Do not try
3772 to undo the user's settings, that would just be maddening. */
3773 if (strcmp (rs->buf, "OK") != 0)
3774 warning (_("Remote refused setting permissions with: %s"), rs->buf);
3777 /* This type describes each known response to the qSupported
3779 struct protocol_feature
3781 /* The name of this protocol feature. */
3784 /* The default for this protocol feature. */
3785 enum packet_support default_support;
3787 /* The function to call when this feature is reported, or after
3788 qSupported processing if the feature is not supported.
3789 The first argument points to this structure. The second
3790 argument indicates whether the packet requested support be
3791 enabled, disabled, or probed (or the default, if this function
3792 is being called at the end of processing and this feature was
3793 not reported). The third argument may be NULL; if not NULL, it
3794 is a NUL-terminated string taken from the packet following
3795 this feature's name and an equals sign. */
3796 void (*func) (const struct protocol_feature *, enum packet_support,
3799 /* The corresponding packet for this feature. Only used if
3800 FUNC is remote_supported_packet. */
3805 remote_supported_packet (const struct protocol_feature *feature,
3806 enum packet_support support,
3807 const char *argument)
3811 warning (_("Remote qSupported response supplied an unexpected value for"
3812 " \"%s\"."), feature->name);
3816 if (remote_protocol_packets[feature->packet].support
3817 == PACKET_SUPPORT_UNKNOWN)
3818 remote_protocol_packets[feature->packet].support = support;
3822 remote_packet_size (const struct protocol_feature *feature,
3823 enum packet_support support, const char *value)
3825 struct remote_state *rs = get_remote_state ();
3830 if (support != PACKET_ENABLE)
3833 if (value == NULL || *value == '\0')
3835 warning (_("Remote target reported \"%s\" without a size."),
3841 packet_size = strtol (value, &value_end, 16);
3842 if (errno != 0 || *value_end != '\0' || packet_size < 0)
3844 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3845 feature->name, value);
3849 if (packet_size > MAX_REMOTE_PACKET_SIZE)
3851 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3852 packet_size, MAX_REMOTE_PACKET_SIZE);
3853 packet_size = MAX_REMOTE_PACKET_SIZE;
3856 /* Record the new maximum packet size. */
3857 rs->explicit_packet_size = packet_size;
3861 remote_multi_process_feature (const struct protocol_feature *feature,
3862 enum packet_support support, const char *value)
3864 struct remote_state *rs = get_remote_state ();
3866 rs->multi_process_aware = (support == PACKET_ENABLE);
3870 remote_non_stop_feature (const struct protocol_feature *feature,
3871 enum packet_support support, const char *value)
3873 struct remote_state *rs = get_remote_state ();
3875 rs->non_stop_aware = (support == PACKET_ENABLE);
3879 remote_cond_tracepoint_feature (const struct protocol_feature *feature,
3880 enum packet_support support,
3883 struct remote_state *rs = get_remote_state ();
3885 rs->cond_tracepoints = (support == PACKET_ENABLE);
3889 remote_cond_breakpoint_feature (const struct protocol_feature *feature,
3890 enum packet_support support,
3893 struct remote_state *rs = get_remote_state ();
3895 rs->cond_breakpoints = (support == PACKET_ENABLE);
3899 remote_breakpoint_commands_feature (const struct protocol_feature *feature,
3900 enum packet_support support,
3903 struct remote_state *rs = get_remote_state ();
3905 rs->breakpoint_commands = (support == PACKET_ENABLE);
3909 remote_fast_tracepoint_feature (const struct protocol_feature *feature,
3910 enum packet_support support,
3913 struct remote_state *rs = get_remote_state ();
3915 rs->fast_tracepoints = (support == PACKET_ENABLE);
3919 remote_static_tracepoint_feature (const struct protocol_feature *feature,
3920 enum packet_support support,
3923 struct remote_state *rs = get_remote_state ();
3925 rs->static_tracepoints = (support == PACKET_ENABLE);
3929 remote_install_in_trace_feature (const struct protocol_feature *feature,
3930 enum packet_support support,
3933 struct remote_state *rs = get_remote_state ();
3935 rs->install_in_trace = (support == PACKET_ENABLE);
3939 remote_disconnected_tracing_feature (const struct protocol_feature *feature,
3940 enum packet_support support,
3943 struct remote_state *rs = get_remote_state ();
3945 rs->disconnected_tracing = (support == PACKET_ENABLE);
3949 remote_enable_disable_tracepoint_feature (const struct protocol_feature *feature,
3950 enum packet_support support,
3953 struct remote_state *rs = get_remote_state ();
3955 rs->enable_disable_tracepoints = (support == PACKET_ENABLE);
3959 remote_string_tracing_feature (const struct protocol_feature *feature,
3960 enum packet_support support,
3963 struct remote_state *rs = get_remote_state ();
3965 rs->string_tracing = (support == PACKET_ENABLE);
3969 remote_augmented_libraries_svr4_read_feature
3970 (const struct protocol_feature *feature,
3971 enum packet_support support, const char *value)
3973 struct remote_state *rs = get_remote_state ();
3975 rs->augmented_libraries_svr4_read = (support == PACKET_ENABLE);
3978 static const struct protocol_feature remote_protocol_features[] = {
3979 { "PacketSize", PACKET_DISABLE, remote_packet_size, -1 },
3980 { "qXfer:auxv:read", PACKET_DISABLE, remote_supported_packet,
3981 PACKET_qXfer_auxv },
3982 { "qXfer:features:read", PACKET_DISABLE, remote_supported_packet,
3983 PACKET_qXfer_features },
3984 { "qXfer:libraries:read", PACKET_DISABLE, remote_supported_packet,
3985 PACKET_qXfer_libraries },
3986 { "qXfer:libraries-svr4:read", PACKET_DISABLE, remote_supported_packet,
3987 PACKET_qXfer_libraries_svr4 },
3988 { "augmented-libraries-svr4-read", PACKET_DISABLE,
3989 remote_augmented_libraries_svr4_read_feature, -1 },
3990 { "qXfer:memory-map:read", PACKET_DISABLE, remote_supported_packet,
3991 PACKET_qXfer_memory_map },
3992 { "qXfer:spu:read", PACKET_DISABLE, remote_supported_packet,
3993 PACKET_qXfer_spu_read },
3994 { "qXfer:spu:write", PACKET_DISABLE, remote_supported_packet,
3995 PACKET_qXfer_spu_write },
3996 { "qXfer:osdata:read", PACKET_DISABLE, remote_supported_packet,
3997 PACKET_qXfer_osdata },
3998 { "qXfer:threads:read", PACKET_DISABLE, remote_supported_packet,
3999 PACKET_qXfer_threads },
4000 { "qXfer:traceframe-info:read", PACKET_DISABLE, remote_supported_packet,
4001 PACKET_qXfer_traceframe_info },
4002 { "QPassSignals", PACKET_DISABLE, remote_supported_packet,
4003 PACKET_QPassSignals },
4004 { "QProgramSignals", PACKET_DISABLE, remote_supported_packet,
4005 PACKET_QProgramSignals },
4006 { "QStartNoAckMode", PACKET_DISABLE, remote_supported_packet,
4007 PACKET_QStartNoAckMode },
4008 { "multiprocess", PACKET_DISABLE, remote_multi_process_feature, -1 },
4009 { "QNonStop", PACKET_DISABLE, remote_non_stop_feature, -1 },
4010 { "qXfer:siginfo:read", PACKET_DISABLE, remote_supported_packet,
4011 PACKET_qXfer_siginfo_read },
4012 { "qXfer:siginfo:write", PACKET_DISABLE, remote_supported_packet,
4013 PACKET_qXfer_siginfo_write },
4014 { "ConditionalTracepoints", PACKET_DISABLE, remote_cond_tracepoint_feature,
4015 PACKET_ConditionalTracepoints },
4016 { "ConditionalBreakpoints", PACKET_DISABLE, remote_cond_breakpoint_feature,
4017 PACKET_ConditionalBreakpoints },
4018 { "BreakpointCommands", PACKET_DISABLE, remote_breakpoint_commands_feature,
4019 PACKET_BreakpointCommands },
4020 { "FastTracepoints", PACKET_DISABLE, remote_fast_tracepoint_feature,
4021 PACKET_FastTracepoints },
4022 { "StaticTracepoints", PACKET_DISABLE, remote_static_tracepoint_feature,
4023 PACKET_StaticTracepoints },
4024 {"InstallInTrace", PACKET_DISABLE, remote_install_in_trace_feature,
4025 PACKET_InstallInTrace},
4026 { "DisconnectedTracing", PACKET_DISABLE, remote_disconnected_tracing_feature,
4028 { "ReverseContinue", PACKET_DISABLE, remote_supported_packet,
4030 { "ReverseStep", PACKET_DISABLE, remote_supported_packet,
4032 { "TracepointSource", PACKET_DISABLE, remote_supported_packet,
4033 PACKET_TracepointSource },
4034 { "QAllow", PACKET_DISABLE, remote_supported_packet,
4036 { "EnableDisableTracepoints", PACKET_DISABLE,
4037 remote_enable_disable_tracepoint_feature, -1 },
4038 { "qXfer:fdpic:read", PACKET_DISABLE, remote_supported_packet,
4039 PACKET_qXfer_fdpic },
4040 { "qXfer:uib:read", PACKET_DISABLE, remote_supported_packet,
4042 { "QDisableRandomization", PACKET_DISABLE, remote_supported_packet,
4043 PACKET_QDisableRandomization },
4044 { "QAgent", PACKET_DISABLE, remote_supported_packet, PACKET_QAgent},
4045 { "QTBuffer:size", PACKET_DISABLE,
4046 remote_supported_packet, PACKET_QTBuffer_size},
4047 { "tracenz", PACKET_DISABLE,
4048 remote_string_tracing_feature, -1 },
4049 { "Qbtrace:off", PACKET_DISABLE, remote_supported_packet, PACKET_Qbtrace_off },
4050 { "Qbtrace:bts", PACKET_DISABLE, remote_supported_packet, PACKET_Qbtrace_bts },
4051 { "qXfer:btrace:read", PACKET_DISABLE, remote_supported_packet,
4052 PACKET_qXfer_btrace }
4055 static char *remote_support_xml;
4057 /* Register string appended to "xmlRegisters=" in qSupported query. */
4060 register_remote_support_xml (const char *xml)
4062 #if defined(HAVE_LIBEXPAT)
4063 if (remote_support_xml == NULL)
4064 remote_support_xml = concat ("xmlRegisters=", xml, (char *) NULL);
4067 char *copy = xstrdup (remote_support_xml + 13);
4068 char *p = strtok (copy, ",");
4072 if (strcmp (p, xml) == 0)
4079 while ((p = strtok (NULL, ",")) != NULL);
4082 remote_support_xml = reconcat (remote_support_xml,
4083 remote_support_xml, ",", xml,
4090 remote_query_supported_append (char *msg, const char *append)
4093 return reconcat (msg, msg, ";", append, (char *) NULL);
4095 return xstrdup (append);
4099 remote_query_supported (void)
4101 struct remote_state *rs = get_remote_state ();
4104 unsigned char seen [ARRAY_SIZE (remote_protocol_features)];
4106 /* The packet support flags are handled differently for this packet
4107 than for most others. We treat an error, a disabled packet, and
4108 an empty response identically: any features which must be reported
4109 to be used will be automatically disabled. An empty buffer
4110 accomplishes this, since that is also the representation for a list
4111 containing no features. */
4114 if (remote_protocol_packets[PACKET_qSupported].support != PACKET_DISABLE)
4117 struct cleanup *old_chain = make_cleanup (free_current_contents, &q);
4119 q = remote_query_supported_append (q, "multiprocess+");
4121 if (remote_support_xml)
4122 q = remote_query_supported_append (q, remote_support_xml);
4124 q = remote_query_supported_append (q, "qRelocInsn+");
4126 q = reconcat (q, "qSupported:", q, (char *) NULL);
4129 do_cleanups (old_chain);
4131 getpkt (&rs->buf, &rs->buf_size, 0);
4133 /* If an error occured, warn, but do not return - just reset the
4134 buffer to empty and go on to disable features. */
4135 if (packet_ok (rs->buf, &remote_protocol_packets[PACKET_qSupported])
4138 warning (_("Remote failure reply: %s"), rs->buf);
4143 memset (seen, 0, sizeof (seen));
4148 enum packet_support is_supported;
4149 char *p, *end, *name_end, *value;
4151 /* First separate out this item from the rest of the packet. If
4152 there's another item after this, we overwrite the separator
4153 (terminated strings are much easier to work with). */
4155 end = strchr (p, ';');
4158 end = p + strlen (p);
4168 warning (_("empty item in \"qSupported\" response"));
4173 name_end = strchr (p, '=');
4176 /* This is a name=value entry. */
4177 is_supported = PACKET_ENABLE;
4178 value = name_end + 1;
4187 is_supported = PACKET_ENABLE;
4191 is_supported = PACKET_DISABLE;
4195 is_supported = PACKET_SUPPORT_UNKNOWN;
4199 warning (_("unrecognized item \"%s\" "
4200 "in \"qSupported\" response"), p);
4206 for (i = 0; i < ARRAY_SIZE (remote_protocol_features); i++)
4207 if (strcmp (remote_protocol_features[i].name, p) == 0)
4209 const struct protocol_feature *feature;
4212 feature = &remote_protocol_features[i];
4213 feature->func (feature, is_supported, value);
4218 /* If we increased the packet size, make sure to increase the global
4219 buffer size also. We delay this until after parsing the entire
4220 qSupported packet, because this is the same buffer we were
4222 if (rs->buf_size < rs->explicit_packet_size)
4224 rs->buf_size = rs->explicit_packet_size;
4225 rs->buf = xrealloc (rs->buf, rs->buf_size);
4228 /* Handle the defaults for unmentioned features. */
4229 for (i = 0; i < ARRAY_SIZE (remote_protocol_features); i++)
4232 const struct protocol_feature *feature;
4234 feature = &remote_protocol_features[i];
4235 feature->func (feature, feature->default_support, NULL);
4239 /* Remove any of the remote.c targets from target stack. Upper targets depend
4240 on it so remove them first. */
4243 remote_unpush_target (void)
4245 pop_all_targets_above (process_stratum - 1);
4249 remote_open_1 (char *name, int from_tty,
4250 struct target_ops *target, int extended_p)
4252 struct remote_state *rs = get_remote_state ();
4255 error (_("To open a remote debug connection, you need to specify what\n"
4256 "serial device is attached to the remote system\n"
4257 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4259 /* See FIXME above. */
4260 if (!target_async_permitted)
4261 wait_forever_enabled_p = 1;
4263 /* If we're connected to a running target, target_preopen will kill it.
4264 Ask this question first, before target_preopen has a chance to kill
4266 if (rs->remote_desc != NULL && !have_inferiors ())
4269 && !query (_("Already connected to a remote target. Disconnect? ")))
4270 error (_("Still connected."));
4273 /* Here the possibly existing remote target gets unpushed. */
4274 target_preopen (from_tty);
4276 /* Make sure we send the passed signals list the next time we resume. */
4277 xfree (rs->last_pass_packet);
4278 rs->last_pass_packet = NULL;
4280 /* Make sure we send the program signals list the next time we
4282 xfree (rs->last_program_signals_packet);
4283 rs->last_program_signals_packet = NULL;
4285 remote_fileio_reset ();
4286 reopen_exec_file ();
4289 rs->remote_desc = remote_serial_open (name);
4290 if (!rs->remote_desc)
4291 perror_with_name (name);
4293 if (baud_rate != -1)
4295 if (serial_setbaudrate (rs->remote_desc, baud_rate))
4297 /* The requested speed could not be set. Error out to
4298 top level after closing remote_desc. Take care to
4299 set remote_desc to NULL to avoid closing remote_desc
4301 serial_close (rs->remote_desc);
4302 rs->remote_desc = NULL;
4303 perror_with_name (name);
4307 serial_raw (rs->remote_desc);
4309 /* If there is something sitting in the buffer we might take it as a
4310 response to a command, which would be bad. */
4311 serial_flush_input (rs->remote_desc);
4315 puts_filtered ("Remote debugging using ");
4316 puts_filtered (name);
4317 puts_filtered ("\n");
4319 push_target (target); /* Switch to using remote target now. */
4321 /* Register extra event sources in the event loop. */
4322 remote_async_inferior_event_token
4323 = create_async_event_handler (remote_async_inferior_event_handler,
4325 rs->notif_state = remote_notif_state_allocate ();
4327 /* Reset the target state; these things will be queried either by
4328 remote_query_supported or as they are needed. */
4329 init_all_packet_configs ();
4330 rs->cached_wait_status = 0;
4331 rs->explicit_packet_size = 0;
4333 rs->multi_process_aware = 0;
4334 rs->extended = extended_p;
4335 rs->non_stop_aware = 0;
4336 rs->waiting_for_stop_reply = 0;
4337 rs->ctrlc_pending_p = 0;
4339 rs->general_thread = not_sent_ptid;
4340 rs->continue_thread = not_sent_ptid;
4341 rs->remote_traceframe_number = -1;
4343 /* Probe for ability to use "ThreadInfo" query, as required. */
4344 rs->use_threadinfo_query = 1;
4345 rs->use_threadextra_query = 1;
4347 if (target_async_permitted)
4349 /* With this target we start out by owning the terminal. */
4350 remote_async_terminal_ours_p = 1;
4352 /* FIXME: cagney/1999-09-23: During the initial connection it is
4353 assumed that the target is already ready and able to respond to
4354 requests. Unfortunately remote_start_remote() eventually calls
4355 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4356 around this. Eventually a mechanism that allows
4357 wait_for_inferior() to expect/get timeouts will be
4359 wait_forever_enabled_p = 0;
4362 /* First delete any symbols previously loaded from shared libraries. */
4363 no_shared_libraries (NULL, 0);
4366 init_thread_list ();
4368 /* Start the remote connection. If error() or QUIT, discard this
4369 target (we'd otherwise be in an inconsistent state) and then
4370 propogate the error on up the exception chain. This ensures that
4371 the caller doesn't stumble along blindly assuming that the
4372 function succeeded. The CLI doesn't have this problem but other
4373 UI's, such as MI do.
4375 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4376 this function should return an error indication letting the
4377 caller restore the previous state. Unfortunately the command
4378 ``target remote'' is directly wired to this function making that
4379 impossible. On a positive note, the CLI side of this problem has
4380 been fixed - the function set_cmd_context() makes it possible for
4381 all the ``target ....'' commands to share a common callback
4382 function. See cli-dump.c. */
4384 volatile struct gdb_exception ex;
4386 TRY_CATCH (ex, RETURN_MASK_ALL)
4388 remote_start_remote (from_tty, target, extended_p);
4392 /* Pop the partially set up target - unless something else did
4393 already before throwing the exception. */
4394 if (rs->remote_desc != NULL)
4395 remote_unpush_target ();
4396 if (target_async_permitted)
4397 wait_forever_enabled_p = 1;
4398 throw_exception (ex);
4402 if (target_async_permitted)
4403 wait_forever_enabled_p = 1;
4406 /* This takes a program previously attached to and detaches it. After
4407 this is done, GDB can be used to debug some other program. We
4408 better not have left any breakpoints in the target program or it'll
4409 die when it hits one. */
4412 remote_detach_1 (const char *args, int from_tty, int extended)
4414 int pid = ptid_get_pid (inferior_ptid);
4415 struct remote_state *rs = get_remote_state ();
4418 error (_("Argument given to \"detach\" when remotely debugging."));
4420 if (!target_has_execution)
4421 error (_("No process to detach from."));
4425 char *exec_file = get_exec_file (0);
4426 if (exec_file == NULL)
4428 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file,
4429 target_pid_to_str (pid_to_ptid (pid)));
4430 gdb_flush (gdb_stdout);
4433 /* Tell the remote target to detach. */
4434 if (remote_multi_process_p (rs))
4435 xsnprintf (rs->buf, get_remote_packet_size (), "D;%x", pid);
4437 strcpy (rs->buf, "D");
4440 getpkt (&rs->buf, &rs->buf_size, 0);
4442 if (rs->buf[0] == 'O' && rs->buf[1] == 'K')
4444 else if (rs->buf[0] == '\0')
4445 error (_("Remote doesn't know how to detach"));
4447 error (_("Can't detach process."));
4449 if (from_tty && !extended)
4450 puts_filtered (_("Ending remote debugging.\n"));
4452 target_mourn_inferior ();
4456 remote_detach (struct target_ops *ops, const char *args, int from_tty)
4458 remote_detach_1 (args, from_tty, 0);
4462 extended_remote_detach (struct target_ops *ops, const char *args, int from_tty)
4464 remote_detach_1 (args, from_tty, 1);
4467 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4470 remote_disconnect (struct target_ops *target, char *args, int from_tty)
4473 error (_("Argument given to \"disconnect\" when remotely debugging."));
4475 /* Make sure we unpush even the extended remote targets; mourn
4476 won't do it. So call remote_mourn_1 directly instead of
4477 target_mourn_inferior. */
4478 remote_mourn_1 (target);
4481 puts_filtered ("Ending remote debugging.\n");
4484 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4485 be chatty about it. */
4488 extended_remote_attach_1 (struct target_ops *target, char *args, int from_tty)
4490 struct remote_state *rs = get_remote_state ();
4492 char *wait_status = NULL;
4494 pid = parse_pid_to_attach (args);
4496 /* Remote PID can be freely equal to getpid, do not check it here the same
4497 way as in other targets. */
4499 if (remote_protocol_packets[PACKET_vAttach].support == PACKET_DISABLE)
4500 error (_("This target does not support attaching to a process"));
4504 char *exec_file = get_exec_file (0);
4507 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
4508 target_pid_to_str (pid_to_ptid (pid)));
4510 printf_unfiltered (_("Attaching to %s\n"),
4511 target_pid_to_str (pid_to_ptid (pid)));
4513 gdb_flush (gdb_stdout);
4516 xsnprintf (rs->buf, get_remote_packet_size (), "vAttach;%x", pid);
4518 getpkt (&rs->buf, &rs->buf_size, 0);
4520 if (packet_ok (rs->buf,
4521 &remote_protocol_packets[PACKET_vAttach]) == PACKET_OK)
4525 /* Save the reply for later. */
4526 wait_status = alloca (strlen (rs->buf) + 1);
4527 strcpy (wait_status, rs->buf);
4529 else if (strcmp (rs->buf, "OK") != 0)
4530 error (_("Attaching to %s failed with: %s"),
4531 target_pid_to_str (pid_to_ptid (pid)),
4534 else if (remote_protocol_packets[PACKET_vAttach].support == PACKET_DISABLE)
4535 error (_("This target does not support attaching to a process"));
4537 error (_("Attaching to %s failed"),
4538 target_pid_to_str (pid_to_ptid (pid)));
4540 set_current_inferior (remote_add_inferior (0, pid, 1));
4542 inferior_ptid = pid_to_ptid (pid);
4546 struct thread_info *thread;
4548 /* Get list of threads. */
4549 remote_threads_info (target);
4551 thread = first_thread_of_process (pid);
4553 inferior_ptid = thread->ptid;
4555 inferior_ptid = pid_to_ptid (pid);
4557 /* Invalidate our notion of the remote current thread. */
4558 record_currthread (rs, minus_one_ptid);
4562 /* Now, if we have thread information, update inferior_ptid. */
4563 inferior_ptid = remote_current_thread (inferior_ptid);
4565 /* Add the main thread to the thread list. */
4566 add_thread_silent (inferior_ptid);
4569 /* Next, if the target can specify a description, read it. We do
4570 this before anything involving memory or registers. */
4571 target_find_description ();
4575 /* Use the previously fetched status. */
4576 gdb_assert (wait_status != NULL);
4578 if (target_can_async_p ())
4580 struct notif_event *reply
4581 = remote_notif_parse (¬if_client_stop, wait_status);
4583 push_stop_reply ((struct stop_reply *) reply);
4585 target_async (inferior_event_handler, 0);
4589 gdb_assert (wait_status != NULL);
4590 strcpy (rs->buf, wait_status);
4591 rs->cached_wait_status = 1;
4595 gdb_assert (wait_status == NULL);
4599 extended_remote_attach (struct target_ops *ops, char *args, int from_tty)
4601 extended_remote_attach_1 (ops, args, from_tty);
4605 /* Check for the availability of vCont. This function should also check
4609 remote_vcont_probe (struct remote_state *rs)
4613 strcpy (rs->buf, "vCont?");
4615 getpkt (&rs->buf, &rs->buf_size, 0);
4618 /* Make sure that the features we assume are supported. */
4619 if (strncmp (buf, "vCont", 5) == 0)
4622 int support_s, support_S, support_c, support_C;
4628 rs->supports_vCont.t = 0;
4629 rs->supports_vCont.r = 0;
4630 while (p && *p == ';')
4633 if (*p == 's' && (*(p + 1) == ';' || *(p + 1) == 0))
4635 else if (*p == 'S' && (*(p + 1) == ';' || *(p + 1) == 0))
4637 else if (*p == 'c' && (*(p + 1) == ';' || *(p + 1) == 0))
4639 else if (*p == 'C' && (*(p + 1) == ';' || *(p + 1) == 0))
4641 else if (*p == 't' && (*(p + 1) == ';' || *(p + 1) == 0))
4642 rs->supports_vCont.t = 1;
4643 else if (*p == 'r' && (*(p + 1) == ';' || *(p + 1) == 0))
4644 rs->supports_vCont.r = 1;
4646 p = strchr (p, ';');
4649 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4650 BUF will make packet_ok disable the packet. */
4651 if (!support_s || !support_S || !support_c || !support_C)
4655 packet_ok (buf, &remote_protocol_packets[PACKET_vCont]);
4658 /* Helper function for building "vCont" resumptions. Write a
4659 resumption to P. ENDP points to one-passed-the-end of the buffer
4660 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4661 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4662 resumed thread should be single-stepped and/or signalled. If PTID
4663 equals minus_one_ptid, then all threads are resumed; if PTID
4664 represents a process, then all threads of the process are resumed;
4665 the thread to be stepped and/or signalled is given in the global
4669 append_resumption (char *p, char *endp,
4670 ptid_t ptid, int step, enum gdb_signal siggnal)
4672 struct remote_state *rs = get_remote_state ();
4674 if (step && siggnal != GDB_SIGNAL_0)
4675 p += xsnprintf (p, endp - p, ";S%02x", siggnal);
4677 /* GDB is willing to range step. */
4678 && use_range_stepping
4679 /* Target supports range stepping. */
4680 && rs->supports_vCont.r
4681 /* We don't currently support range stepping multiple
4682 threads with a wildcard (though the protocol allows it,
4683 so stubs shouldn't make an active effort to forbid
4685 && !(remote_multi_process_p (rs) && ptid_is_pid (ptid)))
4687 struct thread_info *tp;
4689 if (ptid_equal (ptid, minus_one_ptid))
4691 /* If we don't know about the target thread's tid, then
4692 we're resuming magic_null_ptid (see caller). */
4693 tp = find_thread_ptid (magic_null_ptid);
4696 tp = find_thread_ptid (ptid);
4697 gdb_assert (tp != NULL);
4699 if (tp->control.may_range_step)
4701 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
4703 p += xsnprintf (p, endp - p, ";r%s,%s",
4704 phex_nz (tp->control.step_range_start,
4706 phex_nz (tp->control.step_range_end,
4710 p += xsnprintf (p, endp - p, ";s");
4713 p += xsnprintf (p, endp - p, ";s");
4714 else if (siggnal != GDB_SIGNAL_0)
4715 p += xsnprintf (p, endp - p, ";C%02x", siggnal);
4717 p += xsnprintf (p, endp - p, ";c");
4719 if (remote_multi_process_p (rs) && ptid_is_pid (ptid))
4723 /* All (-1) threads of process. */
4724 nptid = ptid_build (ptid_get_pid (ptid), 0, -1);
4726 p += xsnprintf (p, endp - p, ":");
4727 p = write_ptid (p, endp, nptid);
4729 else if (!ptid_equal (ptid, minus_one_ptid))
4731 p += xsnprintf (p, endp - p, ":");
4732 p = write_ptid (p, endp, ptid);
4738 /* Append a vCont continue-with-signal action for threads that have a
4739 non-zero stop signal. */
4742 append_pending_thread_resumptions (char *p, char *endp, ptid_t ptid)
4744 struct thread_info *thread;
4746 ALL_THREADS (thread)
4747 if (ptid_match (thread->ptid, ptid)
4748 && !ptid_equal (inferior_ptid, thread->ptid)
4749 && thread->suspend.stop_signal != GDB_SIGNAL_0
4750 && signal_pass_state (thread->suspend.stop_signal))
4752 p = append_resumption (p, endp, thread->ptid,
4753 0, thread->suspend.stop_signal);
4754 thread->suspend.stop_signal = GDB_SIGNAL_0;
4760 /* Resume the remote inferior by using a "vCont" packet. The thread
4761 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4762 resumed thread should be single-stepped and/or signalled. If PTID
4763 equals minus_one_ptid, then all threads are resumed; the thread to
4764 be stepped and/or signalled is given in the global INFERIOR_PTID.
4765 This function returns non-zero iff it resumes the inferior.
4767 This function issues a strict subset of all possible vCont commands at the
4771 remote_vcont_resume (ptid_t ptid, int step, enum gdb_signal siggnal)
4773 struct remote_state *rs = get_remote_state ();
4777 if (remote_protocol_packets[PACKET_vCont].support == PACKET_SUPPORT_UNKNOWN)
4778 remote_vcont_probe (rs);
4780 if (remote_protocol_packets[PACKET_vCont].support == PACKET_DISABLE)
4784 endp = rs->buf + get_remote_packet_size ();
4786 /* If we could generate a wider range of packets, we'd have to worry
4787 about overflowing BUF. Should there be a generic
4788 "multi-part-packet" packet? */
4790 p += xsnprintf (p, endp - p, "vCont");
4792 if (ptid_equal (ptid, magic_null_ptid))
4794 /* MAGIC_NULL_PTID means that we don't have any active threads,
4795 so we don't have any TID numbers the inferior will
4796 understand. Make sure to only send forms that do not specify
4798 append_resumption (p, endp, minus_one_ptid, step, siggnal);
4800 else if (ptid_equal (ptid, minus_one_ptid) || ptid_is_pid (ptid))
4802 /* Resume all threads (of all processes, or of a single
4803 process), with preference for INFERIOR_PTID. This assumes
4804 inferior_ptid belongs to the set of all threads we are about
4806 if (step || siggnal != GDB_SIGNAL_0)
4808 /* Step inferior_ptid, with or without signal. */
4809 p = append_resumption (p, endp, inferior_ptid, step, siggnal);
4812 /* Also pass down any pending signaled resumption for other
4813 threads not the current. */
4814 p = append_pending_thread_resumptions (p, endp, ptid);
4816 /* And continue others without a signal. */
4817 append_resumption (p, endp, ptid, /*step=*/ 0, GDB_SIGNAL_0);
4821 /* Scheduler locking; resume only PTID. */
4822 append_resumption (p, endp, ptid, step, siggnal);
4825 gdb_assert (strlen (rs->buf) < get_remote_packet_size ());
4830 /* In non-stop, the stub replies to vCont with "OK". The stop
4831 reply will be reported asynchronously by means of a `%Stop'
4833 getpkt (&rs->buf, &rs->buf_size, 0);
4834 if (strcmp (rs->buf, "OK") != 0)
4835 error (_("Unexpected vCont reply in non-stop mode: %s"), rs->buf);
4841 /* Tell the remote machine to resume. */
4844 remote_resume (struct target_ops *ops,
4845 ptid_t ptid, int step, enum gdb_signal siggnal)
4847 struct remote_state *rs = get_remote_state ();
4850 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
4851 (explained in remote-notif.c:handle_notification) so
4852 remote_notif_process is not called. We need find a place where
4853 it is safe to start a 'vNotif' sequence. It is good to do it
4854 before resuming inferior, because inferior was stopped and no RSP
4855 traffic at that moment. */
4857 remote_notif_process (rs->notif_state, ¬if_client_stop);
4859 rs->last_sent_signal = siggnal;
4860 rs->last_sent_step = step;
4862 /* The vCont packet doesn't need to specify threads via Hc. */
4863 /* No reverse support (yet) for vCont. */
4864 if (execution_direction != EXEC_REVERSE)
4865 if (remote_vcont_resume (ptid, step, siggnal))
4868 /* All other supported resume packets do use Hc, so set the continue
4870 if (ptid_equal (ptid, minus_one_ptid))
4871 set_continue_thread (any_thread_ptid);
4873 set_continue_thread (ptid);
4876 if (execution_direction == EXEC_REVERSE)
4878 /* We don't pass signals to the target in reverse exec mode. */
4879 if (info_verbose && siggnal != GDB_SIGNAL_0)
4880 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4884 && remote_protocol_packets[PACKET_bs].support == PACKET_DISABLE)
4885 error (_("Remote reverse-step not supported."));
4887 && remote_protocol_packets[PACKET_bc].support == PACKET_DISABLE)
4888 error (_("Remote reverse-continue not supported."));
4890 strcpy (buf, step ? "bs" : "bc");
4892 else if (siggnal != GDB_SIGNAL_0)
4894 buf[0] = step ? 'S' : 'C';
4895 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
4896 buf[2] = tohex (((int) siggnal) & 0xf);
4900 strcpy (buf, step ? "s" : "c");
4905 /* We are about to start executing the inferior, let's register it
4906 with the event loop. NOTE: this is the one place where all the
4907 execution commands end up. We could alternatively do this in each
4908 of the execution commands in infcmd.c. */
4909 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4910 into infcmd.c in order to allow inferior function calls to work
4911 NOT asynchronously. */
4912 if (target_can_async_p ())
4913 target_async (inferior_event_handler, 0);
4915 /* We've just told the target to resume. The remote server will
4916 wait for the inferior to stop, and then send a stop reply. In
4917 the mean time, we can't start another command/query ourselves
4918 because the stub wouldn't be ready to process it. This applies
4919 only to the base all-stop protocol, however. In non-stop (which
4920 only supports vCont), the stub replies with an "OK", and is
4921 immediate able to process further serial input. */
4923 rs->waiting_for_stop_reply = 1;
4927 /* Set up the signal handler for SIGINT, while the target is
4928 executing, ovewriting the 'regular' SIGINT signal handler. */
4930 async_initialize_sigint_signal_handler (void)
4932 signal (SIGINT, async_handle_remote_sigint);
4935 /* Signal handler for SIGINT, while the target is executing. */
4937 async_handle_remote_sigint (int sig)
4939 signal (sig, async_handle_remote_sigint_twice);
4940 mark_async_signal_handler (async_sigint_remote_token);
4943 /* Signal handler for SIGINT, installed after SIGINT has already been
4944 sent once. It will take effect the second time that the user sends
4947 async_handle_remote_sigint_twice (int sig)
4949 signal (sig, async_handle_remote_sigint);
4950 mark_async_signal_handler (async_sigint_remote_twice_token);
4953 /* Perform the real interruption of the target execution, in response
4956 async_remote_interrupt (gdb_client_data arg)
4959 fprintf_unfiltered (gdb_stdlog, "async_remote_interrupt called\n");
4961 target_stop (inferior_ptid);
4964 /* Perform interrupt, if the first attempt did not succeed. Just give
4965 up on the target alltogether. */
4967 async_remote_interrupt_twice (gdb_client_data arg)
4970 fprintf_unfiltered (gdb_stdlog, "async_remote_interrupt_twice called\n");
4975 /* Reinstall the usual SIGINT handlers, after the target has
4978 async_cleanup_sigint_signal_handler (void *dummy)
4980 signal (SIGINT, handle_sigint);
4983 /* Send ^C to target to halt it. Target will respond, and send us a
4985 static void (*ofunc) (int);
4987 /* The command line interface's stop routine. This function is installed
4988 as a signal handler for SIGINT. The first time a user requests a
4989 stop, we call remote_stop to send a break or ^C. If there is no
4990 response from the target (it didn't stop when the user requested it),
4991 we ask the user if he'd like to detach from the target. */
4993 sync_remote_interrupt (int signo)
4995 /* If this doesn't work, try more severe steps. */
4996 signal (signo, sync_remote_interrupt_twice);
4998 gdb_call_async_signal_handler (async_sigint_remote_token, 1);
5001 /* The user typed ^C twice. */
5004 sync_remote_interrupt_twice (int signo)
5006 signal (signo, ofunc);
5007 gdb_call_async_signal_handler (async_sigint_remote_twice_token, 1);
5008 signal (signo, sync_remote_interrupt);
5011 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5012 thread, all threads of a remote process, or all threads of all
5016 remote_stop_ns (ptid_t ptid)
5018 struct remote_state *rs = get_remote_state ();
5020 char *endp = rs->buf + get_remote_packet_size ();
5022 if (remote_protocol_packets[PACKET_vCont].support == PACKET_SUPPORT_UNKNOWN)
5023 remote_vcont_probe (rs);
5025 if (!rs->supports_vCont.t)
5026 error (_("Remote server does not support stopping threads"));
5028 if (ptid_equal (ptid, minus_one_ptid)
5029 || (!remote_multi_process_p (rs) && ptid_is_pid (ptid)))
5030 p += xsnprintf (p, endp - p, "vCont;t");
5035 p += xsnprintf (p, endp - p, "vCont;t:");
5037 if (ptid_is_pid (ptid))
5038 /* All (-1) threads of process. */
5039 nptid = ptid_build (ptid_get_pid (ptid), 0, -1);
5042 /* Small optimization: if we already have a stop reply for
5043 this thread, no use in telling the stub we want this
5045 if (peek_stop_reply (ptid))
5051 write_ptid (p, endp, nptid);
5054 /* In non-stop, we get an immediate OK reply. The stop reply will
5055 come in asynchronously by notification. */
5057 getpkt (&rs->buf, &rs->buf_size, 0);
5058 if (strcmp (rs->buf, "OK") != 0)
5059 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid), rs->buf);
5062 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5063 remote target. It is undefined which thread of which process
5064 reports the stop. */
5067 remote_stop_as (ptid_t ptid)
5069 struct remote_state *rs = get_remote_state ();
5071 rs->ctrlc_pending_p = 1;
5073 /* If the inferior is stopped already, but the core didn't know
5074 about it yet, just ignore the request. The cached wait status
5075 will be collected in remote_wait. */
5076 if (rs->cached_wait_status)
5079 /* Send interrupt_sequence to remote target. */
5080 send_interrupt_sequence ();
5083 /* This is the generic stop called via the target vector. When a target
5084 interrupt is requested, either by the command line or the GUI, we
5085 will eventually end up here. */
5088 remote_stop (struct target_ops *self, ptid_t ptid)
5091 fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
5094 remote_stop_ns (ptid);
5096 remote_stop_as (ptid);
5099 /* Ask the user what to do when an interrupt is received. */
5102 interrupt_query (void)
5104 target_terminal_ours ();
5106 if (target_can_async_p ())
5108 signal (SIGINT, handle_sigint);
5113 if (query (_("Interrupted while waiting for the program.\n\
5114 Give up (and stop debugging it)? ")))
5116 remote_unpush_target ();
5121 target_terminal_inferior ();
5124 /* Enable/disable target terminal ownership. Most targets can use
5125 terminal groups to control terminal ownership. Remote targets are
5126 different in that explicit transfer of ownership to/from GDB/target
5130 remote_terminal_inferior (struct target_ops *self)
5132 if (!target_async_permitted)
5133 /* Nothing to do. */
5136 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5137 idempotent. The event-loop GDB talking to an asynchronous target
5138 with a synchronous command calls this function from both
5139 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5140 transfer the terminal to the target when it shouldn't this guard
5142 if (!remote_async_terminal_ours_p)
5144 delete_file_handler (input_fd);
5145 remote_async_terminal_ours_p = 0;
5146 async_initialize_sigint_signal_handler ();
5147 /* NOTE: At this point we could also register our selves as the
5148 recipient of all input. Any characters typed could then be
5149 passed on down to the target. */
5153 remote_terminal_ours (struct target_ops *self)
5155 if (!target_async_permitted)
5156 /* Nothing to do. */
5159 /* See FIXME in remote_terminal_inferior. */
5160 if (remote_async_terminal_ours_p)
5162 async_cleanup_sigint_signal_handler (NULL);
5163 add_file_handler (input_fd, stdin_event_handler, 0);
5164 remote_async_terminal_ours_p = 1;
5168 remote_console_output (char *msg)
5172 for (p = msg; p[0] && p[1]; p += 2)
5175 char c = fromhex (p[0]) * 16 + fromhex (p[1]);
5179 fputs_unfiltered (tb, gdb_stdtarg);
5181 gdb_flush (gdb_stdtarg);
5184 typedef struct cached_reg
5187 gdb_byte data[MAX_REGISTER_SIZE];
5190 DEF_VEC_O(cached_reg_t);
5192 typedef struct stop_reply
5194 struct notif_event base;
5196 /* The identifier of the thread about this event */
5199 /* The remote state this event is associated with. When the remote
5200 connection, represented by a remote_state object, is closed,
5201 all the associated stop_reply events should be released. */
5202 struct remote_state *rs;
5204 struct target_waitstatus ws;
5206 /* Expedited registers. This makes remote debugging a bit more
5207 efficient for those targets that provide critical registers as
5208 part of their normal status mechanism (as another roundtrip to
5209 fetch them is avoided). */
5210 VEC(cached_reg_t) *regcache;
5212 int stopped_by_watchpoint_p;
5213 CORE_ADDR watch_data_address;
5218 DECLARE_QUEUE_P (stop_reply_p);
5219 DEFINE_QUEUE_P (stop_reply_p);
5220 /* The list of already fetched and acknowledged stop events. This
5221 queue is used for notification Stop, and other notifications
5222 don't need queue for their events, because the notification events
5223 of Stop can't be consumed immediately, so that events should be
5224 queued first, and be consumed by remote_wait_{ns,as} one per
5225 time. Other notifications can consume their events immediately,
5226 so queue is not needed for them. */
5227 static QUEUE (stop_reply_p) *stop_reply_queue;
5230 stop_reply_xfree (struct stop_reply *r)
5232 notif_event_xfree ((struct notif_event *) r);
5236 remote_notif_stop_parse (struct notif_client *self, char *buf,
5237 struct notif_event *event)
5239 remote_parse_stop_reply (buf, (struct stop_reply *) event);
5243 remote_notif_stop_ack (struct notif_client *self, char *buf,
5244 struct notif_event *event)
5246 struct stop_reply *stop_reply = (struct stop_reply *) event;
5249 putpkt ((char *) self->ack_command);
5251 if (stop_reply->ws.kind == TARGET_WAITKIND_IGNORE)
5252 /* We got an unknown stop reply. */
5253 error (_("Unknown stop reply"));
5255 push_stop_reply (stop_reply);
5259 remote_notif_stop_can_get_pending_events (struct notif_client *self)
5261 /* We can't get pending events in remote_notif_process for
5262 notification stop, and we have to do this in remote_wait_ns
5263 instead. If we fetch all queued events from stub, remote stub
5264 may exit and we have no chance to process them back in
5266 mark_async_event_handler (remote_async_inferior_event_token);
5271 stop_reply_dtr (struct notif_event *event)
5273 struct stop_reply *r = (struct stop_reply *) event;
5275 VEC_free (cached_reg_t, r->regcache);
5278 static struct notif_event *
5279 remote_notif_stop_alloc_reply (void)
5281 struct notif_event *r
5282 = (struct notif_event *) XNEW (struct stop_reply);
5284 r->dtr = stop_reply_dtr;
5289 /* A client of notification Stop. */
5291 struct notif_client notif_client_stop =
5295 remote_notif_stop_parse,
5296 remote_notif_stop_ack,
5297 remote_notif_stop_can_get_pending_events,
5298 remote_notif_stop_alloc_reply,
5302 /* A parameter to pass data in and out. */
5304 struct queue_iter_param
5307 struct stop_reply *output;
5310 /* Remove stop replies in the queue if its pid is equal to the given
5314 remove_stop_reply_for_inferior (QUEUE (stop_reply_p) *q,
5315 QUEUE_ITER (stop_reply_p) *iter,
5319 struct queue_iter_param *param = data;
5320 struct inferior *inf = param->input;
5322 if (ptid_get_pid (event->ptid) == inf->pid)
5324 stop_reply_xfree (event);
5325 QUEUE_remove_elem (stop_reply_p, q, iter);
5331 /* Discard all pending stop replies of inferior INF. */
5334 discard_pending_stop_replies (struct inferior *inf)
5337 struct queue_iter_param param;
5338 struct stop_reply *reply;
5339 struct remote_state *rs = get_remote_state ();
5340 struct remote_notif_state *rns = rs->notif_state;
5342 /* This function can be notified when an inferior exists. When the
5343 target is not remote, the notification state is NULL. */
5344 if (rs->remote_desc == NULL)
5347 reply = (struct stop_reply *) rns->pending_event[notif_client_stop.id];
5349 /* Discard the in-flight notification. */
5350 if (reply != NULL && ptid_get_pid (reply->ptid) == inf->pid)
5352 stop_reply_xfree (reply);
5353 rns->pending_event[notif_client_stop.id] = NULL;
5357 param.output = NULL;
5358 /* Discard the stop replies we have already pulled with
5360 QUEUE_iterate (stop_reply_p, stop_reply_queue,
5361 remove_stop_reply_for_inferior, ¶m);
5364 /* If its remote state is equal to the given remote state,
5365 remove EVENT from the stop reply queue. */
5368 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p) *q,
5369 QUEUE_ITER (stop_reply_p) *iter,
5373 struct queue_iter_param *param = data;
5374 struct remote_state *rs = param->input;
5376 if (event->rs == rs)
5378 stop_reply_xfree (event);
5379 QUEUE_remove_elem (stop_reply_p, q, iter);
5385 /* Discard the stop replies for RS in stop_reply_queue. */
5388 discard_pending_stop_replies_in_queue (struct remote_state *rs)
5390 struct queue_iter_param param;
5393 param.output = NULL;
5394 /* Discard the stop replies we have already pulled with
5396 QUEUE_iterate (stop_reply_p, stop_reply_queue,
5397 remove_stop_reply_of_remote_state, ¶m);
5400 /* A parameter to pass data in and out. */
5403 remote_notif_remove_once_on_match (QUEUE (stop_reply_p) *q,
5404 QUEUE_ITER (stop_reply_p) *iter,
5408 struct queue_iter_param *param = data;
5409 ptid_t *ptid = param->input;
5411 if (ptid_match (event->ptid, *ptid))
5413 param->output = event;
5414 QUEUE_remove_elem (stop_reply_p, q, iter);
5421 /* Remove the first reply in 'stop_reply_queue' which matches
5424 static struct stop_reply *
5425 remote_notif_remove_queued_reply (ptid_t ptid)
5427 struct queue_iter_param param;
5429 param.input = &ptid;
5430 param.output = NULL;
5432 QUEUE_iterate (stop_reply_p, stop_reply_queue,
5433 remote_notif_remove_once_on_match, ¶m);
5435 fprintf_unfiltered (gdb_stdlog,
5436 "notif: discard queued event: 'Stop' in %s\n",
5437 target_pid_to_str (ptid));
5439 return param.output;
5442 /* Look for a queued stop reply belonging to PTID. If one is found,
5443 remove it from the queue, and return it. Returns NULL if none is
5444 found. If there are still queued events left to process, tell the
5445 event loop to get back to target_wait soon. */
5447 static struct stop_reply *
5448 queued_stop_reply (ptid_t ptid)
5450 struct stop_reply *r = remote_notif_remove_queued_reply (ptid);
5452 if (!QUEUE_is_empty (stop_reply_p, stop_reply_queue))
5453 /* There's still at least an event left. */
5454 mark_async_event_handler (remote_async_inferior_event_token);
5459 /* Push a fully parsed stop reply in the stop reply queue. Since we
5460 know that we now have at least one queued event left to pass to the
5461 core side, tell the event loop to get back to target_wait soon. */
5464 push_stop_reply (struct stop_reply *new_event)
5466 QUEUE_enque (stop_reply_p, stop_reply_queue, new_event);
5469 fprintf_unfiltered (gdb_stdlog,
5470 "notif: push 'Stop' %s to queue %d\n",
5471 target_pid_to_str (new_event->ptid),
5472 QUEUE_length (stop_reply_p,
5475 mark_async_event_handler (remote_async_inferior_event_token);
5479 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p) *q,
5480 QUEUE_ITER (stop_reply_p) *iter,
5481 struct stop_reply *event,
5484 ptid_t *ptid = data;
5486 return !(ptid_equal (*ptid, event->ptid)
5487 && event->ws.kind == TARGET_WAITKIND_STOPPED);
5490 /* Returns true if we have a stop reply for PTID. */
5493 peek_stop_reply (ptid_t ptid)
5495 return !QUEUE_iterate (stop_reply_p, stop_reply_queue,
5496 stop_reply_match_ptid_and_ws, &ptid);
5499 /* Parse the stop reply in BUF. Either the function succeeds, and the
5500 result is stored in EVENT, or throws an error. */
5503 remote_parse_stop_reply (char *buf, struct stop_reply *event)
5505 struct remote_arch_state *rsa = get_remote_arch_state ();
5509 event->ptid = null_ptid;
5510 event->rs = get_remote_state ();
5511 event->ws.kind = TARGET_WAITKIND_IGNORE;
5512 event->ws.value.integer = 0;
5513 event->stopped_by_watchpoint_p = 0;
5514 event->regcache = NULL;
5519 case 'T': /* Status with PC, SP, FP, ... */
5520 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5521 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5523 n... = register number
5524 r... = register contents
5527 p = &buf[3]; /* after Txx */
5535 /* If the packet contains a register number, save it in
5536 pnum and set p1 to point to the character following it.
5537 Otherwise p1 points to p. */
5539 /* If this packet is an awatch packet, don't parse the 'a'
5540 as a register number. */
5542 if (strncmp (p, "awatch", strlen("awatch")) != 0
5543 && strncmp (p, "core", strlen ("core") != 0))
5545 /* Read the ``P'' register number. */
5546 pnum = strtol (p, &p_temp, 16);
5552 if (p1 == p) /* No register number present here. */
5554 p1 = strchr (p, ':');
5556 error (_("Malformed packet(a) (missing colon): %s\n\
5559 if (strncmp (p, "thread", p1 - p) == 0)
5560 event->ptid = read_ptid (++p1, &p);
5561 else if ((strncmp (p, "watch", p1 - p) == 0)
5562 || (strncmp (p, "rwatch", p1 - p) == 0)
5563 || (strncmp (p, "awatch", p1 - p) == 0))
5565 event->stopped_by_watchpoint_p = 1;
5566 p = unpack_varlen_hex (++p1, &addr);
5567 event->watch_data_address = (CORE_ADDR) addr;
5569 else if (strncmp (p, "library", p1 - p) == 0)
5573 while (*p_temp && *p_temp != ';')
5576 event->ws.kind = TARGET_WAITKIND_LOADED;
5579 else if (strncmp (p, "replaylog", p1 - p) == 0)
5581 event->ws.kind = TARGET_WAITKIND_NO_HISTORY;
5582 /* p1 will indicate "begin" or "end", but it makes
5583 no difference for now, so ignore it. */
5584 p_temp = strchr (p1 + 1, ';');
5588 else if (strncmp (p, "core", p1 - p) == 0)
5592 p = unpack_varlen_hex (++p1, &c);
5597 /* Silently skip unknown optional info. */
5598 p_temp = strchr (p1 + 1, ';');
5605 struct packet_reg *reg = packet_reg_from_pnum (rsa, pnum);
5606 cached_reg_t cached_reg;
5611 error (_("Malformed packet(b) (missing colon): %s\n\
5617 error (_("Remote sent bad register number %s: %s\n\
5619 hex_string (pnum), p, buf);
5621 cached_reg.num = reg->regnum;
5623 fieldsize = hex2bin (p, cached_reg.data,
5624 register_size (target_gdbarch (),
5627 if (fieldsize < register_size (target_gdbarch (),
5629 warning (_("Remote reply is too short: %s"), buf);
5631 VEC_safe_push (cached_reg_t, event->regcache, &cached_reg);
5635 error (_("Remote register badly formatted: %s\nhere: %s"),
5640 if (event->ws.kind != TARGET_WAITKIND_IGNORE)
5644 case 'S': /* Old style status, just signal only. */
5648 event->ws.kind = TARGET_WAITKIND_STOPPED;
5649 sig = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
5650 if (GDB_SIGNAL_FIRST <= sig && sig < GDB_SIGNAL_LAST)
5651 event->ws.value.sig = (enum gdb_signal) sig;
5653 event->ws.value.sig = GDB_SIGNAL_UNKNOWN;
5656 case 'W': /* Target exited. */
5663 /* GDB used to accept only 2 hex chars here. Stubs should
5664 only send more if they detect GDB supports multi-process
5666 p = unpack_varlen_hex (&buf[1], &value);
5670 /* The remote process exited. */
5671 event->ws.kind = TARGET_WAITKIND_EXITED;
5672 event->ws.value.integer = value;
5676 /* The remote process exited with a signal. */
5677 event->ws.kind = TARGET_WAITKIND_SIGNALLED;
5678 if (GDB_SIGNAL_FIRST <= value && value < GDB_SIGNAL_LAST)
5679 event->ws.value.sig = (enum gdb_signal) value;
5681 event->ws.value.sig = GDB_SIGNAL_UNKNOWN;
5684 /* If no process is specified, assume inferior_ptid. */
5685 pid = ptid_get_pid (inferior_ptid);
5694 else if (strncmp (p,
5695 "process:", sizeof ("process:") - 1) == 0)
5699 p += sizeof ("process:") - 1;
5700 unpack_varlen_hex (p, &upid);
5704 error (_("unknown stop reply packet: %s"), buf);
5707 error (_("unknown stop reply packet: %s"), buf);
5708 event->ptid = pid_to_ptid (pid);
5713 if (non_stop && ptid_equal (event->ptid, null_ptid))
5714 error (_("No process or thread specified in stop reply: %s"), buf);
5717 /* When the stub wants to tell GDB about a new notification reply, it
5718 sends a notification (%Stop, for example). Those can come it at
5719 any time, hence, we have to make sure that any pending
5720 putpkt/getpkt sequence we're making is finished, before querying
5721 the stub for more events with the corresponding ack command
5722 (vStopped, for example). E.g., if we started a vStopped sequence
5723 immediately upon receiving the notification, something like this
5731 1.6) <-- (registers reply to step #1.3)
5733 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5736 To solve this, whenever we parse a %Stop notification successfully,
5737 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5738 doing whatever we were doing:
5744 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5745 2.5) <-- (registers reply to step #2.3)
5747 Eventualy after step #2.5, we return to the event loop, which
5748 notices there's an event on the
5749 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5750 associated callback --- the function below. At this point, we're
5751 always safe to start a vStopped sequence. :
5754 2.7) <-- T05 thread:2
5760 remote_notif_get_pending_events (struct notif_client *nc)
5762 struct remote_state *rs = get_remote_state ();
5764 if (rs->notif_state->pending_event[nc->id] != NULL)
5767 fprintf_unfiltered (gdb_stdlog,
5768 "notif: process: '%s' ack pending event\n",
5772 nc->ack (nc, rs->buf, rs->notif_state->pending_event[nc->id]);
5773 rs->notif_state->pending_event[nc->id] = NULL;
5777 getpkt (&rs->buf, &rs->buf_size, 0);
5778 if (strcmp (rs->buf, "OK") == 0)
5781 remote_notif_ack (nc, rs->buf);
5787 fprintf_unfiltered (gdb_stdlog,
5788 "notif: process: '%s' no pending reply\n",
5793 /* Called when it is decided that STOP_REPLY holds the info of the
5794 event that is to be returned to the core. This function always
5795 destroys STOP_REPLY. */
5798 process_stop_reply (struct stop_reply *stop_reply,
5799 struct target_waitstatus *status)
5803 *status = stop_reply->ws;
5804 ptid = stop_reply->ptid;
5806 /* If no thread/process was reported by the stub, assume the current
5808 if (ptid_equal (ptid, null_ptid))
5809 ptid = inferior_ptid;
5811 if (status->kind != TARGET_WAITKIND_EXITED
5812 && status->kind != TARGET_WAITKIND_SIGNALLED)
5814 struct remote_state *rs = get_remote_state ();
5816 /* Expedited registers. */
5817 if (stop_reply->regcache)
5819 struct regcache *regcache
5820 = get_thread_arch_regcache (ptid, target_gdbarch ());
5825 VEC_iterate(cached_reg_t, stop_reply->regcache, ix, reg);
5827 regcache_raw_supply (regcache, reg->num, reg->data);
5828 VEC_free (cached_reg_t, stop_reply->regcache);
5831 rs->remote_stopped_by_watchpoint_p = stop_reply->stopped_by_watchpoint_p;
5832 rs->remote_watch_data_address = stop_reply->watch_data_address;
5834 remote_notice_new_inferior (ptid, 0);
5835 demand_private_info (ptid)->core = stop_reply->core;
5838 stop_reply_xfree (stop_reply);
5842 /* The non-stop mode version of target_wait. */
5845 remote_wait_ns (ptid_t ptid, struct target_waitstatus *status, int options)
5847 struct remote_state *rs = get_remote_state ();
5848 struct stop_reply *stop_reply;
5852 /* If in non-stop mode, get out of getpkt even if a
5853 notification is received. */
5855 ret = getpkt_or_notif_sane (&rs->buf, &rs->buf_size,
5856 0 /* forever */, &is_notif);
5859 if (ret != -1 && !is_notif)
5862 case 'E': /* Error of some sort. */
5863 /* We're out of sync with the target now. Did it continue
5864 or not? We can't tell which thread it was in non-stop,
5865 so just ignore this. */
5866 warning (_("Remote failure reply: %s"), rs->buf);
5868 case 'O': /* Console output. */
5869 remote_console_output (rs->buf + 1);
5872 warning (_("Invalid remote reply: %s"), rs->buf);
5876 /* Acknowledge a pending stop reply that may have arrived in the
5878 if (rs->notif_state->pending_event[notif_client_stop.id] != NULL)
5879 remote_notif_get_pending_events (¬if_client_stop);
5881 /* If indeed we noticed a stop reply, we're done. */
5882 stop_reply = queued_stop_reply (ptid);
5883 if (stop_reply != NULL)
5884 return process_stop_reply (stop_reply, status);
5886 /* Still no event. If we're just polling for an event, then
5887 return to the event loop. */
5888 if (options & TARGET_WNOHANG)
5890 status->kind = TARGET_WAITKIND_IGNORE;
5891 return minus_one_ptid;
5894 /* Otherwise do a blocking wait. */
5895 ret = getpkt_or_notif_sane (&rs->buf, &rs->buf_size,
5896 1 /* forever */, &is_notif);
5900 /* Wait until the remote machine stops, then return, storing status in
5901 STATUS just as `wait' would. */
5904 remote_wait_as (ptid_t ptid, struct target_waitstatus *status, int options)
5906 struct remote_state *rs = get_remote_state ();
5907 ptid_t event_ptid = null_ptid;
5909 struct stop_reply *stop_reply;
5913 status->kind = TARGET_WAITKIND_IGNORE;
5914 status->value.integer = 0;
5916 stop_reply = queued_stop_reply (ptid);
5917 if (stop_reply != NULL)
5918 return process_stop_reply (stop_reply, status);
5920 if (rs->cached_wait_status)
5921 /* Use the cached wait status, but only once. */
5922 rs->cached_wait_status = 0;
5928 if (!target_is_async_p ())
5930 ofunc = signal (SIGINT, sync_remote_interrupt);
5931 /* If the user hit C-c before this packet, or between packets,
5932 pretend that it was hit right here. */
5933 if (check_quit_flag ())
5936 sync_remote_interrupt (SIGINT);
5940 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5941 _never_ wait for ever -> test on target_is_async_p().
5942 However, before we do that we need to ensure that the caller
5943 knows how to take the target into/out of async mode. */
5944 ret = getpkt_or_notif_sane (&rs->buf, &rs->buf_size,
5945 wait_forever_enabled_p, &is_notif);
5947 if (!target_is_async_p ())
5948 signal (SIGINT, ofunc);
5950 /* GDB gets a notification. Return to core as this event is
5952 if (ret != -1 && is_notif)
5953 return minus_one_ptid;
5958 rs->remote_stopped_by_watchpoint_p = 0;
5960 /* We got something. */
5961 rs->waiting_for_stop_reply = 0;
5963 /* Assume that the target has acknowledged Ctrl-C unless we receive
5964 an 'F' or 'O' packet. */
5965 if (buf[0] != 'F' && buf[0] != 'O')
5966 rs->ctrlc_pending_p = 0;
5970 case 'E': /* Error of some sort. */
5971 /* We're out of sync with the target now. Did it continue or
5972 not? Not is more likely, so report a stop. */
5973 warning (_("Remote failure reply: %s"), buf);
5974 status->kind = TARGET_WAITKIND_STOPPED;
5975 status->value.sig = GDB_SIGNAL_0;
5977 case 'F': /* File-I/O request. */
5978 remote_fileio_request (buf, rs->ctrlc_pending_p);
5979 rs->ctrlc_pending_p = 0;
5981 case 'T': case 'S': case 'X': case 'W':
5983 struct stop_reply *stop_reply
5984 = (struct stop_reply *) remote_notif_parse (¬if_client_stop,
5987 event_ptid = process_stop_reply (stop_reply, status);
5990 case 'O': /* Console output. */
5991 remote_console_output (buf + 1);
5993 /* The target didn't really stop; keep waiting. */
5994 rs->waiting_for_stop_reply = 1;
5998 if (rs->last_sent_signal != GDB_SIGNAL_0)
6000 /* Zero length reply means that we tried 'S' or 'C' and the
6001 remote system doesn't support it. */
6002 target_terminal_ours_for_output ();
6004 ("Can't send signals to this remote system. %s not sent.\n",
6005 gdb_signal_to_name (rs->last_sent_signal));
6006 rs->last_sent_signal = GDB_SIGNAL_0;
6007 target_terminal_inferior ();
6009 strcpy ((char *) buf, rs->last_sent_step ? "s" : "c");
6010 putpkt ((char *) buf);
6012 /* We just told the target to resume, so a stop reply is in
6014 rs->waiting_for_stop_reply = 1;
6017 /* else fallthrough */
6019 warning (_("Invalid remote reply: %s"), buf);
6021 rs->waiting_for_stop_reply = 1;
6025 if (status->kind == TARGET_WAITKIND_IGNORE)
6027 /* Nothing interesting happened. If we're doing a non-blocking
6028 poll, we're done. Otherwise, go back to waiting. */
6029 if (options & TARGET_WNOHANG)
6030 return minus_one_ptid;
6034 else if (status->kind != TARGET_WAITKIND_EXITED
6035 && status->kind != TARGET_WAITKIND_SIGNALLED)
6037 if (!ptid_equal (event_ptid, null_ptid))
6038 record_currthread (rs, event_ptid);
6040 event_ptid = inferior_ptid;
6043 /* A process exit. Invalidate our notion of current thread. */
6044 record_currthread (rs, minus_one_ptid);
6049 /* Wait until the remote machine stops, then return, storing status in
6050 STATUS just as `wait' would. */
6053 remote_wait (struct target_ops *ops,
6054 ptid_t ptid, struct target_waitstatus *status, int options)
6059 event_ptid = remote_wait_ns (ptid, status, options);
6061 event_ptid = remote_wait_as (ptid, status, options);
6063 if (target_can_async_p ())
6065 /* If there are are events left in the queue tell the event loop
6067 if (!QUEUE_is_empty (stop_reply_p, stop_reply_queue))
6068 mark_async_event_handler (remote_async_inferior_event_token);
6074 /* Fetch a single register using a 'p' packet. */
6077 fetch_register_using_p (struct regcache *regcache, struct packet_reg *reg)
6079 struct remote_state *rs = get_remote_state ();
6081 char regp[MAX_REGISTER_SIZE];
6084 if (remote_protocol_packets[PACKET_p].support == PACKET_DISABLE)
6087 if (reg->pnum == -1)
6092 p += hexnumstr (p, reg->pnum);
6095 getpkt (&rs->buf, &rs->buf_size, 0);
6099 switch (packet_ok (buf, &remote_protocol_packets[PACKET_p]))
6103 case PACKET_UNKNOWN:
6106 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6107 gdbarch_register_name (get_regcache_arch (regcache),
6112 /* If this register is unfetchable, tell the regcache. */
6115 regcache_raw_supply (regcache, reg->regnum, NULL);
6119 /* Otherwise, parse and supply the value. */
6125 error (_("fetch_register_using_p: early buf termination"));
6127 regp[i++] = fromhex (p[0]) * 16 + fromhex (p[1]);
6130 regcache_raw_supply (regcache, reg->regnum, regp);
6134 /* Fetch the registers included in the target's 'g' packet. */
6137 send_g_packet (void)
6139 struct remote_state *rs = get_remote_state ();
6142 xsnprintf (rs->buf, get_remote_packet_size (), "g");
6143 remote_send (&rs->buf, &rs->buf_size);
6145 /* We can get out of synch in various cases. If the first character
6146 in the buffer is not a hex character, assume that has happened
6147 and try to fetch another packet to read. */
6148 while ((rs->buf[0] < '0' || rs->buf[0] > '9')
6149 && (rs->buf[0] < 'A' || rs->buf[0] > 'F')
6150 && (rs->buf[0] < 'a' || rs->buf[0] > 'f')
6151 && rs->buf[0] != 'x') /* New: unavailable register value. */
6154 fprintf_unfiltered (gdb_stdlog,
6155 "Bad register packet; fetching a new packet\n");
6156 getpkt (&rs->buf, &rs->buf_size, 0);
6159 buf_len = strlen (rs->buf);
6161 /* Sanity check the received packet. */
6162 if (buf_len % 2 != 0)
6163 error (_("Remote 'g' packet reply is of odd length: %s"), rs->buf);
6169 process_g_packet (struct regcache *regcache)
6171 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6172 struct remote_state *rs = get_remote_state ();
6173 struct remote_arch_state *rsa = get_remote_arch_state ();
6178 buf_len = strlen (rs->buf);
6180 /* Further sanity checks, with knowledge of the architecture. */
6181 if (buf_len > 2 * rsa->sizeof_g_packet)
6182 error (_("Remote 'g' packet reply is too long: %s"), rs->buf);
6184 /* Save the size of the packet sent to us by the target. It is used
6185 as a heuristic when determining the max size of packets that the
6186 target can safely receive. */
6187 if (rsa->actual_register_packet_size == 0)
6188 rsa->actual_register_packet_size = buf_len;
6190 /* If this is smaller than we guessed the 'g' packet would be,
6191 update our records. A 'g' reply that doesn't include a register's
6192 value implies either that the register is not available, or that
6193 the 'p' packet must be used. */
6194 if (buf_len < 2 * rsa->sizeof_g_packet)
6196 rsa->sizeof_g_packet = buf_len / 2;
6198 for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
6200 if (rsa->regs[i].pnum == -1)
6203 if (rsa->regs[i].offset >= rsa->sizeof_g_packet)
6204 rsa->regs[i].in_g_packet = 0;
6206 rsa->regs[i].in_g_packet = 1;
6210 regs = alloca (rsa->sizeof_g_packet);
6212 /* Unimplemented registers read as all bits zero. */
6213 memset (regs, 0, rsa->sizeof_g_packet);
6215 /* Reply describes registers byte by byte, each byte encoded as two
6216 hex characters. Suck them all up, then supply them to the
6217 register cacheing/storage mechanism. */
6220 for (i = 0; i < rsa->sizeof_g_packet; i++)
6222 if (p[0] == 0 || p[1] == 0)
6223 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6224 internal_error (__FILE__, __LINE__,
6225 _("unexpected end of 'g' packet reply"));
6227 if (p[0] == 'x' && p[1] == 'x')
6228 regs[i] = 0; /* 'x' */
6230 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
6234 for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
6236 struct packet_reg *r = &rsa->regs[i];
6240 if (r->offset * 2 >= strlen (rs->buf))
6241 /* This shouldn't happen - we adjusted in_g_packet above. */
6242 internal_error (__FILE__, __LINE__,
6243 _("unexpected end of 'g' packet reply"));
6244 else if (rs->buf[r->offset * 2] == 'x')
6246 gdb_assert (r->offset * 2 < strlen (rs->buf));
6247 /* The register isn't available, mark it as such (at
6248 the same time setting the value to zero). */
6249 regcache_raw_supply (regcache, r->regnum, NULL);
6252 regcache_raw_supply (regcache, r->regnum,
6259 fetch_registers_using_g (struct regcache *regcache)
6262 process_g_packet (regcache);
6265 /* Make the remote selected traceframe match GDB's selected
6269 set_remote_traceframe (void)
6272 struct remote_state *rs = get_remote_state ();
6274 if (rs->remote_traceframe_number == get_traceframe_number ())
6277 /* Avoid recursion, remote_trace_find calls us again. */
6278 rs->remote_traceframe_number = get_traceframe_number ();
6280 newnum = target_trace_find (tfind_number,
6281 get_traceframe_number (), 0, 0, NULL);
6283 /* Should not happen. If it does, all bets are off. */
6284 if (newnum != get_traceframe_number ())
6285 warning (_("could not set remote traceframe"));
6289 remote_fetch_registers (struct target_ops *ops,
6290 struct regcache *regcache, int regnum)
6292 struct remote_arch_state *rsa = get_remote_arch_state ();
6295 set_remote_traceframe ();
6296 set_general_thread (inferior_ptid);
6300 struct packet_reg *reg = packet_reg_from_regnum (rsa, regnum);
6302 gdb_assert (reg != NULL);
6304 /* If this register might be in the 'g' packet, try that first -
6305 we are likely to read more than one register. If this is the
6306 first 'g' packet, we might be overly optimistic about its
6307 contents, so fall back to 'p'. */
6308 if (reg->in_g_packet)
6310 fetch_registers_using_g (regcache);
6311 if (reg->in_g_packet)
6315 if (fetch_register_using_p (regcache, reg))
6318 /* This register is not available. */
6319 regcache_raw_supply (regcache, reg->regnum, NULL);
6324 fetch_registers_using_g (regcache);
6326 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
6327 if (!rsa->regs[i].in_g_packet)
6328 if (!fetch_register_using_p (regcache, &rsa->regs[i]))
6330 /* This register is not available. */
6331 regcache_raw_supply (regcache, i, NULL);
6335 /* Prepare to store registers. Since we may send them all (using a
6336 'G' request), we have to read out the ones we don't want to change
6340 remote_prepare_to_store (struct target_ops *self, struct regcache *regcache)
6342 struct remote_arch_state *rsa = get_remote_arch_state ();
6344 gdb_byte buf[MAX_REGISTER_SIZE];
6346 /* Make sure the entire registers array is valid. */
6347 switch (remote_protocol_packets[PACKET_P].support)
6349 case PACKET_DISABLE:
6350 case PACKET_SUPPORT_UNKNOWN:
6351 /* Make sure all the necessary registers are cached. */
6352 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
6353 if (rsa->regs[i].in_g_packet)
6354 regcache_raw_read (regcache, rsa->regs[i].regnum, buf);
6361 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6362 packet was not recognized. */
6365 store_register_using_P (const struct regcache *regcache,
6366 struct packet_reg *reg)
6368 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6369 struct remote_state *rs = get_remote_state ();
6370 /* Try storing a single register. */
6371 char *buf = rs->buf;
6372 gdb_byte regp[MAX_REGISTER_SIZE];
6375 if (remote_protocol_packets[PACKET_P].support == PACKET_DISABLE)
6378 if (reg->pnum == -1)
6381 xsnprintf (buf, get_remote_packet_size (), "P%s=", phex_nz (reg->pnum, 0));
6382 p = buf + strlen (buf);
6383 regcache_raw_collect (regcache, reg->regnum, regp);
6384 bin2hex (regp, p, register_size (gdbarch, reg->regnum));
6386 getpkt (&rs->buf, &rs->buf_size, 0);
6388 switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_P]))
6393 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6394 gdbarch_register_name (gdbarch, reg->regnum), rs->buf);
6395 case PACKET_UNKNOWN:
6398 internal_error (__FILE__, __LINE__, _("Bad result from packet_ok"));
6402 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6403 contents of the register cache buffer. FIXME: ignores errors. */
6406 store_registers_using_G (const struct regcache *regcache)
6408 struct remote_state *rs = get_remote_state ();
6409 struct remote_arch_state *rsa = get_remote_arch_state ();
6413 /* Extract all the registers in the regcache copying them into a
6418 regs = alloca (rsa->sizeof_g_packet);
6419 memset (regs, 0, rsa->sizeof_g_packet);
6420 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
6422 struct packet_reg *r = &rsa->regs[i];
6425 regcache_raw_collect (regcache, r->regnum, regs + r->offset);
6429 /* Command describes registers byte by byte,
6430 each byte encoded as two hex characters. */
6433 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6435 bin2hex (regs, p, rsa->sizeof_g_packet);
6437 getpkt (&rs->buf, &rs->buf_size, 0);
6438 if (packet_check_result (rs->buf) == PACKET_ERROR)
6439 error (_("Could not write registers; remote failure reply '%s'"),
6443 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6444 of the register cache buffer. FIXME: ignores errors. */
6447 remote_store_registers (struct target_ops *ops,
6448 struct regcache *regcache, int regnum)
6450 struct remote_arch_state *rsa = get_remote_arch_state ();
6453 set_remote_traceframe ();
6454 set_general_thread (inferior_ptid);
6458 struct packet_reg *reg = packet_reg_from_regnum (rsa, regnum);
6460 gdb_assert (reg != NULL);
6462 /* Always prefer to store registers using the 'P' packet if
6463 possible; we often change only a small number of registers.
6464 Sometimes we change a larger number; we'd need help from a
6465 higher layer to know to use 'G'. */
6466 if (store_register_using_P (regcache, reg))
6469 /* For now, don't complain if we have no way to write the
6470 register. GDB loses track of unavailable registers too
6471 easily. Some day, this may be an error. We don't have
6472 any way to read the register, either... */
6473 if (!reg->in_g_packet)
6476 store_registers_using_G (regcache);
6480 store_registers_using_G (regcache);
6482 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
6483 if (!rsa->regs[i].in_g_packet)
6484 if (!store_register_using_P (regcache, &rsa->regs[i]))
6485 /* See above for why we do not issue an error here. */
6490 /* Return the number of hex digits in num. */
6493 hexnumlen (ULONGEST num)
6497 for (i = 0; num != 0; i++)
6503 /* Set BUF to the minimum number of hex digits representing NUM. */
6506 hexnumstr (char *buf, ULONGEST num)
6508 int len = hexnumlen (num);
6510 return hexnumnstr (buf, num, len);
6514 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6517 hexnumnstr (char *buf, ULONGEST num, int width)
6523 for (i = width - 1; i >= 0; i--)
6525 buf[i] = "0123456789abcdef"[(num & 0xf)];
6532 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6535 remote_address_masked (CORE_ADDR addr)
6537 unsigned int address_size = remote_address_size;
6539 /* If "remoteaddresssize" was not set, default to target address size. */
6541 address_size = gdbarch_addr_bit (target_gdbarch ());
6543 if (address_size > 0
6544 && address_size < (sizeof (ULONGEST) * 8))
6546 /* Only create a mask when that mask can safely be constructed
6547 in a ULONGEST variable. */
6550 mask = (mask << address_size) - 1;
6556 /* Determine whether the remote target supports binary downloading.
6557 This is accomplished by sending a no-op memory write of zero length
6558 to the target at the specified address. It does not suffice to send
6559 the whole packet, since many stubs strip the eighth bit and
6560 subsequently compute a wrong checksum, which causes real havoc with
6563 NOTE: This can still lose if the serial line is not eight-bit
6564 clean. In cases like this, the user should clear "remote
6568 check_binary_download (CORE_ADDR addr)
6570 struct remote_state *rs = get_remote_state ();
6572 switch (remote_protocol_packets[PACKET_X].support)
6574 case PACKET_DISABLE:
6578 case PACKET_SUPPORT_UNKNOWN:
6584 p += hexnumstr (p, (ULONGEST) addr);
6586 p += hexnumstr (p, (ULONGEST) 0);
6590 putpkt_binary (rs->buf, (int) (p - rs->buf));
6591 getpkt (&rs->buf, &rs->buf_size, 0);
6593 if (rs->buf[0] == '\0')
6596 fprintf_unfiltered (gdb_stdlog,
6597 "binary downloading NOT "
6598 "supported by target\n");
6599 remote_protocol_packets[PACKET_X].support = PACKET_DISABLE;
6604 fprintf_unfiltered (gdb_stdlog,
6605 "binary downloading supported by target\n");
6606 remote_protocol_packets[PACKET_X].support = PACKET_ENABLE;
6613 /* Write memory data directly to the remote machine.
6614 This does not inform the data cache; the data cache uses this.
6615 HEADER is the starting part of the packet.
6616 MEMADDR is the address in the remote memory space.
6617 MYADDR is the address of the buffer in our space.
6618 LEN is the number of bytes.
6619 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6620 should send data as binary ('X'), or hex-encoded ('M').
6622 The function creates packet of the form
6623 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6625 where encoding of <DATA> is termined by PACKET_FORMAT.
6627 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6630 Return the transferred status, error or OK (an
6631 'enum target_xfer_status' value). Save the number of bytes
6632 transferred in *XFERED_LEN. Only transfer a single packet. */
6634 static enum target_xfer_status
6635 remote_write_bytes_aux (const char *header, CORE_ADDR memaddr,
6636 const gdb_byte *myaddr, ULONGEST len,
6637 ULONGEST *xfered_len, char packet_format,
6640 struct remote_state *rs = get_remote_state ();
6650 if (packet_format != 'X' && packet_format != 'M')
6651 internal_error (__FILE__, __LINE__,
6652 _("remote_write_bytes_aux: bad packet format"));
6655 return TARGET_XFER_EOF;
6657 payload_size = get_memory_write_packet_size ();
6659 /* The packet buffer will be large enough for the payload;
6660 get_memory_packet_size ensures this. */
6663 /* Compute the size of the actual payload by subtracting out the
6664 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6666 payload_size -= strlen ("$,:#NN");
6668 /* The comma won't be used. */
6670 header_length = strlen (header);
6671 payload_size -= header_length;
6672 payload_size -= hexnumlen (memaddr);
6674 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6676 strcat (rs->buf, header);
6677 p = rs->buf + strlen (header);
6679 /* Compute a best guess of the number of bytes actually transfered. */
6680 if (packet_format == 'X')
6682 /* Best guess at number of bytes that will fit. */
6683 todo = min (len, payload_size);
6685 payload_size -= hexnumlen (todo);
6686 todo = min (todo, payload_size);
6690 /* Num bytes that will fit. */
6691 todo = min (len, payload_size / 2);
6693 payload_size -= hexnumlen (todo);
6694 todo = min (todo, payload_size / 2);
6698 internal_error (__FILE__, __LINE__,
6699 _("minimum packet size too small to write data"));
6701 /* If we already need another packet, then try to align the end
6702 of this packet to a useful boundary. */
6703 if (todo > 2 * REMOTE_ALIGN_WRITES && todo < len)
6704 todo = ((memaddr + todo) & ~(REMOTE_ALIGN_WRITES - 1)) - memaddr;
6706 /* Append "<memaddr>". */
6707 memaddr = remote_address_masked (memaddr);
6708 p += hexnumstr (p, (ULONGEST) memaddr);
6715 /* Append <len>. Retain the location/size of <len>. It may need to
6716 be adjusted once the packet body has been created. */
6718 plenlen = hexnumstr (p, (ULONGEST) todo);
6726 /* Append the packet body. */
6727 if (packet_format == 'X')
6729 /* Binary mode. Send target system values byte by byte, in
6730 increasing byte addresses. Only escape certain critical
6732 payload_length = remote_escape_output (myaddr, todo, (gdb_byte *) p,
6733 &nr_bytes, payload_size);
6735 /* If not all TODO bytes fit, then we'll need another packet. Make
6736 a second try to keep the end of the packet aligned. Don't do
6737 this if the packet is tiny. */
6738 if (nr_bytes < todo && nr_bytes > 2 * REMOTE_ALIGN_WRITES)
6742 new_nr_bytes = (((memaddr + nr_bytes) & ~(REMOTE_ALIGN_WRITES - 1))
6744 if (new_nr_bytes != nr_bytes)
6745 payload_length = remote_escape_output (myaddr, new_nr_bytes,
6746 (gdb_byte *) p, &nr_bytes,
6750 p += payload_length;
6751 if (use_length && nr_bytes < todo)
6753 /* Escape chars have filled up the buffer prematurely,
6754 and we have actually sent fewer bytes than planned.
6755 Fix-up the length field of the packet. Use the same
6756 number of characters as before. */
6757 plen += hexnumnstr (plen, (ULONGEST) nr_bytes, plenlen);
6758 *plen = ':'; /* overwrite \0 from hexnumnstr() */
6763 /* Normal mode: Send target system values byte by byte, in
6764 increasing byte addresses. Each byte is encoded as a two hex
6766 nr_bytes = bin2hex (myaddr, p, todo);
6770 putpkt_binary (rs->buf, (int) (p - rs->buf));
6771 getpkt (&rs->buf, &rs->buf_size, 0);
6773 if (rs->buf[0] == 'E')
6774 return TARGET_XFER_E_IO;
6776 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6777 fewer bytes than we'd planned. */
6778 *xfered_len = (ULONGEST) nr_bytes;
6779 return TARGET_XFER_OK;
6782 /* Write memory data directly to the remote machine.
6783 This does not inform the data cache; the data cache uses this.
6784 MEMADDR is the address in the remote memory space.
6785 MYADDR is the address of the buffer in our space.
6786 LEN is the number of bytes.
6788 Return the transferred status, error or OK (an
6789 'enum target_xfer_status' value). Save the number of bytes
6790 transferred in *XFERED_LEN. Only transfer a single packet. */
6792 static enum target_xfer_status
6793 remote_write_bytes (CORE_ADDR memaddr, const gdb_byte *myaddr, ULONGEST len,
6794 ULONGEST *xfered_len)
6796 char *packet_format = 0;
6798 /* Check whether the target supports binary download. */
6799 check_binary_download (memaddr);
6801 switch (remote_protocol_packets[PACKET_X].support)
6804 packet_format = "X";
6806 case PACKET_DISABLE:
6807 packet_format = "M";
6809 case PACKET_SUPPORT_UNKNOWN:
6810 internal_error (__FILE__, __LINE__,
6811 _("remote_write_bytes: bad internal state"));
6813 internal_error (__FILE__, __LINE__, _("bad switch"));
6816 return remote_write_bytes_aux (packet_format,
6817 memaddr, myaddr, len, xfered_len,
6818 packet_format[0], 1);
6821 /* Read memory data directly from the remote machine.
6822 This does not use the data cache; the data cache uses this.
6823 MEMADDR is the address in the remote memory space.
6824 MYADDR is the address of the buffer in our space.
6825 LEN is the number of bytes.
6827 Return the transferred status, error or OK (an
6828 'enum target_xfer_status' value). Save the number of bytes
6829 transferred in *XFERED_LEN. */
6831 static enum target_xfer_status
6832 remote_read_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, ULONGEST len,
6833 ULONGEST *xfered_len)
6835 struct remote_state *rs = get_remote_state ();
6836 int max_buf_size; /* Max size of packet output buffer. */
6844 max_buf_size = get_memory_read_packet_size ();
6845 /* The packet buffer will be large enough for the payload;
6846 get_memory_packet_size ensures this. */
6848 /* Number if bytes that will fit. */
6849 todo = min (len, max_buf_size / 2);
6851 /* Construct "m"<memaddr>","<len>". */
6852 memaddr = remote_address_masked (memaddr);
6855 p += hexnumstr (p, (ULONGEST) memaddr);
6857 p += hexnumstr (p, (ULONGEST) todo);
6860 getpkt (&rs->buf, &rs->buf_size, 0);
6861 if (rs->buf[0] == 'E'
6862 && isxdigit (rs->buf[1]) && isxdigit (rs->buf[2])
6863 && rs->buf[3] == '\0')
6864 return TARGET_XFER_E_IO;
6865 /* Reply describes memory byte by byte, each byte encoded as two hex
6868 i = hex2bin (p, myaddr, todo);
6869 /* Return what we have. Let higher layers handle partial reads. */
6870 *xfered_len = (ULONGEST) i;
6871 return TARGET_XFER_OK;
6876 /* Sends a packet with content determined by the printf format string
6877 FORMAT and the remaining arguments, then gets the reply. Returns
6878 whether the packet was a success, a failure, or unknown. */
6880 static enum packet_result
6881 remote_send_printf (const char *format, ...)
6883 struct remote_state *rs = get_remote_state ();
6884 int max_size = get_remote_packet_size ();
6887 va_start (ap, format);
6890 if (vsnprintf (rs->buf, max_size, format, ap) >= max_size)
6891 internal_error (__FILE__, __LINE__, _("Too long remote packet."));
6893 if (putpkt (rs->buf) < 0)
6894 error (_("Communication problem with target."));
6897 getpkt (&rs->buf, &rs->buf_size, 0);
6899 return packet_check_result (rs->buf);
6903 restore_remote_timeout (void *p)
6905 int value = *(int *)p;
6907 remote_timeout = value;
6910 /* Flash writing can take quite some time. We'll set
6911 effectively infinite timeout for flash operations.
6912 In future, we'll need to decide on a better approach. */
6913 static const int remote_flash_timeout = 1000;
6916 remote_flash_erase (struct target_ops *ops,
6917 ULONGEST address, LONGEST length)
6919 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
6920 int saved_remote_timeout = remote_timeout;
6921 enum packet_result ret;
6922 struct cleanup *back_to = make_cleanup (restore_remote_timeout,
6923 &saved_remote_timeout);
6925 remote_timeout = remote_flash_timeout;
6927 ret = remote_send_printf ("vFlashErase:%s,%s",
6928 phex (address, addr_size),
6932 case PACKET_UNKNOWN:
6933 error (_("Remote target does not support flash erase"));
6935 error (_("Error erasing flash with vFlashErase packet"));
6940 do_cleanups (back_to);
6943 static enum target_xfer_status
6944 remote_flash_write (struct target_ops *ops, ULONGEST address,
6945 ULONGEST length, ULONGEST *xfered_len,
6946 const gdb_byte *data)
6948 int saved_remote_timeout = remote_timeout;
6949 enum target_xfer_status ret;
6950 struct cleanup *back_to = make_cleanup (restore_remote_timeout,
6951 &saved_remote_timeout);
6953 remote_timeout = remote_flash_timeout;
6954 ret = remote_write_bytes_aux ("vFlashWrite:", address, data, length,
6956 do_cleanups (back_to);
6962 remote_flash_done (struct target_ops *ops)
6964 int saved_remote_timeout = remote_timeout;
6966 struct cleanup *back_to = make_cleanup (restore_remote_timeout,
6967 &saved_remote_timeout);
6969 remote_timeout = remote_flash_timeout;
6970 ret = remote_send_printf ("vFlashDone");
6971 do_cleanups (back_to);
6975 case PACKET_UNKNOWN:
6976 error (_("Remote target does not support vFlashDone"));
6978 error (_("Error finishing flash operation"));
6985 remote_files_info (struct target_ops *ignore)
6987 puts_filtered ("Debugging a target over a serial line.\n");
6990 /* Stuff for dealing with the packets which are part of this protocol.
6991 See comment at top of file for details. */
6993 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
6994 error to higher layers. Called when a serial error is detected.
6995 The exception message is STRING, followed by a colon and a blank,
6996 the system error message for errno at function entry and final dot
6997 for output compatibility with throw_perror_with_name. */
7000 unpush_and_perror (const char *string)
7002 int saved_errno = errno;
7004 remote_unpush_target ();
7005 throw_error (TARGET_CLOSE_ERROR, "%s: %s.", string,
7006 safe_strerror (saved_errno));
7009 /* Read a single character from the remote end. */
7012 readchar (int timeout)
7015 struct remote_state *rs = get_remote_state ();
7017 ch = serial_readchar (rs->remote_desc, timeout);
7022 switch ((enum serial_rc) ch)
7025 remote_unpush_target ();
7026 throw_error (TARGET_CLOSE_ERROR, _("Remote connection closed"));
7029 unpush_and_perror (_("Remote communication error. "
7030 "Target disconnected."));
7032 case SERIAL_TIMEOUT:
7038 /* Wrapper for serial_write that closes the target and throws if
7042 remote_serial_write (const char *str, int len)
7044 struct remote_state *rs = get_remote_state ();
7046 if (serial_write (rs->remote_desc, str, len))
7048 unpush_and_perror (_("Remote communication error. "
7049 "Target disconnected."));
7053 /* Send the command in *BUF to the remote machine, and read the reply
7054 into *BUF. Report an error if we get an error reply. Resize
7055 *BUF using xrealloc if necessary to hold the result, and update
7059 remote_send (char **buf,
7063 getpkt (buf, sizeof_buf, 0);
7065 if ((*buf)[0] == 'E')
7066 error (_("Remote failure reply: %s"), *buf);
7069 /* Return a pointer to an xmalloc'ed string representing an escaped
7070 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7071 etc. The caller is responsible for releasing the returned
7075 escape_buffer (const char *buf, int n)
7077 struct cleanup *old_chain;
7078 struct ui_file *stb;
7081 stb = mem_fileopen ();
7082 old_chain = make_cleanup_ui_file_delete (stb);
7084 fputstrn_unfiltered (buf, n, 0, stb);
7085 str = ui_file_xstrdup (stb, NULL);
7086 do_cleanups (old_chain);
7090 /* Display a null-terminated packet on stdout, for debugging, using C
7094 print_packet (char *buf)
7096 puts_filtered ("\"");
7097 fputstr_filtered (buf, '"', gdb_stdout);
7098 puts_filtered ("\"");
7104 return putpkt_binary (buf, strlen (buf));
7107 /* Send a packet to the remote machine, with error checking. The data
7108 of the packet is in BUF. The string in BUF can be at most
7109 get_remote_packet_size () - 5 to account for the $, # and checksum,
7110 and for a possible /0 if we are debugging (remote_debug) and want
7111 to print the sent packet as a string. */
7114 putpkt_binary (char *buf, int cnt)
7116 struct remote_state *rs = get_remote_state ();
7118 unsigned char csum = 0;
7119 char *buf2 = alloca (cnt + 6);
7126 /* Catch cases like trying to read memory or listing threads while
7127 we're waiting for a stop reply. The remote server wouldn't be
7128 ready to handle this request, so we'd hang and timeout. We don't
7129 have to worry about this in synchronous mode, because in that
7130 case it's not possible to issue a command while the target is
7131 running. This is not a problem in non-stop mode, because in that
7132 case, the stub is always ready to process serial input. */
7133 if (!non_stop && target_can_async_p () && rs->waiting_for_stop_reply)
7134 error (_("Cannot execute this command while the target is running."));
7136 /* We're sending out a new packet. Make sure we don't look at a
7137 stale cached response. */
7138 rs->cached_wait_status = 0;
7140 /* Copy the packet into buffer BUF2, encapsulating it
7141 and giving it a checksum. */
7146 for (i = 0; i < cnt; i++)
7152 *p++ = tohex ((csum >> 4) & 0xf);
7153 *p++ = tohex (csum & 0xf);
7155 /* Send it over and over until we get a positive ack. */
7159 int started_error_output = 0;
7163 struct cleanup *old_chain;
7167 str = escape_buffer (buf2, p - buf2);
7168 old_chain = make_cleanup (xfree, str);
7169 fprintf_unfiltered (gdb_stdlog, "Sending packet: %s...", str);
7170 gdb_flush (gdb_stdlog);
7171 do_cleanups (old_chain);
7173 remote_serial_write (buf2, p - buf2);
7175 /* If this is a no acks version of the remote protocol, send the
7176 packet and move on. */
7180 /* Read until either a timeout occurs (-2) or '+' is read.
7181 Handle any notification that arrives in the mean time. */
7184 ch = readchar (remote_timeout);
7192 case SERIAL_TIMEOUT:
7195 if (started_error_output)
7197 putchar_unfiltered ('\n');
7198 started_error_output = 0;
7207 fprintf_unfiltered (gdb_stdlog, "Ack\n");
7211 fprintf_unfiltered (gdb_stdlog, "Nak\n");
7213 case SERIAL_TIMEOUT:
7217 break; /* Retransmit buffer. */
7221 fprintf_unfiltered (gdb_stdlog,
7222 "Packet instead of Ack, ignoring it\n");
7223 /* It's probably an old response sent because an ACK
7224 was lost. Gobble up the packet and ack it so it
7225 doesn't get retransmitted when we resend this
7228 remote_serial_write ("+", 1);
7229 continue; /* Now, go look for +. */
7236 /* If we got a notification, handle it, and go back to looking
7238 /* We've found the start of a notification. Now
7239 collect the data. */
7240 val = read_frame (&rs->buf, &rs->buf_size);
7245 struct cleanup *old_chain;
7248 str = escape_buffer (rs->buf, val);
7249 old_chain = make_cleanup (xfree, str);
7250 fprintf_unfiltered (gdb_stdlog,
7251 " Notification received: %s\n",
7253 do_cleanups (old_chain);
7255 handle_notification (rs->notif_state, rs->buf);
7256 /* We're in sync now, rewait for the ack. */
7263 if (!started_error_output)
7265 started_error_output = 1;
7266 fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
7268 fputc_unfiltered (ch & 0177, gdb_stdlog);
7269 fprintf_unfiltered (gdb_stdlog, "%s", rs->buf);
7278 if (!started_error_output)
7280 started_error_output = 1;
7281 fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
7283 fputc_unfiltered (ch & 0177, gdb_stdlog);
7287 break; /* Here to retransmit. */
7291 /* This is wrong. If doing a long backtrace, the user should be
7292 able to get out next time we call QUIT, without anything as
7293 violent as interrupt_query. If we want to provide a way out of
7294 here without getting to the next QUIT, it should be based on
7295 hitting ^C twice as in remote_wait. */
7306 /* Come here after finding the start of a frame when we expected an
7307 ack. Do our best to discard the rest of this packet. */
7316 c = readchar (remote_timeout);
7319 case SERIAL_TIMEOUT:
7320 /* Nothing we can do. */
7323 /* Discard the two bytes of checksum and stop. */
7324 c = readchar (remote_timeout);
7326 c = readchar (remote_timeout);
7329 case '*': /* Run length encoding. */
7330 /* Discard the repeat count. */
7331 c = readchar (remote_timeout);
7336 /* A regular character. */
7342 /* Come here after finding the start of the frame. Collect the rest
7343 into *BUF, verifying the checksum, length, and handling run-length
7344 compression. NUL terminate the buffer. If there is not enough room,
7345 expand *BUF using xrealloc.
7347 Returns -1 on error, number of characters in buffer (ignoring the
7348 trailing NULL) on success. (could be extended to return one of the
7349 SERIAL status indications). */
7352 read_frame (char **buf_p,
7359 struct remote_state *rs = get_remote_state ();
7366 c = readchar (remote_timeout);
7369 case SERIAL_TIMEOUT:
7371 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
7375 fputs_filtered ("Saw new packet start in middle of old one\n",
7377 return -1; /* Start a new packet, count retries. */
7380 unsigned char pktcsum;
7386 check_0 = readchar (remote_timeout);
7388 check_1 = readchar (remote_timeout);
7390 if (check_0 == SERIAL_TIMEOUT || check_1 == SERIAL_TIMEOUT)
7393 fputs_filtered ("Timeout in checksum, retrying\n",
7397 else if (check_0 < 0 || check_1 < 0)
7400 fputs_filtered ("Communication error in checksum\n",
7405 /* Don't recompute the checksum; with no ack packets we
7406 don't have any way to indicate a packet retransmission
7411 pktcsum = (fromhex (check_0) << 4) | fromhex (check_1);
7412 if (csum == pktcsum)
7417 struct cleanup *old_chain;
7420 str = escape_buffer (buf, bc);
7421 old_chain = make_cleanup (xfree, str);
7422 fprintf_unfiltered (gdb_stdlog,
7423 "Bad checksum, sentsum=0x%x, "
7424 "csum=0x%x, buf=%s\n",
7425 pktcsum, csum, str);
7426 do_cleanups (old_chain);
7428 /* Number of characters in buffer ignoring trailing
7432 case '*': /* Run length encoding. */
7437 c = readchar (remote_timeout);
7439 repeat = c - ' ' + 3; /* Compute repeat count. */
7441 /* The character before ``*'' is repeated. */
7443 if (repeat > 0 && repeat <= 255 && bc > 0)
7445 if (bc + repeat - 1 >= *sizeof_buf - 1)
7447 /* Make some more room in the buffer. */
7448 *sizeof_buf += repeat;
7449 *buf_p = xrealloc (*buf_p, *sizeof_buf);
7453 memset (&buf[bc], buf[bc - 1], repeat);
7459 printf_filtered (_("Invalid run length encoding: %s\n"), buf);
7463 if (bc >= *sizeof_buf - 1)
7465 /* Make some more room in the buffer. */
7467 *buf_p = xrealloc (*buf_p, *sizeof_buf);
7478 /* Read a packet from the remote machine, with error checking, and
7479 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7480 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7481 rather than timing out; this is used (in synchronous mode) to wait
7482 for a target that is is executing user code to stop. */
7483 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7484 don't have to change all the calls to getpkt to deal with the
7485 return value, because at the moment I don't know what the right
7486 thing to do it for those. */
7494 timed_out = getpkt_sane (buf, sizeof_buf, forever);
7498 /* Read a packet from the remote machine, with error checking, and
7499 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7500 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7501 rather than timing out; this is used (in synchronous mode) to wait
7502 for a target that is is executing user code to stop. If FOREVER ==
7503 0, this function is allowed to time out gracefully and return an
7504 indication of this to the caller. Otherwise return the number of
7505 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7506 enough reason to return to the caller. *IS_NOTIF is an output
7507 boolean that indicates whether *BUF holds a notification or not
7508 (a regular packet). */
7511 getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever,
7512 int expecting_notif, int *is_notif)
7514 struct remote_state *rs = get_remote_state ();
7520 /* We're reading a new response. Make sure we don't look at a
7521 previously cached response. */
7522 rs->cached_wait_status = 0;
7524 strcpy (*buf, "timeout");
7527 timeout = watchdog > 0 ? watchdog : -1;
7528 else if (expecting_notif)
7529 timeout = 0; /* There should already be a char in the buffer. If
7532 timeout = remote_timeout;
7536 /* Process any number of notifications, and then return when
7540 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
7542 for (tries = 1; tries <= MAX_TRIES; tries++)
7544 /* This can loop forever if the remote side sends us
7545 characters continuously, but if it pauses, we'll get
7546 SERIAL_TIMEOUT from readchar because of timeout. Then
7547 we'll count that as a retry.
7549 Note that even when forever is set, we will only wait
7550 forever prior to the start of a packet. After that, we
7551 expect characters to arrive at a brisk pace. They should
7552 show up within remote_timeout intervals. */
7554 c = readchar (timeout);
7555 while (c != SERIAL_TIMEOUT && c != '$' && c != '%');
7557 if (c == SERIAL_TIMEOUT)
7559 if (expecting_notif)
7560 return -1; /* Don't complain, it's normal to not get
7561 anything in this case. */
7563 if (forever) /* Watchdog went off? Kill the target. */
7566 remote_unpush_target ();
7567 throw_error (TARGET_CLOSE_ERROR,
7568 _("Watchdog timeout has expired. "
7569 "Target detached."));
7572 fputs_filtered ("Timed out.\n", gdb_stdlog);
7576 /* We've found the start of a packet or notification.
7577 Now collect the data. */
7578 val = read_frame (buf, sizeof_buf);
7583 remote_serial_write ("-", 1);
7586 if (tries > MAX_TRIES)
7588 /* We have tried hard enough, and just can't receive the
7589 packet/notification. Give up. */
7590 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7592 /* Skip the ack char if we're in no-ack mode. */
7593 if (!rs->noack_mode)
7594 remote_serial_write ("+", 1);
7598 /* If we got an ordinary packet, return that to our caller. */
7603 struct cleanup *old_chain;
7606 str = escape_buffer (*buf, val);
7607 old_chain = make_cleanup (xfree, str);
7608 fprintf_unfiltered (gdb_stdlog, "Packet received: %s\n", str);
7609 do_cleanups (old_chain);
7612 /* Skip the ack char if we're in no-ack mode. */
7613 if (!rs->noack_mode)
7614 remote_serial_write ("+", 1);
7615 if (is_notif != NULL)
7620 /* If we got a notification, handle it, and go back to looking
7624 gdb_assert (c == '%');
7628 struct cleanup *old_chain;
7631 str = escape_buffer (*buf, val);
7632 old_chain = make_cleanup (xfree, str);
7633 fprintf_unfiltered (gdb_stdlog,
7634 " Notification received: %s\n",
7636 do_cleanups (old_chain);
7638 if (is_notif != NULL)
7641 handle_notification (rs->notif_state, *buf);
7643 /* Notifications require no acknowledgement. */
7645 if (expecting_notif)
7652 getpkt_sane (char **buf, long *sizeof_buf, int forever)
7654 return getpkt_or_notif_sane_1 (buf, sizeof_buf, forever, 0, NULL);
7658 getpkt_or_notif_sane (char **buf, long *sizeof_buf, int forever,
7661 return getpkt_or_notif_sane_1 (buf, sizeof_buf, forever, 1,
7667 remote_kill (struct target_ops *ops)
7669 volatile struct gdb_exception ex;
7671 /* Catch errors so the user can quit from gdb even when we
7672 aren't on speaking terms with the remote system. */
7673 TRY_CATCH (ex, RETURN_MASK_ERROR)
7679 if (ex.error == TARGET_CLOSE_ERROR)
7681 /* If we got an (EOF) error that caused the target
7682 to go away, then we're done, that's what we wanted.
7683 "k" is susceptible to cause a premature EOF, given
7684 that the remote server isn't actually required to
7685 reply to "k", and it can happen that it doesn't
7686 even get to reply ACK to the "k". */
7690 /* Otherwise, something went wrong. We didn't actually kill
7691 the target. Just propagate the exception, and let the
7692 user or higher layers decide what to do. */
7693 throw_exception (ex);
7696 /* We've killed the remote end, we get to mourn it. Since this is
7697 target remote, single-process, mourning the inferior also
7698 unpushes remote_ops. */
7699 target_mourn_inferior ();
7703 remote_vkill (int pid, struct remote_state *rs)
7705 if (remote_protocol_packets[PACKET_vKill].support == PACKET_DISABLE)
7708 /* Tell the remote target to detach. */
7709 xsnprintf (rs->buf, get_remote_packet_size (), "vKill;%x", pid);
7711 getpkt (&rs->buf, &rs->buf_size, 0);
7713 if (packet_ok (rs->buf,
7714 &remote_protocol_packets[PACKET_vKill]) == PACKET_OK)
7716 else if (remote_protocol_packets[PACKET_vKill].support == PACKET_DISABLE)
7723 extended_remote_kill (struct target_ops *ops)
7726 int pid = ptid_get_pid (inferior_ptid);
7727 struct remote_state *rs = get_remote_state ();
7729 res = remote_vkill (pid, rs);
7730 if (res == -1 && !(rs->extended && remote_multi_process_p (rs)))
7732 /* Don't try 'k' on a multi-process aware stub -- it has no way
7733 to specify the pid. */
7737 getpkt (&rs->buf, &rs->buf_size, 0);
7738 if (rs->buf[0] != 'O' || rs->buf[0] != 'K')
7741 /* Don't wait for it to die. I'm not really sure it matters whether
7742 we do or not. For the existing stubs, kill is a noop. */
7748 error (_("Can't kill process"));
7750 target_mourn_inferior ();
7754 remote_mourn (struct target_ops *ops)
7756 remote_mourn_1 (ops);
7759 /* Worker function for remote_mourn. */
7761 remote_mourn_1 (struct target_ops *target)
7763 unpush_target (target);
7765 /* remote_close takes care of doing most of the clean up. */
7766 generic_mourn_inferior ();
7770 extended_remote_mourn_1 (struct target_ops *target)
7772 struct remote_state *rs = get_remote_state ();
7774 /* In case we got here due to an error, but we're going to stay
7776 rs->waiting_for_stop_reply = 0;
7778 /* If the current general thread belonged to the process we just
7779 detached from or has exited, the remote side current general
7780 thread becomes undefined. Considering a case like this:
7782 - We just got here due to a detach.
7783 - The process that we're detaching from happens to immediately
7784 report a global breakpoint being hit in non-stop mode, in the
7785 same thread we had selected before.
7786 - GDB attaches to this process again.
7787 - This event happens to be the next event we handle.
7789 GDB would consider that the current general thread didn't need to
7790 be set on the stub side (with Hg), since for all it knew,
7791 GENERAL_THREAD hadn't changed.
7793 Notice that although in all-stop mode, the remote server always
7794 sets the current thread to the thread reporting the stop event,
7795 that doesn't happen in non-stop mode; in non-stop, the stub *must
7796 not* change the current thread when reporting a breakpoint hit,
7797 due to the decoupling of event reporting and event handling.
7799 To keep things simple, we always invalidate our notion of the
7801 record_currthread (rs, minus_one_ptid);
7803 /* Unlike "target remote", we do not want to unpush the target; then
7804 the next time the user says "run", we won't be connected. */
7806 /* Call common code to mark the inferior as not running. */
7807 generic_mourn_inferior ();
7809 if (!have_inferiors ())
7811 if (!remote_multi_process_p (rs))
7813 /* Check whether the target is running now - some remote stubs
7814 automatically restart after kill. */
7816 getpkt (&rs->buf, &rs->buf_size, 0);
7818 if (rs->buf[0] == 'S' || rs->buf[0] == 'T')
7820 /* Assume that the target has been restarted. Set
7821 inferior_ptid so that bits of core GDB realizes
7822 there's something here, e.g., so that the user can
7823 say "kill" again. */
7824 inferior_ptid = magic_null_ptid;
7831 extended_remote_mourn (struct target_ops *ops)
7833 extended_remote_mourn_1 (ops);
7837 extended_remote_supports_disable_randomization (struct target_ops *self)
7839 return (remote_protocol_packets[PACKET_QDisableRandomization].support
7844 extended_remote_disable_randomization (int val)
7846 struct remote_state *rs = get_remote_state ();
7849 xsnprintf (rs->buf, get_remote_packet_size (), "QDisableRandomization:%x",
7852 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
7854 error (_("Target does not support QDisableRandomization."));
7855 if (strcmp (reply, "OK") != 0)
7856 error (_("Bogus QDisableRandomization reply from target: %s"), reply);
7860 extended_remote_run (char *args)
7862 struct remote_state *rs = get_remote_state ();
7865 /* If the user has disabled vRun support, or we have detected that
7866 support is not available, do not try it. */
7867 if (remote_protocol_packets[PACKET_vRun].support == PACKET_DISABLE)
7870 strcpy (rs->buf, "vRun;");
7871 len = strlen (rs->buf);
7873 if (strlen (remote_exec_file) * 2 + len >= get_remote_packet_size ())
7874 error (_("Remote file name too long for run packet"));
7875 len += 2 * bin2hex ((gdb_byte *) remote_exec_file, rs->buf + len,
7876 strlen (remote_exec_file));
7878 gdb_assert (args != NULL);
7881 struct cleanup *back_to;
7885 argv = gdb_buildargv (args);
7886 back_to = make_cleanup ((void (*) (void *)) freeargv, argv);
7887 for (i = 0; argv[i] != NULL; i++)
7889 if (strlen (argv[i]) * 2 + 1 + len >= get_remote_packet_size ())
7890 error (_("Argument list too long for run packet"));
7891 rs->buf[len++] = ';';
7892 len += 2 * bin2hex ((gdb_byte *) argv[i], rs->buf + len,
7895 do_cleanups (back_to);
7898 rs->buf[len++] = '\0';
7901 getpkt (&rs->buf, &rs->buf_size, 0);
7903 if (packet_ok (rs->buf, &remote_protocol_packets[PACKET_vRun]) == PACKET_OK)
7905 /* We have a wait response. All is well. */
7908 else if (remote_protocol_packets[PACKET_vRun].support == PACKET_DISABLE)
7909 /* It wasn't disabled before, but it is now. */
7913 if (remote_exec_file[0] == '\0')
7914 error (_("Running the default executable on the remote target failed; "
7915 "try \"set remote exec-file\"?"));
7917 error (_("Running \"%s\" on the remote target failed"),
7922 /* In the extended protocol we want to be able to do things like
7923 "run" and have them basically work as expected. So we need
7924 a special create_inferior function. We support changing the
7925 executable file and the command line arguments, but not the
7929 extended_remote_create_inferior (struct target_ops *ops,
7930 char *exec_file, char *args,
7931 char **env, int from_tty)
7935 struct remote_state *rs = get_remote_state ();
7937 /* If running asynchronously, register the target file descriptor
7938 with the event loop. */
7939 if (target_can_async_p ())
7940 target_async (inferior_event_handler, 0);
7942 /* Disable address space randomization if requested (and supported). */
7943 if (extended_remote_supports_disable_randomization (ops))
7944 extended_remote_disable_randomization (disable_randomization);
7946 /* Now restart the remote server. */
7947 run_worked = extended_remote_run (args) != -1;
7950 /* vRun was not supported. Fail if we need it to do what the
7952 if (remote_exec_file[0])
7953 error (_("Remote target does not support \"set remote exec-file\""));
7955 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7957 /* Fall back to "R". */
7958 extended_remote_restart ();
7961 if (!have_inferiors ())
7963 /* Clean up from the last time we ran, before we mark the target
7964 running again. This will mark breakpoints uninserted, and
7965 get_offsets may insert breakpoints. */
7966 init_thread_list ();
7967 init_wait_for_inferior ();
7970 /* vRun's success return is a stop reply. */
7971 stop_reply = run_worked ? rs->buf : NULL;
7972 add_current_inferior_and_thread (stop_reply);
7974 /* Get updated offsets, if the stub uses qOffsets. */
7979 /* Given a location's target info BP_TGT and the packet buffer BUF, output
7980 the list of conditions (in agent expression bytecode format), if any, the
7981 target needs to evaluate. The output is placed into the packet buffer
7982 started from BUF and ended at BUF_END. */
7985 remote_add_target_side_condition (struct gdbarch *gdbarch,
7986 struct bp_target_info *bp_tgt, char *buf,
7989 struct agent_expr *aexpr = NULL;
7992 char *buf_start = buf;
7994 if (VEC_empty (agent_expr_p, bp_tgt->conditions))
7997 buf += strlen (buf);
7998 xsnprintf (buf, buf_end - buf, "%s", ";");
8001 /* Send conditions to the target and free the vector. */
8003 VEC_iterate (agent_expr_p, bp_tgt->conditions, ix, aexpr);
8006 xsnprintf (buf, buf_end - buf, "X%x,", aexpr->len);
8007 buf += strlen (buf);
8008 for (i = 0; i < aexpr->len; ++i)
8009 buf = pack_hex_byte (buf, aexpr->buf[i]);
8016 remote_add_target_side_commands (struct gdbarch *gdbarch,
8017 struct bp_target_info *bp_tgt, char *buf)
8019 struct agent_expr *aexpr = NULL;
8022 if (VEC_empty (agent_expr_p, bp_tgt->tcommands))
8025 buf += strlen (buf);
8027 sprintf (buf, ";cmds:%x,", bp_tgt->persist);
8028 buf += strlen (buf);
8030 /* Concatenate all the agent expressions that are commands into the
8033 VEC_iterate (agent_expr_p, bp_tgt->tcommands, ix, aexpr);
8036 sprintf (buf, "X%x,", aexpr->len);
8037 buf += strlen (buf);
8038 for (i = 0; i < aexpr->len; ++i)
8039 buf = pack_hex_byte (buf, aexpr->buf[i]);
8044 /* Insert a breakpoint. On targets that have software breakpoint
8045 support, we ask the remote target to do the work; on targets
8046 which don't, we insert a traditional memory breakpoint. */
8049 remote_insert_breakpoint (struct target_ops *ops,
8050 struct gdbarch *gdbarch,
8051 struct bp_target_info *bp_tgt)
8053 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8054 If it succeeds, then set the support to PACKET_ENABLE. If it
8055 fails, and the user has explicitly requested the Z support then
8056 report an error, otherwise, mark it disabled and go on. */
8058 if (remote_protocol_packets[PACKET_Z0].support != PACKET_DISABLE)
8060 CORE_ADDR addr = bp_tgt->placed_address;
8061 struct remote_state *rs;
8064 struct condition_list *cond = NULL;
8066 /* Make sure the remote is pointing at the right process, if
8068 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8069 set_general_process ();
8071 gdbarch_remote_breakpoint_from_pc (gdbarch, &addr, &bpsize);
8073 rs = get_remote_state ();
8075 endbuf = rs->buf + get_remote_packet_size ();
8080 addr = (ULONGEST) remote_address_masked (addr);
8081 p += hexnumstr (p, addr);
8082 xsnprintf (p, endbuf - p, ",%d", bpsize);
8084 if (remote_supports_cond_breakpoints (ops))
8085 remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
8087 if (remote_can_run_breakpoint_commands (ops))
8088 remote_add_target_side_commands (gdbarch, bp_tgt, p);
8091 getpkt (&rs->buf, &rs->buf_size, 0);
8093 switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z0]))
8098 bp_tgt->placed_address = addr;
8099 bp_tgt->placed_size = bpsize;
8101 case PACKET_UNKNOWN:
8106 /* If this breakpoint has target-side commands but this stub doesn't
8107 support Z0 packets, throw error. */
8108 if (!VEC_empty (agent_expr_p, bp_tgt->tcommands))
8109 throw_error (NOT_SUPPORTED_ERROR, _("\
8110 Target doesn't support breakpoints that have target side commands."));
8112 return memory_insert_breakpoint (ops, gdbarch, bp_tgt);
8116 remote_remove_breakpoint (struct target_ops *ops,
8117 struct gdbarch *gdbarch,
8118 struct bp_target_info *bp_tgt)
8120 CORE_ADDR addr = bp_tgt->placed_address;
8121 struct remote_state *rs = get_remote_state ();
8123 if (remote_protocol_packets[PACKET_Z0].support != PACKET_DISABLE)
8126 char *endbuf = rs->buf + get_remote_packet_size ();
8128 /* Make sure the remote is pointing at the right process, if
8130 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8131 set_general_process ();
8137 addr = (ULONGEST) remote_address_masked (bp_tgt->placed_address);
8138 p += hexnumstr (p, addr);
8139 xsnprintf (p, endbuf - p, ",%d", bp_tgt->placed_size);
8142 getpkt (&rs->buf, &rs->buf_size, 0);
8144 return (rs->buf[0] == 'E');
8147 return memory_remove_breakpoint (ops, gdbarch, bp_tgt);
8151 watchpoint_to_Z_packet (int type)
8156 return Z_PACKET_WRITE_WP;
8159 return Z_PACKET_READ_WP;
8162 return Z_PACKET_ACCESS_WP;
8165 internal_error (__FILE__, __LINE__,
8166 _("hw_bp_to_z: bad watchpoint type %d"), type);
8171 remote_insert_watchpoint (struct target_ops *self,
8172 CORE_ADDR addr, int len, int type,
8173 struct expression *cond)
8175 struct remote_state *rs = get_remote_state ();
8176 char *endbuf = rs->buf + get_remote_packet_size ();
8178 enum Z_packet_type packet = watchpoint_to_Z_packet (type);
8180 if (remote_protocol_packets[PACKET_Z0 + packet].support == PACKET_DISABLE)
8183 /* Make sure the remote is pointing at the right process, if
8185 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8186 set_general_process ();
8188 xsnprintf (rs->buf, endbuf - rs->buf, "Z%x,", packet);
8189 p = strchr (rs->buf, '\0');
8190 addr = remote_address_masked (addr);
8191 p += hexnumstr (p, (ULONGEST) addr);
8192 xsnprintf (p, endbuf - p, ",%x", len);
8195 getpkt (&rs->buf, &rs->buf_size, 0);
8197 switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z0 + packet]))
8201 case PACKET_UNKNOWN:
8206 internal_error (__FILE__, __LINE__,
8207 _("remote_insert_watchpoint: reached end of function"));
8211 remote_watchpoint_addr_within_range (struct target_ops *target, CORE_ADDR addr,
8212 CORE_ADDR start, int length)
8214 CORE_ADDR diff = remote_address_masked (addr - start);
8216 return diff < length;
8221 remote_remove_watchpoint (struct target_ops *self,
8222 CORE_ADDR addr, int len, int type,
8223 struct expression *cond)
8225 struct remote_state *rs = get_remote_state ();
8226 char *endbuf = rs->buf + get_remote_packet_size ();
8228 enum Z_packet_type packet = watchpoint_to_Z_packet (type);
8230 if (remote_protocol_packets[PACKET_Z0 + packet].support == PACKET_DISABLE)
8233 /* Make sure the remote is pointing at the right process, if
8235 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8236 set_general_process ();
8238 xsnprintf (rs->buf, endbuf - rs->buf, "z%x,", packet);
8239 p = strchr (rs->buf, '\0');
8240 addr = remote_address_masked (addr);
8241 p += hexnumstr (p, (ULONGEST) addr);
8242 xsnprintf (p, endbuf - p, ",%x", len);
8244 getpkt (&rs->buf, &rs->buf_size, 0);
8246 switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z0 + packet]))
8249 case PACKET_UNKNOWN:
8254 internal_error (__FILE__, __LINE__,
8255 _("remote_remove_watchpoint: reached end of function"));
8259 int remote_hw_watchpoint_limit = -1;
8260 int remote_hw_watchpoint_length_limit = -1;
8261 int remote_hw_breakpoint_limit = -1;
8264 remote_region_ok_for_hw_watchpoint (struct target_ops *self,
8265 CORE_ADDR addr, int len)
8267 if (remote_hw_watchpoint_length_limit == 0)
8269 else if (remote_hw_watchpoint_length_limit < 0)
8271 else if (len <= remote_hw_watchpoint_length_limit)
8278 remote_check_watch_resources (struct target_ops *self,
8279 int type, int cnt, int ot)
8281 if (type == bp_hardware_breakpoint)
8283 if (remote_hw_breakpoint_limit == 0)
8285 else if (remote_hw_breakpoint_limit < 0)
8287 else if (cnt <= remote_hw_breakpoint_limit)
8292 if (remote_hw_watchpoint_limit == 0)
8294 else if (remote_hw_watchpoint_limit < 0)
8298 else if (cnt <= remote_hw_watchpoint_limit)
8305 remote_stopped_by_watchpoint (struct target_ops *ops)
8307 struct remote_state *rs = get_remote_state ();
8309 return rs->remote_stopped_by_watchpoint_p;
8313 remote_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
8315 struct remote_state *rs = get_remote_state ();
8318 if (remote_stopped_by_watchpoint (target))
8320 *addr_p = rs->remote_watch_data_address;
8329 remote_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
8330 struct bp_target_info *bp_tgt)
8333 struct remote_state *rs;
8337 /* The length field should be set to the size of a breakpoint
8338 instruction, even though we aren't inserting one ourselves. */
8340 gdbarch_remote_breakpoint_from_pc
8341 (gdbarch, &bp_tgt->placed_address, &bp_tgt->placed_size);
8343 if (remote_protocol_packets[PACKET_Z1].support == PACKET_DISABLE)
8346 /* Make sure the remote is pointing at the right process, if
8348 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8349 set_general_process ();
8351 rs = get_remote_state ();
8353 endbuf = rs->buf + get_remote_packet_size ();
8359 addr = remote_address_masked (bp_tgt->placed_address);
8360 p += hexnumstr (p, (ULONGEST) addr);
8361 xsnprintf (p, endbuf - p, ",%x", bp_tgt->placed_size);
8363 if (remote_supports_cond_breakpoints (self))
8364 remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
8366 if (remote_can_run_breakpoint_commands (self))
8367 remote_add_target_side_commands (gdbarch, bp_tgt, p);
8370 getpkt (&rs->buf, &rs->buf_size, 0);
8372 switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z1]))
8375 if (rs->buf[1] == '.')
8377 message = strchr (rs->buf + 2, '.');
8379 error (_("Remote failure reply: %s"), message + 1);
8382 case PACKET_UNKNOWN:
8387 internal_error (__FILE__, __LINE__,
8388 _("remote_insert_hw_breakpoint: reached end of function"));
8393 remote_remove_hw_breakpoint (struct target_ops *self, struct gdbarch *gdbarch,
8394 struct bp_target_info *bp_tgt)
8397 struct remote_state *rs = get_remote_state ();
8399 char *endbuf = rs->buf + get_remote_packet_size ();
8401 if (remote_protocol_packets[PACKET_Z1].support == PACKET_DISABLE)
8404 /* Make sure the remote is pointing at the right process, if
8406 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8407 set_general_process ();
8413 addr = remote_address_masked (bp_tgt->placed_address);
8414 p += hexnumstr (p, (ULONGEST) addr);
8415 xsnprintf (p, endbuf - p, ",%x", bp_tgt->placed_size);
8418 getpkt (&rs->buf, &rs->buf_size, 0);
8420 switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z1]))
8423 case PACKET_UNKNOWN:
8428 internal_error (__FILE__, __LINE__,
8429 _("remote_remove_hw_breakpoint: reached end of function"));
8432 /* Verify memory using the "qCRC:" request. */
8435 remote_verify_memory (struct target_ops *ops,
8436 const gdb_byte *data, CORE_ADDR lma, ULONGEST size)
8438 struct remote_state *rs = get_remote_state ();
8439 unsigned long host_crc, target_crc;
8442 /* Make sure the remote is pointing at the right process. */
8443 set_general_process ();
8445 /* FIXME: assumes lma can fit into long. */
8446 xsnprintf (rs->buf, get_remote_packet_size (), "qCRC:%lx,%lx",
8447 (long) lma, (long) size);
8450 /* Be clever; compute the host_crc before waiting for target
8452 host_crc = xcrc32 (data, size, 0xffffffff);
8454 getpkt (&rs->buf, &rs->buf_size, 0);
8455 if (rs->buf[0] == 'E')
8458 if (rs->buf[0] != 'C')
8459 error (_("remote target does not support this operation"));
8461 for (target_crc = 0, tmp = &rs->buf[1]; *tmp; tmp++)
8462 target_crc = target_crc * 16 + fromhex (*tmp);
8464 return (host_crc == target_crc);
8467 /* compare-sections command
8469 With no arguments, compares each loadable section in the exec bfd
8470 with the same memory range on the target, and reports mismatches.
8471 Useful for verifying the image on the target against the exec file. */
8474 compare_sections_command (char *args, int from_tty)
8477 struct cleanup *old_chain;
8479 const char *sectname;
8487 error (_("command cannot be used without an exec file"));
8489 /* Make sure the remote is pointing at the right process. */
8490 set_general_process ();
8492 for (s = exec_bfd->sections; s; s = s->next)
8494 if (!(s->flags & SEC_LOAD))
8495 continue; /* Skip non-loadable section. */
8497 size = bfd_get_section_size (s);
8499 continue; /* Skip zero-length section. */
8501 sectname = bfd_get_section_name (exec_bfd, s);
8502 if (args && strcmp (args, sectname) != 0)
8503 continue; /* Not the section selected by user. */
8505 matched = 1; /* Do this section. */
8508 sectdata = xmalloc (size);
8509 old_chain = make_cleanup (xfree, sectdata);
8510 bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
8512 res = target_verify_memory (sectdata, lma, size);
8515 error (_("target memory fault, section %s, range %s -- %s"), sectname,
8516 paddress (target_gdbarch (), lma),
8517 paddress (target_gdbarch (), lma + size));
8519 printf_filtered ("Section %s, range %s -- %s: ", sectname,
8520 paddress (target_gdbarch (), lma),
8521 paddress (target_gdbarch (), lma + size));
8523 printf_filtered ("matched.\n");
8526 printf_filtered ("MIS-MATCHED!\n");
8530 do_cleanups (old_chain);
8533 warning (_("One or more sections of the remote executable does not match\n\
8534 the loaded file\n"));
8535 if (args && !matched)
8536 printf_filtered (_("No loaded section named '%s'.\n"), args);
8539 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8540 into remote target. The number of bytes written to the remote
8541 target is returned, or -1 for error. */
8543 static enum target_xfer_status
8544 remote_write_qxfer (struct target_ops *ops, const char *object_name,
8545 const char *annex, const gdb_byte *writebuf,
8546 ULONGEST offset, LONGEST len, ULONGEST *xfered_len,
8547 struct packet_config *packet)
8551 struct remote_state *rs = get_remote_state ();
8552 int max_size = get_memory_write_packet_size ();
8554 if (packet->support == PACKET_DISABLE)
8555 return TARGET_XFER_E_IO;
8557 /* Insert header. */
8558 i = snprintf (rs->buf, max_size,
8559 "qXfer:%s:write:%s:%s:",
8560 object_name, annex ? annex : "",
8561 phex_nz (offset, sizeof offset));
8562 max_size -= (i + 1);
8564 /* Escape as much data as fits into rs->buf. */
8565 buf_len = remote_escape_output
8566 (writebuf, len, (gdb_byte *) rs->buf + i, &max_size, max_size);
8568 if (putpkt_binary (rs->buf, i + buf_len) < 0
8569 || getpkt_sane (&rs->buf, &rs->buf_size, 0) < 0
8570 || packet_ok (rs->buf, packet) != PACKET_OK)
8571 return TARGET_XFER_E_IO;
8573 unpack_varlen_hex (rs->buf, &n);
8576 return TARGET_XFER_OK;
8579 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8580 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8581 number of bytes read is returned, or 0 for EOF, or -1 for error.
8582 The number of bytes read may be less than LEN without indicating an
8583 EOF. PACKET is checked and updated to indicate whether the remote
8584 target supports this object. */
8586 static enum target_xfer_status
8587 remote_read_qxfer (struct target_ops *ops, const char *object_name,
8589 gdb_byte *readbuf, ULONGEST offset, LONGEST len,
8590 ULONGEST *xfered_len,
8591 struct packet_config *packet)
8593 struct remote_state *rs = get_remote_state ();
8594 LONGEST i, n, packet_len;
8596 if (packet->support == PACKET_DISABLE)
8597 return TARGET_XFER_E_IO;
8599 /* Check whether we've cached an end-of-object packet that matches
8601 if (rs->finished_object)
8603 if (strcmp (object_name, rs->finished_object) == 0
8604 && strcmp (annex ? annex : "", rs->finished_annex) == 0
8605 && offset == rs->finished_offset)
8606 return TARGET_XFER_EOF;
8609 /* Otherwise, we're now reading something different. Discard
8611 xfree (rs->finished_object);
8612 xfree (rs->finished_annex);
8613 rs->finished_object = NULL;
8614 rs->finished_annex = NULL;
8617 /* Request only enough to fit in a single packet. The actual data
8618 may not, since we don't know how much of it will need to be escaped;
8619 the target is free to respond with slightly less data. We subtract
8620 five to account for the response type and the protocol frame. */
8621 n = min (get_remote_packet_size () - 5, len);
8622 snprintf (rs->buf, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8623 object_name, annex ? annex : "",
8624 phex_nz (offset, sizeof offset),
8625 phex_nz (n, sizeof n));
8626 i = putpkt (rs->buf);
8628 return TARGET_XFER_E_IO;
8631 packet_len = getpkt_sane (&rs->buf, &rs->buf_size, 0);
8632 if (packet_len < 0 || packet_ok (rs->buf, packet) != PACKET_OK)
8633 return TARGET_XFER_E_IO;
8635 if (rs->buf[0] != 'l' && rs->buf[0] != 'm')
8636 error (_("Unknown remote qXfer reply: %s"), rs->buf);
8638 /* 'm' means there is (or at least might be) more data after this
8639 batch. That does not make sense unless there's at least one byte
8640 of data in this reply. */
8641 if (rs->buf[0] == 'm' && packet_len == 1)
8642 error (_("Remote qXfer reply contained no data."));
8644 /* Got some data. */
8645 i = remote_unescape_input ((gdb_byte *) rs->buf + 1,
8646 packet_len - 1, readbuf, n);
8648 /* 'l' is an EOF marker, possibly including a final block of data,
8649 or possibly empty. If we have the final block of a non-empty
8650 object, record this fact to bypass a subsequent partial read. */
8651 if (rs->buf[0] == 'l' && offset + i > 0)
8653 rs->finished_object = xstrdup (object_name);
8654 rs->finished_annex = xstrdup (annex ? annex : "");
8655 rs->finished_offset = offset + i;
8659 return TARGET_XFER_EOF;
8663 return TARGET_XFER_OK;
8667 static enum target_xfer_status
8668 remote_xfer_partial (struct target_ops *ops, enum target_object object,
8669 const char *annex, gdb_byte *readbuf,
8670 const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
8671 ULONGEST *xfered_len)
8673 struct remote_state *rs;
8678 set_remote_traceframe ();
8679 set_general_thread (inferior_ptid);
8681 rs = get_remote_state ();
8683 /* Handle memory using the standard memory routines. */
8684 if (object == TARGET_OBJECT_MEMORY)
8686 /* If the remote target is connected but not running, we should
8687 pass this request down to a lower stratum (e.g. the executable
8689 if (!target_has_execution)
8690 return TARGET_XFER_EOF;
8692 if (writebuf != NULL)
8693 return remote_write_bytes (offset, writebuf, len, xfered_len);
8695 return remote_read_bytes (offset, readbuf, len, xfered_len);
8698 /* Handle SPU memory using qxfer packets. */
8699 if (object == TARGET_OBJECT_SPU)
8702 return remote_read_qxfer (ops, "spu", annex, readbuf, offset, len,
8703 xfered_len, &remote_protocol_packets
8704 [PACKET_qXfer_spu_read]);
8706 return remote_write_qxfer (ops, "spu", annex, writebuf, offset, len,
8707 xfered_len, &remote_protocol_packets
8708 [PACKET_qXfer_spu_write]);
8711 /* Handle extra signal info using qxfer packets. */
8712 if (object == TARGET_OBJECT_SIGNAL_INFO)
8715 return remote_read_qxfer (ops, "siginfo", annex, readbuf, offset, len,
8716 xfered_len, &remote_protocol_packets
8717 [PACKET_qXfer_siginfo_read]);
8719 return remote_write_qxfer (ops, "siginfo", annex,
8720 writebuf, offset, len, xfered_len,
8721 &remote_protocol_packets
8722 [PACKET_qXfer_siginfo_write]);
8725 if (object == TARGET_OBJECT_STATIC_TRACE_DATA)
8728 return remote_read_qxfer (ops, "statictrace", annex,
8729 readbuf, offset, len, xfered_len,
8730 &remote_protocol_packets
8731 [PACKET_qXfer_statictrace_read]);
8733 return TARGET_XFER_E_IO;
8736 /* Only handle flash writes. */
8737 if (writebuf != NULL)
8743 case TARGET_OBJECT_FLASH:
8744 return remote_flash_write (ops, offset, len, xfered_len,
8748 return TARGET_XFER_E_IO;
8752 /* Map pre-existing objects onto letters. DO NOT do this for new
8753 objects!!! Instead specify new query packets. */
8756 case TARGET_OBJECT_AVR:
8760 case TARGET_OBJECT_AUXV:
8761 gdb_assert (annex == NULL);
8762 return remote_read_qxfer (ops, "auxv", annex, readbuf, offset, len,
8764 &remote_protocol_packets[PACKET_qXfer_auxv]);
8766 case TARGET_OBJECT_AVAILABLE_FEATURES:
8767 return remote_read_qxfer
8768 (ops, "features", annex, readbuf, offset, len, xfered_len,
8769 &remote_protocol_packets[PACKET_qXfer_features]);
8771 case TARGET_OBJECT_LIBRARIES:
8772 return remote_read_qxfer
8773 (ops, "libraries", annex, readbuf, offset, len, xfered_len,
8774 &remote_protocol_packets[PACKET_qXfer_libraries]);
8776 case TARGET_OBJECT_LIBRARIES_SVR4:
8777 return remote_read_qxfer
8778 (ops, "libraries-svr4", annex, readbuf, offset, len, xfered_len,
8779 &remote_protocol_packets[PACKET_qXfer_libraries_svr4]);
8781 case TARGET_OBJECT_MEMORY_MAP:
8782 gdb_assert (annex == NULL);
8783 return remote_read_qxfer (ops, "memory-map", annex, readbuf, offset, len,
8785 &remote_protocol_packets[PACKET_qXfer_memory_map]);
8787 case TARGET_OBJECT_OSDATA:
8788 /* Should only get here if we're connected. */
8789 gdb_assert (rs->remote_desc);
8790 return remote_read_qxfer
8791 (ops, "osdata", annex, readbuf, offset, len, xfered_len,
8792 &remote_protocol_packets[PACKET_qXfer_osdata]);
8794 case TARGET_OBJECT_THREADS:
8795 gdb_assert (annex == NULL);
8796 return remote_read_qxfer (ops, "threads", annex, readbuf, offset, len,
8798 &remote_protocol_packets[PACKET_qXfer_threads]);
8800 case TARGET_OBJECT_TRACEFRAME_INFO:
8801 gdb_assert (annex == NULL);
8802 return remote_read_qxfer
8803 (ops, "traceframe-info", annex, readbuf, offset, len, xfered_len,
8804 &remote_protocol_packets[PACKET_qXfer_traceframe_info]);
8806 case TARGET_OBJECT_FDPIC:
8807 return remote_read_qxfer (ops, "fdpic", annex, readbuf, offset, len,
8809 &remote_protocol_packets[PACKET_qXfer_fdpic]);
8811 case TARGET_OBJECT_OPENVMS_UIB:
8812 return remote_read_qxfer (ops, "uib", annex, readbuf, offset, len,
8814 &remote_protocol_packets[PACKET_qXfer_uib]);
8816 case TARGET_OBJECT_BTRACE:
8817 return remote_read_qxfer (ops, "btrace", annex, readbuf, offset, len,
8819 &remote_protocol_packets[PACKET_qXfer_btrace]);
8822 return TARGET_XFER_E_IO;
8825 /* Note: a zero OFFSET and LEN can be used to query the minimum
8827 if (offset == 0 && len == 0)
8828 return (get_remote_packet_size ());
8829 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8830 large enough let the caller deal with it. */
8831 if (len < get_remote_packet_size ())
8832 return TARGET_XFER_E_IO;
8833 len = get_remote_packet_size ();
8835 /* Except for querying the minimum buffer size, target must be open. */
8836 if (!rs->remote_desc)
8837 error (_("remote query is only available after target open"));
8839 gdb_assert (annex != NULL);
8840 gdb_assert (readbuf != NULL);
8846 /* We used one buffer char for the remote protocol q command and
8847 another for the query type. As the remote protocol encapsulation
8848 uses 4 chars plus one extra in case we are debugging
8849 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8852 while (annex[i] && (i < (get_remote_packet_size () - 8)))
8854 /* Bad caller may have sent forbidden characters. */
8855 gdb_assert (isprint (annex[i]) && annex[i] != '$' && annex[i] != '#');
8860 gdb_assert (annex[i] == '\0');
8862 i = putpkt (rs->buf);
8864 return TARGET_XFER_E_IO;
8866 getpkt (&rs->buf, &rs->buf_size, 0);
8867 strcpy ((char *) readbuf, rs->buf);
8869 *xfered_len = strlen ((char *) readbuf);
8870 return TARGET_XFER_OK;
8874 remote_search_memory (struct target_ops* ops,
8875 CORE_ADDR start_addr, ULONGEST search_space_len,
8876 const gdb_byte *pattern, ULONGEST pattern_len,
8877 CORE_ADDR *found_addrp)
8879 int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
8880 struct remote_state *rs = get_remote_state ();
8881 int max_size = get_memory_write_packet_size ();
8882 struct packet_config *packet =
8883 &remote_protocol_packets[PACKET_qSearch_memory];
8884 /* Number of packet bytes used to encode the pattern;
8885 this could be more than PATTERN_LEN due to escape characters. */
8886 int escaped_pattern_len;
8887 /* Amount of pattern that was encodable in the packet. */
8888 int used_pattern_len;
8891 ULONGEST found_addr;
8893 /* Don't go to the target if we don't have to.
8894 This is done before checking packet->support to avoid the possibility that
8895 a success for this edge case means the facility works in general. */
8896 if (pattern_len > search_space_len)
8898 if (pattern_len == 0)
8900 *found_addrp = start_addr;
8904 /* If we already know the packet isn't supported, fall back to the simple
8905 way of searching memory. */
8907 if (packet->support == PACKET_DISABLE)
8909 /* Target doesn't provided special support, fall back and use the
8910 standard support (copy memory and do the search here). */
8911 return simple_search_memory (ops, start_addr, search_space_len,
8912 pattern, pattern_len, found_addrp);
8915 /* Make sure the remote is pointing at the right process. */
8916 set_general_process ();
8918 /* Insert header. */
8919 i = snprintf (rs->buf, max_size,
8920 "qSearch:memory:%s;%s;",
8921 phex_nz (start_addr, addr_size),
8922 phex_nz (search_space_len, sizeof (search_space_len)));
8923 max_size -= (i + 1);
8925 /* Escape as much data as fits into rs->buf. */
8926 escaped_pattern_len =
8927 remote_escape_output (pattern, pattern_len, (gdb_byte *) rs->buf + i,
8928 &used_pattern_len, max_size);
8930 /* Bail if the pattern is too large. */
8931 if (used_pattern_len != pattern_len)
8932 error (_("Pattern is too large to transmit to remote target."));
8934 if (putpkt_binary (rs->buf, i + escaped_pattern_len) < 0
8935 || getpkt_sane (&rs->buf, &rs->buf_size, 0) < 0
8936 || packet_ok (rs->buf, packet) != PACKET_OK)
8938 /* The request may not have worked because the command is not
8939 supported. If so, fall back to the simple way. */
8940 if (packet->support == PACKET_DISABLE)
8942 return simple_search_memory (ops, start_addr, search_space_len,
8943 pattern, pattern_len, found_addrp);
8948 if (rs->buf[0] == '0')
8950 else if (rs->buf[0] == '1')
8953 if (rs->buf[1] != ',')
8954 error (_("Unknown qSearch:memory reply: %s"), rs->buf);
8955 unpack_varlen_hex (rs->buf + 2, &found_addr);
8956 *found_addrp = found_addr;
8959 error (_("Unknown qSearch:memory reply: %s"), rs->buf);
8965 remote_rcmd (struct target_ops *self, char *command,
8966 struct ui_file *outbuf)
8968 struct remote_state *rs = get_remote_state ();
8971 if (!rs->remote_desc)
8972 error (_("remote rcmd is only available after target open"));
8974 /* Send a NULL command across as an empty command. */
8975 if (command == NULL)
8978 /* The query prefix. */
8979 strcpy (rs->buf, "qRcmd,");
8980 p = strchr (rs->buf, '\0');
8982 if ((strlen (rs->buf) + strlen (command) * 2 + 8/*misc*/)
8983 > get_remote_packet_size ())
8984 error (_("\"monitor\" command ``%s'' is too long."), command);
8986 /* Encode the actual command. */
8987 bin2hex ((gdb_byte *) command, p, strlen (command));
8989 if (putpkt (rs->buf) < 0)
8990 error (_("Communication problem with target."));
8992 /* get/display the response */
8997 /* XXX - see also remote_get_noisy_reply(). */
8998 QUIT; /* Allow user to bail out with ^C. */
9000 if (getpkt_sane (&rs->buf, &rs->buf_size, 0) == -1)
9002 /* Timeout. Continue to (try to) read responses.
9003 This is better than stopping with an error, assuming the stub
9004 is still executing the (long) monitor command.
9005 If needed, the user can interrupt gdb using C-c, obtaining
9006 an effect similar to stop on timeout. */
9011 error (_("Target does not support this command."));
9012 if (buf[0] == 'O' && buf[1] != 'K')
9014 remote_console_output (buf + 1); /* 'O' message from stub. */
9017 if (strcmp (buf, "OK") == 0)
9019 if (strlen (buf) == 3 && buf[0] == 'E'
9020 && isdigit (buf[1]) && isdigit (buf[2]))
9022 error (_("Protocol error with Rcmd"));
9024 for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
9026 char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
9028 fputc_unfiltered (c, outbuf);
9034 static VEC(mem_region_s) *
9035 remote_memory_map (struct target_ops *ops)
9037 VEC(mem_region_s) *result = NULL;
9038 char *text = target_read_stralloc (¤t_target,
9039 TARGET_OBJECT_MEMORY_MAP, NULL);
9043 struct cleanup *back_to = make_cleanup (xfree, text);
9045 result = parse_memory_map (text);
9046 do_cleanups (back_to);
9053 packet_command (char *args, int from_tty)
9055 struct remote_state *rs = get_remote_state ();
9057 if (!rs->remote_desc)
9058 error (_("command can only be used with remote target"));
9061 error (_("remote-packet command requires packet text as argument"));
9063 puts_filtered ("sending: ");
9064 print_packet (args);
9065 puts_filtered ("\n");
9068 getpkt (&rs->buf, &rs->buf_size, 0);
9069 puts_filtered ("received: ");
9070 print_packet (rs->buf);
9071 puts_filtered ("\n");
9075 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9077 static void display_thread_info (struct gdb_ext_thread_info *info);
9079 static void threadset_test_cmd (char *cmd, int tty);
9081 static void threadalive_test (char *cmd, int tty);
9083 static void threadlist_test_cmd (char *cmd, int tty);
9085 int get_and_display_threadinfo (threadref *ref);
9087 static void threadinfo_test_cmd (char *cmd, int tty);
9089 static int thread_display_step (threadref *ref, void *context);
9091 static void threadlist_update_test_cmd (char *cmd, int tty);
9093 static void init_remote_threadtests (void);
9095 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9098 threadset_test_cmd (char *cmd, int tty)
9100 int sample_thread = SAMPLE_THREAD;
9102 printf_filtered (_("Remote threadset test\n"));
9103 set_general_thread (sample_thread);
9108 threadalive_test (char *cmd, int tty)
9110 int sample_thread = SAMPLE_THREAD;
9111 int pid = ptid_get_pid (inferior_ptid);
9112 ptid_t ptid = ptid_build (pid, 0, sample_thread);
9114 if (remote_thread_alive (ptid))
9115 printf_filtered ("PASS: Thread alive test\n");
9117 printf_filtered ("FAIL: Thread alive test\n");
9120 void output_threadid (char *title, threadref *ref);
9123 output_threadid (char *title, threadref *ref)
9127 pack_threadid (&hexid[0], ref); /* Convert threead id into hex. */
9129 printf_filtered ("%s %s\n", title, (&hexid[0]));
9133 threadlist_test_cmd (char *cmd, int tty)
9136 threadref nextthread;
9137 int done, result_count;
9138 threadref threadlist[3];
9140 printf_filtered ("Remote Threadlist test\n");
9141 if (!remote_get_threadlist (startflag, &nextthread, 3, &done,
9142 &result_count, &threadlist[0]))
9143 printf_filtered ("FAIL: threadlist test\n");
9146 threadref *scan = threadlist;
9147 threadref *limit = scan + result_count;
9149 while (scan < limit)
9150 output_threadid (" thread ", scan++);
9155 display_thread_info (struct gdb_ext_thread_info *info)
9157 output_threadid ("Threadid: ", &info->threadid);
9158 printf_filtered ("Name: %s\n ", info->shortname);
9159 printf_filtered ("State: %s\n", info->display);
9160 printf_filtered ("other: %s\n\n", info->more_display);
9164 get_and_display_threadinfo (threadref *ref)
9168 struct gdb_ext_thread_info threadinfo;
9170 set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
9171 | TAG_MOREDISPLAY | TAG_DISPLAY;
9172 if (0 != (result = remote_get_threadinfo (ref, set, &threadinfo)))
9173 display_thread_info (&threadinfo);
9178 threadinfo_test_cmd (char *cmd, int tty)
9180 int athread = SAMPLE_THREAD;
9184 int_to_threadref (&thread, athread);
9185 printf_filtered ("Remote Threadinfo test\n");
9186 if (!get_and_display_threadinfo (&thread))
9187 printf_filtered ("FAIL cannot get thread info\n");
9191 thread_display_step (threadref *ref, void *context)
9193 /* output_threadid(" threadstep ",ref); *//* simple test */
9194 return get_and_display_threadinfo (ref);
9198 threadlist_update_test_cmd (char *cmd, int tty)
9200 printf_filtered ("Remote Threadlist update test\n");
9201 remote_threadlist_iterator (thread_display_step, 0, CRAZY_MAX_THREADS);
9205 init_remote_threadtests (void)
9207 add_com ("tlist", class_obscure, threadlist_test_cmd,
9208 _("Fetch and print the remote list of "
9209 "thread identifiers, one pkt only"));
9210 add_com ("tinfo", class_obscure, threadinfo_test_cmd,
9211 _("Fetch and display info about one thread"));
9212 add_com ("tset", class_obscure, threadset_test_cmd,
9213 _("Test setting to a different thread"));
9214 add_com ("tupd", class_obscure, threadlist_update_test_cmd,
9215 _("Iterate through updating all remote thread info"));
9216 add_com ("talive", class_obscure, threadalive_test,
9217 _(" Remote thread alive test "));
9222 /* Convert a thread ID to a string. Returns the string in a static
9226 remote_pid_to_str (struct target_ops *ops, ptid_t ptid)
9228 static char buf[64];
9229 struct remote_state *rs = get_remote_state ();
9231 if (ptid_equal (ptid, null_ptid))
9232 return normal_pid_to_str (ptid);
9233 else if (ptid_is_pid (ptid))
9235 /* Printing an inferior target id. */
9237 /* When multi-process extensions are off, there's no way in the
9238 remote protocol to know the remote process id, if there's any
9239 at all. There's one exception --- when we're connected with
9240 target extended-remote, and we manually attached to a process
9241 with "attach PID". We don't record anywhere a flag that
9242 allows us to distinguish that case from the case of
9243 connecting with extended-remote and the stub already being
9244 attached to a process, and reporting yes to qAttached, hence
9245 no smart special casing here. */
9246 if (!remote_multi_process_p (rs))
9248 xsnprintf (buf, sizeof buf, "Remote target");
9252 return normal_pid_to_str (ptid);
9256 if (ptid_equal (magic_null_ptid, ptid))
9257 xsnprintf (buf, sizeof buf, "Thread <main>");
9258 else if (rs->extended && remote_multi_process_p (rs))
9259 xsnprintf (buf, sizeof buf, "Thread %d.%ld",
9260 ptid_get_pid (ptid), ptid_get_tid (ptid));
9262 xsnprintf (buf, sizeof buf, "Thread %ld",
9263 ptid_get_tid (ptid));
9268 /* Get the address of the thread local variable in OBJFILE which is
9269 stored at OFFSET within the thread local storage for thread PTID. */
9272 remote_get_thread_local_address (struct target_ops *ops,
9273 ptid_t ptid, CORE_ADDR lm, CORE_ADDR offset)
9275 if (remote_protocol_packets[PACKET_qGetTLSAddr].support != PACKET_DISABLE)
9277 struct remote_state *rs = get_remote_state ();
9279 char *endp = rs->buf + get_remote_packet_size ();
9280 enum packet_result result;
9282 strcpy (p, "qGetTLSAddr:");
9284 p = write_ptid (p, endp, ptid);
9286 p += hexnumstr (p, offset);
9288 p += hexnumstr (p, lm);
9292 getpkt (&rs->buf, &rs->buf_size, 0);
9293 result = packet_ok (rs->buf,
9294 &remote_protocol_packets[PACKET_qGetTLSAddr]);
9295 if (result == PACKET_OK)
9299 unpack_varlen_hex (rs->buf, &result);
9302 else if (result == PACKET_UNKNOWN)
9303 throw_error (TLS_GENERIC_ERROR,
9304 _("Remote target doesn't support qGetTLSAddr packet"));
9306 throw_error (TLS_GENERIC_ERROR,
9307 _("Remote target failed to process qGetTLSAddr request"));
9310 throw_error (TLS_GENERIC_ERROR,
9311 _("TLS not supported or disabled on this target"));
9316 /* Provide thread local base, i.e. Thread Information Block address.
9317 Returns 1 if ptid is found and thread_local_base is non zero. */
9320 remote_get_tib_address (ptid_t ptid, CORE_ADDR *addr)
9322 if (remote_protocol_packets[PACKET_qGetTIBAddr].support != PACKET_DISABLE)
9324 struct remote_state *rs = get_remote_state ();
9326 char *endp = rs->buf + get_remote_packet_size ();
9327 enum packet_result result;
9329 strcpy (p, "qGetTIBAddr:");
9331 p = write_ptid (p, endp, ptid);
9335 getpkt (&rs->buf, &rs->buf_size, 0);
9336 result = packet_ok (rs->buf,
9337 &remote_protocol_packets[PACKET_qGetTIBAddr]);
9338 if (result == PACKET_OK)
9342 unpack_varlen_hex (rs->buf, &result);
9344 *addr = (CORE_ADDR) result;
9347 else if (result == PACKET_UNKNOWN)
9348 error (_("Remote target doesn't support qGetTIBAddr packet"));
9350 error (_("Remote target failed to process qGetTIBAddr request"));
9353 error (_("qGetTIBAddr not supported or disabled on this target"));
9358 /* Support for inferring a target description based on the current
9359 architecture and the size of a 'g' packet. While the 'g' packet
9360 can have any size (since optional registers can be left off the
9361 end), some sizes are easily recognizable given knowledge of the
9362 approximate architecture. */
9364 struct remote_g_packet_guess
9367 const struct target_desc *tdesc;
9369 typedef struct remote_g_packet_guess remote_g_packet_guess_s;
9370 DEF_VEC_O(remote_g_packet_guess_s);
9372 struct remote_g_packet_data
9374 VEC(remote_g_packet_guess_s) *guesses;
9377 static struct gdbarch_data *remote_g_packet_data_handle;
9380 remote_g_packet_data_init (struct obstack *obstack)
9382 return OBSTACK_ZALLOC (obstack, struct remote_g_packet_data);
9386 register_remote_g_packet_guess (struct gdbarch *gdbarch, int bytes,
9387 const struct target_desc *tdesc)
9389 struct remote_g_packet_data *data
9390 = gdbarch_data (gdbarch, remote_g_packet_data_handle);
9391 struct remote_g_packet_guess new_guess, *guess;
9394 gdb_assert (tdesc != NULL);
9397 VEC_iterate (remote_g_packet_guess_s, data->guesses, ix, guess);
9399 if (guess->bytes == bytes)
9400 internal_error (__FILE__, __LINE__,
9401 _("Duplicate g packet description added for size %d"),
9404 new_guess.bytes = bytes;
9405 new_guess.tdesc = tdesc;
9406 VEC_safe_push (remote_g_packet_guess_s, data->guesses, &new_guess);
9409 /* Return 1 if remote_read_description would do anything on this target
9410 and architecture, 0 otherwise. */
9413 remote_read_description_p (struct target_ops *target)
9415 struct remote_g_packet_data *data
9416 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle);
9418 if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
9424 static const struct target_desc *
9425 remote_read_description (struct target_ops *target)
9427 struct remote_g_packet_data *data
9428 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle);
9430 /* Do not try this during initial connection, when we do not know
9431 whether there is a running but stopped thread. */
9432 if (!target_has_execution || ptid_equal (inferior_ptid, null_ptid))
9435 if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
9437 struct remote_g_packet_guess *guess;
9439 int bytes = send_g_packet ();
9442 VEC_iterate (remote_g_packet_guess_s, data->guesses, ix, guess);
9444 if (guess->bytes == bytes)
9445 return guess->tdesc;
9447 /* We discard the g packet. A minor optimization would be to
9448 hold on to it, and fill the register cache once we have selected
9449 an architecture, but it's too tricky to do safely. */
9455 /* Remote file transfer support. This is host-initiated I/O, not
9456 target-initiated; for target-initiated, see remote-fileio.c. */
9458 /* If *LEFT is at least the length of STRING, copy STRING to
9459 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9460 decrease *LEFT. Otherwise raise an error. */
9463 remote_buffer_add_string (char **buffer, int *left, char *string)
9465 int len = strlen (string);
9468 error (_("Packet too long for target."));
9470 memcpy (*buffer, string, len);
9474 /* NUL-terminate the buffer as a convenience, if there is
9480 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9481 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9482 decrease *LEFT. Otherwise raise an error. */
9485 remote_buffer_add_bytes (char **buffer, int *left, const gdb_byte *bytes,
9488 if (2 * len > *left)
9489 error (_("Packet too long for target."));
9491 bin2hex (bytes, *buffer, len);
9495 /* NUL-terminate the buffer as a convenience, if there is
9501 /* If *LEFT is large enough, convert VALUE to hex and add it to
9502 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9503 decrease *LEFT. Otherwise raise an error. */
9506 remote_buffer_add_int (char **buffer, int *left, ULONGEST value)
9508 int len = hexnumlen (value);
9511 error (_("Packet too long for target."));
9513 hexnumstr (*buffer, value);
9517 /* NUL-terminate the buffer as a convenience, if there is
9523 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9524 value, *REMOTE_ERRNO to the remote error number or zero if none
9525 was included, and *ATTACHMENT to point to the start of the annex
9526 if any. The length of the packet isn't needed here; there may
9527 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9529 Return 0 if the packet could be parsed, -1 if it could not. If
9530 -1 is returned, the other variables may not be initialized. */
9533 remote_hostio_parse_result (char *buffer, int *retcode,
9534 int *remote_errno, char **attachment)
9541 if (buffer[0] != 'F')
9545 *retcode = strtol (&buffer[1], &p, 16);
9546 if (errno != 0 || p == &buffer[1])
9549 /* Check for ",errno". */
9553 *remote_errno = strtol (p + 1, &p2, 16);
9554 if (errno != 0 || p + 1 == p2)
9559 /* Check for ";attachment". If there is no attachment, the
9560 packet should end here. */
9563 *attachment = p + 1;
9566 else if (*p == '\0')
9572 /* Send a prepared I/O packet to the target and read its response.
9573 The prepared packet is in the global RS->BUF before this function
9574 is called, and the answer is there when we return.
9576 COMMAND_BYTES is the length of the request to send, which may include
9577 binary data. WHICH_PACKET is the packet configuration to check
9578 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9579 is set to the error number and -1 is returned. Otherwise the value
9580 returned by the function is returned.
9582 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9583 attachment is expected; an error will be reported if there's a
9584 mismatch. If one is found, *ATTACHMENT will be set to point into
9585 the packet buffer and *ATTACHMENT_LEN will be set to the
9586 attachment's length. */
9589 remote_hostio_send_command (int command_bytes, int which_packet,
9590 int *remote_errno, char **attachment,
9591 int *attachment_len)
9593 struct remote_state *rs = get_remote_state ();
9594 int ret, bytes_read;
9595 char *attachment_tmp;
9597 if (!rs->remote_desc
9598 || remote_protocol_packets[which_packet].support == PACKET_DISABLE)
9600 *remote_errno = FILEIO_ENOSYS;
9604 putpkt_binary (rs->buf, command_bytes);
9605 bytes_read = getpkt_sane (&rs->buf, &rs->buf_size, 0);
9607 /* If it timed out, something is wrong. Don't try to parse the
9611 *remote_errno = FILEIO_EINVAL;
9615 switch (packet_ok (rs->buf, &remote_protocol_packets[which_packet]))
9618 *remote_errno = FILEIO_EINVAL;
9620 case PACKET_UNKNOWN:
9621 *remote_errno = FILEIO_ENOSYS;
9627 if (remote_hostio_parse_result (rs->buf, &ret, remote_errno,
9630 *remote_errno = FILEIO_EINVAL;
9634 /* Make sure we saw an attachment if and only if we expected one. */
9635 if ((attachment_tmp == NULL && attachment != NULL)
9636 || (attachment_tmp != NULL && attachment == NULL))
9638 *remote_errno = FILEIO_EINVAL;
9642 /* If an attachment was found, it must point into the packet buffer;
9643 work out how many bytes there were. */
9644 if (attachment_tmp != NULL)
9646 *attachment = attachment_tmp;
9647 *attachment_len = bytes_read - (*attachment - rs->buf);
9653 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9654 remote file descriptor, or -1 if an error occurs (and set
9658 remote_hostio_open (const char *filename, int flags, int mode,
9661 struct remote_state *rs = get_remote_state ();
9663 int left = get_remote_packet_size () - 1;
9665 remote_buffer_add_string (&p, &left, "vFile:open:");
9667 remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
9669 remote_buffer_add_string (&p, &left, ",");
9671 remote_buffer_add_int (&p, &left, flags);
9672 remote_buffer_add_string (&p, &left, ",");
9674 remote_buffer_add_int (&p, &left, mode);
9676 return remote_hostio_send_command (p - rs->buf, PACKET_vFile_open,
9677 remote_errno, NULL, NULL);
9680 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9681 Return the number of bytes written, or -1 if an error occurs (and
9682 set *REMOTE_ERRNO). */
9685 remote_hostio_pwrite (int fd, const gdb_byte *write_buf, int len,
9686 ULONGEST offset, int *remote_errno)
9688 struct remote_state *rs = get_remote_state ();
9690 int left = get_remote_packet_size ();
9693 remote_buffer_add_string (&p, &left, "vFile:pwrite:");
9695 remote_buffer_add_int (&p, &left, fd);
9696 remote_buffer_add_string (&p, &left, ",");
9698 remote_buffer_add_int (&p, &left, offset);
9699 remote_buffer_add_string (&p, &left, ",");
9701 p += remote_escape_output (write_buf, len, (gdb_byte *) p, &out_len,
9702 get_remote_packet_size () - (p - rs->buf));
9704 return remote_hostio_send_command (p - rs->buf, PACKET_vFile_pwrite,
9705 remote_errno, NULL, NULL);
9708 /* Read up to LEN bytes FD on the remote target into READ_BUF
9709 Return the number of bytes read, or -1 if an error occurs (and
9710 set *REMOTE_ERRNO). */
9713 remote_hostio_pread (int fd, gdb_byte *read_buf, int len,
9714 ULONGEST offset, int *remote_errno)
9716 struct remote_state *rs = get_remote_state ();
9719 int left = get_remote_packet_size ();
9720 int ret, attachment_len;
9723 remote_buffer_add_string (&p, &left, "vFile:pread:");
9725 remote_buffer_add_int (&p, &left, fd);
9726 remote_buffer_add_string (&p, &left, ",");
9728 remote_buffer_add_int (&p, &left, len);
9729 remote_buffer_add_string (&p, &left, ",");
9731 remote_buffer_add_int (&p, &left, offset);
9733 ret = remote_hostio_send_command (p - rs->buf, PACKET_vFile_pread,
9734 remote_errno, &attachment,
9740 read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len,
9742 if (read_len != ret)
9743 error (_("Read returned %d, but %d bytes."), ret, (int) read_len);
9748 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9749 (and set *REMOTE_ERRNO). */
9752 remote_hostio_close (int fd, int *remote_errno)
9754 struct remote_state *rs = get_remote_state ();
9756 int left = get_remote_packet_size () - 1;
9758 remote_buffer_add_string (&p, &left, "vFile:close:");
9760 remote_buffer_add_int (&p, &left, fd);
9762 return remote_hostio_send_command (p - rs->buf, PACKET_vFile_close,
9763 remote_errno, NULL, NULL);
9766 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9767 occurs (and set *REMOTE_ERRNO). */
9770 remote_hostio_unlink (const char *filename, int *remote_errno)
9772 struct remote_state *rs = get_remote_state ();
9774 int left = get_remote_packet_size () - 1;
9776 remote_buffer_add_string (&p, &left, "vFile:unlink:");
9778 remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
9781 return remote_hostio_send_command (p - rs->buf, PACKET_vFile_unlink,
9782 remote_errno, NULL, NULL);
9785 /* Read value of symbolic link FILENAME on the remote target. Return
9786 a null-terminated string allocated via xmalloc, or NULL if an error
9787 occurs (and set *REMOTE_ERRNO). */
9790 remote_hostio_readlink (const char *filename, int *remote_errno)
9792 struct remote_state *rs = get_remote_state ();
9795 int left = get_remote_packet_size ();
9796 int len, attachment_len;
9800 remote_buffer_add_string (&p, &left, "vFile:readlink:");
9802 remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
9805 len = remote_hostio_send_command (p - rs->buf, PACKET_vFile_readlink,
9806 remote_errno, &attachment,
9812 ret = xmalloc (len + 1);
9814 read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len,
9815 (gdb_byte *) ret, len);
9816 if (read_len != len)
9817 error (_("Readlink returned %d, but %d bytes."), len, read_len);
9824 remote_fileio_errno_to_host (int errnum)
9848 case FILEIO_ENOTDIR:
9868 case FILEIO_ENAMETOOLONG:
9869 return ENAMETOOLONG;
9875 remote_hostio_error (int errnum)
9877 int host_error = remote_fileio_errno_to_host (errnum);
9879 if (host_error == -1)
9880 error (_("Unknown remote I/O error %d"), errnum);
9882 error (_("Remote I/O error: %s"), safe_strerror (host_error));
9886 remote_hostio_close_cleanup (void *opaque)
9888 int fd = *(int *) opaque;
9891 remote_hostio_close (fd, &remote_errno);
9896 remote_bfd_iovec_open (struct bfd *abfd, void *open_closure)
9898 const char *filename = bfd_get_filename (abfd);
9899 int fd, remote_errno;
9902 gdb_assert (remote_filename_p (filename));
9904 fd = remote_hostio_open (filename + 7, FILEIO_O_RDONLY, 0, &remote_errno);
9907 errno = remote_fileio_errno_to_host (remote_errno);
9908 bfd_set_error (bfd_error_system_call);
9912 stream = xmalloc (sizeof (int));
9918 remote_bfd_iovec_close (struct bfd *abfd, void *stream)
9920 int fd = *(int *)stream;
9925 /* Ignore errors on close; these may happen if the remote
9926 connection was already torn down. */
9927 remote_hostio_close (fd, &remote_errno);
9929 /* Zero means success. */
9934 remote_bfd_iovec_pread (struct bfd *abfd, void *stream, void *buf,
9935 file_ptr nbytes, file_ptr offset)
9937 int fd = *(int *)stream;
9939 file_ptr pos, bytes;
9942 while (nbytes > pos)
9944 bytes = remote_hostio_pread (fd, (gdb_byte *) buf + pos, nbytes - pos,
9945 offset + pos, &remote_errno);
9947 /* Success, but no bytes, means end-of-file. */
9951 errno = remote_fileio_errno_to_host (remote_errno);
9952 bfd_set_error (bfd_error_system_call);
9963 remote_bfd_iovec_stat (struct bfd *abfd, void *stream, struct stat *sb)
9965 /* FIXME: We should probably implement remote_hostio_stat. */
9966 sb->st_size = INT_MAX;
9971 remote_filename_p (const char *filename)
9973 return strncmp (filename,
9974 REMOTE_SYSROOT_PREFIX,
9975 sizeof (REMOTE_SYSROOT_PREFIX) - 1) == 0;
9979 remote_bfd_open (const char *remote_file, const char *target)
9981 bfd *abfd = gdb_bfd_openr_iovec (remote_file, target,
9982 remote_bfd_iovec_open, NULL,
9983 remote_bfd_iovec_pread,
9984 remote_bfd_iovec_close,
9985 remote_bfd_iovec_stat);
9991 remote_file_put (const char *local_file, const char *remote_file, int from_tty)
9993 struct cleanup *back_to, *close_cleanup;
9994 int retcode, fd, remote_errno, bytes, io_size;
9997 int bytes_in_buffer;
10000 struct remote_state *rs = get_remote_state ();
10002 if (!rs->remote_desc)
10003 error (_("command can only be used with remote target"));
10005 file = gdb_fopen_cloexec (local_file, "rb");
10007 perror_with_name (local_file);
10008 back_to = make_cleanup_fclose (file);
10010 fd = remote_hostio_open (remote_file, (FILEIO_O_WRONLY | FILEIO_O_CREAT
10012 0700, &remote_errno);
10014 remote_hostio_error (remote_errno);
10016 /* Send up to this many bytes at once. They won't all fit in the
10017 remote packet limit, so we'll transfer slightly fewer. */
10018 io_size = get_remote_packet_size ();
10019 buffer = xmalloc (io_size);
10020 make_cleanup (xfree, buffer);
10022 close_cleanup = make_cleanup (remote_hostio_close_cleanup, &fd);
10024 bytes_in_buffer = 0;
10027 while (bytes_in_buffer || !saw_eof)
10031 bytes = fread (buffer + bytes_in_buffer, 1,
10032 io_size - bytes_in_buffer,
10037 error (_("Error reading %s."), local_file);
10040 /* EOF. Unless there is something still in the
10041 buffer from the last iteration, we are done. */
10043 if (bytes_in_buffer == 0)
10051 bytes += bytes_in_buffer;
10052 bytes_in_buffer = 0;
10054 retcode = remote_hostio_pwrite (fd, buffer, bytes,
10055 offset, &remote_errno);
10058 remote_hostio_error (remote_errno);
10059 else if (retcode == 0)
10060 error (_("Remote write of %d bytes returned 0!"), bytes);
10061 else if (retcode < bytes)
10063 /* Short write. Save the rest of the read data for the next
10065 bytes_in_buffer = bytes - retcode;
10066 memmove (buffer, buffer + retcode, bytes_in_buffer);
10072 discard_cleanups (close_cleanup);
10073 if (remote_hostio_close (fd, &remote_errno))
10074 remote_hostio_error (remote_errno);
10077 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file);
10078 do_cleanups (back_to);
10082 remote_file_get (const char *remote_file, const char *local_file, int from_tty)
10084 struct cleanup *back_to, *close_cleanup;
10085 int fd, remote_errno, bytes, io_size;
10089 struct remote_state *rs = get_remote_state ();
10091 if (!rs->remote_desc)
10092 error (_("command can only be used with remote target"));
10094 fd = remote_hostio_open (remote_file, FILEIO_O_RDONLY, 0, &remote_errno);
10096 remote_hostio_error (remote_errno);
10098 file = gdb_fopen_cloexec (local_file, "wb");
10100 perror_with_name (local_file);
10101 back_to = make_cleanup_fclose (file);
10103 /* Send up to this many bytes at once. They won't all fit in the
10104 remote packet limit, so we'll transfer slightly fewer. */
10105 io_size = get_remote_packet_size ();
10106 buffer = xmalloc (io_size);
10107 make_cleanup (xfree, buffer);
10109 close_cleanup = make_cleanup (remote_hostio_close_cleanup, &fd);
10114 bytes = remote_hostio_pread (fd, buffer, io_size, offset, &remote_errno);
10116 /* Success, but no bytes, means end-of-file. */
10119 remote_hostio_error (remote_errno);
10123 bytes = fwrite (buffer, 1, bytes, file);
10125 perror_with_name (local_file);
10128 discard_cleanups (close_cleanup);
10129 if (remote_hostio_close (fd, &remote_errno))
10130 remote_hostio_error (remote_errno);
10133 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file);
10134 do_cleanups (back_to);
10138 remote_file_delete (const char *remote_file, int from_tty)
10140 int retcode, remote_errno;
10141 struct remote_state *rs = get_remote_state ();
10143 if (!rs->remote_desc)
10144 error (_("command can only be used with remote target"));
10146 retcode = remote_hostio_unlink (remote_file, &remote_errno);
10148 remote_hostio_error (remote_errno);
10151 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file);
10155 remote_put_command (char *args, int from_tty)
10157 struct cleanup *back_to;
10161 error_no_arg (_("file to put"));
10163 argv = gdb_buildargv (args);
10164 back_to = make_cleanup_freeargv (argv);
10165 if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
10166 error (_("Invalid parameters to remote put"));
10168 remote_file_put (argv[0], argv[1], from_tty);
10170 do_cleanups (back_to);
10174 remote_get_command (char *args, int from_tty)
10176 struct cleanup *back_to;
10180 error_no_arg (_("file to get"));
10182 argv = gdb_buildargv (args);
10183 back_to = make_cleanup_freeargv (argv);
10184 if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
10185 error (_("Invalid parameters to remote get"));
10187 remote_file_get (argv[0], argv[1], from_tty);
10189 do_cleanups (back_to);
10193 remote_delete_command (char *args, int from_tty)
10195 struct cleanup *back_to;
10199 error_no_arg (_("file to delete"));
10201 argv = gdb_buildargv (args);
10202 back_to = make_cleanup_freeargv (argv);
10203 if (argv[0] == NULL || argv[1] != NULL)
10204 error (_("Invalid parameters to remote delete"));
10206 remote_file_delete (argv[0], from_tty);
10208 do_cleanups (back_to);
10212 remote_command (char *args, int from_tty)
10214 help_list (remote_cmdlist, "remote ", -1, gdb_stdout);
10218 remote_can_execute_reverse (struct target_ops *self)
10220 if (remote_protocol_packets[PACKET_bs].support == PACKET_ENABLE
10221 || remote_protocol_packets[PACKET_bc].support == PACKET_ENABLE)
10228 remote_supports_non_stop (struct target_ops *self)
10234 remote_supports_disable_randomization (struct target_ops *self)
10236 /* Only supported in extended mode. */
10241 remote_supports_multi_process (struct target_ops *self)
10243 struct remote_state *rs = get_remote_state ();
10245 /* Only extended-remote handles being attached to multiple
10246 processes, even though plain remote can use the multi-process
10247 thread id extensions, so that GDB knows the target process's
10249 return rs->extended && remote_multi_process_p (rs);
10253 remote_supports_cond_tracepoints (void)
10255 struct remote_state *rs = get_remote_state ();
10257 return rs->cond_tracepoints;
10261 remote_supports_cond_breakpoints (struct target_ops *self)
10263 struct remote_state *rs = get_remote_state ();
10265 return rs->cond_breakpoints;
10269 remote_supports_fast_tracepoints (void)
10271 struct remote_state *rs = get_remote_state ();
10273 return rs->fast_tracepoints;
10277 remote_supports_static_tracepoints (void)
10279 struct remote_state *rs = get_remote_state ();
10281 return rs->static_tracepoints;
10285 remote_supports_install_in_trace (void)
10287 struct remote_state *rs = get_remote_state ();
10289 return rs->install_in_trace;
10293 remote_supports_enable_disable_tracepoint (struct target_ops *self)
10295 struct remote_state *rs = get_remote_state ();
10297 return rs->enable_disable_tracepoints;
10301 remote_supports_string_tracing (struct target_ops *self)
10303 struct remote_state *rs = get_remote_state ();
10305 return rs->string_tracing;
10309 remote_can_run_breakpoint_commands (struct target_ops *self)
10311 struct remote_state *rs = get_remote_state ();
10313 return rs->breakpoint_commands;
10317 remote_trace_init (void)
10320 remote_get_noisy_reply (&target_buf, &target_buf_size);
10321 if (strcmp (target_buf, "OK") != 0)
10322 error (_("Target does not support this command."));
10325 static void free_actions_list (char **actions_list);
10326 static void free_actions_list_cleanup_wrapper (void *);
10328 free_actions_list_cleanup_wrapper (void *al)
10330 free_actions_list (al);
10334 free_actions_list (char **actions_list)
10338 if (actions_list == 0)
10341 for (ndx = 0; actions_list[ndx]; ndx++)
10342 xfree (actions_list[ndx]);
10344 xfree (actions_list);
10347 /* Recursive routine to walk through command list including loops, and
10348 download packets for each command. */
10351 remote_download_command_source (int num, ULONGEST addr,
10352 struct command_line *cmds)
10354 struct remote_state *rs = get_remote_state ();
10355 struct command_line *cmd;
10357 for (cmd = cmds; cmd; cmd = cmd->next)
10359 QUIT; /* Allow user to bail out with ^C. */
10360 strcpy (rs->buf, "QTDPsrc:");
10361 encode_source_string (num, addr, "cmd", cmd->line,
10362 rs->buf + strlen (rs->buf),
10363 rs->buf_size - strlen (rs->buf));
10365 remote_get_noisy_reply (&target_buf, &target_buf_size);
10366 if (strcmp (target_buf, "OK"))
10367 warning (_("Target does not support source download."));
10369 if (cmd->control_type == while_control
10370 || cmd->control_type == while_stepping_control)
10372 remote_download_command_source (num, addr, *cmd->body_list);
10374 QUIT; /* Allow user to bail out with ^C. */
10375 strcpy (rs->buf, "QTDPsrc:");
10376 encode_source_string (num, addr, "cmd", "end",
10377 rs->buf + strlen (rs->buf),
10378 rs->buf_size - strlen (rs->buf));
10380 remote_get_noisy_reply (&target_buf, &target_buf_size);
10381 if (strcmp (target_buf, "OK"))
10382 warning (_("Target does not support source download."));
10388 remote_download_tracepoint (struct bp_location *loc)
10390 #define BUF_SIZE 2048
10394 char buf[BUF_SIZE];
10395 char **tdp_actions;
10396 char **stepping_actions;
10398 struct cleanup *old_chain = NULL;
10399 struct agent_expr *aexpr;
10400 struct cleanup *aexpr_chain = NULL;
10402 struct breakpoint *b = loc->owner;
10403 struct tracepoint *t = (struct tracepoint *) b;
10405 encode_actions_rsp (loc, &tdp_actions, &stepping_actions);
10406 old_chain = make_cleanup (free_actions_list_cleanup_wrapper,
10408 (void) make_cleanup (free_actions_list_cleanup_wrapper,
10411 tpaddr = loc->address;
10412 sprintf_vma (addrbuf, tpaddr);
10413 xsnprintf (buf, BUF_SIZE, "QTDP:%x:%s:%c:%lx:%x", b->number,
10414 addrbuf, /* address */
10415 (b->enable_state == bp_enabled ? 'E' : 'D'),
10416 t->step_count, t->pass_count);
10417 /* Fast tracepoints are mostly handled by the target, but we can
10418 tell the target how big of an instruction block should be moved
10420 if (b->type == bp_fast_tracepoint)
10422 /* Only test for support at download time; we may not know
10423 target capabilities at definition time. */
10424 if (remote_supports_fast_tracepoints ())
10428 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
10429 tpaddr, &isize, NULL))
10430 xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":F%x",
10433 /* If it passed validation at definition but fails now,
10434 something is very wrong. */
10435 internal_error (__FILE__, __LINE__,
10436 _("Fast tracepoint not "
10437 "valid during download"));
10440 /* Fast tracepoints are functionally identical to regular
10441 tracepoints, so don't take lack of support as a reason to
10442 give up on the trace run. */
10443 warning (_("Target does not support fast tracepoints, "
10444 "downloading %d as regular tracepoint"), b->number);
10446 else if (b->type == bp_static_tracepoint)
10448 /* Only test for support at download time; we may not know
10449 target capabilities at definition time. */
10450 if (remote_supports_static_tracepoints ())
10452 struct static_tracepoint_marker marker;
10454 if (target_static_tracepoint_marker_at (tpaddr, &marker))
10455 strcat (buf, ":S");
10457 error (_("Static tracepoint not valid during download"));
10460 /* Fast tracepoints are functionally identical to regular
10461 tracepoints, so don't take lack of support as a reason
10462 to give up on the trace run. */
10463 error (_("Target does not support static tracepoints"));
10465 /* If the tracepoint has a conditional, make it into an agent
10466 expression and append to the definition. */
10469 /* Only test support at download time, we may not know target
10470 capabilities at definition time. */
10471 if (remote_supports_cond_tracepoints ())
10473 aexpr = gen_eval_for_expr (tpaddr, loc->cond);
10474 aexpr_chain = make_cleanup_free_agent_expr (aexpr);
10475 xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":X%x,",
10477 pkt = buf + strlen (buf);
10478 for (ndx = 0; ndx < aexpr->len; ++ndx)
10479 pkt = pack_hex_byte (pkt, aexpr->buf[ndx]);
10481 do_cleanups (aexpr_chain);
10484 warning (_("Target does not support conditional tracepoints, "
10485 "ignoring tp %d cond"), b->number);
10488 if (b->commands || *default_collect)
10491 remote_get_noisy_reply (&target_buf, &target_buf_size);
10492 if (strcmp (target_buf, "OK"))
10493 error (_("Target does not support tracepoints."));
10495 /* do_single_steps (t); */
10498 for (ndx = 0; tdp_actions[ndx]; ndx++)
10500 QUIT; /* Allow user to bail out with ^C. */
10501 xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%c",
10502 b->number, addrbuf, /* address */
10504 ((tdp_actions[ndx + 1] || stepping_actions)
10507 remote_get_noisy_reply (&target_buf,
10509 if (strcmp (target_buf, "OK"))
10510 error (_("Error on target while setting tracepoints."));
10513 if (stepping_actions)
10515 for (ndx = 0; stepping_actions[ndx]; ndx++)
10517 QUIT; /* Allow user to bail out with ^C. */
10518 xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%s%s",
10519 b->number, addrbuf, /* address */
10520 ((ndx == 0) ? "S" : ""),
10521 stepping_actions[ndx],
10522 (stepping_actions[ndx + 1] ? "-" : ""));
10524 remote_get_noisy_reply (&target_buf,
10526 if (strcmp (target_buf, "OK"))
10527 error (_("Error on target while setting tracepoints."));
10531 if (remote_protocol_packets[PACKET_TracepointSource].support
10534 if (b->addr_string)
10536 strcpy (buf, "QTDPsrc:");
10537 encode_source_string (b->number, loc->address,
10538 "at", b->addr_string, buf + strlen (buf),
10539 2048 - strlen (buf));
10542 remote_get_noisy_reply (&target_buf, &target_buf_size);
10543 if (strcmp (target_buf, "OK"))
10544 warning (_("Target does not support source download."));
10546 if (b->cond_string)
10548 strcpy (buf, "QTDPsrc:");
10549 encode_source_string (b->number, loc->address,
10550 "cond", b->cond_string, buf + strlen (buf),
10551 2048 - strlen (buf));
10553 remote_get_noisy_reply (&target_buf, &target_buf_size);
10554 if (strcmp (target_buf, "OK"))
10555 warning (_("Target does not support source download."));
10557 remote_download_command_source (b->number, loc->address,
10558 breakpoint_commands (b));
10561 do_cleanups (old_chain);
10565 remote_can_download_tracepoint (void)
10567 struct remote_state *rs = get_remote_state ();
10568 struct trace_status *ts;
10571 /* Don't try to install tracepoints until we've relocated our
10572 symbols, and fetched and merged the target's tracepoint list with
10574 if (rs->starting_up)
10577 ts = current_trace_status ();
10578 status = remote_get_trace_status (ts);
10580 if (status == -1 || !ts->running_known || !ts->running)
10583 /* If we are in a tracing experiment, but remote stub doesn't support
10584 installing tracepoint in trace, we have to return. */
10585 if (!remote_supports_install_in_trace ())
10593 remote_download_trace_state_variable (struct trace_state_variable *tsv)
10595 struct remote_state *rs = get_remote_state ();
10598 xsnprintf (rs->buf, get_remote_packet_size (), "QTDV:%x:%s:%x:",
10599 tsv->number, phex ((ULONGEST) tsv->initial_value, 8),
10601 p = rs->buf + strlen (rs->buf);
10602 if ((p - rs->buf) + strlen (tsv->name) * 2 >= get_remote_packet_size ())
10603 error (_("Trace state variable name too long for tsv definition packet"));
10604 p += 2 * bin2hex ((gdb_byte *) (tsv->name), p, strlen (tsv->name));
10607 remote_get_noisy_reply (&target_buf, &target_buf_size);
10608 if (*target_buf == '\0')
10609 error (_("Target does not support this command."));
10610 if (strcmp (target_buf, "OK") != 0)
10611 error (_("Error on target while downloading trace state variable."));
10615 remote_enable_tracepoint (struct bp_location *location)
10617 struct remote_state *rs = get_remote_state ();
10620 sprintf_vma (addr_buf, location->address);
10621 xsnprintf (rs->buf, get_remote_packet_size (), "QTEnable:%x:%s",
10622 location->owner->number, addr_buf);
10624 remote_get_noisy_reply (&rs->buf, &rs->buf_size);
10625 if (*rs->buf == '\0')
10626 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10627 if (strcmp (rs->buf, "OK") != 0)
10628 error (_("Error on target while enabling tracepoint."));
10632 remote_disable_tracepoint (struct bp_location *location)
10634 struct remote_state *rs = get_remote_state ();
10637 sprintf_vma (addr_buf, location->address);
10638 xsnprintf (rs->buf, get_remote_packet_size (), "QTDisable:%x:%s",
10639 location->owner->number, addr_buf);
10641 remote_get_noisy_reply (&rs->buf, &rs->buf_size);
10642 if (*rs->buf == '\0')
10643 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10644 if (strcmp (rs->buf, "OK") != 0)
10645 error (_("Error on target while disabling tracepoint."));
10649 remote_trace_set_readonly_regions (void)
10653 bfd_size_type size;
10659 return; /* No information to give. */
10661 strcpy (target_buf, "QTro");
10662 offset = strlen (target_buf);
10663 for (s = exec_bfd->sections; s; s = s->next)
10665 char tmp1[40], tmp2[40];
10668 if ((s->flags & SEC_LOAD) == 0 ||
10669 /* (s->flags & SEC_CODE) == 0 || */
10670 (s->flags & SEC_READONLY) == 0)
10674 vma = bfd_get_section_vma (abfd, s);
10675 size = bfd_get_section_size (s);
10676 sprintf_vma (tmp1, vma);
10677 sprintf_vma (tmp2, vma + size);
10678 sec_length = 1 + strlen (tmp1) + 1 + strlen (tmp2);
10679 if (offset + sec_length + 1 > target_buf_size)
10681 if (remote_protocol_packets[PACKET_qXfer_traceframe_info].support
10684 Too many sections for read-only sections definition packet."));
10687 xsnprintf (target_buf + offset, target_buf_size - offset, ":%s,%s",
10689 offset += sec_length;
10693 putpkt (target_buf);
10694 getpkt (&target_buf, &target_buf_size, 0);
10699 remote_trace_start (void)
10701 putpkt ("QTStart");
10702 remote_get_noisy_reply (&target_buf, &target_buf_size);
10703 if (*target_buf == '\0')
10704 error (_("Target does not support this command."));
10705 if (strcmp (target_buf, "OK") != 0)
10706 error (_("Bogus reply from target: %s"), target_buf);
10710 remote_get_trace_status (struct trace_status *ts)
10712 /* Initialize it just to avoid a GCC false warning. */
10714 /* FIXME we need to get register block size some other way. */
10715 extern int trace_regblock_size;
10716 volatile struct gdb_exception ex;
10717 enum packet_result result;
10719 if (remote_protocol_packets[PACKET_qTStatus].support == PACKET_DISABLE)
10722 trace_regblock_size = get_remote_arch_state ()->sizeof_g_packet;
10724 putpkt ("qTStatus");
10726 TRY_CATCH (ex, RETURN_MASK_ERROR)
10728 p = remote_get_noisy_reply (&target_buf, &target_buf_size);
10732 if (ex.error != TARGET_CLOSE_ERROR)
10734 exception_fprintf (gdb_stderr, ex, "qTStatus: ");
10737 throw_exception (ex);
10740 result = packet_ok (p, &remote_protocol_packets[PACKET_qTStatus]);
10742 /* If the remote target doesn't do tracing, flag it. */
10743 if (result == PACKET_UNKNOWN)
10746 /* We're working with a live target. */
10747 ts->filename = NULL;
10750 error (_("Bogus trace status reply from target: %s"), target_buf);
10752 /* Function 'parse_trace_status' sets default value of each field of
10753 'ts' at first, so we don't have to do it here. */
10754 parse_trace_status (p, ts);
10756 return ts->running;
10760 remote_get_tracepoint_status (struct breakpoint *bp,
10761 struct uploaded_tp *utp)
10763 struct remote_state *rs = get_remote_state ();
10765 struct bp_location *loc;
10766 struct tracepoint *tp = (struct tracepoint *) bp;
10767 size_t size = get_remote_packet_size ();
10771 tp->base.hit_count = 0;
10772 tp->traceframe_usage = 0;
10773 for (loc = tp->base.loc; loc; loc = loc->next)
10775 /* If the tracepoint was never downloaded, don't go asking for
10777 if (tp->number_on_target == 0)
10779 xsnprintf (rs->buf, size, "qTP:%x:%s", tp->number_on_target,
10780 phex_nz (loc->address, 0));
10782 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
10783 if (reply && *reply)
10786 parse_tracepoint_status (reply + 1, bp, utp);
10792 utp->hit_count = 0;
10793 utp->traceframe_usage = 0;
10794 xsnprintf (rs->buf, size, "qTP:%x:%s", utp->number,
10795 phex_nz (utp->addr, 0));
10797 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
10798 if (reply && *reply)
10801 parse_tracepoint_status (reply + 1, bp, utp);
10807 remote_trace_stop (void)
10810 remote_get_noisy_reply (&target_buf, &target_buf_size);
10811 if (*target_buf == '\0')
10812 error (_("Target does not support this command."));
10813 if (strcmp (target_buf, "OK") != 0)
10814 error (_("Bogus reply from target: %s"), target_buf);
10818 remote_trace_find (enum trace_find_type type, int num,
10819 CORE_ADDR addr1, CORE_ADDR addr2,
10822 struct remote_state *rs = get_remote_state ();
10823 char *endbuf = rs->buf + get_remote_packet_size ();
10825 int target_frameno = -1, target_tracept = -1;
10827 /* Lookups other than by absolute frame number depend on the current
10828 trace selected, so make sure it is correct on the remote end
10830 if (type != tfind_number)
10831 set_remote_traceframe ();
10834 strcpy (p, "QTFrame:");
10835 p = strchr (p, '\0');
10839 xsnprintf (p, endbuf - p, "%x", num);
10842 xsnprintf (p, endbuf - p, "pc:%s", phex_nz (addr1, 0));
10845 xsnprintf (p, endbuf - p, "tdp:%x", num);
10848 xsnprintf (p, endbuf - p, "range:%s:%s", phex_nz (addr1, 0),
10849 phex_nz (addr2, 0));
10851 case tfind_outside:
10852 xsnprintf (p, endbuf - p, "outside:%s:%s", phex_nz (addr1, 0),
10853 phex_nz (addr2, 0));
10856 error (_("Unknown trace find type %d"), type);
10860 reply = remote_get_noisy_reply (&(rs->buf), &rs->buf_size);
10861 if (*reply == '\0')
10862 error (_("Target does not support this command."));
10864 while (reply && *reply)
10869 target_frameno = (int) strtol (p, &reply, 16);
10871 error (_("Unable to parse trace frame number"));
10872 /* Don't update our remote traceframe number cache on failure
10873 to select a remote traceframe. */
10874 if (target_frameno == -1)
10879 target_tracept = (int) strtol (p, &reply, 16);
10881 error (_("Unable to parse tracepoint number"));
10883 case 'O': /* "OK"? */
10884 if (reply[1] == 'K' && reply[2] == '\0')
10887 error (_("Bogus reply from target: %s"), reply);
10890 error (_("Bogus reply from target: %s"), reply);
10893 *tpp = target_tracept;
10895 rs->remote_traceframe_number = target_frameno;
10896 return target_frameno;
10900 remote_get_trace_state_variable_value (int tsvnum, LONGEST *val)
10902 struct remote_state *rs = get_remote_state ();
10906 set_remote_traceframe ();
10908 xsnprintf (rs->buf, get_remote_packet_size (), "qTV:%x", tsvnum);
10910 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
10911 if (reply && *reply)
10915 unpack_varlen_hex (reply + 1, &uval);
10916 *val = (LONGEST) uval;
10924 remote_save_trace_data (const char *filename)
10926 struct remote_state *rs = get_remote_state ();
10930 strcpy (p, "QTSave:");
10932 if ((p - rs->buf) + strlen (filename) * 2 >= get_remote_packet_size ())
10933 error (_("Remote file name too long for trace save packet"));
10934 p += 2 * bin2hex ((gdb_byte *) filename, p, strlen (filename));
10937 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
10938 if (*reply == '\0')
10939 error (_("Target does not support this command."));
10940 if (strcmp (reply, "OK") != 0)
10941 error (_("Bogus reply from target: %s"), reply);
10945 /* This is basically a memory transfer, but needs to be its own packet
10946 because we don't know how the target actually organizes its trace
10947 memory, plus we want to be able to ask for as much as possible, but
10948 not be unhappy if we don't get as much as we ask for. */
10951 remote_get_raw_trace_data (gdb_byte *buf, ULONGEST offset, LONGEST len)
10953 struct remote_state *rs = get_remote_state ();
10959 strcpy (p, "qTBuffer:");
10961 p += hexnumstr (p, offset);
10963 p += hexnumstr (p, len);
10967 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
10968 if (reply && *reply)
10970 /* 'l' by itself means we're at the end of the buffer and
10971 there is nothing more to get. */
10975 /* Convert the reply into binary. Limit the number of bytes to
10976 convert according to our passed-in buffer size, rather than
10977 what was returned in the packet; if the target is
10978 unexpectedly generous and gives us a bigger reply than we
10979 asked for, we don't want to crash. */
10980 rslt = hex2bin (target_buf, buf, len);
10984 /* Something went wrong, flag as an error. */
10989 remote_set_disconnected_tracing (int val)
10991 struct remote_state *rs = get_remote_state ();
10993 if (rs->disconnected_tracing)
10997 xsnprintf (rs->buf, get_remote_packet_size (), "QTDisconnected:%x", val);
10999 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
11000 if (*reply == '\0')
11001 error (_("Target does not support this command."));
11002 if (strcmp (reply, "OK") != 0)
11003 error (_("Bogus reply from target: %s"), reply);
11006 warning (_("Target does not support disconnected tracing."));
11010 remote_core_of_thread (struct target_ops *ops, ptid_t ptid)
11012 struct thread_info *info = find_thread_ptid (ptid);
11014 if (info && info->private)
11015 return info->private->core;
11020 remote_set_circular_trace_buffer (int val)
11022 struct remote_state *rs = get_remote_state ();
11025 xsnprintf (rs->buf, get_remote_packet_size (), "QTBuffer:circular:%x", val);
11027 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
11028 if (*reply == '\0')
11029 error (_("Target does not support this command."));
11030 if (strcmp (reply, "OK") != 0)
11031 error (_("Bogus reply from target: %s"), reply);
11034 static struct traceframe_info *
11035 remote_traceframe_info (void)
11039 /* If current traceframe is not selected, don't bother the remote
11041 if (get_traceframe_number () < 0)
11044 text = target_read_stralloc (¤t_target,
11045 TARGET_OBJECT_TRACEFRAME_INFO, NULL);
11048 struct traceframe_info *info;
11049 struct cleanup *back_to = make_cleanup (xfree, text);
11051 info = parse_traceframe_info (text);
11052 do_cleanups (back_to);
11059 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11060 instruction on which a fast tracepoint may be placed. Returns -1
11061 if the packet is not supported, and 0 if the minimum instruction
11062 length is unknown. */
11065 remote_get_min_fast_tracepoint_insn_len (void)
11067 struct remote_state *rs = get_remote_state ();
11070 /* If we're not debugging a process yet, the IPA can't be
11072 if (!target_has_execution)
11075 /* Make sure the remote is pointing at the right process. */
11076 set_general_process ();
11078 xsnprintf (rs->buf, get_remote_packet_size (), "qTMinFTPILen");
11080 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
11081 if (*reply == '\0')
11085 ULONGEST min_insn_len;
11087 unpack_varlen_hex (reply, &min_insn_len);
11089 return (int) min_insn_len;
11094 remote_set_trace_buffer_size (LONGEST val)
11096 if (remote_protocol_packets[PACKET_QTBuffer_size].support
11099 struct remote_state *rs = get_remote_state ();
11100 char *buf = rs->buf;
11101 char *endbuf = rs->buf + get_remote_packet_size ();
11102 enum packet_result result;
11104 gdb_assert (val >= 0 || val == -1);
11105 buf += xsnprintf (buf, endbuf - buf, "QTBuffer:size:");
11106 /* Send -1 as literal "-1" to avoid host size dependency. */
11110 buf += hexnumstr (buf, (ULONGEST) -val);
11113 buf += hexnumstr (buf, (ULONGEST) val);
11116 remote_get_noisy_reply (&rs->buf, &rs->buf_size);
11117 result = packet_ok (rs->buf,
11118 &remote_protocol_packets[PACKET_QTBuffer_size]);
11120 if (result != PACKET_OK)
11121 warning (_("Bogus reply from target: %s"), rs->buf);
11126 remote_set_trace_notes (const char *user, const char *notes,
11127 const char *stop_notes)
11129 struct remote_state *rs = get_remote_state ();
11131 char *buf = rs->buf;
11132 char *endbuf = rs->buf + get_remote_packet_size ();
11135 buf += xsnprintf (buf, endbuf - buf, "QTNotes:");
11138 buf += xsnprintf (buf, endbuf - buf, "user:");
11139 nbytes = bin2hex ((gdb_byte *) user, buf, strlen (user));
11145 buf += xsnprintf (buf, endbuf - buf, "notes:");
11146 nbytes = bin2hex ((gdb_byte *) notes, buf, strlen (notes));
11152 buf += xsnprintf (buf, endbuf - buf, "tstop:");
11153 nbytes = bin2hex ((gdb_byte *) stop_notes, buf, strlen (stop_notes));
11157 /* Ensure the buffer is terminated. */
11161 reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
11162 if (*reply == '\0')
11165 if (strcmp (reply, "OK") != 0)
11166 error (_("Bogus reply from target: %s"), reply);
11172 remote_use_agent (int use)
11174 if (remote_protocol_packets[PACKET_QAgent].support != PACKET_DISABLE)
11176 struct remote_state *rs = get_remote_state ();
11178 /* If the stub supports QAgent. */
11179 xsnprintf (rs->buf, get_remote_packet_size (), "QAgent:%d", use);
11181 getpkt (&rs->buf, &rs->buf_size, 0);
11183 if (strcmp (rs->buf, "OK") == 0)
11194 remote_can_use_agent (void)
11196 return (remote_protocol_packets[PACKET_QAgent].support != PACKET_DISABLE);
11199 struct btrace_target_info
11201 /* The ptid of the traced thread. */
11205 /* Check whether the target supports branch tracing. */
11208 remote_supports_btrace (struct target_ops *self)
11210 if (remote_protocol_packets[PACKET_Qbtrace_off].support != PACKET_ENABLE)
11212 if (remote_protocol_packets[PACKET_Qbtrace_bts].support != PACKET_ENABLE)
11214 if (remote_protocol_packets[PACKET_qXfer_btrace].support != PACKET_ENABLE)
11220 /* Enable branch tracing. */
11222 static struct btrace_target_info *
11223 remote_enable_btrace (ptid_t ptid)
11225 struct btrace_target_info *tinfo = NULL;
11226 struct packet_config *packet = &remote_protocol_packets[PACKET_Qbtrace_bts];
11227 struct remote_state *rs = get_remote_state ();
11228 char *buf = rs->buf;
11229 char *endbuf = rs->buf + get_remote_packet_size ();
11231 if (packet->support != PACKET_ENABLE)
11232 error (_("Target does not support branch tracing."));
11234 set_general_thread (ptid);
11236 buf += xsnprintf (buf, endbuf - buf, "%s", packet->name);
11238 getpkt (&rs->buf, &rs->buf_size, 0);
11240 if (packet_ok (rs->buf, packet) == PACKET_ERROR)
11242 if (rs->buf[0] == 'E' && rs->buf[1] == '.')
11243 error (_("Could not enable branch tracing for %s: %s"),
11244 target_pid_to_str (ptid), rs->buf + 2);
11246 error (_("Could not enable branch tracing for %s."),
11247 target_pid_to_str (ptid));
11250 tinfo = xzalloc (sizeof (*tinfo));
11251 tinfo->ptid = ptid;
11256 /* Disable branch tracing. */
11259 remote_disable_btrace (struct btrace_target_info *tinfo)
11261 struct packet_config *packet = &remote_protocol_packets[PACKET_Qbtrace_off];
11262 struct remote_state *rs = get_remote_state ();
11263 char *buf = rs->buf;
11264 char *endbuf = rs->buf + get_remote_packet_size ();
11266 if (packet->support != PACKET_ENABLE)
11267 error (_("Target does not support branch tracing."));
11269 set_general_thread (tinfo->ptid);
11271 buf += xsnprintf (buf, endbuf - buf, "%s", packet->name);
11273 getpkt (&rs->buf, &rs->buf_size, 0);
11275 if (packet_ok (rs->buf, packet) == PACKET_ERROR)
11277 if (rs->buf[0] == 'E' && rs->buf[1] == '.')
11278 error (_("Could not disable branch tracing for %s: %s"),
11279 target_pid_to_str (tinfo->ptid), rs->buf + 2);
11281 error (_("Could not disable branch tracing for %s."),
11282 target_pid_to_str (tinfo->ptid));
11288 /* Teardown branch tracing. */
11291 remote_teardown_btrace (struct btrace_target_info *tinfo)
11293 /* We must not talk to the target during teardown. */
11297 /* Read the branch trace. */
11299 static enum btrace_error
11300 remote_read_btrace (VEC (btrace_block_s) **btrace,
11301 struct btrace_target_info *tinfo,
11302 enum btrace_read_type type)
11304 struct packet_config *packet = &remote_protocol_packets[PACKET_qXfer_btrace];
11305 struct remote_state *rs = get_remote_state ();
11306 struct cleanup *cleanup;
11310 if (packet->support != PACKET_ENABLE)
11311 error (_("Target does not support branch tracing."));
11313 #if !defined(HAVE_LIBEXPAT)
11314 error (_("Cannot process branch tracing result. XML parsing not supported."));
11319 case BTRACE_READ_ALL:
11322 case BTRACE_READ_NEW:
11325 case BTRACE_READ_DELTA:
11329 internal_error (__FILE__, __LINE__,
11330 _("Bad branch tracing read type: %u."),
11331 (unsigned int) type);
11334 xml = target_read_stralloc (¤t_target,
11335 TARGET_OBJECT_BTRACE, annex);
11337 return BTRACE_ERR_UNKNOWN;
11339 cleanup = make_cleanup (xfree, xml);
11340 *btrace = parse_xml_btrace (xml);
11341 do_cleanups (cleanup);
11343 return BTRACE_ERR_NONE;
11347 remote_augmented_libraries_svr4_read (void)
11349 struct remote_state *rs = get_remote_state ();
11351 return rs->augmented_libraries_svr4_read;
11354 /* Implementation of to_load. */
11357 remote_load (struct target_ops *self, char *name, int from_tty)
11359 generic_load (name, from_tty);
11363 init_remote_ops (void)
11365 remote_ops.to_shortname = "remote";
11366 remote_ops.to_longname = "Remote serial target in gdb-specific protocol";
11367 remote_ops.to_doc =
11368 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11369 Specify the serial device it is connected to\n\
11370 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
11371 remote_ops.to_open = remote_open;
11372 remote_ops.to_close = remote_close;
11373 remote_ops.to_detach = remote_detach;
11374 remote_ops.to_disconnect = remote_disconnect;
11375 remote_ops.to_resume = remote_resume;
11376 remote_ops.to_wait = remote_wait;
11377 remote_ops.to_fetch_registers = remote_fetch_registers;
11378 remote_ops.to_store_registers = remote_store_registers;
11379 remote_ops.to_prepare_to_store = remote_prepare_to_store;
11380 remote_ops.to_files_info = remote_files_info;
11381 remote_ops.to_insert_breakpoint = remote_insert_breakpoint;
11382 remote_ops.to_remove_breakpoint = remote_remove_breakpoint;
11383 remote_ops.to_stopped_by_watchpoint = remote_stopped_by_watchpoint;
11384 remote_ops.to_stopped_data_address = remote_stopped_data_address;
11385 remote_ops.to_watchpoint_addr_within_range =
11386 remote_watchpoint_addr_within_range;
11387 remote_ops.to_can_use_hw_breakpoint = remote_check_watch_resources;
11388 remote_ops.to_insert_hw_breakpoint = remote_insert_hw_breakpoint;
11389 remote_ops.to_remove_hw_breakpoint = remote_remove_hw_breakpoint;
11390 remote_ops.to_region_ok_for_hw_watchpoint
11391 = remote_region_ok_for_hw_watchpoint;
11392 remote_ops.to_insert_watchpoint = remote_insert_watchpoint;
11393 remote_ops.to_remove_watchpoint = remote_remove_watchpoint;
11394 remote_ops.to_kill = remote_kill;
11395 remote_ops.to_load = remote_load;
11396 remote_ops.to_mourn_inferior = remote_mourn;
11397 remote_ops.to_pass_signals = remote_pass_signals;
11398 remote_ops.to_program_signals = remote_program_signals;
11399 remote_ops.to_thread_alive = remote_thread_alive;
11400 remote_ops.to_find_new_threads = remote_threads_info;
11401 remote_ops.to_pid_to_str = remote_pid_to_str;
11402 remote_ops.to_extra_thread_info = remote_threads_extra_info;
11403 remote_ops.to_get_ada_task_ptid = remote_get_ada_task_ptid;
11404 remote_ops.to_stop = remote_stop;
11405 remote_ops.to_xfer_partial = remote_xfer_partial;
11406 remote_ops.to_rcmd = remote_rcmd;
11407 remote_ops.to_log_command = serial_log_command;
11408 remote_ops.to_get_thread_local_address = remote_get_thread_local_address;
11409 remote_ops.to_stratum = process_stratum;
11410 remote_ops.to_has_all_memory = default_child_has_all_memory;
11411 remote_ops.to_has_memory = default_child_has_memory;
11412 remote_ops.to_has_stack = default_child_has_stack;
11413 remote_ops.to_has_registers = default_child_has_registers;
11414 remote_ops.to_has_execution = default_child_has_execution;
11415 remote_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */
11416 remote_ops.to_can_execute_reverse = remote_can_execute_reverse;
11417 remote_ops.to_magic = OPS_MAGIC;
11418 remote_ops.to_memory_map = remote_memory_map;
11419 remote_ops.to_flash_erase = remote_flash_erase;
11420 remote_ops.to_flash_done = remote_flash_done;
11421 remote_ops.to_read_description = remote_read_description;
11422 remote_ops.to_search_memory = remote_search_memory;
11423 remote_ops.to_can_async_p = remote_can_async_p;
11424 remote_ops.to_is_async_p = remote_is_async_p;
11425 remote_ops.to_async = remote_async;
11426 remote_ops.to_terminal_inferior = remote_terminal_inferior;
11427 remote_ops.to_terminal_ours = remote_terminal_ours;
11428 remote_ops.to_supports_non_stop = remote_supports_non_stop;
11429 remote_ops.to_supports_multi_process = remote_supports_multi_process;
11430 remote_ops.to_supports_disable_randomization
11431 = remote_supports_disable_randomization;
11432 remote_ops.to_fileio_open = remote_hostio_open;
11433 remote_ops.to_fileio_pwrite = remote_hostio_pwrite;
11434 remote_ops.to_fileio_pread = remote_hostio_pread;
11435 remote_ops.to_fileio_close = remote_hostio_close;
11436 remote_ops.to_fileio_unlink = remote_hostio_unlink;
11437 remote_ops.to_fileio_readlink = remote_hostio_readlink;
11438 remote_ops.to_supports_enable_disable_tracepoint = remote_supports_enable_disable_tracepoint;
11439 remote_ops.to_supports_string_tracing = remote_supports_string_tracing;
11440 remote_ops.to_supports_evaluation_of_breakpoint_conditions = remote_supports_cond_breakpoints;
11441 remote_ops.to_can_run_breakpoint_commands = remote_can_run_breakpoint_commands;
11442 remote_ops.to_trace_init = remote_trace_init;
11443 remote_ops.to_download_tracepoint = remote_download_tracepoint;
11444 remote_ops.to_can_download_tracepoint = remote_can_download_tracepoint;
11445 remote_ops.to_download_trace_state_variable
11446 = remote_download_trace_state_variable;
11447 remote_ops.to_enable_tracepoint = remote_enable_tracepoint;
11448 remote_ops.to_disable_tracepoint = remote_disable_tracepoint;
11449 remote_ops.to_trace_set_readonly_regions = remote_trace_set_readonly_regions;
11450 remote_ops.to_trace_start = remote_trace_start;
11451 remote_ops.to_get_trace_status = remote_get_trace_status;
11452 remote_ops.to_get_tracepoint_status = remote_get_tracepoint_status;
11453 remote_ops.to_trace_stop = remote_trace_stop;
11454 remote_ops.to_trace_find = remote_trace_find;
11455 remote_ops.to_get_trace_state_variable_value
11456 = remote_get_trace_state_variable_value;
11457 remote_ops.to_save_trace_data = remote_save_trace_data;
11458 remote_ops.to_upload_tracepoints = remote_upload_tracepoints;
11459 remote_ops.to_upload_trace_state_variables
11460 = remote_upload_trace_state_variables;
11461 remote_ops.to_get_raw_trace_data = remote_get_raw_trace_data;
11462 remote_ops.to_get_min_fast_tracepoint_insn_len = remote_get_min_fast_tracepoint_insn_len;
11463 remote_ops.to_set_disconnected_tracing = remote_set_disconnected_tracing;
11464 remote_ops.to_set_circular_trace_buffer = remote_set_circular_trace_buffer;
11465 remote_ops.to_set_trace_buffer_size = remote_set_trace_buffer_size;
11466 remote_ops.to_set_trace_notes = remote_set_trace_notes;
11467 remote_ops.to_core_of_thread = remote_core_of_thread;
11468 remote_ops.to_verify_memory = remote_verify_memory;
11469 remote_ops.to_get_tib_address = remote_get_tib_address;
11470 remote_ops.to_set_permissions = remote_set_permissions;
11471 remote_ops.to_static_tracepoint_marker_at
11472 = remote_static_tracepoint_marker_at;
11473 remote_ops.to_static_tracepoint_markers_by_strid
11474 = remote_static_tracepoint_markers_by_strid;
11475 remote_ops.to_traceframe_info = remote_traceframe_info;
11476 remote_ops.to_use_agent = remote_use_agent;
11477 remote_ops.to_can_use_agent = remote_can_use_agent;
11478 remote_ops.to_supports_btrace = remote_supports_btrace;
11479 remote_ops.to_enable_btrace = remote_enable_btrace;
11480 remote_ops.to_disable_btrace = remote_disable_btrace;
11481 remote_ops.to_teardown_btrace = remote_teardown_btrace;
11482 remote_ops.to_read_btrace = remote_read_btrace;
11483 remote_ops.to_augmented_libraries_svr4_read =
11484 remote_augmented_libraries_svr4_read;
11487 /* Set up the extended remote vector by making a copy of the standard
11488 remote vector and adding to it. */
11491 init_extended_remote_ops (void)
11493 extended_remote_ops = remote_ops;
11495 extended_remote_ops.to_shortname = "extended-remote";
11496 extended_remote_ops.to_longname =
11497 "Extended remote serial target in gdb-specific protocol";
11498 extended_remote_ops.to_doc =
11499 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11500 Specify the serial device it is connected to (e.g. /dev/ttya).";
11501 extended_remote_ops.to_open = extended_remote_open;
11502 extended_remote_ops.to_create_inferior = extended_remote_create_inferior;
11503 extended_remote_ops.to_mourn_inferior = extended_remote_mourn;
11504 extended_remote_ops.to_detach = extended_remote_detach;
11505 extended_remote_ops.to_attach = extended_remote_attach;
11506 extended_remote_ops.to_kill = extended_remote_kill;
11507 extended_remote_ops.to_supports_disable_randomization
11508 = extended_remote_supports_disable_randomization;
11512 remote_can_async_p (struct target_ops *ops)
11514 struct remote_state *rs = get_remote_state ();
11516 if (!target_async_permitted)
11517 /* We only enable async when the user specifically asks for it. */
11520 /* We're async whenever the serial device is. */
11521 return serial_can_async_p (rs->remote_desc);
11525 remote_is_async_p (struct target_ops *ops)
11527 struct remote_state *rs = get_remote_state ();
11529 if (!target_async_permitted)
11530 /* We only enable async when the user specifically asks for it. */
11533 /* We're async whenever the serial device is. */
11534 return serial_is_async_p (rs->remote_desc);
11537 /* Pass the SERIAL event on and up to the client. One day this code
11538 will be able to delay notifying the client of an event until the
11539 point where an entire packet has been received. */
11541 static serial_event_ftype remote_async_serial_handler;
11544 remote_async_serial_handler (struct serial *scb, void *context)
11546 struct remote_state *rs = context;
11548 /* Don't propogate error information up to the client. Instead let
11549 the client find out about the error by querying the target. */
11550 rs->async_client_callback (INF_REG_EVENT, rs->async_client_context);
11554 remote_async_inferior_event_handler (gdb_client_data data)
11556 inferior_event_handler (INF_REG_EVENT, NULL);
11560 remote_async (struct target_ops *ops,
11561 void (*callback) (enum inferior_event_type event_type,
11565 struct remote_state *rs = get_remote_state ();
11567 if (callback != NULL)
11569 serial_async (rs->remote_desc, remote_async_serial_handler, rs);
11570 rs->async_client_callback = callback;
11571 rs->async_client_context = context;
11574 serial_async (rs->remote_desc, NULL, NULL);
11578 set_remote_cmd (char *args, int from_tty)
11580 help_list (remote_set_cmdlist, "set remote ", -1, gdb_stdout);
11584 show_remote_cmd (char *args, int from_tty)
11586 /* We can't just use cmd_show_list here, because we want to skip
11587 the redundant "show remote Z-packet" and the legacy aliases. */
11588 struct cleanup *showlist_chain;
11589 struct cmd_list_element *list = remote_show_cmdlist;
11590 struct ui_out *uiout = current_uiout;
11592 showlist_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "showlist");
11593 for (; list != NULL; list = list->next)
11594 if (strcmp (list->name, "Z-packet") == 0)
11596 else if (list->type == not_set_cmd)
11597 /* Alias commands are exactly like the original, except they
11598 don't have the normal type. */
11602 struct cleanup *option_chain
11603 = make_cleanup_ui_out_tuple_begin_end (uiout, "option");
11605 ui_out_field_string (uiout, "name", list->name);
11606 ui_out_text (uiout, ": ");
11607 if (list->type == show_cmd)
11608 do_show_command ((char *) NULL, from_tty, list);
11610 cmd_func (list, NULL, from_tty);
11611 /* Close the tuple. */
11612 do_cleanups (option_chain);
11615 /* Close the tuple. */
11616 do_cleanups (showlist_chain);
11620 /* Function to be called whenever a new objfile (shlib) is detected. */
11622 remote_new_objfile (struct objfile *objfile)
11624 struct remote_state *rs = get_remote_state ();
11626 if (rs->remote_desc != 0) /* Have a remote connection. */
11627 remote_check_symbols ();
11630 /* Pull all the tracepoints defined on the target and create local
11631 data structures representing them. We don't want to create real
11632 tracepoints yet, we don't want to mess up the user's existing
11636 remote_upload_tracepoints (struct uploaded_tp **utpp)
11638 struct remote_state *rs = get_remote_state ();
11641 /* Ask for a first packet of tracepoint definition. */
11643 getpkt (&rs->buf, &rs->buf_size, 0);
11645 while (*p && *p != 'l')
11647 parse_tracepoint_definition (p, utpp);
11648 /* Ask for another packet of tracepoint definition. */
11650 getpkt (&rs->buf, &rs->buf_size, 0);
11657 remote_upload_trace_state_variables (struct uploaded_tsv **utsvp)
11659 struct remote_state *rs = get_remote_state ();
11662 /* Ask for a first packet of variable definition. */
11664 getpkt (&rs->buf, &rs->buf_size, 0);
11666 while (*p && *p != 'l')
11668 parse_tsv_definition (p, utsvp);
11669 /* Ask for another packet of variable definition. */
11671 getpkt (&rs->buf, &rs->buf_size, 0);
11677 /* The "set/show range-stepping" show hook. */
11680 show_range_stepping (struct ui_file *file, int from_tty,
11681 struct cmd_list_element *c,
11684 fprintf_filtered (file,
11685 _("Debugger's willingness to use range stepping "
11686 "is %s.\n"), value);
11689 /* The "set/show range-stepping" set hook. */
11692 set_range_stepping (char *ignore_args, int from_tty,
11693 struct cmd_list_element *c)
11695 struct remote_state *rs = get_remote_state ();
11697 /* Whene enabling, check whether range stepping is actually
11698 supported by the target, and warn if not. */
11699 if (use_range_stepping)
11701 if (rs->remote_desc != NULL)
11703 if (remote_protocol_packets[PACKET_vCont].support == PACKET_SUPPORT_UNKNOWN)
11704 remote_vcont_probe (rs);
11706 if (remote_protocol_packets[PACKET_vCont].support == PACKET_ENABLE
11707 && rs->supports_vCont.r)
11711 warning (_("Range stepping is not supported by the current target"));
11716 _initialize_remote (void)
11718 struct remote_state *rs;
11719 struct cmd_list_element *cmd;
11720 const char *cmd_name;
11722 /* architecture specific data */
11723 remote_gdbarch_data_handle =
11724 gdbarch_data_register_post_init (init_remote_state);
11725 remote_g_packet_data_handle =
11726 gdbarch_data_register_pre_init (remote_g_packet_data_init);
11728 /* Initialize the per-target state. At the moment there is only one
11729 of these, not one per target. Only one target is active at a
11731 remote_state = new_remote_state ();
11733 init_remote_ops ();
11734 add_target (&remote_ops);
11736 init_extended_remote_ops ();
11737 add_target (&extended_remote_ops);
11739 /* Hook into new objfile notification. */
11740 observer_attach_new_objfile (remote_new_objfile);
11741 /* We're no longer interested in notification events of an inferior
11743 observer_attach_inferior_exit (discard_pending_stop_replies);
11745 /* Set up signal handlers. */
11746 async_sigint_remote_token =
11747 create_async_signal_handler (async_remote_interrupt, NULL);
11748 async_sigint_remote_twice_token =
11749 create_async_signal_handler (async_remote_interrupt_twice, NULL);
11752 init_remote_threadtests ();
11755 stop_reply_queue = QUEUE_alloc (stop_reply_p, stop_reply_xfree);
11756 /* set/show remote ... */
11758 add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, _("\
11759 Remote protocol specific variables\n\
11760 Configure various remote-protocol specific variables such as\n\
11761 the packets being used"),
11762 &remote_set_cmdlist, "set remote ",
11763 0 /* allow-unknown */, &setlist);
11764 add_prefix_cmd ("remote", class_maintenance, show_remote_cmd, _("\
11765 Remote protocol specific variables\n\
11766 Configure various remote-protocol specific variables such as\n\
11767 the packets being used"),
11768 &remote_show_cmdlist, "show remote ",
11769 0 /* allow-unknown */, &showlist);
11771 add_cmd ("compare-sections", class_obscure, compare_sections_command, _("\
11772 Compare section data on target to the exec file.\n\
11773 Argument is a single section name (default: all loaded sections)."),
11776 add_cmd ("packet", class_maintenance, packet_command, _("\
11777 Send an arbitrary packet to a remote target.\n\
11778 maintenance packet TEXT\n\
11779 If GDB is talking to an inferior via the GDB serial protocol, then\n\
11780 this command sends the string TEXT to the inferior, and displays the\n\
11781 response packet. GDB supplies the initial `$' character, and the\n\
11782 terminating `#' character and checksum."),
11785 add_setshow_boolean_cmd ("remotebreak", no_class, &remote_break, _("\
11786 Set whether to send break if interrupted."), _("\
11787 Show whether to send break if interrupted."), _("\
11788 If set, a break, instead of a cntrl-c, is sent to the remote target."),
11789 set_remotebreak, show_remotebreak,
11790 &setlist, &showlist);
11791 cmd_name = "remotebreak";
11792 cmd = lookup_cmd (&cmd_name, setlist, "", -1, 1);
11793 deprecate_cmd (cmd, "set remote interrupt-sequence");
11794 cmd_name = "remotebreak"; /* needed because lookup_cmd updates the pointer */
11795 cmd = lookup_cmd (&cmd_name, showlist, "", -1, 1);
11796 deprecate_cmd (cmd, "show remote interrupt-sequence");
11798 add_setshow_enum_cmd ("interrupt-sequence", class_support,
11799 interrupt_sequence_modes, &interrupt_sequence_mode,
11801 Set interrupt sequence to remote target."), _("\
11802 Show interrupt sequence to remote target."), _("\
11803 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
11804 NULL, show_interrupt_sequence,
11805 &remote_set_cmdlist,
11806 &remote_show_cmdlist);
11808 add_setshow_boolean_cmd ("interrupt-on-connect", class_support,
11809 &interrupt_on_connect, _("\
11810 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11811 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11812 If set, interrupt sequence is sent to remote target."),
11814 &remote_set_cmdlist, &remote_show_cmdlist);
11816 /* Install commands for configuring memory read/write packets. */
11818 add_cmd ("remotewritesize", no_class, set_memory_write_packet_size, _("\
11819 Set the maximum number of bytes per memory write packet (deprecated)."),
11821 add_cmd ("remotewritesize", no_class, show_memory_write_packet_size, _("\
11822 Show the maximum number of bytes per memory write packet (deprecated)."),
11824 add_cmd ("memory-write-packet-size", no_class,
11825 set_memory_write_packet_size, _("\
11826 Set the maximum number of bytes per memory-write packet.\n\
11827 Specify the number of bytes in a packet or 0 (zero) for the\n\
11828 default packet size. The actual limit is further reduced\n\
11829 dependent on the target. Specify ``fixed'' to disable the\n\
11830 further restriction and ``limit'' to enable that restriction."),
11831 &remote_set_cmdlist);
11832 add_cmd ("memory-read-packet-size", no_class,
11833 set_memory_read_packet_size, _("\
11834 Set the maximum number of bytes per memory-read packet.\n\
11835 Specify the number of bytes in a packet or 0 (zero) for the\n\
11836 default packet size. The actual limit is further reduced\n\
11837 dependent on the target. Specify ``fixed'' to disable the\n\
11838 further restriction and ``limit'' to enable that restriction."),
11839 &remote_set_cmdlist);
11840 add_cmd ("memory-write-packet-size", no_class,
11841 show_memory_write_packet_size,
11842 _("Show the maximum number of bytes per memory-write packet."),
11843 &remote_show_cmdlist);
11844 add_cmd ("memory-read-packet-size", no_class,
11845 show_memory_read_packet_size,
11846 _("Show the maximum number of bytes per memory-read packet."),
11847 &remote_show_cmdlist);
11849 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class,
11850 &remote_hw_watchpoint_limit, _("\
11851 Set the maximum number of target hardware watchpoints."), _("\
11852 Show the maximum number of target hardware watchpoints."), _("\
11853 Specify a negative limit for unlimited."),
11854 NULL, NULL, /* FIXME: i18n: The maximum
11855 number of target hardware
11856 watchpoints is %s. */
11857 &remote_set_cmdlist, &remote_show_cmdlist);
11858 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class,
11859 &remote_hw_watchpoint_length_limit, _("\
11860 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11861 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11862 Specify a negative limit for unlimited."),
11863 NULL, NULL, /* FIXME: i18n: The maximum
11864 length (in bytes) of a target
11865 hardware watchpoint is %s. */
11866 &remote_set_cmdlist, &remote_show_cmdlist);
11867 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class,
11868 &remote_hw_breakpoint_limit, _("\
11869 Set the maximum number of target hardware breakpoints."), _("\
11870 Show the maximum number of target hardware breakpoints."), _("\
11871 Specify a negative limit for unlimited."),
11872 NULL, NULL, /* FIXME: i18n: The maximum
11873 number of target hardware
11874 breakpoints is %s. */
11875 &remote_set_cmdlist, &remote_show_cmdlist);
11877 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure,
11878 &remote_address_size, _("\
11879 Set the maximum size of the address (in bits) in a memory packet."), _("\
11880 Show the maximum size of the address (in bits) in a memory packet."), NULL,
11882 NULL, /* FIXME: i18n: */
11883 &setlist, &showlist);
11885 add_packet_config_cmd (&remote_protocol_packets[PACKET_X],
11886 "X", "binary-download", 1);
11888 add_packet_config_cmd (&remote_protocol_packets[PACKET_vCont],
11889 "vCont", "verbose-resume", 0);
11891 add_packet_config_cmd (&remote_protocol_packets[PACKET_QPassSignals],
11892 "QPassSignals", "pass-signals", 0);
11894 add_packet_config_cmd (&remote_protocol_packets[PACKET_QProgramSignals],
11895 "QProgramSignals", "program-signals", 0);
11897 add_packet_config_cmd (&remote_protocol_packets[PACKET_qSymbol],
11898 "qSymbol", "symbol-lookup", 0);
11900 add_packet_config_cmd (&remote_protocol_packets[PACKET_P],
11901 "P", "set-register", 1);
11903 add_packet_config_cmd (&remote_protocol_packets[PACKET_p],
11904 "p", "fetch-register", 1);
11906 add_packet_config_cmd (&remote_protocol_packets[PACKET_Z0],
11907 "Z0", "software-breakpoint", 0);
11909 add_packet_config_cmd (&remote_protocol_packets[PACKET_Z1],
11910 "Z1", "hardware-breakpoint", 0);
11912 add_packet_config_cmd (&remote_protocol_packets[PACKET_Z2],
11913 "Z2", "write-watchpoint", 0);
11915 add_packet_config_cmd (&remote_protocol_packets[PACKET_Z3],
11916 "Z3", "read-watchpoint", 0);
11918 add_packet_config_cmd (&remote_protocol_packets[PACKET_Z4],
11919 "Z4", "access-watchpoint", 0);
11921 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_auxv],
11922 "qXfer:auxv:read", "read-aux-vector", 0);
11924 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_features],
11925 "qXfer:features:read", "target-features", 0);
11927 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_libraries],
11928 "qXfer:libraries:read", "library-info", 0);
11930 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_libraries_svr4],
11931 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
11933 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_memory_map],
11934 "qXfer:memory-map:read", "memory-map", 0);
11936 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_spu_read],
11937 "qXfer:spu:read", "read-spu-object", 0);
11939 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_spu_write],
11940 "qXfer:spu:write", "write-spu-object", 0);
11942 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_osdata],
11943 "qXfer:osdata:read", "osdata", 0);
11945 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_threads],
11946 "qXfer:threads:read", "threads", 0);
11948 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_siginfo_read],
11949 "qXfer:siginfo:read", "read-siginfo-object", 0);
11951 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_siginfo_write],
11952 "qXfer:siginfo:write", "write-siginfo-object", 0);
11954 add_packet_config_cmd
11955 (&remote_protocol_packets[PACKET_qXfer_traceframe_info],
11956 "qXfer:traceframe-info:read", "traceframe-info", 0);
11958 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_uib],
11959 "qXfer:uib:read", "unwind-info-block", 0);
11961 add_packet_config_cmd (&remote_protocol_packets[PACKET_qGetTLSAddr],
11962 "qGetTLSAddr", "get-thread-local-storage-address",
11965 add_packet_config_cmd (&remote_protocol_packets[PACKET_qGetTIBAddr],
11966 "qGetTIBAddr", "get-thread-information-block-address",
11969 add_packet_config_cmd (&remote_protocol_packets[PACKET_bc],
11970 "bc", "reverse-continue", 0);
11972 add_packet_config_cmd (&remote_protocol_packets[PACKET_bs],
11973 "bs", "reverse-step", 0);
11975 add_packet_config_cmd (&remote_protocol_packets[PACKET_qSupported],
11976 "qSupported", "supported-packets", 0);
11978 add_packet_config_cmd (&remote_protocol_packets[PACKET_qSearch_memory],
11979 "qSearch:memory", "search-memory", 0);
11981 add_packet_config_cmd (&remote_protocol_packets[PACKET_qTStatus],
11982 "qTStatus", "trace-status", 0);
11984 add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_open],
11985 "vFile:open", "hostio-open", 0);
11987 add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_pread],
11988 "vFile:pread", "hostio-pread", 0);
11990 add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_pwrite],
11991 "vFile:pwrite", "hostio-pwrite", 0);
11993 add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_close],
11994 "vFile:close", "hostio-close", 0);
11996 add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_unlink],
11997 "vFile:unlink", "hostio-unlink", 0);
11999 add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_readlink],
12000 "vFile:readlink", "hostio-readlink", 0);
12002 add_packet_config_cmd (&remote_protocol_packets[PACKET_vAttach],
12003 "vAttach", "attach", 0);
12005 add_packet_config_cmd (&remote_protocol_packets[PACKET_vRun],
12008 add_packet_config_cmd (&remote_protocol_packets[PACKET_QStartNoAckMode],
12009 "QStartNoAckMode", "noack", 0);
12011 add_packet_config_cmd (&remote_protocol_packets[PACKET_vKill],
12012 "vKill", "kill", 0);
12014 add_packet_config_cmd (&remote_protocol_packets[PACKET_qAttached],
12015 "qAttached", "query-attached", 0);
12017 add_packet_config_cmd (&remote_protocol_packets[PACKET_ConditionalTracepoints],
12018 "ConditionalTracepoints",
12019 "conditional-tracepoints", 0);
12021 add_packet_config_cmd (&remote_protocol_packets[PACKET_ConditionalBreakpoints],
12022 "ConditionalBreakpoints",
12023 "conditional-breakpoints", 0);
12025 add_packet_config_cmd (&remote_protocol_packets[PACKET_BreakpointCommands],
12026 "BreakpointCommands",
12027 "breakpoint-commands", 0);
12029 add_packet_config_cmd (&remote_protocol_packets[PACKET_FastTracepoints],
12030 "FastTracepoints", "fast-tracepoints", 0);
12032 add_packet_config_cmd (&remote_protocol_packets[PACKET_TracepointSource],
12033 "TracepointSource", "TracepointSource", 0);
12035 add_packet_config_cmd (&remote_protocol_packets[PACKET_QAllow],
12036 "QAllow", "allow", 0);
12038 add_packet_config_cmd (&remote_protocol_packets[PACKET_StaticTracepoints],
12039 "StaticTracepoints", "static-tracepoints", 0);
12041 add_packet_config_cmd (&remote_protocol_packets[PACKET_InstallInTrace],
12042 "InstallInTrace", "install-in-trace", 0);
12044 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_statictrace_read],
12045 "qXfer:statictrace:read", "read-sdata-object", 0);
12047 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_fdpic],
12048 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
12050 add_packet_config_cmd (&remote_protocol_packets[PACKET_QDisableRandomization],
12051 "QDisableRandomization", "disable-randomization", 0);
12053 add_packet_config_cmd (&remote_protocol_packets[PACKET_QAgent],
12054 "QAgent", "agent", 0);
12056 add_packet_config_cmd (&remote_protocol_packets[PACKET_QTBuffer_size],
12057 "QTBuffer:size", "trace-buffer-size", 0);
12059 add_packet_config_cmd (&remote_protocol_packets[PACKET_Qbtrace_off],
12060 "Qbtrace:off", "disable-btrace", 0);
12062 add_packet_config_cmd (&remote_protocol_packets[PACKET_Qbtrace_bts],
12063 "Qbtrace:bts", "enable-btrace", 0);
12065 add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_btrace],
12066 "qXfer:btrace", "read-btrace", 0);
12068 /* Keep the old ``set remote Z-packet ...'' working. Each individual
12069 Z sub-packet has its own set and show commands, but users may
12070 have sets to this variable in their .gdbinit files (or in their
12072 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure,
12073 &remote_Z_packet_detect, _("\
12074 Set use of remote protocol `Z' packets"), _("\
12075 Show use of remote protocol `Z' packets "), _("\
12076 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
12078 set_remote_protocol_Z_packet_cmd,
12079 show_remote_protocol_Z_packet_cmd,
12080 /* FIXME: i18n: Use of remote protocol
12081 `Z' packets is %s. */
12082 &remote_set_cmdlist, &remote_show_cmdlist);
12084 add_prefix_cmd ("remote", class_files, remote_command, _("\
12085 Manipulate files on the remote system\n\
12086 Transfer files to and from the remote target system."),
12087 &remote_cmdlist, "remote ",
12088 0 /* allow-unknown */, &cmdlist);
12090 add_cmd ("put", class_files, remote_put_command,
12091 _("Copy a local file to the remote system."),
12094 add_cmd ("get", class_files, remote_get_command,
12095 _("Copy a remote file to the local system."),
12098 add_cmd ("delete", class_files, remote_delete_command,
12099 _("Delete a remote file."),
12102 remote_exec_file = xstrdup ("");
12103 add_setshow_string_noescape_cmd ("exec-file", class_files,
12104 &remote_exec_file, _("\
12105 Set the remote pathname for \"run\""), _("\
12106 Show the remote pathname for \"run\""), NULL, NULL, NULL,
12107 &remote_set_cmdlist, &remote_show_cmdlist);
12109 add_setshow_boolean_cmd ("range-stepping", class_run,
12110 &use_range_stepping, _("\
12111 Enable or disable range stepping."), _("\
12112 Show whether target-assisted range stepping is enabled."), _("\
12113 If on, and the target supports it, when stepping a source line, GDB\n\
12114 tells the target to step the corresponding range of addresses itself instead\n\
12115 of issuing multiple single-steps. This speeds up source level\n\
12116 stepping. If off, GDB always issues single-steps, even if range\n\
12117 stepping is supported by the target. The default is on."),
12118 set_range_stepping,
12119 show_range_stepping,
12123 /* Eventually initialize fileio. See fileio.c */
12124 initialize_remote_fileio (remote_set_cmdlist, remote_show_cmdlist);
12126 /* Take advantage of the fact that the LWP field is not used, to tag
12127 special ptids with it set to != 0. */
12128 magic_null_ptid = ptid_build (42000, 1, -1);
12129 not_sent_ptid = ptid_build (42000, 1, -2);
12130 any_thread_ptid = ptid_build (42000, 1, 0);
12132 target_buf_size = 2048;
12133 target_buf = xmalloc (target_buf_size);