Fix spurious FAILs with examine-backward.exp
[deliverable/binutils-gdb.git] / gdb / remote.c
index 837b9ee5124e8ac3f4e3a55279adae49c790be19..2f34c4c300f0f529bd726358ff980622459753dd 100644 (file)
@@ -283,6 +283,11 @@ typedef unsigned char threadref[OPAQUETHREADBYTES];
 
 #define MAXTHREADLISTRESULTS 32
 
+/* The max number of chars in debug output.  The rest of chars are
+   omitted.  */
+
+#define REMOTE_DEBUG_MAX_CHAR 512
+
 /* Data for the vFile:pread readahead cache.  */
 
 struct readahead_cache
@@ -6306,7 +6311,7 @@ remote_console_output (char *msg)
 typedef struct cached_reg
 {
   int num;
-  gdb_byte data[MAX_REGISTER_SIZE];
+  gdb_byte *data;
 } cached_reg_t;
 
 DEF_VEC_O(cached_reg_t);
@@ -6402,6 +6407,13 @@ static void
 stop_reply_dtr (struct notif_event *event)
 {
   struct stop_reply *r = (struct stop_reply *) event;
+  cached_reg_t *reg;
+  int ix;
+
+  for (ix = 0;
+       VEC_iterate (cached_reg_t, r->regcache, ix, reg);
+       ix++)
+    xfree (reg->data);
 
   VEC_free (cached_reg_t, r->regcache);
 }
@@ -6974,6 +6986,7 @@ Packet: '%s'\n"),
                {
                  struct packet_reg *reg = packet_reg_from_pnum (rsa, pnum);
                  cached_reg_t cached_reg;
+                 struct gdbarch *gdbarch = target_gdbarch ();
 
                  if (reg == NULL)
                    error (_("Remote sent bad register number %s: %s\n\
@@ -6981,14 +6994,14 @@ Packet: '%s'\n"),
                           hex_string (pnum), p, buf);
 
                  cached_reg.num = reg->regnum;
+                 cached_reg.data = (gdb_byte *)
+                   xmalloc (register_size (gdbarch, reg->regnum));
 
                  p = p1 + 1;
                  fieldsize = hex2bin (p, cached_reg.data,
-                                      register_size (target_gdbarch (),
-                                                     reg->regnum));
+                                      register_size (gdbarch, reg->regnum));
                  p += 2 * fieldsize;
-                 if (fieldsize < register_size (target_gdbarch (),
-                                                reg->regnum))
+                 if (fieldsize < register_size (gdbarch, reg->regnum))
                    warning (_("Remote reply is too short: %s"), buf);
 
                  VEC_safe_push (cached_reg_t, event->regcache, &cached_reg);
@@ -7209,9 +7222,13 @@ process_stop_reply (struct stop_reply *stop_reply,
          int ix;
 
          for (ix = 0;
-              VEC_iterate(cached_reg_t, stop_reply->regcache, ix, reg);
+              VEC_iterate (cached_reg_t, stop_reply->regcache, ix, reg);
               ix++)
+         {
            regcache_raw_supply (regcache, reg->num, reg->data);
+           xfree (reg->data);
+         }
+
          VEC_free (cached_reg_t, stop_reply->regcache);
        }
 
@@ -7462,9 +7479,10 @@ remote_wait (struct target_ops *ops,
 static int
 fetch_register_using_p (struct regcache *regcache, struct packet_reg *reg)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
   struct remote_state *rs = get_remote_state ();
   char *buf, *p;
-  char regp[MAX_REGISTER_SIZE];
+  gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
   int i;
 
   if (packet_support (PACKET_p) == PACKET_DISABLE)
@@ -7741,7 +7759,6 @@ remote_prepare_to_store (struct target_ops *self, struct regcache *regcache)
 {
   struct remote_arch_state *rsa = get_remote_arch_state ();
   int i;
-  gdb_byte buf[MAX_REGISTER_SIZE];
 
   /* Make sure the entire registers array is valid.  */
   switch (packet_support (PACKET_P))
@@ -7751,7 +7768,7 @@ remote_prepare_to_store (struct target_ops *self, struct regcache *regcache)
       /* Make sure all the necessary registers are cached.  */
       for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
        if (rsa->regs[i].in_g_packet)
-         regcache_raw_read (regcache, rsa->regs[i].regnum, buf);
+         regcache_raw_update (regcache, rsa->regs[i].regnum);
       break;
     case PACKET_ENABLE:
       break;
@@ -7769,7 +7786,7 @@ store_register_using_P (const struct regcache *regcache,
   struct remote_state *rs = get_remote_state ();
   /* Try storing a single register.  */
   char *buf = rs->buf;
-  gdb_byte regp[MAX_REGISTER_SIZE];
+  gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
   char *p;
 
   if (packet_support (PACKET_P) == PACKET_DISABLE)
@@ -8656,16 +8673,10 @@ remote_send (char **buf,
 static std::string
 escape_buffer (const char *buf, int n)
 {
-  struct cleanup *old_chain;
-  struct ui_file *stb;
+  string_file stb;
 
-  stb = mem_fileopen ();
-  old_chain = make_cleanup_ui_file_delete (stb);
-
-  fputstrn_unfiltered (buf, n, '\\', stb);
-  std::string str = ui_file_as_string (stb);
-  do_cleanups (old_chain);
-  return str;
+  stb.putstrn (buf, n, '\\');
+  return std::move (stb.string ());
 }
 
 /* Display a null-terminated packet on stdout, for debugging, using C
@@ -8749,9 +8760,21 @@ putpkt_binary (const char *buf, int cnt)
        {
          *p = '\0';
 
-         std::string str = escape_buffer (buf2, p - buf2);
+         int len = (int) (p - buf2);
+
+         std::string str
+           = escape_buffer (buf2, std::min (len, REMOTE_DEBUG_MAX_CHAR));
+
+         fprintf_unfiltered (gdb_stdlog, "Sending packet: %s", str.c_str ());
+
+         if (str.length () > REMOTE_DEBUG_MAX_CHAR)
+           {
+             fprintf_unfiltered (gdb_stdlog, "[%zu bytes omitted]",
+                                 str.length () - REMOTE_DEBUG_MAX_CHAR);
+           }
+
+         fprintf_unfiltered (gdb_stdlog, "...");
 
-         fprintf_unfiltered (gdb_stdlog, "Sending packet: %s...", str.c_str ());
          gdb_flush (gdb_stdlog);
        }
       remote_serial_write (buf2, p - buf2);
@@ -9179,9 +9202,20 @@ getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever,
        {
          if (remote_debug)
            {
-             std::string str = escape_buffer (*buf, val);
+             std::string str
+               = escape_buffer (*buf,
+                                std::min (val, REMOTE_DEBUG_MAX_CHAR));
+
+             fprintf_unfiltered (gdb_stdlog, "Packet received: %s",
+                                 str.c_str ());
+
+             if (str.length () >  REMOTE_DEBUG_MAX_CHAR)
+               {
+                 fprintf_unfiltered (gdb_stdlog, "[%zu bytes omitted]",
+                                     str.length () - REMOTE_DEBUG_MAX_CHAR);
+               }
 
-             fprintf_unfiltered (gdb_stdlog, "Packet received: %s\n", str.c_str ());
+             fprintf_unfiltered (gdb_stdlog, "\n");
            }
 
          /* Skip the ack char if we're in no-ack mode.  */
@@ -9630,11 +9664,9 @@ remote_add_target_side_condition (struct gdbarch *gdbarch,
   xsnprintf (buf, buf_end - buf, "%s", ";");
   buf++;
 
-  /* Send conditions to the target and free the vector.  */
-  for (int ix = 0; ix < bp_tgt->conditions.size (); ix++)
+  /* Send conditions to the target.  */
+  for (agent_expr *aexpr : bp_tgt->conditions)
     {
-      struct agent_expr *aexpr = bp_tgt->conditions[ix];
-
       xsnprintf (buf, buf_end - buf, "X%x,", aexpr->len);
       buf += strlen (buf);
       for (int i = 0; i < aexpr->len; ++i)
@@ -9658,10 +9690,8 @@ remote_add_target_side_commands (struct gdbarch *gdbarch,
 
   /* Concatenate all the agent expressions that are commands into the
      cmds parameter.  */
-  for (int ix = 0; ix < bp_tgt->tcommands.size (); ix++)
+  for (agent_expr *aexpr : bp_tgt->tcommands)
     {
-      struct agent_expr *aexpr = bp_tgt->tcommands[ix];
-
       sprintf (buf, "X%x,", aexpr->len);
       buf += strlen (buf);
       for (int i = 0; i < aexpr->len; ++i)
@@ -13653,8 +13683,9 @@ remote_can_async_p (struct target_ops *ops)
 {
   struct remote_state *rs = get_remote_state ();
 
+  /* We don't go async if the user has explicitly prevented it with the
+     "maint set target-async" command.  */
   if (!target_async_permitted)
-    /* We only enable async when the user specifically asks for it.  */
     return 0;
 
   /* We're async whenever the serial device is.  */
This page took 0.030915 seconds and 4 git commands to generate.