svn commit: r235741 - in stable/9/sys: ddb gdb kern sys
John Baldwin
jhb at FreeBSD.org
Mon May 21 21:14:10 UTC 2012
Author: jhb
Date: Mon May 21 21:14:09 2012
New Revision: 235741
URL: http://svn.freebsd.org/changeset/base/235741
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/9/sys/ddb/db_main.c
stable/9/sys/gdb/gdb_main.c
stable/9/sys/kern/subr_kdb.c
stable/9/sys/kern/subr_turnstile.c
stable/9/sys/sys/kdb.h
Directory Properties:
stable/9/sys/ (props changed)
stable/9/sys/amd64/include/xen/ (props changed)
stable/9/sys/boot/ (props changed)
stable/9/sys/boot/i386/efi/ (props changed)
stable/9/sys/boot/ia64/efi/ (props changed)
stable/9/sys/boot/ia64/ski/ (props changed)
stable/9/sys/boot/powerpc/boot1.chrp/ (props changed)
stable/9/sys/boot/powerpc/ofw/ (props changed)
stable/9/sys/cddl/contrib/opensolaris/ (props changed)
stable/9/sys/conf/ (props changed)
stable/9/sys/contrib/dev/acpica/ (props changed)
stable/9/sys/contrib/octeon-sdk/ (props changed)
stable/9/sys/contrib/pf/ (props changed)
stable/9/sys/contrib/x86emu/ (props changed)
stable/9/sys/dev/ (props changed)
stable/9/sys/dev/e1000/ (props changed)
stable/9/sys/dev/ixgbe/ (props changed)
stable/9/sys/fs/ (props changed)
stable/9/sys/fs/ntfs/ (props changed)
stable/9/sys/modules/ (props changed)
Modified: stable/9/sys/ddb/db_main.c
==============================================================================
--- stable/9/sys/ddb/db_main.c Mon May 21 21:10:00 2012 (r235740)
+++ stable/9/sys/ddb/db_main.c Mon May 21 21:14:09 2012 (r235741)
@@ -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/9/sys/gdb/gdb_main.c
==============================================================================
--- stable/9/sys/gdb/gdb_main.c Mon May 21 21:10:00 2012 (r235740)
+++ stable/9/sys/gdb/gdb_main.c Mon May 21 21:14:09 2012 (r235741)
@@ -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/9/sys/kern/subr_kdb.c
==============================================================================
--- stable/9/sys/kern/subr_kdb.c Mon May 21 21:10:00 2012 (r235740)
+++ stable/9/sys/kern/subr_kdb.c Mon May 21 21:14:09 2012 (r235741)
@@ -73,7 +73,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);
@@ -371,6 +371,7 @@ kdb_backtrace(void)
struct stack st;
printf("KDB: stack backtrace:\n");
+ stack_zero(&st);
stack_save(&st);
stack_print_ddb(&st);
}
@@ -378,6 +379,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/9/sys/kern/subr_turnstile.c
==============================================================================
--- stable/9/sys/kern/subr_turnstile.c Mon May 21 21:10:00 2012 (r235740)
+++ stable/9/sys/kern/subr_turnstile.c Mon May 21 21:14:09 2012 (r235741)
@@ -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/9/sys/sys/kdb.h
==============================================================================
--- stable/9/sys/sys/kdb.h Mon May 21 21:10:00 2012 (r235740)
+++ stable/9/sys/sys/kdb.h Mon May 21 21:14:09 2012 (r235741)
@@ -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);
More information about the svn-src-stable-9
mailing list