Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <yao@codesourcery.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH 2/3] Factor remote_read_bytes.
Date: Tue, 11 Mar 2014 12:45:00 -0000	[thread overview]
Message-ID: <1394541731-27486-2-git-send-email-yao@codesourcery.com> (raw)
In-Reply-To: <1394541731-27486-1-git-send-email-yao@codesourcery.com>

This patch moves code in remote_read_bytes on reading from the remote
stub to a new function remote_read_bytes_1.

gdb:

2014-03-11  Yao Qi  <yao@codesourcery.com>

	* remote.c (remote_read_bytes): Move code on reading from the
	remote stub to ...
	(remote_read_bytes_1): ... here.  New function.
---
 gdb/remote.c |   97 ++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 54 insertions(+), 43 deletions(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index afe9d12..b5c6b4b 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -6824,6 +6824,56 @@ remote_write_bytes (CORE_ADDR memaddr, const gdb_byte *myaddr, ULONGEST len,
 				 packet_format[0], 1);
 }
 
+/* Read memory data directly from the remote machine.
+   This does not use the data cache; the data cache uses this.
+   MEMADDR is the address in the remote memory space.
+   MYADDR is the address of the buffer in our space.
+   LEN is the number of bytes.
+
+   Return the transferred status, error or OK (an
+   'enum target_xfer_status' value).  Save the number of bytes
+   transferred in *XFERED_LEN.  */
+
+static enum target_xfer_status
+remote_read_bytes_1 (CORE_ADDR memaddr, gdb_byte *myaddr, ULONGEST len,
+		     ULONGEST *xfered_len)
+{
+  struct remote_state *rs = get_remote_state ();
+  int max_buf_size;		/* Max size of packet output buffer.  */
+  char *p;
+  int todo;
+  int i;
+
+  max_buf_size = get_memory_read_packet_size ();
+  /* The packet buffer will be large enough for the payload;
+     get_memory_packet_size ensures this.  */
+
+  /* Number if bytes that will fit.  */
+  todo = min (len, max_buf_size / 2);
+
+  /* Construct "m"<memaddr>","<len>".  */
+  memaddr = remote_address_masked (memaddr);
+  p = rs->buf;
+  *p++ = 'm';
+  p += hexnumstr (p, (ULONGEST) memaddr);
+  *p++ = ',';
+  p += hexnumstr (p, (ULONGEST) todo);
+  *p = '\0';
+  putpkt (rs->buf);
+  getpkt (&rs->buf, &rs->buf_size, 0);
+  if (rs->buf[0] == 'E'
+      && isxdigit (rs->buf[1]) && isxdigit (rs->buf[2])
+      && rs->buf[3] == '\0')
+    return TARGET_XFER_E_IO;
+  /* Reply describes memory byte by byte, each byte encoded as two hex
+     characters.  */
+  p = rs->buf;
+  i = hex2bin (p, myaddr, todo);
+  /* Return what we have.  Let higher layers handle partial reads.  */
+  *xfered_len = (ULONGEST) i;
+  return TARGET_XFER_OK;
+}
+
 /* Read memory from the live target, even if currently inspecting a
    traceframe.  The return is the same as that of target_read.  */
 
@@ -6905,26 +6955,14 @@ memory_xfer_live_readonly_partial (struct target_ops *ops,
   return TARGET_XFER_EOF;
 }
 
-/* Read memory data directly from the remote machine.
-   This does not use the data cache; the data cache uses this.
-   MEMADDR is the address in the remote memory space.
-   MYADDR is the address of the buffer in our space.
-   LEN is the number of bytes.
-
-   Return the transferred status, error or OK (an
-   'enum target_xfer_status' value).  Save the number of bytes
-   transferred in *XFERED_LEN.  */
+/* Similar to remote_read_bytes_1, but it reads from the remote stub
+   first if the requested memory is unavailable in traceframe.
+   Otherwise, fall back to remote_read_bytes_1.  */
 
 static enum target_xfer_status
 remote_read_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, ULONGEST len,
 		   ULONGEST *xfered_len)
 {
-  struct remote_state *rs = get_remote_state ();
-  int max_buf_size;		/* Max size of packet output buffer.  */
-  char *p;
-  int todo;
-  int i;
-
   if (len == 0)
     return 0;
 
@@ -6985,34 +7023,7 @@ remote_read_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, ULONGEST len,
 	}
     }
 
-  max_buf_size = get_memory_read_packet_size ();
-  /* The packet buffer will be large enough for the payload;
-     get_memory_packet_size ensures this.  */
-
-  /* Number if bytes that will fit.  */
-  todo = min (len, max_buf_size / 2);
-
-  /* Construct "m"<memaddr>","<len>".  */
-  memaddr = remote_address_masked (memaddr);
-  p = rs->buf;
-  *p++ = 'm';
-  p += hexnumstr (p, (ULONGEST) memaddr);
-  *p++ = ',';
-  p += hexnumstr (p, (ULONGEST) todo);
-  *p = '\0';
-  putpkt (rs->buf);
-  getpkt (&rs->buf, &rs->buf_size, 0);
-  if (rs->buf[0] == 'E'
-      && isxdigit (rs->buf[1]) && isxdigit (rs->buf[2])
-      && rs->buf[3] == '\0')
-    return TARGET_XFER_E_IO;
-  /* Reply describes memory byte by byte, each byte encoded as two hex
-     characters.  */
-  p = rs->buf;
-  i = hex2bin (p, myaddr, todo);
-  /* Return what we have.  Let higher layers handle partial reads.  */
-  *xfered_len = (ULONGEST) i;
-  return TARGET_XFER_OK;
+  return remote_read_bytes_1 (memaddr, myaddr, len, xfered_len);
 }
 
 \f
-- 
1.7.7.6


  reply	other threads:[~2014-03-11 12:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-11 12:44 [PATCH 1/3] Move the traceframe_available_memory code from memory_xfer_partial_1 down to the targets Yao Qi
2014-03-11 12:45 ` Yao Qi [this message]
2014-03-21 11:57   ` [PATCH 2/3] Factor remote_read_bytes Pedro Alves
2014-03-11 12:45 ` [PATCH 3/3] Remove target_read_live_memory Yao Qi
2014-03-21 12:01   ` Pedro Alves
2014-03-22 11:23     ` Yao Qi
2014-03-21  9:41 ` [PATCH 1/3] Move the traceframe_available_memory code from memory_xfer_partial_1 down to the targets Yao Qi
2014-03-21 11:56 ` Pedro Alves
2014-03-22 11:20   ` Yao Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1394541731-27486-2-git-send-email-yao@codesourcery.com \
    --to=yao@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox