public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 6/7] Implement multiple-filesystem support for remote targets
Date: Thu, 16 Apr 2015 12:27:00 -0000	[thread overview]
Message-ID: <1429186791-6867-7-git-send-email-gbenson@redhat.com> (raw)
In-Reply-To: <1429186791-6867-1-git-send-email-gbenson@redhat.com>

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) <fs_pid>: 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);
 
-- 
1.7.1

  parent reply	other threads:[~2015-04-16 12:27 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-16 12:19 [PATCH 0/7] GNU/Linux mount namespace support Gary Benson
2015-04-16 12:19 ` [PATCH 4/7] Remove linux_proc_pid_get_ns Gary Benson
2015-04-17  4:36   ` Doug Evans
2015-04-17 13:44     ` Gary Benson
2015-04-16 12:20 ` [PATCH 1/7] Move make_cleanup_close to common code Gary Benson
2015-04-17  2:47   ` Doug Evans
2015-04-16 12:20 ` [PATCH 2/7] Introduce target_fileio_set_fs Gary Benson
2015-04-17  3:04   ` Doug Evans
2015-04-17 13:36     ` Gary Benson
2015-04-17 14:21       ` Pedro Alves
2015-04-17 17:28         ` Doug Evans
2015-04-17 17:46           ` Pedro Alves
2015-04-20 11:11             ` Gary Benson
2015-04-16 12:27 ` Gary Benson [this message]
2015-04-16 15:12   ` [PATCH 6/7] Implement multiple-filesystem support for remote targets Eli Zaretskii
2015-04-17 15:06   ` Pedro Alves
2015-04-17 16:00     ` Gary Benson
2015-04-17 16:07       ` Pedro Alves
2015-04-17 16:20         ` Gary Benson
2015-04-17 15:31   ` Pedro Alves
2015-04-17 16:01     ` Gary Benson
2015-04-16 12:34 ` [PATCH 3/7] Introduce nat/linux-namespaces.[ch] Gary Benson
2015-04-17  4:26   ` Doug Evans
2015-04-17 13:41     ` Gary Benson
2015-04-17 14:52   ` Pedro Alves
2015-04-17 17:32     ` Doug Evans
2015-04-20 11:12       ` Gary Benson
2015-04-16 12:54 ` [PATCH 7/7] Implement vFile:setfs in gdbserver Gary Benson
2015-04-17 15:30   ` Pedro Alves
2015-04-17 16:47     ` Gary Benson
2015-04-17 16:29       ` Gary Benson
2015-04-17 17:09         ` Pedro Alves
2015-04-16 13:06 ` [PATCH 5/7] Implement multiple-filesystem support for Linux targets Gary Benson
2015-04-17 15:35 ` [PATCH 0/7] GNU/Linux mount namespace support Pedro Alves
2015-04-20 16:49 ` Iago López Galeiras
2015-04-21  7:56   ` Gary Benson
2015-04-30 12:06 ` [PATCH 3/9 v2] Remove linux_proc_pid_get_ns Gary Benson
2015-05-21 14:56   ` Pedro Alves
2015-04-30 12:06 ` [PATCH 0/9 v2] GNU/Linux mount namespace support Gary Benson
2015-06-10 14:23   ` [pushed][PATCH " Gary Benson
2015-04-30 12:06 ` [PATCH 5/9 v2] Add "inferior" argument to some target_fileio functions Gary Benson
2015-05-21 14:57   ` Pedro Alves
2015-04-30 12:06 ` [PATCH 6/9 v2] Implement mount namespace support for native Linux targets Gary Benson
2015-04-30 16:24   ` Eli Zaretskii
2015-04-30 18:05     ` Gary Benson
2015-05-21 14:59   ` Pedro Alves
2015-05-27 10:16     ` Gary Benson
2015-04-30 12:15 ` [PATCH 4/9 v2] Comment and whitespace changes Gary Benson
2015-05-21 14:57   ` Pedro Alves
2015-04-30 12:41 ` [PATCH 8/9 v2] Implement vFile:setfs in gdbserver Gary Benson
2015-05-21 15:00   ` Pedro Alves
2015-06-09 14:11     ` Gary Benson
2015-06-09 14:23       ` Pedro Alves
2015-06-10  9:01         ` Gary Benson
2015-06-10  9:41           ` Gary Benson
2015-06-10 14:53             ` Pedro Alves
2015-04-30 12:45 ` [PATCH 2/9 v2] Introduce nat/linux-namespaces.[ch] Gary Benson
     [not found]   ` <20150501000739.740.47967@domU-12-31-39-0A-A0-4F>
2015-05-01  9:28     ` Gary Benson
2015-05-01 13:18       ` Alban Crequy
2015-05-01 20:29         ` Gary Benson
2015-05-06 18:55           ` Alban Crequy
2015-05-07  8:42             ` Gary Benson
2015-05-07 10:39           ` Gary Benson
2015-05-21 14:56   ` Pedro Alves
2015-05-27 10:14     ` Gary Benson
2015-06-11  8:40     ` James Greenhalgh
2015-06-11 11:04       ` Pedro Alves
2015-06-11 12:42         ` [OB PATCH] Use pulongest for printing ssize_t Gary Benson
2015-06-15 15:02   ` [PATCH 2/9 v2] Introduce nat/linux-namespaces.[ch] Michael Eager
2015-06-15 22:12     ` Michael Eager
2015-06-16  8:40       ` Gary Benson
2015-06-16 14:19         ` Michael Eager
2015-06-17  9:51           ` Gary Benson
2016-01-08 10:49   ` Yao Qi
2016-01-11 16:40     ` Gary Benson
2016-01-18 11:44       ` [OB PATCH] Fix gdbserver build failure on targets without fork Gary Benson
2015-04-30 14:12 ` [PATCH 1/9 v2] Move make_cleanup_close to common code Gary Benson
2015-05-21 14:56   ` Pedro Alves
2015-05-27  9:52     ` Gary Benson
2015-04-30 14:12 ` [PATCH 7/9 v2] Implement multiple-filesystem support for remote targets Gary Benson
2015-04-30 17:10   ` Eli Zaretskii
2015-05-21 15:04   ` Pedro Alves
2015-04-30 14:14 ` [PATCH 9/9 v2] Announce new container-awareness features for GNU/Linux systems Gary Benson
2015-04-30 16:20   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1429186791-6867-7-git-send-email-gbenson@redhat.com \
    --to=gbenson@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).