Disclosure of Invention
The invention aims to provide a non-invasive coverage rate statistical method for various processor architectures, which is used for solving the problem that coverage rate information cannot be acquired difficultly in the embedded software object code testing process.
The invention relates to a non-invasive coverage rate statistical method aiming at various processor architectures, which comprises the following steps: building an embedded software simulation running environment; analyzing various architecture target files and debugging information formats, acquiring debugging information formats corresponding to the processor, and acquiring embedded software source code target code corresponding relation information by analyzing the debugging information formats; analyzing the source code to obtain the branch information of the source code; acquiring coverage information, comprising: after the simulation execution starts, judging whether the current instruction is a branch instruction or not, if not, continuing to execute the instruction; if so, taking the current address as the end address of the basic block, and taking the start address and the end address of the basic block as indexes, and updating the coverage rate lookup table; and outputting the result of the statistical analysis of the coverage rate.
According to an embodiment of the present invention, a non-invasive coverage statistical method for multiple processor architectures is provided, wherein a debug information format middebug info is defined, and multiple debug information is converted into the debug information format middebug info after being analyzed, the debug information includes file information, function information, and source code and object code corresponding relationship information, wherein the file information includes a file name, a file path, an object code start address and an object code end address corresponding to a file, the function information includes a function name, a function start address, and a function end address, and the source code and object code corresponding relationship information includes a source code line number, and an object code start address and an object end address corresponding to the line source code.
According to an embodiment of the non-intrusive coverage statistical method for various processor architectures, the building of the embedded software simulation running environment comprises the following steps: simulating a target processor kernel instruction set, simulating an embedded system peripheral and controlling a simulation process; the simulation of the target processor kernel instruction set adopts a dynamic binary compilation method based on LLVM to realize the heterogeneous execution of a target instruction under a Windows/Intel host machine architecture, and the target code is separated from the original hardware execution environment; the embedded system peripheral simulation is used for realizing the simulation of target processor peripheral equipment, and comprises RS-422 and RS-485 serial port equipment simulation, switching value equipment simulation and storage system simulation; the simulation process control adopts a unified clock scheduling algorithm to realize the execution control and the cooperative operation of all components of the virtual environment.
In an embodiment of the present invention, a method for non-intrusive coverage statistics for multiple processor architectures, parsing multiple architecture target files and debug information formats comprises: establishing a three-level structure information table with file, function and line number information; (1) analyzing a target file of a plurality of processors, determining the type of debugging information according to the structure of the target file, and reading the debugging information; (2) analyzing the debugging information formats of Dwarf1, Dwarf2, Dwarf3, sta, COFF and OMF51, and converting the debugging information formats into a debugging information format MidDebugInfo; (3) reading debugging information in a debugging information format MidDebugInfo, and judging the type of a current debugging information node; (4) judging whether the current debugging information node is a file start type node or not, if so, creating a file information recording structure, writing a target code start address corresponding to the file into the current file information recording structure, executing the step (3), and if not, executing the step (5); (5) judging whether the current debugging information node is a function starting type node or not, if so, creating a function information recording structure, writing a target code starting address corresponding to a function into the current function information recording structure, inserting the current function information structure into a current file information recording mechanism, and executing the step (3), otherwise, executing the step (6); (6) judging whether the current debugging information node is a line number information type node, if so, creating a line number information recording structure, inserting the current line number information structure into a current function information recording mechanism, and executing the step (3), otherwise, executing the step (7); (7) judging whether the current debugging information node is a function end type node or not, if so, writing the target code end address corresponding to the function into the current function information recording structure, executing the step (3), and if not, executing the step (8); (8) judging whether the current debugging information node is a file end type node or not, if so, writing an end address of the target code corresponding to the file into the current file information recording structure, and executing the step (9); (9) and (4) judging whether the reading of the debugging information is finished, if not, executing the step (3), otherwise, starting to analyze the source code to obtain the branch information of the source code.
In an embodiment of the non-intrusive coverage statistics method for multiple processor architectures according to the present invention, parsing the source code branch information comprises: acquiring source code path information; and reading in the source files one by one according to the three-level query structure table, judging the branch information of the source code line corresponding to the line number information node, and acquiring the branch condition of the source code.
In an embodiment of the present invention, a non-invasive coverage statistics method for various processor architectures is provided, wherein the coverage information output format is: a basic block start address, a basic block end address, a number of executions, a branch instruction address, and branch information.
According to an embodiment of the non-intrusive coverage rate statistical method for various processor architectures, a file for recording coverage rate information is read according to a three-level structure information table of files, functions and line number information, and a coverage rate statistical analysis result is generated according to the corresponding relation between a source code and a target code and the branch information of a source file.
In one embodiment of the present invention, a non-intrusive coverage statistics method for multiple processor architectures is provided, wherein the coverage statistics output provides instruction fetching, decoding, disassembling, and performing information parsing to generate a coverage statistics analysis result.
According to an embodiment of the present invention, a basic block of object codes is used as a minimum statistical unit, the basic block includes a start address, an end address, a branch instruction address, execution times and branch information, and one basic block includes one or more lines of object codes corresponding to source codes.
In an embodiment of the non-intrusive coverage statistics method for various processor architectures according to the present invention, obtaining coverage information comprises: (a) running an embedded simulation environment and loading a target file into a simulation memory; (b) simulating the execution start, and taking the execution start address as the start address of the first basic block; (c) reading and translating the instruction, executing the current instruction and judging whether the current instruction is a branch instruction, if not, continuing to execute the step (c), and if so, executing the step (d); (d) the address corresponding to the branch instruction is a basic block end address, and the start address and the end address of the current basic block and the branch information of the branch instruction are recorded; (e) using the starting address and the ending address of the basic block as indexes, inquiring the position of the current basic block in a three-level coverage rate information table, determining a line number information structure corresponding to the basic block, and adding the execution times of the corresponding line number information structure together to update branch information; (f) judging whether the coverage rate is generated or not, if not, continuing to execute the step (c), and if so, executing the step (g); (g) and writing the information recorded in the coverage rate information lookup table into a file of a specified path in a specific format, and suspending simulation execution.
The invention aims to provide a non-invasive coverage rate statistical method for various processor architectures, which converts different types of debugging information formats into universal type debugging information by analyzing the types of target files and the types of the debugging information formats under different processor architectures, acquires coverage rate execution information according to a processor virtualization simulation system, and finally completes the coverage rate statistical analysis function, makes up the defects of the existing coverage rate statistical analysis tool, and meets the requirements of coverage rate statistical analysis under various scenes.
Detailed Description
In order to make the objects, contents, and advantages of the present invention clearer, the following detailed description of the embodiments of the present invention will be given in conjunction with examples.
The invention relates to a non-invasive coverage rate statistical method aiming at various processor architectures, which comprises the following steps:
the method for building the embedded software simulation running environment comprises the following steps:
the embedded software simulation running environment adopts the virtualization simulation technology to realize the high-precision and high-performance simulation of a target system, provides the virtualization running environment of the embedded software, and records the instruction execution process and the branch information, and mainly comprises the following steps: the method comprises the steps of target processor kernel instruction set simulation, embedded system peripheral simulation and simulation process control.
Analyzing various architecture target files and debugging information formats comprises:
the analysis of the multiple architecture target files and the debugging information formats mainly analyzes the file format and the debugging information format related to the mainstream embedded processor, acquires the debugging information format corresponding to the processor by analyzing the file format, and acquires the embedded software source code target code corresponding relation information by analyzing the debugging information format.
The mainstream embedded software relates to a plurality of debugging information formats, in order to facilitate the statistics and output of the coverage rate information of the embedded software, a new debugging information format (MidDebugInfo) is defined, and the plurality of debugging information are converted into the debugging information format after being analyzed. The debugging information mainly comprises file information, function information and source code and target code corresponding relation information, wherein the file information comprises a file name, a file path, a target code starting address and a target code ending address corresponding to the file, the function information comprises a function name, a function starting address and a function ending address, and the source code and target code corresponding relation information comprises a source code line number, a target code starting address and a target ending address corresponding to the source code line. In order to facilitate the recording and query of information, a three-level structure information table of files, functions and row number information is established, wherein the files can contain a plurality of functions, and the functions contain a three-level coverage rate information table of a plurality of row number information; when the coverage rate information needs to be updated, inquiring a file where a Basic Block (Basic Block) is located, then inquiring a function where the Basic Block is located, finally sequentially traversing the target code address contained in the Basic Block, and then updating the line number information of the target code interval.
The source code branch information parsing includes:
the source code branch information mainly provides a function of obtaining analysis information of the source code, the embedded processor assembly instruction set comprises various branch instructions, the branch information of the source code cannot be obtained through debugging information format analysis, and the branch information of the source code can be obtained through analyzing the source code.
The coverage information acquisition comprises:
in the process of program simulation execution, after instruction fetching and decoding, the instruction code of the executed instruction can be obtained. By judging the execution code, whether the instruction code is a jump instruction or not and the type of the jump instruction can be obtained. By debugging information format analysis and source code analysis information analysis, the source code corresponding to the instruction, the source code corresponding to the jump instruction and the type corresponding to the jump instruction can be obtained.
In the process of acquiring the coverage rate information, in order to reduce the influence of coverage rate statistics on simulation execution, a Basic Block (Basic Block) of target codes is taken as a minimum statistical unit, the Basic Block comprises a start address, an end address, a Branch Instruction (Branch Instruction) address, execution times and Branch information, and one Basic Block comprises one or more lines of target codes corresponding to source codes.
After the simulation execution starts, judging whether the current instruction is a branch instruction or not, and if not, continuing to execute; if the Current instruction is a branch instruction, the Current address (Current Program Count) is used as the end address of the basic block, and the start address and the end address of the basic block are used as indexes to update the coverage rate lookup table.
The output of the result of the coverage rate statistical analysis comprises the following steps:
and outputting a coverage statistical result, wherein the output of the coverage statistical result mainly provides instruction fetching, decoding, disassembling and information analysis execution, and finally generates a coverage statistical analysis result.
For an embodiment of the present invention, a non-invasive statistical coverage analysis method for various processor architectures includes the following specific steps:
the method for building the embedded software simulation running environment comprises the following steps:
the embedded software simulation operation environment adopts the virtualization simulation technology to realize the high-precision high-performance simulation of a target system, provides the virtualization operation environment of the embedded software, provides a monitoring means of the instruction execution process and state, is an execution platform of an abnormal processing test case of the embedded software, and mainly comprises: the method comprises the steps of target processor kernel instruction set simulation, embedded system peripheral simulation and simulation process control.
The target processor kernel instruction set simulation adopts a dynamic binary compilation method based on LLVM to realize heterogeneous execution of a target instruction under a Windows/Intel host machine architecture, and a target code is separated from an original hardware execution environment; the embedded system peripheral simulation is used for realizing the simulation of target processor peripheral equipment, comprises RS-422 and RS-485 serial port equipment simulation, switching value equipment simulation, storage system simulation and the like, and supports the injection and the acquisition of data excitation; the simulation process control adopts a unified clock scheduling algorithm to realize the execution control and the cooperative operation of all components of the virtual environment.
The analysis of the formats of the various architecture target files and debugging information comprises the following steps:
analyzing a file format and a debugging information format related to the mainstream embedded processor, acquiring the debugging information format corresponding to the processor by analyzing the file format, and acquiring the embedded software source code object code corresponding relation information by analyzing the debugging information format. And a three-level structure information table of file, function and row number information is established, so that the information is conveniently recorded and inquired.
(1) Analyzing a target file of a plurality of processors, determining the type of debugging information according to the structure of the target file, and reading the debugging information;
(2) analyzing the debugging information formats of Dwarf1, Dwarf2, Dwarf3, stab, COFF and OMF51, and converting the debugging information formats into MidDebugInfo;
(3) reading MidDebugInfo debugging information, and judging the node type of the current debugging information;
(4) judging whether the current debugging information node is a file start type node or not, if so, creating a file information recording structure, writing a target code start address corresponding to the file into the current file information recording structure, executing the step (3), and if not, executing the step (5);
(5) judging whether the current debugging information node is a function starting type node or not, if so, creating a function information recording structure, writing a target code starting address corresponding to a function into the current function information recording structure, inserting the current function information structure into a current file information recording mechanism, and executing the step (3), otherwise, executing the step (6);
(6) judging whether the current debugging information node is a line number information type node, if so, creating a line number information recording structure, inserting the current line number information structure into a current function information recording mechanism, and executing the step (3), otherwise, executing the step (7);
(7) judging whether the current debugging information node is a function end type node or not, if so, writing the target code end address corresponding to the function into the current function information recording structure, executing the step (3), and if not, executing the step (8);
(8) judging whether the current debugging information node is a file end type node or not, if so, writing an end address of the target code corresponding to the file into the current file information recording structure, and executing the step (9);
(9) judging whether the reading of the debugging information is finished or not, if not, executing the step (3), otherwise, executing the step (10);
the source code branch information parsing includes:
the source code branch information mainly provides a function of obtaining analysis information of the source code, the embedded processor assembly instruction set comprises various branch instructions, the branch information of the source code cannot be obtained through debugging information format analysis, and the branch information of the source code can be obtained through analyzing the source code.
(10) Acquiring source code path information;
(11) reading in source files one by one according to the three-level query structure table, judging the branch information of the source code row corresponding to the row number information node, and acquiring the branch condition of the source code;
the coverage information acquisition comprises:
in the process of program simulation execution, after instruction fetching and decoding, the instruction code of the executed instruction can be obtained. By judging the execution code, whether the instruction code is a jump instruction or not and the type of the jump instruction can be obtained. By debugging information format analysis and source code analysis information analysis, the source code corresponding to the instruction, the source code corresponding to the jump instruction and the type corresponding to the jump instruction can be obtained.
(12) The embedded software simulation running environment adopts a virtualization simulation technology to realize high-precision high-performance simulation of a target system, provides a virtualization running environment of embedded software, and constructs the embedded software simulation running environment through the environment;
(13) running an embedded simulation environment and loading a target file into a simulation memory;
(14) simulating the execution start, and taking the execution start address as the start address of the first basic block;
(15) reading an instruction, translating the instruction, executing the current instruction and judging whether the current instruction is a branch instruction or not, if not, continuing to execute the step (15), and if so, executing the step (16);
(16) the address corresponding to the current instruction is a basic block end address, and the start address and the end address of the current basic block and the branch information of the branch instruction are recorded;
(17) using the start address and the end address of the basic block as indexes, inquiring the position of the current basic block in a three-level coverage rate information table, determining a line number information structure corresponding to the basic block, and adding the execution times of the corresponding line number information structure together to update branch information;
(18) judging whether the coverage rate is generated or not, if not, continuing to execute the step (15), and if so, executing the step (19);
(19) and writing the information recorded in the coverage rate information lookup table into a file of a specified path in a specific format, and suspending simulation execution. The output format of the coverage rate information is as follows: the basic block starting address, the basic block ending address, the execution times, the branch instruction address and the branch information are divided by colons in the middle;
the output of the result of the coverage rate statistical analysis comprises the following steps:
and outputting a coverage statistical result, wherein the output of the coverage statistical result mainly provides instruction fetching, decoding, disassembling and information analysis execution, and finally generates a coverage statistical analysis result.
(20) And reading the file for recording the coverage rate information according to the three-level structure information table of the file, the function and the line number information, and generating a coverage rate statistical analysis result according to the corresponding relation between the source code and the target code and the branch information of the source file.
The invention realizes the debugging of the software by analyzing the debugging information of the software target file and realizes the statistics of the statement coverage rate and the branch coverage rate of the software by analyzing the DWARF information. The software performance evaluation is realized by abstracting fault types and simulating fault injection of the software and counting the execution times of statements of a tested program and the number of clocks in the simulation execution process. Only the information required by the virtual verification platform is processed in the lexical analysis process, so that the time consumed by the lexical analyzer is reduced. The parallel instruction serialization idea is adopted to solve the DSP instruction parallel problem. In the coverage rate information counting process, only jump instruction information is counted, and the execution efficiency of the simulator is improved.
The above description is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, several modifications and variations can be made without departing from the technical principle of the present invention, and these modifications and variations should also be regarded as the protection scope of the present invention.