Home System Tutorial LINUX What are the tools and methods for understanding the source code reading and editing of Linux kernel development?

What are the tools and methods for understanding the source code reading and editing of Linux kernel development?

Jan 26, 2024 pm 10:42 PM
linux kernel Source code reading

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

linux内核源码在线阅读_linux内核代码在线_linux 内核代码阅读工具

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Exploring the functions of the Linux kernel: a detailed introduction to the five major parts Exploring the functions of the Linux kernel: a detailed introduction to the five major parts Mar 21, 2024 am 09:57 AM

As the core part of the operating system, the Linux kernel is responsible for important functions such as managing hardware resources and providing system calls. This article will delve into the five major parts of the Linux kernel, including process management, file system, network communication, device driver and memory management, and provide a detailed introduction and code examples. 1. Process Management Process Creation In the Linux kernel, process creation is implemented through the fork() system call. Here is a simple example code: #include

Practical combat | RISC-V Linux entry address 2M reserved memory optimization Practical combat | RISC-V Linux entry address 2M reserved memory optimization Aug 01, 2023 pm 03:37 PM

The previous article analyzed the page table creation for RISC-V Linux startup. It was mentioned that the RISC-V Linux entry address must be 2M aligned. Today I will talk about how to solve the 2M alignment problem, or how to optimize part of the memory.

Is non-MMU support provided by the uClinux port of the Linux kernel? Is non-MMU support provided by the uClinux port of the Linux kernel? Jan 26, 2024 pm 05:18 PM

It’s long and has a lot of technical content, so click to follow it and you won’t get lost. Preface: Understanding the Linux Kernel A computer system is a symbiosis of hardware and software. They are interdependent and inseparable. Computer hardware Linux kernel transplantation steps include peripheral devices, processors, memory, hard drives and other electronic devices that make up the computer cylinder. And without software to operate and control it, it cannot work by itself. The software that completes this control work is called the operating system. In Linux terminology, it is called the "kernel" or "core". The main modules (or components) of the Linux kernel are divided into the following parts: storage management, CPU and process management, file system, device management and driver, network communication Linux forum, and system

Secret tips for Linux kernel TCP protocol stack optimization revealed Secret tips for Linux kernel TCP protocol stack optimization revealed Jan 28, 2024 am 09:39 AM

Hello dear readers! Here, I am honored to share with you the valuable experience and skills I have accumulated as a senior network engineer with my professional skills in the development and optimization of the Linux kernel TCP protocol stack. I believe that through this article, we can learn from each other and discuss it, and bring practical and useful reference materials to you who have a strong interest in this field or are currently working on it. 1. TCP connection establishment TCP connection establishment is a key transaction of the TCP protocol stack, but it is not uncommon to face many connection problems. After careful consideration and detailed debugging, I discovered some common and practical problems and their solutions, including preventing SYN flooding attacks (by adjusting system parameters) and dealing with network congestion (that is, using TCPFastOp

Linux Kernel: Revealing the Hidden BOSS of Computer Operating Systems Linux Kernel: Revealing the Hidden BOSS of Computer Operating Systems Mar 24, 2024 am 09:10 AM

Discusses the view that the Linux kernel plays an important role in computer operating systems. Linux kernel design and implementation. Through in-depth analysis of Linux kernel design and practical applications, it reveals its prominent position and influence in this field. 1. Optimized memory management By using virtual memory management technology, the Linux kernel can efficiently complete memory allocation and recycling. With the help of the replacement page algorithm, the Linux kernel is designed and implemented to accurately handle the mapping relationship between physical memory and virtual memory. Flexible adjustments can be made based on the specific needs of the application, thereby improving overall system performance. 2. The powerful process management kernel uses its excellent multi-tasking technology to enable multiple processes to coexist harmoniously in a single system. Carefully formulated

An in-depth exploration of the Linux kernel source code distribution An in-depth exploration of the Linux kernel source code distribution Mar 15, 2024 am 10:21 AM

This is a 1500-word article that explores the Linux kernel source code distribution in depth. Due to limited space, we will focus on the organizational structure of the Linux kernel source code and provide some specific code examples to help readers better understand. The Linux kernel is an open source operating system kernel whose source code is hosted on GitHub. The entire Linux kernel source code distribution is very large, containing hundreds of thousands of lines of code, involving multiple different subsystems and modules. To gain a deeper understanding of the Linux kernel source code

Explore the relationship between the Android system and the Linux kernel Explore the relationship between the Android system and the Linux kernel Mar 14, 2024 pm 12:48 PM

The Android system and the Linux kernel are two closely related entities, and the relationship between them is close and complex. In the Android system, the Linux kernel plays an important role, providing underlying hardware drivers and system call support for the Android system. This article will explore the relationship between the Android system and the Linux kernel, how they interact and work together, and provide some specific code examples. Android is a mobile operating system developed based on the Linux kernel and is mainly used for mobile devices such as smartphones and tablets. L

Do you really know how to debug Linux kernel failures? You will be enlightened after reading this article! Do you really know how to debug Linux kernel failures? You will be enlightened after reading this article! Aug 03, 2023 pm 04:50 PM

The Linux kernel is the core of the operating system and controls access to system resources such as the CPU, I/O devices, physical memory, and file systems. During the boot process and while the system is running, the kernel writes various messages to the kernel ring buffer. These messages include a variety of information about system operations.

See all articles