Summary of source reading tools and debugging methods for Linux kernel under Ubuntu

Source: Internet
Author: User

Http://blog.chinaunix.net/uid-20940095-id-66148.html

A Linux kernel source reading tool

Under Windows, of course, the source insight is preferred, but Linux does not have the source insight such a good tool, but there are a lot of alternatives, but feel absolutely certain people will choose the combination of Vim+ctags+cscope, There are also some people who choose source Insight in wine or choose Navigatror, of course, the combination of Vim+ctags+cscope for code reading is a better option, but when I use Eclipse, The personal feeling that using eclipse as the source code reading tool in Linux is much more convenient than the vim+ctags+cscope combination.

The following is the configuration installation scenario for Eclipse in the Linux environment:

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

Eclipse Environment Configuration scenario: http://forum.ubuntu.org.cn/viewtopic.php?t=183803

Two eclipse + qemu for Linux source compilation and debugging

Initially debugging the kernel using the combination of QEMU + insight or QEMU + DDD, compared to the Insgiht interface is much better, but Ubuntu 10.04 version, removed the insight of the default support, can only download insight source compiled installation, And insight update is very slow. Long ago saw someone using Eclipse + QEMU to compile and debug the Linux kernel source code, this time finally smoked a time to try, after all, Eclipse debugger is very powerful.

Tool Mix: Eclipse IDE for C + + Linux developers + qemu-0.12.3 (preferably with KVM, unfortunately the machine is too old to support hardware virtualization)

1. First we want to download the kernel source code from www.kernel.org, here I choose is linux-2.6.32.tar.bz2. I download it to my home directory, and then enter the following command under Terminal.

$ CD (Back to home directory)

$ tar XF linux-2.6.32.tar.bz2 (unzip source)

$ mkdir linux-2.6.32-obj (Create a target file output directory for a compiled kernel)

$ cd linux-2.6.32 (enter kernel source root directory)

$ make o=~/linux-2.6.28-obj menuconfig (here we will configure the kernel and generate the kernel configuration file in the ~/linux-2.6.32-obj directory. config)

$ make Mrproper

2. Next we open the Elicpse, there is a welcome screen for the first opening,

We click on the workbench image on the right to turn off the Welcome screen. Because the eclipse CDT is a very powerful C/s + + IDE, it automatically parses the project's source program and compiles the project and generates smart hints by default. However, because we do not use these functions in the debugging kernel process, we should close them.

First we get rid of the build automatically option in Window->preferences->general->workspace.

Then, in window->preferences->c/c++-a indexer, change the default fast C + + + indexer to no indexer.

Then we started to create a new project.

From the menu, select File, New, project ..., c/C + +, project, and then click the Next button.

A dialog box appears and a project name, such as Linux-kernel, is entered in the Project Name field. Then use the default location option to tick off. In the Location column, fill in the path of the kernel source you just unzipped. Project type Select Makefile Project, Empty project. Toolchains Select Linux GCC. The end result is as follows:

Then click the Next button and the next dialog box appears. This is because the default configuration of the project does not exactly meet our requirements. So we click the Advanced Settings button to open a Project configuration dialog box. We select the C + + build option on the left, and on the appropriate right side of the page we will check the Use default build command under the Builder Settings Options page and specify a new Build command for Make O=/ho Me/xxx/linux-2.6.28-obj. Then click File System in the build location ... button to change the output directory of the obj file to/home/xxx/linux-2.6.28-obj. The end result is as follows:

Then click the Behaviour Options page, change all in Build (Incremental build) to a space, and the following clean to Mrproper (this is the command target for purging the kernel obj file by default). As shown in the following:

This time you can compile the kernel. Ctrl + B starts compiling the kernel.

The kernel is finished compiling. A large kernel image of Bzimage will be generated under/home/xxx/linux-2.6.32-obj/arch/x86/boot/.

At this point we run the QEMU virtual machine under Xterm, the command line is as follows:

$ qemu-s-s-hda ~/linux-0.2.img-kernel/home/xxx/linux-2.6.32-obj/arch/x86/boot/bzimage-append Root=/dev/hda

Let me explain the parameters on this command line.

The-S option indicates that when we run the virtual machine, 1234 ports are opened as debug ports for use in the Eclipse network debugging

The-s option indicates that we want to "freeze" the virtual machine when we start the VM, waiting for the debugger to issue a command to continue running.

-hda ~/linux-0.2.img means we want to run the hard drive (this file can be http://wiki.qemu.org/Download down to)
-kernel/home/xxx/linux-2.6.32-obj/arch/x86/boot/bzimage represents the kernel image we want to debug

-append Root=/dev/hda represents the parameters we want to pass to the kernel (here you may feel a bit strange why is/dev/hda not/dev/hda1 or/dev/hda2? Because this image is only a partitioned binary image, not an entire hard disk image)

When you start, you'll see that the screen is black and nothing. Because we have specified the-s parameter to "freeze" the virtual machine.

Continue back to eclipse, when we select Run-and-Debug configurations in the menu, this is the time to open a configuration page. Then we double-click the mouse on the C + + application, then the Debug configuration option pops up on the right side of the page, then we select Linux-kernel in the Project column, and fill in the/home/xxx/in the C + + application below Linux-2.6.32-obj/vmlinux, as shown in:

Then we click on the Debugger Options page and change Debugger to GdbServer Debugger. Change the stop on startup at to Start_kernel, and change the type of the connection sub-options page to TCP to change port number to 1234, as shown in the following:

Then click the Debug button to start debugging! At this point eclipse will prompt us to switch perspective, select Yes, and no longer prompt.

This is the beginning of debugging the kernel, but also the source-level debugging! Such as:

Summary: I do not know whether it is my machine rotten or ECLIPSE+QEMU, although debugging information more detailed, Eclipse debugger is strong enough, but every time before debugging to compile, time too long, can't afford!! Which heroes can know how to debug every time do not compile!!

Summary of source reading tools and debugging methods for Linux kernel under Ubuntu

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.