#include "exceptions.h"
#include "remote-fileio.h"
#include "event-loop.h"
+#include "target.h"
#include <fcntl.h>
#include <sys/time.h>
remote_fileio_reply (retcode, 0);
}
-/* Wrapper function for remote_write_bytes() which has the disadvantage to
- write only one packet, regardless of the requested number of bytes to
- transfer. This wrapper calls remote_write_bytes() as often as needed. */
-static int
-remote_fileio_write_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
-{
- int ret = 0, written;
-
- while (len > 0 && (written = remote_write_bytes (memaddr, myaddr, len)) > 0)
- {
- len -= written;
- memaddr += written;
- myaddr += written;
- ret += written;
- }
- return ret;
-}
-
static void
remote_fileio_func_open (char *buf)
{
CORE_ADDR ptrval;
- int length, retlength;
+ int length;
long num;
int flags, fd;
mode_t mode;
}
mode = remote_fileio_mode_to_host (num, 1);
- /* Request pathname using 'm' packet. */
+ /* Request pathname. */
pathname = alloca (length);
- retlength = remote_read_bytes (ptrval, (gdb_byte *) pathname, length);
- if (retlength != length)
+ if (target_read_memory (ptrval, (gdb_byte *) pathname, length) != 0)
{
remote_fileio_ioerror ();
return;
if (ret > 0)
{
- retlength = remote_fileio_write_bytes (ptrval, buffer, ret);
- if (retlength != ret)
- ret = -1; /* errno has been set to EIO in
- remote_fileio_write_bytes(). */
+ errno = target_write_memory (ptrval, buffer, ret);
+ if (errno != 0)
+ ret = -1;
}
if (ret < 0)
long target_fd, num;
LONGEST lnum;
CORE_ADDR ptrval;
- int fd, ret, retlength;
+ int fd, ret;
gdb_byte *buffer;
size_t length;
length = (size_t) num;
buffer = (gdb_byte *) xmalloc (length);
- retlength = remote_read_bytes (ptrval, buffer, length);
- if (retlength != length)
+ if (target_read_memory (ptrval, buffer, length) != 0)
{
xfree (buffer);
remote_fileio_ioerror ();
remote_fileio_func_rename (char *buf)
{
CORE_ADDR old_ptr, new_ptr;
- int old_len, new_len, retlength;
+ int old_len, new_len;
char *oldpath, *newpath;
int ret, of, nf;
struct stat ost, nst;
/* Request oldpath using 'm' packet */
oldpath = alloca (old_len);
- retlength = remote_read_bytes (old_ptr, (gdb_byte *) oldpath, old_len);
- if (retlength != old_len)
+ if (target_read_memory (old_ptr, (gdb_byte *) oldpath, old_len) != 0)
{
remote_fileio_ioerror ();
return;
/* Request newpath using 'm' packet */
newpath = alloca (new_len);
- retlength = remote_read_bytes (new_ptr, (gdb_byte *) newpath, new_len);
- if (retlength != new_len)
+ if (target_read_memory (new_ptr, (gdb_byte *) newpath, new_len) != 0)
{
remote_fileio_ioerror ();
return;
remote_fileio_func_unlink (char *buf)
{
CORE_ADDR ptrval;
- int length, retlength;
+ int length;
char *pathname;
int ret;
struct stat st;
}
/* Request pathname using 'm' packet */
pathname = alloca (length);
- retlength = remote_read_bytes (ptrval, (gdb_byte *) pathname, length);
- if (retlength != length)
+ if (target_read_memory (ptrval, (gdb_byte *) pathname, length) != 0)
{
remote_fileio_ioerror ();
return;
remote_fileio_func_stat (char *buf)
{
CORE_ADDR statptr, nameptr;
- int ret, namelength, retlength;
+ int ret, namelength;
char *pathname;
LONGEST lnum;
struct stat st;
/* Request pathname using 'm' packet */
pathname = alloca (namelength);
- retlength = remote_read_bytes (nameptr, (gdb_byte *) pathname, namelength);
- if (retlength != namelength)
+ if (target_read_memory (nameptr, (gdb_byte *) pathname, namelength) != 0)
{
remote_fileio_ioerror ();
return;
{
remote_fileio_to_fio_stat (&st, &fst);
remote_fileio_to_fio_uint (0, fst.fst_dev);
-
- retlength = remote_fileio_write_bytes (statptr,
- (gdb_byte *) &fst, sizeof fst);
- if (retlength != sizeof fst)
+
+ errno = target_write_memory (statptr, (gdb_byte *) &fst, sizeof fst);
+ if (errno != 0)
{
remote_fileio_return_errno (-1);
return;
{
remote_fileio_to_fio_stat (&st, &fst);
- retlength = remote_fileio_write_bytes (ptrval, (gdb_byte *) &fst,
- sizeof fst);
- if (retlength != sizeof fst)
+ errno = target_write_memory (ptrval, (gdb_byte *) &fst, sizeof fst);
+ if (errno != 0)
{
remote_fileio_return_errno (-1);
return;
{
remote_fileio_to_fio_timeval (&tv, &ftv);
- retlength = remote_fileio_write_bytes (ptrval, (gdb_byte *) &ftv,
- sizeof ftv);
- if (retlength != sizeof ftv)
+ errno = target_write_memory (ptrval, (gdb_byte *) &ftv, sizeof ftv);
+ if (errno != 0)
{
remote_fileio_return_errno (-1);
return;
{
/* Request commandline using 'm' packet */
cmdline = alloca (length);
- retlength = remote_read_bytes (ptrval, (gdb_byte *) cmdline, length);
- if (retlength != length)
+ if (target_read_memory (ptrval, (gdb_byte *) cmdline, length) != 0)
{
remote_fileio_ioerror ();
return;
Returns number of bytes transferred, or 0 (setting errno) for
error. Only transfer a single packet. */
-int
+static int
remote_write_bytes (CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
{
char *packet_format = 0;
Returns number of bytes transferred, or 0 for error. */
-/* NOTE: cagney/1999-10-18: This function (and its siblings in other
- remote targets) shouldn't attempt to read the entire buffer.
- Instead it should read a single packet worth of data and then
- return the byte size of that packet to the caller. The caller (its
- caller and its callers caller ;-) already contains code for
- handling partial reads. */
-
-int
+static int
remote_read_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
{
struct remote_state *rs = get_remote_state ();
int max_buf_size; /* Max size of packet output buffer. */
- int origlen;
+ char *p;
+ int todo;
+ int i;
if (len <= 0)
return 0;
/* The packet buffer will be large enough for the payload;
get_memory_packet_size ensures this. */
- origlen = len;
- while (len > 0)
- {
- char *p;
- int todo;
- int i;
+ /* Number if bytes that will fit. */
+ todo = min (len, max_buf_size / 2);
- todo = min (len, max_buf_size / 2); /* num bytes that will fit. */
-
- /* construct "m"<memaddr>","<len>" */
- /* sprintf (rs->buf, "m%lx,%x", (unsigned long) memaddr, todo); */
- 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')
- {
- /* There is no correspondance between what the remote
- protocol uses for errors and errno codes. We would like
- a cleaner way of representing errors (big enough to
- include errno codes, bfd_error codes, and others). But
- for now just return EIO. */
- errno = EIO;
- return 0;
- }
-
- /* Reply describes memory byte by byte,
- each byte encoded as two hex characters. */
-
- p = rs->buf;
- if ((i = hex2bin (p, myaddr, todo)) < todo)
- {
- /* Reply is short. This means that we were able to read
- only part of what we wanted to. */
- return i + (origlen - len);
- }
- myaddr += todo;
- memaddr += todo;
- len -= todo;
+ /* 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')
+ {
+ /* There is no correspondance between what the remote protocol
+ uses for errors and errno codes. We would like a cleaner way
+ of representing errors (big enough to include errno codes,
+ bfd_error codes, and others). But for now just return
+ EIO. */
+ errno = EIO;
+ return 0;
}
- return origlen;
+ /* 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. */
+ return i;
}
\f