kgdb module debugging question
Hi,
I am trying to debug my loadable kernel module via KGDB remote debugging. I have tried to explain the steps that I am following in detail: Note: [dev@dev] represents development machine [test@test] represents test machine 1. Configure the kerenl: [dev@dev] cd ~/linux-2.6.38.8/ [dev@dev/linux-2.6.38.8] make menuconfig Make sure the following two options are enabled Kernel Hacking -> Magic SysRq Key : : -> KGDB: Kernel Debugger Give 'Y' to both option Note: In Linux Version 2.6.38.8, these options are enabled by default. 2. Built he kernel and my driver Note: mydriver source resides at ~/mysource/ a. mydriver.ko file at ~/output/. b. bzImage at ~/linux-2.6.38.8/arch/i386/boot c. System.map at ~/linux-2.6.38.8 d. vmlinux at ~/linux-2.6.38.8 3. Copy System.map and bzImage to some external media storage. 4. Copy the following kernel images to target machine (/boot) with root permissions [root$test] cd /boot [root$test/boot] cp /media/<device>/bzImage vmlinuz-2.6.38.8-kgdb [root$test/boot] cp /media/<device>/System.map System.map-2.6.38.8-kgdb 5. Copy mydriver.ko file to test machine [root$test] cd ~/mydriver/ [root$test/mydriver] cp /media/<device>/mydriver.ko mydriver.ko 6. Add a grub entry [root$test] cd /boot/grub [root$test] vi grub.cfg Add below lines: menuentry 'Ubuntu, with Linux 2.6.38.8-kgdb' --class ubuntu --class gnu-linux --class gnu --class os { recordfail set gfxpayload=$linux_gfx_mode insmod part_msdos insmod ext2 set root='(/dev/sda,msdos1)' search --no-floppy --fs-uuid --set=root bfc015dd-36ce-469a-b11f-4e7939ba4b90 linux /boot/vmlinuz-2.6.38.8-kgdb root=/dev/sda1 ro crashkernel=384M-2G:64M,2G-:128M quiet splash vt.handoff=7 kgbwait kgdboc=ttyS0,115200 7. Boot the test machine with those kernel parameters. 8. This will stop your Kernel booting on Test machine and wait for the gdb connection from devlopment machine. 9. On development machine, start GDB session and run following commands [dev@dev] cd ~/linux-2.6.38.8 [dev@dev] gdb vmlinux The argument vmlinux file is the file that is created with Debug symbols and it is present in the directory where you gave "make" command.. (gdb)set remotebaud 115200 (gdb)target remote /dev/ttyS0 Remote debugging using /dev/ttyS0 kgdb_breakpoint () at kernel/debug/debug_core.c:960 960 wmb(); /*Sync point after breakpoint */ 10. This will give control to your development machine. 11. Once development machine has control and to do the normal boot give the below command (gdb)continue This will continue Kernel booting and it will not return GDB prompt back unless and until there is a kernel crash. 12. Before loading your module on test machine, make sure the serial interface baud rate is set to 115200 [test@root] stty -F /dev/ttyS0 115200 13. Load the module on test machine, [test@root] cd ~/mydriver/ [test@root] insmod mydriver.ko 14. Send SysRq + g command. [test@root] echo 1 > /proc/sys/kernel/sysrq [test@root] echo g > /proc/sysrq-trigger This will stop the kernel execution and give control to the gdb (gdb) target remote /dev/ttyS0 Remote debugging using /dev/ttyS0 kgdb_breakpoint () at kernel/debug/debug_core.c:960 960 wmb(); /* Sync point after breakpoint */ (gdb) 15. Since we had started your GDB session with vmlinux file and now we are trying to debug a module that we have written, GDB session wont know any of the symbols that we are using in our Module. To solve this problem, we have to make GDB aware of those symbols using add-symbol-file. Syntax: (gdb)add-symbol-file <path to .ko file> <.Text Section address> <Test Machine> Run the below command to know the address of .text section [test@root]cat /sys/modules/mydriver/sections/.text 0xfa4a7000 This will give the second argument that you need to give to add-symbol-file commands. <Development Machine> (gdb)add-symbol-file ~/output/mydriver.ko 0xfa425000 add symbol table from file "/home/mymachine/output/mydriver.ko" at .text_addr = 0xfa425000 (y or n)y Reading symbols from /home/mymachine/output/mydriver.ko ..done It will load the symbol information. 16. Now we are able to set breakpoint to your module functions. (gdb)br mydriver_function Breakpoint 1 at 0xfa4581ae: file ~/mysource/mydriver_source.c, line 1168 16. Continue (gdb)c Warning: Cannot insert breakpoint 1. Error accessing memory address 0xfa4581ae: Unknown error 4294967295 Note: Currently getting above error on continuing. On exploring, came accross below link http://www.mail-archive.com/kgdb-bug.../msg03464.html As per the above link, CONFIG_DEBUG_RODATA should be turned off when using kgdb. I tried with turning CONFIG_DEBUG_RODATA off, but still facing the above issue. Please correct me where I went wrong. Thanks and Regards, Meena |
The mistake I was making is that I wase setting the breakpoint using break (br) instead I have to use hbreak(hb) hardware assisted breakpoint.
|
I got the same problem with error, i.e. "Error accessing memory address 0xf895d000: Unknown error -1."
Using hbreak as you said solved my problem! Thanks. |
CONFIG_DEBUG_SET_MODULE_RONX need turn off also to debug kernel module
|
Try to disable CONFIG_DEBUG_RODATA and CONFIG_RANDOMIZE_BASE
|
All times are GMT -5. The time now is 08:16 AM. |