Friday, January 22, 2010

KGDB Tutorial

KGDB Tutorial

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] (ex: kgdboc=ttyAMA1 for qemu-system-arm)
  2. (alternatively) From sysfs
    echo TTY_DEVICE > /sys/module/kgdboc/parameters/kgdboc

Connecting GDB to the Kernel through 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 -net
      nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=./scripts/qemu-ifup
      -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 show "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




    0 comments:

    Post a Comment