Module Name:    src
Committed By:   christos
Date:           Sun Feb  8 19:41:00 UTC 2015

Modified Files:
        src/sys/kern: kern_timeout.c

Log Message:
make the ddb code crash(8) friendly.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/kern/kern_timeout.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_timeout.c
diff -u src/sys/kern/kern_timeout.c:1.48 src/sys/kern/kern_timeout.c:1.49
--- src/sys/kern/kern_timeout.c:1.48	Wed Dec 10 12:09:49 2014
+++ src/sys/kern/kern_timeout.c	Sun Feb  8 14:41:00 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_timeout.c,v 1.48 2014/12/10 17:09:49 martin Exp $	*/
+/*	$NetBSD: kern_timeout.c,v 1.49 2015/02/08 19:41:00 christos Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_timeout.c,v 1.48 2014/12/10 17:09:49 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_timeout.c,v 1.49 2015/02/08 19:41:00 christos Exp $");
 
 /*
  * Timeouts are kept in a hierarchical timing wheel.  The c_time is the
@@ -101,6 +101,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_timeout
 #include <machine/db_machdep.h>
 #include <ddb/db_interface.h>
 #include <ddb/db_access.h>
+#include <ddb/db_cpu.h>
 #include <ddb/db_sym.h>
 #include <ddb/db_output.h>
 #endif
@@ -165,8 +166,6 @@ do {									\
 #define CIRCQ_LAST(elem,list)	((elem)->cq_next_l == (list))
 #define CIRCQ_EMPTY(list)	((list)->cq_next_l == (list))
 
-static void	callout_softclock(void *);
-
 struct callout_cpu {
 	kmutex_t	*cc_lock;
 	sleepq_t	cc_sleepq;
@@ -183,6 +182,9 @@ struct callout_cpu {
 	char		cc_name2[12];
 };
 
+#ifndef CRASH
+
+static void	callout_softclock(void *);
 static struct callout_cpu callout_cpu0;
 static void *callout_sih;
 
@@ -757,21 +759,32 @@ callout_softclock(void *v)
 	cc->cc_lwp = NULL;
 	mutex_spin_exit(cc->cc_lock);
 }
+#endif
 
 #ifdef DDB
 static void
 db_show_callout_bucket(struct callout_cpu *cc, struct callout_circq *bucket)
 {
-	callout_impl_t *c;
+	callout_impl_t *c, ci;
 	db_expr_t offset;
 	const char *name;
 	static char question[] = "?";
+	struct callout_circq bi;
+	struct callout_cpu cci;
 	int b;
 
+	db_read_bytes((db_addr_t)cc, sizeof(cci), (char *)&cci);
+	cc = &cci;
+
+	db_read_bytes((db_addr_t)bucket, sizeof(bi), (char *)&bi);
+	bucket = &bi;
+
 	if (CIRCQ_EMPTY(bucket))
 		return;
 
 	for (c = CIRCQ_FIRST(bucket); /*nothing*/; c = CIRCQ_NEXT(&c->c_list)) {
+		db_read_bytes((db_addr_t)c, sizeof(ci), (char *)&ci);
+		c = &ci;
 		db_find_sym_and_offset((db_addr_t)(intptr_t)c->c_func, &name,
 		    &offset);
 		name = name ? name : question;
@@ -789,12 +802,13 @@ db_show_callout_bucket(struct callout_cp
 void
 db_show_callout(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
 {
-	CPU_INFO_ITERATOR cii;
 	struct callout_cpu *cc;
 	struct cpu_info *ci;
 	int b;
 
+#ifndef CRASH
 	db_printf("hardclock_ticks now: %d\n", hardclock_ticks);
+#endif
 	db_printf("    ticks  wheel               arg  func\n");
 
 	/*
@@ -802,13 +816,15 @@ db_show_callout(db_expr_t addr, bool had
 	 * anyhow, and we might be called in a circumstance where
 	 * some other CPU was paused while holding the lock.
 	 */
-	for (CPU_INFO_FOREACH(cii, ci)) {
-		cc = ci->ci_data.cpu_callout;
+	for (ci = db_cpu_first(); ci != NULL; ci = db_cpu_next(ci)) {
+		db_read_bytes((db_addr_t)&ci->ci_data.cpu_callout,
+		    sizeof(cc), (char *)&cc);
 		db_show_callout_bucket(cc, &cc->cc_todo);
 	}
 	for (b = 0; b < BUCKETS; b++) {
-		for (CPU_INFO_FOREACH(cii, ci)) {
-			cc = ci->ci_data.cpu_callout;
+		for (ci = db_cpu_first(); ci != NULL; ci = db_cpu_next(ci)) {
+			db_read_bytes((db_addr_t)&ci->ci_data.cpu_callout,
+			    sizeof(cc), (char *)&cc);
 			db_show_callout_bucket(cc, &cc->cc_wheel[b]);
 		}
 	}

Reply via email to