Debug the Linux kernel with kgdb and VMware, System Call__linux

Source: Internet
Author: User

Linux kernel and system call is not easy to debug, refer to here:

Http://stackoverflow.com/questions/5999205/cannot-step-into-system-call-source-code

In short, if you want to debug system call on your computer, then when you go into system call, the system is already suspended and how it responds to user input.

So, there is a UML (http://user-mode-linux.sourceforge.net/) way to start the kernel as a process so that it can be debugged on the machine.

Otherwise, only through the serial port, or network, etc. from different machines to debug.

Using KGDB and VMware virtual machines toss the next to debug Linux system call with a serial port. Sum up. editing the kernel

First, install the Linux system in the virtual machine (note that the hard disk space is larger) and compile the kernel with the debug information:

First download the relevant package, and the current kernel source code, pay attention to the source code with the Apt-get source, is placed in the current directory.

mkdir Code
CD code
sudo apt-get dpkg-dev
sudo apt-get source linux-image-$ (uname-r)
sudo apt-get Install Libncurses5-dev
sudo apt-get install BC
Re-configure the editing options:

sudo make Menuconfig
There will be an interface that you can set up the editing options for yourself. Under the "Kernel hacking", there are kgdb options, but seemingly by default are selected.

Execute make compilation, then execute

sudo make made
modules_install  //Codec module
It took me 3, 4 hours to make up my story, and it was 11G.

copy these compiled data to a host, wait for the debugging time to use. Configuring a serial port for a virtual machine

In VMware's "Settings", "Hardware", point "Add", select "Serial Port", then "output to Socket", in "socket (named pipe)", fill in "/tmp/testsocket ”。 The serial data in the virtual machine will be written to the/tmp/testsocket file.


Configure new kernel boot

The easiest way to use the new kernel is to switch directly to the root user:

Make install
Automatically copies Vmlinuz,.config, Initrd.img, and so on to the boot directory and starts with the new kernel by default.

Only start with a new kernel can not debug, modify the/boot/grub/grub.cfg file, under the "Linux" command to increase the KGDB parameters, such as:

Linux/boot/vmlinuz-3.13.0-24-generic root=uuid=xxx-b91d-xxx-839d-xxxxxx ro quiet kgdboc=ttys1,115200 kgdbwait
If you simply do not want to start the wait, you can remove the kgdbwait parameter.

Restart the virtual machine, you can find the stop on this screen:


using SOCAT to transmit serial data to the PTS virtual machine has been paused, waiting for our connection.

First, use SOCAT to transfer the serial output of the virtual machine to PTS (you can view more information about PTS with the man pts).

With CTRL + ALT + F1, enter the Tty1, and then enter the following command:

sudo socat-d-d/tmp/testsocket PTY

If successful, we can see output like this:

Successfully connected
... PTY IS/DEV/PTS/14
connect pts with GDB, and debug

Switch to root, into the compiled code directory copied from the virtual machine, and execute:

GdB./vmlinux


If you do not load the Vmlinux file, you will not be able to break the breakpoint. Type in GDB again.

Remote Debugging USING/DEV/PTS/14
continue

Then you can see the Linux in the virtual machine turned on and started normally.
Note that if you want to interrupt a point on system call, add "Sys_" before the number of original letters. Such as
Break Sys_open

After entering continue in gdb, I found no way to interrupt the point, can be in the virtual machine as root user:
echo g >/proc/sysrq-trigger

This allows the virtual machine to pause and can be restarted in the host's gdb.
Reference:http://www.opensourceforu.com/2011/03/kgdb-with-virtualbox-debug-live-kernel/#
Http://www.eetop.cn/blog/html/21/766721-25573.html
http://blog.csdn.net/u011839461/article/details/12002075
Http://wenku.baidu.com/view/baf6af3f0912a21614792996.html
http://my.oschina.net/fgq611/blog/113249
http://blog.csdn.net/star_xiong/article/details/17357821

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.