Compilation processing method and device, electronic equipment and readable storage medium

By inserting null instructions for the prologue module of the objective function in the Release mode of the compiler and replacing it with breakpoint instructions, the problem of difficulty in debugging and analysis in the Release mode is solved, the quality and efficiency of software development are improved, and the realization of the Release mode is realized. debugging function.

CN119127206APending Publication Date: 2024-12-13龙芯中科(合肥)技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411156716.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-21
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

During the software development process, there is a lack of debugging and analysis methods under the Release mode, which makes it difficult for technicians to locate and analyze problems, affecting the quality and efficiency of software development.

Method used

In the compiler's Release mode, insert a null instruction before the first instruction of the preamble module of the objective function, and detect whether it is a preset breakpoint function. If so, replace the null instruction with a breakpoint instruction or a specific function instruction to achieve Debugging analysis in Release mode.

Benefits of technology

By providing debugging and analysis methods in Release mode, the quality and efficiency of software development are improved, allowing technicians to accurately breakpoints and debug preset breakpoint functions in Release mode to obtain the data basis for the operation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127206A_ABST
    Figure CN119127206A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a compiling processing method and device, electronic equipment and a readable storage medium, the method is applied to a compiler, and the method comprises the steps that in the process of compiling a target application program in a release mode, a target function which is currently compiled is compiled; inserting a null instruction in front of the first instruction of the ordinal module of the objective function; detecting whether the target function is a preset breakpoint function; if it is determined that the target function is the preset breakpoint function, replacing the null instruction with a target instruction, so that the target instruction is executed first when the target function is operated; the target instruction comprises a breakpoint instruction or a specific function instruction; and compiling and running the target function according to the target instruction. According to the embodiment of the invention, a means for debugging and analyzing the objective function can be provided for technicians in the Release mode, so that the quality and efficiency of software development can be further improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a compiling processing method, device, electronic device and readable storage medium. Background Art

[0002] During software development, Debug mode and Release mode are two common working modes of the compiler. Debug mode contains a lot of debugging information, such as variable tracking information, detailed error reports, etc. This debugging information increases the workload of the compiler, resulting in a slower compilation process. When the program is running, this additional information also needs to be processed and stored, which in turn affects the speed of the program. In contrast, Release mode will perform more optimization processing during compilation, such as removing unnecessary debugging information, performing code optimization, etc., in order to improve the execution rate and efficiency of the program.

[0003] However, some exceptions only exist in Release mode and not in Debug mode. The lack of debugging and analysis methods in Release mode makes it difficult for technicians to locate and analyze problems, which in turn affects the quality and efficiency of software development. Summary of the invention

[0004] In view of the above problems, an embodiment of the present invention is proposed to provide a compilation processing method that overcomes the above problems or at least partially solves the above problems, which can provide technicians with a means of debugging and analyzing target functions in Release mode, thereby further improving the quality and efficiency of software development.

[0005] Correspondingly, the embodiment of the present invention also provides a compiling and processing device, an electronic device, and a computer program product to ensure the implementation and application of the above method.

[0006] In a first aspect, an embodiment of the present invention discloses a compilation processing method, which is applied to a compiler, and the method includes:

[0007] During the compilation of the target application in the release mode, for the currently compiled target function, inserting a null instruction before the first instruction of the prologue module of the target function;

[0008] Detecting whether the target function is a preset breakpoint function;

[0009] If it is determined that the target function is the preset breakpoint function, the empty instruction is replaced with a target instruction so that the target instruction is executed first when the target function is executed; the target instruction includes a breakpoint instruction or a specific function instruction;

[0010] The target function is compiled and executed according to the target instruction.

[0011] In a second aspect, an embodiment of the present invention discloses a compilation processing device, which is applied to a compiler, and the device includes:

[0012] An initialization module, used for inserting a null instruction before the first instruction of a prologue module of a currently compiled target function during the compilation of the target application in the release mode;

[0013] A function detection module, used to detect whether the target function is a preset breakpoint function;

[0014] an instruction optimization module, for replacing the empty instruction with a target instruction if it is determined that the target function is the preset breakpoint function, so that the target instruction is executed first when the target function is run; the target instruction includes a breakpoint instruction or a specific function instruction;

[0015] The compile and run module is used to compile and run the target function according to the target instruction.

[0016] In the third aspect, an embodiment of the present invention discloses an electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the steps of any of the compilation processing methods described above.

[0017] In a fourth aspect, an embodiment of the present invention discloses a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, it can implement any of the compilation processing methods described above.

[0018] In a fifth aspect, an embodiment of the present invention discloses a computer program product, including a computer program, wherein when the computer program is executed by a processor, the steps of the compilation processing method as described in any one of the above are performed.

[0019] The embodiments of the present invention include the following advantages:

[0020] The embodiment of the present invention optimizes the process of compiler compiling target application program in Release mode. In the process of compiler compiling target application program in Release mode, for the currently compiled target function, an empty instruction is inserted before the first instruction of the prologue module of the target function. The empty instruction, as a reserved instruction slot in the prologue module, can realize the placeholder function, so that it can be replaced with the target instruction when needed, and will not affect the normal execution of the original instruction in the prologue module of the target function. When the compiler detects that the target function is a preset breakpoint function, the empty instruction of the reserved instruction slot in the prologue module of the target function is replaced with the target instruction; the target instruction includes a breakpoint instruction or a specific function instruction. If the target instruction is a breakpoint instruction, when the target function is subsequently run, it will realize accurate breakpoint to the expected preset breakpoint function in Release mode, and debug the preset breakpoint function. If the target instruction is a specific function instruction, when the target function is subsequently run, it will trigger the return value of the specific function instruction to be executed, providing a data basis for analyzing the operation of the target function. Through the embodiments of the present invention, a means for debugging and analyzing a target function is provided to technical personnel in the Release mode, thereby further improving the quality and efficiency of software development. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 is a flowchart of a compiling method embodiment of the present invention;

[0022] Figure 2 is a flowchart of another compiling method embodiment of the present invention;

[0023] Figure 3 is a structural block diagram of an embodiment of a compiling and processing device of the present invention;

[0024] Figure 4 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0025] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0026] The terms "first", "second", etc. in the specification and claims of the present invention are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable when appropriate, so that the embodiments of the present invention can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, the term "and / or" in the specification and claims is used to describe the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. In the embodiments of the present invention, the term "multiple" refers to two or more, and other quantifiers are similar.

[0027] Reference Figure 1 , shows a flowchart of a compiling method embodiment of the present invention, the method is applied to a compiler, and the method may include the following steps:

[0028] Step 101: During the compilation of the target application in the release mode, for the currently compiled target function, insert a null instruction before the first instruction of the prologue module of the target function;

[0029] Step 102: Detect whether the target function is a preset breakpoint function;

[0030] Step 103: if it is determined that the target function is the preset breakpoint function, the empty instruction is replaced with a target instruction so that the target instruction is executed first when the target function is run; the target instruction includes a breakpoint instruction or a specific function instruction;

[0031] Step 104: compile and run the target function according to the target instruction.

[0032] The compilation processing method provided by the present invention can insert breakpoint instructions into the preset breakpoint function specified in the target application in the process of compiling the target application in the Release mode, so that the target application can be accurately broken to the expected preset breakpoint function when compiled in the Release mode, so that the preset breakpoint function can be debugged and analyzed. The embodiment of the present invention can provide a means for technicians to debug and analyze the target function in the Release mode, so as to further improve the quality and efficiency of software development.

[0033] Furthermore, the embodiments of the present invention can be applied to a console environment under a non-graphical operation interface such as a server, and the console environment is a console window development environment. The console environment does not have an integrated development tool (IDE), but only a program command line running window interface. When compiling an application in Release mode in a console environment, it is difficult for technicians to perform debugging and analysis, which increases the difficulty of developing applications. The embodiments of the present invention can provide a debugging and analysis means for Release mode in a console environment.

[0034] In a specific implementation, the compiler can be implemented by a virtual machine. Exemplarily, the virtual machine can be a Java Virtual Machine (JVM) or a .NET virtual machine (Common Language Runtime (CLR) of the .NET Framework). The Java virtual machine is the core part of the Java program, responsible for compiling the Java source code into executable bytecode and executing it. The .NET virtual machine is used to compile and run applications based on the .NET Framework.

[0035] In specific implementations, a function usually includes the following three parts after compilation: a prologue (Prolog) module, a function body, and an epilog (Epilog) module.

[0036] The prologue module and epilogue module are two fixed codes, which are generated by the compiler when compiling each function in the application. The compiler generates the prologue module code of each function at the beginning and the epilogue module code of each function at the end.

[0037] The prologue module and epilogue module each include their own instruction sequences, which are used to save and restore registers, manage the stack, and handle other tasks caused by function calls and returns.

[0038] The embodiment of the present invention optimizes the compilation process of the compiler. When the compiler compiles the target application in the release mode, for the currently compiled target function, a null instruction is inserted before the first instruction of the prologue module of the target function. That is, when the compiler compiles each function in the target application as the target function, when generating the prologue module for each function, a null instruction is inserted before the first instruction of the prologue module of each function, thereby setting a reserved instruction slot in the prologue module, so that when the current function is determined to be a preset breakpoint function, the null instruction can be replaced with the target instruction (such as a breakpoint instruction), thereby achieving accurate breakpoint to the desired preset breakpoint function during compilation and operation.

[0039] It should be noted that the reserved instruction slot is a newly added instruction slot set in the prologue module, which is located before the first instruction of the instruction sequence of the prologue module. Therefore, after the empty instruction inserted in the prologue module of the preset breakpoint function is replaced with the breakpoint instruction, when the compilation runs to the preset breakpoint function, the breakpoint instruction in the reserved instruction slot will be executed first, so that the execution of the preset breakpoint function can be suspended, and it will automatically stop at the breakpoint instruction for debugging and analysis. For non-preset breakpoint functions, there are empty instructions in the reserved instruction slot, which will not affect the execution of the original instructions of the non-preset breakpoint function.

[0040] In one example, for function functionA, when the compiler compiles to function functionA, it generates a prologue module PrologA for function functionA, assuming that PrologA includes the following instruction sequence: instruction 1, instruction 2, instruction 3. The compiler can insert an empty instruction before instruction 1. Thus, the prologue module PrologA of function functionA includes the following instruction sequence: empty instruction, instruction 1, instruction 2, instruction 3. Among them, the newly added empty instruction becomes a reserved instruction slot in the prologue module PrologA, which can be replaced by the target instruction later, and will not affect the execution of instruction 1, instruction 2, and instruction 3.

[0041] For function functionA, after compilation, the following three parts are obtained: the prologue module PrologA, the function body and the epilogue module.

[0042] Next, the compiler detects whether the currently compiled target function is a preset breakpoint function; if it is determined that the target function is a preset breakpoint function, the empty instruction of the reserved instruction slot in the prologue module of the target function is replaced with a target instruction; the target instruction may include a breakpoint instruction or a specific function instruction.

[0043] Taking the target instruction as a breakpoint instruction as an example, assuming that the target function currently compiled by the compiler is function A, assuming that the preset breakpoint function is function A, the compiler detects that the target function currently compiled is the preset breakpoint function, and replaces the empty instruction in the reserved instruction slot in the prologue module PrologA of function functionA with the breakpoint instruction. Therefore, the prologue module PrologA of function functionA includes the following instruction sequence: breakpoint instruction, instruction 1, instruction 2, instruction 3.

[0044] In a specific implementation, the instruction set of each architecture contains the machine code definition of the breakpoint instruction. During the process of compiling the target application, if the compiler detects that the target function being compiled is a preset breakpoint function, the machine code of the breakpoint instruction defined in the instruction set of the current architecture can be obtained and inserted into the preamble module of the target function.

[0045] In this way, during the subsequent compilation or running process, when function functionA is run, the breakpoint instruction therein will be triggered, thereby pausing the subsequent steps of instruction 1, instruction 2, instruction 3 and the function body of functionA, and the debugging state of the target function can be entered, so that the technician can debug and analyze the target function functionA.

[0046] In addition, the target instruction may also be a specific function instruction. The specific function instruction may be used to perform a specific function operation or set a specific mark. Exemplarily, the specific function instruction may be used to return the running status information of the target function during the debugging process; or, the specific function instruction may set a specific mark, through which the purpose of transmitting information may be achieved. The embodiment of the present invention does not limit the type of the specific function instruction.

[0047] The specific function instruction can be set according to actual needs. Exemplarily, the specific function instruction can be a register copy instruction. The register copy instruction is used to copy the value of a specified input parameter of the preset breakpoint function to a specified temporary register. In this way, no matter how this input parameter is circulated in other registers or stacks during the compilation process, the original value of the input parameter can be quickly read from the specified temporary register.

[0048] Furthermore, the embodiment of the present invention does not limit the number of preset breakpoint functions. The number of preset breakpoint functions may be greater than or equal to 1. When the number of preset breakpoint functions is greater than 1, target instructions may be inserted into the prologue modules of at least two preset breakpoint functions during the compilation of the target application, thereby implementing debugging and analysis of multiple functions.

[0049] In an example, assume that both function functionA and function functionB are preset breakpoint functions. When the compiler compiles to function functionA, it generates a prologue module PrologA for function functionA and inserts a null instruction before the first instruction of PrologA. The compiler detects that functionA is a preset breakpoint function, and replaces the null instruction inserted in PrologA with a breakpoint instruction. When the compiler compiles to function functionB, it generates a prologue module PrologB for function functionB and inserts a null instruction before the first instruction of PrologB. The compiler detects that functionB is a preset breakpoint function, and replaces the null instruction inserted in PrologB with a breakpoint instruction. In this way, when function functionA is subsequently run, the breakpoint instruction in function functionA will be triggered, and then the breakpoint instruction will be executed first to pause the running process of function functionA. When function functionB is run, the breakpoint instruction in function functionB will also be triggered, and then the breakpoint instruction will be executed first to pause the running process of function functionB.

[0050] It is understandable that the above examples take the target instruction as a breakpoint instruction. In a specific implementation, the target instruction may also be a specific function instruction. For example, in the above examples, for functionA and functionB, the empty instruction may be replaced with a specific function instruction, or the empty instruction in the prologue module PrologA of functionA may be replaced with a breakpoint instruction, and the empty instruction in the prologue module PrologB of functionB may be replaced with a specific function instruction, and so on.

[0051] In an optional embodiment of the present invention, the method may further include:

[0052] A breakpoint function detection module is set in the compiler, and corresponding first identifiers are set in the breakpoint function detection module according to at least one preset breakpoint function.

[0053] The breakpoint function detection module can be used to detect whether the currently compiled target function is a preset breakpoint function. The number of preset breakpoint functions preset in the breakpoint function detection module can be set according to actual needs.

[0054] The first identifier may be a function name of a preset breakpoint function or a hash identifier of a preset breakpoint function. Both the function name and the hash identifier of a function may uniquely identify the function, and there is a mapping relationship between the function name and the hash identifier of a function. The function name may be a string of characters. The hash identifier may be a string of numbers generated according to the function name.

[0055] In an optional embodiment of the present invention, the detecting whether the target function is a preset breakpoint function may include:

[0056] Obtaining a second identifier of the objective function;

[0057] The breakpoint function detection module is called according to the second identifier, and the second identifier is compared with the first identifier of each preset breakpoint function respectively. If there is a matching first identifier, it is determined that the target function is the preset breakpoint function.

[0058] In a specific implementation, the second identifier of the target function currently being compiled can be obtained according to the handle of the target function currently being compiled. The second identifier can be a function name or a hash identifier of the target function.

[0059] The breakpoint function detection module is called by taking the second identifier as a parameter, and the breakpoint function detection module can compare the second identifier with the first identifier of each preset breakpoint function preset in the breakpoint function detection module, and output a detection result of whether the target function is a preset breakpoint function. Specifically, if there is a first identifier matching the second identifier in the breakpoint function detection module, a detection result of determining that the target function is a preset breakpoint function is output; otherwise, if there is no first identifier matching the second identifier in the breakpoint function detection module, a detection result of determining that the target function is not a preset breakpoint function is output.

[0060] In one example, compMethodHnd is the handle of the target function currently being compiled. The second identifier of the target function can be obtained according to the handle through the function eeGetMethodFullName(). For example, by executing the function eeGetMethodFullName(compiler->info.compMethodHnd), the second identifier of the target function can be obtained.

[0061] For example, when executing the function eeGetMethodFullName (compiler->info.compMethodHnd), the function name of the target function is obtained as str1, and the function name of the preset breakpoint function is str2. The breakpoint function detection module detects whether str1 and str2 are consistent to determine whether the target function is the preset breakpoint function. If they are consistent, it is determined that the target function is the preset breakpoint function. If they are inconsistent, it is determined that the target function is not the preset breakpoint function.

[0062] For another example, when executing the function eeGetMethodFullName (compiler->info.compMethodHnd), the hash identifier of the target function is obtained as val1, and the hash identifier of the preset breakpoint function is val2. The breakpoint function detection module detects whether val1 and val2 are consistent to determine whether the target function is the preset breakpoint function. If they are consistent, it is determined that the target function is the preset breakpoint function. If they are inconsistent, it is determined that the target function is not the preset breakpoint function.

[0063] The embodiment of the present invention does not limit the method by which the breakpoint function detection module compares the first identifier and the second identifier. Exemplarily, the breakpoint function detection module can use the string comparison function strcmp(str1, str2) in the standard library to compare whether the first identifier and the second identifier are consistent, thereby determining whether the target function is a preset breakpoint function.

[0064] In an optional embodiment of the present invention, the method may further include:

[0065] If it is determined that the target function is not the preset breakpoint function, the null instruction inserted in the prologue module of the target function is kept unchanged.

[0066] In an embodiment of the present invention, if it is detected that the target function is a preset breakpoint function, the empty instruction of the reserved instruction slot in the prologue module of the target function is replaced with a breakpoint instruction or a specific function instruction, thereby providing a means of debugging or analyzing the preset breakpoint function. If it is detected that the target function is not a preset breakpoint function, the empty instruction of the reserved instruction slot in the prologue module of the target function is kept unchanged, which will not affect the normal execution of other instructions in the prologue module of the target function.

[0067] Furthermore, through the embodiment of the present invention, when the compiler compiles the target application, a null instruction can be inserted into the prologue module of each function. The null instruction can realize a placeholder function, and in the subsequent process of entering the preset breakpoint function for debugging and analysis, an operation space can be reserved for non-preset breakpoint functions.

[0068] For example, during debugging, the empty instruction in the reserved instruction slot in the preamble module of the specified non-preset breakpoint function can be replaced with a breakpoint instruction or a specific function instruction, thereby enabling debugging and analysis of the specified non-preset breakpoint function after entering the debugging state.

[0069] Exemplarily, after triggering the execution of the breakpoint instruction and entering the debugging state of the target function, during the debugging of the target function, it may jump to a non-preset breakpoint function. Since the reserved instruction slot in the prologue module of the non-preset breakpoint function is also an empty instruction, the empty instruction in the reserved instruction slot in the prologue module of the non-preset breakpoint function can be dynamically modified, such as replacing the empty instruction with a breakpoint instruction or a specific function instruction. The specific function instruction can be used to perform a specific function operation or set a specific mark. Exemplarily, the specific function instruction can return the running status information of the non-preset breakpoint function, such as the input parameter value of the non-preset breakpoint function; or, the specific function instruction can set a specific mark, and the purpose of transmitting information is achieved through the specific mark, so that the function level entered during the operation of the target application can be known through the specific mark, and the data basis is provided for analyzing the operation of the target application.

[0070] In an optional embodiment of the present invention, after entering the debugging state of the target function, the method further includes:

[0071] Save the disassembled instructions and corresponding address information generated during the debugging process to the log file;

[0072] By querying the log file, obtaining a memory address corresponding to a null instruction inserted in a prologue module of a specified non-preset breakpoint function;

[0073] The instruction code in the memory address is replaced with the instruction code of the target instruction.

[0074] Exemplarily, after entering the debugging state of the preset breakpoint function, a debugging tool such as GBD (GNU Debugger) can be used to execute the target application, and the disassembly instructions and corresponding address information can be output at the same time, and the output information can be redirected and saved in a log file. In this way, the empty instructions reserved in the prologue module of each non-preset breakpoint function and the memory address corresponding to the empty instructions can be viewed in the log file. By querying the log file, the memory address corresponding to the empty instruction inserted in the prologue module of the specified non-preset breakpoint function can be obtained, and then the instruction code stored in the memory address corresponding to the empty instruction inserted in the prologue module of the specified non-preset breakpoint function (i.e., the instruction code of the empty instruction) can be modified to the instruction code of the target instruction to be replaced. In this way, the empty instruction in the reserved instruction slot in the prologue module of the specified non-preset breakpoint function is replaced with a breakpoint instruction or a specific function instruction.

[0075] In an optional embodiment of the present invention, the target instruction is a breakpoint instruction, and after the empty instruction is replaced with the breakpoint instruction, the method may further include:

[0076] According to the compilation mode of the target application, triggering the execution of the breakpoint instruction to enter the debugging state of the target function; the compilation mode includes a just-in-time compilation mode or a pre-compilation mode;

[0077] After debugging is completed, the breakpoint instruction is replaced with a null instruction again, so that the breakpoint instruction is not executed when the target function is run again.

[0078] In specific implementations, the compilation mode of the target application is different, and the compilation and running process of the target application may also be different. Generally, the compilation mode of the application may include a Just-In-Time (JIT) mode or an AOT (Ahead-of-Time) pre-compilation mode.

[0079] Just-In-Time (JIT) mode refers to the compiler dynamically compiling the interpreted bytecode into native code while the program is running, and then executing the compiled code directly on the computer so that the program can run faster. JIT compilation is commonly used for interpreted languages ​​​​such as Python, RubyQ, and JavaScript. This compilation method can increase the execution speed of the program and does not require a pre-compilation process, so it can reduce the memory usage of the compiler.

[0080] Ahead-of-Time (AOT) means that the compiler compiles the source code into native code before the program runs so that the program can run faster. AOT compilation is commonly used for static programming languages, such as C, C++, and Java. In AOT compilation, the compiler compiles the source code into native code before the program runs and stores the compiled code on the computer. When the program runs, the program directly executes the compiled code. This compilation method can increase the execution speed of the program and does not require compilation at runtime, so it can reduce the startup time of the program.

[0081] In one example, it is assumed that the target application includes functions funcA, funcB, and funcC, wherein funcA calls funcB, and funcB calls funcC.

[0082] Assuming that the target application is compiled and run in Release mode, the program cannot usually be debugged in Release mode. The embodiment of the present invention inserts a breakpoint instruction in a preset breakpoint function in Release mode to implement the debugging function in Release mode. In Release mode, JIT compilation mode or AOT compilation mode can be further adopted.

[0083] In Release mode, if the target application uses JIT compilation mode, the target application is compiled while running. That is, when the actual execution of function funcA begins, function funcA is compiled in real time, and function funcA is run immediately after the compilation is completed. At this time, since function funcB and function funcC have not been executed yet, function funcB and function funcC have not been compiled into machine code executable by the local machine. During the running of function funcA, function funcA needs to call function funcB, and function funcB is compiled in real time, and function funcB is run immediately after the compilation is completed. During the running of function funcB, function funcB needs to call function funcC, and function funcC is compiled in real time, and function funcC is run immediately after the compilation is completed.

[0084] In Release mode, if the target application uses AOT compilation mode, all compilation work must be completed before running the target application, that is, functions funcA, funcB and funcC are compiled into machine codes that can be directly run by the local machine, and then the target application is run. No further compilation is required during the running process.

[0085] Through the embodiments of the present invention, the JIT compilation mode or the AOT compilation mode is adopted in the Release mode, which can provide means for debugging and analysis for technical personnel.

[0086] In the embodiment of the present invention, after the empty instruction of the reserved instruction slot in the prologue module of the target function is replaced with a breakpoint instruction, the timing of triggering the execution of the breakpoint instruction may be different depending on the compilation mode of the target application.

[0087] If the target function is a preset breakpoint function, after triggering the execution of the breakpoint instruction, the debugging state of the target function can be entered; after the debugging of the target function is completed, the breakpoint instruction of the reserved instruction slot in the prologue module of the target function is replaced with an empty instruction to restore the normal operation of the target function.

[0088] In an optional embodiment of the present invention, triggering the execution of the breakpoint instruction according to the compilation mode of the target application may include:

[0089] If the compilation mode is a just-in-time compilation mode, after the compilation of the target function is completed, the target function is run;

[0090] The breakpoint instruction is synchronously triggered to execute during the execution of the target function.

[0091] If the current compilation mode is JIT compilation mode, the target function will be run immediately after the target function is compiled. When the target function is run, the breakpoint instructions in the target function will be automatically triggered.

[0092] For example, in the above example, the target application includes functions funcA, funcB, and funcC. Assuming that the compilation mode is JIT compilation mode, the target function currently compiled is function funcA, and function funcA is a preset breakpoint function, then the reserved instruction slot in the prologue module of function funcA is the breakpoint instruction. After the compilation of function funcA is completed, function funcA is run immediately. When running function funcA, the breakpoint instruction in the prologue module will be executed first, and thus it will stop at the breakpoint instruction for debugging and analysis.

[0093] After the debugging of the target function is completed, the breakpoint instruction of the reserved instruction slot in the prologue module of the target function is replaced with an empty instruction, and then the subsequent compilation process is continued, such as continuing to compile the next function of the target function.

[0094] For example, after the debugging analysis of function funcA is completed, the breakpoint instruction in the reserved instruction slot in the prologue module of function funcA can be replaced with an empty instruction again, and then the subsequent compilation process can be continued, such as compiling function funcB when function funcB needs to be called. In the process of compiling function funcB, an empty instruction is inserted before the first instruction of the prologue module of funcB, and it is detected whether function funcB is a preset breakpoint function. The subsequent steps have been described in detail in the previous embodiment and will not be repeated here.

[0095] In an optional embodiment of the present invention, triggering the execution of the breakpoint instruction according to the compilation mode of the target application may include:

[0096] If the compilation mode is the pre-compilation mode, after the target function is compiled, the compilation process is continued until the target application is compiled, and a compilation result file is generated;

[0097] After replacing the compilation result file to the directory where the corresponding original file in the target application is located, restarting the target application, and automatically triggering the execution of the breakpoint instruction when running to the target function.

[0098] The original file refers to the source code file of the target application. The compiled result file refers to the executable file obtained after the target application is compiled.

[0099] If the current compilation mode is AOT compilation mode, after the target function is compiled, the subsequent compilation process needs to be continued until all functions of the target application are compiled and the compilation result file of the target application is generated. The compilation result file is replaced to the directory where the original file of the target application is located, that is, the original file of the target application is replaced with the compilation result file, and the target application is restarted to make the compilation result file effective. When the target function is run, the breakpoint instruction in the target function will be automatically triggered.

[0100] For example, in the above example, the target application includes functions funcA, funcB, and funcC. Assuming the compilation mode is AOT compilation mode, it is necessary to first complete the compilation of functions funcA, funcB, and funcC, and then run the target application in the form of an executable file or the like.

[0101] Assuming that funcA and funcB are preset breakpoint functions, and funcC is not a preset breakpoint function, after compilation is completed, the reserved instruction slot in the prologue module of funcA is a breakpoint instruction, the reserved instruction slot in the prologue module of funcB is a breakpoint instruction, and the reserved instruction slot in the prologue module of funcC is an empty instruction.

[0102] After all functions of the target application are compiled, the compilation result files are generated, including the compilation result files of funcA, funcB and funcC. The compilation result file of funcA is replaced to the directory where the original file corresponding to funcA in the target application is located. Similarly, the compilation result files of funcB and funcC are replaced. Then, the target application is restarted to make the compilation result files effective.

[0103] In the process of running the target application, the function funcA is run first. When running the function funcA, the breakpoint instruction therein will be executed first, and thus the program will stop at the breakpoint instruction for debugging and analysis.

[0104] After the debugging and analysis of function funcA is completed, the breakpoint instruction in the reserved instruction slot in the preamble module of function funcA can be replaced with an empty instruction again, and then the target application can continue to run. Next, when running function funcA, function funcB will be called. When running function funcB, the breakpoint instruction therein will be executed first, and thus it will stop at the breakpoint instruction for debugging and analysis.

[0105] After the debugging and analysis of function funcB is completed, the breakpoint instruction in the reserved instruction slot in the prologue module of function funcB can be replaced with an empty instruction again, and then the target application can continue to run. Next, when running function funcB, function funcC will be called. The reserved instruction slot in the prologue module of function funcC is an empty instruction, which does not affect the normal operation of function funcC, so function funcC runs normally.

[0106] Further, in an embodiment of the present invention, the compilation result file may be a compilation result file corresponding to the target application, or the compilation result file may be a compilation result file corresponding to a dynamic link library included in the target application.

[0107] In a specific implementation, if the target application has only one main function, and the main function is the preset breakpoint function, and the project name corresponding to the target application is assumed to be projectA, after projectA is compiled using the method of the present invention, the compiled result file obtained is projectA.dll. The projectA.dll can be used to replace the original file projectA.dll that is not compiled using the method of the present invention.

[0108] A Dynamic Link Library (DLL) is a module that contains functions and data that can be used by another module (application or DLL).

[0109] If the target application includes a dynamic link library, and if one or more functions in the dynamic link library need to be used as preset breakpoint functions, the target application needs to be pre-compiled using the method of the present invention, which includes compiling all functions and all dynamic link libraries included in the target application. After the target application is compiled, the compiled result file obtained includes the compiled result file of the dynamic link library, and the compiled result file of the dynamic link library needs to be replaced with the directory where the corresponding original file is located.

[0110] For example, the project name of the target application is projectB, and projectB needs to use the dynamic link library A.dll. A.dll contains multiple library functions. It is assumed that the library function funcA needs to be used as a preset breakpoint function. For ease of description, the A.dll contained in projectB before compiling using the method of the present invention is called the old A.dll. In the process of compiling projectB using the method of the present invention, when compiling to funcA, an empty instruction will be inserted before the first instruction of the prologue module of funcA, and if funcA is detected as a preset breakpoint function, the empty instruction in the prologue module of funcA will be replaced with a breakpoint instruction. After projectB is compiled, the compilation result file includes A.dll. The A.dll compiled using the method of the present invention is called the new A.dll. The new A.dll is different from the old A.dll, and the new A.dll has a breakpoint instruction inserted in the prologue module of funcA. In order to make the inserted breakpoint instruction effective, the new A.dll needs to be replaced with the corresponding position of the old A.dll in the project directory structure of projectB, that is, replace the new A.dll with the directory where the old A.dll is located in the target application, and then restart the target application to make the new A.dll effective. When the target application calls funcA in the new A.dll, the breakpoint instruction in funcA is automatically triggered to enter the debugging state of the target function funcA.

[0111] Reference Figure 2 , shows a flowchart of another compiling method embodiment of the present invention, comprising the following steps:

[0112] Step S201: setting a breakpoint function detection module in the prologue compilation processing module inside the compiler, and setting a first identifier of a preset breakpoint function in the breakpoint function detection module.

[0113] Step S202: In a console environment, a compiler is started through a command line to compile a target application in Release mode.

[0114] If the JIT compilation mode is used, the compiler will compile and run the target application at the same time. If the AOT compilation mode is used, the compiler will compile the target application first, and after all functions in the target application are compiled, a compilation result file will be generated. This compilation result file needs to be replaced in the directory where the original file of the target application is located, and it will take effect after restarting the operation.

[0115] Step S203, for the currently compiled target function, if JIT compilation is currently being performed or the first AOT compilation is being performed, execute step S204 to enter the next compilation process; otherwise, it means that the breakpoint instruction has been inserted, and execute step S213 to trigger the breakpoint instruction.

[0116] Step S204, entering the prologue compilation processing module inside the compiler, the prologue compilation processing module generates a prologue module for the target function, and inserts a null instruction before the first instruction of the prologue module.

[0117] Step S205: Obtain a second identifier of the target function according to the function handle stored in the compilation class where the target function currently being compiled is located. The obtained second identifier is used as an input parameter of the breakpoint function detection module.

[0118] Step S206, calling the breakpoint function detection module, and comparing the second identifier with the first identifier of each preset breakpoint function preset in the breakpoint function detection module through the breakpoint function detection module. If there is a matching first identifier, it is determined that the target function is a preset breakpoint function, and step S208 is executed; otherwise, it is determined that the target function is not a preset breakpoint function, and step S207 is executed.

[0119] Step S207, if the target function currently being compiled is not a preset breakpoint function, then the target function is compiled continuously and the process jumps to step S203 to compile the next function.

[0120] Step S208: If the target function currently being compiled is a preset breakpoint function, the empty instructions in the reserved instruction slots in the prologue module of the target function are replaced with breakpoint instructions.

[0121] Step S209, continue compiling the current target function.

[0122] Step S210, if the compilation mode currently adopted by the target application is the JIT compilation mode, jump to step S213; if the compilation mode currently adopted by the target application is the AOT compilation mode, execute step S211.

[0123] Step S211, if all functions of the target application have not been compiled, jump to step S203 to continue compiling the next function of the target application as the target function; if all functions of the target application have been compiled, execute step S212.

[0124] Step S212, after all functions of the target application have been compiled, the compiled result file is replaced to the directory where the corresponding original file is located, and the target application is restarted.

[0125] Step S213, running the target function, automatically triggering the execution breakpoint instruction, and entering the debugging state of the target function.

[0126] Step S214: If the debugging and analysis of the target function is not finished, return to step S203 to continue debugging. If the debugging and analysis of the target function is finished, execute step S215.

[0127] Step S215, modifying the breakpoint instruction replaced in the reserved instruction slot in step S208, and replacing it back with an empty instruction.

[0128] Step S216, end the operation.

[0129] In summary, the embodiment of the present invention optimizes the process of the compiler compiling the target application program in the Release mode. In the process of the compiler compiling the target application program in the Release mode, for the currently compiled target function, an empty instruction is inserted before the first instruction of the prologue module of the target function. The empty instruction, as a reserved instruction slot in the prologue module, can realize the placeholder function, so that it can be replaced with the target instruction when needed, and will not affect the normal execution of the original instruction in the prologue module of the target function. When the compiler detects that the target function is a preset breakpoint function, the empty instruction of the reserved instruction slot in the prologue module of the target function is replaced with a target instruction; the target instruction includes a breakpoint instruction or a specific function instruction. If the target instruction is a breakpoint instruction, when the target function is subsequently run, it will realize an accurate breakpoint to the expected preset breakpoint function in the Release mode, and debug the preset breakpoint function. If the target instruction is a specific function instruction, when the target function is subsequently run, it will trigger the return value of the specific function instruction to be executed, providing a data basis for analyzing the operation of the target function. Through the embodiments of the present invention, a means for debugging and analyzing a target function is provided to technical personnel in the Release mode, thereby further improving the quality and efficiency of software development.

[0130] Furthermore, through the embodiment of the present invention, during the process of the compiler compiling the target application, a null instruction can be inserted into the prologue module of each function. The null instruction can realize the placeholder function, and in the subsequent process of entering the preset breakpoint function for debugging and analysis, operation space is also reserved for non-preset breakpoint functions, thereby providing a wider range of debugging and analysis means in the Release mode, and also providing a feasible basis for the subsequent development of debugging and diagnostic tools in this scenario.

[0131] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0132] Reference Figure 3 , shows a structural block diagram of an embodiment of a compiling processing device of the present invention, the device is applied to a compiler, and the device may include:

[0133] The initialization module 301 is used to insert a null instruction before the first instruction of the prologue module of the target function currently compiled during the compilation of the target application in the release mode;

[0134] A function detection module 302 is used to detect whether the target function is a preset breakpoint function;

[0135] The instruction optimization module 303 is used for replacing the empty instruction with a target instruction if it is determined that the target function is the preset breakpoint function, so that the target instruction is executed first when the target function is run; the target instruction includes a breakpoint instruction or a specific function instruction;

[0136] The compiling and running module 304 is used to compile and run the target function according to the target instruction.

[0137] Optionally, the instruction optimization module is further configured to keep the empty instructions inserted in the prologue module of the target function unchanged if it is determined that the target function is not the preset breakpoint function.

[0138] Optionally, the target instruction is a breakpoint instruction, and the device further includes:

[0139] A breakpoint trigger module, used to trigger the execution of the breakpoint instruction and enter the debugging state of the target function according to the compilation mode of the target application; the compilation mode includes a just-in-time compilation mode or a pre-compilation mode;

[0140] The instruction recovery module is used to replace the breakpoint instruction with a null instruction again after debugging is completed, so that the breakpoint instruction is not executed when the target function is run again.

[0141] Optionally, the breakpoint triggering module is specifically used to run the target function after the target function is compiled if the compilation mode is the just-in-time compilation mode; and synchronously trigger the execution of the breakpoint instruction during the running of the target function.

[0142] Optionally, the breakpoint trigger module is specifically used to, if the compilation mode is a pre-compilation mode, continue the compilation process after the compilation of the target function is completed, until the compilation of the target application is completed, and generate a compilation result file; after replacing the compilation result file with the directory where the corresponding original file in the target application is located, restart the target application, and automatically trigger the execution of the breakpoint instruction when running to the target function.

[0143] Optionally, the device further comprises:

[0144] An initial setting module, used to set a breakpoint function detection module in the compiler, and to set corresponding first identifiers in the breakpoint function detection module according to at least one preset breakpoint function;

[0145] The function detection module is specifically used to obtain the second identifier of the target function; call the breakpoint function detection module according to the second identifier, and compare the second identifier with the first identifier of each preset breakpoint function respectively. If there is a matching first identifier, it is determined that the target function is the preset breakpoint function.

[0146] The embodiment of the present invention optimizes the process of compiler compiling target application program in Release mode. In the process of compiler compiling target application program in Release mode, for the currently compiled target function, an empty instruction is inserted before the first instruction of the prologue module of the target function. The empty instruction, as a reserved instruction slot in the prologue module, can realize the placeholder function, so that it can be replaced with the target instruction when needed, and will not affect the normal execution of the original instruction in the prologue module of the target function. When the compiler detects that the target function is a preset breakpoint function, the empty instruction of the reserved instruction slot in the prologue module of the target function is replaced with the target instruction; the target instruction includes a breakpoint instruction or a specific function instruction. If the target instruction is a breakpoint instruction, when the target function is subsequently run, it will realize the precise breakpoint to the expected preset breakpoint function in Release mode, and realize debugging of the preset breakpoint function. If the target instruction is a specific function instruction, when the target function is subsequently run, it will trigger the return value of the specific function instruction to be executed, and provide a data basis for analyzing the operation of the target function. Through the embodiments of the present invention, a means for debugging and analyzing a target function is provided to technical personnel in the Release mode, thereby further improving the quality and efficiency of software development.

[0147] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0148] Reference Figure 4 , is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. Figure 4 As shown, the electronic device includes: a processor, a memory, a communication interface and a communication bus, and the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the steps of the compilation processing method of the aforementioned embodiment.

[0149] An embodiment of the present invention provides a non-transitory computer-readable storage medium. When instructions in the storage medium are executed by a program or a processor of a terminal, the terminal is enabled to execute the steps of the compiling processing method of the foregoing embodiment.

[0150] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0151] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0152] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0153] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a predictable manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0154] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0155] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0156] Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A compiling method, characterized in that: Applied to a compiler, the method comprises: During the compilation of the target application in the release mode, for the currently compiled target function, inserting a null instruction before the first instruction of the prologue module of the target function; Detecting whether the target function is a preset breakpoint function; If it is determined that the target function is the preset breakpoint function, the empty instruction is replaced with a target instruction so that the target instruction is executed first when the target function is executed; the target instruction includes a breakpoint instruction or a specific function instruction; The target function is compiled and executed according to the target instruction.

2. The method according to claim 1, characterized in that The method further comprises: If it is determined that the target function is not the preset breakpoint function, the null instruction inserted in the prologue module of the target function is kept unchanged.

3. The method according to claim 1, characterized in that The target instruction is a breakpoint instruction. After replacing the empty instruction with the breakpoint instruction, the method further includes: According to the compilation mode of the target application, triggering the execution of the breakpoint instruction to enter the debugging state of the target function; the compilation mode includes a just-in-time compilation mode or a pre-compilation mode; After debugging is completed, the breakpoint instruction is replaced with a null instruction again, so that the breakpoint instruction is not executed when the target function is run again.

4. The method according to claim 3, characterized in that: The step of triggering the execution of the breakpoint instruction according to the compilation mode of the target application program includes: If the compilation mode is a just-in-time compilation mode, after the compilation of the target function is completed, the target function is run; The breakpoint instruction is synchronously triggered to execute during the execution of the target function.

5. The method according to claim 3, characterized in that: The step of triggering the execution of the breakpoint instruction according to the compilation mode of the target application program includes: If the compilation mode is the pre-compilation mode, after the compilation of the target function is completed, the compilation process is continued until the compilation of the target application is completed, and a compilation result file is generated; After replacing the compilation result file to the directory where the corresponding original file in the target application is located, restarting the target application, and automatically triggering the execution of the breakpoint instruction when running to the target function.

6. The method according to claim 1, characterized in that The method further comprises: Setting a breakpoint function detection module in the compiler, and setting corresponding first identifiers in the breakpoint function detection module according to at least one preset breakpoint function; The detecting whether the target function is a preset breakpoint function includes: Obtaining a second identifier of the objective function; The breakpoint function detection module is called according to the second identifier, and the second identifier is compared with the first identifier of each preset breakpoint function respectively. If there is a matching first identifier, it is determined that the target function is the preset breakpoint function.

7. A compiling and processing device, characterized in that: Applied to a compiler, the device comprises: An initialization module, used for inserting a null instruction before the first instruction of a prologue module of a currently compiled target function during the compilation of the target application in the release mode; A function detection module, used to detect whether the target function is a preset breakpoint function; an instruction optimization module, for replacing the empty instruction with a target instruction if it is determined that the target function is the preset breakpoint function, so that the target instruction is executed first when the target function is run; the target instruction includes a breakpoint instruction or a specific function instruction; The compile and run module is used to compile and run the target function according to the target instruction.

8. An electronic device, characterized in that: include: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the steps of the compiling method according to any one of claims 1 to 6.

9. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the steps of the compiling and processing method according to any one of claims 1 to 6 are implemented.

10. A computer program product, comprising a computer program, characterized in that The computer program executed by the processor is the steps of the compiling method according to any one of claims 1 to 6.