Software defect locating method and apparatus, device, storage medium and program product
By acquiring defect description information and code file information, using a preset model to determine defect keywords and split code blocks, the problem of low efficiency in locating complex logic errors in existing technologies is solved, and automated and efficient software defect location is achieved.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- CLOUD INTELLIGENCE ASSETS HOLDING (SINGAPORE) PTE LTD
- Filing Date
- 2025-12-11
- Publication Date
- 2026-07-16
AI Technical Summary
In existing technologies, static or dynamic code analysis tools cannot efficiently locate complex logical errors, requiring manual intervention, resulting in low efficiency in software defect location.
By acquiring defect description information and code file information, using a preset model to determine defect keywords, and splitting associated files into code blocks, the target code block is retrieved based on the degree of matching, thus narrowing the index range and improving the location efficiency.
Without manual intervention, the system automatically locates target code blocks that match defect keywords using a preset model, thus improving the efficiency of software defect localization.
Smart Images

Figure CN2025141930_16072026_PF_FP_ABST
Abstract
Description
Software defect location methods, devices, equipment, storage media and program products
[0001] This disclosure claims priority to Chinese Patent Application No. 202510046129.4, filed on January 13, 2025, entitled "Software Defect Location Method, Apparatus, Device, Storage Medium and Program Product", the entire contents of which are incorporated herein by reference. Technical Field
[0002] This disclosure relates to the field of computers, and in particular to a method, apparatus, device, storage medium, and program product for locating software defects. Background Technology
[0003] As software functionality and code continue to evolve, software size and structure become increasingly complex. To ensure the normal operation of the software, defect location, defect repair, and defect testing are necessary. Among these, defect location, as a prerequisite for defect repair, is a crucial and indispensable step in the entire defect repair process, as its accuracy and efficiency affect subsequent steps. However, this step becomes increasingly complex and inefficient as the software size increases.
[0004] In related technologies, static or dynamic code analysis tools are typically used to examine the corresponding code files or the software runtime to locate code errors. However, static or dynamic code analysis tools can usually only locate syntax errors or errors that conform to specific templates (e.g., memory errors, deadlocks, etc.), and cannot locate complex logical errors; for more complex logical errors, manual location is required.
[0005] As can be seen from the above, the efficiency of software defect localization in related technologies is low. Summary of the Invention
[0006] This disclosure provides a method, apparatus, device, storage medium, and program product for locating software defects, thereby addressing the problem of low efficiency in locating software defects.
[0007] In a first aspect, embodiments of this disclosure provide a software defect localization method, including:
[0008] Obtain 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;
[0009] Based on the defect description information, code file information, and preset model, defect keywords are determined, and associated files are determined from the code files corresponding to the target software.
[0010] The associated file is split into multiple code blocks;
[0011] Among the multiple code blocks in the associated file, the target code block that matches the defect keyword is retrieved.
[0012] In one possible implementation, the associated files include a first associated file and a second associated file; based on the defect description information, code file information, and a preset model, defect keywords are determined, and associated files are determined from the code files corresponding to the target software, including:
[0013] Based on the defect description information, code file information, and preset model, defect keywords are determined, and a first associated file is determined from the code file corresponding to the target software.
[0014] Based on the relevance between the defect keywords and the code file, a second associated file is determined from the code file corresponding to the target software.
[0015] In one possible implementation, the associated file further includes a third associated file; the method further includes:
[0016] 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.
[0017] In one possible implementation, the preset model is further used to preprocess the defect description information to obtain preprocessed defect description information;
[0018] Retrieving target code blocks that match the defect keywords from multiple code blocks in the associated file, including:
[0019] Using the code blocks obtained from the splitting of the associated files as the index range, the matching degree of each code block is calculated based on the defect description information, the defect keywords, and the preprocessed defect description information;
[0020] Based on the degree of matching, the target code block is determined from the code blocks obtained by splitting the associated file.
[0021] In one possible implementation, determining the target code block from the code blocks obtained by splitting the associated file based on the matching degree includes:
[0022] The code blocks obtained from the associated files and their dependent files are sorted in descending order of matching degree;
[0023] Based on the code snippets of the code blocks, generate the code block text vectors of the top N code blocks in the sorted results, where N is a positive integer greater than 1;
[0024] Determine the defect text vector of the preprocessed defect description information;
[0025] Based on the similarity between the defective text vector and the code block text vector, the target code block is determined from the top N code blocks in the sorting results.
[0026] In one possible implementation, the target code block is determined from the top N code blocks in the ranking result based on the similarity between the defective text vector and the code block text vector, including:
[0027] Determine the similarity threshold corresponding to the target software;
[0028] Based on the similarity between the defective text vector and the code block text vector, the code block with a similarity greater than or equal to the similarity threshold among the top N code blocks in the ranking result is determined as the target code block.
[0029] In one possible implementation, the code file information further includes external dependency description information of the target software, which describes the external components that the code file corresponding to the target software depends on.
[0030] In one possible implementation, the associated file is split into multiple code blocks, including:
[0031] Obtain the abstract syntax tree of the associated file;
[0032] Based on the abstract syntax tree, the associated file is split into multiple code blocks.
[0033] In one possible implementation, the method further includes:
[0034] Based on the code snippet of the target code block and the location information, a defect location report of the target software is generated, wherein the location information is used to locate the target code block.
[0035] Secondly, embodiments of this disclosure provide a software defect localization device, comprising: an acquisition module, a first determination module, a splitting module, and a second determination module, wherein...
[0036] 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;
[0037] The first determining module is used to determine defect keywords based on the defect description information, code file information, and preset model, and to determine associated files from the code files corresponding to the target software;
[0038] The splitting module is used to split the associated file into multiple code blocks;
[0039] The second determining module is used to retrieve, among multiple code blocks in the associated file, a target code block that matches the defect keyword.
[0040] In one possible implementation, the associated files include a first associated file and a second associated file; the first determining module is specifically used for:
[0041] Based on the defect description information, code file information, and preset model, defect keywords are determined, and a first associated file is determined from the code file corresponding to the target software.
[0042] Based on the relevance between the defect keywords and the code file, a second associated file is determined from the code file corresponding to the target software.
[0043] In one possible implementation, the associated file also includes a third associated file;
[0044] The first determining module is further configured to, based on the file dependency graph of the target software, 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.
[0045] In one possible implementation, the preset model is further used to preprocess the defect description information to obtain preprocessed defect description information; the second determining module is specifically used for:
[0046] Using the code blocks obtained from the splitting of the associated files as the index range, the matching degree of each code block is calculated based on the defect description information, the defect keywords, and the preprocessed defect description information;
[0047] Based on the degree of matching, the target code block is determined from the code blocks obtained by splitting the associated file.
[0048] In one possible implementation, the second determining module is specifically used for:
[0049] The code blocks obtained from the associated files and their dependent files are sorted in descending order of matching degree;
[0050] Based on the code snippets of the code blocks, generate the code block text vectors of the top N code blocks in the sorted results, where N is a positive integer greater than 1;
[0051] Determine the defect text vector of the preprocessed defect description information;
[0052] Based on the similarity between the defective text vector and the code block text vector, the target code block is determined from the top N code blocks in the sorting results.
[0053] In one possible implementation, the second determining module is specifically used for:
[0054] Determine the similarity threshold corresponding to the target software;
[0055] Based on the similarity between the defective text vector and the code block text vector, the code block with a similarity greater than or equal to the similarity threshold among the top N code blocks in the ranking result is determined as the target code block.
[0056] In one possible implementation, the code file information further includes external dependency description information of the target software, which describes the external components that the code file corresponding to the target software depends on.
[0057] In one possible implementation, the splitting module is specifically used for:
[0058] Obtain the abstract syntax tree of the associated file;
[0059] Based on the abstract syntax tree, the associated file is split into multiple code blocks.
[0060] In one possible implementation, the second determining module is further configured to:
[0061] Based on the code snippet of the target code block and the location information, a defect location report of the target software is generated, wherein the location information is used to locate the target code block.
[0062] Thirdly, embodiments of this disclosure provide an electronic device, including: a memory and a processor;
[0063] The memory stores computer-executed instructions;
[0064] The processor executes computer execution instructions stored in the memory, causing the processor to perform the method described in any of the first aspects.
[0065] Fourthly, embodiments of this disclosure provide a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, are used to implement the method described in any of the first aspects.
[0066] Fifthly, embodiments of this disclosure provide a computer program product, including a computer program that, when executed by a processor, implements the method shown in any of the first aspects.
[0067] This disclosure provides a software defect localization method, apparatus, device, storage medium, and program product. The electronic device can acquire defect description information and code file information of the target software, and based on the defect description information, code file information, and a preset model, determine defect keywords and related files from the corresponding code files of the target software. The electronic device can split the related files into multiple code blocks and determine the target code block matching the defect keywords within the code blocks of the related files. Since the electronic device can determine defect keywords through a preset model and identify related files highly relevant to the problem, it can then determine the target code block matching the defect keywords within the code blocks of the related files. This eliminates the need for manual defect localization, and by using the code blocks of the related files as an index to determine the target code block, the index range is narrowed, thus improving the efficiency of defect localization in the target software. Attached Figure Description
[0068] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0069] Figure 1 is a schematic diagram of an application scenario provided by an exemplary embodiment of this disclosure;
[0070] Figure 2 is a flowchart illustrating a software defect localization method provided by an exemplary embodiment of this disclosure;
[0071] Figure 3 is a schematic diagram of a code block splitting based on an AST syntax tree provided by an exemplary embodiment of this disclosure;
[0072] Figure 4 is a flowchart illustrating another software defect localization method provided by an exemplary embodiment of this disclosure;
[0073] Figure 5 is a schematic diagram of a file dependency graph provided by an exemplary embodiment of this disclosure;
[0074] Figure 6 is a schematic diagram of a software defect localization method provided by an exemplary embodiment of the present disclosure;
[0075] Figure 7 is a schematic diagram of a software defect location device provided in an exemplary embodiment of the present disclosure;
[0076] Figure 8 is a schematic diagram of the structure of an electronic device provided by an exemplary embodiment of this disclosure.
[0077] The accompanying drawings have illustrated specific embodiments of this disclosure, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concepts of this disclosure to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0078] 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, data stored, data displayed, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with relevant laws, regulations and standards, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0079] To make the objectives, technical solutions, and advantages of this disclosure clearer, the technical solutions of this disclosure will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without creative effort are within the scope of protection of this disclosure.
[0080] To facilitate understanding of the technical solutions disclosed herein, the concepts involved in this disclosure will first be explained.
[0081] Abstract Syntax Tree (AST): A tree-like representation of the abstract syntactic structure of a code file, which displays the syntactic structure of the code in a tree form.
[0082] File dependency graph: Files have dependencies on each other due to mutual references. The file dependency graph is a structured representation of the mutual dependencies between files.
[0083] The application scenarios of this disclosure will be explained below with reference to Figure 1.
[0084] Figure 1 is a schematic diagram of an application scenario provided by an exemplary embodiment of this disclosure. Referring to Figure 1, the target software may have a corresponding code library, which 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.
[0085] When the target software exhibits 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, so as to identify the target code block with the defect in multiple code files.
[0086] For example, if the target software is an online shopping app, and a duplicate order occurs when a user places an order through the app, this indicates a defect in the target software that causes duplicate orders. The defect description might be: "A user placed an order for product A through the target software at 15:00 today, but a duplicate order occurred. It's unclear whether this is caused by an error in the front-end submission logic or a flaw in the back-end order processing logic. We hope to find the specific cause of the duplicate order in order to resolve this issue." The electronic device can then use this defect description to locate the defect in the 100 corresponding code files of the target software, identifying the defective target code block within those files. For example, the target code blocks could be code block 1 and code block 3.
[0087] In related technologies, static or dynamic code analysis tools are typically used to examine the corresponding code files or the software runtime to locate code errors. However, static or dynamic code analysis tools can usually only locate syntax errors or errors that conform to specific templates (e.g., memory errors, deadlocks, etc.); for more complex logical errors, manual location is required. Therefore, it is clear that related technologies are inefficient for software defect location.
[0088] In this embodiment, the electronic device can determine defect keywords and related files from the corresponding code files of the target software based on defect description information, target software code file information, and a preset model. Then, it can identify target code blocks matching the defect keywords within the code blocks of the related files. Since the electronic device can determine defect keywords and identify related files highly relevant to the problem using a preset model, and can then identify target code blocks matching the defect keywords within the code blocks of the related files, manual defect localization is unnecessary. Furthermore, using the code blocks of the related files as an index to determine the target code block narrows the index range, thus improving the efficiency of defect localization in the target software.
[0089] The technical solutions disclosed herein will now be described in detail through specific embodiments. It should be noted that the following embodiments may exist independently or in combination with each other; identical or similar content will not be repeated in different embodiments.
[0090] The execution subject of this disclosure can be an electronic device or a software defect location device installed in an electronic device. The software defect location device can be implemented in software or a combination of software and hardware. The software defect location device can be a processor in the electronic device. For ease of understanding, the following description will use an electronic device as the execution subject.
[0091] Figure 2 is a flowchart illustrating a software defect localization method provided by an exemplary embodiment of this disclosure. Referring to Figure 2, the method may include:
[0092] S201. Obtain defect description information of the target software and code file information of the target software.
[0093] Optionally, the defect description information of the target software can be input by the user or automatically generated by the electronic device based on the defects of the target software.
[0094] The code file information may include information describing the code files corresponding to the target software.
[0095] Optionally, the code files corresponding to the target software can be stored in a code library according to a directory tree corresponding to the target software. The electronic device can determine the directory tree in the code library and use the directory tree as information describing the code files corresponding to the target software; therefore, the code file information can include the directory tree.
[0096] Optionally, the codebase may include external dependency description files. The electronic device can parse these files to obtain external dependency description information. This information can describe the external components (e.g., dependent libraries, dependent frameworks, third-party services, etc.) that the target software's code files depend on. For example, the external dependency description information may include the name, version, and source of the external components that the target software's code files depend on.
[0097] Optionally, the code file information may also include descriptions of external dependencies corresponding to the target software.
[0098] For example, if the target software is a shopping app, and the user's description of the defect is "When the user placed an order for product A through the target software at 15:00 today, a duplicate order occurred. It is unclear whether the issue was caused by an error in the submission logic of the front-end page or by an implementation defect in the back-end order processing logic. The user hopes to find out the specific cause of the duplicate order in order to resolve the problem," and the corresponding code library for the shopping app is code library 1, then the electronic device obtains the defect description information and the code file information. The code file information may include external dependency description information and the directory tree 1 defined in code library 1.
[0099] S202. Based on the defect description information, code file information, and preset model, determine the defect keywords and identify the associated files from the code files corresponding to the target software.
[0100] Since defect description information can be user-defined and may include redundant information, after the electronic device inputs the defect description information into a preset model, the model can preprocess the defect description information to obtain preprocessed defect description information. Optionally, preprocessing may include referencing disambiguation, removing redundant information, etc.
[0101] Optionally, in any embodiment of this disclosure, the preset model can be a pre-trained Large Language Model (LLM). The preset model may contain over one billion parameters, and its underlying transformer may comprise a series of neural networks. In one or more embodiments, the preset model may include an encoder and / or decoder and possess self-attention functionality. The encoder and / or decoder can extract meaning from the input text and clarify the structural relationships between contexts. The preset model is pre-trained on a public dataset containing over 1TB (terabytes) of text data to learn a general language representation.
[0102] To adapt to the application scenario of software defect localization in this disclosure, we trained a large language model on a dedicated dataset containing thousands of defect descriptions and code file information, obtaining a pre-defined model. The pre-defined model can receive defect descriptions and code file information as input, preprocess the defect descriptions, and output preprocessed defect descriptions and defect keywords; furthermore, based on the defect keywords and code file information, it can identify and output the first associated file in the corresponding code file of the target software.
[0103] By using a pre-defined model, the semantics of defect description information can be better captured, and the defect description information can be preprocessed to generate concise and accurate preprocessed defect description information. This allows for more accurate identification of defect keywords. Furthermore, it can better capture the semantic relevance between defect keywords and code files, thereby more accurately retrieving the first associated file. This strengthens the targeting and relevance of identifying the first associated file, and thus improves the accuracy of retrieving the target code block.
[0104] For example, if the defect description information is as shown in the example above, the electronic device can preprocess the defect description information through a preset model to obtain the preprocessed defect description information as "When ordering product A at 15:00, a duplicate order occurred. Please find out whether the problem is caused by an error in the submission logic of the front-end page or by an implementation defect in the back-end order processing logic".
[0105] Optionally, defect keywords and associated files can be determined from the code files corresponding to the target software based on defect description information, code file information, and a preset model, as follows: Defect keywords are determined based on defect description information, code file information, and a preset model, and a first associated file is determined from the code files corresponding to the target software; a second associated file is determined from the code files corresponding to the target software based on the relevance between the defect keywords and the code files. The associated files may include both the first and second associated files.
[0106] Optionally, the electronic device can extract defect keywords from the preprocessed defect description information using a preset model, and determine the first associated file in the code file corresponding to the target software based on the defect keywords and code file information.
[0107] For example, if the preprocessed defect description information is as shown in the example above, the electronic device can extract three defect keywords from the preprocessed defect description information using a preset model: order placement, submission logic, and order processing logic. If the code file information includes the directory tree corresponding to the shopping software and external dependency description information, and the code library includes 100 code files corresponding to the target software, the electronic device can use a preset model to determine the four code files related to order processing as the first associated files among the 100 code files based on the "order placement" and "order processing logic" and the code file information. Assume these four code files can be Order / Dao.java, Order / Controller.java, Order / Handler.java, and Order / Transform.java. Based on the "submission logic" and the code file information, it can determine the three code files related to submission logic as the first associated files among the 100 code files. Assume these three code files can be Submit / Handler.java, Submit / Fail.java, and Submit / Verify.java. The electronic device can then identify seven primary associated files, namely code file 1 (i.e., Order / Dao.java file), code file 2 (i.e., Order / Controller.java file), ..., code file 7 (Submit / Verify.java file).
[0108] Optionally, the electronic device can use a preset relevance algorithm to calculate the relevance between defective keywords and code files, and then determine the code files with a relevance greater than or equal to the first relevance threshold as the second associated files in the code files corresponding to the target software.
[0109] For example, the preset relevance algorithm can be the BM25 algorithm, the Term Frequency-Inverse Document Frequency (TF-IDF) algorithm, etc.
[0110] Optionally, the first relevance threshold can be preset by a user. For example, the first relevance threshold can be 0.8.
[0111] For example, if the codebase contains 100 code files corresponding to the target software, and there are three defect keywords: order placement, submission logic, and order processing logic, and the default relevance algorithm is the BM25 algorithm, then the electronic device can use the BM25 algorithm to calculate the relevance between these three defect keywords and the 100 code files, obtaining 100 relevance scores. If the first relevance threshold is 0.8, then code files with a relevance score greater than 0.8 can be identified as second-related files. Assume the electronic device can identify five second-related files: code file 3, code file 10, code file 21, code file 22, and code file 23.
[0112] After an electronic device identifies at least one first associated file and at least one second associated file, it can determine that the associated files include at least one first associated file and at least one second associated file.
[0113] 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, then 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.
[0114] S203. Split the associated file into multiple code blocks.
[0115] Alternatively, the associated file can be split into multiple code blocks by: obtaining the abstract syntax tree of the associated file; and splitting the associated file into multiple code blocks based on the abstract syntax tree.
[0116] For any associated file, the electronic device can use an AST parsing tool to parse the associated file to obtain the corresponding AST syntax tree, and then split the associated file into multiple code chunks according to the structure of the AST syntax tree.
[0117] A code block is a logically related set of code statements. For any given code block, it can include code snippets used for defect keyword retrieval and location information. For example, the location information might 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 within the code file. For instance, the location information included in code block 1 could be: the module name to which code block 1 belongs is the "Order Processing Module", the file path is "shopping-software / order / file1", and the line number range of code block 1 within code file 1 is 010-020.
[0118] The AST syntax tree will now be explained with reference to Figure 3.
[0119] Figure 3 is a schematic diagram of code block splitting based on an AST syntax tree provided by an exemplary embodiment of this disclosure. Referring to Figure 3, the AST syntax tree can be obtained by parsing 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 code file 1 into 10 code blocks according to the structure of this AST syntax tree.
[0120] For example, if an electronic device is determined to have 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 code file 1 can be split into 10 code blocks; code file 2 can be split into 8 code blocks; and so on; code file 23 can be split into 15 code blocks. Assume that the 11 associated files correspond to a total of 200 code blocks, namely code block 1, code block 2, ..., code block 200.
[0121] S204. Among multiple code blocks in the associated file, retrieve the target code block that matches the defect keyword.
[0122] Electronic devices can use a preset relevance algorithm to calculate the relevance between defect keywords and multiple code blocks corresponding to associated files, thereby identifying code blocks with a relevance greater than a second relevance threshold as target code blocks that match the defect keywords.
[0123] It should be noted that when calculating the relevance between multiple defect keywords and code blocks using the preset relevance algorithm, the multiple defect keywords are treated as a whole and the relevance between them and the code block is calculated.
[0124] For example, if there are 200 code blocks and three defect keywords—"order placement," "submission logic," and "order processing logic"—and the default relevance algorithm is the BM25 algorithm, the electronic device can use the BM25 algorithm to calculate the relevance of these three defect keywords to each code block, resulting in 200 relevance scores. If the second relevance threshold is 0.9, the electronic device can identify code blocks with a relevance score greater than 0.9 as target code blocks. Assume there are eight target code blocks: 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.
[0125] In this embodiment, the electronic device can acquire defect description information and code file information of the target software. Based on the defect description information, code file information, and a preset model, it determines defect keywords and identifies associated files from the corresponding code files of the target software. The electronic device can split the associated files into multiple code blocks and retrieve target code blocks that match the defect keywords from among the multiple code blocks of the associated files. Since the electronic device can determine defect keywords through the preset model and identify associated files that are highly relevant to the problem, it can then identify target code blocks that match the defect keywords from the code blocks of the associated files. This eliminates the need for manual defect localization, and by using the code blocks of the associated files as the index range to determine the target code block, the index range is narrowed, thus improving the efficiency of defect localization in the target software.
[0126] The software defect localization method described above will now be explained in detail based on the embodiment shown in Figure 2 and in conjunction with Figure 4.
[0127] Figure 4 is a flowchart illustrating another software defect localization method provided by an exemplary embodiment of this disclosure. Referring to Figure 4, the method may include:
[0128] S401. Obtain defect description information of the target software and code file information of the target software.
[0129] It should be noted that the execution process of step S401 can be found in step S201, and will not be repeated here.
[0130] S402. Based on the defect description information, code file information, and preset model, determine the defect keywords and determine the first associated file from the code file corresponding to the target software.
[0131] Electronic devices preprocess defect description information using a preset model to obtain preprocessed defect description information, and then extract defect keywords from the preprocessed defect description information.
[0132] After identifying defect keywords for electronic devices, a preset model can be used to determine the first associated file in the code file corresponding to the target software, based on the defect keywords and code file information.
[0133] Optionally, the first associated file can be determined as follows: The electronic device can determine the role of each code file based on the external dependency description information in the code file information using a preset model, and determine the semantic relevance between defect keywords and each file path in the directory tree. Then, the code file corresponding to the file path with a semantic relevance greater than or equal to the preset relevance threshold is determined as the first associated file.
[0134] It should be noted that the file path refers to the complete file path of each code file in the directory tree.
[0135] Optionally, the preset relevance threshold can be preset manually or determined by the semantic relevance distribution.
[0136] For example, if an electronic device is identified as having three defect keywords: order placement, submission logic, and order processing logic, and if the codebase contains 100 code files, the electronic device, through a pre-defined model, determines the function of these 100 code files based on external dependency description information, and determines the semantic relevance between the three defect keywords and the file paths corresponding to these 100 files in the directory tree. For instance, for code file 1, if the external dependency description information includes that code file 1 depends on the order database, then the content of code file 1 can be determined to be order-related content, and the semantic relevance between the defect keywords and the file path (Order / Dao.java) of code file 1 can be determined to be 0.9.
[0137] If the preset relevance threshold is 0.7, and assuming the file paths with semantic relevance 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 these 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 (i.e., Order / Dao.java), code file 2 corresponding to file path 2 (i.e., Order / Controller.java), ..., code file 7 (i.e., Submit / Verify.java).
[0138] S403. Based on the relevance between defect keywords and code files, determine the second associated file from the code files corresponding to the target software.
[0139] Optionally, the execution process of step S403 can be found in the relevant content of step S202, and will not be repeated here.
[0140] S404. Based on the file dependency graph of the target software, 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.
[0141] A codebase may include at least one code file, and dependencies may exist between these at least one code file. The first associated file is determined from at least one code file. Based on practical development experience, defects may also exist in the code files that the first associated file depends on. Therefore, when locating software issues, it is also necessary to consider calculating the degree of association between the code files that the first associated file depends on and the defects.
[0142] A file dependency graph can include the dependencies between at least one code file corresponding to the target software.
[0143] The file dependency graph will now be explained with reference to Figure 5.
[0144] Figure 5 is a schematic diagram of a file dependency graph provided by an exemplary embodiment of this disclosure. Referring to Figure 5, if the target software corresponds to 100 code files, the file dependency graph can include the dependency relationships between the 100 code files. As shown in Figure 5, in the file dependency graph, code file 1 depends on code files 25 and 26, code file 2 depends on code file 24, code files 3 and 4 have no dependent code files, code file 5 depends on code files 8 and 9, code file 6 has no dependent code files, code file 7 depends on code files 14, 15, and 16, ..., and code file 99 depends on code file 100.
[0145] Optionally, the electronic device can determine the file dependency graph of the target software, and based on the file dependency graph, determine the code file that the first associated file depends on in the code library, and determine the code file that the first associated file depends on as the third associated file.
[0146] For example, if there are seven first-related files, namely code file 1, code file 2, code file 3, ..., code file 7, and the file dependency graph is shown in Figure 5, then the electronic device can determine, based on the file dependency graph, that code file 1 depends on code files 25 and 26, code file 2 depends on code file 24, ..., and code file 7 depends on code files 14, 15, and 16. The electronic device can determine that the seven first-related files depend on a total of eight code files (i.e., code files 25, 26, 24, 8, 9, 14, 15, and 16), and identify these eight code files as third-related files.
[0147] S405. The associated files are determined to include the first associated file, the second associated file, and the third associated file.
[0148] For example, if an electronic device is determined to have 7 first associated files, 5 second associated files, and 8 third associated files as shown in Table 1:
[0149] Table 1
[0150] The electronic device can then identify a total of 19 associated files, 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 be found in step S203, and will not be repeated here.
[0153] S407. Using the code blocks obtained from the splitting of associated files as the index range, calculate the matching degree of each code block based on defect keywords and preprocessed defect description information.
[0154] Optionally, after obtaining multiple code blocks from the split associated file, the electronic device can perform text indexing on these code blocks. Specifically, the electronic device can simplify the code blocks to generate corresponding tags, and generate a text index based on the tags. The text index includes the tags of each code block.
[0155] Optionally, for any given code block, the electronic device can remove useless information (e.g., curly braces, semicolons, etc.) from the code block to simplify it, and use the simplified code block as its label. The label of the code block then includes the useful information from the code block.
[0156] For example, if there are 19 associated files, and these 19 files correspond to a total of 500 code blocks, the electronic device can simplify each of these 500 code blocks to obtain a tag for each code block, and generate a text index based on the tags of these 500 code blocks. The text index can include the tags of the 500 code blocks.
[0157] Since the text index is built based on the tags of each code block, electronic devices using the text index as the indexing scope are equivalent to using the code blocks obtained by splitting the associated file as the indexing scope. Indexing based on the text index can improve indexing efficiency.
[0158] Electronic devices can use a pre-defined relevance algorithm to calculate the degree of matching of tags for each code block in the text index based on defect keywords and pre-processed defect description information.
[0159] Specifically, electronic devices can use a preset relevance algorithm to calculate the first relevance between defect keywords and the tags of each code block in the text index; and can use a preset relevance algorithm to calculate the second relevance between the preprocessed defect description information and the tags of each code block in the text index.
[0160] For any given code block, the electronic device can determine the degree of matching of the code block's tags based on the first and second relevance of the tags corresponding to the code block, and use the degree of matching of the code block's tags as the degree of matching of the code block.
[0161] Optionally, the degree of matching can be a statistical value calculated based on the first relevance and the second relevance. For example, the statistical value can be the average or a weighted average, etc.
[0162] For example, if the defect description is "When a user placed an order for product A through the target software at 15:00 today, a duplicate order occurred. It is unclear whether this was caused by an error in the submission logic of 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 resolve the problem"; and the preprocessed defect description is "When ordering product A at 15:00, a duplicate order occurred. Please determine whether the problem was caused by an error in the submission logic of the front-end page or an implementation defect in the back-end order processing logic"; and the defect keywords are "order," "submission logic," and "order processing logic," and the text index includes 500 code block tags, then the electronic device can use the BM25 algorithm to calculate the first relevance of the preprocessed defect description with the tags of these 500 code blocks, obtaining 500 first relevances; and can use the BM25 algorithm to calculate the second relevance of the defect keywords with the tags of these 500 code blocks, obtaining 500 second relevances. Assume that these 500 first relevances and 500 second relevances are as shown in Table 2:
[0163] Table 2
[0164] If the matching degree is the average of the first relevance and the second relevance, then the matching degree of the label for each code block can be calculated as shown in Table 2.
[0165] S408. Based on the degree of matching, determine the target code block from the code blocks obtained by splitting the associated file.
[0166] Optionally, the target code block can be determined from the code blocks split from the associated file based on the degree of matching as follows: sort the code blocks split from the associated file in descending order of matching degree; generate code block text vectors for the top N code blocks in the sorted results based on the code fragments of the code blocks; determine the defect text vector of the preprocessed defect description information; and determine the target code block from the top N code blocks in the sorted results based on the correlation between the defect text vector and the code block text vector.
[0167] N can be a positive integer greater than 1, and N can be preset by the user. For example, N can be 10.
[0168] Since the matching degree of each code block is calculated using a preset relevance algorithm without utilizing the contextual information of the code fragments within the code block, after determining the top N code blocks in the sorted results, code block text vectors can be generated for each of these top N code blocks based on the code fragments within them. 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 vectors of the N code blocks using a preset similarity algorithm, and determine the target code block from the N code blocks based on the similarity.
[0169] For example, the preset similarity algorithm can be cosine similarity algorithm, Euclidean distance algorithm, Pearson correlation coefficient algorithm, etc.
[0170] Optionally, the target code block can be determined from the top N code blocks in the ranking results based on the similarity between the defect text vector and the code block text vector, as follows: determine the 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 with a similarity greater than or equal to the similarity threshold from the top N code blocks in the ranking results as the target code block.
[0171] By using code block text vectors, the contextual information of code fragments within a code block can be expressed. Therefore, based on the first N code blocks determined according to the degree of matching, the target code block can be identified from the first N code blocks based on the correlation between the defect text vector and the code block text vector, further improving the accuracy of identifying the target code block.
[0172] Optionally, the similarity threshold can be determined based on the correlation distribution between the defect text vector and the code block text vector. For example, the similarity threshold could be 0.8.
[0173] 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 descending order of matching degree to obtain the sorting result. If N is 10, the electronic device can determine the top 10 code blocks in the sorting result. Assume the top 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 fragments 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 fragments 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 fragments in code block 465. The electronic device can generate a defect text vector of the preprocessed defect description information. Electronic devices can use the cosine similarity algorithm to calculate the similarity between the defect text vector and the text vectors of each code block, as shown in Table 3:
[0174] Table 3
[0175] If the similarity threshold corresponding to the target software is 0.5, the electronic device can identify code block 3, code block 1, code block 20, code block 65, and code block 412 as the target code blocks among the 10 code blocks.
[0176] S409. Based on the code snippets and location information of the target code block, generate a defect location report for the target software.
[0177] Location information can be used to locate the target code block. For example, location 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. For example, the location information included in code block 1 may be: the module name to which code block 1 belongs is the order processing module, the file path where it is located is "shopping-software / order / file1", and the line number range of code block 1 in code file 1 is 010-020.
[0178] For example, if the target software is shopping software, and the electronic device is determined to have 5 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 these 5 target code blocks.
[0179] It should be noted that the various processing steps (S401-S409) shown in the embodiment of FIG4 do not constitute a specific limitation on the software defect localization process. In other embodiments of this disclosure, the software defect localization process may include more or fewer steps than that in the embodiment of FIG4. For example, the software defect localization process may include some of the steps in the embodiment of FIG4, or some steps in the embodiment of FIG4 may be replaced by steps with the same function, or some steps in the embodiment of FIG4 may be split into multiple steps, etc.
[0180] In this embodiment, the electronic device can acquire defect description information and code file information of the target software. Based on the defect description information, code file information, and a preset model, the electronic device can determine defect keywords and identify a first associated file from the code files corresponding to the target software. Based on the relevance between the defect keywords and the code files, it can also identify a second associated file from the code files corresponding to the target software. Furthermore, based on the file dependency graph of the target software, it can identify the code files dependent on by the first associated file as third associated files within the code files corresponding to the target software. Therefore, the associated files include the first, second, and third associated files. The electronic device can split the associated files into multiple code blocks and use these code blocks as the index range. Based on the defect keywords and preprocessed defect description information, it can calculate the matching degree of each code block and, based on the matching degree, identify the target code block from the code blocks split from the associated files. The electronic device can generate a defect location report for the target software based on the code fragments and location information of the target code block. Because electronic devices can identify highly relevant related files from the code files corresponding to the target software based on defect keywords, and then identify the defective target code block within the code blocks of the related files, the index range is narrowed, improving the speed of defect localization in the target software. Furthermore, a preset similarity algorithm can be used to determine the top N code blocks with high relevance, and then the target code block can be identified from these top N code blocks based on the code block text vector. This not only considers the keyword matching relevance between the defect description information and the code block, but also the contextual information of the code fragments in the code block, improving the accuracy of defect localization in the target software. Therefore, the efficiency of defect localization in the target software is comprehensively improved.
[0181] Below, based on any of the above embodiments and in conjunction with Figure 6, the above software defect location method will be further explained.
[0182] Figure 6 is a schematic diagram of a software defect localization method provided by an exemplary embodiment of this disclosure. Referring to Figure 6, steps ①②③④⑤⑥⑦⑧⑨ are included.
[0183] In step ①, the electronic device can input defect description information and code file information into the preset model.
[0184] For example, the defect description information could be: "When a user placed an order for product A through the target software at 15:00 today, a duplicate order occurred. It is unclear whether the issue was caused by an error in the submission logic of the front-end page or by 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 resolve the problem." The code file information could include the directory tree defined in code repository 1, as well as external dependency description information.
[0185] In step ②, the electronic device can preprocess the defect description information using a preset model to obtain preprocessed defect description information. For example, the preprocessed defect description information could be: When ordering product A at 15:00, a duplicate order occurred. Please determine whether the problem was caused by an error in the submission logic of the front-end page or by an implementation defect in the back-end order processing logic.
[0186] In step ③, the electronic device can determine defect keywords from the preprocessed defect description information using a preset model. For example, if the preprocessed defect description information is as shown in the example above, the defect keywords could be: order placement, submission logic, and order processing logic.
[0187] In step ④, the electronic device can determine the first associated file in the code library corresponding to the target software based on the defect keywords and code file information. For example, the code library may include multiple code files corresponding to the target software, namely code file 1, code file 2, code file 3, ..., code file 100.
[0188] Optionally, the specific execution process of step ④ can be found in the execution process of step S402, and will not be repeated here.
[0189] For example, the electronic device can identify the existence of 7 first associated files, as shown in Table 1.
[0190] In step ⑤, based on the relevance between defect keywords and code files, a second associated file is determined from the code files corresponding to the target software.
[0191] Optionally, the specific execution process of step ⑤ can be found in the execution process of step S202, and will not be repeated here.
[0192] For example, the electronic device can identify the existence of 5 second associated files, as shown in Table 1.
[0193] In step ⑥, 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.
[0194] Optionally, the specific execution process of step ⑥ can be found in the execution process of step S404, and will not be repeated here.
[0195] For example, the electronic device can identify the existence of 8 third-party associated files, as shown in Table 1.
[0196] The electronic device can determine that the associated files include a first associated file, a second associated file, and a third associated file. For example, the associated files may be as shown in Table 1.
[0197] In step ⑦, the electronic device can split the associated file to obtain multiple code blocks.
[0198] For example, if there are 19 associated files, the electronic device can use an AST parsing tool to parse each associated file and obtain the AST syntax tree corresponding to each associated file. Then, based on the AST syntax tree, the corresponding associated file can be split to obtain multiple code blocks. Assuming that the 19 associated files are split, a total of 500 code blocks can be obtained, as shown in Figure 6.
[0199] In step ⑧, the electronic device can determine the degree of matching for each code block and, based on the degree of matching, select the top N code blocks from the sorted results among multiple code blocks.
[0200] It should be noted that the process of determining the matching degree of each code block can be found in the relevant content of step S407, and will not be repeated here.
[0201] For example, if the matching degree of the 500 code blocks is as shown in Table 2, and N is 10, then the 500 code blocks are sorted in descending order of matching degree to obtain the sorting result. The electronic device can determine the top 10 code blocks in the sorting result. Assume that the top 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, as shown in Figure 6.
[0202] In step 9, 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 code block text vector. Then, based on the defect text vector and the code block text vector of each code block, the target code block can be determined from the first N code blocks in the sorting result.
[0203] For example, if the similarity between the defective text vector and the text vectors of the first 10 code blocks is as shown in Table 3, and if the similarity threshold is 0.5, then the electronic device can identify code block 3, code block 1, code block 20, code block 65, and code block 412 as target code blocks among these 10 code blocks, as shown in Figure 6.
[0204] In this embodiment, the electronic device can acquire defect description information of the target software and code file information of the target software. Based on the defect description information, code file information, and a preset model, the electronic device can determine defect keywords, identify a first associated file from the code file corresponding to the target software, and determine a second associated file from the code file corresponding to the target software based on the relevance between the defect keywords and the code file. Furthermore, based on the file dependency graph of the target software, the electronic device can identify the code file dependent on by the first associated file as a third associated file within the code file corresponding to the target software. Thus, the associated files can be determined to include the first, second, and third associated files. The electronic device can split the associated files into multiple code blocks, using the code blocks obtained from the split associated files as the index range. Based on the defect keywords and preprocessed defect description information, the matching degree of each code block is calculated. Based on the matching degree, the top N code blocks in the sorted results are determined from the multiple code blocks. Then, based on the defect text vector and the code block text vector of each code block, the target code block can be determined from the top N code blocks. Because electronic devices can identify highly relevant related files from the code files corresponding to the target software based on defect keywords, and then identify the defective target code block within the code blocks of the related files, the index range is narrowed, improving the speed of defect localization in the target software. Furthermore, a preset similarity algorithm can be used to determine the top N code blocks with high relevance, and then the target code block can be identified from these top N code blocks based on the code block text vector. This not only considers the keyword matching relevance between the defect description information and the code block, but also the contextual information of the code fragments in the code block, improving the accuracy of defect localization in the target software. Therefore, the efficiency of defect localization in the target software is comprehensively improved.
[0205] The technical solution disclosed herein can be applied to the software development process to help developers quickly locate and fix software defects. For example, in automated testing, this technical solution can help testers quickly locate defects in test cases. In automated development and question-answering systems, it can be used as part of the Retrieval-Augmented Generation (RAG) process to provide code information related to the question. Furthermore, the technical solution disclosed herein can also be used in teaching and research fields to help students and researchers better understand methods for locating software defects.
[0206] Figure 7 is a schematic diagram of a software defect location device provided in an exemplary embodiment of this disclosure. Referring to 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...
[0207] The acquisition module 11 is used to acquire defect description information of the target software and code file information of the target software. The code file information includes information describing the code file corresponding to the target software.
[0208] The first determining module 12 is used to determine defect keywords and related files from the code files corresponding to the target software, based on defect description information, code file information and preset models.
[0209] Splitting module 13 is used to split associated files into multiple code blocks;
[0210] The second determining module 14 is used to retrieve, among multiple code blocks in the associated file, the target code block that matches the defect keyword.
[0211] The software defect location device provided in this disclosure can execute the technical solution shown in the above method embodiments. Its implementation principle and beneficial effects are similar, and will not be described again here.
[0212] In one possible implementation, the associated files include a first associated file and a second associated file; the first determining module 12 is specifically used for:
[0213] Based on defect description information, code file information, and preset models, defect keywords are determined, and the first associated file is determined from the code file corresponding to the target software.
[0214] Based on the relevance between defect keywords and code files, a second associated file is determined from the code files corresponding to the target software.
[0215] In one possible implementation, the associated file also includes a third associated file;
[0216] The first determining module 12 is also used to determine, based on the file dependency graph of the target software, the code file that the first associated file depends on as the third associated file in the code file corresponding to the target software.
[0217] In one possible implementation, the preset model is further used to preprocess the defect description information to obtain preprocessed defect description information; the second determining module 14 is specifically used for:
[0218] Using the code blocks obtained from splitting associated files as the index range, the matching degree of each code block is calculated based on defect description information, defect keywords, and preprocessed defect description information;
[0219] Based on the degree of matching, the target code block is determined from the code blocks obtained by splitting the associated files.
[0220] In one possible implementation, the second determining module 14 is specifically used for:
[0221] Sort the code blocks obtained from the associated files according to the degree of matching from high to low;
[0222] Based on the code snippets, generate the code block text vectors of the top N code blocks in the sorted results, where N is a positive integer greater than 1;
[0223] Determine the defect text vector of the preprocessed defect description information;
[0224] Based on the similarity between the defect text vector and the code block text vector, the target code block is determined from the top N code blocks in the sorting results.
[0225] In one possible implementation, the second determining module 14 is specifically used for:
[0226] Determine the similarity threshold for the target software;
[0227] Based on the similarity between the defect text vector and the code block text vector, the code blocks with a similarity greater than or equal to the similarity threshold in the top N code blocks in the ranking results are identified as target code blocks.
[0228] In one possible implementation, the code file information also includes external dependency description information of the target software, which describes the external components that the code file corresponding to the target software depends on.
[0229] In one possible implementation, the splitting module 13 is specifically used for:
[0230] Obtain the abstract syntax tree of the associated file;
[0231] Based on the abstract syntax tree, the associated files are split into multiple code blocks.
[0232] In one possible implementation, the second determining module 14 is further configured to:
[0233] Based on the code snippets of the target code block and the location information, a defect location report for the target software is generated. The location information is used to locate the target code block.
[0234] The software defect location device provided in this disclosure can execute the technical solution shown in the above method embodiments. Its implementation principle and beneficial effects are similar, and will not be described again here.
[0235] Figure 8 is a schematic diagram of the structure of an electronic device provided by an exemplary embodiment of the present disclosure. Referring to 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.
[0236] Memory 22 stores instructions executed by the computer;
[0237] The processor 21 executes computer execution instructions stored in the memory 22, causing the processor 21 to perform the method as shown in the above method embodiment.
[0238] Accordingly, this disclosure provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, are used to implement the methods described in the above method embodiments.
[0239] Accordingly, this disclosure also provides a computer program product, including a computer program, which, when executed by a processor, can implement the methods shown in the above-described method embodiments.
[0240] Those skilled in the art will understand that embodiments of this disclosure can be provided as methods, systems, or computer program products. Therefore, this disclosure can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this disclosure can take the form of a computer program product embodied 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.
[0241] This disclosure is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in one or more flowchart illustrations and / or one or more block diagrams.
[0242] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more flowcharts and / or one or more block diagrams.
[0243] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide steps for implementing the functions specified in one or more flowcharts and / or one or more block diagrams.
[0244] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0245] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0246] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, 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 technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0247] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0248] The above are merely embodiments of this disclosure and are not intended to limit the scope of this disclosure. Various modifications and variations can be made to this disclosure by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this disclosure should be included within the scope of the claims of this disclosure.
Claims
1. A method for locating software defects, comprising: Obtain defect description information of the target software and code file information of the target software, wherein the code file information includes a directory tree and external dependency description information corresponding to the target software; Based on the defect description information, code file information, and preset model, defect keywords are determined; the preset model is a pre-trained large language model. Identify associated files from the code files corresponding to the target software; split the associated files into multiple code blocks; Among the multiple code blocks in the associated file, the target code block that matches the defect keyword is retrieved.
2. The method according to claim 1, wherein the associated file includes a first associated file and a second associated file; Based on the defect description information, code file information, and preset model, defect keywords are determined, and associated files are determined from the code files corresponding to the target software, including: Based on the defect description information, code file information, and preset model, defect keywords are determined, and a first associated file is determined from the code file corresponding to the target software. Based on the relevance between the defect keywords 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, wherein determining the first associated file from the code file corresponding to the target software includes: The role of each code file is determined based on external dependency description information. The semantic relevance between the defect keywords and each code file path in the directory tree is determined. The code file corresponding to the file path with a semantic relevance greater than or equal to a preset relevance threshold is determined as the first associated file.
4. The method according to claim 2 or 3, wherein the associated file further includes a third associated file; the method further 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.
5. The method according to any one of claims 1-4, wherein the preset model is further used to preprocess the defect description information to obtain preprocessed defect description information; Retrieving target code blocks that match the defect keywords from multiple code blocks in the associated file, including: Using the code blocks obtained from the splitting of the associated files as the index range, and based on the defect keywords and the preprocessed defect description information, the matching degree of each code block is calculated; Based on the degree of matching, the target code block is determined from the code blocks obtained by splitting the associated file.
6. The method according to claim 5, wherein the step of calculating the matching degree of each code block based on the defect keywords and the preprocessed defect description information, using the code blocks obtained by splitting the associated file as the index range, includes: Each of the multiple code blocks is simplified to generate a tag corresponding to each code block, and a text index is generated based on the tag of the code block; Using a pre-defined relevance algorithm, the first relevance between defect keywords and the tags of each code block in the text index is calculated; using the same pre-defined relevance algorithm, the second relevance between the pre-processed defect description information and the tags of each code block in the text index is calculated. Based on the first relevance and the second relevance corresponding to the tags of the code blocks, the matching degree of the tags of each code block is determined, and the matching degree of the tags of the code block is taken as the matching degree of the code block.
7. The method according to claim 6, wherein determining the matching degree of the tags of each code block based on the first relevance and the second relevance corresponding to the tags of the code blocks includes: The average or weighted average of the first relevance and the second relevance is calculated as the degree of matching.
8. The method according to claim 6 or 7, wherein the simplification process for each of the plurality of code blocks comprises: Remove curly braces and / or semicolons from each of the multiple code blocks.
9. The method according to any one of claims 5-8, wherein determining the target code block from the code blocks obtained by splitting the associated file based on the matching degree, comprising: The code blocks obtained from the associated files are sorted in descending order of matching degree; Based on the code snippets of the code blocks, generate the code block text vectors of the top N code blocks in the sorted results, where N is a positive integer greater than 1; Determine the 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 top N code blocks in the sorting results, wherein the text vector of the code block is used to express the context information of the code fragment in the code block.
10. The method according to claim 9, wherein the target code block is determined from the top N code blocks in the ranking result based on the similarity between the defective text vector and the code block text vector, comprising: Determine the similarity threshold corresponding to the target software; Based on the similarity between the defective text vector and the code block text vector, the code block with a similarity greater than or equal to the similarity threshold among the top N code blocks in the ranking result is determined as the target code block.
11. The method according to claim 10, wherein the similarity threshold is determined based on the correlation distribution between the defect text vector and the code block text vector.
12. The method according to claim 10 or 11, wherein the similarity between the defective text vector and the code block text vector is obtained by calculating the cosine similarity algorithm, the Euclidean distance algorithm, or the Pearson correlation coefficient algorithm.
13. The method according to any one of claims 5-12, wherein the preprocessing of the defect description information comprises: The defect description information is then resolved by referencing and / or redundant information is removed.
14. The method according to any one of claims 1-13, wherein the code file information further includes external dependency description information of the target software, the external dependency description information being used to describe the external components on which the code file corresponding to the target software depends.
15. The method according to any one of claims 1-14, wherein the associated file is split into multiple code blocks, comprising: Obtain the abstract syntax tree of the associated file; Based on the abstract syntax tree, the associated file is split into multiple code blocks.
16. The method according to any one of claims 1-15, further comprising: Based on the code snippet of the target code block and the location information, a defect location report of the target software is generated, wherein the location information is used to locate the target code block.
17. A software defect location device, comprising: The module includes 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 determining module is used to determine defect keywords based on the defect description information, code file information, and 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 determining module is used to retrieve, among multiple code blocks in the associated file, a target code block that matches the defect keyword.
18. An electronic device comprising: At least one processor; as well as A memory that is communicatively connected to the at least one processor; The memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, cause the electronic device to perform the method according to any one of claims 1-16.
19. A computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the method as described in any one of claims 1-16.
20. A computer program product comprising a computer program that, when executed by a processor, implements the method as claimed in any one of claims 1-16.