Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 May 2012 21:16:08 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r235742 - in stable/8/sys: ddb gdb kern sys
Message-ID:  <201205212116.q4LLG8V0073045@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Mon May 21 21:16:08 2012
New Revision: 235742
URL: http://svn.freebsd.org/changeset/base/235742

Log:
  MFC 234190,234196,234280:
  - Extend the KDB interface to add a per-debugger callback to print a
    backtrace for an arbitrary thread (rather than the calling thread).
    A kdb_backtrace_thread() wrapper function uses the configured debugger
    if possible, otherwise it falls back to using stack(9) if that is
    available.
  - Replace a direct call to db_trace_thread() in propagate_priority()
    with a call to kdb_backtrace_thread() instead.

Modified:
  stable/8/sys/ddb/db_main.c
  stable/8/sys/gdb/gdb_main.c
  stable/8/sys/kern/subr_kdb.c
  stable/8/sys/kern/subr_turnstile.c
  stable/8/sys/sys/kdb.h
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/boot/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)
  stable/8/sys/dev/e1000/   (props changed)

Modified: stable/8/sys/ddb/db_main.c
==============================================================================
--- stable/8/sys/ddb/db_main.c	Mon May 21 21:14:09 2012	(r235741)
+++ stable/8/sys/ddb/db_main.c	Mon May 21 21:16:08 2012	(r235742)
@@ -51,8 +51,10 @@ SYSCTL_NODE(_debug, OID_AUTO, ddb, CTLFL
 static dbbe_init_f db_init;
 static dbbe_trap_f db_trap;
 static dbbe_trace_f db_trace_self_wrapper;
+static dbbe_trace_thread_f db_trace_thread_wrapper;
 
-KDB_BACKEND(ddb, db_init, db_trace_self_wrapper, db_trap);
+KDB_BACKEND(ddb, db_init, db_trace_self_wrapper, db_trace_thread_wrapper,
+    db_trap);
 
 vm_offset_t ksym_start, ksym_end;
 
@@ -246,3 +248,15 @@ db_trace_self_wrapper(void)
 		db_trace_self();
 	(void)kdb_jmpbuf(prev_jb);
 }
+
+static void
+db_trace_thread_wrapper(struct thread *td)
+{
+	jmp_buf jb;
+	void *prev_jb;
+
+	prev_jb = kdb_jmpbuf(jb);
+	if (setjmp(jb) == 0)
+		db_trace_thread(td, -1);
+	(void)kdb_jmpbuf(prev_jb);
+}

Modified: stable/8/sys/gdb/gdb_main.c
==============================================================================
--- stable/8/sys/gdb/gdb_main.c	Mon May 21 21:14:09 2012	(r235741)
+++ stable/8/sys/gdb/gdb_main.c	Mon May 21 21:16:08 2012	(r235742)
@@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$");
 static dbbe_init_f gdb_init;
 static dbbe_trap_f gdb_trap;
 
-KDB_BACKEND(gdb, gdb_init, NULL, gdb_trap);
+KDB_BACKEND(gdb, gdb_init, NULL, NULL, gdb_trap);
 
 static struct gdb_dbgport null_gdb_dbgport;
 DATA_SET(gdb_dbgport_set, null_gdb_dbgport);

Modified: stable/8/sys/kern/subr_kdb.c
==============================================================================
--- stable/8/sys/kern/subr_kdb.c	Mon May 21 21:14:09 2012	(r235741)
+++ stable/8/sys/kern/subr_kdb.c	Mon May 21 21:16:08 2012	(r235742)
@@ -71,7 +71,7 @@ struct trapframe *kdb_frame = NULL;
 static int	kdb_break_to_debugger = KDB_BREAK_TO_DEBUGGER;
 static int	kdb_alt_break_to_debugger = KDB_ALT_BREAK_TO_DEBUGGER;
 
-KDB_BACKEND(null, NULL, NULL, NULL);
+KDB_BACKEND(null, NULL, NULL, NULL, NULL);
 SET_DECLARE(kdb_dbbe_set, struct kdb_dbbe);
 
 static int kdb_sysctl_available(SYSCTL_HANDLER_ARGS);
@@ -384,6 +384,7 @@ kdb_backtrace(void)
 		struct stack st;
 
 		printf("KDB: stack backtrace:\n");
+		stack_zero(&st);
 		stack_save(&st);
 		stack_print_ddb(&st);
 	}
@@ -391,6 +392,30 @@ kdb_backtrace(void)
 }
 
 /*
+ * Similar to kdb_backtrace() except that it prints a backtrace of an
+ * arbitrary thread rather than the calling thread.
+ */
+void
+kdb_backtrace_thread(struct thread *td)
+{
+
+	if (kdb_dbbe != NULL && kdb_dbbe->dbbe_trace_thread != NULL) {
+		printf("KDB: stack backtrace of thread %d:\n", td->td_tid);
+		kdb_dbbe->dbbe_trace_thread(td);
+	}
+#ifdef STACK
+	else {
+		struct stack st;
+
+		printf("KDB: stack backtrace of thread %d:\n", td->td_tid);
+		stack_zero(&st);
+		stack_save_td(&st, td);
+		stack_print_ddb(&st);
+	}
+#endif
+}
+
+/*
  * Set/change the current backend.
  */
 

Modified: stable/8/sys/kern/subr_turnstile.c
==============================================================================
--- stable/8/sys/kern/subr_turnstile.c	Mon May 21 21:14:09 2012	(r235741)
+++ stable/8/sys/kern/subr_turnstile.c	Mon May 21 21:16:08 2012	(r235742)
@@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/kdb.h>
 #include <sys/kernel.h>
 #include <sys/ktr.h>
 #include <sys/lock.h>
@@ -78,7 +79,6 @@ __FBSDID("$FreeBSD$");
 #include <vm/uma.h>
 
 #ifdef DDB
-#include <sys/kdb.h>
 #include <ddb/ddb.h>
 #include <sys/lockmgr.h>
 #include <sys/sx.h>
@@ -216,9 +216,7 @@ propagate_priority(struct thread *td)
 			printf(
 		"Sleeping thread (tid %d, pid %d) owns a non-sleepable lock\n",
 			    td->td_tid, td->td_proc->p_pid);
-#ifdef DDB
-			db_trace_thread(td, -1);
-#endif
+			kdb_backtrace_thread(td);
 			panic("sleeping thread");
 		}
 

Modified: stable/8/sys/sys/kdb.h
==============================================================================
--- stable/8/sys/sys/kdb.h	Mon May 21 21:14:09 2012	(r235741)
+++ stable/8/sys/sys/kdb.h	Mon May 21 21:16:08 2012	(r235742)
@@ -31,31 +31,34 @@
 
 #include <machine/setjmp.h>
 
+struct pcb;
+struct thread;
+struct trapframe;
+
 typedef int dbbe_init_f(void);
 typedef void dbbe_trace_f(void);
+typedef void dbbe_trace_thread_f(struct thread *);
 typedef int dbbe_trap_f(int, int);
 
 struct kdb_dbbe {
 	const char	*dbbe_name;
 	dbbe_init_f	*dbbe_init;
 	dbbe_trace_f	*dbbe_trace;
+	dbbe_trace_thread_f *dbbe_trace_thread;
 	dbbe_trap_f	*dbbe_trap;
 	int		dbbe_active;
 };
 
-#define	KDB_BACKEND(name, init, trace, trap)		\
+#define	KDB_BACKEND(name, init, trace, trace_thread, trap) \
 	static struct kdb_dbbe name##_dbbe = {		\
 		.dbbe_name = #name,			\
 		.dbbe_init = init,			\
 		.dbbe_trace = trace,			\
+		.dbbe_trace_thread = trace_thread,	\
 		.dbbe_trap = trap			\
 	};						\
 	DATA_SET(kdb_dbbe_set, name##_dbbe)
 
-struct pcb;
-struct thread;
-struct trapframe;
-
 extern int kdb_active;			/* Non-zero while in debugger. */
 extern int debugger_on_panic;		/* enter the debugger on panic. */
 extern struct kdb_dbbe *kdb_dbbe;	/* Default debugger backend or NULL. */
@@ -67,6 +70,7 @@ int	kdb_alt_break(int, int *);
 int	kdb_alt_break_gdb(int, int *);
 int	kdb_break(void);
 void	kdb_backtrace(void);
+void	kdb_backtrace_thread(struct thread *);
 int	kdb_dbbe_select(const char *);
 void	kdb_enter(const char *, const char *);
 void	kdb_init(void);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201205212116.q4LLG8V0073045>