Debuggers and Related ToolsEdit

Generally don't use any debuggers and just use traditional printk statements. ie write better code!

Using gdbEdit

  • need to understand assmebly code for target
  • proficient in gdb commands
  • match source to optimized assembly
  • can't modify kernel data unlike application gdb
  • can't set breakpoints/watchpoints/singlestep
  • compile with CONFIG_DEBUG_INFO set
  • no module information initially, need to "teach" gdb
gdb /usr/src/linux/vmlinux /proc/kcore

See "install vmlinux and debug symbols on Ubuntu " for setup

kcore is generated when read like /proc/read systems

core-file /proc/kcore

flush gdb cache to read up-to-date information

Relevant Sections for debugging:


   This section contains the executable code for the module. The debugger must 
   know where this section is to be able to give tracebacks or set breakpoints. 
   (Neither of these operations is relevant when running the debugger on 
   /proc/kcore,but they can useful when working with kgdb, described below).


   These two sections hold the module’s variables. Any variable that is not 
   initialized at compile time ends up in .bss, while those that are initialized 
   go into data.

The relevant symbols can be seen at /sys/modules/ModuleName/sections. to add symbols to gdb:

(gdb) add-symbol-file .../scull.ko 0xd0832000 \
-s .bss 0xd0837100 \
-s .data 0xd0836be0

Using kdbEdit

Using kgdbEdit