Assertion 'xfered>0' in target.c for remote connection

Message ID aa1105df36e944a19ba2129fdef8ea22@SVR-ORW-MBX-04.mgc.mentorg.com
State New, archived
Headers

Commit Message

Carroll, Paul Nov. 3, 2017, 8:36 p.m. UTC
  Thanks for your comments, Sergio.
Sadly, I had to manually put the tabs into my patch here, but it looks correct now.
I also removed the TARGET_XFER_OK/TARGET_XFER_EOF test in remote_read_bytes, for the reasons you noted.
The TARGET_XFER_UNAVAILABLE/TARGET_XFER_EOF test is still necessary in case 0 bytes is returned by remote_read_bytes_1.
Some of the added tests are for writing blocks, rather than reading blocks.
It is possible that these returns are not needed, but it seems safer to just cover all of the returns.
  

Patch

diff -rup fsf/gdb/ChangeLog fix/gdb/ChangeLog
--- fsf/gdb/ChangeLog	2017-11-02 16:13:19.188615000 -0500
+++ fix/gdb/ChangeLog	2017-11-02 16:13:21.626754500 -0500
@@ -1,3 +1,10 @@ 
+2017-11-02  Paul Carroll  <pcarroll@codesourcery.com>
+
+	PR gdb/22388
+	* remote.c (remote_write_bytes_aux, remote_read_bytes_1,
+	remote_read_bytes, remote_write_qxfer, remote_xfer_partial):
+	Return TARGET_XFER_EOF if size of returned data is 0.
+
 2017-11-02  Yao Qi  <yao.qi@linaro.org>

 	* frame.c (do_frame_register_read): Remove aspace.
diff -rup fsf/gdb/remote.c fix/gdb/remote.c
--- fsf/gdb/remote.c	2017-11-02 16:06:15.979408800 -0500
+++ fix/gdb/remote.c	2017-11-03 13:01:04.953135100 -0500
@@ -8264,7 +8264,7 @@  remote_write_bytes_aux (const char *head
   /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
      send fewer units than we'd planned.  */
   *xfered_len_units = (ULONGEST) units_written;
-  return TARGET_XFER_OK;
+  return (*xfered_len_units != 0) ? TARGET_XFER_OK : TARGET_XFER_EOF;
 }

 /* Write memory data directly to the remote machine.
@@ -8358,7 +8358,7 @@  remote_read_bytes_1 (CORE_ADDR memaddr,
   decoded_bytes = hex2bin (p, myaddr, todo_units * unit_size);
   /* Return what we have.  Let higher layers handle partial reads.  */
   *xfered_len_units = (ULONGEST) (decoded_bytes / unit_size);
-  return TARGET_XFER_OK;
+  return (*xfered_len_units != 0) ? TARGET_XFER_OK : TARGET_XFER_EOF;
 }

 /* Using the set of read-only target sections of remote, read live
@@ -8461,7 +8461,8 @@  remote_read_bytes (struct target_ops *op
 		  /* No use trying further, we know some memory starting
 		     at MEMADDR isn't available.  */
 		  *xfered_len = len;
-		  return TARGET_XFER_UNAVAILABLE;
+		  return (*xfered_len != 0) ?
+		    TARGET_XFER_UNAVAILABLE : TARGET_XFER_EOF;
 		}
 	    }

@@ -10386,7 +10387,7 @@  remote_write_qxfer (struct target_ops *o
   unpack_varlen_hex (rs->buf, &n);

   *xfered_len = n;
-  return TARGET_XFER_OK;
+  return (*xfered_len != 0) ? TARGET_XFER_OK : TARGET_XFER_EOF;
 }

 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
@@ -10687,7 +10688,7 @@  remote_xfer_partial (struct target_ops *
   strcpy ((char *) readbuf, rs->buf);

   *xfered_len = strlen ((char *) readbuf);
-  return TARGET_XFER_OK;
+  return (*xfered_len != 0) ? TARGET_XFER_OK : TARGET_XFER_EOF;
 }

 /* Implementation of to_get_memory_xfer_limit.  */