This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 2/3 v2] Implement vFile:fstat: packet in gdbserver
- From: Gary Benson <gbenson at redhat dot com>
- To: gdb-patches at sourceware dot org
- Cc: Pedro Alves <palves at redhat dot com>, Eli Zaretskii <eliz at gnu dot org>
- Date: Wed, 11 Mar 2015 10:33:49 +0000
- Subject: [PATCH 2/3 v2] Implement vFile:fstat: packet in gdbserver
- Authentication-results: sourceware.org; auth=none
- References: <54FF3878 dot 8050202 at redhat dot com>
Eli, could you please review the qSupported part of the docs in
this patch? The remainder of the patch is unchanged from the
patch you previously approved.
Thanks,
Gary
---
This patch adds a new packet "vFile:fstat:" to gdbserver.
This can be used by clients to retrieve information about
open files.
gdb/ChangeLog:
* NEWS: Announce new vFile:fstat packet.
gdb/doc/ChangeLog:
* gdb.texinfo (Host I/O Packets): Document the vFile:fstat
packet.
(General Query Packets): Document the vFile:fstat qSupported
features.
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/ChangeLog | 4 ++++
gdb/NEWS | 3 +++
gdb/doc/ChangeLog | 7 +++++++
gdb/doc/gdb.texinfo | 15 +++++++++++++++
gdb/gdbserver/ChangeLog | 9 +++++++++
gdb/gdbserver/hostio.c | 41 +++++++++++++++++++++++++++++++++++++++++
gdb/gdbserver/server.c | 2 ++
7 files changed, 81 insertions(+), 0 deletions(-)
diff --git a/gdb/NEWS b/gdb/NEWS
index 49dc0e6..f08f972 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -73,6 +73,9 @@ hwbreak stop reason
Indicates the target stopped for a hardware breakpoint. This is
required for correct non-stop mode operation.
+vFile:fstat:
+ Return information about files on the remote system.
+
* The info record command now shows the recording format and the
branch tracing configuration for the current thread when using
the btrace record target.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 1ee1346..b197c1f 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -36062,6 +36062,11 @@ These are the currently defined stub features and their properties:
@tab @samp{-}
@tab No
+@item @samp{vFile:fstat}
+@tab No
+@tab @samp{-}
+@tab Yes
+
@end multitable
These are the currently defined stub features, in more detail:
@@ -36250,6 +36255,9 @@ breakpoints.
The remote stub reports the @samp{hwbreak} stop reason for hardware
breakpoints.
+@item vFile:fstat
+The remote stub understands the @samp{vFile:fstat} packet.
+
@end table
@item qSymbol::
@@ -37411,6 +37419,13 @@ packet is used. @samp{vFile:write} returns the number of bytes written,
which may be shorter than the length of @var{data}, or -1 if an
error occurred.
+@item vFile:fstat: @var{fd}
+Get information about the open file corresponding to @var{fd}.
+On success the information is returned as a binary attachment
+and the return value is the size of this attachment in bytes.
+If an error occurs the return value is -1. The format of the
+returned binary attachment is as described in @ref{struct stat}.
+
@item vFile:unlink: @var{filename}
Delete the file at @var{filename} on the target. Return 0,
or -1 if an error occurs. The @var{filename} is a string.
diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c
index ec29eb9..cc0192b 100644
--- a/gdb/gdbserver/hostio.c
+++ b/gdb/gdbserver/hostio.c
@@ -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;
@@ -412,6 +415,42 @@ handle_pwrite (char *own_buf, int packet_len)
}
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))
+ sprintf (own_buf, "F-1,%x", FILEIO_ENOSYS);
+}
+
+static void
handle_close (char *own_buf)
{
int fd, ret;
@@ -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:"))
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 4189877..4d8faa3 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -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;
}
--
1.7.1