Qemu + eclipse combination: Linux kernel debugging

Source: Internet
Author: User

I. Linux kernel source code reading Tool

Of course, source insight is preferred in windows, but there is no such good tool as source insight in linux, but there are also many alternatives, however, some people will definitely choose the combination of vim + ctags + csloud, some will also choose source insight in wine or navigatror, of course, the combination of vim + ctags + csags is a better choice for code reading. However, after I use eclipse, I personally feel that using eclipse as the source code reading tool in linux is much more convenient than the combination of vim + ctags + cs.pdf.

The following describes how to configure and install eclipse in linux:

Eclipse: http://eclipse.org/downloads? OsType = linux

Eclipse environment configuration scheme: http://forum.ubuntu.org.cn/viewtopic.php? T = 183803

2. Compile and debug the Linux source code using eclipse + qemu

At first, the kernel was debugged using a combination of qemu + insight or qemu + ddd. Compared with insgiht, the interface is better. However, in ubuntu 10.04 or later versions, default support for Insight is deleted, only the source code compilation and installation of insight can be downloaded, and the update of insight is very slow. A long time ago, I saw someone using eclipse + qemu to compile and debug the Linux kernel source code. This time I finally took some time to try it out. After all, the debugger of eclipse is very powerful.

Tool combination: Eclipse IDE for C/C ++ Linux Developers + qemu-0.12.3 (preferably kvm, unfortunately the machine is too old to support hardware virtualization)

 

 

1. First we will download the kernel source code from www.kernel.org, where I chose linux-2.6.32.tar.bz2. I downloaded it to my home directory, and then entered the following command under terminal.

$ Cd (back to main directory)

$ Tar xf linux-2.6.32.tar.bz2 (extract source code)

$ Mkdir linux-2.6.32-obj (create a destination file output directory for compiling the kernel)

$ Cd linux-2.6.32 (go to the kernel source code root directory)

$ Make O = ~ /Linux-2.6.28-obj menuconfig (Here we want to configure the kernel, and in ~ /The Kernel configuration file is generated under the linux-2.6.32-obj directory. config)

$ Make mrproper

 

 

2. Next we will open elicpse. There will be a welcome screen when we open it for the first time,

Click the workbench image on the right to turn off the welcome screen. Because eclipse cdt is a very powerful c/c ++ ide, it automatically parses the source program in the project by default, compiles the project, and generates intelligent prompts. However, since these functions are not used during kernel debugging, We need to disable them.

First, remove the Build Automatically option from Window> Preferences> General> Workspace.

Go to Window> Preferences> C/C ++> Indexer and change the default Fast c/c ++ indexer to No indexer.

Then we start to create a new project.

Select File> New> Project from the menu... -> C/C ++-> C Project and click Next.

A dialog box is displayed. Enter a Project Name in the Project Name field, for example, linux-kernel. Then, deselect the Use default location option. Fill in the path of the extracted kernel source code in the Location column. Select Makefile Project> Empty project for project type. Select Linux GCC for Toolchains. The final result is shown in:

 

Click Next to display the Next dialog box. At this time, the default configuration of the project does not fully meet our requirements. So we click the Advanced Settings button to open a project configuration dialog box. Select the C/C ++ Build option on the left. On the right-side page, select the Use default build command on the Builder Settings option page, then specify a new Build command as make O =/home/xxx/linux-2.6.28-obj. click File in Build location
System... The button changes the output directory of the obj file to/home/xxx/linux-2.6.28-obj. The final result is shown in:

Click the Behaviour option page, change all in build (Incremental Build) to a space, and change the following clean to mrproper (this is the command target for clearing the kernel obj file by default ). As shown in figure:

 

At this time, you can compile the kernel. Ctrl + B start to compile the kernel.

 

Compile the kernel. At/home/xxx/linux-2.6.32-obj/arch/x86/boot/, a large kernel image of bzImage will be generated.

Run the qemu VM in xterm. The command line is as follows:

$ Qemu-s-hda ~ /Linux-0.2.img-kernel/home/XXX/linux-2.6.32-obj/ARCH/x86/boot/bzimage-append root =/dev/hda

I will explain the parameters on this command line.

The-s option indicates that port 1234 is enabled as the debugging port when we run the Virtual Machine for use in eclipse network debugging.

The-s option indicates that the VM needs to be frozen when the VM is started, waiting for the debugger to issue a command to continue running.

-Hda ~ /Linux-0.2.img indicates the hard disk we want to run (this file can be downloaded at http://wiki.qemu.org/download)
-Kernel/home/XXX/linux-2.6.32-obj/ARCH/x86/boot/bzimage indicates the kernel image we want to debug

-Append root =/dev/hda indicates the parameter we want to pass to the kernel (Here you may feel a bit strange why it is/dev/hda instead of/dev/hda1 or/dev/hda2?? Because this image is only a partition binary image, not the entire hard disk image)

After it is started, you will see nothing black on the screen. Because the-S parameter is specified, the VM is frozen.

Go back to eclipse. In this case, select Run-> debug deployments from the menu, and open a configuration page. Then we double-click the mouse on the C/C ++ application, then the debug configuration option is displayed on the right side of the page, and then we select Linux-kernel in the project column, enter/home/XXX/linux-2.6.32-obj/vmlinux in the C/C ++ Application below, as shown in:

Click the debugger option page to change the debugger to gdbserver debugger. change stop on startup at to start_kernel, and change the type on the connection sub-option page to TCP to change the port number to 1234, as shown in the end:

Click debug to start debugging! At this time, eclipse will prompt us to switch to perspective, select Yes, and no longer prompt.

At this time, we started to debug the kernel, and it was source code-level debugging! For example:

 

Summary: for those with poor machine configuration, this combination may be depressing, and the debugging time is too long. Another problem is that compilation is required for each debugging. I don't know if there are any options to disable automatic compilation during debugging. I 'd like to inform my younger brother of this issue.

Related Article

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.