How to setup kgdb for Linux kernel module debugging

It is my first question on this forum.

I am writing a LKM (Loadable Kernel Module) for my Linux colibri-imx6 4.1.39 kernel and want to use the kgdb for remote debugging.
Does somebody know, which CONFIG_ settings must be made in the .config file and how to setup my target in order to start the kgdb?

Thanks in advance

The below config options will have to be enabled.

CONFIG_DEBUG_INFO
CONFIG_GDB_SCRIPTS
CONFIG_KGDB
CONFIG_KGDB_SERIAL_CONSOLE

Some information on kgdb setup can be found here and here.

Thanks for your response,
I finally added the commands “kgdbwait kgdbco=ttymcx0,115200” to the kernel command line. and my kernel stopped after booting with the “[1]kdb>” prompt.
regards JBA

Hi,

I tried KGDB with the i.MX7D 1GB module.
We need to setup Host-PC for GDB client and Target-i.MX7 for GDB server.
Here is the list of things which I followed.

  • Enable below config, by using make menuconfig

    CONFIG_KGDB=y

    CONFIG_MAGIC_SYSRQ=y

    CONFIG_DEBUG_INFO=y

    CONFIG_KGDB_SERIAL_CONSOLE=y

Then save and compile the kernel and modules. Also, replace on module.

  • To enter in KGDB mode on Target-i.MX7, there are two methods.

(a) From Uboot Env variable

Stop booting at uboot by pressing any key, and add “kgdboc=ttymxc0,115200 kgdbwait” line.

Colibri iMX7 # editenv setup
edit: setenv setupargs "console=tty1 console=${console},${baudrate}n8 ${memargs} consoleblank=0 kgdboc=ttymxc0,115200 kgdbwait" 

Colibri iMX7 # saveenv

Colibri iMX7 # boot

Booting will stop in between by saying
[ 1.040988] KGDB: Registered I/O driver kgdboc
[ 1.084058] KGDB: Waiting for connection from remote gdb…

(b) From Kernel user space using sysfs :

$ echo "ttymxc0,115200" > /sys/module/kgdboc/parameters/kgdboc 

$ echo g > /proc/sysrq-trigger 
  • Now need to setup a Host-PC environment as a GDB client.
    Export toolchain. (Here I am using Linaro toolchain which I used for my kernel build.)
    Run gdb with vmlinux as an argument.

    deven@deven:-> arm-linux-gnueabihf-gdb vmlinux

Before doing the below steps, make sure you are exited from minicom.
Set baud rate of UART port.

(gdb) set serial baud 115200

Set target as a UART port.

(gdb)  target remote /dev/ttyUSBX

That’s all you are ready to use KGDB.
Here are some commands which are helpful.

gdb > break ds1307_probe   	(To put break point at function )
gdb > continue		(booting continue)
gdb > bt			(backtrace)
gdb > n			(next)
gdb > info breakpoints
gdb > delete breakpoints 2
gdb > break mm/oom_kill.c:436 (using file and numbers)
gdb > print oom_kills 	(to print variable)
gdb > info break
gdb > info registers
gdb > info threads
gdb > list 

NOTE: If you want to use KDB, then enable CONFIG_KGDB_KDB=y, and perform the same steps as above.