Module Name:    src
Committed By:   christos
Date:           Sun Jan  6 03:23:55 UTC 2013

Modified Files:
        src/sys/ddb: db_command.c db_interface.h db_xxx.c

Log Message:
Add "show dmesg" that prints the contents of the message buffer.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/sys/ddb/db_command.c
cvs rdiff -u -r1.29 -r1.30 src/sys/ddb/db_interface.h
cvs rdiff -u -r1.67 -r1.68 src/sys/ddb/db_xxx.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/ddb/db_command.c
diff -u src/sys/ddb/db_command.c:1.139 src/sys/ddb/db_command.c:1.140
--- src/sys/ddb/db_command.c:1.139	Sat Jan  5 10:23:27 2013
+++ src/sys/ddb/db_command.c	Sat Jan  5 22:23:55 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_command.c,v 1.139 2013/01/05 15:23:27 christos Exp $	*/
+/*	$NetBSD: db_command.c,v 1.140 2013/01/06 03:23:55 christos Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.139 2013/01/05 15:23:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.140 2013/01/06 03:23:55 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_aio.h"
@@ -240,6 +240,8 @@ static const struct db_command db_show_c
 #endif
 	{ DDB_ADD_CMD("buf",	db_buf_print_cmd,	0,
 	    "Print the struct buf at address.", "[/f] address",NULL) },
+	{ DDB_ADD_CMD("dmesg",	db_show_dmesg,	0,
+	    "Print the current message buffer",NULL,NULL) },
 	{ DDB_ADD_CMD("event",	db_event_print_cmd,	0,
 	    "Print all the non-zero evcnt(9) event counters.", "[/fitm]",NULL) },
 	{ DDB_ADD_CMD("files", db_show_files_cmd,	0,

Index: src/sys/ddb/db_interface.h
diff -u src/sys/ddb/db_interface.h:1.29 src/sys/ddb/db_interface.h:1.30
--- src/sys/ddb/db_interface.h:1.29	Sat Jan  5 10:23:27 2013
+++ src/sys/ddb/db_interface.h	Sat Jan  5 22:23:55 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_interface.h,v 1.29 2013/01/05 15:23:27 christos Exp $	*/
+/*	$NetBSD: db_interface.h,v 1.30 2013/01/06 03:23:55 christos Exp $	*/
 
 /*-
  * Copyright (c) 1995 The NetBSD Foundation, Inc.
@@ -44,6 +44,7 @@ void		db_stack_trace_print(db_expr_t, bo
 void		db_kgdb_cmd(db_expr_t, bool, db_expr_t, const char *);
 void		db_show_files_cmd(db_expr_t, bool, db_expr_t, const char *);
 void		db_show_panic(db_expr_t, bool, db_expr_t, const char *);
+void		db_show_dmesg(db_expr_t, bool, db_expr_t, const char *);
 
 /* kern/kern_proc.c */
 void		db_kill_proc(db_expr_t, bool, db_expr_t, const char *);

Index: src/sys/ddb/db_xxx.c
diff -u src/sys/ddb/db_xxx.c:1.67 src/sys/ddb/db_xxx.c:1.68
--- src/sys/ddb/db_xxx.c:1.67	Sat Jan  5 10:23:27 2013
+++ src/sys/ddb/db_xxx.c	Sat Jan  5 22:23:55 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_xxx.c,v 1.67 2013/01/05 15:23:27 christos Exp $	*/
+/*	$NetBSD: db_xxx.c,v 1.68 2013/01/06 03:23:55 christos Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.67 2013/01/05 15:23:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.68 2013/01/06 03:23:55 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_kgdb.h"
@@ -320,3 +320,33 @@ db_show_panic(db_expr_t addr, bool haddr
 	(void)splx(s);
 #endif
 }
+
+extern kmutex_t log_lock;
+
+void
+db_show_dmesg(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
+{
+#ifdef _KERNEL	/* XXX CRASH(8) */
+	long maxlen, beg, end, len;
+
+	mutex_spin_enter(&log_lock);
+	maxlen = msgbufp->msg_bufs;
+	beg = msgbufp->msg_bufx;
+	end = msgbufp->msg_bufs;
+	mutex_spin_exit(&log_lock);
+
+	while (maxlen > 0) {
+		len = MIN(end - beg, maxlen);
+		if (len == 0)
+			break;
+		db_printf("%.*s", (int)len, (const char *)&msgbufp->msg_bufc[beg]);
+		maxlen -= len;
+		/*
+		 * ... then, copy from the beginning of message buffer to
+		 * the write pointer.
+		 */
+		beg = 0;
+		end = msgbufp->msg_bufx;
+	}
+#endif
+}

Reply via email to