From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 5/7] Implement multiple-filesystem support for Linux targets
Date: Thu, 16 Apr 2015 13:06:00 -0000 [thread overview]
Message-ID: <1429186791-6867-6-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 native Linux targets where GDB and the inferior have different
filesystem namespaces.
gdb/ChangeLog:
* linux-nat.c (fileio.h): New include.
(nat/linux-namespaces.h): Likewise.
(super_fileio_open): New static variable.
(super_fileio_unlink): Likewise.
(super_fileio_readlink): Likewise.
(fs_ns_pid): Likewise.
(linux_nat_fileio_set_fs): New function.
(linux_nat_filesystem_is_local): Likewise.
(linux_nat_enter_fs): Likewise.
(open_closure): New structure.
(linux_nat_fileio_open_1): New function.
(linux_nat_fileio_open): Likewise.
(unlink_closure): New structure.
(linux_nat_fileio_unlink_1): New function.
(linux_nat_fileio_unlink): Likewise.
(linux_nat_add_target): Install new target methods.
(readlink_closure): New structure.
(linux_nat_fileio_readlink_1): New function.
(linux_nat_fileio_readlink): Likewise.
---
gdb/ChangeLog | 22 ++++++
gdb/linux-nat.c | 193 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 215 insertions(+), 0 deletions(-)
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index b04aa68..a54c704 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -66,6 +66,8 @@
#include "target-descriptions.h"
#include "filestuff.h"
#include "objfiles.h"
+#include "fileio.h"
+#include "nat/linux-namespaces.h"
#ifndef SPUFS_MAGIC
#define SPUFS_MAGIC 0x23c9b64e
@@ -196,6 +198,24 @@ static target_xfer_partial_ftype *super_xfer_partial;
Called by our to_close. */
static void (*super_close) (struct target_ops *);
+/* The saved to_fileio_open method, inherited from inf-child.c.
+ Called by our to_fileio_open. */
+
+static int (*super_fileio_open) (struct target_ops *,
+ const char *, int, int, int *);
+
+/* The saved to_fileio_unlink method, inherited from inf-child.c.
+ Called by our to_fileio_unlink. */
+
+static int (*super_fileio_unlink) (struct target_ops *,
+ const char *, int *);
+
+/* The saved to_fileio_readlink method, inherited from inf-child.c.
+ Called by our to_fileio_readlink. */
+
+static char *(*super_fileio_readlink) (struct target_ops *,
+ const char *, int *);
+
static unsigned int debug_linux_nat;
static void
show_debug_linux_nat (struct ui_file *file, int from_tty,
@@ -4842,6 +4862,169 @@ linux_nat_core_of_thread (struct target_ops *ops, ptid_t ptid)
return -1;
}
+/* Process ID of inferior whose filesystem namespace the various
+ target_fileio functions will use. Zero means to use our own. */
+
+static int fs_ns_pid = 0;
+
+/* Implementation of to_fileio_set_fs. */
+
+static void
+linux_nat_fileio_set_fs (struct target_ops *ops, int pid)
+{
+ fs_ns_pid = pid;
+}
+
+/* Implementation of to_filesystem_is_local. */
+
+static int
+linux_nat_filesystem_is_local (struct target_ops *ops)
+{
+ return fs_ns_pid == 0
+ || linux_ns_same (getpid (), fs_ns_pid, LINUX_NS_MNT);
+}
+
+/* Enter the filesystem namespace of the process specified by
+ target_fileio_set_fs and call FUNC with the argument ARG,
+ restoring the original filesystem namespace afterwards.
+ Set TARGET_ERRNO if FUNC is not called. */
+
+static void
+linux_nat_enter_fs (void (*func) (void *), void *arg, int *target_errno)
+{
+ if (fs_ns_pid == 0)
+ func (arg);
+ else if (!linux_ns_enter (fs_ns_pid, LINUX_NS_MNT, func, arg))
+ *target_errno = host_to_fileio_error (errno);
+}
+
+/* Arguments and return value of to_fileio_open. */
+
+struct open_closure
+{
+ struct target_ops *ops;
+ const char *filename;
+ int flags;
+ int mode;
+ int *target_errno;
+ int return_value;
+};
+
+/* Helper for linux_nat_fileio_open. */
+
+static void
+linux_nat_fileio_open_1 (void *arg)
+{
+ struct open_closure *clo = (struct open_closure *) arg;
+
+ clo->return_value = super_fileio_open (clo->ops, clo->filename,
+ clo->flags, clo->mode,
+ clo->target_errno);
+}
+
+/* Implementation of to_fileio_open. */
+
+static int
+linux_nat_fileio_open (struct target_ops *ops,
+ const char *filename, int flags, int mode,
+ int *target_errno)
+{
+ struct open_closure clo =
+ {
+ /* Arguments. */
+ ops, filename, flags, mode, target_errno,
+
+ /* Failure return value. */
+ -1
+ };
+
+ linux_nat_enter_fs (linux_nat_fileio_open_1, &clo, target_errno);
+
+ return clo.return_value;
+}
+
+/* Arguments and return value of to_fileio_unlink. */
+
+struct unlink_closure
+{
+ struct target_ops *ops;
+ const char *filename;
+ int *target_errno;
+ int return_value;
+};
+
+/* Helper for linux_nat_fileio_unlink. */
+
+static void
+linux_nat_fileio_unlink_1 (void *arg)
+{
+ struct unlink_closure *clo = (struct unlink_closure *) arg;
+
+ clo->return_value = super_fileio_unlink (clo->ops, clo->filename,
+ clo->target_errno);
+}
+
+/* Implementation of to_fileio_unlink. */
+
+static int
+linux_nat_fileio_unlink (struct target_ops *ops,
+ const char *filename, int *target_errno)
+{
+ struct unlink_closure clo =
+ {
+ /* Arguments. */
+ ops, filename, target_errno,
+
+ /* Failure return value. */
+ -1
+ };
+
+ linux_nat_enter_fs (linux_nat_fileio_unlink_1, &clo, target_errno);
+
+ return clo.return_value;
+}
+
+/* Arguments and return value of to_fileio_readlink. */
+
+struct readlink_closure
+{
+ struct target_ops *ops;
+ const char *filename;
+ int *target_errno;
+ char *return_value;
+};
+
+/* Helper for linux_nat_fileio_readlink. */
+
+static void
+linux_nat_fileio_readlink_1 (void *arg)
+{
+ struct readlink_closure *clo = (struct readlink_closure *) arg;
+
+ clo->return_value = super_fileio_readlink (clo->ops, clo->filename,
+ clo->target_errno);
+}
+
+/* Implementation of to_fileio_readlink. */
+
+static char *
+linux_nat_fileio_readlink (struct target_ops *ops,
+ const char *filename, int *target_errno)
+{
+ struct readlink_closure clo =
+ {
+ /* Arguments. */
+ ops, filename, target_errno,
+
+ /* Failure return value. */
+ NULL
+ };
+
+ linux_nat_enter_fs (linux_nat_fileio_readlink_1, &clo, target_errno);
+
+ return clo.return_value;
+}
+
void
linux_nat_add_target (struct target_ops *t)
{
@@ -4895,6 +5078,16 @@ linux_nat_add_target (struct target_ops *t)
t->to_core_of_thread = linux_nat_core_of_thread;
+ /* Target File-I/O functions. */
+ t->to_fileio_set_fs = linux_nat_fileio_set_fs;
+ t->to_filesystem_is_local = linux_nat_filesystem_is_local;
+ super_fileio_open = t->to_fileio_open;
+ t->to_fileio_open = linux_nat_fileio_open;
+ super_fileio_unlink = t->to_fileio_unlink;
+ t->to_fileio_unlink = linux_nat_fileio_unlink;
+ super_fileio_readlink = t->to_fileio_readlink;
+ t->to_fileio_readlink = linux_nat_fileio_readlink;
+
/* We don't change the stratum; this target will sit at
process_stratum and thread_db will set at thread_stratum. This
is a little strange, since this is a multi-threaded-capable
--
1.7.1
next prev parent reply other threads:[~2015-04-16 13:06 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 ` [PATCH 6/7] Implement multiple-filesystem support for remote targets Gary Benson
2015-04-16 15:12 ` 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 ` Gary Benson [this message]
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 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: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: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-6-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