From patchwork Wed Sep 12 23:37:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 29351 Received: (qmail 60628 invoked by alias); 12 Sep 2018 23:43:17 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 60598 invoked by uid 89); 12 Sep 2018 23:43:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy= X-HELO: mail.baldwin.cx Received: from bigwig.baldwin.cx (HELO mail.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 12 Sep 2018 23:43:14 +0000 Received: from ralph.com (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id 2ECBA10B67C for ; Wed, 12 Sep 2018 19:37:31 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH v2 4/6] Support 'info proc files' on live FreeBSD processes. Date: Wed, 12 Sep 2018 16:37:05 -0700 Message-Id: <20180912233707.43492-5-jhb@FreeBSD.org> In-Reply-To: <20180912233707.43492-1-jhb@FreeBSD.org> References: <20180912233707.43492-1-jhb@FreeBSD.org> X-IsSubscribed: yes This walks the list of struct kinfo_file objects returned by a call to kinfo_getfile outputting a description of each open file descriptor. gdb/ChangeLog: * fbsd-nat.c (fbsd_nat_target::info_proc): List open file descriptors for IP_FILES and IP_ALL. --- gdb/ChangeLog | 5 +++++ gdb/fbsd-nat.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index bcd69e7e73..997c079218 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-09-12 John Baldwin + + * fbsd-nat.c (fbsd_nat_target::info_proc): List open file + descriptors for IP_FILES and IP_ALL. + 2018-09-12 John Baldwin * fbsd-tdep.c (KF_FLAGS, KF_OFFSET, KF_VNODE_TYPE, KF_SOCK_DOMAIN) diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index 2b829bfc3b..24e40e2406 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -265,6 +265,9 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what) bool do_cmdline = false; bool do_cwd = false; bool do_exe = false; +#ifdef HAVE_KINFO_GETFILE + bool do_files = false; +#endif #ifdef HAVE_KINFO_GETVMMAP bool do_mappings = false; #endif @@ -295,10 +298,18 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what) case IP_CWD: do_cwd = true; break; +#ifdef HAVE_KINFO_GETFILE + case IP_FILES: + do_files = true; + break; +#endif case IP_ALL: do_cmdline = true; do_cwd = true; do_exe = true; +#ifdef HAVE_KINFO_GETFILE + do_files = true; +#endif #ifdef HAVE_KINFO_GETVMMAP do_mappings = true; #endif @@ -322,7 +333,7 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what) printf_filtered (_("process %d\n"), pid); #ifdef HAVE_KINFO_GETFILE - if (do_cwd || do_exe) + if (do_cwd || do_exe || do_files) fdtbl.reset (kinfo_getfile (pid, &nfd)); #endif @@ -374,6 +385,25 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what) else warning (_("unable to fetch executable path name")); } +#ifdef HAVE_KINFO_GETFILE + if (do_files) + { + struct kinfo_file *kf = fdtbl.get (); + + if (nfd > 0) + { + fbsd_info_proc_files_header (); + for (int i = 0; i < nfd; i++, kf++) + fbsd_info_proc_files_entry (kf->kf_type, kf->kf_fd, kf->kf_flags, + kf->kf_offset, kf->kf_vnode_type, + kf->kf_sock_domain, kf->kf_sock_type, + kf->kf_sock_protocol, &kf->kf_sa_local, + &kf->kf_sa_peer, kf->kf_path); + } + else + warning (_("unable to fetch list of open files")); + } +#endif #ifdef HAVE_KINFO_GETVMMAP if (do_mappings) {