Re: [PATCH 8/9 v2] Implement vFile:setfs in gdbserver

Pedro Alves
2015-05-21T15:00:11Z

On 04/30/2015 01:05 PM, Gary Benson wrote:
> This commit implements the "vFile:setfs" packet in gdbserver.
>
> gdb/gdbserver/ChangeLog:
>
> * target.h (struct target_ops) <multifs_open>: New field.
> <multifs_unlink>: Likewise.
> <multifs_readlink>: Likewise.
> * linux-low.c (nat/linux-namespaces.h): New include.
> (linux_target_ops): Initialize the_target->multifs_open,
> the_target->multifs_unlink and the_target->multifs_readlink.
> * hostio.c (hostio_fs_pid): New static variable.
> (handle_setfs): New function.
> (handle_open): Use the_target->multifs_open as appropriate.
> (handle_unlink): Use the_target->multifs_unlink as appropriate.
> (handle_readlink): Use the_target->multifs_readlink as
> appropriate.
> (handle_vFile): Handle vFile:setfs packets.
> ---
> gdb/gdbserver/ChangeLog | 16 +++++++++++
> gdb/gdbserver/hostio.c | 62 ++++++++++++++++++++++++++++++++++++++++++--
> gdb/gdbserver/linux-low.c | 4 +++
> gdb/gdbserver/target.h | 21 +++++++++++++++
> 4 files changed, 100 insertions(+), 3 deletions(-)
>
> diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c
> index 9e858d9..10cff5a 100644
> --- a/gdb/gdbserver/hostio.c
> +++ b/gdb/gdbserver/hostio.c
> @@ -243,6 +243,47 @@ hostio_reply_with_data (char *own_buf, char *buffer, int len,
> return input_index;
> }
>
> +/* Process ID of inferior whose filesystem hostio functions
> + that take FILENAME arguments will use. Zero means to use
> + our own filesystem. */
> +
> +static int hostio_fs_pid = 0;

This should be cleared if GDB reconnects.

> +
> +/* Handle a "vFile:setfs:" packet. */
> +
> +static void
> +handle_setfs (char *own_buf)
> +{
> + char *p;
> + int pid;
> +
> + /* If the target doesn't have any of the in-filesystem-of methods
> + then there's no point in GDB sending "vFile:setfs:" packets. We
> + reply with an empty packet (i.e. we pretend we don't understand
> + "vFile:setfs:") and that should stop GDB sending any more. */
> + if (the_target->multifs_open == NULL
> + && the_target->multifs_unlink == NULL
> + && the_target->multifs_readlink == NULL)
> + {
> + own_buf[0] = '\0';
> + return;
> + }

For the setns/ENOSYS case, how about somehow probing whether setns
actually works here (with a new method, or probing one of the existing
ones with getpid()) and return empty packet, instead of ending up with
open failing with ENOSYS later on?

Some comment for the native side, actually.

Thanks,
Pedro Alves