KGDB is the Linux Kernel Debugger.
To use KGDB to debug your Nios2 Linux Kernel, you'll need to checkout the most recent unstable-nios2mmu branch and enable the following kernel configuration options:
Kernel hacking --->
[*] Kernel debugging
[*] KGDB: kernel debugger --->
<*> KGDB: use kgdb over the serial console
We will be using the Altera UART for communication to KGDB, thus the console must be on the JTAG UART. Make sure you configure the serial drivers as follows:
Device Drivers --->
Character devices --->
Serial drivers --->
<*> Altera JTAG UART support
[*] Altera JTAG UART console support
<*> Altera UART support
[ ] Altera UART console support
Then add the following bootargs string to your dts:
bootargs = "debug kgdboc=ttyAL0,115200 kgdbwait console=ttyJ0,115200";
Then rebuild your kernel.
After downloading the kernel to your target you should see the boot messages pass by until the kernel pauses with the following log messages:
ttyAL0 at MMIO 0x6000000 (irq = 2) is a Altera UART
kgdb: Registered I/O driver kgdboc.
kgdb: Waiting for connection from remote gdb...
Now start gdb on your development host using:
nios2-linux-gnu-gdb -b 115200
Inside gdb, connect to the target KGDB using (replace /dev/ttyS0 by whatever device you're using, e.g. /dev/ttyUSB0)
target remote /dev/ttyS0
Then load the symbols from your kernel image (assuming you started gdb from inside your uClinux-dist):
You can now set breakpoints, e.g. to break on program load:
For more complete information about compiler optimizations, see our Optimization Notice.