Compiler dependency extracting device, and source code analysis system
The compiler dependency extraction device facilitates efficient and accurate source code analysis using a general-purpose compiler by tagging and extracting source code based on compiler information, addressing the limitations of existing methods that require dedicated compilers.
Patent Information
- Application Number
- JP2023024362
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-02-20
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2043-02-20
AI Technical Summary
Existing source code analysis methods, particularly static analysis, are limited by the need for a dedicated compiler to support specific compilers, making it difficult to analyze source code using general-purpose compilers.
A compiler dependency extraction device that includes a tagging condition database, a source code tagging unit, and an analysis target extraction unit to tag and extract source code based on compiler information, allowing analysis with a general-purpose compiler.
Enables efficient analysis of source code using a general-purpose compiler without relying on specific compilers, ensuring accurate and adaptable analysis that considers the unique characteristics of the development project.
Smart Images

Figure 2024118113000001
Abstract
Description
[Technical field]
[0001] The present disclosure relates to a compiler dependency extraction device and a source code analysis system. [Background technology]
[0002] Methods for detecting defects in software include source code analysis techniques such as static analysis and dynamic analysis. Source code analysis techniques can be performed at a lower cost than when a person actually visually detects defects, and can detect defects even in large-scale source code.
[0003] In order to perform more accurate source code analysis on source code, it is necessary to transmit information about the source code to be analyzed to the analysis system. A representative example of the information about the source code to be analyzed is compiler information, which is information required for compiling the source code.
[0004] The source code of software that runs on a microcontroller often assumes that it will be compiled with a dedicated compiler, and the source code contains descriptions that are dependent on the compiler. Dedicated compilers are often developed by microcontroller vendors, and there has been a problem in that advanced source code analysis methods such as static analysis cannot be performed unless a dedicated analysis system that supports the compiler is used.
[0005] To solve this problem, a method is used in which the source code has branches that depend on both compilers so that the code can be run on analysis systems that support the other specific compiler.
[0006] For example, in source code written in the C language, it is possible to describe compiler information using directives and to use if directives to achieve different behavior for each type of compiler (see, for example, non-patent document 1).
[0007] This method has the disadvantage that the source code becomes complicated because it is necessary to add compiler information to the source code. Thus, there was a problem in the past that it was not possible to analyze the source code using a specific compiler without adding compiler information to the source code.
[0008] Moreover, Patent Document 1 discloses a technique for allowing platform-dependent source code to run independently of the platform. [Prior art documents] [Patent documents]
[0009] [Patent Document 1] Special Publication No. 2015-524126 [Non-patent literature]
[0010] [Non-Patent Document 1] Coding Practices Guide for Embedded Software Development (https: / / www.ipa.go.jp / files / 000064005.pdf) Summary of the Invention [Problem to be solved by the invention]
[0011] As described above, the technology described in Patent Document 1 is a technology for running platform-dependent source code independently of the platform, and is not a technology for performing source code analysis using a general-purpose compiler.
[0012] Therefore, an object of the present disclosure is to provide a technique that enables efficient analysis of source code to be analyzed using a general-purpose compiler, without relying on a specific compiler. [Means for solving the problem]
[0013] The compiler dependency extraction device according to the present disclosure includes a tagging condition DB in which a plurality of tagging conditions for assigning tags to source code are stored, a source code tagging unit that determines, from the plurality of tagging conditions stored in the tagging condition DB, a tagging condition that matches the source code included in a source code project to be analyzed, and assigns the tag to the source code included in the source code project based on the tagging condition, a tagged source code DB that stores the source code included in the source code project in association with the assigned tag, and a source code to be analyzed extraction unit that extracts the source code to be analyzed and the assigned tag from the tagged source code DB in association with each other based on compiler information used when analyzing the source code to be analyzed. Effect of the Invention
[0014] According to the present disclosure, by analyzing the source code to be analyzed extracted by the analysis target source code extraction unit, it is possible to efficiently analyze the source code to be analyzed using a general-purpose compiler without relying on a specific compiler. [Brief description of the drawings]
[0015] [Figure 1] 1 is a functional block diagram showing an outline of a configuration of a source code analysis system according to an embodiment; [Diagram 2] 4 is a sequence diagram showing a process flow of the source code analysis system according to the embodiment; FIG. [Diagram 3] 4 is a flowchart showing a process related to a compiler dependency extraction device according to an embodiment. [Figure 4] 10 is a flowchart showing a process related to a source code tagging unit included in the compiler dependency extraction device according to the embodiment. [Diagram 5] 4 is a diagram showing a tagging condition DB table stored in a tagging condition DB included in the compiler dependency extraction device according to the embodiment. FIG. [Figure 6]4 is a diagram showing a tagged source code DB table stored in a tagged source code DB included in the compiler dependency extraction device according to the embodiment. FIG. [Figure 7] 1 is a block diagram showing an example of a hardware configuration of a compiler dependency extraction device according to an embodiment; [Figure 8] 1 is a block diagram showing an example of a hardware configuration of a compiler dependency extraction device according to an embodiment; DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0016] <Embodiment> <Analysis system configuration> DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS The following describes an embodiment of the present invention with reference to the accompanying drawings, in which: Fig. 1 is a functional block diagram showing an outline of the configuration of an analysis system 102 according to an embodiment of the present invention.
[0017] As shown in FIG. 1, an analysis system 102 (source code analysis system) is connected to a user terminal 101 and a source code repository 103, and analyzes source code in a source code project stored in the source code repository 103 in response to input from the user terminal 101.
[0018] The user terminal 101 is a terminal that a user uses to operate the analysis system 102. The analysis system 102 analyzes source code in a source code project and outputs the analysis results to the user terminal 101. The source code repository 103 is a database that stores the source code project to be analyzed.
[0019] The analysis system 102 includes a source code analysis device 104 and a compiler dependency extraction device 105 .
[0020] The source code analysis device 104 is a device that analyzes source code to be analyzed based on compiler information, and is capable of selecting compiler information to be used as an analysis condition.
[0021] The compiler dependency extraction device 105 is a device that extracts source code to be analyzed based on compiler information used when analyzing the source code to be analyzed. The compiler dependency extraction device 105 includes a tagging condition DB 106, a source code tagging unit 107, a tagged source code DB 108, and an analysis target source code extraction unit 109.
[0022] The tagging condition DB 106 is a database that stores a plurality of tagging conditions for attaching tags to source code. The tagging condition DB 106 stores in advance pairs of source code patterns and tags to be attached.
[0023] The source code tagging unit 107 determines a tagging condition that matches the source code included in the source code project to be analyzed from among multiple tagging conditions stored in the tagging condition DB 106, and assigns tags to the source code included in the source code project based on the determined tagging condition.
[0024] The tagged source code DB 108 is a database that stores source code included in a source code project and tags added by the source code tagging unit 107 in association with each other.
[0025] The analysis target source code extraction unit 109 extracts and links the source code to be analyzed with the assigned tags from the tagged source code DB 108 based on the compiler information used when analyzing the source code to be analyzed, and outputs the extracted source code in a data format that can be used by the source code analysis device 104.
[0026] Here, the trigger for analyzing the source code may be based not only on an input from the user terminal 101, but also on a preset time. Specifically, the source code analysis device 104 may be connected to a scheduling device 110 that issues an analysis execution command based on a preset time. The scheduling device 110 may be built into the user terminal 101, or may be provided as a peripheral device of the analysis system 102 separately from the user terminal 101. Alternatively, the user terminal 101 and the scheduling device 110 may be provided within the analysis system 102.
[0027] For example, analysis can be continuously performed once a week by setting the analysis start time to 0:00 every Friday for analysis system 102. This can eliminate human errors such as input errors and forgotten inputs when performing source code analysis, compared to when input from user terminal 101 is used as a trigger.
[0028] Furthermore, when the analysis is triggered by input from the user terminal 101, the timing of analysis execution is left to human judgment, and so there is a possibility that the analysis results may not reflect the actual situation if the conditions for executing the analysis are not met or if the person in charge of analysis executes the analysis when the source code is in a good state. By executing the analysis based on a preset time, it is possible to execute an analysis of the source code that reflects the actual situation.
[0029] The operation of the analysis system 102 will be described. Fig. 2 is a sequence diagram showing a process flow of the analysis system 102 according to the embodiment. Here, a flow will be described from when a source code analysis execution command is issued by the user terminal 101 to when source code analysis is executed and until the analysis result of the source code is displayed.
[0030] 2, the user terminal 101 outputs a source code analysis execution command 201 to the source code analysis device 104. The source code analysis execution command 201 may include all or part of the compiler information used when analyzing the source code to be analyzed. In this case, the compiler information included in the source code analysis execution command 201 may be added to or overwritten on the compiler information read by reading in a source code analysis environment 202, which will be described later.
[0031] Next, the source code analysis device 104 reads compiler information to be used for analysis by reading in the source code analysis environment 202. The compiler information may include not only the compiler name itself, but also the programming language, the version of the programming language specification, or a specific project name. Here, the compiler information is represented in a data format such as "C90" or "RH850".
[0032] Also, depending on the tag, the same name may have different meanings depending on the category to which it belongs. For example, if there is a tag called "C90" that identifies a past project, it may be difficult to distinguish it from "C90", which is the version of the C language specification. To avoid this, information necessary to identify the meaning of the tag may be added. For example, in the case of "C90" above, the tag name may be set so that the multiple meanings of "C90" can be distinguished by adding the category name as a prefix, such as "Project: C90" or "Programming Language Specification: C90".
[0033] Furthermore, the compiler information may be not only a single character string, but also an array of character strings including multiple tags and logical expressions such as AND and OR, for example, a data format such as "(C90 OR C99) AND RH850".
[0034] Returning to the explanation of the operation of the analysis system 102, the source code analysis device 104 outputs compiler information to the compiler dependency extraction device 105 in response to a call 203 of the source code to be analyzed, and requests the source code to be analyzed.
[0035] The compiler dependency extraction device 105 requests the source code to be analyzed by making a source code call 204 to the source code repository 103. One method for acquiring the source code is to specify the URL of the source code repository 103. The source code is acquired by accessing the specified URL of the source code repository 103 via a protocol such as HTTP or SSH. Alternatively, the compiler dependency extraction device 105 may acquire the source code from its own file system.
[0036] The compiler dependency extraction device 105 extracts compiler dependencies from the source code and compiler information (205), and generates source code to be analyzed. Details of the compiler dependency extraction (205) will be described later with reference to FIG.
[0037] The source code analysis device 104 executes (206) source code analysis using the compiler information read in (202) source code analysis environment and the source code to be analyzed, and upon completion of the source code analysis, notifies (207) the user terminal 101 of the completion of the source code analysis. Upon receiving (207) the notification of the completion of the source code analysis, the user terminal 101 displays (208) the analysis results.
[0038] Next, a detailed description will be given of the compiler dependency extraction 205. Fig. 3 is a flowchart showing the process related to the compiler dependency extraction device 105 according to the embodiment.
[0039] As shown in FIG. 3, when the process starts, the compiler dependency extraction device 105 receives the URL of the source code repository 103 in which the source code project to be analyzed is stored (step S301), and extracts the source code project from the source code repository 103 (step S302).
[0040] The source code tagging unit 107 extracts a file (source file) in which one source code is stored from the source code project (step S303). The source code tagging unit 107 extracts source code information from the source file (step S304), and assigns a tag to the source file (step S305). If there is a source file that has not been extracted (YES in step S306), the process proceeds to step S303, and steps S303 to S306 are repeated until all source files in the source code project have been tagged.
[0041] In this embodiment, tagging of source code is performed on a source file basis, but tagging may be performed not only on a source file basis, but also on an executable file basis, a directory including a source file basis, a function or variable basis, or a line basis. If tagging is performed on a function basis, a tagging condition DB 106 for determining the tag to be assigned to each function is created in advance. Similarly, the source code location column 601 (see FIG. 6) of the tagged source code DB 108 is written as a character string that can identify a function in the source code.
[0042] For example, for a function "initialize_deviceA()" in "components / deviceA.x", you can write it as "components / deviceA.x##initialize_deviceA" so that the function in the source code can be uniquely identified.
[0043] Furthermore, the granularity at which tagging is performed may not be one, but may be a combination of multiple granularities. If the tagging condition DB 106 and the source code to be tagged have not changed compared to the previous source code analysis, the results of tagging performed in the previous analysis may be reused in order to reduce the time required for tagging. Details of the flow in which the source code tagging unit 107 assigns tags to source files will be described later with reference to FIG. 4.
[0044] If there are no unextracted source files (NO in step S306), the analysis target source code extraction unit 109 determines tags for extracting source code to be output as an analysis target based on the compiler information (step S307). The analysis target source code extraction unit 109 selects, for each source code, a tag that is to be analyzed, thereby extracting the source code to be analyzed (step S308).
[0045] If the tags include a logical expression, then the extraction of source code is conditional on having a particular combination of tags, or having some from a particular set of tags, based on the logical expression.
[0046] For example, if the condition is "(CPU1 AND Compiler1) OR Project1", source code containing both the CPU1 and Compiler1 tags or source code containing the Project1 tag will be selected, and any other source code will not be selected.
[0047] The form of the source code to be extracted for analysis may be one in which the file structure of the original source code project is maintained while excluding source code that does not have tags. After the compiler dependency extraction device 105 returns the extracted source code to be analyzed to the source code analysis device 104 (step S309), the process ends.
[0048] Next, a description will be given of processing related to the source code tagging unit 107. Fig. 4 is a flowchart showing processing related to the source code tagging unit 107 included in the compiler dependency extraction device 105 according to the embodiment. Fig. 5 is a diagram showing a tagging condition DB table stored in the tagging condition DB 106 included in the compiler dependency extraction device 105 according to the embodiment.
[0049] As shown in FIG. 4, when the process starts, the source code tagging unit extracts one tagging condition from the tagging condition DB 106 (step S401), and determines whether the pattern of the tagging condition matches the source code (step S402).
[0050] 5, a condition for assigning a corresponding tag to source code is described in a pattern column 501. A tag column 502 describes one or more tags to be assigned to the source code when the corresponding pattern is satisfied.
[0051] For example, when a source code contains a macro variable that includes a specific company product name, the source code is highly likely to be related to the corresponding product development project. In that case, it can be assumed that the information on the compiler, microcomputer, CPU architecture, etc. required to compile the corresponding source code is the same as that used in the development project. The user of the analysis system 102 uses knowledge of such past development projects and knowledge of the development tool chain to build the tagging condition DB 106 in advance.
[0052] If the source code matches the tagging conditions (YES in step S403), the source code tagging unit 107 assigns the matching tag to the source code (step S404), associates the source code with the assigned tag, and stores them in the tagged source code DB 108.
[0053] Next, if there are any undetermined tagging conditions (step S405), the process proceeds to step S401, and steps S401 to S405 are repeated until all tagging conditions in the tagging DB table have been determined. If the source code does not match the tagging conditions (NO in step S403), the process proceeds to step S405.
[0054] Since tagging of source code and comparison of the tagged source code with the tagging conditions can be performed in parallel, the tagging and comparison processes to be performed can be listed in advance, and each process can be divided and executed on a different CPU or a different PC in a distributed manner.
[0055] Furthermore, if the tagging conditions and the target source code have not changed since the previous source code analysis, the above two processes may cache the tagging results from the previous source code analysis and reuse them as the results for the next execution, thereby saving the time and computational resources required for tagging.
[0056] Furthermore, if the source code has been partially modified, the previous tagging results may be reused only for the source code that has not been modified, and tagging may be performed for the source code that has been modified.
[0057] FIG. 6 is a diagram showing a tagged source code DB table stored in the tagged source code DB 108 included in the compiler dependency extraction device 105 according to the embodiment.
[0058] 6, the location of the source code to be analyzed is stored in a source code location column 601, and tags to be added to the source code to be analyzed are described in a tag column 602. Note that if there are no tags to be added, zero tags may be described.
[0059] <Hardware configuration> 7 and 8 are block diagrams showing an example of a hardware configuration of the compiler dependency extraction device 105 according to the embodiment.
[0060] As shown in FIG. 7, the tagging condition DB 106 and the tagged source code DB 108 in the compiler dependency extraction device 105 are a storage device 121. The functions of the source code tagging unit 107 and the analysis target source code extraction unit 109 in the compiler dependency extraction device 105 are realized by a processing circuit 120. That is, the compiler dependency extraction device 105 includes a processing circuit 120 for determining a tagging condition that is suitable for a source code included in a source code project to be analyzed from among a plurality of tagging conditions stored in the tagging condition DB 106, attaching a tag to the source code included in the source code project based on the tagging condition, and extracting the source code to be analyzed and the attached tag from the tagged source code DB 108 in association with each other based on compiler information used when analyzing the source code to be analyzed. The processing circuit 120 may be a dedicated hardware or a processor (also called a CPU (Central Processing Unit), a central processing unit, a processing unit, an arithmetic unit, a microprocessor, a microcomputer, or a DSP (Digital Signal Processor)) that executes a program stored in a memory.
[0061] When the processing circuit 120 is a dedicated hardware, the processing circuit 120 corresponds to, for example, a single circuit, a composite circuit, a programmed processor, a parallel programmed processor, an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or a combination of these. Each function of the source code tagging unit 107 and the analysis target source code extraction unit 109 may be realized by the processing circuit 120, or each function may be realized together by one processing circuit 120.
[0062] When the processing circuit 120 is the processor 122 shown in FIG. 8, each function of the source code tagging unit 107 and the analysis target source code extraction unit 109 is realized by software, firmware, or a combination of software and firmware. The software or firmware is written as a program and stored in the memory 123. The processor 122 realizes each function by reading and executing the program recorded in the memory 123. That is, the compiler dependency extraction device 105 includes a memory 123 for storing a program that results in the execution of a step of determining a tagging condition that is suitable for the source code included in the analysis target source code project from among a plurality of tagging conditions stored in the tagging condition DB 106, and assigning a tag to the source code included in the source code project based on the tagging condition, and a step of linking and extracting the analysis target source code and the assigned tag from the tagged source code DB 108 based on the compiler information used when analyzing the analysis target source code. Also, it can be said that these programs cause a computer to execute the procedures or methods of the source code tagging unit 107 and the analysis target source code extraction unit 109. Here, the memory may be, for example, a non-volatile or volatile semiconductor memory such as RAM (Random Access Memory), ROM (Read Only Memory), flash memory, EPROM (Erasable Programmable Read Only Memory), EEPROM (Electrically Erasable Programmable Read Only Memory), a magnetic disk, a flexible disk, an optical disk, a compact disk, a DVD (Digital Versatile Disc), or any storage medium that will be used in the future.
[0063] It should be noted that some of the functions of the source code tagging unit 107 and the analysis target source code extraction unit 109 may be realized by dedicated hardware, and the other functions may be realized by software or firmware.
[0064] In this way, the processing circuit 120 can realize each of the above-mentioned functions by hardware, software, firmware, or a combination of these. Also, the source code analysis device 104 is realized by a hardware configuration similar to that of the compiler dependency extraction device 105.
[0065] <Effects> As described above, the compiler dependency extraction device 105 according to the embodiment includes a tagging condition DB 106 in which a plurality of tagging conditions for tagging source code are stored, a source code tagging unit 107 that determines a tagging condition that is suitable for source code included in a source code project to be analyzed from the plurality of tagging conditions stored in the tagging condition DB 106 and tags the source code included in the source code project based on the tagging condition, a tagged source code DB 108 that stores the source code included in the source code project in association with the assigned tags, and an analysis target source code extraction unit 109 that extracts the source code to be analyzed and the assigned tags from the tagged source code DB 108 in association with each other based on compiler information used when analyzing the source code to be analyzed.
[0066] Moreover, the analysis system 102 according to the embodiment includes a compiler dependency extraction device 105 and a source code analysis device 104 that analyzes the source code to be analyzed that is extracted from the compiler dependency extraction device 105 based on the compiler information.
[0067] Therefore, by analyzing the source code to be analyzed extracted by the analysis target source code extraction unit 109, the source code to be analyzed can be efficiently analyzed using a general-purpose compiler without relying on a specific compiler.
[0068] Furthermore, since the source code in the source code project can be analyzed without being modified, it is possible to realize highly accurate analysis adapted to the characteristics of the source code and the characteristics of the development project that developed the source code.
[0069] Furthermore, since the tagging conditions include information regarding the development project of the source code, it is possible to realize accurate analysis of the source code taking into account the circumstances specific to the development project that developed the source code.
[0070] In addition, since the source code analysis device 104 is connected to a scheduling device 110 that issues an analysis execution command based on a preset time, human errors such as input errors and forgotten inputs regarding the execution of source code analysis can be eliminated compared to when the trigger is input from the user terminal 101.
[0071] It should be noted that the embodiments can be freely combined, and each embodiment can be modified or omitted as appropriate.
[0072] Various aspects of the present disclosure are summarized below as appendices.
[0073] (Appendix 1) A tagging condition database that stores multiple tagging conditions for tagging source code; a source code tagging unit that determines a tagging condition that matches the source code included in a source code project to be analyzed from among the multiple tagging conditions stored in the tagging condition DB, and assigns the tag to the source code included in the source code project based on the determined tagging condition; a tagged source code DB that associates and stores the source code included in the source code project with the tag; an analysis target source code extraction unit that extracts the analysis target source code and the assigned tag from the tagged source code DB in association with each other based on compiler information used when analyzing the analysis target source code; A compiler dependency extractor comprising:
[0074] (Appendix 2) The compiler dependency extraction apparatus of claim 1, wherein the tagging conditions include information about a development project of the source code.
[0075] (Appendix 3) A compiler dependency extraction apparatus according to claim 1 or 2; a source code analysis device that analyzes the source code to be analyzed, which is extracted from the compiler dependency extraction device, based on the compiler information; A source code analysis system comprising:
[0076] (Appendix 4) 4. The source code analysis system according to claim 3, wherein the source code analysis device is connected to a scheduling device that issues an analysis execution command based on a preset time. [Explanation of symbols]
[0077] 102 analysis system, 104 source code analysis device, 105 compiler dependency extraction device, 106 tagging condition DB, 107 source code tagging unit, 108 tagged source code DB, 109 analysis target source code extraction unit, 110 scheduling device.
Claims
1. A tagging condition DB storing a plurality of tagging conditions for attaching tags to source code; a source code tagging unit that determines a tagging condition that is suitable for the source code included in a source code project to be analyzed from among the tagging conditions stored in the tagging condition DB, and assigns the tag to the source code included in the source code project based on the determined tagging condition; a tagged source code DB that associates and stores the source code included in the source code project with the tag; an analysis target source code extraction unit that extracts the analysis target source code and the assigned tag from the tagged source code DB in association with each other based on compiler information used when analyzing the analysis target source code; A compiler dependency extractor comprising:
2. The compiler dependency extraction apparatus according to claim 1 , wherein the tagging conditions include information about a development project of the source code.
3. A compiler dependency extraction apparatus according to claim 1; a source code analysis device that analyzes the source code to be analyzed that is extracted from the compiler dependency extraction device based on the compiler information; A source code analysis system comprising:
4. 4. The source code analysis system according to claim 3, wherein the source code analysis device is connected to a scheduling device that issues an analysis execution command based on a preset time.
Citation Information
Patent Citations
Automatic program starting device
JP1994230946A
Program source file version management system
JP2003067228A
Software development support system
JP2006268299A
Program distribution device and program distribution method
JP2020144580A
Code classification mechanism
US20210208874A1
