Friday, January 22, 2010

KGDB Tutorial

KGDB Tutorial


Upstrteam documentation: Using kgdb, kdb and the kernel debugger internals by Jason Wessel

Building a Kernel that supports KGDB

menuconfig KGDB
        bool "KGDB: kernel debugging with remote gdb"
        depends on HAVE_ARCH_KGDB
        depends on DEBUG_KERNEL && EXPERIMENTAL
        help
          If you say Y here, it will be possible to remotely debug the
          kernel using gdb.  
config KGDB_SERIAL_CONSOLE
        tristate "KGDB: use kgdb over the serial console"
        select CONSOLE_POLL
        select MAGIC_SYSRQ
        default y
        help
          Share a serial console with kgdb. Sysrq-g must be used
          to break in initially.

KGDB Boot and Module Options

  1. Boot with kgdboc=<tty-device>,[baud] (e.g. kgdboc=ttyAMA1 for an integratorcp board emulated by qemu-system-arm, vport0p2 for virtio serial, ttyS0 for a 16550 UART on an x86 etc)
  2. (alternatively) From sysfs
    echo TTY_DEVICE > /sys/module/kgdboc/parameters/kgdboc

Connecting GDB to the Kernel through a QEMU Emulated Serial Port

  • [arm-cross: linux-2.6]$ qemu-system-arm -nographic -s -M integratorcp -kernel ./zImage-2.6.32-integratorcp-v5 -serial tcp:localhost:2345,server -append "console=ttyAMA0 root=/dev/nfs nfsroot=172.20.0.1:/nfsroot/box,nfsvers=3 rw ip=172.20.0.2::172.20.0.1:255.255.255.0 kgdboc=ttyAMA0 kgdbwait"
  • [arm-cross: linux-2.6]$ telnet localhost:2345
  • Wait till the telnet session shows "kgdb: Waiting for connection from remote gdb..." then terminate telnet with CTRL-] then CTRL-D
  • [arm-cross: linux-2.6]$ gdb ./vmlinux
  • (gdb) target remote localhost:2345
  • Trouble Shooting: (gdb) set debug remote 1

Connecting GDB to the Kernel through a Physical Serial Port

  • [scottt@2530p linux-2.6]$ gdb ./vmlinux
  • (gdb) set remotebaud 115200
  • (gdb) target remote /dev/ttyS0 # change ttyS0 to the actual serial device on your development machine