Function level defect positioning method based on call graph and multi-level comparative learning

By constructing local and global call graphs, combining graph neural networks and pre-trained models for multi-level comparative learning, the problem of difficulty in effectively utilizing call relationships between functions in the existing technology is solved, and efficient in complex software systems Accurate defect positioning.

CN119441007AActive Publication Date: 2025-02-14NANJING UNIV OF POSTS & TELECOMM
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411580479.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-07
Publication Date
2025-02-14
Estimated Expiration
2044-11-07

AI Technical Summary

Technical Problem

The prior art is difficult to effectively utilize the call relationship between functions in software defect positioning, resulting in insufficient accuracy of defect positioning in complex software systems.

Method used

By constructing local call graphs and global call graphs, combining graph neural networks and pre-trained models, multi-level comparison learning is performed, and the similarity between functions and defect reports is calculated to achieve function-level defect positioning.

Benefits of technology

It significantly improves the accuracy and efficiency of defect positioning, can fully understand the software structure in complex software systems, and effectively locate complex defects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119441007A_ABST
    Figure CN119441007A_ABST
Patent Text Reader

Abstract

The invention discloses a function level defect positioning method based on a call graph and multi-level comparative learning. The method comprises the following steps: constructing a local call graph containing class nodes and internal function nodes and a global call graph covering all functions; performing graph embedding learning on the two calling graphs by utilizing Light-GCN to generate local and global embedding vectors of the function; meanwhile, a pre-training code model is adopted to extract a semantic embedding vector of the function code, and a pre-training language model is used to obtain a semantic embedding vector of the defect report; in order to optimize the performance of the model, a multi-level contrast loss function including local contrast loss, global contrast loss and semantic contrast loss is designed, and the matching relationship between a defect report and function embedding is effectively optimized by minimizing the loss function, so that the overall positioning capability is enhanced, and the positioning accuracy is improved. And the defect positioning accuracy of the model is obviously improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of software engineering technology, and specifically to a function-level defect localization method based on call graph and multi-level comparative learning. The method combines local call graph and global call graph, utilizes graph neural network and pre-training model, and realizes automatic identification and localization of defective functions in software projects. Background Art

[0002] With the rapid development of information technology, software systems are increasingly used in many key fields such as finance, medical care, transportation, and communications. The complexity and scale of these systems are constantly expanding, resulting in software defects becoming one of the main factors affecting system stability, security, and user experience. Efficiently and accurately locating and repairing software defects is of great significance for ensuring the normal operation of the system, reducing maintenance costs, and improving development efficiency. Defect localization refers to determining the location of the source code that causes abnormal software behavior based on defect reports. Development teams usually rely on defect tracking systems such as Bugzilla and JIRA to record, track, and manage these defects. However, as the scale of software projects expands, the number of defect reports increases dramatically. For example, in the large-scale software Eclipse, almost 200 defects are reported by users every day. If you rely solely on manual analysis and location, it will not only consume a lot of time and energy, but also require developers to have high professional skills.

[0003] To meet this challenge, researchers have introduced various automated defect localization methods. In recent years, with the rapid development of artificial intelligence and machine learning technologies, more and more studies have applied these advanced technologies to the field of software defect localization to improve the automation level and intelligent capabilities of localization.

[0004] At present, related research mainly focuses on defect location at the file level. Such methods are usually analyzed based on the modification history of the file, code features, or dependencies between files. However, a research survey shows that about 52% of software practitioners prefer to use function-level granularity for defect location, while only 26% prefer file-level granularity, which shows that developers prefer to quickly and accurately locate specific functions in actual work, rather than just identifying files that may have problems. Although some studies have attempted to improve the accuracy of defect location at the function level by analyzing the code features of a single function, these methods often regard functions as independent units and ignore the complex calling relationships and interactions between functions, resulting in insufficient performance in complex software systems. Therefore, how to better understand and utilize the relationship between functions at the function level and improve the accuracy of defect location is still a research topic that needs to be solved urgently. Summary of the invention

[0005] In view of the deficiencies in the prior art, the present invention discloses a function-level defect localization method based on call graph and multi-level comparative learning to solve the problems raised in the above background technology.

[0006] To achieve the above object, the present invention provides the following technical solution: a function-level defect location method based on call graph and multi-level contrast learning, comprising the following steps:

[0007] S1. Construct local call graph and global call graph. Use parsing tools to parse the source code of the target class and generate an abstract syntax tree. By analyzing the abstract syntax tree, identify the class name, field and member function, and extract the calling relationship between functions, and then construct a local call graph containing class nodes and their internal function nodes. Use the same parsing tool to parse the source code of the entire software project and generate an abstract syntax tree of the project. By analyzing the abstract syntax tree, identify all functions and their calling relationships, and then construct a global call graph covering the entire project.

[0008] S2. Use graph neural network for embedding learning, input the constructed local call graph and global call graph into Light-GCN respectively to obtain the embedding vector of each function in the local call graph and the global call graph;

[0009] S3. Extract the semantic embedding vector and map it to a unified feature space. Use the pre-trained code model to extract the semantic embedding vector of the target function code. Use the pre-trained language model to extract the semantic embedding vector of the defect report text. Use a two-layer fully connected neural network and ReLU activation function to map the embedding vector of the defect report and the multi-dimensional embedding vector of the function to the same feature space.

[0010] S4, calculating the similarity between the defect report and the function, using cosine similarity as a similarity measurement method, and calculating the similarity between the semantic embedding vector of the defect report and the local embedding vector of the function, the global embedding vector, and the code semantic embedding vector;

[0011] S5. Construct a multi-level contrast loss function model, and set a multi-level contrast loss function including local contrast loss, global contrast loss and semantic contrast loss;

[0012] S6. Defect localization implementation. For each function, its comprehensive score is calculated based on the local similarity, global similarity and code semantic similarity between it and the defect report. Each function is sorted in descending order according to its comprehensive score, and the top k functions with the highest scores are selected as the defect localization results.

[0013] Preferably, in step S1, the nodes in the local call graph include a node C representing a class and a plurality of nodes {F1, F2, ..., F m}; Class node C contains the class name and its attribute information, and is connected to all function nodes; the directed edges between function nodes represent function call relationships; the local call graph is represented as:

[0014] G LCG (V, E)

[0015] in,

[0016] V={C,F1,F2,...,F m},

[0017] E={(C,F i )|1≤i≤m}∪{(F i , F j )|F i Call F j}.

[0018] Preferably, in step S1, all function sets in the project are represented as {F1, F2, ..., F n}, the global call graph is represented as:

[0019] G GCG (V, E)

[0020] Where V = {F1, F2, ..., F n}, E={(F i , F j )|F i Call F j}.

[0021] Preferably, in step S2, the embedding vectors of each function in the local call graph and the global call graph are respectively and The calculation formula is:

[0022]

[0023] in, and are the embedding vectors of nodes in the local call graph and the global call graph of the kth layer, respectively, and l is the number of layers of Light-GCN.

[0024] Preferably, in step S3, the semantic embedding vector of the function code is represented as:

[0025]

[0026] in, is the function F i The semantic embedding vector of .

[0027] Preferably, in step S3, the semantic embedding vector of the defect report is represented as:

[0028] r i =BERT(R i )

[0029] Among them, r i Report a bug for R i The semantic embedding vector of .

[0030] Preferably, in step S3, the embedding vector mapping is expressed as:

[0031]

[0032] Among them, δ represents the ReLU activation function, W (1) and W (2) is the weight matrix, b (1) and b (2) is the bias term.

[0033] Preferably, in step S4, the cosine similarity calculated by the similarity calculation is expressed as:

[0034]

[0035] Among them, z a and z b are two embedding vectors used to calculate similarity.

[0036] Preferably, the multi-level contrast loss in step S5 is expressed as:

[0037]

[0038] in,

[0039]

[0040]

[0041] Among them, τ is the temperature parameter, and Represent the similarity between the defect report and the local call graph, the global call graph and the code semantics respectively.

[0042] Preferably, the comprehensive score calculation in step S6 is expressed as:

[0043]

[0044] in, and Represent the similarity between the defect report and the local call graph, the global call graph and the code semantics respectively.

[0045] Compared with the prior art, the present invention has the following beneficial effects:

[0046] 1. In the present invention, by constructing the Local Call Graph (LCG) and the Global Call Graph (GCG), the calling relationship between functions is fully utilized, which significantly improves the accuracy and efficiency of defect location. Specifically, LCG focuses on function calls within a single class, can capture dependencies and interactions within the class in a fine-grained manner, and is suitable for locating defects within a local range; while GCG covers the function call relationship of the entire project, provides macro dependency patterns and context information, helps to identify defect paths across classes and modules, and fully understand the software structure, thereby effectively locating complex defects.

[0047] 2. In the present invention, LCG and GCG complement each other. The former provides in-depth analysis capabilities, and the latter provides an overall structural perspective. The combination of the two not only covers a variety of defect types, but also significantly enhances the comprehensiveness and accuracy of positioning.

[0048] 3. In order to process large-scale code bases, the present invention introduces a lightweight graph convolutional network (Light Graph Convolutional Network, Light-GCN) to extract the representation of the call graph, ensuring high efficiency and scalability, reducing computational complexity and speeding up processing.

[0049] 4. The present invention uses pre-trained models (such as BERT and CodeBERT) to extract semantic representations of defect reports and codes, thereby improving the quality of semantic representations.

[0050] 5. The present invention effectively optimizes the matching relationship between defect reports and function embeddings by designing a multi-level contrast loss function, including local contrast loss, global contrast loss and semantic contrast loss, thereby enhancing the overall positioning capability. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.

[0052] In the attached picture:

[0053] Figure 1 is a flow chart of the method of the present invention. DETAILED DESCRIPTION

[0054] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.

[0055] Example: Figure 1 As shown in FIG. 1 , the function-level defect localization method based on call graph and multi-level contrastive learning includes the following steps:

[0056] 1. Build a local call graph:

[0057] Use tools such as Spoon or JavaParser to parse the source code of the target class and generate an abstract syntax tree (AST) of the class. Identify the class name, fields, and all functions of the target class by analyzing the AST, and extract the calling relationships between functions in the class. Construct a local call graph, where the nodes include a node C representing the class and multiple nodes {F1, F2, ..., F m The class node C contains the class name and its attribute information, and is connected to all function nodes; the directed edges between function nodes represent function call relationships.

[0058] The local call graph can be represented as:

[0059] G LCG (V, E)

[0060] in,

[0061] V={C,F1,F2,...,F m},

[0062] E={(C,F i )∣1≤i≤m}∪{(F i ,F j )∣F i Call F j}

[0063] 2. Build a global call graph

[0064] Use Spoon or JavaParser to parse the source code of the entire software project and generate the project's AST. By analyzing the AST, identify all functions in the project, extract the call relationships between all functions in the project, and identify the call paths between functions. Then build the project's global call graph, with nodes for all functions defined in the project {F1, F2, ..., F n}, the edge is a directed edge from the caller function to the called function, indicating the calling relationship between functions.

[0065] The global call graph can be represented as:

[0066] G GCG (V,E)

[0067] in,

[0068] V={F1,F2,…,F n}

[0069] E={(F i ,F j )|F i Call F j}

[0070] 3. Graph Neural Network Embedding

[0071] The constructed local call graph and global call graph are input into Light-GCN respectively to obtain the embedding vectors of each function in the local call graph and the global call graph.

[0072] 1) Node feature initialization:

[0073] For each node in the local call graph and the global call graph, the pre-trained code model (CodeBERT) is used to extract the semantic features of the node as the initial feature vector of the node:

[0074]

[0075] in, For node V v The initial eigenvector of .

[0076] 2) Light-GCN layer processing:

[0077] The core idea of ​​Light-GCN is to reduce computational complexity through linear message passing. Its layer update formula is:

[0078]

[0079] Among them, h (k) is the node embedding vector of the kth layer, is the normalized adjacency matrix. The specific normalization process is as follows:

[0080]

[0081] Among them, A is the adjacency matrix of the graph and D is the node degree matrix.

[0082] 3) Graph embedding vector generation:

[0083] Through multiple layers of Light-GCN, we get multiple layers of node embeddings for each function in the local call graph and the global call graph. The final node embedding vector can be obtained by summing up the embeddings of each layer:

[0084]

[0085] in, is the function F in the local call graph of the kth layer iThe embedding vector of , l is the number of layers of Light-GCN.

[0086]

[0087] in, is the function F in the global call graph of the kth layer i The embedding vector of , l is the number of layers of Light-GCN.

[0088] 4. Semantic Embedding Vector Extraction

[0089] A pre-trained code model (such as CodeBERT) is used to extract the code semantic embedding vector of the target function; a pre-trained language model (such as BERT) is used to extract the semantic embedding vector of the pre-processed defect report.

[0090] 1) Function code semantic embedding:

[0091]

[0092] in, is the function F i The semantic embedding vector of .

[0093] 2) Defect report semantic embedding:

[0094] r i =BERT(R i )

[0095] Among them, r i Report a bug for R i The semantic embedding vector of .

[0096] 5. Embedding Vector Mapping

[0097] Through two layers of fully connected neural network (Multi-Layer Perceptron, MLP) plus ReLU activation function, the function is locally embedded in the vector Function global embedding vector Function code semantic embedding vector and the semantic embedding vector r of the defect report i Mapped to a unified feature space. The mapping process is implemented by the following formula:

[0098] z'=W (2) δ(W (1) z+b (1) )+b (2)

[0099] Specifically, a two-layer fully connected neural network (MLP) and a ReLU activation function are used to map the embedded vectors to the same feature space:

[0100]

[0101] Among them, W (1) and W (2) is the weight matrix of the fully connected layer, b (1) and b (2) is the bias, δ is the ReLU activation function, z is the input embedding vector, and z' is the mapped feature vector.

[0102] 6. Similarity calculation

[0103] The similarity between the defect report and the function in different dimensions is calculated to measure the degree of matching. Cosine similarity is used as the similarity measurement method to calculate the semantic embedding vector r of the defect report respectively. i and embedding the function locally into a vector Function global embedding vector Function code semantic embedding vector The similarity between:

[0104]

[0105] Among them, z a and z b are two embedding vectors used to calculate similarity.

[0106] The specific similarity calculation is as follows:

[0107]

[0108] in, represents the similarity between defect report i and function j at the local level; represents the similarity between defect report i and function j at the global level; Indicates the similarity between defect report i and function j at the semantic level.

[0109] 7. Multi-level contrast loss function design

[0110] In order to optimize the model performance, a multi-level contrast loss function including local contrast loss, global contrast loss and semantic contrast loss is designed.

[0111] Local contrast loss:

[0112]

[0113] Global contrast loss:

[0114]

[0115] Semantic Contrastive Loss:

[0116]

[0117] Total contrast loss:

[0118]

[0119] 8. Defect location implementation

[0120] Using the trained model to locate defects includes the following steps:

[0121] 1) Calculate the comprehensive score

[0122] For each function F j , based on its comparison with the defect report R i The local similarity between Global Similarity Similarity to code semantics Calculate its comprehensive score S j :

[0123]

[0124] 2) Function sorting and result selection

[0125] According to the comprehensive score S of each function j Sort the functions in descending order and select the top k functions with the highest scores as the results of defect location.

[0126] Finally, it should be noted that the above description is only a preferred example of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A function-level defect localization method based on call graph and multi-level contrastive learning, characterized in that: The following steps are involved: S1. Construct local call graph and global call graph. Use parsing tools to parse the source code of the target class and generate an abstract syntax tree. By analyzing the abstract syntax tree, identify the class name, field and member function, and extract the calling relationship between functions, and then construct a local call graph containing class nodes and their internal function nodes. Use the same parsing tool to parse the source code of the entire software project and generate an abstract syntax tree of the project. By analyzing the abstract syntax tree, identify all functions and their calling relationships, and then construct a global call graph covering the entire project. S2. Use graph neural network for embedding learning, input the constructed local call graph and global call graph into Light-GCN respectively to obtain the embedding vector of each function in the local call graph and the global call graph; S3. Extract the semantic embedding vector and map it to a unified feature space. Use the pre-trained code model to extract the semantic embedding vector of the target function code. Use the pre-trained language model to extract the semantic embedding vector of the defect report text. Use a two-layer fully connected neural network and ReLU activation function to map the embedding vector of the defect report and the multi-dimensional embedding vector of the function to the same feature space. S4, calculating the similarity between the defect report and the function, using cosine similarity as a similarity measurement method, and calculating the similarity between the semantic embedding vector of the defect report and the local embedding vector of the function, the global embedding vector, and the code semantic embedding vector; S5. Construct a multi-level contrast loss function model, and set a multi-level contrast loss function including local contrast loss, global contrast loss and semantic contrast loss; S6. Defect localization implementation. For each function, its comprehensive score is calculated based on the local similarity, global similarity and code semantic similarity between it and the defect report. Each function is sorted in descending order according to its comprehensive score, and the top k functions with the highest scores are selected as the defect localization results.

2. The method for locating function-level defects based on call graph and multi-level contrastive learning according to claim 1, characterized in that: In step S1, the nodes in the local call graph include a node C representing a class and multiple nodes {F1, F2, ..., F m }; Class node C contains the class name and its attribute information, and is connected to all function nodes; the directed edges between function nodes represent function call relationships; the local call graph is represented as: G LCG (V,E) in, V={C,F1,F2,…,F m }, E={(C,F i )∣1≤i≤m}∪{(F i ,F j )∣F i Call F j }.

3. The method for locating function-level defects based on call graph and multi-level contrastive learning according to claim 1, characterized in that: In step S1, the set of all functions in the project is represented as {F1, F2, ..., F n }, the global call graph is represented as: G GCG (V,E) Where V = {F1, F2, …, F n }, E={(F i ,F j )|F i Call F j }.

4. The method for locating function-level defects based on call graph and multi-level contrastive learning according to claim 1, characterized in that: In step S2, the embedding vectors of each function in the local call graph and the global call graph are and The calculation formula is: in, and are the embedding vectors of nodes in the local call graph and the global call graph of the kth layer, respectively, and l is the number of layers of Light-GCN.

5. The method for locating function-level defects based on call graph and multi-level contrastive learning according to claim 1, characterized in that: In step S3, the semantic embedding vector of the function code is represented as: in, is the function F i The semantic embedding vector of .

6. The method for locating function-level defects based on call graph and multi-level contrastive learning according to claim 1, characterized in that: In step S3, the semantic embedding vector of the defect report is represented as: r i =BERT(E i ) Among them, r i Report a bug for R i The semantic embedding vector of .

7. The method for locating function-level defects based on call graph and multi-level contrastive learning according to claim 1, characterized in that: In step S3, the embedding vector mapping is expressed as: Among them, δ represents the ReLU activation function, W (1) and W (2) is the weight matrix, b (1) and b (2) is the bias term.

8. The method for locating function-level defects based on call graph and multi-level contrastive learning according to claim 1, characterized in that: In step S4, the cosine similarity of the similarity calculation is expressed as: Among them, z a and z b are two embedding vectors used to calculate similarity.

9. The method for locating function-level defects based on call graph and multi-level contrastive learning according to claim 1, characterized in that: The multi-level contrast loss in step S5 is expressed as: in, Among them, τ is the temperature parameter, and Represent the similarity between the defect report and the local call graph, the global call graph and the code semantics respectively.

10. The method for locating function-level defects based on call graph and multi-level contrastive learning according to claim 1, characterized in that: The comprehensive score calculation in step S6 is expressed as: in, and Represent the similarity between the defect report and the local call graph, the global call graph and the code semantics respectively.

Citation Information

Patent Citations

  • Defect positioning method and device based on function calling records

    CN104794059A

  • Bug report-oriented fine-grained defect positioning method

    CN110502361A

  • Function-level defect positioning method based on embedding technology

    CN112328469A

  • Defect code positioning method and device, storage medium and computer equipment

    CN115061908A

  • Software defect positioning method based on enhanced embedded vector semantic representation

    CN116302953A