Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Register KTR events for debugger related signals
details: https://anonhg.NetBSD.org/src/rev/a170f96d1d9b
branches: trunk
changeset: 998819:a170f96d1d9b
user: kamil <kamil%NetBSD.org@localhost>
date: Fri May 03 22:34:21 2019 +0000
description:
Register KTR events for debugger related signals
Register signals for:
- crashes (FPE, SEGV, FPE, ILL, BUS)
- LWP events
- CHLD (FORK/VFORK/VFORK_DONE) events -- temporarily disabled
- EXEC events
While there refactor related functions in order to simplify the code.
Add missing comment documentation for recently added kernel functions.
diffstat:
sys/kern/kern_exec.c | 8 +--
sys/kern/kern_fork.c | 29 +++++++++------
sys/kern/kern_lwp.c | 8 +--
sys/kern/kern_sig.c | 91 +++++++++++++++++++++++++++++++++++++++------------
sys/kern/sys_lwp.c | 8 +--
sys/sys/signalvar.h | 4 +-
6 files changed, 97 insertions(+), 51 deletions(-)
diffs (truncated from 414 to 300 lines):
diff -r a37e949d0daf -r a170f96d1d9b sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c Fri May 03 19:06:50 2019 +0000
+++ b/sys/kern/kern_exec.c Fri May 03 22:34:21 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exec.c,v 1.463 2019/05/01 17:21:55 kamil Exp $ */
+/* $NetBSD: kern_exec.c,v 1.464 2019/05/03 22:34:21 kamil Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.463 2019/05/01 17:21:55 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.464 2019/05/03 22:34:21 kamil Exp $");
#include "opt_exec.h"
#include "opt_execfmt.h"
@@ -1271,9 +1271,7 @@
if ((p->p_slflag & (PSL_TRACED|PSL_SYSCALL)) == PSL_TRACED) {
mutex_enter(p->p_lock);
- eventswitch(SIGTRAP, TRAP_EXEC);
- // XXX ktrpoint(KTR_PSIG)
- mutex_exit(p->p_lock);
+ eventswitch(TRAP_EXEC);
mutex_enter(proc_lock);
}
diff -r a37e949d0daf -r a170f96d1d9b sys/kern/kern_fork.c
--- a/sys/kern/kern_fork.c Fri May 03 19:06:50 2019 +0000
+++ b/sys/kern/kern_fork.c Fri May 03 22:34:21 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_fork.c,v 1.211 2019/05/01 18:01:54 kamil Exp $ */
+/* $NetBSD: kern_fork.c,v 1.212 2019/05/03 22:34:21 kamil Exp $ */
/*-
* Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.211 2019/05/01 18:01:54 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.212 2019/05/03 22:34:21 kamil Exp $");
#include "opt_ktrace.h"
#include "opt_dtrace.h"
@@ -203,6 +203,9 @@
*/
static struct timeval fork_tfmrate = { 10, 0 };
+/*
+ * Check if a process is traced and shall inform about FORK events.
+ */
static inline bool
tracefork(struct proc *p, int flags)
{
@@ -211,6 +214,9 @@
(PSL_TRACEFORK|PSL_TRACED) && (flags & FORK_PPWAIT) == 0;
}
+/*
+ * Check if a process is traced and shall inform about VFORK events.
+ */
static inline bool
tracevfork(struct proc *p, int flags)
{
@@ -219,6 +225,9 @@
(PSL_TRACEVFORK|PSL_TRACED) && (flags & FORK_PPWAIT) != 0;
}
+/*
+ * Check if a process is traced and shall inform about VFORK_DONE events.
+ */
static inline bool
tracevforkdone(struct proc *p, int flags)
{
@@ -595,9 +604,7 @@
*/
if (tracefork(p1, flags) || tracevfork(p1, flags)) {
mutex_enter(p1->p_lock);
- eventswitch(SIGTRAP, TRAP_CHLD);
- // XXX ktrpoint(KTR_PSIG)
- mutex_exit(p1->p_lock);
+ eventswitch(TRAP_CHLD);
mutex_enter(proc_lock);
}
@@ -614,16 +621,16 @@
if (tracevforkdone(p1, flags)) {
mutex_enter(p1->p_lock);
p1->p_vfpid_done = retval[0];
- eventswitch(SIGTRAP, TRAP_CHLD);
- // XXX ktrpoint(KTR_PSIG)
- mutex_exit(p1->p_lock);
- // proc_lock unlocked
+ eventswitch(TRAP_CHLD);
} else
mutex_exit(proc_lock);
return 0;
}
+/*
+ * MI code executed in each newly spawned process before returning to userland.
+ */
void
child_return(void *arg)
{
@@ -639,9 +646,7 @@
}
mutex_enter(p->p_lock);
- eventswitch(SIGTRAP, TRAP_CHLD);
- // XXX ktrpoint(KTR_PSIG)
- mutex_exit(p->p_lock);
+ eventswitch(TRAP_CHLD);
}
my_tracer_is_gone:
diff -r a37e949d0daf -r a170f96d1d9b sys/kern/kern_lwp.c
--- a/sys/kern/kern_lwp.c Fri May 03 19:06:50 2019 +0000
+++ b/sys/kern/kern_lwp.c Fri May 03 22:34:21 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_lwp.c,v 1.199 2019/05/02 22:23:49 kamil Exp $ */
+/* $NetBSD: kern_lwp.c,v 1.200 2019/05/03 22:34:21 kamil Exp $ */
/*-
* Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -211,7 +211,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.199 2019/05/02 22:23:49 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.200 2019/05/03 22:34:21 kamil Exp $");
#include "opt_ddb.h"
#include "opt_lockdebug.h"
@@ -1083,9 +1083,7 @@
(PSL_TRACED|PSL_TRACELWP_EXIT)) {
mutex_enter(p->p_lock);
p->p_lwp_exited = l->l_lid;
- eventswitch(SIGTRAP, TRAP_LWP);
- // XXX ktrpoint(KTR_PSIG)
- mutex_exit(p->p_lock);
+ eventswitch(TRAP_LWP);
mutex_enter(proc_lock);
}
diff -r a37e949d0daf -r a170f96d1d9b sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c Fri May 03 19:06:50 2019 +0000
+++ b/sys/kern/kern_sig.c Fri May 03 22:34:21 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_sig.c,v 1.356 2019/05/02 22:23:49 kamil Exp $ */
+/* $NetBSD: kern_sig.c,v 1.357 2019/05/03 22:34:21 kamil Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.356 2019/05/02 22:23:49 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.357 2019/05/03 22:34:21 kamil Exp $");
#include "opt_ptrace.h"
#include "opt_dtrace.h"
@@ -902,6 +902,7 @@
struct sigacts *ps;
int signo = ksi->ksi_signo;
sigset_t *mask;
+ sig_t action;
KASSERT(KSI_TRAP_P(ksi));
@@ -912,6 +913,10 @@
mutex_enter(proc_lock);
mutex_enter(p->p_lock);
+ mask = &l->l_sigmask;
+ ps = p->p_sigacts;
+ action = SIGACTION_PS(ps, signo).sa_handler;
+
if (ISSET(p->p_slflag, PSL_TRACED) &&
!(p->p_pptr == p->p_opptr && ISSET(p->p_lflag, PL_PPWAIT)) &&
p->p_xsig != SIGKILL &&
@@ -921,14 +926,16 @@
p->p_sigctx.ps_lwp = ksi->ksi_lid;
p->p_sigctx.ps_info = ksi->ksi_info;
sigswitch(0, signo, false);
- // XXX ktrpoint(KTR_PSIG)
- mutex_exit(p->p_lock);
+
+ if (ktrpoint(KTR_PSIG)) {
+ if (p->p_emul->e_ktrpsig)
+ p->p_emul->e_ktrpsig(signo, action, mask, ksi);
+ else
+ ktrpsig(signo, action, mask, ksi);
+ }
return;
}
- mask = &l->l_sigmask;
- ps = p->p_sigacts;
-
const bool caught = sigismember(&p->p_sigctx.ps_sigcatch, signo);
const bool masked = sigismember(mask, signo);
if (caught && !masked) {
@@ -936,15 +943,12 @@
l->l_ru.ru_nsignals++;
kpsendsig(l, ksi, mask);
mutex_exit(p->p_lock);
+
if (ktrpoint(KTR_PSIG)) {
if (p->p_emul->e_ktrpsig)
- p->p_emul->e_ktrpsig(signo,
- SIGACTION_PS(ps, signo).sa_handler,
- mask, ksi);
+ p->p_emul->e_ktrpsig(signo, action, mask, ksi);
else
- ktrpsig(signo,
- SIGACTION_PS(ps, signo).sa_handler,
- mask, ksi);
+ ktrpsig(signo, action, mask, ksi);
}
return;
}
@@ -954,7 +958,7 @@
* reset it to the default action so that the process or
* its tracer will be notified.
*/
- const bool ignored = SIGACTION_PS(ps, signo).sa_handler == SIG_IGN;
+ const bool ignored = action == SIG_IGN;
if (masked || ignored) {
mutex_enter(&ps->sa_mutex);
sigdelset(mask, signo);
@@ -1539,35 +1543,68 @@
}
}
+/*
+ * Stop the current process and switch away to the debugger notifying
+ * an event specific to a traced process only.
+ */
void
-eventswitch(int signo, int code)
+eventswitch(int code)
{
struct lwp *l = curlwp;
struct proc *p = l->l_proc;
+ struct sigacts *ps;
+ sigset_t *mask;
+ sig_t action;
+ ksiginfo_t ksi;
+ const int signo = SIGTRAP;
KASSERT(mutex_owned(proc_lock));
KASSERT(mutex_owned(p->p_lock));
+ KASSERT(p->p_pptr != initproc);
KASSERT(l->l_stat == LSONPROC);
- KASSERT((l->l_flag & LW_SYSTEM) == 0);
+ KASSERT(ISSET(p->p_slflag, PSL_TRACED));
+ KASSERT(!ISSET(l->l_flag, LW_SYSTEM));
KASSERT(p->p_nrlwps > 0);
+ KASSERT((code == TRAP_CHLD) || (code == TRAP_LWP) ||
+ (code == TRAP_EXEC));
/*
* If there's a pending SIGKILL process it immediately.
*/
if (p->p_xsig == SIGKILL ||
sigismember(&p->p_sigpend.sp_set, SIGKILL)) {
+ mutex_exit(p->p_lock);
mutex_exit(proc_lock);
return;
}
+ KSI_INIT_TRAP(&ksi);
+ ksi.ksi_lid = l->l_lid;
+ ksi.ksi_info._signo = signo;
+ ksi.ksi_info._code = code;
+
+ /* Needed for ktrace */
+ ps = p->p_sigacts;
+ action = SIGACTION_PS(ps, signo).sa_handler;
+ mask = &l->l_sigmask;
+
p->p_xsig = signo;
p->p_sigctx.ps_faked = true;
- p->p_sigctx.ps_lwp = l->l_lid;
- memset(&p->p_sigctx.ps_info, 0, sizeof(p->p_sigctx.ps_info));
- p->p_sigctx.ps_info._signo = signo;
- p->p_sigctx.ps_info._code = code;
+ p->p_sigctx.ps_lwp = ksi.ksi_lid;
+ p->p_sigctx.ps_info = ksi.ksi_info;
sigswitch(0, signo, false);
+
+ /* XXX: hangs for VFORK */
+ if (code == TRAP_CHLD)
Home |
Main Index |
Thread Index |
Old Index