From patchwork Mon Dec 10 20:01:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 30612 Received: (qmail 26259 invoked by alias); 10 Dec 2018 20:03:21 -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 26250 invoked by uid 89); 10 Dec 2018 20:03:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=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=claimed, Hx-languages-length:2775, intercepted, believed 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; Mon, 10 Dec 2018 20:03:18 +0000 Received: from ralph.baldwin.cx (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id 1855110B754 for ; Mon, 10 Dec 2018 15:03:16 -0500 (EST) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH] Workaround a FreeBSD kernel bug resulting in spurious SIGTRAP events. Date: Mon, 10 Dec 2018 12:01:31 -0800 Message-Id: <20181210200131.95450-1-jhb@FreeBSD.org> MIME-Version: 1.0 X-IsSubscribed: yes The ptrace command PT_LWPINFO to request detailed information about a stopped thread can return stale signal information from an earlier stop. Events which are reporting an intercepted signal will always report the correct information, but signal stops for some other events such as system call enter/exit events might include stale siginfo from an earlier signal. In particular, if a thread reports a system call entry or exit event after previously reporting a single-step or breakpoint event via SIGTRAP, fbsd_handle_debug_trap believed the system call event was the previous event and claimed it resulting in a spurious SIGTRAP event. True breakpoint and single-step events will never report another event in the pl_flags member of struct ptrace_lwpinfo. Use this to detect stale siginfo by requiring pl_flags to have only the PL_FLAG_SI flag and no other flags before treating a SIGTRAP as a single-step or breakpoint trap. gdb/ChangeLog: * fbsd-nat.c (fbsd_handle_debug_trap): Require pl.pl_flags to equal PL_FLAG_SI. (fbsd_nat_target::stopped_by_sw_breakpoint): Likewise. --- gdb/ChangeLog | 6 ++++++ gdb/fbsd-nat.c | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d60dddd2ea..cf85a4b52f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-12-10 John Baldwin + + * fbsd-nat.c (fbsd_handle_debug_trap): Require pl.pl_flags to + equal PL_FLAG_SI. + (fbsd_nat_target::stopped_by_sw_breakpoint): Likewise. + 2018-12-10 Andrew Burgess * riscv-tdep.c (riscv_register_name): Fix ARI warning by removing diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index 6ec273b1cf..e6b6894919 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -1238,8 +1238,14 @@ fbsd_handle_debug_trap (ptid_t ptid, const struct ptrace_lwpinfo &pl) { /* Ignore traps without valid siginfo or for signals other than - SIGTRAP. */ - if (! (pl.pl_flags & PL_FLAG_SI) || pl.pl_siginfo.si_signo != SIGTRAP) + SIGTRAP. + + FreeBSD kernels prior to r341800 can return stale siginfo for at + least some events, but those events can be identified by + additional flags set in pl_flags. True breakpoint and + single-step traps should not have other flags set in + pl_flags. */ + if (pl.pl_flags != PL_FLAG_SI || pl.pl_siginfo.si_signo != SIGTRAP) return false; /* Trace traps are either a single step or a hardware watchpoint or @@ -1517,7 +1523,7 @@ fbsd_nat_target::stopped_by_sw_breakpoint () sizeof pl) == -1) return false; - return ((pl.pl_flags & PL_FLAG_SI) + return (pl.pl_flags == PL_FLAG_SI && pl.pl_siginfo.si_signo == SIGTRAP && pl.pl_siginfo.si_code == TRAP_BRKPT); }