Software compiling method and device, debugging method and device, storage medium and program product

By recording inline function information in the assembly file and transmitting it in the debug information data segment of the object file, the problem of inaccurate inline function debug information is solved, and more accurate code debugging is achieved.

CN121597213APending Publication Date: 2026-03-03CAMBRIAN (KUNSHAN) INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411154515.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-21
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

Existing compilation methods, when dealing with inline functions in the code, no longer provide accurate or complete debugging information, failing to meet the debugging needs of developers.

Method used

When generating the assembly file, information about inline functions is recorded, and this information is also recorded in the debug information data segment of the object file to generate complete debug information, helping developers to accurately display the location of inline functions during debugging.

Benefits of technology

It improves the effectiveness of code debugging, ensures that debugging information for inline functions is displayed correctly, and helps developers locate problems in the program more accurately.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121597213A_ABST
    Figure CN121597213A_ABST
Patent Text Reader

Abstract

The invention provides a software compiling method and device, a debugging method and device, a storage medium and a program product. The software compiling method comprises the following steps: generating a first intermediate expression containing debugging information according to a target source program code; if the debugging information contains the inline function identifier, generating first line number information and inline function information to obtain an assembly file; the inline function information comprises a function name corresponding to the first line number information and second line number information corresponding to the inline function identifier; compiling the assembly file to obtain a target file; the debugging information data segment in the target file comprises a table item for recording inline function information. According to the method, the inline information can be correctly generated when the assembly file is generated, and the assembly file containing the inline information is further compiled into the target file. According to the method and the device, the inline information can be correctly displayed by analyzing the debugging information data segment of the target file during debugging by a developer, so that the effectiveness of code debugging is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to computer software technology, and more particularly to a software compilation method, debugging method, apparatus, storage medium, and program product. Background Technology

[0002] In software development, inline functions are a common optimization technique that reduces the overhead of function calls by inserting function code directly at the call point. However, using inline functions can bring difficulties during debugging because the code of an inline function no longer exists as an independent function after compilation, but is embedded in the code that calls it. Existing compilation methods, when inline functions are present in the code, output debugging information that is no longer accurate or complete, failing to meet the debugging needs of developers. Summary of the Invention

[0003] This application provides a software compilation method, debugging method, apparatus, storage medium, and program product to solve the problem that when the compilation method has inline functions in the code, the output debugging information is no longer accurate or missing, and cannot meet the debugging needs of developers.

[0004] In a first aspect, this application provides a software compilation method, comprising: generating a first intermediate representation containing debugging information based on target source code;

[0005] If the debugging information contains an inline function identifier, then the first line number information and the inline function information are generated to obtain the assembly file; the inline function information includes: the function name corresponding to the first line number information, and the second line number information corresponding to the inline function identifier;

[0006] The assembly file is compiled to obtain an object file; the debugging information data segment in the object file includes entries that record the inline function information.

[0007] Optionally, before generating the second line number information corresponding to the inline function identifier, the method further includes: if the same inline function identifier already exists in the debugging information, then the second line number information is not generated.

[0008] Optionally, compiling the assembly file to obtain the object file includes:

[0009] Based on the assembly file, a second intermediate representation is generated;

[0010] By traversing the second intermediate expression, the first line number information of the target source code associated with the second intermediate expression and the second line number information of the target source code associated with the inline function identifier are obtained;

[0011] The debugging information data segment is generated according to the preset debugging data format and integrated into the target file.

[0012] Optionally, obtaining the first line number information of the target source code associated with the second intermediate expression, and the second line number information of the target source code associated with the inline function identifier, includes:

[0013] Based on the second intermediate expression, the third line number information of the assembly file is obtained through the first pointer;

[0014] Based on the third line number information, the first line number information in the target source program code associated with the second intermediate expression is obtained through the second pointer;

[0015] Based on the first line number information, the second line number information in the target source code associated with the inline function identifier is obtained through the third pointer.

[0016] Optionally, the extended opcode of the debug information data segment includes an inline information comment entry; the inline information comment entry includes a first parameter and a second parameter; the first parameter is used to record the offset of the current function in the debug string, and the second parameter is used to record different inline positions of the same line number information in the target source program code.

[0017] Optionally, before generating the debug information data segment in the target file according to a preset debug data format, the method further includes:

[0018] Create an inline identifier variable;

[0019] Update the inline identifier value of the inline identifier variable when switching between the program counter and the line number;

[0020] Use the file index and line number as keys and the inline identifier value as the value for key-value mapping;

[0021] The step of generating the debugging information data segment according to the preset debugging data format includes:

[0022] The inline identifier value of the file index and line number mapping in the second line number information is filled into the second parameter of the debug information data segment to obtain the debug information data segment.

[0023] Optionally, the debug information data segment further includes: a special code entry; the special code entry is used to switch the program counter and line number, and the inline identifier value of the inline identifier variable is updated each time the special code entry is generated.

[0024] Optionally, it also includes:

[0025] The line number information of the assembly file is stored using a chain structure; wherein, the chain structure includes the second intermediate expression and the line number information recording unit; the line number information recording unit includes: a first sub-unit, a second sub-unit, and a third sub-unit;

[0026] The first sub-unit is used to record the third row number information;

[0027] The second subunit is used to record the first row number information;

[0028] The third sub-unit is used to record the second row number information;

[0029] The first subunit, the second subunit, and the third subunit all include a category field, which is used to characterize whether the line number information recording unit records the line number information of the assembly file or the line number information of the target source program code.

[0030] Optionally, it also includes: linking the target file to obtain an executable program.

[0031] Secondly, this application provides a software debugging method, applied to a target file as described in the first aspect, or an executable program or a dump file generated by the execution of the executable program as described in the first aspect, comprising: debugging the target file / executable program / dump file using a debugger according to debugging instructions, so as to parse the debugging information data segment in the target file / executable program / dump file.

[0032] Optionally, the debugger's data structure includes: fields for an extended line number state machine and fields for an extended line number table entity;

[0033] The extended row number state machine field is used to store the inline information of the inline information annotation table entry record;

[0034] The fields of the extended line number table entity are used to store the mapping relationship between the line number of the inline information and the program counter.

[0035] Optionally, the fields of the extended line number state machine include: inline function position identifier, function name offset, and inline function stack;

[0036] The inline function position identifier is used to record the position of the current function caller in the inline function stack;

[0037] The function name offset is used to record the offset of the caller's function name string within the debug string;

[0038] The inline function stack is used to record the state of the line number program.

[0039] Optionally, the inline function stack includes: a file, line numbers, and a program counter;

[0040] The file is used to record the filename of the target source code;

[0041] The line number is used to record the line number of the target source program code;

[0042] The program counter is used to record the address of the currently executing instruction.

[0043] Optionally, the fields of the extended line number table entity include: inline line number, inline file name, inline function name, and inline program counter;

[0044] The inline line number is used to record the line number of the inline function;

[0045] The inline filename is used to record the filename of the inline function;

[0046] The inline function name is used to record the function name of the current inline function caller;

[0047] The inline program counter is used to record the program counter of the current inline function caller.

[0048] Optionally, parsing the debug information data segment in the target file / executable program / dump file includes:

[0049] Maintain the line number state machine, which is used to track the state of the line numbering program;

[0050] Traverse the debug information data segment;

[0051] The inline function stack records the current filename, line number, and program counter;

[0052] If the current program counter is located within an inline function, then the function name, line number, file name, and program counter of the caller of the current inline function are obtained through the inline function stack.

[0053] Record information about the row number table entity and its extended inline information.

[0054] Optionally, it also includes:

[0055] Retrieve the corresponding line number table entity based on the current program counter;

[0056] If the row number table entity contains first inline information, then print the first inline information.

[0057] Optionally, printing the first inline information includes:

[0058] Obtain the function name and first inline information of the current inline function based on the current program counter, and print the function name and the first inline information;

[0059] Retrieve the second inline information of the inline function based on the filename, line number, and program counter of the current inline information;

[0060] If the second inline information is not empty, then update the current program counter to the program counter in the second inline information at this time.

[0061] Thirdly, this application provides a software compilation apparatus, comprising:

[0062] The assembly module is used to generate a first intermediate representation containing debugging information based on the target source code; if the debugging information contains inline function identifiers, it generates first line number information and inline function information to obtain an assembly file; the inline function information includes: the function name corresponding to the first line number information, and the second line number information corresponding to the inline function identifier;

[0063] The compilation module is used to compile the assembly file to obtain an object file; the debugging information data segment in the object file includes entries that record inline function information.

[0064] Fourthly, this application provides a software debugging apparatus, comprising: an application to a target file as described in the first aspect, or an executable program as described in the first aspect, or a dump file generated by the execution of the executable program, comprising:

[0065] The execution module is used to debug the target file / executable program / dump file according to the debugging instructions, so as to parse the debugging information data segment in the target file / executable program / dump file.

[0066] Fifthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any of the first or second aspects.

[0067] Sixthly, this application provides a computer program product including a computer program that, when executed by a processor, implements the method as described in any of the first or second aspects.

[0068] The software compilation method, debugging method, apparatus, storage medium, and program product provided in this application, when generating assembly file output line number information, if the debugging information corresponding to the line number information contains an inline function identifier, it indicates the presence of inline information. In this case, the function name calling the inline function and the line number information corresponding to the inline function identifier are further generated to ensure correct generation of inline information when generating the assembly file. The assembly file containing inline information is further compiled into an object file, and the inline information is recorded in the debugging information data segment of the object file. This assists developers in correctly displaying inline information during debugging by parsing the debugging information data segment of the object file, improving the effectiveness of code debugging. Attached Figure Description

[0069] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0070] Figure 1 This is a schematic diagram illustrating an application scenario involved in an embodiment of this application;

[0071] Figure 2 A flowchart illustrating a software compilation method provided in an embodiment of this application;

[0072] Figure 3 This application provides a schematic diagram of a structure for storing row number information.

[0073] Figure 4 A schematic diagram illustrating the process of generating a row number table provided in this application embodiment;

[0074] Figure 5 A flowchart illustrating the printing of inline information provided in this application embodiment;

[0075] Figure 6 This is a schematic diagram of the structure of a software compilation device provided in an embodiment of this application;

[0076] Figure 7 This is a schematic diagram of a software debugging device provided in an embodiment of this application.

[0077] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0078] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0079] Figure 1 This is a schematic diagram illustrating an application scenario involved in an embodiment of this application. For example... Figure 1 As shown, the software compilation method provided in this application is applied to software compilation scenarios. Developers use software compilation tools installed on electronic devices to convert target source code into machine code to generate target files. For ease of debugging and error tracking, it is usually necessary to retain line number information of the source code in the generated machine code. Developers can debug the target file using software debugging tools installed on electronic devices to understand the program's running status, identify and fix errors and performance issues, and improve software quality and reliability. The target source code here can be any type: C source file, C++ source file, WAN C source file, etc.

[0080] Currently, inline functions are a common optimization technique in software development, reducing the overhead of function calls by directly inserting function code at the call point. However, using inline functions can bring certain difficulties during debugging because the code of the inline function no longer exists as an independent function after compilation, but is embedded in the code that calls it.

[0081] In some examples, the compiled object files, when debugged using software debugging tools, output debug information data segments that, while containing the location of the assertion failure and related function information, do not output information about the called inline functions. Therefore, the output debug information cannot determine which line of the inline function was called, making the debug information inaccurate or incomplete, and failing to meet the developer's debugging needs.

[0082] In view of this, this application proposes a software compilation method that, when generating an assembly file, if inline information exists, further records the inline information in the assembly file and transmits it to the object file, thereby generating complete debugging information to assist developers in parsing the debugging information during software debugging, thereby more accurately locating problems in the program.

[0083] It should be understood that the software compilation method of this application embodiment can be used in any scenario where compilation of target source code can be performed. The execution subject of this application embodiment can be a software compilation tool, or an electronic device or compilation system with the software compilation tool installed. The following description uses a software compilation tool as an example.

[0084] The technical solution of this application and how it solves the above-mentioned technical problems will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.

[0085] Figure 2 This is a flowchart illustrating a software compilation method provided in an embodiment of this application. Figure 2 As shown, the method may include, for example, the following steps:

[0086] S201. Generate a first intermediate representation containing debugging information based on the target source code.

[0087] The target source code here can be code written in any high-level language to implement various functions, such as C, C++, or Bang C. For example, the target source code can be used for data transfer and vector addition. The target source code can be stored in an electronic device as a corresponding target source file, such as a C source file, C++ source file, or Bang C source file. In the following embodiments, the target source instructions are located in the i-th row and j-th column of the target source code, also referred to as the i-th row and j-th column of the target source file.

[0088] The first intermediate representation can be, for example, an intermediate representation language situated between the target source code and machine code, such as a Low Level Virtual Machine Intermediate Representation (LLVM IR). The first intermediate representation contains complete debugging information. This debugging information may include the register mapping between the target source code and the first intermediate representation, as well as the line number mapping between the target source code and the first intermediate representation.

[0089] In one example, the i-th line of target source code is converted to the j1-th line or the first intermediate expression from the j1-th line to the j2-th line. That is, the mapping relationship between the target source code line number and the first intermediate expression line number is: the i-th line of target source code is mapped to the j1-th line or the first intermediate expression 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 line number of the target source code. j1 is an integer greater than or equal to 1 and less than the total line number of the first intermediate expression, and j2 is an integer greater than j1 and less than or equal to the total line number of the first intermediate expression. In other words, one line of target source code can be mapped to one line of first intermediate expression, or one line of target source code can be mapped to multiple lines of first intermediate expression.

[0090] The mapping relationship between the target source program code register and the first intermediate expression register can be, for example, that target source program register a is mapped to the first intermediate expression register b1, or target source program register a is mapped to the first intermediate expression registers b1 to b2. That is, one target source program register is mapped to one first intermediate expression register, or it can be mapped to two or more first intermediate expression registers. Here, the target source program register and the first intermediate expression register can be virtual registers.

[0091] In one example, debugging information can include the location of the target source program instruction corresponding to the LLVM IR instruction within the entire target source file. This includes, for example, the line number and column number of the target source program instruction in the target source code, the function information corresponding to that location, and the location where the function is called if it is an inline function. For instance, debugging information can be attached to the LLVM IR instruction using metadata tags, such as "!dbg". These metadata tags contain the location information of the target source program instruction corresponding to the LLVM IR instruction within the entire target source code. For example, a function call in the target source code corresponding to an LLVM IR instruction, associated with the debugging information "!15", would look like this:

[0092] ! 15=! DILocation(line:60,column:3,scope:!16,inlinedAt:!18)

[0093] ! 18=distinct! DILocation(line:9,column:3,scope:!8)

[0094] In the debug information, "!DILocation" indicates the debug information location, which describes the position of the LLVM IR instruction in the target source code. "inlinedAt" is a field of "!DILocation," used as an inline function identifier to indicate whether the location is part of an inline function call. "!15" indicates that the LLVM IR instruction is located at line 60, column 3 in the target source code. This location belongs to the scope described by "!16," and it is inline. The location where the inline information is called is recorded by the debug information in "!18." "!18" indicates that the LLVM IR instruction is located inline at line 9, column 3 in the target source code. This location belongs to the scope described by "!8." Based on the information recorded in "!16", the function name of the target source program instruction corresponding to the current LLVM IR instruction can be obtained, for example, "__bang_add", as well as the file index of the target source file where the target source program instruction is located, for example, 3 (corresponding to the file path of file3); based on the information recorded in "!8", the function name of the inline function called by the target source program instruction corresponding to the current LLVM IR instruction can be obtained, for example, "kernel", as well as the file index of the target source file where the inline function called is located, for example, file index 1 (corresponding to the file path of file1).

[0095] Therefore, by using the complete index, we can determine that the target source program instruction corresponding to "!15" is located at line 60, column 3 of file3, and the inline information "!18" is located at line 9, column 3 of file1. The function name of the target source program instruction corresponding to the current LLVM IR instruction is, for example, "__bang_add".

[0096] In summary, this debugging information can help developers trace the specific location of the first intermediate expression instruction in the target source code and the inlining information of inline functions.

[0097] One possible implementation is that developers can generate the first intermediate representation by triggering compilation directives. Possible compilation directives include: the compiler name, the target source file name, the target architecture, enabling advanced optimizations (-O3), generating only debug information including line numbers (-gline-directives-only), generating an LLVM IR file (-emit-llvm), and generating code only for the device (`--bang-device-only`). Using these compilation directives, the software compilation tool can compile the target source file and generate the first intermediate representation, the LLVM IR.

[0098] S202. Detect whether the debugging information contains an inline function identifier. For example, in the debugging information of the first intermediate expression, the inline function identifier inlinedAt can be used to describe whether the location of the target source program instruction corresponding to the first intermediate expression instruction is part of an inline function call. The metadata identifier corresponding to the inline function identifier inlinedAt can indicate the location where the inline function is called in the target source program code. If the inline function identifier inlinedAt of the debugging information is not empty, it means that the debugging information contains an inline function identifier.

[0099] If so, proceed with steps S203 and S204.

[0100] S203. Generate the first line number information and inline function information to obtain the assembly file; the inline function information includes: the function name corresponding to the first line number information, and the second line number information corresponding to the inline function identifier.

[0101] Software compilation tools can further convert the first intermediate expression into an assembly file. An assembly file is a source code file written in assembly language, typically containing one assembly instruction per line. When converting the first intermediate expression into an assembly file, the software compilation tool can also generate a mapping relationship between the first intermediate expression and the instructions in the assembly file, thereby obtaining debugging information for both the first intermediate expression and the assembly file. This debugging information includes, but is not limited to, the line number mapping relationship and register mapping relationship between the instructions in the first intermediate expression and the assembly file. One possible implementation is that developers can generate the assembly file by triggering compilation instructions. Possible compilation instructions include: compiler instructions, optimization options, debugging information, input files, and output files. For example, a compilation instruction could be `cncc-O3-gline-directives-only-S–emit-llvm test.ll -o test.s`, which can compile a first intermediate expression file named `test.ll` into an assembly file named `test.s` and generate debugging information. Specifically,

[0102] First, the first line number information is generated based on the first intermediate expression instruction. For details, please refer to the preceding explanation; it will not be repeated here.

[0103] Then, when generating the first line number information, if the inline function identifier is not empty, further inline function information is generated to produce an assembly file. The inline function information may include: the function name corresponding to the first line number information, and the second line number information corresponding to the inline function identifier. When the debugging information in the first intermediate expression contains the inline function identifier, the generated assembly file may include: the function name corresponding to the first line number information, the second line number information, the file path of the target source file corresponding to the first intermediate expression instruction, the first line number information, and the assembly instruction.

[0104] The function name corresponding to the first line number can be the function name corresponding to the assembly instruction corresponding to the first line number. As mentioned before, for example, the function name of the target source program instruction corresponding to the assembly instruction with the current first line number is "__bang_add". In the assembly file, for example, func_name can be used to represent the function corresponding to the current assembly instruction, and Linfo_string1 is used to record the function name corresponding to the current assembly instruction. As mentioned before, continuing with the example of a function call in the target source program code corresponding to an LLVM IR instruction, associated with the debugging information "!15", through the complete index, we can determine that the position of the target source program instruction corresponding to "!15" is the 60th line and the 3rd column of file3. The generated first line number information is: first file index 3, first line number 60, first column number 3. The function name of the target source program instruction corresponding to the current LLVM IR instruction is, for example, "__bang_add", which is the function name corresponding to the first line number.

[0105] The second line number information can indicate the location where the inline function is called. For example, it could include the second file index, second line number, and second column number of the target source file containing the instruction called by the inline function. The second file index can be the index corresponding to the file path of the target source file containing the instruction called by the inline function. For instance, debugging information can include a mapping between the file path of the target source file and the second file index, which identifies the file path of the target source file containing the instruction called by the inline function. The second line number is the line number of the instruction called by the inline function within the entire target source code. The second column number is the column number of the instruction called by the inline function within the entire target source code. This second line number information associates the inline function code with its call location, allowing the display of the inline function's call location within the target source code during subsequent debugging. As mentioned earlier, continuing with the example of a function call in the target source code corresponding to an LLVM IR instruction, associated with the debugging information "!15", the complete index determines that the inline information "!18" corresponds to the 9th line and 3rd column of file1. The generated second line number information is: second file index 1, second line number 9, second column number 3.

[0106] S204. Compile the assembly file to obtain the object file; the debugging information data segment in the object file includes entries that record inline function information.

[0107] Software compilers translate each assembly instruction in assembly code into corresponding machine instructions, generating binary machine code, also known as binary code or object code. Object files can contain machine code, debugging information, etc., and can be, for example, CNBin files. During the compilation process, the compiler can also generate debugging information. This information records the line number mapping between assembly instructions and binary instructions, as well as the mapping between the registers in the assembly code and the registers in the object file. The registers in the assembly code are also called assembly registers, and the registers in the object file are also called physical registers. Debugging information helps in understanding the correspondence between the machine code in the object file and the target source code during debugging. One possible implementation is that developers can generate object files by triggering compilation instructions. One possible compilation instruction is CNAS, which includes: the compiler name, optimization options, debugging information, input file, output file, etc. For example, a compilation instruction like `cnas-O3-gline-directives-only-c test.so test.o` can compile an assembly file named `test.s` into an object file named `test.o` and generate debugging information.

[0108] During the compilation process of generating assembly files from target source code, software compilation tools establish a line number mapping between the target source code and the assembly code. Similarly, during the compilation process of generating object files from the assembly files, they establish a line number mapping between the assembly code and the machine code. This mapping can be obtained during debugging. For example, line i of the target source code maps to line j of the assembly code. After the assembly code is converted to machine code, line j maps to line k of the machine code. This method establishes the line number mapping between the target source code and the machine code.

[0109] For example, target source program register A1 can be mapped to assembly register B1. The physical resource allocated to assembly register B1 is, for example, physical register C1; that is, assembly register B1 is mapped to physical register C1. Software compilation tools can determine that target source program register A1 is mapped to physical register C1. Software compilation tools can determine the mapping relationship between target source program registers and physical resources in the above manner.

[0110] Software compilation tools can generate debugging information based on the line number mapping relationship between the target source code and the machine code, and the register mapping relationship between the target source code and the machine code.

[0111] In object files, debugging information is typically stored in specific data segments, such as the debug information data segment `.debug_line`. The debug information data segment in an object file contains a mapping between line numbers in the target source code and line numbers in the machine code. The information in the debug information data segment helps map the machine code back to the target source code location when debugging the object file, allowing developers to view and control the execution of the target source code during debugging.

[0112] In this embodiment of the disclosure, the debug information data segment in the object file includes entries that record inline function information. This embodiment can transmit inline information recorded in the assembly file to the object file, thereby generating complete debug information in the object file. This assists developers in correctly displaying the information of inline functions in the target source code when debugging the object file.

[0113] In summary, the software compilation method provided in this application, when generating assembly file output line number information, indicates the presence of inline information if the debugging information corresponding to that line number information contains an inline function identifier. In this case, the function name calling the inline function and the line number information corresponding to the inline function identifier are further generated to ensure correct generation of inline information when generating the assembly file. The assembly file containing inline information is then compiled into an object file, and the inline information is recorded in the debugging information data segment of the object file. This allows developers to correctly display the inline information during debugging by parsing the debugging information data segment of the object file, improving the effectiveness of code debugging.

[0114] If the software compiler determines that the debugging information of the first intermediate expression does not contain inline function identifiers, then the first line number information can be generated based on the first intermediate expression instructions. The first line number information can be the location information of the target source program instruction corresponding to any assembly instruction within the entire target source program code. For example, the first line number information may include: the first file index, the first line number, and the first column number, but not inline information. The first file index can be an index pointing to the file path of the target source file. For example, the debugging information may include a mapping relationship between the file path of the target source file and the first file index, through which the specific file path of the target source file can be identified. The first line number is the line number in the target source program code, indicating the line position of one of the target source program instructions corresponding to the assembly instruction within the entire target source program code. The first column number is the column number in the target source program code, indicating the column position of one of the target source program instructions corresponding to the assembly instruction within the entire target source program code. The first line number information can associate the position of the assembly instruction with its corresponding target source program instruction within the entire target source program code, allowing the position of the target source program code to be displayed during subsequent debugging. As mentioned earlier, the debugging information in the first intermediate expression contains the line number mapping relationship between the target source code and the first intermediate expression. Therefore, the first line number information can be generated based on the debugging information in the first intermediate expression. Continuing with the example of a function call in the target source code corresponding to an LLVM IR instruction, associated with the debugging information "!15", the location of the target source instruction corresponding to "!15" can be determined through the complete index to be line 60 and column 3 of file3. The generated first line number information is: first file index 3, first line number 60, first column number 3.

[0115] When the debugging information in the first intermediate expression does not include inline function identifiers, the generated assembly file may include: the file path of the target source file corresponding to the current first intermediate expression instruction, the first line number information, assembly instructions, etc.

[0116] Furthermore, before generating the second line number information corresponding to the inline function identifier, the software compiler can check whether the same inline function identifier already exists in the debug information. If the same inline function identifier already exists in the debug information, the second line number information will not be generated.

[0117] If the same inline function identifier already exists in the debugging information, it can be assumed that the inline information of the current assembly instruction overlaps with the inline information of the previous assembly instruction. Based on the inline information of the previous assembly instruction, the inline information of the current assembly instruction can be effectively analyzed. It is unnecessary to continue generating the second line number information of the current assembly instruction. At this time, the generation of the second line number information can be stopped to reduce redundant information in the generated assembly file.

[0118] As an example, software compilation tools may also include the following steps when converting assembly files into object files:

[0119] S2041. Generate the second intermediate expression based on the assembly file.

[0120] Each assembly instruction typically includes: the instruction's opcode, operands, destination register, source register, etc. Each assembly instruction can correspond to one or more second intermediate expressions. When generating a second intermediate expression from an assembly instruction, the second intermediate expression can also include: the instruction's opcode, operands, destination register, source register, etc.

[0121] When a software compiler generates a second intermediate representation based on assembly instructions, it can associate the line number information of the assembly file (such as file index, line number, column number, etc.) with the second intermediate representation.

[0122] In one example, line i of the target source code maps to line j of the assembly code. After the assembly code is converted to a second intermediate representation, line j of the assembly code maps to line p of the second intermediate representation. After the second intermediate representation is converted to machine code, line p of the second intermediate representation maps to line k of the machine code. Therefore, in the mapping of line i of the target source code to line p of the second intermediate representation, line i of the target source code maps to line k of the machine code. Based on this, we can establish the line number mapping relationship between the target source code and the second intermediate representation, as well as the line number mapping relationship between the target source code and the machine code.

[0123] Therefore, based on the second intermediate expression instruction, the line number information of the assembly file containing the corresponding assembly instruction can be obtained. Based on the assembly instruction, the line number information of the entire target source program code containing the corresponding target source program instruction can be obtained. Thus, the position of the corresponding target source program instruction within the entire target source program code can be obtained based on the second intermediate expression instruction. A chained structure is a data structure that can be used to record the relationships between instructions at different levels. Therefore, software compilation tools can use a chained structure to record line number information.

[0124] Each second intermediate expression can be associated with one or more linked structures, which record the location information of the second intermediate expression in different file levels. For example, for the second intermediate expression corresponding to an assembly instruction, the linked structure can record the line number information of the assembly file corresponding to the second intermediate expression, as well as the line number information of the target source code corresponding to the second intermediate expression. In one example: the line number information of the assembly file is stored using a linked structure; where the linked structure includes the second intermediate expression and line number information recording units; the line number information recording unit includes: a first subunit, a second subunit, and a third subunit; wherein, the first subunit is used to record the third line number information; the second subunit is used to record the fourth line number information; and the third subunit is used to record the fifth line number information.

[0125] The third line number information is the location information of the assembly instruction corresponding to the second intermediate expression instruction in the entire assembly file. For example, it includes the file name of the assembly file and the third line number. The third line number can be the line number of the assembly instruction corresponding to the second intermediate expression instruction in the entire assembly file.

[0126] The fourth line number information indicates the location of the target source program instruction corresponding to the second intermediate expression instruction within the entire target source program code. This fourth line number information may include, for example, the fourth file index, the fourth line number, and the fourth column number, but does not include inline information. The fourth file index can be the index of the file path of the target source file where the target source program instruction corresponding to the second intermediate expression is located. The fourth line number is the line number of the target source program instruction corresponding to the second intermediate expression within the entire target source program code. The fourth column number is the column number of the target source program instruction corresponding to the second intermediate expression within the entire target source program code.

[0127] The fifth line number information indicates the location of the target source program instruction in the target source program code where the inline function corresponding to the second intermediate expression instruction is called. The fifth line number information may include, for example, the fifth file index, the fifth line number, and the fifth column number. The fifth file index can be the index corresponding to the file path of the target source file where the target source program instruction of the inline function is located. The fifth line number is the line number of the target source program instruction of the inline function within the entire target source program code. The fifth column number is the column number of the target source program instruction of the inline function within the entire target source program code. The first, second, and third subunits all include a category field, which indicates whether the line number information recording unit records the line number information of the assembly file / the line number information of the target source program code.

[0128] Figure 3 This is a schematic diagram of a structure for storing row number information provided in an embodiment of this application. Figure 3 As shown, taking the assembly instruction add.nram.f32, the corresponding assembly file line number is 16, and the location of this assembly instruction in the target source code is: fourth file index 3, fourth line number 60, fourth column number 3. The corresponding inline information is: fifth file index 1, fifth line number 9, fifth column number 3. This is used as an example for illustration.

[0129] The second intermediate expression instruction corresponding to the above assembly instruction can be add.nram.f32.

[0130] The first subunit, for example loc1, is used to store the location information of the assembly instructions corresponding to the second intermediate expression in the assembly file. For example, it may include: third line number information and a category field. The third line number information may include: the file name of the assembly file and the line number of the assembly file. The category field indicates that the first subunit records the line number of the assembly file.

[0131] The second subunit, for example loc2, is used to store the location information of the target source program instruction corresponding to the second intermediate expression in the entire target source program code. For example, it may include: the fourth line number information and a category field. The fourth line number information may include: the fourth file index, the fourth line number, and the fourth column number. The category field indicates that the second subunit records the line number of the target source program code.

[0132] When the target source program instruction corresponding to the fourth line number information recorded in the second subunit is an inline function, the software compiler adds a third subunit to the chain structure and uses the third subunit to record the location in the target source program code where the inline function corresponding to the fourth line number information is called.

[0133] The third subunit, for example loc3, is used to store the location information of the inline function corresponding to the second intermediate expression in the target source code. For example, it may include: the fifth line number information and a category field. The fifth line number information may include: the fifth file index, the fifth line number, and the fifth column number. The category field indicates that the third subunit records the line number of the target source code.

[0134] Linked structures allow for the dynamic addition or deletion of elements without the need to reallocate or move large amounts of data. Storing line number information in assembly files through linked structures simplifies management and facilitates expansion. By adding fields and pointers to the linked structure, debugging information containing inline information can be stored using three sub-units, which helps in generating correct debugging information.

[0135] S2042. By traversing the second intermediate expression, obtain the fourth line number information of the target source code associated with the second intermediate expression, and the fifth line number information of the target source code associated with the inline function identifier.

[0136] Continue to refer to Figure 3 The diagram shown illustrates the structure for storing line number information. The following explains how to obtain line number information from the target source code.

[0137] In one example, the software compiler converts the assembly file into a second intermediate representation and obtains the line number information corresponding to the second intermediate representation through a pointer. The following explains how to obtain the line number information corresponding to the second intermediate representation through a pointer.

[0138] As mentioned earlier, software compilation tools can record line number information corresponding to instructions at different levels using a chained structure. The chained structure consists of multiple nodes, each containing data and one or more pointers to other nodes. For example, taking the node storing the second intermediate expression as the starting node of the chained structure, the first pointer points to the next node in the chained structure, i.e., the first sub-unit; the first sub-unit stores the location information of the assembly file where the assembly instruction corresponding to the second intermediate expression is located, for example, the third line number, and the second pointer points to the next node in the chained structure, i.e., the second sub-unit; the second sub-unit stores the location information of the target source program instruction corresponding to the assembly instruction within the target source program code, for example, the fourth line number.

[0139] 1. The software compiler obtains the third line number information of the assembly file through the first pointer based on the second intermediate expression.

[0140] For example, the node storing the second intermediate expression is taken as the starting node of the chain structure. This node includes a first pointer, which can point to the next node of the chain structure, namely the first sub-unit. The first sub-unit stores the location information of the assembly file where the assembly instruction corresponding to the second intermediate expression is located, such as the third line number information. Therefore, according to the second intermediate expression, the third line number information of the assembly file can be obtained through the first pointer.

[0141] 2. Based on the third line number information, the software compilation tool obtains the fourth line number information in the target source program code associated with the second intermediate expression through the second pointer.

[0142] For example, the first subunit includes a second pointer, which can point to the next node in the chain structure, namely the second subunit. The second subunit stores the location information of the target source program code where the assembly instruction is located, such as the fourth line number. Therefore, the fourth line number information in the target source program code associated with the second intermediate expression can be obtained through the second pointer.

[0143] If the target source program instruction corresponding to the assembly instruction stored in the second subunit is not an inline function, then the second subunit is the last node of the chain structure; if the target source program instruction corresponding to the assembly instruction stored in the second subunit is an inline function, then the second subunit includes a third pointer, which points to the next node of the chain structure, namely the third subunit.

[0144] 3. Based on the fourth line number information, the software compilation tool obtains the fifth line number information in the target source code associated with the inline function identifier through the third pointer.

[0145] For example, when the assembly instruction stored in the second subunit corresponds to an inline function in the target source program, the second subunit includes a third pointer. This third pointer points to the next node in the chain structure, i.e., the third subunit. The third subunit stores the location information of the function called by the inline function within the target source program code, such as the fifth line number. Therefore, the fifth line number information in the target source program code associated with the inline function can be obtained through the third pointer. During debugging, the third pointer allows jumping from the current inline function's information to the caller's information, thus establishing a connection between line number information at different levels.

[0146] By obtaining the line number information in the target source code based on the second intermediate expression, the line number information of the assembly file can be obtained. Then, through pointer mapping, the position of the corresponding second intermediate expression in the target source code, as well as the position of the called inline function in the target source code, can be obtained.

[0147] It should be understood that when obtaining the line number of the target source program instruction associated with the second intermediate expression in the target source program code, all line number information recording units need to be considered, and the traversal order is from deep to shallow. For example, it can be from the third sub-unit to the second sub-unit. Because the first sub-unit records the line number information of the assembly file, while the debug information data segment only needs to record the mapping from the program counter to the line number of the target source program code, the first sub-unit does not need to be accessed.

[0148] The above describes how software compilers, during the conversion of assembly files into object files, generate a second intermediate representation. Based on this second intermediate representation, they obtain the location information of the target source program instruction corresponding to the assembly instruction within the target source program code (e.g., line number 4), and, when the target source program instruction corresponding to the assembly instruction is an inline function, the location information of the inline function being called within the target source program code (e.g., line number 5). The following describes another method for obtaining debugging information.

[0149] In one example, during the process of converting an assembly file into an object file, the software compilation tool records line number information through a chain structure and embeds the line number information in the chain structure into the object file, thereby generating complete debugging information in the object file, which facilitates debugging of the object file during the debugging phase.

[0150] S2043. Generate debugging information data segments according to the preset debugging data format and integrate them into the target file.

[0151] The default debug data format can be any standard format used for debugging information, such as DebuggingWith Attributed Record Formats (DWARF). DWARF includes multiple segments, each storing different types of debug information, such as the debug information data segment `.debug_line` and the debug string table `.debug_str`. The debug information data segment stores line number information of the target source code, including the mapping between machine code addresses and the corresponding filenames and line numbers of the target source code. For example, in DWARF format debug information, the debug information data segment `.debug_line` may include a line number program. The software compiler uses the line number program to describe the mapping between line numbers of the target source code and machine code addresses. For example, the line number program may include a series of instructions that the software compiler uses to establish the mapping between machine code addresses and line numbers of the target source code. During debugging, executing these instructions generates and updates a state machine. This state machine, for example, can be named "lnp_state_machine". It contains information such as the current line number, filename, and corresponding machine code address of the target source code. The state machine allows determination of the position of the currently executing target source code instruction within the entire target source code. The software compilation tool disclosed herein can generate debugging information data segments according to a preset debugging data format and integrate them into the target file. This can be used to map machine code addresses back to line numbers in the target source code during debugging of the target file.

[0152] In one example, the extended opcode of the debug information data segment includes an inline information comment entry, such as DW_LNE_annotate_inline_info, to record inline function information in the debug information; the inline information comment entry includes a first parameter and a second parameter; the first parameter is used to record the offset of the current function in the debug string, and the second parameter is used to record different inline positions of the same line number information in the target source program code.

[0153] The two parameters will be explained below.

[0154] (1) The first parameter, for example, FunctionNameOffset_1, is used to record the offset of the current function in the debug string .debug_str. The DWARF debug string .debug_str is used to store strings in the debug information. In DWARF, all strings are stored in a separate segment of .debug_str, which stores the Linfo_string entries for the function names corresponding to all assembly instructions in the assembly file. All records of strings are recorded with offsets in .debug_str, meaning there is an offset in the debug string .debug_str pointing to the corresponding string. Linfo_string is a string label that can be used to identify the location of a string in memory. During debugging, when it is necessary to display the function name or operation name of the current instruction, the Linfo_string label can be used to find the corresponding string. For example, "Linfo_string0" and "Linfo_string1" are two string labels that point to the strings "__memcpy" and "__bang_add" respectively. When encountering a memory copy operation during debugging, "Linfo_string0" can be used to display "__memcpy", providing an easily readable name during debugging.

[0155] (2) The second parameter, for example, ContextID_1, is used to record different inline positions of the same line number information in the target source code. This parameter is used to represent the unique ID of the current line number information. When the line number information in the same target source code is inlined in different positions, this parameter can obtain the accurate inline position.

[0156] If the data structure currently recording line number information contains inline information, then the offset relative to the debug string is filled into the first parameter to record the function name of the inline information; and the inline information is filled into the second parameter to record the inline position of the inline information.

[0157] The following explains how to fill inline information into the second parameter when generating the debug information data segment.

[0158] (1) Create an inline identifier variable GlobalContextID; this variable records the mapping relationship between file indexes and line numbers and the inline identifier value of the inline identifier variable GlobalContextID. The inline identifier variable can be a globally unique identifier. Each time a new inline function call is generated, the inline identifier value of the inline identifier variable will increment to ensure that each inline function call has a unique identifier. Different inline function calls can be distinguished by different inline identifier values.

[0159] (2) Update the inline identifier value of the inline identifier variable when switching between the program counter and the line number;

[0160] Switching the program counter can record changes in the program counter in the debugging information, so that when debugging the target file, machine code addresses can be mapped back to line numbers in the target source code.

[0161] In one example, the debug information data segment in the DWARF format also includes: a special code entry; this special code entry is used to switch the program counter and line number, and the inline identifier value of the inline identifier variable is updated each time a special code entry is generated. This method ensures that each special code entry has a unique identifier that identifies the mapping between the address and line number of each machine code.

[0162] (3) Use the file index fileno and line number line as keys and the inline identifier value of the inline identifier variable as values ​​to perform key-value mapping;

[0163] By establishing a mapping relationship between file index + line number and inline identifier value, different file indexes + line numbers correspond one-to-one with inline identifier values. The file index + line number allows for quick lookup of the corresponding inline identifier value, thus enabling accurate code location switching during debugging.

[0164] (4) Fill the inline identifier value of the file index and line number mapping in the fifth line number information of the target source program code associated with the inline function identifier into the second parameter of the debug information data segment .debug_line to obtain the debug information data segment .debug_line.

[0165] The key composed of the file index and line number is unique and corresponds one-to-one with the inline identifier value. When the line number information in the same target source code is inlined in different locations, it can correspond to different inline identifier values, so the accurate inline location can be obtained through the inline identifier value.

[0166] In one example, suppose there is an inline function "__bang_add" that is called inline in different places. When the software compiler generates the debug information data segment .debug_line, it generates a unique inline identifier value for each inline call, as shown below:

[0167] (1) The first time the inline function "__bang_add" is called:

[0168] The value of the inline identifier variable GlobalContextID is 1;

[0169] Record the mapping between the file index fileno + line number and the value of the inline identifier variable GlobalContextID;

[0170] The first parameter of the inline information comment entry, FunctionNameOffset_1, is set to the function name "__bang_add", and the second parameter, ContextID_1, is set to the value 1.

[0171] (2) When the inline function "__bang_add" is called for the second time:

[0172] The value of the inline identifier variable GlobalContextID is 2;

[0173] Record the mapping between the file index fileno + line number and the value of the inline identifier variable GlobalContextID;

[0174] The first parameter of the inline information comment entry, FunctionNameOffset_1, is set to the function name "__bang_add", and the second parameter, ContextID_1, is set to the value 2.

[0175] In this way, the inline identifier variable GlobalContextID ensures the uniqueness of each inline function call, and these contexts can be correctly identified and traced when the debugger parses the debug information data segment .debug_line.

[0176] In summary, the generated debug information data segment can record the offset of the function name corresponding to the first line number relative to the debug string using the first parameter, and the inline identifier value mapped to the second line number in the inline function identifier using the second parameter. Since each offset in the debug string points to a function name string, during debugging, by parsing the offset relative to the debug string in the first parameter, the function name corresponding to the first line number can be obtained; by parsing the inline identifier value in the second parameter, the second file index and second line number of the second line number can be obtained. Through these operations, the location of the inline function call can be determined during debugging.

[0177] Furthermore, software compilation tools can link one or more object files to generate an executable program that can run on the target platform. If an error occurs during the execution of this executable program, a dump file, such as a cndump file, will be generated. This dump file contains the memory state, register values, and call information at the time of the error. Object files can include host-side code, device-side code, library files, etc.

[0178] One possible implementation is that developers can generate an executable program by triggering a compilation directive. One possible directive is `cnlink`, which includes the compiler name, input file, and output file. The directive is as follows: `cnlink file1.o file2.o output`. This directive will link two object files named `file1.o` and `file2.o` to generate an executable program named `output`.

[0179] It should be understood that the embodiments of this application are only illustrative of the functions related to this application. In specific implementation, whether the software compilation tool has other functions is not limited in the embodiments of this application.

[0180] The following describes how to debug a target file, or an executable program or a dump file generated by running an executable program. The execution entity in this application embodiment can be a software debugging tool, or an electronic device or debugging system with the software debugging tool installed. The following description uses a software debugging tool as an example; a software debugging tool is also called a debugger.

[0181] Software debugging tools can receive debugging commands input by the user and debug the target file / executable program / dump file according to the debugging commands. Specifically, software debugging tools can parse the debugging information data segment in the target file / executable program / dump file and debug the target file / executable program / dump file according to the debugging information data segment.

[0182] The way a software debugging tool receives debugging commands from the user depends on how the user triggers those commands. For example, the user can trigger a debugging command by typing it in the keyboard, or by triggering a control that integrates debugging commands in the debugger's main interface. Accordingly, the software debugging tool receives the debugging command. Debugging commands can include, for example, setting breakpoints, running the program, or single-stepping through the code.

[0183] An executable program is generated by linking one or more object files, and therefore contains debugging information data segments contained in the object files. A dump file contains debugging information generated when the program crashes. Therefore, during debugging, the executable program or the dump file generated by the executable program can be debugged to parse the debugging information data segments in the object files / executable program / dump file, thereby diagnosing and repairing errors in the executable program.

[0184] As an example: The debugger's internal data structures include the line number state machine (lnp_state_machine) and the line number table entity (linetable_entry). As mentioned earlier, the debug information data segment can contain a line number program, which describes the mapping relationship between the target source code line numbers and machine code addresses. The line number state machine is used to track the state of the line number program. To support the debug information data segment with extended inline information comment entries, the debugger also needs to support parsing inline information comment entries during the debug information data segment parsing stage. The improved debugger data structure is shown below:

[0185] The debugger's data structure includes: fields for the extended line number state machine and fields for the extended line number table entity.

[0186] (1) The extended row number state machine field is used to store the inline information of the inline information annotation table entries.

[0187] For example, the fields of the extended line number state machine include: inline function position identifier ContextId_2, function name offset FunctionNameOffset_2, and inline function stack ContextStack.

[0188] The inline function location identifier ContextId_2 is used to record the position of the current inline function caller in the inline function stack; so that inline function information can be correctly displayed and processed during debugging.

[0189] The function name offset FunctionNameOffset_2 is used to record the offset of the caller function name string of the inline function in the debug string; the debugger can use the function name offset to find the function name in the debug information.

[0190] The inline function stack, ContextStack, is used to record the state of the line number program. Whenever an inline function is entered or exited, the debugger can update this stack. Different positions in the inline function stack correspond to the state of different line number programs, thereby helping the debugger maintain the call hierarchy of inline functions so that the call stack and inline function information can be displayed correctly during debugging.

[0191] In one example, the stack of an inline function can include: file, line number, and program counter;

[0192] The file is used to record the filename of the target source code. The filename can help debuggers or analysis tools quickly locate the source code file, making it easier for developers to view and understand the code. In some examples, the target source code is usually distributed across multiple files, and the filename can help distinguish the same function or variable names in different files.

[0193] Line numbers are used to record the line numbers of the target source code. Line numbers can pinpoint the specific location within the target source code, helping developers quickly find the problem. When errors or exceptions occur, line numbers can be used to generate detailed error reports, facilitating rapid problem fixing.

[0194] The program counter is used to record the address of the currently executing instruction.

[0195] By recording filenames, line numbers, and program counters on the inline function stack, debuggers can accurately display the call relationships and execution locations of inline functions.

[0196] By extending the fields of the line number state machine, it can now record inline information in addition to supporting the recording and storage of debugging information such as line numbers and program counters. Through the data recorded by the line number state machine, the filename, line number, and function name corresponding to the first line number in the target source code can be obtained.

[0197] (2) Fields of the extended line number table entity are used to store the mapping relationship between line numbers and program counters for inline information.

[0198] For example, the fields of the extended line number table entity include: inline line number, inline file name, inline function name, and inline program counter;

[0199] Inline line numbers are used to record the line numbers of inline functions;

[0200] Inline filename, used to record the filename of the inline function;

[0201] The inline function name is used to record the function name of the current inline function caller.

[0202] The inline program counter is used to record the program counter of the current inline function caller.

[0203] By extending the fields of the line number table entity, it can be made to support recording inline information in addition to supporting the recording of line numbers and program counter information.

[0204] The debugger uses the fields of the extended line number state machine and the extended line number table entity to support parsing the debug information data segment .debug_line with extended inline information.

[0205] The above describes how to extend the debugger's data structure to support recording inline information. The following explains how to use the extended data structure to parse the debug information data segment in the object file / executable / dump file during actual debugging.

[0206] The debugger's data structures include a linetable, which manages line number information for the target source code. It consists of multiple linetable_entry entities, and the linetable is generated by parsing the debug information data segment in the object file / executable / dump file. The following explains how the linetable is generated.

[0207] Example 4 is a schematic diagram illustrating the process of generating a row number table according to an embodiment of this application. Figure 4 As shown, the method may include, for example, the following steps:

[0208] S401. Maintain the line number state machine, which is used to track the state of the line number program. The line number state machine records the current debugging state, including: file name, line number, program counter, and extended inline information (inline function location identifier ContextId_2, function name offset FunctionNameOffset_2, inline function stack ContextStack).

[0209] Among them, the filename is used to record the name of the target source file currently being processed; the line number is used to record the line number of the target source program code currently being processed; the program counter is used to record the current machine instruction address; the inline function caller position identifier is used to record the mapping value between the file index and line number of the current inline function; the function name offset is used to record the offset of the current function in the debug string, and the function name of the current function can be obtained from the debug string based on the function name offset; and the inline function stack is used to record the call hierarchy of the inline functions.

[0210] By maintaining a line number state machine, machine instruction code can be mapped to the line number and filename of the target source program code based on the current state of the line number state machine.

[0211] S402. Traverse the debug information data segment. For example, an iterative traversal method can be used to read each record in the debug information data segment item by item. Based on each record in the debug information data segment, update the information of each parameter of the line number state machine, such as updating the current file name, line number, and program counter information.

[0212] When the inline function position flag is not 0, it means that the program counter is inside the inline function. At this time, information such as the function name, line number, file name, and program counter of the caller of the current inline function are obtained from the inline function stack.

[0213] S403. Record the current file name, line number, and program counter through the inline function stack.

[0214] If the current program counter is located within an inline function, the function name, line number, file name, and program counter of the caller of the current inline function are obtained through the inline function stack.

[0215] S404 Records information about the row number table entity and extended inline information.

[0216] Repeat steps S402-S404 until the debug information data segment traversal is complete.

[0217] The debugger uses a line number state machine to parse debug information data segments and maintains the current state information during the parsing process. A line number table entity records the mapping relationship from a line number to the program counter. By passing the state information from the line number state machine to the line number table entity, a complete mapping relationship from line number to program counter is generated, including expanded inline information. The line number table entity associates machine code addresses with target source program code line numbers, thus supporting various debugging operations such as breakpoint setting, single-step execution, source code display, and backtracking. The debugger can accurately trace and display the context information of inline function calls during debugging.

[0218] Furthermore, when the program encounters a breakpoint or exception during runtime, the debugger can print the parsed debugging information after generating a line number table from the debug information data segment in the object file / executable / dump file. If the line number table entity `linetable_entry` contains inline information, the debugger will recursively search for and print the call chain of the inline functions. Details are as follows.

[0219] Figure 5 This is a schematic diagram illustrating an inline information printing process provided in an embodiment of this application. For example... Figure 5 As shown, the method may include, for example, the following steps:

[0220] S501. Obtain the corresponding line number table entity based on the current program counter. As mentioned earlier, when the inline function position identifier is not 0, the line number table entity can obtain the function name, line number, file name, and program counter information of the caller of the current inline function from the inline function stack. Therefore, based on the information recorded in the line number table entity, it can be determined whether it contains inline information.

[0221] S502. Check whether the row number table entity contains the first inline information.

[0222] If so, proceed to step S503.

[0223] S503, Print the first inline information.

[0224] The first inline information can be the function name and inline information of the currently executing inline function, obtained from the current program counter. This inline information may include, for example, the filename of the target source file containing the currently executing function and the line number of the function in the target source program code.

[0225] S504. Obtain the second inline information of the inline function based on the file name, line number, and program counter of the current inline information.

[0226] The second inline information can be the inline information of the caller of the inline function corresponding to the first inline information. The second inline information and the first inline information can, for example, be nested. The second inline information may include, for example, the filename of the target source file containing the caller of the inline function corresponding to the first inline information, and the line number of the caller in the target source program code.

[0227] S505, Check if the second inline information is not empty.

[0228] If so, proceed to step S506. If the second inline information is not empty, it means that there is inline information in the layer below the layer where the inline function is located.

[0229] S506. Update the current program counter to the program counter in the second inline information at this time.

[0230] If inline information still exists in the inline function layer, then the program counter in the inline information at this time is taken as the current program counter, and step S502 is repeated to print the complete inline information.

[0231] As mentioned earlier, when compiling target source code to generate object files / executable programs, software compilation tools can generate debugging information according to a preset debugging data format, such as DWARF format. DWARF includes multiple segments, each storing different types of debugging information, such as the debugging information data segment .debug_line and the debugging string table .debug_str. Specifically, the debugging information data segment .debug_line can store the mapping relationship between machine code and line numbers in the target source code, while the debugging string table .debug_str can store the mapping relationship between machine code and strings in the debugging information. These strings can be, for example, variable names, function names, type names, file paths, etc.

[0232] When parsing debugging information in target files / executables / dump files, the debugger can extract strings from the debug string table `.debug_str` and line number information from the debug information data segment `.debug_line` based on the machine code. This generates a line number table, a symbol table `symtab`, to associate strings (such as variable names and function names) in the target source code with their corresponding line numbers. For example, the symbol table `symtab` can contain symbols like "kernel", "f1", "f2", "f3", and "__assert_fail" along with their respective line numbers in the target source code. The debugger uses the information in `symtab` to look up the corresponding function name and line number based on the current program counter. For instance, when the program counter reaches the machine code address corresponding to function `f3`, the debugger can use the information in `symtab` to parse the string and line number in the target source code corresponding to that machine code address. During debugging, user-readable function name parsing and line number information can be output.

[0233] The following example illustrates how the function `kernel`, as the top-level function, calls the inline function `f1`, which in turn calls the inline function `f2`, which in turn calls the inline function `f3`, and finally, `f3` calls the `assert` function. When the program encounters a breakpoint or exception during runtime, such as an `assert` failure, when the program executes `assert(0)`, since `0` is false, the `assert` function expands to a call to `__assert_fail`, where `__assert_fail` is the currently executing function. The inline function information is printed as follows:

[0234] (1) For example, the __assert_fail function is located on line 8259 of the file "bang_device_functions.h". Print the function name __assert_fail and the filename of the target source file bang_device_functions.h, line 8259. (2) The next level on the call stack is in function f3, located on line 5 of the file "test.mul". Print the function name, filename, and line number of function f3. (3) The next level on the call stack is in function f2, located on line 10 of the file "test.mul". Print the function name, filename, and line number of f2. (4) The next level on the call stack is in function f1, located on line 15 of the file "test.mul". Print the function name, filename, and line number of f1. (5) The top level is in function kernel, located on line 19 of the file "test.mul". Print the function name, filename, and line number of kernel.

[0235] By parsing and printing information layer by layer, the debugger can completely print out inline function information. This helps developers understand the call path when assertions fail, making it easier to locate and fix problems.

[0236] Printing inline information helps debuggers understand the correspondence between inline functions and machine code in the target source code, accurately locate the inline function where the problem lies, improve code readability and comprehension, and assist developers in accurately locating problems, thereby enabling more effective code debugging and optimization.

[0237] In summary, the debugger, through the fields of the extended line number state machine and the extended line number table entity, can support the parsing of debug information data segments with extended inline information comment entries, thereby associating machine code addresses with target source program code line numbers and enabling debugging operations on functions containing inline functions.

[0238] It should be understood that the embodiments of this application are only illustrative of the functions related to this application. In specific implementation, whether the software debugging tool has other functions is not limited in the embodiments of this application. Figure 6 This is a schematic diagram of a software compilation device provided in an embodiment of this application. Figure 6 As shown, the device may include, for example, an assembly module 601 and a compilation module 602. Optionally, the device may also include a linker module 603.

[0239] The assembler module 601 is used to generate a first intermediate representation containing debugging information based on the target source code; if the debugging information contains inline function identifiers, it generates first line number information and inline function information to obtain an assembly file; the inline function information includes: the function name corresponding to the first line number information, and the second line number information corresponding to the inline function identifier; the compiler module 602 is used to compile the assembly file to obtain an object file; the debugging information data segment in the object file includes entries that record inline function information.

[0240] One possible implementation is that, before generating the second line number information corresponding to the inline function identifier, the assembler module 601 is also configured not to generate the second line number information if the same inline function identifier already exists in the debugging information.

[0241] One possible implementation is that the compiler module 602 is specifically used to: generate a second intermediate expression based on the assembly file; obtain the first line number information of the target source code associated with the second intermediate expression and the second line number information of the target source code associated with the inline function identifier by traversing the second intermediate expression; generate a debug information data segment according to a preset debug data format and integrate it into the target file.

[0242] One possible implementation is that the compiler module 602 is specifically used to: obtain the third line number information of the assembly file through the first pointer based on the second intermediate expression; obtain the first line number information in the target source code associated with the second intermediate expression through the second pointer based on the third line number information; and obtain the second line number information in the target source code associated with the inline function identifier through the third pointer based on the first line number information.

[0243] One possible implementation is that the extended opcode of the debug information data segment includes an inline information comment entry; the inline information comment entry includes a first parameter and a second parameter; the first parameter is used to record the offset of the current function in the debug string, and the second parameter is used to record different inline positions of the same line number information in the target source program code.

[0244] In one possible implementation, before generating the debug information data segment in the target file according to the preset debug data format, the compiler module 602 is also used to create an inline identifier variable; update the inline identifier value of the inline identifier variable when switching the program counter and line number; perform key-value mapping using the file index and line number as keys and the inline identifier value as values; specifically, the compiler module 602 is used to fill the inline identifier value mapped by the file index and line number in the second line number information into the second parameter in the debug information data segment to obtain the debug information data segment.

[0245] One possible implementation includes the following in the debug information data segment: a special code entry; the special code entry is used to switch the program counter and line number, and the inline identifier value of the inline identifier variable is updated each time a special code entry is generated.

[0246] One possible implementation is that the compiler module 602 uses a chained structure to store the line number information of the assembly file; wherein, the chained structure includes a second intermediate expression and a line number information recording unit; the line number information recording unit includes: a first subunit, a second subunit, and a third subunit; the first subunit is used to record the third line number information; the second subunit is used to record the first line number information; the third subunit is used to record the second line number information; the first subunit, the second subunit, and the third subunit all include: a category field, which is used to indicate that the line number information recorded by the line number information recording unit is the line number information of the assembly file / the line number information of the target source program code.

[0247] One possible implementation is a linker module 603, which is used to link object files to obtain an executable program.

[0248] The apparatus provided in this application embodiment can perform the actions in the above software compilation method embodiment. Its implementation principle and technical effect are similar, and will not be described again here.

[0249] Figure 7This is a schematic diagram of a software debugging device provided in an embodiment of this application. Figure 7 As shown, the device may include, for example, a debugging module 701. Optionally, the device may also include at least one of the following modules: an acquisition module 702 and a printing module 703.

[0250] The debugging module 701 is used to debug the target file / executable program / dump file according to the debugging instructions, and to parse the debugging information data segment in the target file / executable program / dump file.

[0251] One possible implementation is that the debugger's data structure includes: fields of an extended line number state machine and fields of an extended line number table entity; the fields of the extended line number state machine are used to store the inline information of the inline information comment table entries; the fields of the extended line number table entity are used to store the mapping relationship between the line number of the inline information and the program counter.

[0252] One possible implementation is that the extended line number state machine includes the following fields: inline function position identifier, function name offset, and inline function stack; the inline function position identifier is used to record the position of the current function caller in the inline function stack; the function name offset is used to record the offset of the caller's function name string in the debug string; and the inline function stack is used to record the state of the line number program.

[0253] One possible implementation of the inline function stack includes: a file, line numbers, and a program counter; the file is used to record the filename of the target source code; the line numbers are used to record the line numbers of the target source code; and the program counter is used to record the address of the currently executing instruction.

[0254] One possible implementation is that the extended line number table entity includes the following fields: inline line number, inline file name, inline function name, and inline program counter; the inline line number is used to record the line number of the inline function; the inline file name is used to record the file name of the inline function; the inline function name is used to record the function name of the current inline function caller; and the inline program counter is used to record the program counter of the current inline function caller.

[0255] One possible implementation is the debugging module 701, which is specifically used to: maintain the line number state machine, which is used to track the state of the line number program; traverse the debugging information data segment; record the current file name, line number, and program counter through the inline function stack; if the current program counter is located in an inline function, obtain the function name, line number, file name, and program counter of the caller of the current inline function through the inline function stack; and record the information of the line number table entity and the extended inline information.

[0256] One possible implementation is that the acquisition module 702 is used to acquire the corresponding line number table entity according to the current program counter; and the printing module 703 is used to print the first inline information if the line number table entity contains the first inline information.

[0257] One possible implementation is the printing module 703, which is specifically used to: obtain the function name and first inline information of the current inline function based on the current program counter, and print the function name and the first inline information; obtain the second inline information of the inline function based on the file name, line number and program counter of the current inline information; if the second inline information is not empty, update the current program counter to the program counter in the second inline information at this time.

[0258] The apparatus provided in this application embodiment can perform the actions in the above software debugging method embodiment. Its implementation principle and technical effect are similar, and will not be described again here.

[0259] This application also provides a computer-readable storage medium, which may include various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk. Specifically, the computer-readable storage medium stores program instructions, which are used to implement the actions of the above-described software compilation method or software debugging method.

[0260] This application also provides a computer program product including executable instructions stored in a readable storage medium. At least one processor of an electronic device can read the executable instructions from the readable storage medium, and the at least one processor executes the executable instructions to cause the electronic device to perform the actions described in the software compilation method or software debugging method implementation.

[0261] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.

[0262] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

Claims

1. A software compilation method, characterized in that, include: Based on the target source code, generate a first intermediate representation containing debugging information; If the debugging information contains inline function identifiers, then the first line number information and inline function information are generated to obtain the assembly file; The inline function information includes: the function name corresponding to the first line number information, and the second line number information corresponding to the inline function identifier; The assembly file is compiled to obtain an object file; the debugging information data segment in the object file includes entries that record the inline function information.

2. The method according to claim 1, characterized in that, Before generating the second line number information corresponding to the inline function identifier, the method further includes: If the same inline function identifier already exists in the debugging information, the second line number information will not be generated.

3. The method according to claim 1, characterized in that, The process of compiling the assembly file to obtain the object file includes: Based on the assembly file, a second intermediate representation is generated; By traversing the second intermediate expression, the fourth line number information of the target source code associated with the second intermediate expression and the fifth line number information of the target source code associated with the inline function identifier are obtained; The debugging information data segment is generated according to the preset debugging data format and integrated into the target file.

4. The method according to claim 3, characterized in that, The step of obtaining the fourth line number information of the target source code associated with the second intermediate expression, and the fifth line number information of the target source code associated with the inline function identifier, includes: Based on the second intermediate expression, the third line number information of the assembly file is obtained through the first pointer; Based on the third line number information, the fourth line number information in the target source program code associated with the second intermediate expression is obtained through the second pointer; Based on the first line number information, the fifth line number information in the target source code associated with the inline function identifier is obtained through the third pointer.

5. The method according to claim 4, characterized in that, The extended opcode of the debug information data segment includes inline information comment entries; the inline information comment entries include a first parameter and a second parameter; the first parameter is used to record the offset of the current function in the debug string, and the second parameter is used to record different inline positions of the same line number information in the target source program code.

6. The method according to claim 5, characterized in that, Before generating the debug information data segment in the target file according to the preset debug data format, the method further includes: Create an inline identifier variable; Update the inline identifier value of the inline identifier variable when switching between the program counter and the line number; Use the file index and line number as keys and the inline identifier value as the value for key-value mapping; The step of generating the debugging information data segment according to the preset debugging data format includes: The inline identifier value of the file index and line number mapping in the fifth line number information is filled into the second parameter of the debug information data segment to obtain the debug information data segment.

7. The method according to claim 6, characterized in that, The debug information data segment further includes: a special code entry; the special code entry is used to switch the program counter and line number, and the inline identifier value of the inline identifier variable is updated each time the special code entry is generated.

8. The method according to any one of claims 4 to 7, characterized in that, Also includes: The line number information of the assembly file is stored using a chain structure; wherein, the chain structure includes the second intermediate expression and the line number information recording unit; the line number information recording unit includes: a first sub-unit, a second sub-unit, and a third sub-unit; The first sub-unit is used to record the third row number information; The second sub-unit is used to record the fourth row number information; The third sub-unit is used to record the fifth row number information; The first subunit, the second subunit, and the third subunit all include a category field, which is used to characterize whether the line number information recording unit records the line number information of the assembly file or the line number information of the target source program code.

9. The method according to any one of claims 1 to 7, characterized in that, Also includes: The target files are linked to obtain an executable program.

10. A software debugging method, characterized in that, Applied to the target file as described in any one of claims 1 to 8, or the executable program as described in claim 9 or the dump file generated by running the executable program, comprising: According to the debugging instructions, the target file / executable program / dump file is debugged using a debugger to parse the debugging information data segment in the target file / executable program / dump file.

11. The method according to claim 10, characterized in that, The debugger's data structure includes: fields for the extended line number state machine and fields for the extended line number table entity; The extended row number state machine field is used to store the inline information of the inline information annotation table entry record; The fields of the extended line number table entity are used to store the mapping relationship between the line number of the inline information and the program counter.

12. The method according to claim 11, characterized in that, The fields of the extended line number state machine include: inline function position identifier, function name offset, and inline function stack; The inline function position identifier is used to record the position of the current function caller in the inline function stack; The function name offset is used to record the offset of the caller's function name string within the debug string; The inline function stack is used to record the state of the line number program.

13. The method according to claim 12, characterized in that, The inline function stack includes: file, line number, and program counter; The file is used to record the filename of the target source code; The line number is used to record the line number of the target source program code; The program counter is used to record the address of the currently executing instruction.

14. The method according to claim 11, characterized in that, The fields of the extended line number table entity include: inline line number, inline file name, inline function name, and inline program counter; The inline line number is used to record the line number of the inline function; The inline filename is used to record the filename of the inline function; The inline function name is used to record the function name of the current inline function caller; The inline program counter is used to record the program counter of the current inline function caller.

15. The method according to claim 12, characterized in that, The step of parsing the debug information data segment in the target file / executable program / dump file includes: Maintain the line number state machine, which is used to track the state of the line numbering program; Traverse the debug information data segment; The inline function stack records the current filename, line number, and program counter; If the current program counter is located within an inline function, then the function name, line number, file name, and program counter of the caller of the current inline function are obtained through the inline function stack. Record information about the row number table entity and its extended inline information.

16. The method according to any one of claims 11 to 15, characterized in that, Also includes: Retrieve the corresponding line number table entity based on the current program counter; If the row number table entity contains first inline information, then print the first inline information.

17. The method according to claim 16, characterized in that, The printing of the first inline information includes: Obtain the function name and first inline information of the current inline function based on the current program counter, and print the function name and the first inline information; Retrieve the second inline information of the inline function based on the filename, line number, and program counter of the current inline information; If the second inline information is not empty, then update the current program counter to the program counter in the second inline information at this time.

18. A software compilation apparatus, characterized in that, include: The assembly module is used to generate a first intermediate representation containing debugging information based on the target source code; If the debugging information contains inline function identifiers, then the first line number information and inline function information are generated to obtain the assembly file; The inline function information includes: the function name corresponding to the first line number information, and the second line number information corresponding to the inline function identifier; The compilation module is used to compile the assembly file to obtain an object file; the debugging information data segment in the object file includes entries that record inline function information.

19. A software debugging device, characterized in that, Applied to the target file as described in any one of claims 1 to 8, or the executable program as described in claim 9 or the dump file generated by running the executable program, comprising: The execution module is used to debug the target file / executable program / dump file according to the debugging instructions, so as to parse the debugging information data segment in the target file / executable program / dump file.

20. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1 to 17.

21. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method described in any one of claims 1 to 17.