[PATCH 0/7] GNU/Linux mount namespace support

Gary Benson
2015-04-16T12:19:58Z

Hi all,

This series allows GDB and gdbserver on GNU/Linux systems to attach
to processes in mount namespaces other than the debugger's own when
invoked with the appropriate permissions. This allows an application
running in a container to be debugged by running GDB or gdbserver on
the host, or by running GDB or gdbserver from within another container
that shares the host's PID namespace.

This series builds on the 'Do not require "file" commands for remote
targets' series that is currently under review:

https://sourceware.org/ml/gdb-patches/2015-04/msg00015.html

It also requires the 'Do not manipulate "target:" filenames as local
paths' patch to function correctly:

https://sourceware.org/ml/gdb-patches/2015-04/msg00547.html

A tree with the latest versions of all these patches applied is
available here:

https://github.com/gbenson/binutils-gdb/tree/namespaces

The patches in this series are as follows:

- Patch 1 (Move make_cleanup_close to common code) is a minor
refactoring required for patch 3.

- Patch 2 (Introduce target_fileio_set_fs) adds target-layer
support for systems where different processes can have different
views of the filesystem. The new function target_fileio_set_fs
sets the context in which target_filesystem_is_local and the
other target_fileio_* functions operate, and can be called to
select the filesystem of a specific inferior or the filesystem
of the debugger (GDB or gdbserver). The default implementation
of target_fileio_set_fs does nothing, which means that targets
where inferiors and the debugger share the same filesystem will
work without modification.

- Patch 3 (Introduce nat/linux-namespaces.[ch]) introduces some
shared code that GDB and gdbserver can use to query and enter
Linux namespaces.

- GDB contained a small amount of namespace-aware code used to
display a warning. Patch 4 (Remove linux_proc_pid_get_ns)
replaces the querying part of this code with a call to the
new code introduced by patch 3.

- Patch 5 (Implement multiple-filesystem support for Linux targets)
does exactly what it says on the tin. With this patch you can
attach to processes in containers using the native Linux target
using, e.g., "gdb -p PID".

- Patch 6 (Implement multiple-filesystem support for remote targets)
adds remote protocol support for remote targets where different
processes can have different views of the filesystem. A new
vFile:setfs packet is introduced that passes the context set using
target_fileio_set_fs to the remote target. Caching is used to
avoid sending unnecessary vFile:setfs packets.

- Patch 7 (Implement vFile:setfs in gdbserver) implements the
vFile:setfs packet in gdbserver. Currently only GNU/Linux systems
support this; gdbserver on other systems will return empty
responses in reply to vFile:setfs packets.

Built and regtested on RHEL 6.6 x86_64.

Ok to commit?

Thanks,
Gary

--