[PATCH] Use kinfo_getfile to implement fdwalk on FreeBSD.
Pedro Alves
palves@redhat.com
Fri Nov 30 22:39:00 GMT 2018
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
More information about the Gdb-patches
mailing list