diff options
author | John Baldwin <jhb@FreeBSD.org> | 2018-11-30 15:14:18 -0800 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2018-11-30 15:14:18 -0800 |
commit | 93579f6f908fa6010b141fd5da2974d878869c80 (patch) | |
tree | fad26e511d1d99c849f9042d0042faadce2d3c9f /gdb/common | |
parent | 4717cec4fe4cb3a086fb13161603112e8ded787e (diff) | |
download | binutils-93579f6f908fa6010b141fd5da2974d878869c80.zip binutils-93579f6f908fa6010b141fd5da2974d878869c80.tar.gz binutils-93579f6f908fa6010b141fd5da2974d878869c80.tar.bz2 |
Use kinfo_getfile to implement fdwalk on FreeBSD.
kinfo_getfile() requires a couple of system calls to fetch the list of
open file descriptors. This can be much cheaper than invoking fstat
on all of the values from 0 to the open file resource limit maximum.
gdb/ChangeLog:
* common/filestuff.c [HAVE_KINFO_GETFILE]: Include headers.
(fdwalk) [HAVE_KINFO_GETFILE]: Use kinfo_getfile.
Diffstat (limited to 'gdb/common')
-rw-r--r-- | gdb/common/filestuff.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gdb/common/filestuff.c b/gdb/common/filestuff.c index 0db5c69..f4d5e38 100644 --- a/gdb/common/filestuff.c +++ b/gdb/common/filestuff.c @@ -36,6 +36,11 @@ #define HAVE_SOCKETS 1 #endif +#ifdef HAVE_KINFO_GETFILE +#include <sys/user.h> +#include <libutil.h> +#endif + #ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> #endif /* HAVE_SYS_RESOURCE_H */ @@ -108,6 +113,25 @@ fdwalk (int (*func) (void *, int), void *arg) } /* We may fall through to the next case. */ #endif +#ifdef HAVE_KINFO_GETFILE + 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; + } + /* We may fall through to the next case. */ +#endif { int max, fd; |