From patchwork Mon Jul 18 14:57:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 13845 Received: (qmail 29485 invoked by alias); 18 Jul 2016 14:58:53 -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 29351 invoked by uid 89); 18 Jul 2016 14:58:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=birth, Hx-languages-length:4502, fork, excluding X-HELO: bigwig.baldwin.cx Received: from bigwig.baldwin.cx (HELO bigwig.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Mon, 18 Jul 2016 14:58:42 +0000 Received: from ralph.com (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 2BEBEB99B for ; Mon, 18 Jul 2016 10:58:40 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH 1/3] Consolidate code to enable optional FreeBSD native target event reporting. Date: Mon, 18 Jul 2016 07:57:57 -0700 Message-Id: <20160718145759.58543-2-jhb@FreeBSD.org> In-Reply-To: <20160718145759.58543-1-jhb@FreeBSD.org> References: <20160718145759.58543-1-jhb@FreeBSD.org> X-IsSubscribed: yes Add a new function to enable optional event reporting for FreeBSD native targets. Specifically, use this to enable fork and LWP events. The bodies of fbsd_enable_follow_fork and fbsd_enable_lwp_events have been subsumed into the new function. In addition, use the PT_GET_EVENT_MASK and PT_EVENT_SET_MASK requests added in FreeBSD 12 when present to enable these events. gdb/ChangeLog: * fbsd-nat.c (fbsd_enable_lwp_events): Remove function. (fbsd_enable_proc_events): New function. (fbsd_enable_follow_fork): Remove function. (fbsd_post_startup_inferior): Use "fbsd_enable_proc_events". (fbsd_post_attach): Likewise. --- gdb/ChangeLog | 8 ++++++++ gdb/fbsd-nat.c | 59 ++++++++++++++++++++++++++++------------------------------ 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6c187dc..dcedc14 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2016-07-15 John Baldwin + * fbsd-nat.c (fbsd_enable_lwp_events): Remove function. + (fbsd_enable_proc_events): New function. + (fbsd_enable_follow_fork): Remove function. + (fbsd_post_startup_inferior): Use "fbsd_enable_proc_events". + (fbsd_post_attach): Likewise. + +2016-07-15 John Baldwin + * common/signals.c (gdb_signal_from_host): Handle SIGLIBRT. (do_gdb_signal_to_host): Likewise. * infrun.c (_initialize_infrun): Pass GDB_SIGNAL_LIBRT through to diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index fa9516e..508ab19 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -412,22 +412,43 @@ fbsd_thread_name (struct target_ops *self, struct thread_info *thr) } #endif -#ifdef PT_LWP_EVENTS -/* Enable LWP events for a specific process. +/* Enable additional event reporting on new processes. - To catch LWP events, PT_LWP_EVENTS is set on every traced process. + To catch fork events, PTRACE_FORK is set on every traced process + to enable stops on returns from fork or vfork. Note that both the + parent and child will always stop, even if system call stops are + not enabled. + + To catch LWP events, PTRACE_EVENTS is set on every traced process. This enables stops on the birth for new LWPs (excluding the "main" LWP) and the death of LWPs (excluding the last LWP in a process). Note that unlike fork events, the LWP that creates a new LWP does not report an event. */ static void -fbsd_enable_lwp_events (pid_t pid) +fbsd_enable_proc_events (pid_t pid) { +#ifdef PT_GET_EVENT_MASK + int events; + + if (ptrace (PT_GET_EVENT_MASK, pid, (PTRACE_TYPE_ARG3)&events, + sizeof (events)) == -1) + perror_with_name (("ptrace")); + events |= PTRACE_FORK | PTRACE_LWP; + if (ptrace (PT_SET_EVENT_MASK, pid, (PTRACE_TYPE_ARG3)&events, + sizeof (events)) == -1) + perror_with_name (("ptrace")); +#else +#ifdef TDP_RFPPWAIT + if (ptrace (PT_FOLLOW_FORK, pid, (PTRACE_TYPE_ARG3)0, 1) == -1) + perror_with_name (("ptrace")); +#endif +#ifdef PT_LWP_EVENTS if (ptrace (PT_LWP_EVENTS, pid, (PTRACE_TYPE_ARG3)0, 1) == -1) perror_with_name (("ptrace")); -} #endif +#endif +} /* Add threads for any new LWPs in a process. @@ -957,20 +978,6 @@ fbsd_remove_vfork_catchpoint (struct target_ops *self, int pid) { return 0; } - -/* Enable fork tracing for a specific process. - - To catch fork events, PT_FOLLOW_FORK is set on every traced process - to enable stops on returns from fork or vfork. Note that both the - parent and child will always stop, even if system call stops are - not enabled. */ - -static void -fbsd_enable_follow_fork (pid_t pid) -{ - if (ptrace (PT_FOLLOW_FORK, pid, (PTRACE_TYPE_ARG3)0, 1) == -1) - perror_with_name (("ptrace")); -} #endif /* Implement the "to_post_startup_inferior" target_ops method. */ @@ -978,12 +985,7 @@ fbsd_enable_follow_fork (pid_t pid) static void fbsd_post_startup_inferior (struct target_ops *self, ptid_t pid) { -#ifdef TDP_RFPPWAIT - fbsd_enable_follow_fork (ptid_get_pid (pid)); -#endif -#ifdef PT_LWP_EVENTS - fbsd_enable_lwp_events (ptid_get_pid (pid)); -#endif + fbsd_enable_proc_events (ptid_get_pid (pid)); } /* Implement the "to_post_attach" target_ops method. */ @@ -991,12 +993,7 @@ fbsd_post_startup_inferior (struct target_ops *self, ptid_t pid) static void fbsd_post_attach (struct target_ops *self, int pid) { -#ifdef TDP_RFPPWAIT - fbsd_enable_follow_fork (pid); -#endif -#ifdef PT_LWP_EVENTS - fbsd_enable_lwp_events (pid); -#endif + fbsd_enable_proc_events (pid); fbsd_add_threads (pid); }