svn commit: r229254 - stable/9/sys/ddb

Konstantin Belousov kib at FreeBSD.org
Mon Jan 2 00:01:10 UTC 2012


Author: kib
Date: Mon Jan  2 00:01:09 2012
New Revision: 229254
URL: http://svn.freebsd.org/changeset/base/229254

Log:
  MFC r228569:
  Add 'findstack' ddb command to search either the thread kernel stack
  or cached stack containing the specified kernel virtual address.

Modified:
  stable/9/sys/ddb/db_command.c
  stable/9/sys/ddb/db_ps.c
  stable/9/sys/ddb/ddb.h
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/ddb/db_command.c
==============================================================================
--- stable/9/sys/ddb/db_command.c	Sun Jan  1 23:58:42 2012	(r229253)
+++ stable/9/sys/ddb/db_command.c	Mon Jan  2 00:01:09 2012	(r229254)
@@ -140,6 +140,7 @@ static struct command db_cmds[] = {
 	{ "unscript",	db_unscript_cmd,	CS_OWN,	0 },
 	{ "capture",	db_capture_cmd,		CS_OWN,	0 },
 	{ "textdump",	db_textdump_cmd,	CS_OWN, 0 },
+	{ "findstack",	db_findstack_cmd,	0,	0 },
 };
 struct command_table db_cmd_table = LIST_HEAD_INITIALIZER(db_cmd_table);
 

Modified: stable/9/sys/ddb/db_ps.c
==============================================================================
--- stable/9/sys/ddb/db_ps.c	Sun Jan  1 23:58:42 2012	(r229253)
+++ stable/9/sys/ddb/db_ps.c	Mon Jan  2 00:01:09 2012	(r229254)
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/proc.h>
 #include <sys/sysent.h>
 #include <sys/systm.h>
+#include <sys/_kstack_cache.h>
 #include <vm/vm.h>
 #include <vm/vm_param.h>
 #include <vm/pmap.h>
@@ -429,3 +430,39 @@ DB_SHOW_COMMAND(proc, db_show_proc)
 			break;
 	}
 }
+
+void
+db_findstack_cmd(db_expr_t addr, boolean_t have_addr,
+    db_expr_t dummy3 __unused, char *dummy4 __unused)
+{
+	struct proc *p;
+	struct thread *td;
+	struct kstack_cache_entry *ks_ce;
+	vm_offset_t saddr;
+
+	if (have_addr)
+		saddr = addr;
+	else {
+		db_printf("Usage: findstack <address>\n");
+		return;
+	}
+
+	for (p = LIST_FIRST(&allproc); p != NULL; p = LIST_NEXT(p, p_list)) {
+		FOREACH_THREAD_IN_PROC(p, td) {
+			if (td->td_kstack <= saddr && saddr < td->td_kstack +
+			    PAGE_SIZE * td->td_kstack_pages) {
+				db_printf("Thread %p\n", td);
+				return;
+			}
+		}
+	}
+
+	for (ks_ce = kstack_cache; ks_ce != NULL;
+	     ks_ce = ks_ce->next_ks_entry) {
+		if ((vm_offset_t)ks_ce <= saddr && saddr < (vm_offset_t)ks_ce +
+		    PAGE_SIZE * KSTACK_PAGES) {
+			db_printf("Cached stack %p\n", ks_ce);
+			return;
+		}
+	}
+}

Modified: stable/9/sys/ddb/ddb.h
==============================================================================
--- stable/9/sys/ddb/ddb.h	Sun Jan  1 23:58:42 2012	(r229253)
+++ stable/9/sys/ddb/ddb.h	Mon Jan  2 00:01:09 2012	(r229254)
@@ -226,6 +226,7 @@ db_cmdfcn_t	db_delete_cmd;
 db_cmdfcn_t	db_deletehwatch_cmd;
 db_cmdfcn_t	db_deletewatch_cmd;
 db_cmdfcn_t	db_examine_cmd;
+db_cmdfcn_t	db_findstack_cmd;
 db_cmdfcn_t	db_hwatchpoint_cmd;
 db_cmdfcn_t	db_listbreak_cmd;
 db_cmdfcn_t	db_scripts_cmd;


More information about the svn-src-stable-9 mailing list