5
votes

I am trying to setup linux kernel module debugging, using two machines - target and host. On target machine, I have compiled and installed a 3.5.0 kernel with CONFIG_MAGIC_SYSRQ=y flag and other flags for over the serial console debugging.

When I want to break the kernel to attach remote gdb, I use

$ echo g > /proc/sysrq-trigger

But above command is not breaking the kernel.

$ cat /proc/sys/kernel/sysrq" 

Above command is returning 1, hence magic sysrq keys are enabled. Even "echo b > /proc/sysrq-trigger" is working and rebooting the machine. Can anybody please point out what I may be missing?

Thanks

1
And your kernel parameters are correct? See kernel.org/pub/linux/kernel/people/jwessel/kdb/EnableKGDB.html.dbrank0
I have used "kgdboc=ttyS0,115200 vmalloc=256MB" as boot params. I have also tried without vmalloc but still doesn't work. I have referred kernel.orgNaveen Rawat
I would try with kgdbwait parameter. If it does not even stop with that, then you probably missed something when configuring.dbrank0
ok my bad, when i checked using multimeter, turns out that the cable i was using was not null modem cable. once i switched the cable, it worked.Naveen Rawat
@NaveenRawat how did you verify this?4pie0

1 Answers

4
votes

You have first configure your target kernel as follows

CONFIG_FRAME_POINTER=y
CONFIG_DEBUG_KERNEL=y
CONFIG_KGDB=y
CONFIG_DEBUG_INFO=y
CONFIG_KGDB_SERIAL_CONSOLE=y (here I am using serial port for kgdb) 
CONFIG_MAGIC_SYSRQ= y (for sysrq functions).

Now compile kernel with imx6 configuration file. Boot the target with this compiled kernel.You have to tell tell target which serial port you are going to use for kgdb pupose.In my case I am using the same console port for kgdb also.This settings you can do either through kernel parameters or via sysfs entry.For imx6 sabrelite board,I am using ttymxc1 for console.This will change depending on your target

1) As a kernel parameter Add the following parameter to bootargs

kgdboc=/dev/ttymxc1,115200 to your arguments.

2) If you are using sysfs entry, do like this

echo /dev/ttymxc1,115200 > /sys/module/kgdboc/parameters/kgdboc

Since same serial port is used for both the console and debugging, we use agent proxy. Through agent proxy we get the target console as well as we do the debugging. Source for compiling agentproxy is available at the following link "https://kernel.googlesource.com/pub/scm/utils/kernel/kgdb/agent-proxy/+/agent-proxy-1.96" After compiling for host pc ,run it as follows

sudo ./agent-proxy 5550^5551 0 /dev/ttyS0,15200

Now you can see target terminal through telnet with this agentproxy support

sudo  telnet localhost 5550

(It is better to use this telnet instead of minicom where only this agent proxy support comes.) When you want to start debugging, the target system has to enter debug mode from normal mode. We can do that in this way in target

echo g > /proc/sysrq-trigger

Now it will enter debugger mode. Now from host side run gdb on vmlinux of the arm compiled kernel. Go to the corresponding kernel source directory and do like this

arm-fsl-linux-gnueabi-gdb ./vmlinux

Now it will show gdb terminal .From there you have to connect to target for kgdb,

$target remote /dev/ttyS0

In my case my host serial port is /dev/ttyS0. Now it will get connected to target. Here after you can use gdb commands to debug the kernel.

You try this way.