From patchwork Thu Apr 16 12:19:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 6256 Received: (qmail 25167 invoked by alias); 16 Apr 2015 12:27:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 25143 invoked by uid 89); 16 Apr 2015 12:27:21 -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, SPF_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; Thu, 16 Apr 2015 12:27:19 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id C9F408EFC9 for ; Thu, 16 Apr 2015 12:19:56 +0000 (UTC) Received: from blade.nx (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3GCJtg8021147 for ; Thu, 16 Apr 2015 08:19:56 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 4DCB1264113 for ; Thu, 16 Apr 2015 13:19:54 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Subject: [PATCH 6/7] Implement multiple-filesystem support for remote targets Date: Thu, 16 Apr 2015 13:19:50 +0100 Message-Id: <1429186791-6867-7-git-send-email-gbenson@redhat.com> In-Reply-To: <1429186791-6867-1-git-send-email-gbenson@redhat.com> References: <1429186791-6867-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes This commit allows GDB to access executables and shared libraries on remote targets where the inferior and the remote stub do not share a common filesystem. A new packet "vFile:setfs" is added to the remote protocol and the three remote hostio functions with filename arguments are modified to send "vFile:setfs" packets as necessary. gdb/ChangeLog: * remote.c (struct remote_state) : New field. (new_remote_state): Initialize the above. (PACKET_vFile_setfs): New enum value. (remote_fs_pid): New static variable. (remote_hostio_set_fs_deferred): New function. (remote_hostio_set_filesystem): Likewise. (remote_hostio_open): Call the above. (remote_hostio_unlink): Likewise. (remote_hostio_readlink): Likewise. (init_remote_ops): Initialize to_fileio_set_fs. (_initialize_remote): Register new "set/show remote hostio-setfs-packet" command. * NEWS: Mention that GDB and gdbserver support attaching to processes in different mount namespaces on GNU/Linux systems. Announce new vFile:setfs packet. gdb/doc/ChangeLog: * gdb.texinfo (Remote Configuration): Document the "set/show remote hostio-setfs-packet" command. (Host I/O Packets): Document the vFile:setfs packet. --- gdb/ChangeLog | 18 +++++++++++++++ gdb/NEWS | 8 +++++++ gdb/doc/ChangeLog | 6 +++++ gdb/doc/gdb.texinfo | 11 +++++++++ gdb/remote.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 0 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 62cbdcb..a9f05e4 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -42,6 +42,10 @@ (no "set sysroot" or "file" commands are required). See "New remote packets" below. +* GDB and gdbserver now support attaching to processes running in + different mount namespaces from the debugger on GNU/Linux systems. + See "New remote packets" below. + * Python Scripting ** gdb.Objfile objects have a new attribute "username", @@ -116,6 +120,10 @@ qXfer:exec-file:read Return the full absolute name of the file that was executed to create a process running on the remote system. +vFile:setfs: + Set the filesystem accessed by vFile: packets with filename + arguments. + * 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 e7872dd..fc0f4b1 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -19889,6 +19889,10 @@ are: @tab @code{vFile:fstat} @tab Host I/O +@item @code{hostio-setfs-packet} +@tab @code{vFile:setfs} +@tab Host I/O + @item @code{noack-packet} @tab @code{QStartNoAckMode} @tab Packet acknowledgment @@ -37533,6 +37537,13 @@ An empty response indicates that this operation is not recognized. These are the supported Host I/O operations: @table @samp +@item vFile:setfs: @var{pid} +Set the filesystem accessed by @code{vFile} packets with +@var{filename} arguments to the filesystem as seen by process +@var{pid}. If @var{pid} is zero, set the filesystem to that +seen by the remote stub. Return 0 on success, or -1 if an +error occurs. + @item vFile:open: @var{filename}, @var{flags}, @var{mode} Open a file at @var{filename} and return a file descriptor for it, or return -1 if an error occurs. The @var{filename} is a string, diff --git a/gdb/remote.c b/gdb/remote.c index 3b2325f..3202871 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -367,6 +367,12 @@ struct remote_state /* The branch trace configuration. */ struct btrace_config btrace_config; + + /* The argument to the last "vFile:setfs:" packet we sent, used + to avoid sending repeated unnecessary "vFile:setfs:" packets. + Initialized to -1 to indicate that no "vFile:setfs:" packet + has yet been sent. */ + int fs_pid; }; /* Private data that we'll store in (struct thread_info)->private. */ @@ -409,6 +415,7 @@ new_remote_state (void) result->buf = xmalloc (result->buf_size); result->remote_traceframe_number = -1; result->last_sent_signal = GDB_SIGNAL_0; + result->fs_pid = -1; return result; } @@ -1243,6 +1250,7 @@ enum { PACKET_Z2, PACKET_Z3, PACKET_Z4, + PACKET_vFile_setfs, PACKET_vFile_open, PACKET_vFile_pread, PACKET_vFile_pwrite, @@ -9879,6 +9887,46 @@ remote_hostio_send_command (int command_bytes, int which_packet, return ret; } +/* Process ID of inferior whose filesystem remote_hostio functions + that take FILENAME arguments will use. Zero means to use the + remote stub's filesystem. */ + +static int remote_fs_pid = 0; + +/* Implementation of to_fileio_set_fs. */ + +static void +remote_hostio_set_fs_deferred (struct target_ops *self, int pid) +{ + remote_fs_pid = pid; +} + +/* Set the filesystem remote_hostio functions that take FILENAME + arguments will use. */ + +static void +remote_hostio_set_filesystem (void) +{ + struct remote_state *rs = get_remote_state (); + + if (rs->fs_pid == -1 || remote_fs_pid != rs->fs_pid) + { + char *p = rs->buf; + int left = get_remote_packet_size () - 1; + int remote_errno; + char arg[9]; + + remote_buffer_add_string (&p, &left, "vFile:setfs:"); + + xsnprintf (arg, sizeof (arg), "%x", remote_fs_pid); + remote_buffer_add_string (&p, &left, arg); + + if (remote_hostio_send_command (p - rs->buf, PACKET_vFile_setfs, + &remote_errno, NULL, NULL) == 0) + rs->fs_pid = remote_fs_pid; + } +} + /* Return nonzero if the filesystem accessed by the target_fileio_* methods is the local filesystem, zero otherwise. */ @@ -9901,6 +9949,8 @@ remote_hostio_open (struct target_ops *self, char *p = rs->buf; int left = get_remote_packet_size () - 1; + remote_hostio_set_filesystem (); + remote_buffer_add_string (&p, &left, "vFile:open:"); remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename, @@ -10015,6 +10065,8 @@ remote_hostio_unlink (struct target_ops *self, char *p = rs->buf; int left = get_remote_packet_size () - 1; + remote_hostio_set_filesystem (); + remote_buffer_add_string (&p, &left, "vFile:unlink:"); remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename, @@ -10040,6 +10092,8 @@ remote_hostio_readlink (struct target_ops *self, int read_len; char *ret; + remote_hostio_set_filesystem (); + remote_buffer_add_string (&p, &left, "vFile:readlink:"); remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename, @@ -11756,6 +11810,7 @@ Specify the serial device it is connected to\n\ remote_ops.to_supports_multi_process = remote_supports_multi_process; remote_ops.to_supports_disable_randomization = remote_supports_disable_randomization; + remote_ops.to_fileio_set_fs = remote_hostio_set_fs_deferred; remote_ops.to_filesystem_is_local = remote_filesystem_is_local; remote_ops.to_fileio_open = remote_hostio_open; remote_ops.to_fileio_pwrite = remote_hostio_pwrite; @@ -12322,6 +12377,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL, add_packet_config_cmd (&remote_protocol_packets[PACKET_qTStatus], "qTStatus", "trace-status", 0); + add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_setfs], + "vFile:setfs", "hostio-setfs", 0); + add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_open], "vFile:open", "hostio-open", 0);