Index: sys/kern/kern_fork.c =================================================================== --- sys/kern/kern_fork.c (revision 230617) +++ sys/kern/kern_fork.c (working copy) @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -702,7 +703,8 @@ * for runaway child. */ td->td_dbgflags |= TDB_FORK; - td->td_dbg_forked = p2->p_pid; + td2->td_dbgflags |= TDB_FORK; + td->td_dbg_forked = td2->td_dbg_forked = p2->p_pid; td2->td_dbgflags |= TDB_STOPATFORK; _PHOLD(p2); p2_held = 1; @@ -731,6 +733,13 @@ knote_fork(&p1->p_klist, p2->p_pid); SDT_PROBE(proc, kernel, , create, p2, p1, flags, 0, 0); + if (td->td_dbgflags & TDB_FORK) { + PTRACESTOP_SC(p1, td, S_PT_FORK); + PROC_LOCK(p1); + td->td_dbgflags &= ~TDB_FORK; + PROC_UNLOCK(p1); + } + /* * Wait until debugger is attached to child. */ @@ -1036,6 +1045,7 @@ proc_reparent(p, dbg); sx_xunlock(&proctree_lock); ptracestop(td, SIGSTOP); + td->td_dbgflags &= ~TDB_FORK; } else { /* * ... otherwise clear the request. Index: sys/kern/sys_process.c =================================================================== --- sys/kern/sys_process.c (revision 230617) +++ sys/kern/sys_process.c (working copy) @@ -868,10 +868,14 @@ break; case PT_FOLLOW_FORK: - if (data) + if (data) { p->p_flag |= P_FOLLOWFORK; - else + p->p_stops |= S_PT_FORK; + } + else { p->p_flag &= ~P_FOLLOWFORK; + p->p_stops &= ~S_PT_FORK; + } break; case PT_STEP: Index: sys/sys/ptrace.h =================================================================== --- sys/sys/ptrace.h (revision 230617) +++ sys/sys/ptrace.h (working copy) @@ -142,6 +142,7 @@ */ #define S_PT_SCE 0x000010000 #define S_PT_SCX 0x000020000 +#define S_PT_FORK 0x000040000 int ptrace_set_pc(struct thread *_td, unsigned long _addr); int ptrace_single_step(struct thread *_td);