Skip to content
J. Neuschäfer edited this page Jan 28, 2023 · 2 revisions

(WIP)

Sometimes you want to attach GDB to your kernel, but you don't have fancy hardware support (JTAG). For those cases, the Linux kernel has a module named KGDB.

scripts/config -e CONFIG_KGDB                          # KGDB core
scripts/config -e CONFIG_KGDB_SERIAL_CONSOLE           # debugging over serial port
scripts/config -d CONFIG_STRICT_KERNEL_RWX             # to allow software breakpoints to work (necessary on ARM926)
scripts/config -d CONFIG_KGDB_KDB                      # disable the interactive debugger frontend (KDB)
scripts/config -e CONFIG_MAGIC_SYSRQ                   # allow breaking into the debugger...
scripts/config -e CONFIG_MAGIC_SYSRQ_SERIAL            #   via the serial port
scripts/config --set-str CONFIG_CMDLINE "kgdboc=ttyS0" # finally, enable KGDB on /dev/ttyS0
scripts/config -e CONFIG_DEBUG_INFO_DWARF5             # enable debug info
scripts/config -e CONFIG_DEBUG_INFO_COMPRESSED_ZLIB    # (make 'em small)

After building and booting your new kernel, download agent-proxy and start it on your workstation:

agent-proxy 9000^9001 0 /dev/ttyUSB0,115200

Next, you'll want to connect to port 9000 with telnet (this is for interactive console use), and to port 9001 with GDB. Make sure to use the right GDB, as a GDB targetting x86 won't help you debug ARM kernels very well.

$ gdb-multiarch -q vmlinux --ex "target remote localhost:9001".
(gdb) ....

References