Program inspection apparatus, and program inspection method
The program inspection apparatus addresses the challenge of identifying true error causes in source code by using a compiler to analyze changes in error occurrence positions resulting from equivalent changes, thereby clarifying the root cause of errors.
Patent Information
- Application Number
- JP2023576622
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Priority Date
- 2022-01-27
- Filing Date
- 2022-10-24
- Publication Date
- 2025-06-11
- Estimated Expiration
- 2042-10-24
AI Technical Summary
It is challenging to identify the true cause of errors in source code when process-equivalent changes are made, as the behavioral changes caused by these changes can be unclear.
A program inspection apparatus is configured with a computer that executes a compiler to identify error occurrence positions in source code, generates change position candidates for equivalent changes, and determines the true error cause position based on changes in error occurrence positions.
The apparatus effectively clarifies the true cause of errors by analyzing changes in compiler behavior resulting from equivalent changes in the source code.
Smart Images

Figure 0007691528000001 
Figure 0007691528000002 
Figure 0007691528000003
Abstract
Description
Incorporation by reference
[0001] This application claims the priority of Japanese Patent Application No. 2022-11199, filed on January 27, 2022, and incorporates its content by reference herein.
Technical Field
[0002] The present invention relates to a program inspection device.
Background Art
[0003] When a compiler compiles source code, incorrect source code descriptions may not be output as errors, and the influence may spread to other parts, resulting in normal descriptions being output as errors. Since the user is not directly notified of the cause of the error, it may be difficult to correct the incorrect part.
[0004] As the background art in this technical field, there is the following prior art. Patent Document 1 (Japanese Unexamined Patent Application Publication No. 2010-117808) describes that when referring to a source file of a program, if there is a pointer-type variable to data of 2 bytes or more in the program, a process of automatically calling a misalignment check library for detecting misalignment is added to generate an object file. The debug device executes instructions based on the object file, and if it reaches the error routine process in the misalignment check library, a break occurs, and a language processing device for detecting misalignment is described.
[0005] Patent Document 2 (Japanese Patent Application Laid-Open No. 2012-048445) describes a program execution device 120 including an instruction execution unit that executes an object program, a cache memory that temporarily holds the object program, a program loading unit that reads the object program and causes the cache memory to hold it in response to a fetch request for the object program by the instruction execution unit, and a check code determination unit that sequentially calculates a check code derivation formula for the read object program, generates a check code in block units, and determines the validity of the object program in block units by comparing it with a check code pre-inserted into the object program.
Summary of the Invention
Problems to be Solved by the Invention
[0006] When a process-equivalent change is made to the source code, the behavior of the compiler (e.g., the presence or absence of errors, the location where errors occur) may change. However, it is difficult to clarify the true cause of an error from the behavioral changes due to process-equivalent changes.
[0007] The present invention has been made to solve the above-described problems, and an object thereof is to provide an inspection device that clarifies the true cause of an error from seemingly unclear behavioral changes.
Means for Solving the Problems
[0008] A typical example of the invention disclosed in the present application is as follows. That is, a program inspection apparatus is configured by a computer having an arithmetic unit that executes predetermined arithmetic processing and a storage device connected to the arithmetic unit. The storage device stores at least a compiler that compiles source code. The arithmetic unit, by executing the compiler, identifies the error occurrence position in the source code, generates a change position candidate for applying an equivalent change to the source code, by executing the compiler, identifies the error occurrence position in the source code to which the equivalent change has been applied to the change position candidate, and identifies the true error cause position in the source code based on the change in the error occurrence position.
Effect of the Invention
[0009] According to one aspect of the present invention, the code that is the true cause can be identified from the change in the operation of the compiler. Problems, configurations, and effects other than those described above will be clarified by the description of the following embodiments.
Brief Description of the Drawings
[0010]
Figure 1
Figure 2
Figure 3
Figure 4
Figure 5
Figure 6
Figure 7A
Figure 7B
Figure 8A
Figure 8B
Embodiments for Carrying Out the Invention
[0011] Hereinafter, embodiments of the present invention will be described with reference to the drawings. It should be noted that the present invention is not limited to the following embodiments, and within the scope not departing from the gist of the present invention, the configurations of each part can be appropriately added, changed, deleted, etc. and implemented.
[0012] <Example 1> FIG. 1 is a block diagram showing an example of the configuration of the inspection apparatus 1 according to Example 1 of the present invention.
[0013] The inspection apparatus 1 is an apparatus for inspecting the inspection target code 9 which is source code, and is composed of a computer including a processor (CPU) 20, a storage device (HDD) 21, a communication device 22, and a memory 23. The processor 20, the storage device (HDD) 21, the communication device 22, and the memory 23 are connected via an interconnect 24. The inspection apparatus 1 may have an input interface and an output interface (not shown).
[0014] The processor 20 is an arithmetic unit that executes a program stored in the memory 23. Hereinafter, for convenience, the program may be described as the operating entity of each process, but the actual operating entity of each process is the processor 2. Note that a part of the process performed by the processor 20 executing the program may be executed by another arithmetic unit (for example, hardware such as an ASIC or FPGA).
[0015] The memory 23 includes a ROM which is a non-volatile memory element and a RAM which is a volatile memory element. The ROM stores unchangeable programs (such as BIOS). The RAM is a high-speed and volatile memory element like a DRAM (Dynamic Random Access Memory), and temporarily stores the programs executed by the processor 20 and the data used during the execution of the programs. The memory 23 stores an analysis program 4, a code modification program 5, an inspection program 6, an end determination program 7, a compiler 8, a code to be inspected 9, initial error information 10, modified code 11, the previous error position 12, and a dummy code database 13.
[0016] The auxiliary storage device 21 is a large-capacity and non-volatile storage device such as a magnetic storage device (HDD) or a flash memory (SSD). The auxiliary storage device 21 stores the data used by the processor 20 during program execution (such as the code to be inspected 9, initial error information 10, modified code 11, the previous error position 12, the dummy code database 13, etc.) and the programs executed by the processor 20. That is, the programs are read from the auxiliary storage device 21, loaded into the memory 23, and executed by the processor 20 to realize each function of the inspection device 1.
[0017] The communication device 22 is a network interface device that controls communication with other devices according to a predetermined protocol.
[0018] The input interface is an interface to which input devices such as keyboards and mice are connected and which receives inputs from the operator. The output interface is an interface to which output devices such as display devices and printers are connected and which outputs the execution results of the program (e.g., the identified true error cause location) in a form visible to the operator. Note that a user terminal connected to the inspection device 1 via a network may provide the input device and the output device. In this case, the inspection device 1 may have the function of a web server, and the user terminal may access the inspection device 1 using a predetermined protocol (e.g., http).
[0019] The program executed by the processor 20 is provided to the inspection device 1 via a removable medium (such as a CD-ROM or a flash memory) or a network and stored in the non-volatile auxiliary storage device 21 which is a non-temporary storage medium. Therefore, the inspection device 1 may preferably have an interface for reading data from the removable medium.
[0020] The inspection device 1 is a computer system configured physically on one computer or on a plurality of computers configured logically or physically, and may operate on a virtual computer built on a plurality of physical computer resources. For example, the analysis program 4, the code change program 5, the inspection program 6, the end determination program 7, and the compiler 8 may each operate on a separate physical or logical computer, or a plurality of them may be combined to operate on one physical or logical computer.
[0021] FIG. 2 is a configuration diagram of the functional elements of the inspection device 1 according to the first embodiment.
[0022] In the inspection device 1, the analysis program 4 analyzes the code to be inspected 9, the code modification program 5 inserts dummy code into the code to be inspected 9, makes an equivalent modification such that the code to be inspected 9 performs the same operation, outputs it as the modified code 11, the compiler 8 compiles the modified code 11, the inspection program 6 inspects the result of the compilation, and the end determination program 7 determines the end of the process. Details of each process will be described with reference to the flowcharts after FIG. 3. When the end determination program 7 determines to continue the process, it instructs the code modification program 5 to insert dummy code at the next dummy code insertion position candidate, and until the end determination program 7 determines the end of the process, the inspection process of the code to be inspected 9 by the code modification program 5, the compiler 8, and the inspection program 6 is repeated.
[0023] FIG. 3 is a flowchart showing an example of the process executed by the analysis program 4 according to the first embodiment. The analysis program 4 analyzes the code to be inspected 9 which is the source code, and outputs dummy code insertion position candidates.
[0024] In step 101, the analysis program 4 acquires the code to be inspected 9 to be analyzed.
[0025] In step 102, the analysis program 4 analyzes the acquired code to be inspected 9. For example, it searches for the break points of sentences. The analysis program 4 may use a syntax analysis algorithm.
[0026] In step 103, the analysis program 4 generates dummy code insertion position candidates. The analysis program 4 may generate dummy code insertion position candidates for the entire range of the code 9 to be inspected. Also, when inserting dummy code from the beginning of the code 9 to be inspected, dummy code insertion position candidates may be generated in the range from the beginning of the code 9 to the error position of the initial error information 10, or dummy code insertion position candidates may be generated in the range from the beginning of the code 9 to several lines below the error position of the initial error information 10. Also, when inserting dummy code from the end of the code 9 to be inspected, dummy code insertion position candidates may be generated in the range from the end of the code 9 to the error position of the initial error information 10, or dummy code insertion position candidates may be generated in the range from the end of the code 9 to several lines above the error position of the initial error information 10.
[0027] In step 104, the analysis program 4 outputs the generated dummy code insertion position candidates to the code change program 5.
[0028] Figure 4 is a flowchart showing an example of the processing executed by the code change program 5 according to the first embodiment. The code change program 5 inserts dummy code into one of the dummy code insertion position candidates to generate the changed code 11.
[0029] In step 201, the code change program 5 obtains the dummy code insertion position generated by the analysis program 4.
[0030] In step 202, the code change program 5 obtains a dummy code description from the dummy code database 13. The dummy code is a variable declaration statement or a function call statement not directly related to the process. It is advisable to prepare the dummy code in the dummy code database 13 for each pattern that can be parsed syntactically. The inserted dummy code preferably has the same nature as the error line in terms of grammar. The code change program 5 may determine the dummy code to be inserted according to the type of dummy code determined by the analysis program 4 referring to the initial error information 10. The dummy code may be determined according to the error information that occurs or may occur. For example, when only a specific error occurs in the code under test 9 or only a specific type of error is recorded in the initial error information 10, one type of dummy code corresponding to the error may be used. The initial error information 10 is the position information of the error line before dummy code insertion obtained by the first compilation of the program.
[0031] In step 203, the code change program 5 inserts the dummy code at the dummy code insertion position candidate and changes the source code. For example, in the code under test 9 before dummy code insertion shown in FIG. 7A, when the dummy code is inserted on the 7th line, the changed code 11 shown in FIG. 7B is obtained.
[0032] In step 204, the code change program 5 outputs the changed code 11 with the dummy code inserted and the information of the dummy code insertion position to the compiler 8, and outputs the information of the dummy code insertion position to the inspection program 6.
[0033] FIG. 5 is a flowchart showing an example of the process executed by the inspection program 6 according to the first embodiment. The inspection program 6 compares the dummy code insertion location with the location where the compilation error occurs and outputs the inspection result.
[0034] In step 301, the inspection program 6 obtains the object code generated by the compiler 8 from the changed code 11 with the dummy code inserted, the error occurrence position generated during compilation, and the information of the dummy code insertion position.
[0035] In step 302, the inspection program 6 performs a comparative analysis on the dummy code insertion location and the location where a compilation error occurs to obtain an inspection result.
[0036] In step 303, the inspection program 6 outputs the inspection result (whether the insertion location results in an error) to the end determination program 7.
[0037] FIG. 6 is a flowchart showing an example of the process executed by the end determination program 7 according to the first embodiment. The end determination program 7 estimates the true error cause location based on whether there is a change in the inspection result.
[0038] In step 401, the end determination program 7 obtains the inspection result and the previous error position.
[0039] In step 402, the end determination program 7 determines whether the obtained inspection result indicates "there is a change". If the inspection result indicates "there is a change", the process proceeds to step 404; otherwise, the process proceeds to step 403.
[0040] If the dummy code insertion position changes, the error position changes. If there is no change in the error position from the previous error position, the true error location is before the dummy code insertion position. Therefore, if the dummy code insertion position is shifted forward from the last part and the error position (the line number where the error occurs) does not change, it can be estimated that there is a true error location between the dummy code insertion position and the error position.
[0041] For example, in the code to be inspected 9 shown in Fig. 8A, dummy code is inserted at line number 7, and an error has occurred at the dummy code insertion position. This is because ref_t defined on the first line is redefined on the fifth line, and an error has occurred in the function prompt declaration (line 7) that uses the doubly defined ref_t. Next, in the code to be inspected 9 shown in Fig. 8B, no error occurs at the position of the dummy code inserted at line number 4, but an error occurs in the error message of the initial error information 10. This is because no error occurs in the dummy code inserted at line number 4 before the redefinition of ref_t on line 6. Therefore, in Fig. 8B, it can be determined that there is a true error cause between the current dummy code insertion position and the previous dummy code insertion position.
[0042] In step 403, if the inspection result is "there is a change", the end determination program 7 identifies the true error cause position from the obtained result, outputs the identified true error cause position from the output interface or the communication device 22, and ends the process.
[0043] In step 404, if the inspection result is "no change", the end determination program 7 records the current error position in the previous error position 12. The previous error position 12 is used to compare whether there is a change in the error position during the next compilation.
[0044] In step 405, the end determination program 7 inserts dummy code at the next dummy code insertion position and instructs the code change program 5 to continue the inspection process of the code to be inspected 9.
[0045] As described above, the program inspection apparatus 1 according to the embodiment of the present invention identifies the error occurrence position of the code to be inspected (source code) 9 by executing the compiler 8, generates a change position candidate (dummy code insertion position candidate) to which an equivalent change is applied to the code to be inspected 9, identifies the error occurrence position of the source code to which the equivalent change is applied (dummy code is inserted into the dummy code insertion position candidate) by executing the compiler 8, and identifies the true error cause position of the code to be inspected 9 based on the change in the error occurrence position. Therefore, it is possible to estimate the description of the code that is the true cause from the change in the operation of the compiler 8.
[0046] Note that the present invention is not limited to the above-described embodiments, and includes various modifications and equivalent configurations within the scope of the appended claims. For example, the above-described embodiments have been described in detail for easy understanding of the present invention, and the present invention is not necessarily limited to those having all the configurations described. Also, a part of the configuration of one embodiment may be replaced with the configuration of another embodiment. Further, the configuration of another embodiment may be added to the configuration of one embodiment. Also, for a part of the configuration of each embodiment, addition, deletion, or replacement with other configurations may be performed.
[0047] In addition, each of the above-described configurations, functions, processing units, processing means, etc. may be realized in hardware, for example, by designing a part or all of them with an integrated circuit, or may be realized in software by a processor interpreting and executing a program that realizes each function.
[0048] Information such as programs, tables, and files that realize each function can be stored in a storage device such as a memory, a hard disk, an SSD (Solid State Drive), or a recording medium such as an IC card, an SD card, or a DVD.
[0049] Also, the control lines and information lines show those considered necessary for explanation, and do not necessarily show all the control lines and information lines necessary for implementation. In practice, it may be considered that almost all configurations are interconnected.
Claims
1. A program inspection device, composed of a computer having an arithmetic unit that executes predetermined arithmetic processing and a storage device connected to the arithmetic unit, wherein the storage device stores at least a compiler for compiling source code, and the arithmetic unit identifies the error occurrence position of the source code by executing the compiler, generates a change position candidate for applying an equivalent change to the source code, identifies the error occurrence position of the source code to which the equivalent change is applied to the change position candidate by executing the compiler, and identifies the true error cause position of the source code based on the change in the error occurrence position, characterized in that it is a program inspection device.
2. The program inspection device according to claim 1, wherein the range for applying the equivalent change is determined in relation to the error occurrence position of the source code before the equivalent change, characterized in that it is a program inspection device.
3. The program inspection device according to claim 1, wherein the equivalent change is the insertion of dummy code that makes the source code perform the same operation, characterized in that it is a program inspection device.
4. The program inspection device according to claim 3, wherein the equivalent change is the insertion of dummy code having the same nature as the code at the error occurrence position of the source code before the application of the equivalent change, characterized in that it is a program inspection device.
5. The program inspection device according to claim 3, wherein the arithmetic unit estimates that the range in which the error occurrence position changes due to the change in the insertion position of the dummy code is the true error cause position, characterized in that it is a program inspection device.
6. A program inspection method executed by a program inspection device, wherein the program inspection device is composed of a computer having an arithmetic unit that executes predetermined arithmetic processing and a storage device connected to the arithmetic unit, the storage device stores at least a compiler for compiling source code, and the program inspection method includes the arithmetic unit identifying the error occurrence position of the source code by executing the compiler, the arithmetic unit generating a change position candidate for applying an equivalent change to the source code, and the arithmetic unit identifying the error occurrence position of the source code to which the equivalent change is applied to the change position candidate by executing the compiler, A program inspection method, characterized in that the arithmetic unit specifies a true error cause position of the source code based on a change in the error occurrence position.
Citation Information
Patent Citations
Crash source code positioning method and device, medium and electronic equipment
CN113918444A
Error knowledge base generator
JP1997044347A