Debugging information generation method and device and electronic equipment
By converting the second code of the program into an intermediate representation and updating the association relationship, debugging information is generated, which solves the problem of being unable to generate debugging information in a compilation optimization scenario, and achieves effective location and solution of program problems.
Patent Information
- Application Number
- CN202310215693.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-02
- Publication Date
- 2024-09-03
AI Technical Summary
The existing technology cannot generate debugging information in a compilation optimization scenario, making it difficult to locate program problems.
By obtaining the second code of the program, converting it into an intermediate representation in a preset format, establishing an association with the intermediate representation, receiving updated parameters, updating the association, and generating debugging information.
Implemented the ability to generate debugging information in compilation optimization scenarios, supporting the location and resolution of program problems.
Smart Images

Figure CN118585418A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a debugging information generating method, device and electronic device. Background Art
[0002] Before a program written in any programming language is put into actual operation, the program can be debugged manually or using a compilation tool to obtain debugging information. The debugging information can record relevant information during the program running process, and the problems that occur during the program running process can be solved through the debugging information.
[0003] Debug information is generated after compilation and linking according to the debugging action. In order to debug outside the development environment, the debugging information can be stored in the form of a file.
[0004] However, the related art does not support the generation of debugging information in the scenario of compile result optimization. Summary of the invention
[0005] The present disclosure provides a debugging information generating method, device and electronic device.
[0006] According to a first aspect of the present disclosure, a method for generating debugging information is provided, the method comprising: obtaining a second code corresponding to a program; converting the second code into an intermediate representation in a preset format, and establishing an association relationship between the second code and the intermediate representation; receiving an update parameter to update the association relationship between the second code and the intermediate representation; and generating debugging information according to the updated association relationship.
[0007] According to a second aspect of the present disclosure, a debugging information generating device is provided, which includes: an acquisition unit, used to acquire a second code corresponding to a program; a first conversion unit, used to convert the second code into an intermediate representation in a preset format and establish an association relationship between the second code and the intermediate representation; a receiving unit, used to receive update parameters to update the association relationship between the second code and the intermediate representation; and a generating unit, used to generate debugging information according to the updated association relationship.
[0008] According to a third aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method provided in the first aspect.
[0009] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute the method provided in the first aspect.
[0010] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising: a computer program, wherein the computer program is stored in a readable storage medium, at least one processor of an electronic device can read the computer program from the readable storage medium, and the at least one processor executes the computer program so that the electronic device executes the method described in the first aspect.
[0011] According to the scheme disclosed in the present invention, the second code corresponding to the program is obtained; the second code is converted into an intermediate representation in a preset format, and an association relationship between the second code and the intermediate representation is established; an update parameter is received to update the association relationship between the second code and the intermediate representation; and debugging information is generated according to the updated association relationship. Since the scheme can combine compilation optimization with debugging information generation, update parameters are generated according to compilation optimization, and the above-mentioned second association relationship is updated by the update parameters, and debugging information generation from the updated second association relationship is supported, thereby enabling debugging information generation in a compilation optimization scenario.
[0012] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0014] Figure 1 is a schematic diagram of an embodiment of a compiler of the present disclosure;
[0015] Figure 2 is a schematic diagram of an embodiment of a method for generating debugging information provided by the present disclosure;
[0016] Figure 3 is a schematic diagram of another embodiment of the debugging information generating method provided by the present disclosure;
[0017] Figure 4 is a schematic diagram of another embodiment of the debugging information generating method provided by the present disclosure;
[0018] Figure 5 is a schematic block diagram of an example electronic device that can be used to implement embodiments of the present disclosure. DETAILED DESCRIPTION
[0019] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0020] For some processors, such as GPU processors, in order to enable these processors to complete corresponding functions, programs related to the processors can be developed. After the program development is completed, these programs can be debugged by compiling and assembling to generate debugging information. For example, the program is compiled by a compiler, and the compiled code is converted into code that can be executed by the above processor by an assembler. Debug information can be generated according to the compilation of the program by the compiler and the process of the assembler generating executable code.
[0021] In the process where the relevant assembler generates the code that can be executed by the above-mentioned processor based on the code compiled by the compiler, the code can be compiled and optimized, but the relevant assembler usually does not support the generation of debugging information under the compilation optimization scenario. Therefore, in the compilation optimization scenario, the corresponding debugging information cannot be generated. However, compilation optimization is a necessary step before the program is released. Some program problems will only be exposed during compilation optimization, and the problems may come from the program or from the compiler or assembler itself. In addition, usually for a released program, if there is a problem on the user side, it is very difficult to locate the problem if there is no debugging information. Therefore, it is necessary to solve the problem that the corresponding debugging information cannot be generated in the compilation optimization scenario.
[0022] In order to solve the above problems, the present disclosure provides a debugging information generation method to support the generation of debugging information in a compilation optimization scenario. The execution subject of the debugging information generation method of the present disclosure can be a compiler, which can run on a terminal device, such as a CPU, and the compiler can support the compilation of multi-level programming languages and the generation of debugging information.
[0023] Please refer to Figure 1 , Figure 1 FIG. 1 shows a schematic diagram of the structure of the compiler involved in the present disclosure. Figure 1 As shown, the compiler includes a compiling module 101 and an assembling module 102, and the compiler can support the compilation and debugging information generation of two-level programming languages. The input of the compiling module 101 can be a first code, and the output can be a second code. The input of the assembling module 102 is the second code, and the output is a target code. The target code here can be a machine code that can be executed by a processor. Figure 1Only one implementation of the compiler disclosed in the present invention is described by way of example. In other embodiments, the compiler may also support the compilation and debugging information generation of more than two-level programming languages (for example, three-level programming languages), which is not specifically limited here.
[0024] Please refer to Figure 2 , Figure 2 FIG. 1 is a schematic diagram of an embodiment of a method for generating debugging information provided by the present disclosure. Figure 2 As shown, the debugging information generation method provided in this embodiment includes:
[0025] S201. Obtain a second code corresponding to the program.
[0026] The program here can be a program that implements various functions, such as a program that drives a preset processor to perform corresponding functions. The preset processor here can be, for example, a graphics processor or an artificial intelligence processor. In schematic form, the corresponding function can be, for example, using an artificial intelligence processor to complete neural network operations such as convolution.
[0027] The program code may include a high-level language code written in a high-level program language, such as a C language code, an assembly language code written in an assembly language, etc. The second code here may be an assembly language code or a high-level language code.
[0028] S202: Convert the second code into an intermediate representation in a preset format, and establish a second association relationship between the second code and the intermediate representation.
[0029] The intermediate representation (IR) here may be an intermediate representation in the process of converting the second code into the target code. The compiler of the present disclosure may optimize the intermediate representation.
[0030] The second association relationship between the second code and the intermediate representation here includes: a mapping relationship between the row number of the second code and the row number of the intermediate representation, and a mapping relationship between the second code register and the intermediate representation register.
[0031] Taking the second code as an assembly language code as an example, the second association relationship between the second code and the intermediate representation here may include: a mapping relationship between assembly code line numbers and intermediate representation line numbers, and a mapping relationship between assembly registers and intermediate representation registers.
[0032] Schematically, the i-th line of assembly code is converted to the j1-th line or the intermediate representation from the j1-th line to the j2-th line, that is, the mapping relationship between the above-mentioned assembly code line number and the intermediate representation line number is: the j1-th line is mapped to or the intermediate representation from the j1-th line to the j2-th line. Here, i is an integer greater than or equal to 1 and less than or equal to the total number of assembly code lines. j1 is an integer greater than or equal to 1 and less than the total number of intermediate representation lines, and j2 is an integer greater than j1 and less than or equal to the total number of intermediate representation lines. In other words, a line of assembly code can be mapped to a line of intermediate representation, or a line of assembly code can be mapped to multiple lines of intermediate representation.
[0033] The mapping relationship between the assembly registers and the intermediate representation registers may be, for example, assembly register a is mapped to intermediate representation register b1, or assembly register a is mapped to intermediate representation registers b1 to b2. That is, one assembly register is mapped to one intermediate representation register, or may be mapped to more than two intermediate representation registers.
[0034] The second code register and the intermediate representation register here may be virtual registers.
[0035] S203: Receive an update parameter to update a second association relationship between the second code and the intermediate representation.
[0036] In some application scenarios, the user can compile and optimize the program based on the intermediate representation. After the optimization, the intermediate representation may change. Therefore, the second association relationship between the second code and the intermediate representation needs to be updated. The user or the electronic device connected to the above-mentioned execution subject can generate update parameters according to the updated intermediate representation and send the above-mentioned update parameters to the above-mentioned execution subject.
[0037] The update parameter here is a parameter used to update the second association relationship between the second code and the intermediate representation, for example, updating the mapping relationship between the second code line number and the intermediate representation line number, and / or updating the mapping relationship between the second code register and the intermediate representation register.
[0038] S204: Generate debugging information according to the updated second association relationship.
[0039] Illustratively, the above debugging information may include information about the relationship between the second code and the target code, such as the target code instruction address and the location of the source code corresponding to the instruction address in the second code file.
[0040] In this embodiment, the second code corresponding to the program is obtained; the second code is converted into an intermediate representation in a preset format, and a second association relationship between the second code and the intermediate representation is established; an update parameter is received to update the second association relationship between the second code and the intermediate representation; and debugging information is generated according to the updated second association relationship. Since each link from the second code to the intermediate representation is optimized in the compilation optimization scenario, the intermediate representation will change after the above optimization, or the association relationship between the second code and the intermediate representation will change. The related technology does not support the generation of debugging information in the compilation optimization scenario, and the scheme provided in this embodiment can combine compilation optimization with debugging information generation, generate update parameters according to compilation optimization, update the above second association relationship by the update parameters, support the generation of debugging information by the updated second association relationship, and thus realize the generation of debugging information in the compilation optimization scenario.
[0041] In some embodiments, the receiving of update parameters includes: receiving update parameters through an application programming interface (Application Programming Interface, API) interface, and the update parameters are determined according to a compilation optimization method.
[0042] In these embodiments, each link from the second code to the intermediate representation can be compiled and optimized. For example, various compilation optimization methods, such as scalar optimization, dead code deletion, loop unrolling, loop pipelining, common expression deletion, automatic vectorization, function inlining, constant propagation, loop invariant externalization, partial redundancy deletion, control flow simplification, inter-procedural optimization, etc., are used to compile and optimize the above links. The compilation optimization method is only described here in an exemplary manner, and not all compilation optimization methods are exhaustive. The above examples are not used to limit the protection scope of the disclosed solution.
[0043] After compiling and optimizing each link from the second code to the intermediate representation, an optimized intermediate representation is obtained. After the above compilation optimization method, the above intermediate representation may change. In this way, the second association relationship between the second code and the intermediate representation needs to be updated. The user can generate update parameters according to the updated intermediate representation through the API interface, send the above update parameters to the execution subject of the debugging information generation method, and the above execution subject updates the second association relationship between the above second code and the compiled optimized intermediate representation according to the above update parameters.
[0044] In these optional implementations, the compiler may receive the above update parameters through a pre-provided API interface.
[0045] After receiving the update parameters, the compiler of the API interface may update the second association relationship between the second code and the intermediate representation according to the update parameters to obtain corresponding debugging information.
[0046] The following description will be made by taking the second code as an assembly code as an example.
[0047] Assume the following assembly code:
[0048] %r0=%r1+%r2;
[0049] %r3=%r1+%r2;
[0050] %r4=%r0.
[0051] The intermediate representation can be expressed as follows:
[0052] pr0=pr1+pr2;
[0053] pr3=pr1+pr2;
[0054] pr4=pr0.
[0055] Assuming that there are no fixed values for pr0, pr3 and pr4 at other locations, the intermediate representation after scalar optimization is as follows, and other locations using pr0, pr3 and pr4 are all changed to pr5.
[0056] pr5=pr1+pr2;
[0057] pr0=pr5;
[0058] pr3=pr5;
[0059] pr4=pr5;
[0060] The intermediate representation is newly created during compilation optimization. The corresponding API interface can be called to adjust the original mapping relationship to pr0, pr3 and pr4 to map to pr5.
[0061] Furthermore, the above API interface includes a setting class interface and / or a copy class interface.
[0062] The setting class interface may include the following parameters: the second code register number and the intermediate representation register number, and its function is to establish a mapping relationship between the intermediate representation register number and the second code register number. Schematically, the setting class interface may include the following two types:
[0063] (1)void setValueInfo(IR*stmt,UINT old_IR_pr,UINT new_IR_pr,Region*rg).
[0064] Among them, stmt: preset intermediate representation; old_IR_pr: virtual register number of the old intermediate representation (i.e., the intermediate representation before the update); new_IR_pr: virtual register number of the new intermediate representation (i.e., the intermediate representation after the update); Region, corresponding to the function in the preset intermediate representation framework, each function abstraction corresponds to a Region value.
[0065] The functions that can be realized by this setting class interface are: obtaining the second code register number corresponding to the old intermediate representation register number, establishing a mapping relationship between the new intermediate representation register number and the above second code register number, and hanging the mapping relationship on the stmt.
[0066] (2) void setValueInfo(IR*stmt, const char*secondcode_pr, UINT IR_pr, Region*rg).
[0067] Among them, second code_pr_name is the second code register number; IR_pr is the intermediate representation virtual register number, which can be an updated intermediate representation.
[0068] The function implemented by the interface may be to establish a mapping relationship between IR_pr and the second code _pr_name when there is no intermediate representation virtual register number before the update, and set the mapping relationship on stmt.
[0069] In the above example, the setting class interface (2) can be used to receive the update parameters for adjusting the above register mapping relationship. Schematically, using the setting class interface (2) to adjust the register mapping relationship can be expressed as follows:
[0070] setValueInfo(ir,"%r0",pr5,rg);
[0071] setValueInfo(ir,"%r3",pr5,rg);
[0072] setValueInfo(ir,"%r4",pr5,rg).
[0073] The copy class interface may include parameters: intermediate representation src and intermediate representation tgt, and its function is to copy the corresponding mapping relationship on the intermediate representation src to the intermediate representation tgt. Exemplarily, the copy class interface may include the following two types:
[0074] (1)void copyValueInfo(IR*tgt,IR const*src,Region*rg).
[0075] Among them, Region corresponds to a function in the preset intermediate representation, and each function abstraction corresponds to a Region value.
[0076] The function implemented by the copy interface is: copying the corresponding mapping relationship on the intermediate representation src to the intermediate representation tgt, thereby setting the corresponding mapping relationship on the intermediate representation src to the mapping relationship corresponding to the intermediate representation tgt.
[0077] (2)void copyValueInfo(IR*tgt,Dbx const*dbx,Region*rg);
[0078] Among them, Dbx: the entity of all debugging information; copy the DebugValueInfo in Dbx to tgt; DebugValueInfo is a member of Dbx.
[0079] In this way, after the above compilation optimization is performed, the update parameters generated by the above compilation optimization can be received through the setting class interface and / or the copy class interface. Then, the above update parameters are passed to the pre-edited program instructions using the above interface, and the second association relationship between the second code and the intermediate representation is updated by the above program instructions according to the above update parameters.
[0080] In these embodiments, the second association relationship is updated by using the API interface to receive update parameters generated by the compilation optimization process, and debugging information is generated according to the updated second association relationship, thereby associating the compilation optimization process with the generation of debugging information, thereby supporting the generation of debugging information in the compilation optimization scenario.
[0081] In some embodiments, the specific content of the above-mentioned second association relationship, such as the line number mapping relationship and register mapping relationship between the second code and the intermediate representation, can be recorded in the file DebugValueInfo. Each pass of the assembler can maintain the file DebugValueInfo. After the register allocation and hardware address allocation are completed, all files DebugValueInfo are optimized uniformly. After the register and hardware address allocation are completed, the embodiment of the present disclosure uniformly optimizes all DebugValueInfo, which can achieve global optimization and is conducive to improving the readability of the debugging information generated according to the second association relationship after global optimization.
[0082] Based on this, the above method further includes, before generating the debugging information, processing the program after the second association relationship is updated, and the processing may include:
[0083] First, at least one basic block is traversed, and the second association relationship between the second code and the intermediate representation in the basic block is processed until the second association relationship between the second code and the intermediate representation in the basic block no longer changes.
[0084] Secondly, debugging information is generated according to a second association relationship between the second code in the processed basic block and the intermediate representation.
[0085] It should be clear that the compilation process of the above program may include converting the above program into a control flow graph, which may include at least one basic block; wherein a basic block refers to a code block with only one entry and one exit. The entry is the first statement in it, and the exit is the last statement in it. For a basic block, it is only entered from its entry and exited from its exit during execution. Each basic block may include at least one instruction. The above only has one entry, which means that there will be no other place to enter this basic block through jump-type instructions. The above only has one exit, which means that only the last instruction can lead to entering other basic blocks for execution. As long as the first instruction in the basic block is executed, all executions in the basic block will be executed only once in sequence.
[0086] As an implementation method, at least one basic block in the control flow graph may be traversed in reverse order, and for each basic block, the second association relationship between the second code in the basic block and the intermediate representation is processed until the second association relationship between the second code in the basic block and the intermediate representation no longer changes.
[0087] The above-mentioned processing of the second association relationship between the second code and the intermediate representation in the basic block includes: calculating and merging the corresponding intermediate representation of the basic block. During the above-mentioned calculation and merging process, the line number mapping relationship and the register mapping relationship between the second code and the intermediate representation in the process can be tracked and adjusted in real time until the intermediate representation no longer changes, and then the line number mapping relationship and the register mapping relationship between the second code in the basic block and the intermediate representation no longer change.
[0088] For example: the debug information file DebugValueInfo1 in the basic block records that the assembly register %r1 corresponds to the physical register R1 at the instruction address 0x0-0x8, and the debug information file DebugValueInfo2 records that the assembly register %r1 corresponds to the physical register R1 at the instruction address 0x8-0x10. Then the debug information files DebugValueInfo1 and DebugValueInfo2 can be merged into one DebugValueInfo, and the instruction address range corresponding to the debug information file DebugValueInfo obtained after the merger is set to 0x0-0x10. In these implementations, the association relationship between the second code and the intermediate representation in each basic block is processed by traversing at least one basic block as described above, so that simplified debug information can be obtained, making the debug information more readable. Please refer to Figure 3 , Figure 3 FIG. 1 is a schematic diagram of another embodiment of the debugging information generation method provided by the present disclosure. Figure 3 As shown, the debugging information generation method provided in this embodiment includes:
[0089] S301. Obtain a second code corresponding to the program.
[0090] The program here may be a program for implementing various functions, such as a program for driving a preset processor to execute a corresponding function, etc. The preset processor here may be, for example, a graphics processor. Schematically, the corresponding function may be, for example, a graphics display function, etc.
[0091] Here, the second code may be various codes, for example, a code corresponding to an assembly language, etc. It may also be a code corresponding to other languages.
[0092] S302: Convert the second code into an intermediate representation in a preset format, and establish a second association relationship between the second code and the intermediate representation.
[0093] S303: Receive update parameters to update the second association relationship between the second code and the intermediate representation, wherein the update parameters are determined according to a compilation optimization method.
[0094] The specific implementation of steps S301 to S302 can refer to Figure 2 The embodiments shown are not described in detail here.
[0095] S304: Convert the intermediate representation into target code.
[0096] The target code here may be, for example, a machine code executed by a processor (eg, a graphics processor or an artificial intelligence processor).
[0097] After the compilation optimization in step S302, the intermediate representation is the compiled optimized code. According to the compiled optimized intermediate representation, the update parameter for adjusting the second association relationship between the compiled optimized intermediate representation and the second code can be determined, thereby updating the second association relationship (the specific implementation of updating the second association relationship can refer to Figure 2 The description of the embodiment shown in the figure is not repeated here.) After the second association relationship is updated, the intermediate representation can be converted into a target code.
[0098] When converting the intermediate representation into target code, the compiler can allocate physical resources to the registers in the intermediate representation, and then convert the opcodes in the intermediate representation into machine instructions recognizable by the processor according to the preset format conversion relationship. The above-mentioned allocation of physical resources to the registers in the intermediate representation includes: allocating physical registers or physical memory to the registers in the intermediate representation.
[0099] S305. Generate a third association relationship between the second code and the target code according to the updated second association relationship, and obtain debugging information, wherein the debugging information includes a register mapping relationship between the second code and the target code.
[0100] After obtaining the updated second association relationship between the second code and the intermediate representation in step S303 and converting the intermediate representation into the target code in step S304, the third association relationship between the second code and the target code can be determined based on the second association relationship between the second code and the intermediate representation and the conversion relationship between the intermediate representation and the target code. It should be noted that there may be no order between the above steps S304 and S305, and the two may be performed simultaneously.
[0101] Schematically, the i-th line of the second code is mapped to the j-th line of the intermediate representation. After the intermediate representation is converted into the target code, the j-th line of the intermediate representation is mapped to the k-th line of the target code, and then the i-th line of the second code is mapped to the k-th line of the target code. According to the above method, a line number mapping relationship between the second code and the target code can be established.
[0102] For another example, in the compiled optimized second code and the intermediate representation, the second code register A1 is mapped to the intermediate representation register B1. The physical resource allocated to the intermediate representation register B1 is, for example, the physical register C1, that is, the intermediate representation register B1 is mapped to the physical register C1. The compiler may determine that the second code register A1 is mapped to the physical register C1.
[0103] The compiler can determine the mapping relationship between the second code registers and the physical resources in the above manner. The above mapping relationship can be called the register mapping relationship from the second code to the target code.
[0104] The compiler may generate debugging information according to the line number mapping relationship between the second code and the target code, the register mapping relationship between the second code and the target code, the line number mapping between the second code and the intermediate representation, and the register mapping between the second code and the intermediate representation.
[0105] In some embodiments, the debugging information can be output visually, for example, the last debugging information can be displayed in the display interface corresponding to the program according to the user's call instruction. By outputting the debugging information visually, the user can locate the problem of the program according to the debugging information.
[0106] In this embodiment, the second code corresponding to the program is obtained; the second code is converted into an intermediate representation of a preset format, and a second association relationship between the second code and the intermediate representation is established; an update parameter is received to update the second association relationship between the second code and the intermediate representation, and the update parameter is determined according to the compilation optimization method; the intermediate representation is converted into a target code; a third association relationship between the second code and the target code is generated according to the updated second association relationship, and debugging information is obtained, wherein the debugging information includes a register mapping relationship between the second code and the target code. It is realized that when the second code to the intermediate representation is compiled and optimized, debugging information including the third association relationship between the second code and the target code can be obtained. Thereby, problems that will only occur during optimization during the compilation process can be located. It is also possible to locate the problem part through the above debugging information when a problem occurs on the user side after the program is released.
[0107] Please refer to Figure 4 , which shows a schematic diagram of another embodiment of the debugging information generation method provided by the present disclosure. Figure 4 As shown, the debugging information generation method includes the following steps:
[0108] S401. Obtain a first code corresponding to a program.
[0109] The first code is a code of the program written in a high-level language. The high-level language here can be, for example, various C languages. The program here is used to enable the processor to perform corresponding functions, such as enabling the graphics processor to realize the display function.
[0110] S402: Convert the first code into the second code, and generate a first association relationship between the first code and the second code to obtain first-level debugging information.
[0111] The first code may be a code of the program edited in various programming languages, and the second code may be a code of the program edited in various programming languages different from the first code.
[0112] In some application scenarios, the second code is a code of the above program written in a programming language that is closer to machine language than the first code.
[0113] The above process of converting the first code into the second code includes the steps of preprocessing, lexical analysis, syntax analysis, semantic analysis and optimization.
[0114] Through the above process, the first association relationship between the first code and the second code can be determined.
[0115] Taking the first code as a code written in C language and the second code as a code written in assembly language as an example, the process of converting the first code into the second code includes: allocating second code registers to variables in the first code, establishing a mapping relationship between the variables in the first code and the second code registers, and converting the instructions in the first code into instructions written in the second code according to semantics.
[0116] After converting the first code into the second code, a first association relationship between the first code and the second code may be generated to obtain first-level debugging information.
[0117] The first level debugging information may include a line number mapping relationship between the first code and the second code. The mapping between the line numbers of the first code and the second code is used to indicate the corresponding relationship between each line of the first code and each line of the second code.
[0118] For example, the tth line of the first code corresponds to the p1th line or the p1 to p2th lines of the second code. A mapping relationship can be established in which the tth line of the first code is mapped to the p1th line of the second code, or a mapping relationship can be established in which the tth line of the first code is mapped to the p1 to p2th lines of the second code.
[0119] The first level debugging information also includes a register mapping between the first code and the second code.
[0120] In some application scenarios, the first code may be a code edited in C language, and the second code may be a code written in assembly language. The first-level debugging information also includes a register mapping relationship between the first code and the second code. The register mapping relationship here is used to indicate the mapping between the variables of the first code and the registers of the second code.
[0121] In these application scenarios, registers corresponding to the second code may be allocated to the variables in the first code. After the registers are allocated to the variables in the first code, a mapping relationship between the variables and the registers may be established.
[0122] In some embodiments, the register mapping between the first code and the second code in the first level debugging information includes: a mapping between variables of the first code and string encodings of registers of the second code, wherein the string encodings are obtained by encoding the numbers of the registers of the second code.
[0123] The second code register refers to a register corresponding to the second code.
[0124] The numbers of the second code registers can be encoded in advance according to a preset encoding format to obtain the string codes corresponding to the second code registers. Then, a mapping relationship between the second code registers and the string codes is established. By establishing the mapping relationship between the second code registers and the string codes, it is beneficial to achieve decoupling between debugging information of different modules.
[0125] In these embodiments, when allocating a register to a variable of the first code, the string encoding of the second code register may be allocated to the first code variable.
[0126] Illustratively, the character string encoding corresponding to the second code register numbered “1” may be “%r0”.
[0127] In practice, the conversion of the first code from step S401 to step S402 into the second code and the establishment of the association relationship between the first code and the second code may be implemented by a compiler.
[0128] S403: Obtain a second code corresponding to the program.
[0129] S404: Convert the second code into an intermediate representation in a preset format, and establish a second association relationship between the second code and the intermediate representation.
[0130] S405: Receive an update parameter to update a second association relationship between the second code and the intermediate representation.
[0131] S406: Convert the intermediate representation into target code.
[0132] S407: Generate a third association relationship between the second code and the target code according to the updated association relationship, and obtain debugging information, wherein the debugging information includes a register mapping from the second code to the target code.
[0133] The second code here can be, for example, the code of the above program written in assembly language, and can be converted from the first code of the program.
[0134] In some embodiments, the intermediate representation here may be a code between assembly language and machine code. Compilation optimization may be performed at each link between the second code and the intermediate representation. After the compilation optimization, the second association relationship between the second code and the intermediate representation is updated according to the update parameter.
[0135] In some embodiments, the compiler may further establish a mapping table between the string encoding of the second code register and the hardware resources.
[0136] After the hardware resources are allocated to the second code register, a mapping table between the string encoding of the second code register and the hardware resources can be established. For example, the hardware resource allocated to the string encoding "%r1" is the physical register "p1". In the above mapping table, "%r1" can be mapped to "p1".
[0137] Illustratively, the first code may be a code written in C language. The second code may be a code written in assembly language. The target code may be a machine code.
[0138] The register mapping between the second code and the target code in the debugging information determined in the above step S407 may include a mapping relationship between the second code registers and the physical resources.
[0139] After obtaining the first level debugging information corresponding to the conversion of the first code into the second code, and the debugging information corresponding to the conversion of the second code into the target code, the two debugging information can be assembled into respective corresponding segments. In practice, respective corresponding segments can be generated for the register mapping in the first level debugging information and the line number mapping from the first code to the second code. Respective corresponding segments are generated for the register mapping and line number mapping between the second code and the target code in the above debugging information.
[0140] The specific implementation of steps S403 to S407 can refer to Figure 2 and Figure 3 The relevant parts of the illustrated embodiment are not described in detail here.
[0141] In some application scenarios, the above steps S403 to S407 may be implemented by a preset assembler.
[0142] By generating the first-level debugging information and the debugging information between the second code and the machine code, and carrying the first debugging information and the debugging information in the respective corresponding segments, decoupling between debugging information at various levels is achieved.
[0143] In the related art, during the conversion of the first code to the target code, debugging information with strong coupling between the first code and the target code can be generated, for example, the debugging information records the line number mapping between the first code and the target code and the mapping between the first code variables and the target code hardware resources, or the debugging information generated during the conversion of the first code to the second code and the debugging information generated during the conversion of the second code to the target code are recorded in the same segment. In the process of generating these debugging information, if a register overflow occurs during the mapping between the second code and the target code, the register needs to be modified, and accordingly, the mapping relationship between the first code and the second code needs to be modified at the same time, so the above process is relatively complicated. In addition, for this kind of debugging information, when locating the problem, it is impossible to accurately locate whether the problem occurs during the conversion process of the first code to the second code, or during the conversion process of the second code to the target code. That is, it is impossible to accurately locate the problem, which is not conducive to the maintenance of debugging information.
[0144] and Figure 3 Compared with the illustrated embodiment, the present embodiment highlights the steps of converting the first code into the second code and obtaining the first level debugging information according to the first association relationship between the first code and the second code, so that the above-mentioned first level debugging information and the debugging information from the second code to the target code can be obtained through the present embodiment, and the process of converting the first code to the target code generates two levels of debugging information. It is helpful to decouple the debugging information in the process of converting the first code into the second code and the debugging information in the process of converting the second code into the target code. The disclosed embodiment can separately maintain the first level debugging information and the debugging information between the above-mentioned second code and the target code. On the one hand, the complexity of maintaining the debugging information between the first code and the target code is reduced. On the other hand, when a problem occurs in the program, the code involved in the debugging information of each level can be checked according to the debugging information of that level to locate the problem, so that the problem can be located quickly, and the complexity of locating the problem can also be reduced.
[0145] In some optional implementations, the compiler may also support the compilation and debugging information generation of two or more level programming languages (for example, three level programming languages), and the debugging information generation method may further include:
[0146] First, a header code of a program is received and the header code is converted into a first code.
[0147] Secondly, a first-level association relationship between the first-level code and the first code is generated to obtain first-level debugging information, where the first-level debugging information includes a variable mapping relationship between the first-level code and the first code.
[0148] Here, the first level code and the first code can both be the code of the above program written in a high-level language. In these optional implementations, the first level code can be a program code written in any programming language. For example, a code written in Python programming language. The first code can be the code of the above program written in any programming language. For example, the code of the above program written in C programming language.
[0149] In these optional implementations, the first-level code can be converted into the first code. When converting the first-level code into the first code, it is necessary to convert between variables, and convert each line of the first-level code into one or more lines of the first code according to the semantics of the line of code. Further, the compiler can establish a first-level association relationship between the first-level code and the first code, and generate first-level debugging information based on the above-mentioned first-level association relationship. The first-level debugging information here includes a variable mapping relationship between the first-level code and the first code. The variable mapping relationship between the above-mentioned first-level code and the first code can indicate the equivalence relationship between the variables in the first-level code and the variables in the first code. In addition, the above-mentioned first-level debugging information also includes line number mapping. The line number mapping can characterize the corresponding relationship between each line of code in the first-level code and each line of code in the first code.
[0150] Optionally, in the process of converting the first-level code into the first code, the compilation process can also be compiled and optimized. The specific compilation optimization method can refer to the description above and is not specifically limited here. Further, the compiler can also update the parameters in the compilation optimization process through the corresponding API interface to generate the above-mentioned first-level debugging information based on the updated information. The API interface and update method here are similar to those described above, and the details can be referred to the description above.
[0151] After converting the first-level code into the first code to obtain the first-level debugging information, the first code can also be converted into the second code and the first-level debugging information can be obtained, and then the second code can be converted into an intermediate representation, and the second association between the second code and the intermediate representation can be updated according to the update parameter, and the intermediate representation can be converted into a machine code, and then the debugging information can be generated according to the third association between the second code and the machine code. In this way, multi-level debugging information for codes written in any language can be realized. For each level of debugging information, a segment corresponding to the debugging information of that level can be generated. The debugging information generated by the above process can be generated for any first-level code. In addition, the above scheme can realize the independence of debugging information in different links in the process of converting the first-level code into the target code, which helps to reduce the complexity of adjusting the debugging information. In addition, it also helps to increase the speed of locating the problem.
[0152] Please continue to refer to Figure 1 , Figure 1is a schematic structural diagram of a compiler provided according to the present disclosure, such as Figure 1 As shown, the compiler 100 provided in this embodiment includes: a compile module 101 and an assemble module 102 .
[0153] The assembly module 102 is used to
[0154] Obtaining a second code corresponding to the program;
[0155] Converting the second code into an intermediate representation in a preset format, and establishing a second association relationship between the second code and the intermediate representation;
[0156] receiving an update parameter to update a second association relationship between the second code and the intermediate representation;
[0157] Debug information is generated according to the updated second association relationship.
[0158] In some embodiments, the assembly module 102 is further configured to:
[0159] The update parameters are received through the API interface, and the update parameters are determined according to the compilation optimization method.
[0160] In some embodiments, the API interface includes: a setting type interface and / or a copy type interface.
[0161] In some embodiments, the debugging information includes a third association relationship between the second code and the target code; the assembly module 102 is further used to:
[0162] Convert the intermediate representation into target code;
[0163] A third association relationship between the second code and the target code is generated according to the updated second association relationship, and debugging information is obtained, wherein the debugging information includes a register mapping relationship between the second code and the target code.
[0164] In some embodiments, the assembly module 102 is further configured to:
[0165] Processing the intermediate representation;
[0166] Convert the processed intermediate representation into target code.
[0167] In some embodiments, the program includes at least one basic block; the assembly module 102 is further configured to:
[0168] traversing at least one basic block, processing the second association relationship between the second code and the intermediate representation in the basic block until the second association relationship between the second code and the intermediate representation in the basic block no longer changes;
[0169] Debug information is generated according to a second association relationship between the second code in the processed basic block and the intermediate representation.
[0170] In some embodiments, the compiling module 101 is used to:
[0171] Obtaining a first code corresponding to the program;
[0172] The first code is converted into a second code, and a first association relationship between the first code and the second code is generated to obtain first-level debugging information.
[0173] In some embodiments, the compiling module 101 is further configured to:
[0174] The first level debug information includes the register mapping between the first code and the second code:
[0175] The register mapping in the first-level debugging information includes: a mapping between variables of the first code and string codes of registers of the second code, wherein the string codes are obtained by encoding the numbers of the registers of the second code.
[0176] In some embodiments, the compiling module 101 is further configured to:
[0177] receiving a first level code of a program and converting the first level code into a first code;
[0178] A first-level association relationship between the first-level code and the first code is generated to obtain first-level debugging information, wherein the first-level debugging information includes a variable mapping relationship between the first-level code and the first code, and the variable mapping relationship indicates an equivalent relationship between variables in the first-level code and variables in the first code.
[0179] In some embodiments, the debugging information, the first-level debugging information, and the first-level debugging information also include a line number mapping, and the line number mapping is used to indicate the corresponding relationship between line numbers of different codes.
[0180] The compiler of this embodiment can execute Figure 2 , Figure 3 or Figure 4 The specific implementation process and technical principles of the technical solution in the method shown are the same and will not be repeated here.
[0181] refer to Figure 5, which shows a schematic diagram of the structure of an electronic device 500 suitable for implementing the embodiment of the present disclosure, and the electronic device 500 may be a terminal device or a server. The terminal device may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, personal digital assistants (PDAs), tablet computers (Portable Android Devices, PADs), portable multimedia players (PMPs), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0182] like Figure 5 As shown, the electronic device 500 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 to a random access memory (RAM) 503. Various programs and data required for the operation of the electronic device 500 are also stored in the RAM 503. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0183] Typically, the following devices may be connected to the I / O interface 505: input devices 506 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 508 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 509. The communication devices 509 may allow the electronic device 500 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 5 The electronic device 500 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0184] The present disclosure also provides a computer-readable storage medium, in which a computer-executable instruction is stored. When a processor executes the computer-executable instruction, the following is implemented: Figure 2 , Figure 3 and Figure 4The debugging information generating method of the illustrated embodiment.
[0185] The present disclosure also provides a computer program product, including a computer program. When the computer program is executed by a processor, Figure 2 , Figure 3 and Figure 4 The debugging information generating method of the illustrated embodiment.
[0186] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by the processing device 501, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0187] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0188] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0189] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device executes the method shown in the above embodiment.
[0190] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0191] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0192] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0193] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0194] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for generating debugging information, comprising: Obtaining a second code corresponding to the program; Convert the second code into an intermediate representation in a preset format, and establish a second association relationship between the second code and the intermediate representation; receiving an update parameter to update a second association relationship between the second code and the intermediate representation; Debug information is generated according to the updated second association relationship.
2. The method according to claim 1, characterized in that The receiving update parameter comprises: The update parameters are received through the API interface, and the update parameters are determined according to the compilation optimization method.
3. The method according to claim 2, characterized in that The API interface includes: a setting type interface and / or a copy type interface.
4. The method according to claim 1, characterized in that: The debugging information includes a third association relationship between the second code and the target code; and the generating the debugging information according to the updated second association relationship includes: Converting the intermediate representation into target code; A third association relationship between the second code and the target code is generated according to the updated second association relationship, and the debugging information is obtained, wherein the debugging information includes a register mapping relationship between the second code and the target code.
5. The method according to claim 4, characterized in that The converting the intermediate representation into a target code comprises: processing the intermediate representation; The processed intermediate representation is converted into target code.
6. The method according to any one of claims 1 to 5, characterized in that The program includes at least one basic block; and the step of generating debugging information according to the updated second association relationship includes: traversing at least one basic block, processing a second association relationship between a second code in the basic block and the intermediate representation until the second association relationship between the second code in the basic block and the intermediate representation no longer changes; The debugging information is generated according to a second association relationship between the second code in the processed basic block and the intermediate representation.
7. The method according to any one of claims 1 to 5, characterized in that The method further comprises: Obtaining a first code corresponding to the program; The first code is converted into the second code, and a first association relationship between the first code and the second code is generated to obtain first-level debugging information.
8. The method according to claim 7, characterized in that The first level debugging information includes a register mapping between the first code and the second code: The register mapping in the first-level debugging information includes: a mapping between variables of the first code and string codes of registers of the second code, wherein the string codes are obtained by encoding the numbers of the registers of the second code.
9. The method according to claim 7, characterized in that: The method further comprises: receiving a first level code of a program and converting the first level code into a first code; A first-level association relationship between the first-level code and the first code is generated to obtain first-level debugging information, wherein the first-level debugging information includes a variable mapping relationship between the first-level code and the first code, and the variable mapping relationship indicates an equivalent relationship between variables in the first-level code and variables in the first code.
10. The method according to claim 9, characterized in that The debugging information, the first-level debugging information, and the first-level debugging information further include a line number mapping, and the line number mapping is used to indicate a corresponding relationship between line numbers of different codes.
11. An electronic device, characterized in that: include: Processor and memory; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor executes the debugging information generating method according to any one of claims 1 to 10.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When the processor executes the computer-executable instructions, the debugging information generating method according to any one of claims 1 to 7 is implemented.
13. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the debugging information generating method according to any one of claims 1 to 10 is implemented.
