Bug 108673 - kgdb doesn't work very well very long
Summary: kgdb doesn't work very well very long
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: amd64 (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-amd64 (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-02 01:30 UTC by Ravi Murty
Modified: 2007-02-08 17:46 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ravi Murty 2007-02-02 01:30:14 UTC
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

Fix: 

See "Full description".
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.
Comment 1 dfilter service freebsd_committer freebsd_triage 2007-02-05 21:48:43 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"
Comment 2 John Baldwin freebsd_committer freebsd_triage 2007-02-05 21:49:19 UTC
State Changed
From-To: open->patched

Fix applied to HEAD.
Comment 3 John Baldwin freebsd_committer freebsd_triage 2007-02-05 21:49:37 UTC
I've just fixed this and it should be in RELENG_6 in a couple of days.  
Thanks.

-- 
John Baldwin
Comment 4 John Baldwin freebsd_committer freebsd_triage 2007-02-08 17:46:00 UTC
State Changed
From-To: patched->closed

Fix merged to 6.x.