From a257b5bbf7a6dc411e3b2602e485e114f88d8203 Mon Sep 17 00:00:00 2001 From: Andrew Cagney Date: Mon, 30 Jun 2003 15:50:52 +0000 Subject: 2003-06-30 Andrew Cagney * 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 | 6 ++++++ gdb/remote.c | 45 ++++++++++++++++++++++++++------------------- 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 + * 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 + * remote.c (remote_async_wait): Fix -Wformat problem. 2003-06-29 Andrew Cagney 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,:#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,:...#nn". */ + payload_size = (get_memory_write_packet_size () - (strlen ("$M,:#NN") + + hexnumlen (memaddr) + + hexnumlen (len))); - /* construct "M"","":" */ - /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */ - p = buf; + /* Construct the packet header: "[MX],:". */ - /* 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 */ + /* Append "". */ memaddr = remote_address_masked (memaddr); p += hexnumstr (p, (ULONGEST) memaddr); + + /* Append ",". */ *p++ = ','; - /* Append . Retain the location/size of . It may - need to be adjusted once the packet body has been created. */ + /* Append . Retain the location/size of . 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() */ } -- cgit v1.1