On Fri, Mar 26, 2010 at 12:51 PM, J.C. Roberts <list-...@designtools.org>
wrote:
...
> Think about it this way; you use the "boot> " prompt to boot up your
> experimental kernel named "/bsd.exp". It dumps core before you can get
> a dmesg, so you want to see what the heck was going on. You reboot with
> your normal kernel "/bsd"  and use dmesg on the core file, and tell it
> where to find the corresponding names (i.e. in your experimental kernel)
>
>        # dmesg -M bsd.exp.core -N /bsd.exp
>
> Obviously, the default input for values, /dev/kmem, will only give
> values of the currently running kernel, hence to get those values you
> either need to running a particular kernel, or crash it to dump core.

Yes, exactly.


> As for dmesg picking the right kernel file for getting the names of the
> currently running kernel, there is either some magic in demsg which
> picks the right kernel from disk, or a properly running kernel does not
> need to read names from the kernel file since they're already in memory.

It's simpler than that: when run without the -N or -M options, dmesg
gets the info via sysctl() instead of trying to read from /dev/kmem.
This makes it ABI-proof against various kernel or libkvm changes that
break code that reads /dev/kmem.

That's true not just of dmesg but of all the other programs that need
kernel info: ps, netstat, fstat, ipcs, systat, etc.

$ sysctl -A kern 2>&1 >/dev/null | grep 'use ' | head
sysctl: use pstat to view kern.vnode information
sysctl: use ps to view kern.proc information
sysctl: use pstat to view kern.file information
sysctl: use pstat -t to view kern.tty.ttyinfo information
sysctl: use dmesg to view kern.msgbuf
sysctl: use netstat to view kern.mbstat
sysctl: use ps to view kern.proc2 information
sysctl: use fstat to view kern.file2 information
sysctl: use vmstat or systat to view vm.vmmeter information
sysctl: use vmstat or systat to view vm.uvmexp information
$

Make sense?

Philip Guenther

Reply via email to