Re: [PATCH 4/7] Introduce linux_pid_to_exec_file

Pedro Alves
2015-04-15T09:37:21Z

On 04/01/2015 12:22 PM, Gary Benson wrote:
> This commit introduces a new function, linux_pid_to_exec_file, that
> shared Linux code can use to discover the filename of the executable
> that was run to create a process on the system.
>
> gdb/ChangeLog:
>
> * nat/linux-nat.h (linux_pid_to_exec_file): New declaration.
> * nat/linux-nat.c: New file.
> * Makefile.in (common-linux-nat.o): New rule.
> * config/aarch64/linux.mh (NATDEPFILES): Add common-linux-nat.o.
> * config/alpha/alpha-linux.mh (NATDEPFILES): Likewise.
> * config/arm/linux.mh (NATDEPFILES): Likewise.
> * config/i386/linux.mh (NATDEPFILES): Likewise.
> * config/i386/linux64.mh (NATDEPFILES): Likewise.
> * config/ia64/linux.mh (NATDEPFILES): Likewise.
> * config/m32r/linux.mh (NATDEPFILES): Likewise.
> * config/m68k/linux.mh (NATDEPFILES): Likewise.
> * config/mips/linux.mh (NATDEPFILES): Likewise.
> * config/pa/linux.mh (NATDEPFILES): Likewise.
> * config/powerpc/linux.mh (NATDEPFILES): Likewise.
> * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise.
> * config/powerpc/spu-linux.mh (NATDEPFILES): Likewise.
> * config/s390/linux.mh (NATDEPFILES): Likewise.
> * config/sparc/linux.mh (NATDEPFILES): Likewise.
> * config/sparc/linux64.mh (NATDEPFILES): Likewise.
> * config/tilegx/linux.mh (NATDEPFILES): Likewise.
> * config/xtensa/linux.mh (NATDEPFILES): Likewise.
> * linux-nat.c (linux_child_pid_to_exec_file): Factored out
> to new function linux_pid_to_exec_file in nat/linux-nat.c.

Sorry for pushing back a after you touched all these files, but,
there's already a natural place for this shared function.

> --- /dev/null
> +++ b/gdb/nat/linux-nat.c
> @@ -0,0 +1,37 @@
> +/* Native-dependent code for GNU/Linux
...
> +char *
> +linux_pid_to_exec_file (int pid)
> +{
> + static char buf[PATH_MAX];
> + char name[PATH_MAX];
> +
> + xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
> + memset (buf, 0, PATH_MAX);
> + if (readlink (name, buf, PATH_MAX - 1) <= 0)
> + strcpy (buf, name);
> +
> + return buf;
> +}

Instead please move this function to nat/linux-procfs.c,
(and call it linux_proc_pid_to_exec_file).

Thanks,
Pedro Alves