Http://hi.baidu.com/%C4%FE%BE%B2%B5%C4%B7%B1%BB%AA/blog/item/1c4c83192ac4dd158718bf66.html
Principle:
GDB supports remote debugging, serial port connection, and TPC/IP network connection.
In ubuntu 9.10linux, virtualbox acts as a virtual machine and installs a Linux system to be debugged.
A. Create a link.
Select the serial port for debugging. In the virtual machine configuration of virtualbox, set the serial port to "COM1", "Host-pipe", select "CREATE", and enter: "/tmp/v_pip0" serves as the pipe connected to the virtual machine serial port. Now, the connection between the VM and the debugging platform is complete.
B. Test the serial port:
Enter stty ispeed 115200 ospeed 115200-F/dev/ttys0 in gest OS to set the working speed of the serial port com1.
Download the minicom serial port tool from the host OS and set its configuration file (/etc/minicom/minirc. DF1) to write as follows:
Pu port UNIX #/tmp/v_pip0
Start minicom. After the link is connected, it is displayed online. On the Gest OS side, you can use Cat and echo commands to read and write the serial port. On The minicom side, you can directly input the data that the serial port arrives at will be directly displayed on the screen.
If you can communicate, the serial port is working properly.
C. Compile the kernel that can be debugged:
Choose to debug the kernel through serial port
Bytes -------------------------------------------------------------------------------------------
Make menuconfig-> kernel hacking->
[*] Kernel debugging [*]
[*] Compile the kernel with debug info
[*] Kgdb: kernel debugging with remote GDB --->
--- Kgdb: kernel debugging with remote GDB
<*> Kgdb: Use kgdb over the serial console
Bytes -------------------------------------------------------------------------------------------
D. Set the debugging environment:
> Write/boot/GRUB/grub. cfg to start the project:
Linux/boot/... after entry: kgdboc =
> Copy the new kernel to the Host OS for debugging. Remember: Copy vmlinux instead of vmlinuz (Compressed ).
E. Start GDB to start debugging:
> After the new kernel is started, enter stty ispeed 115200 ospeed 115200-F/dev/ttys0 In the Gest OS for debugging.
Set the speed of serial port COM1, press Alt + print sysrq + G magic key, enable GDB debugging, freeze the system, and display kgdb
Waiting
> Run the following command on the host OS:
Socat udp4-listen: 6443/tmp/v_pip0
Map MPs queue to UDP port
Run GDB./vmlinux
After entering, set the gdb target:
Target remote UDP: localhost: 6443
Wait a moment, and you will be connected to gest OS.
Certificate -----------------------------------------------------------------------------------------------------------------------------------
PS: module debugging
>
Before starting module debugging, insert the module into the system and make sure that the-G option is available for cflags during module compilation. Copy module files and module source files
Run CAT/proc/modules in the Host OS to find the module's loading address. Remember, when you debug GDB in the Host OS
Yes.
>
After running GDB, run the add-symbol-file command to load the symbol of the module:
(GDB) Add-symbol-file my-module.ko address
Here address is the module loading address, which is obtained above.
Now, the module can be debugged (set breakpoints, etc ).
**************************************** ***************
Http://forum.linuxfans.org/thread-44268-1-89.html
For kernel, I suggest u to use kgdb
Http://kgdb.sourceforge.net/connect.html
Http://www.cs.wm.edu /~ Bob/ddd-with-modules.html
**************************************** ******************