☰
×
◈ Introductions
◈ Linux Kernel Compilation
◈ Linux Kernel Debugging
◈ Linux Kernel APIs - I
◈ Linux Kernel APIS - II
◈ Linux Kernel APIS - III
◈ KGDB Setup
◈ QEMU Setup
◈ Linux System Calls Table
◈ Useful Linux Commands
Home
About
Consulting
Training
Tutorials
Interview Questions
Contact
Tutorials
KGDB Setup Tutorial
Home
KGDB Setup
◈ Introductions
◈ Linux Kernel Compilation
◈ Linux Kernel Debugging
◈ Linux Kernel APIs - I
◈ Linux Kernel APIS - II
◈ Linux Kernel APIS - III
◈ KGDB Setup
◈ QEMU Setup
◈ Linux System Calls Table
◈ Useful Linux Commands
Tutorials - KGDB Setup
KGDB Setup
« Prev
Next »
KGDB Setup
Minicom Setup dmesg | grep ttyS [ 12.282348] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A [ 12.282928] 00:0c: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A Now press Ctrl-A O, navigate to Serial port setup and hit Enter, type A and make sure the device is set to /dev/ttyS0, then hit Enter to validate. Type E and make sure the value is 115200, press Enter to validate. Type Enter again to go back to the previous screen and finally navigate to Save setup as dfl, Enter to validate, Esc to go back to the first screen and Ctrl-A Q to quit. Now, re-run: How to test Serial Port Testing the DEBUG cable Testing the working of the Null-modem serial cable. dmesg | grep tty setserial -g /dev/ttyS[0123] On the HOST machine : stty ispeed 115200 ospeed 115200 -F /dev/ttyS0 cat testfile.txt > /dev/ttyS0 On the Target machine : stty ispeed 115200 ospeed 115200 -F /dev/ttyS0 cat /dev/ttyS0 Target machine setup BASE_DIR = /usr/src/linux 1. Download Linux kernel source : linux-3.4.7.tar.bz2 2. Unzip the kernel sources cd ${BASE_DIR} tar -jxvf linux-3.4.7.tar.bz2 3. Change the directory as follows: cd ${BASE_DIR}/linux-3.4.7 4. In the ${BASE_DIR}/linux-3.4.7/Makefile, set the EXTRAVERSION = -kgdb 5. make menuconfig Select the options appropriate for the target machine Hardware. Select the options pertaining to kgdb under "Kernel hacking" enable kernel debugging enable compile kernel with debug option enable compile kernel with frame pointers enable KGDB: debugging under this enable debugging over serial CONFIG_HAVE_ARCH_KGDB=y CONFIG_KGDB=y CONFIG_KGDB_SERIAL_CONSOLE=y #CONFIG_DEBUG_RODATA=n 6. make bzImage (for just to check target booting ) ( or ) 6. make 7. make modules 8. make modules_install 9. make install 10. copy the vmlinux from ${BASE_DIR}/linux-3.4.7/arch/x86/boot/ to /boot directory and rename it as vmlinux-3.4.7-kgdb 11. Edit the /boot/grub/grub.conf file in the target machine to have the kgdb enabled kernel entry. The grub location and content may vary depending on the distros. Please do careful edit default=0 Time = 10 #hiddenmenu (comment the hidden menu) title Linux-3.4.7-kgdb root (hd0,0) kernel /boot/vmlinuz-3.4.7-kgdb ro root=/dev/hda1 kgdbwait kgdb8250=ttyS1,115200,4 kgdboc=ttyS1,115200 12. Now copy the ${BASE_DIR}/linux-3.4.7/ to host machine 13. And reboot the system 14. Select the appropriate kernel i.e linux-3.4.7-kgdb 15. After booting, the target machine will wait for the host development machine to connect, by displaying the message :- Waiting for connection from remote gdb... HOST machine setup 1. Change the directory to ${BASE_DIR}/linux-3.4.7/ on host machine 2. Ssty speed 115200 > /dev/ttyS0 3. gdb vmlinux 4. gdb>set remotebaud /dev/ttyS0 5. gdb>target remote /dev/ttyS0 Remote debugging using /dev/ttyS0 breakpoint () at kernel/kgdb.c:1212 1212 atomic_set(&kgdb_setting_breakpoint, 0); 6. gdb> continue On target machine echo "g" > /proc/sysrq-trigger After the target kernel boots , compile the module and copy the .ko to host and then insert it using 1. Insmod module.ko 2. cat /sys/module/module_name/sections/.text , obtain the address 3. Obtain the control on the host machine execute the command echo 1 > /proc/sys/kernel/sysrq this will return the control on host machine 4. then on target remove the inserted module 5. now on host gdb> add-symbol-file
<.text address> 6. gdb> br
7. on the target m/c insert the module 8. it will break at the mentioned function name and we can do debugging..
« Prev
Next »
Helpful Links
Interview Questions
Corporate Training
Recommended Books
Linux Consulting
Apply for Job Assistance
If you have any queries please email us at
info@motionzen.com