X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fgdbserver%2Fhostio.c;h=b03b5ad11bf831b4e14445d70ddadd83add11b48;hb=7823a9415b2919241f7a7425d9dcc3c62ada0779;hp=a74c2f880dff76369dbdd8da20b954759b05357c;hpb=d5749ee7156fa25f5c649d1288f074cbdd40303c;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c index a74c2f880d..b03b5ad11b 100644 --- a/gdb/gdbserver/hostio.c +++ b/gdb/gdbserver/hostio.c @@ -1,5 +1,5 @@ /* Host file transfer support for gdbserver. - Copyright (C) 2007-2013 Free Software Foundation, Inc. + Copyright (C) 2007-2015 Free Software Foundation, Inc. Contributed by CodeSourcery. @@ -20,10 +20,14 @@ #include "server.h" #include "gdb/fileio.h" +#include "hostio.h" #include #include #include +#include +#include +#include "fileio.h" extern int remote_debug; @@ -410,6 +414,42 @@ handle_pwrite (char *own_buf, int packet_len) free (data); } +static void +handle_fstat (char *own_buf, int *new_packet_len) +{ + int fd, bytes_sent; + char *p; + struct stat st; + struct fio_stat fst; + + p = own_buf + strlen ("vFile:fstat:"); + + if (require_int (&p, &fd) + || require_valid_fd (fd) + || require_end (p)) + { + hostio_packet_error (own_buf); + return; + } + + if (fstat (fd, &st) == -1) + { + hostio_error (own_buf); + return; + } + + host_to_fileio_stat (&st, &fst); + + bytes_sent = hostio_reply_with_data (own_buf, + (char *) &fst, sizeof (fst), + new_packet_len); + + /* If the response does not fit into a single packet, do not attempt + to return a partial response, but simply fail. */ + if (bytes_sent < sizeof (fst)) + write_enn (own_buf); +} + static void handle_close (char *own_buf) { @@ -477,7 +517,6 @@ handle_unlink (char *own_buf) static void handle_readlink (char *own_buf, int *new_packet_len) { -#if defined (HAVE_READLINK) char filename[HOSTIO_PATH_MAX], linkname[HOSTIO_PATH_MAX]; char *p; int ret, bytes_sent; @@ -504,9 +543,6 @@ handle_readlink (char *own_buf, int *new_packet_len) to return a partial response, but simply fail. */ if (bytes_sent < ret) sprintf (own_buf, "F-1,%x", FILEIO_ENAMETOOLONG); -#else /* ! HAVE_READLINK */ - sprintf (own_buf, "F-1,%x", FILEIO_ENOSYS); -#endif } /* Handle all the 'F' file transfer packets. */ @@ -514,17 +550,19 @@ handle_readlink (char *own_buf, int *new_packet_len) int handle_vFile (char *own_buf, int packet_len, int *new_packet_len) { - if (strncmp (own_buf, "vFile:open:", 11) == 0) + if (startswith (own_buf, "vFile:open:")) handle_open (own_buf); - else if (strncmp (own_buf, "vFile:pread:", 11) == 0) + else if (startswith (own_buf, "vFile:pread:")) handle_pread (own_buf, new_packet_len); - else if (strncmp (own_buf, "vFile:pwrite:", 12) == 0) + else if (startswith (own_buf, "vFile:pwrite:")) handle_pwrite (own_buf, packet_len); - else if (strncmp (own_buf, "vFile:close:", 12) == 0) + else if (startswith (own_buf, "vFile:fstat:")) + handle_fstat (own_buf, new_packet_len); + else if (startswith (own_buf, "vFile:close:")) handle_close (own_buf); - else if (strncmp (own_buf, "vFile:unlink:", 13) == 0) + else if (startswith (own_buf, "vFile:unlink:")) handle_unlink (own_buf); - else if (strncmp (own_buf, "vFile:readlink:", 15) == 0) + else if (startswith (own_buf, "vFile:readlink:")) handle_readlink (own_buf, new_packet_len); else return 0;