From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30943 invoked by alias); 6 Apr 2015 16:41:10 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 30931 invoked by uid 89); 6 Apr 2015 16:41:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f177.google.com Received: from mail-pd0-f177.google.com (HELO mail-pd0-f177.google.com) (209.85.192.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 06 Apr 2015 16:41:08 +0000 Received: by pddn5 with SMTP id n5so49486978pdd.2 for ; Mon, 06 Apr 2015 09:41:06 -0700 (PDT) X-Received: by 10.70.96.65 with SMTP id dq1mr10182306pdb.79.1428338466267; Mon, 06 Apr 2015 09:41:06 -0700 (PDT) Received: from seba.sebabeach.org.gmail.com (173-13-178-53-sfba.hfc.comcastbusiness.net. [173.13.178.53]) by mx.google.com with ESMTPSA id j4sm5196712pdk.76.2015.04.06.09.41.05 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2015 09:41:05 -0700 (PDT) From: Doug Evans To: Gary Benson Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 4/7] Introduce linux_pid_to_exec_file References: <1427887341-31819-1-git-send-email-gbenson@redhat.com> <1427887341-31819-5-git-send-email-gbenson@redhat.com> Date: Mon, 06 Apr 2015 16:41:00 -0000 In-Reply-To: <1427887341-31819-5-git-send-email-gbenson@redhat.com> (Gary Benson's message of "Wed, 1 Apr 2015 12:22:18 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg00149.txt.bz2 Gary Benson writes: > 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. > > ... > > 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 @@ > +/* Native-dependent code for GNU/Linux > + > + Copyright (C) 2000-2015 Free Software Foundation, Inc. > + > + This file is part of GDB. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +#include "common-defs.h" > +#include "nat/linux-nat.h" > + > +/* 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 enum target_stop_reason lwp_stop_reason (struct lwp_info *lwp); > > 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 */ Hi. I like the idea of returning NULL if the executable file cannot be determined, but the implementation doesn't do this. Also, while I don't have a strong opinion, it seems preferable to return a const char *.