GDB (xrefs)
/tmp/gdb-8.1/gdb/remote.c
Go to the documentation of this file.
1 /* Remote target communications for serial-line targets in custom GDB protocol
2 
3  Copyright (C) 1988-2018 Free Software Foundation, Inc.
4 
5  This file is part of GDB.
6 
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.
11 
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.
16 
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/>. */
19 
20 /* See the GDB User Guide for details of the GDB remote protocol. */
21 
22 #include "defs.h"
23 #include <ctype.h>
24 #include <fcntl.h>
25 #include "inferior.h"
26 #include "infrun.h"
27 #include "bfd.h"
28 #include "symfile.h"
29 #include "target.h"
30 /*#include "terminal.h" */
31 #include "gdbcmd.h"
32 #include "objfiles.h"
33 #include "gdb-stabs.h"
34 #include "gdbthread.h"
35 #include "remote.h"
36 #include "remote-notif.h"
37 #include "regcache.h"
38 #include "value.h"
39 #include "observer.h"
40 #include "solib.h"
41 #include "cli/cli-decode.h"
42 #include "cli/cli-setshow.h"
43 #include "target-descriptions.h"
44 #include "gdb_bfd.h"
45 #include "filestuff.h"
46 #include "rsp-low.h"
47 #include "disasm.h"
48 #include "location.h"
49 
50 #include "gdb_sys_time.h"
51 
52 #include "event-loop.h"
53 #include "event-top.h"
54 #include "inf-loop.h"
55 
56 #include <signal.h>
57 #include "serial.h"
58 
59 #include "gdbcore.h" /* for exec_bfd */
60 
61 #include "remote-fileio.h"
62 #include "gdb/fileio.h"
63 #include <sys/stat.h>
64 #include "xml-support.h"
65 
66 #include "memory-map.h"
67 
68 #include "tracepoint.h"
69 #include "ax.h"
70 #include "ax-gdb.h"
71 #include "agent.h"
72 #include "btrace.h"
73 #include "record-btrace.h"
74 #include <algorithm>
75 #include "common/scoped_restore.h"
76 #include "environ.h"
77 #include "common/byte-vector.h"
78 
79 /* Per-program-space data key. */
80 static const struct program_space_data *remote_pspace_data;
81 
82 /* The variable registered as the control variable used by the
83  remote exec-file commands. While the remote exec-file setting is
84  per-program-space, the set/show machinery uses this as the
85  location of the remote exec-file value. */
86 static char *remote_exec_file_var;
87 
88 /* The size to align memory write packets, when practical. The protocol
89  does not guarantee any alignment, and gdb will generate short
90  writes and unaligned writes, but even as a best-effort attempt this
91  can improve bulk transfers. For instance, if a write is misaligned
92  relative to the target's data bus, the stub may need to make an extra
93  round trip fetching data from the target. This doesn't make a
94  huge difference, but it's easy to do, so we try to be helpful.
95 
96  The alignment chosen is arbitrary; usually data bus width is
97  important here, not the possibly larger cache line size. */
98 enum { REMOTE_ALIGN_WRITES = 16 };
99 
100 /* Prototypes for local functions. */
101 static int getpkt_sane (char **buf, long *sizeof_buf, int forever);
102 static int getpkt_or_notif_sane (char **buf, long *sizeof_buf,
103  int forever, int *is_notif);
104 
105 static void remote_files_info (struct target_ops *ignore);
106 
107 static void remote_prepare_to_store (struct target_ops *self,
108  struct regcache *regcache);
109 
110 static void remote_open_1 (const char *, int, struct target_ops *,
111  int extended_p);
112 
113 static void remote_close (struct target_ops *self);
114 
115 struct remote_state;
116 
117 static int remote_vkill (int pid, struct remote_state *rs);
118 
119 static void remote_kill_k (void);
120 
121 static void remote_mourn (struct target_ops *ops);
122 
123 static void extended_remote_restart (void);
124 
125 static void remote_send (char **buf, long *sizeof_buf_p);
126 
127 static int readchar (int timeout);
128 
129 static void remote_serial_write (const char *str, int len);
130 
131 static void remote_kill (struct target_ops *ops);
132 
133 static int remote_can_async_p (struct target_ops *);
134 
135 static int remote_is_async_p (struct target_ops *);
136 
137 static void remote_async (struct target_ops *ops, int enable);
138 
139 static void remote_thread_events (struct target_ops *ops, int enable);
140 
141 static void interrupt_query (void);
142 
143 static void set_general_thread (ptid_t ptid);
144 static void set_continue_thread (ptid_t ptid);
145 
146 static void get_offsets (void);
147 
148 static void skip_frame (void);
149 
150 static long read_frame (char **buf_p, long *sizeof_buf);
151 
152 static int hexnumlen (ULONGEST num);
153 
154 static void init_remote_ops (void);
155 
156 static void init_extended_remote_ops (void);
157 
158 static void remote_stop (struct target_ops *self, ptid_t);
159 
160 static int stubhex (int ch);
161 
162 static int hexnumstr (char *, ULONGEST);
163 
164 static int hexnumnstr (char *, ULONGEST, int);
165 
167 
168 static void print_packet (const char *);
169 
170 static int stub_unpack_int (char *buff, int fieldlength);
171 
172 static ptid_t remote_current_thread (ptid_t oldptid);
173 
174 static int putpkt_binary (const char *buf, int cnt);
175 
176 static void check_binary_download (CORE_ADDR addr);
177 
178 struct packet_config;
179 
180 static void show_packet_config_cmd (struct packet_config *config);
181 
182 static void show_remote_protocol_packet_cmd (struct ui_file *file,
183  int from_tty,
184  struct cmd_list_element *c,
185  const char *value);
186 
187 static char *write_ptid (char *buf, const char *endbuf, ptid_t ptid);
188 static ptid_t read_ptid (const char *buf, const char **obuf);
189 
190 static void remote_set_permissions (struct target_ops *self);
191 
192 static int remote_get_trace_status (struct target_ops *self,
193  struct trace_status *ts);
194 
195 static int remote_upload_tracepoints (struct target_ops *self,
196  struct uploaded_tp **utpp);
197 
198 static int remote_upload_trace_state_variables (struct target_ops *self,
199  struct uploaded_tsv **utsvp);
200 
201 static void remote_query_supported (void);
202 
203 static void remote_check_symbols (void);
204 
205 struct stop_reply;
206 static void stop_reply_xfree (struct stop_reply *);
207 static void remote_parse_stop_reply (char *, struct stop_reply *);
208 static void push_stop_reply (struct stop_reply *);
210 static int peek_stop_reply (ptid_t ptid);
211 
214 
216 
217 static void remote_terminal_ours (struct target_ops *self);
218 
219 static int remote_read_description_p (struct target_ops *target);
220 
221 static void remote_console_output (char *msg);
222 
223 static int remote_supports_cond_breakpoints (struct target_ops *self);
224 
225 static int remote_can_run_breakpoint_commands (struct target_ops *self);
226 
227 static void remote_btrace_reset (void);
228 
229 static void remote_btrace_maybe_reopen (void);
230 
231 static int stop_reply_queue_length (void);
232 
233 static void readahead_cache_invalidate (void);
234 
235 static void remote_unpush_and_throw (void);
236 
237 static struct remote_state *get_remote_state (void);
238 
239 /* For "remote". */
240 
242 
243 /* For "set remote" and "show remote". */
244 
247 
248 /* Stub vCont actions support.
249 
250  Each field is a boolean flag indicating whether the stub reports
251  support for the corresponding action. */
252 
254 {
255  /* vCont;t */
256  int t;
257 
258  /* vCont;r */
259  int r;
260 
261  /* vCont;s */
262  int s;
263 
264  /* vCont;S */
265  int S;
266 };
267 
268 /* Controls whether GDB is willing to use range stepping. */
269 
270 static int use_range_stepping = 1;
271 
272 #define OPAQUETHREADBYTES 8
273 
274 /* a 64 bit opaque identifier */
275 typedef unsigned char threadref[OPAQUETHREADBYTES];
276 
277 /* About this many threadisds fit in a packet. */
278 
279 #define MAXTHREADLISTRESULTS 32
280 
281 /* The max number of chars in debug output. The rest of chars are
282  omitted. */
283 
284 #define REMOTE_DEBUG_MAX_CHAR 512
285 
286 /* Data for the vFile:pread readahead cache. */
287 
289 {
290  /* The file descriptor for the file that is being cached. -1 if the
291  cache is invalid. */
292  int fd;
293 
294  /* The offset into the file that the cache buffer corresponds
295  to. */
297 
298  /* The buffer holding the cache contents. */
300  /* The buffer's size. We try to read as much as fits into a packet
301  at a time. */
302  size_t bufsize;
303 
304  /* Cache hit and miss counters. */
307 };
308 
309 /* Description of the remote protocol state for the currently
310  connected target. This is per-target state, and independent of the
311  selected architecture. */
312 
314 {
315  /* A buffer to use for incoming packets, and its current size. The
316  buffer is grown dynamically for larger incoming packets.
317  Outgoing packets may also be constructed in this buffer.
318  BUF_SIZE is always at least REMOTE_PACKET_SIZE;
319  REMOTE_PACKET_SIZE should be used to limit the length of outgoing
320  packets. */
321  char *buf;
322  long buf_size;
323 
324  /* True if we're going through initial connection setup (finding out
325  about the remote side's threads, relocating symbols, etc.). */
327 
328  /* If we negotiated packet size explicitly (and thus can bypass
329  heuristics for the largest packet size that will not overflow
330  a buffer in the stub), this will be set to that packet size.
331  Otherwise zero, meaning to use the guessed size. */
333 
334  /* remote_wait is normally called when the target is running and
335  waits for a stop reply packet. But sometimes we need to call it
336  when the target is already stopped. We can send a "?" packet
337  and have remote_wait read the response. Or, if we already have
338  the response, we can stash it in BUF and tell remote_wait to
339  skip calling getpkt. This flag is set when BUF contains a
340  stop reply packet and the target is not waiting. */
342 
343  /* True, if in no ack mode. That is, neither GDB nor the stub will
344  expect acks from each other. The connection is assumed to be
345  reliable. */
347 
348  /* True if we're connected in extended remote mode. */
349  int extended;
350 
351  /* True if we resumed the target and we're waiting for the target to
352  stop. In the mean time, we can't start another command/query.
353  The remote server wouldn't be ready to process it, so we'd
354  timeout waiting for a reply that would never come and eventually
355  we'd close the connection. This can happen in asynchronous mode
356  because we allow GDB commands while the target is running. */
358 
359  /* The status of the stub support for the various vCont actions. */
361 
362  /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
363  responded to that. */
365 
366  /* True if we saw a Ctrl-C while reading or writing from/to the
367  remote descriptor. At that point it is not safe to send a remote
368  interrupt packet, so we instead remember we saw the Ctrl-C and
369  process it once we're done with sending/receiving the current
370  packet, which should be shortly. If however that takes too long,
371  and the user presses Ctrl-C again, we offer to disconnect. */
373 
374  /* Descriptor for I/O to remote machine. Initialize it to NULL so that
375  remote_open knows that we don't have a file open when the program
376  starts. */
378 
379  /* These are the threads which we last sent to the remote system. The
380  TID member will be -1 for all or -2 for not sent yet. */
383 
384  /* This is the traceframe which we last selected on the remote system.
385  It will be -1 if no traceframe is selected. */
387 
389 
390  /* The last QProgramSignals packet sent to the target. We bypass
391  sending a new program signals list down to the target if the new
392  packet is exactly the same as the last we sent. IOW, we only let
393  the target know about program signals list changes. */
395 
396  enum gdb_signal last_sent_signal;
397 
399 
400  /* The execution direction of the last resume we got. */
402 
406 
407  /* Should we try the 'ThreadInfo' query packet?
408 
409  This variable (NOT available to the user: auto-detect only!)
410  determines whether GDB will use the new, simpler "ThreadInfo"
411  query or the older, more complex syntax for thread queries.
412  This is an auto-detect variable (set to true at each connect,
413  and set to false when the target fails to recognize it). */
416 
420 
421  /* The state of remote notification. */
423 
424  /* The branch trace configuration. */
426 
427  /* The argument to the last "vFile:setfs:" packet we sent, used
428  to avoid sending repeated unnecessary "vFile:setfs:" packets.
429  Initialized to -1 to indicate that no "vFile:setfs:" packet
430  has yet been sent. */
431  int fs_pid;
432 
433  /* A readahead cache for vFile:pread. Often, reading a binary
434  involves a sequence of small reads. E.g., when parsing an ELF
435  file. A readahead cache helps mostly the case of remote
436  debugging on a connection with higher latency, due to the
437  request/reply nature of the RSP. We only cache data for a single
438  file descriptor at a time. */
440 };
441 
442 /* Private data that we'll store in (struct thread_info)->priv. */
444 {
447  int core = -1;
448 
449  /* Thread handle, perhaps a pthread_t or thread_t value, stored as a
450  sequence of bytes. */
452 
453  /* Whether the target stopped for a breakpoint/watchpoint. */
455 
456  /* This is set to the data address of the access causing the target
457  to stop for a watchpoint. */
459 
460  /* Fields used by the vCont action coalescing implemented in
461  remote_resume / remote_commit_resume. remote_resume stores each
462  thread's last resume request in these fields, so that a later
463  remote_commit_resume knows which is the proper action for this
464  thread to include in the vCont packet. */
465 
466  /* True if the last target_resume call for this thread was a step
467  request, false if a continue request. */
469 
470  /* The signal specified in the last target_resume call for this
471  thread. */
472  gdb_signal last_resume_sig = GDB_SIGNAL_0;
473 
474  /* Whether this thread was already vCont-resumed on the remote
475  side. */
476  int vcont_resumed = 0;
477 };
478 
479 /* This data could be associated with a target, but we do not always
480  have access to the current target when we need it, so for now it is
481  static. This will be fine for as long as only one target is in use
482  at a time. */
483 static struct remote_state *remote_state;
484 
485 static struct remote_state *
487 {
488  return remote_state;
489 }
490 
491 /* Allocate a new struct remote_state with xmalloc, initialize it, and
492  return it. */
493 
494 static struct remote_state *
496 {
497  struct remote_state *result = XCNEW (struct remote_state);
498 
499  /* The default buffer size is unimportant; it will be expanded
500  whenever a larger buffer is needed. */
501  result->buf_size = 400;
502  result->buf = (char *) xmalloc (result->buf_size);
503  result->remote_traceframe_number = -1;
504  result->last_sent_signal = GDB_SIGNAL_0;
506  result->fs_pid = -1;
507 
508  return result;
509 }
510 
511 /* Description of the remote protocol for a given architecture. */
512 
514 {
515  long offset; /* Offset into G packet. */
516  long regnum; /* GDB's internal register number. */
517  LONGEST pnum; /* Remote protocol register number. */
518  int in_g_packet; /* Always part of G packet. */
519  /* long size in bytes; == register_size (target_gdbarch (), regnum);
520  at present. */
521  /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
522  at present. */
523 };
524 
526 {
527  /* Description of the remote protocol registers. */
529 
530  /* Description of the remote protocol registers indexed by REGNUM
531  (making an array gdbarch_num_regs in size). */
532  struct packet_reg *regs;
533 
534  /* This is the size (in chars) of the first response to the ``g''
535  packet. It is used as a heuristic when determining the maximum
536  size of memory-read and memory-write packets. A target will
537  typically only reserve a buffer large enough to hold the ``g''
538  packet. The size does not include packet overhead (headers and
539  trailers). */
541 
542  /* This is the maximum size (in chars) of a non read/write packet.
543  It is also used as a cap on the size of read/write packets. */
545 };
546 
547 /* Utility: generate error from an incoming stub packet. */
548 static void
549 trace_error (char *buf)
550 {
551  if (*buf++ != 'E')
552  return; /* not an error msg */
553  switch (*buf)
554  {
555  case '1': /* malformed packet error */
556  if (*++buf == '0') /* general case: */
557  error (_("remote.c: error in outgoing packet."));
558  else
559  error (_("remote.c: error in outgoing packet at field #%ld."),
560  strtol (buf, NULL, 16));
561  default:
562  error (_("Target returns error code '%s'."), buf);
563  }
564 }
565 
566 /* Utility: wait for reply from stub, while accepting "O" packets. */
567 
568 static char *
570 {
571  struct remote_state *rs = get_remote_state ();
572 
573  do /* Loop on reply from remote stub. */
574  {
575  char *buf;
576 
577  QUIT; /* Allow user to bail out with ^C. */
578  getpkt (&rs->buf, &rs->buf_size, 0);
579  buf = rs->buf;
580  if (buf[0] == 'E')
581  trace_error (buf);
582  else if (startswith (buf, "qRelocInsn:"))
583  {
584  ULONGEST ul;
585  CORE_ADDR from, to, org_to;
586  const char *p, *pp;
587  int adjusted_size = 0;
588  int relocated = 0;
589 
590  p = buf + strlen ("qRelocInsn:");
591  pp = unpack_varlen_hex (p, &ul);
592  if (*pp != ';')
593  error (_("invalid qRelocInsn packet: %s"), buf);
594  from = ul;
595 
596  p = pp + 1;
597  unpack_varlen_hex (p, &ul);
598  to = ul;
599 
600  org_to = to;
601 
602  TRY
603  {
605  relocated = 1;
606  }
607  CATCH (ex, RETURN_MASK_ALL)
608  {
609  if (ex.error == MEMORY_ERROR)
610  {
611  /* Propagate memory errors silently back to the
612  target. The stub may have limited the range of
613  addresses we can write to, for example. */
614  }
615  else
616  {
617  /* Something unexpectedly bad happened. Be verbose
618  so we can tell what, and propagate the error back
619  to the stub, so it doesn't get stuck waiting for
620  a response. */
622  _("warning: relocating instruction: "));
623  }
624  putpkt ("E01");
625  }
626  END_CATCH
627 
628  if (relocated)
629  {
630  adjusted_size = to - org_to;
631 
632  xsnprintf (buf, rs->buf_size, "qRelocInsn:%x", adjusted_size);
633  putpkt (buf);
634  }
635  }
636  else if (buf[0] == 'O' && buf[1] != 'K')
637  remote_console_output (buf + 1); /* 'O' message from stub */
638  else
639  return buf; /* Here's the actual reply. */
640  }
641  while (1);
642 }
643 
644 /* Handle for retreving the remote protocol data from gdbarch. */
646 
647 static struct remote_arch_state *
649 {
650  gdb_assert (gdbarch != NULL);
651  return ((struct remote_arch_state *)
653 }
654 
655 /* Fetch the global remote target state. */
656 
657 static struct remote_state *
659 {
660  /* Make sure that the remote architecture state has been
661  initialized, because doing so might reallocate rs->buf. Any
662  function which calls getpkt also needs to be mindful of changes
663  to rs->buf, but this call limits the number of places which run
664  into trouble. */
666 
667  return get_remote_state_raw ();
668 }
669 
670 /* Cleanup routine for the remote module's pspace data. */
671 
672 static void
673 remote_pspace_data_cleanup (struct program_space *pspace, void *arg)
674 {
675  char *remote_exec_file = (char *) arg;
676 
677  xfree (remote_exec_file);
678 }
679 
680 /* Fetch the remote exec-file from the current program space. */
681 
682 static const char *
684 {
685  char *remote_exec_file;
686 
687  remote_exec_file
688  = (char *) program_space_data (current_program_space,
690  if (remote_exec_file == NULL)
691  return "";
692 
693  return remote_exec_file;
694 }
695 
696 /* Set the remote exec file for PSPACE. */
697 
698 static void
700  char *remote_exec_file)
701 {
702  char *old_file = (char *) program_space_data (pspace, remote_pspace_data);
703 
704  xfree (old_file);
705  set_program_space_data (pspace, remote_pspace_data,
706  xstrdup (remote_exec_file));
707 }
708 
709 /* The "set/show remote exec-file" set command hook. */
710 
711 static void
712 set_remote_exec_file (const char *ignored, int from_tty,
713  struct cmd_list_element *c)
714 {
717 }
718 
719 /* The "set/show remote exec-file" show command hook. */
720 
721 static void
722 show_remote_exec_file (struct ui_file *file, int from_tty,
723  struct cmd_list_element *cmd, const char *value)
724 {
725  fprintf_filtered (file, "%s\n", remote_exec_file_var);
726 }
727 
728 static int
729 compare_pnums (const void *lhs_, const void *rhs_)
730 {
731  const struct packet_reg * const *lhs
732  = (const struct packet_reg * const *) lhs_;
733  const struct packet_reg * const *rhs
734  = (const struct packet_reg * const *) rhs_;
735 
736  if ((*lhs)->pnum < (*rhs)->pnum)
737  return -1;
738  else if ((*lhs)->pnum == (*rhs)->pnum)
739  return 0;
740  else
741  return 1;
742 }
743 
744 static int
746 {
747  int regnum, num_remote_regs, offset;
748  struct packet_reg **remote_regs;
749 
750  for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
751  {
752  struct packet_reg *r = &regs[regnum];
753 
754  if (register_size (gdbarch, regnum) == 0)
755  /* Do not try to fetch zero-sized (placeholder) registers. */
756  r->pnum = -1;
757  else
759 
760  r->regnum = regnum;
761  }
762 
763  /* Define the g/G packet format as the contents of each register
764  with a remote protocol number, in order of ascending protocol
765  number. */
766 
767  remote_regs = XALLOCAVEC (struct packet_reg *, gdbarch_num_regs (gdbarch));
768  for (num_remote_regs = 0, regnum = 0;
770  regnum++)
771  if (regs[regnum].pnum != -1)
772  remote_regs[num_remote_regs++] = &regs[regnum];
773 
774  qsort (remote_regs, num_remote_regs, sizeof (struct packet_reg *),
775  compare_pnums);
776 
777  for (regnum = 0, offset = 0; regnum < num_remote_regs; regnum++)
778  {
779  remote_regs[regnum]->in_g_packet = 1;
780  remote_regs[regnum]->offset = offset;
781  offset += register_size (gdbarch, remote_regs[regnum]->regnum);
782  }
783 
784  return offset;
785 }
786 
787 /* Given the architecture described by GDBARCH, return the remote
788  protocol register's number and the register's offset in the g/G
789  packets of GDB register REGNUM, in PNUM and POFFSET respectively.
790  If the target does not have a mapping for REGNUM, return false,
791  otherwise, return true. */
792 
793 int
795  int *pnum, int *poffset)
796 {
798 
799  std::vector<packet_reg> regs (gdbarch_num_regs (gdbarch));
800 
802 
803  *pnum = regs[regnum].pnum;
804  *poffset = regs[regnum].offset;
805 
806  return *pnum != -1;
807 }
808 
809 static void *
811 {
812  struct remote_state *rs = get_remote_state_raw ();
813  struct remote_arch_state *rsa;
814 
816 
817  /* Use the architecture to build a regnum<->pnum table, which will be
818  1:1 unless a feature set specifies otherwise. */
821  struct packet_reg);
822 
823  /* Record the maximum possible size of the g packet - it may turn out
824  to be smaller. */
826 
827  /* Default maximum number of characters in a packet body. Many
828  remote stubs have a hardwired buffer size of 400 bytes
829  (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
830  as the maximum packet-size to ensure that the packet and an extra
831  NUL character can always fit in the buffer. This stops GDB
832  trashing stubs that try to squeeze an extra NUL into what is
833  already a full buffer (As of 1999-12-04 that was most stubs). */
834  rsa->remote_packet_size = 400 - 1;
835 
836  /* This one is filled in when a ``g'' packet is received. */
838 
839  /* Should rsa->sizeof_g_packet needs more space than the
840  default, adjust the size accordingly. Remember that each byte is
841  encoded as two characters. 32 is the overhead for the packet
842  header / footer. NOTE: cagney/1999-10-26: I suspect that 8
843  (``$NN:G...#NN'') is a better guess, the below has been padded a
844  little. */
845  if (rsa->sizeof_g_packet > ((rsa->remote_packet_size - 32) / 2))
846  rsa->remote_packet_size = (rsa->sizeof_g_packet * 2 + 32);
847 
848  /* Make sure that the packet buffer is plenty big enough for
849  this architecture. */
850  if (rs->buf_size < rsa->remote_packet_size)
851  {
852  rs->buf_size = 2 * rsa->remote_packet_size;
853  rs->buf = (char *) xrealloc (rs->buf, rs->buf_size);
854  }
855 
856  return rsa;
857 }
858 
859 /* Return the current allowed size of a remote packet. This is
860  inferred from the current architecture, and should be used to
861  limit the length of outgoing packets. */
862 static long
864 {
865  struct remote_state *rs = get_remote_state ();
867 
868  if (rs->explicit_packet_size)
869  return rs->explicit_packet_size;
870 
871  return rsa->remote_packet_size;
872 }
873 
874 static struct packet_reg *
876  long regnum)
877 {
878  if (regnum < 0 && regnum >= gdbarch_num_regs (gdbarch))
879  return NULL;
880  else
881  {
882  struct packet_reg *r = &rsa->regs[regnum];
883 
884  gdb_assert (r->regnum == regnum);
885  return r;
886  }
887 }
888 
889 static struct packet_reg *
891  LONGEST pnum)
892 {
893  int i;
894 
895  for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
896  {
897  struct packet_reg *r = &rsa->regs[i];
898 
899  if (r->pnum == pnum)
900  return r;
901  }
902  return NULL;
903 }
904 
905 static struct target_ops remote_ops;
906 
908 
909 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
910  ``forever'' still use the normal timeout mechanism. This is
911  currently used by the ASYNC code to guarentee that target reads
912  during the initial connect always time-out. Once getpkt has been
913  modified to return a timeout indication and, in turn
914  remote_wait()/wait_for_inferior() have gained a timeout parameter
915  this can go away. */
916 static int wait_forever_enabled_p = 1;
917 
918 /* Allow the user to specify what sequence to send to the remote
919  when he requests a program interruption: Although ^C is usually
920  what remote systems expect (this is the default, here), it is
921  sometimes preferable to send a break. On other systems such
922  as the Linux kernel, a break followed by g, which is Magic SysRq g
923  is required in order to interrupt the execution. */
924 const char interrupt_sequence_control_c[] = "Ctrl-C";
925 const char interrupt_sequence_break[] = "BREAK";
926 const char interrupt_sequence_break_g[] = "BREAK-g";
927 static const char *const interrupt_sequence_modes[] =
928  {
932  NULL
933  };
935 
936 static void
937 show_interrupt_sequence (struct ui_file *file, int from_tty,
938  struct cmd_list_element *c,
939  const char *value)
940 {
942  fprintf_filtered (file,
943  _("Send the ASCII ETX character (Ctrl-c) "
944  "to the remote target to interrupt the "
945  "execution of the program.\n"));
947  fprintf_filtered (file,
948  _("send a break signal to the remote target "
949  "to interrupt the execution of the program.\n"));
951  fprintf_filtered (file,
952  _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
953  "the remote target to interrupt the execution "
954  "of Linux kernel.\n"));
955  else
956  internal_error (__FILE__, __LINE__,
957  _("Invalid value for interrupt_sequence_mode: %s."),
959 }
960 
961 /* This boolean variable specifies whether interrupt_sequence is sent
962  to the remote target when gdb connects to it.
963  This is mostly needed when you debug the Linux kernel: The Linux kernel
964  expects BREAK g which is Magic SysRq g for connecting gdb. */
965 static int interrupt_on_connect = 0;
966 
967 /* This variable is used to implement the "set/show remotebreak" commands.
968  Since these commands are now deprecated in favor of "set/show remote
969  interrupt-sequence", it no longer has any effect on the code. */
970 static int remote_break;
971 
972 static void
973 set_remotebreak (const char *args, int from_tty, struct cmd_list_element *c)
974 {
975  if (remote_break)
977  else
979 }
980 
981 static void
982 show_remotebreak (struct ui_file *file, int from_tty,
983  struct cmd_list_element *c,
984  const char *value)
985 {
986 }
987 
988 /* This variable sets the number of bits in an address that are to be
989  sent in a memory ("M" or "m") packet. Normally, after stripping
990  leading zeros, the entire address would be sent. This variable
991  restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
992  initial implementation of remote.c restricted the address sent in
993  memory packets to ``host::sizeof long'' bytes - (typically 32
994  bits). Consequently, for 64 bit targets, the upper 32 bits of an
995  address was never sent. Since fixing this bug may cause a break in
996  some remote targets this variable is principly provided to
997  facilitate backward compatibility. */
998 
999 static unsigned int remote_address_size;
1000 
1001 
1002 /* User configurable variables for the number of characters in a
1003  memory read/write packet. MIN (rsa->remote_packet_size,
1004  rsa->sizeof_g_packet) is the default. Some targets need smaller
1005  values (fifo overruns, et.al.) and some users need larger values
1006  (speed up transfers). The variables ``preferred_*'' (the user
1007  request), ``current_*'' (what was actually set) and ``forced_*''
1008  (Positive - a soft limit, negative - a hard limit). */
1009 
1011 {
1012  const char *name;
1013  long size;
1014  int fixed_p;
1015 };
1016 
1017 /* The default max memory-write-packet-size. The 16k is historical.
1018  (It came from older GDB's using alloca for buffers and the
1019  knowledge (folklore?) that some hosts don't cope very well with
1020  large alloca calls.) */
1021 #define DEFAULT_MAX_MEMORY_PACKET_SIZE 16384
1022 
1023 /* The minimum remote packet size for memory transfers. Ensures we
1024  can write at least one byte. */
1025 #define MIN_MEMORY_PACKET_SIZE 20
1026 
1027 /* Compute the current size of a read/write packet. Since this makes
1028  use of ``actual_register_packet_size'' the computation is dynamic. */
1029 
1030 static long
1032 {
1033  struct remote_state *rs = get_remote_state ();
1035 
1036  long what_they_get;
1037  if (config->fixed_p)
1038  {
1039  if (config->size <= 0)
1040  what_they_get = DEFAULT_MAX_MEMORY_PACKET_SIZE;
1041  else
1042  what_they_get = config->size;
1043  }
1044  else
1045  {
1046  what_they_get = get_remote_packet_size ();
1047  /* Limit the packet to the size specified by the user. */
1048  if (config->size > 0
1049  && what_they_get > config->size)
1050  what_they_get = config->size;
1051 
1052  /* Limit it to the size of the targets ``g'' response unless we have
1053  permission from the stub to use a larger packet size. */
1054  if (rs->explicit_packet_size == 0
1055  && rsa->actual_register_packet_size > 0
1056  && what_they_get > rsa->actual_register_packet_size)
1057  what_they_get = rsa->actual_register_packet_size;
1058  }
1059  if (what_they_get < MIN_MEMORY_PACKET_SIZE)
1060  what_they_get = MIN_MEMORY_PACKET_SIZE;
1061 
1062  /* Make sure there is room in the global buffer for this packet
1063  (including its trailing NUL byte). */
1064  if (rs->buf_size < what_they_get + 1)
1065  {
1066  rs->buf_size = 2 * what_they_get;
1067  rs->buf = (char *) xrealloc (rs->buf, 2 * what_they_get);
1068  }
1069 
1070  return what_they_get;
1071 }
1072 
1073 /* Update the size of a read/write packet. If they user wants
1074  something really big then do a sanity check. */
1075 
1076 static void
1077 set_memory_packet_size (const char *args, struct memory_packet_config *config)
1078 {
1079  int fixed_p = config->fixed_p;
1080  long size = config->size;
1081 
1082  if (args == NULL)
1083  error (_("Argument required (integer, `fixed' or `limited')."));
1084  else if (strcmp (args, "hard") == 0
1085  || strcmp (args, "fixed") == 0)
1086  fixed_p = 1;
1087  else if (strcmp (args, "soft") == 0
1088  || strcmp (args, "limit") == 0)
1089  fixed_p = 0;
1090  else
1091  {
1092  char *end;
1093 
1094  size = strtoul (args, &end, 0);
1095  if (args == end)
1096  error (_("Invalid %s (bad syntax)."), config->name);
1097 
1098  /* Instead of explicitly capping the size of a packet to or
1099  disallowing it, the user is allowed to set the size to
1100  something arbitrarily large. */
1101  }
1102 
1103  /* So that the query shows the correct value. */
1104  if (size <= 0)
1106 
1107  /* Extra checks? */
1108  if (fixed_p && !config->fixed_p)
1109  {
1110  if (! query (_("The target may not be able to correctly handle a %s\n"
1111  "of %ld bytes. Change the packet size? "),
1112  config->name, size))
1113  error (_("Packet size not changed."));
1114  }
1115  /* Update the config. */
1116  config->fixed_p = fixed_p;
1117  config->size = size;
1118 }
1119 
1120 static void
1122 {
1123  printf_filtered (_("The %s is %ld. "), config->name, config->size);
1124  if (config->fixed_p)
1125  printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1126  get_memory_packet_size (config));
1127  else
1128  printf_filtered (_("Packets are limited to %ld bytes.\n"),
1129  get_memory_packet_size (config));
1130 }
1131 
1133 {
1134  "memory-write-packet-size",
1135 };
1136 
1137 static void
1138 set_memory_write_packet_size (const char *args, int from_tty)
1139 {
1141 }
1142 
1143 static void
1144 show_memory_write_packet_size (const char *args, int from_tty)
1145 {
1147 }
1148 
1149 static long
1151 {
1153 }
1154 
1156 {
1157  "memory-read-packet-size",
1158 };
1159 
1160 static void
1161 set_memory_read_packet_size (const char *args, int from_tty)
1162 {
1164 }
1165 
1166 static void
1167 show_memory_read_packet_size (const char *args, int from_tty)
1168 {
1170 }
1171 
1172 static long
1174 {
1176 
1177  /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1178  extra buffer size argument before the memory read size can be
1179  increased beyond this. */
1180  if (size > get_remote_packet_size ())
1182  return size;
1183 }
1184 
1185 
1186 /* Generic configuration support for packets the stub optionally
1187  supports. Allows the user to specify the use of the packet as well
1188  as allowing GDB to auto-detect support in the remote stub. */
1189 
1191  {
1195  };
1196 
1198  {
1199  const char *name;
1200  const char *title;
1201 
1202  /* If auto, GDB auto-detects support for this packet or feature,
1203  either through qSupported, or by trying the packet and looking
1204  at the response. If true, GDB assumes the target supports this
1205  packet. If false, the packet is disabled. Configs that don't
1206  have an associated command always have this set to auto. */
1208 
1209  /* Does the target support this packet? */
1211  };
1212 
1213 /* Analyze a packet's return value and update the packet config
1214  accordingly. */
1215 
1217 {
1221 };
1222 
1223 static enum packet_support packet_config_support (struct packet_config *config);
1224 static enum packet_support packet_support (int packet);
1225 
1226 static void
1228 {
1229  const char *support = "internal-error";
1230 
1231  switch (packet_config_support (config))
1232  {
1233  case PACKET_ENABLE:
1234  support = "enabled";
1235  break;
1236  case PACKET_DISABLE:
1237  support = "disabled";
1238  break;
1240  support = "unknown";
1241  break;
1242  }
1243  switch (config->detect)
1244  {
1245  case AUTO_BOOLEAN_AUTO:
1246  printf_filtered (_("Support for the `%s' packet "
1247  "is auto-detected, currently %s.\n"),
1248  config->name, support);
1249  break;
1250  case AUTO_BOOLEAN_TRUE:
1251  case AUTO_BOOLEAN_FALSE:
1252  printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1253  config->name, support);
1254  break;
1255  }
1256 }
1257 
1258 static void
1259 add_packet_config_cmd (struct packet_config *config, const char *name,
1260  const char *title, int legacy)
1261 {
1262  char *set_doc;
1263  char *show_doc;
1264  char *cmd_name;
1265 
1266  config->name = name;
1267  config->title = title;
1268  set_doc = xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1269  name, title);
1270  show_doc = xstrprintf ("Show current use of remote "
1271  "protocol `%s' (%s) packet",
1272  name, title);
1273  /* set/show TITLE-packet {auto,on,off} */
1274  cmd_name = xstrprintf ("%s-packet", title);
1276  &config->detect, set_doc,
1277  show_doc, NULL, /* help_doc */
1278  NULL,
1281  /* The command code copies the documentation strings. */
1282  xfree (set_doc);
1283  xfree (show_doc);
1284  /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1285  if (legacy)
1286  {
1287  char *legacy_name;
1288 
1289  legacy_name = xstrprintf ("%s-packet", name);
1290  add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
1292  add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
1294  }
1295 }
1296 
1297 static enum packet_result
1298 packet_check_result (const char *buf)
1299 {
1300  if (buf[0] != '\0')
1301  {
1302  /* The stub recognized the packet request. Check that the
1303  operation succeeded. */
1304  if (buf[0] == 'E'
1305  && isxdigit (buf[1]) && isxdigit (buf[2])
1306  && buf[3] == '\0')
1307  /* "Enn" - definitly an error. */
1308  return PACKET_ERROR;
1309 
1310  /* Always treat "E." as an error. This will be used for
1311  more verbose error messages, such as E.memtypes. */
1312  if (buf[0] == 'E' && buf[1] == '.')
1313  return PACKET_ERROR;
1314 
1315  /* The packet may or may not be OK. Just assume it is. */
1316  return PACKET_OK;
1317  }
1318  else
1319  /* The stub does not support the packet. */
1320  return PACKET_UNKNOWN;
1321 }
1322 
1323 static enum packet_result
1324 packet_ok (const char *buf, struct packet_config *config)
1325 {
1326  enum packet_result result;
1327 
1328  if (config->detect != AUTO_BOOLEAN_TRUE
1329  && config->support == PACKET_DISABLE)
1330  internal_error (__FILE__, __LINE__,
1331  _("packet_ok: attempt to use a disabled packet"));
1332 
1333  result = packet_check_result (buf);
1334  switch (result)
1335  {
1336  case PACKET_OK:
1337  case PACKET_ERROR:
1338  /* The stub recognized the packet request. */
1339  if (config->support == PACKET_SUPPORT_UNKNOWN)
1340  {
1341  if (remote_debug)
1343  "Packet %s (%s) is supported\n",
1344  config->name, config->title);
1345  config->support = PACKET_ENABLE;
1346  }
1347  break;
1348  case PACKET_UNKNOWN:
1349  /* The stub does not support the packet. */
1350  if (config->detect == AUTO_BOOLEAN_AUTO
1351  && config->support == PACKET_ENABLE)
1352  {
1353  /* If the stub previously indicated that the packet was
1354  supported then there is a protocol error. */
1355  error (_("Protocol error: %s (%s) conflicting enabled responses."),
1356  config->name, config->title);
1357  }
1358  else if (config->detect == AUTO_BOOLEAN_TRUE)
1359  {
1360  /* The user set it wrong. */
1361  error (_("Enabled packet %s (%s) not recognized by stub"),
1362  config->name, config->title);
1363  }
1364 
1365  if (remote_debug)
1367  "Packet %s (%s) is NOT supported\n",
1368  config->name, config->title);
1369  config->support = PACKET_DISABLE;
1370  break;
1371  }
1372 
1373  return result;
1374 }
1375 
1376 enum {
1429 
1430  /* Support for conditional tracepoints. */
1432 
1433  /* Support for target-side breakpoint conditions. */
1435 
1436  /* Support for target-side breakpoint commands. */
1438 
1439  /* Support for fast tracepoints. */
1441 
1442  /* Support for static tracepoints. */
1444 
1445  /* Support for installing tracepoints while a trace experiment is
1446  running. */
1448 
1461 
1462  /* Support for the QNonStop packet. */
1464 
1465  /* Support for the QThreadEvents packet. */
1467 
1468  /* Support for multi-process extensions. */
1470 
1471  /* Support for enabling and disabling tracepoints while a trace
1472  experiment is running. */
1474 
1475  /* Support for collecting strings using the tracenz bytecode. */
1477 
1478  /* Support for continuing to run a trace experiment while GDB is
1479  disconnected. */
1481 
1482  /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1484 
1485  /* Support for the qXfer:btrace-conf:read packet. */
1487 
1488  /* Support for the Qbtrace-conf:bts:size packet. */
1490 
1491  /* Support for swbreak+ feature. */
1493 
1494  /* Support for hwbreak+ feature. */
1496 
1497  /* Support for fork events. */
1499 
1500  /* Support for vfork events. */
1502 
1503  /* Support for the Qbtrace-conf:pt:size packet. */
1505 
1506  /* Support for exec events. */
1508 
1509  /* Support for query supported vCont actions. */
1511 
1512  /* Support remote CTRL-C. */
1514 
1515  /* Support TARGET_WAITKIND_NO_RESUMED. */
1517 
1519 };
1520 
1522 
1523 /* Returns the packet's corresponding "set remote foo-packet" command
1524  state. See struct packet_config for more details. */
1525 
1526 static enum auto_boolean
1528 {
1529  return remote_protocol_packets[packet].detect;
1530 }
1531 
1532 /* Returns whether a given packet or feature is supported. This takes
1533  into account the state of the corresponding "set remote foo-packet"
1534  command, which may be used to bypass auto-detection. */
1535 
1536 static enum packet_support
1538 {
1539  switch (config->detect)
1540  {
1541  case AUTO_BOOLEAN_TRUE:
1542  return PACKET_ENABLE;
1543  case AUTO_BOOLEAN_FALSE:
1544  return PACKET_DISABLE;
1545  case AUTO_BOOLEAN_AUTO:
1546  return config->support;
1547  default:
1548  gdb_assert_not_reached (_("bad switch"));
1549  }
1550 }
1551 
1552 /* Same as packet_config_support, but takes the packet's enum value as
1553  argument. */
1554 
1555 static enum packet_support
1556 packet_support (int packet)
1557 {
1558  struct packet_config *config = &remote_protocol_packets[packet];
1559 
1560  return packet_config_support (config);
1561 }
1562 
1563 static void
1564 show_remote_protocol_packet_cmd (struct ui_file *file, int from_tty,
1565  struct cmd_list_element *c,
1566  const char *value)
1567 {
1568  struct packet_config *packet;
1569 
1570  for (packet = remote_protocol_packets;
1572  packet++)
1573  {
1574  if (&packet->detect == c->var)
1575  {
1576  show_packet_config_cmd (packet);
1577  return;
1578  }
1579  }
1580  internal_error (__FILE__, __LINE__, _("Could not find config for %s"),
1581  c->name);
1582 }
1583 
1584 /* Should we try one of the 'Z' requests? */
1585 
1587 {
1594 };
1595 
1596 /* For compatibility with older distributions. Provide a ``set remote
1597  Z-packet ...'' command that updates all the Z packet types. */
1598 
1600 
1601 static void
1602 set_remote_protocol_Z_packet_cmd (const char *args, int from_tty,
1603  struct cmd_list_element *c)
1604 {
1605  int i;
1606 
1607  for (i = 0; i < NR_Z_PACKET_TYPES; i++)
1609 }
1610 
1611 static void
1612 show_remote_protocol_Z_packet_cmd (struct ui_file *file, int from_tty,
1613  struct cmd_list_element *c,
1614  const char *value)
1615 {
1616  int i;
1617 
1618  for (i = 0; i < NR_Z_PACKET_TYPES; i++)
1619  {
1621  }
1622 }
1623 
1624 /* Returns true if the multi-process extensions are in effect. */
1625 
1626 static int
1628 {
1630 }
1631 
1632 /* Returns true if fork events are supported. */
1633 
1634 static int
1636 {
1638 }
1639 
1640 /* Returns true if vfork events are supported. */
1641 
1642 static int
1644 {
1646 }
1647 
1648 /* Returns true if exec events are supported. */
1649 
1650 static int
1652 {
1654 }
1655 
1656 /* Insert fork catchpoint target routine. If fork events are enabled
1657  then return success, nothing more to do. */
1658 
1659 static int
1661 {
1662  struct remote_state *rs = get_remote_state ();
1663 
1664  return !remote_fork_event_p (rs);
1665 }
1666 
1667 /* Remove fork catchpoint target routine. Nothing to do, just
1668  return success. */
1669 
1670 static int
1672 {
1673  return 0;
1674 }
1675 
1676 /* Insert vfork catchpoint target routine. If vfork events are enabled
1677  then return success, nothing more to do. */
1678 
1679 static int
1681 {
1682  struct remote_state *rs = get_remote_state ();
1683 
1684  return !remote_vfork_event_p (rs);
1685 }
1686 
1687 /* Remove vfork catchpoint target routine. Nothing to do, just
1688  return success. */
1689 
1690 static int
1692 {
1693  return 0;
1694 }
1695 
1696 /* Insert exec catchpoint target routine. If exec events are
1697  enabled, just return success. */
1698 
1699 static int
1701 {
1702  struct remote_state *rs = get_remote_state ();
1703 
1704  return !remote_exec_event_p (rs);
1705 }
1706 
1707 /* Remove exec catchpoint target routine. Nothing to do, just
1708  return success. */
1709 
1710 static int
1712 {
1713  return 0;
1714 }
1715 
1716 
1717 /* Asynchronous signal handle registered as event loop source for
1718  when we have pending events ready to be passed to the core. */
1719 
1721 
1722 
1723 
1727 
1728 /* Find out if the stub attached to PID (and hence GDB should offer to
1729  detach instead of killing it when bailing out). */
1730 
1731 static int
1733 {
1734  struct remote_state *rs = get_remote_state ();
1735  size_t size = get_remote_packet_size ();
1736 
1738  return 0;
1739 
1740  if (remote_multi_process_p (rs))
1741  xsnprintf (rs->buf, size, "qAttached:%x", pid);
1742  else
1743  xsnprintf (rs->buf, size, "qAttached");
1744 
1745  putpkt (rs->buf);
1746  getpkt (&rs->buf, &rs->buf_size, 0);
1747 
1748  switch (packet_ok (rs->buf,
1750  {
1751  case PACKET_OK:
1752  if (strcmp (rs->buf, "1") == 0)
1753  return 1;
1754  break;
1755  case PACKET_ERROR:
1756  warning (_("Remote failure reply: %s"), rs->buf);
1757  break;
1758  case PACKET_UNKNOWN:
1759  break;
1760  }
1761 
1762  return 0;
1763 }
1764 
1765 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1766  has been invented by GDB, instead of reported by the target. Since
1767  we can be connected to a remote system before before knowing about
1768  any inferior, mark the target with execution when we find the first
1769  inferior. If ATTACHED is 1, then we had just attached to this
1770  inferior. If it is 0, then we just created this inferior. If it
1771  is -1, then try querying the remote stub to find out if it had
1772  attached to the inferior or not. If TRY_OPEN_EXEC is true then
1773  attempt to open this inferior's executable as the main executable
1774  if no main executable is open already. */
1775 
1776 static struct inferior *
1777 remote_add_inferior (int fake_pid_p, int pid, int attached,
1778  int try_open_exec)
1779 {
1780  struct inferior *inf;
1781 
1782  /* Check whether this process we're learning about is to be
1783  considered attached, or if is to be considered to have been
1784  spawned by the stub. */
1785  if (attached == -1)
1786  attached = remote_query_attached (pid);
1787 
1789  {
1790  /* If the target shares code across all inferiors, then every
1791  attach adds a new inferior. */
1792  inf = add_inferior (pid);
1793 
1794  /* ... and every inferior is bound to the same program space.
1795  However, each inferior may still have its own address
1796  space. */
1797  inf->aspace = maybe_new_address_space ();
1798  inf->pspace = current_program_space;
1799  }
1800  else
1801  {
1802  /* In the traditional debugging scenario, there's a 1-1 match
1803  between program/address spaces. We simply bind the inferior
1804  to the program space's address space. */
1805  inf = current_inferior ();
1807  }
1808 
1809  inf->attach_flag = attached;
1810  inf->fake_pid_p = fake_pid_p;
1811 
1812  /* If no main executable is currently open then attempt to
1813  open the file that was executed to create this inferior. */
1814  if (try_open_exec && get_exec_file (0) == NULL)
1815  exec_file_locate_attach (pid, 0, 1);
1816 
1817  return inf;
1818 }
1819 
1821 
1822 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1823  according to RUNNING. */
1824 
1825 static void
1826 remote_add_thread (ptid_t ptid, int running, int executing)
1827 {
1828  struct remote_state *rs = get_remote_state ();
1829  struct thread_info *thread;
1830 
1831  /* GDB historically didn't pull threads in the initial connection
1832  setup. If the remote target doesn't even have a concept of
1833  threads (e.g., a bare-metal target), even if internally we
1834  consider that a single-threaded target, mentioning a new thread
1835  might be confusing to the user. Be silent then, preserving the
1836  age old behavior. */
1837  if (rs->starting_up)
1838  thread = add_thread_silent (ptid);
1839  else
1840  thread = add_thread (ptid);
1841 
1844  set_running (ptid, running);
1845 }
1846 
1847 /* Come here when we learn about a thread id from the remote target.
1848  It may be the first time we hear about such thread, so take the
1849  opportunity to add it to GDB's thread list. In case this is the
1850  first time we're noticing its corresponding inferior, add it to
1851  GDB's inferior list as well. EXECUTING indicates whether the
1852  thread is (internally) executing or stopped. */
1853 
1854 static void
1856 {
1857  /* In non-stop mode, we assume new found threads are (externally)
1858  running until proven otherwise with a stop reply. In all-stop,
1859  we can only get here if all threads are stopped. */
1860  int running = target_is_non_stop_p () ? 1 : 0;
1861 
1862  /* If this is a new thread, add it to GDB's thread list.
1863  If we leave it up to WFI to do this, bad things will happen. */
1864 
1865  if (in_thread_list (currthread) && is_exited (currthread))
1866  {
1867  /* We're seeing an event on a thread id we knew had exited.
1868  This has to be a new thread reusing the old id. Add it. */
1869  remote_add_thread (currthread, running, executing);
1870  return;
1871  }
1872 
1873  if (!in_thread_list (currthread))
1874  {
1875  struct inferior *inf = NULL;
1876  int pid = ptid_get_pid (currthread);
1877 
1879  && pid == ptid_get_pid (inferior_ptid))
1880  {
1881  /* inferior_ptid has no thread member yet. This can happen
1882  with the vAttach -> remote_wait,"TAAthread:" path if the
1883  stub doesn't support qC. This is the first stop reported
1884  after an attach, so this is the main thread. Update the
1885  ptid in the thread list. */
1886  if (in_thread_list (pid_to_ptid (pid)))
1887  thread_change_ptid (inferior_ptid, currthread);
1888  else
1889  {
1890  remote_add_thread (currthread, running, executing);
1891  inferior_ptid = currthread;
1892  }
1893  return;
1894  }
1895 
1897  {
1898  /* inferior_ptid is not set yet. This can happen with the
1899  vRun -> remote_wait,"TAAthread:" path if the stub
1900  doesn't support qC. This is the first stop reported
1901  after an attach, so this is the main thread. Update the
1902  ptid in the thread list. */
1903  thread_change_ptid (inferior_ptid, currthread);
1904  return;
1905  }
1906 
1907  /* When connecting to a target remote, or to a target
1908  extended-remote which already was debugging an inferior, we
1909  may not know about it yet. Add it before adding its child
1910  thread, so notifications are emitted in a sensible order. */
1911  if (!in_inferior_list (ptid_get_pid (currthread)))
1912  {
1913  struct remote_state *rs = get_remote_state ();
1914  int fake_pid_p = !remote_multi_process_p (rs);
1915 
1916  inf = remote_add_inferior (fake_pid_p,
1917  ptid_get_pid (currthread), -1, 1);
1918  }
1919 
1920  /* This is really a new thread. Add it. */
1921  remote_add_thread (currthread, running, executing);
1922 
1923  /* If we found a new inferior, let the common code do whatever
1924  it needs to with it (e.g., read shared libraries, insert
1925  breakpoints), unless we're just setting up an all-stop
1926  connection. */
1927  if (inf != NULL)
1928  {
1929  struct remote_state *rs = get_remote_state ();
1930 
1931  if (!rs->starting_up)
1932  notice_new_inferior (currthread, executing, 0);
1933  }
1934  }
1935 }
1936 
1937 /* Return THREAD's private thread data, creating it if necessary. */
1938 
1939 static remote_thread_info *
1941 {
1942  gdb_assert (thread != NULL);
1943 
1944  if (thread->priv == NULL)
1945  thread->priv.reset (new remote_thread_info);
1946 
1947  return static_cast<remote_thread_info *> (thread->priv.get ());
1948 }
1949 
1950 /* Return PTID's private thread data, creating it if necessary. */
1951 
1952 static remote_thread_info *
1954 {
1955  struct thread_info *info = find_thread_ptid (ptid);
1956 
1957  return get_remote_thread_info (info);
1958 }
1959 
1960 /* Call this function as a result of
1961  1) A halt indication (T packet) containing a thread id
1962  2) A direct query of currthread
1963  3) Successful execution of set thread */
1964 
1965 static void
1966 record_currthread (struct remote_state *rs, ptid_t currthread)
1967 {
1968  rs->general_thread = currthread;
1969 }
1970 
1971 /* If 'QPassSignals' is supported, tell the remote stub what signals
1972  it can simply pass through to the inferior without reporting. */
1973 
1974 static void
1976  int numsigs, unsigned char *pass_signals)
1977 {
1979  {
1980  char *pass_packet, *p;
1981  int count = 0, i;
1982  struct remote_state *rs = get_remote_state ();
1983 
1984  gdb_assert (numsigs < 256);
1985  for (i = 0; i < numsigs; i++)
1986  {
1987  if (pass_signals[i])
1988  count++;
1989  }
1990  pass_packet = (char *) xmalloc (count * 3 + strlen ("QPassSignals:") + 1);
1991  strcpy (pass_packet, "QPassSignals:");
1992  p = pass_packet + strlen (pass_packet);
1993  for (i = 0; i < numsigs; i++)
1994  {
1995  if (pass_signals[i])
1996  {
1997  if (i >= 16)
1998  *p++ = tohex (i >> 4);
1999  *p++ = tohex (i & 15);
2000  if (count)
2001  *p++ = ';';
2002  else
2003  break;
2004  count--;
2005  }
2006  }
2007  *p = 0;
2008  if (!rs->last_pass_packet || strcmp (rs->last_pass_packet, pass_packet))
2009  {
2010  putpkt (pass_packet);
2011  getpkt (&rs->buf, &rs->buf_size, 0);
2013  if (rs->last_pass_packet)
2014  xfree (rs->last_pass_packet);
2015  rs->last_pass_packet = pass_packet;
2016  }
2017  else
2018  xfree (pass_packet);
2019  }
2020 }
2021 
2022 /* If 'QCatchSyscalls' is supported, tell the remote stub
2023  to report syscalls to GDB. */
2024 
2025 static int
2027  int pid, bool needed, int any_count,
2028  gdb::array_view<const int> syscall_counts)
2029 {
2030  const char *catch_packet;
2031  enum packet_result result;
2032  int n_sysno = 0;
2033 
2035  {
2036  /* Not supported. */
2037  return 1;
2038  }
2039 
2040  if (needed && any_count == 0)
2041  {
2042  /* Count how many syscalls are to be caught. */
2043  for (size_t i = 0; i < syscall_counts.size (); i++)
2044  {
2045  if (syscall_counts[i] != 0)
2046  n_sysno++;
2047  }
2048  }
2049 
2050  if (remote_debug)
2051  {
2053  "remote_set_syscall_catchpoint "
2054  "pid %d needed %d any_count %d n_sysno %d\n",
2055  pid, needed, any_count, n_sysno);
2056  }
2057 
2058  std::string built_packet;
2059  if (needed)
2060  {
2061  /* Prepare a packet with the sysno list, assuming max 8+1
2062  characters for a sysno. If the resulting packet size is too
2063  big, fallback on the non-selective packet. */
2064  const int maxpktsz = strlen ("QCatchSyscalls:1") + n_sysno * 9 + 1;
2065  built_packet.reserve (maxpktsz);
2066  built_packet = "QCatchSyscalls:1";
2067  if (any_count == 0)
2068  {
2069  /* Add in each syscall to be caught. */
2070  for (size_t i = 0; i < syscall_counts.size (); i++)
2071  {
2072  if (syscall_counts[i] != 0)
2073  string_appendf (built_packet, ";%zx", i);
2074  }
2075  }
2076  if (built_packet.size () > get_remote_packet_size ())
2077  {
2078  /* catch_packet too big. Fallback to less efficient
2079  non selective mode, with GDB doing the filtering. */
2080  catch_packet = "QCatchSyscalls:1";
2081  }
2082  else
2083  catch_packet = built_packet.c_str ();
2084  }
2085  else
2086  catch_packet = "QCatchSyscalls:0";
2087 
2088  struct remote_state *rs = get_remote_state ();
2089 
2090  putpkt (catch_packet);
2091  getpkt (&rs->buf, &rs->buf_size, 0);
2093  if (result == PACKET_OK)
2094  return 0;
2095  else
2096  return -1;
2097 }
2098 
2099 /* If 'QProgramSignals' is supported, tell the remote stub what
2100  signals it should pass through to the inferior when detaching. */
2101 
2102 static void
2104  int numsigs, unsigned char *signals)
2105 {
2107  {
2108  char *packet, *p;
2109  int count = 0, i;
2110  struct remote_state *rs = get_remote_state ();
2111 
2112  gdb_assert (numsigs < 256);
2113  for (i = 0; i < numsigs; i++)
2114  {
2115  if (signals[i])
2116  count++;
2117  }
2118  packet = (char *) xmalloc (count * 3 + strlen ("QProgramSignals:") + 1);
2119  strcpy (packet, "QProgramSignals:");
2120  p = packet + strlen (packet);
2121  for (i = 0; i < numsigs; i++)
2122  {
2123  if (signal_pass_state (i))
2124  {
2125  if (i >= 16)
2126  *p++ = tohex (i >> 4);
2127  *p++ = tohex (i & 15);
2128  if (count)
2129  *p++ = ';';
2130  else
2131  break;
2132  count--;
2133  }
2134  }
2135  *p = 0;
2137  || strcmp (rs->last_program_signals_packet, packet) != 0)
2138  {
2139  putpkt (packet);
2140  getpkt (&rs->buf, &rs->buf_size, 0);
2143  rs->last_program_signals_packet = packet;
2144  }
2145  else
2146  xfree (packet);
2147  }
2148 }
2149 
2150 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
2151  MINUS_ONE_PTID, set the thread to -1, so the stub returns the
2152  thread. If GEN is set, set the general thread, if not, then set
2153  the step/continue thread. */
2154 static void
2155 set_thread (ptid_t ptid, int gen)
2156 {
2157  struct remote_state *rs = get_remote_state ();
2158  ptid_t state = gen ? rs->general_thread : rs->continue_thread;
2159  char *buf = rs->buf;
2160  char *endbuf = rs->buf + get_remote_packet_size ();
2161 
2162  if (ptid_equal (state, ptid))
2163  return;
2164 
2165  *buf++ = 'H';
2166  *buf++ = gen ? 'g' : 'c';
2167  if (ptid_equal (ptid, magic_null_ptid))
2168  xsnprintf (buf, endbuf - buf, "0");
2169  else if (ptid_equal (ptid, any_thread_ptid))
2170  xsnprintf (buf, endbuf - buf, "0");
2171  else if (ptid_equal (ptid, minus_one_ptid))
2172  xsnprintf (buf, endbuf - buf, "-1");
2173  else
2174  write_ptid (buf, endbuf, ptid);
2175  putpkt (rs->buf);
2176  getpkt (&rs->buf, &rs->buf_size, 0);
2177  if (gen)
2178  rs->general_thread = ptid;
2179  else
2180  rs->continue_thread = ptid;
2181 }
2182 
2183 static void
2185 {
2186  set_thread (ptid, 1);
2187 }
2188 
2189 static void
2191 {
2192  set_thread (ptid, 0);
2193 }
2194 
2195 /* Change the remote current process. Which thread within the process
2196  ends up selected isn't important, as long as it is the same process
2197  as what INFERIOR_PTID points to.
2198 
2199  This comes from that fact that there is no explicit notion of
2200  "selected process" in the protocol. The selected process for
2201  general operations is the process the selected general thread
2202  belongs to. */
2203 
2204 static void
2206 {
2207  struct remote_state *rs = get_remote_state ();
2208 
2209  /* If the remote can't handle multiple processes, don't bother. */
2210  if (!remote_multi_process_p (rs))
2211  return;
2212 
2213  /* We only need to change the remote current thread if it's pointing
2214  at some other process. */
2217 }
2218 
2219 
2220 /* Return nonzero if this is the main thread that we made up ourselves
2221  to model non-threaded targets as single-threaded. */
2222 
2223 static int
2225 {
2226  if (ptid_equal (ptid, magic_null_ptid))
2227  /* The main thread is always alive. */
2228  return 1;
2229 
2230  if (ptid_get_pid (ptid) != 0 && ptid_get_lwp (ptid) == 0)
2231  /* The main thread is always alive. This can happen after a
2232  vAttach, if the remote side doesn't support
2233  multi-threading. */
2234  return 1;
2235 
2236  return 0;
2237 }
2238 
2239 /* Return nonzero if the thread PTID is still alive on the remote
2240  system. */
2241 
2242 static int
2244 {
2245  struct remote_state *rs = get_remote_state ();
2246  char *p, *endp;
2247 
2248  /* Check if this is a thread that we made up ourselves to model
2249  non-threaded targets as single-threaded. */
2250  if (remote_thread_always_alive (ops, ptid))
2251  return 1;
2252 
2253  p = rs->buf;
2254  endp = rs->buf + get_remote_packet_size ();
2255 
2256  *p++ = 'T';
2257  write_ptid (p, endp, ptid);
2258 
2259  putpkt (rs->buf);
2260  getpkt (&rs->buf, &rs->buf_size, 0);
2261  return (rs->buf[0] == 'O' && rs->buf[1] == 'K');
2262 }
2263 
2264 /* Return a pointer to a thread name if we know it and NULL otherwise.
2265  The thread_info object owns the memory for the name. */
2266 
2267 static const char *
2268 remote_thread_name (struct target_ops *ops, struct thread_info *info)
2269 {
2270  if (info->priv != NULL)
2271  {
2272  const std::string &name = get_remote_thread_info (info)->name;
2273  return !name.empty () ? name.c_str () : NULL;
2274  }
2275 
2276  return NULL;
2277 }
2278 
2279 /* About these extended threadlist and threadinfo packets. They are
2280  variable length packets but, the fields within them are often fixed
2281  length. They are redundent enough to send over UDP as is the
2282  remote protocol in general. There is a matching unit test module
2283  in libstub. */
2284 
2285 /* WARNING: This threadref data structure comes from the remote O.S.,
2286  libstub protocol encoding, and remote.c. It is not particularly
2287  changable. */
2288 
2289 /* Right now, the internal structure is int. We want it to be bigger.
2290  Plan to fix this. */
2291 
2292 typedef int gdb_threadref; /* Internal GDB thread reference. */
2293 
2294 /* gdb_ext_thread_info is an internal GDB data structure which is
2295  equivalent to the reply of the remote threadinfo packet. */
2296 
2298  {
2299  threadref threadid; /* External form of thread reference. */
2300  int active; /* Has state interesting to GDB?
2301  regs, stack. */
2302  char display[256]; /* Brief state display, name,
2303  blocked/suspended. */
2304  char shortname[32]; /* To be used to name threads. */
2305  char more_display[256]; /* Long info, statistics, queue depth,
2306  whatever. */
2307  };
2308 
2309 /* The volume of remote transfers can be limited by submitting
2310  a mask containing bits specifying the desired information.
2311  Use a union of these values as the 'selection' parameter to
2312  get_thread_info. FIXME: Make these TAG names more thread specific. */
2313 
2314 #define TAG_THREADID 1
2315 #define TAG_EXISTS 2
2316 #define TAG_DISPLAY 4
2317 #define TAG_THREADNAME 8
2318 #define TAG_MOREDISPLAY 16
2319 
2320 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2321 
2322 static char *unpack_nibble (char *buf, int *val);
2323 
2324 static char *unpack_byte (char *buf, int *value);
2325 
2326 static char *pack_int (char *buf, int value);
2327 
2328 static char *unpack_int (char *buf, int *value);
2329 
2330 static char *unpack_string (char *src, char *dest, int length);
2331 
2332 static char *pack_threadid (char *pkt, threadref *id);
2333 
2334 static char *unpack_threadid (char *inbuf, threadref *id);
2335 
2336 void int_to_threadref (threadref *id, int value);
2337 
2338 static int threadref_to_int (threadref *ref);
2339 
2340 static void copy_threadref (threadref *dest, threadref *src);
2341 
2342 static int threadmatch (threadref *dest, threadref *src);
2343 
2344 static char *pack_threadinfo_request (char *pkt, int mode,
2345  threadref *id);
2346 
2347 static int remote_unpack_thread_info_response (char *pkt,
2348  threadref *expectedref,
2349  struct gdb_ext_thread_info
2350  *info);
2351 
2352 
2353 static int remote_get_threadinfo (threadref *threadid,
2354  int fieldset, /*TAG mask */
2355  struct gdb_ext_thread_info *info);
2356 
2357 static char *pack_threadlist_request (char *pkt, int startflag,
2358  int threadcount,
2359  threadref *nextthread);
2360 
2361 static int parse_threadlist_response (char *pkt,
2362  int result_limit,
2363  threadref *original_echo,
2364  threadref *resultlist,
2365  int *doneflag);
2366 
2367 static int remote_get_threadlist (int startflag,
2368  threadref *nextthread,
2369  int result_limit,
2370  int *done,
2371  int *result_count,
2372  threadref *threadlist);
2373 
2374 typedef int (*rmt_thread_action) (threadref *ref, void *context);
2375 
2376 static int remote_threadlist_iterator (rmt_thread_action stepfunction,
2377  void *context, int looplimit);
2378 
2379 static int remote_newthread_step (threadref *ref, void *context);
2380 
2381 
2382 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2383  buffer we're allowed to write to. Returns
2384  BUF+CHARACTERS_WRITTEN. */
2385 
2386 static char *
2387 write_ptid (char *buf, const char *endbuf, ptid_t ptid)
2388 {
2389  int pid, tid;
2390  struct remote_state *rs = get_remote_state ();
2391 
2392  if (remote_multi_process_p (rs))
2393  {
2394  pid = ptid_get_pid (ptid);
2395  if (pid < 0)
2396  buf += xsnprintf (buf, endbuf - buf, "p-%x.", -pid);
2397  else
2398  buf += xsnprintf (buf, endbuf - buf, "p%x.", pid);
2399  }
2400  tid = ptid_get_lwp (ptid);
2401  if (tid < 0)
2402  buf += xsnprintf (buf, endbuf - buf, "-%x", -tid);
2403  else
2404  buf += xsnprintf (buf, endbuf - buf, "%x", tid);
2405 
2406  return buf;
2407 }
2408 
2409 /* Extract a PTID from BUF. If non-null, OBUF is set to one past the
2410  last parsed char. Returns null_ptid if no thread id is found, and
2411  throws an error if the thread id has an invalid format. */
2412 
2413 static ptid_t
2414 read_ptid (const char *buf, const char **obuf)
2415 {
2416  const char *p = buf;
2417  const char *pp;
2418  ULONGEST pid = 0, tid = 0;
2419 
2420  if (*p == 'p')
2421  {
2422  /* Multi-process ptid. */
2423  pp = unpack_varlen_hex (p + 1, &pid);
2424  if (*pp != '.')
2425  error (_("invalid remote ptid: %s"), p);
2426 
2427  p = pp;
2428  pp = unpack_varlen_hex (p + 1, &tid);
2429  if (obuf)
2430  *obuf = pp;
2431  return ptid_build (pid, tid, 0);
2432  }
2433 
2434  /* No multi-process. Just a tid. */
2435  pp = unpack_varlen_hex (p, &tid);
2436 
2437  /* Return null_ptid when no thread id is found. */
2438  if (p == pp)
2439  {
2440  if (obuf)
2441  *obuf = pp;
2442  return null_ptid;
2443  }
2444 
2445  /* Since the stub is not sending a process id, then default to
2446  what's in inferior_ptid, unless it's null at this point. If so,
2447  then since there's no way to know the pid of the reported
2448  threads, use the magic number. */
2451  else
2453 
2454  if (obuf)
2455  *obuf = pp;
2456  return ptid_build (pid, tid, 0);
2457 }
2458 
2459 static int
2460 stubhex (int ch)
2461 {
2462  if (ch >= 'a' && ch <= 'f')
2463  return ch - 'a' + 10;
2464  if (ch >= '0' && ch <= '9')
2465  return ch - '0';
2466  if (ch >= 'A' && ch <= 'F')
2467  return ch - 'A' + 10;
2468  return -1;
2469 }
2470 
2471 static int
2472 stub_unpack_int (char *buff, int fieldlength)
2473 {
2474  int nibble;
2475  int retval = 0;
2476 
2477  while (fieldlength)
2478  {
2479  nibble = stubhex (*buff++);
2480  retval |= nibble;
2481  fieldlength--;
2482  if (fieldlength)
2483  retval = retval << 4;
2484  }
2485  return retval;
2486 }
2487 
2488 static char *
2489 unpack_nibble (char *buf, int *val)
2490 {
2491  *val = fromhex (*buf++);
2492  return buf;
2493 }
2494 
2495 static char *
2496 unpack_byte (char *buf, int *value)
2497 {
2498  *value = stub_unpack_int (buf, 2);
2499  return buf + 2;
2500 }
2501 
2502 static char *
2503 pack_int (char *buf, int value)
2504 {
2505  buf = pack_hex_byte (buf, (value >> 24) & 0xff);
2506  buf = pack_hex_byte (buf, (value >> 16) & 0xff);
2507  buf = pack_hex_byte (buf, (value >> 8) & 0x0ff);
2508  buf = pack_hex_byte (buf, (value & 0xff));
2509  return buf;
2510 }
2511 
2512 static char *
2513 unpack_int (char *buf, int *value)
2514 {
2515  *value = stub_unpack_int (buf, 8);
2516  return buf + 8;
2517 }
2518 
2519 #if 0 /* Currently unused, uncomment when needed. */
2520 static char *pack_string (char *pkt, char *string);
2521 
2522 static char *
2523 pack_string (char *pkt, char *string)
2524 {
2525  char ch;
2526  int len;
2527 
2528  len = strlen (string);
2529  if (len > 200)
2530  len = 200; /* Bigger than most GDB packets, junk??? */
2531  pkt = pack_hex_byte (pkt, len);
2532  while (len-- > 0)
2533  {
2534  ch = *string++;
2535  if ((ch == '\0') || (ch == '#'))
2536  ch = '*'; /* Protect encapsulation. */
2537  *pkt++ = ch;
2538  }
2539  return pkt;
2540 }
2541 #endif /* 0 (unused) */
2542 
2543 static char *
2544 unpack_string (char *src, char *dest, int length)
2545 {
2546  while (length--)
2547  *dest++ = *src++;
2548  *dest = '\0';
2549  return src;
2550 }
2551 
2552 static char *
2553 pack_threadid (char *pkt, threadref *id)
2554 {
2555  char *limit;
2556  unsigned char *altid;
2557 
2558  altid = (unsigned char *) id;
2559  limit = pkt + BUF_THREAD_ID_SIZE;
2560  while (pkt < limit)
2561  pkt = pack_hex_byte (pkt, *altid++);
2562  return pkt;
2563 }
2564 
2565 
2566 static char *
2567 unpack_threadid (char *inbuf, threadref *id)
2568 {
2569  char *altref;
2570  char *limit = inbuf + BUF_THREAD_ID_SIZE;
2571  int x, y;
2572 
2573  altref = (char *) id;
2574 
2575  while (inbuf < limit)
2576  {
2577  x = stubhex (*inbuf++);
2578  y = stubhex (*inbuf++);
2579  *altref++ = (x << 4) | y;
2580  }
2581  return inbuf;
2582 }
2583 
2584 /* Externally, threadrefs are 64 bits but internally, they are still
2585  ints. This is due to a mismatch of specifications. We would like
2586  to use 64bit thread references internally. This is an adapter
2587  function. */
2588 
2589 void
2591 {
2592  unsigned char *scan;
2593 
2594  scan = (unsigned char *) id;
2595  {
2596  int i = 4;
2597  while (i--)
2598  *scan++ = 0;
2599  }
2600  *scan++ = (value >> 24) & 0xff;
2601  *scan++ = (value >> 16) & 0xff;
2602  *scan++ = (value >> 8) & 0xff;
2603  *scan++ = (value & 0xff);
2604 }
2605 
2606 static int
2608 {
2609  int i, value = 0;
2610  unsigned char *scan;
2611 
2612  scan = *ref;
2613  scan += 4;
2614  i = 4;
2615  while (i-- > 0)
2616  value = (value << 8) | ((*scan++) & 0xff);
2617  return value;
2618 }
2619 
2620 static void
2622 {
2623  int i;
2624  unsigned char *csrc, *cdest;
2625 
2626  csrc = (unsigned char *) src;
2627  cdest = (unsigned char *) dest;
2628  i = 8;
2629  while (i--)
2630  *cdest++ = *csrc++;
2631 }
2632 
2633 static int
2635 {
2636  /* Things are broken right now, so just assume we got a match. */
2637 #if 0
2638  unsigned char *srcp, *destp;
2639  int i, result;
2640  srcp = (char *) src;
2641  destp = (char *) dest;
2642 
2643  result = 1;
2644  while (i-- > 0)
2645  result &= (*srcp++ == *destp++) ? 1 : 0;
2646  return result;
2647 #endif
2648  return 1;
2649 }
2650 
2651 /*
2652  threadid:1, # always request threadid
2653  context_exists:2,
2654  display:4,
2655  unique_name:8,
2656  more_display:16
2657  */
2658 
2659 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2660 
2661 static char *
2662 pack_threadinfo_request (char *pkt, int mode, threadref *id)
2663 {
2664  *pkt++ = 'q'; /* Info Query */
2665  *pkt++ = 'P'; /* process or thread info */
2666  pkt = pack_int (pkt, mode); /* mode */
2667  pkt = pack_threadid (pkt, id); /* threadid */
2668  *pkt = '\0'; /* terminate */
2669  return pkt;
2670 }
2671 
2672 /* These values tag the fields in a thread info response packet. */
2673 /* Tagging the fields allows us to request specific fields and to
2674  add more fields as time goes by. */
2675 
2676 #define TAG_THREADID 1 /* Echo the thread identifier. */
2677 #define TAG_EXISTS 2 /* Is this process defined enough to
2678  fetch registers and its stack? */
2679 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2680 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2681 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2682  the process. */
2683 
2684 static int
2686  struct gdb_ext_thread_info *info)
2687 {
2688  struct remote_state *rs = get_remote_state ();
2689  int mask, length;
2690  int tag;
2691  threadref ref;
2692  char *limit = pkt + rs->buf_size; /* Plausible parsing limit. */
2693  int retval = 1;
2694 
2695  /* info->threadid = 0; FIXME: implement zero_threadref. */
2696  info->active = 0;
2697  info->display[0] = '\0';
2698  info->shortname[0] = '\0';
2699  info->more_display[0] = '\0';
2700 
2701  /* Assume the characters indicating the packet type have been
2702  stripped. */
2703  pkt = unpack_int (pkt, &mask); /* arg mask */
2704  pkt = unpack_threadid (pkt, &ref);
2705 
2706  if (mask == 0)
2707  warning (_("Incomplete response to threadinfo request."));
2708  if (!threadmatch (&ref, expectedref))
2709  { /* This is an answer to a different request. */
2710  warning (_("ERROR RMT Thread info mismatch."));
2711  return 0;
2712  }
2713  copy_threadref (&info->threadid, &ref);
2714 
2715  /* Loop on tagged fields , try to bail if somthing goes wrong. */
2716 
2717  /* Packets are terminated with nulls. */
2718  while ((pkt < limit) && mask && *pkt)
2719  {
2720  pkt = unpack_int (pkt, &tag); /* tag */
2721  pkt = unpack_byte (pkt, &length); /* length */
2722  if (!(tag & mask)) /* Tags out of synch with mask. */
2723  {
2724  warning (_("ERROR RMT: threadinfo tag mismatch."));
2725  retval = 0;
2726  break;
2727  }
2728  if (tag == TAG_THREADID)
2729  {
2730  if (length != 16)
2731  {
2732  warning (_("ERROR RMT: length of threadid is not 16."));
2733  retval = 0;
2734  break;
2735  }
2736  pkt = unpack_threadid (pkt, &ref);
2737  mask = mask & ~TAG_THREADID;
2738  continue;
2739  }
2740  if (tag == TAG_EXISTS)
2741  {
2742  info->active = stub_unpack_int (pkt, length);
2743  pkt += length;
2744  mask = mask & ~(TAG_EXISTS);
2745  if (length > 8)
2746  {
2747  warning (_("ERROR RMT: 'exists' length too long."));
2748  retval = 0;
2749  break;
2750  }
2751  continue;
2752  }
2753  if (tag == TAG_THREADNAME)
2754  {
2755  pkt = unpack_string (pkt, &info->shortname[0], length);
2756  mask = mask & ~TAG_THREADNAME;
2757  continue;
2758  }
2759  if (tag == TAG_DISPLAY)
2760  {
2761  pkt = unpack_string (pkt, &info->display[0], length);
2762  mask = mask & ~TAG_DISPLAY;
2763  continue;
2764  }
2765  if (tag == TAG_MOREDISPLAY)
2766  {
2767  pkt = unpack_string (pkt, &info->more_display[0], length);
2768  mask = mask & ~TAG_MOREDISPLAY;
2769  continue;
2770  }
2771  warning (_("ERROR RMT: unknown thread info tag."));
2772  break; /* Not a tag we know about. */
2773  }
2774  return retval;
2775 }
2776 
2777 static int
2778 remote_get_threadinfo (threadref *threadid, int fieldset, /* TAG mask */
2779  struct gdb_ext_thread_info *info)
2780 {
2781  struct remote_state *rs = get_remote_state ();
2782  int result;
2783 
2784  pack_threadinfo_request (rs->buf, fieldset, threadid);
2785  putpkt (rs->buf);
2786  getpkt (&rs->buf, &rs->buf_size, 0);
2787 
2788  if (rs->buf[0] == '\0')
2789  return 0;
2790 
2791  result = remote_unpack_thread_info_response (rs->buf + 2,
2792  threadid, info);
2793  return result;
2794 }
2795 
2796 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2797 
2798 static char *
2799 pack_threadlist_request (char *pkt, int startflag, int threadcount,
2801 {
2802  *pkt++ = 'q'; /* info query packet */
2803  *pkt++ = 'L'; /* Process LIST or threadLIST request */
2804  pkt = pack_nibble (pkt, startflag); /* initflag 1 bytes */
2805  pkt = pack_hex_byte (pkt, threadcount); /* threadcount 2 bytes */
2806  pkt = pack_threadid (pkt, nextthread); /* 64 bit thread identifier */
2807  *pkt = '\0';
2808  return pkt;
2809 }
2810 
2811 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2812 
2813 static int
2814 parse_threadlist_response (char *pkt, int result_limit,
2815  threadref *original_echo, threadref *resultlist,
2816  int *doneflag)
2817 {
2818  struct remote_state *rs = get_remote_state ();
2819  char *limit;
2820  int count, resultcount, done;
2821 
2822  resultcount = 0;
2823  /* Assume the 'q' and 'M chars have been stripped. */
2824  limit = pkt + (rs->buf_size - BUF_THREAD_ID_SIZE);
2825  /* done parse past here */
2826  pkt = unpack_byte (pkt, &count); /* count field */
2827  pkt = unpack_nibble (pkt, &done);
2828  /* The first threadid is the argument threadid. */
2829  pkt = unpack_threadid (pkt, original_echo); /* should match query packet */
2830  while ((count-- > 0) && (pkt < limit))
2831  {
2832  pkt = unpack_threadid (pkt, resultlist++);
2833  if (resultcount++ >= result_limit)
2834  break;
2835  }
2836  if (doneflag)
2837  *doneflag = done;
2838  return resultcount;
2839 }
2840 
2841 /* Fetch the next batch of threads from the remote. Returns -1 if the
2842  qL packet is not supported, 0 on error and 1 on success. */
2843 
2844 static int
2845 remote_get_threadlist (int startflag, threadref *nextthread, int result_limit,
2846  int *done, int *result_count, threadref *threadlist)
2847 {
2848  struct remote_state *rs = get_remote_state ();
2849  int result = 1;
2850 
2851  /* Trancate result limit to be smaller than the packet size. */
2852  if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10)
2853  >= get_remote_packet_size ())
2854  result_limit = (get_remote_packet_size () / BUF_THREAD_ID_SIZE) - 2;
2855 
2856  pack_threadlist_request (rs->buf, startflag, result_limit, nextthread);
2857  putpkt (rs->buf);
2858  getpkt (&rs->buf, &rs->buf_size, 0);
2859  if (*rs->buf == '\0')
2860  {
2861  /* Packet not supported. */
2862  return -1;
2863  }
2864 
2865  *result_count =
2866  parse_threadlist_response (rs->buf + 2, result_limit,
2867  &rs->echo_nextthread, threadlist, done);
2868 
2869  if (!threadmatch (&rs->echo_nextthread, nextthread))
2870  {
2871  /* FIXME: This is a good reason to drop the packet. */
2872  /* Possably, there is a duplicate response. */
2873  /* Possabilities :
2874  retransmit immediatly - race conditions
2875  retransmit after timeout - yes
2876  exit
2877  wait for packet, then exit
2878  */
2879  warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2880  return 0; /* I choose simply exiting. */
2881  }
2882  if (*result_count <= 0)
2883  {
2884  if (*done != 1)
2885  {
2886  warning (_("RMT ERROR : failed to get remote thread list."));
2887  result = 0;
2888  }
2889  return result; /* break; */
2890  }
2891  if (*result_count > result_limit)
2892  {
2893  *result_count = 0;
2894  warning (_("RMT ERROR: threadlist response longer than requested."));
2895  return 0;
2896  }
2897  return result;
2898 }
2899 
2900 /* Fetch the list of remote threads, with the qL packet, and call
2901  STEPFUNCTION for each thread found. Stops iterating and returns 1
2902  if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2903  STEPFUNCTION returns false. If the packet is not supported,
2904  returns -1. */
2905 
2906 static int
2907 remote_threadlist_iterator (rmt_thread_action stepfunction, void *context,
2908  int looplimit)
2909 {
2910  struct remote_state *rs = get_remote_state ();
2911  int done, i, result_count;
2912  int startflag = 1;
2913  int result = 1;
2914  int loopcount = 0;
2915 
2916  done = 0;
2917  while (!done)
2918  {
2919  if (loopcount++ > looplimit)
2920  {
2921  result = 0;
2922  warning (_("Remote fetch threadlist -infinite loop-."));
2923  break;
2924  }
2925  result = remote_get_threadlist (startflag, &rs->nextthread,
2927  &done, &result_count,
2928  rs->resultthreadlist);
2929  if (result <= 0)
2930  break;
2931  /* Clear for later iterations. */
2932  startflag = 0;
2933  /* Setup to resume next batch of thread references, set nextthread. */
2934  if (result_count >= 1)
2935  copy_threadref (&rs->nextthread,
2936  &rs->resultthreadlist[result_count - 1]);
2937  i = 0;
2938  while (result_count--)
2939  {
2940  if (!(*stepfunction) (&rs->resultthreadlist[i++], context))
2941  {
2942  result = 0;
2943  break;
2944  }
2945  }
2946  }
2947  return result;
2948 }
2949 
2950 /* A thread found on the remote target. */
2951 
2953 {
2954  explicit thread_item (ptid_t ptid_)
2955  : ptid (ptid_)
2956  {}
2957 
2958  thread_item (thread_item &&other) = default;
2959  thread_item &operator= (thread_item &&other) = default;
2960 
2962 
2963  /* The thread's PTID. */
2965 
2966  /* The thread's extra info. */
2968 
2969  /* The thread's name. */
2971 
2972  /* The core the thread was running on. -1 if not known. */
2973  int core = -1;
2974 
2975  /* The thread handle associated with the thread. */
2977 };
2978 
2979 /* Context passed around to the various methods listing remote
2980  threads. As new threads are found, they're added to the ITEMS
2981  vector. */
2982 
2984 {
2985  /* Return true if this object contains an entry for a thread with ptid
2986  PTID. */
2987 
2988  bool contains_thread (ptid_t ptid) const
2989  {
2990  auto match_ptid = [&] (const thread_item &item)
2991  {
2992  return item.ptid == ptid;
2993  };
2994 
2995  auto it = std::find_if (this->items.begin (),
2996  this->items.end (),
2997  match_ptid);
2998 
2999  return it != this->items.end ();
3000  }
3001 
3002  /* Remove the thread with ptid PTID. */
3003 
3004  void remove_thread (ptid_t ptid)
3005  {
3006  auto match_ptid = [&] (const thread_item &item)
3007  {
3008  return item.ptid == ptid;
3009  };
3010 
3011  auto it = std::remove_if (this->items.begin (),
3012  this->items.end (),
3013  match_ptid);
3014 
3015  if (it != this->items.end ())
3016  this->items.erase (it);
3017  }
3018 
3019  /* The threads found on the remote target. */
3020  std::vector<thread_item> items;
3021 };
3022 
3023 static int
3025 {
3026  struct threads_listing_context *context
3027  = (struct threads_listing_context *) data;
3028  int pid = inferior_ptid.pid ();
3029  int lwp = threadref_to_int (ref);
3030  ptid_t ptid (pid, lwp);
3031 
3032  context->items.emplace_back (ptid);
3033 
3034  return 1; /* continue iterator */
3035 }
3036 
3037 #define CRAZY_MAX_THREADS 1000
3038 
3039 static ptid_t
3041 {
3042  struct remote_state *rs = get_remote_state ();
3043 
3044  putpkt ("qC");
3045  getpkt (&rs->buf, &rs->buf_size, 0);
3046  if (rs->buf[0] == 'Q' && rs->buf[1] == 'C')
3047  {
3048  const char *obuf;
3049  ptid_t result;
3050 
3051  result = read_ptid (&rs->buf[2], &obuf);
3052  if (*obuf != '\0' && remote_debug)
3054  "warning: garbage in qC reply\n");
3055 
3056  return result;
3057  }
3058  else
3059  return oldpid;
3060 }
3061 
3062 /* List remote threads using the deprecated qL packet. */
3063 
3064 static int
3066  struct threads_listing_context *context)
3067 {
3069  CRAZY_MAX_THREADS) >= 0)
3070  return 1;
3071 
3072  return 0;
3073 }
3074 
3075 #if defined(HAVE_LIBEXPAT)
3076 
3077 static void
3079  const struct gdb_xml_element *element,
3080  void *user_data, VEC(gdb_xml_value_s) *attributes)
3081 {
3082  struct threads_listing_context *data
3083  = (struct threads_listing_context *) user_data;
3084  struct gdb_xml_value *attr;
3085 
3086  char *id = (char *) xml_find_attribute (attributes, "id")->value;
3087  ptid_t ptid = read_ptid (id, NULL);
3088 
3089  data->items.emplace_back (ptid);
3090  thread_item &item = data->items.back ();
3091 
3092  attr = xml_find_attribute (attributes, "core");
3093  if (attr != NULL)
3094  item.core = *(ULONGEST *) attr->value;
3095 
3096  attr = xml_find_attribute (attributes, "name");
3097  if (attr != NULL)
3098  item.name = (const char *) attr->value;
3099 
3100  attr = xml_find_attribute (attributes, "handle");
3101  if (attr != NULL)
3102  item.thread_handle = hex2bin ((const char *) attr->value);
3103 }
3104 
3105 static void
3106 end_thread (struct gdb_xml_parser *parser,
3107  const struct gdb_xml_element *element,
3108  void *user_data, const char *body_text)
3109 {
3110  struct threads_listing_context *data
3111  = (struct threads_listing_context *) user_data;
3112 
3113  if (body_text != NULL && *body_text != '\0')
3114  data->items.back ().extra = body_text;
3115 }
3116 
3118  { "id", GDB_XML_AF_NONE, NULL, NULL },
3120  { "name", GDB_XML_AF_OPTIONAL, NULL, NULL },
3121  { "handle", GDB_XML_AF_OPTIONAL, NULL, NULL },
3122  { NULL, GDB_XML_AF_NONE, NULL, NULL }
3123 };
3124 
3126  { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
3127 };
3128 
3130  { "thread", thread_attributes, thread_children,
3133  { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
3134 };
3135 
3137  { "threads", NULL, threads_children,
3138  GDB_XML_EF_NONE, NULL, NULL },
3139  { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
3140 };
3141 
3142 #endif
3143 
3144 /* List remote threads using qXfer:threads:read. */
3145 
3146 static int
3148  struct threads_listing_context *context)
3149 {
3150 #if defined(HAVE_LIBEXPAT)
3152  {
3155 
3156  if (xml != NULL && *xml != '\0')
3157  {
3158  gdb_xml_parse_quick (_("threads"), "threads.dtd",
3159  threads_elements, xml.get (), context);
3160  }
3161 
3162  return 1;
3163  }
3164 #endif
3165 
3166  return 0;
3167 }
3168 
3169 /* List remote threads using qfThreadInfo/qsThreadInfo. */
3170 
3171 static int
3173  struct threads_listing_context *context)
3174 {
3175  struct remote_state *rs = get_remote_state ();
3176 
3177  if (rs->use_threadinfo_query)
3178  {
3179  const char *bufp;
3180 
3181  putpkt ("qfThreadInfo");
3182  getpkt (&rs->buf, &rs->buf_size, 0);
3183  bufp = rs->buf;
3184  if (bufp[0] != '\0') /* q packet recognized */
3185  {
3186  while (*bufp++ == 'm') /* reply contains one or more TID */
3187  {
3188  do
3189  {
3190  ptid_t ptid = read_ptid (bufp, &bufp);
3191  context->items.emplace_back (ptid);
3192  }
3193  while (*bufp++ == ','); /* comma-separated list */
3194  putpkt ("qsThreadInfo");
3195  getpkt (&rs->buf, &rs->buf_size, 0);
3196  bufp = rs->buf;
3197  }
3198  return 1;
3199  }
3200  else
3201  {
3202  /* Packet not recognized. */
3203  rs->use_threadinfo_query = 0;
3204  }
3205  }
3206 
3207  return 0;
3208 }
3209 
3210 /* Implement the to_update_thread_list function for the remote
3211  targets. */
3212 
3213 static void
3215 {
3216  struct threads_listing_context context;
3217  int got_list = 0;
3218 
3219  /* We have a few different mechanisms to fetch the thread list. Try
3220  them all, starting with the most preferred one first, falling
3221  back to older methods. */
3222  if (remote_get_threads_with_qxfer (ops, &context)
3223  || remote_get_threads_with_qthreadinfo (ops, &context)
3224  || remote_get_threads_with_ql (ops, &context))
3225  {
3226  struct thread_info *tp, *tmp;
3227 
3228  got_list = 1;
3229 
3230  if (context.items.empty ()
3232  {
3233  /* Some targets don't really support threads, but still
3234  reply an (empty) thread list in response to the thread
3235  listing packets, instead of replying "packet not
3236  supported". Exit early so we don't delete the main
3237  thread. */
3238  return;
3239  }
3240 
3241  /* CONTEXT now holds the current thread list on the remote
3242  target end. Delete GDB-side threads no longer found on the
3243  target. */
3244  ALL_THREADS_SAFE (tp, tmp)
3245  {
3246  if (!context.contains_thread (tp->ptid))
3247  {
3248  /* Not found. */
3249  delete_thread (tp->ptid);
3250  }
3251  }
3252 
3253  /* Remove any unreported fork child threads from CONTEXT so
3254  that we don't interfere with follow fork, which is where
3255  creation of such threads is handled. */
3256  remove_new_fork_children (&context);
3257 
3258  /* And now add threads we don't know about yet to our list. */
3259  for (thread_item &item : context.items)
3260  {
3261  if (item.ptid != null_ptid)
3262  {
3263  /* In non-stop mode, we assume new found threads are
3264  executing until proven otherwise with a stop reply.
3265  In all-stop, we can only get here if all threads are
3266  stopped. */
3267  int executing = target_is_non_stop_p () ? 1 : 0;
3268 
3270 
3272  info->core = item.core;
3273  info->extra = std::move (item.extra);
3274  info->name = std::move (item.name);
3275  info->thread_handle = std::move (item.thread_handle);
3276  }
3277  }
3278  }
3279 
3280  if (!got_list)
3281  {
3282  /* If no thread listing method is supported, then query whether
3283  each known thread is alive, one by one, with the T packet.
3284  If the target doesn't support threads at all, then this is a
3285  no-op. See remote_thread_alive. */
3286  prune_threads ();
3287  }
3288 }
3289 
3290 /*
3291  * Collect a descriptive string about the given thread.
3292  * The target may say anything it wants to about the thread
3293  * (typically info about its blocked / runnable state, name, etc.).
3294  * This string will appear in the info threads display.
3295  *
3296  * Optional: targets are not required to implement this function.
3297  */
3298 
3299 static const char *
3301 {
3302  struct remote_state *rs = get_remote_state ();
3303  int result;
3304  int set;
3305  threadref id;
3306  struct gdb_ext_thread_info threadinfo;
3307  static char display_buf[100]; /* arbitrary... */
3308  int n = 0; /* position in display_buf */
3309 
3310  if (rs->remote_desc == 0) /* paranoia */
3311  internal_error (__FILE__, __LINE__,
3312  _("remote_threads_extra_info"));
3313 
3314  if (ptid_equal (tp->ptid, magic_null_ptid)
3315  || (ptid_get_pid (tp->ptid) != 0 && ptid_get_lwp (tp->ptid) == 0))
3316  /* This is the main thread which was added by GDB. The remote
3317  server doesn't know about it. */
3318  return NULL;
3319 
3321  {
3322  struct thread_info *info = find_thread_ptid (tp->ptid);
3323 
3324  if (info != NULL && info->priv != NULL)
3325  {
3326  const std::string &extra = get_remote_thread_info (info)->extra;
3327  return !extra.empty () ? extra.c_str () : NULL;
3328  }
3329  else
3330  return NULL;
3331  }
3332 
3333  if (rs->use_threadextra_query)
3334  {
3335  char *b = rs->buf;
3336  char *endb = rs->buf + get_remote_packet_size ();
3337 
3338  xsnprintf (b, endb - b, "qThreadExtraInfo,");
3339  b += strlen (b);
3340  write_ptid (b, endb, tp->ptid);
3341 
3342  putpkt (rs->buf);
3343  getpkt (&rs->buf, &rs->buf_size, 0);
3344  if (rs->buf[0] != 0)
3345  {
3346  n = std::min (strlen (rs->buf) / 2, sizeof (display_buf));
3347  result = hex2bin (rs->buf, (gdb_byte *) display_buf, n);
3348  display_buf [result] = '\0';
3349  return display_buf;
3350  }
3351  }
3352 
3353  /* If the above query fails, fall back to the old method. */
3354  rs->use_threadextra_query = 0;
3357  int_to_threadref (&id, ptid_get_lwp (tp->ptid));
3358  if (remote_get_threadinfo (&id, set, &threadinfo))
3359  if (threadinfo.active)
3360  {
3361  if (*threadinfo.shortname)
3362  n += xsnprintf (&display_buf[0], sizeof (display_buf) - n,
3363  " Name: %s,", threadinfo.shortname);
3364  if (*threadinfo.display)
3365  n += xsnprintf (&display_buf[n], sizeof (display_buf) - n,
3366  " State: %s,", threadinfo.display);
3367  if (*threadinfo.more_display)
3368  n += xsnprintf (&display_buf[n], sizeof (display_buf) - n,
3369  " Priority: %s", threadinfo.more_display);
3370 
3371  if (n > 0)
3372  {
3373  /* For purely cosmetic reasons, clear up trailing commas. */
3374  if (',' == display_buf[n-1])
3375  display_buf[n-1] = ' ';
3376  return display_buf;
3377  }
3378  }
3379  return NULL;
3380 }
3381 
3382 
3383 static int
3385  struct static_tracepoint_marker *marker)
3386 {
3387  struct remote_state *rs = get_remote_state ();
3388  char *p = rs->buf;
3389 
3390  xsnprintf (p, get_remote_packet_size (), "qTSTMat:");
3391  p += strlen (p);
3392  p += hexnumstr (p, addr);
3393  putpkt (rs->buf);
3394  getpkt (&rs->buf, &rs->buf_size, 0);
3395  p = rs->buf;
3396 
3397  if (*p == 'E')
3398  error (_("Remote failure reply: %s"), p);
3399 
3400  if (*p++ == 'm')
3401  {
3403  return 1;
3404  }
3405 
3406  return 0;
3407 }
3408 
3410 remote_static_tracepoint_markers_by_strid (struct target_ops *self,
3411  const char *strid)
3412 {
3413  struct remote_state *rs = get_remote_state ();
3414  VEC(static_tracepoint_marker_p) *markers = NULL;
3415  struct static_tracepoint_marker *marker = NULL;
3416  struct cleanup *old_chain;
3417  const char *p;
3418 
3419  /* Ask for a first packet of static tracepoint marker
3420  definition. */
3421  putpkt ("qTfSTM");
3422  getpkt (&rs->buf, &rs->buf_size, 0);
3423  p = rs->buf;
3424  if (*p == 'E')
3425  error (_("Remote failure reply: %s"), p);
3426 
3427  old_chain = make_cleanup (free_current_marker, &marker);
3428 
3429  while (*p++ == 'm')
3430  {
3431  if (marker == NULL)
3432  marker = XCNEW (struct static_tracepoint_marker);
3433 
3434  do
3435  {
3437 
3438  if (strid == NULL || strcmp (strid, marker->str_id) == 0)
3439  {
3441  markers, marker);
3442  marker = NULL;
3443  }
3444  else
3445  {
3447  memset (marker, 0, sizeof (*marker));
3448  }
3449  }
3450  while (*p++ == ','); /* comma-separated list */
3451  /* Ask for another packet of static tracepoint definition. */
3452  putpkt ("qTsSTM");
3453  getpkt (&rs->buf, &rs->buf_size, 0);
3454  p = rs->buf;
3455  }
3456 
3457  do_cleanups (old_chain);
3458  return markers;
3459 }
3460 
3461 
3462 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3463 
3464 static ptid_t
3465 remote_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
3466 {
3467  return ptid_build (ptid_get_pid (inferior_ptid), lwp, 0);
3468 }
3469 
3470 
3471 /* Restart the remote side; this is an extended protocol operation. */
3472 
3473 static void
3475 {
3476  struct remote_state *rs = get_remote_state ();
3477 
3478  /* Send the restart command; for reasons I don't understand the
3479  remote side really expects a number after the "R". */
3480  xsnprintf (rs->buf, get_remote_packet_size (), "R%x", 0);
3481  putpkt (rs->buf);
3482 
3484 }
3485 
3486 /* Clean up connection to a remote debugger. */
3487 
3488 static void
3489 remote_close (struct target_ops *self)
3490 {
3491  struct remote_state *rs = get_remote_state ();
3492 
3493  if (rs->remote_desc == NULL)
3494  return; /* already closed */
3495 
3496  /* Make sure we leave stdin registered in the event loop. */
3497  remote_terminal_ours (self);
3498 
3499  serial_close (rs->remote_desc);
3500  rs->remote_desc = NULL;
3501 
3502  /* We don't have a connection to the remote stub anymore. Get rid
3503  of all the inferiors and their threads we were controlling.
3504  Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3505  will be unable to find the thread corresponding to (pid, 0, 0). */
3508 
3509  /* We are closing the remote target, so we should discard
3510  everything of this target. */
3512 
3515 
3517 
3519 }
3520 
3521 /* Query the remote side for the text, data and bss offsets. */
3522 
3523 static void
3525 {
3526  struct remote_state *rs = get_remote_state ();
3527  char *buf;
3528  char *ptr;
3529  int lose, num_segments = 0, do_sections, do_segments;
3530  CORE_ADDR text_addr, data_addr, bss_addr, segments[2];
3531  struct section_offsets *offs;
3532  struct symfile_segment_data *data;
3533 
3534  if (symfile_objfile == NULL)
3535  return;
3536 
3537  putpkt ("qOffsets");
3538  getpkt (&rs->buf, &rs->buf_size, 0);
3539  buf = rs->buf;
3540 
3541  if (buf[0] == '\000')
3542  return; /* Return silently. Stub doesn't support
3543  this command. */
3544  if (buf[0] == 'E')
3545  {
3546  warning (_("Remote failure reply: %s"), buf);
3547  return;
3548  }
3549 
3550  /* Pick up each field in turn. This used to be done with scanf, but
3551  scanf will make trouble if CORE_ADDR size doesn't match
3552  conversion directives correctly. The following code will work
3553  with any size of CORE_ADDR. */
3554  text_addr = data_addr = bss_addr = 0;
3555  ptr = buf;
3556  lose = 0;
3557 
3558  if (startswith (ptr, "Text="))
3559  {
3560  ptr += 5;
3561  /* Don't use strtol, could lose on big values. */
3562  while (*ptr && *ptr != ';')
3563  text_addr = (text_addr << 4) + fromhex (*ptr++);
3564 
3565  if (startswith (ptr, ";Data="))
3566  {
3567  ptr += 6;
3568  while (*ptr && *ptr != ';')
3569  data_addr = (data_addr << 4) + fromhex (*ptr++);
3570  }
3571  else
3572  lose = 1;
3573 
3574  if (!lose && startswith (ptr, ";Bss="))
3575  {
3576  ptr += 5;
3577  while (*ptr && *ptr != ';')
3578  bss_addr = (bss_addr << 4) + fromhex (*ptr++);
3579 
3580  if (bss_addr != data_addr)
3581  warning (_("Target reported unsupported offsets: %s"), buf);
3582  }
3583  else
3584  lose = 1;
3585  }
3586  else if (startswith (ptr, "TextSeg="))
3587  {
3588  ptr += 8;
3589  /* Don't use strtol, could lose on big values. */
3590  while (*ptr && *ptr != ';')
3591  text_addr = (text_addr << 4) + fromhex (*ptr++);
3592  num_segments = 1;
3593 
3594  if (startswith (ptr, ";DataSeg="))
3595  {
3596  ptr += 9;
3597  while (*ptr && *ptr != ';')
3598  data_addr = (data_addr << 4) + fromhex (*ptr++);
3599  num_segments++;
3600  }
3601  }
3602  else
3603  lose = 1;
3604 
3605  if (lose)
3606  error (_("Malformed response to offset query, %s"), buf);
3607  else if (*ptr != '\0')
3608  warning (_("Target reported unsupported offsets: %s"), buf);
3609 
3610  offs = ((struct section_offsets *)
3611  alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile->num_sections)));
3612  memcpy (offs, symfile_objfile->section_offsets,
3613  SIZEOF_N_SECTION_OFFSETS (symfile_objfile->num_sections));
3614 
3616  do_segments = (data != NULL);
3617  do_sections = num_segments == 0;
3618 
3619  if (num_segments > 0)
3620  {
3621  segments[0] = text_addr;
3622  segments[1] = data_addr;
3623  }
3624  /* If we have two segments, we can still try to relocate everything
3625  by assuming that the .text and .data offsets apply to the whole
3626  text and data segments. Convert the offsets given in the packet
3627  to base addresses for symfile_map_offsets_to_segments. */
3628  else if (data && data->num_segments == 2)
3629  {
3630  segments[0] = data->segment_bases[0] + text_addr;
3631  segments[1] = data->segment_bases[1] + data_addr;
3632  num_segments = 2;
3633  }
3634  /* If the object file has only one segment, assume that it is text
3635  rather than data; main programs with no writable data are rare,
3636  but programs with no code are useless. Of course the code might
3637  have ended up in the data segment... to detect that we would need
3638  the permissions here. */
3639  else if (data && data->num_segments == 1)
3640  {
3641  segments[0] = data->segment_bases[0] + text_addr;
3642  num_segments = 1;
3643  }
3644  /* There's no way to relocate by segment. */
3645  else
3646  do_segments = 0;
3647 
3648  if (do_segments)
3649  {
3650  int ret = symfile_map_offsets_to_segments (symfile_objfile->obfd, data,
3651  offs, num_segments, segments);
3652 
3653  if (ret == 0 && !do_sections)
3654  error (_("Can not handle qOffsets TextSeg "
3655  "response with this symbol file"));
3656 
3657  if (ret > 0)
3658  do_sections = 0;
3659  }
3660 
3661  if (data)
3663 
3664  if (do_sections)
3665  {
3666  offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_addr;
3667 
3668  /* This is a temporary kludge to force data and bss to use the
3669  same offsets because that's what nlmconv does now. The real
3670  solution requires changes to the stub and remote.c that I
3671  don't have time to do right now. */
3672 
3673  offs->offsets[SECT_OFF_DATA (symfile_objfile)] = data_addr;
3674  offs->offsets[SECT_OFF_BSS (symfile_objfile)] = data_addr;
3675  }
3676 
3678 }
3679 
3680 /* Send interrupt_sequence to remote target. */
3681 static void
3683 {
3684  struct remote_state *rs = get_remote_state ();
3685 
3687  remote_serial_write ("\x03", 1);
3691  {
3693  remote_serial_write ("g", 1);
3694  }
3695  else
3696  internal_error (__FILE__, __LINE__,
3697  _("Invalid value for interrupt_sequence_mode: %s."),
3699 }
3700 
3701 
3702 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3703  and extract the PTID. Returns NULL_PTID if not found. */
3704 
3705 static ptid_t
3707 {
3708  if (stop_reply[0] == 'T' && strlen (stop_reply) > 3)
3709  {
3710  const char *p;
3711 
3712  /* Txx r:val ; r:val (...) */
3713  p = &stop_reply[3];
3714 
3715  /* Look for "register" named "thread". */
3716  while (*p != '\0')
3717  {
3718  const char *p1;
3719 
3720  p1 = strchr (p, ':');
3721  if (p1 == NULL)
3722  return null_ptid;
3723 
3724  if (strncmp (p, "thread", p1 - p) == 0)
3725  return read_ptid (++p1, &p);
3726 
3727  p1 = strchr (p, ';');
3728  if (p1 == NULL)
3729  return null_ptid;
3730  p1++;
3731 
3732  p = p1;
3733  }
3734  }
3735 
3736  return null_ptid;
3737 }
3738 
3739 /* Determine the remote side's current thread. If we have a stop
3740  reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3741  "thread" register we can extract the current thread from. If not,
3742  ask the remote which is the current thread with qC. The former
3743  method avoids a roundtrip. */
3744 
3745 static ptid_t
3746 get_current_thread (char *wait_status)
3747 {
3748  ptid_t ptid = null_ptid;
3749 
3750  /* Note we don't use remote_parse_stop_reply as that makes use of
3751  the target architecture, which we haven't yet fully determined at
3752  this point. */
3753  if (wait_status != NULL)
3754  ptid = stop_reply_extract_thread (wait_status);
3755  if (ptid_equal (ptid, null_ptid))
3757 
3758  return ptid;
3759 }
3760 
3761 /* Query the remote target for which is the current thread/process,
3762  add it to our tables, and update INFERIOR_PTID. The caller is
3763  responsible for setting the state such that the remote end is ready
3764  to return the current thread.
3765 
3766  This function is called after handling the '?' or 'vRun' packets,
3767  whose response is a stop reply from which we can also try
3768  extracting the thread. If the target doesn't support the explicit
3769  qC query, we infer the current thread from that stop reply, passed
3770  in in WAIT_STATUS, which may be NULL. */
3771 
3772 static void
3774 {
3775  struct remote_state *rs = get_remote_state ();
3776  int fake_pid_p = 0;
3777 
3779 
3780  /* Now, if we have thread information, update inferior_ptid. */
3781  ptid_t curr_ptid = get_current_thread (wait_status);
3782 
3783  if (curr_ptid != null_ptid)
3784  {
3785  if (!remote_multi_process_p (rs))
3786  fake_pid_p = 1;
3787  }
3788  else
3789  {
3790  /* Without this, some commands which require an active target
3791  (such as kill) won't work. This variable serves (at least)
3792  double duty as both the pid of the target process (if it has
3793  such), and as a flag indicating that a target is active. */
3794  curr_ptid = magic_null_ptid;
3795  fake_pid_p = 1;
3796  }
3797 
3798  remote_add_inferior (fake_pid_p, ptid_get_pid (curr_ptid), -1, 1);
3799 
3800  /* Add the main thread and switch to it. Don't try reading
3801  registers yet, since we haven't fetched the target description
3802  yet. */
3803  thread_info *tp = add_thread_silent (curr_ptid);
3805 }
3806 
3807 /* Print info about a thread that was found already stopped on
3808  connection. */
3809 
3810 static void
3812 {
3813  struct target_waitstatus *ws = &thread->suspend.waitstatus;
3814 
3815  switch_to_thread (thread->ptid);
3818 
3819  thread->suspend.waitstatus_pending_p = 0;
3820 
3821  if (ws->kind == TARGET_WAITKIND_STOPPED)
3822  {
3823  enum gdb_signal sig = ws->value.sig;
3824 
3825  if (signal_print_state (sig))
3827  }
3828  observer_notify_normal_stop (NULL, 1);
3829 }
3830 
3831 /* Process all initial stop replies the remote side sent in response
3832  to the ? packet. These indicate threads that were already stopped
3833  on initial connection. We mark these threads as stopped and print
3834  their current frame before giving the user the prompt. */
3835 
3836 static void
3838 {
3839  int pending_stop_replies = stop_reply_queue_length ();
3840  struct inferior *inf;
3841  struct thread_info *thread;
3842  struct thread_info *selected = NULL;
3843  struct thread_info *lowest_stopped = NULL;
3844  struct thread_info *first = NULL;
3845 
3846  /* Consume the initial pending events. */
3847  while (pending_stop_replies-- > 0)
3848  {
3849  ptid_t waiton_ptid = minus_one_ptid;
3850  ptid_t event_ptid;
3851  struct target_waitstatus ws;
3852  int ignore_event = 0;
3853  struct thread_info *thread;
3854 
3855  memset (&ws, 0, sizeof (ws));
3856  event_ptid = target_wait (waiton_ptid, &ws, TARGET_WNOHANG);
3857  if (remote_debug)
3858  print_target_wait_results (waiton_ptid, event_ptid, &ws);
3859 
3860  switch (ws.kind)
3861  {
3866  /* We shouldn't see these, but if we do, just ignore. */
3867  if (remote_debug)
3868  fprintf_unfiltered (gdb_stdlog, "remote: event ignored\n");
3869  ignore_event = 1;
3870  break;
3871 
3872  case TARGET_WAITKIND_EXECD:
3873  xfree (ws.value.execd_pathname);
3874  break;
3875  default:
3876  break;
3877  }
3878 
3879  if (ignore_event)
3880  continue;
3881 
3882  thread = find_thread_ptid (event_ptid);
3883 
3884  if (ws.kind == TARGET_WAITKIND_STOPPED)
3885  {
3886  enum gdb_signal sig = ws.value.sig;
3887 
3888  /* Stubs traditionally report SIGTRAP as initial signal,
3889  instead of signal 0. Suppress it. */
3890  if (sig == GDB_SIGNAL_TRAP)
3891  sig = GDB_SIGNAL_0;
3892  thread->suspend.stop_signal = sig;
3893  ws.value.sig = sig;
3894  }
3895 
3896  thread->suspend.waitstatus = ws;
3897 
3898  if (ws.kind != TARGET_WAITKIND_STOPPED
3899  || ws.value.sig != GDB_SIGNAL_0)
3900  thread->suspend.waitstatus_pending_p = 1;
3901 
3902  set_executing (event_ptid, 0);
3903  set_running (event_ptid, 0);
3904  get_remote_thread_info (thread)->vcont_resumed = 0;
3905  }
3906 
3907  /* "Notice" the new inferiors before anything related to
3908  registers/memory. */
3909  ALL_INFERIORS (inf)
3910  {
3911  if (inf->pid == 0)
3912  continue;
3913 
3914  inf->needs_setup = 1;
3915 
3916  if (non_stop)
3917  {
3918  thread = any_live_thread_of_process (inf->pid);
3919  notice_new_inferior (thread->ptid,
3920  thread->state == THREAD_RUNNING,
3921  from_tty);
3922  }
3923  }
3924 
3925  /* If all-stop on top of non-stop, pause all threads. Note this
3926  records the threads' stop pc, so must be done after "noticing"
3927  the inferiors. */
3928  if (!non_stop)
3929  {
3930  stop_all_threads ();
3931 
3932  /* If all threads of an inferior were already stopped, we
3933  haven't setup the inferior yet. */
3934  ALL_INFERIORS (inf)
3935  {
3936  if (inf->pid == 0)
3937  continue;
3938 
3939  if (inf->needs_setup)
3940  {
3941  thread = any_live_thread_of_process (inf->pid);
3942  switch_to_thread_no_regs (thread);
3943  setup_inferior (0);
3944  }
3945  }
3946  }
3947 
3948  /* Now go over all threads that are stopped, and print their current
3949  frame. If all-stop, then if there's a signalled thread, pick
3950  that as current. */
3951  ALL_NON_EXITED_THREADS (thread)
3952  {
3953  if (first == NULL)
3954  first = thread;
3955 
3956  if (!non_stop)
3957  set_running (thread->ptid, 0);
3958  else if (thread->state != THREAD_STOPPED)
3959  continue;
3960 
3961  if (selected == NULL
3962  && thread->suspend.waitstatus_pending_p)
3963  selected = thread;
3964 
3965  if (lowest_stopped == NULL
3966  || thread->inf->num < lowest_stopped->inf->num
3967  || thread->per_inf_num < lowest_stopped->per_inf_num)
3968  lowest_stopped = thread;
3969 
3970  if (non_stop)
3971  print_one_stopped_thread (thread);
3972  }
3973 
3974  /* In all-stop, we only print the status of one thread, and leave
3975  others with their status pending. */
3976  if (!non_stop)
3977  {
3978  thread = selected;
3979  if (thread == NULL)
3980  thread = lowest_stopped;
3981  if (thread == NULL)
3982  thread = first;
3983 
3984  print_one_stopped_thread (thread);
3985  }
3986 
3987  /* For "info program". */
3988  thread = inferior_thread ();
3989  if (thread->state == THREAD_STOPPED)
3991 }
3992 
3993 /* Start the remote connection and sync state. */
3994 
3995 static void
3996 remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
3997 {
3998  struct remote_state *rs = get_remote_state ();
3999  struct packet_config *noack_config;
4000  char *wait_status = NULL;
4001 
4002  /* Signal other parts that we're going through the initial setup,
4003  and so things may not be stable yet. E.g., we don't try to
4004  install tracepoints until we've relocated symbols. Also, a
4005  Ctrl-C before we're connected and synced up can't interrupt the
4006  target. Instead, it offers to drop the (potentially wedged)
4007  connection. */
4008  rs->starting_up = 1;
4009 
4010  QUIT;
4011 
4014 
4015  /* Ack any packet which the remote side has already sent. */
4016  remote_serial_write ("+", 1);
4017 
4018  /* The first packet we send to the target is the optional "supported
4019  packets" request. If the target can answer this, it will tell us
4020  which later probes to skip. */
4022 
4023  /* If the stub wants to get a QAllow, compose one and send it. */
4025  remote_set_permissions (target);
4026 
4027  /* gdbserver < 7.7 (before its fix from 2013-12-11) did reply to any
4028  unknown 'v' packet with string "OK". "OK" gets interpreted by GDB
4029  as a reply to known packet. For packet "vFile:setfs:" it is an
4030  invalid reply and GDB would return error in
4031  remote_hostio_set_filesystem, making remote files access impossible.
4032  Disable "vFile:setfs:" in such case. Do not disable other 'v' packets as
4033  other "vFile" packets get correctly detected even on gdbserver < 7.7. */
4034  {
4035  const char v_mustreplyempty[] = "vMustReplyEmpty";
4036 
4037  putpkt (v_mustreplyempty);
4038  getpkt (&rs->buf, &rs->buf_size, 0);
4039  if (strcmp (rs->buf, "OK") == 0)
4041  else if (strcmp (rs->buf, "") != 0)
4042  error (_("Remote replied unexpectedly to '%s': %s"), v_mustreplyempty,
4043  rs->buf);
4044  }
4045 
4046  /* Next, we possibly activate noack mode.
4047 
4048  If the QStartNoAckMode packet configuration is set to AUTO,
4049  enable noack mode if the stub reported a wish for it with
4050  qSupported.
4051 
4052  If set to TRUE, then enable noack mode even if the stub didn't
4053  report it in qSupported. If the stub doesn't reply OK, the
4054  session ends with an error.
4055 
4056  If FALSE, then don't activate noack mode, regardless of what the
4057  stub claimed should be the default with qSupported. */
4058 
4060  if (packet_config_support (noack_config) != PACKET_DISABLE)
4061  {
4062  putpkt ("QStartNoAckMode");
4063  getpkt (&rs->buf, &rs->buf_size, 0);
4064  if (packet_ok (rs->buf, noack_config) == PACKET_OK)
4065  rs->noack_mode = 1;
4066  }
4067 
4068  if (extended_p)
4069  {
4070  /* Tell the remote that we are using the extended protocol. */
4071  putpkt ("!");
4072  getpkt (&rs->buf, &rs->buf_size, 0);
4073  }
4074 
4075  /* Let the target know which signals it is allowed to pass down to
4076  the program. */
4078 
4079  /* Next, if the target can specify a description, read it. We do
4080  this before anything involving memory or registers. */
4082 
4083  /* Next, now that we know something about the target, update the
4084  address spaces in the program spaces. */
4086 
4087  /* On OSs where the list of libraries is global to all
4088  processes, we fetch them early. */
4090  solib_add (NULL, from_tty, auto_solib_add);
4091 
4092  if (target_is_non_stop_p ())
4093  {
4095  error (_("Non-stop mode requested, but remote "
4096  "does not support non-stop"));
4097 
4098  putpkt ("QNonStop:1");
4099  getpkt (&rs->buf, &rs->buf_size, 0);
4100 
4101  if (strcmp (rs->buf, "OK") != 0)
4102  error (_("Remote refused setting non-stop mode with: %s"), rs->buf);
4103 
4104  /* Find about threads and processes the stub is already
4105  controlling. We default to adding them in the running state.
4106  The '?' query below will then tell us about which threads are
4107  stopped. */
4108  remote_update_thread_list (target);
4109  }
4111  {
4112  /* Don't assume that the stub can operate in all-stop mode.
4113  Request it explicitly. */
4114  putpkt ("QNonStop:0");
4115  getpkt (&rs->buf, &rs->buf_size, 0);
4116 
4117  if (strcmp (rs->buf, "OK") != 0)
4118  error (_("Remote refused setting all-stop mode with: %s"), rs->buf);
4119  }
4120 
4121  /* Upload TSVs regardless of whether the target is running or not. The
4122  remote stub, such as GDBserver, may have some predefined or builtin
4123  TSVs, even if the target is not running. */
4124  if (remote_get_trace_status (target, current_trace_status ()) != -1)
4125  {
4126  struct uploaded_tsv *uploaded_tsvs = NULL;
4127 
4128  remote_upload_trace_state_variables (target, &uploaded_tsvs);
4129  merge_uploaded_trace_state_variables (&uploaded_tsvs);
4130  }
4131 
4132  /* Check whether the target is running now. */
4133  putpkt ("?");
4134  getpkt (&rs->buf, &rs->buf_size, 0);
4135 
4136  if (!target_is_non_stop_p ())
4137  {
4138  if (rs->buf[0] == 'W' || rs->buf[0] == 'X')
4139  {
4140  if (!extended_p)
4141  error (_("The target is not running (try extended-remote?)"));
4142 
4143  /* We're connected, but not running. Drop out before we
4144  call start_remote. */
4145  rs->starting_up = 0;
4146  return;
4147  }
4148  else
4149  {
4150  /* Save the reply for later. */
4151  wait_status = (char *) alloca (strlen (rs->buf) + 1);
4152  strcpy (wait_status, rs->buf);
4153  }
4154 
4155  /* Fetch thread list. */
4157 
4158  /* Let the stub know that we want it to return the thread. */
4160 
4161  if (thread_count () == 0)
4162  {
4163  /* Target has no concept of threads at all. GDB treats
4164  non-threaded target as single-threaded; add a main
4165  thread. */
4166  add_current_inferior_and_thread (wait_status);
4167  }
4168  else
4169  {
4170  /* We have thread information; select the thread the target
4171  says should be current. If we're reconnecting to a
4172  multi-threaded program, this will ideally be the thread
4173  that last reported an event before GDB disconnected. */
4174  inferior_ptid = get_current_thread (wait_status);
4176  {
4177  /* Odd... The target was able to list threads, but not
4178  tell us which thread was current (no "thread"
4179  register in T stop reply?). Just pick the first
4180  thread in the thread list then. */
4181 
4182  if (remote_debug)
4184  "warning: couldn't determine remote "
4185  "current thread; picking first in list.\n");
4186 
4188  }
4189  }
4190 
4191  /* init_wait_for_inferior should be called before get_offsets in order
4192  to manage `inserted' flag in bp loc in a correct state.
4193  breakpoint_init_inferior, called from init_wait_for_inferior, set
4194  `inserted' flag to 0, while before breakpoint_re_set, called from
4195  start_remote, set `inserted' flag to 1. In the initialization of
4196  inferior, breakpoint_init_inferior should be called first, and then
4197  breakpoint_re_set can be called. If this order is broken, state of
4198  `inserted' flag is wrong, and cause some problems on breakpoint
4199  manipulation. */
4201 
4202  get_offsets (); /* Get text, data & bss offsets. */
4203 
4204  /* If we could not find a description using qXfer, and we know
4205  how to do it some other way, try again. This is not
4206  supported for non-stop; it could be, but it is tricky if
4207  there are no stopped threads when we connect. */
4208  if (remote_read_description_p (target)
4209  && gdbarch_target_desc (target_gdbarch ()) == NULL)
4210  {
4213  }
4214 
4215  /* Use the previously fetched status. */
4216  gdb_assert (wait_status != NULL);
4217  strcpy (rs->buf, wait_status);
4218  rs->cached_wait_status = 1;
4219 
4220  start_remote (from_tty); /* Initialize gdb process mechanisms. */
4221  }
4222  else
4223  {
4224  /* Clear WFI global state. Do this before finding about new
4225  threads and inferiors, and setting the current inferior.
4226  Otherwise we would clear the proceed status of the current
4227  inferior when we want its stop_soon state to be preserved
4228  (see notice_new_inferior). */
4230 
4231  /* In non-stop, we will either get an "OK", meaning that there
4232  are no stopped threads at this time; or, a regular stop
4233  reply. In the latter case, there may be more than one thread
4234  stopped --- we pull them all out using the vStopped
4235  mechanism. */
4236  if (strcmp (rs->buf, "OK") != 0)
4237  {
4238  struct notif_client *notif = &notif_client_stop;
4239 
4240  /* remote_notif_get_pending_replies acks this one, and gets
4241  the rest out. */
4243  = remote_notif_parse (notif, rs->buf);
4245  }
4246 
4247  if (thread_count () == 0)
4248  {
4249  if (!extended_p)
4250  error (_("The target is not running (try extended-remote?)"));
4251 
4252  /* We're connected, but not running. Drop out before we
4253  call start_remote. */
4254  rs->starting_up = 0;
4255  return;
4256  }
4257 
4258  /* In non-stop mode, any cached wait status will be stored in
4259  the stop reply queue. */
4260  gdb_assert (wait_status == NULL);
4261 
4262  /* Report all signals during attach/startup. */
4263  remote_pass_signals (target, 0, NULL);
4264 
4265  /* If there are already stopped threads, mark them stopped and
4266  report their stops before giving the prompt to the user. */
4267  process_initial_stop_replies (from_tty);
4268 
4269  if (target_can_async_p ())
4270  target_async (1);
4271  }
4272 
4273  /* If we connected to a live target, do some additional setup. */
4275  {
4276  if (symfile_objfile) /* No use without a symbol-file. */
4278  }
4279 
4280  /* Possibly the target has been engaged in a trace run started
4281  previously; find out where things are at. */
4282  if (remote_get_trace_status (target, current_trace_status ()) != -1)
4283  {
4284  struct uploaded_tp *uploaded_tps = NULL;
4285 
4286  if (current_trace_status ()->running)
4287  printf_filtered (_("Trace is already running on the target.\n"));
4288 
4289  remote_upload_tracepoints (target, &uploaded_tps);
4290 
4291  merge_uploaded_tracepoints (&uploaded_tps);
4292  }
4293 
4294  /* Possibly the target has been engaged in a btrace record started
4295  previously; find out where things are at. */
4297 
4298  /* The thread and inferior lists are now synchronized with the
4299  target, our symbols have been relocated, and we're merged the
4300  target's tracepoints with ours. We're done with basic start
4301  up. */
4302  rs->starting_up = 0;
4303 
4304  /* Maybe breakpoints are global and need to be inserted now. */
4306  insert_breakpoints ();
4307 }
4308 
4309 /* Open a connection to a remote debugger.
4310  NAME is the filename used for communication. */
4311 
4312 static void
4313 remote_open (const char *name, int from_tty)
4314 {
4315  remote_open_1 (name, from_tty, &remote_ops, 0);
4316 }
4317 
4318 /* Open a connection to a remote debugger using the extended
4319  remote gdb protocol. NAME is the filename used for communication. */
4320 
4321 static void
4322 extended_remote_open (const char *name, int from_tty)
4323 {
4324  remote_open_1 (name, from_tty, &extended_remote_ops, 1 /*extended_p */);
4325 }
4326 
4327 /* Reset all packets back to "unknown support". Called when opening a
4328  new connection to a remote target. */
4329 
4330 static void
4332 {
4333  int i;
4334 
4335  for (i = 0; i < PACKET_MAX; i++)
4337 }
4338 
4339 /* Initialize all packet configs. */
4340 
4341 static void
4343 {
4344  int i;
4345 
4346  for (i = 0; i < PACKET_MAX; i++)
4347  {
4350  }
4351 }
4352 
4353 /* Symbol look-up. */
4354 
4355 static void
4357 {
4358  char *msg, *reply, *tmp;
4359  int end;
4360  long reply_size;
4361  struct cleanup *old_chain;
4362 
4363  /* The remote side has no concept of inferiors that aren't running
4364  yet, it only knows about running processes. If we're connected
4365  but our current inferior is not running, we should not invite the
4366  remote target to request symbol lookups related to its
4367  (unrelated) current process. */
4368  if (!target_has_execution)
4369  return;
4370 
4372  return;
4373 
4374  /* Make sure the remote is pointing at the right process. Note
4375  there's no way to select "no process". */
4377 
4378  /* Allocate a message buffer. We can't reuse the input buffer in RS,
4379  because we need both at the same time. */
4380  msg = (char *) xmalloc (get_remote_packet_size ());
4381  old_chain = make_cleanup (xfree, msg);
4382  reply = (char *) xmalloc (get_remote_packet_size ());
4384  reply_size = get_remote_packet_size ();
4385 
4386  /* Invite target to request symbol lookups. */
4387 
4388  putpkt ("qSymbol::");
4389  getpkt (&reply, &reply_size, 0);
4391 
4392  while (startswith (reply, "qSymbol:"))
4393  {
4394  struct bound_minimal_symbol sym;
4395 
4396  tmp = &reply[8];
4397  end = hex2bin (tmp, (gdb_byte *) msg, strlen (tmp) / 2);
4398  msg[end] = '\0';
4399  sym = lookup_minimal_symbol (msg, NULL, NULL);
4400  if (sym.minsym == NULL)
4401  xsnprintf (msg, get_remote_packet_size (), "qSymbol::%s", &reply[8]);
4402  else
4403  {
4404  int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
4405  CORE_ADDR sym_addr = BMSYMBOL_VALUE_ADDRESS (sym);
4406 
4407  /* If this is a function address, return the start of code
4408  instead of any data function descriptor. */
4410  sym_addr,
4411  &current_target);
4412 
4413  xsnprintf (msg, get_remote_packet_size (), "qSymbol:%s:%s",
4414  phex_nz (sym_addr, addr_size), &reply[8]);
4415  }
4416 
4417  putpkt (msg);
4418  getpkt (&reply, &reply_size, 0);
4419  }
4420 
4421  do_cleanups (old_chain);
4422 }
4423 
4424 static struct serial *
4426 {
4427  static int udp_warning = 0;
4428 
4429  /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
4430  of in ser-tcp.c, because it is the remote protocol assuming that the
4431  serial connection is reliable and not the serial connection promising
4432  to be. */
4433  if (!udp_warning && startswith (name, "udp:"))
4434  {
4435  warning (_("The remote protocol may be unreliable over UDP.\n"
4436  "Some events may be lost, rendering further debugging "
4437  "impossible."));
4438  udp_warning = 1;
4439  }
4440 
4441  return serial_open (name);
4442 }
4443 
4444 /* Inform the target of our permission settings. The permission flags
4445  work without this, but if the target knows the settings, it can do
4446  a couple things. First, it can add its own check, to catch cases
4447  that somehow manage to get by the permissions checks in target
4448  methods. Second, if the target is wired to disallow particular
4449  settings (for instance, a system in the field that is not set up to
4450  be able to stop at a breakpoint), it can object to any unavailable
4451  permissions. */
4452 
4453 void
4455 {
4456  struct remote_state *rs = get_remote_state ();
4457 
4458  xsnprintf (rs->buf, get_remote_packet_size (), "QAllow:"
4459  "WriteReg:%x;WriteMem:%x;"
4460  "InsertBreak:%x;InsertTrace:%x;"
4461  "InsertFastTrace:%x;Stop:%x",
4465  putpkt (rs->buf);
4466  getpkt (&rs->buf, &rs->buf_size, 0);
4467 
4468  /* If the target didn't like the packet, warn the user. Do not try
4469  to undo the user's settings, that would just be maddening. */
4470  if (strcmp (rs->buf, "OK") != 0)
4471  warning (_("Remote refused setting permissions with: %s"), rs->buf);
4472 }
4473 
4474 /* This type describes each known response to the qSupported
4475  packet. */
4477 {
4478  /* The name of this protocol feature. */
4479  const char *name;
4480 
4481  /* The default for this protocol feature. */
4483 
4484  /* The function to call when this feature is reported, or after
4485  qSupported processing if the feature is not supported.
4486  The first argument points to this structure. The second
4487  argument indicates whether the packet requested support be
4488  enabled, disabled, or probed (or the default, if this function
4489  is being called at the end of processing and this feature was
4490  not reported). The third argument may be NULL; if not NULL, it
4491  is a NUL-terminated string taken from the packet following
4492  this feature's name and an equals sign. */
4493  void (*func) (const struct protocol_feature *, enum packet_support,
4494  const char *);
4495 
4496  /* The corresponding packet for this feature. Only used if
4497  FUNC is remote_supported_packet. */
4498  int packet;
4499 };
4500 
4501 static void
4503  enum packet_support support,
4504  const char *argument)
4505 {
4506  if (argument)
4507  {
4508  warning (_("Remote qSupported response supplied an unexpected value for"
4509  " \"%s\"."), feature->name);
4510  return;
4511  }
4512 
4513  remote_protocol_packets[feature->packet].support = support;
4514 }
4515 
4516 static void
4517 remote_packet_size (const struct protocol_feature *feature,
4518  enum packet_support support, const char *value)
4519 {
4520  struct remote_state *rs = get_remote_state ();
4521 
4522  int packet_size;
4523  char *value_end;
4524 
4525  if (support != PACKET_ENABLE)
4526  return;
4527 
4528  if (value == NULL || *value == '\0')
4529  {
4530  warning (_("Remote target reported \"%s\" without a size."),
4531  feature->name);
4532  return;
4533  }
4534 
4535  errno = 0;
4536  packet_size = strtol (value, &value_end, 16);
4537  if (errno != 0 || *value_end != '\0' || packet_size < 0)
4538  {
4539  warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4540  feature->name, value);
4541  return;
4542  }
4543 
4544  /* Record the new maximum packet size. */
4545  rs->explicit_packet_size = packet_size;
4546 }
4547 
4549  { "PacketSize", PACKET_DISABLE, remote_packet_size, -1 },
4550  { "qXfer:auxv:read", PACKET_DISABLE, remote_supported_packet,
4552  { "qXfer:exec-file:read", PACKET_DISABLE, remote_supported_packet,
4554  { "qXfer:features:read", PACKET_DISABLE, remote_supported_packet,
4556  { "qXfer:libraries:read", PACKET_DISABLE, remote_supported_packet,
4558  { "qXfer:libraries-svr4:read", PACKET_DISABLE, remote_supported_packet,
4560  { "augmented-libraries-svr4-read", PACKET_DISABLE,
4562  { "qXfer:memory-map:read", PACKET_DISABLE, remote_supported_packet,
4564  { "qXfer:spu:read", PACKET_DISABLE, remote_supported_packet,
4566  { "qXfer:spu:write", PACKET_DISABLE, remote_supported_packet,
4568  { "qXfer:osdata:read", PACKET_DISABLE, remote_supported_packet,
4570  { "qXfer:threads:read", PACKET_DISABLE, remote_supported_packet,
4572  { "qXfer:traceframe-info:read", PACKET_DISABLE, remote_supported_packet,
4574  { "QPassSignals", PACKET_DISABLE, remote_supported_packet,
4576  { "QCatchSyscalls", PACKET_DISABLE, remote_supported_packet,
4578  { "QProgramSignals", PACKET_DISABLE, remote_supported_packet,
4580  { "QSetWorkingDir", PACKET_DISABLE, remote_supported_packet,
4582  { "QStartupWithShell", PACKET_DISABLE, remote_supported_packet,
4584  { "QEnvironmentHexEncoded", PACKET_DISABLE, remote_supported_packet,
4586  { "QEnvironmentReset", PACKET_DISABLE, remote_supported_packet,
4588  { "QEnvironmentUnset", PACKET_DISABLE, remote_supported_packet,
4590  { "QStartNoAckMode", PACKET_DISABLE, remote_supported_packet,
4592  { "multiprocess", PACKET_DISABLE, remote_supported_packet,
4595  { "qXfer:siginfo:read", PACKET_DISABLE, remote_supported_packet,
4597  { "qXfer:siginfo:write", PACKET_DISABLE, remote_supported_packet,
4599  { "ConditionalTracepoints", PACKET_DISABLE, remote_supported_packet,
4601  { "ConditionalBreakpoints", PACKET_DISABLE, remote_supported_packet,
4603  { "BreakpointCommands", PACKET_DISABLE, remote_supported_packet,
4605  { "FastTracepoints", PACKET_DISABLE, remote_supported_packet,
4607  { "StaticTracepoints", PACKET_DISABLE, remote_supported_packet,
4609  {"InstallInTrace", PACKET_DISABLE, remote_supported_packet,
4611  { "DisconnectedTracing", PACKET_DISABLE, remote_supported_packet,
4613  { "ReverseContinue", PACKET_DISABLE, remote_supported_packet,
4614  PACKET_bc },
4615  { "ReverseStep", PACKET_DISABLE, remote_supported_packet,
4616  PACKET_bs },
4617  { "TracepointSource", PACKET_DISABLE, remote_supported_packet,
4620  PACKET_QAllow },
4621  { "EnableDisableTracepoints", PACKET_DISABLE, remote_supported_packet,
4623  { "qXfer:fdpic:read", PACKET_DISABLE, remote_supported_packet,
4625  { "qXfer:uib:read", PACKET_DISABLE, remote_supported_packet,
4626  PACKET_qXfer_uib },
4627  { "QDisableRandomization", PACKET_DISABLE, remote_supported_packet,
4630  { "QTBuffer:size", PACKET_DISABLE,
4636  { "qXfer:btrace:read", PACKET_DISABLE, remote_supported_packet,
4638  { "qXfer:btrace-conf:read", PACKET_DISABLE, remote_supported_packet,
4640  { "Qbtrace-conf:bts:size", PACKET_DISABLE, remote_supported_packet,
4644  { "fork-events", PACKET_DISABLE, remote_supported_packet,
4646  { "vfork-events", PACKET_DISABLE, remote_supported_packet,
4648  { "exec-events", PACKET_DISABLE, remote_supported_packet,
4650  { "Qbtrace-conf:pt:size", PACKET_DISABLE, remote_supported_packet,
4655 };
4656 
4657 static char *remote_support_xml;
4658 
4659 /* Register string appended to "xmlRegisters=" in qSupported query. */
4660 
4661 void
4663 {
4664 #if defined(HAVE_LIBEXPAT)
4665  if (remote_support_xml == NULL)
4666  remote_support_xml = concat ("xmlRegisters=", xml, (char *) NULL);
4667  else
4668  {
4669  char *copy = xstrdup (remote_support_xml + 13);
4670  char *p = strtok (copy, ",");
4671 
4672  do
4673  {
4674  if (strcmp (p, xml) == 0)
4675  {
4676  /* already there */
4677  xfree (copy);
4678  return;
4679  }
4680  }
4681  while ((p = strtok (NULL, ",")) != NULL);
4682  xfree (copy);
4683 
4685  remote_support_xml, ",", xml,
4686  (char *) NULL);
4687  }
4688 #endif
4689 }
4690 
4691 static char *
4692 remote_query_supported_append (char *msg, const char *append)
4693 {
4694  if (msg)
4695  return reconcat (msg, msg, ";", append, (char *) NULL);
4696  else
4697  return xstrdup (append);
4698 }
4699 
4700 static void
4702 {
4703  struct remote_state *rs = get_remote_state ();
4704  char *next;
4705  int i;
4706  unsigned char seen [ARRAY_SIZE (remote_protocol_features)];
4707 
4708  /* The packet support flags are handled differently for this packet
4709  than for most others. We treat an error, a disabled packet, and
4710  an empty response identically: any features which must be reported
4711  to be used will be automatically disabled. An empty buffer
4712  accomplishes this, since that is also the representation for a list
4713  containing no features. */
4714 
4715  rs->buf[0] = 0;
4717  {
4718  char *q = NULL;
4719  struct cleanup *old_chain = make_cleanup (free_current_contents, &q);
4720 
4722  q = remote_query_supported_append (q, "multiprocess+");
4723 
4725  q = remote_query_supported_append (q, "swbreak+");
4727  q = remote_query_supported_append (q, "hwbreak+");
4728 
4729  q = remote_query_supported_append (q, "qRelocInsn+");
4730 
4732  != AUTO_BOOLEAN_FALSE)
4733  q = remote_query_supported_append (q, "fork-events+");
4735  != AUTO_BOOLEAN_FALSE)
4736  q = remote_query_supported_append (q, "vfork-events+");
4738  != AUTO_BOOLEAN_FALSE)
4739  q = remote_query_supported_append (q, "exec-events+");
4740 
4742  q = remote_query_supported_append (q, "vContSupported+");
4743 
4745  q = remote_query_supported_append (q, "QThreadEvents+");
4746 
4748  q = remote_query_supported_append (q, "no-resumed+");
4749 
4750  /* Keep this one last to work around a gdbserver <= 7.10 bug in
4751  the qSupported:xmlRegisters=i386 handling. */
4752  if (remote_support_xml != NULL
4755 
4756  q = reconcat (q, "qSupported:", q, (char *) NULL);
4757  putpkt (q);
4758 
4759  do_cleanups (old_chain);
4760 
4761  getpkt (&rs->buf, &rs->buf_size, 0);
4762 
4763  /* If an error occured, warn, but do not return - just reset the
4764  buffer to empty and go on to disable features. */
4766  == PACKET_ERROR)
4767  {
4768  warning (_("Remote failure reply: %s"), rs->buf);
4769  rs->buf[0] = 0;
4770  }
4771  }
4772 
4773  memset (seen, 0, sizeof (seen));
4774 
4775  next = rs->buf;
4776  while (*next)
4777  {
4778  enum packet_support is_supported;
4779  char *p, *end, *name_end, *value;
4780 
4781  /* First separate out this item from the rest of the packet. If
4782  there's another item after this, we overwrite the separator
4783  (terminated strings are much easier to work with). */
4784  p = next;
4785  end = strchr (p, ';');
4786  if (end == NULL)
4787  {
4788  end = p + strlen (p);
4789  next = end;
4790  }
4791  else
4792  {
4793  *end = '\0';
4794  next = end + 1;
4795 
4796  if (end == p)
4797  {
4798  warning (_("empty item in \"qSupported\" response"));
4799  continue;
4800  }
4801  }
4802 
4803  name_end = strchr (p, '=');
4804  if (name_end)
4805  {
4806  /* This is a name=value entry. */
4807  is_supported = PACKET_ENABLE;
4808  value = name_end + 1;
4809  *name_end = '\0';
4810  }
4811  else
4812  {
4813  value = NULL;
4814  switch (end[-1])
4815  {
4816  case '+':
4817  is_supported = PACKET_ENABLE;
4818  break;
4819 
4820  case '-':
4821  is_supported = PACKET_DISABLE;
4822  break;
4823 
4824  case '?':
4825  is_supported = PACKET_SUPPORT_UNKNOWN;
4826  break;
4827 
4828  default:
4829  warning (_("unrecognized item \"%s\" "
4830  "in \"qSupported\" response"), p);
4831  continue;
4832  }
4833  end[-1] = '\0';
4834  }
4835 
4836  for (i = 0; i < ARRAY_SIZE (remote_protocol_features); i++)
4837  if (strcmp (remote_protocol_features[i].name, p) == 0)
4838  {
4839  const struct protocol_feature *feature;
4840 
4841  seen[i] = 1;
4842  feature = &remote_protocol_features[i];
4843  feature->func (feature, is_supported, value);
4844  break;
4845  }
4846  }
4847 
4848  /* If we increased the packet size, make sure to increase the global
4849  buffer size also. We delay this until after parsing the entire
4850  qSupported packet, because this is the same buffer we were
4851  parsing. */
4852  if (rs->buf_size < rs->explicit_packet_size)
4853  {
4854  rs->buf_size = rs->explicit_packet_size;
4855  rs->buf = (char *) xrealloc (rs->buf, rs->buf_size);
4856  }
4857 
4858  /* Handle the defaults for unmentioned features. */
4859  for (i = 0; i < ARRAY_SIZE (remote_protocol_features); i++)
4860  if (!seen[i])
4861  {
4862  const struct protocol_feature *feature;
4863 
4864  feature = &remote_protocol_features[i];
4865  feature->func (feature, feature->default_support, NULL);
4866  }
4867 }
4868 
4869 /* Serial QUIT handler for the remote serial descriptor.
4870 
4871  Defers handling a Ctrl-C until we're done with the current
4872  command/response packet sequence, unless:
4873 
4874  - We're setting up the connection. Don't send a remote interrupt
4875  request, as we're not fully synced yet. Quit immediately
4876  instead.
4877 
4878  - The target has been resumed in the foreground
4879  (target_terminal::is_ours is false) with a synchronous resume
4880  packet, and we're blocked waiting for the stop reply, thus a
4881  Ctrl-C should be immediately sent to the target.
4882 
4883  - We get a second Ctrl-C while still within the same serial read or
4884  write. In that case the serial is seemingly wedged --- offer to
4885  quit/disconnect.
4886 
4887  - We see a second Ctrl-C without target response, after having
4888  previously interrupted the target. In that case the target/stub
4889  is probably wedged --- offer to quit/disconnect.
4890 */
4891 
4892 static void
4894 {
4895  struct remote_state *rs = get_remote_state ();
4896 
4897  if (check_quit_flag ())
4898  {
4899  /* If we're starting up, we're not fully synced yet. Quit
4900  immediately. */
4901  if (rs->starting_up)
4902  quit ();
4903  else if (rs->got_ctrlc_during_io)
4904  {
4905  if (query (_("The target is not responding to GDB commands.\n"
4906  "Stop debugging it? ")))
4908  }
4909  /* If ^C has already been sent once, offer to disconnect. */
4910  else if (!target_terminal::is_ours () && rs->ctrlc_pending_p)
4911  interrupt_query ();
4912  /* All-stop protocol, and blocked waiting for stop reply. Send
4913  an interrupt request. */
4916  else
4917  rs->got_ctrlc_during_io = 1;
4918  }
4919 }
4920 
4921 /* Remove any of the remote.c targets from target stack. Upper targets depend
4922  on it so remove them first. */
4923 
4924 static void
4926 {
4928 }
4929 
4930 static void
4932 {
4934  throw_error (TARGET_CLOSE_ERROR, _("Disconnected from target."));
4935 }
4936 
4937 static void
4938 remote_open_1 (const char *name, int from_tty,
4939  struct target_ops *target, int extended_p)
4940 {
4941  struct remote_state *rs = get_remote_state ();
4942 
4943  if (name == 0)
4944  error (_("To open a remote debug connection, you need to specify what\n"
4945  "serial device is attached to the remote system\n"
4946  "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4947 
4948  /* See FIXME above. */
4951 
4952  /* If we're connected to a running target, target_preopen will kill it.
4953  Ask this question first, before target_preopen has a chance to kill
4954  anything. */
4955  if (rs->remote_desc != NULL && !have_inferiors ())
4956  {
4957  if (from_tty
4958  && !query (_("Already connected to a remote target. Disconnect? ")))
4959  error (_("Still connected."));
4960  }
4961 
4962  /* Here the possibly existing remote target gets unpushed. */
4963  target_preopen (from_tty);
4964 
4965  /* Make sure we send the passed signals list the next time we resume. */
4966  xfree (rs->last_pass_packet);
4967  rs->last_pass_packet = NULL;
4968 
4969  /* Make sure we send the program signals list the next time we
4970  resume. */
4972  rs->last_program_signals_packet = NULL;
4973 
4975  reopen_exec_file ();
4976  reread_symbols ();
4977 
4979  if (!rs->remote_desc)
4981 
4982  if (baud_rate != -1)
4983  {
4985  {
4986  /* The requested speed could not be set. Error out to
4987  top level after closing remote_desc. Take care to
4988  set remote_desc to NULL to avoid closing remote_desc
4989  more than once. */
4990  serial_close (rs->remote_desc);
4991  rs->remote_desc = NULL;
4993  }
4994  }
4995 
4997  serial_raw (rs->remote_desc);
4998 
4999  /* If there is something sitting in the buffer we might take it as a
5000  response to a command, which would be bad. */
5002 
5003  if (from_tty)
5004  {
5005  puts_filtered ("Remote debugging using ");
5006  puts_filtered (name);
5007  puts_filtered ("\n");
5008  }
5009  push_target (target); /* Switch to using remote target now. */
5010 
5011  /* Register extra event sources in the event loop. */
5014  NULL);
5016 
5017  /* Reset the target state; these things will be queried either by
5018  remote_query_supported or as they are needed. */
5020  rs->cached_wait_status = 0;
5021  rs->explicit_packet_size = 0;
5022  rs->noack_mode = 0;
5023  rs->extended = extended_p;
5024  rs->waiting_for_stop_reply = 0;
5025  rs->ctrlc_pending_p = 0;
5026  rs->got_ctrlc_during_io = 0;
5027 
5030  rs->remote_traceframe_number = -1;
5031 
5033 
5034  /* Probe for ability to use "ThreadInfo" query, as required. */
5035  rs->use_threadinfo_query = 1;
5036  rs->use_threadextra_query = 1;
5037 
5039 
5041  {
5042  /* FIXME: cagney/1999-09-23: During the initial connection it is
5043  assumed that the target is already ready and able to respond to
5044  requests. Unfortunately remote_start_remote() eventually calls
5045  wait_for_inferior() with no timeout. wait_forever_enabled_p gets
5046  around this. Eventually a mechanism that allows
5047  wait_for_inferior() to expect/get timeouts will be
5048  implemented. */
5050  }
5051 
5052  /* First delete any symbols previously loaded from shared libraries. */
5053  no_shared_libraries (NULL, 0);
5054 
5055  /* Start afresh. */
5056  init_thread_list ();
5057 
5058  /* Start the remote connection. If error() or QUIT, discard this
5059  target (we'd otherwise be in an inconsistent state) and then
5060  propogate the error on up the exception chain. This ensures that
5061  the caller doesn't stumble along blindly assuming that the
5062  function succeeded. The CLI doesn't have this problem but other
5063  UI's, such as MI do.
5064 
5065  FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
5066  this function should return an error indication letting the
5067  caller restore the previous state. Unfortunately the command
5068  ``target remote'' is directly wired to this function making that
5069  impossible. On a positive note, the CLI side of this problem has
5070  been fixed - the function set_cmd_context() makes it possible for
5071  all the ``target ....'' commands to share a common callback
5072  function. See cli-dump.c. */
5073  {
5074 
5075  TRY
5076  {
5077  remote_start_remote (from_tty, target, extended_p);
5078  }
5079  CATCH (ex, RETURN_MASK_ALL)
5080  {
5081  /* Pop the partially set up target - unless something else did
5082  already before throwing the exception. */
5083  if (rs->remote_desc != NULL)
5087  throw_exception (ex);
5088  }
5089  END_CATCH
5090  }
5091 
5093 
5096 }
5097 
5098 /* Detach the specified process. */
5099 
5100 static void
5102 {
5103  struct remote_state *rs = get_remote_state ();
5104 
5105  if (remote_multi_process_p (rs))
5106  xsnprintf (rs->buf, get_remote_packet_size (), "D;%x", pid);
5107  else
5108  strcpy (rs->buf, "D");
5109 
5110  putpkt (rs->buf);
5111  getpkt (&rs->buf, &rs->buf_size, 0);
5112 
5113  if (rs->buf[0] == 'O' && rs->buf[1] == 'K')
5114  ;
5115  else if (rs->buf[0] == '\0')
5116  error (_("Remote doesn't know how to detach"));
5117  else
5118  error (_("Can't detach process."));
5119 }
5120 
5121 /* This detaches a program to which we previously attached, using
5122  inferior_ptid to identify the process. After this is done, GDB
5123  can be used to debug some other program. We better not have left
5124  any breakpoints in the target program or it'll die when it hits
5125  one. */
5126 
5127 static void
5128 remote_detach_1 (const char *args, int from_tty)
5129 {
5130  int pid = ptid_get_pid (inferior_ptid);
5131  struct remote_state *rs = get_remote_state ();
5133  int is_fork_parent;
5134 
5135  if (args)
5136  error (_("Argument given to \"detach\" when remotely debugging."));
5137 
5138  if (!target_has_execution)
5139  error (_("No process to detach from."));
5140 
5141  target_announce_detach (from_tty);
5142 
5143  /* Tell the remote target to detach. */
5145 
5146  /* Exit only if this is the only active inferior. */
5147  if (from_tty && !rs->extended && number_of_live_inferiors () == 1)
5148  puts_filtered (_("Ending remote debugging.\n"));
5149 
5150  /* Check to see if we are detaching a fork parent. Note that if we
5151  are detaching a fork child, tp == NULL. */
5152  is_fork_parent = (tp != NULL
5154 
5155  /* If doing detach-on-fork, we don't mourn, because that will delete
5156  breakpoints that should be available for the followed inferior. */
5157  if (!is_fork_parent)
5159  else
5160  {
5162  detach_inferior (pid);
5163  }
5164 }
5165 
5166 static void
5167 remote_detach (struct target_ops *ops, const char *args, int from_tty)
5168 {
5169  remote_detach_1 (args, from_tty);
5170 }
5171 
5172 static void
5173 extended_remote_detach (struct target_ops *ops, const char *args, int from_tty)
5174 {
5175  remote_detach_1 (args, from_tty);
5176 }
5177 
5178 /* Target follow-fork function for remote targets. On entry, and
5179  at return, the current inferior is the fork parent.
5180 
5181  Note that although this is currently only used for extended-remote,
5182  it is named remote_follow_fork in anticipation of using it for the
5183  remote target as well. */
5184 
5185 static int
5186 remote_follow_fork (struct target_ops *ops, int follow_child,
5187  int detach_fork)
5188 {
5189  struct remote_state *rs = get_remote_state ();
5191 
5192  if ((kind == TARGET_WAITKIND_FORKED && remote_fork_event_p (rs))
5193  || (kind == TARGET_WAITKIND_VFORKED && remote_vfork_event_p (rs)))
5194  {
5195  /* When following the parent and detaching the child, we detach
5196  the child here. For the case of following the child and
5197  detaching the parent, the detach is done in the target-
5198  independent follow fork code in infrun.c. We can't use
5199  target_detach when detaching an unfollowed child because
5200  the client side doesn't know anything about the child. */
5201  if (detach_fork && !follow_child)
5202  {
5203  /* Detach the fork child. */
5204  ptid_t child_ptid;
5205  pid_t child_pid;
5206 
5208  child_pid = ptid_get_pid (child_ptid);
5209 
5210  remote_detach_pid (child_pid);
5211  detach_inferior (child_pid);
5212  }
5213  }
5214  return 0;
5215 }
5216 
5217 /* Target follow-exec function for remote targets. Save EXECD_PATHNAME
5218  in the program space of the new inferior. On entry and at return the
5219  current inferior is the exec'ing inferior. INF is the new exec'd
5220  inferior, which may be the same as the exec'ing inferior unless
5221  follow-exec-mode is "new". */
5222 
5223 static void
5225  struct inferior *inf, char *execd_pathname)
5226 {
5227  /* We know that this is a target file name, so if it has the "target:"
5228  prefix we strip it off before saving it in the program space. */
5229  if (is_target_filename (execd_pathname))
5230  execd_pathname += strlen (TARGET_SYSROOT_PREFIX);
5231 
5232  set_pspace_remote_exec_file (inf->pspace, execd_pathname);
5233 }
5234 
5235 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
5236 
5237 static void
5238 remote_disconnect (struct target_ops *target, const char *args, int from_tty)
5239 {
5240  if (args)
5241  error (_("Argument given to \"disconnect\" when remotely debugging."));
5242 
5243  /* Make sure we unpush even the extended remote targets. Calling
5244  target_mourn_inferior won't unpush, and remote_mourn won't
5245  unpush if there is more than one inferior left. */
5246  unpush_target (target);
5248 
5249  if (from_tty)
5250  puts_filtered ("Ending remote debugging.\n");
5251 }
5252 
5253 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
5254  be chatty about it. */
5255 
5256 static void
5257 extended_remote_attach (struct target_ops *target, const char *args,
5258  int from_tty)
5259 {
5260  struct remote_state *rs = get_remote_state ();
5261  int pid;
5262  char *wait_status = NULL;
5263 
5264  pid = parse_pid_to_attach (args);
5265 
5266  /* Remote PID can be freely equal to getpid, do not check it here the same
5267  way as in other targets. */
5268 
5270  error (_("This target does not support attaching to a process"));
5271 
5272  if (from_tty)
5273  {
5274  char *exec_file = get_exec_file (0);
5275 
5276  if (exec_file)
5277  printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
5279  else
5280  printf_unfiltered (_("Attaching to %s\n"),
5282 
5284  }
5285 
5286  xsnprintf (rs->buf, get_remote_packet_size (), "vAttach;%x", pid);
5287  putpkt (rs->buf);
5288  getpkt (&rs->buf, &rs->buf_size, 0);
5289 
5290  switch (packet_ok (rs->buf,
5292  {
5293  case PACKET_OK:
5294  if (!target_is_non_stop_p ())
5295  {
5296  /* Save the reply for later. */
5297  wait_status = (char *) alloca (strlen (rs->buf) + 1);
5298  strcpy (wait_status, rs->buf);
5299  }
5300  else if (strcmp (rs->buf, "OK") != 0)
5301  error (_("Attaching to %s failed with: %s"),
5303  rs->buf);
5304  break;
5305  case PACKET_UNKNOWN:
5306  error (_("This target does not support attaching to a process"));
5307  default:
5308  error (_("Attaching to %s failed"),
5310  }
5311 
5313 
5315 
5316  if (target_is_non_stop_p ())
5317  {
5318  struct thread_info *thread;
5319 
5320  /* Get list of threads. */
5321  remote_update_thread_list (target);
5322 
5323  thread = first_thread_of_process (pid);
5324  if (thread)
5325  inferior_ptid = thread->ptid;
5326  else
5328 
5329  /* Invalidate our notion of the remote current thread. */
5331  }
5332  else
5333  {
5334  /* Now, if we have thread information, update inferior_ptid. */
5336 
5337  /* Add the main thread to the thread list. */
5339  }
5340 
5341  /* Next, if the target can specify a description, read it. We do
5342  this before anything involving memory or registers. */
5344 
5345  if (!target_is_non_stop_p ())
5346  {
5347  /* Use the previously fetched status. */
5348  gdb_assert (wait_status != NULL);
5349 
5350  if (target_can_async_p ())
5351  {
5352  struct notif_event *reply
5353  = remote_notif_parse (&notif_client_stop, wait_status);
5354 
5355  push_stop_reply ((struct stop_reply *) reply);
5356 
5357  target_async (1);
5358  }
5359  else
5360  {
5361  gdb_assert (wait_status != NULL);
5362  strcpy (rs->buf, wait_status);
5363  rs->cached_wait_status = 1;
5364  }
5365  }
5366  else
5367  gdb_assert (wait_status == NULL);
5368 }
5369 
5370 /* Implementation of the to_post_attach method. */
5371 
5372 static void
5374 {
5375  /* Get text, data & bss offsets. */
5376  get_offsets ();
5377 
5378  /* In certain cases GDB might not have had the chance to start
5379  symbol lookup up until now. This could happen if the debugged
5380  binary is not using shared libraries, the vsyscall page is not
5381  present (on Linux) and the binary itself hadn't changed since the
5382  debugging process was started. */
5383  if (symfile_objfile != NULL)
5385 }
5386 
5387 
5388 /* Check for the availability of vCont. This function should also check
5389  the response. */
5390 
5391 static void
5393 {
5394  char *buf;
5395 
5396  strcpy (rs->buf, "vCont?");
5397  putpkt (rs->buf);
5398  getpkt (&rs->buf, &rs->buf_size, 0);
5399  buf = rs->buf;
5400 
5401  /* Make sure that the features we assume are supported. */
5402  if (startswith (buf, "vCont"))
5403  {
5404  char *p = &buf[5];
5405  int support_c, support_C;
5406 
5407  rs->supports_vCont.s = 0;
5408  rs->supports_vCont.S = 0;
5409  support_c = 0;
5410  support_C = 0;
5411  rs->supports_vCont.t = 0;
5412  rs->supports_vCont.r = 0;
5413  while (p && *p == ';')
5414  {
5415  p++;
5416  if (*p == 's' && (*(p + 1) == ';' || *(p + 1) == 0))
5417  rs->supports_vCont.s = 1;
5418  else if (*p == 'S' && (*(p + 1) == ';' || *(p + 1) == 0))
5419  rs->supports_vCont.S = 1;
5420  else if (*p == 'c' && (*(p + 1) == ';' || *(p + 1) == 0))
5421  support_c = 1;
5422  else if (*p == 'C' && (*(p + 1) == ';' || *(p + 1) == 0))
5423  support_C = 1;
5424  else if (*p == 't' && (*(p + 1) == ';' || *(p + 1) == 0))
5425  rs->supports_vCont.t = 1;
5426  else if (*p == 'r' && (*(p + 1) == ';' || *(p + 1) == 0))
5427  rs->supports_vCont.r = 1;
5428 
5429  p = strchr (p, ';');
5430  }
5431 
5432  /* If c, and C are not all supported, we can't use vCont. Clearing
5433  BUF will make packet_ok disable the packet. */
5434  if (!support_c || !support_C)
5435  buf[0] = 0;
5436  }
5437 
5439 }
5440 
5441 /* Helper function for building "vCont" resumptions. Write a
5442  resumption to P. ENDP points to one-passed-the-end of the buffer
5443  we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
5444  thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
5445  resumed thread should be single-stepped and/or signalled. If PTID
5446  equals minus_one_ptid, then all threads are resumed; if PTID
5447  represents a process, then all threads of the process are resumed;
5448  the thread to be stepped and/or signalled is given in the global
5449  INFERIOR_PTID. */
5450 
5451 static char *
5452 append_resumption (char *p, char *endp,
5453  ptid_t ptid, int step, enum gdb_signal siggnal)
5454 {
5455  struct remote_state *rs = get_remote_state ();
5456 
5457  if (step && siggnal != GDB_SIGNAL_0)
5458  p += xsnprintf (p, endp - p, ";S%02x", siggnal);
5459  else if (step
5460  /* GDB is willing to range step. */
5462  /* Target supports range stepping. */
5463  && rs->supports_vCont.r
5464  /* We don't currently support range stepping multiple
5465  threads with a wildcard (though the protocol allows it,
5466  so stubs shouldn't make an active effort to forbid
5467  it). */
5468  && !(remote_multi_process_p (rs) && ptid_is_pid (ptid)))
5469  {
5470  struct thread_info *tp;
5471 
5473  {
5474  /* If we don't know about the target thread's tid, then
5475  we're resuming magic_null_ptid (see caller). */
5477  }
5478  else
5479  tp = find_thread_ptid (ptid);
5480  gdb_assert (tp != NULL);
5481 
5482  if (tp->control.may_range_step)
5483  {
5484  int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
5485 
5486  p += xsnprintf (p, endp - p, ";r%s,%s",
5488  addr_size),
5490  addr_size));
5491  }
5492  else
5493  p += xsnprintf (p, endp - p, ";s");
5494  }
5495  else if (step)
5496  p += xsnprintf (p, endp - p, ";s");
5497  else if (siggnal != GDB_SIGNAL_0)
5498  p += xsnprintf (p, endp - p, ";C%02x", siggnal);
5499  else
5500  p += xsnprintf (p, endp - p, ";c");
5501 
5502  if (remote_multi_process_p (rs) && ptid_is_pid (ptid))
5503  {
5504  ptid_t nptid;
5505 
5506  /* All (-1) threads of process. */
5507  nptid = ptid_build (ptid_get_pid (ptid), -1, 0);
5508 
5509  p += xsnprintf (p, endp - p, ":");
5510  p = write_ptid (p, endp, nptid);
5511  }
5512  else if (!ptid_equal (ptid, minus_one_ptid))
5513  {
5514  p += xsnprintf (p, endp - p, ":");
5515  p = write_ptid (p, endp, ptid);
5516  }
5517 
5518  return p;
5519 }
5520 
5521 /* Clear the thread's private info on resume. */
5522 
5523 static void
5525 {
5526  if (thread->priv != NULL)
5527  {
5529 
5530  priv->stop_reason = TARGET_STOPPED_BY_NO_REASON;
5531  priv->watch_data_address = 0;
5532  }
5533 }
5534 
5535 /* Append a vCont continue-with-signal action for threads that have a
5536  non-zero stop signal. */
5537 
5538 static char *
5540 {
5541  struct thread_info *thread;
5542 
5543  ALL_NON_EXITED_THREADS (thread)
5544  if (ptid_match (thread->ptid, ptid)
5545  && !ptid_equal (inferior_ptid, thread->ptid)
5546  && thread->suspend.stop_signal != GDB_SIGNAL_0)
5547  {
5548  p = append_resumption (p, endp, thread->ptid,
5549  0, thread->suspend.stop_signal);
5550  thread->suspend.stop_signal = GDB_SIGNAL_0;
5552  }
5553 
5554  return p;
5555 }
5556 
5557 /* Set the target running, using the packets that use Hc
5558  (c/s/C/S). */
5559 
5560 static void
5562  ptid_t ptid, int step, enum gdb_signal siggnal)
5563 {
5564  struct remote_state *rs = get_remote_state ();
5565  struct thread_info *thread;
5566  char *buf;
5567 
5568  rs->last_sent_signal = siggnal;
5569  rs->last_sent_step = step;
5570 
5571  /* The c/s/C/S resume packets use Hc, so set the continue
5572  thread. */
5575  else
5577 
5578  ALL_NON_EXITED_THREADS (thread)
5580 
5581  buf = rs->buf;
5583  {
5584  /* We don't pass signals to the target in reverse exec mode. */
5585  if (info_verbose && siggnal != GDB_SIGNAL_0)
5586  warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5587  siggnal);
5588 
5589  if (step && packet_support (PACKET_bs) == PACKET_DISABLE)
5590  error (_("Remote reverse-step not supported."));
5591  if (!step && packet_support (PACKET_bc) == PACKET_DISABLE)
5592  error (_("Remote reverse-continue not supported."));
5593 
5594  strcpy (buf, step ? "bs" : "bc");
5595  }
5596  else if (siggnal != GDB_SIGNAL_0)
5597  {
5598  buf[0] = step ? 'S' : 'C';
5599  buf[1] = tohex (((int) siggnal >> 4) & 0xf);
5600  buf[2] = tohex (((int) siggnal) & 0xf);
5601  buf[3] = '\0';
5602  }
5603  else
5604  strcpy (buf, step ? "s" : "c");
5605 
5606  putpkt (buf);
5607 }
5608 
5609 /* Resume the remote inferior by using a "vCont" packet. The thread
5610  to be resumed is PTID; STEP and SIGGNAL indicate whether the
5611  resumed thread should be single-stepped and/or signalled. If PTID
5612  equals minus_one_ptid, then all threads are resumed; the thread to
5613  be stepped and/or signalled is given in the global INFERIOR_PTID.
5614  This function returns non-zero iff it resumes the inferior.
5615 
5616  This function issues a strict subset of all possible vCont commands
5617  at the moment. */
5618 
5619 static int
5620 remote_resume_with_vcont (ptid_t ptid, int step, enum gdb_signal siggnal)
5621 {
5622  struct remote_state *rs = get_remote_state ();
5623  char *p;
5624  char *endp;
5625 
5626  /* No reverse execution actions defined for vCont. */
5628  return 0;
5629 
5631  remote_vcont_probe (rs);
5632 
5634  return 0;
5635 
5636  p = rs->buf;
5637  endp = rs->buf + get_remote_packet_size ();
5638 
5639  /* If we could generate a wider range of packets, we'd have to worry
5640  about overflowing BUF. Should there be a generic
5641  "multi-part-packet" packet? */
5642 
5643  p += xsnprintf (p, endp - p, "vCont");
5644 
5645  if (ptid_equal (ptid, magic_null_ptid))
5646  {
5647  /* MAGIC_NULL_PTID means that we don't have any active threads,
5648  so we don't have any TID numbers the inferior will
5649  understand. Make sure to only send forms that do not specify
5650  a TID. */
5651  append_resumption (p, endp, minus_one_ptid, step, siggnal);
5652  }
5653  else if (ptid_equal (ptid, minus_one_ptid) || ptid_is_pid (ptid))
5654  {
5655  /* Resume all threads (of all processes, or of a single
5656  process), with preference for INFERIOR_PTID. This assumes
5657  inferior_ptid belongs to the set of all threads we are about
5658  to resume. */
5659  if (step || siggnal != GDB_SIGNAL_0)
5660  {
5661  /* Step inferior_ptid, with or without signal. */
5662  p = append_resumption (p, endp, inferior_ptid, step, siggnal);
5663  }
5664 
5665  /* Also pass down any pending signaled resumption for other
5666  threads not the current. */
5667  p = append_pending_thread_resumptions (p, endp, ptid);
5668 
5669  /* And continue others without a signal. */
5670  append_resumption (p, endp, ptid, /*step=*/ 0, GDB_SIGNAL_0);
5671  }
5672  else
5673  {
5674  /* Scheduler locking; resume only PTID. */
5675  append_resumption (p, endp, ptid, step, siggnal);
5676  }
5677 
5678  gdb_assert (strlen (rs->buf) < get_remote_packet_size ());
5679  putpkt (rs->buf);
5680 
5681  if (target_is_non_stop_p ())
5682  {
5683  /* In non-stop, the stub replies to vCont with "OK". The stop
5684  reply will be reported asynchronously by means of a `%Stop'
5685  notification. */
5686  getpkt (&rs->buf, &rs->buf_size, 0);
5687  if (strcmp (rs->buf, "OK") != 0)
5688  error (_("Unexpected vCont reply in non-stop mode: %s"), rs->buf);
5689  }
5690 
5691  return 1;
5692 }
5693 
5694 /* Tell the remote machine to resume. */
5695 
5696 static void
5698  ptid_t ptid, int step, enum gdb_signal siggnal)
5699 {
5700  struct remote_state *rs = get_remote_state ();
5701 
5702  /* When connected in non-stop mode, the core resumes threads
5703  individually. Resuming remote threads directly in target_resume
5704  would thus result in sending one packet per thread. Instead, to
5705  minimize roundtrip latency, here we just store the resume
5706  request; the actual remote resumption will be done in
5707  target_commit_resume / remote_commit_resume, where we'll be able
5708  to do vCont action coalescing. */
5710  {
5711  remote_thread_info *remote_thr;
5712 
5713  if (ptid_equal (minus_one_ptid, ptid) || ptid_is_pid (ptid))
5714  remote_thr = get_remote_thread_info (inferior_ptid);
5715  else
5716  remote_thr = get_remote_thread_info (ptid);
5717 
5718  remote_thr->last_resume_step = step;
5719  remote_thr->last_resume_sig = siggnal;
5720  return;
5721  }
5722 
5723  /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5724  (explained in remote-notif.c:handle_notification) so
5725  remote_notif_process is not called. We need find a place where
5726  it is safe to start a 'vNotif' sequence. It is good to do it
5727  before resuming inferior, because inferior was stopped and no RSP
5728  traffic at that moment. */
5729  if (!target_is_non_stop_p ())
5731 
5733 
5734  /* Prefer vCont, and fallback to s/c/S/C, which use Hc. */
5735  if (!remote_resume_with_vcont (ptid, step, siggnal))
5736  remote_resume_with_hc (ops, ptid, step, siggnal);
5737 
5738  /* We are about to start executing the inferior, let's register it
5739  with the event loop. NOTE: this is the one place where all the
5740  execution commands end up. We could alternatively do this in each
5741  of the execution commands in infcmd.c. */
5742  /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5743  into infcmd.c in order to allow inferior function calls to work
5744  NOT asynchronously. */
5745  if (target_can_async_p ())
5746  target_async (1);
5747 
5748  /* We've just told the target to resume. The remote server will
5749  wait for the inferior to stop, and then send a stop reply. In
5750  the mean time, we can't start another command/query ourselves
5751  because the stub wouldn't be ready to process it. This applies
5752  only to the base all-stop protocol, however. In non-stop (which
5753  only supports vCont), the stub replies with an "OK", and is
5754  immediate able to process further serial input. */
5755  if (!target_is_non_stop_p ())
5756  rs->waiting_for_stop_reply = 1;
5757 }
5758 
5760  (int *may_global_wildcard_vcont);
5761 static int is_pending_fork_parent_thread (struct thread_info *thread);
5762 
5763 /* Private per-inferior info for target remote processes. */
5764 
5766 {
5767  /* Whether we can send a wildcard vCont for this process. */
5768  bool may_wildcard_vcont = true;
5769 };
5770 
5771 /* Get the remote private inferior data associated to INF. */
5772 
5773 static remote_inferior *
5775 {
5776  if (inf->priv == NULL)
5777  inf->priv.reset (new remote_inferior);
5778 
5779  return static_cast<remote_inferior *> (inf->priv.get ());
5780 }
5781 
5782 /* Structure used to track the construction of a vCont packet in the
5783  outgoing packet buffer. This is used to send multiple vCont
5784  packets if we have more actions than would fit a single packet. */
5785 
5787 {
5788  /* Pointer to the first action. P points here if no action has been
5789  appended yet. */
5791 
5792  /* Where the next action will be appended. */
5793  char *p;
5794 
5795  /* The end of the buffer. Must never write past this. */
5796  char *endp;
5797 };
5798 
5799 /* Prepare the outgoing buffer for a new vCont packet. */
5800 
5801 static void
5803 {
5804  struct remote_state *rs = get_remote_state ();
5805 
5806  builder->p = rs->buf;
5807  builder->endp = rs->buf + get_remote_packet_size ();
5808  builder->p += xsnprintf (builder->p, builder->endp - builder->p, "vCont");
5809  builder->first_action = builder->p;
5810 }
5811 
5812 /* If the vCont packet being built has any action, send it to the
5813  remote end. */
5814 
5815 static void
5817 {
5818  struct remote_state *rs;
5819 
5820  if (builder->p == builder->first_action)
5821  return;
5822 
5823  rs = get_remote_state ();
5824  putpkt (rs->buf);
5825  getpkt (&rs->buf, &rs->buf_size, 0);
5826  if (strcmp (rs->buf, "OK") != 0)
5827  error (_("Unexpected vCont reply in non-stop mode: %s"), rs->buf);
5828 }
5829 
5830 /* The largest action is range-stepping, with its two addresses. This
5831  is more than sufficient. If a new, bigger action is created, it'll
5832  quickly trigger a failed assertion in append_resumption (and we'll
5833  just bump this). */
5834 #define MAX_ACTION_SIZE 200
5835 
5836 /* Append a new vCont action in the outgoing packet being built. If
5837  the action doesn't fit the packet along with previous actions, push
5838  what we've got so far to the remote end and start over a new vCont
5839  packet (with the new action). */
5840 
5841 static void
5843  ptid_t ptid, int step, enum gdb_signal siggnal)
5844 {
5845  char buf[MAX_ACTION_SIZE + 1];
5846  char *endp;
5847  size_t rsize;
5848 
5849  endp = append_resumption (buf, buf + sizeof (buf),
5850  ptid, step, siggnal);
5851 
5852  /* Check whether this new action would fit in the vCont packet along
5853  with previous actions. If not, send what we've got so far and
5854  start a new vCont packet. */
5855  rsize = endp - buf;
5856  if (rsize > builder->endp - builder->p)
5857  {
5858  vcont_builder_flush (builder);
5859  vcont_builder_restart (builder);
5860 
5861  /* Should now fit. */
5862  gdb_assert (rsize <= builder->endp - builder->p);
5863  }
5864 
5865  memcpy (builder->p, buf, rsize);
5866  builder->p += rsize;
5867  *builder->p = '\0';
5868 }
5869 
5870 /* to_commit_resume implementation. */
5871 
5872 static void
5874 {
5875  struct inferior *inf;
5876  struct thread_info *tp;
5877  int any_process_wildcard;
5878  int may_global_wildcard_vcont;
5880 
5881  /* If connected in all-stop mode, we'd send the remote resume
5882  request directly from remote_resume. Likewise if
5883  reverse-debugging, as there are no defined vCont actions for
5884  reverse execution. */
5886  return;
5887 
5888  /* Try to send wildcard actions ("vCont;c" or "vCont;c:pPID.-1")
5889  instead of resuming all threads of each process individually.
5890  However, if any thread of a process must remain halted, we can't
5891  send wildcard resumes and must send one action per thread.
5892 
5893  Care must be taken to not resume threads/processes the server
5894  side already told us are stopped, but the core doesn't know about
5895  yet, because the events are still in the vStopped notification
5896  queue. For example:
5897 
5898  #1 => vCont s:p1.1;c
5899  #2 <= OK
5900  #3 <= %Stopped T05 p1.1
5901  #4 => vStopped
5902  #5 <= T05 p1.2
5903  #6 => vStopped
5904  #7 <= OK
5905  #8 (infrun handles the stop for p1.1 and continues stepping)
5906  #9 => vCont s:p1.1;c
5907 
5908  The last vCont above would resume thread p1.2 by mistake, because
5909  the server has no idea that the event for p1.2 had not been
5910  handled yet.
5911 
5912  The server side must similarly ignore resume actions for the
5913  thread that has a pending %Stopped notification (and any other
5914  threads with events pending), until GDB acks the notification
5915  with vStopped. Otherwise, e.g., the following case is
5916  mishandled:
5917 
5918  #1 => g (or any other packet)
5919  #2 <= [registers]
5920  #3 <= %Stopped T05 p1.2
5921  #4 => vCont s:p1.1;c
5922  #5 <= OK
5923 
5924  Above, the server must not resume thread p1.2. GDB can't know
5925  that p1.2 stopped until it acks the %Stopped notification, and
5926  since from GDB's perspective all threads should be running, it
5927  sends a "c" action.
5928 
5929  Finally, special care must also be given to handling fork/vfork
5930  events. A (v)fork event actually tells us that two processes
5931  stopped -- the parent and the child. Until we follow the fork,
5932  we must not resume the child. Therefore, if we have a pending
5933  fork follow, we must not send a global wildcard resume action
5934  (vCont;c). We can still send process-wide wildcards though. */
5935 
5936  /* Start by assuming a global wildcard (vCont;c) is possible. */
5937  may_global_wildcard_vcont = 1;
5938 
5939  /* And assume every process is individually wildcard-able too. */
5941  {
5943 
5944  priv->may_wildcard_vcont = true;
5945  }
5946 
5947  /* Check for any pending events (not reported or processed yet) and
5948  disable process and global wildcard resumes appropriately. */
5949  check_pending_events_prevent_wildcard_vcont (&may_global_wildcard_vcont);
5950 
5952  {
5953  /* If a thread of a process is not meant to be resumed, then we
5954  can't wildcard that process. */
5955  if (!tp->executing)
5956  {
5958 
5959  /* And if we can't wildcard a process, we can't wildcard
5960  everything either. */
5961  may_global_wildcard_vcont = 0;
5962  continue;
5963  }
5964 
5965  /* If a thread is the parent of an unfollowed fork, then we
5966  can't do a global wildcard, as that would resume the fork
5967  child. */
5969  may_global_wildcard_vcont = 0;
5970  }
5971 
5972  /* Now let's build the vCont packet(s). Actions must be appended
5973  from narrower to wider scopes (thread -> process -> global). If
5974  we end up with too many actions for a single packet vcont_builder
5975  flushes the current vCont packet to the remote side and starts a
5976  new one. */
5978 
5979  /* Threads first. */
5981  {
5982  remote_thread_info *remote_thr = get_remote_thread_info (tp);
5983 
5984  if (!tp->executing || remote_thr->vcont_resumed)
5985  continue;
5986 
5988 
5989  if (!remote_thr->last_resume_step
5990  && remote_thr->last_resume_sig == GDB_SIGNAL_0
5992  {
5993  /* We'll send a wildcard resume instead. */
5994  remote_thr->vcont_resumed = 1;
5995  continue;
5996  }
5997 
5999  remote_thr->last_resume_step,
6000  remote_thr->last_resume_sig);
6001  remote_thr->vcont_resumed = 1;
6002  }
6003 
6004  /* Now check whether we can send any process-wide wildcard. This is
6005  to avoid sending a global wildcard in the case nothing is
6006  supposed to be resumed. */
6007  any_process_wildcard = 0;
6008 
6010  {
6011  if (get_remote_inferior (inf)->may_wildcard_vcont)
6012  {
6013  any_process_wildcard = 1;
6014  break;
6015  }
6016  }
6017 
6018  if (any_process_wildcard)
6019  {
6020  /* If all processes are wildcard-able, then send a single "c"
6021  action, otherwise, send an "all (-1) threads of process"
6022  continue action for each running process, if any. */
6023  if (may_global_wildcard_vcont)
6024  {
6026  0, GDB_SIGNAL_0);
6027  }
6028  else
6029  {
6031  {
6032  if (get_remote_inferior (inf)->may_wildcard_vcont)
6033  {
6035  pid_to_ptid (inf->pid),
6036  0, GDB_SIGNAL_0);
6037  }
6038  }
6039  }
6040  }
6041 
6043 }
6044 
6045 
6046 
6047 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
6048  thread, all threads of a remote process, or all threads of all
6049  processes. */
6050 
6051 static void
6053 {
6054  struct remote_state *rs = get_remote_state ();
6055  char *p = rs->buf;
6056  char *endp = rs->buf + get_remote_packet_size ();
6057 
6059  remote_vcont_probe (rs);
6060 
6061  if (!rs->supports_vCont.t)
6062  error (_("Remote server does not support stopping threads"));
6063 
6064  if (ptid_equal (ptid, minus_one_ptid)
6065  || (!remote_multi_process_p (rs) && ptid_is_pid (ptid)))
6066  p += xsnprintf (p, endp - p, "vCont;t");
6067  else
6068  {
6069  ptid_t nptid;
6070 
6071  p += xsnprintf (p, endp - p, "vCont;t:");
6072 
6073  if (ptid_is_pid (ptid))
6074  /* All (-1) threads of process. */
6075  nptid = ptid_build (ptid_get_pid (ptid), -1, 0);
6076  else
6077  {
6078  /* Small optimization: if we already have a stop reply for
6079  this thread, no use in telling the stub we want this
6080  stopped. */
6081  if (peek_stop_reply (ptid))
6082  return;
6083 
6084  nptid = ptid;
6085  }
6086 
6087  write_ptid (p, endp, nptid);
6088  }
6089 
6090  /* In non-stop, we get an immediate OK reply. The stop reply will
6091  come in asynchronously by notification. */
6092  putpkt (rs->buf);
6093  getpkt (&rs->buf, &rs->buf_size, 0);
6094  if (strcmp (rs->buf, "OK") != 0)
6095  error (_("Stopping %s failed: %s"), target_pid_to_str (ptid), rs->buf);
6096 }
6097 
6098 /* All-stop version of target_interrupt. Sends a break or a ^C to
6099  interrupt the remote target. It is undefined which thread of which
6100  process reports the interrupt. */
6101 
6102 static void
6104 {
6105  struct remote_state *rs = get_remote_state ();
6106 
6107  rs->ctrlc_pending_p = 1;
6108 
6109  /* If the inferior is stopped already, but the core didn't know
6110  about it yet, just ignore the request. The cached wait status
6111  will be collected in remote_wait. */
6112  if (rs->cached_wait_status)
6113  return;
6114 
6115  /* Send interrupt_sequence to remote target. */
6117 }
6118 
6119 /* Non-stop version of target_interrupt. Uses `vCtrlC' to interrupt
6120  the remote target. It is undefined which thread of which process
6121  reports the interrupt. Throws an error if the packet is not
6122  supported by the server. */
6123 
6124 static void
6126 {
6127  struct remote_state *rs = get_remote_state ();
6128  char *p = rs->buf;
6129  char *endp = rs->buf + get_remote_packet_size ();
6130 
6131  xsnprintf (p, endp - p, "vCtrlC");
6132 
6133  /* In non-stop, we get an immediate OK reply. The stop reply will
6134  come in asynchronously by notification. */
6135  putpkt (rs->buf);
6136  getpkt (&rs->buf, &rs->buf_size, 0);
6137 
6139  {
6140  case PACKET_OK:
6141  break;
6142  case PACKET_UNKNOWN:
6143  error (_("No support for interrupting the remote target."));
6144  case PACKET_ERROR:
6145  error (_("Interrupting target failed: %s"), rs->buf);
6146  }
6147 }
6148 
6149 /* Implement the to_stop function for the remote targets. */
6150 
6151 static void
6152 remote_stop (struct target_ops *self, ptid_t ptid)
6153 {
6154  if (remote_debug)
6155  fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
6156 
6157  if (target_is_non_stop_p ())
6158  remote_stop_ns (ptid);
6159  else
6160  {
6161  /* We don't currently have a way to transparently pause the
6162  remote target in all-stop mode. Interrupt it instead. */
6164  }
6165 }
6166 
6167 /* Implement the to_interrupt function for the remote targets. */
6168 
6169 static void
6170 remote_interrupt (struct target_ops *self, ptid_t ptid)
6171 {
6172  if (remote_debug)
6173  fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
6174 
6175  if (target_is_non_stop_p ())
6177  else
6179 }
6180 
6181 /* Implement the to_pass_ctrlc function for the remote targets. */
6182 
6183 static void
6185 {
6186  struct remote_state *rs = get_remote_state ();
6187 
6188  if (remote_debug)
6189  fprintf_unfiltered (gdb_stdlog, "remote_pass_ctrlc called\n");
6190 
6191  /* If we're starting up, we're not fully synced yet. Quit
6192  immediately. */
6193  if (rs->starting_up)
6194  quit ();
6195  /* If ^C has already been sent once, offer to disconnect. */
6196  else if (rs->ctrlc_pending_p)
6197  interrupt_query ();
6198  else
6200 }
6201 
6202 /* Ask the user what to do when an interrupt is received. */
6203 
6204 static void
6206 {
6207  struct remote_state *rs = get_remote_state ();
6208 
6209  if (rs->waiting_for_stop_reply && rs->ctrlc_pending_p)
6210  {
6211  if (query (_("The target is not responding to interrupt requests.\n"
6212  "Stop debugging it? ")))
6213  {
6215  throw_error (TARGET_CLOSE_ERROR, _("Disconnected from target."));
6216  }
6217  }
6218  else
6219  {
6220  if (query (_("Interrupted while waiting for the program.\n"
6221  "Give up waiting? ")))
6222  quit ();
6223  }
6224 }
6225 
6226 /* Enable/disable target terminal ownership. Most targets can use
6227  terminal groups to control terminal ownership. Remote targets are
6228  different in that explicit transfer of ownership to/from GDB/target
6229  is required. */
6230 
6231 static void
6233 {
6234  /* NOTE: At this point we could also register our selves as the
6235  recipient of all input. Any characters typed could then be
6236  passed on down to the target. */
6237 }
6238 
6239 static void
6241 {
6242 }
6243 
6244 static void
6246 {
6247  char *p;
6248 
6249  for (p = msg; p[0] && p[1]; p += 2)
6250  {
6251  char tb[2];
6252  char c = fromhex (p[0]) * 16 + fromhex (p[1]);
6253 
6254  tb[0] = c;
6255  tb[1] = 0;
6257  }
6259 }
6260 
6262 
6263 typedef struct stop_reply
6264 {
6266 
6267  /* The identifier of the thread about this event */
6269 
6270  /* The remote state this event is associated with. When the remote
6271  connection, represented by a remote_state object, is closed,
6272  all the associated stop_reply events should be released. */
6273  struct remote_state *rs;
6274 
6276 
6277  /* The architecture associated with the expedited registers. */
6279 
6280  /* Expedited registers. This makes remote debugging a bit more
6281  efficient for those targets that provide critical registers as
6282  part of their normal status mechanism (as another roundtrip to
6283  fetch them is avoided). */
6285 
6286  enum target_stop_reason stop_reason;
6287 
6288  CORE_ADDR watch_data_address;
6289 
6290  int core;
6291 } *stop_reply_p;
6292 
6295 /* The list of already fetched and acknowledged stop events. This
6296  queue is used for notification Stop, and other notifications
6297  don't need queue for their events, because the notification events
6298  of Stop can't be consumed immediately, so that events should be
6299  queued first, and be consumed by remote_wait_{ns,as} one per
6300  time. Other notifications can consume their events immediately,
6301  so queue is not needed for them. */
6302 static QUEUE (stop_reply_p) *stop_reply_queue;
6303 
6304 static void
6305 stop_reply_xfree (struct stop_reply *r)
6306 {
6307  notif_event_xfree ((struct notif_event *) r);
6308 }
6309 
6310 /* Return the length of the stop reply queue. */
6311 
6312 static int
6314 {
6315  return QUEUE_length (stop_reply_p, stop_reply_queue);
6316 }
6317 
6318 static void
6319 remote_notif_stop_parse (struct notif_client *self, char *buf,
6320  struct notif_event *event)
6321 {
6322  remote_parse_stop_reply (buf, (struct stop_reply *) event);
6323 }
6324 
6325 static void
6326 remote_notif_stop_ack (struct notif_client *self, char *buf,
6327  struct notif_event *event)
6328 {
6329  struct stop_reply *stop_reply = (struct stop_reply *) event;
6330 
6331  /* acknowledge */
6332  putpkt (self->ack_command);
6333 
6335  /* We got an unknown stop reply. */
6336  error (_("Unknown stop reply"));
6337 
6339 }
6340 
6341 static int
6343 {
6344  /* We can't get pending events in remote_notif_process for
6345  notification stop, and we have to do this in remote_wait_ns
6346  instead. If we fetch all queued events from stub, remote stub
6347  may exit and we have no chance to process them back in
6348  remote_wait_ns. */
6350  return 0;
6351 }
6352 
6353 static void
6355 {
6356  struct stop_reply *r = (struct stop_reply *) event;
6357  cached_reg_t *reg;
6358  int ix;
6359 
6360  for (ix = 0;
6361  VEC_iterate (cached_reg_t, r->regcache, ix, reg);
6362  ix++)
6363  xfree (reg->data);
6364 
6365  VEC_free (cached_reg_t, r->regcache);
6366 }
6367 
6368 static struct notif_event *
6370 {
6371  /* We cast to a pointer to the "base class". */
6372  struct notif_event *r = (struct notif_event *) XNEW (struct stop_reply);
6373 
6374  r->dtr = stop_reply_dtr;
6375 
6376  return r;
6377 }
6378 
6379 /* A client of notification Stop. */
6380 
6382 {
6383  "Stop",
6384  "vStopped",
6390 };
6391 
6392 /* A parameter to pass data in and out. */
6393 
6395 {
6396  void *input;
6398 };
6399 
6400 /* Determine if THREAD_PTID is a pending fork parent thread. ARG contains
6401  the pid of the process that owns the threads we want to check, or
6402  -1 if we want to check all threads. */
6403 
6404 static int
6406  ptid_t thread_ptid)
6407 {
6410  {
6411  if (event_pid == -1 || event_pid == ptid_get_pid (thread_ptid))
6412  return 1;
6413  }
6414 
6415  return 0;
6416 }
6417 
6418 /* Return the thread's pending status used to determine whether the
6419  thread is a fork parent stopped at a fork event. */
6420 
6421 static struct target_waitstatus *
6423 {
6424  if (thread->suspend.waitstatus_pending_p)
6425  return &thread->suspend.waitstatus;
6426  else
6427  return &thread->pending_follow;
6428 }
6429 
6430 /* Determine if THREAD is a pending fork parent thread. */
6431 
6432 static int
6434 {
6435  struct target_waitstatus *ws = thread_pending_fork_status (thread);
6436  int pid = -1;
6437 
6438  return is_pending_fork_parent (ws, pid, thread->ptid);
6439 }
6440 
6441 /* Check whether EVENT is a fork event, and if it is, remove the
6442  fork child from the context list passed in DATA. */
6443 
6444 static int
6446  QUEUE_ITER (stop_reply_p) *iter,
6447  stop_reply_p event,
6448  void *data)
6449 {
6450  struct queue_iter_param *param = (struct queue_iter_param *) data;
6451  struct threads_listing_context *context
6452  = (struct threads_listing_context *) param->input;
6453 
6454  if (event->ws.kind == TARGET_WAITKIND_FORKED
6455  || event->ws.kind == TARGET_WAITKIND_VFORKED
6456  || event->ws.kind == TARGET_WAITKIND_THREAD_EXITED)
6457  context->remove_thread (event->ws.value.related_pid);
6458 
6459  return 1;
6460 }
6461 
6462 /* If CONTEXT contains any fork child threads that have not been
6463  reported yet, remove them from the CONTEXT list. If such a
6464  thread exists it is because we are stopped at a fork catchpoint
6465  and have not yet called follow_fork, which will set up the
6466  host-side data structures for the new process. */
6467 
6468 static void
6470 {
6471  struct thread_info * thread;
6472  int pid = -1;
6473  struct notif_client *notif = &notif_client_stop;
6474  struct queue_iter_param param;
6475 
6476  /* For any threads stopped at a fork event, remove the corresponding
6477  fork child threads from the CONTEXT list. */
6478  ALL_NON_EXITED_THREADS (thread)
6479  {
6480  struct target_waitstatus *ws = thread_pending_fork_status (thread);
6481 
6482  if (is_pending_fork_parent (ws, pid, thread->ptid))
6483  context->remove_thread (ws->value.related_pid);
6484  }
6485 
6486  /* Check for any pending fork events (not reported or processed yet)
6487  in process PID and remove those fork child threads from the
6488  CONTEXT list as well. */
6490  param.input = context;
6491  param.output = NULL;
6492  QUEUE_iterate (stop_reply_p, stop_reply_queue,
6494 }
6495 
6496 /* Check whether EVENT would prevent a global or process wildcard
6497  vCont action. */
6498 
6499 static int
6502  QUEUE_ITER (stop_reply_p) *iter,
6503  stop_reply_p event,
6504  void *data)
6505 {
6506  struct inferior *inf;
6507  int *may_global_wildcard_vcont = (int *) data;
6508 
6509  if (event->ws.kind == TARGET_WAITKIND_NO_RESUMED
6510  || event->ws.kind == TARGET_WAITKIND_NO_HISTORY)
6511  return 1;
6512 
6513  if (event->ws.kind == TARGET_WAITKIND_FORKED
6514  || event->ws.kind == TARGET_WAITKIND_VFORKED)
6515  *may_global_wildcard_vcont = 0;
6516 
6517  inf = find_inferior_ptid (event->ptid);
6518 
6519  /* This may be the first time we heard about this process.
6520  Regardless, we must not do a global wildcard resume, otherwise
6521  we'd resume this process too. */
6522  *may_global_wildcard_vcont = 0;
6523  if (inf != NULL)
6525 
6526  return 1;
6527 }
6528 
6529 /* Check whether any event pending in the vStopped queue would prevent
6530  a global or process wildcard vCont action. Clear
6531  *may_global_wildcard if we can't do a global wildcard (vCont;c),
6532  and clear the event inferior's may_wildcard_vcont flag if we can't
6533  do a process-wide wildcard resume (vCont;c:pPID.-1). */
6534 
6535 static void
6537 {
6538  struct notif_client *notif = &notif_client_stop;
6539 
6541  QUEUE_iterate (stop_reply_p, stop_reply_queue,
6543  may_global_wildcard);
6544 }
6545 
6546 /* Remove stop replies in the queue if its pid is equal to the given
6547  inferior's pid. */
6548 
6549 static int
6551  QUEUE_ITER (stop_reply_p) *iter,
6552  stop_reply_p event,
6553  void *data)
6554 {
6555  struct queue_iter_param *param = (struct queue_iter_param *) data;
6556  struct inferior *inf = (struct inferior *) param->input;
6557 
6558  if (ptid_get_pid (event->ptid) == inf->pid)
6559  {
6560  stop_reply_xfree (event);
6561  QUEUE_remove_elem (stop_reply_p, q, iter);
6562  }
6563 
6564  return 1;
6565 }
6566 
6567 /* Discard all pending stop replies of inferior INF. */
6568 
6569 static void
6571 {
6572  struct queue_iter_param param;
6573  struct stop_reply *reply;
6574  struct remote_state *rs = get_remote_state ();
6575  struct remote_notif_state *rns = rs->notif_state;
6576 
6577  /* This function can be notified when an inferior exists. When the
6578  target is not remote, the notification state is NULL. */
6579  if (rs->remote_desc == NULL)
6580  return;
6581 
6582  reply = (struct stop_reply *) rns->pending_event[notif_client_stop.id];
6583 
6584  /* Discard the in-flight notification. */
6585  if (reply != NULL && ptid_get_pid (reply->ptid) == inf->pid)
6586  {
6587  stop_reply_xfree (reply);
6588  rns->pending_event[notif_client_stop.id] = NULL;
6589  }
6590 
6591  param.input = inf;
6592  param.output = NULL;
6593  /* Discard the stop replies we have already pulled with
6594  vStopped. */
6595  QUEUE_iterate (stop_reply_p, stop_reply_queue,
6597 }
6598 
6599 /* If its remote state is equal to the given remote state,
6600  remove EVENT from the stop reply queue. */
6601 
6602 static int
6604  QUEUE_ITER (stop_reply_p) *iter,
6605  stop_reply_p event,
6606  void *data)
6607 {
6608  struct queue_iter_param *param = (struct queue_iter_param *) data;
6609  struct remote_state *rs = (struct remote_state *) param->input;
6610 
6611  if (event->rs == rs)
6612  {
6613  stop_reply_xfree (event);
6614  QUEUE_remove_elem (stop_reply_p, q, iter);
6615  }
6616 
6617  return 1;
6618 }
6619 
6620 /* Discard the stop replies for RS in stop_reply_queue. */
6621 
6622 static void
6624 {
6625  struct queue_iter_param param;
6626 
6627  param.input = rs;
6628  param.output = NULL;
6629  /* Discard the stop replies we have already pulled with
6630  vStopped. */
6631  QUEUE_iterate (stop_reply_p, stop_reply_queue,
6633 }
6634 
6635 /* A parameter to pass data in and out. */
6636 
6637 static int
6639  QUEUE_ITER (stop_reply_p) *iter,
6640  stop_reply_p event,
6641  void *data)
6642 {
6643  struct queue_iter_param *param = (struct queue_iter_param *) data;
6644  ptid_t *ptid = (ptid_t *) param->input;
6645 
6646  if (ptid_match (event->ptid, *ptid))
6647  {
6648  param->output = event;
6649  QUEUE_remove_elem (stop_reply_p, q, iter);
6650  return 0;
6651  }
6652 
6653  return 1;
6654 }
6655 
6656 /* Remove the first reply in 'stop_reply_queue' which matches
6657  PTID. */
6658 
6659 static struct stop_reply *
6661 {
6662  struct queue_iter_param param;
6663 
6664  param.input = &ptid;
6665  param.output = NULL;
6666 
6667  QUEUE_iterate (stop_reply_p, stop_reply_queue,
6669  if (notif_debug)
6671  "notif: discard queued event: 'Stop' in %s\n",
6672  target_pid_to_str (ptid));
6673 
6674  return param.output;
6675 }
6676 
6677 /* Look for a queued stop reply belonging to PTID. If one is found,
6678  remove it from the queue, and return it. Returns NULL if none is
6679  found. If there are still queued events left to process, tell the
6680  event loop to get back to target_wait soon. */
6681 
6682 static struct stop_reply *
6684 {
6686 
6687  if (!QUEUE_is_empty (stop_reply_p, stop_reply_queue))
6688  /* There's still at least an event left. */
6690 
6691  return r;
6692 }
6693 
6694 /* Push a fully parsed stop reply in the stop reply queue. Since we
6695  know that we now have at least one queued event left to pass to the
6696  core side, tell the event loop to get back to target_wait soon. */
6697 
6698 static void
6699 push_stop_reply (struct stop_reply *new_event)
6700 {
6701  QUEUE_enque (stop_reply_p, stop_reply_queue, new_event);
6702 
6703  if (notif_debug)
6705  "notif: push 'Stop' %s to queue %d\n",
6706  target_pid_to_str (new_event->ptid),
6708  stop_reply_queue));
6709 
6711 }
6712 
6713 static int
6715  QUEUE_ITER (stop_reply_p) *iter,
6716  struct stop_reply *event,
6717  void *data)
6718 {
6719  ptid_t *ptid = (ptid_t *) data;
6720 
6721  return !(ptid_equal (*ptid, event->ptid)
6722  && event->ws.kind == TARGET_WAITKIND_STOPPED);
6723 }
6724 
6725 /* Returns true if we have a stop reply for PTID. */
6726 
6727 static int
6729 {
6730  return !QUEUE_iterate (stop_reply_p, stop_reply_queue,
6732 }
6733 
6734 /* Helper for remote_parse_stop_reply. Return nonzero if the substring
6735  starting with P and ending with PEND matches PREFIX. */
6736 
6737 static int
6738 strprefix (const char *p, const char *pend, const char *prefix)
6739 {
6740  for ( ; p < pend; p++, prefix++)
6741  if (*p != *prefix)
6742  return 0;
6743  return *prefix == '\0';
6744 }
6745 
6746 /* Parse the stop reply in BUF. Either the function succeeds, and the
6747  result is stored in EVENT, or throws an error. */
6748 
6749 static void
6750 remote_parse_stop_reply (char *buf, struct stop_reply *event)
6751 {
6752  remote_arch_state *rsa = NULL;
6753  ULONGEST addr;
6754  const char *p;
6755  int skipregs = 0;
6756 
6757  event->ptid = null_ptid;
6758  event->rs = get_remote_state ();
6759  event->ws.kind = TARGET_WAITKIND_IGNORE;
6760  event->ws.value.integer = 0;
6761  event->stop_reason = TARGET_STOPPED_BY_NO_REASON;
6762  event->regcache = NULL;
6763  event->core = -1;
6764 
6765  switch (buf[0])
6766  {
6767  case 'T': /* Status with PC, SP, FP, ... */
6768  /* Expedited reply, containing Signal, {regno, reg} repeat. */
6769  /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
6770  ss = signal number
6771  n... = register number
6772  r... = register contents
6773  */
6774 
6775  p = &buf[3]; /* after Txx */
6776  while (*p)
6777  {
6778  const char *p1;
6779  int fieldsize;
6780 
6781  p1 = strchr (p, ':');
6782  if (p1 == NULL)
6783  error (_("Malformed packet(a) (missing colon): %s\n\
6784 Packet: '%s'\n"),
6785  p, buf);
6786  if (p == p1)
6787  error (_("Malformed packet(a) (missing register number): %s\n\
6788 Packet: '%s'\n"),
6789  p, buf);
6790 
6791  /* Some "registers" are actually extended stop information.
6792  Note if you're adding a new entry here: GDB 7.9 and
6793  earlier assume that all register "numbers" that start
6794  with an hex digit are real register numbers. Make sure
6795  the server only sends such a packet if it knows the
6796  client understands it. */
6797 
6798  if (strprefix (p, p1, "thread"))
6799  event->ptid = read_ptid (++p1, &p);
6800  else if (strprefix (p, p1, "syscall_entry"))
6801  {
6802  ULONGEST sysno;
6803 
6804  event->ws.kind = TARGET_WAITKIND_SYSCALL_ENTRY;
6805  p = unpack_varlen_hex (++p1, &sysno);
6806  event->ws.value.syscall_number = (int) sysno;
6807  }
6808  else if (strprefix (p, p1, "syscall_return"))
6809  {
6810  ULONGEST sysno;
6811 
6812  event->ws.kind = TARGET_WAITKIND_SYSCALL_RETURN;
6813  p = unpack_varlen_hex (++p1, &sysno);
6814  event->ws.value.syscall_number = (int) sysno;
6815  }
6816  else if (strprefix (p, p1, "watch")
6817  || strprefix (p, p1, "rwatch")
6818  || strprefix (p, p1, "awatch"))
6819  {
6820  event->stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
6821  p = unpack_varlen_hex (++p1, &addr);
6822  event->watch_data_address = (CORE_ADDR) addr;
6823  }
6824  else if (strprefix (p, p1, "swbreak"))
6825  {
6826  event->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
6827 
6828  /* Make sure the stub doesn't forget to indicate support
6829  with qSupported. */
6831  error (_("Unexpected swbreak stop reason"));
6832 
6833  /* The value part is documented as "must be empty",
6834  though we ignore it, in case we ever decide to make
6835  use of it in a backward compatible way. */
6836  p = strchrnul (p1 + 1, ';');
6837  }
6838  else if (strprefix (p, p1, "hwbreak"))
6839  {
6840  event->stop_reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
6841 
6842  /* Make sure the stub doesn't forget to indicate support
6843  with qSupported. */
6845  error (_("Unexpected hwbreak stop reason"));
6846 
6847  /* See above. */
6848  p = strchrnul (p1 + 1, ';');
6849  }
6850  else if (strprefix (p, p1, "library"))
6851  {
6852  event->ws.kind = TARGET_WAITKIND_LOADED;
6853  p = strchrnul (p1 + 1, ';');
6854  }
6855  else if (strprefix (p, p1, "replaylog"))
6856  {
6857  event->ws.kind = TARGET_WAITKIND_NO_HISTORY;
6858  /* p1 will indicate "begin" or "end", but it makes
6859  no difference for now, so ignore it. */
6860  p = strchrnul (p1 + 1, ';');
6861  }
6862  else if (strprefix (p, p1, "core"))
6863  {
6864  ULONGEST c;
6865 
6866  p = unpack_varlen_hex (++p1, &c);
6867  event->core = c;
6868  }
6869  else if (strprefix (p, p1, "fork"))
6870  {
6871  event->ws.value.related_pid = read_ptid (++p1, &p);
6872  event->ws.kind = TARGET_WAITKIND_FORKED;
6873  }
6874  else if (strprefix (p, p1, "vfork"))
6875  {
6876  event->ws.value.related_pid = read_ptid (++p1, &p);
6877  event->ws.kind = TARGET_WAITKIND_VFORKED;
6878  }
6879  else if (strprefix (p, p1, "vforkdone"))
6880  {
6881  event->ws.kind = TARGET_WAITKIND_VFORK_DONE;
6882  p = strchrnul (p1 + 1, ';');
6883  }
6884  else if (strprefix (p, p1, "exec"))
6885  {
6886  ULONGEST ignored;
6887  char pathname[PATH_MAX];
6888  int pathlen;
6889 
6890  /* Determine the length of the execd pathname. */
6891  p = unpack_varlen_hex (++p1, &ignored);
6892  pathlen = (p - p1) / 2;
6893 
6894  /* Save the pathname for event reporting and for
6895  the next run command. */
6896  hex2bin (p1, (gdb_byte *) pathname, pathlen);
6897  pathname[pathlen] = '\0';
6898 
6899  /* This is freed during event handling. */
6900  event->ws.value.execd_pathname = xstrdup (pathname);
6901  event->ws.kind = TARGET_WAITKIND_EXECD;
6902 
6903  /* Skip the registers included in this packet, since
6904  they may be for an architecture different from the
6905  one used by the original program. */
6906  skipregs = 1;
6907  }
6908  else if (strprefix (p, p1, "create"))
6909  {
6910  event->ws.kind = TARGET_WAITKIND_THREAD_CREATED;
6911  p = strchrnul (p1 + 1, ';');
6912  }
6913  else
6914  {
6915  ULONGEST pnum;
6916  const char *p_temp;
6917 
6918  if (skipregs)
6919  {
6920  p = strchrnul (p1 + 1, ';');
6921  p++;
6922  continue;
6923  }
6924 
6925  /* Maybe a real ``P'' register number. */
6926  p_temp = unpack_varlen_hex (p, &pnum);
6927  /* If the first invalid character is the colon, we got a
6928  register number. Otherwise, it's an unknown stop
6929  reason. */
6930  if (p_temp == p1)
6931  {
6932  /* If we haven't parsed the event's thread yet, find
6933  it now, in order to find the architecture of the
6934  reported expedited registers. */
6935  if (event->ptid == null_ptid)
6936  {
6937  const char *thr = strstr (p1 + 1, ";thread:");
6938  if (thr != NULL)
6939  event->ptid = read_ptid (thr + strlen (";thread:"),
6940  NULL);
6941  else
6942  {
6943  /* Either the current thread hasn't changed,
6944  or the inferior is not multi-threaded.
6945  The event must be for the thread we last
6946  set as (or learned as being) current. */
6947  event->ptid = event->rs->general_thread;
6948  }
6949  }
6950 
6951  if (rsa == NULL)
6952  {
6953  inferior *inf = (event->ptid == null_ptid
6954  ? NULL
6955  : find_inferior_ptid (event->ptid));
6956  /* If this is the first time we learn anything
6957  about this process, skip the registers
6958  included in this packet, since we don't yet
6959  know which architecture to use to parse them.
6960  We'll determine the architecture later when
6961  we process the stop reply and retrieve the
6962  target description, via
6963  remote_notice_new_inferior ->
6964  post_create_inferior. */
6965  if (inf == NULL)
6966  {
6967  p = strchrnul (p1 + 1, ';');
6968  p++;
6969  continue;
6970  }
6971 
6972  event->arch = inf->gdbarch;
6973  rsa = get_remote_arch_state (event->arch);
6974  }
6975 
6976  packet_reg *reg
6977  = packet_reg_from_pnum (event->arch, rsa, pnum);
6979 
6980  if (reg == NULL)
6981  error (_("Remote sent bad register number %s: %s\n\
6982 Packet: '%s'\n"),
6983  hex_string (pnum), p, buf);
6984 
6985  cached_reg.num = reg->regnum;
6986  cached_reg.data = (gdb_byte *)
6987  xmalloc (register_size (event->arch, reg->regnum));
6988 
6989  p = p1 + 1;
6990  fieldsize = hex2bin (p, cached_reg.data,
6991  register_size (event->arch, reg->regnum));
6992  p += 2 * fieldsize;
6993  if (fieldsize < register_size (event->arch, reg->regnum))
6994  warning (_("Remote reply is too short: %s"), buf);
6995 
6996  VEC_safe_push (cached_reg_t, event->regcache, &cached_reg);
6997  }
6998  else
6999  {
7000  /* Not a number. Silently skip unknown optional
7001  info. */
7002  p = strchrnul (p1 + 1, ';');
7003  }
7004  }
7005 
7006  if (*p != ';')
7007  error (_("Remote register badly formatted: %s\nhere: %s"),
7008  buf, p);
7009  ++p;
7010  }
7011 
7012  if (event->ws.kind != TARGET_WAITKIND_IGNORE)
7013  break;
7014 
7015  /* fall through */
7016  case 'S': /* Old style status, just signal only. */
7017  {
7018  int sig;
7019 
7020  event->ws.kind = TARGET_WAITKIND_STOPPED;
7021  sig = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
7022  if (GDB_SIGNAL_FIRST <= sig && sig < GDB_SIGNAL_LAST)
7023  event->ws.value.sig = (enum gdb_signal) sig;
7024  else
7025  event->ws.value.sig = GDB_SIGNAL_UNKNOWN;
7026  }
7027  break;
7028  case 'w': /* Thread exited. */
7029  {
7030  const char *p;
7031  ULONGEST value;
7032 
7033  event->ws.kind = TARGET_WAITKIND_THREAD_EXITED;
7034  p = unpack_varlen_hex (&buf[1], &value);
7035  event->ws.value.integer = value;
7036  if (*p != ';')
7037  error (_("stop reply packet badly formatted: %s"), buf);
7038  event->ptid = read_ptid (++p, NULL);
7039  break;
7040  }
7041  case 'W': /* Target exited. */
7042  case 'X':
7043  {
7044  const char *p;
7045  int pid;
7046  ULONGEST value;
7047 
7048  /* GDB used to accept only 2 hex chars here. Stubs should
7049  only send more if they detect GDB supports multi-process
7050  support. */
7051  p = unpack_varlen_hex (&buf[1], &value);
7052 
7053  if (buf[0] == 'W')
7054  {
7055  /* The remote process exited. */
7056  event->ws.kind = TARGET_WAITKIND_EXITED;
7057  event->ws.value.integer = value;
7058  }
7059  else
7060  {
7061  /* The remote process exited with a signal. */
7062  event->ws.kind = TARGET_WAITKIND_SIGNALLED;
7063  if (GDB_SIGNAL_FIRST <= value && value < GDB_SIGNAL_LAST)
7064  event->ws.value.sig = (enum gdb_signal) value;
7065  else
7066  event->ws.value.sig = GDB_SIGNAL_UNKNOWN;
7067  }
7068 
7069  /* If no process is specified, assume inferior_ptid. */
7071  if (*p == '\0')
7072  ;
7073  else if (*p == ';')
7074  {
7075  p++;
7076 
7077  if (*p == '\0')
7078  ;
7079  else if (startswith (p, "process:"))
7080  {
7081  ULONGEST upid;
7082 
7083  p += sizeof ("process:") - 1;
7084  unpack_varlen_hex (p, &upid);
7085  pid = upid;
7086  }
7087  else
7088  error (_("unknown stop reply packet: %s"), buf);
7089  }
7090  else
7091  error (_("unknown stop reply packet: %s"), buf);
7092  event->ptid = pid_to_ptid (pid);
7093  }
7094  break;
7095  case 'N':
7096  event->ws.kind = TARGET_WAITKIND_NO_RESUMED;
7097  event->ptid = minus_one_ptid;
7098  break;
7099  }
7100 
7101  if (target_is_non_stop_p () && ptid_equal (event->ptid, null_ptid))
7102  error (_("No process or thread specified in stop reply: %s"), buf);
7103 }
7104 
7105 /* When the stub wants to tell GDB about a new notification reply, it
7106  sends a notification (%Stop, for example). Those can come it at
7107  any time, hence, we have to make sure that any pending
7108  putpkt/getpkt sequence we're making is finished, before querying
7109  the stub for more events with the corresponding ack command
7110  (vStopped, for example). E.g., if we started a vStopped sequence
7111  immediately upon receiving the notification, something like this
7112  could happen:
7113 
7114  1.1) --> Hg 1
7115  1.2) <-- OK
7116  1.3) --> g
7117  1.4) <-- %Stop
7118  1.5) --> vStopped
7119  1.6) <-- (registers reply to step #1.3)
7120 
7121  Obviously, the reply in step #1.6 would be unexpected to a vStopped
7122  query.
7123 
7124  To solve this, whenever we parse a %Stop notification successfully,
7125  we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
7126  doing whatever we were doing:
7127 
7128  2.1) --> Hg 1
7129  2.2) <-- OK
7130  2.3) --> g
7131  2.4) <-- %Stop
7132  <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
7133  2.5) <-- (registers reply to step #2.3)
7134 
7135  Eventualy after step #2.5, we return to the event loop, which
7136  notices there's an event on the
7137  REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
7138  associated callback --- the function below. At this point, we're
7139  always safe to start a vStopped sequence. :
7140 
7141  2.6) --> vStopped
7142  2.7) <-- T05 thread:2
7143  2.8) --> vStopped
7144  2.9) --> OK
7145 */
7146 
7147 void
7149 {
7150  struct remote_state *rs = get_remote_state ();
7151 
7152  if (rs->notif_state->pending_event[nc->id] != NULL)
7153  {
7154  if (notif_debug)
7156  "notif: process: '%s' ack pending event\n",
7157  nc->name);
7158 
7159  /* acknowledge */
7160  nc->ack (nc, rs->buf, rs->notif_state->pending_event[nc->id]);
7161  rs->notif_state->pending_event[nc->id] = NULL;
7162 
7163  while (1)
7164  {
7165  getpkt (&rs->buf, &rs->buf_size, 0);
7166  if (strcmp (rs->buf, "OK") == 0)
7167  break;
7168  else
7169  remote_notif_ack (nc, rs->buf);
7170  }
7171  }
7172  else
7173  {
7174  if (notif_debug)
7176  "notif: process: '%s' no pending reply\n",
7177  nc->name);
7178  }
7179 }
7180 
7181 /* Called when it is decided that STOP_REPLY holds the info of the
7182  event that is to be returned to the core. This function always
7183  destroys STOP_REPLY. */
7184 
7185 static ptid_t
7187  struct target_waitstatus *status)
7188 {
7189  ptid_t ptid;
7190 
7191  *status = stop_reply->ws;
7192  ptid = stop_reply->ptid;
7193 
7194  /* If no thread/process was reported by the stub, assume the current
7195  inferior. */
7196  if (ptid_equal (ptid, null_ptid))
7197  ptid = inferior_ptid;
7198 
7199  if (status->kind != TARGET_WAITKIND_EXITED
7200  && status->kind != TARGET_WAITKIND_SIGNALLED
7201  && status->kind != TARGET_WAITKIND_NO_RESUMED)
7202  {
7203  /* Expedited registers. */
7204  if (stop_reply->regcache)
7205  {
7206  struct regcache *regcache
7208  cached_reg_t *reg;
7209  int ix;
7210 
7211  for (ix = 0;
7212  VEC_iterate (cached_reg_t, stop_reply->regcache, ix, reg);
7213  ix++)
7214  {
7215  regcache_raw_supply (regcache, reg->num, reg->data);
7216  xfree (reg->data);
7217  }
7218 
7219  VEC_free (cached_reg_t, stop_reply->regcache);
7220  }
7221 
7224  remote_thr->core = stop_reply->core;
7225  remote_thr->stop_reason = stop_reply->stop_reason;
7226  remote_thr->watch_data_address = stop_reply->watch_data_address;
7227  remote_thr->vcont_resumed = 0;
7228  }
7229 
7231  return ptid;
7232 }
7233 
7234 /* The non-stop mode version of target_wait. */
7235 
7236 static ptid_t
7238 {
7239  struct remote_state *rs = get_remote_state ();
7240  struct stop_reply *stop_reply;
7241  int ret;
7242  int is_notif = 0;
7243 
7244  /* If in non-stop mode, get out of getpkt even if a
7245  notification is received. */
7246 
7247  ret = getpkt_or_notif_sane (&rs->buf, &rs->buf_size,
7248  0 /* forever */, &is_notif);
7249  while (1)
7250  {
7251  if (ret != -1 && !is_notif)
7252  switch (rs->buf[0])
7253  {
7254  case 'E': /* Error of some sort. */
7255  /* We're out of sync with the target now. Did it continue
7256  or not? We can't tell which thread it was in non-stop,
7257  so just ignore this. */
7258  warning (_("Remote failure reply: %s"), rs->buf);
7259  break;
7260  case 'O': /* Console output. */
7261  remote_console_output (rs->buf + 1);
7262  break;
7263  default:
7264  warning (_("Invalid remote reply: %s"), rs->buf);
7265  break;
7266  }
7267 
7268  /* Acknowledge a pending stop reply that may have arrived in the
7269  mean time. */
7272 
7273  /* If indeed we noticed a stop reply, we're done. */
7275  if (stop_reply != NULL)
7277 
7278  /* Still no event. If we're just polling for an event, then
7279  return to the event loop. */
7280  if (options & TARGET_WNOHANG)
7281  {
7283  return minus_one_ptid;
7284  }
7285 
7286  /* Otherwise do a blocking wait. */
7287  ret = getpkt_or_notif_sane (&rs->buf, &rs->buf_size,
7288  1 /* forever */, &is_notif);
7289  }
7290 }
7291 
7292 /* Wait until the remote machine stops, then return, storing status in
7293  STATUS just as `wait' would. */
7294 
7295 static ptid_t
7297 {
7298  struct remote_state *rs = get_remote_state ();
7299  ptid_t event_ptid = null_ptid;
7300  char *buf;
7301  struct stop_reply *stop_reply;
7302 
7303  again:
7304 
7306  status->value.integer = 0;
7307 
7309  if (stop_reply != NULL)
7311 
7312  if (rs->cached_wait_status)
7313  /* Use the cached wait status, but only once. */
7314  rs->cached_wait_status = 0;
7315  else
7316  {
7317  int ret;
7318  int is_notif;
7319  int forever = ((options & TARGET_WNOHANG) == 0
7321 
7322  if (!rs->waiting_for_stop_reply)
7323  {
7325  return minus_one_ptid;
7326  }
7327 
7328  /* FIXME: cagney/1999-09-27: If we're in async mode we should
7329  _never_ wait for ever -> test on target_is_async_p().
7330  However, before we do that we need to ensure that the caller
7331  knows how to take the target into/out of async mode. */
7332  ret = getpkt_or_notif_sane (&rs->buf, &rs->buf_size,
7333  forever, &is_notif);
7334 
7335  /* GDB gets a notification. Return to core as this event is
7336  not interesting. */
7337  if (ret != -1 && is_notif)
7338  return minus_one_ptid;
7339 
7340  if (ret == -1 && (options & TARGET_WNOHANG) != 0)
7341  return minus_one_ptid;
7342  }
7343 
7344  buf = rs->buf;
7345 
7346  /* Assume that the target has acknowledged Ctrl-C unless we receive
7347  an 'F' or 'O' packet. */
7348  if (buf[0] != 'F' && buf[0] != 'O')
7349  rs->ctrlc_pending_p = 0;
7350 
7351  switch (buf[0])
7352  {
7353  case 'E': /* Error of some sort. */
7354  /* We're out of sync with the target now. Did it continue or
7355  not? Not is more likely, so report a stop. */
7357 
7358  warning (_("Remote failure reply: %s"), buf);
7360  status->value.sig = GDB_SIGNAL_0;
7361  break;
7362  case 'F': /* File-I/O request. */
7363  /* GDB may access the inferior memory while handling the File-I/O
7364  request, but we don't want GDB accessing memory while waiting
7365  for a stop reply. See the comments in putpkt_binary. Set
7366  waiting_for_stop_reply to 0 temporarily. */
7369  rs->ctrlc_pending_p = 0;
7370  /* GDB handled the File-I/O request, and the target is running
7371  again. Keep waiting for events. */
7373  break;
7374  case 'N': case 'T': case 'S': case 'X': case 'W':
7375  {
7376  struct stop_reply *stop_reply;
7377 
7378  /* There is a stop reply to handle. */
7380 
7381  stop_reply
7383  rs->buf);
7384 
7385  event_ptid = process_stop_reply (stop_reply, status);
7386  break;
7387  }
7388  case 'O': /* Console output. */
7389  remote_console_output (buf + 1);
7390  break;
7391  case '\0':
7392  if (rs->last_sent_signal != GDB_SIGNAL_0)
7393  {
7394  /* Zero length reply means that we tried 'S' or 'C' and the
7395  remote system doesn't support it. */
7398  ("Can't send signals to this remote system. %s not sent.\n",
7400  rs->last_sent_signal = GDB_SIGNAL_0;
7402 
7403  strcpy (buf, rs->last_sent_step ? "s" : "c");
7404  putpkt (buf);
7405  break;
7406  }
7407  /* else fallthrough */
7408  default:
7409  warning (_("Invalid remote reply: %s"), buf);
7410  break;
7411  }
7412 
7413  if (status->kind == TARGET_WAITKIND_NO_RESUMED)
7414  return minus_one_ptid;
7415  else if (status->kind == TARGET_WAITKIND_IGNORE)
7416  {
7417  /* Nothing interesting happened. If we're doing a non-blocking
7418  poll, we're done. Otherwise, go back to waiting. */
7419  if (options & TARGET_WNOHANG)
7420  return minus_one_ptid;
7421  else
7422  goto again;
7423  }
7424  else if (status->kind != TARGET_WAITKIND_EXITED
7425  && status->kind != TARGET_WAITKIND_SIGNALLED)
7426  {
7427  if (!ptid_equal (event_ptid, null_ptid))
7428  record_currthread (rs, event_ptid);
7429  else
7430  event_ptid = inferior_ptid;
7431  }
7432  else
7433  /* A process exit. Invalidate our notion of current thread. */
7435 
7436  return event_ptid;
7437 }
7438 
7439 /* Wait until the remote machine stops, then return, storing status in
7440  STATUS just as `wait' would. */
7441 
7442 static ptid_t
7444  ptid_t ptid, struct target_waitstatus *status, int options)
7445 {
7446  ptid_t event_ptid;
7447 
7448  if (target_is_non_stop_p ())
7449  event_ptid = remote_wait_ns (ptid, status, options);
7450  else
7451  event_ptid = remote_wait_as (ptid, status, options);
7452 
7453  if (target_is_async_p ())
7454  {
7455  /* If there are are events left in the queue tell the event loop
7456  to return here. */
7457  if (!QUEUE_is_empty (stop_reply_p, stop_reply_queue))
7459  }
7460 
7461  return event_ptid;
7462 }
7463 
7464 /* Fetch a single register using a 'p' packet. */
7465 
7466 static int
7468 {
7469  struct gdbarch *gdbarch = regcache->arch ();
7470  struct remote_state *rs = get_remote_state ();
7471  char *buf, *p;
7472  gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
7473  int i;
7474 
7476  return 0;
7477 
7478  if (reg->pnum == -1)
7479  return 0;
7480 
7481  p = rs->buf;
7482  *p++ = 'p';
7483  p += hexnumstr (p, reg->pnum);
7484  *p++ = '\0';
7485  putpkt (rs->buf);
7486  getpkt (&rs->buf, &rs->buf_size, 0);
7487 
7488  buf = rs->buf;
7489 
7491  {
7492  case PACKET_OK:
7493  break;
7494  case PACKET_UNKNOWN:
7495  return 0;
7496  case PACKET_ERROR:
7497  error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
7499  reg->regnum),
7500  buf);
7501  }
7502 
7503  /* If this register is unfetchable, tell the regcache. */
7504  if (buf[0] == 'x')
7505  {
7506  regcache_raw_supply (regcache, reg->regnum, NULL);
7507  return 1;
7508  }
7509 
7510  /* Otherwise, parse and supply the value. */
7511  p = buf;
7512  i = 0;
7513  while (p[0] != 0)
7514  {
7515  if (p[1] == 0)
7516  error (_("fetch_register_using_p: early buf termination"));
7517 
7518  regp[i++] = fromhex (p[0]) * 16 + fromhex (p[1]);
7519  p += 2;
7520  }
7521  regcache_raw_supply (regcache, reg->regnum, regp);
7522  return 1;
7523 }
7524 
7525 /* Fetch the registers included in the target's 'g' packet. */
7526 
7527 static int
7529 {
7530  struct remote_state *rs = get_remote_state ();
7531  int buf_len;
7532 
7533  xsnprintf (rs->buf, get_remote_packet_size (), "g");
7534  remote_send (&rs->buf, &rs->buf_size);
7535 
7536  /* We can get out of synch in various cases. If the first character
7537  in the buffer is not a hex character, assume that has happened
7538  and try to fetch another packet to read. */
7539  while ((rs->buf[0] < '0' || rs->buf[0] > '9')
7540  && (rs->buf[0] < 'A' || rs->buf[0] > 'F')
7541  && (rs->buf[0] < 'a' || rs->buf[0] > 'f')
7542  && rs->buf[0] != 'x') /* New: unavailable register value. */
7543  {
7544  if (remote_debug)
7546  "Bad register packet; fetching a new packet\n");
7547  getpkt (&rs->buf, &rs->buf_size, 0);
7548  }
7549 
7550  buf_len = strlen (rs->buf);
7551 
7552  /* Sanity check the received packet. */
7553  if (buf_len % 2 != 0)
7554  error (_("Remote 'g' packet reply is of odd length: %s"), rs->buf);
7555 
7556  return buf_len / 2;
7557 }
7558 
7559 static void
7561 {
7562  struct gdbarch *gdbarch = regcache->arch ();
7563  struct remote_state *rs = get_remote_state ();
7565  int i, buf_len;
7566  char *p;
7567  char *regs;
7568 
7569  buf_len = strlen (rs->buf);
7570 
7571  /* Further sanity checks, with knowledge of the architecture. */
7572  if (buf_len > 2 * rsa->sizeof_g_packet)
7573  error (_("Remote 'g' packet reply is too long (expected %ld bytes, got %d "
7574  "bytes): %s"), rsa->sizeof_g_packet, buf_len / 2, rs->buf);
7575 
7576  /* Save the size of the packet sent to us by the target. It is used
7577  as a heuristic when determining the max size of packets that the
7578  target can safely receive. */
7579  if (rsa->actual_register_packet_size == 0)
7580  rsa->actual_register_packet_size = buf_len;
7581 
7582  /* If this is smaller than we guessed the 'g' packet would be,
7583  update our records. A 'g' reply that doesn't include a register's
7584  value implies either that the register is not available, or that
7585  the 'p' packet must be used. */
7586  if (buf_len < 2 * rsa->sizeof_g_packet)
7587  {
7588  long sizeof_g_packet = buf_len / 2;
7589 
7590  for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
7591  {
7592  long offset = rsa->regs[i].offset;
7593  long reg_size = register_size (gdbarch, i);
7594 
7595  if (rsa->regs[i].pnum == -1)
7596  continue;
7597 
7598  if (offset >= sizeof_g_packet)
7599  rsa->regs[i].in_g_packet = 0;
7600  else if (offset + reg_size > sizeof_g_packet)
7601  error (_("Truncated register %d in remote 'g' packet"), i);
7602  else
7603  rsa->regs[i].in_g_packet = 1;
7604  }
7605 
7606  /* Looks valid enough, we can assume this is the correct length
7607  for a 'g' packet. It's important not to adjust
7608  rsa->sizeof_g_packet if we have truncated registers otherwise
7609  this "if" won't be run the next time the method is called
7610  with a packet of the same size and one of the internal errors
7611  below will trigger instead. */
7612  rsa->sizeof_g_packet = sizeof_g_packet;
7613  }
7614 
7615  regs = (char *) alloca (rsa->sizeof_g_packet);
7616 
7617  /* Unimplemented registers read as all bits zero. */
7618  memset (regs, 0, rsa->sizeof_g_packet);
7619 
7620  /* Reply describes registers byte by byte, each byte encoded as two
7621  hex characters. Suck them all up, then supply them to the
7622  register cacheing/storage mechanism. */
7623 
7624  p = rs->buf;
7625  for (i = 0; i < rsa->sizeof_g_packet; i++)
7626  {
7627  if (p[0] == 0 || p[1] == 0)
7628  /* This shouldn't happen - we adjusted sizeof_g_packet above. */
7629  internal_error (__FILE__, __LINE__,
7630  _("unexpected end of 'g' packet reply"));
7631 
7632  if (p[0] == 'x' && p[1] == 'x')
7633  regs[i] = 0; /* 'x' */
7634  else
7635  regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
7636  p += 2;
7637  }
7638 
7639  for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
7640  {
7641  struct packet_reg *r = &rsa->regs[i];
7642  long reg_size = register_size (gdbarch, i);
7643 
7644  if (r->in_g_packet)
7645  {
7646  if ((r->offset + reg_size) * 2 > strlen (rs->buf))
7647  /* This shouldn't happen - we adjusted in_g_packet above. */
7648  internal_error (__FILE__, __LINE__,
7649  _("unexpected end of 'g' packet reply"));
7650  else if (rs->buf[r->offset * 2] == 'x')
7651  {
7652  gdb_assert (r->offset * 2 < strlen (rs->buf));
7653  /* The register isn't available, mark it as such (at
7654  the same time setting the value to zero). */
7655  regcache_raw_supply (regcache, r->regnum, NULL);
7656  }
7657  else
7659  regs + r->offset);
7660  }
7661  }
7662 }
7663 
7664 static void
7666 {
7667  send_g_packet ();
7669 }
7670 
7671 /* Make the remote selected traceframe match GDB's selected
7672  traceframe. */
7673 
7674 static void
7676 {
7677  int newnum;
7678  struct remote_state *rs = get_remote_state ();
7679 
7681  return;
7682 
7683  /* Avoid recursion, remote_trace_find calls us again. */
7685 
7686  newnum = target_trace_find (tfind_number,
7687  get_traceframe_number (), 0, 0, NULL);
7688 
7689  /* Should not happen. If it does, all bets are off. */
7690  if (newnum != get_traceframe_number ())
7691  warning (_("could not set remote traceframe"));
7692 }
7693 
7694 static void
7696  struct regcache *regcache, int regnum)
7697 {
7698  struct gdbarch *gdbarch = regcache->arch ();
7700  int i;
7701 
7704 
7705  if (regnum >= 0)
7706  {
7708 
7709  gdb_assert (reg != NULL);
7710 
7711  /* If this register might be in the 'g' packet, try that first -
7712  we are likely to read more than one register. If this is the
7713  first 'g' packet, we might be overly optimistic about its
7714  contents, so fall back to 'p'. */
7715  if (reg->in_g_packet)
7716  {
7718  if (reg->in_g_packet)
7719  return;
7720  }
7721 
7723  return;
7724 
7725  /* This register is not available. */
7726  regcache_raw_supply (regcache, reg->regnum, NULL);
7727 
7728  return;
7729  }
7730 
7732 
7733  for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
7734  if (!rsa->regs[i].in_g_packet)
7735  if (!fetch_register_using_p (regcache, &rsa->regs[i]))
7736  {
7737  /* This register is not available. */
7738  regcache_raw_supply (regcache, i, NULL);
7739  }
7740 }
7741 
7742 /* Prepare to store registers. Since we may send them all (using a
7743  'G' request), we have to read out the ones we don't want to change
7744  first. */
7745 
7746 static void
7748 {
7750  int i;
7751 
7752  /* Make sure the entire registers array is valid. */
7753  switch (packet_support (PACKET_P))
7754  {
7755  case PACKET_DISABLE:
7757  /* Make sure all the necessary registers are cached. */
7758  for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++)
7759  if (rsa->regs[i].in_g_packet)
7761  break;
7762  case PACKET_ENABLE:
7763  break;
7764  }
7765 }
7766 
7767 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
7768  packet was not recognized. */
7769 
7770 static int
7772  struct packet_reg *reg)
7773 {
7774  struct gdbarch *gdbarch = regcache->arch ();
7775  struct remote_state *rs = get_remote_state ();
7776  /* Try storing a single register. */
7777  char *buf = rs->buf;
7778  gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
7779  char *p;
7780 
7782  return 0;
7783 
7784  if (reg->pnum == -1)
7785  return 0;
7786 
7787  xsnprintf (buf, get_remote_packet_size (), "P%s=", phex_nz (reg->pnum, 0));
7788  p = buf + strlen (buf);
7789  regcache_raw_collect (regcache, reg->regnum, regp);
7790  bin2hex (regp, p, register_size (gdbarch, reg->regnum));
7791  putpkt (rs->buf);
7792  getpkt (&rs->buf, &rs->buf_size, 0);
7793 
7794  switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_P]))
7795  {
7796  case PACKET_OK:
7797  return 1;
7798  case PACKET_ERROR:
7799  error (_("Could not write register \"%s\"; remote failure reply '%s'"),
7800  gdbarch_register_name (gdbarch, reg->regnum), rs->buf);
7801  case PACKET_UNKNOWN:
7802  return 0;
7803  default:
7804  internal_error (__FILE__, __LINE__, _("Bad result from packet_ok"));
7805  }
7806 }
7807 
7808 /* Store register REGNUM, or all registers if REGNUM == -1, from the
7809  contents of the register cache buffer. FIXME: ignores errors. */
7810 
7811 static void
7813 {
7814  struct remote_state *rs = get_remote_state ();
7816  gdb_byte *regs;
7817  char *p;
7818 
7819  /* Extract all the registers in the regcache copying them into a
7820  local buffer. */
7821  {
7822  int i;
7823 
7824  regs = (gdb_byte *) alloca (rsa->sizeof_g_packet);
7825  memset (regs, 0, rsa->sizeof_g_packet);
7826  for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++)
7827  {
7828  struct packet_reg *r = &rsa->regs[i];
7829 
7830  if (r->in_g_packet)
7831  regcache_raw_collect (regcache, r->regnum, regs + r->offset);
7832  }
7833  }
7834 
7835  /* Command describes registers byte by byte,
7836  each byte encoded as two hex characters. */
7837  p = rs->buf;
7838  *p++ = 'G';
7839  bin2hex (regs, p, rsa->sizeof_g_packet);
7840  putpkt (rs->buf);
7841  getpkt (&rs->buf, &rs->buf_size, 0);
7842  if (packet_check_result (rs->buf) == PACKET_ERROR)
7843  error (_("Could not write registers; remote failure reply '%s'"),
7844  rs->buf);
7845 }
7846 
7847 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
7848  of the register cache buffer. FIXME: ignores errors. */
7849 
7850 static void
7852  struct regcache *regcache, int regnum)
7853 {
7854  struct gdbarch *gdbarch = regcache->arch ();
7856  int i;
7857 
7860 
7861  if (regnum >= 0)
7862  {
7864 
7865  gdb_assert (reg != NULL);
7866 
7867  /* Always prefer to store registers using the 'P' packet if
7868  possible; we often change only a small number of registers.
7869  Sometimes we change a larger number; we'd need help from a
7870  higher layer to know to use 'G'. */
7872  return;
7873 
7874  /* For now, don't complain if we have no way to write the
7875  register. GDB loses track of unavailable registers too
7876  easily. Some day, this may be an error. We don't have
7877  any way to read the register, either... */
7878  if (!reg->in_g_packet)
7879  return;
7880 
7882  return;
7883  }
7884 
7886 
7887  for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
7888  if (!rsa->regs[i].in_g_packet)
7889  if (!store_register_using_P (regcache, &rsa->regs[i]))
7890  /* See above for why we do not issue an error here. */
7891  continue;
7892 }
7893 
7894 
7895 /* Return the number of hex digits in num. */
7896 
7897 static int
7899 {
7900  int i;
7901 
7902  for (i = 0; num != 0; i++)
7903  num >>= 4;
7904 
7905  return std::max (i, 1);
7906 }
7907 
7908 /* Set BUF to the minimum number of hex digits representing NUM. */
7909 
7910 static int
7911 hexnumstr (char *buf, ULONGEST num)
7912 {
7913  int len = hexnumlen (num);
7914 
7915  return hexnumnstr (buf, num, len);
7916 }
7917 
7918 
7919 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
7920 
7921 static int
7922 hexnumnstr (char *buf, ULONGEST num, int width)
7923 {
7924  int i;
7925 
7926  buf[width] = '\0';
7927 
7928  for (i = width - 1; i >= 0; i--)
7929  {
7930  buf[i] = "0123456789abcdef"[(num & 0xf)];
7931  num >>= 4;
7932  }
7933 
7934  return width;
7935 }
7936 
7937 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
7938 
7939 static CORE_ADDR
7941 {
7942  unsigned int address_size = remote_address_size;
7943 
7944  /* If "remoteaddresssize" was not set, default to target address size. */
7945  if (!address_size)
7946  address_size = gdbarch_addr_bit (target_gdbarch ());
7947 
7948  if (address_size > 0
7949  && address_size < (sizeof (ULONGEST) * 8))
7950  {
7951  /* Only create a mask when that mask can safely be constructed
7952  in a ULONGEST variable. */
7953  ULONGEST mask = 1;
7954 
7955  mask = (mask << address_size) - 1;
7956  addr &= mask;
7957  }
7958  return addr;
7959 }
7960 
7961 /* Determine whether the remote target supports binary downloading.
7962  This is accomplished by sending a no-op memory write of zero length
7963  to the target at the specified address. It does not suffice to send
7964  the whole packet, since many stubs strip the eighth bit and
7965  subsequently compute a wrong checksum, which causes real havoc with
7966  remote_write_bytes.
7967 
7968  NOTE: This can still lose if the serial line is not eight-bit
7969  clean. In cases like this, the user should clear "remote
7970  X-packet". */
7971 
7972 static void
7974 {
7975  struct remote_state *rs = get_remote_state ();
7976 
7977  switch (packet_support (PACKET_X))
7978  {
7979  case PACKET_DISABLE:
7980  break;
7981  case PACKET_ENABLE:
7982  break;
7984  {
7985  char *p;
7986 
7987  p = rs->buf;
7988  *p++ = 'X';
7989  p += hexnumstr (p, (ULONGEST) addr);
7990  *p++ = ',';
7991  p += hexnumstr (p, (ULONGEST) 0);
7992  *p++ = ':';
7993  *p = '\0';
7994 
7995  putpkt_binary (rs->buf, (int) (p - rs->buf));
7996  getpkt (&rs->buf, &rs->buf_size, 0);
7997 
7998  if (rs->buf[0] == '\0')
7999  {
8000  if (remote_debug)
8002  "binary downloading NOT "
8003  "supported by target\n");
8005  }
8006  else
8007  {
8008  if (remote_debug)
8010  "binary downloading supported by target\n");
8012  }
8013  break;
8014  }
8015  }
8016 }
8017 
8018 /* Helper function to resize the payload in order to try to get a good
8019  alignment. We try to write an amount of data such that the next write will
8020  start on an address aligned on REMOTE_ALIGN_WRITES. */
8021 
8022 static int
8024 {
8025  return ((memaddr + todo) & ~(REMOTE_ALIGN_WRITES - 1)) - memaddr;
8026 }
8027 
8028 /* Write memory data directly to the remote machine.
8029  This does not inform the data cache; the data cache uses this.
8030  HEADER is the starting part of the packet.
8031  MEMADDR is the address in the remote memory space.
8032  MYADDR is the address of the buffer in our space.
8033  LEN_UNITS is the number of addressable units to write.
8034  UNIT_SIZE is the length in bytes of an addressable unit.
8035  PACKET_FORMAT should be either 'X' or 'M', and indicates if we
8036  should send data as binary ('X'), or hex-encoded ('M').
8037 
8038  The function creates packet of the form
8039  <HEADER><ADDRESS>,<LENGTH>:<DATA>
8040 
8041  where encoding of <DATA> is terminated by PACKET_FORMAT.
8042 
8043  If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
8044  are omitted.
8045 
8046  Return the transferred status, error or OK (an
8047  'enum target_xfer_status' value). Save the number of addressable units
8048  transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
8049 
8050  On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
8051  exchange between gdb and the stub could look like (?? in place of the
8052  checksum):
8053 
8054  -> $m1000,4#??
8055  <- aaaabbbbccccdddd
8056 
8057  -> $M1000,3:eeeeffffeeee#??
8058  <- OK
8059 
8060  -> $m1000,4#??
8061  <- eeeeffffeeeedddd */
8062 
8063 static enum target_xfer_status
8064 remote_write_bytes_aux (const char *header, CORE_ADDR memaddr,
8065  const gdb_byte *myaddr, ULONGEST len_units,
8066  int unit_size, ULONGEST *xfered_len_units,
8067  char packet_format, int use_length)
8068 {
8069  struct remote_state *rs = get_remote_state ();
8070  char *p;
8071  char *plen = NULL;
8072  int plenlen = 0;
8073  int todo_units;
8074  int units_written;
8075  int payload_capacity_bytes;
8076  int payload_length_bytes;
8077 
8078  if (packet_format != 'X' && packet_format != 'M')
8079  internal_error (__FILE__, __LINE__,
8080  _("remote_write_bytes_aux: bad packet format"));
8081 
8082  if (len_units == 0)
8083  return TARGET_XFER_EOF;
8084 
8085  payload_capacity_bytes = get_memory_write_packet_size ();
8086 
8087  /* The packet buffer will be large enough for the payload;
8088  get_memory_packet_size ensures this. */
8089  rs->buf[0] = '\0';
8090 
8091  /* Compute the size of the actual payload by subtracting out the
8092  packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
8093 
8094  payload_capacity_bytes -= strlen ("$,:#NN");
8095  if (!use_length)
8096  /* The comma won't be used. */
8097  payload_capacity_bytes += 1;
8098  payload_capacity_bytes -= strlen (header);
8099  payload_capacity_bytes -= hexnumlen (memaddr);
8100 
8101  /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
8102 
8103  strcat (rs->buf, header);
8104  p = rs->buf + strlen (header);
8105 
8106  /* Compute a best guess of the number of bytes actually transfered. */
8107  if (packet_format == 'X')
8108  {
8109  /* Best guess at number of bytes that will fit. */
8110  todo_units = std::min (len_units,
8111  (ULONGEST) payload_capacity_bytes / unit_size);
8112  if (use_length)
8113  payload_capacity_bytes -= hexnumlen (todo_units);
8114  todo_units = std::min (todo_units, payload_capacity_bytes / unit_size);
8115  }
8116  else
8117  {
8118  /* Number of bytes that will fit. */
8119  todo_units
8120  = std::min (len_units,
8121  (ULONGEST) (payload_capacity_bytes / unit_size) / 2);
8122  if (use_length)
8123  payload_capacity_bytes -= hexnumlen (todo_units);
8124  todo_units = std::min (todo_units,
8125  (payload_capacity_bytes / unit_size) / 2);
8126  }
8127 
8128  if (todo_units <= 0)
8129  internal_error (__FILE__, __LINE__,
8130  _("minimum packet size too small to write data"));
8131 
8132  /* If we already need another packet, then try to align the end
8133  of this packet to a useful boundary. */
8134  if (todo_units > 2 * REMOTE_ALIGN_WRITES && todo_units < len_units)
8135  todo_units = align_for_efficient_write (todo_units, memaddr);
8136 
8137  /* Append "<memaddr>". */
8138  memaddr = remote_address_masked (memaddr);
8139  p += hexnumstr (p, (ULONGEST) memaddr);
8140 
8141  if (use_length)
8142  {
8143  /* Append ",". */
8144  *p++ = ',';
8145 
8146  /* Append the length and retain its location and size. It may need to be
8147  adjusted once the packet body has been created. */
8148  plen = p;
8149  plenlen = hexnumstr (p, (ULONGEST) todo_units);
8150  p += plenlen;
8151  }
8152 
8153  /* Append ":". */
8154  *p++ = ':';
8155  *p = '\0';
8156 
8157  /* Append the packet body. */
8158  if (packet_format == 'X')
8159  {
8160  /* Binary mode. Send target system values byte by byte, in
8161  increasing byte addresses. Only escape certain critical
8162  characters. */
8163  payload_length_bytes =
8164  remote_escape_output (myaddr, todo_units, unit_size, (gdb_byte *) p,
8165  &units_written, payload_capacity_bytes);
8166 
8167  /* If not all TODO units fit, then we'll need another packet. Make
8168  a second try to keep the end of the packet aligned. Don't do
8169  this if the packet is tiny. */
8170  if (units_written < todo_units && units_written > 2 * REMOTE_ALIGN_WRITES)
8171  {
8172  int new_todo_units;
8173 
8174  new_todo_units = align_for_efficient_write (units_written, memaddr);
8175 
8176  if (new_todo_units != units_written)
8177  payload_length_bytes =
8178  remote_escape_output (myaddr, new_todo_units, unit_size,
8179  (gdb_byte *) p, &units_written,
8180  payload_capacity_bytes);
8181  }
8182 
8183  p += payload_length_bytes;
8184  if (use_length && units_written < todo_units)
8185  {
8186  /* Escape chars have filled up the buffer prematurely,
8187  and we have actually sent fewer units than planned.
8188  Fix-up the length field of the packet. Use the same
8189  number of characters as before. */
8190  plen += hexnumnstr (plen, (ULONGEST) units_written,
8191  plenlen);
8192  *plen = ':'; /* overwrite \0 from hexnumnstr() */
8193  }
8194  }
8195  else
8196  {
8197  /* Normal mode: Send target system values byte by byte, in
8198  increasing byte addresses. Each byte is encoded as a two hex
8199  value. */
8200  p += 2 * bin2hex (myaddr, p, todo_units * unit_size);
8201  units_written = todo_units;
8202  }
8203 
8204  putpkt_binary (rs->buf, (int) (p - rs->buf));
8205  getpkt (&rs->buf, &rs->buf_size, 0);
8206 
8207  if (rs->buf[0] == 'E')
8208  return TARGET_XFER_E_IO;
8209 
8210  /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
8211  send fewer units than we'd planned. */
8212  *xfered_len_units = (ULONGEST) units_written;
8213  return (*xfered_len_units != 0) ? TARGET_XFER_OK : TARGET_XFER_EOF;
8214 }
8215 
8216 /* Write memory data directly to the remote machine.
8217  This does not inform the data cache; the data cache uses this.
8218  MEMADDR is the address in the remote memory space.
8219  MYADDR is the address of the buffer in our space.
8220  LEN is the number of bytes.
8221 
8222  Return the transferred status, error or OK (an
8223  'enum target_xfer_status' value). Save the number of bytes
8224  transferred in *XFERED_LEN. Only transfer a single packet. */
8225 
8226 static enum target_xfer_status
8227 remote_write_bytes (CORE_ADDR memaddr, const gdb_byte *myaddr, ULONGEST len,
8228  int unit_size, ULONGEST *xfered_len)
8229 {
8230  const char *packet_format = NULL;
8231 
8232  /* Check whether the target supports binary download. */
8233  check_binary_download (memaddr);
8234 
8235  switch (packet_support (PACKET_X))
8236  {
8237  case PACKET_ENABLE:
8238  packet_format = "X";
8239  break;
8240  case PACKET_DISABLE:
8241  packet_format = "M";
8242  break;
8244  internal_error (__FILE__, __LINE__,
8245  _("remote_write_bytes: bad internal state"));
8246  default:
8247  internal_error (__FILE__, __LINE__, _("bad switch"));
8248  }
8249 
8250  return remote_write_bytes_aux (packet_format,
8251  memaddr, myaddr, len, unit_size, xfered_len,
8252  packet_format[0], 1);
8253 }
8254 
8255 /* Read memory data directly from the remote machine.
8256  This does not use the data cache; the data cache uses this.
8257  MEMADDR is the address in the remote memory space.
8258  MYADDR is the address of the buffer in our space.
8259  LEN_UNITS is the number of addressable memory units to read..
8260  UNIT_SIZE is the length in bytes of an addressable unit.
8261 
8262  Return the transferred status, error or OK (an
8263  'enum target_xfer_status' value). Save the number of bytes
8264  transferred in *XFERED_LEN_UNITS.
8265 
8266  See the comment of remote_write_bytes_aux for an example of
8267  memory read/write exchange between gdb and the stub. */
8268 
8269 static enum target_xfer_status
8270 remote_read_bytes_1 (CORE_ADDR memaddr, gdb_byte *myaddr, ULONGEST len_units,
8271  int unit_size, ULONGEST *xfered_len_units)
8272 {
8273  struct remote_state *rs = get_remote_state ();
8274  int buf_size_bytes; /* Max size of packet output buffer. */
8275  char *p;
8276  int todo_units;
8277  int decoded_bytes;
8278 
8279  buf_size_bytes = get_memory_read_packet_size ();
8280  /* The packet buffer will be large enough for the payload;
8281  get_memory_packet_size ensures this. */
8282 
8283  /* Number of units that will fit. */
8284  todo_units = std::min (len_units,
8285  (ULONGEST) (buf_size_bytes / unit_size) / 2);
8286 
8287  /* Construct "m"<memaddr>","<len>". */
8288  memaddr = remote_address_masked (memaddr);
8289  p = rs->buf;
8290  *p++ = 'm';
8291  p += hexnumstr (p, (ULONGEST) memaddr);
8292  *p++ = ',';
8293  p += hexnumstr (p, (ULONGEST) todo_units);
8294  *p = '\0';
8295  putpkt (rs->buf);
8296  getpkt (&rs->buf, &rs->buf_size, 0);
8297  if (rs->buf[0] == 'E'
8298  && isxdigit (rs->buf[1]) && isxdigit (rs->buf[2])
8299  && rs->buf[3] == '\0')
8300  return TARGET_XFER_E_IO;
8301  /* Reply describes memory byte by byte, each byte encoded as two hex
8302  characters. */
8303  p = rs->buf;
8304  decoded_bytes = hex2bin (p, myaddr, todo_units * unit_size);
8305  /* Return what we have. Let higher layers handle partial reads. */
8306  *xfered_len_units = (ULONGEST) (decoded_bytes / unit_size);
8307  return (*xfered_len_units != 0) ? TARGET_XFER_OK : TARGET_XFER_EOF;
8308 }
8309 
8310 /* Using the set of read-only target sections of remote, read live
8311  read-only memory.
8312 
8313  For interface/parameters/return description see target.h,
8314  to_xfer_partial. */
8315 
8316 static enum target_xfer_status
8318  ULONGEST memaddr, ULONGEST len,
8319  int unit_size, ULONGEST *xfered_len)
8320 {
8321  struct target_section *secp;
8322  struct target_section_table *table;
8323 
8324  secp = target_section_by_addr (ops, memaddr);
8325  if (secp != NULL
8326  && (bfd_get_section_flags (secp->the_bfd_section->owner,
8327  secp->the_bfd_section)
8328  & SEC_READONLY))
8329  {
8330  struct target_section *p;
8331  ULONGEST memend = memaddr + len;
8332 
8333  table = target_get_section_table (ops);
8334 
8335  for (p = table->sections; p < table->sections_end; p++)
8336  {
8337  if (memaddr >= p->addr)
8338  {
8339  if (memend <= p->endaddr)
8340  {
8341  /* Entire transfer is within this section. */
8342  return remote_read_bytes_1 (memaddr, readbuf, len, unit_size,
8343  xfered_len);
8344  }
8345  else if (memaddr >= p->endaddr)
8346  {
8347  /* This section ends before the transfer starts. */
8348  continue;
8349  }
8350  else
8351  {
8352  /* This section overlaps the transfer. Just do half. */
8353  len = p->endaddr - memaddr;
8354  return remote_read_bytes_1 (memaddr, readbuf, len, unit_size,
8355  xfered_len);
8356  }
8357  }
8358  }
8359  }
8360 
8361  return TARGET_XFER_EOF;
8362 }
8363 
8364 /* Similar to remote_read_bytes_1, but it reads from the remote stub
8365  first if the requested memory is unavailable in traceframe.
8366  Otherwise, fall back to remote_read_bytes_1. */
8367 
8368 static enum target_xfer_status
8370  gdb_byte *myaddr, ULONGEST len, int unit_size,
8371  ULONGEST *xfered_len)
8372 {
8373  if (len == 0)
8374  return TARGET_XFER_EOF;
8375 
8376  if (get_traceframe_number () != -1)
8377  {
8378  std::vector<mem_range> available;
8379 
8380  /* If we fail to get the set of available memory, then the
8381  target does not support querying traceframe info, and so we
8382  attempt reading from the traceframe anyway (assuming the
8383  target implements the old QTro packet then). */
8384  if (traceframe_available_memory (&available, memaddr, len))
8385  {
8386  if (available.empty () || available[0].start != memaddr)
8387  {
8388  enum target_xfer_status res;
8389 
8390  /* Don't read into the traceframe's available
8391  memory. */
8392  if (!available.empty ())
8393  {
8394  LONGEST oldlen = len;
8395 
8396  len = available[0].start - memaddr;
8397  gdb_assert (len <= oldlen);
8398  }
8399 
8400  /* This goes through the topmost target again. */
8401  res = remote_xfer_live_readonly_partial (ops, myaddr, memaddr,
8402  len, unit_size, xfered_len);
8403  if (res == TARGET_XFER_OK)
8404  return TARGET_XFER_OK;
8405  else
8406  {
8407  /* No use trying further, we know some memory starting
8408  at MEMADDR isn't available. */
8409  *xfered_len = len;
8410  return (*xfered_len != 0) ?
8412  }
8413  }
8414 
8415  /* Don't try to read more than how much is available, in
8416  case the target implements the deprecated QTro packet to
8417  cater for older GDBs (the target's knowledge of read-only
8418  sections may be outdated by now). */
8419  len = available[0].length;
8420  }
8421  }
8422 
8423  return remote_read_bytes_1 (memaddr, myaddr, len, unit_size, xfered_len);
8424 }
8425 
8426 
8427 
8428 /* Sends a packet with content determined by the printf format string
8429  FORMAT and the remaining arguments, then gets the reply. Returns
8430  whether the packet was a success, a failure, or unknown. */
8431 
8432 static enum packet_result remote_send_printf (const char *format, ...)
8433  ATTRIBUTE_PRINTF (1, 2);
8434 
8435 static enum packet_result
8436 remote_send_printf (const char *format, ...)
8437 {
8438  struct remote_state *rs = get_remote_state ();
8439  int max_size = get_remote_packet_size ();
8440  va_list ap;
8441 
8442  va_start (ap, format);
8443 
8444  rs->buf[0] = '\0';
8445  if (vsnprintf (rs->buf, max_size, format, ap) >= max_size)
8446  internal_error (__FILE__, __LINE__, _("Too long remote packet."));
8447 
8448  if (putpkt (rs->buf) < 0)
8449  error (_("Communication problem with target."));
8450 
8451  rs->buf[0] = '\0';
8452  getpkt (&rs->buf, &rs->buf_size, 0);
8453 
8454  return packet_check_result (rs->buf);
8455 }
8456 
8457 /* Flash writing can take quite some time. We'll set
8458  effectively infinite timeout for flash operations.
8459  In future, we'll need to decide on a better approach. */
8460 static const int remote_flash_timeout = 1000;
8461 
8462 static void
8464  ULONGEST address, LONGEST length)
8465 {
8466  int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
8467  enum packet_result ret;
8468  scoped_restore restore_timeout
8470 
8471  ret = remote_send_printf ("vFlashErase:%s,%s",
8472  phex (address, addr_size),
8473  phex (length, 4));
8474  switch (ret)
8475  {
8476  case PACKET_UNKNOWN:
8477  error (_("Remote target does not support flash erase"));
8478  case PACKET_ERROR:
8479  error (_("Error erasing flash with vFlashErase packet"));
8480  default:
8481  break;
8482  }
8483 }
8484 
8485 static enum target_xfer_status
8487  ULONGEST length, ULONGEST *xfered_len,
8488  const gdb_byte *data)
8489 {
8490  scoped_restore restore_timeout
8492  return remote_write_bytes_aux ("vFlashWrite:", address, data, length, 1,
8493  xfered_len,'X', 0);
8494 }
8495 
8496 static void
8498 {
8499  int ret;
8500 
8501  scoped_restore restore_timeout
8503 
8504  ret = remote_send_printf ("vFlashDone");
8505 
8506  switch (ret)
8507  {
8508  case PACKET_UNKNOWN:
8509  error (_("Remote target does not support vFlashDone"));
8510  case PACKET_ERROR:
8511  error (_("Error finishing flash operation"));
8512  default:
8513  break;
8514  }
8515 }
8516 
8517 static void
8519 {
8520  puts_filtered ("Debugging a target over a serial line.\n");
8521 }
8522 
8523 /* Stuff for dealing with the packets which are part of this protocol.
8524  See comment at top of file for details. */
8525 
8526 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
8527  error to higher layers. Called when a serial error is detected.
8528  The exception message is STRING, followed by a colon and a blank,
8529  the system error message for errno at function entry and final dot
8530  for output compatibility with throw_perror_with_name. */
8531 
8532 static void
8533 unpush_and_perror (const char *string)
8534 {
8535  int saved_errno = errno;
8536 
8538  throw_error (TARGET_CLOSE_ERROR, "%s: %s.", string,
8539  safe_strerror (saved_errno));
8540 }
8541 
8542 /* Read a single character from the remote end. The current quit
8543  handler is overridden to avoid quitting in the middle of packet
8544  sequence, as that would break communication with the remote server.
8545  See remote_serial_quit_handler for more detail. */
8546 
8547 static int
8548 readchar (int timeout)
8549 {
8550  int ch;
8551  struct remote_state *rs = get_remote_state ();
8552 
8553  {
8554  scoped_restore restore_quit
8556 
8557  rs->got_ctrlc_during_io = 0;
8558 
8559  ch = serial_readchar (rs->remote_desc, timeout);
8560 
8561  if (rs->got_ctrlc_during_io)
8562  set_quit_flag ();
8563  }
8564 
8565  if (ch >= 0)
8566  return ch;
8567 
8568  switch ((enum serial_rc) ch)
8569  {
8570  case SERIAL_EOF:
8572  throw_error (TARGET_CLOSE_ERROR, _("Remote connection closed"));
8573  /* no return */
8574  case SERIAL_ERROR:
8575  unpush_and_perror (_("Remote communication error. "
8576  "Target disconnected."));
8577  /* no return */
8578  case SERIAL_TIMEOUT:
8579  break;
8580  }
8581  return ch;
8582 }
8583 
8584 /* Wrapper for serial_write that closes the target and throws if
8585  writing fails. The current quit handler is overridden to avoid
8586  quitting in the middle of packet sequence, as that would break
8587  communication with the remote server. See
8588  remote_serial_quit_handler for more detail. */
8589 
8590 static void
8591 remote_serial_write (const char *str, int len)
8592 {
8593  struct remote_state *rs = get_remote_state ();
8594 
8595  scoped_restore restore_quit
8597 
8598  rs->got_ctrlc_during_io = 0;
8599 
8600  if (serial_write (rs->remote_desc, str, len))
8601  {
8602  unpush_and_perror (_("Remote communication error. "
8603  "Target disconnected."));
8604  }
8605 
8606  if (rs->got_ctrlc_during_io)
8607  set_quit_flag ();
8608 }
8609 
8610 /* Send the command in *BUF to the remote machine, and read the reply
8611  into *BUF. Report an error if we get an error reply. Resize
8612  *BUF using xrealloc if necessary to hold the result, and update
8613  *SIZEOF_BUF. */
8614 
8615 static void
8617  long *sizeof_buf)
8618 {
8619  putpkt (*buf);
8620  getpkt (buf, sizeof_buf, 0);
8621 
8622  if ((*buf)[0] == 'E')
8623  error (_("Remote failure reply: %s"), *buf);
8624 }
8625 
8626 /* Return a string representing an escaped version of BUF, of len N.
8627  E.g. \n is converted to \\n, \t to \\t, etc. */
8628 
8629 static std::string
8630 escape_buffer (const char *buf, int n)
8631 {
8632  string_file stb;
8633 
8634  stb.putstrn (buf, n, '\\');
8635  return std::move (stb.string ());
8636 }
8637 
8638 /* Display a null-terminated packet on stdout, for debugging, using C
8639  string notation. */
8640 
8641 static void
8642 print_packet (const char *buf)
8643 {
8644  puts_filtered ("\"");
8646  puts_filtered ("\"");
8647 }
8648 
8649 int
8650 putpkt (const char *buf)
8651 {
8652  return putpkt_binary (buf, strlen (buf));
8653 }
8654 
8655 /* Send a packet to the remote machine, with error checking. The data
8656  of the packet is in BUF. The string in BUF can be at most
8657  get_remote_packet_size () - 5 to account for the $, # and checksum,
8658  and for a possible /0 if we are debugging (remote_debug) and want
8659  to print the sent packet as a string. */
8660 
8661 static int
8662 putpkt_binary (const char *buf, int cnt)
8663 {
8664  struct remote_state *rs = get_remote_state ();
8665  int i;
8666  unsigned char csum = 0;
8667  gdb::def_vector<char> data (cnt + 6);
8668  char *buf2 = data.data ();
8669 
8670  int ch;
8671  int tcount = 0;
8672  char *p;
8673 
8674  /* Catch cases like trying to read memory or listing threads while
8675  we're waiting for a stop reply. The remote server wouldn't be
8676  ready to handle this request, so we'd hang and timeout. We don't
8677  have to worry about this in synchronous mode, because in that
8678  case it's not possible to issue a command while the target is
8679  running. This is not a problem in non-stop mode, because in that
8680  case, the stub is always ready to process serial input. */
8681  if (!target_is_non_stop_p ()
8682  && target_is_async_p ()
8683  && rs->waiting_for_stop_reply)
8684  {
8685  error (_("Cannot execute this command while the target is running.\n"
8686  "Use the \"interrupt\" command to stop the target\n"
8687  "and then try again."));
8688  }
8689 
8690  /* We're sending out a new packet. Make sure we don't look at a
8691  stale cached response. */
8692  rs->cached_wait_status = 0;
8693 
8694  /* Copy the packet into buffer BUF2, encapsulating it
8695  and giving it a checksum. */
8696 
8697  p = buf2;
8698  *p++ = '$';
8699 
8700  for (i = 0; i < cnt; i++)
8701  {
8702  csum += buf[i];
8703  *p++ = buf[i];
8704  }
8705  *p++ = '#';
8706  *p++ = tohex ((csum >> 4) & 0xf);
8707  *p++ = tohex (csum & 0xf);
8708 
8709  /* Send it over and over until we get a positive ack. */
8710 
8711  while (1)
8712  {
8713  int started_error_output = 0;
8714 
8715  if (remote_debug)
8716  {
8717  *p = '\0';
8718 
8719  int len = (int) (p - buf2);
8720 
8721  std::string str
8722  = escape_buffer (buf2, std::min (len, REMOTE_DEBUG_MAX_CHAR));
8723 
8724  fprintf_unfiltered (gdb_stdlog, "Sending packet: %s", str.c_str ());
8725 
8726  if (str.length () > REMOTE_DEBUG_MAX_CHAR)
8727  {
8728  fprintf_unfiltered (gdb_stdlog, "[%zu bytes omitted]",
8729  str.length () - REMOTE_DEBUG_MAX_CHAR);
8730  }
8731 
8732  fprintf_unfiltered (gdb_stdlog, "...");
8733 
8735  }
8736  remote_serial_write (buf2, p - buf2);
8737 
8738  /* If this is a no acks version of the remote protocol, send the
8739  packet and move on. */
8740  if (rs->noack_mode)
8741  break;
8742 
8743  /* Read until either a timeout occurs (-2) or '+' is read.
8744  Handle any notification that arrives in the mean time. */
8745  while (1)
8746  {
8747  ch = readchar (remote_timeout);
8748 
8749  if (remote_debug)
8750  {
8751  switch (ch)
8752  {
8753  case '+':
8754  case '-':
8755  case SERIAL_TIMEOUT:
8756  case '$':
8757  case '%':
8758  if (started_error_output)
8759  {
8760  putchar_unfiltered ('\n');
8761  started_error_output = 0;
8762  }
8763  }
8764  }
8765 
8766  switch (ch)
8767  {
8768  case '+':
8769  if (remote_debug)
8770  fprintf_unfiltered (gdb_stdlog, "Ack\n");
8771  return 1;
8772  case '-':
8773  if (remote_debug)
8774  fprintf_unfiltered (gdb_stdlog, "Nak\n");
8775  /* FALLTHROUGH */
8776  case SERIAL_TIMEOUT:
8777  tcount++;
8778  if (tcount > 3)
8779  return 0;
8780  break; /* Retransmit buffer. */
8781  case '$':
8782  {
8783  if (remote_debug)
8785  "Packet instead of Ack, ignoring it\n");
8786  /* It's probably an old response sent because an ACK
8787  was lost. Gobble up the packet and ack it so it
8788  doesn't get retransmitted when we resend this
8789  packet. */
8790  skip_frame ();
8791  remote_serial_write ("+", 1);
8792  continue; /* Now, go look for +. */
8793  }
8794 
8795  case '%':
8796  {
8797  int val;
8798 
8799  /* If we got a notification, handle it, and go back to looking
8800  for an ack. */
8801  /* We've found the start of a notification. Now
8802  collect the data. */
8803  val = read_frame (&rs->buf, &rs->buf_size);
8804  if (val >= 0)
8805  {
8806  if (remote_debug)
8807  {
8808  std::string str = escape_buffer (rs->buf, val);
8809 
8811  " Notification received: %s\n",
8812  str.c_str ());
8813  }
8814  handle_notification (rs->notif_state, rs->buf);
8815  /* We're in sync now, rewait for the ack. */
8816  tcount = 0;
8817  }
8818  else
8819  {
8820  if (remote_debug)
8821  {
8822  if (!started_error_output)
8823  {
8824  started_error_output = 1;
8825  fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
8826  }
8827  fputc_unfiltered (ch & 0177, gdb_stdlog);
8828  fprintf_unfiltered (gdb_stdlog, "%s", rs->buf);
8829  }
8830  }
8831  continue;
8832  }
8833  /* fall-through */
8834  default:
8835  if (remote_debug)
8836  {
8837  if (!started_error_output)
8838  {
8839  started_error_output = 1;
8840  fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
8841  }
8842  fputc_unfiltered (ch & 0177, gdb_stdlog);
8843  }
8844  continue;
8845  }
8846  break; /* Here to retransmit. */
8847  }
8848 
8849 #if 0
8850  /* This is wrong. If doing a long backtrace, the user should be
8851  able to get out next time we call QUIT, without anything as
8852  violent as interrupt_query. If we want to provide a way out of
8853  here without getting to the next QUIT, it should be based on
8854  hitting ^C twice as in remote_wait. */
8855  if (quit_flag)
8856  {
8857  quit_flag = 0;
8858  interrupt_query ();
8859  }
8860 #endif
8861  }
8862 
8863  return 0;
8864 }
8865 
8866 /* Come here after finding the start of a frame when we expected an
8867  ack. Do our best to discard the rest of this packet. */
8868 
8869 static void
8871 {
8872  int c;
8873 
8874  while (1)
8875  {
8876  c = readchar (remote_timeout);
8877  switch (c)
8878  {
8879  case SERIAL_TIMEOUT:
8880  /* Nothing we can do. */
8881  return;
8882  case '#':
8883  /* Discard the two bytes of checksum and stop. */
8884  c = readchar (remote_timeout);
8885  if (c >= 0)
8886  c = readchar (remote_timeout);
8887 
8888  return;
8889  case '*': /* Run length encoding. */
8890  /* Discard the repeat count. */
8891  c = readchar (remote_timeout);
8892  if (c < 0)
8893  return;
8894  break;
8895  default:
8896  /* A regular character. */
8897  break;
8898  }
8899  }
8900 }
8901 
8902 /* Come here after finding the start of the frame. Collect the rest
8903  into *BUF, verifying the checksum, length, and handling run-length
8904  compression. NUL terminate the buffer. If there is not enough room,
8905  expand *BUF using xrealloc.
8906 
8907  Returns -1 on error, number of characters in buffer (ignoring the
8908  trailing NULL) on success. (could be extended to return one of the
8909  SERIAL status indications). */
8910 
8911 static long
8912 read_frame (char **buf_p,
8913  long *sizeof_buf)
8914 {
8915  unsigned char csum;
8916  long bc;
8917  int c;
8918  char *buf = *buf_p;
8919  struct remote_state *rs = get_remote_state ();
8920 
8921  csum = 0;
8922  bc = 0;
8923 
8924  while (1)
8925  {
8926  c = readchar (remote_timeout);
8927  switch (c)
8928  {
8929  case SERIAL_TIMEOUT:
8930  if (remote_debug)
8931  fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
8932  return -1;
8933  case '$':
8934  if (remote_debug)
8935  fputs_filtered ("Saw new packet start in middle of old one\n",
8936  gdb_stdlog);
8937  return -1; /* Start a new packet, count retries. */
8938  case '#':
8939  {
8940  unsigned char pktcsum;
8941  int check_0 = 0;
8942  int check_1 = 0;
8943 
8944  buf[bc] = '\0';
8945 
8946  check_0 = readchar (remote_timeout);
8947  if (check_0 >= 0)
8948  check_1 = readchar (remote_timeout);
8949 
8950  if (check_0 == SERIAL_TIMEOUT || check_1 == SERIAL_TIMEOUT)
8951  {
8952  if (remote_debug)
8953  fputs_filtered ("Timeout in checksum, retrying\n",
8954  gdb_stdlog);
8955  return -1;
8956  }
8957  else if (check_0 < 0 || check_1 < 0)
8958  {
8959  if (remote_debug)
8960  fputs_filtered ("Communication error in checksum\n",
8961  gdb_stdlog);
8962  return -1;
8963  }
8964 
8965  /* Don't recompute the checksum; with no ack packets we
8966  don't have any way to indicate a packet retransmission
8967  is necessary. */
8968  if (rs->noack_mode)
8969  return bc;
8970 
8971  pktcsum = (fromhex (check_0) << 4) | fromhex (check_1);
8972  if (csum == pktcsum)
8973  return bc;
8974 
8975  if (remote_debug)
8976  {
8977  std::string str = escape_buffer (buf, bc);
8978 
8980  "Bad checksum, sentsum=0x%x, "
8981  "csum=0x%x, buf=%s\n",
8982  pktcsum, csum, str.c_str ());
8983  }
8984  /* Number of characters in buffer ignoring trailing
8985  NULL. */
8986  return -1;
8987  }
8988  case '*': /* Run length encoding. */
8989  {
8990  int repeat;
8991 
8992  csum += c;
8993  c = readchar (remote_timeout);
8994  csum += c;
8995  repeat = c - ' ' + 3; /* Compute repeat count. */
8996 
8997  /* The character before ``*'' is repeated. */
8998 
8999  if (repeat > 0 && repeat <= 255 && bc > 0)
9000  {
9001  if (bc + repeat - 1 >= *sizeof_buf - 1)
9002  {
9003  /* Make some more room in the buffer. */
9004  *sizeof_buf += repeat;
9005  *buf_p = (char *) xrealloc (*buf_p, *sizeof_buf);
9006  buf = *buf_p;
9007  }
9008 
9009  memset (&buf[bc], buf[bc - 1], repeat);
9010  bc += repeat;
9011  continue;
9012  }
9013 
9014  buf[bc] = '\0';
9015  printf_filtered (_("Invalid run length encoding: %s\n"), buf);
9016  return -1;
9017  }
9018  default:
9019  if (bc >= *sizeof_buf - 1)
9020  {
9021  /* Make some more room in the buffer. */
9022  *sizeof_buf *= 2;
9023  *buf_p = (char *) xrealloc (*buf_p, *sizeof_buf);
9024  buf = *buf_p;
9025  }
9026 
9027  buf[bc++] = c;
9028  csum += c;
9029  continue;
9030  }
9031  }
9032 }
9033 
9034 /* Read a packet from the remote machine, with error checking, and
9035  store it in *BUF. Resize *BUF using xrealloc if necessary to hold
9036  the result, and update *SIZEOF_BUF. If FOREVER, wait forever
9037  rather than timing out; this is used (in synchronous mode) to wait
9038  for a target that is is executing user code to stop. */
9039 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
9040  don't have to change all the calls to getpkt to deal with the
9041  return value, because at the moment I don't know what the right
9042  thing to do it for those. */
9043 void
9044 getpkt (char **buf,
9045  long *sizeof_buf,
9046  int forever)
9047 {
9048  getpkt_sane (buf, sizeof_buf, forever);
9049 }
9050 
9051 
9052 /* Read a packet from the remote machine, with error checking, and
9053  store it in *BUF. Resize *BUF using xrealloc if necessary to hold
9054  the result, and update *SIZEOF_BUF. If FOREVER, wait forever
9055  rather than timing out; this is used (in synchronous mode) to wait
9056  for a target that is is executing user code to stop. If FOREVER ==
9057  0, this function is allowed to time out gracefully and return an
9058  indication of this to the caller. Otherwise return the number of
9059  bytes read. If EXPECTING_NOTIF, consider receiving a notification
9060  enough reason to return to the caller. *IS_NOTIF is an output
9061  boolean that indicates whether *BUF holds a notification or not
9062  (a regular packet). */
9063 
9064 static int
9065 getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever,
9066  int expecting_notif, int *is_notif)
9067 {
9068  struct remote_state *rs = get_remote_state ();
9069  int c;
9070  int tries;
9071  int timeout;
9072  int val = -1;
9073 
9074  /* We're reading a new response. Make sure we don't look at a
9075  previously cached response. */
9076  rs->cached_wait_status = 0;
9077 
9078  strcpy (*buf, "timeout");
9079 
9080  if (forever)
9081  timeout = watchdog > 0 ? watchdog : -1;
9082  else if (expecting_notif)
9083  timeout = 0; /* There should already be a char in the buffer. If
9084  not, bail out. */
9085  else
9086  timeout = remote_timeout;
9087 
9088 #define MAX_TRIES 3
9089 
9090  /* Process any number of notifications, and then return when
9091  we get a packet. */
9092  for (;;)
9093  {
9094  /* If we get a timeout or bad checksum, retry up to MAX_TRIES
9095  times. */
9096  for (tries = 1; tries <= MAX_TRIES; tries++)
9097  {
9098  /* This can loop forever if the remote side sends us
9099  characters continuously, but if it pauses, we'll get
9100  SERIAL_TIMEOUT from readchar because of timeout. Then
9101  we'll count that as a retry.
9102 
9103  Note that even when forever is set, we will only wait
9104  forever prior to the start of a packet. After that, we
9105  expect characters to arrive at a brisk pace. They should
9106  show up within remote_timeout intervals. */
9107  do
9108  c = readchar (timeout);
9109  while (c != SERIAL_TIMEOUT && c != '$' && c != '%');
9110 
9111  if (c == SERIAL_TIMEOUT)
9112  {
9113  if (expecting_notif)
9114  return -1; /* Don't complain, it's normal to not get
9115  anything in this case. */
9116 
9117  if (forever) /* Watchdog went off? Kill the target. */
9118  {
9121  _("Watchdog timeout has expired. "
9122  "Target detached."));
9123  }
9124  if (remote_debug)
9125  fputs_filtered ("Timed out.\n", gdb_stdlog);
9126  }
9127  else
9128  {
9129  /* We've found the start of a packet or notification.
9130  Now collect the data. */
9131  val = read_frame (buf, sizeof_buf);
9132  if (val >= 0)
9133  break;
9134  }
9135 
9136  remote_serial_write ("-", 1);
9137  }
9138 
9139  if (tries > MAX_TRIES)
9140  {
9141  /* We have tried hard enough, and just can't receive the
9142  packet/notification. Give up. */
9143  printf_unfiltered (_("Ignoring packet error, continuing...\n"));
9144 
9145  /* Skip the ack char if we're in no-ack mode. */
9146  if (!rs->noack_mode)
9147  remote_serial_write ("+", 1);
9148  return -1;
9149  }
9150 
9151  /* If we got an ordinary packet, return that to our caller. */
9152  if (c == '$')
9153  {
9154  if (remote_debug)
9155  {
9156  std::string str
9157  = escape_buffer (*buf,
9158  std::min (val, REMOTE_DEBUG_MAX_CHAR));
9159 
9160  fprintf_unfiltered (gdb_stdlog, "Packet received: %s",
9161  str.c_str ());
9162 
9163  if (str.length () > REMOTE_DEBUG_MAX_CHAR)
9164  {
9165  fprintf_unfiltered (gdb_stdlog, "[%zu bytes omitted]",
9166  str.length () - REMOTE_DEBUG_MAX_CHAR);
9167  }
9168 
9170  }
9171 
9172  /* Skip the ack char if we're in no-ack mode. */
9173  if (!rs->noack_mode)
9174  remote_serial_write ("+", 1);
9175  if (is_notif != NULL)
9176  *is_notif = 0;
9177  return val;
9178  }
9179 
9180  /* If we got a notification, handle it, and go back to looking
9181  for a packet. */
9182  else
9183  {
9184  gdb_assert (c == '%');
9185 
9186  if (remote_debug)
9187  {
9188  std::string str = escape_buffer (*buf, val);
9189 
9191  " Notification received: %s\n",
9192  str.c_str ());
9193  }
9194  if (is_notif != NULL)
9195  *is_notif = 1;
9196 
9198 
9199  /* Notifications require no acknowledgement. */
9200 
9201  if (expecting_notif)
9202  return val;
9203  }
9204  }
9205 }
9206 
9207 static int
9208 getpkt_sane (char **buf, long *sizeof_buf, int forever)
9209 {
9210  return getpkt_or_notif_sane_1 (buf, sizeof_buf, forever, 0, NULL);
9211 }
9212 
9213 static int
9214 getpkt_or_notif_sane (char **buf, long *sizeof_buf, int forever,
9215  int *is_notif)
9216 {
9217  return getpkt_or_notif_sane_1 (buf, sizeof_buf, forever, 1,
9218  is_notif);
9219 }
9220 
9221 /* Check whether EVENT is a fork event for the process specified
9222  by the pid passed in DATA, and if it is, kill the fork child. */
9223 
9224 static int
9226  QUEUE_ITER (stop_reply_p) *iter,
9227  stop_reply_p event,
9228  void *data)
9229 {
9230  struct queue_iter_param *param = (struct queue_iter_param *) data;
9231  int parent_pid = *(int *) param->input;
9232 
9233  if (is_pending_fork_parent (&event->ws, parent_pid, event->ptid))
9234  {
9235  struct remote_state *rs = get_remote_state ();
9236  int child_pid = ptid_get_pid (event->ws.value.related_pid);
9237  int res;
9238 
9239  res = remote_vkill (child_pid, rs);
9240  if (res != 0)
9241  error (_("Can't kill fork child process %d"), child_pid);
9242  }
9243 
9244  return 1;
9245 }
9246 
9247 /* Kill any new fork children of process PID that haven't been
9248  processed by follow_fork. */
9249 
9250 static void
9252 {
9253  struct thread_info *thread;
9254  struct notif_client *notif = &notif_client_stop;
9255  struct queue_iter_param param;
9256 
9257  /* Kill the fork child threads of any threads in process PID
9258  that are stopped at a fork event. */
9259  ALL_NON_EXITED_THREADS (thread)
9260  {
9261  struct target_waitstatus *ws = &thread->pending_follow;
9262 
9263  if (is_pending_fork_parent (ws, pid, thread->ptid))
9264  {
9265  struct remote_state *rs = get_remote_state ();
9266  int child_pid = ptid_get_pid (ws->value.related_pid);
9267  int res;
9268 
9269  res = remote_vkill (child_pid, rs);
9270  if (res != 0)
9271  error (_("Can't kill fork child process %d"), child_pid);
9272  }
9273  }
9274 
9275  /* Check for any pending fork events (not reported or processed yet)
9276  in process PID and kill those fork child threads as well. */
9278  param.input = &pid;
9279  param.output = NULL;
9280  QUEUE_iterate (stop_reply_p, stop_reply_queue,
9281  kill_child_of_pending_fork, &param);
9282 }
9283 
9284 
9285 /* Target hook to kill the current inferior. */
9286 
9287 static void
9289 {
9290  int res = -1;
9291  int pid = ptid_get_pid (inferior_ptid);
9292  struct remote_state *rs = get_remote_state ();
9293 
9295  {
9296  /* If we're stopped while forking and we haven't followed yet,
9297  kill the child task. We need to do this before killing the
9298  parent task because if this is a vfork then the parent will
9299  be sleeping. */
9301 
9302  res = remote_vkill (pid, rs);
9303  if (res == 0)
9304  {
9306  return;
9307  }
9308  }
9309 
9310  /* If we are in 'target remote' mode and we are killing the only
9311  inferior, then we will tell gdbserver to exit and unpush the
9312  target. */
9313  if (res == -1 && !remote_multi_process_p (rs)
9314  && number_of_live_inferiors () == 1)
9315  {
9316  remote_kill_k ();
9317 
9318  /* We've killed the remote end, we get to mourn it. If we are
9319  not in extended mode, mourning the inferior also unpushes
9320  remote_ops from the target stack, which closes the remote
9321  connection. */
9323 
9324  return;
9325  }
9326 
9327  error (_("Can't kill process"));
9328 }
9329 
9330 /* Send a kill request to the target using the 'vKill' packet. */
9331 
9332 static int
9333 remote_vkill (int pid, struct remote_state *rs)
9334 {
9336  return -1;
9337 
9338  /* Tell the remote target to detach. */
9339  xsnprintf (rs->buf, get_remote_packet_size (), "vKill;%x", pid);
9340  putpkt (rs->buf);
9341  getpkt (&rs->buf, &rs->buf_size, 0);
9342 
9343  switch (packet_ok (rs->buf,
9345  {
9346  case PACKET_OK:
9347  return 0;
9348  case PACKET_ERROR:
9349  return 1;
9350  case PACKET_UNKNOWN:
9351  return -1;
9352  default:
9353  internal_error (__FILE__, __LINE__, _("Bad result from packet_ok"));
9354  }
9355 }
9356 
9357 /* Send a kill request to the target using the 'k' packet. */
9358 
9359 static void
9361 {
9362  /* Catch errors so the user can quit from gdb even when we
9363  aren't on speaking terms with the remote system. */
9364  TRY
9365  {
9366  putpkt ("k");
9367  }
9368  CATCH (ex, RETURN_MASK_ERROR)
9369  {
9370  if (ex.error == TARGET_CLOSE_ERROR)
9371  {
9372  /* If we got an (EOF) error that caused the target
9373  to go away, then we're done, that's what we wanted.
9374  "k" is susceptible to cause a premature EOF, given
9375  that the remote server isn't actually required to
9376  reply to "k", and it can happen that it doesn't
9377  even get to reply ACK to the "k". */
9378  return;
9379  }
9380 
9381  /* Otherwise, something went wrong. We didn't actually kill
9382  the target. Just propagate the exception, and let the
9383  user or higher layers decide what to do. */
9384  throw_exception (ex);
9385  }
9386  END_CATCH
9387 }
9388 
9389 static void
9390 remote_mourn (struct target_ops *target)
9391 {
9392  struct remote_state *rs = get_remote_state ();
9393 
9394  /* In 'target remote' mode with one inferior, we close the connection. */
9395  if (!rs->extended && number_of_live_inferiors () <= 1)
9396  {
9397  unpush_target (target);
9398 
9399  /* remote_close takes care of doing most of the clean up. */
9401  return;
9402  }
9403 
9404  /* In case we got here due to an error, but we're going to stay
9405  connected. */
9406  rs->waiting_for_stop_reply = 0;
9407 
9408  /* If the current general thread belonged to the process we just
9409  detached from or has exited, the remote side current general
9410  thread becomes undefined. Considering a case like this:
9411 
9412  - We just got here due to a detach.
9413  - The process that we're detaching from happens to immediately
9414  report a global breakpoint being hit in non-stop mode, in the
9415  same thread we had selected before.
9416  - GDB attaches to this process again.
9417  - This event happens to be the next event we handle.
9418 
9419  GDB would consider that the current general thread didn't need to
9420  be set on the stub side (with Hg), since for all it knew,
9421  GENERAL_THREAD hadn't changed.
9422 
9423  Notice that although in all-stop mode, the remote server always
9424  sets the current thread to the thread reporting the stop event,
9425  that doesn't happen in non-stop mode; in non-stop, the stub *must
9426  not* change the current thread when reporting a breakpoint hit,
9427  due to the decoupling of event reporting and event handling.
9428 
9429  To keep things simple, we always invalidate our notion of the
9430  current thread. */
9432 
9433  /* Call common code to mark the inferior as not running. */
9435 
9436  if (!have_inferiors ())
9437  {
9438  if (!remote_multi_process_p (rs))
9439  {
9440  /* Check whether the target is running now - some remote stubs
9441  automatically restart after kill. */
9442  putpkt ("?");
9443  getpkt (&rs->buf, &rs->buf_size, 0);
9444 
9445  if (rs->buf[0] == 'S' || rs->buf[0] == 'T')
9446  {
9447  /* Assume that the target has been restarted. Set
9448  inferior_ptid so that bits of core GDB realizes
9449  there's something here, e.g., so that the user can
9450  say "kill" again. */
9452  }
9453  }
9454  }
9455 }
9456 
9457 static int
9459 {
9461 }
9462 
9463 static void
9465 {
9466  struct remote_state *rs = get_remote_state ();
9467  char *reply;
9468 
9469  xsnprintf (rs->buf, get_remote_packet_size (), "QDisableRandomization:%x",
9470  val);
9471  putpkt (rs->buf);
9472  reply = remote_get_noisy_reply ();
9473  if (*reply == '\0')
9474  error (_("Target does not support QDisableRandomization."));
9475  if (strcmp (reply, "OK") != 0)
9476  error (_("Bogus QDisableRandomization reply from target: %s"), reply);
9477 }
9478 
9479 static int
9481 {
9482  struct remote_state *rs = get_remote_state ();
9483  int len;
9484  const char *remote_exec_file = get_remote_exec_file ();
9485 
9486  /* If the user has disabled vRun support, or we have detected that
9487  support is not available, do not try it. */
9489  return -1;
9490 
9491  strcpy (rs->buf, "vRun;");
9492  len = strlen (rs->buf);
9493 
9494  if (strlen (remote_exec_file) * 2 + len >= get_remote_packet_size ())
9495  error (_("Remote file name too long for run packet"));
9496  len += 2 * bin2hex ((gdb_byte *) remote_exec_file, rs->buf + len,
9497  strlen (remote_exec_file));
9498 
9499  if (!args.empty ())
9500  {
9501  int i;
9502 
9503  gdb_argv argv (args.c_str ());
9504  for (i = 0; argv[i] != NULL; i++)
9505  {
9506  if (strlen (argv[i]) * 2 + 1 + len >= get_remote_packet_size ())
9507  error (_("Argument list too long for run packet"));
9508  rs->buf[len++] = ';';
9509  len += 2 * bin2hex ((gdb_byte *) argv[i], rs->buf + len,
9510  strlen (argv[i]));
9511  }
9512  }
9513 
9514  rs->buf[len++] = '\0';
9515 
9516  putpkt (rs->buf);
9517  getpkt (&rs->buf, &rs->buf_size, 0);
9518 
9520  {
9521  case PACKET_OK:
9522  /* We have a wait response. All is well. */
9523  return 0;
9524  case PACKET_UNKNOWN:
9525  return -1;
9526  case PACKET_ERROR:
9527  if (remote_exec_file[0] == '\0')
9528  error (_("Running the default executable on the remote target failed; "
9529  "try \"set remote exec-file\"?"));
9530  else
9531  error (_("Running \"%s\" on the remote target failed"),
9532  remote_exec_file);
9533  default:
9534  gdb_assert_not_reached (_("bad switch"));
9535  }
9536 }
9537 
9538 /* Helper function to send set/unset environment packets. ACTION is
9539  either "set" or "unset". PACKET is either "QEnvironmentHexEncoded"
9540  or "QEnvironmentUnsetVariable". VALUE is the variable to be
9541  sent. */
9542 
9543 static void
9545  const char *action,
9546  const char *packet,
9547  const char *value)
9548 {
9549  /* Convert the environment variable to an hex string, which
9550  is the best format to be transmitted over the wire. */
9551  std::string encoded_value = bin2hex ((const gdb_byte *) value,
9552  strlen (value));
9553 
9555  "%s:%s", packet, encoded_value.c_str ());
9556 
9557  putpkt (rs->buf);
9558  getpkt (&rs->buf, &rs->buf_size, 0);
9559  if (strcmp (rs->buf, "OK") != 0)
9560  warning (_("Unable to %s environment variable '%s' on remote."),
9561  action, value);
9562 }
9563 
9564 /* Helper function to handle the QEnvironment* packets. */
9565 
9566 static void
9568 {
9570  {
9571  putpkt ("QEnvironmentReset");
9572  getpkt (&rs->buf, &rs->buf_size, 0);
9573  if (strcmp (rs->buf, "OK") != 0)
9574  warning (_("Unable to reset environment on remote."));
9575  }
9576 
9578 
9580  for (const std::string &el : e->user_set_env ())
9581  send_environment_packet (rs, "set", "QEnvironmentHexEncoded",
9582  el.c_str ());
9583 
9585  for (const std::string &el : e->user_unset_env ())
9586  send_environment_packet (rs, "unset", "QEnvironmentUnset", el.c_str ());
9587 }
9588 
9589 /* Helper function to set the current working directory for the
9590  inferior in the remote target. */
9591 
9592 static void
9594 {
9596  {
9597  const char *inferior_cwd = get_inferior_cwd ();
9598 
9599  if (inferior_cwd != NULL)
9600  {
9601  std::string hexpath = bin2hex ((const gdb_byte *) inferior_cwd,
9602  strlen (inferior_cwd));
9603 
9605  "QSetWorkingDir:%s", hexpath.c_str ());
9606  }
9607  else
9608  {
9609  /* An empty inferior_cwd means that the user wants us to
9610  reset the remote server's inferior's cwd. */
9612  "QSetWorkingDir:");
9613  }
9614 
9615  putpkt (rs->buf);
9616  getpkt (&rs->buf, &rs->buf_size, 0);
9617  if (packet_ok (rs->buf,
9619  != PACKET_OK)
9620  error (_("\
9621 Remote replied unexpectedly while setting the inferior's working\n\
9622 directory: %s"),
9623  rs->buf);
9624 
9625  }
9626 }
9627 
9628 /* In the extended protocol we want to be able to do things like
9629  "run" and have them basically work as expected. So we need
9630  a special create_inferior function. We support changing the
9631  executable file and the command line arguments, but not the
9632  environment. */
9633 
9634 static void
9636  const char *exec_file,
9637  const std::string &args,
9638  char **env, int from_tty)
9639 {
9640  int run_worked;
9641  char *stop_reply;
9642  struct remote_state *rs = get_remote_state ();
9643  const char *remote_exec_file = get_remote_exec_file ();
9644 
9645  /* If running asynchronously, register the target file descriptor
9646  with the event loop. */
9647  if (target_can_async_p ())
9648  target_async (1);
9649 
9650  /* Disable address space randomization if requested (and supported). */
9653 
9654  /* If startup-with-shell is on, we inform gdbserver to start the
9655  remote inferior using a shell. */
9657  {
9659  "QStartupWithShell:%d", startup_with_shell ? 1 : 0);
9660  putpkt (rs->buf);
9661  getpkt (&rs->buf, &rs->buf_size, 0);
9662  if (strcmp (rs->buf, "OK") != 0)
9663  error (_("\
9664 Remote replied unexpectedly while setting startup-with-shell: %s"),
9665  rs->buf);
9666  }
9667 
9669 
9671 
9672  /* Now restart the remote server. */
9673  run_worked = extended_remote_run (args) != -1;
9674  if (!run_worked)
9675  {
9676  /* vRun was not supported. Fail if we need it to do what the
9677  user requested. */
9678  if (remote_exec_file[0])
9679  error (_("Remote target does not support \"set remote exec-file\""));
9680  if (!args.empty ())
9681  error (_("Remote target does not support \"set args\" or run <ARGS>"));
9682 
9683  /* Fall back to "R". */
9685  }
9686 
9687  if (!have_inferiors ())
9688  {
9689  /* Clean up from the last time we ran, before we mark the target
9690  running again. This will mark breakpoints uninserted, and
9691  get_offsets may insert breakpoints. */
9692  init_thread_list ();
9694  }
9695 
9696  /* vRun's success return is a stop reply. */
9697  stop_reply = run_worked ? rs->buf : NULL;
9699 
9700  /* Get updated offsets, if the stub uses qOffsets. */
9701  get_offsets ();
9702 }
9703 
9704 
9705 /* Given a location's target info BP_TGT and the packet buffer BUF, output
9706  the list of conditions (in agent expression bytecode format), if any, the
9707  target needs to evaluate. The output is placed into the packet buffer
9708  started from BUF and ended at BUF_END. */
9709 
9710 static int
9712  struct bp_target_info *bp_tgt, char *buf,
9713  char *buf_end)
9714 {
9715  if (bp_tgt->conditions.empty ())
9716  return 0;
9717 
9718  buf += strlen (buf);
9719  xsnprintf (buf, buf_end - buf, "%s", ";");
9720  buf++;
9721 
9722  /* Send conditions to the target. */
9723  for (agent_expr *aexpr : bp_tgt->conditions)
9724  {
9725  xsnprintf (buf, buf_end - buf, "X%x,", aexpr->len);
9726  buf += strlen (buf);
9727  for (int i = 0; i < aexpr->len; ++i)
9728  buf = pack_hex_byte (buf, aexpr->buf[i]);
9729  *buf = '\0';
9730  }
9731  return 0;
9732 }
9733 
9734 static void
9736  struct bp_target_info *bp_tgt, char *buf)
9737 {
9738  if (bp_tgt->tcommands.empty ())
9739  return;
9740 
9741  buf += strlen (buf);
9742 
9743  sprintf (buf, ";cmds:%x,", bp_tgt->persist);
9744  buf += strlen (buf);
9745 
9746  /* Concatenate all the agent expressions that are commands into the
9747  cmds parameter. */
9748  for (agent_expr *aexpr : bp_tgt->tcommands)
9749  {
9750  sprintf (buf, "X%x,", aexpr->len);
9751  buf += strlen (buf);
9752  for (int i = 0; i < aexpr->len; ++i)
9753  buf = pack_hex_byte (buf, aexpr->buf[i]);
9754  *buf = '\0';
9755  }
9756 }
9757 
9758 /* Insert a breakpoint. On targets that have software breakpoint
9759  support, we ask the remote target to do the work; on targets
9760  which don't, we insert a traditional memory breakpoint. */
9761 
9762 static int
9764  struct gdbarch *gdbarch,
9765  struct bp_target_info *bp_tgt)
9766 {
9767  /* Try the "Z" s/w breakpoint packet if it is not already disabled.
9768  If it succeeds, then set the support to PACKET_ENABLE. If it
9769  fails, and the user has explicitly requested the Z support then
9770  report an error, otherwise, mark it disabled and go on. */
9771 
9773  {
9774  CORE_ADDR addr = bp_tgt->reqstd_address;
9775  struct remote_state *rs;
9776  char *p, *endbuf;
9777 
9778  /* Make sure the remote is pointing at the right process, if
9779  necessary. */
9782 
9783  rs = get_remote_state ();
9784  p = rs->buf;
9785  endbuf = rs->buf + get_remote_packet_size ();
9786 
9787  *(p++) = 'Z';
9788  *(p++) = '0';
9789  *(p++) = ',';
9790  addr = (ULONGEST) remote_address_masked (addr);
9791  p += hexnumstr (p, addr);
9792  xsnprintf (p, endbuf - p, ",%d", bp_tgt->kind);
9793 
9795  remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
9796 
9799 
9800  putpkt (rs->buf);
9801  getpkt (&rs->buf, &rs->buf_size, 0);
9802 
9804  {
9805  case PACKET_ERROR:
9806  return -1;
9807  case PACKET_OK:
9808  return 0;
9809  case PACKET_UNKNOWN:
9810  break;
9811  }
9812  }
9813 
9814  /* If this breakpoint has target-side commands but this stub doesn't
9815  support Z0 packets, throw error. */
9816  if (!bp_tgt->tcommands.empty ())
9818 Target doesn't support breakpoints that have target side commands."));
9819 
9820  return memory_insert_breakpoint (ops, gdbarch, bp_tgt);
9821 }
9822 
9823 static int
9825  struct gdbarch *gdbarch,
9826  struct bp_target_info *bp_tgt,
9827  enum remove_bp_reason reason)
9828 {
9829  CORE_ADDR addr = bp_tgt->placed_address;
9830  struct remote_state *rs = get_remote_state ();
9831 
9833  {
9834  char *p = rs->buf;
9835  char *endbuf = rs->buf + get_remote_packet_size ();
9836 
9837  /* Make sure the remote is pointing at the right process, if
9838  necessary. */
9841 
9842  *(p++) = 'z';
9843  *(p++) = '0';
9844  *(p++) = ',';
9845 
9846  addr = (ULONGEST) remote_address_masked (bp_tgt->placed_address);
9847  p += hexnumstr (p, addr);
9848  xsnprintf (p, endbuf - p, ",%d", bp_tgt->kind);
9849 
9850  putpkt (rs->buf);
9851  getpkt (&rs->buf, &rs->buf_size, 0);
9852 
9853  return (rs->buf[0] == 'E');
9854  }
9855 
9856  return memory_remove_breakpoint (ops, gdbarch, bp_tgt, reason);
9857 }
9858 
9859 static enum Z_packet_type
9861 {
9862  switch (type)
9863  {
9864  case hw_write:
9865  return Z_PACKET_WRITE_WP;
9866  break;
9867  case hw_read:
9868  return Z_PACKET_READ_WP;
9869  break;
9870  case hw_access:
9871  return Z_PACKET_ACCESS_WP;
9872  break;
9873  default:
9874  internal_error (__FILE__, __LINE__,
9875  _("hw_bp_to_z: bad watchpoint type %d"), type);
9876  }
9877 }
9878 
9879 static int
9880 remote_insert_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
9881  enum target_hw_bp_type type, struct expression *cond)
9882 {
9883  struct remote_state *rs = get_remote_state ();
9884  char *endbuf = rs->buf + get_remote_packet_size ();
9885  char *p;
9886  enum Z_packet_type packet = watchpoint_to_Z_packet (type);
9887 
9888  if (packet_support (PACKET_Z0 + packet) == PACKET_DISABLE)
9889  return 1;
9890 
9891  /* Make sure the remote is pointing at the right process, if
9892  necessary. */
9895 
9896  xsnprintf (rs->buf, endbuf - rs->buf, "Z%x,", packet);
9897  p = strchr (rs->buf, '\0');
9898  addr = remote_address_masked (addr);
9899  p += hexnumstr (p, (ULONGEST) addr);
9900  xsnprintf (p, endbuf - p, ",%x", len);
9901 
9902  putpkt (rs->buf);
9903  getpkt (&rs->buf, &rs->buf_size, 0);
9904 
9905  switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z0 + packet]))
9906  {
9907  case PACKET_ERROR:
9908  return -1;
9909  case PACKET_UNKNOWN:
9910  return 1;
9911  case PACKET_OK:
9912  return 0;
9913  }
9914  internal_error (__FILE__, __LINE__,
9915  _("remote_insert_watchpoint: reached end of function"));
9916 }
9917 
9918 static int
9920  CORE_ADDR start, int length)
9921 {
9922  CORE_ADDR diff = remote_address_masked (addr - start);
9923 
9924  return diff < length;
9925 }
9926 
9927 
9928 static int
9929 remote_remove_watchpoint (struct target_ops *self, CORE_ADDR addr, int len,
9930  enum target_hw_bp_type type, struct expression *cond)
9931 {
9932  struct remote_state *rs = get_remote_state ();
9933  char *endbuf = rs->buf + get_remote_packet_size ();
9934  char *p;
9935  enum Z_packet_type packet = watchpoint_to_Z_packet (type);
9936 
9937  if (packet_support (PACKET_Z0 + packet) == PACKET_DISABLE)
9938  return -1;
9939 
9940  /* Make sure the remote is pointing at the right process, if
9941  necessary. */
9944 
9945  xsnprintf (rs->buf, endbuf - rs->buf, "z%x,", packet);
9946  p = strchr (rs->buf, '\0');
9947  addr = remote_address_masked (addr);
9948  p += hexnumstr (p, (ULONGEST) addr);
9949  xsnprintf (p, endbuf - p, ",%x", len);
9950  putpkt (rs->buf);
9951  getpkt (&rs->buf, &rs->buf_size, 0);
9952 
9953  switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_Z0 + packet]))
9954  {
9955  case PACKET_ERROR:
9956  case PACKET_UNKNOWN:
9957  return -1;
9958  case PACKET_OK:
9959  return 0;
9960  }
9961  internal_error (__FILE__, __LINE__,
9962  _("remote_remove_watchpoint: reached end of function"));
9963 }
9964 
9965 
9969 
9970 static int
9972  CORE_ADDR addr, int len)
9973 {
9975  return 0;
9976  else if (remote_hw_watchpoint_length_limit < 0)
9977  return 1;
9978  else if (len <= remote_hw_watchpoint_length_limit)
9979  return 1;
9980  else
9981  return 0;
9982 }
9983 
9984 static int
9986  enum bptype type, int cnt, int ot)
9987 {
9989  {
9990  if (remote_hw_breakpoint_limit == 0)
9991  return 0;
9992  else if (remote_hw_breakpoint_limit < 0)
9993  return 1;
9994  else if (cnt <= remote_hw_breakpoint_limit)
9995  return 1;
9996  }
9997  else
9998  {
9999  if (remote_hw_watchpoint_limit == 0)
10000  return 0;
10001  else if (remote_hw_watchpoint_limit < 0)
10002  return 1;
10003  else if (ot)
10004  return -1;
10005  else if (cnt <= remote_hw_watchpoint_limit)
10006  return 1;
10007  }
10008  return -1;
10009 }
10010 
10011 /* The to_stopped_by_sw_breakpoint method of target remote. */
10012 
10013 static int
10015 {
10016  struct thread_info *thread = inferior_thread ();
10017 
10018  return (thread->priv != NULL
10019  && (get_remote_thread_info (thread)->stop_reason
10021 }
10022 
10023 /* The to_supports_stopped_by_sw_breakpoint method of target
10024  remote. */
10025 
10026 static int
10028 {
10030 }
10031 
10032 /* The to_stopped_by_hw_breakpoint method of target remote. */
10033 
10034 static int
10036 {
10037  struct thread_info *thread = inferior_thread ();
10038 
10039  return (thread->priv != NULL
10040  && (get_remote_thread_info (thread)->stop_reason
10042 }
10043 
10044 /* The to_supports_stopped_by_hw_breakpoint method of target
10045  remote. */
10046 
10047 static int
10049 {
10051 }
10052 
10053 static int
10055 {
10056  struct thread_info *thread = inferior_thread ();
10057 
10058  return (thread->priv != NULL
10059  && (get_remote_thread_info (thread)->stop_reason
10061 }
10062 
10063 static int
10065 {
10066  struct thread_info *thread = inferior_thread ();
10067 
10068  if (thread->priv != NULL
10069  && (get_remote_thread_info (thread)->stop_reason
10071  {
10072  *addr_p = get_remote_thread_info (thread)->watch_data_address;
10073  return 1;
10074  }
10075 
10076  return 0;
10077 }
10078 
10079 
10080 static int
10082  struct bp_target_info *bp_tgt)
10083 {
10084  CORE_ADDR addr = bp_tgt->reqstd_address;
10085  struct remote_state *rs;
10086  char *p, *endbuf;
10087  char *message;
10088 
10090  return -1;
10091 
10092  /* Make sure the remote is pointing at the right process, if
10093  necessary. */
10096 
10097  rs = get_remote_state ();
10098  p = rs->buf;
10099  endbuf = rs->buf + get_remote_packet_size ();
10100 
10101  *(p++) = 'Z';
10102  *(p++) = '1';
10103  *(p++) = ',';
10104 
10105  addr = remote_address_masked (addr);
10106  p += hexnumstr (p, (ULONGEST) addr);
10107  xsnprintf (p, endbuf - p, ",%x", bp_tgt->kind);
10108 
10110  remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
10111 
10114 
10115  putpkt (rs->buf);
10116  getpkt (&rs->buf, &rs->buf_size, 0);
10117 
10119  {
10120  case PACKET_ERROR:
10121  if (rs->buf[1] == '.')
10122  {
10123  message = strchr (rs->buf + 2, '.');
10124  if (message)
10125  error (_("Remote failure reply: %s"), message + 1);
10126  }
10127  return -1;
10128  case PACKET_UNKNOWN:
10129  return -1;
10130  case PACKET_OK:
10131  return 0;
10132  }
10133  internal_error (__FILE__, __LINE__,
10134  _("remote_insert_hw_breakpoint: reached end of function"));
10135 }
10136 
10137 
10138 static int
10140  struct bp_target_info *bp_tgt)
10141 {
10142  CORE_ADDR addr;
10143  struct remote_state *rs = get_remote_state ();
10144  char *p = rs->buf;
10145  char *endbuf = rs->buf + get_remote_packet_size ();
10146 
10148  return -1;
10149 
10150  /* Make sure the remote is pointing at the right process, if
10151  necessary. */
10154 
10155  *(p++) = 'z';
10156  *(p++) = '1';
10157  *(p++) = ',';
10158 
10159  addr = remote_address_masked (bp_tgt->placed_address);
10160  p += hexnumstr (p, (ULONGEST) addr);
10161  xsnprintf (p, endbuf - p, ",%x", bp_tgt->kind);
10162 
10163  putpkt (rs->buf);
10164  getpkt (&rs->buf, &rs->buf_size, 0);
10165 
10167  {
10168  case PACKET_ERROR:
10169  case PACKET_UNKNOWN:
10170  return -1;
10171  case PACKET_OK:
10172  return 0;
10173  }
10174  internal_error (__FILE__, __LINE__,
10175  _("remote_remove_hw_breakpoint: reached end of function"));
10176 }
10177 
10178 /* Verify memory using the "qCRC:" request. */
10179 
10180 static int
10182  const gdb_byte *data, CORE_ADDR lma, ULONGEST size)
10183 {
10184  struct remote_state *rs = get_remote_state ();
10185  unsigned long host_crc, target_crc;
10186  char *tmp;
10187 
10188  /* It doesn't make sense to use qCRC if the remote target is
10189  connected but not running. */
10191  {
10192  enum packet_result result;
10193 
10194  /* Make sure the remote is pointing at the right process. */
10196 
10197  /* FIXME: assumes lma can fit into long. */
10198  xsnprintf (rs->buf, get_remote_packet_size (), "qCRC:%lx,%lx",
10199  (long) lma, (long) size);
10200  putpkt (rs->buf);
10201 
10202  /* Be clever; compute the host_crc before waiting for target
10203  reply. */
10204  host_crc = xcrc32 (data, size, 0xffffffff);
10205 
10206  getpkt (&rs->buf, &rs->buf_size, 0);
10207 
10208  result = packet_ok (rs->buf,
10210  if (result == PACKET_ERROR)
10211  return -1;
10212  else if (result == PACKET_OK)
10213  {
10214  for (target_crc = 0, tmp = &rs->buf[1]; *tmp; tmp++)
10215  target_crc = target_crc * 16 + fromhex (*tmp);
10216 
10217  return (host_crc == target_crc);
10218  }
10219  }
10220 
10221  return simple_verify_memory (ops, data, lma, size);
10222 }
10223 
10224 /* compare-sections command
10225 
10226  With no arguments, compares each loadable section in the exec bfd
10227  with the same memory range on the target, and reports mismatches.
10228  Useful for verifying the image on the target against the exec file. */
10229 
10230 static void
10231 compare_sections_command (const char *args, int from_tty)
10232 {
10233  asection *s;
10234  const char *sectname;
10235  bfd_size_type size;
10236  bfd_vma lma;
10237  int matched = 0;
10238  int mismatched = 0;
10239  int res;
10240  int read_only = 0;
10241 
10242  if (!exec_bfd)
10243  error (_("command cannot be used without an exec file"));
10244 
10245  /* Make sure the remote is pointing at the right process. */
10247 
10248  if (args != NULL && strcmp (args, "-r") == 0)
10249  {
10250  read_only = 1;
10251  args = NULL;
10252  }
10253 
10254  for (s = exec_bfd->sections; s; s = s->next)
10255  {
10256  if (!(s->flags & SEC_LOAD))
10257  continue; /* Skip non-loadable section. */
10258 
10259  if (read_only && (s->flags & SEC_READONLY) == 0)
10260  continue; /* Skip writeable sections */
10261 
10262  size = bfd_get_section_size (s);
10263  if (size == 0)
10264  continue; /* Skip zero-length section. */
10265 
10266  sectname = bfd_get_section_name (exec_bfd, s);
10267  if (args && strcmp (args, sectname) != 0)
10268  continue; /* Not the section selected by user. */
10269 
10270  matched = 1; /* Do this section. */
10271  lma = s->lma;
10272 
10273  gdb::byte_vector sectdata (size);
10274  bfd_get_section_contents (exec_bfd, s, sectdata.data (), 0, size);
10275 
10276  res = target_verify_memory (sectdata.data (), lma, size);
10277 
10278  if (res == -1)
10279  error (_("target memory fault, section %s, range %s -- %s"), sectname,
10280  paddress (target_gdbarch (), lma),
10281  paddress (target_gdbarch (), lma + size));
10282 
10283  printf_filtered ("Section %s, range %s -- %s: ", sectname,
10284  paddress (target_gdbarch (), lma),
10285  paddress (target_gdbarch (), lma + size));
10286  if (res)
10287  printf_filtered ("matched.\n");
10288  else
10289  {
10290  printf_filtered ("MIS-MATCHED!\n");
10291  mismatched++;
10292  }
10293  }
10294  if (mismatched > 0)
10295  warning (_("One or more sections of the target image does not match\n\
10296 the loaded file\n"));
10297  if (args && !matched)
10298  printf_filtered (_("No loaded section named '%s'.\n"), args);
10299 }
10300 
10301 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
10302  into remote target. The number of bytes written to the remote
10303  target is returned, or -1 for error. */
10304 
10305 static enum target_xfer_status
10306 remote_write_qxfer (struct target_ops *ops, const char *object_name,
10307  const char *annex, const gdb_byte *writebuf,
10308  ULONGEST offset, LONGEST len, ULONGEST *xfered_len,
10309  struct packet_config *packet)
10310 {
10311  int i, buf_len;
10312  ULONGEST n;
10313  struct remote_state *rs = get_remote_state ();
10314  int max_size = get_memory_write_packet_size ();
10315 
10316  if (packet_config_support (packet) == PACKET_DISABLE)
10317  return TARGET_XFER_E_IO;
10318 
10319  /* Insert header. */
10320  i = snprintf (rs->buf, max_size,
10321  "qXfer:%s:write:%s:%s:",
10322  object_name, annex ? annex : "",
10323  phex_nz (offset, sizeof offset));
10324  max_size -= (i + 1);
10325 
10326  /* Escape as much data as fits into rs->buf. */
10327  buf_len = remote_escape_output
10328  (writebuf, len, 1, (gdb_byte *) rs->buf + i, &max_size, max_size);
10329 
10330  if (putpkt_binary (rs->buf, i + buf_len) < 0
10331  || getpkt_sane (&rs->buf, &rs->buf_size, 0) < 0
10332  || packet_ok (rs->buf, packet) != PACKET_OK)
10333  return TARGET_XFER_E_IO;
10334 
10335  unpack_varlen_hex (rs->buf, &n);
10336 
10337  *xfered_len = n;
10338  return (*xfered_len != 0) ? TARGET_XFER_OK : TARGET_XFER_EOF;
10339 }
10340 
10341 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
10342  Data at OFFSET, of up to LEN bytes, is read into READBUF; the
10343  number of bytes read is returned, or 0 for EOF, or -1 for error.
10344  The number of bytes read may be less than LEN without indicating an
10345  EOF. PACKET is checked and updated to indicate whether the remote
10346  target supports this object. */
10347 
10348 static enum target_xfer_status
10349 remote_read_qxfer (struct target_ops *ops, const char *object_name,
10350  const char *annex,
10351  gdb_byte *readbuf, ULONGEST offset, LONGEST len,
10352  ULONGEST *xfered_len,
10353  struct packet_config *packet)
10354 {
10355  struct remote_state *rs = get_remote_state ();
10356  LONGEST i, n, packet_len;
10357 
10358  if (packet_config_support (packet) == PACKET_DISABLE)
10359  return TARGET_XFER_E_IO;
10360 
10361  /* Check whether we've cached an end-of-object packet that matches
10362  this request. */
10363  if (rs->finished_object)
10364  {
10365  if (strcmp (object_name, rs->finished_object) == 0
10366  && strcmp (annex ? annex : "", rs->finished_annex) == 0
10367  && offset == rs->finished_offset)
10368  return TARGET_XFER_EOF;
10369 
10370 
10371  /* Otherwise, we're now reading something different. Discard
10372  the cache. */
10373  xfree (rs->finished_object);
10374  xfree (rs->finished_annex);
10375  rs->finished_object = NULL;
10376  rs->finished_annex = NULL;
10377  }
10378 
10379  /* Request only enough to fit in a single packet. The actual data
10380  may not, since we don't know how much of it will need to be escaped;
10381  the target is free to respond with slightly less data. We subtract
10382  five to account for the response type and the protocol frame. */
10383  n = std::min<LONGEST> (get_remote_packet_size () - 5, len);
10384  snprintf (rs->buf, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
10385  object_name, annex ? annex : "",
10386  phex_nz (offset, sizeof offset),
10387  phex_nz (n, sizeof n));
10388  i = putpkt (rs->buf);
10389  if (i < 0)
10390  return TARGET_XFER_E_IO;
10391 
10392  rs->buf[0] = '\0';
10393  packet_len = getpkt_sane (&rs->buf, &rs->buf_size, 0);
10394  if (packet_len < 0 || packet_ok (rs->buf, packet) != PACKET_OK)
10395  return TARGET_XFER_E_IO;
10396 
10397  if (rs->buf[0] != 'l' && rs->buf[0] != 'm')
10398  error (_("Unknown remote qXfer reply: %s"), rs->buf);
10399 
10400  /* 'm' means there is (or at least might be) more data after this
10401  batch. That does not make sense unless there's at least one byte
10402  of data in this reply. */
10403  if (rs->buf[0] == 'm' && packet_len == 1)
10404  error (_("Remote qXfer reply contained no data."));
10405 
10406  /* Got some data. */
10407  i = remote_unescape_input ((gdb_byte *) rs->buf + 1,
10408  packet_len - 1, readbuf, n);
10409 
10410  /* 'l' is an EOF marker, possibly including a final block of data,
10411  or possibly empty. If we have the final block of a non-empty
10412  object, record this fact to bypass a subsequent partial read. */
10413  if (rs->buf[0] == 'l' && offset + i > 0)
10414  {
10415  rs->finished_object = xstrdup (object_name);
10416  rs->finished_annex = xstrdup (annex ? annex : "");
10417  rs->finished_offset = offset + i;
10418  }
10419 
10420  if (i == 0)
10421  return TARGET_XFER_EOF;
10422  else
10423  {
10424  *xfered_len = i;
10425  return TARGET_XFER_OK;
10426  }
10427 }
10428 
10429 static enum target_xfer_status
10431  const char *annex, gdb_byte *readbuf,
10432  const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
10433  ULONGEST *xfered_len)
10434 {
10435  struct remote_state *rs;
10436  int i;
10437  char *p2;
10438  char query_type;
10440 
10443 
10444  rs = get_remote_state ();
10445 
10446  /* Handle memory using the standard memory routines. */
10447  if (object == TARGET_OBJECT_MEMORY)
10448  {
10449  /* If the remote target is connected but not running, we should
10450  pass this request down to a lower stratum (e.g. the executable
10451  file). */
10452  if (!target_has_execution)
10453  return TARGET_XFER_EOF;
10454 
10455  if (writebuf != NULL)
10456  return remote_write_bytes (offset, writebuf, len, unit_size,
10457  xfered_len);
10458  else
10459  return remote_read_bytes (ops, offset, readbuf, len, unit_size,
10460  xfered_len);
10461  }
10462 
10463  /* Handle SPU memory using qxfer packets. */
10464  if (object == TARGET_OBJECT_SPU)
10465  {
10466  if (readbuf)
10467  return remote_read_qxfer (ops, "spu", annex, readbuf, offset, len,
10468  xfered_len, &remote_protocol_packets
10470  else
10471  return remote_write_qxfer (ops, "spu", annex, writebuf, offset, len,
10472  xfered_len, &remote_protocol_packets
10474  }
10475 
10476  /* Handle extra signal info using qxfer packets. */
10477  if (object == TARGET_OBJECT_SIGNAL_INFO)
10478  {
10479  if (readbuf)
10480  return remote_read_qxfer (ops, "siginfo", annex, readbuf, offset, len,
10481  xfered_len, &remote_protocol_packets
10483  else
10484  return remote_write_qxfer (ops, "siginfo", annex,
10485  writebuf, offset, len, xfered_len,
10488  }
10489 
10490  if (object == TARGET_OBJECT_STATIC_TRACE_DATA)
10491  {
10492  if (readbuf)
10493  return remote_read_qxfer (ops, "statictrace", annex,
10494  readbuf, offset, len, xfered_len,
10497  else
10498  return TARGET_XFER_E_IO;
10499  }
10500 
10501  /* Only handle flash writes. */
10502  if (writebuf != NULL)
10503  {
10504  switch (object)
10505  {
10506  case TARGET_OBJECT_FLASH:
10507  return remote_flash_write (ops, offset, len, xfered_len,
10508  writebuf);
10509 
10510  default:
10511  return TARGET_XFER_E_IO;
10512  }
10513  }
10514 
10515  /* Map pre-existing objects onto letters. DO NOT do this for new
10516  objects!!! Instead specify new query packets. */
10517  switch (object)
10518  {
10519  case TARGET_OBJECT_AVR:
10520  query_type = 'R';
10521  break;
10522 
10523  case TARGET_OBJECT_AUXV:
10524  gdb_assert (annex == NULL);
10525  return remote_read_qxfer (ops, "auxv", annex, readbuf, offset, len,
10526  xfered_len,
10528 
10530  return remote_read_qxfer
10531  (ops, "features", annex, readbuf, offset, len, xfered_len,
10533 
10535  return remote_read_qxfer
10536  (ops, "libraries", annex, readbuf, offset, len, xfered_len,
10538 
10540  return remote_read_qxfer
10541  (ops, "libraries-svr4", annex, readbuf, offset, len, xfered_len,
10543 
10545  gdb_assert (annex == NULL);
10546  return remote_read_qxfer (ops, "memory-map", annex, readbuf, offset, len,
10547  xfered_len,
10549 
10550  case TARGET_OBJECT_OSDATA:
10551  /* Should only get here if we're connected. */
10552  gdb_assert (rs->remote_desc);
10553  return remote_read_qxfer
10554  (ops, "osdata", annex, readbuf, offset, len, xfered_len,
10556 
10557  case TARGET_OBJECT_THREADS:
10558  gdb_assert (annex == NULL);
10559  return remote_read_qxfer (ops, "threads", annex, readbuf, offset, len,
10560  xfered_len,
10562 
10564  gdb_assert (annex == NULL);
10565  return remote_read_qxfer
10566  (ops, "traceframe-info", annex, readbuf, offset, len, xfered_len,
10568 
10569  case TARGET_OBJECT_FDPIC:
10570  return remote_read_qxfer (ops, "fdpic", annex, readbuf, offset, len,
10571  xfered_len,
10573 
10575  return remote_read_qxfer (ops, "uib", annex, readbuf, offset, len,
10576  xfered_len,
10578 
10579  case TARGET_OBJECT_BTRACE:
10580  return remote_read_qxfer (ops, "btrace", annex, readbuf, offset, len,
10581  xfered_len,
10583 
10585  return remote_read_qxfer (ops, "btrace-conf", annex, readbuf, offset,
10586  len, xfered_len,
10588 
10590  return remote_read_qxfer (ops, "exec-file", annex, readbuf, offset,
10591  len, xfered_len,
10593 
10594  default:
10595  return TARGET_XFER_E_IO;
10596  }
10597 
10598  /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
10599  large enough let the caller deal with it. */
10600  if (len < get_remote_packet_size ())
10601  return TARGET_XFER_E_IO;
10602  len = get_remote_packet_size ();
10603 
10604  /* Except for querying the minimum buffer size, target must be open. */
10605  if (!rs->remote_desc)
10606  error (_("remote query is only available after target open"));
10607 
10608  gdb_assert (annex != NULL);
10609  gdb_assert (readbuf != NULL);
10610 
10611  p2 = rs->buf;
10612  *p2++ = 'q';
10613  *p2++ = query_type;
10614 
10615  /* We used one buffer char for the remote protocol q command and
10616  another for the query type. As the remote protocol encapsulation
10617  uses 4 chars plus one extra in case we are debugging
10618  (remote_debug), we have PBUFZIZ - 7 left to pack the query
10619  string. */
10620  i = 0;
10621  while (annex[i] && (i < (get_remote_packet_size () - 8)))
10622  {
10623  /* Bad caller may have sent forbidden characters. */
10624  gdb_assert (isprint (annex[i]) && annex[i] != '$' && annex[i] != '#');
10625  *p2++ = annex[i];
10626  i++;
10627  }
10628  *p2 = '\0';
10629  gdb_assert (annex[i] == '\0');
10630 
10631  i = putpkt (rs->buf);
10632  if (i < 0)
10633  return TARGET_XFER_E_IO;
10634 
10635  getpkt (&rs->buf, &rs->buf_size, 0);
10636  strcpy ((char *) readbuf, rs->buf);
10637 
10638  *xfered_len = strlen ((char *) readbuf);
10639  return (*xfered_len != 0) ? TARGET_XFER_OK : TARGET_XFER_EOF;
10640 }
10641 
10642 /* Implementation of to_get_memory_xfer_limit. */
10643 
10644 static ULONGEST
10646 {
10647  return get_memory_write_packet_size ();
10648 }
10649 
10650 static int
10652  CORE_ADDR start_addr, ULONGEST search_space_len,
10653  const gdb_byte *pattern, ULONGEST pattern_len,
10654  CORE_ADDR *found_addrp)
10655 {
10656  int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
10657  struct remote_state *rs = get_remote_state ();
10658  int max_size = get_memory_write_packet_size ();
10659  struct packet_config *packet =
10661  /* Number of packet bytes used to encode the pattern;
10662  this could be more than PATTERN_LEN due to escape characters. */
10663  int escaped_pattern_len;
10664  /* Amount of pattern that was encodable in the packet. */
10665  int used_pattern_len;
10666  int i;
10667  int found;
10668  ULONGEST found_addr;
10669 
10670  /* Don't go to the target if we don't have to. This is done before
10671  checking packet_config_support to avoid the possibility that a
10672  success for this edge case means the facility works in
10673  general. */
10674  if (pattern_len > search_space_len)
10675  return 0;
10676  if (pattern_len == 0)
10677  {
10678  *found_addrp = start_addr;
10679  return 1;
10680  }
10681 
10682  /* If we already know the packet isn't supported, fall back to the simple
10683  way of searching memory. */
10684 
10685  if (packet_config_support (packet) == PACKET_DISABLE)
10686  {
10687  /* Target doesn't provided special support, fall back and use the
10688  standard support (copy memory and do the search here). */
10689  return simple_search_memory (ops, start_addr, search_space_len,
10690  pattern, pattern_len, found_addrp);
10691  }
10692 
10693  /* Make sure the remote is pointing at the right process. */
10695 
10696  /* Insert header. */
10697  i = snprintf (rs->buf, max_size,
10698  "qSearch:memory:%s;%s;",
10699  phex_nz (start_addr, addr_size),
10700  phex_nz (search_space_len, sizeof (search_space_len)));
10701  max_size -= (i + 1);
10702 
10703  /* Escape as much data as fits into rs->buf. */
10704  escaped_pattern_len =
10705  remote_escape_output (pattern, pattern_len, 1, (gdb_byte *) rs->buf + i,
10706  &used_pattern_len, max_size);
10707 
10708  /* Bail if the pattern is too large. */
10709  if (used_pattern_len != pattern_len)
10710  error (_("Pattern is too large to transmit to remote target."));
10711 
10712  if (putpkt_binary (rs->buf, i + escaped_pattern_len) < 0
10713  || getpkt_sane (&rs->buf, &rs->buf_size, 0) < 0
10714  || packet_ok (rs->buf, packet) != PACKET_OK)
10715  {
10716  /* The request may not have worked because the command is not
10717  supported. If so, fall back to the simple way. */
10718  if (packet_config_support (packet) == PACKET_DISABLE)
10719  {
10720  return simple_search_memory (ops, start_addr, search_space_len,
10721  pattern, pattern_len, found_addrp);
10722  }
10723  return -1;
10724  }
10725 
10726  if (rs->buf[0] == '0')
10727  found = 0;
10728  else if (rs->buf[0] == '1')
10729  {
10730  found = 1;
10731  if (rs->buf[1] != ',')
10732  error (_("Unknown qSearch:memory reply: %s"), rs->buf);
10733  unpack_varlen_hex (rs->buf + 2, &found_addr);
10734  *found_addrp = found_addr;
10735  }
10736  else
10737  error (_("Unknown qSearch:memory reply: %s"), rs->buf);
10738 
10739  return found;
10740 }
10741 
10742 static void
10743 remote_rcmd (struct target_ops *self, const char *command,
10744  struct ui_file *outbuf)
10745 {
10746  struct remote_state *rs = get_remote_state ();
10747  char *p = rs->buf;
10748 
10749  if (!rs->remote_desc)
10750  error (_("remote rcmd is only available after target open"));
10751 
10752  /* Send a NULL command across as an empty command. */
10753  if (command == NULL)
10754  command = "";
10755 
10756  /* The query prefix. */
10757  strcpy (rs->buf, "qRcmd,");
10758  p = strchr (rs->buf, '\0');
10759 
10760  if ((strlen (rs->buf) + strlen (command) * 2 + 8/*misc*/)
10762  error (_("\"monitor\" command ``%s'' is too long."), command);
10763 
10764  /* Encode the actual command. */
10765  bin2hex ((const gdb_byte *) command, p, strlen (command));
10766 
10767  if (putpkt (rs->buf) < 0)
10768  error (_("Communication problem with target."));
10769 
10770  /* get/display the response */
10771  while (1)
10772  {
10773  char *buf;
10774 
10775  /* XXX - see also remote_get_noisy_reply(). */
10776  QUIT; /* Allow user to bail out with ^C. */
10777  rs->buf[0] = '\0';
10778  if (getpkt_sane (&rs->buf, &rs->buf_size, 0) == -1)
10779  {
10780  /* Timeout. Continue to (try to) read responses.
10781  This is better than stopping with an error, assuming the stub
10782  is still executing the (long) monitor command.
10783  If needed, the user can interrupt gdb using C-c, obtaining
10784  an effect similar to stop on timeout. */
10785  continue;
10786  }
10787  buf = rs->buf;
10788  if (buf[0] == '\0')
10789  error (_("Target does not support this command."));
10790  if (buf[0] == 'O' && buf[1] != 'K')
10791  {
10792  remote_console_output (buf + 1); /* 'O' message from stub. */
10793  continue;
10794  }
10795  if (strcmp (buf, "OK") == 0)
10796  break;
10797  if (strlen (buf) == 3 && buf[0] == 'E'
10798  && isdigit (buf[1]) && isdigit (buf[2]))
10799  {
10800  error (_("Protocol error with Rcmd"));
10801  }
10802  for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
10803  {
10804  char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
10805 
10806  fputc_unfiltered (c, outbuf);
10807  }
10808  break;
10809  }
10810 }
10811 
10812 static std::vector<mem_region>
10814 {
10815  std::vector<mem_region> result;
10818 
10819  if (text)
10820  result = parse_memory_map (text.get ());
10821 
10822  return result;
10823 }
10824 
10825 static void
10826 packet_command (const char *args, int from_tty)
10827 {
10828  struct remote_state *rs = get_remote_state ();
10829 
10830  if (!rs->remote_desc)
10831  error (_("command can only be used with remote target"));
10832 
10833  if (!args)
10834  error (_("remote-packet command requires packet text as argument"));
10835 
10836  puts_filtered ("sending: ");
10837  print_packet (args);
10838  puts_filtered ("\n");
10839  putpkt (args);
10840 
10841  getpkt (&rs->buf, &rs->buf_size, 0);
10842  puts_filtered ("received: ");
10843  print_packet (rs->buf);
10844  puts_filtered ("\n");
10845 }
10846 
10847 #if 0
10848 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
10849 
10850 static void display_thread_info (struct gdb_ext_thread_info *info);
10851 
10852 static void threadset_test_cmd (char *cmd, int tty);
10853 
10854 static void threadalive_test (char *cmd, int tty);
10855 
10856 static void threadlist_test_cmd (char *cmd, int tty);
10857 
10858 int get_and_display_threadinfo (threadref *ref);
10859 
10860 static void threadinfo_test_cmd (char *cmd, int tty);
10861 
10862 static int thread_display_step (threadref *ref, void *context);
10863 
10864 static void threadlist_update_test_cmd (char *cmd, int tty);
10865 
10866 static void init_remote_threadtests (void);
10867 
10868 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
10869 
10870 static void
10871 threadset_test_cmd (const char *cmd, int tty)
10872 {
10873  int sample_thread = SAMPLE_THREAD;
10874 
10875  printf_filtered (_("Remote threadset test\n"));
10876  set_general_thread (sample_thread);
10877 }
10878 
10879 
10880 static void
10881 threadalive_test (const char *cmd, int tty)
10882 {
10883  int sample_thread = SAMPLE_THREAD;
10884  int pid = ptid_get_pid (inferior_ptid);
10885  ptid_t ptid = ptid_build (pid, sample_thread, 0);
10886 
10887  if (remote_thread_alive (ptid))
10888  printf_filtered ("PASS: Thread alive test\n");
10889  else
10890  printf_filtered ("FAIL: Thread alive test\n");
10891 }
10892 
10893 void output_threadid (char *title, threadref *ref);
10894 
10895 void
10896 output_threadid (char *title, threadref *ref)
10897 {
10898  char hexid[20];
10899 
10900  pack_threadid (&hexid[0], ref); /* Convert threead id into hex. */
10901  hexid[16] = 0;
10902  printf_filtered ("%s %s\n", title, (&hexid[0]));
10903 }
10904 
10905 static void
10906 threadlist_test_cmd (const char *cmd, int tty)
10907 {
10908  int startflag = 1;
10910  int done, result_count;
10911  threadref threadlist[3];
10912 
10913  printf_filtered ("Remote Threadlist test\n");
10914  if (!remote_get_threadlist (startflag, &nextthread, 3, &done,
10915  &result_count, &threadlist[0]))
10916  printf_filtered ("FAIL: threadlist test\n");
10917  else
10918  {
10919  threadref *scan = threadlist;
10920  threadref *limit = scan + result_count;
10921 
10922  while (scan < limit)
10923  output_threadid (" thread ", scan++);
10924  }
10925 }
10926 
10927 void
10928 display_thread_info (struct gdb_ext_thread_info *info)
10929 {
10930  output_threadid ("Threadid: ", &info->threadid);
10931  printf_filtered ("Name: %s\n ", info->shortname);
10932  printf_filtered ("State: %s\n", info->display);
10933  printf_filtered ("other: %s\n\n", info->more_display);
10934 }
10935 
10936 int
10937 get_and_display_threadinfo (threadref *ref)
10938 {
10939  int result;
10940  int set;
10941  struct gdb_ext_thread_info threadinfo;
10942 
10945  if (0 != (result = remote_get_threadinfo (ref, set, &threadinfo)))
10946  display_thread_info (&threadinfo);
10947  return result;
10948 }
10949 
10950 static void
10951 threadinfo_test_cmd (const char *cmd, int tty)
10952 {
10953  int athread = SAMPLE_THREAD;
10954  threadref thread;
10955  int set;
10956 
10957  int_to_threadref (&thread, athread);
10958  printf_filtered ("Remote Threadinfo test\n");
10959  if (!get_and_display_threadinfo (&thread))
10960  printf_filtered ("FAIL cannot get thread info\n");
10961 }
10962 
10963 static int
10964 thread_display_step (threadref *ref, void *context)
10965 {
10966  /* output_threadid(" threadstep ",ref); *//* simple test */
10967  return get_and_display_threadinfo (ref);
10968 }
10969 
10970 static void
10971 threadlist_update_test_cmd (const char *cmd, int tty)
10972 {
10973  printf_filtered ("Remote Threadlist update test\n");
10974  remote_threadlist_iterator (thread_display_step, 0, CRAZY_MAX_THREADS);
10975 }
10976 
10977 static void
10978 init_remote_threadtests (void)
10979 {
10980  add_com ("tlist", class_obscure, threadlist_test_cmd,
10981  _("Fetch and print the remote list of "
10982  "thread identifiers, one pkt only"));
10983  add_com ("tinfo", class_obscure, threadinfo_test_cmd,
10984  _("Fetch and display info about one thread"));
10985  add_com ("tset", class_obscure, threadset_test_cmd,
10986  _("Test setting to a different thread"));
10987  add_com ("tupd", class_obscure, threadlist_update_test_cmd,
10988  _("Iterate through updating all remote thread info"));
10989  add_com ("talive", class_obscure, threadalive_test,
10990  _(" Remote thread alive test "));
10991 }
10992 
10993 #endif /* 0 */
10994 
10995 /* Convert a thread ID to a string. Returns the string in a static
10996  buffer. */
10997 
10998 static const char *
11000 {
11001  static char buf[64];
11002  struct remote_state *rs = get_remote_state ();
11003 
11004  if (ptid_equal (ptid, null_ptid))
11005  return normal_pid_to_str (ptid);
11006  else if (ptid_is_pid (ptid))
11007  {
11008  /* Printing an inferior target id. */
11009 
11010  /* When multi-process extensions are off, there's no way in the
11011  remote protocol to know the remote process id, if there's any
11012  at all. There's one exception --- when we're connected with
11013  target extended-remote, and we manually attached to a process
11014  with "attach PID". We don't record anywhere a flag that
11015  allows us to distinguish that case from the case of
11016  connecting with extended-remote and the stub already being
11017  attached to a process, and reporting yes to qAttached, hence
11018  no smart special casing here. */
11019  if (!remote_multi_process_p (rs))
11020  {
11021  xsnprintf (buf, sizeof buf, "Remote target");
11022  return buf;
11023  }
11024 
11025  return normal_pid_to_str (ptid);
11026  }
11027  else
11028  {
11029  if (ptid_equal (magic_null_ptid, ptid))
11030  xsnprintf (buf, sizeof buf, "Thread <main>");
11031  else if (remote_multi_process_p (rs))
11032  if (ptid_get_lwp (ptid) == 0)
11033  return normal_pid_to_str (ptid);
11034  else
11035  xsnprintf (buf, sizeof buf, "Thread %d.%ld",
11036  ptid_get_pid (ptid), ptid_get_lwp (ptid));
11037  else
11038  xsnprintf (buf, sizeof buf, "Thread %ld",
11039  ptid_get_lwp (ptid));
11040  return buf;
11041  }
11042 }
11043 
11044 /* Get the address of the thread local variable in OBJFILE which is
11045  stored at OFFSET within the thread local storage for thread PTID. */
11046 
11047 static CORE_ADDR
11049  ptid_t ptid, CORE_ADDR lm, CORE_ADDR offset)
11050 {
11052  {
11053  struct remote_state *rs = get_remote_state ();
11054  char *p = rs->buf;
11055  char *endp = rs->buf + get_remote_packet_size ();
11056  enum packet_result result;
11057 
11058  strcpy (p, "qGetTLSAddr:");
11059  p += strlen (p);
11060  p = write_ptid (p, endp, ptid);
11061  *p++ = ',';
11062  p += hexnumstr (p, offset);
11063  *p++ = ',';
11064  p += hexnumstr (p, lm);
11065  *p++ = '\0';
11066 
11067  putpkt (rs->buf);
11068  getpkt (&rs->buf, &rs->buf_size, 0);
11069  result = packet_ok (rs->buf,
11071  if (result == PACKET_OK)
11072  {
11073  ULONGEST result;
11074 
11075  unpack_varlen_hex (rs->buf, &result);
11076  return result;
11077  }
11078  else if (result == PACKET_UNKNOWN)
11080  _("Remote target doesn't support qGetTLSAddr packet"));
11081  else
11083  _("Remote target failed to process qGetTLSAddr request"));
11084  }
11085  else
11087  _("TLS not supported or disabled on this target"));
11088  /* Not reached. */
11089  return 0;
11090 }
11091 
11092 /* Provide thread local base, i.e. Thread Information Block address.
11093  Returns 1 if ptid is found and thread_local_base is non zero. */
11094 
11095 static int
11097 {
11099  {
11100  struct remote_state *rs = get_remote_state ();
11101  char *p = rs->buf;
11102  char *endp = rs->buf + get_remote_packet_size ();
11103  enum packet_result result;
11104 
11105  strcpy (p, "qGetTIBAddr:");
11106  p += strlen (p);
11107  p = write_ptid (p, endp, ptid);
11108  *p++ = '\0';
11109 
11110  putpkt (rs->buf);
11111  getpkt (&rs->buf, &rs->buf_size, 0);
11112  result = packet_ok (rs->buf,
11114  if (result == PACKET_OK)
11115  {
11116  ULONGEST result;
11117 
11118  unpack_varlen_hex (rs->buf, &result);
11119  if (addr)
11120  *addr = (CORE_ADDR) result;
11121  return 1;
11122  }
11123  else if (result == PACKET_UNKNOWN)
11124  error (_("Remote target doesn't support qGetTIBAddr packet"));
11125  else
11126  error (_("Remote target failed to process qGetTIBAddr request"));
11127  }
11128  else
11129  error (_("qGetTIBAddr not supported or disabled on this target"));
11130  /* Not reached. */
11131  return 0;
11132 }
11133 
11134 /* Support for inferring a target description based on the current
11135  architecture and the size of a 'g' packet. While the 'g' packet
11136  can have any size (since optional registers can be left off the
11137  end), some sizes are easily recognizable given knowledge of the
11138  approximate architecture. */
11139 
11141 {
11142  int bytes;
11143  const struct target_desc *tdesc;
11144 };
11147 
11149 {
11150  VEC(remote_g_packet_guess_s) *guesses;
11151 };
11152 
11154 
11155 static void *
11156 remote_g_packet_data_init (struct obstack *obstack)
11157 {
11158  return OBSTACK_ZALLOC (obstack, struct remote_g_packet_data);
11159 }
11160 
11161 void
11163  const struct target_desc *tdesc)
11164 {
11165  struct remote_g_packet_data *data
11166  = ((struct remote_g_packet_data *)
11168  struct remote_g_packet_guess new_guess, *guess;
11169  int ix;
11170 
11171  gdb_assert (tdesc != NULL);
11172 
11173  for (ix = 0;
11174  VEC_iterate (remote_g_packet_guess_s, data->guesses, ix, guess);
11175  ix++)
11176  if (guess->bytes == bytes)
11177  internal_error (__FILE__, __LINE__,
11178  _("Duplicate g packet description added for size %d"),
11179  bytes);
11180 
11181  new_guess.bytes = bytes;
11182  new_guess.tdesc = tdesc;
11183  VEC_safe_push (remote_g_packet_guess_s, data->guesses, &new_guess);
11184 }
11185 
11186 /* Return 1 if remote_read_description would do anything on this target
11187  and architecture, 0 otherwise. */
11188 
11189 static int
11191 {
11192  struct remote_g_packet_data *data
11193  = ((struct remote_g_packet_data *)
11195 
11196  if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
11197  return 1;
11198 
11199  return 0;
11200 }
11201 
11202 static const struct target_desc *
11204 {
11205  struct remote_g_packet_data *data
11206  = ((struct remote_g_packet_data *)
11208 
11209  /* Do not try this during initial connection, when we do not know
11210  whether there is a running but stopped thread. */
11212  return target->beneath->to_read_description (target->beneath);
11213 
11214  if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
11215  {
11216  struct remote_g_packet_guess *guess;
11217  int ix;
11218  int bytes = send_g_packet ();
11219 
11220  for (ix = 0;
11221  VEC_iterate (remote_g_packet_guess_s, data->guesses, ix, guess);
11222  ix++)
11223  if (guess->bytes == bytes)
11224  return guess->tdesc;
11225 
11226  /* We discard the g packet. A minor optimization would be to
11227  hold on to it, and fill the register cache once we have selected
11228  an architecture, but it's too tricky to do safely. */
11229  }
11230 
11231  return target->beneath->to_read_description (target->beneath);
11232 }
11233 
11234 /* Remote file transfer support. This is host-initiated I/O, not
11235  target-initiated; for target-initiated, see remote-fileio.c. */
11236 
11237 /* If *LEFT is at least the length of STRING, copy STRING to
11238  *BUFFER, update *BUFFER to point to the new end of the buffer, and
11239  decrease *LEFT. Otherwise raise an error. */
11240 
11241 static void
11242 remote_buffer_add_string (char **buffer, int *left, const char *string)
11243 {
11244  int len = strlen (string);
11245 
11246  if (len > *left)
11247  error (_("Packet too long for target."));
11248 
11249  memcpy (*buffer, string, len);
11250  *buffer += len;
11251  *left -= len;
11252 
11253  /* NUL-terminate the buffer as a convenience, if there is
11254  room. */
11255  if (*left)
11256  **buffer = '\0';
11257 }
11258 
11259 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
11260  *BUFFER, update *BUFFER to point to the new end of the buffer, and
11261  decrease *LEFT. Otherwise raise an error. */
11262 
11263 static void
11264 remote_buffer_add_bytes (char **buffer, int *left, const gdb_byte *bytes,
11265  int len)
11266 {
11267  if (2 * len > *left)
11268  error (_("Packet too long for target."));
11269 
11270  bin2hex (bytes, *buffer, len);
11271  *buffer += 2 * len;
11272  *left -= 2 * len;
11273 
11274  /* NUL-terminate the buffer as a convenience, if there is
11275  room. */
11276  if (*left)
11277  **buffer = '\0';
11278 }
11279 
11280 /* If *LEFT is large enough, convert VALUE to hex and add it to
11281  *BUFFER, update *BUFFER to point to the new end of the buffer, and
11282  decrease *LEFT. Otherwise raise an error. */
11283 
11284 static void
11286 {
11287  int len = hexnumlen (value);
11288 
11289  if (len > *left)
11290  error (_("Packet too long for target."));
11291 
11292  hexnumstr (*buffer, value);
11293  *buffer += len;
11294  *left -= len;
11295 
11296  /* NUL-terminate the buffer as a convenience, if there is
11297  room. */
11298  if (*left)
11299  **buffer = '\0';
11300 }
11301 
11302 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
11303  value, *REMOTE_ERRNO to the remote error number or zero if none
11304  was included, and *ATTACHMENT to point to the start of the annex
11305  if any. The length of the packet isn't needed here; there may
11306  be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
11307 
11308  Return 0 if the packet could be parsed, -1 if it could not. If
11309  -1 is returned, the other variables may not be initialized. */
11310 
11311 static int
11312 remote_hostio_parse_result (char *buffer, int *retcode,
11313  int *remote_errno, char **attachment)
11314 {
11315  char *p, *p2;
11316 
11317  *remote_errno = 0;
11318  *attachment = NULL;
11319 
11320  if (buffer[0] != 'F')
11321  return -1;
11322 
11323  errno = 0;
11324  *retcode = strtol (&buffer[1], &p, 16);
11325  if (errno != 0 || p == &buffer[1])
11326  return -1;
11327 
11328  /* Check for ",errno". */
11329  if (*p == ',')
11330  {
11331  errno = 0;
11332  *remote_errno = strtol (p + 1, &p2, 16);
11333  if (errno != 0 || p + 1 == p2)
11334  return -1;
11335  p = p2;
11336  }
11337 
11338  /* Check for ";attachment". If there is no attachment, the
11339  packet should end here. */
11340  if (*p == ';')
11341  {
11342  *attachment = p + 1;
11343  return 0;
11344  }
11345  else if (*p == '\0')
11346  return 0;
11347  else
11348  return -1;
11349 }
11350 
11351 /* Send a prepared I/O packet to the target and read its response.
11352  The prepared packet is in the global RS->BUF before this function
11353  is called, and the answer is there when we return.
11354 
11355  COMMAND_BYTES is the length of the request to send, which may include
11356  binary data. WHICH_PACKET is the packet configuration to check
11357  before attempting a packet. If an error occurs, *REMOTE_ERRNO
11358  is set to the error number and -1 is returned. Otherwise the value
11359  returned by the function is returned.
11360 
11361  ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
11362  attachment is expected; an error will be reported if there's a
11363  mismatch. If one is found, *ATTACHMENT will be set to point into
11364  the packet buffer and *ATTACHMENT_LEN will be set to the
11365  attachment's length. */
11366 
11367 static int
11368 remote_hostio_send_command (int command_bytes, int which_packet,
11369  int *remote_errno, char **attachment,
11370  int *attachment_len)
11371 {
11372  struct remote_state *rs = get_remote_state ();
11373  int ret, bytes_read;
11374  char *attachment_tmp;
11375 
11376  if (!rs->remote_desc
11377  || packet_support (which_packet) == PACKET_DISABLE)
11378  {
11379  *remote_errno = FILEIO_ENOSYS;
11380  return -1;
11381  }
11382 
11383  putpkt_binary (rs->buf, command_bytes);
11384  bytes_read = getpkt_sane (&rs->buf, &rs->buf_size, 0);
11385 
11386  /* If it timed out, something is wrong. Don't try to parse the
11387  buffer. */
11388  if (bytes_read < 0)
11389  {
11390  *remote_errno = FILEIO_EINVAL;
11391  return -1;
11392  }
11393 
11394  switch (packet_ok (rs->buf, &remote_protocol_packets[which_packet]))
11395  {
11396  case PACKET_ERROR:
11397  *remote_errno = FILEIO_EINVAL;
11398  return -1;
11399  case PACKET_UNKNOWN:
11400  *remote_errno = FILEIO_ENOSYS;
11401  return -1;
11402  case PACKET_OK:
11403  break;
11404  }
11405 
11406  if (remote_hostio_parse_result (rs->buf, &ret, remote_errno,
11407  &attachment_tmp))
11408  {
11409  *remote_errno = FILEIO_EINVAL;
11410  return -1;
11411  }
11412 
11413  /* Make sure we saw an attachment if and only if we expected one. */
11414  if ((attachment_tmp == NULL && attachment != NULL)
11415  || (attachment_tmp != NULL && attachment == NULL))
11416  {
11417  *remote_errno = FILEIO_EINVAL;
11418  return -1;
11419  }
11420 
11421  /* If an attachment was found, it must point into the packet buffer;
11422  work out how many bytes there were. */
11423  if (attachment_tmp != NULL)
11424  {
11425  *attachment = attachment_tmp;
11426  *attachment_len = bytes_read - (*attachment - rs->buf);
11427  }
11428 
11429  return ret;
11430 }
11431 
11432 /* Invalidate the readahead cache. */
11433 
11434 static void
11436 {
11437  struct remote_state *rs = get_remote_state ();
11438 
11439  rs->readahead_cache.fd = -1;
11440 }
11441 
11442 /* Invalidate the readahead cache if it is holding data for FD. */
11443 
11444 static void
11446 {
11447  struct remote_state *rs = get_remote_state ();
11448 
11449  if (rs->readahead_cache.fd == fd)
11450  rs->readahead_cache.fd = -1;
11451 }
11452 
11453 /* Set the filesystem remote_hostio functions that take FILENAME
11454  arguments will use. Return 0 on success, or -1 if an error
11455  occurs (and set *REMOTE_ERRNO). */
11456 
11457 static int
11458 remote_hostio_set_filesystem (struct inferior *inf, int *remote_errno)
11459 {
11460  struct remote_state *rs = get_remote_state ();
11461  int required_pid = (inf == NULL || inf->fake_pid_p) ? 0 : inf->pid;
11462  char *p = rs->buf;
11463  int left = get_remote_packet_size () - 1;
11464  char arg[9];
11465  int ret;
11466 
11468  return 0;
11469 
11470  if (rs->fs_pid != -1 && required_pid == rs->fs_pid)
11471  return 0;
11472 
11473  remote_buffer_add_string (&p, &left, "vFile:setfs:");
11474 
11475  xsnprintf (arg, sizeof (arg), "%x", required_pid);
11476  remote_buffer_add_string (&p, &left, arg);
11477 
11479  remote_errno, NULL, NULL);
11480 
11482  return 0;
11483 
11484  if (ret == 0)
11485  rs->fs_pid = required_pid;
11486 
11487  return ret;
11488 }
11489 
11490 /* Implementation of to_fileio_open. */
11491 
11492 static int
11494  struct inferior *inf, const char *filename,
11495  int flags, int mode, int warn_if_slow,
11496  int *remote_errno)
11497 {
11498  struct remote_state *rs = get_remote_state ();
11499  char *p = rs->buf;
11500  int left = get_remote_packet_size () - 1;
11501 
11502  if (warn_if_slow)
11503  {
11504  static int warning_issued = 0;
11505 
11506  printf_unfiltered (_("Reading %s from remote target...\n"),
11507  filename);
11508 
11509  if (!warning_issued)
11510  {
11511  warning (_("File transfers from remote targets can be slow."
11512  " Use \"set sysroot\" to access files locally"
11513  " instead."));
11514  warning_issued = 1;
11515  }
11516  }
11517 
11518  if (remote_hostio_set_filesystem (inf, remote_errno) != 0)
11519  return -1;
11520 
11521  remote_buffer_add_string (&p, &left, "vFile:open:");
11522 
11523  remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
11524  strlen (filename));
11525  remote_buffer_add_string (&p, &left, ",");
11526 
11527  remote_buffer_add_int (&p, &left, flags);
11528  remote_buffer_add_string (&p, &left, ",");
11529 
11530  remote_buffer_add_int (&p, &left, mode);
11531 
11533  remote_errno, NULL, NULL);
11534 }
11535 
11536 /* Implementation of to_fileio_pwrite. */
11537 
11538 static int
11540  int fd, const gdb_byte *write_buf, int len,
11541  ULONGEST offset, int *remote_errno)
11542 {
11543  struct remote_state *rs = get_remote_state ();
11544  char *p = rs->buf;
11545  int left = get_remote_packet_size ();
11546  int out_len;
11547 
11549 
11550  remote_buffer_add_string (&p, &left, "vFile:pwrite:");
11551 
11552  remote_buffer_add_int (&p, &left, fd);
11553  remote_buffer_add_string (&p, &left, ",");
11554 
11555  remote_buffer_add_int (&p, &left, offset);
11556  remote_buffer_add_string (&p, &left, ",");
11557 
11558  p += remote_escape_output (write_buf, len, 1, (gdb_byte *) p, &out_len,
11559  get_remote_packet_size () - (p - rs->buf));
11560 
11562  remote_errno, NULL, NULL);
11563 }
11564 
11565 /* Helper for the implementation of to_fileio_pread. Read the file
11566  from the remote side with vFile:pread. */
11567 
11568 static int
11570  int fd, gdb_byte *read_buf, int len,
11571  ULONGEST offset, int *remote_errno)
11572 {
11573  struct remote_state *rs = get_remote_state ();
11574  char *p = rs->buf;
11575  char *attachment;
11576  int left = get_remote_packet_size ();
11577  int ret, attachment_len;
11578  int read_len;
11579 
11580  remote_buffer_add_string (&p, &left, "vFile:pread:");
11581 
11582  remote_buffer_add_int (&p, &left, fd);
11583  remote_buffer_add_string (&p, &left, ",");
11584 
11585  remote_buffer_add_int (&p, &left, len);
11586  remote_buffer_add_string (&p, &left, ",");
11587 
11588  remote_buffer_add_int (&p, &left, offset);
11589 
11591  remote_errno, &attachment,
11592  &attachment_len);
11593 
11594  if (ret < 0)
11595  return ret;
11596 
11597  read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len,
11598  read_buf, len);
11599  if (read_len != ret)
11600  error (_("Read returned %d, but %d bytes."), ret, (int) read_len);
11601 
11602  return ret;
11603 }
11604 
11605 /* Serve pread from the readahead cache. Returns number of bytes
11606  read, or 0 if the request can't be served from the cache. */
11607 
11608 static int
11610  int fd, gdb_byte *read_buf, size_t len,
11611  ULONGEST offset)
11612 {
11613  struct readahead_cache *cache = &rs->readahead_cache;
11614 
11615  if (cache->fd == fd
11616  && cache->offset <= offset
11617  && offset < cache->offset + cache->bufsize)
11618  {
11619  ULONGEST max = cache->offset + cache->bufsize;
11620 
11621  if (offset + len > max)
11622  len = max - offset;
11623 
11624  memcpy (read_buf, cache->buf + offset - cache->offset, len);
11625  return len;
11626  }
11627 
11628  return 0;
11629 }
11630 
11631 /* Implementation of to_fileio_pread. */
11632 
11633 static int
11635  int fd, gdb_byte *read_buf, int len,
11636  ULONGEST offset, int *remote_errno)
11637 {
11638  int ret;
11639  struct remote_state *rs = get_remote_state ();
11640  struct readahead_cache *cache = &rs->readahead_cache;
11641 
11642  ret = remote_hostio_pread_from_cache (rs, fd, read_buf, len, offset);
11643  if (ret > 0)
11644  {
11645  cache->hit_count++;
11646 
11647  if (remote_debug)
11648  fprintf_unfiltered (gdb_stdlog, "readahead cache hit %s\n",
11649  pulongest (cache->hit_count));
11650  return ret;
11651  }
11652 
11653  cache->miss_count++;
11654  if (remote_debug)
11655  fprintf_unfiltered (gdb_stdlog, "readahead cache miss %s\n",
11656  pulongest (cache->miss_count));
11657 
11658  cache->fd = fd;
11659  cache->offset = offset;
11660  cache->bufsize = get_remote_packet_size ();
11661  cache->buf = (gdb_byte *) xrealloc (cache->buf, cache->bufsize);
11662 
11663  ret = remote_hostio_pread_vFile (self, cache->fd, cache->buf, cache->bufsize,
11664  cache->offset, remote_errno);
11665  if (ret <= 0)
11666  {
11668  return ret;
11669  }
11670 
11671  cache->bufsize = ret;
11672  return remote_hostio_pread_from_cache (rs, fd, read_buf, len, offset);
11673 }
11674 
11675 /* Implementation of to_fileio_close. */
11676 
11677 static int
11678 remote_hostio_close (struct target_ops *self, int fd, int *remote_errno)
11679 {
11680  struct remote_state *rs = get_remote_state ();
11681  char *p = rs->buf;
11682  int left = get_remote_packet_size () - 1;
11683 
11685 
11686  remote_buffer_add_string (&p, &left, "vFile:close:");
11687 
11688  remote_buffer_add_int (&p, &left, fd);
11689 
11691  remote_errno, NULL, NULL);
11692 }
11693 
11694 /* Implementation of to_fileio_unlink. */
11695 
11696 static int
11698  struct inferior *inf, const char *filename,
11699  int *remote_errno)
11700 {
11701  struct remote_state *rs = get_remote_state ();
11702  char *p = rs->buf;
11703  int left = get_remote_packet_size () - 1;
11704 
11705  if (remote_hostio_set_filesystem (inf, remote_errno) != 0)
11706  return -1;
11707 
11708  remote_buffer_add_string (&p, &left, "vFile:unlink:");
11709 
11710  remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
11711  strlen (filename));
11712 
11714  remote_errno, NULL, NULL);
11715 }
11716 
11717 /* Implementation of to_fileio_readlink. */
11718 
11719 static char *
11721  struct inferior *inf, const char *filename,
11722  int *remote_errno)
11723 {
11724  struct remote_state *rs = get_remote_state ();
11725  char *p = rs->buf;
11726  char *attachment;
11727  int left = get_remote_packet_size ();
11728  int len, attachment_len;
11729  int read_len;
11730  char *ret;
11731 
11732  if (remote_hostio_set_filesystem (inf, remote_errno) != 0)
11733  return NULL;
11734 
11735  remote_buffer_add_string (&p, &left, "vFile:readlink:");
11736 
11737  remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
11738  strlen (filename));
11739 
11741  remote_errno, &attachment,
11742  &attachment_len);
11743 
11744  if (len < 0)
11745  return NULL;
11746 
11747  ret = (char *) xmalloc (len + 1);
11748 
11749  read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len,
11750  (gdb_byte *) ret, len);
11751  if (read_len != len)
11752  error (_("Readlink returned %d, but %d bytes."), len, read_len);
11753 
11754  ret[len] = '\0';
11755  return ret;
11756 }
11757 
11758 /* Implementation of to_fileio_fstat. */
11759 
11760 static int
11762  int fd, struct stat *st,
11763  int *remote_errno)
11764 {
11765  struct remote_state *rs = get_remote_state ();
11766  char *p = rs->buf;
11767  int left = get_remote_packet_size ();
11768  int attachment_len, ret;
11769  char *attachment;
11770  struct fio_stat fst;
11771  int read_len;
11772 
11773  remote_buffer_add_string (&p, &left, "vFile:fstat:");
11774 
11775  remote_buffer_add_int (&p, &left, fd);
11776 
11778  remote_errno, &attachment,
11779  &attachment_len);
11780  if (ret < 0)
11781  {
11782  if (*remote_errno != FILEIO_ENOSYS)
11783  return ret;
11784 
11785  /* Strictly we should return -1, ENOSYS here, but when
11786  "set sysroot remote:" was implemented in August 2008
11787  BFD's need for a stat function was sidestepped with
11788  this hack. This was not remedied until March 2015
11789  so we retain the previous behavior to avoid breaking
11790  compatibility.
11791 
11792  Note that the memset is a March 2015 addition; older
11793  GDBs set st_size *and nothing else* so the structure
11794  would have garbage in all other fields. This might
11795  break something but retaining the previous behavior
11796  here would be just too wrong. */
11797 
11798  memset (st, 0, sizeof (struct stat));
11799  st->st_size = INT_MAX;
11800  return 0;
11801  }
11802 
11803  read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len,
11804  (gdb_byte *) &fst, sizeof (fst));
11805 
11806  if (read_len != ret)
11807  error (_("vFile:fstat returned %d, but %d bytes."), ret, read_len);
11808 
11809  if (read_len != sizeof (fst))
11810  error (_("vFile:fstat returned %d bytes, but expecting %d."),
11811  read_len, (int) sizeof (fst));
11812 
11813  remote_fileio_to_host_stat (&fst, st);
11814 
11815  return 0;
11816 }
11817 
11818 /* Implementation of to_filesystem_is_local. */
11819 
11820 static int
11822 {
11823  /* Valgrind GDB presents itself as a remote target but works
11824  on the local filesystem: it does not implement remote get
11825  and users are not expected to set a sysroot. To handle
11826  this case we treat the remote filesystem as local if the
11827  sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
11828  does not support vFile:open. */
11829  if (strcmp (gdb_sysroot, TARGET_SYSROOT_PREFIX) == 0)
11830  {
11832 
11833  if (ps == PACKET_SUPPORT_UNKNOWN)
11834  {
11835  int fd, remote_errno;
11836 
11837  /* Try opening a file to probe support. The supplied
11838  filename is irrelevant, we only care about whether
11839  the stub recognizes the packet or not. */
11840  fd = remote_hostio_open (self, NULL, "just probing",
11841  FILEIO_O_RDONLY, 0700, 0,
11842  &remote_errno);
11843 
11844  if (fd >= 0)
11845  remote_hostio_close (self, fd, &remote_errno);
11846 
11848  }
11849 
11850  if (ps == PACKET_DISABLE)
11851  {
11852  static int warning_issued = 0;
11853 
11854  if (!warning_issued)
11855  {
11856  warning (_("remote target does not support file"
11857  " transfer, attempting to access files"
11858  " from local filesystem."));
11859  warning_issued = 1;
11860  }
11861 
11862  return 1;
11863  }
11864  }
11865 
11866  return 0;
11867 }
11868 
11869 static int
11871 {
11872  switch (errnum)
11873  {
11874  case FILEIO_EPERM:
11875  return EPERM;
11876  case FILEIO_ENOENT:
11877  return ENOENT;
11878  case FILEIO_EINTR:
11879  return EINTR;
11880  case FILEIO_EIO:
11881  return EIO;
11882  case FILEIO_EBADF:
11883  return EBADF;
11884  case FILEIO_EACCES:
11885  return EACCES;
11886  case FILEIO_EFAULT:
11887  return EFAULT;
11888  case FILEIO_EBUSY:
11889  return EBUSY;
11890  case FILEIO_EEXIST:
11891  return EEXIST;
11892  case FILEIO_ENODEV:
11893  return ENODEV;
11894  case FILEIO_ENOTDIR:
11895  return ENOTDIR;
11896  case FILEIO_EISDIR:
11897  return EISDIR;
11898  case FILEIO_EINVAL:
11899  return EINVAL;
11900  case FILEIO_ENFILE:
11901  return ENFILE;
11902  case FILEIO_EMFILE:
11903  return EMFILE;
11904  case FILEIO_EFBIG:
11905  return EFBIG;
11906  case FILEIO_ENOSPC:
11907  return ENOSPC;
11908  case FILEIO_ESPIPE:
11909  return ESPIPE;
11910  case FILEIO_EROFS:
11911  return EROFS;
11912  case FILEIO_ENOSYS:
11913  return ENOSYS;
11914  case FILEIO_ENAMETOOLONG:
11915  return ENAMETOOLONG;
11916  }
11917  return -1;
11918 }
11919 
11920 static char *
11922 {
11923  int host_error = remote_fileio_errno_to_host (errnum);
11924 
11925  if (host_error == -1)
11926  error (_("Unknown remote I/O error %d"), errnum);
11927  else
11928  error (_("Remote I/O error: %s"), safe_strerror (host_error));
11929 }
11930 
11931 static void
11933 {
11934  int fd = *(int *) opaque;
11935  int remote_errno;
11936 
11937  remote_hostio_close (find_target_at (process_stratum), fd, &remote_errno);
11938 }
11939 
11940 void
11941 remote_file_put (const char *local_file, const char *remote_file, int from_tty)
11942 {
11943  struct cleanup *back_to, *close_cleanup;
11944  int retcode, fd, remote_errno, bytes, io_size;
11945  gdb_byte *buffer;
11946  int bytes_in_buffer;
11947  int saw_eof;
11948  ULONGEST offset;
11949  struct remote_state *rs = get_remote_state ();
11950 
11951  if (!rs->remote_desc)
11952  error (_("command can only be used with remote target"));
11953 
11954  gdb_file_up file = gdb_fopen_cloexec (local_file, "rb");
11955  if (file == NULL)
11956  perror_with_name (local_file);
11957 
11959  remote_file, (FILEIO_O_WRONLY | FILEIO_O_CREAT
11960  | FILEIO_O_TRUNC),
11961  0700, 0, &remote_errno);
11962  if (fd == -1)
11963  remote_hostio_error (remote_errno);
11964 
11965  /* Send up to this many bytes at once. They won't all fit in the
11966  remote packet limit, so we'll transfer slightly fewer. */
11967  io_size = get_remote_packet_size ();
11968  buffer = (gdb_byte *) xmalloc (io_size);
11969  back_to = make_cleanup (xfree, buffer);
11970 
11971  close_cleanup = make_cleanup (remote_hostio_close_cleanup, &fd);
11972 
11973  bytes_in_buffer = 0;
11974  saw_eof = 0;
11975  offset = 0;
11976  while (bytes_in_buffer || !saw_eof)
11977  {
11978  if (!saw_eof)
11979  {
11980  bytes = fread (buffer + bytes_in_buffer, 1,
11981  io_size - bytes_in_buffer,
11982  file.get ());
11983  if (bytes == 0)
11984  {
11985  if (ferror (file.get ()))
11986  error (_("Error reading %s."), local_file);
11987  else
11988  {
11989  /* EOF. Unless there is something still in the
11990  buffer from the last iteration, we are done. */
11991  saw_eof = 1;
11992  if (bytes_in_buffer == 0)
11993  break;
11994  }
11995  }
11996  }
11997  else
11998  bytes = 0;
11999 
12000  bytes += bytes_in_buffer;
12001  bytes_in_buffer = 0;
12002 
12004  fd, buffer, bytes,
12005  offset, &remote_errno);
12006 
12007  if (retcode < 0)
12008  remote_hostio_error (remote_errno);
12009  else if (retcode == 0)
12010  error (_("Remote write of %d bytes returned 0!"), bytes);
12011  else if (retcode < bytes)
12012  {
12013  /* Short write. Save the rest of the read data for the next
12014  write. */
12015  bytes_in_buffer = bytes - retcode;
12016  memmove (buffer, buffer + retcode, bytes_in_buffer);
12017  }
12018 
12019  offset += retcode;
12020  }
12021 
12022  discard_cleanups (close_cleanup);
12023  if (remote_hostio_close (find_target_at (process_stratum), fd, &remote_errno))
12024  remote_hostio_error (remote_errno);
12025 
12026  if (from_tty)
12027  printf_filtered (_("Successfully sent file \"%s\".\n"), local_file);
12028  do_cleanups (back_to);
12029 }
12030 
12031 void
12032 remote_file_get (const char *remote_file, const char *local_file, int from_tty)
12033 {
12034  struct cleanup *back_to, *close_cleanup;
12035  int fd, remote_errno, bytes, io_size;
12036  gdb_byte *buffer;
12037  ULONGEST offset;
12038  struct remote_state *rs = get_remote_state ();
12039 
12040  if (!rs->remote_desc)
12041  error (_("command can only be used with remote target"));
12042 
12044  remote_file, FILEIO_O_RDONLY, 0, 0,
12045  &remote_errno);
12046  if (fd == -1)
12047  remote_hostio_error (remote_errno);
12048 
12049  gdb_file_up file = gdb_fopen_cloexec (local_file, "wb");
12050  if (file == NULL)
12051  perror_with_name (local_file);
12052 
12053  /* Send up to this many bytes at once. They won't all fit in the
12054  remote packet limit, so we'll transfer slightly fewer. */
12055  io_size = get_remote_packet_size ();
12056  buffer = (gdb_byte *) xmalloc (io_size);
12057  back_to = make_cleanup (xfree, buffer);
12058 
12059  close_cleanup = make_cleanup (remote_hostio_close_cleanup, &fd);
12060 
12061  offset = 0;
12062  while (1)
12063  {
12065  fd, buffer, io_size, offset, &remote_errno);
12066  if (bytes == 0)
12067  /* Success, but no bytes, means end-of-file. */
12068  break;
12069  if (bytes == -1)
12070  remote_hostio_error (remote_errno);
12071 
12072  offset += bytes;
12073 
12074  bytes = fwrite (buffer, 1, bytes, file.get ());
12075  if (bytes == 0)
12076  perror_with_name (local_file);
12077  }
12078 
12079  discard_cleanups (close_cleanup);
12080  if (remote_hostio_close (find_target_at (process_stratum), fd, &remote_errno))
12081  remote_hostio_error (remote_errno);
12082 
12083  if (from_tty)
12084  printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file);
12085  do_cleanups (back_to);
12086 }
12087 
12088 void
12089 remote_file_delete (const char *remote_file, int from_tty)
12090 {
12091  int retcode, remote_errno;
12092  struct remote_state *rs = get_remote_state ();
12093 
12094  if (!rs->remote_desc)
12095  error (_("command can only be used with remote target"));
12096 
12098  NULL, remote_file, &remote_errno);
12099  if (retcode == -1)
12100  remote_hostio_error (remote_errno);
12101 
12102  if (from_tty)
12103  printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file);
12104 }
12105 
12106 static void
12107 remote_put_command (const char *args, int from_tty)
12108 {
12109  if (args == NULL)
12110  error_no_arg (_("file to put"));
12111 
12112  gdb_argv argv (args);
12113  if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
12114  error (_("Invalid parameters to remote put"));
12115 
12116  remote_file_put (argv[0], argv[1], from_tty);
12117 }
12118 
12119 static void
12120 remote_get_command (const char *args, int from_tty)
12121 {
12122  if (args == NULL)
12123  error_no_arg (_("file to get"));
12124 
12125  gdb_argv argv (args);
12126  if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
12127  error (_("Invalid parameters to remote get"));
12128 
12129  remote_file_get (argv[0], argv[1], from_tty);
12130 }
12131 
12132 static void
12133 remote_delete_command (const char *args, int from_tty)
12134 {
12135  if (args == NULL)
12136  error_no_arg (_("file to delete"));
12137 
12138  gdb_argv argv (args);
12139  if (argv[0] == NULL || argv[1] != NULL)
12140  error (_("Invalid parameters to remote delete"));
12141 
12142  remote_file_delete (argv[0], from_tty);
12143 }
12144 
12145 static void
12146 remote_command (const char *args, int from_tty)
12147 {
12149 }
12150 
12151 static int
12153 {
12156  return 1;
12157  else
12158  return 0;
12159 }
12160 
12161 static int
12163 {
12164  return 1;
12165 }
12166 
12167 static int
12169 {
12170  /* Only supported in extended mode. */
12171  return 0;
12172 }
12173 
12174 static int
12176 {
12177  struct remote_state *rs = get_remote_state ();
12178 
12179  return remote_multi_process_p (rs);
12180 }
12181 
12182 static int
12184 {
12186 }
12187 
12188 static int
12190 {
12192 }
12193 
12194 static int
12196 {
12198 }
12199 
12200 static int
12202 {
12204 }
12205 
12206 static int
12208 {
12210 }
12211 
12212 static int
12214 {
12216  == PACKET_ENABLE);
12217 }
12218 
12219 static int
12221 {
12223 }
12224 
12225 static int
12227 {
12229 }
12230 
12231 static void
12233 {
12234  struct remote_state *rs = get_remote_state ();
12235 
12236  putpkt ("QTinit");
12238  if (strcmp (rs->buf, "OK") != 0)
12239  error (_("Target does not support this command."));
12240 }
12241 
12242 /* Recursive routine to walk through command list including loops, and
12243  download packets for each command. */
12244 
12245 static void
12247  struct command_line *cmds)
12248 {
12249  struct remote_state *rs = get_remote_state ();
12250  struct command_line *cmd;
12251 
12252  for (cmd = cmds; cmd; cmd = cmd->next)
12253  {
12254  QUIT; /* Allow user to bail out with ^C. */
12255  strcpy (rs->buf, "QTDPsrc:");
12256  encode_source_string (num, addr, "cmd", cmd->line,
12257  rs->buf + strlen (rs->buf),
12258  rs->buf_size - strlen (rs->buf));
12259  putpkt (rs->buf);
12261  if (strcmp (rs->buf, "OK"))
12262  warning (_("Target does not support source download."));
12263 
12264  if (cmd->control_type == while_control
12266  {
12267  remote_download_command_source (num, addr, *cmd->body_list);
12268 
12269  QUIT; /* Allow user to bail out with ^C. */
12270  strcpy (rs->buf, "QTDPsrc:");
12271  encode_source_string (num, addr, "cmd", "end",
12272  rs->buf + strlen (rs->buf),
12273  rs->buf_size - strlen (rs->buf));
12274  putpkt (rs->buf);
12276  if (strcmp (rs->buf, "OK"))
12277  warning (_("Target does not support source download."));
12278  }
12279  }
12280 }
12281 
12282 static void
12284 {
12285 #define BUF_SIZE 2048
12286 
12287  CORE_ADDR tpaddr;
12288  char addrbuf[40];
12289  char buf[BUF_SIZE];
12290  std::vector<std::string> tdp_actions;
12291  std::vector<std::string> stepping_actions;
12292  char *pkt;
12293  struct breakpoint *b = loc->owner;
12294  struct tracepoint *t = (struct tracepoint *) b;
12295  struct remote_state *rs = get_remote_state ();
12296 
12297  encode_actions_rsp (loc, &tdp_actions, &stepping_actions);
12298 
12299  tpaddr = loc->address;
12300  sprintf_vma (addrbuf, tpaddr);
12301  xsnprintf (buf, BUF_SIZE, "QTDP:%x:%s:%c:%lx:%x", b->number,
12302  addrbuf, /* address */
12303  (b->enable_state == bp_enabled ? 'E' : 'D'),
12304  t->step_count, t->pass_count);
12305  /* Fast tracepoints are mostly handled by the target, but we can
12306  tell the target how big of an instruction block should be moved
12307  around. */
12308  if (b->type == bp_fast_tracepoint)
12309  {
12310  /* Only test for support at download time; we may not know
12311  target capabilities at definition time. */
12313  {
12314  if (gdbarch_fast_tracepoint_valid_at (loc->gdbarch, tpaddr,
12315  NULL))
12316  xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":F%x",
12317  gdb_insn_length (loc->gdbarch, tpaddr));
12318  else
12319  /* If it passed validation at definition but fails now,
12320  something is very wrong. */
12321  internal_error (__FILE__, __LINE__,
12322  _("Fast tracepoint not "
12323  "valid during download"));
12324  }
12325  else
12326  /* Fast tracepoints are functionally identical to regular
12327  tracepoints, so don't take lack of support as a reason to
12328  give up on the trace run. */
12329  warning (_("Target does not support fast tracepoints, "
12330  "downloading %d as regular tracepoint"), b->number);
12331  }
12332  else if (b->type == bp_static_tracepoint)
12333  {
12334  /* Only test for support at download time; we may not know
12335  target capabilities at definition time. */
12337  {
12338  struct static_tracepoint_marker marker;
12339 
12340  if (target_static_tracepoint_marker_at (tpaddr, &marker))
12341  strcat (buf, ":S");
12342  else
12343  error (_("Static tracepoint not valid during download"));
12344  }
12345  else
12346  /* Fast tracepoints are functionally identical to regular
12347  tracepoints, so don't take lack of support as a reason
12348  to give up on the trace run. */
12349  error (_("Target does not support static tracepoints"));
12350  }
12351  /* If the tracepoint has a conditional, make it into an agent
12352  expression and append to the definition. */
12353  if (loc->cond)
12354  {
12355  /* Only test support at download time, we may not know target
12356  capabilities at definition time. */
12358  {
12359  agent_expr_up aexpr = gen_eval_for_expr (tpaddr, loc->cond.get ());
12360  xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":X%x,",
12361  aexpr->len);
12362  pkt = buf + strlen (buf);
12363  for (int ndx = 0; ndx < aexpr->len; ++ndx)
12364  pkt = pack_hex_byte (pkt, aexpr->buf[ndx]);
12365  *pkt = '\0';
12366  }
12367  else
12368  warning (_("Target does not support conditional tracepoints, "
12369  "ignoring tp %d cond"), b->number);
12370  }
12371 
12372  if (b->commands || *default_collect)
12373  strcat (buf, "-");
12374  putpkt (buf);
12376  if (strcmp (rs->buf, "OK"))
12377  error (_("Target does not support tracepoints."));
12378 
12379  /* do_single_steps (t); */
12380  for (auto action_it = tdp_actions.begin ();
12381  action_it != tdp_actions.end (); action_it++)
12382  {
12383  QUIT; /* Allow user to bail out with ^C. */
12384 
12385  bool has_more = (action_it != tdp_actions.end ()
12386  || !stepping_actions.empty ());
12387 
12388  xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%c",
12389  b->number, addrbuf, /* address */
12390  action_it->c_str (),
12391  has_more ? '-' : 0);
12392  putpkt (buf);
12394  if (strcmp (rs->buf, "OK"))
12395  error (_("Error on target while setting tracepoints."));
12396  }
12397 
12398  for (auto action_it = stepping_actions.begin ();
12399  action_it != stepping_actions.end (); action_it++)
12400  {
12401  QUIT; /* Allow user to bail out with ^C. */
12402 
12403  bool is_first = action_it == stepping_actions.begin ();
12404  bool has_more = action_it != stepping_actions.end ();
12405 
12406  xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%s%s",
12407  b->number, addrbuf, /* address */
12408  is_first ? "S" : "",
12409  action_it->c_str (),
12410  has_more ? "-" : "");
12411  putpkt (buf);
12413  if (strcmp (rs->buf, "OK"))
12414  error (_("Error on target while setting tracepoints."));
12415  }
12416 
12418  {
12419  if (b->location != NULL)
12420  {
12421  strcpy (buf, "QTDPsrc:");
12422  encode_source_string (b->number, loc->address, "at",
12423  event_location_to_string (b->location.get ()),
12424  buf + strlen (buf), 2048 - strlen (buf));
12425  putpkt (buf);
12427  if (strcmp (rs->buf, "OK"))
12428  warning (_("Target does not support source download."));
12429  }
12430  if (b->cond_string)
12431  {
12432  strcpy (buf, "QTDPsrc:");
12433  encode_source_string (b->number, loc->address,
12434  "cond", b->cond_string, buf + strlen (buf),
12435  2048 - strlen (buf));
12436  putpkt (buf);
12438  if (strcmp (rs->buf, "OK"))
12439  warning (_("Target does not support source download."));
12440  }
12442  breakpoint_commands (b));
12443  }
12444 }
12445 
12446 static int
12448 {
12449  struct remote_state *rs = get_remote_state ();
12450  struct trace_status *ts;
12451  int status;
12452 
12453  /* Don't try to install tracepoints until we've relocated our
12454  symbols, and fetched and merged the target's tracepoint list with
12455  ours. */
12456  if (rs->starting_up)
12457  return 0;
12458 
12459  ts = current_trace_status ();
12460  status = remote_get_trace_status (self, ts);
12461 
12462  if (status == -1 || !ts->running_known || !ts->running)
12463  return 0;
12464 
12465  /* If we are in a tracing experiment, but remote stub doesn't support
12466  installing tracepoint in trace, we have to return. */
12468  return 0;
12469 
12470  return 1;
12471 }
12472 
12473 
12474 static void
12476  struct trace_state_variable *tsv)
12477 {
12478  struct remote_state *rs = get_remote_state ();
12479  char *p;
12480 
12481  xsnprintf (rs->buf, get_remote_packet_size (), "QTDV:%x:%s:%x:",
12482  tsv->number, phex ((ULONGEST) tsv->initial_value, 8),
12483  tsv->builtin);
12484  p = rs->buf + strlen (rs->buf);
12485  if ((p - rs->buf) + strlen (tsv->name) * 2 >= get_remote_packet_size ())
12486  error (_("Trace state variable name too long for tsv definition packet"));
12487  p += 2 * bin2hex ((gdb_byte *) (tsv->name), p, strlen (tsv->name));
12488  *p++ = '\0';
12489  putpkt (rs->buf);
12491  if (*rs->buf == '\0')
12492  error (_("Target does not support this command."));
12493  if (strcmp (rs->buf, "OK") != 0)
12494  error (_("Error on target while downloading trace state variable."));
12495 }
12496 
12497 static void
12499  struct bp_location *location)
12500 {
12501  struct remote_state *rs = get_remote_state ();
12502  char addr_buf[40];
12503 
12504  sprintf_vma (addr_buf, location->address);
12505  xsnprintf (rs->buf, get_remote_packet_size (), "QTEnable:%x:%s",
12506  location->owner->number, addr_buf);
12507  putpkt (rs->buf);
12509  if (*rs->buf == '\0')
12510  error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
12511  if (strcmp (rs->buf, "OK") != 0)
12512  error (_("Error on target while enabling tracepoint."));
12513 }
12514 
12515 static void
12517  struct bp_location *location)
12518 {
12519  struct remote_state *rs = get_remote_state ();
12520  char addr_buf[40];
12521 
12522  sprintf_vma (addr_buf, location->address);
12523  xsnprintf (rs->buf, get_remote_packet_size (), "QTDisable:%x:%s",
12524  location->owner->number, addr_buf);
12525  putpkt (rs->buf);
12527  if (*rs->buf == '\0')
12528  error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
12529  if (strcmp (rs->buf, "OK") != 0)
12530  error (_("Error on target while disabling tracepoint."));
12531 }
12532 
12533 static void
12535 {
12536  asection *s;
12537  bfd *abfd = NULL;
12538  bfd_size_type size;
12539  bfd_vma vma;
12540  int anysecs = 0;
12541  int offset = 0;
12542 
12543  if (!exec_bfd)
12544  return; /* No information to give. */
12545 
12546  struct remote_state *rs = get_remote_state ();
12547 
12548  strcpy (rs->buf, "QTro");
12549  offset = strlen (rs->buf);
12550  for (s = exec_bfd->sections; s; s = s->next)
12551  {
12552  char tmp1[40], tmp2[40];
12553  int sec_length;
12554 
12555  if ((s->flags & SEC_LOAD) == 0 ||
12556  /* (s->flags & SEC_CODE) == 0 || */
12557  (s->flags & SEC_READONLY) == 0)
12558  continue;
12559 
12560  anysecs = 1;
12561  vma = bfd_get_section_vma (abfd, s);
12562  size = bfd_get_section_size (s);
12563  sprintf_vma (tmp1, vma);
12564  sprintf_vma (tmp2, vma + size);
12565  sec_length = 1 + strlen (tmp1) + 1 + strlen (tmp2);
12566  if (offset + sec_length + 1 > rs->buf_size)
12567  {
12569  warning (_("\
12570 Too many sections for read-only sections definition packet."));
12571  break;
12572  }
12573  xsnprintf (rs->buf + offset, rs->buf_size - offset, ":%s,%s",
12574  tmp1, tmp2);
12575  offset += sec_length;
12576  }
12577  if (anysecs)
12578  {
12579  putpkt (rs->buf);
12580  getpkt (&rs->buf, &rs->buf_size, 0);
12581  }
12582 }
12583 
12584 static void
12586 {
12587  struct remote_state *rs = get_remote_state ();
12588 
12589  putpkt ("QTStart");
12591  if (*rs->buf == '\0')
12592  error (_("Target does not support this command."));
12593  if (strcmp (rs->buf, "OK") != 0)
12594  error (_("Bogus reply from target: %s"), rs->buf);
12595 }
12596 
12597 static int
12599 {
12600  /* Initialize it just to avoid a GCC false warning. */
12601  char *p = NULL;
12602  /* FIXME we need to get register block size some other way. */
12603  extern int trace_regblock_size;
12604  enum packet_result result;
12605  struct remote_state *rs = get_remote_state ();
12606 
12608  return -1;
12609 
12612 
12613  putpkt ("qTStatus");
12614 
12615  TRY
12616  {
12617  p = remote_get_noisy_reply ();
12618  }
12619  CATCH (ex, RETURN_MASK_ERROR)
12620  {
12621  if (ex.error != TARGET_CLOSE_ERROR)
12622  {
12623  exception_fprintf (gdb_stderr, ex, "qTStatus: ");
12624  return -1;
12625  }
12626  throw_exception (ex);
12627  }
12628  END_CATCH
12629 
12631 
12632  /* If the remote target doesn't do tracing, flag it. */
12633  if (result == PACKET_UNKNOWN)
12634  return -1;
12635 
12636  /* We're working with a live target. */
12637  ts->filename = NULL;
12638 
12639  if (*p++ != 'T')
12640  error (_("Bogus trace status reply from target: %s"), rs->buf);
12641 
12642  /* Function 'parse_trace_status' sets default value of each field of
12643  'ts' at first, so we don't have to do it here. */
12644  parse_trace_status (p, ts);
12645 
12646  return ts->running;
12647 }
12648 
12649 static void
12651  struct uploaded_tp *utp)
12652 {
12653  struct remote_state *rs = get_remote_state ();
12654  char *reply;
12655  struct bp_location *loc;
12656  struct tracepoint *tp = (struct tracepoint *) bp;
12657  size_t size = get_remote_packet_size ();
12658 
12659  if (tp)
12660  {
12661  tp->hit_count = 0;
12662  tp->traceframe_usage = 0;
12663  for (loc = tp->loc; loc; loc = loc->next)
12664  {
12665  /* If the tracepoint was never downloaded, don't go asking for
12666  any status. */
12667  if (tp->number_on_target == 0)
12668  continue;
12669  xsnprintf (rs->buf, size, "qTP:%x:%s", tp->number_on_target,
12670  phex_nz (loc->address, 0));
12671  putpkt (rs->buf);
12672  reply = remote_get_noisy_reply ();
12673  if (reply && *reply)
12674  {
12675  if (*reply == 'V')
12676  parse_tracepoint_status (reply + 1, bp, utp);
12677  }
12678  }
12679  }
12680  else if (utp)
12681  {
12682  utp->hit_count = 0;
12683  utp->traceframe_usage = 0;
12684  xsnprintf (rs->buf, size, "qTP:%x:%s", utp->number,
12685  phex_nz (utp->addr, 0));
12686  putpkt (rs->buf);
12687  reply = remote_get_noisy_reply ();
12688  if (reply && *reply)
12689  {
12690  if (*reply == 'V')
12691  parse_tracepoint_status (reply + 1, bp, utp);
12692  }
12693  }
12694 }
12695 
12696 static void
12698 {
12699  struct remote_state *rs = get_remote_state ();
12700 
12701  putpkt ("QTStop");
12703  if (*rs->buf == '\0')
12704  error (_("Target does not support this command."));
12705  if (strcmp (rs->buf, "OK") != 0)
12706  error (_("Bogus reply from target: %s"), rs->buf);
12707 }
12708 
12709 static int
12711  enum trace_find_type type, int num,
12712  CORE_ADDR addr1, CORE_ADDR addr2,
12713  int *tpp)
12714 {
12715  struct remote_state *rs = get_remote_state ();
12716  char *endbuf = rs->buf + get_remote_packet_size ();
12717  char *p, *reply;
12718  int target_frameno = -1, target_tracept = -1;
12719 
12720  /* Lookups other than by absolute frame number depend on the current
12721  trace selected, so make sure it is correct on the remote end
12722  first. */
12723  if (type != tfind_number)
12725 
12726  p = rs->buf;
12727  strcpy (p, "QTFrame:");
12728  p = strchr (p, '\0');
12729  switch (type)
12730  {
12731  case tfind_number:
12732  xsnprintf (p, endbuf - p, "%x", num);
12733  break;
12734  case tfind_pc:
12735  xsnprintf (p, endbuf - p, "pc:%s", phex_nz (addr1, 0));
12736  break;
12737  case tfind_tp:
12738  xsnprintf (p, endbuf - p, "tdp:%x", num);
12739  break;
12740  case tfind_range:
12741  xsnprintf (p, endbuf - p, "range:%s:%s", phex_nz (addr1, 0),
12742  phex_nz (addr2, 0));
12743  break;
12744  case tfind_outside:
12745  xsnprintf (p, endbuf - p, "outside:%s:%s", phex_nz (addr1, 0),
12746  phex_nz (addr2, 0));
12747  break;
12748  default:
12749  error (_("Unknown trace find type %d"), type);
12750  }
12751 
12752  putpkt (rs->buf);
12753  reply = remote_get_noisy_reply ();
12754  if (*reply == '\0')
12755  error (_("Target does not support this command."));
12756 
12757  while (reply && *reply)
12758  switch (*reply)
12759  {
12760  case 'F':
12761  p = ++reply;
12762  target_frameno = (int) strtol (p, &reply, 16);
12763  if (reply == p)
12764  error (_("Unable to parse trace frame number"));
12765  /* Don't update our remote traceframe number cache on failure
12766  to select a remote traceframe. */
12767  if (target_frameno == -1)
12768  return -1;
12769  break;
12770  case 'T':
12771  p = ++reply;
12772  target_tracept = (int) strtol (p, &reply, 16);
12773  if (reply == p)
12774  error (_("Unable to parse tracepoint number"));
12775  break;
12776  case 'O': /* "OK"? */
12777  if (reply[1] == 'K' && reply[2] == '\0')
12778  reply += 2;
12779  else
12780  error (_("Bogus reply from target: %s"), reply);
12781  break;
12782  default:
12783  error (_("Bogus reply from target: %s"), reply);
12784  }
12785  if (tpp)
12786  *tpp = target_tracept;
12787 
12788  rs->remote_traceframe_number = target_frameno;
12789  return target_frameno;
12790 }
12791 
12792 static int
12794  int tsvnum, LONGEST *val)
12795 {
12796  struct remote_state *rs = get_remote_state ();
12797  char *reply;
12798  ULONGEST uval;
12799 
12801 
12802  xsnprintf (rs->buf, get_remote_packet_size (), "qTV:%x", tsvnum);
12803  putpkt (rs->buf);
12804  reply = remote_get_noisy_reply ();
12805  if (reply && *reply)
12806  {
12807  if (*reply == 'V')
12808  {
12809  unpack_varlen_hex (reply + 1, &uval);
12810  *val = (LONGEST) uval;
12811  return 1;
12812  }
12813  }
12814  return 0;
12815 }
12816 
12817 static int
12818 remote_save_trace_data (struct target_ops *self, const char *filename)
12819 {
12820  struct remote_state *rs = get_remote_state ();
12821  char *p, *reply;
12822 
12823  p = rs->buf;
12824  strcpy (p, "QTSave:");
12825  p += strlen (p);
12826  if ((p - rs->buf) + strlen (filename) * 2 >= get_remote_packet_size ())
12827  error (_("Remote file name too long for trace save packet"));
12828  p += 2 * bin2hex ((gdb_byte *) filename, p, strlen (filename));
12829  *p++ = '\0';
12830  putpkt (rs->buf);
12831  reply = remote_get_noisy_reply ();
12832  if (*reply == '\0')
12833  error (_("Target does not support this command."));
12834  if (strcmp (reply, "OK") != 0)
12835  error (_("Bogus reply from target: %s"), reply);
12836  return 0;
12837 }
12838 
12839 /* This is basically a memory transfer, but needs to be its own packet
12840  because we don't know how the target actually organizes its trace
12841  memory, plus we want to be able to ask for as much as possible, but
12842  not be unhappy if we don't get as much as we ask for. */
12843 
12844 static LONGEST
12847 {
12848  struct remote_state *rs = get_remote_state ();
12849  char *reply;
12850  char *p;
12851  int rslt;
12852 
12853  p = rs->buf;
12854  strcpy (p, "qTBuffer:");
12855  p += strlen (p);
12856  p += hexnumstr (p, offset);
12857  *p++ = ',';
12858  p += hexnumstr (p, len);
12859  *p++ = '\0';
12860 
12861  putpkt (rs->buf);
12862  reply = remote_get_noisy_reply ();
12863  if (reply && *reply)
12864  {
12865  /* 'l' by itself means we're at the end of the buffer and
12866  there is nothing more to get. */
12867  if (*reply == 'l')
12868  return 0;
12869 
12870  /* Convert the reply into binary. Limit the number of bytes to
12871  convert according to our passed-in buffer size, rather than
12872  what was returned in the packet; if the target is
12873  unexpectedly generous and gives us a bigger reply than we
12874  asked for, we don't want to crash. */
12875  rslt = hex2bin (reply, buf, len);
12876  return rslt;
12877  }
12878 
12879  /* Something went wrong, flag as an error. */
12880  return -1;
12881 }
12882 
12883 static void
12885 {
12886  struct remote_state *rs = get_remote_state ();
12887 
12889  {
12890  char *reply;
12891 
12892  xsnprintf (rs->buf, get_remote_packet_size (), "QTDisconnected:%x", val);
12893  putpkt (rs->buf);
12894  reply = remote_get_noisy_reply ();
12895  if (*reply == '\0')
12896  error (_("Target does not support this command."));
12897  if (strcmp (reply, "OK") != 0)
12898  error (_("Bogus reply from target: %s"), reply);
12899  }
12900  else if (val)
12901  warning (_("Target does not support disconnected tracing."));
12902 }
12903 
12904 static int
12906 {
12907  struct thread_info *info = find_thread_ptid (ptid);
12908 
12909  if (info != NULL && info->priv != NULL)
12910  return get_remote_thread_info (info)->core;
12911 
12912  return -1;
12913 }
12914 
12915 static void
12917 {
12918  struct remote_state *rs = get_remote_state ();
12919  char *reply;
12920 
12921  xsnprintf (rs->buf, get_remote_packet_size (), "QTBuffer:circular:%x", val);
12922  putpkt (rs->buf);
12923  reply = remote_get_noisy_reply ();
12924  if (*reply == '\0')
12925  error (_("Target does not support this command."));
12926  if (strcmp (reply, "OK") != 0)
12927  error (_("Bogus reply from target: %s"), reply);
12928 }
12929 
12930 static traceframe_info_up
12932 {
12935  NULL);
12936  if (text != NULL)
12937  return parse_traceframe_info (text.get ());
12938 
12939  return NULL;
12940 }
12941 
12942 /* Handle the qTMinFTPILen packet. Returns the minimum length of
12943  instruction on which a fast tracepoint may be placed. Returns -1
12944  if the packet is not supported, and 0 if the minimum instruction
12945  length is unknown. */
12946 
12947 static int
12949 {
12950  struct remote_state *rs = get_remote_state ();
12951  char *reply;
12952 
12953  /* If we're not debugging a process yet, the IPA can't be
12954  loaded. */
12955  if (!target_has_execution)
12956  return 0;
12957 
12958  /* Make sure the remote is pointing at the right process. */
12960 
12961  xsnprintf (rs->buf, get_remote_packet_size (), "qTMinFTPILen");
12962  putpkt (rs->buf);
12963  reply = remote_get_noisy_reply ();
12964  if (*reply == '\0')
12965  return -1;
12966  else
12967  {
12968  ULONGEST min_insn_len;
12969 
12970  unpack_varlen_hex (reply, &min_insn_len);
12971 
12972  return (int) min_insn_len;
12973  }
12974 }
12975 
12976 static void
12978 {
12980  {
12981  struct remote_state *rs = get_remote_state ();
12982  char *buf = rs->buf;
12983  char *endbuf = rs->buf + get_remote_packet_size ();
12984  enum packet_result result;
12985 
12986  gdb_assert (val >= 0 || val == -1);
12987  buf += xsnprintf (buf, endbuf - buf, "QTBuffer:size:");
12988  /* Send -1 as literal "-1" to avoid host size dependency. */
12989  if (val < 0)
12990  {
12991  *buf++ = '-';
12992  buf += hexnumstr (buf, (ULONGEST) -val);
12993  }
12994  else
12995  buf += hexnumstr (buf, (ULONGEST) val);
12996 
12997  putpkt (rs->buf);
12999  result = packet_ok (rs->buf,
13001 
13002  if (result != PACKET_OK)
13003  warning (_("Bogus reply from target: %s"), rs->buf);
13004  }
13005 }
13006 
13007 static int
13009  const char *user, const char *notes,
13010  const char *stop_notes)
13011 {
13012  struct remote_state *rs = get_remote_state ();
13013  char *reply;
13014  char *buf = rs->buf;
13015  char *endbuf = rs->buf + get_remote_packet_size ();
13016  int nbytes;
13017 
13018  buf += xsnprintf (buf, endbuf - buf, "QTNotes:");
13019  if (user)
13020  {
13021  buf += xsnprintf (buf, endbuf - buf, "user:");
13022  nbytes = bin2hex ((gdb_byte *) user, buf, strlen (user));
13023  buf += 2 * nbytes;
13024  *buf++ = ';';
13025  }
13026  if (notes)
13027  {
13028  buf += xsnprintf (buf, endbuf - buf, "notes:");
13029  nbytes = bin2hex ((gdb_byte *) notes, buf, strlen (notes));
13030  buf += 2 * nbytes;
13031  *buf++ = ';';
13032  }
13033  if (stop_notes)
13034  {
13035  buf += xsnprintf (buf, endbuf - buf, "tstop:");
13036  nbytes = bin2hex ((gdb_byte *) stop_notes, buf, strlen (stop_notes));
13037  buf += 2 * nbytes;
13038  *buf++ = ';';
13039  }
13040  /* Ensure the buffer is terminated. */
13041  *buf = '\0';
13042 
13043  putpkt (rs->buf);
13044  reply = remote_get_noisy_reply ();
13045  if (*reply == '\0')
13046  return 0;
13047 
13048  if (strcmp (reply, "OK") != 0)
13049  error (_("Bogus reply from target: %s"), reply);
13050 
13051  return 1;
13052 }
13053 
13054 static int
13055 remote_use_agent (struct target_ops *self, int use)
13056 {
13058  {
13059  struct remote_state *rs = get_remote_state ();
13060 
13061  /* If the stub supports QAgent. */
13062  xsnprintf (rs->buf, get_remote_packet_size (), "QAgent:%d", use);
13063  putpkt (rs->buf);
13064  getpkt (&rs->buf, &rs->buf_size, 0);
13065 
13066  if (strcmp (rs->buf, "OK") == 0)
13067  {
13068  use_agent = use;
13069  return 1;
13070  }
13071  }
13072 
13073  return 0;
13074 }
13075 
13076 static int
13078 {
13080 }
13081 
13082 struct btrace_target_info
13083 {
13084  /* The ptid of the traced thread. */
13085  ptid_t ptid;
13086 
13087  /* The obtained branch trace configuration. */
13088  struct btrace_config conf;
13089 };
13090 
13091 /* Reset our idea of our target's btrace configuration. */
13092 
13093 static void
13095 {
13096  struct remote_state *rs = get_remote_state ();
13097 
13098  memset (&rs->btrace_config, 0, sizeof (rs->btrace_config));
13099 }
13100 
13101 /* Check whether the target supports branch tracing. */
13102 
13103 static int
13105 {
13107  return 0;
13109  return 0;
13110 
13111  switch (format)
13112  {
13113  case BTRACE_FORMAT_NONE:
13114  return 0;
13115 
13116  case BTRACE_FORMAT_BTS:
13118 
13119  case BTRACE_FORMAT_PT:
13120  /* The trace is decoded on the host. Even if our target supports it,
13121  we still need to have libipt to decode the trace. */
13122 #if defined (HAVE_LIBIPT)
13124 #else /* !defined (HAVE_LIBIPT) */
13125  return 0;
13126 #endif /* !defined (HAVE_LIBIPT) */
13127  }
13128 
13129  internal_error (__FILE__, __LINE__, _("Unknown branch trace format"));
13130 }
13131 
13132 /* Synchronize the configuration with the target. */
13133 
13134 static void
13135 btrace_sync_conf (const struct btrace_config *conf)
13136 {
13137  struct packet_config *packet;
13138  struct remote_state *rs;
13139  char *buf, *pos, *endbuf;
13140 
13141  rs = get_remote_state ();
13142  buf = rs->buf;
13143  endbuf = buf + get_remote_packet_size ();
13144 
13146  if (packet_config_support (packet) == PACKET_ENABLE
13147  && conf->bts.size != rs->btrace_config.bts.size)
13148  {
13149  pos = buf;
13150  pos += xsnprintf (pos, endbuf - pos, "%s=0x%x", packet->name,
13151  conf->bts.size);
13152 
13153  putpkt (buf);
13154  getpkt (&buf, &rs->buf_size, 0);
13155 
13156  if (packet_ok (buf, packet) == PACKET_ERROR)
13157  {
13158  if (buf[0] == 'E' && buf[1] == '.')
13159  error (_("Failed to configure the BTS buffer size: %s"), buf + 2);
13160  else
13161  error (_("Failed to configure the BTS buffer size."));
13162  }
13163 
13164  rs->btrace_config.bts.size = conf->bts.size;
13165  }
13166 
13168  if (packet_config_support (packet) == PACKET_ENABLE
13169  && conf->pt.size != rs->btrace_config.pt.size)
13170  {
13171  pos = buf;
13172  pos += xsnprintf (pos, endbuf - pos, "%s=0x%x", packet->name,
13173  conf->pt.size);
13174 
13175  putpkt (buf);
13176  getpkt (&buf, &rs->buf_size, 0);
13177 
13178  if (packet_ok (buf, packet) == PACKET_ERROR)
13179  {
13180  if (buf[0] == 'E' && buf[1] == '.')
13181  error (_("Failed to configure the trace buffer size: %s"), buf + 2);
13182  else
13183  error (_("Failed to configure the trace buffer size."));
13184  }
13185 
13186  rs->btrace_config.pt.size = conf->pt.size;
13187  }
13188 }
13189 
13190 /* Read the current thread's btrace configuration from the target and
13191  store it into CONF. */
13192 
13193 static void
13195 {
13198  if (xml != NULL)
13199  parse_xml_btrace_conf (conf, xml.get ());
13200 }
13201 
13202 /* Maybe reopen target btrace. */
13203 
13204 static void
13206 {
13207  struct remote_state *rs = get_remote_state ();
13208  struct thread_info *tp;
13209  int btrace_target_pushed = 0;
13210  int warned = 0;
13211 
13212  scoped_restore_current_thread restore_thread;
13213 
13215  {
13216  set_general_thread (tp->ptid);
13217 
13218  memset (&rs->btrace_config, 0x00, sizeof (struct btrace_config));
13220 
13222  continue;
13223 
13224 #if !defined (HAVE_LIBIPT)
13226  {
13227  if (!warned)
13228  {
13229  warned = 1;
13230  warning (_("GDB does not support Intel Processor Trace. "
13231  "\"record\" will not work in this session."));
13232  }
13233 
13234  continue;
13235  }
13236 #endif /* !defined (HAVE_LIBIPT) */
13237 
13238  /* Push target, once, but before anything else happens. This way our
13239  changes to the threads will be cleaned up by unpushing the target
13240  in case btrace_read_config () throws. */
13241  if (!btrace_target_pushed)
13242  {
13243  btrace_target_pushed = 1;
13245  printf_filtered (_("Target is recording using %s.\n"),
13247  }
13248 
13249  tp->btrace.target = XCNEW (struct btrace_target_info);
13250  tp->btrace.target->ptid = tp->ptid;
13251  tp->btrace.target->conf = rs->btrace_config;
13252  }
13253 }
13254 
13255 /* Enable branch tracing. */
13256 
13257 static struct btrace_target_info *
13259  const struct btrace_config *conf)
13260 {
13261  struct btrace_target_info *tinfo = NULL;
13262  struct packet_config *packet = NULL;
13263  struct remote_state *rs = get_remote_state ();
13264  char *buf = rs->buf;
13265  char *endbuf = rs->buf + get_remote_packet_size ();
13266 
13267  switch (conf->format)
13268  {
13269  case BTRACE_FORMAT_BTS:
13271  break;
13272 
13273  case BTRACE_FORMAT_PT:
13275  break;
13276  }
13277 
13278  if (packet == NULL || packet_config_support (packet) != PACKET_ENABLE)
13279  error (_("Target does not support branch tracing."));
13280 
13281  btrace_sync_conf (conf);
13282 
13283  set_general_thread (ptid);
13284 
13285  buf += xsnprintf (buf, endbuf - buf, "%s", packet->name);
13286  putpkt (rs->buf);
13287  getpkt (&rs->buf, &rs->buf_size, 0);
13288 
13289  if (packet_ok (rs->buf, packet) == PACKET_ERROR)
13290  {
13291  if (rs->buf[0] == 'E' && rs->buf[1] == '.')
13292  error (_("Could not enable branch tracing for %s: %s"),
13293  target_pid_to_str (ptid), rs->buf + 2);
13294  else
13295  error (_("Could not enable branch tracing for %s."),
13296  target_pid_to_str (ptid));
13297  }
13298 
13299  tinfo = XCNEW (struct btrace_target_info);
13300  tinfo->ptid = ptid;
13301 
13302  /* If we fail to read the configuration, we lose some information, but the
13303  tracing itself is not impacted. */
13304  TRY
13305  {
13306  btrace_read_config (&tinfo->conf);
13307  }
13309  {
13310  if (err.message != NULL)
13311  warning ("%s", err.message);
13312  }
13313  END_CATCH
13314 
13315  return tinfo;
13316 }
13317 
13318 /* Disable branch tracing. */
13319 
13320 static void
13322  struct btrace_target_info *tinfo)
13323 {
13325  struct remote_state *rs = get_remote_state ();
13326  char *buf = rs->buf;
13327  char *endbuf = rs->buf + get_remote_packet_size ();
13328 
13329  if (packet_config_support (packet) != PACKET_ENABLE)
13330  error (_("Target does not support branch tracing."));
13331 
13332  set_general_thread (tinfo->ptid);
13333 
13334  buf += xsnprintf (buf, endbuf - buf, "%s", packet->name);
13335  putpkt (rs->buf);
13336  getpkt (&rs->buf, &rs->buf_size, 0);
13337 
13338  if (packet_ok (rs->buf, packet) == PACKET_ERROR)
13339  {
13340  if (rs->buf[0] == 'E' && rs->buf[1] == '.')
13341  error (_("Could not disable branch tracing for %s: %s"),
13342  target_pid_to_str (tinfo->ptid), rs->buf + 2);
13343  else
13344  error (_("Could not disable branch tracing for %s."),
13345  target_pid_to_str (tinfo->ptid));
13346  }
13347 
13348  xfree (tinfo);
13349 }
13350 
13351 /* Teardown branch tracing. */
13352 
13353 static void
13355  struct btrace_target_info *tinfo)
13356 {
13357  /* We must not talk to the target during teardown. */
13358  xfree (tinfo);
13359 }
13360 
13361 /* Read the branch trace. */
13362 
13363 static enum btrace_error
13365  struct btrace_data *btrace,
13366  struct btrace_target_info *tinfo,
13367  enum btrace_read_type type)
13368 {
13370  const char *annex;
13371 
13372  if (packet_config_support (packet) != PACKET_ENABLE)
13373  error (_("Target does not support branch tracing."));
13374 
13375 #if !defined(HAVE_LIBEXPAT)
13376  error (_("Cannot process branch tracing result. XML parsing not supported."));
13377 #endif
13378 
13379  switch (type)
13380  {
13381  case BTRACE_READ_ALL:
13382  annex = "all";
13383  break;
13384  case BTRACE_READ_NEW:
13385  annex = "new";
13386  break;
13387  case BTRACE_READ_DELTA:
13388  annex = "delta";
13389  break;
13390  default:
13391  internal_error (__FILE__, __LINE__,
13392  _("Bad branch tracing read type: %u."),
13393  (unsigned int) type);
13394  }
13395 
13398  if (xml == NULL)
13399  return BTRACE_ERR_UNKNOWN;
13400 
13401  parse_xml_btrace (btrace, xml.get ());
13402 
13403  return BTRACE_ERR_NONE;
13404 }
13405 
13406 static const struct btrace_config *
13408  const struct btrace_target_info *tinfo)
13409 {
13410  return &tinfo->conf;
13411 }
13412 
13413 static int
13415 {
13417  == PACKET_ENABLE);
13418 }
13419 
13420 /* Implementation of to_load. */
13421 
13422 static void
13423 remote_load (struct target_ops *self, const char *name, int from_tty)
13424 {
13425  generic_load (name, from_tty);
13426 }
13427 
13428 /* Accepts an integer PID; returns a string representing a file that
13429  can be opened on the remote side to get the symbols for the child
13430  process. Returns NULL if the operation is not supported. */
13431 
13432 static char *
13434 {
13435  static gdb::unique_xmalloc_ptr<char> filename;
13436  struct inferior *inf;
13437  char *annex = NULL;
13438 
13440  return NULL;
13441 
13443  if (inf == NULL)
13444  internal_error (__FILE__, __LINE__,
13445  _("not currently attached to process %d"), pid);
13446 
13447  if (!inf->fake_pid_p)
13448  {
13449  const int annex_size = 9;
13450 
13451  annex = (char *) alloca (annex_size);
13452  xsnprintf (annex, annex_size, "%x", pid);
13453  }
13454 
13455  filename = target_read_stralloc (&current_target,
13456  TARGET_OBJECT_EXEC_FILE, annex);
13457 
13458  return filename.get ();
13459 }
13460 
13461 /* Implement the to_can_do_single_step target_ops method. */
13462 
13463 static int
13465 {
13466  /* We can only tell whether target supports single step or not by
13467  supported s and S vCont actions if the stub supports vContSupported
13468  feature. If the stub doesn't support vContSupported feature,
13469  we have conservatively to think target doesn't supports single
13470  step. */
13472  {
13473  struct remote_state *rs = get_remote_state ();
13474 
13476  remote_vcont_probe (rs);
13477 
13478  return rs->supports_vCont.s && rs->supports_vCont.S;
13479  }
13480  else
13481  return 0;
13482 }
13483 
13484 /* Implementation of the to_execution_direction method for the remote
13485  target. */
13486 
13487 static enum exec_direction_kind
13489 {
13490  struct remote_state *rs = get_remote_state ();
13491 
13492  return rs->last_resume_exec_dir;
13493 }
13494 
13495 /* Return pointer to the thread_info struct which corresponds to
13496  THREAD_HANDLE (having length HANDLE_LEN). */
13497 
13498 static struct thread_info *
13500  const gdb_byte *thread_handle,
13501  int handle_len,
13502  struct inferior *inf)
13503 {
13504  struct thread_info *tp;
13505 
13507  {
13509 
13510  if (tp->inf == inf && priv != NULL)
13511  {
13512  if (handle_len != priv->thread_handle.size ())
13513  error (_("Thread handle size mismatch: %d vs %zu (from remote)"),
13514  handle_len, priv->thread_handle.size ());
13515  if (memcmp (thread_handle, priv->thread_handle.data (),
13516  handle_len) == 0)
13517  return tp;
13518  }
13519  }
13520 
13521  return NULL;
13522 }
13523 
13524 static void
13526 {
13527  remote_ops.to_shortname = "remote";
13528  remote_ops.to_longname = "Remote serial target in gdb-specific protocol";
13529  remote_ops.to_doc =
13530  "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13531 Specify the serial device it is connected to\n\
13532 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
13588  remote_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */
13591  remote_ops.to_memory_map = remote_memory_map;
13650  remote_ops.to_static_tracepoint_markers_by_strid
13651  = remote_static_tracepoint_markers_by_strid;
13674 }
13675 
13676 /* Set up the extended remote vector by making a copy of the standard
13677  remote vector and adding to it. */
13678 
13679 static void
13681 {
13683 
13684  extended_remote_ops.to_shortname = "extended-remote";
13686  "Extended remote serial target in gdb-specific protocol";
13688  "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13689 Specify the serial device it is connected to (e.g. /dev/ttya).";
13697 }
13698 
13699 static int
13701 {
13702  struct remote_state *rs = get_remote_state ();
13703 
13704  /* We don't go async if the user has explicitly prevented it with the
13705  "maint set target-async" command. */
13707  return 0;
13708 
13709  /* We're async whenever the serial device is. */
13710  return serial_can_async_p (rs->remote_desc);
13711 }
13712 
13713 static int
13715 {
13716  struct remote_state *rs = get_remote_state ();
13717 
13719  /* We only enable async when the user specifically asks for it. */
13720  return 0;
13721 
13722  /* We're async whenever the serial device is. */
13723  return serial_is_async_p (rs->remote_desc);
13724 }
13725 
13726 /* Pass the SERIAL event on and up to the client. One day this code
13727  will be able to delay notifying the client of an event until the
13728  point where an entire packet has been received. */
13729 
13731 
13732 static void
13733 remote_async_serial_handler (struct serial *scb, void *context)
13734 {
13735  /* Don't propogate error information up to the client. Instead let
13736  the client find out about the error by querying the target. */
13738 }
13739 
13740 static void
13742 {
13744 }
13745 
13746 static void
13747 remote_async (struct target_ops *ops, int enable)
13748 {
13749  struct remote_state *rs = get_remote_state ();
13750 
13751  if (enable)
13752  {
13754 
13755  /* If there are pending events in the stop reply queue tell the
13756  event loop to process them. */
13757  if (!QUEUE_is_empty (stop_reply_p, stop_reply_queue))
13759  /* For simplicity, below we clear the pending events token
13760  without remembering whether it is marked, so here we always
13761  mark it. If there's actually no pending notification to
13762  process, this ends up being a no-op (other than a spurious
13763  event-loop wakeup). */
13764  if (target_is_non_stop_p ())
13766  }
13767  else
13768  {
13769  serial_async (rs->remote_desc, NULL, NULL);
13770  /* If the core is disabling async, it doesn't want to be
13771  disturbed with target events. Clear all async event sources
13772  too. */
13774  if (target_is_non_stop_p ())
13776  }
13777 }
13778 
13779 /* Implementation of the to_thread_events method. */
13780 
13781 static void
13783 {
13784  struct remote_state *rs = get_remote_state ();
13785  size_t size = get_remote_packet_size ();
13786 
13788  return;
13789 
13790  xsnprintf (rs->buf, size, "QThreadEvents:%x", enable ? 1 : 0);
13791  putpkt (rs->buf);
13792  getpkt (&rs->buf, &rs->buf_size, 0);
13793 
13794  switch (packet_ok (rs->buf,
13796  {
13797  case PACKET_OK:
13798  if (strcmp (rs->buf, "OK") != 0)
13799  error (_("Remote refused setting thread events: %s"), rs->buf);
13800  break;
13801  case PACKET_ERROR:
13802  warning (_("Remote failure reply: %s"), rs->buf);
13803  break;
13804  case PACKET_UNKNOWN:
13805  break;
13806  }
13807 }
13808 
13809 static void
13810 set_remote_cmd (const char *args, int from_tty)
13811 {
13813 }
13814 
13815 static void
13816 show_remote_cmd (const char *args, int from_tty)
13817 {
13818  /* We can't just use cmd_show_list here, because we want to skip
13819  the redundant "show remote Z-packet" and the legacy aliases. */
13820  struct cmd_list_element *list = remote_show_cmdlist;
13821  struct ui_out *uiout = current_uiout;
13822 
13823  ui_out_emit_tuple tuple_emitter (uiout, "showlist");
13824  for (; list != NULL; list = list->next)
13825  if (strcmp (list->name, "Z-packet") == 0)
13826  continue;
13827  else if (list->type == not_set_cmd)
13828  /* Alias commands are exactly like the original, except they
13829  don't have the normal type. */
13830  continue;
13831  else
13832  {
13833  ui_out_emit_tuple option_emitter (uiout, "option");
13834 
13835  uiout->field_string ("name", list->name);
13836  uiout->text (": ");
13837  if (list->type == show_cmd)
13838  do_show_command (NULL, from_tty, list);
13839  else
13840  cmd_func (list, NULL, from_tty);
13841  }
13842 }
13843 
13844 
13845 /* Function to be called whenever a new objfile (shlib) is detected. */
13846 static void
13848 {
13849  struct remote_state *rs = get_remote_state ();
13850 
13851  if (rs->remote_desc != 0) /* Have a remote connection. */
13853 }
13854 
13855 /* Pull all the tracepoints defined on the target and create local
13856  data structures representing them. We don't want to create real
13857  tracepoints yet, we don't want to mess up the user's existing
13858  collection. */
13859 
13860 static int
13861 remote_upload_tracepoints (struct target_ops *self, struct uploaded_tp **utpp)
13862 {
13863  struct remote_state *rs = get_remote_state ();
13864  char *p;
13865 
13866  /* Ask for a first packet of tracepoint definition. */
13867  putpkt ("qTfP");
13868  getpkt (&rs->buf, &rs->buf_size, 0);
13869  p = rs->buf;
13870  while (*p && *p != 'l')
13871  {
13872  parse_tracepoint_definition (p, utpp);
13873  /* Ask for another packet of tracepoint definition. */
13874  putpkt ("qTsP");
13875  getpkt (&rs->buf, &rs->buf_size, 0);
13876  p = rs->buf;
13877  }
13878  return 0;
13879 }
13880 
13881 static int
13883  struct uploaded_tsv **utsvp)
13884 {
13885  struct remote_state *rs = get_remote_state ();
13886  char *p;
13887 
13888  /* Ask for a first packet of variable definition. */
13889  putpkt ("qTfV");
13890  getpkt (&rs->buf, &rs->buf_size, 0);
13891  p = rs->buf;
13892  while (*p && *p != 'l')
13893  {
13894  parse_tsv_definition (p, utsvp);
13895  /* Ask for another packet of variable definition. */
13896  putpkt ("qTsV");
13897  getpkt (&rs->buf, &rs->buf_size, 0);
13898  p = rs->buf;
13899  }
13900  return 0;
13901 }
13902 
13903 /* The "set/show range-stepping" show hook. */
13904 
13905 static void
13906 show_range_stepping (struct ui_file *file, int from_tty,
13907  struct cmd_list_element *c,
13908  const char *value)
13909 {
13910  fprintf_filtered (file,
13911  _("Debugger's willingness to use range stepping "
13912  "is %s.\n"), value);
13913 }
13914 
13915 /* The "set/show range-stepping" set hook. */
13916 
13917 static void
13918 set_range_stepping (const char *ignore_args, int from_tty,
13919  struct cmd_list_element *c)
13920 {
13921  struct remote_state *rs = get_remote_state ();
13922 
13923  /* Whene enabling, check whether range stepping is actually
13924  supported by the target, and warn if not. */
13925  if (use_range_stepping)
13926  {
13927  if (rs->remote_desc != NULL)
13928  {
13930  remote_vcont_probe (rs);
13931 
13933  && rs->supports_vCont.r)
13934  return;
13935  }
13936 
13937  warning (_("Range stepping is not supported by the current target"));
13938  }
13939 }
13940 
13941 void
13943 {
13944  struct cmd_list_element *cmd;
13945  const char *cmd_name;
13946 
13947  /* architecture specific data */
13952 
13954  = register_program_space_data_with_cleanup (NULL,
13956 
13957  /* Initialize the per-target state. At the moment there is only one
13958  of these, not one per target. Only one target is active at a
13959  time. */
13961 
13962  init_remote_ops ();
13964 
13967 
13968  /* Hook into new objfile notification. */
13970  /* We're no longer interested in notification events of an inferior
13971  when it exits. */
13973 
13974 #if 0
13975  init_remote_threadtests ();
13976 #endif
13977 
13978  stop_reply_queue = QUEUE_alloc (stop_reply_p, stop_reply_xfree);
13979  /* set/show remote ... */
13980 
13982 Remote protocol specific variables\n\
13983 Configure various remote-protocol specific variables such as\n\
13984 the packets being used"),
13985  &remote_set_cmdlist, "set remote ",
13986  0 /* allow-unknown */, &setlist);
13988 Remote protocol specific variables\n\
13989 Configure various remote-protocol specific variables such as\n\
13990 the packets being used"),
13991  &remote_show_cmdlist, "show remote ",
13992  0 /* allow-unknown */, &showlist);
13993 
13994  add_cmd ("compare-sections", class_obscure, compare_sections_command, _("\
13995 Compare section data on target to the exec file.\n\
13996 Argument is a single section name (default: all loaded sections).\n\
13997 To compare only read-only loaded sections, specify the -r option."),
13998  &cmdlist);
13999 
14000  add_cmd ("packet", class_maintenance, packet_command, _("\
14001 Send an arbitrary packet to a remote target.\n\
14002  maintenance packet TEXT\n\
14003 If GDB is talking to an inferior via the GDB serial protocol, then\n\
14004 this command sends the string TEXT to the inferior, and displays the\n\
14005 response packet. GDB supplies the initial `$' character, and the\n\
14006 terminating `#' character and checksum."),
14007  &maintenancelist);
14008 
14009  add_setshow_boolean_cmd ("remotebreak", no_class, &remote_break, _("\
14010 Set whether to send break if interrupted."), _("\
14011 Show whether to send break if interrupted."), _("\
14012 If set, a break, instead of a cntrl-c, is sent to the remote target."),
14014  &setlist, &showlist);
14015  cmd_name = "remotebreak";
14016  cmd = lookup_cmd (&cmd_name, setlist, "", -1, 1);
14017  deprecate_cmd (cmd, "set remote interrupt-sequence");
14018  cmd_name = "remotebreak"; /* needed because lookup_cmd updates the pointer */
14019  cmd = lookup_cmd (&cmd_name, showlist, "", -1, 1);
14020  deprecate_cmd (cmd, "show remote interrupt-sequence");
14021 
14022  add_setshow_enum_cmd ("interrupt-sequence", class_support,
14024  _("\
14025 Set interrupt sequence to remote target."), _("\
14026 Show interrupt sequence to remote target."), _("\
14027 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
14031 
14032  add_setshow_boolean_cmd ("interrupt-on-connect", class_support,
14033  &interrupt_on_connect, _("\
14034 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
14035 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
14036 If set, interrupt sequence is sent to remote target."),
14037  NULL, NULL,
14039 
14040  /* Install commands for configuring memory read/write packets. */
14041 
14042  add_cmd ("remotewritesize", no_class, set_memory_write_packet_size, _("\
14043 Set the maximum number of bytes per memory write packet (deprecated)."),
14044  &setlist);
14045  add_cmd ("remotewritesize", no_class, show_memory_write_packet_size, _("\
14046 Show the maximum number of bytes per memory write packet (deprecated)."),
14047  &showlist);
14048  add_cmd ("memory-write-packet-size", no_class,
14050 Set the maximum number of bytes per memory-write packet.\n\
14051 Specify the number of bytes in a packet or 0 (zero) for the\n\
14052 default packet size. The actual limit is further reduced\n\
14053 dependent on the target. Specify ``fixed'' to disable the\n\
14054 further restriction and ``limit'' to enable that restriction."),
14056  add_cmd ("memory-read-packet-size", no_class,
14058 Set the maximum number of bytes per memory-read packet.\n\
14059 Specify the number of bytes in a packet or 0 (zero) for the\n\
14060 default packet size. The actual limit is further reduced\n\
14061 dependent on the target. Specify ``fixed'' to disable the\n\
14062 further restriction and ``limit'' to enable that restriction."),
14064  add_cmd ("memory-write-packet-size", no_class,
14066  _("Show the maximum number of bytes per memory-write packet."),
14068  add_cmd ("memory-read-packet-size", no_class,
14070  _("Show the maximum number of bytes per memory-read packet."),
14072 
14073  add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class,
14075 Set the maximum number of target hardware watchpoints."), _("\
14076 Show the maximum number of target hardware watchpoints."), _("\
14077 Specify a negative limit for unlimited."),
14078  NULL, NULL, /* FIXME: i18n: The maximum
14079  number of target hardware
14080  watchpoints is %s. */
14082  add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class,
14084 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
14085 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
14086 Specify a negative limit for unlimited."),
14087  NULL, NULL, /* FIXME: i18n: The maximum
14088  length (in bytes) of a target
14089  hardware watchpoint is %s. */
14091  add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class,
14093 Set the maximum number of target hardware breakpoints."), _("\
14094 Show the maximum number of target hardware breakpoints."), _("\
14095 Specify a negative limit for unlimited."),
14096  NULL, NULL, /* FIXME: i18n: The maximum
14097  number of target hardware
14098  breakpoints is %s. */
14100 
14101  add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure,
14102  &remote_address_size, _("\
14103 Set the maximum size of the address (in bits) in a memory packet."), _("\
14104 Show the maximum size of the address (in bits) in a memory packet."), NULL,
14105  NULL,
14106  NULL, /* FIXME: i18n: */
14107  &setlist, &showlist);
14108 
14110 
14112  "X", "binary-download", 1);
14113 
14115  "vCont", "verbose-resume", 0);
14116 
14118  "QPassSignals", "pass-signals", 0);
14119 
14121  "QCatchSyscalls", "catch-syscalls", 0);
14122 
14124  "QProgramSignals", "program-signals", 0);
14125 
14127  "QSetWorkingDir", "set-working-dir", 0);
14128 
14130  "QStartupWithShell", "startup-with-shell", 0);
14131 
14134  "QEnvironmentHexEncoded", "environment-hex-encoded",
14135  0);
14136 
14138  "QEnvironmentReset", "environment-reset",
14139  0);
14140 
14142  "QEnvironmentUnset", "environment-unset",
14143  0);
14144 
14146  "qSymbol", "symbol-lookup", 0);
14147 
14149  "P", "set-register", 1);
14150 
14152  "p", "fetch-register", 1);
14153 
14155  "Z0", "software-breakpoint", 0);
14156 
14158  "Z1", "hardware-breakpoint", 0);
14159 
14161  "Z2", "write-watchpoint", 0);
14162 
14164  "Z3", "read-watchpoint", 0);
14165 
14167  "Z4", "access-watchpoint", 0);
14168 
14170  "qXfer:auxv:read", "read-aux-vector", 0);
14171 
14173  "qXfer:exec-file:read", "pid-to-exec-file", 0);
14174 
14176  "qXfer:features:read", "target-features", 0);
14177 
14179  "qXfer:libraries:read", "library-info", 0);
14180 
14182  "qXfer:libraries-svr4:read", "library-info-svr4", 0);
14183 
14185  "qXfer:memory-map:read", "memory-map", 0);
14186 
14188  "qXfer:spu:read", "read-spu-object", 0);
14189 
14191  "qXfer:spu:write", "write-spu-object", 0);
14192 
14194  "qXfer:osdata:read", "osdata", 0);
14195 
14197  "qXfer:threads:read", "threads", 0);
14198 
14200  "qXfer:siginfo:read", "read-siginfo-object", 0);
14201 
14203  "qXfer:siginfo:write", "write-siginfo-object", 0);
14204 
14207  "qXfer:traceframe-info:read", "traceframe-info", 0);
14208 
14210  "qXfer:uib:read", "unwind-info-block", 0);
14211 
14213  "qGetTLSAddr", "get-thread-local-storage-address",
14214  0);
14215 
14217  "qGetTIBAddr", "get-thread-information-block-address",
14218  0);
14219 
14221  "bc", "reverse-continue", 0);
14222 
14224  "bs", "reverse-step", 0);
14225 
14227  "qSupported", "supported-packets", 0);
14228 
14230  "qSearch:memory", "search-memory", 0);
14231 
14233  "qTStatus", "trace-status", 0);
14234 
14236  "vFile:setfs", "hostio-setfs", 0);
14237 
14239  "vFile:open", "hostio-open", 0);
14240 
14242  "vFile:pread", "hostio-pread", 0);
14243 
14245  "vFile:pwrite", "hostio-pwrite", 0);
14246 
14248  "vFile:close", "hostio-close", 0);
14249 
14251  "vFile:unlink", "hostio-unlink", 0);
14252 
14254  "vFile:readlink", "hostio-readlink", 0);
14255 
14257  "vFile:fstat", "hostio-fstat", 0);
14258 
14260  "vAttach", "attach", 0);
14261 
14263  "vRun", "run", 0);
14264 
14266  "QStartNoAckMode", "noack", 0);
14267 
14269  "vKill", "kill", 0);
14270 
14272  "qAttached", "query-attached", 0);
14273 
14275  "ConditionalTracepoints",
14276  "conditional-tracepoints", 0);
14277 
14279  "ConditionalBreakpoints",
14280  "conditional-breakpoints", 0);
14281 
14283  "BreakpointCommands",
14284  "breakpoint-commands", 0);
14285 
14287  "FastTracepoints", "fast-tracepoints", 0);
14288 
14290  "TracepointSource", "TracepointSource", 0);
14291 
14293  "QAllow", "allow", 0);
14294 
14296  "StaticTracepoints", "static-tracepoints", 0);
14297 
14299  "InstallInTrace", "install-in-trace", 0);
14300 
14302  "qXfer:statictrace:read", "read-sdata-object", 0);
14303 
14305  "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
14306 
14308  "QDisableRandomization", "disable-randomization", 0);
14309 
14311  "QAgent", "agent", 0);
14312 
14314  "QTBuffer:size", "trace-buffer-size", 0);
14315 
14317  "Qbtrace:off", "disable-btrace", 0);
14318 
14320  "Qbtrace:bts", "enable-btrace-bts", 0);
14321 
14323  "Qbtrace:pt", "enable-btrace-pt", 0);
14324 
14326  "qXfer:btrace", "read-btrace", 0);
14327 
14329  "qXfer:btrace-conf", "read-btrace-conf", 0);
14330 
14332  "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
14333 
14335  "multiprocess-feature", "multiprocess-feature", 0);
14336 
14338  "swbreak-feature", "swbreak-feature", 0);
14339 
14341  "hwbreak-feature", "hwbreak-feature", 0);
14342 
14344  "fork-event-feature", "fork-event-feature", 0);
14345 
14347  "vfork-event-feature", "vfork-event-feature", 0);
14348 
14350  "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
14351 
14353  "vContSupported", "verbose-resume-supported", 0);
14354 
14356  "exec-event-feature", "exec-event-feature", 0);
14357 
14359  "vCtrlC", "ctrl-c", 0);
14360 
14362  "QThreadEvents", "thread-events", 0);
14363 
14365  "N stop reply", "no-resumed-stop-reply", 0);
14366 
14367  /* Assert that we've registered "set remote foo-packet" commands
14368  for all packet configs. */
14369  {
14370  int i;
14371 
14372  for (i = 0; i < PACKET_MAX; i++)
14373  {
14374  /* Ideally all configs would have a command associated. Some
14375  still don't though. */
14376  int excepted;
14377 
14378  switch (i)
14379  {
14380  case PACKET_QNonStop:
14385  case PACKET_qCRC:
14386  /* Additions to this list need to be well justified:
14387  pre-existing packets are OK; new packets are not. */
14388  excepted = 1;
14389  break;
14390  default:
14391  excepted = 0;
14392  break;
14393  }
14394 
14395  /* This catches both forgetting to add a config command, and
14396  forgetting to remove a packet from the exception list. */
14397  gdb_assert (excepted == (remote_protocol_packets[i].name == NULL));
14398  }
14399  }
14400 
14401  /* Keep the old ``set remote Z-packet ...'' working. Each individual
14402  Z sub-packet has its own set and show commands, but users may
14403  have sets to this variable in their .gdbinit files (or in their
14404  documentation). */
14407 Set use of remote protocol `Z' packets"), _("\
14408 Show use of remote protocol `Z' packets "), _("\
14409 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
14410 packets."),
14413  /* FIXME: i18n: Use of remote protocol
14414  `Z' packets is %s. */
14416 
14417  add_prefix_cmd ("remote", class_files, remote_command, _("\
14418 Manipulate files on the remote system\n\
14419 Transfer files to and from the remote target system."),
14420  &remote_cmdlist, "remote ",
14421  0 /* allow-unknown */, &cmdlist);
14422 
14424  _("Copy a local file to the remote system."),
14425  &remote_cmdlist);
14426 
14428  _("Copy a remote file to the local system."),
14429  &remote_cmdlist);
14430 
14432  _("Delete a remote file."),
14433  &remote_cmdlist);
14434 
14436  &remote_exec_file_var, _("\
14437 Set the remote pathname for \"run\""), _("\
14438 Show the remote pathname for \"run\""), NULL,
14443 
14444  add_setshow_boolean_cmd ("range-stepping", class_run,
14445  &use_range_stepping, _("\
14446 Enable or disable range stepping."), _("\
14447 Show whether target-assisted range stepping is enabled."), _("\
14448 If on, and the target supports it, when stepping a source line, GDB\n\
14449 tells the target to step the corresponding range of addresses itself instead\n\
14450 of issuing multiple single-steps. This speeds up source level\n\
14451 stepping. If off, GDB always issues single-steps, even if range\n\
14452 stepping is supported by the target. The default is on."),
14455  &setlist,
14456  &showlist);
14457 
14458  /* Eventually initialize fileio. See fileio.c */
14460 
14461  /* Take advantage of the fact that the TID field is not used, to tag
14462  special ptids with it set to != 0. */
14463  magic_null_ptid = ptid_build (42000, -1, 1);
14464  not_sent_ptid = ptid_build (42000, -2, 1);
14465  any_thread_ptid = ptid_build (42000, 0, 1);
14466 }
void error_no_arg(const char *why)
Definition: cli-cmds.c:185
int(* to_fileio_pread)(struct target_ops *, int fd, gdb_byte *read_buf, int len, ULONGEST offset, int *target_errno)
Definition: target.h:908
enum exec_direction_kind last_resume_exec_dir
Definition: remote.c:401
struct gdbarch * target_gdbarch(void)
Definition: gdbarch.c:5467
long actual_register_packet_size
Definition: remote.c:540
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
Definition: gnu-nat.c:1822
static const struct btrace_config * remote_btrace_conf(struct target_ops *self, const struct btrace_target_info *tinfo)
Definition: remote.c:13407
static void show_remote_cmd(const char *args, int from_tty)
Definition: remote.c:13816
#define target_can_async_p()
Definition: target.h:1778
const char * string
Definition: signals.c:50
static enum packet_result remote_send_printf(const char *format,...) ATTRIBUTE_PRINTF(1
Definition: remote.c:8436
static int hexnumstr(char *, ULONGEST)
Definition: remote.c:7911
static int remote_use_agent(struct target_ops *self, int use)
Definition: remote.c:13055
void add_target(struct target_ops *t)
Definition: target.c:395
static int remote_multi_process_p(struct remote_state *rs)
Definition: remote.c:1627
struct notif_event base
Definition: remote.c:6265
CORE_ADDR reqstd_address
Definition: breakpoint.h:251
static int remote_insert_watchpoint(struct target_ops *self, CORE_ADDR addr, int len, enum target_hw_bp_type type, struct expression *cond)
Definition: remote.c:9880
int default_child_has_stack(struct target_ops *ops)
Definition: target.c:216
int serial_is_async_p(struct serial *scb)
Definition: serial.c:542
static void init_remote_ops(void)
Definition: remote.c:13525
const char * name
Definition: cli-decode.h:52
struct btrace_config_bts bts
void no_shared_libraries(const char *ignored, int from_tty)
Definition: solib.c:1261
static void interrupt_query(void)
Definition: remote.c:6205
static void show_memory_write_packet_size(const char *args, int from_tty)
Definition: remote.c:1144
static struct remote_state * new_remote_state(void)
Definition: remote.c:495
static void remote_set_permissions(struct target_ops *self)
Definition: remote.c:4454
gdb_byte * buf
Definition: remote.c:299
bp_location * loc
Definition: breakpoint.h:702
static const char * remote_pid_to_str(struct target_ops *ops, ptid_t ptid)
Definition: remote.c:10999
const char interrupt_sequence_control_c[]
Definition: remote.c:924
void release_static_tracepoint_marker(struct static_tracepoint_marker *marker)
Definition: tracepoint.c:3736
static void remote_flash_erase(struct target_ops *ops, ULONGEST address, LONGEST length)
Definition: remote.c:8463
static void show_interrupt_sequence(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: remote.c:937
struct command_line * breakpoint_commands(struct breakpoint *b)
Definition: breakpoint.c:303
void reopen_exec_file(void)
Definition: corefile.c:127
constexpr int pid() const
Definition: ptid.h:53
#define MIN_MEMORY_PACKET_SIZE
Definition: remote.c:1025
static constexpr ptid_t tid
struct cmd_list_element * next
Definition: cli-decode.h:49
struct thread_info * add_thread(ptid_t ptid)
Definition: thread.c:333
struct address_space * maybe_new_address_space(void)
Definition: progspace.c:73
static void extended_remote_post_attach(struct target_ops *ops, int pid)
Definition: remote.c:5373
struct thread_info * find_thread_ptid(ptid_t ptid)
Definition: thread.c:514
static int remote_get_trace_state_variable_value(struct target_ops *self, int tsvnum, LONGEST *val)
Definition: remote.c:12793
static int remote_remove_hw_breakpoint(struct target_ops *self, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition: remote.c:10139
CORE_ADDR offsets[1]
Definition: symtab.h:1273
int(* to_supports_stopped_by_hw_breakpoint)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:499
static int remote_watchpoint_addr_within_range(struct target_ops *target, CORE_ADDR addr, CORE_ADDR start, int length)
Definition: remote.c:9919
int remote_unescape_input(const gdb_byte *buffer, int len, gdb_byte *out_buf, int out_maxlen)
Definition: rsp-low.c:269
static enum target_xfer_status remote_read_bytes_1(CORE_ADDR memaddr, gdb_byte *myaddr, ULONGEST len_units, int unit_size, ULONGEST *xfered_len_units)
Definition: remote.c:8270
int(* to_supports_disable_randomization)(struct target_ops *)
Definition: target.h:842
const struct target_desc *(* to_read_description)(struct target_ops *ops) TARGET_DEFAULT_RETURN(NULL)
Definition: target.h:790
int(* to_is_async_p)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:668
static int remote_newthread_step(threadref *ref, void *context)
Definition: remote.c:3024
int trace_regblock_size
int(* to_upload_tracepoints)(struct target_ops *, struct uploaded_tp **utpp) TARGET_DEFAULT_RETURN(0)
Definition: target.h:1020
int putchar_unfiltered(int c)
Definition: utils.c:1817
const char * to_longname
Definition: target.h:416
void(* to_trace_init)(struct target_ops *) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:949
static ptid_t stop_reply_extract_thread(char *stop_reply)
Definition: remote.c:3706
int(* to_supports_evaluation_of_breakpoint_conditions)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:850
static enum packet_support packet_config_support(struct packet_config *config)
Definition: remote.c:1537
static ULONGEST remote_get_memory_xfer_limit(struct target_ops *ops)
Definition: remote.c:10645
int ptid_is_pid(const ptid_t &ptid)
Definition: ptid.c:79
#define SECT_OFF_TEXT(objfile)
Definition: objfiles.h:686
static int map_regcache_remote_table(struct gdbarch *gdbarch, struct packet_reg *regs)
Definition: remote.c:745
void(* to_program_signals)(struct target_ops *, int, unsigned char *TARGET_DEBUG_PRINTER(target_debug_print_signals)) TARGET_DEFAULT_IGNORE()
Definition: target.h:622
static int remote_hostio_parse_result(char *buffer, int *retcode, int *remote_errno, char **attachment)
Definition: remote.c:11312
static int remote_static_tracepoint_marker_at(struct target_ops *self, CORE_ADDR addr, struct static_tracepoint_marker *marker)
Definition: remote.c:3384
static char * pack_threadlist_request(char *pkt, int startflag, int threadcount, threadref *nextthread)
Definition: remote.c:2799
#define REMOTE_DEBUG_MAX_CHAR
Definition: remote.c:284
static struct memory_packet_config memory_read_packet_config
Definition: remote.c:1155
static int remote_resume_with_vcont(ptid_t ptid, int step, enum gdb_signal siggnal)
Definition: remote.c:5620
CORE_ADDR step_range_start
Definition: gdbthread.h:77
char * buf
Definition: remote.c:321
static int remote_upload_trace_state_variables(struct target_ops *self, struct uploaded_tsv **utsvp)
Definition: remote.c:13882
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2376
bool may_wildcard_vcont
Definition: remote.c:5768
std::unique_ptr< agent_expr > agent_expr_up
Definition: ax.h:159
char * finished_annex
Definition: remote.c:404
void parse_xml_btrace(struct btrace_data *btrace, const char *buffer)
Definition: btrace.c:2197
static void extended_remote_attach(struct target_ops *target, const char *args, int from_tty)
Definition: remote.c:5257
const char interrupt_sequence_break[]
Definition: remote.c:925
static void process_initial_stop_replies(int from_tty)
Definition: remote.c:3837
const char interrupt_sequence_break_g[]
Definition: remote.c:926
int remote_traceframe_number
Definition: remote.c:386
int have_inferiors(void)
Definition: inferior.c:408
static void kill_new_fork_children(int pid, struct remote_state *rs)
Definition: remote.c:9251
static void set_memory_read_packet_size(const char *args, int from_tty)
Definition: remote.c:1161
void target_announce_detach(int from_tty)
Definition: target.c:3177
struct frame_info * get_current_frame(void)
Definition: frame.c:1563
void field_string(const char *fldname, const char *string)
Definition: ui-out.c:544
bfd_vma CORE_ADDR
Definition: common-types.h:41
void remote_notif_process(struct remote_notif_state *state, struct notif_client *except)
Definition: remote-notif.c:101
char * last_pass_packet
Definition: remote.c:388
void * value
Definition: xml-support.h:78
constexpr size_type size() const noexcept
Definition: array-view.h:169
static int remote_can_execute_reverse(struct target_ops *self)
Definition: remote.c:12152
static void remote_terminal_ours(struct target_ops *self)
Definition: remote.c:6240
static int remote_can_download_tracepoint(struct target_ops *self)
Definition: remote.c:12447
#define GDB_SIGNAL_FIRST
ptid_t target_wait(ptid_t ptid, struct target_waitstatus *status, int options)
Definition: target.c:2177
const char * title
Definition: remote.c:1200
void insert_breakpoints(void)
Definition: breakpoint.c:2845
int(* to_fileio_close)(struct target_ops *, int fd, int *target_errno)
Definition: target.h:920
static void show_remote_protocol_Z_packet_cmd(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: remote.c:1612
static int remote_augmented_libraries_svr4_read(struct target_ops *self)
Definition: remote.c:13414
static int remote_hostio_send_command(int command_bytes, int which_packet, int *remote_errno, char **attachment, int *attachment_len)
Definition: remote.c:11368
int ptid_get_pid(const ptid_t &ptid)
Definition: ptid.c:47
void fputs_unfiltered(const char *buf, struct ui_file *file)
Definition: ui-file.c:127
static struct serial * remote_serial_open(const char *name)
Definition: remote.c:4425
void delete_thread(ptid_t)
Definition: thread.c:476
static int peek_stop_reply(ptid_t ptid)
Definition: remote.c:6728
static char * remote_support_xml
Definition: remote.c:4657
char shortname[32]
Definition: remote.c:2304
static const char * interrupt_sequence_mode
Definition: remote.c:934
void xfree(void *)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
Definition: gnu-nat.c:1824
static int threadmatch(threadref *dest, threadref *src)
Definition: remote.c:2634
int target_verify_memory(const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size)
Definition: target.c:3503
static struct remote_state * get_remote_state_raw(void)
Definition: remote.c:486
int may_insert_fast_tracepoints
void set_running(ptid_t ptid, int running)
Definition: thread.c:919
int(* rmt_thread_action)(threadref *ref, void *context)
Definition: remote.c:2374
static void remote_vcont_probe(struct remote_state *rs)
Definition: remote.c:5392
static void show_range_stepping(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: remote.c:13906
static void remote_add_thread(ptid_t ptid, int running, int executing)
Definition: remote.c:1826
static char * unpack_string(char *src, char *dest, int length)
Definition: remote.c:2544
struct cleanup * next
Definition: cleanups.c:40
__extension__ enum cmd_types type
Definition: cli-decode.h:100
void add_setshow_auto_boolean_cmd(const char *name, enum command_class theclass, enum auto_boolean *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:544
static char * unpack_threadid(char *inbuf, threadref *id)
Definition: remote.c:2567
static void remote_btrace_maybe_reopen(void)
Definition: remote.c:13205
int gdbarch_has_global_solist(struct gdbarch *gdbarch)
Definition: gdbarch.c:4602
#define GDBARCH_OBSTACK_CALLOC(GDBARCH, NR, TYPE)
Definition: gdbarch.h:1708
static enum Z_packet_type watchpoint_to_Z_packet(int type)
Definition: remote.c:9860
static int remote_supports_disable_randomization(struct target_ops *self)
Definition: remote.c:12168
static ptid_t remote_get_ada_task_ptid(struct target_ops *self, long lwp, long thread)
Definition: remote.c:3465
int remote_timeout
Definition: top.c:167
static void set_memory_packet_size(const char *args, struct memory_packet_config *config)
Definition: remote.c:1077
static void set_general_process(void)
Definition: remote.c:2205
static struct async_event_handler * remote_async_inferior_event_token
Definition: remote.c:1720
static void remote_parse_stop_reply(char *, struct stop_reply *)
Definition: remote.c:6750
if(!(yy_init))
Definition: ada-lex.c:1075
static const struct program_space_data * remote_pspace_data
Definition: remote.c:80
static char * unpack_byte(char *buf, int *value)
Definition: remote.c:2496
#define QUEUE_enque(TYPE, Q, V)
Definition: queue.h:55
#define INT_MAX
Definition: defs.h:477
threadref threadid
Definition: remote.c:2299
#define BMSYMBOL_VALUE_ADDRESS(symbol)
Definition: symtab.h:691
void set_quit_flag(void)
Definition: extension.c:804
int(* to_has_memory)(struct target_ops *)
Definition: target.h:658
void warning(const char *fmt,...)
Definition: errors.c:26
static void remote_flash_done(struct target_ops *ops)
Definition: remote.c:8497
struct cmd_list_element * deprecate_cmd(struct cmd_list_element *cmd, const char *replacement)
Definition: cli-decode.c:292
void(* to_trace_start)(struct target_ops *) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:984
enum target_stop_reason stop_reason
Definition: remote.c:454
static int remote_get_min_fast_tracepoint_insn_len(struct target_ops *self)
Definition: remote.c:12948
CORE_ADDR * segment_bases
Definition: symfile.h:85
static char * remote_get_noisy_reply()
Definition: remote.c:569
void getpkt(char **buf, long *sizeof_buf, int forever)
Definition: remote.c:9044
static void scan(struct macro_buffer *dest, struct macro_buffer *src, struct macro_name_list *no_loop, macro_lookup_ftype *lookup_func, void *lookup_baton)
Definition: macroexp.c:1446
void(* to_flash_done)(struct target_ops *) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:783
int query(const char *ctlstr,...)
Definition: utils.c:1063
enum gdb_signal last_sent_signal
Definition: remote.c:396
void init_wait_for_inferior(void)
Definition: infrun.c:3252
unsigned available
Definition: go32-nat.c:1072
int disable_randomization
Definition: infrun.c:175
int(* to_has_stack)(struct target_ops *)
Definition: target.h:659
std::string name
Definition: remote.c:2970
counted_command_line commands
Definition: breakpoint.h:719
void push_target(struct target_ops *t)
Definition: target.c:642
int(* to_insert_breakpoint)(struct target_ops *, struct gdbarch *, struct bp_target_info *) TARGET_DEFAULT_FUNC(memory_insert_breakpoint)
Definition: target.h:466
int bin2hex(const gdb_byte *bin, char *hex, int count)
Definition: rsp-low.c:173
char * get_exec_file(int err)
Definition: corefile.c:167
static void set_remote_traceframe(void)
Definition: remote.c:7675
static void remote_new_objfile(struct objfile *objfile)
Definition: remote.c:13847
void register_remote_support_xml(const char *xml)
Definition: remote.c:4662
int gdb_insn_length(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: disasm.c:826
#define QUEUE_length(TYPE, Q)
Definition: queue.h:73
void(* to_rcmd)(struct target_ops *, const char *command, struct ui_file *output) TARGET_DEFAULT_FUNC(default_rcmd)
Definition: target.h:647
std::vector< T, gdb::default_init_allocator< T > > def_vector
Definition: def-vector.h:32
static int check_pending_event_prevents_wildcard_vcont_callback(QUEUE(stop_reply_p) *q, QUEUE_ITER(stop_reply_p) *iter, stop_reply_p event, void *data)
Definition: remote.c:6501
static enum btrace_error remote_read_btrace(struct target_ops *self, struct btrace_data *btrace, struct btrace_target_info *tinfo, enum btrace_read_type type)
Definition: remote.c:13364
static int remote_hostio_unlink(struct target_ops *self, struct inferior *inf, const char *filename, int *remote_errno)
Definition: remote.c:11697
static void btrace_sync_conf(const struct btrace_config *conf)
Definition: remote.c:13135
#define QUEUE_is_empty(TYPE, Q)
Definition: queue.h:66
unsigned int size
static void remote_resume_with_hc(struct target_ops *ops, ptid_t ptid, int step, enum gdb_signal siggnal)
Definition: remote.c:5561
static void remote_pass_signals(struct target_ops *self, int numsigs, unsigned char *pass_signals)
Definition: remote.c:1975
int(* to_core_of_thread)(struct target_ops *, ptid_t ptid) TARGET_DEFAULT_RETURN(-1)
Definition: target.h:1063
ptid_t regcache_get_ptid(const struct regcache *regcache)
Definition: regcache.c:229
int unpush_target(struct target_ops *t)
Definition: target.c:689
int(* to_follow_fork)(struct target_ops *, int, int) TARGET_DEFAULT_FUNC(default_follow_fork)
Definition: target.h:592
static struct remote_arch_state * get_remote_arch_state(struct gdbarch *gdbarch)
Definition: remote.c:648
static void show_memory_read_packet_size(const char *args, int from_tty)
Definition: remote.c:1167
static const char * remote_threads_extra_info(struct target_ops *self, struct thread_info *tp)
Definition: remote.c:3300
void * memset(T *s, int c, size_t n)=delete
void internal_error(const char *file, int line, const char *fmt,...)
Definition: errors.c:50
struct thread_info * inferior_thread(void)
Definition: thread.c:90
int(* to_set_syscall_catchpoint)(struct target_ops *, int, bool, int, gdb::array_view< const int >) TARGET_DEFAULT_RETURN(1)
Definition: target.h:600
static enum target_xfer_status remote_write_bytes(CORE_ADDR memaddr, const gdb_byte *myaddr, ULONGEST len, int unit_size, ULONGEST *xfered_len)
Definition: remote.c:8227
void delete_async_event_handler(async_event_handler **async_handler_ptr)
Definition: event-loop.c:1075
static int wait_forever_enabled_p
Definition: remote.c:916
struct cmd_list_element * lookup_cmd(const char **line, struct cmd_list_element *list, const char *cmdtype, int allow_unknown, int ignore_help_classes)
Definition: cli-decode.c:1515
int info_verbose
Definition: top.c:1791
static enum target_xfer_status remote_flash_write(struct target_ops *ops, ULONGEST address, ULONGEST length, ULONGEST *xfered_len, const gdb_byte *data)
Definition: remote.c:8486
void generic_mourn_inferior(void)
Definition: target.c:3198
CORE_ADDR watch_data_address
Definition: remote.c:458
static void remote_rcmd(struct target_ops *self, const char *command, struct ui_file *outbuf)
Definition: remote.c:10743
void observer_notify_normal_stop(struct bpstats *bs, int print_frame)
void(* to_close)(struct target_ops *)
Definition: target.h:431
void objfile_relocate(struct objfile *objfile, const struct section_offsets *new_offsets)
Definition: objfiles.c:896
void add_setshow_enum_cmd(const char *name, enum command_class theclass, const char *const *enumlist, const char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:515
ULONGEST miss_count
Definition: remote.c:306
const char *(* to_pid_to_str)(struct target_ops *, ptid_t) TARGET_DEFAULT_FUNC(default_pid_to_str)
Definition: target.h:630
union target_waitstatus::@174 value
void mark_async_event_handler(async_event_handler *async_handler_ptr)
Definition: event-loop.c:1036
int serial_write(struct serial *scb, const void *buf, size_t count)
Definition: serial.c:411
const char * name
Definition: remote.c:1199
DEF_VEC_O(cached_reg_t)
static void remote_console_output(char *msg)
Definition: remote.c:6245
static void stop_reply_dtr(struct notif_event *event)
Definition: remote.c:6354
static int align_for_efficient_write(int todo, CORE_ADDR memaddr)
Definition: remote.c:8023
static void remote_trace_start(struct target_ops *self)
Definition: remote.c:12585
void remote_file_delete(const char *remote_file, int from_tty)
Definition: remote.c:12089
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition: cli-decode.c:262
static int remote_stopped_by_watchpoint(struct target_ops *ops)
Definition: remote.c:10054
ptid_t ptid
Definition: remote.c:2964
struct thread_info *(* to_thread_handle_to_thread_info)(struct target_ops *, const gdb_byte *, int, struct inferior *inf) TARGET_DEFAULT_RETURN(NULL)
Definition: target.h:636
ULONGEST hit_count
Definition: remote.c:305
static int remote_supports_stopped_by_hw_breakpoint(struct target_ops *ops)
Definition: remote.c:10048
Definition: ax.h:83
static int remove_child_of_pending_fork(QUEUE(stop_reply_p) *q, QUEUE_ITER(stop_reply_p) *iter, stop_reply_p event, void *data)
Definition: remote.c:6445
static int remote_remove_vfork_catchpoint(struct target_ops *ops, int pid)
Definition: remote.c:1691
static struct cmd_list_element * remote_cmdlist
Definition: remote.c:241
void reread_symbols(void)
Definition: symfile.c:2411
void target_async(int enable)
Definition: target.c:3860
static void remote_follow_exec(struct target_ops *ops, struct inferior *inf, char *execd_pathname)
Definition: remote.c:5224
struct notif_event * pending_event[REMOTE_NOTIF_LAST]
Definition: remote-notif.h:98
static int extended_remote_run(const std::string &args)
Definition: remote.c:9480
void remote_notif_get_pending_events(struct notif_client *nc)
Definition: remote.c:7148
static ptid_t remote_wait_as(ptid_t ptid, struct target_waitstatus *status, int options)
Definition: remote.c:7296
struct observer * observer_attach_inferior_exit(observer_inferior_exit_ftype *f)
static void extended_remote_detach(struct target_ops *ops, const char *args, int from_tty)
Definition: remote.c:5173
static struct cmd_list_element * remote_show_cmdlist
Definition: remote.c:246
#define VEC_safe_push(T, V, O)
Definition: vec.h:276
void(* to_set_disconnected_tracing)(struct target_ops *, int val) TARGET_DEFAULT_IGNORE()
Definition: target.h:1041
struct inferior * find_inferior_ptid(ptid_t ptid)
Definition: inferior.c:321
static void remote_set_disconnected_tracing(struct target_ops *self, int val)
Definition: remote.c:12884
struct readahead_cache readahead_cache
Definition: remote.c:439
struct cmd_list_element * cmdlist
Definition: cli-cmds.c:79
std::vector< thread_item > items
Definition: remote.c:3020
enum thread_state state
Definition: gdbthread.h:287
static int remote_unpack_thread_info_response(char *pkt, threadref *expectedref, struct gdb_ext_thread_info *info)
Definition: remote.c:2685
int tohex(int nib)
Definition: rsp-low.c:41
static CORE_ADDR remote_get_thread_local_address(struct target_ops *ops, ptid_t ptid, CORE_ADDR lm, CORE_ADDR offset)
Definition: remote.c:11048
#define QUEUE_remove_elem(TYPE, Q, ITER)
Definition: queue.h:88
int(* to_supports_enable_disable_tracepoint)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:838
int(* to_remove_watchpoint)(struct target_ops *, CORE_ADDR, int, enum target_hw_bp_type, struct expression *) TARGET_DEFAULT_RETURN(-1)
Definition: target.h:516
static void reset_all_packet_configs_support(void)
Definition: remote.c:4331
static int remote_upload_tracepoints(struct target_ops *self, struct uploaded_tp **utpp)
Definition: remote.c:13861
int(* to_region_ok_for_hw_watchpoint)(struct target_ops *, CORE_ADDR, int) TARGET_DEFAULT_FUNC(default_region_ok_for_hw_watchpoint)
Definition: target.h:543
struct gdbarch_data * gdbarch_data_register_pre_init(gdbarch_data_pre_init_ftype *pre_init)
Definition: gdbarch.c:5130
struct thread_info * first_thread_of_process(int pid)
Definition: thread.c:643
int gdbarch_num_regs(struct gdbarch *gdbarch)
Definition: gdbarch.c:2039
void gdbarch_relocate_instruction(struct gdbarch *gdbarch, CORE_ADDR *to, CORE_ADDR from)
Definition: gdbarch.c:4013
int remote_escape_output(const gdb_byte *buffer, int len_units, int unit_size, gdb_byte *out_buf, int *out_len_units, int out_maxlen_bytes)
Definition: rsp-low.c:214
static void store_registers_using_G(const struct regcache *regcache)
Definition: remote.c:7812
static void remote_kill(struct target_ops *ops)
Definition: remote.c:9288
static void remote_async(struct target_ops *ops, int enable)
Definition: remote.c:13747
static void set_memory_write_packet_size(const char *args, int from_tty)
Definition: remote.c:1138
int(* to_can_use_hw_breakpoint)(struct target_ops *, enum bptype, int, int) TARGET_DEFAULT_RETURN(0)
Definition: target.h:502
#define _(String)
Definition: gdb_locale.h:35
static int remote_supports_stopped_by_sw_breakpoint(struct target_ops *ops)
Definition: remote.c:10027
enum gdb_signal stop_signal
Definition: gdbthread.h:158
void set_current_sal_from_frame(struct frame_info *)
Definition: stack.c:725
int putpkt(const char *buf)
Definition: remote.c:8650
static int is_pending_fork_parent(struct target_waitstatus *ws, int event_pid, ptid_t thread_ptid)
Definition: remote.c:6405
const struct gdb_xml_element threads_elements[]
Definition: remote.c:3136
void(* to_trace_stop)(struct target_ops *) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:997
ULONGEST traceframe_usage
Definition: tracepoint.h:197
static void * remote_g_packet_data_init(struct obstack *obstack)
Definition: remote.c:11156
void initialize_remote_fileio(struct cmd_list_element *remote_set_cmdlist, struct cmd_list_element *remote_show_cmdlist)
static void remote_buffer_add_string(char **buffer, int *left, const char *string)
Definition: remote.c:11242
static void remote_serial_quit_handler(void)
Definition: remote.c:4893
static int stop_reply_queue_length(void)
Definition: remote.c:6313
static char * pack_threadinfo_request(char *pkt, int mode, threadref *id)
Definition: remote.c:2662
long regnum
Definition: remote.c:516
std::vector< mem_region >(*) to_memory_map(struct target_ops *) TARGET_DEFAULT_RETURN(std void(* to_flash_erase)(struct target_ops *, ULONGEST address, LONGEST length) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:775
int signal_print_state(int signo)
Definition: infrun.c:8368
ULONGEST(* to_get_memory_xfer_limit)(struct target_ops *) TARGET_DEFAULT_RETURN(ULONGEST_MAX)
Definition: target.h:751
static std::vector< mem_region > remote_memory_map(struct target_ops *ops)
Definition: remote.c:10813
int default_child_has_execution(struct target_ops *ops, ptid_t the_ptid)
Definition: target.c:236
static int quit_flag
Definition: extension.c:674
int got_ctrlc_during_io
Definition: remote.c:372
static const struct target_desc * remote_read_description(struct target_ops *target)
Definition: remote.c:11203
int(* to_supports_string_tracing)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:845
static void remote_teardown_btrace(struct target_ops *self, struct btrace_target_info *tinfo)
Definition: remote.c:13354
static int remove_stop_reply_for_inferior(QUEUE(stop_reply_p) *q, QUEUE_ITER(stop_reply_p) *iter, stop_reply_p event, void *data)
Definition: remote.c:6550
btrace_format
Definition: btrace-common.h:54
#define END_CATCH
long remote_packet_size
Definition: remote.c:544
int core
Definition: remote.c:2973
void(* to_set_trace_buffer_size)(struct target_ops *, LONGEST val) TARGET_DEFAULT_IGNORE()
Definition: target.h:1046
static int remote_remove_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt, enum remove_bp_reason reason)
Definition: remote.c:9824
const std::set< std::string > & user_unset_env() const
Definition: environ.c:180
void serial_async(struct serial *scb, serial_event_ftype *handler, void *context)
Definition: serial.c:548
static int remote_vkill(int pid, struct remote_state *rs)
Definition: remote.c:9333
gdb::byte_vector thread_handle
Definition: remote.c:451
static unsigned int remote_address_size
Definition: remote.c:999
void text(const char *string)
Definition: ui-out.c:581
#define BUF_SIZE
struct serial * remote_desc
Definition: remote.c:377
struct packet_reg * regs
Definition: remote.c:532
static int remote_notif_remove_once_on_match(QUEUE(stop_reply_p) *q, QUEUE_ITER(stop_reply_p) *iter, stop_reply_p event, void *data)
Definition: remote.c:6638
static void inferior()
Definition: target.c:450
static void start_thread(struct gdb_xml_parser *parser, const struct gdb_xml_element *element, void *user_data, VEC(gdb_xml_value_s) *attributes)
Definition: remote.c:3078
int(* to_get_trace_state_variable_value)(struct target_ops *, int tsv, LONGEST *val) TARGET_DEFAULT_RETURN(0)
Definition: target.h:1013
char * finished_object
Definition: remote.c:403
static void stop_reply_xfree(struct stop_reply *)
int may_insert_tracepoints
static int use_range_stepping
Definition: remote.c:270
static void unpush_and_perror(const char *string)
Definition: remote.c:8533
static int remote_supports_cond_breakpoints(struct target_ops *self)
Definition: remote.c:12189
static void set_pspace_remote_exec_file(struct program_space *pspace, char *remote_exec_file)
Definition: remote.c:699
gdb::unique_xmalloc_ptr< char > target_read_stralloc(struct target_ops *ops, enum target_object object, const char *annex)
Definition: target.c:1927
void printf_filtered(const char *format,...)
Definition: utils.c:2045
static void end_thread(struct gdb_xml_parser *parser, const struct gdb_xml_element *element, void *user_data, const char *body_text)
Definition: remote.c:3106
#define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE)
Definition: gdbarch.h:1709
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: utils.c:2745
gdb::byte_vector thread_handle
Definition: remote.c:2976
static void skip_frame(void)
Definition: remote.c:8870
void quit(void)
Definition: utils.c:731
void string_appendf(std::string &str, const char *fmt,...)
Definition: common-utils.c:195
int(* to_remove_exec_catchpoint)(struct target_ops *, int) TARGET_DEFAULT_RETURN(1)
Definition: target.h:596
#define XNEW(T)
Definition: poison.h:109
trace_find_type
Definition: tracepoint.h:384
long step_count
Definition: breakpoint.h:878
static ptid_t remote_wait_ns(ptid_t ptid, struct target_waitstatus *status, int options)
Definition: remote.c:7237
static void extended_remote_disable_randomization(int val)
Definition: remote.c:9464
static int remote_get_trace_status(struct target_ops *self, struct trace_status *ts)
Definition: remote.c:12598
ptid_t ptid_build(int pid, long lwp, long tid)
Definition: ptid.c:31
void notice_new_inferior(ptid_t ptid, int leave_running, int from_tty)
Definition: infcmd.c:2913
static int remote_core_of_thread(struct target_ops *ops, ptid_t ptid)
Definition: remote.c:12905
#define CRAZY_MAX_THREADS
Definition: remote.c:3037
void(* to_files_info)(struct target_ops *) TARGET_DEFAULT_IGNORE()
Definition: target.h:464
int watchdog
Definition: maint.c:55
static struct target_ops extended_remote_ops
Definition: remote.c:907
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
Definition: cli-decode.c:367
#define TARGET_SYSROOT_PREFIX
Definition: gdb_bfd.h:31
struct trace_status * current_trace_status(void)
Definition: tracepoint.c:189
static int remote_filesystem_is_local(struct target_ops *self)
Definition: remote.c:11821
#define ALL_INFERIORS(I)
Definition: inferior.h:548
static void show_packet_config_cmd(struct packet_config *config)
Definition: remote.c:1227
static void remote_disable_btrace(struct target_ops *self, struct btrace_target_info *tinfo)
Definition: remote.c:13321
int gdbarch_addressable_memory_unit_size(struct gdbarch *gdbarch)
Definition: gdbarch.c:5030
scoped_restore_tmpl< T > make_scoped_restore(T *var)
int hit_count
Definition: breakpoint.h:773
void add_setshow_zuinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:792
mach_port_t kern_return_t mach_port_t msgports mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition: gnu-nat.c:1891
void(* to_thread_events)(struct target_ops *, int) TARGET_DEFAULT_IGNORE()
Definition: target.h:672
const char * normal_pid_to_str(ptid_t ptid)
Definition: target.c:3234
static void remote_trace_stop(struct target_ops *self)
Definition: remote.c:12697
#define QUEUE_ITER(TYPE)
Definition: queue.h:95
#define TRY
int default_child_has_memory(struct target_ops *ops)
Definition: target.c:206
std::vector< agent_expr * > tcommands
Definition: breakpoint.h:276
int in_thread_list(ptid_t ptid)
Definition: thread.c:628
static enum target_xfer_status remote_read_bytes(struct target_ops *ops, CORE_ADDR memaddr, gdb_byte *myaddr, ULONGEST len, int unit_size, ULONGEST *xfered_len)
Definition: remote.c:8369
static void remote_put_command(const char *args, int from_tty)
Definition: remote.c:12107
int thread_count(void)
Definition: thread.c:567
static int remote_supports_btrace(struct target_ops *self, enum btrace_format format)
Definition: remote.c:13104
static void * init_remote_state(struct gdbarch *gdbarch)
Definition: remote.c:810
static void remote_fetch_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
Definition: remote.c:7695
char * line
Definition: cli-script.h:54
#define SIZEOF_N_SECTION_OFFSETS(n)
Definition: symtab.h:1283
void switch_to_thread(ptid_t ptid)
Definition: thread.c:1445
static ptid_t any_thread_ptid
Definition: remote.c:1726
struct cmd_list_element * setlist
Definition: cli-cmds.c:111
static void remote_async_inferior_event_handler(gdb_client_data)
Definition: remote.c:13741
const char *const name
Definition: aarch64-tdep.c:76
int remote_debug
Definition: top.c:171
int(* to_remove_fork_catchpoint)(struct target_ops *, int) TARGET_DEFAULT_RETURN(1)
Definition: target.h:586
void(* to_disable_tracepoint)(struct target_ops *, struct bp_location *location) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:973
static int remote_insert_fork_catchpoint(struct target_ops *ops, int pid)
Definition: remote.c:1660
static void remote_trace_init(struct target_ops *self)
Definition: remote.c:12232
static char * unpack_int(char *buf, int *value)
Definition: remote.c:2513
int last_sent_step
Definition: remote.c:398
static enum target_xfer_status remote_read_qxfer(struct target_ops *ops, const char *object_name, const char *annex, gdb_byte *readbuf, ULONGEST offset, LONGEST len, ULONGEST *xfered_len, struct packet_config *packet)
Definition: remote.c:10349
void serial_log_command(struct target_ops *self, const char *cmd)
Definition: serial.c:130
char more_display[256]
Definition: remote.c:2305
#define VEC_iterate(T, V, I, P)
Definition: vec.h:181
int(* to_can_do_single_step)(struct target_ops *) TARGET_DEFAULT_RETURN(-1)
Definition: target.h:557
#define OPS_MAGIC
Definition: target.h:1270
static void remote_thread_events(struct target_ops *ops, int enable)
Definition: remote.c:13782
#define target_trace_find(type, num, addr1, addr2, tpp)
Definition: target.h:2161
static void remote_unpush_target(void)
Definition: remote.c:4925
static int strprefix(const char *p, const char *pend, const char *prefix)
Definition: remote.c:6738
int per_inf_num
Definition: gdbthread.h:258
static void remote_store_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
Definition: remote.c:7851
int may_stop
int extended
Definition: remote.c:349
int remote_hw_breakpoint_limit
Definition: remote.c:9968
static void remove_new_fork_children(struct threads_listing_context *)
Definition: remote.c:6469
#define TAG_MOREDISPLAY
Definition: remote.c:2681
static int remote_save_trace_data(struct target_ops *self, const char *filename)
Definition: remote.c:12818
char * p
Definition: remote.c:5793
enum exec_direction_kind execution_direction
Definition: infrun.c:9088
struct notif_event * remote_notif_parse(struct notif_client *nc, char *buf)
Definition: remote-notif.c:80
#define CATCH(EXCEPTION, MASK)
std::unique_ptr< FILE, gdb_file_deleter > gdb_file_up
Definition: filestuff.h:59
static int is_pending_fork_parent_thread(struct thread_info *thread)
Definition: remote.c:6433
void register_remote_g_packet_guess(struct gdbarch *gdbarch, int bytes, const struct target_desc *tdesc)
Definition: remote.c:11162
static int remote_is_async_p(struct target_ops *)
Definition: remote.c:13714
thread_suspend_state suspend
Definition: gdbthread.h:295
static void fetch_registers_using_g(struct regcache *regcache)
Definition: remote.c:7665
void merge_uploaded_tracepoints(struct uploaded_tp **uploaded_tps)
Definition: tracepoint.c:3176
static void push_stop_reply(struct stop_reply *)
Definition: remote.c:6699
bptype type
Definition: breakpoint.h:693
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
long offset
Definition: remote.c:515
void update_signals_program_target(void)
Definition: infrun.c:341
int fputc_unfiltered(int c, struct ui_file *stream)
Definition: utils.c:1835
int gdb_xml_parse_quick(const char *name, const char *dtd_name, const struct gdb_xml_element *elements, const char *document, void *user_data)
Definition: xml-support.c:647
void inferior_event_handler(enum inferior_event_type event_type, gdb_client_data client_data)
Definition: inf-loop.c:37
struct target_ops current_target
static QUEUE(stop_reply_p)
Definition: remote.c:6302
struct gdb_xml_value * xml_find_attribute(VEC(gdb_xml_value_s) *attributes, const char *name)
Definition: xml-support.c:231
int noack_mode
Definition: remote.c:346
int(* to_trace_find)(struct target_ops *, enum trace_find_type type, int num, CORE_ADDR addr1, CORE_ADDR addr2, int *tpp) TARGET_DEFAULT_RETURN(-1)
Definition: target.h:1005
static enum packet_result packet_ok(const char *buf, struct packet_config *config)
Definition: remote.c:1324
static char * append_pending_thread_resumptions(char *p, char *endp, ptid_t ptid)
Definition: remote.c:5539
void target_clear_description(void)
static int interrupt_on_connect
Definition: remote.c:965
const char * btrace_format_string(enum btrace_format format)
Definition: btrace-common.c:27
int thread_is_in_step_over_chain(struct thread_info *tp)
Definition: thread.c:418
int target_is_non_stop_p(void)
Definition: target.c:3917
void solib_add(const char *pattern, int from_tty, int readsyms)
Definition: solib.c:961
void merge_uploaded_trace_state_variables(struct uploaded_tsv **uploaded_tsvs)
Definition: tracepoint.c:3299
int(* to_watchpoint_addr_within_range)(struct target_ops *, CORE_ADDR, CORE_ADDR, int) TARGET_DEFAULT_FUNC(default_watchpoint_addr_within_range)
Definition: target.h:537
#define exec_bfd
Definition: exec.h:33
void stop_all_threads(void)
Definition: infrun.c:4468
static void remote_update_thread_list(struct target_ops *ops)
Definition: remote.c:3214
char * gdb_sysroot
Definition: main.c:59
static int remote_notif_stop_can_get_pending_events(struct notif_client *self)
Definition: remote.c:6342
LONGEST(* to_get_raw_trace_data)(struct target_ops *, gdb_byte *buf, ULONGEST offset, LONGEST len) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:1028
void cmd_func(struct cmd_list_element *cmd, const char *args, int from_tty)
Definition: cli-decode.c:1877
void fprintf_filtered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2008
static void check_pending_events_prevent_wildcard_vcont(int *may_global_wildcard_vcont)
Definition: remote.c:6536
void free_current_marker(void *arg)
Definition: tracepoint.c:3678
static void set_thread(ptid_t ptid, int gen)
Definition: remote.c:2155
static char * pack_threadid(char *pkt, threadref *id)
Definition: remote.c:2553
int executing
Definition: gdbthread.h:271
static void extended_remote_open(const char *name, int from_tty)
Definition: remote.c:4322
struct symfile_segment_data * get_symfile_segment_data(bfd *abfd)
Definition: symfile.c:3668
int baud_rate
Definition: serial.c:639
static int remote_region_ok_for_hw_watchpoint(struct target_ops *self, CORE_ADDR addr, int len)
Definition: remote.c:9971
#define MAX_TRIES
enum gdb_signal sig
Definition: waitstatus.h:114
struct inferior * add_inferior(int pid)
Definition: inferior.c:121
static void remote_add_target_side_commands(struct gdbarch *gdbarch, struct bp_target_info *bp_tgt, char *buf)
Definition: remote.c:9735
static bool is_ours()
Definition: target.h:136
struct thread_info * any_live_thread_of_process(int pid)
Definition: thread.c:674
static char * remote_pid_to_exec_file(struct target_ops *self, int pid)
Definition: remote.c:13433
std::vector< mem_region > parse_memory_map(const char *memory_map)
Definition: memory-map.c:172
static struct remote_state * get_remote_state(void)
Definition: remote.c:658
void trace_reset_local_state(void)
Definition: tracepoint.c:1563
void add_setshow_zinteger_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:748
int simple_verify_memory(struct target_ops *ops, const gdb_byte *data, CORE_ADDR lma, ULONGEST size)
Definition: target.c:3464
int(* to_remove_vfork_catchpoint)(struct target_ops *, int) TARGET_DEFAULT_RETURN(1)
Definition: target.h:590
Definition: ptid.h:35
CORE_ADDR gdbarch_convert_from_func_ptr_addr(struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ)
Definition: gdbarch.c:3191
static enum target_xfer_status remote_write_qxfer(struct target_ops *ops, const char *object_name, const char *annex, const gdb_byte *writebuf, ULONGEST offset, LONGEST len, ULONGEST *xfered_len, struct packet_config *packet)
Definition: remote.c:10306
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2018
static enum exec_direction_kind remote_execution_direction(struct target_ops *self)
Definition: remote.c:13488
static struct stop_reply * queued_stop_reply(ptid_t ptid)
Definition: remote.c:6683
int(* to_supports_stopped_by_sw_breakpoint)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:486
char * cond_string
Definition: breakpoint.h:749
void(* to_resume)(struct target_ops *, ptid_t, int TARGET_DEBUG_PRINTER(target_debug_print_step), enum gdb_signal) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:447
static int remote_set_trace_notes(struct target_ops *self, const char *user, const char *notes, const char *stop_notes)
Definition: remote.c:13008
static int parse_threadlist_response(char *pkt, int result_limit, threadref *original_echo, threadref *resultlist, int *doneflag)
Definition: remote.c:2814
int waiting_for_stop_reply
Definition: remote.c:357
void print_target_wait_results(ptid_t waiton_ptid, ptid_t result_ptid, const struct target_waitstatus *ws)
Definition: infrun.c:3419
static void readahead_cache_invalidate(void)
Definition: remote.c:11435
int traceframe_available_memory(std::vector< mem_range > *result, CORE_ADDR memaddr, ULONGEST len)
Definition: tracepoint.c:4057
struct cmd_list_element * showlist
Definition: cli-cmds.c:119
void regcache_raw_update(struct regcache *regcache, int regnum)
Definition: regcache.c:535
static void remote_send(char **buf, long *sizeof_buf_p)
Definition: remote.c:8616
static enum auto_boolean packet_set_cmd_state(int packet)
Definition: remote.c:1527
const char * name
Definition: remote.c:1012
static struct gdbarch_data * remote_g_packet_data_handle
Definition: remote.c:11153
LONGEST pnum
Definition: remote.c:517
int(* to_get_min_fast_tracepoint_insn_len)(struct target_ops *) TARGET_DEFAULT_RETURN(-1)
Definition: target.h:1036
void fputs_filtered(const char *linebuffer, struct ui_file *stream)
Definition: utils.c:1811
int serial_setbaudrate(struct serial *scb, int rate)
Definition: serial.c:516
void update_address_spaces(void)
Definition: progspace.c:376
static enum target_xfer_status remote_xfer_live_readonly_partial(struct target_ops *ops, gdb_byte *readbuf, ULONGEST memaddr, ULONGEST len, int unit_size, ULONGEST *xfered_len)
Definition: remote.c:8317
void puts_filtered(const char *string)
Definition: utils.c:2085
#define gdb_assert_not_reached(message)
Definition: gdb_assert.h:55
static void set_remote_cmd(const char *args, int from_tty)
Definition: remote.c:13810
#define OPAQUETHREADBYTES
Definition: remote.c:272
void discard_all_inferiors(void)
Definition: inferior.c:278
static int remote_exec_event_p(struct remote_state *rs)
Definition: remote.c:1651
int serial_flush_input(struct serial *scb)
Definition: serial.c:469
void generic_load(const char *name, int from_tty)
Definition: symfile.c:2055
size_t bufsize
Definition: remote.c:302
#define TARGET_WNOHANG
Definition: wait.h:28
#define SECT_OFF_DATA(objfile)
Definition: objfiles.h:674
void free_current_contents(void *ptr)
Definition: utils.c:199
#define TAG_THREADNAME
Definition: remote.c:2680
struct cmd_list_element * add_setshow_string_noescape_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:632
void parse_tracepoint_status(const char *p, struct breakpoint *bp, struct uploaded_tp *utp)
Definition: tracepoint.c:3512
static char * remote_exec_file_var
Definition: remote.c:86
static enum packet_result packet_check_result(const char *buf)
Definition: remote.c:1298
static void show_remote_exec_file(struct ui_file *file, int from_tty, struct cmd_list_element *cmd, const char *value)
Definition: remote.c:722
ptid_t pid_to_ptid(int pid)
Definition: ptid.c:39
btrace_read_type
async_event_handler * create_async_event_handler(async_event_handler_func *proc, gdb_client_data client_data)
Definition: event-loop.c:1013
CORE_ADDR(* to_get_thread_local_address)(struct target_ops *ops, ptid_t ptid, CORE_ADDR load_module_addr, CORE_ADDR offset) TARGET_DEFAULT_NORETURN(generic_tls_error())
Definition: target.h:701
int default_child_has_all_memory(struct target_ops *ops)
Definition: target.c:196
static const char *const interrupt_sequence_modes[]
Definition: remote.c:927
void remote_notif_state_xfree(struct remote_notif_state *state)
Definition: remote-notif.c:257
#define current_uiout
Definition: ui-out.h:39
static void remote_buffer_add_int(char **buffer, int *left, ULONGEST value)
Definition: remote.c:11285
int get_traceframe_number(void)
Definition: tracepoint.c:2976
int(* to_insert_exec_catchpoint)(struct target_ops *, int) TARGET_DEFAULT_RETURN(1)
Definition: target.h:594
static int remote_trace_find(struct target_ops *self, enum trace_find_type type, int num, CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
Definition: remote.c:12710
void parse_trace_status(const char *line, struct trace_status *ts)
Definition: tracepoint.c:3352
static void remote_kill_k(void)
Definition: remote.c:9360
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
Definition: cleanups.c:116
static ptid_t read_ptid(const char *buf, const char **obuf)
Definition: remote.c:2414
threadref resultthreadlist[MAXTHREADLISTRESULTS]
Definition: remote.c:419
gdbarch * arch
Definition: remote.c:6278
traceframe_info_up parse_traceframe_info(const char *tframe_info)
Definition: tracepoint.c:4023
struct target_section * sections
Definition: target.h:2334
void(* to_set_permissions)(struct target_ops *) TARGET_DEFAULT_IGNORE()
Definition: target.h:1081
target_xfer_status
Definition: target.h:206
struct btrace_target_info *(* to_enable_btrace)(struct target_ops *, ptid_t ptid, const struct btrace_config *conf) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:1118
void target_interrupt(ptid_t ptid)
Definition: target.c:3328
static void remote_disable_tracepoint(struct target_ops *self, struct bp_location *location)
Definition: remote.c:12516
int use_threadinfo_query
Definition: remote.c:414
const struct gdb_xml_attribute thread_attributes[]
Definition: remote.c:3117
int use_agent
Definition: agent.c:46
int(* to_has_execution)(struct target_ops *, ptid_t)
Definition: target.h:661
static void remote_serial_write(const char *str, int len)
Definition: remote.c:8591
int gdbarch_has_global_breakpoints(struct gdbarch *gdbarch)
Definition: gdbarch.c:4619
static int store_register_using_P(const struct regcache *regcache, struct packet_reg *reg)
Definition: remote.c:7771
static int remote_remove_watchpoint(struct target_ops *self, CORE_ADDR addr, int len, enum target_hw_bp_type type, struct expression *cond)
Definition: remote.c:9929
struct inferior * find_inferior_pid(int pid)
Definition: inferior.c:302
Definition: gdbtypes.h:749
#define ATTRIBUTE_PRINTF
Definition: common-defs.h:70
static int remote_get_threadlist(int startflag, threadref *nextthread, int result_limit, int *done, int *result_count, threadref *threadlist)
Definition: remote.c:2845
void(* to_trace_set_readonly_regions)(struct target_ops *) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:980
const char * filename
Definition: tracepoint.h:92
char * default_collect
static int remote_get_threadinfo(threadref *threadid, int fieldset, struct gdb_ext_thread_info *info)
Definition: remote.c:2778
static void remote_download_command_source(int num, ULONGEST addr, struct command_line *cmds)
Definition: remote.c:12246
int serial_send_break(struct serial *scb)
Definition: serial.c:475
static void show_memory_packet_size(struct memory_packet_config *config)
Definition: remote.c:1121
static remote_inferior * get_remote_inferior(inferior *inf)
Definition: remote.c:5774
static int remote_set_syscall_catchpoint(struct target_ops *self, int pid, bool needed, int any_count, gdb::array_view< const int > syscall_counts)
Definition: remote.c:2026
static ptid_t magic_null_ptid
Definition: remote.c:1724
static const char * remote_thread_name(struct target_ops *ops, struct thread_info *info)
Definition: remote.c:2268
static void remote_enable_tracepoint(struct target_ops *self, struct bp_location *location)
Definition: remote.c:12498
static std::string escape_buffer(const char *buf, int n)
Definition: remote.c:8630
static struct remote_state * remote_state
Definition: remote.c:483
static void vcont_builder_flush(struct vcont_builder *builder)
Definition: remote.c:5816
static int remote_fork_event_p(struct remote_state *rs)
Definition: remote.c:1635
static int getpkt_sane(char **buf, long *sizeof_buf, int forever)
Definition: remote.c:9208
int(* to_fileio_fstat)(struct target_ops *, int fd, struct stat *sb, int *target_errno)
Definition: target.h:915
bp_location * next
Definition: breakpoint.h:324
bool contains_thread(ptid_t ptid) const
Definition: remote.c:2988
static int remote_break
Definition: remote.c:970
struct target_waitstatus pending_follow
Definition: gdbthread.h:342
static void remote_notif_stop_ack(struct notif_client *self, char *buf, struct notif_event *event)
Definition: remote.c:6326
const struct target_desc * tdesc
Definition: remote.c:11143
#define enable()
Definition: ser-go32.c:239
Definition: gnu-nat.c:174
exec_direction_kind
Definition: infrun.h:67
void(* to_get_tracepoint_status)(struct target_ops *, struct breakpoint *tp, struct uploaded_tp *utp) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:991
int pass_count
Definition: breakpoint.h:882
int(* to_upload_trace_state_variables)(struct target_ops *, struct uploaded_tsv **utsvp) TARGET_DEFAULT_RETURN(0)
Definition: target.h:1024
static void remote_packet_size(const struct protocol_feature *feature, enum packet_support support, const char *value)
Definition: remote.c:4517
void target_mourn_inferior(ptid_t ptid)
Definition: target.c:2298
void thread_change_ptid(ptid_t old_ptid, ptid_t new_ptid)
Definition: thread.c:855
int(* to_augmented_libraries_svr4_read)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:1241
int number_on_target
Definition: breakpoint.h:885
gdb_file_up gdb_fopen_cloexec(const char *filename, const char *opentype)
Definition: filestuff.c:296
std::string extra
Definition: remote.c:445
void exception_fprintf(struct ui_file *file, struct gdb_exception e, const char *prefix,...)
Definition: exceptions.c:119
void serial_raw(struct serial *scb)
Definition: serial.c:484
static void remote_buffer_add_bytes(char **buffer, int *left, const gdb_byte *bytes, int len)
Definition: remote.c:11264
const char * gdbarch_register_name(struct gdbarch *gdbarch, int regnr)
Definition: gdbarch.c:2282
int(* to_insert_fork_catchpoint)(struct target_ops *, int) TARGET_DEFAULT_RETURN(1)
Definition: target.h:584
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition: gnu-nat.c:1822
#define target_is_async_p()
Definition: target.h:1781
static struct packet_reg * packet_reg_from_pnum(struct gdbarch *gdbarch, struct remote_arch_state *rsa, LONGEST pnum)
Definition: remote.c:890
static char * unpack_nibble(char *buf, int *val)
Definition: remote.c:2489
const char * to_doc
Definition: target.h:417
static int startswith(const char *string, const char *pattern)
Definition: common-utils.h:107
static void remote_query_supported(void)
Definition: remote.c:4701
Definition: serial.h:224
static void add_packet_config_cmd(struct packet_config *config, const char *name, const char *title, int legacy)
Definition: remote.c:1259
int(* to_insert_watchpoint)(struct target_ops *, CORE_ADDR, int, enum target_hw_bp_type, struct expression *) TARGET_DEFAULT_RETURN(-1)
Definition: target.h:519
char * pack_nibble(char *buf, int nibble)
Definition: rsp-low.c:77
#define symfile_objfile
Definition: progspace.h:227
static int remote_thread_always_alive(struct target_ops *ops, ptid_t ptid)
Definition: remote.c:2224
packet_support
Definition: remote.c:1190
DECLARE_QUEUE_P(stop_reply_p)
static int remote_supports_string_tracing(struct target_ops *self)
Definition: remote.c:12220
CORE_ADDR endaddr
Definition: target.h:2318
int gdbarch_addr_bit(struct gdbarch *gdbarch)
Definition: gdbarch.c:1848
struct thread_info * add_thread_silent(ptid_t ptid)
Definition: thread.c:266
const char * gdb_signal_to_name(enum gdb_signal)
Definition: signals.c:78
ptid_t ptid
Definition: gdbthread.h:219
const struct btrace_config *(* to_btrace_conf)(struct target_ops *self, const struct btrace_target_info *) TARGET_DEFAULT_RETURN(NULL)
Definition: target.h:1145
btrace_error
#define target_has_execution
Definition: target.h:1756
static serial_event_ftype remote_async_serial_handler
Definition: remote.c:13730
enum target_xfer_status(* to_xfer_partial)(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) TARGET_DEFAULT_RETURN(TARGET_XFER_E_IO)
Definition: target.h:739
std::vector< agent_expr * > conditions
Definition: breakpoint.h:272
struct btrace_config conf
Definition: linux-btrace.h:91
const char * event_location_to_string(struct event_location *location)
Definition: location.c:397
int(* to_search_memory)(struct target_ops *ops, CORE_ADDR start_addr, ULONGEST search_space_len, const gdb_byte *pattern, ULONGEST pattern_len, CORE_ADDR *found_addrp) TARGET_DEFAULT_FUNC(default_search_memory)
Definition: target.h:815
char * xstrprintf(const char *format,...)
Definition: common-utils.c:107
static ptid_t remote_current_thread(ptid_t oldptid)
Definition: remote.c:3040
static void remote_detach(struct target_ops *ops, const char *args, int from_tty)
Definition: remote.c:5167
static int hexnumnstr(char *, ULONGEST, int)
Definition: remote.c:7922
static char * remote_hostio_error(int errnum)
Definition: remote.c:11921
void(* func)(const struct protocol_feature *, enum packet_support, const char *)
Definition: remote.c:4493
int regnum
Definition: aarch64-tdep.c:77
#define ALL_NON_EXITED_INFERIORS(I)
Definition: inferior.h:553
long explicit_packet_size
Definition: remote.c:332
void printf_unfiltered(const char *format,...)
Definition: utils.c:2056
static void compare_sections_command(const char *args, int from_tty)
Definition: remote.c:10231
int(* to_get_tib_address)(struct target_ops *, ptid_t ptid, CORE_ADDR *addr) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:1076
static int remote_stopped_data_address(struct target_ops *target, CORE_ADDR *addr_p)
Definition: remote.c:10064
static int remote_insert_exec_catchpoint(struct target_ops *ops, int pid)
Definition: remote.c:1700
CORE_ADDR placed_address
Definition: breakpoint.h:248
int last_resume_step
Definition: remote.c:468
static traceframe_info_up remote_traceframe_info(struct target_ops *self)
Definition: remote.c:12931
static int remote_insert_vfork_catchpoint(struct target_ops *ops, int pid)
Definition: remote.c:1680
traceframe_info_up(* to_traceframe_info)(struct target_ops *) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:1099
static int remote_can_do_single_step(struct target_ops *ops)
Definition: remote.c:13464
static int remote_read_description_p(struct target_ops *target)
Definition: remote.c:11190
int use_threadextra_query
Definition: remote.c:415
void(* to_detach)(struct target_ops *ops, const char *, int) TARGET_DEFAULT_IGNORE()
Definition: target.h:443
static void copy_threadref(threadref *dest, threadref *src)
Definition: remote.c:2621
void(* to_async)(struct target_ops *, int) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:670
int fromhex(int a)
Definition: rsp-low.c:26
struct bfd_section * the_bfd_section
Definition: target.h:2320
static enum target_xfer_status remote_write_bytes_aux(const char *header, CORE_ADDR memaddr, const gdb_byte *myaddr, ULONGEST len_units, int unit_size, ULONGEST *xfered_len_units, char packet_format, int use_length)
Definition: remote.c:8064
static void remote_program_signals(struct target_ops *self, int numsigs, unsigned char *signals)
Definition: remote.c:2103
static void btrace_read_config(struct btrace_config *conf)
Definition: remote.c:13194
static int send_g_packet(void)
Definition: remote.c:7528
static int remote_supports_fast_tracepoints(void)
Definition: remote.c:12195
int num
Definition: inferior.h:324
static void remote_commit_resume(struct target_ops *ops)
Definition: remote.c:5873
void * xmalloc(YYSIZE_T)
static void remote_download_trace_state_variable(struct target_ops *self, struct trace_state_variable *tsv)
Definition: remote.c:12475
static void remote_files_info(struct target_ops *ignore)
Definition: remote.c:8518
void remote_fileio_reset(void)
long ptid_get_lwp(const ptid_t &ptid)
Definition: ptid.c:55
enum packet_support default_support
Definition: remote.c:4482
static int getpkt_or_notif_sane(char **buf, long *sizeof_buf, int forever, int *is_notif)
Definition: remote.c:9214
int remote_hw_watchpoint_limit
Definition: remote.c:9966
target_object
Definition: target.h:132
void * gdb_client_data
Definition: event-loop.h:70
static ptid_t not_sent_ptid
Definition: remote.c:1725
int(* to_insert_hw_breakpoint)(struct target_ops *, struct gdbarch *, struct bp_target_info *) TARGET_DEFAULT_RETURN(-1)
Definition: target.h:507
static void remote_notice_new_inferior(ptid_t currthread, int executing)
Definition: remote.c:1855
char *(* to_pid_to_exec_file)(struct target_ops *, int pid) TARGET_DEFAULT_RETURN(NULL)
Definition: target.h:650
bptype
Definition: breakpoint.h:67
static void ours_for_output()
Definition: target.c:501
#define DEFAULT_MAX_MEMORY_PACKET_SIZE
Definition: remote.c:1021
int number_of_live_inferiors(void)
Definition: inferior.c:424
int(* to_can_run_breakpoint_commands)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:855
void serial_close(struct serial *scb)
Definition: serial.c:348
static long get_memory_read_packet_size(void)
Definition: remote.c:1173
struct cmd_list_element * add_alias_cmd(const char *name, cmd_list_element *old, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
Definition: cli-decode.c:306
CORE_ADDR addr
Definition: target.h:2317
static void remote_detach_pid(int pid)
Definition: remote.c:5101
void set_last_target_status(ptid_t ptid, struct target_waitstatus status)
Definition: infrun.c:4025
Definition: regdef.h:22
std::string & string()
Definition: ui-file.h:132
static void process_g_packet(struct regcache *regcache)
Definition: remote.c:7560
void(* to_commit_resume)(struct target_ops *) TARGET_DEFAULT_IGNORE()
Definition: target.h:451
#define gdb_assert(expr)
Definition: gdb_assert.h:32
serial_rc
Definition: serial.h:101
const char * get_inferior_cwd()
Definition: infcmd.c:237
struct serial * serial_open(const char *name)
Definition: serial.c:204
gdb_environ environment
Definition: inferior.h:372
void(* to_disconnect)(struct target_ops *, const char *, int) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:445
#define TAG_THREADID
Definition: remote.c:2676
#define VEC_empty(T, V)
Definition: vec.h:148
static int hexnumlen(ULONGEST num)
Definition: remote.c:7898
static const struct protocol_feature remote_protocol_features[]
Definition: remote.c:4548
static const struct @28 signals[]
Definition: value.c:169
static int remote_hostio_open(struct target_ops *self, struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, int *remote_errno)
Definition: remote.c:11493
int(* to_can_download_tracepoint)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:959
static void resume_clear_thread_private_info(struct thread_info *thread)
Definition: remote.c:5524
void(* to_log_command)(struct target_ops *, const char *) TARGET_DEFAULT_IGNORE()
Definition: target.h:652
Definition: ui-out.h:77
static void remote_btrace_reset(void)
Definition: remote.c:13094
static int extended_remote_supports_disable_randomization(struct target_ops *self)
Definition: remote.c:9458
CORE_ADDR address
Definition: breakpoint.h:427
static void set_remotebreak(const char *args, int from_tty, struct cmd_list_element *c)
Definition: remote.c:973
static void set_general_thread(ptid_t ptid)
Definition: remote.c:2184
#define QUEUE_alloc(TYPE, FREE_FUNC)
Definition: queue.h:70
static struct thread_info * remote_thread_handle_to_thread_info(struct target_ops *ops, const gdb_byte *thread_handle, int handle_len, struct inferior *inf)
Definition: remote.c:13499
static void remote_terminal_inferior(struct target_ops *self)
Definition: remote.c:6232
static void send_environment_packet(struct remote_state *rs, const char *action, const char *packet, const char *value)
Definition: remote.c:9544
int signal_pass_state(int signo)
Definition: infrun.c:8374
enum btrace_error(* to_read_btrace)(struct target_ops *self, struct btrace_data *data, struct btrace_target_info *btinfo, enum btrace_read_type type) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:1138
struct btrace_config_pt pt
static void remote_interrupt_as(void)
Definition: remote.c:6103
PTR xrealloc(PTR ptr, size_t size)
Definition: common-utils.c:52
int running_known
Definition: tracepoint.h:95
int(* to_verify_memory)(struct target_ops *, const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size) TARGET_DEFAULT_FUNC(default_verify_memory)
Definition: target.h:1070
static void vcont_builder_restart(struct vcont_builder *builder)
Definition: remote.c:5802
void remote_notif_ack(struct notif_client *nc, char *buf)
Definition: remote-notif.c:61
int gdbarch_fast_tracepoint_valid_at(struct gdbarch *gdbarch, CORE_ADDR addr, char **msg)
Definition: gdbarch.c:4653
struct btrace_config btrace_config
Definition: remote.c:425
int(* to_fileio_open)(struct target_ops *, struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, int *target_errno)
Definition: target.h:893
void(* to_download_tracepoint)(struct target_ops *, struct bp_location *location) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:953
void remote_file_get(const char *remote_file, const char *local_file, int from_tty)
Definition: remote.c:12032
static char * remote_hostio_readlink(struct target_ops *self, struct inferior *inf, const char *filename, int *remote_errno)
Definition: remote.c:11720
static VEC(static_tracepoint_marker_p)
Definition: remote.c:3409
static struct packet_reg * packet_reg_from_regnum(struct gdbarch *gdbarch, struct remote_arch_state *rsa, long regnum)
Definition: remote.c:875
void throw_exception(struct gdb_exception exception)
struct command_line * next
Definition: cli-script.h:53
int(* to_remove_hw_breakpoint)(struct target_ops *, struct gdbarch *, struct bp_target_info *) TARGET_DEFAULT_RETURN(-1)
Definition: target.h:510
char * execd_pathname
Definition: waitstatus.h:118
static void extended_remote_set_inferior_cwd(struct remote_state *rs)
Definition: remote.c:9593
long buf_size
Definition: remote.c:322
bfd_byte gdb_byte
Definition: common-types.h:38
static int remote_vfork_event_p(struct remote_state *rs)
Definition: remote.c:1643
static CORE_ADDR remote_address_masked(CORE_ADDR)
Definition: remote.c:7940
void target_update_thread_list(void)
Definition: target.c:3310
enum exec_direction_kind(* to_execution_direction)(struct target_ops *) TARGET_DEFAULT_FUNC(default_execution_direction)
Definition: target.h:828
enum command_control_type control_type
Definition: cli-script.h:55
int in_inferior_list(int pid)
Definition: inferior.c:396
int ctrlc_pending_p
Definition: remote.c:364
void start_remote(int from_tty)
Definition: infrun.c:3218
struct remote_state * rs
Definition: remote.c:6273
static void remote_get_tracepoint_status(struct target_ops *self, struct breakpoint *bp, struct uploaded_tp *utp)
Definition: remote.c:12650
std::unique_ptr< traceframe_info > traceframe_info_up
Definition: tracepoint.h:40
int simple_search_memory(struct target_ops *ops, CORE_ADDR start_addr, ULONGEST search_space_len, const gdb_byte *pattern, ULONGEST pattern_len, CORE_ADDR *found_addrp)
Definition: target.c:2323
void help_list(struct cmd_list_element *list, const char *cmdtype, enum command_class theclass, struct ui_file *stream)
Definition: cli-decode.c:1071
void remote_file_put(const char *local_file, const char *remote_file, int from_tty)
Definition: remote.c:11941
void discard_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:212
int non_stop
Definition: infrun.c:204
void remove_thread(ptid_t ptid)
Definition: remote.c:3004
static int threadref_to_int(threadref *ref)
Definition: remote.c:2607
quit_handler_ftype * quit_handler
Definition: event-top.c:962
unsigned int size
ptid_t null_ptid
Definition: ptid.c:25
void(* to_fetch_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_IGNORE()
Definition: target.h:457
static ptid_t process_stop_reply(struct stop_reply *stop_reply, struct target_waitstatus *status)
Definition: remote.c:7186
static int remote_remove_exec_catchpoint(struct target_ops *ops, int pid)
Definition: remote.c:1711
void(* to_mourn_inferior)(struct target_ops *) TARGET_DEFAULT_FUNC(default_mourn_inferior)
Definition: target.h:606
static const int remote_flash_timeout
Definition: remote.c:8460
static void remote_interrupt(struct target_ops *self, ptid_t ptid)
Definition: remote.c:6170
threadref nextthread
Definition: remote.c:418
const char *(* to_extra_thread_info)(struct target_ops *, struct thread_info *) TARGET_DEFAULT_RETURN(NULL)
Definition: target.h:632
static void remote_close(struct target_ops *self)
Definition: remote.c:3489
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
Definition: utils.c:692
#define QUEUE_iterate(TYPE, Q, OPERATE, PARAM)
Definition: queue.h:83
int encode_source_string(int tpnum, ULONGEST addr, const char *srctype, const char *src, char *buf, int buf_size)
Definition: tracepoint.c:2875
static int remote_hostio_pread_from_cache(struct remote_state *rs, int fd, gdb_byte *read_buf, size_t len, ULONGEST offset)
Definition: remote.c:11609
static int remove_stop_reply_of_remote_state(QUEUE(stop_reply_p) *q, QUEUE_ITER(stop_reply_p) *iter, stop_reply_p event, void *data)
Definition: remote.c:6603
static int remote_verify_memory(struct target_ops *ops, const gdb_byte *data, CORE_ADDR lma, ULONGEST size)
Definition: remote.c:10181
static void set_range_stepping(const char *ignore_args, int from_tty, struct cmd_list_element *c)
Definition: remote.c:13918
int(* to_set_trace_notes)(struct target_ops *, const char *user, const char *notes, const char *stopnotes) TARGET_DEFAULT_RETURN(0)
Definition: target.h:1051
static void send_interrupt_sequence(void)
Definition: remote.c:3682
#define ALL_NON_EXITED_THREADS(T)
Definition: gdbthread.h:490
int serial_can_async_p(struct serial *scb)
Definition: serial.c:536
static remote_thread_info * get_remote_thread_info(thread_info *thread)
Definition: remote.c:1940
int in_g_packet
Definition: remote.c:518
std::unique_ptr< private_thread_info > priv
Definition: gdbthread.h:354
int default_child_has_registers(struct target_ops *ops)
Definition: target.c:226
static int remote_stopped_by_sw_breakpoint(struct target_ops *ops)
Definition: remote.c:10014
std::string extra
Definition: remote.c:2967
void prune_threads(void)
Definition: thread.c:727
int may_insert_breakpoints
#define gdb_stderr
Definition: utils.h:344
void(* to_pass_signals)(struct target_ops *, int, unsigned char *TARGET_DEBUG_PRINTER(target_debug_print_signals)) TARGET_DEFAULT_IGNORE()
Definition: target.h:616
void(* to_stop)(struct target_ops *, ptid_t) TARGET_DEFAULT_IGNORE()
Definition: target.h:641
#define XCNEW(T)
Definition: poison.h:121
pid_t pid
Definition: gnu-nat.c:187
void(* to_teardown_btrace)(struct target_ops *, struct btrace_target_info *tinfo) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:1132
packet_result
Definition: remote.c:1216
ULONGEST traceframe_usage
Definition: breakpoint.h:889
static long get_remote_packet_size(void)
Definition: remote.c:863
static long get_memory_packet_size(struct memory_packet_config *config)
Definition: remote.c:1031
event_location_up location
Definition: breakpoint.h:730
int(* to_save_trace_data)(struct target_ops *, const char *filename) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:1017
static int compare_pnums(const void *lhs_, const void *rhs_)
Definition: remote.c:729
void(* to_download_trace_state_variable)(struct target_ops *, struct trace_state_variable *tsv) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:963
int xsnprintf(char *str, size_t size, const char *format,...)
Definition: common-utils.c:134
int target_async_permitted
Definition: target.c:3876
static struct gdbarch_data * remote_gdbarch_data_handle
Definition: remote.c:645
static void check_binary_download(CORE_ADDR addr)
Definition: remote.c:7973
struct remote_notif_state * remote_notif_state_allocate(void)
Definition: remote-notif.c:239
static void remote_detach_1(const char *args, int from_tty)
Definition: remote.c:5128
void record_btrace_push_target(void)
int(* to_fileio_pwrite)(struct target_ops *, int fd, const gdb_byte *write_buf, int len, ULONGEST offset, int *target_errno)
Definition: target.h:901
thread_control_state control
Definition: gdbthread.h:291
int check_quit_flag(void)
Definition: extension.c:828
target_waitkind
Definition: waitstatus.h:28
int len
Definition: ax.h:94
enum target_waitkind kind
Definition: waitstatus.h:106
static void init_extended_remote_ops(void)
Definition: remote.c:13680
static int remote_hostio_pread_vFile(struct target_ops *self, int fd, gdb_byte *read_buf, int len, ULONGEST offset, int *remote_errno)
Definition: remote.c:11569
void(* to_kill)(struct target_ops *) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:570
thread_item & operator=(thread_item &&other)=default
static void remote_check_symbols(void)
Definition: remote.c:4356
void notif_event_xfree(struct notif_event *event)
Definition: remote-notif.c:220
ptid_t inferior_ptid
Definition: infcmd.c:94
static int remote_threadlist_iterator(rmt_thread_action stepfunction, void *context, int looplimit)
Definition: remote.c:2907
static int remote_insert_hw_breakpoint(struct target_ops *self, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition: remote.c:10081
static int remote_follow_fork(struct target_ops *ops, int follow_child, int detach_fork)
Definition: remote.c:5186
void detach_inferior(int pid)
Definition: inferior.c:257
struct minimal_symbol * minsym
Definition: minsyms.h:34
void exec_file_locate_attach(int pid, int defer_bp_reset, int from_tty)
Definition: exec.c:191
enum REMOTE_NOTIF_ID id
Definition: remote-notif.h:71
char * safe_strerror(int)
enum strata to_stratum
Definition: target.h:656
int(* to_stopped_by_sw_breakpoint)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:483
static int remote_hostio_pwrite(struct target_ops *self, int fd, const gdb_byte *write_buf, int len, ULONGEST offset, int *remote_errno)
Definition: remote.c:11539
void observer_notify_signal_received(enum gdb_signal siggnal)
int gdb_threadref
Definition: remote.c:2292
struct remote_notif_state * notif_state
Definition: remote.c:422
static enum target_xfer_status remote_xfer_partial(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
Definition: remote.c:10430
void(* to_set_circular_trace_buffer)(struct target_ops *, int val) TARGET_DEFAULT_IGNORE()
Definition: target.h:1043
const char * target_pid_to_str(ptid_t ptid)
Definition: target.c:2194
void(* to_open)(const char *, int)
Definition: target.h:426
int offset
Definition: agent.c:65
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:569
int may_write_memory
void(* to_post_attach)(struct target_ops *, int) TARGET_DEFAULT_IGNORE()
Definition: target.h:441
long sizeof_g_packet
Definition: remote.c:528
static void remote_delete_command(const char *args, int from_tty)
Definition: remote.c:12133
struct target_section * target_section_by_addr(struct target_ops *target, CORE_ADDR addr)
Definition: target.c:982
static void extended_remote_create_inferior(struct target_ops *ops, const char *exec_file, const std::string &args, char **env, int from_tty)
Definition: remote.c:9635
Definition: buffer.h:23
int(* to_can_async_p)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:666
static int remote_hostio_close(struct target_ops *self, int fd, int *remote_errno)
Definition: remote.c:11678
int notif_debug
Definition: remote-notif.c:44
int may_write_registers
static void trace_error(char *buf)
Definition: remote.c:549
static constexpr ptid_t lwp
const std::set< std::string > & user_set_env() const
Definition: environ.c:174
#define VEC_free(T, V)
Definition: vec.h:196
#define qsort
Definition: ada-exp.c:2694
static int remote_hostio_set_filesystem(struct inferior *inf, int *remote_errno)
Definition: remote.c:11458
int serial_parity
Definition: serial.c:651
gdbarch * arch() const
Definition: regcache.c:221
#define BUF_THREAD_ID_SIZE
Definition: remote.c:2320
CORE_ADDR stop_pc
Definition: infcmd.c:98
void parse_tsv_definition(const char *line, struct uploaded_tsv **utsvp)
Definition: tracepoint.c:3651
static int stubhex(int ch)
Definition: remote.c:2460
int(* to_static_tracepoint_marker_at)(struct target_ops *, CORE_ADDR, struct static_tracepoint_marker *marker) TARGET_DEFAULT_RETURN(0)
Definition: target.h:1086
static void extended_remote_environment_support(struct remote_state *rs)
Definition: remote.c:9567
static int remote_query_attached(int pid)
Definition: remote.c:1732
static int remote_supports_cond_tracepoints(void)
Definition: remote.c:12183
int parse_pid_to_attach(const char *args)
Definition: utils.c:3139
void switch_to_thread_no_regs(struct thread_info *thread)
Definition: thread.c:1396
int(* to_remove_breakpoint)(struct target_ops *, struct gdbarch *, struct bp_target_info *, enum remove_bp_reason) TARGET_DEFAULT_FUNC(memory_remove_breakpoint)
Definition: target.h:469
static struct inferior * remote_add_inferior(int fake_pid_p, int pid, int attached, int try_open_exec)
Definition: remote.c:1777
char * pack_hex_byte(char *pkt, int byte)
Definition: rsp-low.c:86
int(* to_stopped_by_watchpoint)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:531
void() serial_event_ftype(struct serial *scb, void *context)
Definition: serial.h:208
int(* to_get_trace_status)(struct target_ops *, struct trace_status *ts) TARGET_DEFAULT_RETURN(-1)
Definition: target.h:988
int cached_wait_status
Definition: remote.c:341
static int stop_reply_match_ptid_and_ws(QUEUE(stop_reply_p) *q, QUEUE_ITER(stop_reply_p) *iter, struct stop_reply *event, void *data)
Definition: remote.c:6714
static char * append_resumption(char *p, char *endp, ptid_t ptid, int step, enum gdb_signal siggnal)
Definition: remote.c:5452
ULONGEST addr
Definition: tracepoint.h:170
static void remote_stop_ns(ptid_t ptid)
Definition: remote.c:6052
void(* ack)(struct notif_client *self, char *buf, struct notif_event *event)
Definition: remote-notif.h:60
static const char * get_remote_exec_file(void)
Definition: remote.c:683
#define MAX_ACTION_SIZE
Definition: remote.c:5834
struct ui_file * gdb_stdtarg
Definition: main.c:75
struct inferior * inf
Definition: gdbthread.h:261
target_hw_bp_type
Definition: break-common.h:22
static struct packet_config remote_protocol_packets[PACKET_MAX]
Definition: remote.c:1521
enum auto_boolean detect
Definition: remote.c:1207
static void remote_set_circular_trace_buffer(struct target_ops *self, int val)
Definition: remote.c:12916
void ** data
Definition: gdbarch.c:148
struct thread_info * thread_list
Definition: thread.c:53
void(* to_terminal_ours)(struct target_ops *) TARGET_DEFAULT_IGNORE()
Definition: target.h:566
int(* to_stopped_by_hw_breakpoint)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:496
int ptid_equal(const ptid_t &ptid1, const ptid_t &ptid2)
Definition: ptid.c:71
void parse_xml_btrace_conf(struct btrace_config *conf, const char *xml)
Definition: btrace.c:2296
static void add_current_inferior_and_thread(char *wait_status)
Definition: remote.c:3773
gdb::def_vector< gdb_byte > byte_vector
Definition: byte-vector.h:58
void(* to_enable_tracepoint)(struct target_ops *, struct bp_location *location) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:968
static int readchar(int timeout)
Definition: remote.c:8548
struct inferior * current_inferior(void)
Definition: inferior.c:58
static int remote_supports_enable_disable_tracepoint(struct target_ops *self)
Definition: remote.c:12213
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1004
int is_exited(ptid_t ptid)
Definition: thread.c:969
void remote_fileio_to_host_stat(struct fio_stat *fst, struct stat *st)
void(* to_terminal_inferior)(struct target_ops *) TARGET_DEFAULT_IGNORE()
Definition: target.h:562
int breakpoints_should_be_inserted_now(void)
Definition: breakpoint.c:391
auto_boolean
Definition: defs.h:237
const char * to_shortname
Definition: target.h:415
static void record_currthread(struct remote_state *rs, ptid_t currthread)
Definition: remote.c:1966
gdb_xml_attribute_handler gdb_xml_parse_attr_ulongest
struct program_space * current_program_space
Definition: progspace.c:35
int ptid_match(const ptid_t &ptid, const ptid_t &filter)
Definition: ptid.c:103
#define MAXTHREADLISTRESULTS
Definition: remote.c:279
unsigned char * buf
Definition: ax.h:91
const struct gdb_xml_element thread_children[]
Definition: remote.c:3125
static void remote_unpush_and_throw(void)
Definition: remote.c:4931
struct target_section_table * target_get_section_table(struct target_ops *target)
Definition: target.c:974
static enum auto_boolean remote_Z_packet_detect
Definition: remote.c:1599
static char * remote_query_supported_append(char *msg, const char *append)
Definition: remote.c:4692
unsigned long long ULONGEST
Definition: common-types.h:53
static int remote_can_use_agent(struct target_ops *self)
Definition: remote.c:13077
int starting_up
Definition: remote.c:326
int fs_pid
Definition: remote.c:431
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition: corelow.c:879
static void remote_mourn(struct target_ops *ops)
Definition: remote.c:9390
int to_magic
Definition: target.h:1261
int serial_setparity(struct serial *scb, int parity)
Definition: serial.c:530
static void discard_pending_stop_replies(struct inferior *inf)
Definition: remote.c:6570
static void remote_supported_packet(const struct protocol_feature *feature, enum packet_support support, const char *argument)
Definition: remote.c:4502
static int remote_supports_install_in_trace(void)
Definition: remote.c:12207
int register_size(struct gdbarch *gdbarch, int regnum)
Definition: regcache.c:164
void clear_async_event_handler(async_event_handler *async_handler_ptr)
Definition: event-loop.c:1044
static void remote_interrupt_ns(void)
Definition: remote.c:6125
static int remote_thread_alive(struct target_ops *ops, ptid_t ptid)
Definition: remote.c:2243
thread_item(ptid_t ptid_)
Definition: remote.c:2954
struct observer * observer_attach_new_objfile(observer_new_objfile_ftype *f)
static void print_packet(const char *)
Definition: remote.c:8642
std::string name
Definition: remote.c:446
static struct cmd_list_element * remote_set_cmdlist
Definition: remote.c:245
static struct memory_packet_config memory_write_packet_config
Definition: remote.c:1132
#define gdb_stdlog
Definition: utils.h:349
int(* to_supports_non_stop)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:676
static int remote_can_run_breakpoint_commands(struct target_ops *self)
Definition: remote.c:12226
static int stub_unpack_int(char *buff, int fieldlength)
Definition: remote.c:2472
static void remote_open_1(const char *, int, struct target_ops *, int extended_p)
Definition: remote.c:4938
static struct stop_reply * remote_notif_remove_queued_reply(ptid_t ptid)
Definition: remote.c:6660
int memory_insert_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition: mem-break.c:87
static ptid_t remote_wait(struct target_ops *ops, ptid_t ptid, struct target_waitstatus *status, int options)
Definition: remote.c:7443
void handle_notification(struct remote_notif_state *state, char *buf)
Definition: remote-notif.c:127
ptid_t continue_thread
Definition: remote.c:382
ULONGEST finished_offset
Definition: remote.c:405
int(* to_has_all_memory)(struct target_ops *)
Definition: target.h:657
struct cmd_list_element * maintenancelist
Definition: cli-cmds.c:135
void regcache_raw_collect(const struct regcache *regcache, int regnum, void *buf)
Definition: regcache.c:1085
void(* to_interrupt)(struct target_ops *, ptid_t) TARGET_DEFAULT_IGNORE()
Definition: target.h:643
static void get_offsets(void)
Definition: remote.c:3524
static void set_continue_thread(ptid_t ptid)
Definition: remote.c:2190
int(* to_fileio_unlink)(struct target_ops *, struct inferior *inf, const char *filename, int *target_errno)
Definition: target.h:926
static int remote_add_target_side_condition(struct gdbarch *gdbarch, struct bp_target_info *bp_tgt, char *buf, char *buf_end)
Definition: remote.c:9711
int startup_with_shell
Definition: infcmd.c:111
static LONGEST remote_get_raw_trace_data(struct target_ops *self, gdb_byte *buf, ULONGEST offset, LONGEST len)
Definition: remote.c:12845
static void remote_pass_ctrlc(struct target_ops *self)
Definition: remote.c:6184
int remote_register_number_and_offset(struct gdbarch *gdbarch, int regnum, int *pnum, int *poffset)
Definition: remote.c:794
void(* dtr)(struct notif_event *self)
Definition: remote-notif.h:31
static void remote_open(const char *name, int from_tty)
Definition: remote.c:4313
agent_expr_up gen_eval_for_expr(CORE_ADDR scope, struct expression *expr)
Definition: ax-gdb.c:2496
static void vcont_builder_push_action(struct vcont_builder *builder, ptid_t ptid, int step, enum gdb_signal siggnal)
Definition: remote.c:5842
static int remote_get_threads_with_ql(struct target_ops *ops, struct threads_listing_context *context)
Definition: remote.c:3065
int hex2bin(const char *hex, gdb_byte *bin, int count)
Definition: rsp-low.c:115
void do_show_command(const char *arg, int from_tty, struct cmd_list_element *c)
Definition: cli-setshow.c:560
static char * write_ptid(char *buf, const char *endbuf, ptid_t ptid)
Definition: remote.c:2387
struct target_waitstatus waitstatus
Definition: gdbthread.h:165
void * input
Definition: remote.c:6396
enum btrace_format format
static void print_one_stopped_thread(struct thread_info *thread)
Definition: remote.c:3811
#define TAG_DISPLAY
Definition: remote.c:2679
void(* to_create_inferior)(struct target_ops *, const char *, const std::string &, char **, int)
Definition: target.h:579
static int remote_get_tib_address(struct target_ops *self, ptid_t ptid, CORE_ADDR *addr)
Definition: remote.c:11096
void free_symfile_segment_data(struct symfile_segment_data *data)
Definition: symfile.c:3679
static void remote_trace_set_readonly_regions(struct target_ops *self)
Definition: remote.c:12534
#define OBSTACK_ZALLOC(OBSTACK, TYPE)
Definition: gdb_obstack.h:27
static int remote_check_watch_resources(struct target_ops *self, enum bptype type, int cnt, int ot)
Definition: remote.c:9985
argv
Definition: __init__.py:63
static void remote_set_trace_buffer_size(struct target_ops *self, LONGEST val)
Definition: remote.c:12977
const char * unpack_varlen_hex(const char *buff, ULONGEST *result)
Definition: rsp-low.c:96
#define SECT_OFF_BSS(objfile)
Definition: objfiles.h:695
int(* to_insert_vfork_catchpoint)(struct target_ops *, int) TARGET_DEFAULT_RETURN(1)
Definition: target.h:588
int to_has_thread_control
Definition: target.h:662
int(* to_thread_alive)(struct target_ops *, ptid_t ptid) TARGET_DEFAULT_RETURN(0)
Definition: target.h:626
static void remote_command(const char *args, int from_tty)
Definition: remote.c:12146
enum packet_support support
Definition: remote.c:1210
gdb_byte * data
Definition: regcache.h:227
static void show_remotebreak(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: remote.c:982
int remote_hw_watchpoint_length_limit
Definition: remote.c:9967
void(* to_attach)(struct target_ops *ops, const char *, int)
Definition: target.h:440
void target_preopen(int from_tty)
Definition: target.c:2121
ULONGEST offset
Definition: remote.c:296
ptid_t general_thread
Definition: remote.c:381
void(* to_follow_exec)(struct target_ops *, struct inferior *, char *) TARGET_DEFAULT_IGNORE()
Definition: target.h:598
int serial_readchar(struct serial *scb, int timeout)
Definition: serial.c:380
breakpoint * owner
Definition: breakpoint.h:341
int(* to_use_agent)(struct target_ops *, int use) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:1104
static int detach_fork
Definition: infrun.c:154
void gdb_flush(struct ui_file *file)
Definition: ui-file.c:93
struct async_event_handler * get_pending_events_token
Definition: remote-notif.h:89
void(* to_pass_ctrlc)(struct target_ops *) TARGET_DEFAULT_FUNC(default_target_pass_ctrlc)
Definition: target.h:645
DISABLE_COPY_AND_ASSIGN(thread_item)
int(* to_supports_btrace)(struct target_ops *, enum btrace_format) TARGET_DEFAULT_RETURN(0)
Definition: target.h:1112
int(* to_stopped_data_address)(struct target_ops *, CORE_ADDR *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:535
ptid_t ptid() const
Definition: regcache.h:325
#define QUIT
Definition: defs.h:179
unsigned char threadref[OPAQUETHREADBYTES]
Definition: remote.c:275
static int remote_insert_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition: remote.c:9763
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_const_cfunc_ftype *fun, const char *doc)
Definition: cli-decode.c:902
enum enable_state enable_state
Definition: breakpoint.h:695
void(* to_update_thread_list)(struct target_ops *) TARGET_DEFAULT_IGNORE()
Definition: target.h:628
struct vCont_action_support supports_vCont
Definition: remote.c:360
const char * name
Definition: remote-notif.h:47
static int getpkt_or_notif_sane_1(char **buf, long *sizeof_buf, int forever, int expecting_notif, int *is_notif)
Definition: remote.c:9065
void target_find_description(void)
static void remote_download_tracepoint(struct target_ops *self, struct bp_location *loc)
Definition: remote.c:12283
#define TAG_EXISTS
Definition: remote.c:2677
static void packet_command(const char *args, int from_tty)
Definition: remote.c:10826
void(* to_prepare_to_store)(struct target_ops *, struct regcache *) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:461
static void set_remote_protocol_Z_packet_cmd(const char *args, int from_tty, struct cmd_list_element *c)
Definition: remote.c:1602
Z_packet_type
Definition: remote.c:1586
static void remote_get_command(const char *args, int from_tty)
Definition: remote.c:12120
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:459
ptid_t ptid
Definition: remote.c:6268
threadref echo_nextthread
Definition: remote.c:417
struct stop_reply * output
Definition: remote.c:6397
static void remote_hostio_close_cleanup(void *opaque)
Definition: remote.c:11932
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition: minsyms.c:311
gdb_signal last_resume_sig
Definition: remote.c:472
int memory_remove_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt, enum remove_bp_reason reason)
Definition: mem-break.c:94
int(* to_has_registers)(struct target_ops *)
Definition: target.h:660
static void set_remote_exec_file(const char *ignored, int from_tty, struct cmd_list_element *c)
Definition: remote.c:712
static int remote_get_threads_with_qthreadinfo(struct target_ops *ops, struct threads_listing_context *context)
Definition: remote.c:3172
ptid_t(* to_wait)(struct target_ops *, ptid_t, struct target_waitstatus *, int TARGET_DEBUG_PRINTER(target_debug_print_options)) TARGET_DEFAULT_FUNC(default_target_wait)
Definition: target.h:453
void putstrn(const char *str, int n, int quoter)
Definition: ui-file.c:53
static int remote_stopped_by_hw_breakpoint(struct target_ops *ops)
Definition: remote.c:10035
struct command_line ** body_list
Definition: cli-script.h:71
const char * name
Definition: remote.c:4479
ptid_t(* to_get_ada_task_ptid)(struct target_ops *, long lwp, long thread) TARGET_DEFAULT_FUNC(default_get_ada_task_ptid)
Definition: target.h:797
static void readahead_cache_invalidate_fd(int fd)
Definition: remote.c:11445
int is_target_filename(const char *name)
Definition: gdb_bfd.c:208
static struct target_ops remote_ops
Definition: remote.c:905
static int remote_can_async_p(struct target_ops *)
Definition: remote.c:13700
struct target_waitstatus ws
Definition: remote.c:6275
static long read_frame(char **buf_p, long *sizeof_buf)
Definition: remote.c:8912
void(* to_disable_btrace)(struct target_ops *, struct btrace_target_info *tinfo) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:1124
void pop_all_targets_at_and_above(enum strata stratum)
Definition: target.c:752
void parse_static_tracepoint_marker_definition(const char *line, const char **pp, struct static_tracepoint_marker *marker)
Definition: tracepoint.c:3698
void set_executing(ptid_t ptid, int executing)
Definition: thread.c:991
target_stop_reason
Definition: waitstatus.h:127
static void show_remote_protocol_packet_cmd(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: remote.c:1564
static void remote_disconnect(struct target_ops *target, const char *args, int from_tty)
Definition: remote.c:5238
bool fake_pid_p
Definition: inferior.h:330
static int remote_search_memory(struct target_ops *ops, CORE_ADDR start_addr, ULONGEST search_space_len, const gdb_byte *pattern, ULONGEST pattern_len, CORE_ADDR *found_addrp)
Definition: remote.c:10651
char display[256]
Definition: remote.c:2302
void error(const char *fmt,...)
Definition: errors.c:38
const char *(* to_thread_name)(struct target_ops *, struct thread_info *) TARGET_DEFAULT_RETURN(NULL)
Definition: target.h:634
static struct target_waitstatus * thread_pending_fork_status(struct thread_info *thread)
Definition: remote.c:6422
size_t size
Definition: go32-nat.c:242
char * endp
Definition: remote.c:5796
int symfile_map_offsets_to_segments(bfd *abfd, const struct symfile_segment_data *data, struct section_offsets *offsets, int num_segment_bases, const CORE_ADDR *segment_bases)
Definition: symfile.c:3703
char *(* to_fileio_readlink)(struct target_ops *, struct inferior *inf, const char *filename, int *target_errno)
Definition: target.h:936
struct gdbarch_data * gdbarch_data_register_post_init(gdbarch_data_post_init_ftype *post_init)
Definition: gdbarch.c:5136
static void init_all_packet_configs(void)
Definition: remote.c:4342
ptid_t minus_one_ptid
Definition: ptid.c:26
#define target_static_tracepoint_marker_at(addr, marker)
Definition: target.h:2204
remove_bp_reason
Definition: breakpoint.h:47
static long get_memory_write_packet_size(void)
Definition: remote.c:1150
static char * pack_int(char *buf, int value)
Definition: remote.c:2503
static int remote_fileio_errno_to_host(int errnum)
Definition: remote.c:11870
struct notif_client notif_client_stop
Definition: remote.c:6381
int auto_solib_add
Definition: symfile.c:149
void fputstr_filtered(const char *str, int quoter, struct ui_file *stream)
Definition: utils.c:1254
static void remote_load(struct target_ops *self, const char *name, int from_tty)
Definition: remote.c:13423
static void remote_prepare_to_store(struct target_ops *self, struct regcache *regcache)
Definition: remote.c:7747
void parse_tracepoint_definition(const char *line, struct uploaded_tp **utpp)
Definition: tracepoint.c:3535
static void remote_stop(struct target_ops *self, ptid_t)
Definition: remote.c:6152
static struct btrace_target_info * remote_enable_btrace(struct target_ops *self, ptid_t ptid, const struct btrace_config *conf)
Definition: remote.c:13258
static int remote_hostio_fstat(struct target_ops *self, int fd, struct stat *st, int *remote_errno)
Definition: remote.c:11761
const struct gdb_xml_element threads_children[]
Definition: remote.c:3129
void set_current_inferior(struct inferior *inf)
Definition: inferior.c:64
int gdbarch_remote_register_number(struct gdbarch *gdbarch, int regno)
Definition: gdbarch.c:3004
void throw_error(enum errors error, const char *fmt,...)
long long LONGEST
Definition: common-types.h:52
struct target_ops * beneath
Definition: target.h:414
void inferior_appeared(struct inferior *inf, int pid)
Definition: inferior.c:268
DEFINE_QUEUE_P(stop_reply_p)
static struct notif_event * remote_notif_stop_alloc_reply(void)
Definition: remote.c:6369
int(* to_can_execute_reverse)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:822
void(* to_load)(struct target_ops *, const char *, int) TARGET_DEFAULT_NORETURN(tcomplain())
Definition: target.h:572
struct stop_reply * stop_reply_p
static void remote_start_remote(int from_tty, struct target_ops *target, int extended_p)
Definition: remote.c:3996
void do_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:174
static void discard_pending_stop_replies_in_queue(struct remote_state *)
Definition: remote.c:6623
static void extended_remote_restart(void)
Definition: remote.c:3474
char * first_action
Definition: remote.c:5790
void _initialize_remote(void)
Definition: remote.c:13942
int(* to_filesystem_is_local)(struct target_ops *) TARGET_DEFAULT_RETURN(1)
Definition: target.h:883
struct regcache * get_thread_arch_regcache(ptid_t ptid, struct gdbarch *gdbarch)
Definition: regcache.c:423
int(* to_supports_multi_process)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:833
void setup_inferior(int from_tty)
Definition: infcmd.c:2640
CORE_ADDR step_range_end
Definition: gdbthread.h:78
int(* to_can_use_agent)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
Definition: target.h:1108
static int remote_supports_static_tracepoints(void)
Definition: remote.c:12201
char * last_program_signals_packet
Definition: remote.c:394
void init_thread_list(void)
Definition: thread.c:221
void encode_actions_rsp(struct bp_location *tloc, std::vector< std::string > *tdp_actions, std::vector< std::string > *stepping_actions)
Definition: tracepoint.c:1500
const struct target_desc * gdbarch_target_desc(struct gdbarch *gdbarch)
Definition: gdbarch.c:1536
#define gdb_stdout
Definition: utils.h:340
static ptid_t get_current_thread(char *wait_status)
Definition: remote.c:3746
static int kill_child_of_pending_fork(QUEUE(stop_reply_p) *q, QUEUE_ITER(stop_reply_p) *iter, stop_reply_p event, void *data)
Definition: remote.c:9225
static void remote_resume(struct target_ops *ops, ptid_t ptid, int step, enum gdb_signal siggnal)
Definition: remote.c:5697
#define ALL_THREADS_SAFE(T, TMP)
Definition: gdbthread.h:496
static int putpkt_binary(const char *buf, int cnt)
Definition: remote.c:8662
static void remote_notif_stop_parse(struct notif_client *self, char *buf, struct notif_event *event)
Definition: remote.c:6319
static void remote_pspace_data_cleanup(struct program_space *pspace, void *arg)
Definition: remote.c:673
static int remote_supports_multi_process(struct target_ops *self)
Definition: remote.c:12175
const char * name
Definition: tracepoint.h:53
struct target_ops * find_target_at(enum strata stratum)
Definition: target.c:3161
static int remote_get_threads_with_qxfer(struct target_ops *ops, struct threads_listing_context *context)
Definition: remote.c:3147
void remote_fileio_request(char *buf, int ctrlc_pending_p)
static int remote_hostio_pread(struct target_ops *self, int fd, gdb_byte *read_buf, int len, ULONGEST offset, int *remote_errno)
Definition: remote.c:11634
static int remote_remove_fork_catchpoint(struct target_ops *ops, int pid)
Definition: remote.c:1671
static int remote_supports_non_stop(struct target_ops *self)
Definition: remote.c:12162
static int fetch_register_using_p(struct regcache *regcache, struct packet_reg *reg)
Definition: remote.c:7467
void int_to_threadref(threadref *id, int value)
Definition: remote.c:2590