A software defect localization method based on contextual program reduction technology
Through the software defect positioning method based on context program reduction technology, stack trace and dependency analysis are used to solve the problem of retrieval space explosion caused by noise data interference in the prior art, and statement-level defect positioning is achieved, and defect detection is improved.
Patent Information
- Application Number
- CN202510774210.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-11
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2045-06-11
AI Technical Summary
Existing IR-based defect positioning technology is susceptible to noise data interference when processing defect reports, resulting in a retrieval space explosion and unable to achieve statement-level defect positioning.
A software defect positioning method based on context program reduction technology is adopted to generate stack traces through stack frames, extract suspicious program entities, parse code entities, analyze dependencies, and rank defect probability, and finally achieve statement-level defect positioning.
It effectively reduces the search space, improves the accuracy of defect positioning, and can detect more defect codes at the statement level, reducing false detection and missed detection.
Smart Images

Figure CN120295896B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of defect detection, and in particular to a software defect location method based on context program reduction technology. Background Art
[0002] Software defect localization is one of the most time-consuming and expensive activities in software debugging. As software systems become increasingly complex, these defects can significantly impact software performance and development, resulting in significant financial losses. Existing defect localization techniques based on information retrieval (IR) prioritize suspected defective files by correlating source code with defect reports and providing developers with defect remediation guidance.
[0003] This technology generates defect reports based on source files and uses the structured information in the defect reports for information retrieval, such as matching them with source files with or containing the same name to retrieve suspicious program entities. However, because natural language processing is used to process defect reports, they can be disrupted by noise data irrelevant to the defects in the defect reports. In particular, when a defect report contains multiple program activities from different threads, the large amount of suspected defect information expands the search scope, exploding the search space and making statement-level defect localization impossible. Therefore, it is necessary to design a software defect localization method based on contextual program reduction technology for statement-level defect localization. Summary of the Invention
[0004] The purpose of the present invention is to provide a software defect location method based on context program reduction technology to solve the problems raised in the above background technology.
[0005] In order to solve the above technical problems, the present invention provides the following technical solutions: a software defect location method based on contextual program reduction technology, which adopts a defect location system to work, and the system includes a suspicious program extraction module, a code entity processing module, and a defect location module. The suspicious program extraction module is used to generate a stack trace from the stack frame of the program activity and extract suspicious program entities therefrom. The code entity processing module is used to parse the suspicious program entities and rank the defect probabilities of potential defective code entities. The defect location module is used to locate the defective code entities.
[0006] According to the above technical solution, the suspicious program extraction module includes a stack frame generation module and a stack trace analysis module, wherein the stack frame generation module is electrically connected to the stack trace analysis module; the stack frame generation module is used to record the stack frame of the program when the system fails, and the stack trace analysis module is used to extract the suspicious program entity from the stack frame;
[0007] The code entity processing module includes a regular expression parsing module, a dependency analysis module, and a defect probability ranking module. The regular expression parsing module is electrically connected to the stack trace analysis module and the dependency analysis module, and the dependency analysis module is electrically connected to the defect probability ranking module. The regular expression parsing module is used to parse suspicious program entities, the dependency analysis module is used to analyze the dependencies of code entities in suspicious files, and the defect probability ranking module is used to rank the defect probabilities of potentially defective code entities.
[0008] The defect location module includes a defect detection module, a result output module, a priority adjustment module, and an entity splitting module. The defect detection module is electrically connected to the defect probability ranking module, the priority adjustment module is electrically connected to the result output module and the defect probability ranking module, and the result output module is electrically connected to the defect detection module; the defect detection module is used to detect defect codes, the result output module is used to output the detected defect codes and corresponding location information, the priority adjustment module is used to adjust the defect probability ranking during multiple detections, and the entity splitting module is used to split the code entity into multiple paragraphs.
[0009] According to the above technical solution, the following steps are included:
[0010] S1. Record program activities at the time of system failure and use the system-provided API to obtain the currently executed stack frame information. The stack frame records the order and location of function calls. Use the stack frame to create a stack trace and extract the suspicious program entity from it.
[0011] S2. Use regular expressions to parse the extracted suspicious program entities, divide the code entities in the suspicious program entities into function names, file names, and line numbers, and analyze the dependencies of the code entities in the suspicious files to infer potential defective code entities;
[0012] S3. Rank the defect probabilities of related code entities and adjust the coverage of defect identification statements to cover code entities with high defect probabilities and minimize the search space.
[0013] S4. Detect defective code entities, output the detected defective code entities and their corresponding location information, count the number of defects detected for each defective code entity, and adjust the defect probability of each code entity;
[0014] S5. Split the code entity according to the line number, name the line number interval where defects often occur as a new code entity, and make the new code entity participate in the defect probability ranking.
[0015] According to the above technical solution, in S1, the specific method of creating a stack trace is:
[0016] S1-1. Parse and format the stack frame data, extract the program entity name and layer number of each layer based on the stack frame information, and concatenate this information into a string in the calling order;
[0017] S1-2. When defining suspicious program entities, the definition conditions of suspicious program entities include the program where the function with abnormal number of calls in the code is located, the program where the called function has prompted errors in the error log, the program with highly complex functions with nested loops and multiple conditional branches, the program with recently modified code lines, and the program that depends on known defective modules. The suspicious degree value of each program entity is obtained based on the number of current program entities that meet the definition conditions. ,in The number of program entities in the stack trace, where program entities with a number greater than 0 that meet the defined conditions are defined as suspicious program entities.
[0018] According to the above technical solution, in S2, the specific method for analyzing the dependency relationship of code entities in the suspicious file is:
[0019] S2-1. Use the extracted file names to find the corresponding code entities. Dependencies include functions calling each other, functions using external function variables, data structure sharing between functions, and function attribute inheritance from parent classes. Use an AST parser to perform static code analysis when the code entity is not running, and use a debugger to perform dynamic tracking analysis when the code entity is running.
[0020] S2-2. Get the number of dependencies of each code entity in the program entity ,in The number of code entities in the current suspicious program entity is selected, and the code entities whose number of dependencies is greater than 0 are defined as potential defective code entities.
[0021] According to the above technical solution, in S3, the specific method is:
[0022] S3-1. Ranking of defect probabilities: Calculate the defect probabilities of all potentially defective code entities in each suspicious program entity. The higher the suspicious degree value of the program entity where the code entity is located and the higher the number of dependencies of the code entity, the greater the defect probability, the higher the defect probability ranking, and the higher the detection priority of this code entity. The specific calculation formula is: Defect probability ,in is the weight coefficient of the suspicious degree value of the program entity, is the weight coefficient of the number of dependencies of the code entity, is the serial number of the program entity where the current code entity is located, It is the serial number of the current code entity in the program entity;
[0023] S3-2. Adjust the coverage of identified defect statements: Before searching, adjust the coverage based on the average defect probability of all code entities in the program entity. The higher the average defect probability, the higher the coverage. The specific formula is: Coverage ,in is the coverage of the initial defect statement, is the average defect probability influence coefficient, and .
[0024] According to the above technical solution, in said S4, the specific method of adjusting the defect probability and detection priority is: each time a system failure occurs and a defect is located, the defect probability of each code entity is adjusted so that the currently detected Second test, The defect probability of the current code entity detected is , No. The number of defects detected in the current code entity during the inspection is , No. The number of defects detected in the current code entity during the inspection is If the number of code entities with low defect probability detected is large, the defect probability of the next detection will increase. If the number of code entity detections has an upward trend, the defect probability of the next detection will also increase. The defect probability of the current code entity in the next detection is ,in is the proportional coefficient of the number of detections to the original defect probability, It is the weight coefficient of the detection quantity change trend. The higher the defect probability, the higher the detection priority. The code entity can be tested at the front in the next test, and the defect can be detected quickly with a higher probability. The code entity whose detection result is inconsistent with the theoretical defect probability calculation result can be adjusted to the appropriate detection priority more quickly. The code entity whose bug situation gradually worsens due to the accumulation of data during system operation can also be adjusted to the priority detection position more quickly.
[0025] According to the above technical solution, in S5, the specific method of splitting according to line number is: split the code entity into several paragraphs, recorded as ,in is the paragraph number, and the line number of the paragraph is recorded as , record the line numbers where defects appear in the code entity, determine which line number interval they fall into, and count the number of defects accumulated in each line number interval , when the number of defects accumulated in a certain paragraph exceeds the cumulative threshold When the code of the line number of this paragraph is redefined as a new code entity, if multiple adjacent paragraphs with line numbers exceed the cumulative threshold They are merged into one code entity, and the defect probability of the new code entity is calculated separately. When calculating the defect probability, the number of dependencies is converted according to the ratio of the line number interval of this paragraph to the line number interval of the entire code entity.
[0026] Compared with the prior art, the present invention has the following beneficial effects: first, the present invention records the stack frames of program activities when a system failure occurs to generate a stack trace, extracts suspicious program entities from the stack trace, uses regular expressions to parse the suspicious program entities, and analyzes the dependencies of code entities in the suspicious file to trace back potential defective code entities. The highly structured information in the stack trace can help identify code entities directly and indirectly related to the defect;
[0027] Secondly, the defect probabilities of related code entities are ranked. By adjusting the coverage of defect identification statements, as much code entities with high defect probabilities as possible are covered. As much defective code as possible is detected while minimizing the search space, thus achieving statement-level defect localization. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0029] Figure 1 It is a schematic diagram of the overall module structure of the present invention. DETAILED DESCRIPTION
[0030] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0031] See also Figure 1 The present invention provides a technical solution: a software defect location method based on contextual program reduction technology, the method adopts a defect location system to work, the system includes a suspicious program extraction module, a code entity processing module, and a defect location module, the suspicious program extraction module is used to generate a stack trace from the stack frame of program activity and extract suspicious program entities therein, the code entity processing module is used to parse the suspicious program entities and rank the defect probabilities of potential defective code entities, and the defect location module is used to locate the defective code entities;
[0032] The suspicious program extraction module includes a stack frame generation module and a stack trace analysis module, and the stack frame generation module is electrically connected to the stack trace analysis module; the stack frame generation module is used to record the stack frame of the program when the system fails, and the stack trace analysis module is used to extract the suspicious program entity from the stack frame;
[0033] The code entity processing module includes a regular expression parsing module, a dependency analysis module, and a defect probability ranking module. The regular expression parsing module is electrically connected to the stack trace analysis module and the dependency analysis module, and the dependency analysis module is electrically connected to the defect probability ranking module. The regular expression parsing module is used to parse suspicious program entities, the dependency analysis module is used to analyze the dependencies of code entities in suspicious files, and the defect probability ranking module is used to rank the defect probabilities of potentially defective code entities.
[0034] The defect location module includes a defect detection module, a result output module, a priority adjustment module, and an entity splitting module. The defect detection module is electrically connected to the defect probability ranking module, the priority adjustment module is electrically connected to the result output module and the defect probability ranking module, and the result output module is electrically connected to the defect detection module. The defect detection module is used to detect defect codes, the result output module is used to output the detected defect codes and corresponding location information, the priority adjustment module is used to adjust the defect probability ranking during multiple detections, and the entity splitting module is used to split the code entity into multiple paragraphs.
[0035] The following steps are involved:
[0036] S1. Record program activities at the time of system failure and use the system-provided API to obtain the currently executed stack frame information. The stack frame records the order and location of function calls. Use the stack frame to create a stack trace and extract the suspicious program entity from it.
[0037] S2. Use regular expressions to parse the extracted suspicious program entities, divide the code entities in the suspicious program entities into function names, file names, and line numbers, and analyze the dependencies of the code entities in the suspicious files to infer potential defective code entities;
[0038] S3. Rank the defect probabilities of related code entities and adjust the coverage of defect identification statements to cover code entities with high defect probabilities and minimize the search space.
[0039] S4. Detect defective code entities, output the detected defective code entities and their corresponding location information, count the number of defects detected for each defective code entity, and adjust the defect probability of each code entity;
[0040] S5. Split the code entity by line number, name the line number interval where defects frequently occur as a new code entity, and include the new code entity in the defect probability ranking;
[0041] In S1, the specific method for creating a stack trace is:
[0042] S1-1. Parse and format the stack frame data, extract the program entity name and layer number of each layer based on the stack frame information, and concatenate this information into a string in the calling order;
[0043] S1-2. When defining suspicious program entities, the definition conditions of suspicious program entities include the program where the function with abnormal number of calls in the code is located, the program where the called function has prompted errors in the error log, the program with highly complex functions with nested loops and multiple conditional branches, the program with recently modified code lines, and the program that depends on known defective modules. The suspicious degree value of each program entity is obtained based on the number of current program entities that meet the definition conditions. ,in The number of program entities in the stack trace, where the program entities with a number greater than 0 that meet the defined conditions are defined as suspicious program entities;
[0044] In S2, the specific method for analyzing the dependencies of code entities in suspicious files is as follows:
[0045] S2-1. Use the extracted file names to find the corresponding code entities. Dependencies include functions calling each other, functions using external function variables, data structure sharing between functions, and function attribute inheritance from parent classes. Use an AST parser to perform static code analysis when the code entity is not running, and use a debugger to perform dynamic tracking analysis when the code entity is running.
[0046] S2-2. Get the number of dependencies of each code entity in the program entity ,in The number of code entities in the current suspicious program entity is selected, and the code entities whose number of dependencies is greater than 0 are defined as potential defective code entities;
[0047] In S3, the specific method is:
[0048] S3-1. Ranking of defect probabilities: Calculate the defect probabilities of all potentially defective code entities in each suspicious program entity. The higher the suspicious degree value of the program entity where the code entity is located and the higher the number of dependencies of the code entity, the greater the defect probability, the higher the defect probability ranking, and the higher the detection priority of this code entity. The specific calculation formula is: Defect probability ,in is the weight coefficient of the suspicious degree value of the program entity, is the weight coefficient of the number of dependencies of the code entity, is the serial number of the program entity where the current code entity is located, It is the serial number of the current code entity in the program entity;
[0049] S3-2. Adjust the coverage of identified defect statements: Before searching, adjust the coverage based on the average defect probability of all code entities in the program entity. The higher the average defect probability, the higher the coverage. The specific formula is: Coverage ,in is the coverage of the initial defect statement, is the average defect probability influence coefficient, and ;
[0050] In S4, the specific method of adjusting the defect probability and detection priority is as follows: each time a system failure occurs and a defect is located, the defect probability of each code entity is adjusted so that the currently detected Second test, The defect probability of the current code entity detected is , No. The number of defects detected in the current code entity during the inspection is , No. The number of defects detected in the current code entity during the inspection is If the number of code entities with low defect probability detected is large, the defect probability of the next detection will increase. If the number of code entity detections has an upward trend, the defect probability of the next detection will also increase. The defect probability of the current code entity in the next detection is ,in is the proportional coefficient of the number of detections to the original defect probability, The weight coefficient for the detection quantity change trend is: the higher the defect probability, the higher the detection priority. This means that the code entity will be prioritized for the next inspection, with a higher probability of detecting defects quickly. Furthermore, code entities whose detection results do not match the theoretical defect probability calculation results can be adjusted to the appropriate detection priority more quickly. Furthermore, code entities whose bugs are gradually increasing and worsening as data accumulates during system operation can be adjusted to the priority detection position more quickly.
[0051] In S5, the specific method of splitting by line number is: split the code entity into several paragraphs, recorded as ,in is the paragraph number, and the line number of the paragraph is recorded as , record the line numbers where defects appear in the code entity, determine which line number interval they fall into, and count the number of defects accumulated in each line number interval , when the number of defects accumulated in a certain paragraph exceeds the cumulative threshold When the code of the line number of this paragraph is redefined as a new code entity, if multiple adjacent paragraphs with line numbers exceed the cumulative threshold They are merged into one code entity, and the defect probability of the new code entity is calculated separately. When calculating the defect probability, the number of dependencies is converted according to the ratio of the line number interval of this paragraph to the line number interval of the entire code entity.
[0052] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus.
[0053] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art will be able to modify the technical solutions described in the aforementioned embodiments or substitute equivalents for some of the technical features. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention shall be included within the scope of protection of the present invention.
Claims
1. A software defect localization method based on contextual program reduction technology, characterized by: The method operates using a defect localization system, which includes a suspicious program extraction module, a code entity processing module, and a defect localization module. The suspicious program extraction module is used to generate a stack trace from the stack frames of program activities and extract suspicious program entities therefrom. The code entity processing module is used to parse the suspicious program entities and rank the defect probabilities of potential defective code entities. The defect localization module is used to locate the defective code entities. The following steps are involved: S1. Record program activities at the time of system failure and use the system-provided API to obtain the currently executed stack frame information. The stack frame records the order and location of function calls. Use the stack frame to create a stack trace and extract the suspicious program entity from it. S2. Use regular expressions to parse the extracted suspicious program entities, divide the code entities in the suspicious program entities into function names, file names, and line numbers, and analyze the dependencies of the code entities in the suspicious files to infer potential defective code entities; S3. Rank the defect probabilities of related code entities and adjust the coverage of defect identification statements to cover code entities with high defect probabilities and minimize the search space. S4. Detect defective code entities, output the detected defective code entities and their corresponding location information, count the number of defects detected for each defective code entity, and adjust the defect probability of each code entity; S5. Split the code entity according to the line number, name the line number interval where defects often occur as a new code entity, and make the new code entity participate in the defect probability ranking.
2. The software defect location method based on contextual program reduction technology according to claim 1, characterized in that: The suspicious program extraction module includes a stack frame generation module and a stack trace analysis module, wherein the stack frame generation module is electrically connected to the stack trace analysis module; the stack frame generation module is used to record the stack frame of the program when the system fails, and the stack trace analysis module is used to extract the suspicious program entity from the stack frame; The code entity processing module includes a regular expression parsing module, a dependency analysis module, and a defect probability ranking module. The regular expression parsing module is electrically connected to the stack trace analysis module and the dependency analysis module, and the dependency analysis module is electrically connected to the defect probability ranking module. The regular expression parsing module is used to parse suspicious program entities, the dependency analysis module is used to analyze the dependencies of code entities in suspicious files, and the defect probability ranking module is used to rank the defect probabilities of potentially defective code entities. The defect location module includes a defect detection module, a result output module, a priority adjustment module and an entity splitting module. The defect detection module is electrically connected to the defect probability ranking module, the priority adjustment module is electrically connected to the result output module and the defect probability ranking module, and the result output module is electrically connected to the defect detection module; the defect detection module is used to detect defect codes, the result output module is used to output the detected defect codes and corresponding location information, the priority adjustment module is used to adjust the defect probability ranking during multiple detections, and the entity splitting module is used to split the code entity into multiple paragraphs.
3. The software defect location method based on contextual program reduction technology according to claim 2, characterized in that: In S1, the specific method of creating a stack trace is: S1-1. Parse and format the stack frame data, extract the program entity name and layer number of each layer based on the stack frame information, and concatenate this information into a string in the calling order; S1-2. When defining suspicious program entities, the definition conditions for suspicious program entities include the program where the function in the code is called an abnormal number of times, the program where the called function has prompted an error in the error log, the program with highly complex functions such as nested loops and multiple conditional branches, the program with recently modified code lines, and the program that depends on a known defective module. The suspicious degree value of each program entity is obtained based on the number of current program entities that meet the definition conditions. ,in The number of program entities in the stack trace, where program entities with a number greater than 0 that meet the defined conditions are defined as suspicious program entities.
4. The software defect location method based on contextual program reduction technology according to claim 3, characterized in that: In S2, the specific method for analyzing the dependency relationship of code entities in the suspicious file is: S2-1. Use the extracted file names to find the corresponding code entities. Dependencies include functions calling each other, functions using external function variables, data structure sharing between functions, and function attribute inheritance from parent classes. Use an AST parser to perform static code analysis when the code entity is not running, and use a debugger to perform dynamic tracking analysis when the code entity is running. S2-2. Get the number of dependencies of each code entity in the program entity ,in The number of code entities in the current suspicious program entity is selected, and the code entities whose number of dependencies is greater than 0 are defined as potential defective code entities.
5. The software defect location method based on contextual program reduction technology according to claim 4, characterized in that: In the S3, the specific method is: S3-1. Calculate the defect probability for all potentially defective code entities in each suspicious program entity. The higher the suspicious degree value of the program entity where the code entity is located, the greater the defect probability. The specific calculation formula is: Defect probability ,in is the weight coefficient of the suspicious degree value of the program entity, is the weight coefficient of the number of dependencies of the code entity, is the serial number of the program entity where the current code entity is located, It is the serial number of the current code entity in the program entity; S3-2. Before searching, adjust the coverage rate based on the average defect probability of all code entities in the program entity. The higher the average defect probability, the higher the coverage rate. The specific formula is: Coverage rate ,in is the coverage of the initial defect statement, is the average defect probability influence coefficient, .
6. The software defect location method based on contextual program reduction technology according to claim 5, characterized in that: In said S4, the specific method of adjusting the defect probability and detection priority is: each time a system failure occurs and a defect is located, the defect probability of each code entity is adjusted so that the currently detected Second test, The defect probability of the current code entity detected is , No. The number of defects detected in the current code entity during the inspection is , No. The number of defects detected in the current code entity during the inspection is , then the defect probability of the current code entity in the next detection ,in is the proportional coefficient of the number of detections to the original defect probability, is the weight coefficient of the detection quantity change trend.
7. The software defect location method based on contextual program reduction technology according to claim 6, characterized in that: In the above S5, the specific method of splitting by line number is: split the code entity into several paragraphs, recorded as ,in is the paragraph number, and the line number of the paragraph is recorded as , record the line numbers where defects appear in the code entity, determine which line number interval they fall into, and count the number of defects accumulated in each line number interval , when the number of defects accumulated in a certain paragraph exceeds the cumulative threshold When the code of the line number of this paragraph is redefined as a new code entity, the defect probability is calculated separately for the new code entity.
Citation Information
Patent Citations
Defect detection method for code covering device based on debugging information support
CN115422082A
Software defect positioning method based on feature crossing and structural semantic information matching
CN117851216A