Index: sys/sys/lockdebug.h
===================================================================
RCS file: /cvsroot/src/sys/sys/lockdebug.h,v
retrieving revision 1.14
diff -p -u -r1.14 lockdebug.h
--- sys/sys/lockdebug.h	27 Apr 2013 08:12:34 -0000	1.14
+++ sys/sys/lockdebug.h	28 Jun 2015 14:37:58 -0000
@@ -86,11 +113,20 @@ void	lockdebug_wakeup(volatile void *, u
 
 #else	/* LOCKDEBUG */
 
+#include <sys/lwp.h>
+
 #define	LOCKDEBUG_ALLOC(lock, ops, addr)		false
 #define	LOCKDEBUG_FREE(dodebug, lock)			/* nothing */
 #define	LOCKDEBUG_WANTLOCK(dodebug, lock, where, s)	/* nothing */
+#ifdef DIAGNOSTIC
+#define	LOCKDEBUG_LOCKED(dodebug, lock, al, where, s)	\
+	do { if (s) curlwp->l_shlocks++; else curlwp->l_exlocks++; } while (0)
+#define	LOCKDEBUG_UNLOCKED(dodebug, lock, where, s)	\
+	do { if (s) curlwp->l_shlocks--; else curlwp->l_exlocks--; } while (0)
+#else
 #define	LOCKDEBUG_LOCKED(dodebug, lock, al, where, s)	/* nothing */
 #define	LOCKDEBUG_UNLOCKED(dodebug, lock, where, s)	/* nothing */
+#endif
 #define	LOCKDEBUG_BARRIER(lock, slp)			/* nothing */
 #define	LOCKDEBUG_MEM_CHECK(base, sz)			/* nothing */
 #define	LOCKDEBUG_WAKEUP(dodebug, lock, where)		/* nothing */
Index: sys/sys/userret.h
===================================================================
RCS file: /cvsroot/src/sys/sys/userret.h,v
retrieving revision 1.26
diff -p -u -r1.26 userret.h
--- sys/sys/userret.h	7 Apr 2013 07:54:53 -0000	1.26
+++ sys/sys/userret.h	28 Jun 2015 14:37:58 -0000
@@ -83,6 +83,10 @@ mi_userret(struct lwp *l)
 #ifndef __HAVE_PREEMPTION
 	KASSERT(curcpu()->ci_biglock_count == 0);
 #endif
+#ifndef LOCKDEBUG
+	KASSERTMSG(l->l_exlocks == 0, "%hu exlocks held", l->l_exlocks);
+	KASSERTMSG(l->l_shlocks == 0, "%hu shlocks held", l->l_shlocks);
+#endif
 
 	/*
 	 * Handle "exceptional" events: pending signals, stop/exit actions,