View edit source code with Source Insight

content

1. Introduction to Source Insight

2. Create a Source Insight project and add the reactos project file to the project

3. Use Source Insight to view the code

3.1. View the internal implementation of an interface in reactos

3.2. View the internal implementation of the regsvr32 program through the .c source file corresponding to the regsvr32 program

4. Finally


       Sometimes we need to view the open source code of some large projects, but these open source projects do not support the use of our daily IDE development tools to open, which tool should we choose to view the source code? The Source Insight tool is definitely a good choice. In this article, we will introduce how to use the Source Insight tool to view and edit the source code.

1. Introduction to Source Insight

       Source Insight is one of the most concise and powerful lightweight code browser editors. It is quick to start and easy to use. Many programmers should have used it! It supports almost all languages, such as C, C++, ASM assembly, HTML, etc., can create and maintain its high-performance symbol database, including functions, variables, structures, classes and other symbols, especially for reading the code of large engineering projects. convenient. However, Source Insight is just a code browser editor and does not include a compiler, so there is no ability to compile code.
       This article takes viewing the source code of the reactos open source operating system as an example to introduce how to use the Source Insight editor.

2. Create a Source Insight project and add the reactos project file to the project

Click Project->New Project        in the menu bar to initiate the creation of the project. Enter the project name reactos-2 in the pop-up window, as shown below:

Click OK to enter the project configuration page. In the configuration page, set the directory of the reactos source code, and check the "store function-local symbols in database" option , as shown below:

After checking this option, Source Insight will automatically save symbols such as functions and variables to the database, and you can continue to use them the next time you open the project.
       Click OK to enter the "Add and Remove Project Files" page :

On this page, the source code directory selected in the previous step will be selected by default. Click the "Add Tree" button on the right to add all files in the project directory to the reactos-2 project.

       If there are many files in the project directory, a progress bar for adding files will be displayed:

Source Insight builds a symbol database through the symbol information in these added files to facilitate code reference. Click the Close button to complete the creation of the project.

       Each time Source Insight is started, it will open the last opened project by default. If you have created multiple projects and want to view another project, you can click Project->Close Project to close the currently opened project, and then click Project->Open Project to open another project to view.

3. Use Source Insight to view the code

       Before viewing the code, you can click the "Project Symbol List" button on the right:

Display the function symbols in all files in the project to the list, so as to facilitate searching and viewing in the list. If there are many files in the project directory, this process will be slower, and a progress bar will also be displayed:

Just wait until it finishes searching.

3.1. View the internal implementation of an interface in reactos

       Suppose we now have a look at the internal implementation of the SetUnhandledExceptionFilter function, we can click the following button in the toolbar:

Enter SetUnhandledExceptionFilter in the pop-up window, and then click the Search button to search, and the following results are found:

 Find any entry in the search results, click the toggle button on the left , and jump to the corresponding file and line number of the code:

Click the toggle button on the left in the source code to switch back to the search list.

       Then left-click on the SetUnhandledExceptionFilter function, and the view below will automatically jump to the implementation code inside the SetUnhandledExceptionFilter function:


Double-click the view showing the internal implementation of SetUnhandledExceptionFilter to jump to the internal implementation of the SetUnhandledExceptionFilter function:

So through the above method, we can check the internal implementation of any interface in the system library, and the implementation in reactos is very similar to the implementation of the Windows NT kernel, so by looking at the code in reactos, we can roughly see that Windows Some internal implementation of the system.

3.2. View the internal implementation of the regsvr32 program through the .c source file corresponding to the regsvr32 program

        Previously, we encountered the problem of failure to load the dll control library when registering the control in the installation package. Manually using regsvr32 can manually load and register successfully in the cmd window of Windows, so I want to see how the dll control library is loaded in the regsvr32 program. And how to register controls with the system.

       The regsvr32 program is an independent exe. It has an independent main function and a corresponding .c source file, so click the "Project File List" button on the right :

Switch to the file list page, and then try to enter the regsvr32 keyword in the search box above, and it turns out that the regsvr32.c source file is really found :

Double-click to enter the regsvr32.c source file, find the main function _tWinMain of the regsvr32 program , continue to look down the internal implementation of the _tWinMain function, and see two key points:

One is to call the LoadLibraryEx function to load the dll library, and the LOAD_WITH_ALTERED_SEARCH_PATH parameter is passed in; the other is to register the control with the system by obtaining the DllRegisterServer interface in the library.
       So later we changed the code to load the library from LoadLibrary to LoadLibraryEx (and passed in the LOAD_WITH_ALTERED_SEARCH_PATH parameter) to solve our problem.

4. Finally

       This article just briefly introduces how to create a project, and some details to pay attention to in the process of creating a project. The article also describes how to view the code, and gives two practical examples of viewing the code. This article only introduces some main points, which are for reference only, and more details need to be discovered by the readers themselves.

Guess you like

Origin blog.csdn.net/chenlycly/article/details/124347857