Design and implementation of code debugger

By designing a code debugger, a compilation intermediate code and runtime library containing debugging information is generated, and the program running process is recorded and output, which solves the complex operation of existing methods and achieves the effect of quickly understanding and positioning code problems.

CN120407377APending Publication Date: 2025-08-01王坦
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510473617.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-15
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

Existing code debugging methods such as single-step debugger and inserting code output log information methods are complex and inefficient, making it difficult to quickly understand program running processes or positioning problems.

Method used

Design a code debugger to generate compiled intermediate code containing debugging information through a customized code compiler, generate executable files in combination with the runtime library, record and output program running process information, and render the graphical interface on the front end.

Benefits of technology

It provides a simple and intuitive graphical interface and rich interactive functions, so users can quickly understand the program running principles or positioning problems and avoid complex operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407377A_ABST
    Figure CN120407377A_ABST
Patent Text Reader

Abstract

The invention discloses design and implementation of a code debugger, and relates to the technical field of code debuggers, which comprises the following steps of: 1, compiling a code of a user through a customized code compiler to generate a compiled intermediate code containing specific debugging information and a record statement; 2, linking the compiling intermediate code and the runtime library to generate an executable file containing specific debugging information, a record statement and a runtime function; step 3, running the executable file to obtain information of a running process; 4, reading the running process information according to the debugging information to obtain readable running process information; 5, the readable operation process information is sent to the front end; step 6, rendering a graphical interface by the front end so as to provide a simple and visual graphical interface and rich interaction functions; by using the debugger, a user can quickly understand the running principle of the whole program or quickly locate problems in codes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of code debuggers, and specifically relates to the design and implementation of a code debugger. Background Art

[0002] When software developers need to view the internal running process of a program (such as when a program has a bug or when they need to understand code written by others), generally the following two methods are used:

[0003] The first method is to use commonly used single-step debuggers (such as gdb, lldb, etc.). However, single-step debuggers require troublesome and complex operations to locate the code that needs to be viewed. If the position that needs to be viewed is missed, it is necessary to start from the beginning.

[0004] The second method is to insert code to output log information (also called logging). However, the information that can be obtained is less, and the program needs to be recompiled. If the inserted code is not sufficient to find the key problem, it is necessary to continue inserting code and recompiling.

[0005] The above two commonly used methods are both troublesome and inefficient. If it is necessary to understand the entire running process of the program (for example, when understanding code written by others), a large amount of time is required.

[0006] Therefore, in view of this, the present invention proposes a design and implementation of a code debugger to make up for and improve the deficiencies of the existing technology. Summary of the Invention

[0007] To solve the above technical problems, the present invention provides a design and implementation of a code debugger, which can output the complete running process of a program, and does not require a complex operation process. By using this debugger, users can quickly understand the running principle of the entire program or quickly locate problems in the code.

[0008] To achieve the above object, the technical solution adopted by the present invention is as follows: A design and implementation of a code debugger includes the following steps:

[0009] Step 1: Compile the user's code through a customized code compiler to generate a compiled intermediate code containing specific debugging information and recording statements;

[0010] Step 2: Link the compiled intermediate code with the runtime library to generate an executable file containing specific debugging information, recording statements, and runtime functions;

[0011] Step 3: Run the executable file to obtain information about the running process;

[0012] Step 4: Read the running process information according to the debugging information to obtain readable running process information;

[0013] Step Five: Send the readable running process information to the front end;

[0014] Step Six: The front end renders the graphical interface.

[0015] Preferably, during the process of the customized code compiler compiling the user's code in Step One, the following operations are added:

[0016] S101: Write the information of each function, including type, name, location, and address, into the compilation intermediate code;

[0017] S102: Generate a packArgs function for recording parameter values and a packRet function for recording return values for each function;

[0018] S103: Replace the function call statement, change the function call to call cal lFrame, and pass the function information and packArgs, packRet to the call of the cal lFrame function.

[0019] Preferably, the runtime library is a dynamic link library or a static link library. When the program is linked, the runtime library is linked with the executable file, and the runtime library contains the definition of cal lFrame;

[0020] Among them, the cal lFrame function creates a frame structure for each function call, saves the information of the function call, including the information of the call statement, the frame id of the caller, the frame ids of all called functions, the saved parameter values and return values, the start and end times, and the address in the runtime stack.

[0021] Preferably, when the executable file containing debugging information runs in the runtime system in Step Three, callFrame is called, and among them, cal lFrame calls packArgs and packRet.

[0022] Preferably, during the process of the customized code compiler compiling the user's code in Step One, the following operations are added:

[0023] S201: Write the information of each assignment statement, including type, location, and address, into the compilation intermediate code;

[0024] S202: Replace each assignment statement with a call statement of the logWrite function, and pass the information of the assignment statement to the call of the logWrite function, where the logWrite function is a function defined in the runtime library and is used to actually execute the assignment statement and record the execution of the assignment statement.

[0025] Preferably, when the executable file containing debugging information runs in the runtime system in step 3, logWrite is called.

[0026] Preferably, when the running process information in step 4 is queried, readable running process information is obtained based on the parameter values from the restored memory or function and the type information saved during compilation, and is passed to the front end.

[0027] Preferably, the readable running process information in step 5 is transmitted to the front end using a data transmission method, and the following operations are performed:

[0028] According to the preset data transmission method, the information generated during compilation and runtime and the information of the project are sent to the front end;

[0029] Among them, the information generated during compilation includes the type information and location information of functions and variables;

[0030] The information generated during runtime includes values and time.

[0031] Preferably, the front end obtains the required information from the runtime library and performs the following operations:

[0032] S301. Set up an editing area to display the code of the project, or use the editing area in the integrated development environment. Users can obtain the information under the current cursor by moving the cursor or switching files;

[0033] S302. Set up a details area to display the detailed information under the current cursor, including the information of the function call frame and the values in the memory;

[0034] Among them, the information of the function call frame includes parameter values and return values;

[0035] S303. Set up a view area. Through the interaction of the view, users can view and jump to specific frames, functions, and statements.

[0036] Preferably, the view area includes a stack view, and the stack view includes the stack of the frame currently viewed by the user and the called frames.

[0037] Compared with the prior art, the beneficial effects of the present invention are:

[0038] By generating an executable file containing debugging information from the user's code through a customized code compiler, running it in the runtime system, obtaining information about the entire running process, reading the running process information based on type information to get readable running process information, and directly outputting the readable running process information to a text interface, or sending the running process information to the front end and rendering a graphical interface, a more concise and intuitive graphical interface and rich interaction functions can be provided. Furthermore, the complete running process of the program can be output without a complex operation process. By using this debugger, users can quickly understand the running principle of the entire program or quickly locate problems in the code. Description of the Drawings

[0039] Figure 1 It is a flowchart of the code debugger shown in the present invention. Detailed Implementation Manner

[0040] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0041] Embodiments of the present invention:

[0042] Please refer to Figure 1 As shown, the design and implementation of a code debugger includes the following steps:

[0043] Step 1: Compile the user's code through a customized code compiler to generate a compilation intermediate code containing specific debugging information and recording statements;

[0044] Step 2: Link the compilation intermediate code with the runtime library to generate an executable file containing specific debugging information, recording statements, and runtime functions;

[0045] Step 3: Run the executable file to obtain running process information (which can be to save the entire running process or only save part of the process);

[0046] Step 4: Read the running process information according to the debugging information to obtain readable running process information;

[0047] Step 5: Transmit the readable running process information to the front end using a data transmission method (such as the http protocol);

[0048] Step 6: The front end renders a graphical interface for the user according to the readable running process information.

[0049] During the process of compiling the user's code by the customized code compiler in Step 1, the following operations are performed:

[0050] S101. Write the information of each function, including type, name, location, and address, into the compilation intermediate code;

[0051] S102. Generate a packArgs function for recording parameter values and a packRet function for recording return values for each function;

[0052] S103. Replace the function call statement, change the function call to call callFrame, and pass the function information and packArgs, packRet to the call of the callFrame function.

[0053] For example, in the intermediate code, the call statement is:

[0054] call foo(5)

[0055] It needs to be replaced with:

[0056] store CallExpr.foo, CurCallExpr

[0057] call callFrame(5)

[0058] Among them, CallExpr.foo contains the information of the foo(5) statement (including type, location, called function address, etc.), save CallExpr.foo to CurCallExpr,

[0059] CurCallExpr is a global variable,

[0060] callFrame is a function defined in the runtime library,

[0061] callFrame reads the information in CurCallExpr, creates a frame (i.e., a frame for saving the information when a function is called),

[0062] then uses the packArgs function to record the parameter values, then calls the foo function, and finally uses the packRet function to record the return values;

[0063] Replace each assignment statement with a call statement of the logWrite function, and pass the information of the assignment statement to the call of the logWrite function, where the logWrite function is a function defined in the runtime library and is used to actually execute the assignment statement and record the execution of the assignment statement;

[0064] For example, replace the statement "store 5,n" with:

[0065] call logWrite(n,5).

[0066] logWrite creates a writeEvent for each execution of an assignment statement. The writeEvent contains the execution information of the assignment statement, including the memory address, the value written, the time, and the information of the assignment statement. When the user queries, the value of the memory at that time is found and restored through the memory address and time.

[0067] The linker mainly adds the following functions: integrating the information of each compilation unit.

[0068] The runtime library is a dynamic link library or a static link library. When the program is linked, the runtime library is linked with the executable file. The runtime library contains the definitions of callFrame and logWrite.

[0069] Among them, the callFrame function creates a frame structure for each function call, saves the function call information, including the information of the call statement, the frame id of the caller, the frame ids of all called functions, the saved parameter values and return values, the start and end times, and the address in the runtime stack.

[0070] When the executable file containing debugging information in step three runs in the runtime system, it calls callFrame and logWrite. Among them, callFrame calls packArgs and packRet.

[0071] When the running process information in step four is queried, according to the parameter values from the restored memory or function and the type information saved at compile time, readable running process information is obtained and passed to the front end.

[0072] In step five, the readable running process information is transmitted to the front end using any data transmission method (such as the http protocol).

[0073] Among them, the information generated at compile time includes the type information and location information generated by functions, variables, and memory.

[0074] The information generated at runtime includes values and times.

[0075] The information of the project includes code files and overall running information.

[0076] The front end obtains the required information from the runtime library and performs the following operations:

[0077] S301. Set up an editing area to display the code of the project, or use the editing area in the integrated development environment. The user can obtain the information under the current cursor by moving the cursor or switching files.

[0078] S302. Set up a details area to display the detailed information under the current cursor, including the information of the function call frame and the value of the memory.

[0079] Among them, the information of the function call frame includes parameter values and return values.

[0080] S303. Set up a view area. Through the interaction of the view, the user can view and jump to specific frames, functions, and statements.

[0081] In addition, the front end can be integrated into the IDE (Integrated Development Environment), place the view area and the details area on one side of the IDE, and use the editing area of the IDE.

[0082] The front end can interact with the IDE (for example, when moving the cursor in the editing area, the view area and the details area will display the function where the cursor is located, operating on the view area, and the editing area will automatically jump), and the user can use the front end in the familiar development environment.

[0083] To sum up, take the following program as an example:

[0084]

[0085] Compile the above code using a customized code compiler:

[0086] mtc test.c - o test

[0087] Run the program using a customized runtime system:

[0088] mindtrack -- dump --. / test

[0089] The following results can be output:

[0090]

[0091] The first two lines are the information output by the program itself, and the following are the program running processes output by the debugger. The program running process forms a tree according to the function call relationship. From this tree, the entire running process of the program can be seen.

[0092] Process represents the entire process and has 1 child node.

[0093] main is the main function.

[0094] First, printf("input:") is called and returns 7.

[0095] Then scanf(&"%d",&21845) was called, and it returned 1. Here, 21845 is the value of n before the scanf call (a random number).

[0096] Then fact(3) was called. fact made recursive calls and finally returned 6.

[0097] Finally, printf(&"result:%d\n",6) was called and it returned 10.

[0098] The main function returned 0, and Process also returned 0 (i.e., the status code of the process).

[0099] The entire running process of the whole program is clear at a glance.

[0100] If the program is large, too much information will be output using text output. Therefore, the HTTP protocol (or other communication protocols) can be used to send the running process to the front end, and the front end can provide a more concise and intuitive graphical interface and rich interactive functions.

[0101] By generating an executable file with debugging information from the user's code through a customized code compiler, running it in the runtime system according to the executable file, obtaining the information of the entire running process, reading the running process information according to the type information, getting the readable running process information, directly outputting the readable running process information to the text interface, or sending the running process information to the front end and rendering a graphical interface, thus providing a more concise and intuitive graphical interface and rich interactive functions, and then the complete running process of the program can be output, and no complex operation process is required. By using this debugger, users can quickly understand the running principle of the whole program or quickly locate problems in the code.

[0102] The settings of the sizes of the intervals and thresholds are for the convenience of comparison. Regarding the size of the threshold, it depends on the amount of sample data and the number of base quantities set by those skilled in the art for each group of sample data; as long as the proportional relationship between the parameters and the quantized values is not affected.

[0103] The above formulas are all dimensionless and only take their numerical calculations. The formula is a formula obtained by collecting a large amount of data and performing software simulation to get the closest to the real situation. The preset parameters in the formula are set by those skilled in the art according to the actual situation.

[0104] In the two embodiments provided in the present application, it should be understood that the disclosed devices and systems can be implemented in other ways; for example, the device embodiments described above are merely illustrative. For example, the division of the modules is only a logical function division. In actual implementation, there may be other division methods. For example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed; another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of the devices or modules can be in electrical, mechanical or other forms;

[0105] The above is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention, according to the technical solution and inventive concept of the present invention, makes equivalent substitutions or changes, and should be covered within the protection scope of the present invention.

Claims

1. Design and implementation of a code debugger, characterized in that It includes the following steps: Step 1: Compile the user's code through a customized code compiler to generate intermediate compiled code containing specific debugging information and logging statements; Step 2: Link the intermediate compiled code with the runtime library to generate an executable file containing specific debugging information, logging statements, and runtime functions; Step 3: Run the executable file to obtain information about the running process; Step 4: Read the information about the running process based on the debugging information to obtain readable information about the running process; Step 5: Send the readable information about the running process to the front end; Step 6: The front end renders a graphical interface.

2. The design and implementation of a code debugger according to claim 1, characterized in that, During the process of compiling the user's code by the customized code compiler described in Step 1, the following operations are added: S101: Write the information of each function, including type, name, location, and address, into the intermediate compiled code; S102: Generate a packArgs function for recording parameter values and a packRet function for recording return values for each function; S103: Replace the function call statement, change the function call to a call to callFrame, and pass the function information and packArgs, packRet to the call of the callFrame function.

3. The design and implementation of a code debugger according to claim 2, characterized in that, The runtime library is a dynamic link library or a static link library. When the program is linked, the runtime library is linked with the executable file, and the runtime library contains the definition of callFrame; Among them, the callFrame function creates a frame structure for each function call, saves the information of the function call, including the information of the call statement, the frame id of the caller, the frame ids of all called functions, the saved parameter values and return values, the start and end times, and the address in the runtime stack.

4. The design and implementation of a code debugger according to claim 3, characterized in that, When the executable file containing debugging information described in Step 3 runs in the runtime system, it calls callFrame, where callFrame calls packArgs and packRet.

5. The design and implementation of a code debugger according to claim 4, characterized in that, During the process of compiling the user's code by the customized code compiler described in Step 1, the following operations are added: S201: Write the information of each assignment statement, including type, location, and address, into the intermediate compiled code; S202: Replace each assignment statement with a call statement of the logWrite function, and pass the information of the assignment statement to the call of the logWrite function, where the logWrite function is a function defined in the runtime library and is used to actually execute the assignment statement and record the execution of the assignment statement.

6. The design and implementation of a code debugger according to claim 5, characterized in that, When the executable file containing debugging information described in Step 3 runs in the runtime system, it calls logWrite.

7. The design and implementation of a code debugger according to claim 6, characterized in that, When querying the information about the running process described in Step 4, based on the parameter values from the restored memory or function and the type information saved during compilation, readable information about the running process is obtained.

8. The design and implementation of a code debugger according to claim 7, characterized in that, The readable information about the running process described in Step 5 is transmitted to the front end using a data transmission method and performs the following: Send the information generated during compilation and runtime and the information of the project to the front end according to the preset data transmission method; Among them, the information generated during compilation includes the type information and location information of functions and variables; The information generated during runtime includes values and time.

9. The design and implementation of a code debugger according to claim 8, characterized in that, The front end obtains the required information from the runtime library and performs the following operations: S301. Set up an editing area to display the code of the project, or use the editing area in the integrated development environment. The user can obtain the information under the current cursor by moving the cursor or switching files; S302. Set up a details area to display the detailed information under the current cursor, including the information of the function call frame and the value in memory; Among them, the information of the function call frame includes parameter values and return values; S303. Set up a view area. Through the interaction of the view, the user can view and jump to specific frames, functions, and statements.

10. The design and implementation of a code debugger according to claim 9, characterized in that, The view area includes a stack view, and the stack view includes the stack of the frame currently viewed by the user and the called frames.