From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 123024 invoked by alias); 5 Jan 2018 19:43:56 -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 122936 invoked by uid 89); 5 Jan 2018 19:43:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy= X-HELO: mail.baldwin.cx Received: from bigwig.baldwin.cx (HELO mail.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 05 Jan 2018 19:43:54 +0000 Received: from ralph.baldwin.cx (astound-66-234-202-155.ca.astound.net [66.234.202.155]) by mail.baldwin.cx (Postfix) with ESMTPSA id 2DDDD10AFB2; Fri, 5 Jan 2018 14:43:52 -0500 (EST) From: John Baldwin To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v2 2/5] Don't return stale data from fbsd_pid_to_exec_file for kernel processes. Date: Fri, 05 Jan 2018 19:43:00 -0000 Message-ID: <1784143.eCmo5HAMmC@ralph.baldwin.cx> User-Agent: KMail/4.14.10 (FreeBSD/11.1-STABLE; KDE/4.14.30; amd64; ; ) In-Reply-To: References: <20180104014923.11899-1-jhb@FreeBSD.org> <20180104014923.11899-3-jhb@FreeBSD.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-IsSubscribed: yes X-SW-Source: 2018-01/txt/msg00118.txt.bz2 On Thursday, January 04, 2018 09:57:00 PM Simon Marchi wrote: > On 2018-01-03 08:49 PM, John Baldwin wrote: > > For processes without an associated executable (such as kernel processes), > > the kern.proc.pathname. system control node returns a length of zero > > without modifying the user's buffer. Detect this case and return NULL > > rather than the previous contents of the static buffer 'buf'. > > > > gdb/ChangeLog: > > > > * fbsd-nat.c (fbsd_pid_to_exec_file) [KERN_PROC_PATHNAME]: Return > > NULL for an empty pathname. > > --- > > gdb/ChangeLog | 5 +++++ > > gdb/fbsd-nat.c | 2 +- > > 2 files changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog > > index 29cfbb287b..804dd4f402 100644 > > --- a/gdb/ChangeLog > > +++ b/gdb/ChangeLog > > @@ -1,3 +1,8 @@ > > +2018-01-03 John Baldwin > > + > > + * fbsd-nat.c (fbsd_pid_to_exec_file) [KERN_PROC_PATHNAME]: Return > > + NULL for an empty pathname. > > + > > 2018-01-03 John Baldwin > > > > * fbsd-tdep.c (KVE_STRUCTSIZE, KVE_START, KVE_END, KVE_OFFSET) > > diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c > > index ec4eed9abe..7b1d1bf148 100644 > > --- a/gdb/fbsd-nat.c > > +++ b/gdb/fbsd-nat.c > > @@ -63,7 +63,7 @@ fbsd_pid_to_exec_file (struct target_ops *self, int pid) > > mib[3] = pid; > > buflen = sizeof buf; > > if (sysctl (mib, 4, buf, &buflen, NULL, 0) == 0) > > - return buf; > > + return buflen == 0 ? NULL : buf; > > #endif > > > > xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid); > > > > LGTM, but maybe add a comment saying in what situation the sysctl can > return a buflen of 0. Ok. > Does the alternative method that reads from /proc//exe work in that > case too? No. FreeBSD systems don't generally mount /proc (it's not enabled in the default install), but in the case that 0 is returned, the relevant pointer in the process structure (p_textvp) that '/proc/%d/exe' returns a path for is NULL, so the procfs method will also fail. Actually, I looked at FreeBSD's procfs and the node is named /proc/%d/file, not /proc/%d/exe. I did confirm that FreeBSD's procfs does not create 'file' nodes for kernel processes (but also not for init (pid 1)). I should in fact probably refine this function further to only use procfs in the #else case if not remove it all together: the last release to not include the pathname sysctl was FreeBSD 5.5 released in May 2006. -- John Baldwin