Subject: not entering DDB on traps
To: None <tech-kern@netbsd.org>
From: Assar Westerlund <assar@sics.se>
List: tech-kern
Date: 12/29/1999 15:12:07
--=-=-=

Hi DDB-users.

I find it useful to always have DDB compiled into a kernel so that you
can break into ddb if you find the need for it.  If the machine is
remote, you of course, want it to crash dump instead and that's what
the `ddb.onpanic' sysctl knob is for.  But even if you have it set to
zero, DDB will still be triggered for traps and such.  And this is not
very convenient when the machine is remote.  So I think this should
also be configured with the same sysctl.  (You could make it a
different knob - but I see no reason for why you would want that).

A first cut at patches that implement that (for all the architectures
where this is sufficiently support) is appended below.  This is
untested.  Comments?

/assar


--=-=-=
Content-Disposition: attachment
Content-Description: patches to use db_onpanic to control ddb action on trap

Index: arch/alpha/alpha/trap.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/alpha/alpha/trap.c,v
retrieving revision 1.50
diff -u -w -r1.50 trap.c
--- trap.c	1999/12/04 21:19:57	1.50
+++ trap.c	1999/12/29 14:05:32
@@ -249,7 +249,7 @@
 	u_quad_t sticks;
 	int user;
 #if defined(DDB)
-	int call_debugger = 1;
+	int call_debugger = db_onpanic;
 #endif
 
 	uvmexp.traps++;
Index: arch/arm32/arm32/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/arm32/arm32/db_interface.c,v
retrieving revision 1.30
diff -u -w -r1.30 db_interface.c
--- db_interface.c	1999/10/28 06:49:20	1.30
+++ db_interface.c	1999/12/29 14:05:41
@@ -137,6 +137,9 @@
 	case -1:		/* keyboard interrupt */
 		break;
 	default:
+		if (!db_onpanic)
+			return (0);
+
 		db_printf("kernel: trap");
 		if (db_recover != 0) {
 			db_error("Faulted in DDB; continuing...\n");
Index: arch/bebox/bebox/kgdb_glue.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/bebox/bebox/kgdb_glue.c,v
retrieving revision 1.1
diff -u -w -r1.1 kgdb_glue.c
--- kgdb_glue.c	1997/10/14 06:47:41	1.1
+++ kgdb_glue.c	1999/12/29 14:05:41
@@ -65,6 +65,9 @@
 kgdb_trap_glue(frame)
 	struct trapframe *frame;
 {
+	if (!db_onpanic)
+		return (0);
+
 	if (!(frame->srr1 & PSL_PR)
 	    && (frame->exc == EXC_TRC
 		|| (frame->exc == EXC_PGM
Index: arch/i386/i386/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/i386/db_interface.c,v
retrieving revision 1.27
diff -u -w -r1.27 db_interface.c
--- db_interface.c	1999/10/12 17:08:58	1.27
+++ db_interface.c	1999/12/29 14:05:41
@@ -85,17 +85,15 @@
 {
 	int s;
 
-#if 0
-	if ((boothowto&RB_KDB) == 0)
-		return(0);
-#endif
-
 	switch (type) {
 	case T_BPTFLT:	/* breakpoint */
 	case T_TRCTRAP:	/* single_step */
 	case -1:	/* keyboard interrupt */
 		break;
 	default:
+		if (!db_onpanic)
+			return (0);
+
 		kdbprinttrap(type, code);
 		if (db_recover != 0) {
 			db_error("Faulted in DDB; continuing...\n");
Index: arch/m68k/m68k/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/m68k/m68k/db_interface.c,v
retrieving revision 1.26
diff -u -w -r1.26 db_interface.c
--- db_interface.c	1999/10/12 17:08:58	1.26
+++ db_interface.c	1999/12/29 14:05:42
@@ -77,7 +77,6 @@
 	int	type;
 	register db_regs_t *regs;
 {
-
 	switch (type) {
 	case T_TRACE:		/* single-step */
 	case T_BREAKPOINT:	/* breakpoint */
@@ -86,6 +85,9 @@
 	case -1:
 		break;
 	default:
+		if (!db_onpanic)
+			return (0);
+
 		kdbprinttrap(type, 0);
 		if (db_recover != 0) {
 			/* This will longjmp back to db_command_loop */
Index: arch/mips/mips/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/mips/mips/db_interface.c,v
retrieving revision 1.22
diff -u -w -r1.22 db_interface.c
--- db_interface.c	1999/11/29 11:12:13	1.22
+++ db_interface.c	1999/12/29 14:05:47
@@ -118,6 +118,9 @@
 {
 	struct frame *f = (struct frame *)&ddb_regs;
 
+	if (!db_onpanic)
+		return (0);
+
 #ifdef notyet
 	switch (type) {
 	case T_BREAK:		/* breakpoint */
Index: arch/pc532/pc532/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/pc532/pc532/db_interface.c,v
retrieving revision 1.8
diff -u -w -r1.8 db_interface.c
--- db_interface.c	1998/07/04 22:18:35	1.8
+++ db_interface.c	1999/12/29 14:05:47
@@ -95,6 +95,9 @@
 		break;
 		
 	default:
+		if (!db_onpanic)
+			return (0);
+
 		kdbprinttrap(type, code);
 		if (db_recover != 0) {
 			db_error("Faulted in DDB; continuing...\n");
Index: arch/sh3/sh3/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/sh3/sh3/db_interface.c,v
retrieving revision 1.1
diff -u -w -r1.1 db_interface.c
--- db_interface.c	1999/09/13 10:31:28	1.1
+++ db_interface.c	1999/12/29 14:05:47
@@ -86,17 +86,15 @@
 {
 	int s;
 
-#if 0
-	if ((boothowto&RB_KDB) == 0)
-		return(0);
-#endif
-
 	switch (type) {
 	case T_NMI:	/* NMI interrupt */
 	case T_USERBREAK:	/* breakpoint */
 	case -1:	/* keyboard interrupt */
 		break;
 	default:
+		if (!db_onpanic)
+			return(0);
+
 		kdbprinttrap(type, code);
 		if (db_recover != 0) {
 			db_error("Faulted in DDB; continuing...\n");
Index: arch/sparc/sparc/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/sparc/sparc/db_interface.c,v
retrieving revision 1.30
diff -u -w -r1.30 db_interface.c
--- db_interface.c	1999/10/12 17:08:59	1.30
+++ db_interface.c	1999/12/29 14:05:47
@@ -200,6 +200,9 @@
 	case -1:		/* keyboard interrupt */
 		break;
 	default:
+		if (!db_onpanic)
+			return (0);
+
 		printf("kernel: %s trap", trap_type[type & 0xff]);
 		if (db_recover != 0) {
 			db_error("Faulted in DDB; continuing...\n");
Index: arch/sparc64/sparc64/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/sparc64/sparc64/db_interface.c,v
retrieving revision 1.24
diff -u -w -r1.24 db_interface.c
--- db_interface.c	1999/11/06 20:18:13	1.24
+++ db_interface.c	1999/12/29 14:05:47
@@ -177,6 +177,9 @@
 		printf("kdb tf=%p\n", tf);
 		break;
 	default:
+		if (!db_onpanic)
+			return (0);
+
 		printf("kernel trap %x: %s\n", type, trap_type[type & 0x1ff]);
 		if (db_recover != 0) {
 #if 0
Index: arch/vax/vax/db_machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/vax/vax/db_machdep.c,v
retrieving revision 1.17
diff -u -w -r1.17 db_machdep.c
--- db_machdep.c	1999/06/20 00:58:23	1.17
+++ db_machdep.c	1999/12/29 14:05:53
@@ -128,7 +128,7 @@
 		break;
 
 	default:
-		if ((boothowto & RB_KDB) == 0)
+		if (!db_onpanic)
 			return;
 
 		kdbprinttrap(frame->trap, frame->code);

--=-=-=--