CN105843740B - Method and device for detecting code compiling result - Google Patents

Method and device for detecting code compiling result Download PDF

Info

Publication number
CN105843740B
CN105843740B CN201610172311.5A CN201610172311A CN105843740B CN 105843740 B CN105843740 B CN 105843740B CN 201610172311 A CN201610172311 A CN 201610172311A CN 105843740 B CN105843740 B CN 105843740B
Authority
CN
China
Prior art keywords
code
line
line number
recorded
basic block
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201610172311.5A
Other languages
Chinese (zh)
Other versions
CN105843740A (en
Inventor
刘华星
唐志彬
朱乔
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201610172311.5A priority Critical patent/CN105843740B/en
Publication of CN105843740A publication Critical patent/CN105843740A/en
Application granted granted Critical
Publication of CN105843740B publication Critical patent/CN105843740B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • G06F11/3616Software analysis for verifying properties of programs using software metrics

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a method and a device for detecting a code compiling result. Wherein, the method comprises the following steps: acquiring information of basic blocks from a compiling information file generated by compiling the source code, wherein the information of each basic block comprises: recording a line number of a compiled code line in a piece of code in the source code; acquiring a line number of an effective code line from a source code; detecting whether a missing recorded line number exists in the line numbers of the effective code lines, wherein the missing recorded line number is a line number which is not recorded in the information of the basic block and is positioned in a line number interval formed by a recorded minimum line number and a recorded maximum line number included in the information of the basic block; and recording the line number of the missing record as the line number of the compiled code line when detecting that the line number of the missing record exists in the line numbers of the effective code lines. The invention solves the technical problem that the statistical result aiming at the execution condition of the code line in the code compiling process in the related technology is inaccurate.

Description

Method and device for detecting code compiling result
Technical Field
The invention relates to the field of computers, in particular to a method and a device for detecting a code compiling result.
Background
At present, in order to ensure the stability of software application, software codes are usually required to be tested, wherein the test code coverage rate is an important test link in the software code testing process, and the test code coverage rate is to count the execution conditions of code lines in the code compiling process, such as counting the execution times of the code lines. In the prior art, a instrumentation method is usually used to count the execution condition of a code line, and the instrumentation method may be specifically described as: adding a counting code segment into a source code in the code compiling process, namely performing instrumentation operation on the source code; the client acquires and executes the software application after the pile insertion; after the software application exits, the data of the instrumentation count is transferred to a disk; the number of executions of each code line is deduced by analyzing the file stored in the disk. The following two problems exist in the statistical execution of code lines in the code compiling process by using the instrumentation method:
1. because the instrumentation count information needs to be generated after running in the memory, for a dynamically loaded module, if the dynamically loaded module is not executed, the dynamically loaded module is not loaded, and a corresponding count file cannot be generated, so that statistics on the part of files is lost when the execution condition of a code line is counted.
2. In the code writing process, for convenience of reading, a long code line is often split into multiple lines for writing, such as 44 th line and 45 th line (code in a box shown in fig. 1) in the code segment shown in fig. 1. For this situation, data information of the effective code line that is swapped when the execution condition of the code line is counted by using the instrumentation method will be ignored, that is, only the execution times 32768 of the 44 th line is counted, and the execution times of the 45 th line is ignored, which will cause an error in the statistical result of the execution condition of the code line, and especially when the execution condition of the differentiated code line is counted, this part of the differentiated code line will be omitted, which causes an inaccurate statistical result of the execution condition of the final code line.
In view of the above problems, no effective solution has been proposed.
Disclosure of Invention
The embodiment of the invention provides a method and a device for detecting a code compiling result, which are used for at least solving the technical problem that the statistical result of the code line execution condition in the code compiling process in the related art is inaccurate.
According to an aspect of an embodiment of the present invention, there is provided a method for detecting a code compiling result, including: acquiring information of basic blocks from a compiling information file generated by compiling the source code, wherein the information of each basic block comprises: recording a line number of a compiled code line in a piece of code in the source code; acquiring a line number of an effective code line from a source code; detecting whether a missing recorded line number exists in the line numbers of the effective code lines, wherein the missing recorded line number is a line number which is not recorded in the information of the basic block and is positioned in a line number interval formed by a recorded minimum line number and a recorded maximum line number included in the information of the basic block; and recording the line number of the missing record as the line number of the compiled code line when detecting that the line number of the missing record exists in the line numbers of the effective code lines.
According to another aspect of the embodiments of the present invention, there is also provided an apparatus for detecting a code compiling result, including: a first obtaining module, configured to obtain information of basic blocks from a compilation information file generated by compiling a source code, where the information of each basic block includes: recording a line number of a compiled code line in a piece of code in the source code; the second acquisition module is used for acquiring the line number of the effective code line from the source code; the detection module is used for detecting whether the row number of the missing record exists in the row numbers of the effective code rows, wherein the row number of the missing record is the row number which is not recorded in the information of the basic block and is positioned in a row number interval formed by the recorded minimum row number and the maximum row number included in the information of the basic block; and the recording module is used for recording the line number of the missed record as the line number of the compiled code line when the line number of the valid code line is detected to have the line number of the missed record.
In the embodiment of the invention, the information of the basic block is acquired from the compiling information file generated by compiling the source code, whether the line number which is not recorded in the information of the basic block and is between the minimum line number and the maximum line number recorded in the information of the basic block exists in the line numbers of the effective code lines in the source code is detected according to the information of the basic block, if so, the line number which is not recorded in the information of the basic block is recorded as the line number of the compiled code line, so that the aim of accurately counting the execution condition of the effective code lines in the code compiling process is fulfilled, the technical effect of improving the accuracy of the counting result of the execution condition of the code lines in the code compiling process is achieved, and the technical problem of inaccurate counting result of the execution condition of the code lines in the code compiling process in the related technology is solved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the invention without limiting the invention. In the drawings:
FIG. 1 is a diagram illustrating statistics of the number of executions of a line of code according to the prior art;
FIG. 2 is a diagram illustrating a hardware environment of a method for detecting a result of code compilation according to an embodiment of the present invention;
FIG. 3 is a flow chart of an alternative method for detecting code compilation results according to embodiments of the present invention;
FIG. 4 is a schematic diagram of a compilation information file according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of an active code line according to an embodiment of the invention;
FIG. 6 is a diagram illustrating statistics of the number of times a line of code is executed according to an embodiment of the invention;
FIG. 7 is a schematic diagram of an execution information file according to an embodiment of the present invention;
FIG. 8 is a schematic diagram of an execution information file after completion of an entry according to an embodiment of the present invention;
FIG. 9 is a diagram of an apparatus for detecting the result of code compilation according to an embodiment of the present invention;
FIG. 10 is a diagram illustrating an alternative apparatus for detecting the result of code compilation according to an embodiment of the present invention;
FIG. 11 is a diagram illustrating an alternative apparatus for detecting the result of code compilation according to an embodiment of the present invention;
FIG. 12 is a diagram illustrating an alternative apparatus for detecting the result of code compilation according to an embodiment of the present invention;
FIG. 13 is a diagram illustrating an alternative apparatus for detecting the result of code compilation according to an embodiment of the present invention; and
fig. 14 is a block diagram of a terminal according to an embodiment of the present invention.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
First, partial terms or terms appearing in the description of the embodiments of the present invention are applied to the following explanations:
clang is a lightweight compiler in C, C + +, Objective-C, Objective-C + + languages.
The Gcov is a tool for testing the code coverage rate, namely a tool for testing the execution condition of a code line in the code compiling process.
Gcno, a file generated when Gcov executes.
Example 1
According to an embodiment of the present invention, a method embodiment of a method for detecting a code compilation result is provided.
Alternatively, in the present embodiment, the above code compilation result detection method may be applied to a hardware environment formed by the server 102 and the terminal 104 as shown in fig. 2. As shown in fig. 2, server 102 is connected to terminals 104 via a network, including but not limited to: the terminal 104 is not limited to a PC, a mobile phone, a tablet computer, etc. in a wide area network, a metropolitan area network, or a local area network. The data processing method according to the embodiment of the present invention may be executed by the server 102, the terminal 104, or both the server 102 and the terminal 104. The data processing method of the embodiment of the present invention executed by the terminal 104 may also be executed by a client installed thereon.
Fig. 3 is a flowchart of an alternative method for detecting a code compilation result according to an embodiment of the present invention, and as shown in fig. 3, the method may include the following steps:
step S202, obtaining information of basic blocks from a compiling information file generated by compiling the source code, wherein the information of each basic block comprises: recording a line number of a compiled code line in a piece of code in the source code;
step S204, acquiring the line number of the effective code line from the source code;
step S206, detecting whether the row number of the missing record exists in the row numbers of the effective code rows, wherein the row number of the missing record is the row number which is not recorded in the information of the basic block and is positioned in the row number interval formed by the recorded minimum row number and the maximum row number included in the information of the basic block;
in step S208, when it is detected that the missing recorded line number exists in the line numbers of the effective code lines, the missing recorded line number is recorded as the line number of the compiled code line.
Through the steps S202 to S208, the information of the basic block is obtained from the compiled information file generated by compiling the source code, whether the line number, which is not recorded in the information of the basic block and is located between the minimum line number and the maximum line number recorded in the information of the basic block, exists in the line numbers of the effective code lines in the source code is detected according to the information of the basic block, and if the line number exists, the line number, which is not recorded in the information of the basic block, is recorded as the line number of the compiled code line, so that the technical problem that the statistical result of the code line execution condition in the code compiling process in the related art is inaccurate is solved, and the technical effect of improving the accuracy of the statistical result of the code line execution condition in the code compiling process is realized.
In the technical solution provided in step S202, a file obtained after compiling the source code is a binary file, and a compiled information file can be obtained by performing a disassembling operation on the binary file, as shown in fig. 4, the compiled information file may be composed of disassembling codes, and according to the disassembling codes, the compiled information file may be split into at least one basic block, each basic block corresponds to a section of code in the source code, and a code segment may include at least one code line. The basic block defined by the embodiment of the present invention may have the following characteristics: executing a first code line statement in a code segment corresponding to the basic block, and executing the whole code segment statement once; the basic block is a statement sequence which is executed in sequence in the source code; a basic block only has one exit statement and one entry statement, and the basic block can only enter from the entry statement and exit from the exit statement during execution; the execution times of all code line statements in the basic block are the same; a basic block typically consists of a number of sequential execution statements followed by a jump statement.
Optionally, the compiling information file may include at least one basic block, and each two basic blocks may be separated by an identifier, as shown in the block part of fig. 4, where the identifier is 01450000, the byte where the identifier is located is the starting position of the basic block, and the bytes between the byte where the identifier is located and the next identifier constitute one basic block, and the information of the basic block may be represented by these bytes. For example, the identifier of the first basic block and the identifier of the second basic block in fig. 4 are 01450000, all bytes from the starting position of the first basic block, that is, the identifier 01450000, to the starting position of the second basic block, that is, the identifier 01450000, belong to the first basic block, and information of the first basic block can be acquired from the bytes, specifically: the bytes following the identifier 01450000 are used to indicate the length of the first basic block, i.e. the number of bytes from the byte to the second basic block identifier 01450000, and as shown in fig. 4, the length of the first basic block is 0000000B, i.e. the length of the first basic block is 11, i.e. 11 bytes are included from the byte. Byte 00000001 following the byte representing the length of the first basic block represents the identity of the first basic block, i.e., the identity number representing the basic block is 1, and is used primarily to identify the different basic blocks. The byte 00000000 following the byte representing the different basic block is used to represent the file name of the binary file recorded later generated after compiling for the code segment corresponding to the basic block. The following byte 00000003 is used to indicate the file name length, that is, the file name is represented by the following three bytes, that is, 0000632E74736574, the file name is "test.c", it should be noted that 2F2E in 65742F2E and 0000 in 000000000000 are in a fixed format, see the way that the corresponding byte in the second basic block indicates the file name. The bytes after the file name are used to indicate the line numbers of the compiled code lines in the code end corresponding to the first basic block, which are 0000002B, 0000002C, and 0000002F, respectively, i.e., lines 43, 44, and 47, respectively. The next two bytes 00000000, 00000000 are used to indicate the termination location of the first basic block. Similarly, the second basic block may also obtain information of the second basic block according to the analysis method described above.
It should be noted that the information that the basic block can be obtained by the analysis may include, but is not limited to, a line number recorded as a compiled code line in a piece of code in the source code, such as 43, 44, and 47 recorded in the information of the first basic block in fig. 4. The information of the basic block may further include an identifier of the basic block obtained by the analysis, an identifier of the basic block, a length of the basic block, a file name of a binary file generated after a code segment corresponding to the basic block is compiled, and the like. It should be noted that the minimum line number and the maximum line number can be obtained from the line number of the compiled code line recorded in the information of the basic block, for example, the minimum line number is 43, the maximum line number is 47, and the range of the code lines included in the basic block can be obtained according to the minimum line number and the maximum line number and is 43-47, that is, the 43 th line to the 47 th line correspond to the same basic block. In the range 43-47, only the line number 44 of the compiled code line is recorded in the basic block information, and the code lines with line numbers 45 and 46 may be invalid code lines or may not be counted.
The compiling information file in the embodiment of the present invention may be a Gcno file on an osx system of a mac machine, where the Gcno file is a file generated by a tool Gcov for testing code coverage during execution, and the Gcno file stores information of a basic block corresponding to a code segment, a corresponding relationship between the code segment and the basic block, and the like. It should be further noted that the compiling information file according to the embodiment of the present invention may also be a file generated in a code compiling process under ios, linux, and android systems.
In the technical solution provided in step S204, the source code file in the osx system is generally a file with suffix of.c, cpp, or.m, and the embodiment of the present invention may use Clang to parse the source code file, and specifically may use a command line "Clang-ccl-dump-tokens file name", for example, Clang-ccl-dump-tokens abc.m, as shown in fig. 5, and the block portion is an effective code line of lines 44 and 45 in the code segment shown in fig. 1 obtained by parsing the code segment using Clang. It should be noted that, when the embodiment of the present invention analyzes the source code by using the Clang, the invalid lines such as the blank lines and the comment lines in the source code may be filtered, and some symbols irrelevant to actual execution, such as "{ }", may also be filtered, so that the valid code lines obtained after the Clang analysis are more accurate.
The method comprises the steps of analyzing a source code to obtain an effective code line, obtaining a line number of the effective code line, wherein each line code in the source code corresponds to a line number, the line number is used for identifying the position of the code line in a source code file, and the line number of the code line is shown in FIG. 1. it should be noted that each line in the source code file corresponds to a line number, the line corresponding to the line number can be an effective code line, such as 44 th line and 45 th line, or a blank line, such as 43 th line and 46 th line, or a symbol, such as 47 th line, and the source code file can record the corresponding relation between different line numbers and the code line, such as the line number 45 corresponding to the code line "NS L og (@" aabcdd:%, "), and after obtaining the effective code line in the source code by analyzing, the line number stored in the source code file can obtain the line number corresponding to the effective code line according to the corresponding relation between the line number and the code line number stored in the source code file, such as the effective code line number is obtained by" @ "bcagb" @ L: "@", and the effective code line number stored in the source code line "@" abcdd "@" 3652: "@".
In the technical solution provided in step S206, the row number that is not recorded in the information of the basic block and is located in the row number interval formed by the recorded minimum row number and the recorded maximum row number included in the information of the basic block may be the row number. For example, if the recorded minimum line number 43 and the maximum line number 47 can be obtained from the information of the basic block, and the compiled code behavior 44 recorded in the information of the basic block is executed, the line numbers recorded in the missing are 45 and 46, and the 43 th to 47 th lines in the source code correspond to the same basic block. The number of the effective code lines obtained from the source code may be one or more, and accordingly, the number of the effective code lines may also be one or more. For example, if the line numbers of the effective code lines obtained from the source code are 44 and 45, the result of detecting whether there is a missing recorded line number in the line numbers of the effective code lines is: the row number of the missing record is 45. The embodiment of the invention aims to detect whether the execution condition of the effective code line in the source code is counted or not by detecting whether the line number of the missing record exists in the line numbers of the effective code line or not and whether the execution condition of the code line is counted or not in the compiling process of the source code so as to achieve the effect of ensuring the accuracy of the counting result of the execution condition of the effective code line in the source code.
In the technical solution provided in step S208, since the execution times of the code lines corresponding to the same basic block are the same, that is, when the execution times of the code lines corresponding to the compiled code line and the missing recording line number recorded in the basic block information should be the same, that is, the compiled code line recorded in the basic block information is executed once in the code compiling process, the code line corresponding to the missing recording line number is also executed once. In order to ensure the accuracy of the statistical result of the execution condition of the effective code line in the source code, the embodiment of the present invention may record the line number of the missing record as the line number of the compiled code line when detecting that the line number of the effective code line has the line number of the missing record, so as to achieve the purpose of ensuring that the execution times of the code line corresponding to the compiled code line and the line number of the missing record recorded in the basic block information are the same.
For example, if the line numbers of the effective code lines are 44 and 45, the minimum line number recorded in the information of the basic block is 43, the maximum line number is 47, the compiled code line 44 recorded in the information of the basic block, and the line numbers of the missing records are 45 and 46, the line number 45 in which the missing record exists in the line numbers of the effective code lines can be obtained. The number of executions of the code of the 44 th and 45 th lines should be the same in principle, but the number of executions of the code of the 45 th line is not counted when counting the number of executions of the code line for some reason. Therefore, in order to ensure the accuracy of the statistical result of the execution times of the code lines in the source code, it is necessary to record the line number 45 as the line number of the compiled code line, and the execution times of the 45 th line code is the same as the execution times of the 44 th line code, as shown in fig. 6, where the statistical result of the execution times of the code lines shown in fig. 6 is the result of correcting the statistical result of the execution times of the code lines shown in fig. 1, and the execution times of the 44 th line code and the 45 th line code in the block shown in fig. 6 are both 32768.
As an alternative embodiment, the step S208 of recording the line number of the missing record as the line number of the compiled code line may include: step S2082, adding the missing recorded line number as the line number of the compiled code line into the execution information file generated by executing the source code, where the execution information file at least includes: the line number, recorded as a compiled line of code, is recorded as the number of times the compiled line of code is executed.
It should be noted that the execution information file is a file obtained by compiling the source code, as shown in fig. 7, the line number of the compiled code line and the number of times the compiled code line is executed in the execution information file may be recorded, such as the line number 44 in the block shown in fig. 7, and the number of times 32768 the code of line 44 is executed. The execution information file obtained after the source code is compiled includes only the line number and the execution times of the code lines recorded as compiled, and the line number recorded as missing and the execution times of the code lines corresponding to the line number are not recorded in the execution information file, so in order to ensure the accuracy of the information about the execution of the code lines recorded in the execution information file, the embodiment may add the line number recorded as missing as the line number of the compiled code line into the execution information file generated by the execution of the source code, and the execution information file after the addition may add the line number 45 recorded as missing and the execution times 32768 of the 45 th line code (the same as the execution times of the 44 th line code) into the execution information file in the block shown in fig. 8.
The embodiment improves the accuracy of the execution condition of the code line reflected in the execution information file by supplementing the line number of the missing record as the line number of the compiled code line into the execution information file generated by the execution of the source code. Meanwhile, the code execution condition is modified and stored in the execution information file, and the effect of directly reading the code line execution condition from the execution information file can be achieved.
As an alternative embodiment, the step S2082 of adding the line number of the missing record as the line number of the compiled code line into the execution information file generated when the source code is executed may include: step S20822, supplementing the missing recorded line number to the corresponding position in the execution information file according to the sequence of the line numbers, and recording the executed times of the code line corresponding to the missing recorded line number at the position, wherein the executed times of the code line corresponding to the missing recorded line number is equal to the executed times of the code line corresponding to the line number of the compiled code line in the line number section where the missing recorded line number is located.
It should be noted that, when supplementing the missing recorded line number into the execution information file, the embodiment preferably performs the supplementing according to the line number sequence, which may be according to the line number sequence from small to large, or according to the line number sequence from large to small. The line numbers of the missed records are recorded according to the line number sequence, so that the positions of the line numbers can be conveniently and quickly positioned from the execution information file, and the advantages are more prominent according to the line number sequence, particularly under the condition that the number of lines of the code is especially multiple. For example, the line number 45 is appended to the line number 44 in the execution information file in the block shown in fig. 8.
Optionally, when the row number of the missing record is added to the execution information file, the embodiment may also add the execution count of the code row corresponding to the row number of the missing record to the corresponding position of the row number, such as the execution count 32768 after the row number 45 in the block shown in fig. 8. It should be noted here that the number of times that the code line corresponding to the line number of the missing record is executed is equal to the number of times that the code line corresponding to the line number of the compiled code line in the line number section in which the line number of the missing record is located is executed. For example, the number of execution times of the code line corresponding to the line number 45 is equal to the number of execution times of the code line corresponding to the line number 44 of the compiled code line recorded in the same basic block, which is 32768, as shown in fig. 8. The embodiment can achieve the effect of conveniently and directly obtaining the execution condition of each code line from the execution information file by supplementing the missing recorded line number and the execution times of the code line corresponding to the line number into the execution information file.
As an alternative embodiment, the step S204 of obtaining the line number of the valid code line from the source code may include the following steps:
step S2042, filtering out comment lines, blank lines and symbol information irrelevant to the execution of the source code from the source code to obtain a first code.
Step S2044, record the line number of the code line in the first code as the line number of the effective code line.
It should be noted that the first code is a true valid code line related to actual execution in the source code, except for a comment line, a blank line and a symbol (such as "{ }" or the like) unrelated to execution of the source code. The embodiment performs pre-compiling processing when analyzing the source code, namely filtering out annotation lines, blank lines and symbol information irrelevant to the execution of the source code in the source code, and can ensure the accuracy of the obtained effective code lines. The effective code lines obtained after filtering out the comment lines, the blank lines and the symbol information irrelevant to the execution of the source code are shown in fig. 5. On the basis of ensuring the accuracy of the effective code line obtained by analyzing the source code, the embodiment can obtain the more accurate line number of the effective code line according to the corresponding relationship between the line number and the code line stored in the source code file, thereby achieving the effect of improving the accuracy of the obtained line number of the effective code line.
As an alternative embodiment, the step S202 of obtaining the information of the basic block from the compilation information file generated by compiling the source code may include the following steps:
in step S2022, information of each basic block is acquired from the compilation information file using a predetermined identifier for identifying the start position of the basic block.
Step S2024, identify the identity of the basic block, the line number of the compiled code line from the information of the basic block, wherein the line number of the compiled code line includes the recorded minimum line number and the maximum line number.
From the above detailed description of the basic blocks and the information of the basic blocks in the embodiment, it can be known that there is an identifier, such as the identifier 01450000 in fig. 4, at the start position of each basic block in the compilation information file, and it should be noted that the identifier may be set and adjusted according to the actual situation, that is, the identifier is not limited to 01450000, but may also be other characters. After the identifier is determined in the compiling information file, the information of the basic block can be identified from the byte between the byte where the identifier is located and the next identifier, and the information of the basic block can include, but is not limited to, the identification of the basic block (e.g. 00000001 in fig. 4), the line number of the compiled code line (e.g. 0000002B, 0000002C, 0000002F in fig. 4), the length of the basic block (e.g. 0000000B in fig. 4), the file name of the binary file generated after the code segment corresponding to the basic block is compiled (e.g. 0000632E74736574 in fig. 4, the file name is "test.c"), and the like. It should be noted that the line numbers (e.g., 0000002B, 0000002C, 0000002F in fig. 4) of the compiled code lines include the recorded minimum line number and the maximum line number, as shown in fig. 4, the minimum line number is 0000002B, and the maximum line number is 0000002F.
The embodiment obtains the information of the basic block comprising the line number of the compiled code line, wherein the line number of the compiled code line comprises the recorded minimum line number and the maximum line number, so as to establish the corresponding relation between the basic block and the code segment in the source code, and determine the line number which is missed to be recorded according to the minimum line number and the maximum line number, thereby realizing the effect of improving the accuracy of the statistical result of the execution condition of the code line.
It should be noted that, for simplicity of description, the above-mentioned method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present invention is not limited by the order of acts, as some steps may occur in other orders or concurrently in accordance with the invention. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required by the invention.
Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
Example 2
According to the embodiment of the invention, the invention further provides a device for detecting the code compiling result, which is used for implementing the method for detecting the code compiling result. Fig. 9 is a schematic diagram of an apparatus for detecting a code compiling result according to an embodiment of the invention, and as shown in fig. 9, the apparatus may include:
a first obtaining module 22, configured to obtain information of basic blocks from a compilation information file generated by compiling the source code, where the information of each basic block includes: recording a line number of a compiled code line in a piece of code in the source code; a second obtaining module 24, configured to obtain a line number of the valid code line from the source code; a detecting module 26, configured to detect whether there is a missing recorded line number in the line numbers of the effective code lines, where the missing recorded line number is not recorded in the information of the basic block and is located in a line number interval formed by a recorded minimum line number and a recorded maximum line number included in the information of the basic block; and a recording module 28, configured to record the line number of the missing record as the line number of the compiled code line when the line number of the valid code line is detected to have the line number of the missing record.
It should be noted that the first obtaining module 22 in this embodiment may be configured to execute step S202 in embodiment 1 of this application, the second obtaining module 24 in this embodiment may be configured to execute step S204 in embodiment 1 of this application, the detecting module 26 in this embodiment may be configured to execute step S206 in embodiment 1 of this application, and the recording module 28 in this embodiment may be configured to execute step S208 in embodiment 1 of this application.
It should be noted here that the modules described above are the same as the examples and application scenarios implemented by the corresponding steps, but are not limited to the disclosure of embodiment 1 described above. It should be noted that the modules described above as a part of the apparatus may operate in a hardware environment as shown in fig. 1, and may be implemented by software or hardware.
Through the modules, the technical problem that the statistical result of the execution condition of the code line in the code compiling process is inaccurate in the related technology can be solved, and therefore the technical effect of improving the accuracy of the statistical result of the execution condition of the code line in the code compiling process is achieved.
In the scheme provided by the first obtaining module 22, a file obtained after the source code is compiled is a binary file, and a compiled information file can be obtained by performing a disassembling operation on the binary file. The compilation information file may be composed of disassembled code, from which the disassembly code may be split into at least one basic block, each basic block corresponding to a piece of code in the source code, and a piece of code may include at least one line of code. The compiling information file can be as shown in fig. 4, and details about the compiling information file and the basic block and information thereof have been described in detail in the embodiment of the method of the present invention, and are not described herein again.
In the technical solution provided by the second obtaining module 24, the source code file in the osx system is generally a file with a suffix of.c, cpp, or.m, and in the embodiment of the present invention, the source code file may be parsed by using Clang, and specifically, the command line "Clang-ccl-dump-tokens file name" may be used. It should be noted that, when the embodiment of the present invention analyzes the source code by using the Clang, the invalid lines such as the blank lines and the comment lines in the source code may be filtered, and some symbols irrelevant to actual execution, such as "{ }", may also be filtered, so that the valid code lines obtained after the Clang analysis are more accurate. After the source code is analyzed to obtain the effective code line, the embodiment of the invention can obtain the line number of the effective code line. Each line of code in the source code corresponds to a line number, which is used to identify the position of the line of code in the source code file. It should be noted that each line in the source code file corresponds to a line number, and the line corresponding to the line number may be an effective code line, a blank line, or a symbol. The corresponding relation between different line numbers and code lines can be recorded in the source code file, and after the effective code line in the source code is obtained through analysis, the line number corresponding to the effective code line can be obtained according to the corresponding relation between the line number and the code line stored in the source code file.
In the technical solution provided by the detection module 26, the row number that is not recorded in the information of the basic block and is located in a row number interval formed by the recorded minimum row number and the recorded maximum row number included in the information of the basic block may be the row number. The number of the effective code lines obtained from the source code may be one or more, and accordingly, the number of the effective code lines may also be one or more. The embodiment of the invention aims to detect whether the execution condition of the effective code line in the source code is counted or not by detecting whether the line number of the missing record exists in the line numbers of the effective code line or not and whether the execution condition of the code line is counted or not in the compiling process of the source code so as to achieve the effect of ensuring the accuracy of the counting result of the execution condition of the effective code line in the source code.
In the technical solution provided by the recording module 28, since the execution times of the code lines corresponding to the same basic block are the same, that is, when the execution times of the code lines corresponding to the compiled code line and the missing recording line number recorded in the basic block information should be the same, that is, the compiled code line recorded in the basic block information is executed once in the code compiling process, the code line corresponding to the missing recording line number is also executed once. In order to ensure the accuracy of the statistical result of the execution condition of the effective code line in the source code, the embodiment of the present invention may record the line number of the missing record as the line number of the compiled code line when detecting that the line number of the effective code line has the line number of the missing record, so as to achieve the purpose of ensuring that the execution times of the code line corresponding to the compiled code line and the line number of the missing record recorded in the basic block information are the same.
As an alternative embodiment, fig. 10 is a schematic diagram of an alternative detection apparatus for code compiling result according to an embodiment of the present invention, and as shown in fig. 10, the recording module 28 may include: the adding module 282 is configured to add the missing line number as a line number of a compiled code line into an execution information file generated by executing the source code, where the execution information file at least includes: the line number, recorded as a compiled line of code, is recorded as the number of times the compiled line of code is executed.
It should be noted that the entry supplementing module 282 in this embodiment may be configured to execute step S2082 in embodiment 1 of this application. The execution information file is a file obtained by compiling the source code, and the line number of the compiled code line and the number of times the compiled code line is executed can be recorded in the execution information file. The execution information file obtained after the source code is compiled is only provided with the line number and the execution times of the code line recorded as compiled, and the line number recorded in a missing way and the execution times of the code line corresponding to the line number are not recorded in the execution information file.
The embodiment improves the accuracy of the execution condition of the code line reflected in the execution information file by supplementing the line number of the missing record as the line number of the compiled code line into the execution information file generated by the execution of the source code. Meanwhile, the code execution condition is modified and stored in the execution information file, and the effect of directly reading the code line execution condition from the execution information file can be achieved.
As an alternative embodiment, fig. 11 is a schematic diagram of another alternative detection apparatus for code compiling results according to an embodiment of the present invention, and as shown in fig. 11, the supplementary recording module 282 may include: the first sub-padding module 2822 is configured to pad the missing recorded line numbers to corresponding positions in the execution information file according to the sequence of the line numbers, and record the number of times that a code line corresponding to the missing recorded line number is executed at the positions, where the number of times that the code line corresponding to the missing recorded line number is executed is equal to the number of times that a code line corresponding to a line number of a compiled code line in a line number interval where the missing recorded line number is located is executed.
It should be noted that the first sub-entry module 2822 in this embodiment may be configured to execute step S20822 in embodiment 1 of this application. When the missing recorded line number is added to the execution information file, the embodiment preferably adds the missing recorded line number in the order of the line number, which may be in the order of the line number from small to large, or in the order of the line number from large to small. The line numbers of the missed records are recorded according to the line number sequence, so that the positions of the line numbers can be conveniently and quickly positioned from the execution information file, and the advantages are more prominent according to the line number sequence, particularly under the condition that the number of lines of the code is especially multiple.
Optionally, when the row number of the missing record is added to the execution information file, the embodiment may also add the execution times of the code row corresponding to the row number of the missing record to the corresponding position of the row number. It should be noted here that the number of times that the code line corresponding to the line number of the missing record is executed is equal to the number of times that the code line corresponding to the line number of the compiled code line in the line number section in which the line number of the missing record is located is executed. The embodiment can achieve the effect of conveniently and directly obtaining the execution condition of each code line from the execution information file by supplementing the missing recorded line number and the execution times of the code line corresponding to the line number into the execution information file.
As an alternative embodiment, fig. 12 is a schematic diagram of a detection apparatus for detecting a compiling result of a further alternative code according to an embodiment of the invention, and as shown in fig. 12, the second obtaining module 24 may include: a filtering module 242, configured to filter out, from the source code, an annotation line, a blank line, and symbol information that is irrelevant to execution of the source code, to obtain a first code; a first sub-recording module 244, configured to record the line number of the code line in the first code as the line number of the valid code line.
It should be noted that the filtering module 242 in this embodiment may be configured to execute the step S2042 in embodiment 1 of this application, and the first sub-recording module 244 in this embodiment may be configured to execute the step S2044 in embodiment 1 of this application.
It should be noted that the first code is a true valid code line related to actual execution in the source code, except for a comment line, a blank line and a symbol (such as "{ }" or the like) unrelated to execution of the source code. The embodiment performs pre-compiling processing when analyzing the source code, namely filtering out annotation lines, blank lines and symbol information irrelevant to the execution of the source code in the source code, and can ensure the accuracy of the obtained effective code lines. On the basis of ensuring the accuracy of the effective code line obtained by analyzing the source code, the embodiment can obtain the more accurate line number of the effective code line according to the corresponding relationship between the line number and the code line stored in the source code file, thereby achieving the effect of improving the accuracy of the obtained line number of the effective code line.
As an alternative embodiment, fig. 13 is a schematic diagram of a detection apparatus for detecting a code compiling result according to another alternative embodiment of the invention, and as shown in fig. 13, the first obtaining module 22 may include: a first sub-obtaining module 222, configured to obtain information of each basic block from the compilation information file by using a predetermined identifier, where the identifier is used to identify a start position of the basic block; an identifying module 224, configured to identify, from the information of the basic block, an identification of the basic block, and a line number of the compiled code line, where the line number of the compiled code line includes a minimum line number and a maximum line number that are recorded.
It should be noted that the first sub-obtaining module 222 in this embodiment may be configured to execute step S2022 in embodiment 1 of this application, and the identifying module 224 in this embodiment may be configured to execute step S2024 in embodiment 1 of this application.
From the above detailed description of the basic blocks and the information of the basic blocks in the embodiment, it can be known that there is an identifier at the start position of each basic block in the compilation information file, and it should be noted that the identifier may be set and adjusted according to the actual situation, that is, the identifier is not limited to 01450000 in fig. 4, but may be other characters. After the identifier is determined in the compiling information file, the information of the basic block can be identified from the byte between the byte of the identifier and the next identifier, the information of the basic block can include, but is not limited to, the identification of the basic block, the line number of the compiled code line, the length of the basic block, the file name of the binary file generated after the code segment corresponding to the basic block is compiled, and the like. It should be noted that the line number of the compiled code line includes the minimum line number and the maximum line number that are recorded.
The embodiment obtains the information of the basic block comprising the line number of the compiled code line, wherein the line number of the compiled code line comprises the recorded minimum line number and the maximum line number, so as to establish the corresponding relation between the basic block and the code segment in the source code, and determine the line number which is missed to be recorded according to the minimum line number and the maximum line number, thereby realizing the effect of improving the accuracy of the statistical result of the execution condition of the code line.
It should be noted here that the modules described above are the same as the examples and application scenarios implemented by the corresponding steps, but are not limited to the disclosure of embodiment 1 described above. It should be noted that the modules described above as a part of the apparatus may be operated in a hardware environment as shown in fig. 1, and may be implemented by software, or may be implemented by hardware, where the hardware environment includes a network environment.
Example 3
According to the embodiment of the invention, the invention also provides a server or a terminal for implementing the detection method of the code compiling result.
Fig. 14 is a block diagram of a terminal according to an embodiment of the present invention, and as shown in fig. 14, the terminal may include: one or more processors 201 (only one is shown), a memory 203, and a transmission device 205 (such as the transmission device in the above embodiment), as shown in fig. 14, the terminal may further include an input/output device 207.
The memory 203 may be configured to store software programs and modules, such as program instructions/modules corresponding to the method and apparatus for detecting a code compiling result in the embodiment of the present invention, and the processor 201 executes various functional applications and data processing by running the software programs and modules stored in the memory 203, that is, the method for detecting a code compiling result is implemented. The memory 203 may include high speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 203 may further include memory located remotely from the processor 201, which may be connected to the terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission device 205 is used for receiving or sending data via a network, and can also be used for data transmission between a processor and a memory. Examples of the network may include a wired network and a wireless network. In one example, the transmission device 205 includes a Network adapter (NIC) that can be connected to a router via a Network cable and other Network devices to communicate with the internet or a local area Network. In one example, the transmission device 205 is a Radio Frequency (RF) module, which is used for communicating with the internet in a wireless manner.
Wherein the memory 203 is specifically used for storing application programs.
The processor 201 may call the application stored in the memory 203 via the transmission means 205 to perform the following steps: acquiring information of basic blocks from a compiling information file generated by compiling the source code, wherein the information of each basic block comprises: recording a line number of a compiled code line in a piece of code in the source code; acquiring a line number of an effective code line from a source code; detecting whether a missing recorded line number exists in the line numbers of the effective code lines, wherein the missing recorded line number is not recorded in the information of the basic block and is positioned in a line number interval formed by a recorded minimum line number and a recorded maximum line number included in the information of the basic block; and recording the line number of the missing record as the line number of the compiled code line when detecting that the line number of the missing record exists in the line numbers of the effective code lines.
The processor 201 is further configured to perform the following steps: and filling the missing recorded line number as the line number of the compiled code line into an execution information file generated by executing the source code, wherein the execution information file at least comprises: the line number, recorded as a compiled line of code, is recorded as the number of times the compiled line of code is executed.
The processor 201 is further configured to perform the following steps: and supplementing the row number of the missing record to a corresponding position in the execution information file according to the sequence of the row numbers, and recording the number of times of executing the code row corresponding to the row number of the missing record at the position, wherein the number of times of executing the code row corresponding to the row number of the missing record is equal to the number of times of executing the code row corresponding to the row number of the compiled code row in the row number section where the row number of the missing record is located.
The processor 201 is further configured to perform the following steps: filtering comment lines, blank lines and symbol information irrelevant to the execution of the source code from the source code to obtain a first code; and recording the line number of the code line in the first code as the line number of the effective code line.
The processor 201 is further configured to perform the following steps: acquiring information of each basic block from a compilation information file using a predetermined identifier, wherein the identifier is used for identifying the starting position of the basic block; and identifying the identification of the basic block and the line number of the compiled code line from the information of the basic block, wherein the line number of the compiled code line comprises the minimum line number and the maximum line number which are recorded.
The embodiment of the invention provides a detection scheme of a code compiling result. The method comprises the steps of obtaining information of a basic block from a compiling information file generated by compiling a source code, detecting whether a line number which is not recorded in the information of the basic block and is positioned between a minimum line number and a maximum line number recorded in the information of the basic block exists in line numbers of effective code lines in the source code according to the information of the basic block, and recording the line number which is not recorded in the information of the basic block as the line number of a compiled code line if the line number exists, so that the purpose of accurately counting the execution condition of the effective code lines in the process of compiling the code is achieved, the technical problem that the counting result aiming at the execution condition of the code lines in the process of compiling the code in the related technology is inaccurate is further solved, and the technical effect of improving the accuracy of the counting result of the execution condition of the code lines in the process of compiling the code is achieved.
Optionally, the specific examples in this embodiment may refer to the examples described in embodiment 1 and embodiment 2, and this embodiment is not described herein again.
It can be understood by those skilled in the art that the structure shown in fig. 14 is only an illustration, and the terminal may be a terminal device such as a smart phone (e.g., an Android phone, an iOS phone, etc.), a tablet computer, a palm computer, and a Mobile Internet Device (MID), a PAD, etc. Fig. 14 is a diagram illustrating a structure of the electronic device. For example, the terminal may also include more or fewer components (e.g., network interfaces, display devices, etc.) than shown in FIG. 14, or have a different configuration than shown in FIG. 14.
Those skilled in the art will appreciate that all or part of the steps in the methods of the above embodiments may be implemented by a program instructing hardware associated with the terminal device, where the program may be stored in a computer-readable storage medium, and the storage medium may include: flash disks, Read-Only memories (ROMs), Random Access Memories (RAMs), magnetic or optical disks, and the like.
Example 4
The embodiment of the invention also provides a storage medium. Alternatively, in this embodiment, the storage medium may be a program code for executing a method for detecting a result of compiling a code.
Optionally, in this embodiment, the storage medium may be located on at least one of a plurality of network devices in a network shown in the above embodiment.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps:
s1, obtaining information of basic blocks from a compiling information file generated by compiling the source code, wherein the information of each basic block includes: recording a line number of a compiled code line in a piece of code in the source code;
s2, acquiring the line number of the effective code line from the source code;
s3, detecting whether the row number of the missing record exists in the row numbers of the effective code rows, wherein the row number of the missing record is not recorded in the information of the basic block and is positioned in the row number interval formed by the recorded minimum row number and the maximum row number included in the information of the basic block;
and S4, when detecting that the row number of the missing record exists in the row numbers of the effective code rows, recording the row number of the missing record as the row number of the compiled code rows.
Optionally, the storage medium is further arranged to store program code for performing the steps of: and filling the missing recorded line number as the line number of the compiled code line into an execution information file generated by executing the source code, wherein the execution information file at least comprises: the line number, recorded as a compiled line of code, is recorded as the number of times the compiled line of code is executed.
Optionally, the storage medium is further arranged to store program code for performing the steps of: and supplementing the row number of the missing record to a corresponding position in the execution information file according to the sequence of the row numbers, and recording the number of times of executing the code row corresponding to the row number of the missing record at the position, wherein the number of times of executing the code row corresponding to the row number of the missing record is equal to the number of times of executing the code row corresponding to the row number of the compiled code row in the row number section where the row number of the missing record is located.
Optionally, the storage medium is further arranged to store program code for performing the steps of: filtering comment lines, blank lines and symbol information irrelevant to the execution of the source code from the source code to obtain a first code; and recording the line number of the code line in the first code as the line number of the effective code line.
Optionally, the storage medium is further arranged to store program code for performing the steps of: acquiring information of each basic block from a compilation information file using a predetermined identifier, wherein the identifier is used for identifying the starting position of the basic block; and identifying the identification of the basic block and the line number of the compiled code line from the information of the basic block, wherein the line number of the compiled code line comprises the minimum line number and the maximum line number which are recorded.
Optionally, the specific examples in this embodiment may refer to the examples described in embodiment 1 and embodiment 2, and this embodiment is not described herein again.
Optionally, in this embodiment, the storage medium may include, but is not limited to: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and other various media capable of storing program codes.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
The integrated unit in the above embodiments, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in the above computer-readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing one or more computer devices (which may be personal computers, servers, network devices, etc.) to execute all or part of the steps of the method according to the embodiments of the present invention.
In the above embodiments of the present invention, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In the several embodiments provided in the present application, it should be understood that the disclosed client may be implemented in other manners. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one type of division of logical functions, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.

Claims (10)

1. A method for detecting a code compiling result is characterized by comprising the following steps:
acquiring information of basic blocks from a compiling information file generated by compiling a source code, wherein the information of each basic block comprises: recording a line number of a compiled code line in a piece of code in the source code;
acquiring a line number of an effective code line from the source code;
detecting whether a missing recorded line number exists in the line numbers of the effective code lines, wherein the missing recorded line number is a line number which is not recorded in the information of the basic block and is positioned in a line number interval formed by a recorded minimum line number and a recorded maximum line number included in the information of the basic block; and
when detecting that the line number of the missing record exists in the line numbers of the effective code lines, recording the line number of the missing record as the line number of the compiled code lines;
the obtaining of the line number of the effective code line from the source code includes: filtering out comment lines, blank lines and symbol information irrelevant to the execution of the source code from the source code to obtain a first code, wherein the first code comprises code lines relevant to the actual execution of the source code; and recording the line number of the code line in the first code as the line number of the effective code line.
2. The method of claim 1, wherein recording the line number of the missing record as the line number of the line of compiled code comprises:
and filling the line number of the missing record as the line number of the compiled code line into an execution information file generated by executing the source code, wherein the execution information file at least comprises: the line number of the compiled line of code is recorded, and the number of times the compiled line of code is executed is recorded.
3. The method of claim 2, wherein padding the line number of the missing record as the line number of the compiled code line into an execution information file generated by the execution of the source code comprises:
and supplementing the line numbers of the missing records to corresponding positions in the execution information file according to the sequence of the line numbers, and recording the executed times of the code lines corresponding to the line numbers of the missing records at the positions, wherein the executed times of the code lines corresponding to the line numbers of the missing records are equal to the executed times of the code lines corresponding to the line numbers of the compiled code lines in the line number interval where the line numbers of the missing records are located.
4. The method of claim 1, wherein obtaining information of the basic block from a compilation information file generated by compiling the source code comprises:
acquiring information of each basic block from the compilation information file by using a predetermined identifier, wherein the identifier is used for identifying the starting position of the basic block;
and identifying the identification of the basic block and the line number of the compiled code line from the information of the basic block, wherein the line number of the compiled code line comprises the recorded minimum line number and maximum line number.
5. An apparatus for detecting a result of code compilation, comprising:
a first obtaining module, configured to obtain information of basic blocks from a compilation information file generated by compiling a source code, where the information of each basic block includes: recording a line number of a compiled code line in a piece of code in the source code;
the second acquisition module is used for acquiring the line number of the effective code line from the source code;
the detection module is used for detecting whether a missing recorded line number exists in the line numbers of the effective code lines, wherein the missing recorded line number is a line number which is not recorded in the information of the basic block and is positioned in a line number interval formed by a recorded minimum line number and a recorded maximum line number included in the information of the basic block; and
the recording module is used for recording the line number of the missing record as the line number of the compiled code line when the line number of the missing record exists in the line numbers of the effective code line;
wherein the second obtaining module comprises: the filtering module is used for filtering out comment lines, blank lines and symbol information irrelevant to the execution of the source code from the source code to obtain a first code, and the first code comprises code lines relevant to the actual execution of the source code; and the first sub-recording module is used for recording the line number of the code line in the first code as the line number of the effective code line.
6. The apparatus of claim 5, wherein the recording module comprises:
a supplement module, configured to supplement the missing line number as a line number of a compiled code line into an execution information file generated when the source code is executed, where the execution information file at least includes: the line number of the compiled line of code is recorded, and the number of times the compiled line of code is executed is recorded.
7. The apparatus of claim 6, wherein the logging module comprises:
and the first sub-padding module is used for padding the missing recorded line number to a corresponding position in the execution information file according to the sequence of the line number, and recording the number of times that a code line corresponding to the missing recorded line number is executed at the position, wherein the number of times that the code line corresponding to the missing recorded line number is executed is equal to the number of times that a code line corresponding to a line number of a compiled code line in a line number interval where the missing recorded line number is located is executed.
8. The apparatus of claim 5, wherein the first obtaining module comprises:
a first sub-obtaining module, configured to obtain information of each basic block from the compiled information file by using a predetermined identifier, where the identifier is used to identify a start position of the basic block;
and the identification module is used for identifying the identification of the basic block and the line number of the compiled code line from the information of the basic block, wherein the line number of the compiled code line comprises the recorded minimum line number and the maximum line number.
9. A storage medium, in which a computer program is stored, wherein the computer program is arranged to perform the method of any of claims 1 to 4 when executed.
10. An electronic device comprising a memory and a processor, wherein the memory has stored therein a computer program, and wherein the processor is arranged to execute the computer program to perform the method of any of claims 1 to 4.
CN201610172311.5A 2016-03-23 2016-03-23 Method and device for detecting code compiling result Active CN105843740B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610172311.5A CN105843740B (en) 2016-03-23 2016-03-23 Method and device for detecting code compiling result

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610172311.5A CN105843740B (en) 2016-03-23 2016-03-23 Method and device for detecting code compiling result

Publications (2)

Publication Number Publication Date
CN105843740A CN105843740A (en) 2016-08-10
CN105843740B true CN105843740B (en) 2020-08-04

Family

ID=56583211

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610172311.5A Active CN105843740B (en) 2016-03-23 2016-03-23 Method and device for detecting code compiling result

Country Status (1)

Country Link
CN (1) CN105843740B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106383781B (en) * 2016-09-05 2020-02-14 中国银行股份有限公司 Method and device for realizing code analysis
US20180173610A1 (en) * 2016-12-19 2018-06-21 Mediatek Inc. Method for performing cared-zone code coverage evaluation with no source code modification
CN109271321B (en) * 2018-09-20 2021-08-20 杭州安恒信息技术股份有限公司 Method and device for counting contribution code number

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7861226B1 (en) * 2006-03-16 2010-12-28 Avaya Inc. Constraint solver to code based test data generation for improving software reliability and security
CN103631707B (en) * 2012-08-27 2018-01-30 腾讯科技(深圳)有限公司 A kind of method and device for obtaining code coverage
CN103092761B (en) * 2013-02-05 2015-05-27 烽火通信科技股份有限公司 Method and device of recognizing and checking modifying code blocks based on difference information file

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Exploiting Basic Block Value Locality with Block Reuse;Jian Huang;《Proceedings Fifth International Symposium on High-Performance Computer Architecture》;20020806;第1-9 *
基于编译器插件的轻量级内核重构加固方法研究;王曼丽;《软件 , Computer engineering & Software》;20141231;第35卷(第12期);第12-19页 *

Also Published As

Publication number Publication date
CN105843740A (en) 2016-08-10

Similar Documents

Publication Publication Date Title
CN108845930B (en) Interface operation test method and device, storage medium and electronic device
CN108984389B (en) Application program testing method and terminal equipment
CN107038108B (en) Software testing method and device
US8245212B2 (en) Building call tree branches and utilizing break points
CN108491321B (en) Method and device for determining test case range and storage medium
CN111683055A (en) Industrial honey pot control method and device
CN105843740B (en) Method and device for detecting code compiling result
CN107277019B (en) Data plaintext acquisition method and device, electronic terminal and readable storage medium
CN110543420B (en) Software testing method, system, terminal and storage medium
CN109271315B (en) Script code detection method, script code detection device, computer equipment and storage medium
CN106487602B (en) Application program release version monitoring method and monitoring device
CN112817866A (en) Recording playback method, device, system, computer equipment and storage medium
CN110287700B (en) iOS application security analysis method and device
CN111538665A (en) Program testing method and device, storage medium, and electronic device
CN109918221B (en) Hard disk error reporting analysis method, system, terminal and storage medium
CN112671878B (en) Block chain information subscription method, device, server and storage medium
CN110688173B (en) Positioning method and device of components in cross-platform interface framework and electronic equipment
CN110647457B (en) Data mining method, data processing method and system
CN113535580B (en) CTS test method, CTS test device and test equipment
CN115657981A (en) Method for setting print level of print information in authentication environment and authentication method
CN113326046B (en) Method and device for acquiring compiling time length
CN109582574A (en) A kind of code coverage statistical method, device, storage medium and terminal device
CN106776264B (en) Application program code testing method and device
CN113868137A (en) Method, device and system for processing buried point data and server
CN113806231A (en) Code coverage rate analysis method, device, equipment and medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant