A program defect data feature extraction method, electronic equipment and storage medium

By standardizing and transforming the abstract syntax tree information of the program code, and combining it with data flow information, the problem of inefficient and inaccurate extraction of program features in existing technologies is solved, thereby improving the efficiency and accuracy of software defect analysis.

CN116775121BActive Publication Date: 2025-10-21ZTE CORP +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210239269.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-08
Publication Date
2025-10-21
Estimated Expiration
2042-03-08

AI Technical Summary

Technical Problem

Existing methods for extracting program defect data features cannot efficiently and accurately extract program features from different programming languages, resulting in insufficient accuracy of backend tasks for automatic software repair.

Method used

By obtaining the abstract syntax tree information of the program code, normalizing it, converting it into sequence information, and combining it with data flow information, the defect data features of the defective program code are extracted.

Benefits of technology

It achieves fast and accurate extraction of program patch information and data flow information, improving the efficiency of software defect analysis and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116775121B_ABST
    Figure CN116775121B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a program defect data feature extraction method, an electronic device and a storage medium. The method comprises: obtaining abstract syntax tree information of program code, wherein the program code comprises defect program code and patch program code; performing normalization processing on the abstract syntax tree information to obtain normalized information; obtaining data flow information according to the normalized information; converting the normalized information into sequence information; obtaining program patch information according to the sequence information of the defect program code and the sequence information of the patch program code; and extracting defect data features of the defect program code according to the data flow information, the sequence information and the program patch information. The embodiments of the present application can improve the efficiency and accuracy of program defect data feature extraction, ensure the accuracy of the back-end task, and improve the user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of program repair, and in particular to a method for extracting program defect data features, an electronic device, and a storage medium. Background Art

[0002] With the rapid development of deep learning technology, the intersection of software automatic repair and deep learning has become a trend. Currently, most deep learning-based software automatic repair technologies draw on natural language processing techniques to simply view programs as text sequences, then use neural networks to extract features and perform back-end defect repair. This approach has a significant disadvantage: it loses the inherent characteristics of the code language, such as syntax and data features. Therefore, existing technologies have proposed using an Abstract Syntax Tree (AST) as a feature representation for code, which effectively represents the grammatical features of the code language. However, for software automatic repair, using only the syntax tree as a representation of the program can only reflect the grammatical structure relationship between various identifiers in the code. For defects in a program, syntax errors are only part of the picture; the greater part is the underlying logical errors within the program. To better characterize logical errors in a program, some existing technologies have proposed using data flow graphs (DFGs) as program features. This approach, by capturing the data flow process within the program, can indirectly reveal logical errors within the program.

[0003] While there are currently multiple ways to represent programs, different programming languages ​​have distinct characteristics, resulting in no unified standard for AST and DFG representations. Furthermore, the features required for different tasks, even for the same language, can vary. Consequently, existing methods for extracting program defect data features cannot efficiently and accurately extract program features, and the accuracy of backend tasks cannot be guaranteed. Summary of the Invention

[0004] The following is a summary of the subject matter described in detail herein. This summary is not intended to limit the scope of the claims.

[0005] The embodiments of the present invention provide a method for extracting program defect data features, an electronic device, and a storage medium, which can improve the efficiency and accuracy of program defect data feature extraction, ensure the accuracy of back-end tasks, and improve the user experience.

[0006] In a first aspect, an embodiment of the present invention provides a method for extracting program defect data features, the method comprising: obtaining abstract syntax tree information of a program code, wherein the program code comprises a defective program code and a patch program code; normalizing the abstract syntax tree information to obtain normalized information; obtaining data flow information based on the normalized information; converting the normalized information into sequence information; obtaining program patch information based on the sequence information of the defective program code and the sequence information of the patch program code; and extracting defect data features of the defective program code based on the data flow information, the sequence information, and the program patch information.

[0007] In a second aspect, an embodiment of the present invention provides an electronic device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the program defect data feature extraction method provided by an embodiment of the present invention is implemented.

[0008] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the program defect data feature extraction method provided by the embodiment of the present invention is implemented.

[0009] The embodiment of the present invention obtains the abstract syntax tree information of the program code; normalizes the abstract syntax tree information to obtain normalized information; obtains data flow information based on the normalized information; converts the normalized information into sequence information; obtains program patch information based on the sequence information of the defective program code and the sequence information of the patch program code; and extracts defect data features of the defective program code based on the data flow information, the sequence information, and the program patch information. The solution of the embodiment of the present invention can quickly and accurately extract program patch information and data flow information, facilitate defect repair and analysis and synthesis operations on the program code, and improve the user experience.

[0010] Other features and advantages of the present invention will be described in the following description, and in part will become apparent from the description, or will be understood by practicing the present invention. The purposes and other advantages of the present invention can be realized and obtained through the structures particularly pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] The accompanying drawings are used to provide a further understanding of the technical solution of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the technical solution of the present invention and do not constitute a limitation to the technical solution of the present invention.

[0012] Figure 1This is a flow chart of a method for extracting program defect data features provided by an embodiment of the present invention;

[0013] Figure 2 yes Figure 1 A schematic diagram of a specific implementation process of another embodiment of step S2000;

[0014] Figure 3 yes Figure 2 A schematic diagram of a specific implementation process of another embodiment of step S2300;

[0015] Figure 4 yes Figure 1 A schematic diagram of a specific implementation process of another embodiment of step S3000;

[0016] Figure 5 yes Figure 1 A schematic diagram of a specific implementation process of another embodiment of step S4000;

[0017] Figure 6 yes Figure 1 A schematic diagram of a specific implementation process of another embodiment of step S5000;

[0018] Figure 7 yes Figure 1 A schematic diagram of a specific implementation process of another embodiment of step S6000;

[0019] Figure 8 This is a structural diagram of a program defect data feature extraction device provided by an embodiment of the present invention;

[0020] Figure 9 It is a structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0021] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0022] It should be understood that in the description of the embodiments of the present invention, if there is a description of "first", "second", etc., it is only used for the purpose of distinguishing technical features, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features. "At least one" means one or more, and "more" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can indicate the existence of A alone, the existence of A and B at the same time, and the existence of B alone. A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" and similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b and c can represent: a, b, c, a and b, a and c, b and c or a, b and c, where a, b, c can be single or multiple.

[0023] In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0024] The program defect data feature extraction method involved in the embodiment of the present invention is based on the abstract representation of the program code by AST, and then normalizes the AST to extract normalized information that is convenient for neural network to read and analyze. AST represents the grammatical structure of the program code in the form of a tree, and each node on the tree represents a structure in the program code. Among them, literals, identifiers, expressions, statements, module syntax, and class syntax all have their own AST. In the application of automatic program repair, AST needs to be used in combination with DFG to fully characterize the program code. Therefore, the method of program defect data feature extraction can quickly and accurately extract program patch information and data flow information, which is convenient for defect repair and analysis and synthesis operations on program code, and is particularly suitable for automatic analysis of program defects.

[0025] To ensure accurate extraction of program defect data features, existing methods for extracting program defect data features rely on obtaining the AST and DFG, which represent program code features, and performing differential analysis between the defective program and the patched program. This approach fails to extract program defect data features based on the unique characteristics of different programming languages. Furthermore, because it lacks optimized processing of the abstract syntax tree (AST), it cannot achieve efficient and accurate code feature analysis in automated program defect repair scenarios.

[0026] Based on the above, an embodiment of the present invention provides a program defect data feature extraction method, device, electronic device and computer-readable storage medium, which obtains normalized information by normalizing abstract syntax tree information; and converts the normalized information into sequence information; obtains program patch information based on the sequence information of the defective program code and the sequence information of the patch program code, and finally extracts the defect data features of the defective program code from the sequence information, program patch information and data flow information, so as to achieve the purpose of quickly and accurately extracting program patch information and data flow information, thereby improving the efficiency of software defect analysis and the user experience.

[0027] See Figure 1 , Figure 1 The flowchart of a method for extracting program defect data features provided by an embodiment of the present invention is shown.

[0028] like Figure 1 As shown, the program defect data feature extraction method according to the embodiment of the present invention includes the following steps:

[0029] S1000: Obtain abstract syntax tree information of program code, where the program code includes defective program code and patch program code.

[0030] It's understandable that during the automatic bug repair process, program code includes both defective code and patch code. The process of extracting features from defect data is to rapidly compare and analyze the distinguishing features between the defective and patched code, allowing for rapid correction of anomalies and errors in the defective code. Therefore, it's necessary to process the defective and patched code separately, obtaining their respective abstract syntax tree information for analysis and processing.

[0031] It is understood that by converting code files into abstract syntax tree information, it is easier to analyze, optimize, modify, and perform other operations on the code files. For example, by inputting the program code into an existing AST front-end tool, such as eslint or tree-sitter, the program code's abstract syntax tree information can be obtained. These front-end tools can convert defective program code and patched program code into abstract syntax tree information, respectively. In actual applications, AST conversion of program code using front-end tools or embedded modules is a state of the art and will not be discussed in detail here.

[0032] S2000: normalize the abstract syntax tree information to obtain normalized information.

[0033] Understandably, the abstract syntax tree information obtained directly from program code is voluminous and time-consuming to process. To more concisely express the grammatical features of program code and provide a unified format that can be processed by different back-end algorithms, the abstract syntax tree information needs to be refined and optimized, particularly to accurately extract the grammatical features of program code in different language environments.

[0034] See Figure 2 , Figure 2 FIG. 5 is a schematic diagram showing a specific implementation process of another embodiment of the above step S2000. Figure 2 As shown, step S2000 includes at least the following steps:

[0035] S2100 , traverse each abstract syntax tree node of the abstract syntax tree information in pre-order.

[0036] It is understandable that in order to ensure the integrity and continuity of data, each abstract syntax tree node needs to be traversed in pre-order to avoid data loss and incorrect context.

[0037] S2200: When the abstract syntax tree node has syntax information, create a normalized node corresponding to the abstract syntax tree node, wherein the normalized node includes: an identification number, a parent node pointer, a child node pointer, and a node name, and the node name is consistent with the syntax information.

[0038] It is understood that when it is determined that syntax information exists in an abstract syntax tree node, a normalized node can be created for the current abstract syntax tree node. For syntax-related nodes, a normalized node is created to store an identification number, a parent node pointer, a child node pointer, and a node name. Exemplarily, the identification number is an integer numbering the normalized nodes starting from 0 in pre-order traversal order.

[0039] In addition, when the abstract syntax tree node is "comment", ";", "(", ")", "[", "]", "{", "}", ","", "\n", "'", """, it indicates that the current node is a syntax-irrelevant node and these nodes are ignored in order to remove invalid information in the program code.

[0040] S2300: Obtain normalized information according to the normalized node.

[0041] It is understandable that further optimization processing can be performed on the normalized nodes to obtain more concise and accurate program code normalized nodes. The optimized normalized nodes are then associated and aggregated to obtain normalized information.

[0042] See Figure 3 , Figure 3FIG. 2 shows a schematic diagram of a specific implementation process of another embodiment of the above step S2300. Figure 3 As shown, step S2300 includes at least the following steps:

[0043] S2310: When the node name has a type name, insert a normalized node whose node name is the type name between the normalized node and the parent node of the normalized node.

[0044] It's understood that a type name is a data type defined by the system or user and represents the type of value required to be returned during function execution. Therefore, if a node name already contains a type name, a normalization node must be inserted between the normalization node and its parent node to record the return value corresponding to the type name.

[0045] S2320: When a loop control instruction exists in the node name, create a loop control sub-node and a condition judgment sub-node that match the loop control instruction for the abstract syntax tree node.

[0046] It is understood that the purpose of a loop control instruction is to repeatedly execute the same task until the loop condition is no longer met. Therefore, the loop control instruction normalization node must be equipped with a corresponding loop control sub-node and condition judgment sub-node to ensure the integrity of the data related to the loop control instruction.

[0047] For example, for a loop control normalized node with a node name of "for_statement", a normalized node with a node name of "for_condition" is created, and the child nodes of the current node with a node name of "for", "initializer", "condition", or "update" are placed in the child node list of the "for_condition" node. For a normalized node with a conditional judgment with a node name of "if_statement" or "while_statement", a normalized node of "if_condition" is created, and the child nodes of the current node with a node name of "if", "while", or "condition" are placed in the child node list of the "if_condition" node.

[0048] S2330: If the node name has an identifier, create a child node for the abstract syntax tree node whose node name is consistent with the identifier.

[0049] It's understandable that an identifier is a symbol used to identify an entity, and its meaning varies in different application contexts. In computer programming languages, identifiers are names used by users during programming, naming variables, constants, functions, statement blocks, and so on, establishing a relationship between the name and its usage. Therefore, if a node name contains an identifier, a corresponding child node must be created to record the associated variable, constant, or function.

[0050] Exemplarily, for a normalized node whose node name is "identifier", "primitive_type", "number_literal", "type_identifier" or "field_identifier", a normalized child node is created, whose node name is obtained from the program code corresponding to the current normalized node.

[0051] S2340: When a function instruction exists in the node name, record and process the normalized node and the function instruction.

[0052] It is understandable that function instructions often contain various operation objects and conversion relationships. By recording the normalized nodes and the corresponding function names, the program code can be segmented according to the functions.

[0053] Exemplarily, for a normalized node with a node name of "function_declaration", the function name is found in its subtree, and the normalized node and the function name are recorded in a list.

[0054] For example, to better describe the specific implementation process of each step, the embodiment of the present invention is described using a set of simple defective program codes and patch program codes as an example. The specific program codes are as follows:

[0055] Defective program code:

[0056]

[0057] As can be seen above, the defective code implements a factorial calculation function. The defect is that the variable production is not initialized correctly. The patch code initializes the variable production to 1, fixing the defect.

[0058] It is understandable that after obtaining the normalized information, in order to facilitate direct reading by the neural network, the node relationship can be recorded in the form of a pre-order traversal sequence with backtracking symbols and an adjacency matrix.

[0059] For example, a pre-order traversal sequence with a backtracking symbol is constructed. For each normalized node traversed, its node name is stored in a list. When backtracking, that is, returning to the node on the previous level, a "^" is added to the list as a backtracking symbol. Taking the normalized information of the defective program code as an example, the first six nodes form the sequence: [function_definition, type, primitive_type, int, ^, ^, ^, declarator, function_declarator]. It is understandable that recording node relationships using a pre-order traversal sequence is a prior art method and will not be described in detail here.

[0060] Exemplarily, by obtaining an adjacency matrix with node relationships, wherein the number of rows and columns of the matrix is ​​the same, both being the number of normalized nodes. The elements of the i-th row and j-th column of the matrix are assigned values ​​according to the following rules: if the i-th node is the parent node of the j-th node, then the value assigned is "parent-child relationship"; if the i-th node is the child node of the j-th node, then the value assigned is "child-parent relationship"; if the i-th node is the node immediately to the left of the j-th node, then the value assigned is "brother relationship"; if the i-th node is the node immediately to the right of the j-th node, then the value assigned is "brother relationship"; if the i-th node and the j-th node do not have any of the above relationships, then the value assigned is "no relationship". It is understandable that recording node relationships by means of an adjacency matrix is ​​a prior art and will not be repeated here.

[0061] S3000: Obtain data flow information based on the normalized information.

[0062] See Figure 4 , Figure 4 FIG. 5 is a schematic diagram showing a specific implementation process of another embodiment of the above step S3000. Figure 4 As shown, step S3000 includes at least the following steps:

[0063] S3100, establish a data node data set.

[0064] It is understood that a data node dataset includes at least variable creation instructions, data transfer instructions, and data control instructions. A variable creation instruction typically indicates the first introduction of a new variable into program code. For example, in the C language, the variable declaration and parameter declaration nodes, namely "declaration" and "parameter_declaration," are examples. These nodes create passive data flow relationships, meaning the variable name is created but the data source is left blank.

[0065] Data transfer instructions typically indicate that the data in one variable is updated by some computation on one or more other variables. Examples include assignment nodes, variable definition nodes, increment nodes, and decrement nodes in the C language, namely, assignment_expression, init_declarator, and update_expression. These nodes create a single data flow relationship, meaning that the data flow of the created variable is derived from one or more existing variables.

[0066] Data control instructions typically indicate that data update paths may vary under different conditions. For example, in the C language, these include conditional statement nodes, multi-branch statement nodes, and conditional loop statement nodes, namely "if_statement," "case_statement," "switch_statement," "for_statement," and "while_statement." These nodes establish multi-branch data flow relationships, meaning that the data for all variables following the statement can come from variables before the current statement or from variables within the current statement.

[0067] S3200 , pre-order traversal of the normalized information, extracting normalized information whose node names match the data node data set, and obtaining data node information.

[0068] It can be understood that by traversing the normalized information and extracting the normalized information related to the above data nodes, data node information that can fully reflect each data node in the program code is obtained, thereby ensuring the processing and analysis efficiency of the data nodes.

[0069] S3300: Determine the adjacent relationship between multiple data node information according to the node name of the data node information to form data flow information.

[0070] It can be understood that based on the node names of the data node information and the adjacent relationships between multiple data node information, the conversion and logical relationships between the various data nodes in the program code are obtained, which facilitates the rapid comparison and analysis of non-syntactic feature defects in the defective program based on the data flow information, such as logical errors, incorrect sequence, etc.

[0071] Exemplarily, data flow information is extracted from the normalized information of the above-mentioned defective program code, and 53:n->17:n is obtained, which indicates that the data of the variable n corresponding to the node 53 in the normalized information depends on the variable n corresponding to the node 17; in addition, 75:production->26:production and 75:production->66:production indicate that the data of the variable production corresponding to the node 75 comes from the variable production of the node 26 or the variable production of the node 66, or a combination of the two.

[0072] It is understandable that, similar to the storage method of the above-mentioned normalized information, data stream information can also store the adjacent relationship between data node information in the form of an adjacency matrix, which will not be described in detail here.

[0073] S4000, converts normalized information into sequence information.

[0074] See Figure 5 , Figure 5 FIG. 4 is a schematic diagram showing a specific implementation process of another embodiment of the above step S4000. Figure 5 As shown, step S4000 includes at least the following steps:

[0075] S4100, establishing a code line node data set.

[0076] It's understandable that while the normalized information contains complete program code syntax information, a significant portion of it isn't critical to the proper operation of the program. To further simplify the normalized information and improve system processing speed, it's necessary to extract and process the specialized normalized nodes to obtain code line nodes. A subtree of a code line node can represent a line of code with formatting controls removed and complete syntax. A code line node dataset is established, collecting and counting all code line node types in the program code.

[0077] Exemplarily, for the C programming language, code line nodes include but are not limited to nodes with the following node names: "continue_statement", "break_statement", "return_statement", "declaration", "goto_statement", "parameters", "expression_statement", "for_condition" and "if_condition".

[0078] S4200 , pre-order traversal of the normalized information, extracting normalized information whose node names match the code line node data set, and obtaining code line node information.

[0079] It can be understood that by extracting the normalized information that matches the node name with the code line node data set, the code line node information obtained represents the entire program code, and each node in the code line node information corresponds to the root node of the abstract syntax tree information, and the code line node information subtree represents a line in the program code.

[0080] For example, the code line node information Linenodes1 of the defective program code is: [9: parameters, 20: declaration, 28: for_condition, 62: expression_statement, 72: return_statement]; the code line node information Linenodes2 of the patch program code is: [9: parameters, 20: declaration, 34: for_condition, 67: expression_statement, 78: return_statement]. Each number in the code line node information represents the identification number of the code line node in the abstract syntax tree information.

[0081] S4300: Create a dictionary sequence based on the code line node data set.

[0082] It is understandable that a dictionary sequence is created based on the code line node data set so as to convert the type of the code line node into the corresponding number in the dictionary sequence, thereby further simplifying data processing.

[0083] S4400: Convert code line node information into sequence information according to the dictionary sequence.

[0084] It can be understood that converting the code line node information into sequence information, that is, representing the elements of the code line node information with corresponding numbers in the dictionary sequence, facilitates the neural network to obtain and analyze the sequence information.

[0085] For example, the sequence information Dictnodes1 of the defective program code is [0, 1, 2, 3, 4], and the sequence information Dictnodes2 of the patched program code is [0, 5, 2, 3, 4]. The "0" in the sequence information indicates that the code line node "9: parameters" is numbered "0" in the dictionary sequence, and so on.

[0086] S5000: Obtain program patch information based on the sequence information of the defective program code and the sequence information of the patch program code.

[0087] See Figure 6 , Figure 6 FIG. 5 shows a schematic diagram of another embodiment of the specific implementation process of the above step S5000. Figure 6 As shown, step S5000 at least includes the following steps:

[0088] S5100 , performing a difference comparison between the sequence information of the defective program code and the sequence information of the patch program code.

[0089] It can be understood that, after the simplified processing in step S4000 , the sequence information of the defective program code and the sequence information of the patch program code can be quickly and accurately compared.

[0090] S5200, calculating the difference between the sequence information of the defective program code and the sequence information of the patch program code to obtain program patch information; wherein the program patch information includes: the sequence information identification number of the defective program code, the operation instruction, and the sequence information identification number of the patch program code.

[0091] For example, using Dictnodes1 and Dictnodes2 as an example, the minimum edit operation number of Dictnodes1 and Dictnodes2 can be calculated using the minimum edit distance algorithm to be 1. The specific operation is {[1]: 1modify 1}, which modifies the element with identification number 1 in Dictnodes1 (value 1) to the element with identification number 1 in Dictnodes2 (value 5). This is equivalent to modifying the code line represented by the code line node information corresponding to the identification number 1 in the sequence information of the defective program code (the third line of the defective program code) to the code line represented by the code line node information corresponding to the identification number 1 in the sequence information of the patch program code (the third line of the patch program code). In this way, the defect that the variable "production" in the defective program code is not correctly initialized can be removed, and a result consistent with the patch program code can be obtained. Among them, the difference value between the sequence information of the defective program code and the sequence information of the patch program code calculated by the minimum edit distance algorithm is a prior art and will not be repeated here.

[0092] It is understandable that by comparing the difference between the sequence information of the defective program code and the sequence information of the patch program code, the simplest and fastest way to quickly and accurately convert the defective program code into the patch program code can be obtained, thereby efficiently obtaining the program patch information.

[0093] S6000: Extract defect data features of the defective program code based on the data flow information, sequence information, and program patch information.

[0094] See Figure 7 , Figure 7FIG. 5 shows a schematic diagram of a specific implementation process of another embodiment of the above step S6000. Figure 7 As shown, step S6000 includes at least the following steps:

[0095] S6100: Acquire data flow information and sequence information corresponding to the program patch information.

[0096] It is understood that after obtaining the program patch information in step S5200, the data flow information and sequence information corresponding to the program patch information can be obtained to quickly identify the distinguishing features between the defective program code and the patched program code, and characterize them using the data flow information and sequence information. Obtaining the data flow information and sequence information corresponding to the program patch information can improve the efficiency of analyzing and processing the defective program code and the patched program code, and avoid processing invalid information and interference.

[0097] S6200: Extract distinguishing features of the data stream information and distinguishing features of the sequence information to obtain defect data features.

[0098] It can be understood that by extracting the distinguishing features of data flow information and sequence information between the defective program code and the patch program code through program patch information, the defect data features of the defective program code can be obtained efficiently and accurately, facilitating subsequent further analysis and repair of the defective program code.

[0099] It's understandable that inputting the sequence information, program patch information, and data flow information acquired in the above steps into the neural network significantly improves the system's learning efficiency and accuracy. For example, sequence information and data flow information can be used as program features for neural network learning. Program patch information can also be used to quickly repair program defects, for example, using information such as defective lines and repair operations as features. Furthermore, tasks such as defect location and defect classification can also utilize relevant defect data features.

[0100] See also Figure 8 , Figure 8 It is a structural diagram of the program defect data feature extraction device 700 provided by an embodiment of the present invention. The entire process of the program defect data feature extraction method provided by an embodiment of the present invention involves the following modules in the program defect data feature extraction device 700: acquisition module 710, conversion module 720, calculation module 730 and extraction module 740.

[0101] Among them, the acquisition module 710 is used to obtain the abstract syntax tree information of the program code, wherein the program code includes the defective program code and the patch program code; the conversion module 720 is used to normalize the abstract syntax tree information to obtain normalized information; convert the normalized information into sequence information; and obtain data flow information based on the normalized information; the calculation module 730 is used to obtain program patch information based on the sequence information of the defective program code and the sequence information of the patch program code; the extraction module 740 is used to extract the defect data features of the defective program code based on the sequence information, program patch information and data flow information.

[0102] It should be noted that the information interaction, execution process, etc. between the modules of the above-mentioned device are based on the same concept as the embodiment of the method of the present invention. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0103] Figure 9 An electronic device 800 provided by an embodiment of the present invention is shown. The electronic device 800 includes but is not limited to:

[0104] Memory 801, used for storing programs;

[0105] The processor 802 is configured to execute the program stored in the memory 801 . When the processor 802 executes the program stored in the memory 801 , the processor 802 is configured to execute the above-mentioned method for extracting program defect data features.

[0106] The processor 802 and the memory 801 may be connected via a bus or other means.

[0107] Memory 801, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer executable programs, such as the program defect data feature extraction method described in any embodiment of the present invention. Processor 802 implements the program defect data feature extraction method described above by executing the non-transitory software program and instructions stored in memory 801.

[0108] The memory 801 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and application programs required for at least one function; the data storage area may store data for executing the above-mentioned program defect feature extraction method. In addition, the memory 801 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 801 may optionally include a memory remotely located relative to the processor 802, and these remote memories may be connected to the processor 802 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0109] The non-transient software programs and instructions required to implement the above-mentioned program defect data feature extraction method are stored in the memory 801. When executed by one or more processors 802, the program defect data feature extraction method provided by any embodiment of the present invention is executed.

[0110] An embodiment of the present invention further provides a storage medium storing computer-executable instructions, wherein the computer-executable instructions are used to execute the above-mentioned method for extracting program defect data features.

[0111] In one embodiment, the storage medium stores computer-executable instructions, which are executed by one or more control processors 802, for example, by a processor 802 in the above-mentioned electronic device 800, so that the above-mentioned one or more processors 802 can execute the program defect data feature extraction method provided by any embodiment of the present invention.

[0112] The embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, i.e., they may be located in one place or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of this embodiment.

[0113] Those skilled in the art will appreciate that all or some of the steps and systems in the method disclosed above can be implemented as software, firmware, hardware, and appropriate combinations thereof. Some physical components or all physical components can be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, and the computer-readable medium can include computer storage media (or non-transitory media) and communication media (or temporary media). As known to those skilled in the art, the term computer storage media is included in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data) and is volatile and non-volatile, removable, and non-removable. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory, or other memory technology, CD-ROM, digital versatile disks (DVD), or other optical disk storage, magnetic cassettes, magnetic tapes, disk storage, or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, as is well known to those skilled in the art, communication media typically includes computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.

[0114] The above is a detailed description of the preferred embodiments of the present invention, but the present invention is not limited to the above embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present invention.

Claims

1. A method for extracting program defect data features, the method comprising: Obtaining abstract syntax tree information of program code, wherein the program code includes defective program code and patch program code; Normalizing the abstract syntax tree information to obtain normalized information includes: traversing each abstract syntax tree node of the abstract syntax tree information; creating a normalized node corresponding to the abstract syntax tree node if syntax information exists in the abstract syntax tree node, wherein the normalized node includes an identification number, a parent node pointer, a child node pointer, and a node name, and the node name is consistent with the syntax information; obtaining the normalized information based on the normalized node, including: inserting a normalized node with the node name being the type name between the normalized node and the parent node of the normalized node if a type name exists in the node name; creating a loop control child node and a conditional judgment child node for the abstract syntax tree node that cooperate with the loop control instruction if a loop control instruction exists in the node name; creating a child node with the node name being consistent with the identifier for the abstract syntax tree node if an identifier exists in the node name; and recording the normalized node and the function instruction if a function instruction exists in the node name. Extracting and processing the normalized information to obtain data flow information; converting the normalized information into sequence information; Obtaining program patch information according to the sequence information of the defective program code and the sequence information of the patch program code; Defect data features of the defective program code are extracted based on the data flow information, the sequence information, and the program patch information.

2. The method according to claim 1, characterized in that The extracting and processing the normalized information to obtain data stream information includes: Establish data node dataset; Traversing the normalized information, extracting the normalized information whose node name matches the data node data set, and obtaining data node information; According to the node names of the plurality of data node information, the adjacent relationship between the data node information is determined to form the data flow information.

3. The method according to claim 2, characterized in that The data node data set includes at least: variable creation instructions, data transfer instructions and data control instructions.

4. The method according to claim 1, wherein The converting the normalized information into sequence information comprises: Create a code line node dataset; Traversing the normalized information, extracting the normalized information whose node name matches the code line node data set, and obtaining code line node information; Creating a dictionary sequence according to the code line node data set; The code line node information is converted into the sequence information according to the dictionary sequence.

5. The method according to claim 1, wherein The obtaining program patch information according to the sequence information of the defective program code and the sequence information of the patch program code includes: performing a difference comparison between the sequence information of the defective program code and the sequence information of the patch program code; The difference value between the sequence information of the defective program code and the sequence information of the patch program code is calculated to obtain the program patch information; wherein the program patch information includes: the sequence information identification number of the defective program code, the operation instruction and the sequence information identification number of the patch program code.

6. The method according to claim 1, characterized in that The extracting defect data features of the defective program code according to the data flow information, the sequence information, and the program patch information includes: According to the data flow information and the sequence information corresponding to the program patch information, distinguishing features of the data flow information and the sequence information of the defective program code are extracted to obtain the defect data features.

7. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for extracting program defect data features according to any one of claims 1 to 6 is implemented.

8. A computer-readable storage medium, characterized in that A computer program is stored, and when the computer program is executed by a processor, the method for extracting program defect data features according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Python program type defect detection method based on abstract syntax trees

    CN108932192A

  • Graph-based statement-level program repairing method and system

    CN113741886A