From 36b8c5d486fa809443a7d522780bf3c5a6f70393 Mon Sep 17 00:00:00 2001
From: marcel <marcel@FreeBSD.org>
Date: Tue, 7 Jun 2011 01:28:12 +0000
Subject: Fix making kernel dumps from the debugger by creating a command for
 it. Do not not expect a developer to call doadump(). Calling doadump does not
 necessarily work when it's declared static. Nor does it necessarily do what
 was intended in the context of text dumps. The dump command always creates a
 core dump.

Move printing of error messages from doadump to the dump command,
now that we don't have to worry about being called from DDB.
---
 sys/ddb/db_command.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

(limited to 'sys/ddb/db_command.c')

diff --git a/sys/ddb/db_command.c b/sys/ddb/db_command.c
index 21cb7c5..f2e2c42 100644
--- a/sys/ddb/db_command.c
+++ b/sys/ddb/db_command.c
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/signalvar.h>
 #include <sys/systm.h>
 #include <sys/cons.h>
+#include <sys/conf.h>
 #include <sys/watchdog.h>
 #include <sys/kernel.h>
 
@@ -64,6 +65,7 @@ db_addr_t	db_last_addr;
 db_addr_t	db_prev;
 db_addr_t	db_next;
 
+static db_cmdfcn_t	db_dump;
 static db_cmdfcn_t	db_fncall;
 static db_cmdfcn_t	db_gdb;
 static db_cmdfcn_t	db_halt;
@@ -102,6 +104,7 @@ static struct command db_cmds[] = {
 	{ "w",		db_write_cmd,		CS_MORE|CS_SET_DOT, 0 },
 	{ "delete",	db_delete_cmd,		0,	0 },
 	{ "d",		db_delete_cmd,		0,	0 },
+	{ "dump",	db_dump,		0,	0 },
 	{ "break",	db_breakpoint_cmd,	0,	0 },
 	{ "b",		db_breakpoint_cmd,	0,	0 },
 	{ "dwatch",	db_deletewatch_cmd,	0,	0 },
@@ -526,6 +529,27 @@ db_error(s)
 	kdb_reenter();
 }
 
+static void
+db_dump(db_expr_t dummy, boolean_t dummy2, db_expr_t dummy3, char *dummy4)
+{
+	int error;
+
+	error = doadump(FALSE);
+	if (error) {
+		db_printf("Cannot dump: ");
+		switch (error) {
+		case EBUSY:
+			db_printf("debugger got invoked while dumping.\n");
+			break;
+		case ENXIO:
+			db_printf("no dump device specified.\n");
+			break;
+		default:
+			db_printf("unknown error (error=%d).\n", error);
+			break;
+		}
+	}
+}
 
 /*
  * Call random function:
-- 
cgit v1.1