Sat Dec 3 16:25:50 2011 UTC ()
If we are DIAGNOSTIC don't try to go further if we failed to take the
lock, because we are going to trigger a KASSERT. Also hold the lock
longer and take the proc lock for kpsignal(). Maybe we should add
mutex_steal() and mutex_return() for the debugger? Lock correction
suggestion from jmcneill.


(christos)
diff -r1.65 -r1.66 src/sys/ddb/db_xxx.c

cvs diff -r1.65 -r1.66 src/sys/ddb/db_xxx.c (expand / switch to context diff)
--- src/sys/ddb/db_xxx.c 2011/12/02 23:57:58 1.65
+++ src/sys/ddb/db_xxx.c 2011/12/03 16:25:49 1.66
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_xxx.c,v 1.65 2011/12/02 23:57:58 christos Exp $	*/
+/*	$NetBSD: db_xxx.c,v 1.66 2011/12/03 16:25:49 christos Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.65 2011/12/02 23:57:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.66 2011/12/03 16:25:49 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_kgdb.h"
@@ -108,19 +108,29 @@
 	}
 	/* We might stop when the mutex is held or when not */
 	t = mutex_tryenter(proc_lock);
+#ifdef DIAGNOSTIC
+	if (!t) {
+	       db_error("could not acquire proc_lock mutex\n");
+	       /*NOTREACHED*/
+	}
+#endif
 	p = proc_find((pid_t)pid);
-	if (t)
-		mutex_exit(proc_lock);
 	if (p == NULL) {
-	       db_error("no such proc\n");
-	       /*NOTREACHED*/
+		if (t)
+			mutex_exit(proc_lock);
+		db_error("no such proc\n");
+		/*NOTREACHED*/
 	}
 	KSI_INIT(&ksi);
 	ksi.ksi_signo = sig;
 	ksi.ksi_code = SI_USER;
 	ksi.ksi_pid = 0;
 	ksi.ksi_uid = 0;
+	mutex_enter(p->p_lock);
 	kpsignal2(p, &ksi);
+	mutex_exit(p->p_lock);
+	if (t)
+		mutex_exit(proc_lock);
 #else
 	db_printf("This command is not currently supported.\n");
 #endif