From nobody@FreeBSD.org  Fri Feb  2 01:25:58 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 8FA7116A400
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  2 Feb 2007 01:25:58 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id 8158813C478
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  2 Feb 2007 01:25:58 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l121Pwu3079199
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 2 Feb 2007 01:25:58 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l121Pw1I079198;
	Fri, 2 Feb 2007 01:25:58 GMT
	(envelope-from nobody)
Message-Id: <200702020125.l121Pw1I079198@www.freebsd.org>
Date: Fri, 2 Feb 2007 01:25:58 GMT
From: Ravi Murty<ravi.murty@intel.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: kgdb doesn't work very well very long
X-Send-Pr-Version: www-3.0

>Number:         108673
>Category:       amd64
>Synopsis:       kgdb doesn't work very well very long
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-amd64
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Feb 02 01:30:14 GMT 2007
>Closed-Date:    Thu Feb 08 17:46:15 GMT 2007
>Last-Modified:  Thu Feb 08 17:46:15 GMT 2007
>Originator:     Ravi Murty
>Release:        6.1-release
>Organization:
Intel
>Environment:
FreeBSD 6.1-RELEASE FreeBSD 6.1-RELEASE #17: Thu Feb  16:57:46 PST 2007
>Description:
Here's what I think might be happening.

1. At the loader prompt I enter "boot -d" to break into the debugger because I want to start running the debugger from mi_startup.
2. Kgdb connects on the host and I can step, but it crashes or doesn't work very well. We started to look at things like gdb_txbuf and noticed that a strage 0x78787878 (0x78 is lower case 'x') appears where gdb_txbuf is supposed to be. 
3. We looked at the source code a bit and realized that gdb_txbuf is sized to be 500 bytes (defined by GDB_BUFSZ in amd64/include/gdb_machdep.h).

So here's the problem:
1. When kgdb running on the host connects it runs a query to the target to request all the registers. In amd64's case, that's 56 total registers with 49 of size 8 bytes and 7 of size 4. Since we convert from hex nibbles to char's, we expect it to store 16 char's per 8 byte register and 8 char's for 4 byte registers. Simple math tells us that is (16 * 49 + 8 * 7 = 840). So we need atleast 840B in the buffer to return the result of the query.
2. Indeed when we look at what's at gbd_txbuf on the target (via kgdb), we notice that 0x78787878 appears until location 839. It is 0x78787878 because that happens to be "xxxx" for registers that are undefined (see gdb_packet.c)

Therefore, shouldn't GDB_BUFSZ be > 840B ?

Thanks
Ravi


>How-To-Repeat:
Run kgdb and connect to a machine running 6.1-Release for amd64. Drop to the loader prompt on boot and type "boot -d" and connect to the debugger (gdb backend).

Try and step through the code after this point.
>Fix:
See "Full description".
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: jhb 
State-Changed-When: Mon Feb 5 21:49:19 UTC 2007 
State-Changed-Why:  
Fix applied to HEAD. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: amd64/108673: commit references a PR
Date: Mon,  5 Feb 2007 21:48:43 +0000 (UTC)

 jhb         2007-02-05 21:48:32 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/amd64/include    gdb_machdep.h 
   Log:
   Change GDB_BUFSZ to be large enough to hold a register dump where each
   register takes 16 characters (64-bit register in hex).  In practice this
   is a slight bit of overkill as 7 of the 56 registers are only 32-bit, but
   having the buffer too small results in remote kgdb trashing kernel memory
   when it connects.
   
   PR:             amd64/108673
   Submitted by:   Ravi Murty, Nikhil Rao @ Intel
   MFC after:      3 days
   
   Revision  Changes    Path
   1.6       +1 -1      src/sys/amd64/include/gdb_machdep.h
 _______________________________________________
 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: John Baldwin <jhb@freebsd.org>
To: freebsd-amd64@freebsd.org
Cc: Ravi Murty <ravi.murty@intel.com>, freebsd-gnats-submit@freebsd.org,
        "Rao, Nikhil" <nikhil.rao@intel.com>
Subject: Re: amd64/108673: kgdb doesn't work very well very long
Date: Mon, 5 Feb 2007 16:49:37 -0500

 I've just fixed this and it should be in RELENG_6 in a couple of days.  
 Thanks.
 
 -- 
 John Baldwin
State-Changed-From-To: patched->closed 
State-Changed-By: jhb 
State-Changed-When: Thu Feb 8 17:46:00 UTC 2007 
State-Changed-Why:  
Fix merged to 6.x. 

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