From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 2F69A385E82C for ; Mon, 16 Mar 2020 17:35:25 +0000 (GMT) Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id BDAD61E5F8; Mon, 16 Mar 2020 13:35:24 -0400 (EDT) Subject: Re: [PATCH] Rewrite nbsd_nat_target::pid_to_exec_file to sysctl(3) To: Kamil Rytarowski , gdb-patches@sourceware.org References: <20200316171413.17990-1-n54@gmx.com> From: Simon Marchi Message-ID: <70f19a4d-70dc-2f36-8f6a-1e78d9325d92@simark.ca> Date: Mon, 16 Mar 2020 13:35:24 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200316171413.17990-1-n54@gmx.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US-large Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-25.0 required=5.0 tests=GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Mar 2020 17:35:26 -0000 On 2020-03-16 1:14 p.m., Kamil Rytarowski wrote: > procfs on NetBSD is optional and not recommended. > > * nbsd-nat.c: Include , and > . > * nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite. > --- > gdb/ChangeLog | 6 ++++++ > gdb/nbsd-nat.c | 22 ++++++++++------------ > 2 files changed, 16 insertions(+), 12 deletions(-) > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog > index a0d97584189..358d49755bf 100644 > --- a/gdb/ChangeLog > +++ b/gdb/ChangeLog > @@ -1,3 +1,9 @@ > +2020-03-14 Kamil Rytarowski > + > + * nbsd-nat.c: Include , and > + . > + * nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite. > + > 2020-03-14 Tom Tromey > > * c-typeprint.c (cp_type_print_method_args): Print "__restrict__" > diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c > index e7f91bebb0d..5e881883a1f 100644 > --- a/gdb/nbsd-nat.c > +++ b/gdb/nbsd-nat.c > @@ -21,23 +21,21 @@ > > #include "nbsd-nat.h" > > +#include > +#include > +#include > + > /* Return the name of a file that can be opened to get the symbols for > the child process identified by PID. */ > > char * > nbsd_nat_target::pid_to_exec_file (int pid) > { > - ssize_t len; > static char buf[PATH_MAX]; > - char name[PATH_MAX]; > - > - xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid); > - len = readlink (name, buf, PATH_MAX - 1); > - if (len != -1) > - { > - buf[len] = '\0'; > - return buf; > - } > - > - return NULL; > + size_t buflen; > + int mib[4] = {CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_PATHNAME}; > + buflen = sizeof(buf); Space before parenthesis. Otherwise, that LGTM. Simon