Program reduction method based on program execution information
By introducing program execution information during program reduction, establishing the association between statements and states, and generating candidate reduction programs that satisfy the properties, the problem of insufficient utilization of dynamic semantic information in existing technologies is solved, and more efficient program reduction and understanding are achieved.
Patent Information
- Application Number
- CN202610743933.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-27
- Publication Date
- 2026-08-25
AI Technical Summary
Existing program reduction methods mainly rely on source code structure information, making it difficult to effectively utilize dynamic semantic information during program execution, which may result in candidate programs failing to maintain the behavior of the original program.
By acquiring program state information during program execution, establishing the association between program statements and states, generating candidate reduction programs, and using user-provided property determination methods for iterative reduction, the reduction results are ensured to meet the target properties.
It improves the effectiveness of program reduction, generating smaller, more understandable programs while maintaining the continuity and properties of program execution.
Smart Images

Figure CN122633236A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of software engineering and program analysis, and in particular to a program reduction method based on program execution information. Background Technology
[0002] Program reduction is a technique that automatically reduces the size of a program while preserving its given properties. It is widely used in program debugging, defect localization, and compiler testing. By removing parts of the program that are irrelevant to the properties of the target program, program reduction can generate smaller, more understandable programs, thereby helping developers quickly understand why the program satisfies the properties of the target program.
[0003] Existing program reduction methods primarily reduce programs at the source code level, by continuously removing statements, expressions, or syntactic structures, and then verifying the reduction results using user-defined program property judgment methods. These methods rely heavily on source code structure information and give little consideration to the dynamic semantic information generated during program execution. When parts of code are removed, the original state dependencies of the program may be disrupted, causing candidate programs to fail to maintain their original behavior. Therefore, how to utilize the dynamic information generated during program execution to guide program reduction has become an important problem that needs to be solved in the field of program analysis. Summary of the Invention
[0004] To address the problem that existing program reduction methods mainly rely on source code structure for reduction and are difficult to guide reduction using dynamic semantic information during program execution, this invention proposes a program reduction method based on program execution information. The aim is to use program state information generated during program execution to guide the reduction process, generating a smaller and more easily understood reduced program while ensuring that the properties of the user-given program remain unchanged.
[0005] The key technologies used in this invention include dynamic program analysis, program state acquisition, and program reduction. By acquiring program state information generated during program execution and establishing the correlation between program statements and program states, dynamic execution information is used to guide the program reduction process.
[0006] This invention discloses a program reduction method based on program execution information. First, execution-related units formed during program execution are obtained; then, candidate reduction programs are generated based on these execution-related units; next, the candidate programs are verified using a user-provided program property determination method; finally, the program size is continuously reduced through iteration.
[0007] To achieve the above-mentioned objectives, the present invention provides the following technical solution: a program reduction method based on program execution information, characterized in that the method includes the following steps: S1, call the program nature determination method provided by the user to execute the input program, and obtain the execution-related units formed during the program execution. Each execution-related unit includes a program statement and the corresponding program state after the program statement is executed. S2, generate multiple candidate reduction procedures based on the execution-related unit; S3, call the program property determination method provided by the user to determine the candidate reduced program, and select one of the candidate reduced programs that satisfy the program property as the current program; S4. Re-enter the current program into steps S1 to S3 for iteration until no smaller reduced program that satisfies the program properties can be found.
[0008] Furthermore, step S1 specifically includes the following steps: S11, call the user-provided program property determination method to execute the input program once or multiple times; S12, during program execution, records the executed program statements according to the actual execution order of the program; S13, obtain the program state corresponding to each program statement after execution, associate the program statement with the corresponding program state, and construct the execution-related unit; S14. The constructed multiple execution-related units are organized into an execution-related unit sequence according to the execution order of the program statements.
[0009] Its beneficial effects are: by establishing the association between program statements and program state, dynamic program execution information is introduced into the reduction process, so that the subsequent reduction process can not only utilize program structure information, but also program dynamic semantic information, thereby improving the effectiveness of program reduction.
[0010] Furthermore, the program state includes the memory contents during program execution.
[0011] Furthermore, step S2 specifically includes the following steps: S21, generate multiple candidate execution-related unit sub-sequences from the execution-related unit sequence; S22, For a sequence of execution-related units, extract the program statements corresponding to all execution-related units to form the basic framework of the candidate reduction program; S23, Based on the program state required for the execution of the candidate reduction program, construct additional program statements to restore the necessary program state; S24, Generate a candidate reduction program based on the reserved program statements and the additional program statements.
[0012] Its beneficial effect is that by retaining the program statements corresponding to the target execution unit and restoring the necessary program state required for program execution, the candidate reduction program can maintain the continuity of program execution after deleting some program execution processes, thereby improving the program reduction capability.
[0013] Furthermore, in step S23, the additional program statement is a program statement that assigns values to the necessary memory content in the target program state.
[0014] Furthermore, step S3 specifically includes the following steps: S31, Call the user-provided program property determination method to determine the multiple candidate reduction programs respectively; S32, Filter candidate reduction programs that satisfy the program properties; S33: Select the smallest program from the candidate reduction programs that satisfy the program properties as the current program.
[0015] Its beneficial effect is that it automatically filters candidate reduction programs that meet the program property requirements by using the program property determination method provided by the user, thereby ensuring that the reduction result always meets the target program property.
[0016] Furthermore, step S4 specifically includes the following steps: S41, determine whether step S3 has obtained a candidate reduction program that satisfies the program properties; S42, if a candidate reduction program that satisfies the program properties and further reduces the program size is obtained, then the candidate reduction program is re-entered into steps S1 to S3 to continue execution; S43. If no candidate reduction program is obtained that satisfies the program properties and further reduces the program size, the program reduction process is terminated.
[0017] Its beneficial effect is that by continuously reducing the program size through iteration, the program can continuously approach the minimum reduction result that satisfies the properties of the target program, thereby improving the quality of reduction.
[0018] This invention introduces an execution-related unit to associate program statements with their corresponding program states after execution, thereby enabling the use of dynamic semantic information of the program to guide the reduction process and improve the effectiveness of the reduction results. Attached Figure Description
[0019] Figure 1 This is a flowchart of a program reduction method based on program execution information according to an embodiment of the present invention. Detailed Implementation
[0020] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0021] This embodiment provides a program reduction method based on program execution information. The inputs are the program to be reduced and a user-provided program property determination method; the output is a reduced program that satisfies the target program properties. (See also...) Figure 1 The flowchart of the program reduction method based on program execution information in this embodiment includes the following steps: S1, the user-provided program nature determination method is invoked to execute the input program, and execution-related units formed during program execution are obtained. Each execution-related unit includes a program statement and the corresponding program state after the program statement is executed. Step S1 specifically includes the following steps: S11 calls the user-provided program property determination method to execute the input program once or multiple times. When the program property depends only on the result of a single program execution, the program is executed once and the execution information is recorded; when the program property depends on multiple execution results, the program is executed multiple times. For example, in a differential testing scenario, the same input can be executed on multiple compilation configurations or multiple program versions, thus obtaining multiple execution processes.
[0022] S12: During program execution, the executed program statements are recorded according to the actual execution order. Specifically, during program execution, the execution order information of each executed program statement is recorded. When the program has loop, recursion, or branching structures, the same program statement may generate multiple records at different execution locations; these records are then recorded separately for each corresponding execution location.
[0023] S13: Obtain the program state corresponding to the execution of the program statement, and associate the program statement with the program state to construct an execution-related unit. The program state includes the content in memory during program execution, including variable values, object content, pointer references to objects, heap objects, and other data used during program execution. After the execution of each program statement, obtain the current program state information, and associate the program statement with its corresponding program state after execution to form an execution-related unit.
[0024] S14: Organize multiple execution-related units into an execution-related unit sequence according to the actual execution order of the program. If multiple program execution results exist, further extract the common execution segments between the multiple execution processes. Specifically, for different execution-related unit sequences, traverse the program statements and their corresponding execution positions; if multiple execution processes contain the same program statements and have the same execution order, retain the execution-related unit; otherwise, delete the corresponding execution-related unit. Repeat the above process until no more common execution-related units can be added, thereby generating an execution-related unit sequence.
[0025] S2, generating candidate reduction procedures based on the execution of relevant units. Step S2 specifically includes the following steps: S21, generate multiple candidate execution-related unit sub-sequences from the execution-related unit sequence. In one embodiment, the execution-related unit sequence can be divided according to a preset division strategy.
[0026] S22, for a subsequence of execution-related units, extract the program statements corresponding to all execution-related units to form the basic framework of the candidate reduction program. Specifically, traverse the execution-related units in the candidate execution sequence, extract the corresponding program statements, and retain them in the execution order.
[0027] S23. Construct additional program statements based on the program state required for the execution of the candidate reduced program. Since some program statements have been deleted, the original program state dependencies of the candidate program may be disrupted; therefore, it is necessary to restore the program state required for program execution. Specifically, for each program statement in the candidate program: traverse its dependent program states; determine whether the dependent program states can be generated by the execution of the current candidate program; if they can be generated, use them directly; if they cannot be generated, construct additional restoration statements. The restoration statements are used to assign values to the necessary memory content required for the execution of the candidate program.
[0028] S24, combine the preserved program statements and the restored program statements to generate a candidate reduced program. Specifically, insert the restored program statements before the execution of the corresponding program statements, and reconstruct the candidate program according to the original execution order.
[0029] S3: The user-provided program property determination method is invoked to verify the candidate reduced programs, and one of the candidate reduced programs that satisfies the program properties is selected as the current program. Step S3 specifically includes the following steps: S31, Perform program property verification on multiple candidate reduction programs respectively.
[0030] S32, filter candidate reduction programs that satisfy the program properties.
[0031] S33. Select the smallest program from the candidate reduced programs that satisfy the program properties as the current program. The program size can be measured by indicators such as the number of program statements, the number of program characters, the number of program lexical units, or the program execution scale.
[0032] S4, re-enter the current program into steps S1 to S3 for iteration until no smaller reduced program satisfying the stated program property can be found. Step S4 specifically includes the following steps: S41, determine whether the current round of reduction has obtained a smaller candidate reduction procedure than the previous round.
[0033] S42. If there is a candidate reduction program that satisfies the program properties and has a further reduced size, then update the current program to the new candidate program and re-execute steps S1 to S3.
[0034] S43. If there is no candidate program that satisfies the program properties and whose size is further reduced, then terminate the reduction process and output the result.
[0035] Similarly, this invention also discloses a program reduction system based on program execution information, comprising: Call the execution module: Call the user-provided program nature determination method to execute the input program, and obtain the execution-related units formed during the program execution. Each execution-related unit includes a program statement and the corresponding program state after the program statement is executed; this module can implement the above step S1; Generation module: Generates multiple candidate reduction programs based on the execution-related unit; this module can implement the above step S2; Determination module: calls the user-provided program property determination method to determine the candidate reduced program, and selects one from the candidate reduced programs that satisfy the program property as the current program; this module can implement the above step S3; Iteration Module: The current program is re-inputted and iterated through the execution module, generation module, and judgment module until no smaller reduced program satisfying the stated program property can be found. This module can implement step S4 above.
[0036] The above description is merely a preferred embodiment of the present invention, but the specific embodiments described herein are only for explaining the present invention and are not intended to limit the present invention. Any simple modifications, equivalent changes, and alterations made by those skilled in the art to the above embodiments based on the technical essence of the present invention without departing from the principles and spirit of the present invention should be included within the protection scope of the present invention.
Claims
1. A program reduction method based on program execution information, characterized in that, The method includes the following steps: S1, call the program nature determination method provided by the user to execute the input program, and obtain the execution-related units formed during the program execution. Each execution-related unit includes a program statement and the corresponding program state after the program statement is executed. S2, generate multiple candidate reduction procedures based on the execution-related unit; S3, call the program property determination method provided by the user to determine the candidate reduced program, and select one of the candidate reduced programs that satisfy the program property as the current program; S4. Re-enter the current program into steps S1 to S3 for iteration until no smaller reduced program that satisfies the program properties can be found.
2. The program reduction method based on program execution information according to claim 1, characterized in that, Step S1 specifically includes the following steps: S11, call the user-provided program property determination method to execute the input program once or multiple times; S12, during program execution, records the executed program statements according to the actual execution order of the program; S13, obtain the program state corresponding to each program statement after execution, associate the program statement with the corresponding program state, and construct the execution-related unit; S14. The constructed multiple execution-related units are organized into an execution-related unit sequence according to the execution order of the program statements.
3. The program reduction method based on program execution information according to claim 2, characterized in that, The program state includes the memory contents at the time of program execution.
4. The program reduction method based on program execution information according to claim 1, characterized in that, Step S2 specifically includes the following steps: S21, generate multiple candidate execution-related unit sub-sequences from the execution-related unit sequence; S22, For a sequence of execution-related units, extract the program statements corresponding to all execution-related units to form the basic framework of the candidate reduction program; S23, Based on the program state required for the execution of each candidate reduction procedure, construct additional program statements to restore the necessary program state; S24, Generate a candidate reduction program based on the reserved program statements and the additional program statements.
5. The program reduction method based on program execution information according to claim 4, characterized in that, In step S23, the additional program statement is a program statement that assigns values to the necessary memory content required to execute the candidate reduction program in the target program state.
6. The program reduction method based on program execution information according to claim 1, characterized in that, Step S3 specifically includes the following steps: S31, Call the user-provided program property determination method to determine the multiple candidate reduction programs respectively; S32, Filter candidate reduction programs that satisfy the program properties; S33: Select the smallest program from the candidate reduction programs that satisfy the program properties as the current program.
7. The program reduction method based on program execution information according to claim 1, characterized in that, Step S4 specifically includes the following steps: S41, determine whether step S3 has obtained a candidate reduction program that satisfies the program properties; S42, if a candidate reduction program that satisfies the program properties and further reduces the program size is obtained, then the candidate reduction program is re-entered into steps S1 to S3 to continue execution; S43. If no candidate reduction program is obtained that satisfies the program properties and further reduces the program size, the program reduction process is terminated.
8. A program reduction system based on program execution information, characterized in that, include: Call the execution module: Call the user-provided program nature determination method to execute the input program, and obtain the execution-related units formed during the program execution. Each execution-related unit includes a program statement and the corresponding program state after the program statement is executed. Generation module: Generates multiple candidate reduction programs based on the execution-related unit; Judgment module: calls the user-provided program property judgment method to judge the candidate reduced program, and selects one of the candidate reduced programs that satisfy the program property as the current program; Iteration module: The current program is re-inputted and the execution module, generation module, and judgment module are called for iteration until no smaller reduced program that satisfies the program properties can be found.
9. A non-transitory computer-readable storage medium storing computer instructions thereon, characterized in that, When the computer instructions are executed by one or more processors, the one or more processors perform the program reduction method based on program execution information as described in any one of claims 1-7.