I wanna see all the kprintfs!

When I was reading some OpenDarwin docs on how to debug the kernel, I discovered that there are these wonderful kprintf statements in the kernel that you can turn on with a simple debug option. Unfortunately, those get printed to a serial port, which I don’t have on my PowerBook. I found a really simple way around this, for doing some simple debugging.

I modified the bsd/sys/systm.h file, where the prototype for kprintf lives. I simply commented out the definition for kprintf and put in a #define that defined kprintf to be the same as printf.

You can enable the printfs by putting debug=0x02 on your boot arguments. Here’s how I do that:

sudo nvram boot-args='debug=0x02'

All the kprintf and printf output will go to /var/log/system.log.

Here’s my patch for systm.h.

Comments aren't enabled for this post.