Use Source Insight to read the Linux kernel source code

When developing the driver later, the functions used in the driver are all from the kernel, so you can first create the kernel's Source Insight project under Windows.

If you don't want to learn to drive development, you don't need to create a kernel project. However, when learning large apps in the future, you can also use Source Insight to read and write code. You can learn from the usage of Source Insight explained in this section.

7.4.1 Introduction to Source Insight

Source Insight is a source code editor produced by Source Dynamics. Source Insight provides syntax highlighting, code navigation and customizable keyboard shortcuts. It is not just an editor, but a tool for understanding large source code libraries, so it is called "program editor and analyzer". It is flexible and lightweight, and provides useful features such as relations, context, and symbol windows. When it is building a source code project, it builds an internal database of symbol information, so it can also display the reference tree, class inheritance diagram, and call tree. Its greatest benefit is to speed up the code understanding of unfamiliar projects.

Reference URL:

7.4.2 Unzip the kernel source code on Windows

After downloading the kernel in the previous "7.2 Using repo to download kernel and toolchain, etc.", the kernel was compressed under Ubuntu, and the compressed file was transferred back to Windows through FileZilla and decompressed.

When Windows decompresses the kernel, it will prompt some errors. It will prompt whether to overwrite the file. Just select "Overwrite". This is because files under Linux are case-sensitive, ac and Ac are different files, but under Windows, they are not case-sensitive, and these two files are the same. These errors will not affect our reading of the source code.

7.4.3 Building a project example

In this section, create a new source Insight project of the linux kernel. You can also create projects for other apps in the same way.

  1. Create a new project
    Run source Insight, click the menu "Project->New Project", as shown below:
    Insert picture description here

  2. Set the project name and project data directory
    . Set "New project name" (the name of the project) in the pop-up New Project dialog box, then set Where do you want to store the project data file? (project file save location), click the Browse button Just select the source directory.
    Insert picture description here

  3. Specify the source directory
    Set "Project Source Directory – the main location of your source files" (source directory), click "..." on the left side of the red box to select the source directory, click OK, as shown below:
    Insert picture description here

  4. Add source code
    In the new dialog box that pops up, click "Add" or "Add All". "Add" is to manually select the files to be added, and "Add All" is to add all files. We use "Add All", select "Recursively add lower subdirectories" in the pop-up prompt box and click OK. The same Remove File, Remove All is to remove a single file or remove all files, as shown in the figure below: After
    Insert picture description here
    adding files, click Close, and the interface will return to the main interface, as shown in the figure below, click "Close":
    Insert picture description here

  5. Synchronizing files
    Synchronizing files means to let Source Insight parse the source code and generate a database, which helps to read the source code in the future. For example, when you click on a function, you can quickly jump to where it is defined.

First click the menu "Project->Synchronize Files", as shown in the following figure:
Insert picture description here
In the pop-up dialog box, select "Force all files to be re-parsed", and click the "Start" button to start synchronization, as follows The picture shows:
Insert picture description here

7.4.4 Operation example

  1. Open the project
    After the project suggested above, the project will be opened automatically. If you want to open the project next time, after starting Source Insight, click on the menu "Project -> Open Porject" to select the previously created project in a list, as shown below:
    Insert picture description here
  2. Open the file in the project
    Click the "P" icon to open the file list, double-click the file to open the file, or enter the file name to find the file, as shown in the following figure:
    Insert picture description here
  3. View the definition of a function or variable in the
    file After opening the file, while holding down the ctrl key, click the function or variable with the mouse to jump to the position where it was defined, as shown in the following figure:
    Insert picture description here
  4. Find the reference of a function or variable
    Double-click the function, right-click the pop-up dialog box and select "Lookup Reference"; or after double-clicking the function, use the shortcut key "ctrl+/" to find the reference, as shown below:
    Insert picture description here
  5. Other shortcut keys
hot key Description
Alt + , Back
Alt + . go ahead
F8 Highlight selected characters
Ctrl+F Find
F3 or Shift+F3 Look forward
F4 or Shift+F4 Look back

Full text download: Second Edition of the Complete Manual for Embedded Linux System Development

Technology Exchange Group (
Hongmeng Development/Linux/Embedded/Driver/Data Download) QQ Group: 869222007

Guess you like

Origin blog.csdn.net/thisway_diy/article/details/108746072