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.
On 11/30/18 2:39 PM, Pedro Alves wrote:
> 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. This is what I pushed (modulo using fdtbl[i]. rather than
fdtbl[i]->).
--
John Baldwin