Subject: Using gdb with NetBSD
To: 'tech-kern@netbsd.org' <tech-kern@netbsd.org>
From: Ferrari, Stephen <smf@pirus.com>
List: tech-kern
Date: 08/28/2000 18:38:12
(From looking at the archives I believe this and not tech-tool is the proper
place for this question; let me know if I should ask elsewhere.)

I've built a NetBSD kernel (1.4.2) with some very small changes which seem
to be harmless, yet ineffectual.  (I added a pseudo-device which simply
kicks off a kthread which sleeps for a few seconds, calls sys_socket,
sys_connect, and sys_recvfrom, doesn't like the responses, and
kthread_exits.  The system seems perfectly usable during and after this
process.)  I suspect the bottom line will be something like "you can't do
that", but on the theory it's better to learn to fish than to be given one,
I figured I'd learn to use KGDB and step through the code.

Using the info at http://www.netbsd.org/Documentation/kernel/kgdb.html
<http://www.netbsd.org/Documentation/kernel/kgdb.html>  I built the kernel
with KGDB and booted it -d.  I brought down GDB 5.0, configured it for 
"--target=i386--netbsd -host=i686-pc-cygwin", built it under CygWin/WinNT,
ran it, and was impressed to see:

		This GDB was configured as "--host=i686-pc-cygwin
--target=i386--netbsd".
		kgdb_connect (verbose=1) at
../../../../arch/i386/i386/kgdb_machdep.c:244
		244             if (verbose) 

Some stuff seems to work pretty nicely:  I've had luck setting breakpoints
and having them hit, and usually "info stack" looks quite reasonable.

However, "info threads" gives "warning: RMT ERROR : failed to get remote
thread list" whenever I try it, and if I do "next" I invariably get "Program
received signal SIGSEGV, Segmentation fault. 0xc0100cdd in calltrap ()".

Is what I'm trying to do something that seems like it should clearly work,
am I doing something obviously wrong, or is this mixed combo of host and
target a bit shaky?  I don't know how stable the interfaces are between gcc,
NetBSD, and gdb.  Do I need to carefully choose a compatible combination, or
should I be fine with NetBSD 1.4.2 built with gcc egcs-1.1.1 and gdb built
with gcc egcs-2.91.57?

Thanks much for any help,

	Stephen