Workaround a FreeBSD kernel bug resulting in spurious SIGTRAP events.
authorJohn Baldwin <jhb@FreeBSD.org>
Fri, 21 Dec 2018 18:18:11 +0000 (10:18 -0800)
committerJohn Baldwin <jhb@FreeBSD.org>
Fri, 21 Dec 2018 18:18:11 +0000 (10:18 -0800)
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
gdb/fbsd-nat.c

index db7a745a9cd7da4fc5c6108799b2aa2d12ce629e..4fcd2ebf4f65428f2c75e53c3656c619561d3636 100644 (file)
@@ -1,3 +1,9 @@
+2018-12-21  John Baldwin  <jhb@FreeBSD.org>
+
+       * 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-21  Paul Marechal  <paul.marechal@ericsson.com>
 
        PR gdb/23974
index 6ec273b1cf6ac4db850faf40ddf66b2c52c60464..e6b68949199d744620696d0ad0baba7dde725967 100644 (file)
@@ -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);
 }
This page took 0.031147 seconds and 4 git commands to generate.