From nobody@FreeBSD.org  Sat Jan 26 03:22:22 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B3CFB16A418
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 26 Jan 2008 03:22:22 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 9C92313C45A
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 26 Jan 2008 03:22:22 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m0Q3KhoT096307
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 26 Jan 2008 03:20:44 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m0Q3KhqA096306;
	Sat, 26 Jan 2008 03:20:43 GMT
	(envelope-from nobody)
Message-Id: <200801260320.m0Q3KhqA096306@www.freebsd.org>
Date: Sat, 26 Jan 2008 03:20:43 GMT
From: Scot Hetzel <swhetzel@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: ddb capture buffer too small for textdumps
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         119993
>Category:       kern
>Synopsis:       [patch] ddb capture buffer too small for textdumps
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    rwatson
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jan 26 03:30:01 UTC 2008
>Closed-Date:    Sun Jan 27 10:55:29 UTC 2008
>Last-Modified:  Tue Apr  1 11:40:02 UTC 2008
>Originator:     Scot Hetzel
>Release:        8.0-CURRENT
>Organization:
>Environment:
FreeBSD hp010.hetzel.org 8.0-CURRENT FreeBSD 8.0-CURRENT #0: Sat Jan 19 00:03:54 CST 2008     root@hp010.hetzel.org:/usr/src/sys/amd64/compile/DV8135NR  amd64

>Description:
While trying to debug a kernel panic, I decided to try the new textdump feature and scripted ddb.  I increased debug.ddb.capture.bufsize to it's maximum size (512K).  When the kerne paniced, the kdb.enter.panic script ran but had its output truncated to 512K.

debug.ddb.capture.bufsize: 49152
debug.ddb.capture.maxbufsize: 524288

The problem is that sys/ddb/db_capture.c has fixed DB_CAPTURE_MAXBUFSIZE to 512K.  I was able to get the full output by increasing DB_CAPTURE_MAXBUFSIZE to 5M (3M would have been enough, as ddb.txt was only 2.7M).
>How-To-Repeat:
Add the following to the kernel config file:

options         DEBUG_VFS_LOCKS
options         KTR
options         KTR_COMPILE=(KTR_SPARE2)
options         KTR_MASK=(KTR_SPARE2)
options         KTR_ENTRIES=32768

and then build/install the kernel.  After the reboot, use ddb to add the following scripts:

/sbin/ddb script lockinfo="show locks; show alllocks; show lockedvnods"

/sbin/ddb script kdb.enter.panic="textdump set; capture on; show ktr ; run lockinfo ; show pcpu; bt; ps; alltrace; capture off; call doadump; reset"

sysctl debug.ddb.capture.bufsize=524288

Then do something that causes the kernel to panic.
>Fix:
Apply the attached patch which adds two kernel options to allow the capture buffer size to be changed in the kernel config file:

options         DB_CAPTURE_DEFAULTBUFSIZE=2*1024*1024
options         DB_CAPTURE_MAXBUFSIZE=5*1024*1024

Should DB_CAPTURE* be changed to DDB_CAPTURE*?  Will require a change in ddb/db_capture.c also.

Note: DB_CAPTURE_DEFAULTBUFSIZE can also be set by sysctl.


Patch attached with submission follows:

Index: conf/options
===================================================================
RCS file: /home/ncvs/src/sys/conf/options,v
retrieving revision 1.615
diff -u -r1.615 options
--- conf/options	7 Jan 2008 21:40:09 -0000	1.615
+++ conf/options	25 Jan 2008 23:52:31 -0000
@@ -49,6 +49,8 @@
 # Debugging options.
 DDB
 DDB_NUMSYM	opt_ddb.h
+DB_CAPTURE_DEFAULTBUFSIZE	opt_ddb.h
+DB_CAPTURE_MAXBUFSIZE	opt_ddb.h
 GDB
 KDB		opt_global.h
 KDB_TRACE	opt_kdb.h
Index: ddb/db_capture.c
===================================================================
RCS file: /home/ncvs/src/sys/ddb/db_capture.c,v
retrieving revision 1.2
diff -u -r1.2 db_capture.c
--- ddb/db_capture.c	26 Dec 2007 11:32:32 -0000	1.2
+++ ddb/db_capture.c	25 Jan 2008 23:50:46 -0000
@@ -46,6 +46,8 @@
 #include <ddb/ddb.h>
 #include <ddb/db_lex.h>
 
+#include <opt_ddb.h>
+
 /*
  * While it would be desirable to use a small block-sized buffer and dump
  * incrementally to disk in fixed-size blocks, it's not possible to enter
@@ -55,8 +57,12 @@
  */
 static MALLOC_DEFINE(M_DB_CAPTURE, "db_capture", "DDB capture buffer");
 
+#ifndef DB_CAPTURE_DEFAULTBUFSIZE
 #define	DB_CAPTURE_DEFAULTBUFSIZE	48*1024
+#endif
+#ifndef DB_CAPTURE_MAXBUFSIZE
 #define	DB_CAPTURE_MAXBUFSIZE	512*1024
+#endif
 #define	DB_CAPTURE_FILENAME	"ddb.txt"	/* Captured DDB output. */
 
 static char *db_capture_buf;


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->rwatson 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Jan 26 03:32:48 UTC 2008 
Responsible-Changed-Why:  
Over to author of this feature. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=119993 
State-Changed-From-To: open->analyzed 
State-Changed-By: rwatson 
State-Changed-When: Sat Jan 26 12:19:14 UTC 2008 
State-Changed-Why:  
This seems pretty reasonable, I will make this change or something very 
like it shortly.  I hope also in the long term that we will be able to 
move to incrementally writing textdumps (and other dump types) from 
within the debugger rather than doing it outside the debugger, which is 
what causes textdumps to need a large buffer currently.  Ideally we'd 
write out the output incrementally as it was generated (there's a 
thread on current@ with views along these lines also). 


http://www.freebsd.org/cgi/query-pr.cgi?pr=119993 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/119993: commit references a PR
Date: Sat, 26 Jan 2008 13:56:00 +0000 (UTC)

 rwatson     2008-01-26 13:55:52 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/ddb              db_capture.c 
   Log:
   Rename DB_ constants in db_capture.c to DDB_ so that when they are
   exposed as kernel compile options, they have more meaningful names.
   
   PR:             119993
   MFC after:      2 months
   Suggested by:   Scot Hetzel <swhetzel at gmail dot com>
   
   Revision  Changes    Path
   1.3       +16 -16    src/sys/ddb/db_capture.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/119993: commit references a PR
Date: Sat, 26 Jan 2008 22:32:29 +0000 (UTC)

 rwatson     2008-01-26 22:32:24 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/conf             options 
     sys/ddb              db_capture.c 
   Log:
   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>
   
   Revision  Changes    Path
   1.616     +2 -0      src/sys/conf/options
   1.4       +18 -13    src/sys/ddb/db_capture.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/119993: commit references a PR
Date: Sat, 26 Jan 2008 23:02:21 +0000 (UTC)

 rwatson     2008-01-26 23:02:14 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/ddb              db_capture.c 
   Log:
   Increase maximum DDB capture buffer size to 5MB.
   
   PR:             119993
   MFC after:      2 months
   Suggested by:   Scot Hetzel <swhetzel at gmail dot com>
   
   Revision  Changes    Path
   1.5       +1 -1      src/sys/ddb/db_capture.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: analyzed->closed 
State-Changed-By: rwatson 
State-Changed-When: Sun Jan 27 10:53:44 UTC 2008 
State-Changed-Why:  
Close PR as I've added this patch, with a few minor modifications to handle 
blocksize rounding.  However, I've not adjusted the default buffer size -- 
since it comes out of kernel memor I don't feel comfortable allocating more 
than 48k by default.  Hopefully we can get incremental dumping working 
(which requires modifying our dump approach to allow dumping from within 
the debugger) in the future, eliminating the need for anything more than a 
single block to buffer writes.  I'll MFC these changes with textdumps in a 
couple of months.  Thanks for the submission! 


http://www.freebsd.org/cgi/query-pr.cgi?pr=119993 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/119993: commit references a PR
Date: Mon, 31 Mar 2008 22:09:05 +0000 (UTC)

 rwatson     2008-03-31 22:09:00 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     sys/ddb              db_capture.c 
   Log:
   Merge db_capture.c:1.3 from HEAD to RELENG_7:
   
     Rename DB_ constants in db_capture.c to DDB_ so that when they are
     exposed as kernel compile options, they have more meaningful names.
   
     PR:             119993
     MFC after:      2 months
     Suggested by:   Scot Hetzel <swhetzel at gmail dot com>
   
   Revision  Changes    Path
   1.5.2.3   +16 -16    src/sys/ddb/db_capture.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/119993: commit references a PR
Date: Tue,  1 Apr 2008 11:23:41 +0000 (UTC)

 rwatson     2008-04-01 11:23:32 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     sys/conf             options 
     sys/ddb              db_capture.c 
   Log:
   Merge options:1.616, db_capture.c:1.4 from HEAD to RELNEG_7:
   
     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>
   
   Revision   Changes    Path
   1.608.2.2  +2 -0      src/sys/conf/options
   1.5.2.4    +18 -13    src/sys/ddb/db_capture.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/119993: commit references a PR
Date: Tue,  1 Apr 2008 11:31:24 +0000 (UTC)

 rwatson     2008-04-01 11:31:18 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     sys/ddb              db_capture.c 
   Log:
   Merge db_capture.c:1.5 from HEAD to RELENG_7:
   
     Increase maximum DDB capture buffer size to 5MB.
   
     PR:             119993
     Suggested by:   Scot Hetzel <swhetzel at gmail dot com>
   
   Revision  Changes    Path
   1.5.2.5   +1 -1      src/sys/ddb/db_capture.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
