This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Use kinfo_getfile to implement fdwalk on FreeBSD.
- From: Pedro Alves <palves at redhat dot com>
- To: Tom Tromey <tom at tromey dot com>, John Baldwin <jhb at FreeBSD dot org>
- Cc: gdb-patches at sourceware dot org
- Date: Fri, 30 Nov 2018 22:39:16 +0000
- Subject: Re: [PATCH] Use kinfo_getfile to implement fdwalk on FreeBSD.
- References: <20181130212331.59989-1-jhb@FreeBSD.org> <87bm66kya3.fsf@tromey.com>
On 11/30/2018 10:15 PM, Tom Tromey wrote:
> John> +#ifdef HAVE_KINFO_GETFILE
> John> + gdb::unique_xmalloc_ptr<struct kinfo_file> fdtbl;
> John> + int nfd;
> John> + fdtbl.reset (kinfo_getfile (getpid (), &nfd));
>
> I think this should be combined with the declaration; no need to call
> reset.
If you want, you can also use the array-version of unique_ptr
and eliminate some variables:
int nfd;
gdb::unique_xmalloc_ptr<struct kinfo_file[]> fdtbl
(kinfo_getfile (getpid (), &nfd));
if (fdtbl != NULL)
{
for (int i = 0; i < nfd; i++)
{
if (fdtbl[i]->kf_fd >= 0)
{
int result = func (arg, fdtbl[i]->kf_fd);
if (result != 0)
return result;
}
}
return 0;
}
Thanks,
Pedro Alves