diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -930,12 +930,10 @@ } if (tid == 0) { - if ((p->p_flag & P_STOPPED_TRACE) != 0) { - KASSERT(p->p_xthread != NULL, ("NULL p_xthread")); + if ((p->p_flag & P_STOPPED_TRACE) != 0) td2 = p->p_xthread; - } else { + if (td2 == NULL) td2 = FIRST_THREAD_IN_PROC(p); - } tid = td2->td_tid; } @@ -1322,16 +1320,19 @@ /* * Clear the pending event for the thread that just - * reported its event (p_xthread). This may not be - * the thread passed to PT_CONTINUE, PT_STEP, etc. if - * the debugger is resuming a different thread. + * reported its event (p_xthread), if any. This may + * not be the thread passed to PT_CONTINUE, PT_STEP, + * etc. if the debugger is resuming a different + * thread. There might be no reporting thread if + * the process was just attached. * * Deliver any pending signal via the reporting thread. */ - MPASS(p->p_xthread != NULL); - p->p_xthread->td_dbgflags &= ~TDB_XSIG; - p->p_xthread->td_xsig = data; - p->p_xthread = NULL; + if (p->p_xthread != NULL) { + p->p_xthread->td_dbgflags &= ~TDB_XSIG; + p->p_xthread->td_xsig = data; + p->p_xthread = NULL; + } p->p_xsig = data; /*