2003-06-30 Andrew Cagney <cagney@redhat.com>
authorAndrew Cagney <cagney@redhat.com>
Mon, 30 Jun 2003 15:50:52 +0000 (15:50 +0000)
committerAndrew Cagney <cagney@redhat.com>
Mon, 30 Jun 2003 15:50:52 +0000 (15:50 +0000)
* remote.c (remote_write_bytes): Explicitly compute and then use
the payload size.  Update comments to reflect.  Fixes problem of
GDB not sending small packets as found by Fred Fish.

gdb/ChangeLog
gdb/remote.c

index ffb75307a44f0ba2edd49e046c3b6e7e1f9c8516..2edf938cd21bd4a66eaeb614a306fa4be86938b2 100644 (file)
@@ -1,3 +1,9 @@
+2003-06-30  Andrew Cagney  <cagney@redhat.com>
+
+       * remote.c (remote_write_bytes): Explicitly compute and then use
+       the payload size.  Update comments to reflect.  Fixes problem of
+       GDB not sending small packets as found by Fred Fish.
+
 2003-06-30  Andrew Cagney  <cagney@redhat.com>
 
        * remote.c (remote_async_wait): Fix -Wformat problem.
index 9ccb3a5225ca826342feb4330ec844c431fb50f1..75e1e08ea37833e1a359432c1ca240771552648b 100644 (file)
@@ -3758,42 +3758,45 @@ int
 remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
 {
   unsigned char *buf;
-  int max_buf_size;            /* Max size of packet output buffer */
   unsigned char *p;
   unsigned char *plen;
   long sizeof_buf;
   int plenlen;
   int todo;
   int nr_bytes;
+  int payload_size;
+  unsigned char *payload_start;
 
-  /* Verify that the target can support a binary download */
+  /* Verify that the target can support a binary download */
   check_binary_download (memaddr);
 
-  /* Determine the max packet size. */
-  max_buf_size = get_memory_write_packet_size ();
-  sizeof_buf = max_buf_size + 1; /* Space for trailing NUL */
+  /* Compute the size, and then allocate space for the largest
+     possible packet.  Include space for an extra trailing NUL.  */
+  sizeof_buf = get_memory_write_packet_size () + 1;
   buf = alloca (sizeof_buf);
 
-  /* Subtract header overhead from max payload size -  $M<memaddr>,<len>:#nn */
-  max_buf_size -= 2 + hexnumlen (memaddr + len - 1) + 1 + hexnumlen (len) + 4;
+  /* Compute the size of the actual payload by subtracting out the
+     packet header and footer overhead: "$M<memaddr>,<len>:...#nn".  */
+  payload_size = (get_memory_write_packet_size () - (strlen ("$M,:#NN")
+                                                    + hexnumlen (memaddr)
+                                                    + hexnumlen (len)));
 
-  /* construct "M"<memaddr>","<len>":" */
-  /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
-  p = buf;
+  /* Construct the packet header: "[MX]<memaddr>,<len>:".   */
 
-  /* Append [XM].  Compute a best guess of the number of bytes
+  /* Append "[XM]".  Compute a best guess of the number of bytes
      actually transfered. */
+  p = buf;
   switch (remote_protocol_binary_download.support)
     {
     case PACKET_ENABLE:
       *p++ = 'X';
       /* Best guess at number of bytes that will fit. */
-      todo = min (len, max_buf_size);
+      todo = min (len, payload_size);
       break;
     case PACKET_DISABLE:
       *p++ = 'M';
       /* num bytes that will fit */
-      todo = min (len, max_buf_size / 2);
+      todo = min (len, payload_size / 2);
       break;
     case PACKET_SUPPORT_UNKNOWN:
       internal_error (__FILE__, __LINE__,
@@ -3802,20 +3805,25 @@ remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
       internal_error (__FILE__, __LINE__, "bad switch");
     }
   
-  /* Append <memaddr> */
+  /* Append "<memaddr>".  */
   memaddr = remote_address_masked (memaddr);
   p += hexnumstr (p, (ULONGEST) memaddr);
+
+  /* Append ",".  */
   *p++ = ',';
   
-  /* Append <len>.  Retain the location/size of <len>.  It may
-     need to be adjusted once the packet body has been created. */
+  /* Append <len>.  Retain the location/size of <len>.  It may need to
+     be adjusted once the packet body has been created.  */
   plen = p;
   plenlen = hexnumstr (p, (ULONGEST) todo);
   p += plenlen;
+
+  /* Append ":".  */
   *p++ = ':';
   *p = '\0';
   
-  /* Append the packet body. */
+  /* Append the packet body.  */
+  payload_start = p;
   switch (remote_protocol_binary_download.support)
     {
     case PACKET_ENABLE:
@@ -3823,7 +3831,7 @@ remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
         increasing byte addresses.  Only escape certain critical
         characters.  */
       for (nr_bytes = 0;
-          (nr_bytes < todo) && (p - buf) < (max_buf_size - 2);
+          (nr_bytes < todo) && (p - payload_start) < payload_size;
           nr_bytes++)
        {
          switch (myaddr[nr_bytes] & 0xff)
@@ -3846,7 +3854,6 @@ remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
             and we have actually sent fewer bytes than planned.
             Fix-up the length field of the packet.  Use the same
             number of characters as before.  */
-         
          plen += hexnumnstr (plen, (ULONGEST) nr_bytes, plenlen);
          *plen = ':';  /* overwrite \0 from hexnumnstr() */
        }
This page took 0.039507 seconds and 4 git commands to generate.