aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>2003-06-30 15:50:52 +0000
committerAndrew Cagney <cagney@redhat.com>2003-06-30 15:50:52 +0000
commita257b5bbf7a6dc411e3b2602e485e114f88d8203 (patch)
treed76953a61f5adb6f8ebf122d9b1c9dd4994ca3d2
parent0a2cfde49a830b432ff218be3580938e52438fbd (diff)
downloadbinutils-a257b5bbf7a6dc411e3b2602e485e114f88d8203.zip
binutils-a257b5bbf7a6dc411e3b2602e485e114f88d8203.tar.gz
binutils-a257b5bbf7a6dc411e3b2602e485e114f88d8203.tar.bz2
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.
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/remote.c45
2 files changed, 32 insertions, 19 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ffb7530..2edf938 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
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.
2003-06-29 Andrew Cagney <cagney@redhat.com>
diff --git a/gdb/remote.c b/gdb/remote.c
index 9ccb3a5..75e1e08 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -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() */
}