From frank@exit.com  Tue Oct 25 01:30:18 2005
Return-Path: <frank@exit.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 7105016A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 25 Oct 2005 01:30:18 +0000 (GMT)
	(envelope-from frank@exit.com)
Received: from tinker.exit.com (tinker.exit.com [206.223.0.1])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 09B6C43D48
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 25 Oct 2005 01:30:17 +0000 (GMT)
	(envelope-from frank@exit.com)
Received: from realtime.exit.com (realtime [206.223.0.5])
	by tinker.exit.com (8.13.4/8.13.4) with ESMTP id j9P1UIiU053876
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 24 Oct 2005 18:30:18 -0700 (PDT)
	(envelope-from frank@exit.com)
Message-Id: <1130203817.0@realtime.exit.com>
Date: Mon, 24 Oct 2005 18:30:17 -0700
From: "Frank Mayhar" <frank@exit.com>
To: "FreeBSD gnats submit" <FreeBSD-gnats-submit@freebsd.org>
Subject: [patch] Fix kgdb msgbuf bogosity and infinite loop.
X-Send-Pr-Version: gtk-send-pr 0.4.6 
X-GNATS-Notify:

>Number:         87964
>Category:       bin
>Synopsis:       [patch] Fix kgdb(1) msgbuf bogosity and infinite loop.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    marcel
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 25 01:40:16 GMT 2005
>Closed-Date:    Sat Nov 05 19:15:46 GMT 2005
>Last-Modified:  Sat Nov 05 19:15:46 GMT 2005
>Originator:     Frank Mayhar
>Release:        FreeBSD 6.0-RC1 i386
>Organization:
Exit Consulting 
>Environment:


System: FreeBSD 6.0-RC1 #1: Sun Oct 23 09:38:36 PDT 2005
    frank@jill.exit.com:/usr/obj/usr/src/sys/REALTIME



>Description:


Kgdb has code in it to print the "unread portion of the kernel message buffer" when it starts up with a kernel corefile.  Unfortunately this code is broken, at least in 6.0 and later.  One corefile made it print garbage and another put it into an infinite loop.

The attached patch fixes this behavior in both cases.


>How-To-Repeat:





>Fix:


--- kgdb.patch begins here ---
Index: gnu/usr.bin/gdb/kgdb/main.c
===================================================================
RCS file: /cvs/repos/src/gnu/usr.bin/gdb/kgdb/main.c,v
retrieving revision 1.7.2.2
diff -u -r1.7.2.2 main.c
--- gnu/usr.bin/gdb/kgdb/main.c	15 Sep 2005 05:32:10 -0000	1.7.2.2
+++ gnu/usr.bin/gdb/kgdb/main.c	25 Oct 2005 01:13:05 -0000
@@ -197,6 +197,8 @@
 	return (n);
 }
 
+#define MSGBUF_SEQ_TO_POS(size, seq)     ((seq) % (size))
+
 static void
 kgdb_init_target(void)
 {
@@ -241,6 +243,8 @@
 	size = (int)kgdb_parse("msgbufp->msg_size");
 	rseq = (int)kgdb_parse("msgbufp->msg_rseq");
 	wseq = (int)kgdb_parse("msgbufp->msg_wseq");
+	rseq = MSGBUF_SEQ_TO_POS(size, rseq);
+	wseq = MSGBUF_SEQ_TO_POS(size, wseq);
 	if (bufp == 0 || size == 0 || rseq == wseq)
 		return;
 
--- kgdb.patch ends here ---



>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->marcel 
Responsible-Changed-By: kris 
Responsible-Changed-When: Tue Oct 25 18:39:39 GMT 2005 
Responsible-Changed-Why:  
Assign to kgdb maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=87964 
State-Changed-From-To: open->patched 
State-Changed-By: marcel 
State-Changed-When: Wed Oct 26 02:23:05 GMT 2005 
State-Changed-Why:  
Patch applied to -current. Will be MFC'd after 6.0 release. 
Thanks! 


http://www.freebsd.org/cgi/query-pr.cgi?pr=87964 
State-Changed-From-To: patched->closed 
State-Changed-By: marcel 
State-Changed-When: Sat Nov 5 19:15:03 GMT 2005 
State-Changed-Why:  
Merged onto RELENG_6. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=87964 
>Unformatted:
