This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 4/7] Introduce linux_pid_to_exec_file
- From: Gary Benson <gbenson at redhat dot com>
- To: Doug Evans <xdje42 at gmail dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Tue, 7 Apr 2015 10:07:05 +0100
- Subject: Re: [PATCH 4/7] Introduce linux_pid_to_exec_file
- Authentication-results: sourceware.org; auth=none
- References: <1427887341-31819-1-git-send-email-gbenson at redhat dot com> <1427887341-31819-5-git-send-email-gbenson at redhat dot com> <m3twwti51n dot fsf at sspiff dot org>
Doug Evans wrote:
> Gary Benson <gbenson@redhat.com> writes:
> > diff --git a/gdb/nat/linux-nat.c b/gdb/nat/linux-nat.c
> > new file mode 100644
> > index 0000000..b9deae3
> > --- /dev/null
> > +++ b/gdb/nat/linux-nat.c
> > @@ -0,0 +1,37 @@
...
> > +/* See nat/linux-nat.h. */
> > +
> > +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;
> > +}
> > diff --git a/gdb/nat/linux-nat.h b/gdb/nat/linux-nat.h
> > index 7cdaf40..81c2edc 100644
> > --- a/gdb/nat/linux-nat.h
> > +++ b/gdb/nat/linux-nat.h
> > @@ -78,4 +78,13 @@
> >
> > extern void linux_stop_lwp (struct lwp_info *lwp);
> >
> > +/* Return the pathname of the executable file that was run to create
> > + the process PID. If the executable file cannot be determined, NULL
> > + is returned. Otherwise, a pointer to a character string containing
> > + the pathname is returned. This string should be copied into a
> > + buffer by the client if the string will not be immediately used, or
> > + if it must persist. */
> > +
> > +extern char *linux_pid_to_exec_file (int pid);
> > +
> > #endif /* LINUX_NAT_H */
>
> I like the idea of returning NULL if the executable file cannot be
> determined, but the implementation doesn't do this.
You're right, I will remove that part of the documentation comment.
> Also, while I don't have a strong opinion, it seems preferable
> to return a const char *.
The function is the implementation of target_pid_to_exec_file, via
a wrapper, and that does not return const. I briefly attempted to
constify this but it snowballed.
Thanks,
Gary
--
http://gbenson.net/