I think everyone is self-explanatory about the benefits of debugging. BenArticleExtracted from the original text, but added some details not described in the original text.
My system environment is: Ubuntu 9.10 + eclipse-cpp-galileo-SR1-linux-gtk.tar.gz + qemu 0.11.0
Yes
I want to explain how to shut down the system environment. Because the eclipse CDT source cannot be found in Ubuntu, you must first apt-Get an eclipse
Paltform and then select update and install CDT to install it successfully. But in eclipse Platform
Therefore, we recommend that you install opensuse 11.0. You only need to download an eclipse C/C ++ IDE from eclipse.org.
To directly decompress the package.
The article starts!
1. First we will download the kernel source code from www.kernel.org, where I chose linux-2.6.28.tar.bz2. I downloaded it to my home directory, and then entered the following command under xterm.
$ Cd (back to main directory)
$ Tar xf linux-2.6.28.tar.bz2 (extract source code)
$ Mkdir linux-2.6.28-obj (create a destination file output directory for compiling the kernel)
$ CD linux-2.6.28 (go to the kernel source code root directory)
$ Make o =/home/XXX/linux-2.6.28-obj menuconfig (Here we want to configure the kernel, and in ~ /The linux-2.6.28-obj directory to generate the Kernel configuration file. config) (Note: Here XXX represents your user name)
Note that you need to select
"Compile the kernel with debug info" and "compile the kernel with frame Pointers"
For example:
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 sourceProgramCompile the project and generate 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...> C/C ++> C project from the menu and click Next.
This
When a dialog box appears, enter a project name in the project name column, such as Linux-kernel. Then use default
The location option is cleared. Fill in the path of the extracted kernel source code in the location column. Select makefile project for project type
-> Empty Project. Select Linux GCC for toolchains. The final result is shown in:
However
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.
Use default build command check box, and then 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 to change all in build (incremental build) toSpace, Change the following clean to mrproper (this is the command target for clearing the kernel OBJ file by default ). As shown in figure:
This
Then you can compile the kernel. CTRL + B to start compiling the project. NOTE: If Elipse prompts that the project is not clean
, You only need to enter the source code tree directory under xterm and enter make
Mrproper. Note that the time it takes to compile the kernel depends on the number of options you enable. Therefore, when you enable menuconfig, remove unnecessary options as much as possible.
Shorten the time required to compile the kernel.
...
Compile the kernel. At/home/XXX/linux-2.6.28-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.28-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.28-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.
Follow
Go back to eclipse. In this case, choose run> debug deployments 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 side of the page. Then, select Linux-kernel in the project column.
, Fill in/home/XXX/linux-2.6.28-obj/vmlinux in the following C/C ++ application, as shown in:
However
Click the debugger option page to change the debugger to gdbserver debugger. Stop on startup
Change start_kernel to "type" on the connection suboption page to "TCP" and change "port number" to "1234", as shown in the following figure:
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:
I don't need to say much about what to look at registers and variables. Enjoy kernel debugging!
Learn moreC Language: Http://blog.csdn.net/bigloomy/article/category/841361