Using kdb/kgdb

I’m not really sure where to address this question, but I’m trying to debug a loadable kernel module I wrote. For this purpose, I have compiled a kernel from ti’s fork (mirror?) of Linux 6.12.34. My kernel config is mostly inherited from omap2plus_defconfig but with kgdb/kdb enabled. Everything boots correctly, but when I go to start kdb with sysrq+g, kdb crashes immediately. I can use kdb immediately following boot, but not from userspace.

root@oresat-dev:~# echo g > /proc/sysrq-trigger 
[  105.629191] sysrq: DEBUG

Entering kdb (current=0xc2a9e400, pid 268) on processor 0 due to Keyboard Entry
[0]kdb> [  105.641069] 8<--- cut here ---
[  105.644192] Unable to handle kernel paging request at virtual address fee00064 when read
[  105.652361] [fee00064] *pgd=00000000
[  105.656021] Internal error: Oops: 5 [#1] SMP ARM
[  105.660767] KGDB: re-enter exception: ALL breakpoints killed
[  105.666491] ---[ end trace 0000000000000000 ]---
[  105.671165] note: bash[268] exited with irqs disabled
Killed
2 Likes

Not exactly sure what I did, but I got it to work. Here’s my setup.

Edit: In retrospect, I should have just used RobertCNelson/ti-linux-kernel-dev, but at least I learned something.

/proc/cmdline

console=ttyS0,115200n8 root=/dev/mmcblk0p2 rw rootwait kgdboc=ttyS0 oops=panic panic=0

Configuration, Compilation, and Installation

As I said earlier this is inherited from arch/arm/configs/omap2plus_defconfig. But I also added these.

git clone -b v6.12.34 --depth=1 https://git.ti.com/git/ti-linux-kernel/ti-linux-kernel.git ti-linux-kernel

Within the repo,

export ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
make omap2plus_defconfig

I then customized the generated configuration with nconfig

make nconfig

I added these.

CONFIG_VT=y
CONFIG_VT_CONSOLE=y
CONFIG_KGDB=y
CONFIG_KGDB_KDB=y
CONFIG_PANIC_TIMEOUT=0
CONFIG_WATCHDOG=n
CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE=1
CONFIG_DEBUG_KERNEL=y
CONFIG_DEBUG_INFO=y
CONFIG_GDB_SCRIPTS=y
CONFIG_STRICT_KERNEL_RWX=n

Finally, compile the kernel.

make zImage modules -j$(nproc --all)

Assuming, we already have an image on a microSD and valid device trees.

sudo cp -v  arch/arm/boot/zImage /mnt/BOOT
sudo make INSTALL_MOD_PATH=/mnt/ROOT

Should be good to go from there, though some things will break, since I’m using a jankily compiled kernel.

To get to kdb

debian@oresat-dev:~$ sudo -i
[sudo] password for debian: 
root@oresat-dev:~# echo g > /proc/sysrq-trigger 
[  154.084575] sysrq: DEBUG

Entering kdb (current=0xc2121400, pid 291) on processor 0 due to Keyboard Entry
[0]kdb> 

Notables

kgdb_breakpoint() can be used to hardcode breakpoints. See include/linux/kgdb.h for more.

omap2plus_defconfig doesn’t configure the pruss, so add that if it’s needed.

References

Using Serial kdb / kgdb to Debug the Linux Kernel - Douglas Anderson, Google
TI Processor SDK Linux for AM335X section 3.2.1
Using kgdb, kdb and the kernel debugger internals
Bootlin Elixir: kgdb.h

1 Like

Yea boy! I usually jump in to celebrate others and their respective approaches to finalization!

I was unaware that omap2plus_defconfig did not or does not configure the PRUSS. Yes!

1 Like

Yeah, feels a little weird to not even have it as a LKM.

Unrelated, I appreciate the encouragement! I cross posted this a few places, and so far the only response I’ve gotten is from a chatbot… Kind of a bummer.

1 Like