Software defect positioning method and device, equipment, storage medium and program product
By obtaining the software's defect description information and code file information, using the preset model to determine the defect keywords and associated files, and searching the matching target code blocks in the code block, the problem of low efficiency in software defect positioning in the prior art is solved. Achieve more efficient and accurate defect positioning.
Patent Information
- Application Number
- CN202510046129.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2045-01-13
AI Technical Summary
In the prior art, the efficiency of positioning software defects is low, especially when facing complex logical errors, it requires manual positioning, which is relatively low.
By obtaining the defect description information and code file information of the target software, the defect keyword is determined based on the preset model, and the associated file is determined from the code file. Split the associated file into multiple code blocks and retrieve the target code blocks that match the defective keywords in these code blocks.
There is no need to manually locate defects. The high correlation files and code blocks are determined through the preset model, narrowing the index range, and improving the efficiency and accuracy of software defect positioning.
Smart Images

Figure CN119441012A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a software defect location method, device, equipment, storage medium and program product. Background Art
[0002] With the continuous evolution of software functions and codes, the software scale is getting larger and larger, and the structure is becoming more and more complex. In order to ensure the normal operation of the software, it is necessary to locate defects, repair defects, and test and verify defects. Among them, defect location is a prerequisite for defect repair. Its accuracy and efficiency affect the subsequent steps. It is an important and indispensable step in the entire defect repair process. However, this step becomes more and more complex and inefficient as the scale of software increases.
[0003] In the related art, static or dynamic code analysis tools are usually used to detect the code files corresponding to the software or the software runtime to locate code errors. However, static or dynamic code analysis tools can usually only locate code syntax errors or errors that conform to specific templates (for example, memory errors, deadlocks, etc.), and cannot locate complex logical errors; for more complex logical errors, manual location is required.
[0004] It can be seen from the above that the efficiency of software defect location in the related art is low. Summary of the invention
[0005] Multiple aspects of the present application provide a software defect location method, apparatus, device, storage medium and program product to solve the problem of low efficiency in software defect location.
[0006] In a first aspect, an embodiment of the present application provides a software defect location method, including:
[0007] Acquire defect description information of the target software and code file information of the target software, wherein the code file information includes information describing the code file corresponding to the target software;
[0008] Determine defect keywords based on the defect description information, code file information and a preset model, and determine associated files from the code files corresponding to the target software;
[0009] Splitting the associated file into multiple code blocks;
[0010] Among the multiple code blocks of the associated file, a target code block matching the defect keyword is retrieved.
[0011] In a possible implementation, the associated file includes a first associated file and a second associated file; determining defect keywords based on the defect description information, code file information, and a preset model, and determining an associated file from the code file corresponding to the target software includes:
[0012] Determine defect keywords based on the defect description information, code file information and a preset model, and determine a first associated file from the code file corresponding to the target software;
[0013] Based on the correlation between the defect keyword and the code file, a second associated file is determined from the code file corresponding to the target software.
[0014] In a possible implementation manner, the associated file further includes a third associated file; and the method further includes:
[0015] Based on the file dependency graph of the target software, the code file that the first associated file depends on is determined as the third associated file in the code file corresponding to the target software.
[0016] In a possible implementation manner, the preset model is further used to preprocess the defect description information to obtain preprocessed defect description information;
[0017] Retrieving a target code block matching the defect keyword from among the multiple code blocks of the associated file includes:
[0018] Taking the code blocks obtained by splitting the associated files as the index range, and calculating the matching degree of each code block based on the defect description information, the defect keywords, and the preprocessed defect description information;
[0019] Based on the matching degree, the target code block is determined from the code blocks split from the associated file.
[0020] In a possible implementation, determining the target code block from the code blocks split from the associated file based on the matching degree includes:
[0021] Sorting the code blocks obtained by splitting the associated file and its dependent files in descending order of the matching degree;
[0022] Based on the code snippets of the code blocks, code block text vectors of the first N code blocks in the sorting result are generated, where N is a positive integer greater than 1;
[0023] Determine a defect text vector of the preprocessed defect description information;
[0024] Based on the similarity between the defect text vector and the code block text vector, the target code block is determined from the first N code blocks in the sorting result.
[0025] In a possible implementation, based on the similarity between the defect text vector and the code block text vector, determining the target code block from the first N code blocks in the sorting result includes:
[0026] Determining a similarity threshold corresponding to the target software;
[0027] Based on the similarity between the defect text vector and the code block text vector, a code block having a similarity greater than or equal to the similarity threshold among the first N code blocks in the sorting result is determined as the target code block.
[0028] In a possible implementation, the code file information further includes external dependency description information of the target software, where the external dependency description information is used to describe external components on which the code file corresponding to the target software depends.
[0029] In a possible implementation, the associated file is split into multiple code blocks, including:
[0030] Obtaining an abstract syntax tree of the associated file;
[0031] Based on the abstract syntax tree, the associated file is split into multiple code blocks.
[0032] In a possible implementation, the method further includes:
[0033] A defect location report of the target software is generated based on the code fragment and location information of the target code block, wherein the location information is information used to locate the target code block.
[0034] In a second aspect, an embodiment of the present application provides a software defect location device, including: an acquisition module, a first determination module, a splitting module, and a second determination module, wherein:
[0035] The acquisition module is used to acquire defect description information of the target software and code file information of the target software, wherein the code file information includes information describing the code file corresponding to the target software;
[0036] The first determination module is used to determine defect keywords based on the defect description information, code file information and a preset model, and to determine associated files from the code files corresponding to the target software;
[0037] The splitting module is used to split the associated file into multiple code blocks;
[0038] The second determination module is used to retrieve a target code block matching the defect keyword from among the multiple code blocks in the associated file.
[0039] In a possible implementation manner, the associated file includes a first associated file and a second associated file; and the first determining module is specifically configured to:
[0040] Determine defect keywords based on the defect description information, code file information and a preset model, and determine a first associated file from the code file corresponding to the target software;
[0041] Based on the correlation between the defect keyword and the code file, a second associated file is determined from the code file corresponding to the target software.
[0042] In a possible implementation manner, the associated file further includes a third associated file;
[0043] The first determining module is further configured to determine, based on a file dependency graph of the target software, a code file that the first associated file depends on in a code file corresponding to the target software as the third associated file.
[0044] In a possible implementation manner, the preset model is further used to preprocess the defect description information to obtain preprocessed defect description information; and the second determination module is specifically used to:
[0045] Taking the code blocks obtained by splitting the associated files as the index range, and calculating the matching degree of each code block based on the defect description information, the defect keywords, and the preprocessed defect description information;
[0046] Based on the matching degree, the target code block is determined from the code blocks split from the associated file.
[0047] In a possible implementation manner, the second determining module is specifically configured to:
[0048] Sorting the code blocks obtained by splitting the associated file and its dependent files in descending order of the matching degree;
[0049] Based on the code snippets of the code blocks, code block text vectors of the first N code blocks in the sorting result are generated, where N is a positive integer greater than 1;
[0050] Determine a defect text vector of the preprocessed defect description information;
[0051] Based on the similarity between the defect text vector and the code block text vector, the target code block is determined from the first N code blocks in the sorting result.
[0052] In a possible implementation manner, the second determining module is specifically configured to:
[0053] Determining a similarity threshold corresponding to the target software;
[0054] Based on the similarity between the defect text vector and the code block text vector, a code block having a similarity greater than or equal to the similarity threshold among the first N code blocks in the sorting result is determined as the target code block.
[0055] In a possible implementation, the code file information further includes external dependency description information of the target software, where the external dependency description information is used to describe external components on which the code file corresponding to the target software depends.
[0056] In a possible implementation manner, the splitting module is specifically used to:
[0057] Obtaining an abstract syntax tree of the associated file;
[0058] Based on the abstract syntax tree, the associated file is split into multiple code blocks.
[0059] In a possible implementation manner, the second determining module is further configured to:
[0060] A defect location report of the target software is generated based on the code fragment and location information of the target code block, wherein the location information is information used to locate the target code block.
[0061] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory and a processor;
[0062] The memory stores computer-executable instructions;
[0063] The processor executes the computer-executable instructions stored in the memory, so that the processor performs the method described in any one of the first aspects.
[0064] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the method described in any one of the first aspects.
[0065] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which implements the method shown in any one of the first aspects when executed by a processor.
[0066] The embodiments of the present application provide a method, apparatus, device, storage medium and program product for locating software defects. The electronic device can obtain defect description information of the target software and the code file information of the target software, and determine defect keywords based on the defect description information, the code file information and the preset model, and determine the associated files from the code files corresponding to the target software. The electronic device can split the associated files into multiple code blocks, and determine the target code blocks that match the defect keywords in the code blocks of the associated files. Since the electronic device can determine the defect keywords through the preset model and determine the associated files with high relevance to the problem, it can then determine the target code blocks that match the defect keywords in the code blocks of the associated files, without the need for manual defect location, and the target code blocks are determined with the code blocks of the associated files as the index range, which narrows the index range, thereby improving the efficiency of defect location for the target software. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0068] Figure 1 A schematic diagram of an application scenario provided for an exemplary embodiment of the present application;
[0069] Figure 2 A flowchart of a software defect location method provided for an exemplary embodiment of the present application;
[0070] Figure 3 A schematic diagram of splitting code blocks based on an AST syntax tree provided for an exemplary embodiment of the present application;
[0071] Figure 4 A flowchart of another software defect location method provided for an exemplary embodiment of the present application;
[0072] Figure 5 A schematic diagram of a file dependency graph provided for an exemplary embodiment of the present application;
[0073] Figure 6 A process diagram of a software defect location method provided for an exemplary embodiment of the present application;
[0074] Figure 7 A schematic diagram of the structure of a software defect location device provided by an exemplary embodiment of the present application;
[0075] Figure 8 A schematic structural diagram of an electronic device provided for an exemplary embodiment of the present application.
[0076] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0077] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0078] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0079] Below, in order to facilitate understanding of the technical solution of the present application, the concepts involved in the present application are first explained.
[0080] Abstract Syntax Tree (AST): It is a tree representation of the abstract syntax structure of a code file. It shows the syntax structure of the code in the form of a tree.
[0081] File dependency graph: Files will have dependencies due to mutual references. Based on the dependencies between files, a file dependency graph can be formed. It is a structured representation method for describing the dependencies between files.
[0082] Next, combine Figure 1 , the application scenarios of this application are described.
[0083] Figure 1 A schematic diagram of an application scenario provided for an exemplary embodiment of the present application. Figure 1 The target software may have a corresponding code library, and the code library may include multiple code files. For example, the code library corresponding to the target software may include 100 code files, namely code file 1, code file 2, code file 3, ..., code file 100.
[0084] When the target software produces unexpected behavior (i.e., behavior caused by a software defect), the electronic device can locate the defect in multiple code files in the code library corresponding to the target software based on the defect description information to determine the target code block with the defect in the multiple code files.
[0085] For example, if the target software is a shopping software, when the user places an order through the software, an abnormal situation of repeated orders occurs, which indicates that there is a defect of repeated orders in the target software, and the defect description information is "When the user placed an order to purchase product A through the target software at 15:00 today, a problem of repeated orders occurred. It is not clear whether it is caused by a submission logic error in the front-end page or an implementation defect in the back-end order processing logic. It is hoped that the specific cause of the repeated orders can be found out in order to solve the problem." Then, the electronic device can locate the defect in the 100 code files corresponding to the target software according to the defect description information to determine the target code block with defects in the 100 code files. For example, the target code blocks can be code block 1 and code block 3.
[0086] In the related art, static or dynamic code analysis tools are usually used to detect the code files corresponding to the software or the software when it is running to locate code errors. However, static or dynamic code analysis tools can usually only locate code syntax errors or errors that conform to specific templates (for example, memory errors, deadlocks, etc.); for more complex logical errors, manual positioning is required. As can be seen from the above, the efficiency of software defect positioning in the related art is low.
[0087] In an embodiment of the present application, the electronic device can determine the defect keyword based on the defect description information, the code file information of the target software, and the preset model, and determine the associated file from the code file corresponding to the target software, and then determine the target code block that matches the defect keyword in the code block of the associated file. Since the electronic device can determine the defect keyword through the preset model and determine the associated file with high relevance to the problem, and then determine the target code block that matches the defect keyword in the code block of the associated file, there is no need to manually locate the defect, and the target code block is determined with the code block of the associated file as the index range, which narrows the index range, thereby improving the efficiency of defect location for the target software.
[0088] The technical solutions shown in the present application are described in detail below through specific embodiments. It should be noted that the following embodiments can exist independently or in combination with each other, and the same or similar contents will not be described repeatedly in different embodiments.
[0089] The execution subject of the embodiment of the present application may be an electronic device, or a software defect location device set in the electronic device. The software defect location device may be implemented by software, or by a combination of software and hardware. The software defect location device may be a processor in the electronic device. For ease of understanding, the following description is made by taking the execution subject as an electronic device as an example.
[0090] Figure 2 A flowchart of a method for locating software defects provided by an exemplary embodiment of the present application. Figure 2 , the method may include:
[0091] S201, obtaining defect description information of the target software and code file information of the target software.
[0092] Optionally, the defect description information of the target software may be input by a user, or may be automatically generated by the electronic device according to the defect of the target software.
[0093] The code file information may include information describing a code file corresponding to the target software.
[0094] Optionally, the code file corresponding to the target software may be stored in the code library according to the directory tree corresponding to the target software. The electronic device may determine the directory tree in the code library and determine the directory tree as information describing the code file corresponding to the target software, and the code file information may include the directory tree.
[0095] Optionally, the code library may include an external dependency description file. The electronic device may parse the external dependency description file to obtain external dependency description information. The external dependency description information may be used to describe the external components (e.g., dependency libraries, dependency frameworks, third-party services, etc.) on which the code files corresponding to the target software depend. For example, the external dependency description information may include the name, version, source, etc. of the external component on which the code files corresponding to the target software depend.
[0096] Optionally, the code file information may also include external dependency description information corresponding to the target software.
[0097] For example, if the target software is a shopping software, and the user's defect description information for the target software is "When the user placed an order to purchase product A through the target software at 15:00 today, a problem of duplicate orders occurred. It is not clear whether it was caused by a submission logic error in the front-end page or an implementation defect in the back-end order processing logic. I hope to find out the specific cause of the duplicate orders in order to solve the problem." The code library corresponding to the shopping software is code library 1, then the electronic device obtains the defect description information and code file information, and the code file information may include external dependency description information and directory tree 1 determined in code library 1.
[0098] S202: Determine defect keywords based on defect description information, code file information, and a preset model, and determine associated files from code files corresponding to the target software.
[0099] Since the defect description information may be described by a user and may include redundant information, after the electronic device inputs the defect description information into a preset model, the preset model may be used to preprocess the defect description information to obtain preprocessed defect description information. Optionally, the preprocessing may include reference disambiguation, removal of redundant information, etc.
[0100] Optionally, in any embodiment of the present application, the preset model may be a pre-trained large language model (LLM). The preset model may contain more than one billion parameters, and the underlying converter of the preset model may include a series of neural networks. In one or more embodiments, the preset model may include an encoder and / or a decoder and have a self-attention function. The encoder and / or the decoder can extract meaning from the input text and clarify the structural relationship between the contexts. The preset model is pre-trained on a public dataset containing more than 1TB (terabyte) of text data to learn a general language representation.
[0101] In order to adapt to the application scenario of software defect location in this application, we trained a large language model on a dedicated data set containing thousands of defect description information and code file information to obtain a preset model. The preset model can receive defect description information and code file information as input, and can preprocess the defect description information, output the preprocessed defect description information and defect keywords; and can determine and output the first associated file in the code file corresponding to the target software based on the defect keywords and code file information.
[0102] Through the preset model, the semantics of the defect description information can be better captured, the defect description information can be preprocessed, and concise and accurate preprocessed defect description information can be generated, so that the defect keywords can be determined more accurately; the semantic relevance between the defect keywords and the code files can be better captured to more accurately retrieve the first associated file, thereby strengthening the target and relevance of determining the first associated file, and thus improving the accuracy of retrieving the target code block.
[0103] For example, if the defect description information is as shown in the above example, the electronic device can pre-process the defect description information through a preset model, and the pre-processed defect description information is "When placing an order for product A at 15:00, a duplicate order problem occurred. Please find out whether the problem is caused by an error in the submission logic of the front-end page or an implementation defect in the back-end order processing logic."
[0104] Optionally, the defect keyword can be determined based on the defect description information, the code file information and the preset model, and the associated file can be determined from the code file corresponding to the target software in the following manner: the defect keyword can be determined based on the defect description information, the code file information and the preset model, and the first associated file can be determined from the code file corresponding to the target software; based on the correlation between the defect keyword and the code file, the second associated file can be determined from the code file corresponding to the target software. The associated file can include the first associated file and the second associated file.
[0105] Optionally, the electronic device may extract defect keywords from the preprocessed defect description information through a preset model, and determine a first associated file in the code file corresponding to the target software according to the defect keywords and the code file information.
[0106] For example, if the preprocessed defect description information is as shown in the above example, the electronic device can extract three defect keywords from the preprocessed defect description information through the preset model, namely, order placement, submission logic, and order processing logic. If the code file information includes the directory tree corresponding to the shopping software and the external dependency description information, and the code library includes 100 code files corresponding to the target software, the electronic device can use the preset model to determine the four code files related to order processing as the first associated files among the 100 code files according to "order placement" and "order processing logic" and the code file information, assuming that the four code files can be Order / Dao.java file, Order / Controller.java file, Order / Handler.java file, and Order / Transform.java file respectively; and can determine the three code files related to submission logic as the first associated files among the 100 code files according to "submission logic" and the code file information, assuming that the three code files can be: Submit / Handler.java file, Submit / Fail.java file, and Submit / Verify.java file respectively. The electronic device can then determine seven first associated files, namely code file 1 (ie, Order / Dao.java file), code file 2 (ie, Order / Controller.java file), ..., code file 7 (Submit / Verify.java file).
[0107] Optionally, the electronic device may calculate the correlation between the defect keyword and the code file by using a preset correlation algorithm, and then determine, among the code files corresponding to the target software, the code files having a correlation greater than or equal to a first correlation threshold as the second associated files.
[0108] Exemplarily, the preset relevance algorithm may be a BM25 algorithm, a term frequency-inverse document frequency (TF-IDF) algorithm, or the like.
[0109] Optionally, the first correlation threshold may be preset manually. For example, the first correlation threshold may be 0.8.
[0110] For example, if the code library includes 100 code files corresponding to the target software, there are 3 defect keywords, namely order placement, submission logic, and order processing logic, and the preset correlation algorithm is the BM25 algorithm, then the electronic device can calculate the correlation between the 3 defect keywords and the 100 code files through the BM25 algorithm to obtain 100 correlations. If the first correlation threshold is 0.8, the code file with a correlation greater than 0.8 can be determined as the second associated file. Assume that the electronic device can determine 5 second associated files, namely code file 3, code file 10, code file 21, code file 22, and code file 23.
[0111] After the electronic device determines at least one first associated file and at least one second associated file, it may determine that the associated file includes the at least one first associated file and the at least one second associated file.
[0112] For example, if at least one first associated file includes code file 1, code file 2, code file 3, ..., code file 7, and at least one second associated file includes code file 3, code file 10, code file 21, code file 22, and code file 23, the electronic device can determine that there are 11 associated files, namely code file 1, code file 2, code file 3, code file 4, code file 5, code file 6, code file 7, code file 10, code file 21, code file 22, and code file 23.
[0113] S203, splitting the associated file into multiple code blocks.
[0114] Optionally, the associated file may be split into multiple code blocks in the following manner: obtaining an abstract syntax tree of the associated file; and splitting the associated file into multiple code blocks based on the abstract syntax tree.
[0115] For any associated file, the electronic device can parse the associated file through an AST parsing tool to obtain an AST syntax tree corresponding to the associated file, and then split the associated file into multiple code blocks (Chunks) according to the structure of the AST syntax tree.
[0116] A code block is a group of logically related code statements. For any code block, the code block may include code snippets and location information for defect keyword retrieval. For example, the location information may include the name of the module to which the code block belongs, the file path where the code block is located, and the line number range of the code block in the code file. For example, the location information included in code block 1 may be: the name of the module to which code block 1 belongs is the order processing module, the file path where the code block is located is "shopping-software / order / file 1", and the line number range of code block 1 in code file 1 is 010-020.
[0117] Next, combine Figure 3 , explain the AST syntax tree.
[0118] Figure 3 A schematic diagram of splitting code blocks based on AST syntax tree provided by an exemplary embodiment of the present application. Figure 3 , the AST syntax tree can be obtained by parsing the code file 1. The AST syntax tree can include multiple code blocks, namely: code block 1, code block 2, ..., code block 10. The electronic device can split the code file 1 into 10 code blocks according to the structure of the AST syntax tree.
[0119] For example, if the electronic device determines that there are 11 associated files, namely code file 1, code file 2, code file 3, code file 4, code file 5, code file 6, code file 7, code file 10, code file 21, code file 22, and code file 23, then for code file 1, code file 1 can be split into 10 code blocks; code file 2 can be split into 8 code blocks; ...; code file 23 can be split into 15 code blocks. Assume that there are a total of 200 code blocks corresponding to the 11 associated files, namely code block 1, code block 2, ..., code block 200.
[0120] S204: Retrieve a target code block that matches the defect keyword from among multiple code blocks in the associated file.
[0121] The electronic device can calculate the correlation between the defect keyword and multiple code blocks corresponding to the associated file through a preset correlation algorithm, thereby determining the code block with a correlation greater than a second correlation threshold as a target code block matching the defect keyword.
[0122] It should be noted that when calculating the correlation between multiple defect keywords and the code block through the preset correlation algorithm, the multiple defect keywords are taken as a whole to calculate the correlation between the multiple defect keywords and the code block.
[0123] For example, if there are 200 code blocks, there are 3 defect keywords, namely order placement, submission logic, and order processing logic, and the preset correlation algorithm is the BM25 algorithm, then the electronic device can calculate the correlation between the 3 defect keywords and each code block through the BM25 algorithm to obtain 200 correlations. If the second correlation threshold is 0.9, the electronic device can determine the code block with a correlation greater than 0.9 as the target code block. Assume that there are 8 target code blocks, namely code block 1, code block 3, code block 20, code block 65, code block 86, code block 126, code block 153, and code block 171.
[0124] In an embodiment of the present application, the electronic device can obtain defect description information of the target software and code file information of the target software, and determine defect keywords based on the defect description information, code file information and a preset model, and determine associated files from the code file corresponding to the target software. The electronic device can split the associated file into multiple code blocks, and retrieve the target code block that matches the defect keyword from the multiple code blocks of the associated file. Since the electronic device can determine the defect keyword through the preset model and determine the associated file with high relevance to the problem, it can then determine the target code block that matches the defect keyword in the code block of the associated file, without the need for manual defect location, and the target code block is determined with the code block of the associated file as the index range, which narrows the index range, thereby improving the efficiency of defect location for the target software.
[0125] Below, in Figure 2 Based on the embodiment shown, combined Figure 4 , the above software defect location method is explained in detail.
[0126] Figure 4 A flowchart of another software defect location method provided by an exemplary embodiment of the present application. Figure 4 , methods may include:
[0127] S401, obtaining defect description information of the target software and code file information of the target software.
[0128] It should be noted that the execution process of step S401 can refer to step S201, which will not be described again here.
[0129] S402: Determine defect keywords based on defect description information, code file information, and a preset model, and determine a first associated file from the code file corresponding to the target software.
[0130] The electronic device preprocesses the defect description information through a preset model to obtain preprocessed defect description information, and extracts defect keywords from the preprocessed defect description information.
[0131] After the electronic device determines the defect keyword, it can determine the first associated file in the code file corresponding to the target software through a preset model according to the defect keyword and the code file information.
[0132] Optionally, the first associated file can be determined in the following manner: the electronic device can determine the role of each code file through a preset model according to the external dependency description information in the code file information, and determine the semantic relevance between the defect keyword and each file path in the directory tree, and then determine the code file corresponding to the file path whose semantic relevance is greater than or equal to a preset relevance threshold as the first associated file.
[0133] It should be noted that the file path refers to the complete file path of each code file in the directory tree.
[0134] Optionally, the preset relevance threshold may be manually preset or determined by semantic relevance distribution.
[0135] For example, if the electronic device determines that there are three defect keywords, namely order placement, submission logic, and order processing logic, and if there are 100 code files in the code library, the electronic device determines the functions of the 100 code files based on the external dependency description information through the preset model, and determines the semantic relevance between the three defect keywords and the file paths corresponding to the 100 files in the directory tree. For example, for code file 1, if the external dependency description information includes that code file 1 depends on the order database, it can be determined that the content in code file 1 is order-related content, and the semantic relevance between the defect keyword and the file path of code file 1 (Order / Dao.java) can be determined to be 0.9.
[0136] If the preset relevance threshold is 0.7, assuming that the file paths whose semantic relevance is greater than or equal to the preset relevance threshold are: file path 1 (Order / Dao.java), file path 2 (Order / Controller.java), file path 3 (Order / Handler.java), file path 4 (Order / Transform.java), file path 5 (Submit / Handler.java), file path 6 (Submit / Fail.java), and file path 7 (Submit / Verify.java), then the files corresponding to the 7 file paths can be determined as the first associated files, that is, the first associated files include: code file 1 corresponding to file path 1 (that is, Order / Dao.java file), code file 2 corresponding to file path 2 (that is, Order / Controller.java file), ..., code file 7 (that is, Submit / Verify.java file).
[0137] S403: Based on the correlation between the defect keyword and the code file, determine a second associated file from the code file corresponding to the target software.
[0138] Optionally, the execution process of step S403 may refer to the relevant content in step S202, which will not be repeated here.
[0139] S404: Based on the file dependency graph of the target software, determine, in the code file corresponding to the target software, the code file on which the first associated file depends as the third associated file.
[0140] The code base may include at least one code file, and there may be a dependency relationship between the at least one code file. The first associated file is determined in the at least one code file. Based on actual development experience, there may also be defects in the code file that the first associated file depends on. Therefore, when locating the software, it is also necessary to consider calculating the degree of correlation between the code file that the first associated file depends on and the defect.
[0141] The file dependency graph may include a dependency relationship between at least one code file corresponding to the target software.
[0142] Next, combine Figure 5 , describes the file dependency graph.
[0143] Figure 5 A schematic diagram of a file dependency graph provided for an exemplary embodiment of the present application. Figure 5 , if the target software corresponds to 100 code files, the file dependency graph may include the dependency relationships between the 100 code files. Figure 5 As shown in , in the file dependency graph, code file 1 depends on code file 25 and code file 26, code file 2 depends on code file 24, code file 3 and code file 4 have no dependent code files, code file 5 depends on code file 8 and code file 9, code file 6 has no dependent code files, code file 7 depends on code file 14, code file 15 and code file 16, ..., code file 99 depends on code file 100.
[0144] Optionally, the electronic device may determine a file dependency graph of the target software, and determine in the code library a code file on which the first associated file depends based on the file dependency graph, and determine the code file on which the first associated file depends as a third associated file.
[0145] For example, if there are 7 first associated files, namely code file 1, code file 2, code file 3, ..., code file 7, the file dependency graph is as follows: Figure 5 As shown in , the electronic device can determine, based on the file dependency graph, that the code files that code file 1 depends on are code file 25 and code file 26, the code files that code file 2 depends on are code file 24, ..., and the code files that code file 7 depends on are code file 14, code file 15, and code file 16. The electronic device can determine that there are a total of 8 code files that the 7 first associated files depend on (i.e., code file 25, code file 26, code file 24, code file 8, code file 9, code file 14, code file 15, and code file 16), and determine the 8 code files as the third associated files.
[0146] S405: Determine that the associated files include a first associated file, a second associated file, and a third associated file.
[0147] For example, if the electronic device determines that there are 7 first associated files, 5 second associated files, and 8 third associated files as shown in Table 1:
[0148] Table 1
[0149]
[0150] The electronic device can then determine that there are 19 associated files in total, as shown in Table 1.
[0151] S406: Split the associated file into multiple code blocks.
[0152] It should be noted that the execution process of step S406 can refer to step S203, which will not be described in detail here.
[0153] S407: Using the code blocks obtained by splitting the associated files as index ranges, and calculating the matching degree of each code block based on the defect keywords and the pre-processed defect description information.
[0154] Optionally, after the electronic device obtains multiple code blocks obtained by splitting the associated file, it can perform text indexing on the multiple code blocks. Specifically, the electronic device can simplify the code blocks to generate labels corresponding to the code blocks, and generate text indexes based on the labels of the code blocks. The text index includes the labels of each code block.
[0155] Optionally, for any code block, the electronic device can remove useless information (eg, braces, semicolons, etc.) in the code block to simplify the code block, and use the simplified code block as a label of the code block, so that the label of the code block includes useful information in the code block.
[0156] For example, if there are 19 associated files, and the 19 associated files correspond to 500 code blocks in total, the electronic device can simplify each of the 500 code blocks to obtain a label for each code block, and generate a text index based on the labels of the 500 code blocks. The text index can include the labels of the 500 code blocks.
[0157] Since the text index is established based on the labels of each code block, the electronic device uses the text index as the index range, which is equivalent to using the code blocks obtained by splitting the associated file as the index range. Indexing based on the text index can improve indexing efficiency.
[0158] The electronic device can calculate the matching degree of the label of each code block in the text index based on the defect keywords and the preprocessed defect description information through a preset correlation algorithm.
[0159] Specifically, the electronic device can calculate the first correlation between the defect keyword and the label of each code block in the text index through a preset correlation algorithm; and can calculate the second correlation between the preprocessed defect description information and the label of each code block in the text index through a preset correlation algorithm.
[0160] For any code block, the electronic device can determine the matching degree of the label of the code block according to the first correlation and the second correlation corresponding to the label of the code block, and use the matching degree of the label of the code block as the matching degree of the code block.
[0161] Optionally, the matching degree may be a statistical value calculated based on the first correlation and the second correlation. For example, the statistical value may be an average value or a weighted average value.
[0162] For example, if the defect description information is "When the user placed an order for product A through the target software at 15:00 today, a duplicate order problem occurred. It is not clear whether it was caused by a submission logic error on the front-end page or an implementation defect in the back-end order processing logic. I hope to find out the specific cause of the duplicate order in order to solve the problem"; the pre-processed defect description information is "When ordering product A at 15:00, a duplicate order problem occurred. Please find out whether the problem was caused by a submission logic error on the front-end page or an implementation defect in the back-end order processing logic"; the defect keywords are order placement, submission logic, and order processing logic, and the text index includes the labels of 500 code blocks. Then, the electronic device can use the BM25 algorithm to calculate the first correlation between the pre-processed defect description information and the labels of the 500 code blocks, respectively, to obtain 500 first correlations; and can use the BM25 algorithm to calculate the second correlation between the defect keywords and the labels of the 500 code blocks, respectively, to obtain 500 second correlations. Assume that the 500 first correlations and the 500 second correlations are as shown in Table 2:
[0163] Table 2
[0164]
[0165] If the matching degree is the average value of the first correlation and the second correlation, the matching degree of the label of each code block can be calculated as shown in Table 2, that is, the matching degree of each code block is as shown in Table 2.
[0166] S408: Based on the matching degree, determine the target code block from the code blocks split from the associated files.
[0167] Optionally, the target code block can be determined from the code blocks split from the associated files based on the degree of matching in the following manner: sorting the code blocks split from the associated files in descending order of the degree of matching; generating code block text vectors for the first N code blocks in the sorting result based on code fragments of the code blocks; determining the defect text vector of the preprocessed defect description information; and determining the target code block from the first N code blocks in the sorting result based on the correlation between the defect text vector and the code block text vector.
[0168] N may be a positive integer greater than 1, and may be manually preset. For example, N may be 10.
[0169] Since the matching degree of each code block is calculated by a preset correlation algorithm, the context information of the code snippet in the code block is not used. Therefore, after the first N code blocks of the sorting result are determined, the code block text vectors of the first N code blocks can be generated based on the code snippets in the first N code blocks. The electronic device can determine the defect text vector of the preprocessed defect description information, calculate the similarity between the defect text vector and the code block text vector of the N code blocks by a preset similarity algorithm, and determine the target code block from the N code blocks according to the similarity.
[0170] Exemplarily, the preset similarity algorithm may be a cosine similarity algorithm, a Euclidean distance algorithm, a Pearson correlation coefficient algorithm, or the like.
[0171] Optionally, the target code block can be determined from the first N code blocks in the sorting result based on the similarity between the defect text vector and the code block text vector in the following manner: determine a similarity threshold corresponding to the target software; based on the similarity between the defect text vector and the code block text vector, determine the code block whose similarity is greater than or equal to the similarity threshold as the target code block among the first N code blocks in the sorting result.
[0172] The code block text vector can express the context information of the code fragment in the code block. Therefore, based on the first N code blocks determined according to the matching degree, the target code block is determined in the first N code blocks based on the correlation between the defect text vector and the code block text vector, which further improves the accuracy of determining the target code block.
[0173] Optionally, the similarity threshold may be determined based on the correlation distribution between the defect text vector and the code block text vector. For example, the similarity threshold may be 0.8.
[0174] For example, if the matching degree of the code blocks is as shown in Table 2, the electronic device can sort the 500 code blocks in order of matching degree from high to low to obtain the sorting result. If N is 10, the electronic device can determine the first 10 code blocks in the sorting result. Assume that the first 10 code blocks are code block 3, code block 1, code block 20, code block 126, code block 65, code block 309, code block 351, code block 201, code block 412, and code block 465. For code block 3, the electronic device can generate a code block text vector corresponding to code block 3 based on the code fragment in code block 3; for code block 1, the electronic device can generate a code block text vector corresponding to code block 1 based on the code fragment in code block 1; ...; for code block 465, the electronic device can generate a code block text vector corresponding to code block 465 based on the code fragment in code block 465. The electronic device can generate a defect text vector of the preprocessed defect description information. The electronic device can calculate the similarity between the defect text vector and each code block text vector by the cosine similarity algorithm, assuming that it is as shown in Table 3:
[0175] Table 3
[0176]
[0177] If the similarity threshold corresponding to the target software is 0.5, the electronic device may determine code block 3, code block 1, code block 20, code block 65, and code block 412 as target code blocks among the 10 code blocks.
[0178] S409: Generate a defect location report of the target software based on the code snippet and location information of the target code block.
[0179] The positioning information may be information for positioning the target code block. For example, the positioning information may include the module name to which the code block belongs, the file path where the code block is located, and the line number range of the code block in the code file, etc. For example, the positioning information included in code block 1 may include: the module name to which code block 1 belongs is the order processing module, the file path where the code block is located is "shopping-software / order / file 1", and the line number range of code block 1 in code file 1 is 010-020.
[0180] For example, if the target software is shopping software, and the electronic device determines that there are five target code blocks, namely code block 3, code block 1, code block 20, code block 65, and code block 412, then the electronic device can generate a defect location report for the shopping software based on the code fragments and location information of the five target code blocks.
[0181] It should be noted that in Figure 4The various processing steps (S401 to S409) shown in the embodiment do not constitute a specific limitation on the software defect location process. In other embodiments of the present application, the software defect location process may include: Figure 4 The embodiments may include more or fewer steps. For example, the software defect location process may include: Figure 4 Some steps in the embodiment, or, Figure 4 Some steps in the embodiments may be replaced by steps having the same functions, or Figure 4 Some steps in the embodiments may be split into multiple steps, etc.
[0182] In an embodiment of the present application, the electronic device can obtain defect description information of the target software and code file information of the target software. The electronic device can determine the defect keyword based on the defect description information, the code file information and the preset model, and determine the first associated file from the code file corresponding to the target software, and determine the second associated file from the code file corresponding to the target software based on the correlation between the defect keyword and the code file, and can also determine the code file that the first associated file depends on as the third associated file in the code file corresponding to the target software based on the file dependency graph of the target software, and then determine that the associated file includes the first associated file, the second associated file and the third associated file. The electronic device can split the associated file into multiple code blocks, and use the code blocks obtained by splitting the associated file as the index range, calculate the matching degree of each code block based on the defect keyword and the pre-processed defect description information, and then determine the target code block from the code blocks split from the associated file based on the matching degree. The electronic device can generate a defect location report for the target software based on the code fragment and location information of the target code block. Since the electronic device can determine the associated files with high correlation with the problem from the code files corresponding to the target software according to the defect keywords, and then determine the target code blocks with defects in the code blocks of the associated files, the index range is narrowed and the speed of defect location for the target software is improved; and the top N code blocks with high correlation can be determined by a preset similarity algorithm, and then the target code block can be determined in the top N code blocks based on the code block text vector, which not only considers the keyword matching correlation between the defect description information and the code block, but also considers the context information of the code fragment in the code block, thereby improving the accuracy of defect location for the target software, and thus comprehensively improving the efficiency of defect location for the target software.
[0183] Next, based on any of the above embodiments, Figure 6 , the above software defect location method is further explained.
[0184] Figure 6 A process diagram of a software defect location method provided by an exemplary embodiment of the present application. Figure 6 , including steps ①②③④⑤⑥⑦⑧⑨.
[0185] In step ①, the electronic device can input defect description information and code file information into a preset model.
[0186] For example, the defect description information may be "When a user placed an order to purchase product A through the target software at 15:00 today, a duplicate order problem occurred. It is unclear whether it was caused by a submission logic error in the front-end page or an implementation defect in the back-end order processing logic. We hope to find out the specific cause of the duplicate order in order to solve the problem"; the code file information may include the directory tree determined in the code library 1, and the external dependency description information.
[0187] In step ②, the electronic device can preprocess the defect description information through a preset model to obtain the preprocessed defect description information. For example, the preprocessed defect description information can be: when ordering product A at 15:00, a duplicate order problem occurs. Please find out whether the problem is caused by a submission logic error in the front-end page or an implementation defect in the back-end order processing logic.
[0188] In step ③, the electronic device can determine the defect keywords in the preprocessed defect description information through a preset model. For example, if the preprocessed defect description information is as shown in the above example, the defect keywords can be: order placement, submission logic, and order processing logic.
[0189] In step ④, the electronic device can determine the first associated file in the code library corresponding to the target software according to the defect keyword and the code file information. For example, the code library can include multiple code files corresponding to the target software, namely code file 1, code file 2, code file 3, ..., code file 100.
[0190] Optionally, the specific execution process of step ④ may refer to the execution process of step S402, which will not be repeated here.
[0191] For example, the electronic device may determine that there are 7 first associated files, as shown in Table 1.
[0192] In step ⑤, based on the correlation between the defect keyword and the code file, a second associated file is determined from the code file corresponding to the target software.
[0193] Optionally, the specific execution process of step ⑤ can refer to the execution process of step S202, which will not be repeated here.
[0194] For example, the electronic device may determine that there are five second associated files, as shown in Table 1.
[0195] In step ⑥, based on the file dependency graph of the target software, the code file on which the first associated file depends is determined as the third associated file in the code file corresponding to the target software.
[0196] Optionally, the specific execution process of step ⑥ may refer to the execution process of step S404, which will not be repeated here.
[0197] For example, the electronic device may determine that there are 8 third associated files, as shown in Table 1.
[0198] The electronic device may determine that the associated file includes a first associated file, a second associated file, and a third associated file. For example, the associated file may be as shown in Table 1.
[0199] In step ⑦, the electronic device may split the associated file to obtain multiple code blocks.
[0200] For example, if there are 19 associated files, the electronic device can parse each associated file through the AST parsing tool to obtain the AST syntax tree corresponding to each associated file, and then split the corresponding associated file according to the AST syntax tree to obtain multiple code blocks. Assuming that the 19 associated files are split, a total of 500 code blocks can be obtained, such as Figure 6 as shown in .
[0201] In step ⑧, the electronic device may determine the matching degree corresponding to each code block, and based on the matching degree, select the top N code blocks in the sorting result from the multiple code blocks.
[0202] It should be noted that the process of determining the matching degree corresponding to each code block can refer to the relevant content in step S407, which will not be repeated here.
[0203] For example, if the matching degrees corresponding to the 500 code blocks are as shown in Table 2, and N is 10, the 500 code blocks are sorted in descending order of matching degrees to obtain a sorting result. The electronic device can determine the first 10 code blocks in the sorting result. Assume that the first 10 code blocks are code block 3, code block 1, code block 20, code block 126, code block 65, code block 309, code block 351, code block 201, code block 412, and code block 465. Figure 6 as shown in .
[0204] In step ⑨, the electronic device can generate a defect text vector of the preprocessed defect description information and a code block text vector of the first N code blocks, and calculate the similarity between the defect text vector and the text vectors of each code block, and then determine the target code block from the first N code blocks in the sorting result based on the defect text vector and the code block text vectors of each code block.
[0205] For example, if the similarities between the defect text vector and the code block text vectors of the first 10 code blocks are shown in Table 3, and if the similarity threshold is 0.5, the electronic device can determine code block 3, code block 1, code block 20, code block 65, and code block 412 as target code blocks among the 10 code blocks, as shown in Table 3. Figure 6 as shown in .
[0206] In an embodiment of the present application, the electronic device can obtain defect description information of the target software and code file information of the target software. The electronic device can determine defect keywords based on the defect description information, code file information and preset models, and determine the first associated file from the code file corresponding to the target software, and determine the second associated file from the code file corresponding to the target software based on the correlation between the defect keyword and the code file, and can also determine the code file that the first associated file depends on as the third associated file in the code file corresponding to the target software based on the file dependency graph of the target software, and then determine that the associated file includes the first associated file, the second associated file and the third associated file. The electronic device can split the associated file into multiple code blocks, take the code blocks obtained by splitting the associated file as the index range, calculate the matching degree of each code block based on the defect keywords and the preprocessed defect description information, and determine the top N code blocks of the sorting result from the multiple code blocks based on the matching degree, and then determine the target code block from the top N code blocks based on the defect text vector and the code block text vector of each code block. Since the electronic device can determine the associated files with high correlation with the problem from the code files corresponding to the target software according to the defect keywords, and then determine the target code blocks with defects in the code blocks of the associated files, the index range is narrowed and the speed of defect location for the target software is improved; and the top N code blocks with high correlation can be determined by a preset similarity algorithm, and then the target code block can be determined in the top N code blocks based on the code block text vector, which not only considers the keyword matching correlation between the defect description information and the code block, but also considers the context information of the code fragment in the code block, thereby improving the accuracy of defect location for the target software, and thus comprehensively improving the efficiency of defect location for the target software.
[0207] The technical solution of the present application can be applied in the software development process to help developers quickly locate and fix software defects. For example, in automated testing, the technical solution of the present application can be used to help testers quickly locate defects in test cases. In automated development and question-answering systems, it can be used as a retrieval-augmented generation (RAG) process to provide code information related to the problem. In addition, the technical solution of the present application can also be used in the fields of teaching and research to help students and researchers better understand the method of locating software defects.
[0208] Figure 7 A schematic diagram of the structure of a software defect location device provided by an exemplary embodiment of the present application. Figure 7 The software defect location device 10 includes: an acquisition module 11, a first determination module 12, a splitting module 13 and a second determination module 14, wherein:
[0209] The acquisition module 11 is used to acquire defect description information of the target software and code file information of the target software, wherein the code file information includes information describing the code file corresponding to the target software;
[0210] The first determination module 12 is used to determine defect keywords based on the defect description information, code file information and a preset model, and to determine associated files from the code files corresponding to the target software;
[0211] The splitting module 13 is used to split the associated file into multiple code blocks;
[0212] The second determining module 14 is used to retrieve a target code block matching the defect keyword from among the multiple code blocks in the associated file.
[0213] The software defect location device provided in the embodiment of the present application can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be repeated here.
[0214] In a possible implementation manner, the associated file includes a first associated file and a second associated file; and the first determining module 12 is specifically configured to:
[0215] Determine defect keywords based on the defect description information, code file information and a preset model, and determine a first associated file from the code file corresponding to the target software;
[0216] Based on the correlation between the defect keyword and the code file, a second associated file is determined from the code file corresponding to the target software.
[0217] In a possible implementation manner, the associated file further includes a third associated file;
[0218] The first determining module 12 is further configured to determine, based on a file dependency graph of the target software, a code file that the first associated file depends on in a code file corresponding to the target software as the third associated file.
[0219] In a possible implementation manner, the preset model is further used to preprocess the defect description information to obtain preprocessed defect description information; the second determination module 14 is specifically used to:
[0220] Taking the code blocks obtained by splitting the associated files as the index range, and calculating the matching degree of each code block based on the defect description information, the defect keywords, and the preprocessed defect description information;
[0221] Based on the matching degree, the target code block is determined from the code blocks split from the associated file.
[0222] In a possible implementation manner, the second determining module 14 is specifically configured to:
[0223] Sorting the code blocks obtained by splitting the associated files in descending order of the matching degree;
[0224] Based on the code snippets of the code blocks, code block text vectors of the first N code blocks in the sorting result are generated, where N is a positive integer greater than 1;
[0225] Determine a defect text vector of the preprocessed defect description information;
[0226] Based on the similarity between the defect text vector and the code block text vector, the target code block is determined from the first N code blocks in the sorting result.
[0227] In a possible implementation manner, the second determining module 14 is specifically configured to:
[0228] Determining a similarity threshold corresponding to the target software;
[0229] Based on the similarity between the defect text vector and the code block text vector, a code block having a similarity greater than or equal to the similarity threshold among the first N code blocks in the sorting result is determined as the target code block.
[0230] In a possible implementation, the code file information further includes external dependency description information of the target software, where the external dependency description information is used to describe external components on which the code file corresponding to the target software depends.
[0231] In a possible implementation manner, the splitting module 13 is specifically used to:
[0232] Obtaining an abstract syntax tree of the associated file;
[0233] Based on the abstract syntax tree, the associated file is split into multiple code blocks.
[0234] In a possible implementation manner, the second determining module 14 is further configured to:
[0235] A defect location report of the target software is generated based on the code fragment and location information of the target code block, wherein the location information is information used to locate the target code block.
[0236] The software defect location device provided in the embodiment of the present application can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be repeated here.
[0237] Figure 8 A schematic diagram of the structure of an electronic device provided by an exemplary embodiment of the present application. Figure 8 The electronic device 20 may include a processor 21 and a memory 22. Exemplarily, the processor 21 and the memory 22 are interconnected via a bus 23.
[0238] The memory 22 stores computer-executable instructions;
[0239] The processor 21 executes the computer-executable instructions stored in the memory 22, so that the processor 21 executes the method shown in the above method embodiment.
[0240] Accordingly, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the method described in the above method embodiment.
[0241] Accordingly, an embodiment of the present application may also provide a computer program product, including a computer program, which, when executed by a processor, can implement the method shown in the above method embodiment.
[0242] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0243] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0244] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0245] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0246] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0247] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0248] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0249] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0250] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. A software defect location method, characterized in that: include: Acquire defect description information of the target software and code file information of the target software, wherein the code file information includes information describing the code file corresponding to the target software; Determine defect keywords based on the defect description information, code file information and a preset model, and determine associated files from the code files corresponding to the target software; Splitting the associated file into multiple code blocks; Among the multiple code blocks of the associated file, a target code block matching the defect keyword is retrieved.
2. The method according to claim 1, characterized in that The associated file includes a first associated file and a second associated file; based on the defect description information, the code file information and the preset model, determining the defect keyword, and determining the associated file from the code file corresponding to the target software, including: Determine defect keywords based on the defect description information, code file information and a preset model, and determine a first associated file from the code file corresponding to the target software; Based on the correlation between the defect keyword and the code file, a second associated file is determined from the code file corresponding to the target software.
3. The method according to claim 2, characterized in that The associated file also includes a third associated file; the method also includes: Based on the file dependency graph of the target software, the code file that the first associated file depends on is determined as the third associated file in the code file corresponding to the target software.
4. The method according to any one of claims 1 to 3, characterized in that: The preset model is also used to preprocess the defect description information to obtain preprocessed defect description information; Retrieving a target code block matching the defect keyword from among the multiple code blocks of the associated file includes: Taking the code blocks obtained by splitting the associated files as the index range, and calculating the matching degree of each of the code blocks based on the defect keywords and the pre-processed defect description information; Based on the matching degree, the target code block is determined from the code blocks split from the associated file.
5. The method according to claim 4, characterized in that Determining the target code block from the code blocks split from the associated file based on the matching degree includes: Sorting the code blocks obtained by splitting the associated files in descending order of the matching degree; Based on the code snippets of the code blocks, code block text vectors of the first N code blocks in the sorting result are generated, where N is a positive integer greater than 1; Determine a defect text vector of the preprocessed defect description information; Based on the similarity between the defect text vector and the code block text vector, the target code block is determined from the first N code blocks in the sorting result.
6. The method according to claim 5, characterized in that Determining the target code block from the first N code blocks in the sorting result based on the similarity between the defect text vector and the code block text vector includes: Determining a similarity threshold corresponding to the target software; Based on the similarity between the defect text vector and the code block text vector, a code block having a similarity greater than or equal to the similarity threshold among the first N code blocks in the sorting result is determined as the target code block.
7. The method according to any one of claims 1-3 or 5-6, characterized in that: The code file information also includes external dependency description information of the target software, where the external dependency description information is used to describe the external components on which the code file corresponding to the target software depends.
8. The method according to any one of claims 1-3 or 5-6, characterized in that: Split the associated file into multiple code blocks, including: Obtaining an abstract syntax tree of the associated file; Based on the abstract syntax tree, the associated file is split into multiple code blocks.
9. The method according to any one of claims 1-3 or 5-6, characterized in that: The method further comprises: A defect location report of the target software is generated based on the code fragment and location information of the target code block, wherein the location information is information used to locate the target code block.
10. A software defect location device, characterized in that: include: an acquisition module, a first determination module, a splitting module, and a second determination module, wherein: The acquisition module is used to acquire defect description information of the target software and code file information of the target software, wherein the code file information includes information describing the code file corresponding to the target software; The first determination module is used to determine defect keywords based on the defect description information, code file information and a preset model, and to determine associated files from the code files corresponding to the target software; The splitting module is used to split the associated file into multiple code blocks; The second determination module is used to retrieve a target code block matching the defect keyword from among the multiple code blocks in the associated file.
11. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively coupled to the at least one processor; The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the electronic device to perform the method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the method according to any one of claims 1 to 9 is implemented.
13. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Software defect code file locating method based on reverse index technology
CN105095091A
Code scanning method and device, electronic equipment and medium
CN116680184A
Defect positioning technology based on positioning keyword extraction
CN118114098A
Vulnerability file positioning method and device, computer equipment and storage medium
CN119227074A
Code defect detection method and device, computer equipment and storage medium
CN119272278A
Cited By
Software defect locating method and apparatus, device, storage medium and program product
WO2026149127A1