From f33dc69dfb388185754e6eeef7f1b30369e4ee44 Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Sat, 26 Jan 2008 22:32:23 +0000 Subject: [PATCH] Allow DDB_CAPTURE_DEFAULTBUFSIZE and DDB_CAPTURE_MAXBUFSIZE to be overridden at compile-time using kernel options of the same names. Rather than doing a compile-time CTASSERT of buffer sizes being even multiples of block sizes, just adjust them at boottime, as the failure mode is more user-friendly. MFC after: 2 months PR: 119993 Suggested by: Scot Hetzel --- sys/conf/options | 2 ++ sys/ddb/db_capture.c | 31 ++++++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/sys/conf/options b/sys/conf/options index eb13db69295..3fbcce5986c 100644 --- a/sys/conf/options +++ b/sys/conf/options @@ -48,6 +48,8 @@ TWA_FLASH_FIRMWARE opt_twa.h # Debugging options. DDB +DDB_CAPTURE_DEFAULTBUFSIZE opt_ddb.h +DDB_CAPTURE_MAXBUFSIZE opt_ddb.h DDB_NUMSYM opt_ddb.h GDB KDB opt_global.h diff --git a/sys/ddb/db_capture.c b/sys/ddb/db_capture.c index 5a4cb37a9bc..75da64edd11 100644 --- a/sys/ddb/db_capture.c +++ b/sys/ddb/db_capture.c @@ -32,6 +32,8 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_ddb.h" + #include #include #include @@ -52,11 +54,19 @@ __FBSDID("$FreeBSD$"); * kernel dumper routines without restarting the kernel, which is undesirable * in the midst of debugging. Instead, we maintain a large static global * buffer that we fill from DDB's output routines. + * + * We enforce an invariant at runtime that buffer sizes are even multiples of + * the textdump block size, which is a design choice that we might want to + * reconsider. */ static MALLOC_DEFINE(M_DDB_CAPTURE, "ddb_capture", "DDB capture buffer"); +#ifndef DDB_CAPTURE_DEFAULTBUFSIZE #define DDB_CAPTURE_DEFAULTBUFSIZE 48*1024 +#endif +#ifndef DDB_CAPTURE_MAXBUFSIZE #define DDB_CAPTURE_MAXBUFSIZE 512*1024 +#endif #define DDB_CAPTURE_FILENAME "ddb.txt" /* Captured DDB output. */ static char *db_capture_buf; @@ -81,24 +91,19 @@ SYSCTL_UINT(_debug_ddb_capture, OID_AUTO, maxbufsize, CTLFLAG_RD, "Maximum value for debug.ddb.capture.bufsize"); /* - * Various compile-time assertions: defaults must be even multiples of - * textdump block size. We also perform run-time checking of - * user-configurable values. - */ -CTASSERT(DDB_CAPTURE_DEFAULTBUFSIZE % TEXTDUMP_BLOCKSIZE == 0); -CTASSERT(DDB_CAPTURE_MAXBUFSIZE % TEXTDUMP_BLOCKSIZE == 0); - -/* - * Boot-time allocation of the DDB capture buffer, if any. + * Boot-time allocation of the DDB capture buffer, if any. Force all buffer + * sizes, including the maximum size, to be rounded to block sizes. */ static void db_capture_sysinit(__unused void *dummy) { TUNABLE_INT_FETCH("debug.ddb.capture.bufsize", &db_capture_bufsize); + db_capture_maxbufsize = roundup(db_capture_maxbufsize, + TEXTDUMP_BLOCKSIZE); db_capture_bufsize = roundup(db_capture_bufsize, TEXTDUMP_BLOCKSIZE); - if (db_capture_bufsize > DDB_CAPTURE_MAXBUFSIZE) - db_capture_bufsize = DDB_CAPTURE_MAXBUFSIZE; + if (db_capture_bufsize > db_capture_maxbufsize) + db_capture_bufsize = db_capture_maxbufsize; if (db_capture_bufsize != 0) db_capture_buf = malloc(db_capture_bufsize, M_DDB_CAPTURE, M_WAITOK); @@ -121,7 +126,7 @@ sysctl_debug_ddb_capture_bufsize(SYSCTL_HANDLER_ARGS) if (error || req->newptr == NULL) return (error); size = roundup(size, TEXTDUMP_BLOCKSIZE); - if (size > DDB_CAPTURE_MAXBUFSIZE) + if (size > db_capture_maxbufsize) return (EINVAL); sx_xlock(&db_capture_sx); if (size != 0) { @@ -150,7 +155,7 @@ sysctl_debug_ddb_capture_bufsize(SYSCTL_HANDLER_ARGS) KASSERT(db_capture_bufoff <= db_capture_bufsize, ("sysctl_debug_ddb_capture_bufsize: bufoff > bufsize")); - KASSERT(db_capture_bufsize <= DDB_CAPTURE_MAXBUFSIZE, + KASSERT(db_capture_bufsize <= db_capture_maxbufsize, ("sysctl_debug_ddb_capture_maxbufsize: bufsize > maxbufsize")); return (0);