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 <swhetzel at gmail dot com>
This commit is contained in:
parent
81169af72a
commit
db8d5a7a3d
@ -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
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "opt_ddb.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/kernel.h>
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user