Implement vFile:fstat: in gdbserver
authorGary Benson <gbenson@redhat.com>
Wed, 11 Mar 2015 17:53:57 +0000 (17:53 +0000)
committerGary Benson <gbenson@redhat.com>
Wed, 11 Mar 2015 17:53:57 +0000 (17:53 +0000)
This commit implements the "vFile:fstat:" packet in gdbserver.

gdb/gdbserver/ChangeLog:

* hostio.c (sys/types.h): New include.
(sys/stat.h): Likewise.
(common-remote-fileio.h): Likewise.
(handle_fstat): New function.
(handle_vFile): Handle vFile:fstat packets.
* server.c (handle_query): Report vFile:fstat as supported.

gdb/gdbserver/ChangeLog
gdb/gdbserver/hostio.c
gdb/gdbserver/server.c

index 1a57867ee2267cce77771839c30682ca330ffd63..6b0492a54c285d86ce48c87477f7284efd7d932f 100644 (file)
@@ -1,3 +1,12 @@
+2015-03-11  Gary Benson  <gbenson@redhat.com>
+
+       * hostio.c (sys/types.h): New include.
+       (sys/stat.h): Likewise.
+       (common-remote-fileio.h): Likewise.
+       (handle_fstat): New function.
+       (handle_vFile): Handle vFile:fstat packets.
+       * server.c (handle_query): Report vFile:fstat as supported.
+
 2015-03-11  Gary Benson  <gbenson@redhat.com>
 
        * configure.ac (AC_CHECK_MEMBERS): Add checks for
index ec29eb9d2d4630a5de399d41dace8b82359dfa17..aa659e24745dc965d6498a73e984c442122c7ac8 100644 (file)
@@ -25,6 +25,9 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "common-remote-fileio.h"
 
 extern int remote_debug;
 
@@ -411,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;
+    }
+
+  remote_fileio_to_fio_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)
 {
@@ -517,6 +556,8 @@ handle_vFile (char *own_buf, int packet_len, int *new_packet_len)
     handle_pread (own_buf, new_packet_len);
   else if (startswith (own_buf, "vFile:pwrite:"))
     handle_pwrite (own_buf, packet_len);
+  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 (startswith (own_buf, "vFile:unlink:"))
index 08dbb60710eb2b68eba93fd0b17619077d3d2e49..9ff2f8ef7d4db9bb840634729deaa4521fb636e5 100644 (file)
@@ -2082,6 +2082,8 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       if (target_supports_stopped_by_hw_breakpoint ())
        strcat (own_buf, ";hwbreak+");
 
+      strcat (own_buf, ";vFile:fstat+");
+
       return;
     }