2012-03-20 Pedro Alves <palves@redhat.com>
[deliverable/binutils-gdb.git] / gdb / remote.c
index 591c9f6d4fb99dd5865073d5c4bf4bc3460e94a2..caf6116837f12c78909d6251cae803044085f16e 100644 (file)
@@ -1,8 +1,6 @@
 /* Remote target communications for serial-line targets in custom GDB protocol
 
-   Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-   2010 Free Software Foundation, Inc.
+   Copyright (C) 1988-2012 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "tracepoint.h"
 #include "ax.h"
 #include "ax-gdb.h"
+#include "agent.h"
 
-/* temp hacks for tracepoint encoding migration */
+/* Temp hacks for tracepoint encoding migration.  */
 static char *target_buf;
 static long target_buf_size;
-/*static*/ void
-encode_actions (struct breakpoint *t, struct bp_location *tloc,
-               char ***tdp_actions, char ***stepping_actions);
 
 /* The size to align memory write packets, when practical.  The protocol
    does not guarantee any alignment, and gdb will generate short
@@ -134,8 +130,6 @@ static int remote_is_async_p (void);
 static void remote_async (void (*callback) (enum inferior_event_type event_type,
                                            void *context), void *context);
 
-static int remote_async_mask (int new_mask);
-
 static void remote_detach (struct target_ops *ops, char *args, int from_tty);
 
 static void remote_interrupt (int signo);
@@ -212,6 +206,8 @@ static void show_remote_protocol_packet_cmd (struct ui_file *file,
 static char *write_ptid (char *buf, const char *endbuf, ptid_t ptid);
 static ptid_t read_ptid (char *buf, char **obuf);
 
+static void remote_set_permissions (void);
+
 struct remote_state;
 static int remote_get_trace_status (struct trace_status *ts);
 
@@ -242,6 +238,10 @@ static void remote_terminal_ours (void);
 
 static int remote_read_description_p (struct target_ops *target);
 
+static void remote_console_output (char *msg);
+
+static int remote_supports_cond_breakpoints (void);
+
 /* The non-stop remote protocol provisions for one pending stop reply.
    This is where we keep it until it is acknowledged.  */
 
@@ -271,6 +271,10 @@ struct remote_state
   char *buf;
   long buf_size;
 
+  /* True if we're going through initial connection setup (finding out
+     about the remote side's threads, relocating symbols, etc.).  */
+  int starting_up;
+
   /* If we negotiated packet size explicitly (and thus can bypass
      heuristics for the largest packet size that will not overflow
      a buffer in the stub), this will be set to that packet size.
@@ -315,13 +319,31 @@ struct remote_state
   /* True if the stub reports support for conditional tracepoints.  */
   int cond_tracepoints;
 
+  /* True if the stub reports support for target-side breakpoint
+     conditions.  */
+  int cond_breakpoints;
+
   /* True if the stub reports support for fast tracepoints.  */
   int fast_tracepoints;
 
+  /* True if the stub reports support for static tracepoints.  */
+  int static_tracepoints;
+
+  /* True if the stub reports support for installing tracepoint while
+     tracing.  */
+  int install_in_trace;
+
   /* True if the stub can continue running a trace while GDB is
      disconnected.  */
   int disconnected_tracing;
 
+  /* True if the stub reports support for enabling and disabling
+     tracepoints while a trace experiment is running.  */
+  int enable_disable_tracepoints;
+
+  /* True if the stub can collect strings using tracenz bytecode.  */
+  int string_tracing;
+
   /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
      responded to that.  */
   int ctrlc_pending_p;
@@ -345,7 +367,7 @@ free_private_thread_info (struct private_thread_info *info)
 static int
 remote_multi_process_p (struct remote_state *rs)
 {
-  return rs->extended && rs->multi_process_aware;
+  return rs->multi_process_aware;
 }
 
 /* This data could be associated with a target, but we do not always
@@ -427,15 +449,65 @@ remote_get_noisy_reply (char **buf_p,
   do                           /* Loop on reply from remote stub.  */
     {
       char *buf;
-      QUIT;                    /* allow user to bail out with ^C */
+
+      QUIT;                    /* Allow user to bail out with ^C.  */
       getpkt (buf_p, sizeof_buf, 0);
       buf = *buf_p;
       if (buf[0] == 'E')
        trace_error (buf);
+      else if (strncmp (buf, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
+       {
+         ULONGEST ul;
+         CORE_ADDR from, to, org_to;
+         char *p, *pp;
+         int adjusted_size = 0;
+         volatile struct gdb_exception ex;
+
+         p = buf + strlen ("qRelocInsn:");
+         pp = unpack_varlen_hex (p, &ul);
+         if (*pp != ';')
+           error (_("invalid qRelocInsn packet: %s"), buf);
+         from = ul;
+
+         p = pp + 1;
+         unpack_varlen_hex (p, &ul);
+         to = ul;
+
+         org_to = to;
+
+         TRY_CATCH (ex, RETURN_MASK_ALL)
+           {
+             gdbarch_relocate_instruction (target_gdbarch, &to, from);
+           }
+         if (ex.reason >= 0)
+           {
+             adjusted_size = to - org_to;
+
+             xsnprintf (buf, *sizeof_buf, "qRelocInsn:%x", adjusted_size);
+             putpkt (buf);
+           }
+         else if (ex.reason < 0 && ex.error == MEMORY_ERROR)
+           {
+             /* Propagate memory errors silently back to the target.
+                The stub may have limited the range of addresses we
+                can write to, for example.  */
+             putpkt ("E01");
+           }
+         else
+           {
+             /* Something unexpectedly bad happened.  Be verbose so
+                we can tell what, and propagate the error back to the
+                stub, so it doesn't get stuck waiting for a
+                response.  */
+             exception_fprintf (gdb_stderr, ex,
+                                _("warning: relocating instruction: "));
+             putpkt ("E01");
+           }
+       }
       else if (buf[0] == 'O' && buf[1] != 'K')
        remote_console_output (buf + 1);        /* 'O' message from stub */
       else
-       return buf;             /* here's the actual reply */
+       return buf;             /* Here's the actual reply.  */
     }
   while (1);
 }
@@ -478,24 +550,15 @@ compare_pnums (const void *lhs_, const void *rhs_)
     return 1;
 }
 
-static void *
-init_remote_state (struct gdbarch *gdbarch)
+static int
+map_regcache_remote_table (struct gdbarch *gdbarch, struct packet_reg *regs)
 {
   int regnum, num_remote_regs, offset;
-  struct remote_state *rs = get_remote_state_raw ();
-  struct remote_arch_state *rsa;
   struct packet_reg **remote_regs;
 
-  rsa = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct remote_arch_state);
-
-  /* Use the architecture to build a regnum<->pnum table, which will be
-     1:1 unless a feature set specifies otherwise.  */
-  rsa->regs = GDBARCH_OBSTACK_CALLOC (gdbarch,
-                                     gdbarch_num_regs (gdbarch),
-                                     struct packet_reg);
   for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
     {
-      struct packet_reg *r = &rsa->regs[regnum];
+      struct packet_reg *r = &regs[regnum];
 
       if (register_size (gdbarch, regnum) == 0)
        /* Do not try to fetch zero-sized (placeholder) registers.  */
@@ -511,12 +574,12 @@ init_remote_state (struct gdbarch *gdbarch)
      number.  */
 
   remote_regs = alloca (gdbarch_num_regs (gdbarch)
-                         * sizeof (struct packet_reg *));
+                       * sizeof (struct packet_reg *));
   for (num_remote_regs = 0, regnum = 0;
        regnum < gdbarch_num_regs (gdbarch);
        regnum++)
-    if (rsa->regs[regnum].pnum != -1)
-      remote_regs[num_remote_regs++] = &rsa->regs[regnum];
+    if (regs[regnum].pnum != -1)
+      remote_regs[num_remote_regs++] = &regs[regnum];
 
   qsort (remote_regs, num_remote_regs, sizeof (struct packet_reg *),
         compare_pnums);
@@ -528,11 +591,57 @@ init_remote_state (struct gdbarch *gdbarch)
       offset += register_size (gdbarch, remote_regs[regnum]->regnum);
     }
 
+  return offset;
+}
+
+/* Given the architecture described by GDBARCH, return the remote
+   protocol register's number and the register's offset in the g/G
+   packets of GDB register REGNUM, in PNUM and POFFSET respectively.
+   If the target does not have a mapping for REGNUM, return false,
+   otherwise, return true.  */
+
+int
+remote_register_number_and_offset (struct gdbarch *gdbarch, int regnum,
+                                  int *pnum, int *poffset)
+{
+  int sizeof_g_packet;
+  struct packet_reg *regs;
+  struct cleanup *old_chain;
+
+  gdb_assert (regnum < gdbarch_num_regs (gdbarch));
+
+  regs = xcalloc (gdbarch_num_regs (gdbarch), sizeof (struct packet_reg));
+  old_chain = make_cleanup (xfree, regs);
+
+  sizeof_g_packet = map_regcache_remote_table (gdbarch, regs);
+
+  *pnum = regs[regnum].pnum;
+  *poffset = regs[regnum].offset;
+
+  do_cleanups (old_chain);
+
+  return *pnum != -1;
+}
+
+static void *
+init_remote_state (struct gdbarch *gdbarch)
+{
+  struct remote_state *rs = get_remote_state_raw ();
+  struct remote_arch_state *rsa;
+
+  rsa = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct remote_arch_state);
+
+  /* Use the architecture to build a regnum<->pnum table, which will be
+     1:1 unless a feature set specifies otherwise.  */
+  rsa->regs = GDBARCH_OBSTACK_CALLOC (gdbarch,
+                                     gdbarch_num_regs (gdbarch),
+                                     struct packet_reg);
+
   /* Record the maximum possible size of the g packet - it may turn out
      to be smaller.  */
-  rsa->sizeof_g_packet = offset;
+  rsa->sizeof_g_packet = map_regcache_remote_table (gdbarch, rsa->regs);
 
-  /* Default maximum number of characters in a packet body. Many
+  /* Default maximum number of characters in a packet body.  Many
      remote stubs have a hardwired buffer size of 400 bytes
      (c.f. BUFMAX in m68k-stub.c and i386-stub.c).  BUFMAX-1 is used
      as the maximum packet-size to ensure that the packet and an extra
@@ -545,9 +654,9 @@ init_remote_state (struct gdbarch *gdbarch)
   rsa->actual_register_packet_size = 0;
 
   /* Should rsa->sizeof_g_packet needs more space than the
-     default, adjust the size accordingly. Remember that each byte is
-     encoded as two characters. 32 is the overhead for the packet
-     header / footer. NOTE: cagney/1999-10-26: I suspect that 8
+     default, adjust the size accordingly.  Remember that each byte is
+     encoded as two characters.  32 is the overhead for the packet
+     header / footer.  NOTE: cagney/1999-10-26: I suspect that 8
      (``$NN:G...#NN'') is a better guess, the below has been padded a
      little.  */
   if (rsa->sizeof_g_packet > ((rsa->remote_packet_size - 32) / 2))
@@ -587,6 +696,7 @@ packet_reg_from_regnum (struct remote_arch_state *rsa, long regnum)
   else
     {
       struct packet_reg *r = &rsa->regs[regnum];
+
       gdb_assert (r->regnum == regnum);
       return r;
     }
@@ -596,9 +706,11 @@ static struct packet_reg *
 packet_reg_from_pnum (struct remote_arch_state *rsa, LONGEST pnum)
 {
   int i;
+
   for (i = 0; i < gdbarch_num_regs (target_gdbarch); i++)
     {
       struct packet_reg *r = &rsa->regs[i];
+
       if (r->pnum == pnum)
        return r;
     }
@@ -620,8 +732,6 @@ static struct target_ops remote_ops;
 
 static struct target_ops extended_remote_ops;
 
-static int remote_async_mask_value = 1;
-
 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
    ``forever'' still use the normal timeout mechanism.  This is
    currently used by the ASYNC code to guarentee that target reads
@@ -640,7 +750,7 @@ static int wait_forever_enabled_p = 1;
 const char interrupt_sequence_control_c[] = "Ctrl-C";
 const char interrupt_sequence_break[] = "BREAK";
 const char interrupt_sequence_break_g[] = "BREAK-g";
-static const char *interrupt_sequence_modes[] =
+static const char *const interrupt_sequence_modes[] =
   {
     interrupt_sequence_control_c,
     interrupt_sequence_break,
@@ -708,7 +818,7 @@ static struct serial *remote_desc = NULL;
 
 /* This variable sets the number of bits in an address that are to be
    sent in a memory ("M" or "m") packet.  Normally, after stripping
-   leading zeros, the entire address would be sent. This variable
+   leading zeros, the entire address would be sent.  This variable
    restricts the address to REMOTE_ADDRESS_SIZE bits.  HISTORY: The
    initial implementation of remote.c restricted the address sent in
    memory packets to ``host::sizeof long'' bytes - (typically 32
@@ -804,7 +914,7 @@ get_memory_packet_size (struct memory_packet_config *config)
   return what_they_get;
 }
 
-/* Update the size of a read/write packet. If they user wants
+/* Update the size of a read/write packet.  If they user wants
    something really big then do a sanity check.  */
 
 static void
@@ -812,6 +922,7 @@ set_memory_packet_size (char *args, struct memory_packet_config *config)
 {
   int fixed_p = config->fixed_p;
   long size = config->size;
+
   if (args == NULL)
     error (_("Argument required (integer, `fixed' or `limited')."));
   else if (strcmp (args, "hard") == 0
@@ -823,6 +934,7 @@ set_memory_packet_size (char *args, struct memory_packet_config *config)
   else
     {
       char *end;
+
       size = strtoul (args, &end, 0);
       if (args == end)
        error (_("Invalid %s (bad syntax)."), config->name);
@@ -904,6 +1016,7 @@ static long
 get_memory_read_packet_size (void)
 {
   long size = get_memory_packet_size (&memory_read_packet_config);
+
   /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
      extra buffer size argument before the memory read size can be
      increased beyond this.  */
@@ -914,7 +1027,7 @@ get_memory_read_packet_size (void)
 
 \f
 /* Generic configuration support for packets the stub optionally
-   supports. Allows the user to specify the use of the packet as well
+   supports.  Allows the user to specify the use of the packet as well
    as allowing GDB to auto-detect support in the remote stub.  */
 
 enum packet_support
@@ -963,6 +1076,7 @@ static void
 show_packet_config_cmd (struct packet_config *config)
 {
   char *support = "internal-error";
+
   switch (config->support)
     {
     case PACKET_ENABLE:
@@ -978,7 +1092,8 @@ show_packet_config_cmd (struct packet_config *config)
   switch (config->detect)
     {
     case AUTO_BOOLEAN_AUTO:
-      printf_filtered (_("Support for the `%s' packet is auto-detected, currently %s.\n"),
+      printf_filtered (_("Support for the `%s' packet "
+                        "is auto-detected, currently %s.\n"),
                       config->name, support);
       break;
     case AUTO_BOOLEAN_TRUE:
@@ -1003,12 +1118,14 @@ add_packet_config_cmd (struct packet_config *config, const char *name,
   config->support = PACKET_SUPPORT_UNKNOWN;
   set_doc = xstrprintf ("Set use of remote protocol `%s' (%s) packet",
                        name, title);
-  show_doc = xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
+  show_doc = xstrprintf ("Show current use of remote "
+                        "protocol `%s' (%s) packet",
                         name, title);
   /* set/show TITLE-packet {auto,on,off} */
   cmd_name = xstrprintf ("%s-packet", title);
   add_setshow_auto_boolean_cmd (cmd_name, class_obscure,
-                               &config->detect, set_doc, show_doc, NULL, /* help_doc */
+                               &config->detect, set_doc,
+                               show_doc, NULL, /* help_doc */
                                set_remote_protocol_packet_cmd,
                                show_remote_protocol_packet_cmd,
                                &remote_set_cmdlist, &remote_show_cmdlist);
@@ -1019,6 +1136,7 @@ add_packet_config_cmd (struct packet_config *config, const char *name,
   if (legacy)
     {
       char *legacy_name;
+
       legacy_name = xstrprintf ("%s-packet", name);
       add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
                     &remote_set_cmdlist);
@@ -1128,17 +1246,24 @@ enum {
   PACKET_vFile_pwrite,
   PACKET_vFile_close,
   PACKET_vFile_unlink,
+  PACKET_vFile_readlink,
   PACKET_qXfer_auxv,
   PACKET_qXfer_features,
   PACKET_qXfer_libraries,
+  PACKET_qXfer_libraries_svr4,
   PACKET_qXfer_memory_map,
   PACKET_qXfer_spu_read,
   PACKET_qXfer_spu_write,
   PACKET_qXfer_osdata,
   PACKET_qXfer_threads,
+  PACKET_qXfer_statictrace_read,
+  PACKET_qXfer_traceframe_info,
+  PACKET_qXfer_uib,
+  PACKET_qGetTIBAddr,
   PACKET_qGetTLSAddr,
   PACKET_qSupported,
   PACKET_QPassSignals,
+  PACKET_QProgramSignals,
   PACKET_qSearch_memory,
   PACKET_vAttach,
   PACKET_vRun,
@@ -1148,10 +1273,17 @@ enum {
   PACKET_qXfer_siginfo_write,
   PACKET_qAttached,
   PACKET_ConditionalTracepoints,
+  PACKET_ConditionalBreakpoints,
   PACKET_FastTracepoints,
+  PACKET_StaticTracepoints,
+  PACKET_InstallInTrace,
   PACKET_bc,
   PACKET_bs,
   PACKET_TracepointSource,
+  PACKET_QAllow,
+  PACKET_qXfer_fdpic,
+  PACKET_QDisableRandomization,
+  PACKET_QAgent,
   PACKET_MAX
 };
 
@@ -1173,7 +1305,7 @@ set_remote_protocol_packet_cmd (char *args, int from_tty,
          return;
        }
     }
-  internal_error (__FILE__, __LINE__, "Could not find config for %s",
+  internal_error (__FILE__, __LINE__, _("Could not find config for %s"),
                  c->name);
 }
 
@@ -1194,7 +1326,7 @@ show_remote_protocol_packet_cmd (struct ui_file *file, int from_tty,
          return;
        }
     }
-  internal_error (__FILE__, __LINE__, "Could not find config for %s",
+  internal_error (__FILE__, __LINE__, _("Could not find config for %s"),
                  c->name);
 }
 
@@ -1220,6 +1352,7 @@ set_remote_protocol_Z_packet_cmd (char *args, int from_tty,
                                  struct cmd_list_element *c)
 {
   int i;
+
   for (i = 0; i < NR_Z_PACKET_TYPES; i++)
     {
       remote_protocol_packets[PACKET_Z0 + i].detect = remote_Z_packet_detect;
@@ -1233,6 +1366,7 @@ show_remote_protocol_Z_packet_cmd (struct ui_file *file, int from_tty,
                                   const char *value)
 {
   int i;
+
   for (i = 0; i < NR_Z_PACKET_TYPES; i++)
     {
       show_packet_config_cmd (&remote_protocol_packets[PACKET_Z0 + i]);
@@ -1278,6 +1412,10 @@ static ptid_t any_thread_ptid;
 static ptid_t general_thread;
 static ptid_t continue_thread;
 
+/* This the traceframe which we last selected on the remote system.
+   It will be -1 if no traceframe is selected.  */
+static int remote_traceframe_number = -1;
+
 /* Find out if the stub attached to PID (and hence GDB should offer to
    detach instead of killing it when bailing out).  */
 
@@ -1285,14 +1423,15 @@ static int
 remote_query_attached (int pid)
 {
   struct remote_state *rs = get_remote_state ();
+  size_t size = get_remote_packet_size ();
 
   if (remote_protocol_packets[PACKET_qAttached].support == PACKET_DISABLE)
     return 0;
 
   if (remote_multi_process_p (rs))
-    sprintf (rs->buf, "qAttached:%x", pid);
+    xsnprintf (rs->buf, size, "qAttached:%x", pid);
   else
-    sprintf (rs->buf, "qAttached");
+    xsnprintf (rs->buf, size, "qAttached");
 
   putpkt (rs->buf);
   getpkt (&rs->buf, &rs->buf_size, 0);
@@ -1314,16 +1453,17 @@ remote_query_attached (int pid)
   return 0;
 }
 
-/* Add PID to GDB's inferior table.  Since we can be connected to a
-   remote system before before knowing about any inferior, mark the
-   target with execution when we find the first inferior.  If ATTACHED
-   is 1, then we had just attached to this inferior.  If it is 0, then
-   we just created this inferior.  If it is -1, then try querying the
-   remote stub to find out if it had attached to the inferior or
-   not.  */
+/* Add PID to GDB's inferior table.  If FAKE_PID_P is true, then PID
+   has been invented by GDB, instead of reported by the target.  Since
+   we can be connected to a remote system before before knowing about
+   any inferior, mark the target with execution when we find the first
+   inferior.  If ATTACHED is 1, then we had just attached to this
+   inferior.  If it is 0, then we just created this inferior.  If it
+   is -1, then try querying the remote stub to find out if it had
+   attached to the inferior or not.  */
 
 static struct inferior *
-remote_add_inferior (int pid, int attached)
+remote_add_inferior (int fake_pid_p, int pid, int attached)
 {
   struct inferior *inf;
 
@@ -1355,6 +1495,7 @@ remote_add_inferior (int pid, int attached)
     }
 
   inf->attach_flag = attached;
+  inf->fake_pid_p = fake_pid_p;
 
   return inf;
 }
@@ -1430,7 +1571,13 @@ remote_notice_new_inferior (ptid_t currthread, int running)
         may not know about it yet.  Add it before adding its child
         thread, so notifications are emitted in a sensible order.  */
       if (!in_inferior_list (ptid_get_pid (currthread)))
-       inf = remote_add_inferior (ptid_get_pid (currthread), -1);
+       {
+         struct remote_state *rs = get_remote_state ();
+         int fake_pid_p = !remote_multi_process_p (rs);
+
+         inf = remote_add_inferior (fake_pid_p,
+                                    ptid_get_pid (currthread), -1);
+       }
 
       /* This is really a new thread.  Add it.  */
       remote_add_thread (currthread, running);
@@ -1445,7 +1592,7 @@ remote_notice_new_inferior (ptid_t currthread, int running)
 
 /* Return the private thread data, creating it if necessary.  */
 
-struct private_thread_info *
+static struct private_thread_info *
 demand_private_info (ptid_t ptid)
 {
   struct thread_info *info = find_thread_ptid (ptid);
@@ -1466,8 +1613,7 @@ demand_private_info (ptid_t ptid)
 /* Call this function as a result of
    1) A halt indication (T packet) containing a thread id
    2) A direct query of currthread
-   3) Successful execution of set thread
- */
+   3) Successful execution of set thread */
 
 static void
 record_currthread (ptid_t currthread)
@@ -1481,20 +1627,17 @@ static char *last_pass_packet;
    it can simply pass through to the inferior without reporting.  */
 
 static void
-remote_pass_signals (void)
+remote_pass_signals (int numsigs, unsigned char *pass_signals)
 {
   if (remote_protocol_packets[PACKET_QPassSignals].support != PACKET_DISABLE)
     {
       char *pass_packet, *p;
-      int numsigs = (int) TARGET_SIGNAL_LAST;
       int count = 0, i;
 
       gdb_assert (numsigs < 256);
       for (i = 0; i < numsigs; i++)
        {
-         if (signal_stop_state (i) == 0
-             && signal_print_state (i) == 0
-             && signal_pass_state (i) == 1)
+         if (pass_signals[i])
            count++;
        }
       pass_packet = xmalloc (count * 3 + strlen ("QPassSignals:") + 1);
@@ -1502,9 +1645,7 @@ remote_pass_signals (void)
       p = pass_packet + strlen (pass_packet);
       for (i = 0; i < numsigs; i++)
        {
-         if (signal_stop_state (i) == 0
-             && signal_print_state (i) == 0
-             && signal_pass_state (i) == 1)
+         if (pass_signals[i])
            {
              if (i >= 16)
                *p++ = tohex (i >> 4);
@@ -1534,6 +1675,65 @@ remote_pass_signals (void)
     }
 }
 
+/* The last QProgramSignals packet sent to the target.  We bypass
+   sending a new program signals list down to the target if the new
+   packet is exactly the same as the last we sent.  IOW, we only let
+   the target know about program signals list changes.  */
+
+static char *last_program_signals_packet;
+
+/* If 'QProgramSignals' is supported, tell the remote stub what
+   signals it should pass through to the inferior when detaching.  */
+
+static void
+remote_program_signals (int numsigs, unsigned char *signals)
+{
+  if (remote_protocol_packets[PACKET_QProgramSignals].support != PACKET_DISABLE)
+    {
+      char *packet, *p;
+      int count = 0, i;
+
+      gdb_assert (numsigs < 256);
+      for (i = 0; i < numsigs; i++)
+       {
+         if (signals[i])
+           count++;
+       }
+      packet = xmalloc (count * 3 + strlen ("QProgramSignals:") + 1);
+      strcpy (packet, "QProgramSignals:");
+      p = packet + strlen (packet);
+      for (i = 0; i < numsigs; i++)
+       {
+         if (signal_pass_state (i))
+           {
+             if (i >= 16)
+               *p++ = tohex (i >> 4);
+             *p++ = tohex (i & 15);
+             if (count)
+               *p++ = ';';
+             else
+               break;
+             count--;
+           }
+       }
+      *p = 0;
+      if (!last_program_signals_packet
+         || strcmp (last_program_signals_packet, packet) != 0)
+       {
+         struct remote_state *rs = get_remote_state ();
+         char *buf = rs->buf;
+
+         putpkt (packet);
+         getpkt (&rs->buf, &rs->buf_size, 0);
+         packet_ok (buf, &remote_protocol_packets[PACKET_QProgramSignals]);
+         xfree (last_program_signals_packet);
+         last_program_signals_packet = packet;
+       }
+      else
+       xfree (packet);
+    }
+}
+
 /* If PTID is MAGIC_NULL_PTID, don't set any thread.  If PTID is
    MINUS_ONE_PTID, set the thread to -1, so the stub returns the
    thread.  If GEN is set, set the general thread, if not, then set
@@ -1594,7 +1794,7 @@ set_general_process (void)
   struct remote_state *rs = get_remote_state ();
 
   /* If the remote can't handle multiple processes, don't bother.  */
-  if (!remote_multi_process_p (rs))
+  if (!rs->extended || !remote_multi_process_p (rs))
     return;
 
   /* We only need to change the remote current thread if it's pointing
@@ -1646,12 +1846,11 @@ remote_thread_alive (struct target_ops *ops, ptid_t ptid)
 typedef unsigned char threadref[OPAQUETHREADBYTES];
 
 /* WARNING: This threadref data structure comes from the remote O.S.,
-   libstub protocol encoding, and remote.c. it is not particularly
+   libstub protocol encoding, and remote.c.  It is not particularly
    changable.  */
 
 /* Right now, the internal structure is int. We want it to be bigger.
-   Plan to fix this.
- */
+   Plan to fix this.  */
 
 typedef int gdb_threadref;     /* Internal GDB thread reference.  */
 
@@ -1673,8 +1872,7 @@ struct gdb_ext_thread_info
 /* The volume of remote transfers can be limited by submitting
    a mask containing bits specifying the desired information.
    Use a union of these values as the 'selection' parameter to
-   get_thread_info. FIXME: Make these TAG names more thread specific.
- */
+   get_thread_info.  FIXME: Make these TAG names more thread specific.  */
 
 #define TAG_THREADID 1
 #define TAG_EXISTS 2
@@ -1792,7 +1990,7 @@ read_ptid (char *buf, char **obuf)
       /* Multi-process ptid.  */
       pp = unpack_varlen_hex (p + 1, &pid);
       if (*pp != '.')
-       error (_("invalid remote ptid: %s\n"), p);
+       error (_("invalid remote ptid: %s"), p);
 
       p = pp;
       pp = unpack_varlen_hex (p + 1, &tid);
@@ -2001,7 +2199,7 @@ unpack_threadid (char *inbuf, threadref *id)
 }
 
 /* Externally, threadrefs are 64 bits but internally, they are still
-   ints. This is due to a mismatch of specifications.  We would like
+   ints.  This is due to a mismatch of specifications.  We would like
    to use 64bit thread references internally.  This is an adapter
    function.  */
 
@@ -2266,7 +2464,8 @@ remote_get_threadlist (int startflag, threadref *nextthread, int result_limit,
   int result = 1;
 
   /* Trancate result limit to be smaller than the packet size.  */
-  if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10) >= get_remote_packet_size ())
+  if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10)
+      >= get_remote_packet_size ())
     result_limit = (get_remote_packet_size () / BUF_THREAD_ID_SIZE) - 2;
 
   pack_threadlist_request (rs->buf, startflag, result_limit, nextthread);
@@ -2274,7 +2473,7 @@ remote_get_threadlist (int startflag, threadref *nextthread, int result_limit,
   getpkt (&rs->buf, &rs->buf_size, 0);
 
   if (*rs->buf == '\0')
-    *result_count = 0;
+    return 0;
   else
     *result_count =
       parse_threadlist_response (rs->buf + 2, result_limit, &echo_nextthread,
@@ -2425,12 +2624,14 @@ start_thread (struct gdb_xml_parser *parser,
 
   struct thread_item item;
   char *id;
+  struct gdb_xml_value *attr;
 
-  id = VEC_index (gdb_xml_value_s, attributes, 0)->value;
+  id = xml_find_attribute (attributes, "id")->value;
   item.ptid = read_ptid (id, NULL);
 
-  if (VEC_length (gdb_xml_value_s, attributes) > 1)
-    item.core = *(ULONGEST *) VEC_index (gdb_xml_value_s, attributes, 1)->value;
+  attr = xml_find_attribute (attributes, "core");
+  if (attr != NULL)
+    item.core = *(ULONGEST *) attr->value;
   else
     item.core = -1;
 
@@ -2473,6 +2674,21 @@ const struct gdb_xml_element threads_elements[] = {
   { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
 };
 
+/* Discard the contents of the constructed thread info context.  */
+
+static void
+clear_threads_parsing_context (void *p)
+{
+  struct threads_parsing_context *context = p;
+  int i;
+  struct thread_item *item;
+
+  for (i = 0; VEC_iterate (thread_item_t, context->items, i, item); ++i)
+    xfree (item->extra);
+
+  VEC_free (thread_item_t, context->items);
+}
+
 #endif
 
 /*
@@ -2499,25 +2715,23 @@ remote_threads_info (struct target_ops *ops)
                                         TARGET_OBJECT_THREADS, NULL);
 
       struct cleanup *back_to = make_cleanup (xfree, xml);
+
       if (xml && *xml)
        {
-         struct gdb_xml_parser *parser;
          struct threads_parsing_context context;
-         struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
-
-         context.items = 0;
-         parser = gdb_xml_create_parser_and_cleanup (_("threads"),
-                                                     threads_elements,
-                                                     &context);
 
-         gdb_xml_use_dtd (parser, "threads.dtd");
+         context.items = NULL;
+         make_cleanup (clear_threads_parsing_context, &context);
 
-         if (gdb_xml_parse (parser, xml) == 0)
+         if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
+                                  threads_elements, xml, &context) == 0)
            {
              int i;
              struct thread_item *item;
 
-             for (i = 0; VEC_iterate (thread_item_t, context.items, i, item); ++i)
+             for (i = 0;
+                  VEC_iterate (thread_item_t, context.items, i, item);
+                  ++i)
                {
                  if (!ptid_equal (item->ptid, null_ptid))
                    {
@@ -2533,13 +2747,10 @@ remote_threads_info (struct target_ops *ops)
                      info = demand_private_info (item->ptid);
                      info->core = item->core;
                      info->extra = item->extra;
-                     item->extra = 0;
+                     item->extra = NULL;
                    }
-                 xfree (item->extra);
                }
            }
-
-         VEC_free (thread_item_t, context.items);
        }
 
       do_cleanups (back_to);
@@ -2622,6 +2833,7 @@ remote_threads_extra_info (struct thread_info *tp)
   if (remote_protocol_packets[PACKET_qXfer_threads].support == PACKET_ENABLE)
     {
       struct thread_info *info = find_thread_ptid (tp->ptid);
+
       if (info && info->private)
        return info->private->extra;
       else
@@ -2678,6 +2890,84 @@ remote_threads_extra_info (struct thread_info *tp)
 }
 \f
 
+static int
+remote_static_tracepoint_marker_at (CORE_ADDR addr,
+                                   struct static_tracepoint_marker *marker)
+{
+  struct remote_state *rs = get_remote_state ();
+  char *p = rs->buf;
+
+  xsnprintf (p, get_remote_packet_size (), "qTSTMat:");
+  p += strlen (p);
+  p += hexnumstr (p, addr);
+  putpkt (rs->buf);
+  getpkt (&rs->buf, &rs->buf_size, 0);
+  p = rs->buf;
+
+  if (*p == 'E')
+    error (_("Remote failure reply: %s"), p);
+
+  if (*p++ == 'm')
+    {
+      parse_static_tracepoint_marker_definition (p, &p, marker);
+      return 1;
+    }
+
+  return 0;
+}
+
+static VEC(static_tracepoint_marker_p) *
+remote_static_tracepoint_markers_by_strid (const char *strid)
+{
+  struct remote_state *rs = get_remote_state ();
+  VEC(static_tracepoint_marker_p) *markers = NULL;
+  struct static_tracepoint_marker *marker = NULL;
+  struct cleanup *old_chain;
+  char *p;
+
+  /* Ask for a first packet of static tracepoint marker
+     definition.  */
+  putpkt ("qTfSTM");
+  getpkt (&rs->buf, &rs->buf_size, 0);
+  p = rs->buf;
+  if (*p == 'E')
+    error (_("Remote failure reply: %s"), p);
+
+  old_chain = make_cleanup (free_current_marker, &marker);
+
+  while (*p++ == 'm')
+    {
+      if (marker == NULL)
+       marker = XCNEW (struct static_tracepoint_marker);
+
+      do
+       {
+         parse_static_tracepoint_marker_definition (p, &p, marker);
+
+         if (strid == NULL || strcmp (strid, marker->str_id) == 0)
+           {
+             VEC_safe_push (static_tracepoint_marker_p,
+                            markers, marker);
+             marker = NULL;
+           }
+         else
+           {
+             release_static_tracepoint_marker (marker);
+             memset (marker, 0, sizeof (*marker));
+           }
+       }
+      while (*p++ == ',');     /* comma-separated list */
+      /* Ask for another packet of static tracepoint definition.  */
+      putpkt ("qTsSTM");
+      getpkt (&rs->buf, &rs->buf_size, 0);
+      p = rs->buf;
+    }
+
+  do_cleanups (old_chain);
+  return markers;
+}
+
+\f
 /* Implement the to_get_ada_task_ptid function for the remote targets.  */
 
 static ptid_t
@@ -2718,7 +3008,10 @@ remote_close (int quitting)
   remote_desc = NULL;
 
   /* We don't have a connection to the remote stub anymore.  Get rid
-     of all the inferiors and their threads we were controlling.  */
+     of all the inferiors and their threads we were controlling.
+     Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
+     will be unable to find the thread corresponding to (pid, 0, 0).  */
+  inferior_ptid = null_ptid;
   discard_all_inferiors ();
 
   /* We're no longer interested in any of these events.  */
@@ -2863,7 +3156,8 @@ get_offsets (void)
                                                 offs, num_segments, segments);
 
       if (ret == 0 && !do_sections)
-       error (_("Can not handle qOffsets TextSeg response with this symbol file"));
+       error (_("Can not handle qOffsets TextSeg "
+                "response with this symbol file"));
 
       if (ret > 0)
        do_sections = 0;
@@ -2876,9 +3170,10 @@ get_offsets (void)
     {
       offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_addr;
 
-      /* This is a temporary kludge to force data and bss to use the same offsets
-        because that's what nlmconv does now.  The real solution requires changes
-        to the stub and remote.c that I don't have time to do right now.  */
+      /* This is a temporary kludge to force data and bss to use the
+        same offsets because that's what nlmconv does now.  The real
+        solution requires changes to the stub and remote.c that I
+        don't have time to do right now.  */
 
       offs->offsets[SECT_OFF_DATA (symfile_objfile)] = data_addr;
       offs->offsets[SECT_OFF_BSS (symfile_objfile)] = data_addr;
@@ -2902,22 +3197,9 @@ set_stop_requested_callback (struct thread_info *thread, void *data)
   return 0;
 }
 
-/* Stub for catch_exception.  */
-
-struct start_remote_args
-{
-  int from_tty;
-
-  /* The current target.  */
-  struct target_ops *target;
-
-  /* Non-zero if this is an extended-remote target.  */
-  int extended_p;
-};
-
 /* Send interrupt_sequence to remote target.  */
 static void
-send_interrupt_sequence ()
+send_interrupt_sequence (void)
 {
   if (interrupt_sequence_mode == interrupt_sequence_control_c)
     serial_write (remote_desc, "\x03", 1);
@@ -2934,27 +3216,73 @@ send_interrupt_sequence ()
                    interrupt_sequence_mode);
 }
 
+/* Query the remote target for which is the current thread/process,
+   add it to our tables, and update INFERIOR_PTID.  The caller is
+   responsible for setting the state such that the remote end is ready
+   to return the current thread.  */
+
+static void
+add_current_inferior_and_thread (void)
+{
+  struct remote_state *rs = get_remote_state ();
+  int fake_pid_p = 0;
+  ptid_t ptid;
+
+  inferior_ptid = null_ptid;
+
+  /* Now, if we have thread information, update inferior_ptid.  */
+  ptid = remote_current_thread (inferior_ptid);
+  if (!ptid_equal (ptid, null_ptid))
+    {
+      if (!remote_multi_process_p (rs))
+       fake_pid_p = 1;
+
+      inferior_ptid = ptid;
+    }
+  else
+    {
+      /* Without this, some commands which require an active target
+        (such as kill) won't work.  This variable serves (at least)
+        double duty as both the pid of the target process (if it has
+        such), and as a flag indicating that a target is active.  */
+      inferior_ptid = magic_null_ptid;
+      fake_pid_p = 1;
+    }
+
+  remote_add_inferior (fake_pid_p, ptid_get_pid (inferior_ptid), -1);
+
+  /* Add the main thread.  */
+  add_thread_silent (inferior_ptid);
+}
+
 static void
-remote_start_remote (struct ui_out *uiout, void *opaque)
+remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
 {
-  struct start_remote_args *args = opaque;
   struct remote_state *rs = get_remote_state ();
   struct packet_config *noack_config;
   char *wait_status = NULL;
 
   immediate_quit++;            /* Allow user to interrupt it.  */
 
+  if (interrupt_on_connect)
+    send_interrupt_sequence ();
+
   /* Ack any packet which the remote side has already sent.  */
   serial_write (remote_desc, "+", 1);
 
-  if (interrupt_on_connect)
-    send_interrupt_sequence ();
+  /* Signal other parts that we're going through the initial setup,
+     and so things may not be stable yet.  */
+  rs->starting_up = 1;
 
   /* The first packet we send to the target is the optional "supported
      packets" request.  If the target can answer this, it will tell us
      which later probes to skip.  */
   remote_query_supported ();
 
+  /* If the stub wants to get a QAllow, compose one and send it.  */
+  if (remote_protocol_packets[PACKET_QAllow].support != PACKET_DISABLE)
+    remote_set_permissions ();
+
   /* Next, we possibly activate noack mode.
 
      If the QStartNoAckMode packet configuration is set to AUTO,
@@ -2980,13 +3308,17 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
        rs->noack_mode = 1;
     }
 
-  if (args->extended_p)
+  if (extended_p)
     {
       /* Tell the remote that we are using the extended protocol.  */
       putpkt ("!");
       getpkt (&rs->buf, &rs->buf_size, 0);
     }
 
+  /* Let the target know which signals it is allowed to pass down to
+     the program.  */
+  update_signals_program_target ();
+
   /* Next, if the target can specify a description, read it.  We do
      this before anything involving memory or registers.  */
   target_find_description ();
@@ -2998,24 +3330,25 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
   /* On OSs where the list of libraries is global to all
      processes, we fetch them early.  */
   if (gdbarch_has_global_solist (target_gdbarch))
-    solib_add (NULL, args->from_tty, args->target, auto_solib_add);
+    solib_add (NULL, from_tty, target, auto_solib_add);
 
   if (non_stop)
     {
       if (!rs->non_stop_aware)
-       error (_("Non-stop mode requested, but remote does not support non-stop"));
+       error (_("Non-stop mode requested, but remote "
+                "does not support non-stop"));
 
       putpkt ("QNonStop:1");
       getpkt (&rs->buf, &rs->buf_size, 0);
 
       if (strcmp (rs->buf, "OK") != 0)
-       error ("Remote refused setting non-stop mode with: %s", rs->buf);
+       error (_("Remote refused setting non-stop mode with: %s"), rs->buf);
 
       /* Find about threads and processes the stub is already
         controlling.  We default to adding them in the running state.
         The '?' query below will then tell us about which threads are
         stopped.  */
-      remote_threads_info (args->target);
+      remote_threads_info (target);
     }
   else if (rs->non_stop_aware)
     {
@@ -3025,7 +3358,7 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
       getpkt (&rs->buf, &rs->buf_size, 0);
 
       if (strcmp (rs->buf, "OK") != 0)
-       error ("Remote refused setting all-stop mode with: %s", rs->buf);
+       error (_("Remote refused setting all-stop mode with: %s"), rs->buf);
     }
 
   /* Check whether the target is running now.  */
@@ -3034,13 +3367,18 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
 
   if (!non_stop)
     {
+      ptid_t ptid;
+      int fake_pid_p = 0;
+      struct inferior *inf;
+
       if (rs->buf[0] == 'W' || rs->buf[0] == 'X')
        {
-         if (!args->extended_p)
+         if (!extended_p)
            error (_("The target is not running (try extended-remote?)"));
 
          /* We're connected, but not running.  Drop out before we
             call start_remote.  */
+         rs->starting_up = 0;
          return;
        }
       else
@@ -3053,22 +3391,18 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
       /* Let the stub know that we want it to return the thread.  */
       set_continue_thread (minus_one_ptid);
 
-      /* Without this, some commands which require an active target
-        (such as kill) won't work.  This variable serves (at least)
-        double duty as both the pid of the target process (if it has
-        such), and as a flag indicating that a target is active.
-        These functions should be split out into seperate variables,
-        especially since GDB will someday have a notion of debugging
-        several processes.  */
-      inferior_ptid = magic_null_ptid;
-
-      /* Now, if we have thread information, update inferior_ptid.  */
-      inferior_ptid = remote_current_thread (inferior_ptid);
-
-      remote_add_inferior (ptid_get_pid (inferior_ptid), -1);
-
-      /* Always add the main thread.  */
-      add_thread_silent (inferior_ptid);
+      add_current_inferior_and_thread ();
+
+      /* init_wait_for_inferior should be called before get_offsets in order
+        to manage `inserted' flag in bp loc in a correct state.
+        breakpoint_init_inferior, called from init_wait_for_inferior, set
+        `inserted' flag to 0, while before breakpoint_re_set, called from
+        start_remote, set `inserted' flag to 1.  In the initialization of
+        inferior, breakpoint_init_inferior should be called first, and then
+        breakpoint_re_set can be called.  If this order is broken, state of
+        `inserted' flag is wrong, and cause some problems on breakpoint
+        manipulation.  */
+      init_wait_for_inferior ();
 
       get_offsets ();          /* Get text, data & bss offsets.  */
 
@@ -3076,7 +3410,7 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
         how to do it some other way, try again.  This is not
         supported for non-stop; it could be, but it is tricky if
         there are no stopped threads when we connect.  */
-      if (remote_read_description_p (args->target)
+      if (remote_read_description_p (target)
          && gdbarch_target_desc (target_gdbarch) == NULL)
        {
          target_clear_description ();
@@ -3089,7 +3423,7 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
       rs->cached_wait_status = 1;
 
       immediate_quit--;
-      start_remote (args->from_tty); /* Initialize gdb process mechanisms.  */
+      start_remote (from_tty); /* Initialize gdb process mechanisms.  */
     }
   else
     {
@@ -3131,11 +3465,12 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
 
       if (thread_count () == 0)
        {
-         if (!args->extended_p)
+         if (!extended_p)
            error (_("The target is not running (try extended-remote?)"));
 
          /* We're connected, but not running.  Drop out before we
             call start_remote.  */
+         rs->starting_up = 0;
          return;
        }
 
@@ -3154,6 +3489,9 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
       /* In non-stop mode, any cached wait status will be stored in
         the stop reply queue.  */
       gdb_assert (wait_status == NULL);
+
+      /* Report all signals during attach/startup.  */
+      remote_pass_signals (0, NULL);
     }
 
   /* If we connected to a live target, do some additional setup.  */
@@ -3185,6 +3523,12 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
       merge_uploaded_tracepoints (&uploaded_tps);
     }
 
+  /* The thread and inferior lists are now synchronized with the
+     target, our symbols have been relocated, and we're merged the
+     target's tracepoints with ours.  We're done with basic start
+     up.  */
+  rs->starting_up = 0;
+
   /* If breakpoints are global, insert them now.  */
   if (gdbarch_has_global_breakpoints (target_gdbarch)
       && breakpoints_always_inserted_mode ())
@@ -3215,6 +3559,7 @@ static void
 init_all_packet_configs (void)
 {
   int i;
+
   for (i = 0; i < PACKET_MAX; i++)
     update_packet_config (&remote_protocol_packets[i]);
 }
@@ -3229,10 +3574,19 @@ remote_check_symbols (struct objfile *objfile)
   struct minimal_symbol *sym;
   int end;
 
+  /* The remote side has no concept of inferiors that aren't running
+     yet, it only knows about running processes.  If we're connected
+     but our current inferior is not running, we should not invite the
+     remote target to request symbol lookups related to its
+     (unrelated) current process.  */
+  if (!target_has_execution)
+    return;
+
   if (remote_protocol_packets[PACKET_qSymbol].support == PACKET_DISABLE)
     return;
 
-  /* Make sure the remote is pointing at the right process.  */
+  /* Make sure the remote is pointing at the right process.  Note
+     there's no way to select "no process".  */
   set_general_process ();
 
   /* Allocate a message buffer.  We can't reuse the input buffer in RS,
@@ -3286,15 +3640,45 @@ remote_serial_open (char *name)
      to be.  */
   if (!udp_warning && strncmp (name, "udp:", 4) == 0)
     {
-      warning (_("\
-The remote protocol may be unreliable over UDP.\n\
-Some events may be lost, rendering further debugging impossible."));
+      warning (_("The remote protocol may be unreliable over UDP.\n"
+                "Some events may be lost, rendering further debugging "
+                "impossible."));
       udp_warning = 1;
     }
 
   return serial_open (name);
 }
 
+/* Inform the target of our permission settings.  The permission flags
+   work without this, but if the target knows the settings, it can do
+   a couple things.  First, it can add its own check, to catch cases
+   that somehow manage to get by the permissions checks in target
+   methods.  Second, if the target is wired to disallow particular
+   settings (for instance, a system in the field that is not set up to
+   be able to stop at a breakpoint), it can object to any unavailable
+   permissions.  */
+
+void
+remote_set_permissions (void)
+{
+  struct remote_state *rs = get_remote_state ();
+
+  xsnprintf (rs->buf, get_remote_packet_size (), "QAllow:"
+            "WriteReg:%x;WriteMem:%x;"
+            "InsertBreak:%x;InsertTrace:%x;"
+            "InsertFastTrace:%x;Stop:%x",
+            may_write_registers, may_write_memory,
+            may_insert_breakpoints, may_insert_tracepoints,
+            may_insert_fast_tracepoints, may_stop);
+  putpkt (rs->buf);
+  getpkt (&rs->buf, &rs->buf_size, 0);
+
+  /* If the target didn't like the packet, warn the user.  Do not try
+     to undo the user's settings, that would just be maddening.  */
+  if (strcmp (rs->buf, "OK") != 0)
+    warning (_("Remote refused setting permissions with: %s"), rs->buf);
+}
+
 /* This type describes each known response to the qSupported
    packet.  */
 struct protocol_feature
@@ -3383,6 +3767,7 @@ remote_multi_process_feature (const struct protocol_feature *feature,
                              enum packet_support support, const char *value)
 {
   struct remote_state *rs = get_remote_state ();
+
   rs->multi_process_aware = (support == PACKET_ENABLE);
 }
 
@@ -3391,6 +3776,7 @@ remote_non_stop_feature (const struct protocol_feature *feature,
                              enum packet_support support, const char *value)
 {
   struct remote_state *rs = get_remote_state ();
+
   rs->non_stop_aware = (support == PACKET_ENABLE);
 }
 
@@ -3400,27 +3786,80 @@ remote_cond_tracepoint_feature (const struct protocol_feature *feature,
                                       const char *value)
 {
   struct remote_state *rs = get_remote_state ();
+
   rs->cond_tracepoints = (support == PACKET_ENABLE);
 }
 
+static void
+remote_cond_breakpoint_feature (const struct protocol_feature *feature,
+                               enum packet_support support,
+                               const char *value)
+{
+  struct remote_state *rs = get_remote_state ();
+
+  rs->cond_breakpoints = (support == PACKET_ENABLE);
+}
+
 static void
 remote_fast_tracepoint_feature (const struct protocol_feature *feature,
                                enum packet_support support,
                                const char *value)
 {
   struct remote_state *rs = get_remote_state ();
+
   rs->fast_tracepoints = (support == PACKET_ENABLE);
 }
 
+static void
+remote_static_tracepoint_feature (const struct protocol_feature *feature,
+                                 enum packet_support support,
+                                 const char *value)
+{
+  struct remote_state *rs = get_remote_state ();
+
+  rs->static_tracepoints = (support == PACKET_ENABLE);
+}
+
+static void
+remote_install_in_trace_feature (const struct protocol_feature *feature,
+                                enum packet_support support,
+                                const char *value)
+{
+  struct remote_state *rs = get_remote_state ();
+
+  rs->install_in_trace = (support == PACKET_ENABLE);
+}
+
 static void
 remote_disconnected_tracing_feature (const struct protocol_feature *feature,
                                     enum packet_support support,
                                     const char *value)
 {
   struct remote_state *rs = get_remote_state ();
+
   rs->disconnected_tracing = (support == PACKET_ENABLE);
 }
 
+static void
+remote_enable_disable_tracepoint_feature (const struct protocol_feature *feature,
+                                         enum packet_support support,
+                                         const char *value)
+{
+  struct remote_state *rs = get_remote_state ();
+
+  rs->enable_disable_tracepoints = (support == PACKET_ENABLE);
+}
+
+static void
+remote_string_tracing_feature (const struct protocol_feature *feature,
+                              enum packet_support support,
+                              const char *value)
+{
+  struct remote_state *rs = get_remote_state ();
+
+  rs->string_tracing = (support == PACKET_ENABLE);
+}
+
 static struct protocol_feature remote_protocol_features[] = {
   { "PacketSize", PACKET_DISABLE, remote_packet_size, -1 },
   { "qXfer:auxv:read", PACKET_DISABLE, remote_supported_packet,
@@ -3429,6 +3868,8 @@ static struct protocol_feature remote_protocol_features[] = {
     PACKET_qXfer_features },
   { "qXfer:libraries:read", PACKET_DISABLE, remote_supported_packet,
     PACKET_qXfer_libraries },
+  { "qXfer:libraries-svr4:read", PACKET_DISABLE, remote_supported_packet,
+    PACKET_qXfer_libraries_svr4 },
   { "qXfer:memory-map:read", PACKET_DISABLE, remote_supported_packet,
     PACKET_qXfer_memory_map },
   { "qXfer:spu:read", PACKET_DISABLE, remote_supported_packet,
@@ -3439,8 +3880,12 @@ static struct protocol_feature remote_protocol_features[] = {
     PACKET_qXfer_osdata },
   { "qXfer:threads:read", PACKET_DISABLE, remote_supported_packet,
     PACKET_qXfer_threads },
+  { "qXfer:traceframe-info:read", PACKET_DISABLE, remote_supported_packet,
+    PACKET_qXfer_traceframe_info },
   { "QPassSignals", PACKET_DISABLE, remote_supported_packet,
     PACKET_QPassSignals },
+  { "QProgramSignals", PACKET_DISABLE, remote_supported_packet,
+    PACKET_QProgramSignals },
   { "QStartNoAckMode", PACKET_DISABLE, remote_supported_packet,
     PACKET_QStartNoAckMode },
   { "multiprocess", PACKET_DISABLE, remote_multi_process_feature, -1 },
@@ -3451,8 +3896,14 @@ static struct protocol_feature remote_protocol_features[] = {
     PACKET_qXfer_siginfo_write },
   { "ConditionalTracepoints", PACKET_DISABLE, remote_cond_tracepoint_feature,
     PACKET_ConditionalTracepoints },
+  { "ConditionalBreakpoints", PACKET_DISABLE, remote_cond_breakpoint_feature,
+    PACKET_ConditionalBreakpoints },
   { "FastTracepoints", PACKET_DISABLE, remote_fast_tracepoint_feature,
     PACKET_FastTracepoints },
+  { "StaticTracepoints", PACKET_DISABLE, remote_static_tracepoint_feature,
+    PACKET_StaticTracepoints },
+  {"InstallInTrace", PACKET_DISABLE, remote_install_in_trace_feature,
+   PACKET_InstallInTrace},
   { "DisconnectedTracing", PACKET_DISABLE, remote_disconnected_tracing_feature,
     -1 },
   { "ReverseContinue", PACKET_DISABLE, remote_supported_packet,
@@ -3461,6 +3912,19 @@ static struct protocol_feature remote_protocol_features[] = {
     PACKET_bs },
   { "TracepointSource", PACKET_DISABLE, remote_supported_packet,
     PACKET_TracepointSource },
+  { "QAllow", PACKET_DISABLE, remote_supported_packet,
+    PACKET_QAllow },
+  { "EnableDisableTracepoints", PACKET_DISABLE,
+    remote_enable_disable_tracepoint_feature, -1 },
+  { "qXfer:fdpic:read", PACKET_DISABLE, remote_supported_packet,
+    PACKET_qXfer_fdpic },
+  { "qXfer:uib:read", PACKET_DISABLE, remote_supported_packet,
+    PACKET_qXfer_uib },
+  { "QDisableRandomization", PACKET_DISABLE, remote_supported_packet,
+    PACKET_QDisableRandomization },
+  { "QAgent", PACKET_DISABLE, remote_supported_packet, PACKET_QAgent},
+  { "tracenz", PACKET_DISABLE,
+    remote_string_tracing_feature, -1 },
 };
 
 static char *remote_support_xml;
@@ -3468,11 +3932,11 @@ static char *remote_support_xml;
 /* Register string appended to "xmlRegisters=" in qSupported query.  */
 
 void
-register_remote_support_xml (const char *xml ATTRIBUTE_UNUSED)
+register_remote_support_xml (const char *xml)
 {
 #if defined(HAVE_LIBEXPAT)
   if (remote_support_xml == NULL)
-    remote_support_xml = concat ("xmlRegisters=", xml, NULL);
+    remote_support_xml = concat ("xmlRegisters=", xml, (char *) NULL);
   else
     {
       char *copy = xstrdup (remote_support_xml + 13);
@@ -3490,9 +3954,9 @@ register_remote_support_xml (const char *xml ATTRIBUTE_UNUSED)
       while ((p = strtok (NULL, ",")) != NULL);
       xfree (copy);
 
-      p = concat (remote_support_xml, ",", xml, NULL);
-      xfree (remote_support_xml);
-      remote_support_xml = p;
+      remote_support_xml = reconcat (remote_support_xml,
+                                    remote_support_xml, ",", xml,
+                                    (char *) NULL);
     }
 #endif
 }
@@ -3501,11 +3965,7 @@ static char *
 remote_query_supported_append (char *msg, const char *append)
 {
   if (msg)
-    {
-      char *p = concat (msg, ";", append, NULL);
-      xfree (msg);
-      return p;
-    }
+    return reconcat (msg, msg, ";", append, (char *) NULL);
   else
     return xstrdup (append);
 }
@@ -3529,26 +3989,19 @@ remote_query_supported (void)
   if (remote_protocol_packets[PACKET_qSupported].support != PACKET_DISABLE)
     {
       char *q = NULL;
-      const char *qsupported = gdbarch_qsupported (target_gdbarch);
+      struct cleanup *old_chain = make_cleanup (free_current_contents, &q);
 
-      if (rs->extended)
-       q = remote_query_supported_append (q, "multiprocess+");
-      
-      if (qsupported)
-       q = remote_query_supported_append (q, qsupported);
+      q = remote_query_supported_append (q, "multiprocess+");
 
       if (remote_support_xml)
        q = remote_query_supported_append (q, remote_support_xml);
 
-      if (q)
-       {
-         char *p = concat ("qSupported:", q, NULL);
-         xfree (q);
-         putpkt (p);
-         xfree (p);
-       }
-      else
-       putpkt ("qSupported");
+      q = remote_query_supported_append (q, "qRelocInsn+");
+
+      q = reconcat (q, "qSupported:", q, (char *) NULL);
+      putpkt (q);
+
+      do_cleanups (old_chain);
 
       getpkt (&rs->buf, &rs->buf_size, 0);
 
@@ -3618,7 +4071,8 @@ remote_query_supported (void)
              break;
 
            default:
-             warning (_("unrecognized item \"%s\" in \"qSupported\" response"), p);
+             warning (_("unrecognized item \"%s\" "
+                        "in \"qSupported\" response"), p);
              continue;
            }
          end[-1] = '\0';
@@ -3659,7 +4113,8 @@ remote_query_supported (void)
 
 
 static void
-remote_open_1 (char *name, int from_tty, struct target_ops *target, int extended_p)
+remote_open_1 (char *name, int from_tty,
+              struct target_ops *target, int extended_p)
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -3701,6 +4156,11 @@ remote_open_1 (char *name, int from_tty, struct target_ops *target, int extended
   xfree (last_pass_packet);
   last_pass_packet = NULL;
 
+  /* Make sure we send the program signals list the next time we
+     resume.  */
+  xfree (last_program_signals_packet);
+  last_program_signals_packet = NULL;
+
   remote_fileio_reset ();
   reopen_exec_file ();
   reread_symbols ();
@@ -3759,6 +4219,7 @@ remote_open_1 (char *name, int from_tty, struct target_ops *target, int extended
 
   general_thread = not_sent_ptid;
   continue_thread = not_sent_ptid;
+  remote_traceframe_number = -1;
 
   /* Probe for ability to use "ThreadInfo" query, as required.  */
   use_threadinfo_query = 1;
@@ -3771,9 +4232,9 @@ remote_open_1 (char *name, int from_tty, struct target_ops *target, int extended
 
       /* FIXME: cagney/1999-09-23: During the initial connection it is
         assumed that the target is already ready and able to respond to
-        requests. Unfortunately remote_start_remote() eventually calls
+        requests.  Unfortunately remote_start_remote() eventually calls
         wait_for_inferior() with no timeout.  wait_forever_enabled_p gets
-        around this. Eventually a mechanism that allows
+        around this.  Eventually a mechanism that allows
         wait_for_inferior() to expect/get timeouts will be
         implemented.  */
       wait_forever_enabled_p = 0;
@@ -3801,14 +4262,12 @@ remote_open_1 (char *name, int from_tty, struct target_ops *target, int extended
      all the ``target ....'' commands to share a common callback
      function.  See cli-dump.c.  */
   {
-    struct gdb_exception ex;
-    struct start_remote_args args;
-
-    args.from_tty = from_tty;
-    args.target = target;
-    args.extended_p = extended_p;
+    volatile struct gdb_exception ex;
 
-    ex = catch_exception (uiout, remote_start_remote, &args, RETURN_MASK_ALL);
+    TRY_CATCH (ex, RETURN_MASK_ALL)
+      {
+       remote_start_remote (from_tty, target, extended_p);
+      }
     if (ex.reason < 0)
       {
        /* Pop the partially set up target - unless something else did
@@ -3842,9 +4301,19 @@ remote_detach_1 (char *args, int from_tty, int extended)
   if (!target_has_execution)
     error (_("No process to detach from."));
 
+  if (from_tty)
+    {
+      char *exec_file = get_exec_file (0);
+      if (exec_file == NULL)
+       exec_file = "";
+      printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file,
+                        target_pid_to_str (pid_to_ptid (pid)));
+      gdb_flush (gdb_stdout);
+    }
+
   /* Tell the remote target to detach.  */
   if (remote_multi_process_p (rs))
-    sprintf (rs->buf, "D;%x", pid);
+    xsnprintf (rs->buf, get_remote_packet_size (), "D;%x", pid);
   else
     strcpy (rs->buf, "D");
 
@@ -3858,19 +4327,8 @@ remote_detach_1 (char *args, int from_tty, int extended)
   else
     error (_("Can't detach process."));
 
-  if (from_tty)
-    {
-      if (remote_multi_process_p (rs))
-       printf_filtered (_("Detached from remote %s.\n"),
-                        target_pid_to_str (pid_to_ptid (pid)));
-      else
-       {
-         if (extended)
-           puts_filtered (_("Detached from remote process.\n"));
-         else
-           puts_filtered (_("Ending remote debugging.\n"));
-       }
-    }
+  if (from_tty && !extended)
+    puts_filtered (_("Ending remote debugging.\n"));
 
   discard_pending_stop_replies (pid);
   target_mourn_inferior ();
@@ -3923,16 +4381,27 @@ extended_remote_attach_1 (struct target_ops *target, char *args, int from_tty)
   if (remote_protocol_packets[PACKET_vAttach].support == PACKET_DISABLE)
     error (_("This target does not support attaching to a process"));
 
-  sprintf (rs->buf, "vAttach;%x", pid);
+  if (from_tty)
+    {
+      char *exec_file = get_exec_file (0);
+
+      if (exec_file)
+       printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
+                          target_pid_to_str (pid_to_ptid (pid)));
+      else
+       printf_unfiltered (_("Attaching to %s\n"),
+                          target_pid_to_str (pid_to_ptid (pid)));
+
+      gdb_flush (gdb_stdout);
+    }
+
+  xsnprintf (rs->buf, get_remote_packet_size (), "vAttach;%x", pid);
   putpkt (rs->buf);
   getpkt (&rs->buf, &rs->buf_size, 0);
 
-  if (packet_ok (rs->buf, &remote_protocol_packets[PACKET_vAttach]) == PACKET_OK)
+  if (packet_ok (rs->buf,
+                &remote_protocol_packets[PACKET_vAttach]) == PACKET_OK)
     {
-      if (from_tty)
-       printf_unfiltered (_("Attached to %s\n"),
-                          target_pid_to_str (pid_to_ptid (pid)));
-
       if (!non_stop)
        {
          /* Save the reply for later.  */
@@ -3950,7 +4419,7 @@ extended_remote_attach_1 (struct target_ops *target, char *args, int from_tty)
     error (_("Attaching to %s failed"),
           target_pid_to_str (pid_to_ptid (pid)));
 
-  set_current_inferior (remote_add_inferior (pid, 1));
+  set_current_inferior (remote_add_inferior (0, pid, 1));
 
   inferior_ptid = pid_to_ptid (pid);
 
@@ -4067,6 +4536,7 @@ int
 bin2hex (const gdb_byte *bin, char *hex, int count)
 {
   int i;
+
   /* May use a length, or a nul-terminated string as input.  */
   if (count == 0)
     count = strlen ((char *) bin);
@@ -4212,7 +4682,7 @@ remote_vcont_resume (ptid_t ptid, int step, enum target_signal siggnal)
         so we don't have any TID numbers the inferior will
         understand.  Make sure to only send forms that do not specify
         a TID.  */
-      p = append_resumption (p, endp, minus_one_ptid, step, siggnal);
+      append_resumption (p, endp, minus_one_ptid, step, siggnal);
     }
   else if (ptid_equal (ptid, minus_one_ptid) || ptid_is_pid (ptid))
     {
@@ -4227,12 +4697,12 @@ remote_vcont_resume (ptid_t ptid, int step, enum target_signal siggnal)
        }
 
       /* And continue others without a signal.  */
-      p = append_resumption (p, endp, ptid, /*step=*/ 0, TARGET_SIGNAL_0);
+      append_resumption (p, endp, ptid, /*step=*/ 0, TARGET_SIGNAL_0);
     }
   else
     {
       /* Scheduler locking; resume only PTID.  */
-      p = append_resumption (p, endp, ptid, step, siggnal);
+      append_resumption (p, endp, ptid, step, siggnal);
     }
 
   gdb_assert (strlen (rs->buf) < get_remote_packet_size ());
@@ -4267,9 +4737,6 @@ remote_resume (struct target_ops *ops,
   last_sent_signal = siggnal;
   last_sent_step = step;
 
-  /* Update the inferior on signals to silently pass, if they've changed.  */
-  remote_pass_signals ();
-
   /* The vCont packet doesn't need to specify threads via Hc.  */
   /* No reverse support (yet) for vCont.  */
   if (execution_direction != EXEC_REVERSE)
@@ -4288,7 +4755,7 @@ remote_resume (struct target_ops *ops,
     {
       /* We don't pass signals to the target in reverse exec mode.  */
       if (info_verbose && siggnal != TARGET_SIGNAL_0)
-       warning (" - Can't pass signal %d to target in reverse: ignored.\n",
+       warning (_(" - Can't pass signal %d to target in reverse: ignored."),
                 siggnal);
 
       if (step 
@@ -4314,8 +4781,8 @@ remote_resume (struct target_ops *ops,
 
  done:
   /* We are about to start executing the inferior, let's register it
-     with the event loop. NOTE: this is the one place where all the
-     execution commands end up. We could alternatively do this in each
+     with the event loop.  NOTE: this is the one place where all the
+     execution commands end up.  We could alternatively do this in each
      of the execution commands in infcmd.c.  */
   /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
      into infcmd.c in order to allow inferior function calls to work
@@ -4372,7 +4839,7 @@ async_remote_interrupt (gdb_client_data arg)
   target_stop (inferior_ptid);
 }
 
-/* Perform interrupt, if the first attempt did not succeed. Just give
+/* Perform interrupt, if the first attempt did not succeed.  Just give
    up on the target alltogether.  */
 void
 async_remote_interrupt_twice (gdb_client_data arg)
@@ -4395,9 +4862,9 @@ cleanup_sigint_signal_handler (void *dummy)
    packet.  */
 static void (*ofunc) (int);
 
-/* The command line interface's stop routine. This function is installed
-   as a signal handler for SIGINT. The first time a user requests a
-   stop, we call remote_stop to send a break or ^C. If there is no
+/* The command line interface's stop routine.  This function is installed
+   as a signal handler for SIGINT.  The first time a user requests a
+   stop, we call remote_stop to send a break or ^C.  If there is no
    response from the target (it didn't stop when the user requested it),
    we ask the user if he'd like to detach from the target.  */
 static void
@@ -4459,7 +4926,7 @@ remote_stop_ns (ptid_t ptid)
          nptid = ptid;
        }
 
-      p = write_ptid (p, endp, nptid);
+      write_ptid (p, endp, nptid);
     }
 
   /* In non-stop, we get an immediate OK reply.  The stop reply will
@@ -4491,7 +4958,7 @@ remote_stop_as (ptid_t ptid)
   send_interrupt_sequence ();
 }
 
-/* This is the generic stop called via the target vector. When a target
+/* This is the generic stop called via the target vector.  When a target
    interrupt is requested, either by the command line or the GUI, we
    will eventually end up here.  */
 
@@ -4575,7 +5042,7 @@ remote_terminal_ours (void)
   remote_async_terminal_ours_p = 1;
 }
 
-void
+static void
 remote_console_output (char *msg)
 {
   char *p;
@@ -4584,12 +5051,13 @@ remote_console_output (char *msg)
     {
       char tb[2];
       char c = fromhex (p[0]) * 16 + fromhex (p[1]);
+
       tb[0] = c;
       tb[1] = 0;
       fputs_unfiltered (tb, gdb_stdtarg);
     }
-    gdb_flush (gdb_stdtarg);
-  }
+  gdb_flush (gdb_stdtarg);
+}
 
 typedef struct cached_reg
 {
@@ -4607,6 +5075,10 @@ struct stop_reply
 
   struct target_waitstatus ws;
 
+  /* Expedited registers.  This makes remote debugging a bit more
+     efficient for those targets that provide critical registers as
+     part of their normal status mechanism (as another roundtrip to
+     fetch them is avoided).  */
   VEC(cached_reg_t) *regcache;
 
   int stopped_by_watchpoint_p;
@@ -4625,6 +5097,7 @@ static struct stop_reply *
 stop_reply_xmalloc (void)
 {
   struct stop_reply *r = XMALLOC (struct stop_reply);
+
   r->next = NULL;
   return r;
 }
@@ -4682,6 +5155,7 @@ static void
 do_stop_reply_xfree (void *arg)
 {
   struct stop_reply *r = arg;
+
   stop_reply_xfree (r);
 }
 
@@ -4853,6 +5327,7 @@ Packet: '%s'\n"),
              else if (strncmp (p, "core", p1 - p) == 0)
                {
                  ULONGEST c;
+
                  p = unpack_varlen_hex (++p1, &c);
                  event->core = c;
                }
@@ -4952,6 +5427,7 @@ Packet: '%s'\n"),
                              "process:", sizeof ("process:") - 1) == 0)
              {
                ULONGEST upid;
+
                p += sizeof ("process:") - 1;
                unpack_varlen_hex (p, &upid);
                pid = upid;
@@ -5065,7 +5541,6 @@ process_stop_reply (struct stop_reply *stop_reply,
                    struct target_waitstatus *status)
 {
   ptid_t ptid;
-  struct thread_info *info;
 
   *status = stop_reply->ws;
   ptid = stop_reply->ptid;
@@ -5398,7 +5873,7 @@ send_g_packet (void)
   struct remote_state *rs = get_remote_state ();
   int buf_len;
 
-  sprintf (rs->buf, "g");
+  xsnprintf (rs->buf, get_remote_packet_size (), "g");
   remote_send (&rs->buf, &rs->buf_size);
 
   /* We can get out of synch in various cases.  If the first character
@@ -5481,7 +5956,7 @@ process_g_packet (struct regcache *regcache)
       if (p[0] == 0 || p[1] == 0)
        /* This shouldn't happen - we adjusted sizeof_g_packet above.  */
        internal_error (__FILE__, __LINE__,
-                       "unexpected end of 'g' packet reply");
+                       _("unexpected end of 'g' packet reply"));
 
       if (p[0] == 'x' && p[1] == 'x')
        regs[i] = 0;            /* 'x' */
@@ -5490,30 +5965,28 @@ process_g_packet (struct regcache *regcache)
       p += 2;
     }
 
-  {
-    int i;
-    for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
-      {
-       struct packet_reg *r = &rsa->regs[i];
-       if (r->in_g_packet)
-         {
-           if (r->offset * 2 >= strlen (rs->buf))
-             /* This shouldn't happen - we adjusted in_g_packet above.  */
-             internal_error (__FILE__, __LINE__,
-                             "unexpected end of 'g' packet reply");
-           else if (rs->buf[r->offset * 2] == 'x')
-             {
-               gdb_assert (r->offset * 2 < strlen (rs->buf));
-               /* The register isn't available, mark it as such (at
-                   the same time setting the value to zero).  */
-               regcache_raw_supply (regcache, r->regnum, NULL);
-             }
-           else
-             regcache_raw_supply (regcache, r->regnum,
-                                  regs + r->offset);
-         }
-      }
-  }
+  for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
+    {
+      struct packet_reg *r = &rsa->regs[i];
+
+      if (r->in_g_packet)
+       {
+         if (r->offset * 2 >= strlen (rs->buf))
+           /* This shouldn't happen - we adjusted in_g_packet above.  */
+           internal_error (__FILE__, __LINE__,
+                           _("unexpected end of 'g' packet reply"));
+         else if (rs->buf[r->offset * 2] == 'x')
+           {
+             gdb_assert (r->offset * 2 < strlen (rs->buf));
+             /* The register isn't available, mark it as such (at
+                the same time setting the value to zero).  */
+             regcache_raw_supply (regcache, r->regnum, NULL);
+           }
+         else
+           regcache_raw_supply (regcache, r->regnum,
+                                regs + r->offset);
+       }
+    }
 }
 
 static void
@@ -5523,6 +5996,28 @@ fetch_registers_using_g (struct regcache *regcache)
   process_g_packet (regcache);
 }
 
+/* Make the remote selected traceframe match GDB's selected
+   traceframe.  */
+
+static void
+set_remote_traceframe (void)
+{
+  int newnum;
+
+  if (remote_traceframe_number == get_traceframe_number ())
+    return;
+
+  /* Avoid recursion, remote_trace_find calls us again.  */
+  remote_traceframe_number = get_traceframe_number ();
+
+  newnum = target_trace_find (tfind_number,
+                             get_traceframe_number (), 0, 0, NULL);
+
+  /* Should not happen.  If it does, all bets are off.  */
+  if (newnum != get_traceframe_number ())
+    warning (_("could not set remote traceframe"));
+}
+
 static void
 remote_fetch_registers (struct target_ops *ops,
                        struct regcache *regcache, int regnum)
@@ -5530,11 +6025,13 @@ remote_fetch_registers (struct target_ops *ops,
   struct remote_arch_state *rsa = get_remote_arch_state ();
   int i;
 
+  set_remote_traceframe ();
   set_general_thread (inferior_ptid);
 
   if (regnum >= 0)
     {
       struct packet_reg *reg = packet_reg_from_regnum (rsa, regnum);
+
       gdb_assert (reg != NULL);
 
       /* If this register might be in the 'g' packet, try that first -
@@ -5650,11 +6147,13 @@ store_registers_using_G (const struct regcache *regcache)
      local buffer.  */
   {
     int i;
+
     regs = alloca (rsa->sizeof_g_packet);
     memset (regs, 0, rsa->sizeof_g_packet);
     for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
       {
        struct packet_reg *r = &rsa->regs[i];
+
        if (r->in_g_packet)
          regcache_raw_collect (regcache, r->regnum, regs + r->offset);
       }
@@ -5684,11 +6183,13 @@ remote_store_registers (struct target_ops *ops,
   struct remote_arch_state *rsa = get_remote_arch_state ();
   int i;
 
+  set_remote_traceframe ();
   set_general_thread (inferior_ptid);
 
   if (regnum >= 0)
     {
       struct packet_reg *reg = packet_reg_from_regnum (rsa, regnum);
+
       gdb_assert (reg != NULL);
 
       /* Always prefer to store registers using the 'P' packet if
@@ -5701,7 +6202,7 @@ remote_store_registers (struct target_ops *ops,
       /* For now, don't complain if we have no way to write the
         register.  GDB loses track of unavailable registers too
         easily.  Some day, this may be an error.  We don't have
-        any way to read the register, either... */
+        any way to read the register, either...  */
       if (!reg->in_g_packet)
        return;
 
@@ -5738,6 +6239,7 @@ static int
 hexnumstr (char *buf, ULONGEST num)
 {
   int len = hexnumlen (num);
+
   return hexnumnstr (buf, num, len);
 }
 
@@ -5766,6 +6268,7 @@ static CORE_ADDR
 remote_address_masked (CORE_ADDR addr)
 {
   int address_size = remote_address_size;
+
   /* If "remoteaddresssize" was not set, default to target address size.  */
   if (!address_size)
     address_size = gdbarch_addr_bit (target_gdbarch);
@@ -5776,6 +6279,7 @@ remote_address_masked (CORE_ADDR addr)
       /* Only create a mask when that mask can safely be constructed
          in a ULONGEST variable.  */
       ULONGEST mask = 1;
+
       mask = (mask << address_size) - 1;
       addr &= mask;
     }
@@ -5875,7 +6379,7 @@ remote_unescape_input (const gdb_byte *buffer, int len,
    remote_write_bytes.
 
    NOTE: This can still lose if the serial line is not eight-bit
-   clean. In cases like this, the user should clear "remote
+   clean.  In cases like this, the user should clear "remote
    X-packet".  */
 
 static void
@@ -5908,14 +6412,15 @@ check_binary_download (CORE_ADDR addr)
          {
            if (remote_debug)
              fprintf_unfiltered (gdb_stdlog,
-                                 "binary downloading NOT suppported by target\n");
+                                 "binary downloading NOT "
+                                 "supported by target\n");
            remote_protocol_packets[PACKET_X].support = PACKET_DISABLE;
          }
        else
          {
            if (remote_debug)
              fprintf_unfiltered (gdb_stdlog,
-                                 "binary downloading suppported by target\n");
+                                 "binary downloading supported by target\n");
            remote_protocol_packets[PACKET_X].support = PACKET_ENABLE;
          }
        break;
@@ -5960,7 +6465,7 @@ remote_write_bytes_aux (const char *header, CORE_ADDR memaddr,
 
   if (packet_format != 'X' && packet_format != 'M')
     internal_error (__FILE__, __LINE__,
-                   "remote_write_bytes_aux: bad packet format");
+                   _("remote_write_bytes_aux: bad packet format"));
 
   if (len <= 0)
     return 0;
@@ -5972,11 +6477,11 @@ remote_write_bytes_aux (const char *header, CORE_ADDR memaddr,
   rs->buf[0] = '\0';
 
   /* Compute the size of the actual payload by subtracting out the
-     packet header and footer overhead: "$M<memaddr>,<len>:...#nn".
-     */
+     packet header and footer overhead: "$M<memaddr>,<len>:...#nn".  */
+
   payload_size -= strlen ("$,:#NN");
   if (!use_length)
-    /* The comma won't be used. */
+    /* The comma won't be used.  */
     payload_size += 1;
   header_length = strlen (header);
   payload_size -= header_length;
@@ -6007,7 +6512,7 @@ remote_write_bytes_aux (const char *header, CORE_ADDR memaddr,
 
   if (todo <= 0)
     internal_error (__FILE__, __LINE__,
-                   _("minumum packet size too small to write data"));
+                   _("minimum packet size too small to write data"));
 
   /* If we already need another packet, then try to align the end
      of this packet to a useful boundary.  */
@@ -6105,7 +6610,7 @@ remote_write_bytes_aux (const char *header, CORE_ADDR memaddr,
    Returns number of bytes transferred, or 0 (setting errno) for
    error.  Only transfer a single packet.  */
 
-int
+static int
 remote_write_bytes (CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
 {
   char *packet_format = 0;
@@ -6140,19 +6645,14 @@ remote_write_bytes (CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
 
    Returns number of bytes transferred, or 0 for error.  */
 
-/* NOTE: cagney/1999-10-18: This function (and its siblings in other
-   remote targets) shouldn't attempt to read the entire buffer.
-   Instead it should read a single packet worth of data and then
-   return the byte size of that packet to the caller.  The caller (its
-   caller and its callers caller ;-) already contains code for
-   handling partial reads.  */
-
-int
+static int
 remote_read_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
 {
   struct remote_state *rs = get_remote_state ();
   int max_buf_size;            /* Max size of packet output buffer.  */
-  int origlen;
+  char *p;
+  int todo;
+  int i;
 
   if (len <= 0)
     return 0;
@@ -6161,56 +6661,37 @@ remote_read_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
   /* The packet buffer will be large enough for the payload;
      get_memory_packet_size ensures this.  */
 
-  origlen = len;
-  while (len > 0)
-    {
-      char *p;
-      int todo;
-      int i;
-
-      todo = min (len, max_buf_size / 2);      /* num bytes that will fit */
-
-      /* construct "m"<memaddr>","<len>" */
-      /* sprintf (rs->buf, "m%lx,%x", (unsigned long) memaddr, todo); */
-      memaddr = remote_address_masked (memaddr);
-      p = rs->buf;
-      *p++ = 'm';
-      p += hexnumstr (p, (ULONGEST) memaddr);
-      *p++ = ',';
-      p += hexnumstr (p, (ULONGEST) todo);
-      *p = '\0';
-
-      putpkt (rs->buf);
-      getpkt (&rs->buf, &rs->buf_size, 0);
-
-      if (rs->buf[0] == 'E'
-         && isxdigit (rs->buf[1]) && isxdigit (rs->buf[2])
-         && rs->buf[3] == '\0')
-       {
-         /* There is no correspondance between what the remote
-            protocol uses for errors and errno codes.  We would like
-            a cleaner way of representing errors (big enough to
-            include errno codes, bfd_error codes, and others).  But
-            for now just return EIO.  */
-         errno = EIO;
-         return 0;
-       }
-
-      /* Reply describes memory byte by byte,
-         each byte encoded as two hex characters.  */
+  /* Number if bytes that will fit.  */
+  todo = min (len, max_buf_size / 2);
 
-      p = rs->buf;
-      if ((i = hex2bin (p, myaddr, todo)) < todo)
-       {
-         /* Reply is short.  This means that we were able to read
-            only part of what we wanted to.  */
-         return i + (origlen - len);
-       }
-      myaddr += todo;
-      memaddr += todo;
-      len -= todo;
+  /* Construct "m"<memaddr>","<len>".  */
+  memaddr = remote_address_masked (memaddr);
+  p = rs->buf;
+  *p++ = 'm';
+  p += hexnumstr (p, (ULONGEST) memaddr);
+  *p++ = ',';
+  p += hexnumstr (p, (ULONGEST) todo);
+  *p = '\0';
+  putpkt (rs->buf);
+  getpkt (&rs->buf, &rs->buf_size, 0);
+  if (rs->buf[0] == 'E'
+      && isxdigit (rs->buf[1]) && isxdigit (rs->buf[2])
+      && rs->buf[3] == '\0')
+    {
+      /* There is no correspondance between what the remote protocol
+        uses for errors and errno codes.  We would like a cleaner way
+        of representing errors (big enough to include errno codes,
+        bfd_error codes, and others).  But for now just return
+        EIO.  */
+      errno = EIO;
+      return 0;
     }
-  return origlen;
+  /* Reply describes memory byte by byte, each byte encoded as two hex
+     characters.  */
+  p = rs->buf;
+  i = hex2bin (p, myaddr, todo);
+  /* Return what we have.  Let higher layers handle partial reads.  */
+  return i;
 }
 \f
 
@@ -6233,6 +6714,7 @@ handle_notification (char *buf, size_t length)
        {
          struct cleanup *old_chain;
          struct stop_reply *reply = stop_reply_xmalloc ();
+
          old_chain = make_cleanup (do_stop_reply_xfree, reply);
 
          remote_parse_stop_reply (buf + 5, reply);
@@ -6270,6 +6752,7 @@ remote_xfer_memory (CORE_ADDR mem_addr, gdb_byte *buffer, int mem_len,
 {
   int res;
 
+  set_remote_traceframe ();
   set_general_thread (inferior_ptid);
 
   if (should_write)
@@ -6289,13 +6772,13 @@ remote_send_printf (const char *format, ...)
 {
   struct remote_state *rs = get_remote_state ();
   int max_size = get_remote_packet_size ();
-
   va_list ap;
+
   va_start (ap, format);
 
   rs->buf[0] = '\0';
   if (vsnprintf (rs->buf, max_size, format, ap) >= max_size)
-    internal_error (__FILE__, __LINE__, "Too long remote packet.");
+    internal_error (__FILE__, __LINE__, _("Too long remote packet."));
 
   if (putpkt (rs->buf) < 0)
     error (_("Communication problem with target."));
@@ -6310,6 +6793,7 @@ static void
 restore_remote_timeout (void *p)
 {
   int value = *(int *)p;
+
   remote_timeout = value;
 }
 
@@ -6325,9 +6809,9 @@ remote_flash_erase (struct target_ops *ops,
   int addr_size = gdbarch_addr_bit (target_gdbarch) / 8;
   int saved_remote_timeout = remote_timeout;
   enum packet_result ret;
-
   struct cleanup *back_to = make_cleanup (restore_remote_timeout,
                                           &saved_remote_timeout);
+
   remote_timeout = remote_flash_timeout;
 
   ret = remote_send_printf ("vFlashErase:%s,%s",
@@ -6414,7 +6898,9 @@ readchar (int timeout)
       error (_("Remote connection closed"));
       /* no return */
     case SERIAL_ERROR:
-      perror_with_name (_("Remote communication error"));
+      pop_target ();
+      perror_with_name (_("Remote communication error.  "
+                         "Target disconnected."));
       /* no return */
     case SERIAL_TIMEOUT:
       break;
@@ -6581,6 +7067,7 @@ putpkt_binary (char *buf, int cnt)
            case '-':
              if (remote_debug)
                fprintf_unfiltered (gdb_stdlog, "Nak\n");
+             /* FALLTHROUGH */
            case SERIAL_TIMEOUT:
              tcount++;
              if (tcount > 3)
@@ -6791,8 +7278,8 @@ read_frame (char **buf_p,
                str = escape_buffer (buf, bc);
                old_chain = make_cleanup (xfree, str);
                fprintf_unfiltered (gdb_stdlog,
-                                   "\
-Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
+                                   "Bad checksum, sentsum=0x%x, "
+                                   "csum=0x%x, buf=%s\n",
                                    pktcsum, csum, str);
                do_cleanups (old_chain);
              }
@@ -6803,8 +7290,8 @@ Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
        case '*':               /* Run length encoding.  */
           {
            int repeat;
-           csum += c;
 
+           csum += c;
            c = readchar (remote_timeout);
            csum += c;
            repeat = c - ' ' + 3;       /* Compute repeat count.  */
@@ -7024,12 +7511,20 @@ getpkt_or_notif_sane (char **buf, long *sizeof_buf, int forever)
 }
 
 \f
+/* A helper function that just calls putpkt; for type correctness.  */
+
+static int
+putpkt_for_catch_errors (void *arg)
+{
+  return putpkt (arg);
+}
+
 static void
 remote_kill (struct target_ops *ops)
 {
   /* Use catch_errors so the user can quit from gdb even when we
      aren't on speaking terms with the remote system.  */
-  catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR);
+  catch_errors (putpkt_for_catch_errors, "k", "", RETURN_MASK_ERROR);
 
   /* Don't wait for it to die.  I'm not really sure it matters whether
      we do or not.  For the existing stubs, kill is a noop.  */
@@ -7043,7 +7538,7 @@ remote_vkill (int pid, struct remote_state *rs)
     return -1;
 
   /* Tell the remote target to detach.  */
-  sprintf (rs->buf, "vKill;%x", pid);
+  xsnprintf (rs->buf, get_remote_packet_size (), "vKill;%x", pid);
   putpkt (rs->buf);
   getpkt (&rs->buf, &rs->buf_size, 0);
 
@@ -7064,7 +7559,7 @@ extended_remote_kill (struct target_ops *ops)
   struct remote_state *rs = get_remote_state ();
 
   res = remote_vkill (pid, rs);
-  if (res == -1 && !remote_multi_process_p (rs))
+  if (res == -1 && !(rs->extended && remote_multi_process_p (rs)))
     {
       /* Don't try 'k' on a multi-process aware stub -- it has no way
         to specify the pid.  */
@@ -7157,9 +7652,10 @@ extended_remote_mourn_1 (struct target_ops *target)
 
          if (rs->buf[0] == 'S' || rs->buf[0] == 'T')
            {
-             /* Assume that the target has been restarted.  Set inferior_ptid
-                so that bits of core GDB realizes there's something here, e.g.,
-                so that the user can say "kill" again.  */
+             /* Assume that the target has been restarted.  Set
+                inferior_ptid so that bits of core GDB realizes
+                there's something here, e.g., so that the user can
+                say "kill" again.  */
              inferior_ptid = magic_null_ptid;
            }
        }
@@ -7172,6 +7668,29 @@ extended_remote_mourn (struct target_ops *ops)
   extended_remote_mourn_1 (ops);
 }
 
+static int
+extended_remote_supports_disable_randomization (void)
+{
+  return (remote_protocol_packets[PACKET_QDisableRandomization].support
+         == PACKET_ENABLE);
+}
+
+static void
+extended_remote_disable_randomization (int val)
+{
+  struct remote_state *rs = get_remote_state ();
+  char *reply;
+
+  xsnprintf (rs->buf, get_remote_packet_size (), "QDisableRandomization:%x",
+            val);
+  putpkt (rs->buf);
+  reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
+  if (*reply == '\0')
+    error (_("Target does not support QDisableRandomization."));
+  if (strcmp (reply, "OK") != 0)
+    error (_("Bogus QDisableRandomization reply from target: %s"), reply);
+}
+
 static int
 extended_remote_run (char *args)
 {
@@ -7248,6 +7767,10 @@ extended_remote_create_inferior_1 (char *exec_file, char *args,
   if (target_can_async_p ())
     target_async (inferior_event_handler, 0);
 
+  /* Disable address space randomization if requested (and supported).  */
+  if (extended_remote_supports_disable_randomization ())
+    extended_remote_disable_randomization (disable_randomization);
+
   /* Now restart the remote server.  */
   if (extended_remote_run (args) == -1)
     {
@@ -7271,14 +7794,7 @@ extended_remote_create_inferior_1 (char *exec_file, char *args,
       init_wait_for_inferior ();
     }
 
-  /* Now mark the inferior as running before we do anything else.  */
-  inferior_ptid = magic_null_ptid;
-
-  /* Now, if we have thread information, update inferior_ptid.  */
-  inferior_ptid = remote_current_thread (inferior_ptid);
-
-  remote_add_inferior (ptid_get_pid (inferior_ptid), 0);
-  add_thread_silent (inferior_ptid);
+  add_current_inferior_and_thread ();
 
   /* Get updated offsets, if the stub uses qOffsets.  */
   get_offsets ();
@@ -7293,6 +7809,44 @@ extended_remote_create_inferior (struct target_ops *ops,
 }
 \f
 
+/* Given a location's target info BP_TGT and the packet buffer BUF,  output
+   the list of conditions (in agent expression bytecode format), if any, the
+   target needs to evaluate.  The output is placed into the packet buffer
+   started from BUF and ended at BUF_END.  */
+
+static int
+remote_add_target_side_condition (struct gdbarch *gdbarch,
+                                 struct bp_target_info *bp_tgt, char *buf,
+                                 char *buf_end)
+{
+  struct agent_expr *aexpr = NULL;
+  int i, ix;
+  char *pkt;
+  char *buf_start = buf;
+
+  if (VEC_empty (agent_expr_p, bp_tgt->conditions))
+    return 0;
+
+  buf += strlen (buf);
+  xsnprintf (buf, buf_end - buf, "%s", ";");
+  buf++;
+
+  /* Send conditions to the target and free the vector.  */
+  for (ix = 0;
+       VEC_iterate (agent_expr_p, bp_tgt->conditions, ix, aexpr);
+       ix++)
+    {
+      xsnprintf (buf, buf_end - buf, "X%x,", aexpr->len);
+      buf += strlen (buf);
+      for (i = 0; i < aexpr->len; ++i)
+       buf = pack_hex_byte (buf, aexpr->buf[i]);
+      *buf = '\0';
+    }
+
+  VEC_free (agent_expr_p, bp_tgt->conditions);
+  return 0;
+}
+
 /* Insert a breakpoint.  On targets that have software breakpoint
    support, we ask the remote target to do the work; on targets
    which don't, we insert a traditional memory breakpoint.  */
@@ -7310,20 +7864,25 @@ remote_insert_breakpoint (struct gdbarch *gdbarch,
     {
       CORE_ADDR addr = bp_tgt->placed_address;
       struct remote_state *rs;
-      char *p;
+      char *p, *endbuf;
       int bpsize;
+      struct condition_list *cond = NULL;
 
       gdbarch_remote_breakpoint_from_pc (gdbarch, &addr, &bpsize);
 
       rs = get_remote_state ();
       p = rs->buf;
+      endbuf = rs->buf + get_remote_packet_size ();
 
       *(p++) = 'Z';
       *(p++) = '0';
       *(p++) = ',';
       addr = (ULONGEST) remote_address_masked (addr);
       p += hexnumstr (p, addr);
-      sprintf (p, ",%d", bpsize);
+      xsnprintf (p, endbuf - p, ",%d", bpsize);
+
+      if (remote_supports_cond_breakpoints ())
+       remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
 
       putpkt (rs->buf);
       getpkt (&rs->buf, &rs->buf_size, 0);
@@ -7354,6 +7913,7 @@ remote_remove_breakpoint (struct gdbarch *gdbarch,
   if (remote_protocol_packets[PACKET_Z0].support != PACKET_DISABLE)
     {
       char *p = rs->buf;
+      char *endbuf = rs->buf + get_remote_packet_size ();
 
       *(p++) = 'z';
       *(p++) = '0';
@@ -7361,7 +7921,7 @@ remote_remove_breakpoint (struct gdbarch *gdbarch,
 
       addr = (ULONGEST) remote_address_masked (bp_tgt->placed_address);
       p += hexnumstr (p, addr);
-      sprintf (p, ",%d", bp_tgt->placed_size);
+      xsnprintf (p, endbuf - p, ",%d", bp_tgt->placed_size);
 
       putpkt (rs->buf);
       getpkt (&rs->buf, &rs->buf_size, 0);
@@ -7393,20 +7953,22 @@ watchpoint_to_Z_packet (int type)
 }
 
 static int
-remote_insert_watchpoint (CORE_ADDR addr, int len, int type)
+remote_insert_watchpoint (CORE_ADDR addr, int len, int type,
+                         struct expression *cond)
 {
   struct remote_state *rs = get_remote_state ();
+  char *endbuf = rs->buf + get_remote_packet_size ();
   char *p;
   enum Z_packet_type packet = watchpoint_to_Z_packet (type);
 
   if (remote_protocol_packets[PACKET_Z0 + packet].support == PACKET_DISABLE)
     return 1;
 
-  sprintf (rs->buf, "Z%x,", packet);
+  xsnprintf (rs->buf, endbuf - rs->buf, "Z%x,", packet);
   p = strchr (rs->buf, '\0');
   addr = remote_address_masked (addr);
   p += hexnumstr (p, (ULONGEST) addr);
-  sprintf (p, ",%x", len);
+  xsnprintf (p, endbuf - p, ",%x", len);
 
   putpkt (rs->buf);
   getpkt (&rs->buf, &rs->buf_size, 0);
@@ -7424,22 +7986,33 @@ remote_insert_watchpoint (CORE_ADDR addr, int len, int type)
                  _("remote_insert_watchpoint: reached end of function"));
 }
 
+static int
+remote_watchpoint_addr_within_range (struct target_ops *target, CORE_ADDR addr,
+                                    CORE_ADDR start, int length)
+{
+  CORE_ADDR diff = remote_address_masked (addr - start);
+
+  return diff < length;
+}
+
 
 static int
-remote_remove_watchpoint (CORE_ADDR addr, int len, int type)
+remote_remove_watchpoint (CORE_ADDR addr, int len, int type,
+                         struct expression *cond)
 {
   struct remote_state *rs = get_remote_state ();
+  char *endbuf = rs->buf + get_remote_packet_size ();
   char *p;
   enum Z_packet_type packet = watchpoint_to_Z_packet (type);
 
   if (remote_protocol_packets[PACKET_Z0 + packet].support == PACKET_DISABLE)
     return -1;
 
-  sprintf (rs->buf, "z%x,", packet);
+  xsnprintf (rs->buf, endbuf - rs->buf, "z%x,", packet);
   p = strchr (rs->buf, '\0');
   addr = remote_address_masked (addr);
   p += hexnumstr (p, (ULONGEST) addr);
-  sprintf (p, ",%x", len);
+  xsnprintf (p, endbuf - p, ",%x", len);
   putpkt (rs->buf);
   getpkt (&rs->buf, &rs->buf_size, 0);
 
@@ -7457,8 +8030,22 @@ remote_remove_watchpoint (CORE_ADDR addr, int len, int type)
 
 
 int remote_hw_watchpoint_limit = -1;
+int remote_hw_watchpoint_length_limit = -1;
 int remote_hw_breakpoint_limit = -1;
 
+static int
+remote_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
+{
+  if (remote_hw_watchpoint_length_limit == 0)
+    return 0;
+  else if (remote_hw_watchpoint_length_limit < 0)
+    return 1;
+  else if (len <= remote_hw_watchpoint_length_limit)
+    return 1;
+  else
+    return 0;
+}
+
 static int
 remote_check_watch_resources (int type, int cnt, int ot)
 {
@@ -7495,6 +8082,7 @@ static int
 remote_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
 {
   int rc = 0;
+
   if (remote_stopped_by_watchpoint ())
     {
       *addr_p = remote_watch_data_address;
@@ -7511,7 +8099,7 @@ remote_insert_hw_breakpoint (struct gdbarch *gdbarch,
 {
   CORE_ADDR addr;
   struct remote_state *rs;
-  char *p;
+  char *p, *endbuf;
 
   /* The length field should be set to the size of a breakpoint
      instruction, even though we aren't inserting one ourselves.  */
@@ -7524,6 +8112,7 @@ remote_insert_hw_breakpoint (struct gdbarch *gdbarch,
 
   rs = get_remote_state ();
   p = rs->buf;
+  endbuf = rs->buf + get_remote_packet_size ();
 
   *(p++) = 'Z';
   *(p++) = '1';
@@ -7531,7 +8120,10 @@ remote_insert_hw_breakpoint (struct gdbarch *gdbarch,
 
   addr = remote_address_masked (bp_tgt->placed_address);
   p += hexnumstr (p, (ULONGEST) addr);
-  sprintf (p, ",%x", bp_tgt->placed_size);
+  xsnprintf (p, endbuf - p, ",%x", bp_tgt->placed_size);
+
+  if (remote_supports_cond_breakpoints ())
+    remote_add_target_side_condition (gdbarch, bp_tgt, p, endbuf);
 
   putpkt (rs->buf);
   getpkt (&rs->buf, &rs->buf_size, 0);
@@ -7556,6 +8148,7 @@ remote_remove_hw_breakpoint (struct gdbarch *gdbarch,
   CORE_ADDR addr;
   struct remote_state *rs = get_remote_state ();
   char *p = rs->buf;
+  char *endbuf = rs->buf + get_remote_packet_size ();
 
   if (remote_protocol_packets[PACKET_Z1].support == PACKET_DISABLE)
     return -1;
@@ -7566,7 +8159,7 @@ remote_remove_hw_breakpoint (struct gdbarch *gdbarch,
 
   addr = remote_address_masked (bp_tgt->placed_address);
   p += hexnumstr (p, (ULONGEST) addr);
-  sprintf (p, ",%x", bp_tgt->placed_size);
+  xsnprintf (p, endbuf  - p, ",%x", bp_tgt->placed_size);
 
   putpkt (rs->buf);
   getpkt (&rs->buf, &rs->buf_size, 0);
@@ -7670,17 +8263,17 @@ compare_sections_command (char *args, int from_tty)
   for (s = exec_bfd->sections; s; s = s->next)
     {
       if (!(s->flags & SEC_LOAD))
-       continue;               /* skip non-loadable section */
+       continue;               /* Skip non-loadable section.  */
 
       size = bfd_get_section_size (s);
       if (size == 0)
-       continue;               /* skip zero-length section */
+       continue;               /* Skip zero-length section.  */
 
       sectname = bfd_get_section_name (exec_bfd, s);
       if (args && strcmp (args, sectname) != 0)
-       continue;               /* not the section selected by user */
+       continue;               /* Not the section selected by user.  */
 
-      matched = 1;             /* do this section */
+      matched = 1;             /* Do this section.  */
       lma = s->lma;
 
       sectdata = xmalloc (size);
@@ -7845,6 +8438,7 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
   char *p2;
   char query_type;
 
+  set_remote_traceframe ();
   set_general_thread (inferior_ptid);
 
   rs = get_remote_state ();
@@ -7853,6 +8447,7 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
   if (object == TARGET_OBJECT_MEMORY)
     {
       int xfered;
+
       errno = 0;
 
       /* If the remote target is connected but not running, we should
@@ -7874,7 +8469,7 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
        return -1;
     }
 
-  /* Handle SPU memory using qxfer packets. */
+  /* Handle SPU memory using qxfer packets.  */
   if (object == TARGET_OBJECT_SPU)
     {
       if (readbuf)
@@ -7895,11 +8490,23 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
                                  &remote_protocol_packets
                                  [PACKET_qXfer_siginfo_read]);
       else
-       return remote_write_qxfer (ops, "siginfo", annex, writebuf, offset, len,
+       return remote_write_qxfer (ops, "siginfo", annex,
+                                  writebuf, offset, len,
                                   &remote_protocol_packets
                                   [PACKET_qXfer_siginfo_write]);
     }
 
+  if (object == TARGET_OBJECT_STATIC_TRACE_DATA)
+    {
+      if (readbuf)
+       return remote_read_qxfer (ops, "statictrace", annex,
+                                 readbuf, offset, len,
+                                 &remote_protocol_packets
+                                 [PACKET_qXfer_statictrace_read]);
+      else
+       return -1;
+    }
+
   /* Only handle flash writes.  */
   if (writebuf != NULL)
     {
@@ -7945,6 +8552,11 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
        (ops, "libraries", annex, readbuf, offset, len,
         &remote_protocol_packets[PACKET_qXfer_libraries]);
 
+    case TARGET_OBJECT_LIBRARIES_SVR4:
+      return remote_read_qxfer
+       (ops, "libraries-svr4", annex, readbuf, offset, len,
+        &remote_protocol_packets[PACKET_qXfer_libraries_svr4]);
+
     case TARGET_OBJECT_MEMORY_MAP:
       gdb_assert (annex == NULL);
       return remote_read_qxfer (ops, "memory-map", annex, readbuf, offset, len,
@@ -7962,6 +8574,20 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
       return remote_read_qxfer (ops, "threads", annex, readbuf, offset, len,
                                &remote_protocol_packets[PACKET_qXfer_threads]);
 
+    case TARGET_OBJECT_TRACEFRAME_INFO:
+      gdb_assert (annex == NULL);
+      return remote_read_qxfer
+       (ops, "traceframe-info", annex, readbuf, offset, len,
+        &remote_protocol_packets[PACKET_qXfer_traceframe_info]);
+
+    case TARGET_OBJECT_FDPIC:
+      return remote_read_qxfer (ops, "fdpic", annex, readbuf, offset, len,
+                               &remote_protocol_packets[PACKET_qXfer_fdpic]);
+
+    case TARGET_OBJECT_OPENVMS_UIB:
+      return remote_read_qxfer (ops, "uib", annex, readbuf, offset, len,
+                               &remote_protocol_packets[PACKET_qXfer_uib]);
+
     default:
       return -1;
     }
@@ -7970,7 +8596,7 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
      buffer size.  */
   if (offset == 0 && len == 0)
     return (get_remote_packet_size ());
-  /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
+  /* Minimum outbuf size is get_remote_packet_size ().  If LEN is not
      large enough let the caller deal with it.  */
   if (len < get_remote_packet_size ())
     return -1;
@@ -8024,10 +8650,10 @@ remote_search_memory (struct target_ops* ops,
   int max_size = get_memory_write_packet_size ();
   struct packet_config *packet =
     &remote_protocol_packets[PACKET_qSearch_memory];
-  /* number of packet bytes used to encode the pattern,
-     this could be more than PATTERN_LEN due to escape characters */
+  /* Number of packet bytes used to encode the pattern;
+     this could be more than PATTERN_LEN due to escape characters */
   int escaped_pattern_len;
-  /* amount of pattern that was encodable in the packet */
+  /* Amount of pattern that was encodable in the packet.  */
   int used_pattern_len;
   int i;
   int found;
@@ -8069,7 +8695,7 @@ remote_search_memory (struct target_ops* ops,
 
   /* Bail if the pattern is too large.  */
   if (used_pattern_len != pattern_len)
-    error ("Pattern is too large to transmit to remote target.");
+    error (_("Pattern is too large to transmit to remote target."));
 
   if (putpkt_binary (rs->buf, i + escaped_pattern_len) < 0
       || getpkt_sane (&rs->buf, &rs->buf_size, 0) < 0
@@ -8119,7 +8745,8 @@ remote_rcmd (char *command,
   strcpy (rs->buf, "qRcmd,");
   p = strchr (rs->buf, '\0');
 
-  if ((strlen (rs->buf) + strlen (command) * 2 + 8/*misc*/) > get_remote_packet_size ())
+  if ((strlen (rs->buf) + strlen (command) * 2 + 8/*misc*/)
+      > get_remote_packet_size ())
     error (_("\"monitor\" command ``%s'' is too long."), command);
 
   /* Encode the actual command.  */
@@ -8134,8 +8761,17 @@ remote_rcmd (char *command,
       char *buf;
 
       /* XXX - see also remote_get_noisy_reply().  */
+      QUIT;                    /* Allow user to bail out with ^C.  */
       rs->buf[0] = '\0';
-      getpkt (&rs->buf, &rs->buf_size, 0);
+      if (getpkt_sane (&rs->buf, &rs->buf_size, 0) == -1)
+        { 
+          /* Timeout.  Continue to (try to) read responses.
+             This is better than stopping with an error, assuming the stub
+             is still executing the (long) monitor command.
+             If needed, the user can interrupt gdb using C-c, obtaining
+             an effect similar to stop on timeout.  */
+          continue;
+        }
       buf = rs->buf;
       if (buf[0] == '\0')
        error (_("Target does not support this command."));
@@ -8154,6 +8790,7 @@ remote_rcmd (char *command,
       for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
        {
          char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
+
          fputc_unfiltered (c, outbuf);
        }
       break;
@@ -8170,6 +8807,7 @@ remote_memory_map (struct target_ops *ops)
   if (text)
     {
       struct cleanup *back_to = make_cleanup (xfree, text);
+
       result = parse_memory_map (text);
       do_cleanups (back_to);
     }
@@ -8332,8 +8970,9 @@ threadlist_update_test_cmd (char *cmd, int tty)
 static void
 init_remote_threadtests (void)
 {
-  add_com ("tlist", class_obscure, threadlist_test_cmd, _("\
-Fetch and print the remote list of thread identifiers, one pkt only"));
+  add_com ("tlist", class_obscure, threadlist_test_cmd,
+          _("Fetch and print the remote list of "
+            "thread identifiers, one pkt only"));
   add_com ("tinfo", class_obscure, threadinfo_test_cmd,
           _("Fetch and display info about one thread"));
   add_com ("tset", class_obscure, threadset_test_cmd,
@@ -8355,7 +8994,9 @@ remote_pid_to_str (struct target_ops *ops, ptid_t ptid)
   static char buf[64];
   struct remote_state *rs = get_remote_state ();
 
-  if (ptid_is_pid (ptid))
+  if (ptid_equal (ptid, null_ptid))
+    return normal_pid_to_str (ptid);
+  else if (ptid_is_pid (ptid))
     {
       /* Printing an inferior target id.  */
 
@@ -8380,7 +9021,7 @@ remote_pid_to_str (struct target_ops *ops, ptid_t ptid)
     {
       if (ptid_equal (magic_null_ptid, ptid))
        xsnprintf (buf, sizeof buf, "Thread <main>");
-      else if (remote_multi_process_p (rs))
+      else if (rs->extended && remote_multi_process_p (rs))
        xsnprintf (buf, sizeof buf, "Thread %d.%ld",
                   ptid_get_pid (ptid), ptid_get_tid (ptid));
       else
@@ -8415,7 +9056,8 @@ remote_get_thread_local_address (struct target_ops *ops,
 
       putpkt (rs->buf);
       getpkt (&rs->buf, &rs->buf_size, 0);
-      result = packet_ok (rs->buf, &remote_protocol_packets[PACKET_qGetTLSAddr]);
+      result = packet_ok (rs->buf,
+                         &remote_protocol_packets[PACKET_qGetTLSAddr]);
       if (result == PACKET_OK)
        {
          ULONGEST result;
@@ -8437,8 +9079,50 @@ remote_get_thread_local_address (struct target_ops *ops,
   return 0;
 }
 
-/* Support for inferring a target description based on the current
-   architecture and the size of a 'g' packet.  While the 'g' packet
+/* Provide thread local base, i.e. Thread Information Block address.
+   Returns 1 if ptid is found and thread_local_base is non zero.  */
+
+static int
+remote_get_tib_address (ptid_t ptid, CORE_ADDR *addr)
+{
+  if (remote_protocol_packets[PACKET_qGetTIBAddr].support != PACKET_DISABLE)
+    {
+      struct remote_state *rs = get_remote_state ();
+      char *p = rs->buf;
+      char *endp = rs->buf + get_remote_packet_size ();
+      enum packet_result result;
+
+      strcpy (p, "qGetTIBAddr:");
+      p += strlen (p);
+      p = write_ptid (p, endp, ptid);
+      *p++ = '\0';
+
+      putpkt (rs->buf);
+      getpkt (&rs->buf, &rs->buf_size, 0);
+      result = packet_ok (rs->buf,
+                         &remote_protocol_packets[PACKET_qGetTIBAddr]);
+      if (result == PACKET_OK)
+       {
+         ULONGEST result;
+
+         unpack_varlen_hex (rs->buf, &result);
+         if (addr)
+           *addr = (CORE_ADDR) result;
+         return 1;
+       }
+      else if (result == PACKET_UNKNOWN)
+       error (_("Remote target doesn't support qGetTIBAddr packet"));
+      else
+       error (_("Remote target failed to process qGetTIBAddr request"));
+    }
+  else
+    error (_("qGetTIBAddr not supported or disabled on this target"));
+  /* Not reached.  */
+  return 0;
+}
+
+/* Support for inferring a target description based on the current
+   architecture and the size of a 'g' packet.  While the 'g' packet
    can have any size (since optional registers can be left off the
    end), some sizes are easily recognizable given knowledge of the
    approximate architecture.  */
@@ -8480,7 +9164,7 @@ register_remote_g_packet_guess (struct gdbarch *gdbarch, int bytes,
        ix++)
     if (guess->bytes == bytes)
       internal_error (__FILE__, __LINE__,
-                     "Duplicate g packet description added for size %d",
+                     _("Duplicate g packet description added for size %d"),
                      bytes);
 
   new_guess.bytes = bytes;
@@ -8864,6 +9548,44 @@ remote_hostio_unlink (const char *filename, int *remote_errno)
                                     remote_errno, NULL, NULL);
 }
 
+/* Read value of symbolic link FILENAME on the remote target.  Return
+   a null-terminated string allocated via xmalloc, or NULL if an error
+   occurs (and set *REMOTE_ERRNO).  */
+
+static char *
+remote_hostio_readlink (const char *filename, int *remote_errno)
+{
+  struct remote_state *rs = get_remote_state ();
+  char *p = rs->buf;
+  char *attachment;
+  int left = get_remote_packet_size ();
+  int len, attachment_len;
+  int read_len;
+  char *ret;
+
+  remote_buffer_add_string (&p, &left, "vFile:readlink:");
+
+  remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
+                          strlen (filename));
+
+  len = remote_hostio_send_command (p - rs->buf, PACKET_vFile_readlink,
+                                   remote_errno, &attachment,
+                                   &attachment_len);
+
+  if (len < 0)
+    return NULL;
+
+  ret = xmalloc (len + 1);
+
+  read_len = remote_unescape_input (attachment, attachment_len,
+                                   ret, len);
+  if (read_len != len)
+    error (_("Readlink returned %d, but %d bytes."), len, read_len);
+
+  ret[len] = '\0';
+  return ret;
+}
+
 static int
 remote_fileio_errno_to_host (int errnum)
 {
@@ -9066,7 +9788,8 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty)
     {
       if (!saw_eof)
        {
-         bytes = fread (buffer + bytes_in_buffer, 1, io_size - bytes_in_buffer,
+         bytes = fread (buffer + bytes_in_buffer, 1,
+                        io_size - bytes_in_buffer,
                         file);
          if (bytes == 0)
            {
@@ -9088,7 +9811,8 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty)
       bytes += bytes_in_buffer;
       bytes_in_buffer = 0;
 
-      retcode = remote_hostio_pwrite (fd, buffer, bytes, offset, &remote_errno);
+      retcode = remote_hostio_pwrite (fd, buffer, bytes,
+                                     offset, &remote_errno);
 
       if (retcode < 0)
        remote_hostio_error (remote_errno);
@@ -9264,27 +9988,81 @@ remote_supports_non_stop (void)
   return 1;
 }
 
+static int
+remote_supports_disable_randomization (void)
+{
+  /* Only supported in extended mode.  */
+  return 0;
+}
+
 static int
 remote_supports_multi_process (void)
 {
   struct remote_state *rs = get_remote_state ();
-  return remote_multi_process_p (rs);
+
+  /* Only extended-remote handles being attached to multiple
+     processes, even though plain remote can use the multi-process
+     thread id extensions, so that GDB knows the target process's
+     PID.  */
+  return rs->extended && remote_multi_process_p (rs);
 }
 
-int
+static int
 remote_supports_cond_tracepoints (void)
 {
   struct remote_state *rs = get_remote_state ();
+
   return rs->cond_tracepoints;
 }
 
-int
+static int
+remote_supports_cond_breakpoints (void)
+{
+  struct remote_state *rs = get_remote_state ();
+
+  return rs->cond_breakpoints;
+}
+
+static int
 remote_supports_fast_tracepoints (void)
 {
   struct remote_state *rs = get_remote_state ();
+
   return rs->fast_tracepoints;
 }
 
+static int
+remote_supports_static_tracepoints (void)
+{
+  struct remote_state *rs = get_remote_state ();
+
+  return rs->static_tracepoints;
+}
+
+static int
+remote_supports_install_in_trace (void)
+{
+  struct remote_state *rs = get_remote_state ();
+
+  return rs->install_in_trace;
+}
+
+static int
+remote_supports_enable_disable_tracepoint (void)
+{
+  struct remote_state *rs = get_remote_state ();
+
+  return rs->enable_disable_tracepoints;
+}
+
+static int
+remote_supports_string_tracing (void)
+{
+  struct remote_state *rs = get_remote_state ();
+
+  return rs->string_tracing;
+}
+
 static void
 remote_trace_init (void)
 {
@@ -9328,7 +10106,7 @@ remote_download_command_source (int num, ULONGEST addr,
 
   for (cmd = cmds; cmd; cmd = cmd->next)
     {
-      QUIT;    /* allow user to bail out with ^C */
+      QUIT;    /* Allow user to bail out with ^C.  */
       strcpy (rs->buf, "QTDPsrc:");
       encode_source_string (num, addr, "cmd", cmd->line,
                            rs->buf + strlen (rs->buf),
@@ -9343,7 +10121,7 @@ remote_download_command_source (int num, ULONGEST addr,
        {
          remote_download_command_source (num, addr, *cmd->body_list);
 
-         QUIT; /* allow user to bail out with ^C */
+         QUIT; /* Allow user to bail out with ^C.  */
          strcpy (rs->buf, "QTDPsrc:");
          encode_source_string (num, addr, "cmd", "end",
                                rs->buf + strlen (rs->buf),
@@ -9357,12 +10135,13 @@ remote_download_command_source (int num, ULONGEST addr,
 }
 
 static void
-remote_download_tracepoint (struct breakpoint *t)
+remote_download_tracepoint (struct bp_location *loc)
 {
-  struct bp_location *loc;
+#define BUF_SIZE 2048
+
   CORE_ADDR tpaddr;
   char addrbuf[40];
-  char buf[2048];
+  char buf[BUF_SIZE];
   char **tdp_actions;
   char **stepping_actions;
   int ndx;
@@ -9370,154 +10149,205 @@ remote_download_tracepoint (struct breakpoint *t)
   struct agent_expr *aexpr;
   struct cleanup *aexpr_chain = NULL;
   char *pkt;
-
-  /* Iterate over all the tracepoint locations.  It's up to the target to
-     notice multiple tracepoint packets with the same number but different
-     addresses, and treat them as multiple locations.  */
-  for (loc = t->loc; loc; loc = loc->next)
-    {
-      encode_actions (t, loc, &tdp_actions, &stepping_actions);
-      old_chain = make_cleanup (free_actions_list_cleanup_wrapper,
-                               tdp_actions);
-      (void) make_cleanup (free_actions_list_cleanup_wrapper, stepping_actions);
-
-      tpaddr = loc->address;
-      sprintf_vma (addrbuf, tpaddr);
-      sprintf (buf, "QTDP:%x:%s:%c:%lx:%x", t->number, 
-              addrbuf, /* address */
-              (t->enable_state == bp_enabled ? 'E' : 'D'),
-              t->step_count, t->pass_count);
-      /* Fast tracepoints are mostly handled by the target, but we can
-        tell the target how big of an instruction block should be moved
-        around.  */
-      if (t->type == bp_fast_tracepoint)
+  struct breakpoint *b = loc->owner;
+  struct tracepoint *t = (struct tracepoint *) b;
+
+  encode_actions (loc->owner, loc, &tdp_actions, &stepping_actions);
+  old_chain = make_cleanup (free_actions_list_cleanup_wrapper,
+                           tdp_actions);
+  (void) make_cleanup (free_actions_list_cleanup_wrapper,
+                      stepping_actions);
+
+  tpaddr = loc->address;
+  sprintf_vma (addrbuf, tpaddr);
+  xsnprintf (buf, BUF_SIZE, "QTDP:%x:%s:%c:%lx:%x", b->number,
+            addrbuf, /* address */
+            (b->enable_state == bp_enabled ? 'E' : 'D'),
+            t->step_count, t->pass_count);
+  /* Fast tracepoints are mostly handled by the target, but we can
+     tell the target how big of an instruction block should be moved
+     around.  */
+  if (b->type == bp_fast_tracepoint)
+    {
+      /* Only test for support at download time; we may not know
+        target capabilities at definition time.  */
+      if (remote_supports_fast_tracepoints ())
        {
-         /* Only test for support at download time; we may not know
-            target capabilities at definition time.  */
-         if (remote_supports_fast_tracepoints ())
-           {
-             int isize;
+         int isize;
 
-             if (gdbarch_fast_tracepoint_valid_at (target_gdbarch,
-                                                   tpaddr, &isize, NULL))
-               sprintf (buf + strlen (buf), ":F%x", isize);
-             else
-               /* If it passed validation at definition but fails now,
-                  something is very wrong.  */
-               internal_error (__FILE__, __LINE__,
-                               "Fast tracepoint not valid during download");
-           }
+         if (gdbarch_fast_tracepoint_valid_at (target_gdbarch,
+                                               tpaddr, &isize, NULL))
+           xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":F%x",
+                      isize);
          else
-           /* Fast tracepoints are functionally identical to regular
-              tracepoints, so don't take lack of support as a reason to
-              give up on the trace run.  */
-           warning (_("Target does not support fast tracepoints, downloading %d as regular tracepoint"), t->number);
+           /* If it passed validation at definition but fails now,
+              something is very wrong.  */
+           internal_error (__FILE__, __LINE__,
+                           _("Fast tracepoint not "
+                             "valid during download"));
        }
-      /* If the tracepoint has a conditional, make it into an agent
-        expression and append to the definition.  */
-      if (loc->cond)
+      else
+       /* Fast tracepoints are functionally identical to regular
+          tracepoints, so don't take lack of support as a reason to
+          give up on the trace run.  */
+       warning (_("Target does not support fast tracepoints, "
+                  "downloading %d as regular tracepoint"), b->number);
+    }
+  else if (b->type == bp_static_tracepoint)
+    {
+      /* Only test for support at download time; we may not know
+        target capabilities at definition time.  */
+      if (remote_supports_static_tracepoints ())
        {
-         /* Only test support at download time, we may not know target
-            capabilities at definition time.  */
-         if (remote_supports_cond_tracepoints ())
-           {
-             aexpr = gen_eval_for_expr (tpaddr, loc->cond);
-             aexpr_chain = make_cleanup_free_agent_expr (aexpr);
-             sprintf (buf + strlen (buf), ":X%x,", aexpr->len);
-             pkt = buf + strlen (buf);
-             for (ndx = 0; ndx < aexpr->len; ++ndx)
-               pkt = pack_hex_byte (pkt, aexpr->buf[ndx]);
-             *pkt = '\0';
-             do_cleanups (aexpr_chain);
-           }
+         struct static_tracepoint_marker marker;
+
+         if (target_static_tracepoint_marker_at (tpaddr, &marker))
+           strcat (buf, ":S");
          else
-           warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t->number);
+           error (_("Static tracepoint not valid during download"));
+       }
+      else
+       /* Fast tracepoints are functionally identical to regular
+          tracepoints, so don't take lack of support as a reason
+          to give up on the trace run.  */
+       error (_("Target does not support static tracepoints"));
+    }
+  /* If the tracepoint has a conditional, make it into an agent
+     expression and append to the definition.  */
+  if (loc->cond)
+    {
+      /* Only test support at download time, we may not know target
+        capabilities at definition time.  */
+      if (remote_supports_cond_tracepoints ())
+       {
+         aexpr = gen_eval_for_expr (tpaddr, loc->cond);
+         aexpr_chain = make_cleanup_free_agent_expr (aexpr);
+         xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":X%x,",
+                    aexpr->len);
+         pkt = buf + strlen (buf);
+         for (ndx = 0; ndx < aexpr->len; ++ndx)
+           pkt = pack_hex_byte (pkt, aexpr->buf[ndx]);
+         *pkt = '\0';
+         do_cleanups (aexpr_chain);
        }
+      else
+       warning (_("Target does not support conditional tracepoints, "
+                  "ignoring tp %d cond"), b->number);
+    }
 
-  if (t->commands || *default_collect)
-       strcat (buf, "-");
-      putpkt (buf);
-      remote_get_noisy_reply (&target_buf, &target_buf_size);
-      if (strcmp (target_buf, "OK"))
-       error (_("Target does not support tracepoints."));
+  if (b->commands || *default_collect)
+    strcat (buf, "-");
+  putpkt (buf);
+  remote_get_noisy_reply (&target_buf, &target_buf_size);
+  if (strcmp (target_buf, "OK"))
+    error (_("Target does not support tracepoints."));
 
-      /* do_single_steps (t); */
-      if (tdp_actions)
+  /* do_single_steps (t); */
+  if (tdp_actions)
+    {
+      for (ndx = 0; tdp_actions[ndx]; ndx++)
        {
-         for (ndx = 0; tdp_actions[ndx]; ndx++)
-           {
-             QUIT;     /* allow user to bail out with ^C */
-             sprintf (buf, "QTDP:-%x:%s:%s%c",
-                      t->number, addrbuf, /* address */
-                      tdp_actions[ndx],
-                      ((tdp_actions[ndx + 1] || stepping_actions)
-                       ? '-' : 0));
-             putpkt (buf);
-             remote_get_noisy_reply (&target_buf,
-                                     &target_buf_size);
-             if (strcmp (target_buf, "OK"))
-               error (_("Error on target while setting tracepoints."));
-           }
+         QUIT; /* Allow user to bail out with ^C.  */
+         xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%c",
+                    b->number, addrbuf, /* address */
+                    tdp_actions[ndx],
+                    ((tdp_actions[ndx + 1] || stepping_actions)
+                     ? '-' : 0));
+         putpkt (buf);
+         remote_get_noisy_reply (&target_buf,
+                                 &target_buf_size);
+         if (strcmp (target_buf, "OK"))
+           error (_("Error on target while setting tracepoints."));
        }
-      if (stepping_actions)
+    }
+  if (stepping_actions)
+    {
+      for (ndx = 0; stepping_actions[ndx]; ndx++)
        {
-         for (ndx = 0; stepping_actions[ndx]; ndx++)
-           {
-             QUIT;     /* allow user to bail out with ^C */
-             sprintf (buf, "QTDP:-%x:%s:%s%s%s",
-                      t->number, addrbuf, /* address */
-                      ((ndx == 0) ? "S" : ""),
-                      stepping_actions[ndx],
-                      (stepping_actions[ndx + 1] ? "-" : ""));
-             putpkt (buf);
-             remote_get_noisy_reply (&target_buf,
-                                     &target_buf_size);
-             if (strcmp (target_buf, "OK"))
-               error (_("Error on target while setting tracepoints."));
-           }
+         QUIT; /* Allow user to bail out with ^C.  */
+         xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%s%s",
+                    b->number, addrbuf, /* address */
+                    ((ndx == 0) ? "S" : ""),
+                    stepping_actions[ndx],
+                    (stepping_actions[ndx + 1] ? "-" : ""));
+         putpkt (buf);
+         remote_get_noisy_reply (&target_buf,
+                                 &target_buf_size);
+         if (strcmp (target_buf, "OK"))
+           error (_("Error on target while setting tracepoints."));
        }
+    }
 
-      if (remote_protocol_packets[PACKET_TracepointSource].support == PACKET_ENABLE)
+  if (remote_protocol_packets[PACKET_TracepointSource].support
+      == PACKET_ENABLE)
+    {
+      if (b->addr_string)
        {
-         if (t->addr_string)
-           {
-             strcpy (buf, "QTDPsrc:");
-             encode_source_string (t->number, loc->address,
-                                   "at", t->addr_string, buf + strlen (buf),
-                                   2048 - strlen (buf));
+         strcpy (buf, "QTDPsrc:");
+         encode_source_string (b->number, loc->address,
+                               "at", b->addr_string, buf + strlen (buf),
+                               2048 - strlen (buf));
 
-             putpkt (buf);
-             remote_get_noisy_reply (&target_buf, &target_buf_size);
-             if (strcmp (target_buf, "OK"))
-               warning (_("Target does not support source download."));
-           }
-         if (t->cond_string)
-           {
-             strcpy (buf, "QTDPsrc:");
-             encode_source_string (t->number, loc->address,
-                                   "cond", t->cond_string, buf + strlen (buf),
-                                   2048 - strlen (buf));
-             putpkt (buf);
-             remote_get_noisy_reply (&target_buf, &target_buf_size);
-             if (strcmp (target_buf, "OK"))
-               warning (_("Target does not support source download."));
-           }
-         remote_download_command_source (t->number, loc->address,
-                                         breakpoint_commands (t));
+         putpkt (buf);
+         remote_get_noisy_reply (&target_buf, &target_buf_size);
+         if (strcmp (target_buf, "OK"))
+           warning (_("Target does not support source download."));
        }
-
-      do_cleanups (old_chain);
+      if (b->cond_string)
+       {
+         strcpy (buf, "QTDPsrc:");
+         encode_source_string (b->number, loc->address,
+                               "cond", b->cond_string, buf + strlen (buf),
+                               2048 - strlen (buf));
+         putpkt (buf);
+         remote_get_noisy_reply (&target_buf, &target_buf_size);
+         if (strcmp (target_buf, "OK"))
+           warning (_("Target does not support source download."));
+       }
+      remote_download_command_source (b->number, loc->address,
+                                     breakpoint_commands (b));
     }
+
+  do_cleanups (old_chain);
+}
+
+static int
+remote_can_download_tracepoint (void)
+{
+  struct remote_state *rs = get_remote_state ();
+  struct trace_status *ts;
+  int status;
+
+  /* Don't try to install tracepoints until we've relocated our
+     symbols, and fetched and merged the target's tracepoint list with
+     ours.  */
+  if (rs->starting_up)
+    return 0;
+
+  ts = current_trace_status ();
+  status = remote_get_trace_status (ts);
+
+  if (status == -1 || !ts->running_known || !ts->running)
+    return 0;
+
+  /* If we are in a tracing experiment, but remote stub doesn't support
+     installing tracepoint in trace, we have to return.  */
+  if (!remote_supports_install_in_trace ())
+    return 0;
+
+  return 1;
 }
 
+
 static void
 remote_download_trace_state_variable (struct trace_state_variable *tsv)
 {
   struct remote_state *rs = get_remote_state ();
   char *p;
 
-  sprintf (rs->buf, "QTDV:%x:%s:%x:",
-          tsv->number, phex ((ULONGEST) tsv->initial_value, 8), tsv->builtin);
+  xsnprintf (rs->buf, get_remote_packet_size (), "QTDV:%x:%s:%x:",
+            tsv->number, phex ((ULONGEST) tsv->initial_value, 8),
+            tsv->builtin);
   p = rs->buf + strlen (rs->buf);
   if ((p - rs->buf) + strlen (tsv->name) * 2 >= get_remote_packet_size ())
     error (_("Trace state variable name too long for tsv definition packet"));
@@ -9531,13 +10361,48 @@ remote_download_trace_state_variable (struct trace_state_variable *tsv)
     error (_("Error on target while downloading trace state variable."));
 }
 
+static void
+remote_enable_tracepoint (struct bp_location *location)
+{
+  struct remote_state *rs = get_remote_state ();
+  char addr_buf[40];
+
+  sprintf_vma (addr_buf, location->address);
+  xsnprintf (rs->buf, get_remote_packet_size (), "QTEnable:%x:%s",
+            location->owner->number, addr_buf);
+  putpkt (rs->buf);
+  remote_get_noisy_reply (&rs->buf, &rs->buf_size);
+  if (*rs->buf == '\0')
+    error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
+  if (strcmp (rs->buf, "OK") != 0)
+    error (_("Error on target while enabling tracepoint."));
+}
+
+static void
+remote_disable_tracepoint (struct bp_location *location)
+{
+  struct remote_state *rs = get_remote_state ();
+  char addr_buf[40];
+
+  sprintf_vma (addr_buf, location->address);
+  xsnprintf (rs->buf, get_remote_packet_size (), "QTDisable:%x:%s",
+            location->owner->number, addr_buf);
+  putpkt (rs->buf);
+  remote_get_noisy_reply (&rs->buf, &rs->buf_size);
+  if (*rs->buf == '\0')
+    error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
+  if (strcmp (rs->buf, "OK") != 0)
+    error (_("Error on target while disabling tracepoint."));
+}
+
 static void
 remote_trace_set_readonly_regions (void)
 {
   asection *s;
   bfd_size_type size;
-  bfd_vma lma;
+  bfd_vma vma;
   int anysecs = 0;
+  int offset = 0;
 
   if (!exec_bfd)
     return;                    /* No information to give.  */
@@ -9546,19 +10411,30 @@ remote_trace_set_readonly_regions (void)
   for (s = exec_bfd->sections; s; s = s->next)
     {
       char tmp1[40], tmp2[40];
+      int sec_length;
 
       if ((s->flags & SEC_LOAD) == 0 ||
-      /* (s->flags & SEC_CODE)     == 0 || */
+      /*  (s->flags & SEC_CODE) == 0 || */
          (s->flags & SEC_READONLY) == 0)
        continue;
 
       anysecs = 1;
-      lma = s->lma;
+      vma = bfd_get_section_vma (,s);
       size = bfd_get_section_size (s);
-      sprintf_vma (tmp1, lma);
-      sprintf_vma (tmp2, lma + size);
-      sprintf (target_buf + strlen (target_buf), 
-              ":%s,%s", tmp1, tmp2);
+      sprintf_vma (tmp1, vma);
+      sprintf_vma (tmp2, vma + size);
+      sec_length = 1 + strlen (tmp1) + 1 + strlen (tmp2);
+      if (offset + sec_length + 1 > target_buf_size)
+       {
+         if (remote_protocol_packets[PACKET_qXfer_traceframe_info].support
+             != PACKET_ENABLE)
+           warning (_("\
+Too many sections for read-only sections definition packet."));
+         break;
+       }
+      xsnprintf (target_buf + offset, target_buf_size - offset, ":%s,%s",
+                tmp1, tmp2);
+      offset += sec_length;
     }
   if (anysecs)
     {
@@ -9581,14 +10457,25 @@ remote_trace_start (void)
 static int
 remote_get_trace_status (struct trace_status *ts)
 {
-  char *p, *p1, *p_temp;
-  ULONGEST val;
-  /* FIXME we need to get register block size some other way */
+  /* Initialize it just to avoid a GCC false warning.  */
+  char *p = NULL;
+  /* FIXME we need to get register block size some other way */
   extern int trace_regblock_size;
+  volatile struct gdb_exception ex;
+
   trace_regblock_size = get_remote_arch_state ()->sizeof_g_packet;
 
   putpkt ("qTStatus");
-  p = remote_get_noisy_reply (&target_buf, &target_buf_size);
+
+  TRY_CATCH (ex, RETURN_MASK_ERROR)
+    {
+      p = remote_get_noisy_reply (&target_buf, &target_buf_size);
+    }
+  if (ex.reason < 0)
+    {
+      exception_fprintf (gdb_stderr, ex, "qTStatus: ");
+      return -1;
+    }
 
   /* If the remote target doesn't do tracing, flag it.  */
   if (*p == '\0')
@@ -9611,6 +10498,53 @@ remote_get_trace_status (struct trace_status *ts)
   return ts->running;
 }
 
+static void
+remote_get_tracepoint_status (struct breakpoint *bp,
+                             struct uploaded_tp *utp)
+{
+  struct remote_state *rs = get_remote_state ();
+  char *reply;
+  struct bp_location *loc;
+  struct tracepoint *tp = (struct tracepoint *) bp;
+  size_t size = get_remote_packet_size ();
+
+  if (tp)
+    {
+      tp->base.hit_count = 0;
+      tp->traceframe_usage = 0;
+      for (loc = tp->base.loc; loc; loc = loc->next)
+       {
+         /* If the tracepoint was never downloaded, don't go asking for
+            any status.  */
+         if (tp->number_on_target == 0)
+           continue;
+         xsnprintf (rs->buf, size, "qTP:%x:%s", tp->number_on_target,
+                    phex_nz (loc->address, 0));
+         putpkt (rs->buf);
+         reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
+         if (reply && *reply)
+           {
+             if (*reply == 'V')
+               parse_tracepoint_status (reply + 1, bp, utp);
+           }
+       }
+    }
+  else if (utp)
+    {
+      utp->hit_count = 0;
+      utp->traceframe_usage = 0;
+      xsnprintf (rs->buf, size, "qTP:%x:%s", utp->number,
+                phex_nz (utp->addr, 0));
+      putpkt (rs->buf);
+      reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
+      if (reply && *reply)
+       {
+         if (*reply == 'V')
+           parse_tracepoint_status (reply + 1, bp, utp);
+       }
+    }
+}
+
 static void
 remote_trace_stop (void)
 {
@@ -9628,31 +10562,40 @@ remote_trace_find (enum trace_find_type type, int num,
                   int *tpp)
 {
   struct remote_state *rs = get_remote_state ();
+  char *endbuf = rs->buf + get_remote_packet_size ();
   char *p, *reply;
   int target_frameno = -1, target_tracept = -1;
 
+  /* Lookups other than by absolute frame number depend on the current
+     trace selected, so make sure it is correct on the remote end
+     first.  */
+  if (type != tfind_number)
+    set_remote_traceframe ();
+
   p = rs->buf;
   strcpy (p, "QTFrame:");
   p = strchr (p, '\0');
   switch (type)
     {
     case tfind_number:
-      sprintf (p, "%x", num);
+      xsnprintf (p, endbuf - p, "%x", num);
       break;
     case tfind_pc:
-      sprintf (p, "pc:%s", phex_nz (addr1, 0));
+      xsnprintf (p, endbuf - p, "pc:%s", phex_nz (addr1, 0));
       break;
     case tfind_tp:
-      sprintf (p, "tdp:%x", num);
+      xsnprintf (p, endbuf - p, "tdp:%x", num);
       break;
     case tfind_range:
-      sprintf (p, "range:%s:%s", phex_nz (addr1, 0), phex_nz (addr2, 0));
+      xsnprintf (p, endbuf - p, "range:%s:%s", phex_nz (addr1, 0),
+                phex_nz (addr2, 0));
       break;
     case tfind_outside:
-      sprintf (p, "outside:%s:%s", phex_nz (addr1, 0), phex_nz (addr2, 0));
+      xsnprintf (p, endbuf - p, "outside:%s:%s", phex_nz (addr1, 0),
+                phex_nz (addr2, 0));
       break;
     default:
-      error ("Unknown trace find type %d", type);
+      error (_("Unknown trace find type %d"), type);
     }
 
   putpkt (rs->buf);
@@ -9668,6 +10611,8 @@ remote_trace_find (enum trace_find_type type, int num,
        target_frameno = (int) strtol (p, &reply, 16);
        if (reply == p)
          error (_("Unable to parse trace frame number"));
+       /* Don't update our remote traceframe number cache on failure
+          to select a remote traceframe.  */
        if (target_frameno == -1)
          return -1;
        break;
@@ -9688,6 +10633,8 @@ remote_trace_find (enum trace_find_type type, int num,
       }
   if (tpp)
     *tpp = target_tracept;
+
+  remote_traceframe_number = target_frameno;
   return target_frameno;
 }
 
@@ -9698,7 +10645,9 @@ remote_get_trace_state_variable_value (int tsvnum, LONGEST *val)
   char *reply;
   ULONGEST uval;
 
-  sprintf (rs->buf, "qTV:%x", tsvnum);
+  set_remote_traceframe ();
+
+  xsnprintf (rs->buf, get_remote_packet_size (), "qTV:%x", tsvnum);
   putpkt (rs->buf);
   reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
   if (reply && *reply)
@@ -9728,7 +10677,7 @@ remote_save_trace_data (const char *filename)
   *p++ = '\0';
   putpkt (rs->buf);
   reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
-  if (*reply != '\0')
+  if (*reply == '\0')
     error (_("Target does not support this command."));
   if (strcmp (reply, "OK") != 0)
     error (_("Bogus reply from target: %s"), reply);
@@ -9787,7 +10736,7 @@ remote_set_disconnected_tracing (int val)
     {
       char *reply;
 
-      sprintf (rs->buf, "QTDisconnected:%x", val);
+      xsnprintf (rs->buf, get_remote_packet_size (), "QTDisconnected:%x", val);
       putpkt (rs->buf);
       reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
       if (*reply == '\0')
@@ -9803,6 +10752,7 @@ static int
 remote_core_of_thread (struct target_ops *ops, ptid_t ptid)
 {
   struct thread_info *info = find_thread_ptid (ptid);
+
   if (info && info->private)
     return info->private->core;
   return -1;
@@ -9814,7 +10764,7 @@ remote_set_circular_trace_buffer (int val)
   struct remote_state *rs = get_remote_state ();
   char *reply;
 
-  sprintf (rs->buf, "QTBuffer:circular:%x", val);
+  xsnprintf (rs->buf, get_remote_packet_size (), "QTBuffer:circular:%x", val);
   putpkt (rs->buf);
   reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
   if (*reply == '\0')
@@ -9823,6 +10773,133 @@ remote_set_circular_trace_buffer (int val)
     error (_("Bogus reply from target: %s"), reply);
 }
 
+static struct traceframe_info *
+remote_traceframe_info (void)
+{
+  char *text;
+
+  text = target_read_stralloc (&current_target,
+                              TARGET_OBJECT_TRACEFRAME_INFO, NULL);
+  if (text != NULL)
+    {
+      struct traceframe_info *info;
+      struct cleanup *back_to = make_cleanup (xfree, text);
+
+      info = parse_traceframe_info (text);
+      do_cleanups (back_to);
+      return info;
+    }
+
+  return NULL;
+}
+
+/* Handle the qTMinFTPILen packet.  Returns the minimum length of
+   instruction on which a fast tracepoint may be placed.  Returns -1
+   if the packet is not supported, and 0 if the minimum instruction
+   length is unknown.  */
+
+static int
+remote_get_min_fast_tracepoint_insn_len (void)
+{
+  struct remote_state *rs = get_remote_state ();
+  char *reply;
+
+  /* If we're not debugging a process yet, the IPA can't be
+     loaded.  */
+  if (!target_has_execution)
+    return 0;
+
+  /* Make sure the remote is pointing at the right process.  */
+  set_general_process ();
+
+  xsnprintf (rs->buf, get_remote_packet_size (), "qTMinFTPILen");
+  putpkt (rs->buf);
+  reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
+  if (*reply == '\0')
+    return -1;
+  else
+    {
+      ULONGEST min_insn_len;
+
+      unpack_varlen_hex (reply, &min_insn_len);
+
+      return (int) min_insn_len;
+    }
+}
+
+static int
+remote_set_trace_notes (char *user, char *notes, char *stop_notes)
+{
+  struct remote_state *rs = get_remote_state ();
+  char *reply;
+  char *buf = rs->buf;
+  char *endbuf = rs->buf + get_remote_packet_size ();
+  int nbytes;
+
+  buf += xsnprintf (buf, endbuf - buf, "QTNotes:");
+  if (user)
+    {
+      buf += xsnprintf (buf, endbuf - buf, "user:");
+      nbytes = bin2hex (user, buf, 0);
+      buf += 2 * nbytes;
+      *buf++ = ';';
+    }
+  if (notes)
+    {
+      buf += xsnprintf (buf, endbuf - buf, "notes:");
+      nbytes = bin2hex (notes, buf, 0);
+      buf += 2 * nbytes;
+      *buf++ = ';';
+    }
+  if (stop_notes)
+    {
+      buf += xsnprintf (buf, endbuf - buf, "tstop:");
+      nbytes = bin2hex (stop_notes, buf, 0);
+      buf += 2 * nbytes;
+      *buf++ = ';';
+    }
+  /* Ensure the buffer is terminated.  */
+  *buf = '\0';
+
+  putpkt (rs->buf);
+  reply = remote_get_noisy_reply (&target_buf, &target_buf_size);
+  if (*reply == '\0')
+    return 0;
+
+  if (strcmp (reply, "OK") != 0)
+    error (_("Bogus reply from target: %s"), reply);
+
+  return 1;
+}
+
+static int
+remote_use_agent (int use)
+{
+  if (remote_protocol_packets[PACKET_QAgent].support != PACKET_DISABLE)
+    {
+      struct remote_state *rs = get_remote_state ();
+
+      /* If the stub supports QAgent.  */
+      xsnprintf (rs->buf, get_remote_packet_size (), "QAgent:%d", use);
+      putpkt (rs->buf);
+      getpkt (&rs->buf, &rs->buf_size, 0);
+
+      if (strcmp (rs->buf, "OK") == 0)
+       {
+         use_agent = use;
+         return 1;
+       }
+    }
+
+  return 0;
+}
+
+static int
+remote_can_use_agent (void)
+{
+  return (remote_protocol_packets[PACKET_QAgent].support != PACKET_DISABLE);
+}
+
 static void
 init_remote_ops (void)
 {
@@ -9847,14 +10924,20 @@ Specify the serial device it is connected to\n\
   remote_ops.to_remove_breakpoint = remote_remove_breakpoint;
   remote_ops.to_stopped_by_watchpoint = remote_stopped_by_watchpoint;
   remote_ops.to_stopped_data_address = remote_stopped_data_address;
+  remote_ops.to_watchpoint_addr_within_range =
+    remote_watchpoint_addr_within_range;
   remote_ops.to_can_use_hw_breakpoint = remote_check_watch_resources;
   remote_ops.to_insert_hw_breakpoint = remote_insert_hw_breakpoint;
   remote_ops.to_remove_hw_breakpoint = remote_remove_hw_breakpoint;
+  remote_ops.to_region_ok_for_hw_watchpoint
+     = remote_region_ok_for_hw_watchpoint;
   remote_ops.to_insert_watchpoint = remote_insert_watchpoint;
   remote_ops.to_remove_watchpoint = remote_remove_watchpoint;
   remote_ops.to_kill = remote_kill;
   remote_ops.to_load = generic_load;
   remote_ops.to_mourn_inferior = remote_mourn;
+  remote_ops.to_pass_signals = remote_pass_signals;
+  remote_ops.to_program_signals = remote_program_signals;
   remote_ops.to_thread_alive = remote_thread_alive;
   remote_ops.to_find_new_threads = remote_threads_info;
   remote_ops.to_pid_to_str = remote_pid_to_str;
@@ -9871,7 +10954,7 @@ Specify the serial device it is connected to\n\
   remote_ops.to_has_stack = default_child_has_stack;
   remote_ops.to_has_registers = default_child_has_registers;
   remote_ops.to_has_execution = default_child_has_execution;
-  remote_ops.to_has_thread_control = tc_schedlock;     /* can lock scheduler */
+  remote_ops.to_has_thread_control = tc_schedlock;    /* can lock scheduler */
   remote_ops.to_can_execute_reverse = remote_can_execute_reverse;
   remote_ops.to_magic = OPS_MAGIC;
   remote_ops.to_memory_map = remote_memory_map;
@@ -9882,28 +10965,56 @@ Specify the serial device it is connected to\n\
   remote_ops.to_can_async_p = remote_can_async_p;
   remote_ops.to_is_async_p = remote_is_async_p;
   remote_ops.to_async = remote_async;
-  remote_ops.to_async_mask = remote_async_mask;
   remote_ops.to_terminal_inferior = remote_terminal_inferior;
   remote_ops.to_terminal_ours = remote_terminal_ours;
   remote_ops.to_supports_non_stop = remote_supports_non_stop;
   remote_ops.to_supports_multi_process = remote_supports_multi_process;
+  remote_ops.to_supports_disable_randomization
+    = remote_supports_disable_randomization;
+  remote_ops.to_fileio_open = remote_hostio_open;
+  remote_ops.to_fileio_pwrite = remote_hostio_pwrite;
+  remote_ops.to_fileio_pread = remote_hostio_pread;
+  remote_ops.to_fileio_close = remote_hostio_close;
+  remote_ops.to_fileio_unlink = remote_hostio_unlink;
+  remote_ops.to_fileio_readlink = remote_hostio_readlink;
+  remote_ops.to_supports_enable_disable_tracepoint = remote_supports_enable_disable_tracepoint;
+  remote_ops.to_supports_string_tracing = remote_supports_string_tracing;
+  remote_ops.to_supports_evaluation_of_breakpoint_conditions = remote_supports_cond_breakpoints;
   remote_ops.to_trace_init = remote_trace_init;
   remote_ops.to_download_tracepoint = remote_download_tracepoint;
-  remote_ops.to_download_trace_state_variable = remote_download_trace_state_variable;
+  remote_ops.to_can_download_tracepoint = remote_can_download_tracepoint;
+  remote_ops.to_download_trace_state_variable
+    = remote_download_trace_state_variable;
+  remote_ops.to_enable_tracepoint = remote_enable_tracepoint;
+  remote_ops.to_disable_tracepoint = remote_disable_tracepoint;
   remote_ops.to_trace_set_readonly_regions = remote_trace_set_readonly_regions;
   remote_ops.to_trace_start = remote_trace_start;
   remote_ops.to_get_trace_status = remote_get_trace_status;
+  remote_ops.to_get_tracepoint_status = remote_get_tracepoint_status;
   remote_ops.to_trace_stop = remote_trace_stop;
   remote_ops.to_trace_find = remote_trace_find;
-  remote_ops.to_get_trace_state_variable_value = remote_get_trace_state_variable_value;
+  remote_ops.to_get_trace_state_variable_value
+    = remote_get_trace_state_variable_value;
   remote_ops.to_save_trace_data = remote_save_trace_data;
   remote_ops.to_upload_tracepoints = remote_upload_tracepoints;
-  remote_ops.to_upload_trace_state_variables = remote_upload_trace_state_variables;
+  remote_ops.to_upload_trace_state_variables
+    = remote_upload_trace_state_variables;
   remote_ops.to_get_raw_trace_data = remote_get_raw_trace_data;
+  remote_ops.to_get_min_fast_tracepoint_insn_len = remote_get_min_fast_tracepoint_insn_len;
   remote_ops.to_set_disconnected_tracing = remote_set_disconnected_tracing;
   remote_ops.to_set_circular_trace_buffer = remote_set_circular_trace_buffer;
+  remote_ops.to_set_trace_notes = remote_set_trace_notes;
   remote_ops.to_core_of_thread = remote_core_of_thread;
   remote_ops.to_verify_memory = remote_verify_memory;
+  remote_ops.to_get_tib_address = remote_get_tib_address;
+  remote_ops.to_set_permissions = remote_set_permissions;
+  remote_ops.to_static_tracepoint_marker_at
+    = remote_static_tracepoint_marker_at;
+  remote_ops.to_static_tracepoint_markers_by_strid
+    = remote_static_tracepoint_markers_by_strid;
+  remote_ops.to_traceframe_info = remote_traceframe_info;
+  remote_ops.to_use_agent = remote_use_agent;
+  remote_ops.to_can_use_agent = remote_can_use_agent;
 }
 
 /* Set up the extended remote vector by making a copy of the standard
@@ -9926,6 +11037,8 @@ Specify the serial device it is connected to (e.g. /dev/ttya).";
   extended_remote_ops.to_detach = extended_remote_detach;
   extended_remote_ops.to_attach = extended_remote_attach;
   extended_remote_ops.to_kill = extended_remote_kill;
+  extended_remote_ops.to_supports_disable_randomization
+    = extended_remote_supports_disable_randomization;
 }
 
 static int
@@ -9936,7 +11049,7 @@ remote_can_async_p (void)
     return 0;
 
   /* We're async whenever the serial device is.  */
-  return remote_async_mask_value && serial_can_async_p (remote_desc);
+  return serial_can_async_p (remote_desc);
 }
 
 static int
@@ -9947,7 +11060,7 @@ remote_is_async_p (void)
     return 0;
 
   /* We're async whenever the serial device is.  */
-  return remote_async_mask_value && serial_is_async_p (remote_desc);
+  return serial_is_async_p (remote_desc);
 }
 
 /* Pass the SERIAL event on and up to the client.  One day this code
@@ -9983,10 +11096,6 @@ static void
 remote_async (void (*callback) (enum inferior_event_type event_type,
                                void *context), void *context)
 {
-  if (remote_async_mask_value == 0)
-    internal_error (__FILE__, __LINE__,
-                   _("Calling remote_async when async is masked"));
-
   if (callback != NULL)
     {
       serial_async (remote_desc, remote_async_serial_handler, NULL);
@@ -9997,14 +11106,6 @@ remote_async (void (*callback) (enum inferior_event_type event_type,
     serial_async (remote_desc, NULL, NULL);
 }
 
-static int
-remote_async_mask (int new_mask)
-{
-  int curr_mask = remote_async_mask_value;
-  remote_async_mask_value = new_mask;
-  return curr_mask;
-}
-
 static void
 set_remote_cmd (char *args, int from_tty)
 {
@@ -10018,6 +11119,7 @@ show_remote_cmd (char *args, int from_tty)
      the redundant "show remote Z-packet" and the legacy aliases.  */
   struct cleanup *showlist_chain;
   struct cmd_list_element *list = remote_show_cmdlist;
+  struct ui_out *uiout = current_uiout;
 
   showlist_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "showlist");
   for (; list != NULL; list = list->next)
@@ -10031,6 +11133,7 @@ show_remote_cmd (char *args, int from_tty)
       {
        struct cleanup *option_chain
          = make_cleanup_ui_out_tuple_begin_end (uiout, "option");
+
        ui_out_field_string (uiout, "name", list->name);
        ui_out_text (uiout, ":  ");
        if (list->type == show_cmd)
@@ -10135,7 +11238,7 @@ _initialize_remote (void)
   sigint_remote_token =
     create_async_signal_handler (async_remote_interrupt, NULL);
   sigint_remote_twice_token =
-    create_async_signal_handler (inferior_event_handler_wrapper, NULL);
+    create_async_signal_handler (async_remote_interrupt_twice, NULL);
 
 #if 0
   init_remote_threadtests ();
@@ -10184,7 +11287,8 @@ If set, a break, instead of a cntrl-c, is sent to the remote target."),
   deprecate_cmd (cmd, "show remote interrupt-sequence");
 
   add_setshow_enum_cmd ("interrupt-sequence", class_support,
-                       interrupt_sequence_modes, &interrupt_sequence_mode, _("\
+                       interrupt_sequence_modes, &interrupt_sequence_mode,
+                       _("\
 Set interrupt sequence to remote target."), _("\
 Show interrupt sequence to remote target."), _("\
 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
@@ -10238,14 +11342,27 @@ further restriction and ``limit'' to enable that restriction."),
 Set the maximum number of target hardware watchpoints."), _("\
 Show the maximum number of target hardware watchpoints."), _("\
 Specify a negative limit for unlimited."),
-                           NULL, NULL, /* FIXME: i18n: The maximum number of target hardware watchpoints is %s.  */
+                           NULL, NULL, /* FIXME: i18n: The maximum
+                                          number of target hardware
+                                          watchpoints is %s.  */
+                           &remote_set_cmdlist, &remote_show_cmdlist);
+  add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class,
+                           &remote_hw_watchpoint_length_limit, _("\
+Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
+Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
+Specify a negative limit for unlimited."),
+                           NULL, NULL, /* FIXME: i18n: The maximum
+                                           length (in bytes) of a target
+                                           hardware watchpoint is %s.  */
                            &remote_set_cmdlist, &remote_show_cmdlist);
   add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class,
                            &remote_hw_breakpoint_limit, _("\
 Set the maximum number of target hardware breakpoints."), _("\
 Show the maximum number of target hardware breakpoints."), _("\
 Specify a negative limit for unlimited."),
-                           NULL, NULL, /* FIXME: i18n: The maximum number of target hardware breakpoints is %s.  */
+                           NULL, NULL, /* FIXME: i18n: The maximum
+                                          number of target hardware
+                                          breakpoints is %s.  */
                            &remote_set_cmdlist, &remote_show_cmdlist);
 
   add_setshow_integer_cmd ("remoteaddresssize", class_obscure,
@@ -10265,6 +11382,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
   add_packet_config_cmd (&remote_protocol_packets[PACKET_QPassSignals],
                         "QPassSignals", "pass-signals", 0);
 
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_QProgramSignals],
+                        "QProgramSignals", "program-signals", 0);
+
   add_packet_config_cmd (&remote_protocol_packets[PACKET_qSymbol],
                         "qSymbol", "symbol-lookup", 0);
 
@@ -10298,6 +11418,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
   add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_libraries],
                         "qXfer:libraries:read", "library-info", 0);
 
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_libraries_svr4],
+                        "qXfer:libraries-svr4:read", "library-info-svr4", 0);
+
   add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_memory_map],
                         "qXfer:memory-map:read", "memory-map", 0);
 
@@ -10319,10 +11442,21 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
   add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_siginfo_write],
                          "qXfer:siginfo:write", "write-siginfo-object", 0);
 
+  add_packet_config_cmd
+    (&remote_protocol_packets[PACKET_qXfer_traceframe_info],
+     "qXfer:trace-frame-info:read", "traceframe-info", 0);
+
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_uib],
+                        "qXfer:uib:read", "unwind-info-block", 0);
+
   add_packet_config_cmd (&remote_protocol_packets[PACKET_qGetTLSAddr],
                         "qGetTLSAddr", "get-thread-local-storage-address",
                         0);
 
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_qGetTIBAddr],
+                        "qGetTIBAddr", "get-thread-information-block-address",
+                        0);
+
   add_packet_config_cmd (&remote_protocol_packets[PACKET_bc],
                         "bc", "reverse-continue", 0);
 
@@ -10350,6 +11484,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
   add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_unlink],
                         "vFile:unlink", "hostio-unlink", 0);
 
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_readlink],
+                        "vFile:readlink", "hostio-readlink", 0);
+
   add_packet_config_cmd (&remote_protocol_packets[PACKET_vAttach],
                         "vAttach", "attach", 0);
 
@@ -10366,13 +11503,40 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
                         "qAttached", "query-attached", 0);
 
   add_packet_config_cmd (&remote_protocol_packets[PACKET_ConditionalTracepoints],
-                        "ConditionalTracepoints", "conditional-tracepoints", 0);
+                        "ConditionalTracepoints",
+                        "conditional-tracepoints", 0);
+
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_ConditionalBreakpoints],
+                        "ConditionalBreakpoints",
+                        "conditional-breakpoints", 0);
+
   add_packet_config_cmd (&remote_protocol_packets[PACKET_FastTracepoints],
                         "FastTracepoints", "fast-tracepoints", 0);
 
   add_packet_config_cmd (&remote_protocol_packets[PACKET_TracepointSource],
                         "TracepointSource", "TracepointSource", 0);
 
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_QAllow],
+                        "QAllow", "allow", 0);
+
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_StaticTracepoints],
+                        "StaticTracepoints", "static-tracepoints", 0);
+
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_InstallInTrace],
+                        "InstallInTrace", "install-in-trace", 0);
+
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_statictrace_read],
+                         "qXfer:statictrace:read", "read-sdata-object", 0);
+
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_fdpic],
+                        "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
+
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_QDisableRandomization],
+                        "QDisableRandomization", "disable-randomization", 0);
+
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_QAgent],
+                        "QAgent", "agent", 0);
+
   /* Keep the old ``set remote Z-packet ...'' working.  Each individual
      Z sub-packet has its own set and show commands, but users may
      have sets to this variable in their .gdbinit files (or in their
@@ -10384,7 +11548,9 @@ Show use of remote protocol `Z' packets "), _("\
 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
 packets."),
                                set_remote_protocol_Z_packet_cmd,
-                               show_remote_protocol_Z_packet_cmd, /* FIXME: i18n: Use of remote protocol `Z' packets is %s.  */
+                               show_remote_protocol_Z_packet_cmd,
+                               /* FIXME: i18n: Use of remote protocol
+                                  `Z' packets is %s.  */
                                &remote_set_cmdlist, &remote_show_cmdlist);
 
   add_prefix_cmd ("remote", class_files, remote_command, _("\
This page took 0.082379 seconds and 4 git commands to generate.