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:
- Official website homepage https://www.sourceinsight.com/
- Software download page https://www.sourceinsight.com/trial/
- User guide https://www.sourceinsight.com/doc/v4/userguide/index.html
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.
-
Create a new project
Run source Insight, click the menu "Project->New Project", as shown below:
-
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.
-
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:
-
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
adding files, click Close, and the interface will return to the main interface, as shown in the figure below, click "Close":
-
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:
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:
7.4.4 Operation example
- 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:
- 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:
- 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:
- 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:
- 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