From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 33378 invoked by alias); 11 Mar 2015 10:33:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 33022 invoked by uid 89); 11 Mar 2015 10:33:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 11 Mar 2015 10:33:53 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2BAXpdJ031277 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 11 Mar 2015 06:33:51 -0400 Received: from blade.nx (ovpn-116-85.ams2.redhat.com [10.36.116.85]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2BAXoAU001202; Wed, 11 Mar 2015 06:33:50 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 71006265071; Wed, 11 Mar 2015 10:33:49 +0000 (GMT) From: Gary Benson To: gdb-patches@sourceware.org Cc: Pedro Alves , Eli Zaretskii Subject: [PATCH 2/3 v2] Implement vFile:fstat: packet in gdbserver Date: Wed, 11 Mar 2015 10:33:00 -0000 Message-Id: <1426070029-969-1-git-send-email-gbenson@redhat.com> In-Reply-To: <54FF3878.8050202@redhat.com> References: <54FF3878.8050202@redhat.com> X-IsSubscribed: yes X-SW-Source: 2015-03/txt/msg00275.txt.bz2 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 #include #include +#include +#include +#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