Subject: debugging kernel core dumps ?

From: Darren Reed <[email-masked]>

Having compile a NetBD-current/sparc kernel with the DEBUG and DIAGNOSTIC
options in, how do I then debug the core dumps ?

gdb won't recognise vmcore, the FAQ (3.2.4) mentions "device-pseudo ddb"
(adding this just makes config.new barf) and CTL-ALT-ESC does nothing.

The man page for ddb(4) says nothing useful...I'm lost, where should I be
looking ?

If I add "options KGDB", I presume I need to add the next line defining
KGDBDEV and KGDBRATE, correct ?  If so, does this limit debugging to using
an active kernel and being at the console ? (yuck!)

Also, who is currently working on the union file system ?  I'm after a way
to debug these:
Sep  4 08:47:25 netbsd /netbsd: ufs_unlock: unlocked inode: type VDIR, usecoun
t 2, writecount 0, refcount 0,
Sep  4 08:47:26 netbsd /netbsd:       tag VT_UFS, ino 63232, on dev 7, 6
Sep  4 08:47:26 netbsd /netbsd: panic: ufs_unlock NOT LOCKED

Also, can anyone tell me what this means ?

Sep  4 06:43:54 netbsd /netbsd: note: lost 32 pages in translation

Thanks,
Darren

---

From: Paul Kranenburg <[email-masked]>

> gdb won't recognise vmcore,
Use `gdb -k'

> the FAQ (3.2.4) mentions "device-pseudo ddb"
This is now `options	DDB'.
Also, sparc's DDB routines use L1-A to drop you into the debugger.

-pk

---

From: Greg Earle <[email-masked]>

Dave Burgess writes:

>>> Having compiled a NetBSD(-current)/sparc kernel with the DEBUG and
>>> DIAGNOSTIC options in, how do I then debug the core dumps ?
>> 
>> Good question.  I would have used adb -k, but adb doesn't exist under
>> NetBSD/sparc (which is a pain for more reasons than just kernel
>> coredumps!).
>> 
>> Did you try gdb -k?  Just a guess by analogy to adb -k....
>> 
>
>If this works, I will add it to the FAQ.  If not, then what would the
>correct incantation to make it go be?

Yes, "gdb -k netbsd.N vmcore.N" works - sort of.  It puts you into a "kgdb"
mode.

The reason I say "sort of" is because I'm puzzled by this behavior - I also
have a kernel with options like

...
# Standard system options
options         SWAPPAGER, VNODEPAGER, DEVPAGER # paging
options         DEBUG, DIAGNOSTIC       # extra kernel debugging
options         KTRACE                  # system call tracing support
options         KGDB                    # support for kernel gdb
options         KGDBDEV=0xc01, KGDBRATE=38400   # device & baud rate
...

(I don't have "device-pseudo ddb" or "pseudo-device ddb" or "options DDB",
 however.)

Twice in the last month I've had my machine (SPARCstation IPC, NetBSD/SPARC)
go down with a "panic: rtfree".  Running "gdb -k netbsd.1 vmcore.1" yields

netbsd4me [/var/crash] # gdb -k netbsd.1 vmcore.1
(no debugging symbols found)...panic: rtfree 2
#0  0xf8006c9c in snapshot ()
(kgdb) where
#0  0xf8006c9c in snapshot ()
#1  0xf8006ca4 in snapshot ()
#2  0xf80a21a0 in boot ()
#3  0xf8017818 in panic ()
#4  0xf804055c in rtfree ()
#5  0xf8040a6c in rtrequest ()
#6  0xf80414dc in route_output ()
#7  0xf80401f0 in raw_usrreq ()
#8  0xf80411c0 in route_usrreq ()
#9  0xf80233a8 in sosend ()
...
(kgdb)

Why does it say "No debugging symbols found" (and apparently there aren't) if
I built the kernel with "options DEBUG, DIAGNOSTIC"?  Presumably because my
kernel compile Makefile (i.e., /sys/arch/sparc/compile/NETBSD4ME/Makefile) has

	CFLAGS= ${COPTS} -O2

in it.  I guess I would have assumed that config.new would see "options DEBUG"
and make it "CFLAGS= ${COPTS} -g" instead?  The man page for config.new
admonishes

     The old undocumented-gflag is no longer supported.  Instead, use
     ``makeoptions DEBUG="-g"'' and (typically) ``options KGDB''.

Perhaps a reminder that `options DEBUG, DIAGNOSTIC' *and* `makeoptions
DEBUG="-g"' are probably both needed to get crash dumps working is in order?

	- Greg