Linux kernel debugging: qemu + eclipse combination

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 need to download the kernel source code from www.kernel.org. Here I select
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 the source code)

$ Mkdir linux-2.6.32-obj
(Create a directory for compiling the kernel's target file output)

$ 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 is 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 ++
By default, it automatically parses the source program in the project, compiles the project, and generates intelligent prompts. However, since these functions are not used during kernel debugging, We need to disable them.

First, go to window> preferences> General> workspace.
Remove the build automatically option.

Go to window-> preferences-> C/C ++->
In indexer, 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 column, for example
Linux-kernel. Then, uncheck the use default location option. Fill in the path of the extracted kernel source code in the location column. Project
Type select makefile project-> Empty Project. Choose Linux
Gcc. 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 Advanced Settings
A project configuration dialog box is displayed. Select the C/C ++ build option on the left. On the right-side page, click use on the builder settings option page.
Select default build command, and specify a new build command as make
O =/home/XXX/linux-2.6.28-obj. Then click File in build location
The system... 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
In build), change all 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.

-S
Option indicates that port 1234 is enabled as the debugging port when we run the Virtual Machine for eclipse network debugging.

-S
Option indicates that the VM will 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
It indicates the parameter we want to pass to the kernel (Here you may feel a little 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, choose run> debug from the menu.
In this case, a configuration page is opened. Then, in C/C ++
Double-click the application, and the debug configuration option is displayed on the right page. Select Linux-kernel in the project column, and in the C/C ++
Enter/home/XXX/linux-2.6.32-obj/vmlinux in application, as shown in:

Click the debugger option page to change the debugger to gdbserver.
Change stop on startup at to start_kernel, and change the type on the connection suboption page to TCP to Port
Change the number to 1234, as shown in the following figure:

Click debug to start debugging! At this time, eclipse will prompt us to switch
Perspective, select Yes, 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.