Debugging Tools and Strategies

Debugging ordinary programs is hard enough; kernel debugging is harder still. The following few paragraphs describes some common debugging tools and strategies that you may find useful.


nmDump symbol address, linkage types, and names. Useful for setting break points in Bochs or Qemu.
readelfDump ELF file metadata
objcopyTranslate object file formats
objdumpDump object file metadata and disassembly
addr2lineMap pc to source line
gdbptypeDump type information
p sizeofType size
p &((Foo*)0)->xMember offset
disass 0xaddrDisassemble code
genassymExport constant C expression to assembly to avoid having to maintain them in two places at once.
printfPrintf and primitive CGA console driver for the x86; includes "long long" arithmetic support.


Other tricks of the trade:

Print machine code in a fault handler or debugging statement and copy that code in to an array in a dummy C program to disassemble it with gdb. The C code looks something like this:

	unsigned char code[] = { 0x90, 0x90, 0x90 };
Then in gdb disassemble code.

Add trap handlers for undefined opcodes and then drop ud2 instructions at various points. The trap handler can print out the faulting address, providing a cheap debugging print in places that printf cannot safely be called.