Home > Article > System Tutorial > What are the tools and methods for understanding the source code reading and editing of Linux kernel development?
Developing embedded Linux products often requires tailoring and customizing the kernel to meet the functional and performance requirements of embedded products. This article introduces several tools and techniques for reading Linux kernel source code.
The "Linux kernel development" mentioned here only refers to the kernel and driver-related development work in embedded Linux product development, which is very different from the kernel development of the kernel development team led by Linux.
As the old saying goes, "If you want to do your job well, you must first sharpen your tools." Faced with several gigabytes of Linux kernel code, it is necessary to read, view or search the code. Most people who come into contact with Linux kernel code for the first time Developers all feel like they don’t know where to start. Several source code reading and indexing tools are recommended below, which can provide some convenience for subsequent kernel development.
1、SourceInsight
SourceInsight is a very popular source code reading and editing tool under the Windows platform. Many Linux developers are still accustomed to editing source code under Windows, and even viewing and editing Linux kernel source code are still done in SourceInsight.
Note: SourceInsight is a copyrighted software and you need to solve copyright issues by yourself.
After installing SourceInsight software, create a new project, name it and specify the data storage location, as shown in Figure 1.1.
Figure 1.1 New Project
Click the OK button to enter the project setting interface, as shown in Figure 1.2.
Figure 1.2 Project Settings
Add source code after. After browsing and selecting the Linux kernel source code folder, click the "AddTree" button to add all the files of the kernel source code tree to the project, as shown in Figure 1.3.
Figure 1.3 Adding kernel source code
After the addition is completed, the source code can be read and edited in SourceInsight, as shown in Figure 1.4.
Figure 1.4 Reading source code in SourceInsight
2、Eclipse
Eclipse is a cross-platform IDE that can run on both the Windows platform and Linux. Many developers who are accustomed to graphical interface operations are accustomed to using Eclipse to view and edit Linux source code under Linux.
If you are just viewing the Linux kernel source code in Eclipse, you do not need to install the cross-compiler in advance, otherwise you must install the cross-compiler in advance.
Create a kernel source code project. Click FileàNewàProject to start creating the project, and select Create C Project in the project creation interface, as shown in Figure 1.5.
Figure 1.5 Creating C Project
Click Nextlinux driver download, fill in the project name in the Projectname column of the CProject interface, remove the "Usedefaultlocation" checkbox, and click Browse to set the Location to the Linux kernel source code directory linux kernel code reading tool, as shown in the figure As shown in 1.6. If you do not compile the kernel in Eclipse, you can use LinuxGCC. Otherwise, please use the installed CrossGCC.
Figure 1.6 Exporting Linux kernel source code
Then click Finish to complete the Linux kernel source code export, and the code can be read and edited in Eclipse, as shown in Figure 1.7.
Figure 1.7 Browsing the kernel source code in Eclipse
To perform source code tracking in Eclipse, just select a function, variable or macro definition and press F3. More operations can be found in Navigate.
3.vim ctags cscope
Vi/Vim is a text editor that can efficiently implement code editing in Vim. But Vim's function is more than just a text editor. Using the cooperation of ctags and cscope, Vim can realize source code editing and reading functions that can be called a graphical IDE environment. To some extent, it is even more convenient than a graphical IDE.
The installation of Vi/Vim is no longer introduced. If you are not working on the remote server through remote login, but on the local desktop system, you can also use gvim to start the Vi editor.
lTaglist
Taglist is a source code browsing plug-in for Vim, which can be obtained from the website. After downloading the compressed package, decompress it locally, and then copy the plugin directory in the decompressed directory to the ~/.vim directory. If there is no .vim directory in the host directory, just create such a directory.
lCtags
Ctags is a software used to form tags files. You can download the source code for compilation and installation. Under Ubuntu, it can be installed through apt-get:
$sudoapt-getinstallexuberant-ctags
lSource code reading and tracking
Go into the directory where the source code you intend to view is located, and first generate the tags file:
$ctags-R
The execution time depends on the number of source codes. After execution, a tags file will be visible in the current directory. The more source code, the longer the execution time, and the larger the tags file formed.
Note: If the source code is changed and the code line number changes, the tags file needs to be regenerated.
(1) View the definitions of functions and so on. Open a C file with Vi/Vim. If you know where a function, variable, structure or macro definition is defined, first place the cursor on the function (variable, structure or macro definition) and then press CTRL]. After viewing, press CTRL o to return to the original location.
(2) View the file function list. After opening the C file, enter: TlistToggle in the command state of Vi/Vim (command input in Vi/Vim supports completion), and a function list sidebar will appear on the right side of Vi/Vim, as shown in Figure 1.8. Press CTRL ww (w twice) to switch between list and code viewing.
Figure 1.8 Vi/Vim function list sidebar
If you use Gvim to open the C file on the local desktop, it will be closer to the IDE integrated environment. Double-click the function with the keyboard to jump to the place where the function is defined, and right-click the CTRL mouse to move back to the original location. More practical features need to be experienced in actual operation.
4、LXR
LXR is the abbreviation of LinuxCrossReferencer. It is a popular Linux source code viewing tool. In fact, it is not limited to viewing Linux source code. The download address of LXR is:, refer to the installation instructions of the website linux kernel code reading tool, it is easy to build a local LXR on this machine for source code viewing.
If you don’t want to build a local LXR, you can directly browse the LXR website that has already been set up. Two websites are recommended: one is the Linux source code online reading provided by the open source Chinese website, and the other is the website. The latter is faster and provides The Linux kernel has fewer versions, while the former offers more versions. The website provides source code reading, keyword search and free text search functions. The web page snapshots of the two are shown in Figure 1.9 and Figure 1.10 respectively.
Figure 1.9 Web page snapshot
Figure 1.10 Web page snapshot
The above is the detailed content of What are the tools and methods for understanding the source code reading and editing of Linux kernel development?. For more information, please follow other related articles on the PHP Chinese website!