From 22f1132820b9e7cfd9a651cc4a88e319ec95ea86 Mon Sep 17 00:00:00 2001 From: reinoud Date: Wed, 29 Sep 2004 23:54:11 +0000 Subject: [PATCH] Implement ddb setting that allows all ddb output to be teed into the kernel message buffer/log. Its off by default and can be switched on in the kernel configuration on build time, be set as a variable in ddb and be set using sysctl. This adds the sysctl value ddb.tee_msgbuf = 0 by default. The functionality is especially added and aimed for developers who are not blessed with a serial console and wish to keep all their ddb output in the log. Specifying /l as a modifier to some selected commands will also put the output in the log but not all commands provide one nor has the same meaning for all commands. This feature could in the future also be implemented as an ddb command but that could lead to more bloat allthough maybe easier for non developpers to use when mailing their backtraces from kernel crashes. --- share/man/man4/ddb.4 | 25 ++++++++++++++++++++++++- sys/ddb/TODO | 4 ++-- sys/ddb/db_variables.c | 20 ++++++++++++++++++-- sys/ddb/ddbvar.h | 3 ++- sys/kern/subr_prf.c | 12 ++++++++++-- 5 files changed, 56 insertions(+), 8 deletions(-) diff --git a/share/man/man4/ddb.4 b/share/man/man4/ddb.4 index 4a033619cde4..ca9f6ab323e9 100644 --- a/share/man/man4/ddb.4 +++ b/share/man/man4/ddb.4 @@ -1,4 +1,4 @@ -.\" $NetBSD: ddb.4,v 1.78 2004/03/02 20:57:45 jdc Exp $ +.\" $NetBSD: ddb.4,v 1.79 2004/09/29 23:54:11 reinoud Exp $ .\" .\" Copyright (c) 1997 - 2003 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -80,6 +80,12 @@ To disable entering .Ic ddb upon kernel panic: .Cd options DDB_ONPANIC=0 +.Pp +To enable teeing all +.\" XXX: hack; .Nm automatically introduces newline in SYNOPSIS +.Ic ddb +output to the kernel msgbuf: +.Cd options DDB_TEE_MSGBUF=1 .Sh DESCRIPTION .Nm is the in-kernel debugger. @@ -1116,6 +1122,23 @@ will be initialized to off. Input and output radix. .It Va tabstops Tab stop width. +.It Va tee_msgbuf +If explictly set to non zero (zero is the default) all +.Nm +output will not only be displayed on screen but +also be fed to the msgbuf. +The default of the variable can be set using the kernel configuration option +.D1 Cd options DDB_TEE_MSGBUF=1 +wich will initialise +.Va tee_msgbuf +to be 1. +This option is especially handy for poor souls +who don't have a serial console but want to recall +.Nm +output from a crash investigation. +This option is more generic than the /l command modifier possible for +selected commands as discussed above to log the output. Mixing both /l +and this setting can give double loggings. .\" .It Va work Ns Sy xx .\" Temporary work variable. .\" .Sq Sy xx diff --git a/sys/ddb/TODO b/sys/ddb/TODO index 1867b3adf4f2..75150efcc7ee 100644 --- a/sys/ddb/TODO +++ b/sys/ddb/TODO @@ -1,4 +1,4 @@ -$NetBSD: TODO,v 1.14 2004/09/28 23:02:58 reinoud Exp $ +$NetBSD: TODO,v 1.15 2004/09/29 23:54:11 reinoud Exp $ In rough order. @@ -116,6 +116,6 @@ done Numbers starting with [a-f] should work, but symbols Unfortunately, in ILP32 mode, ddb will only display the low 32-bits of any expression, including registers... -WIP Add support for duplicating all output to the message buffer for +done Add support for duplicating all ddb output to the message buffer for those unlucky souls that don't have a serial console. diff --git a/sys/ddb/db_variables.c b/sys/ddb/db_variables.c index 0d40bbfd7920..6fc43a79de1e 100644 --- a/sys/ddb/db_variables.c +++ b/sys/ddb/db_variables.c @@ -1,4 +1,4 @@ -/* $NetBSD: db_variables.c,v 1.31 2004/05/25 04:31:48 atatat Exp $ */ +/* $NetBSD: db_variables.c,v 1.32 2004/09/29 23:54:11 reinoud Exp $ */ /* * Mach Operating System @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: db_variables.c,v 1.31 2004/05/25 04:31:48 atatat Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_variables.c,v 1.32 2004/09/29 23:54:11 reinoud Exp $"); #include "opt_ddbparam.h" @@ -65,6 +65,15 @@ int db_onpanic = DDB_ONPANIC; #endif int db_fromconsole = DDB_FROMCONSOLE; +/* + * Output DDB output to the message buffer? + */ +#ifndef DDB_TEE_MSGBUF +#define DDB_TEE_MSGBUF 0 +#endif +int db_tee_msgbuf = DDB_TEE_MSGBUF; + + static int db_rw_internal_variable(const struct db_variable *, db_expr_t *, int); static int db_find_variable(const struct db_variable **); @@ -78,6 +87,7 @@ const struct db_variable db_vars[] = { { "lines", (void *)&db_max_line, db_rw_internal_variable }, { "onpanic", (void *)&db_onpanic, db_rw_internal_variable }, { "fromconsole", (void *)&db_fromconsole, db_rw_internal_variable }, + { "tee_msgbuf", (void *)&db_tee_msgbuf, db_rw_internal_variable }, }; const struct db_variable * const db_evars = db_vars + sizeof(db_vars)/sizeof(db_vars[0]); @@ -150,6 +160,12 @@ SYSCTL_SETUP(sysctl_ddb_setup, "sysctl ddb subtree setup") "console"), NULL, 0, &db_fromconsole, 0, CTL_DDB, DDBCTL_FROMCONSOLE, CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "tee_msgbuf", + SYSCTL_DESCR("Whether to tee ddb output to the msgbuf"), + NULL, 0, &db_tee_msgbuf, 0, + CTL_DDB, CTL_CREATE, CTL_EOL); } int diff --git a/sys/ddb/ddbvar.h b/sys/ddb/ddbvar.h index c535be91f513..40dd466b2791 100644 --- a/sys/ddb/ddbvar.h +++ b/sys/ddb/ddbvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: ddbvar.h,v 1.6 2003/12/04 19:38:23 atatat Exp $ */ +/* $NetBSD: ddbvar.h,v 1.7 2004/09/29 23:54:11 reinoud Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -45,6 +45,7 @@ extern int db_onpanic; extern int db_fromconsole; +extern int db_tee_msgbuf; int read_symtab_from_file(struct proc *,struct vnode *,const char *); #endif /* !_DDBVAR_H_ */ diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index ae68af01d1c0..e1b81a151919 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_prf.c,v 1.94 2004/03/23 13:22:04 junyoung Exp $ */ +/* $NetBSD: subr_prf.c,v 1.95 2004/09/29 23:54:11 reinoud Exp $ */ /*- * Copyright (c) 1986, 1988, 1991, 1993 @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.94 2004/03/23 13:22:04 junyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.95 2004/09/29 23:54:11 reinoud Exp $"); #include "opt_ddb.h" #include "opt_ipkdb.h" @@ -545,6 +545,12 @@ db_printf(const char *fmt, ...) va_start(ap, fmt); kprintf(fmt, TODDB, NULL, NULL, ap); va_end(ap); + + if (db_tee_msgbuf) { + va_start(ap, fmt); + kprintf(fmt, TOLOG, NULL, NULL, ap); + va_end(ap); + }; } void @@ -555,6 +561,8 @@ db_vprintf(fmt, ap) /* No mutex needed; DDB pauses all processors. */ kprintf(fmt, TODDB, NULL, NULL, ap); + if (db_tee_msgbuf) + kprintf(fmt, TOLOG, NULL, NULL, ap); } #endif /* DDB */