Hi All,
I know the pain to set up the kgdb and debug the driver module.
Therefore, after I successfully set up the environmnet and succeed to debug my driver these days, I would like post the procedures of setting to help the people who is tortured by it. I think it is the spirit of open source.
If you have other successful and better experiment, please share with us and help me make it better. I will appreciate it.
BTW, I apply it on 32-bit FC 11 and I built kgdb-light from sourceforge.
Thanks for the help from Caz Yokoyama, Nikhil Nygaard and Paul Fulghum.
KGDB Setting & Debugging Driver Module:
1, on the development machine
1.1 in the root home directory, edit a .gdbinit file with the content as below:
set prompt (kgdb)
set solib-search-path /root/arcsas:/root/arcmsr /*set solib-search-path <.ko file's path1>:<.ko file's path2>:<.ko file's path3>*/
set remotebaud 115200
target remote /dev/ttyS0
/* Note: There is no need to add two entries, set debug remote 1 and set debugkernel 1*/
/* Note: The order among the entries is important.*/
1.2 Build a kernel with CONFIG_KGDB=y and CONFIG_KGDB_SERIAL_CONSOLE=y on the development machine, and copy the vmlinuz-XXX and initrd-XXX and system.map-XXX to test machine.
Make a hyperlink for vmlinuz-XXX, initrd-XXX and system.map-XXX.
2, on the test machine
2.1 edit the /etc/rc.d/rc.local file as below,
stty -F /dev/ttyS0 115200 /*This is very important especially on FC 11. Because after booting up, the speed of ttyS* will be reset.
Once gdb can not connect the test machine while Alt+Sys_Rq+g is launched on the test machine.
This entry should be there for this purpose.*/
echo 0 > /proc/sysrq-trigger /*Sets the console log level, controlling which kernel messages will be printed to your console.
'0' would make it so that only emergency messages like PANICs or OOPSes would make it to your console.*/
echo 1 > /proc/sys/kernel/sysrq /*The detailed description can be found in Documentation/sysrq.txt. '1' means enable all functions of sysrq*/
2.2 edit /etc/grub.conf as below,
kgdb=ttyS0,115200 kgdboc=ttyS0,115200 kgdbwait /*This is the only feasible kernel parameter so far*/
3, After the message, "kgdb: Waiting for connection from remote gdb...", showned on the test machine,
run with "gdb vmlinux", which vmlinux is not the bzImage, and it should be the kernel built in the /usr/src/linux/
after the "make && make modules_install && make install" procedure.
4, Press "c" or "continue" after the gdb prompt on the development machine.
5, Insert the mgsl_get_text_ptr() & BREAKPOINT() in the driver's initial function(the first function of driver), where mgsl_get_text_ptr() & BREAKPOINT() are duplicated from drivers/char/synclink.c.
6, Insert driver module on the test machine, then test machine will be stopped automatically.
There is a Hex number appeared in the gdb. Keep it in mind. Then make test machine continue to run.
7, On the development machine, run "more /sys/module/driver_name/sections/.text", and collect the .text section address.
8, Manually calculate the difference of the values, which respectively are collect from 6, and 7,. Keep it.
Reboot the test machine and repeat the Step 3,4,6.
9, Subtrat the value of Step 8 from the hex number you got in the gdb on the development machine. You can use it as the .text section address
while run "add-symbol-file <driver .ko file> <.text section address>".