From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 45154 invoked by alias); 7 Apr 2015 09:07: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 45137 invoked by uid 89); 7 Apr 2015 09:07:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 07 Apr 2015 09:07:09 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t379760P021382 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 7 Apr 2015 05:07:07 -0400 Received: from blade.nx (ovpn-116-118.ams2.redhat.com [10.36.116.118]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t37976Ih018119; Tue, 7 Apr 2015 05:07:06 -0400 Received: by blade.nx (Postfix, from userid 1000) id 5B08126410B; Tue, 7 Apr 2015 10:07:05 +0100 (BST) Date: Tue, 07 Apr 2015 09:07:00 -0000 From: Gary Benson To: Doug Evans Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 4/7] Introduce linux_pid_to_exec_file Message-ID: <20150407090705.GA22271@blade.nx> References: <1427887341-31819-1-git-send-email-gbenson@redhat.com> <1427887341-31819-5-git-send-email-gbenson@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg00187.txt.bz2 Doug Evans wrote: > Gary Benson 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/