A precise error localization method for student programs
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-14
- Publication Date
- 2026-08-14
AI Technical Summary
然而,这样的修复方式往往伴随着冗余修复,修复的质量不高
[0049]本方法使用静态分析技术为将两个具有相似功能的程序建立程序间代码块的1-1匹配,并基于此利用动态分析技术来构建程序代码块的规约,同时结合依赖分析技术构建程序代码块的上下文信息,进一步设计对代码块的可疑性度量,最后从粗粒度到细粒度地进行代码块可疑性判断,实现精准错误定位。从而改进现有的反馈生成技术,通过减少冗余修复的方式提高修复的质量。
Smart Images

Figure CN116701219B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of automatic error location technology combining dynamic and static methods, and in particular to a precise error location method for student programs. Background Technology
[0002] Automatic error localization technology detects anomalies in programs through static or dynamic analysis, isolating them as suspicious code requiring further debugging. This narrows down the search for defective code, helping developers identify flawed statements more quickly and analyze the causes of program failures. How to automate program debugging and more effectively ensure program reliability has received widespread attention. Static analysis refers to the theory and technique of analyzing program behavior without executing the program. Dynamic analysis refers to the theory and technique of obtaining runtime attributes of a program by collecting and analyzing runtime information. Static analysis relying solely on source code analysis is often insufficient for accurate program defect localization; therefore, a combined static and dynamic approach is widely used.
[0003] Automated feedback generation (AFGG) techniques aim to provide precise repair guidance for faulty student programs, helping students better understand and fix their programs. Recent AFGG techniques such as Clara, Sarfgen, and Refactory have demonstrated significant advantages in repairing student programs. These techniques search for a structurally similar correct program as a reference for the faulty student program, then employ a "block-to-block" repair strategy. This involves replacing expressions in the corresponding blocks of the reference program with those in the corrected program to generate repairs for each basic block of the faulty program, ultimately achieving program repair. However, this repair method often involves redundant repairs, resulting in low-quality fixes. To generate minimal repairs, Sarfgen attempts to find the minimum set of repair modifications from the set of modification changes; however, the search space for this subset is large, incurring significant overhead. Refactory introduces a coarse error localization method to reduce repairs by constructing reductions for each basic block, only repairing those that do not meet expectations. However, they assign the same suspicion level to program variables and do not consider contextual information, resulting in a high false positive rate. To address this deficiency, we implemented a precise error localization method that ranges from coarse-grained to fine-grained. This method constructs a table of suspicious variables, assigning different levels of suspicion to program variables. Furthermore, by performing data dependency and control dependency analysis on program code blocks to build contextual information, we further designed a suspiciousness metric for these blocks, reducing the false positive rate and achieving precise error localization. Summary of the Invention
[0004] To address the problems existing in the prior art, this invention provides a precise error localization method for student programs. This method uses static analysis to establish a 1-1 matching of code blocks between two programs with similar functions. Based on this, dynamic analysis is used to construct the specification of the program code blocks. Simultaneously, dependency analysis is combined to construct the context information of the program code blocks. Furthermore, a suspiciousness metric for the code blocks is designed. Finally, suspiciousness judgment of code blocks is performed from coarse-grained to fine-grained, achieving precise error localization. This improves existing feedback generation techniques and enhances the quality of repair by reducing redundant repairs. This invention is achieved through the following technical solutions.
[0005] A precise error localization method for student programs, characterized by the following steps:
[0006] Step 1) Input an error program, a correct reference program, and a set of test cases as input to the method. The error program is named Error Program P. b The reference program is named Correct Program P. c The test cases are named as test case set T = {t1, t2, ..., t}. n};
[0007] Step 2) Design a program block partitioning standard, and divide the erroneous program P into blocks. b Correct procedure P c The code is divided into blocks, and the program code blocks are aligned.
[0008] Step 3) Design a program variable alignment method to complete the error program P. b and the correct procedure P c Variable alignment;
[0009] Step 4) Given a test case t i Run the program under test and design a method for constructing the program code block specification;
[0010] Step 5) Perform data dependency and control dependency analysis on the code block and design a suspiciousness metric for the code block;
[0011] Step 6) Locate the error in the program from coarse-grained to fine-grained to obtain the suspicious code block.
[0012] The above-described method for accurate error localization in student-oriented programs is characterized in that the error program P input in step 1) b Correct procedure P c The test case set T needs to meet the following requirements:
[0013] Error program P b With correct procedure P cThe control structure remains consistent; wherein, the error program P b The correct program P cannot pass all test cases in the test case set T. c You can use all the test cases in the test case set T.
[0014] The above-mentioned precise error localization method for student programs is characterized in that the specific design process of step 2) designing the program block partitioning standard includes the following steps:
[0015] Step 21) specifies that a program code block consists of a control flow statement block and a basic block;
[0016] Step 22) defines a basic block as a sequence of statements executed sequentially, containing zero or more statements;
[0017] Step 23) Defines the control flow statement block as a group of compound statements, consisting of conditional statements and loop statements;
[0018] Step 24) specifies the process of dividing program block B as follows: if there are no control flow statements in the program block, then the program block is a basic block and the division ends; otherwise, the first control flow statement block CSB of the program block is found. CSB divides the program block into subroutine block B1, control flow statement block CSB, and subroutine block B2. Then, subroutine block B1 and subroutine block B2 are divided into program blocks respectively. Finally, control flow statement block CSB is divided into control flow statement blocks.
[0019] Step 25) specifies that the process of dividing control flow statement blocks is mainly divided into two types: (1) Branch control flow statement block division, the If statement is divided into If condition and Then statement blocks, where the If condition cannot be further divided, and the Then statement block is the Then branch of If, as a program block execution program block division, if the If statement has an Else branch, then the Else statement block is similar to the Then statement block and will be executed program block division; (2) Loop control flow statement block division, the While statement is divided into While condition and While execution statement blocks, where the While condition cannot be further divided, and the Then statement block is the Then branch of If, as a program block execution program block division, if the If statement has an Else branch, then the Else statement block is similar to the Then statement block and will be executed program block division; The While condition cannot be further divided, and the execution statement block is executed as a program block. The For statement is divided into For initialization, For condition, For update, and For execution statement block. Among them, For initialization, For condition, and For update cannot be further divided, and the For execution statement block is executed as a program block. The ForEach statement is divided into ForEach iteration and ForEach execution statement block. Among them, ForEach iteration cannot be further divided, and the ForEach execution statement block is executed as a program block.
[0020] Step 26) Remove the faulty program P b The code is used as input for step 3) to complete the program division, and the correct program P is divided. c The code is used as input for step 3) to complete the program division;
[0021] Step 27) Complete the alignment of the program code blocks, error program P b and the correct procedure P c Having the same program partitioning process, the erroneous program P is constructed. b With the correct procedure P c One-to-one matching between program code blocks.
[0022] The aforementioned method for accurate error localization in student-oriented programs is characterized in that, in step 3), a program variable alignment method is designed to complete the error program P. b With correct procedure P c The specific implementation process of variable alignment includes the following steps:
[0023] Step 31) If the program has a return value, it is the error program P. b and the correct procedure P c Add a set of fictitious variables {r1, r2, ..., r n} to program variables, where r i This represents the variable returned by the i-th Return statement in the program;
[0024] Step 32) specifies This represents the u-th indivisible program block B containing program variable v. u The weights, the This represents the variable v in block B. u The usage of this term;
[0025] Step 33) specifies f u (v b ,v c ) represents the variable v b In B ub The usage of the variable v c In B uc The degree of similarity in the situations in which the variable v is used, where the variable v is used. b It is an error program P b The variable in the text, variable v c It is the correct procedure P c The variable in B ub With B uc These represent the erroneous program P. b With correct procedure P c The u-th indivisible program block;
[0026] Step 34) specifies Sim(v) b ,v c ) indicates an error in program P b With correct procedure P c Any pair of variables <v b ,v c Similarity; v b With v c The formula for calculating the similarity is:
[0027] Step 35) Complete program variable matching; in order to reduce erroneous matching, variable matching is performed in rounds, and the matching criteria are relaxed step by step. In the first round, variable pairs with a similarity of 1.0 are added to the variable matching; in the next 4 rounds, variable pairs with lower similarity are added to the variable matching.
[0028] The aforementioned method for precise error localization in student-oriented programs is characterized in that, in step 4), a certain test case t is given. i Run the program under test and provide the specific implementation process of the program code block specification construction method, including the following steps:
[0029] Step 41) Given test case t i Run the erroneous program P respectively b and the correct procedure P c By building a debugger and setting breakpoints, the sequence of changes in the values of all variables in the two programs can be collected during runtime;
[0030] Step 42) Define the specification Spec(B,P) of program code block B of program P as a set of input and output values { i O i >} i=1,2,…s I i and O i These represent the values of the i-th variable in the program before and after the execution of code block B, respectively.
[0031] Step 43) specifies that the method for constructing a program code block is to extract the values before and after running the program code block from the sequence of changes in the values of all variables, and to form the specification of the program code block.
[0032] The aforementioned method for accurate error localization in student programs is characterized in that, in step 5), the specific design process for performing data dependency and control dependency analysis on code blocks and designing a suspiciousness metric for the code blocks includes the following steps:
[0033] Step 51) specifies that the code block has three states: not suspicious, suspicious, and cannot be determined to be suspicious;
[0034] Step 52) Defines the list of suspicious variables for the erroneous program as a set of suspicious variables;
[0035] Step 53) Defines the suspected correct variable table as a set of variables in the correct program. The suspected correct variables are defined in the correct program and affect the changes in the values of important variables in the correct program, but are not in the variable matching.
[0036] Step 54) Construct error program P b code block B b Specification (B) b ,P b ), and the correct procedure P c code block B c Specification (B) c ,P c ), where B c It is code block B b The matched code block;
[0037] Step 55) Construct code block B b The variable dependencies for code block B b Perform data dependency analysis and control dependency analysis to construct the dependencies between the variables involved, and simultaneously construct code block B. c Variable dependencies;
[0038] Step 56) Construct the set of erroneous variables E; iterate through the variables in the suspected variable table, let the variable be v. b The variable in the correct program that it matches is v. c From code block B b Specification (B) b ,P b Extracting variable v from ) b Input / output pairs b O b >, from code block B c Specification (B) c ,P c Extracting variable v from ) c Input / output pairs c O c >, if I b ≠I c Step 5) ends, and the code block is determined to be undetermined as suspicious; if I b =I c And O b ≠O c Then add variable v b Add it to the error variable set E;
[0039] Step 57) Update the suspicious variable table; iterate through the erroneous variable set E, and for any variable v in it... b If it is in code block B b The input value I of any variable s that the input depends on. s If the expected result is not met, it will be added to the list of suspicious variables;
[0040] Step 58) Update the table of suspected correct variables, iterate through the set of erroneous variables E, and for any variable v in it... b The variable v it matches c In code block B c The set of variables that Rely (v) depends on c In block B, any unmatched variable q, if it is in code block B c If the input value does not meet expectations, it will be added to the list of suspected correct variables.
[0041] Step 59) Determine code block B b The state; if the suspicious variable table or the suspicious correct variable table has been updated, then the decision code block B is determined. b The status is "unable to determine whether it is suspicious"; otherwise, if the error set variable is empty, then the code block B is checked. b The status is deemed unsuspecting; otherwise, code block B is judged. b The status is suspicious.
[0042] The aforementioned method for precise error localization in student programs is characterized by the following steps in step 6): The specific implementation process of performing error localization from coarse-grained to fine-grained to obtain suspicious basic blocks includes:
[0043] Step 61) Complete the initialization of the suspicious variable table. If P b For non-void functions, the table of suspected variables is initialized to {r1, r2, ..., r...} n}; If P b For void functions, the list of suspicious variables is initialized to the set of parameter variables;
[0044] Step 62) Complete the initialization of the suspected correct variable table, and initialize the suspected correct variable table as an empty set;
[0045] Step 63) specifies the process of error localization from coarse-grained to fine-grained as follows: given a set of dynamically executed code block paths {B1, B2…B…} n}, sequentially scan the program code blocks within it, let's call them B i As input to step 5), B is obtained. i The suspicious state of B, if B i If the status is "not suspicious," then proceed to the next code block; if B iIf the status is "unable to determine whether it is suspicious," then backtrack and re-evaluate the previous code block B. i-1 The suspicious state of B; if B i The status is suspicious, if B i If the block is a basic block or other indivisible block of statements, then step 63) ends, B i This is the output of our method; otherwise, execute step 64) to obtain B. i The path of the dynamically executed code block is used as input for step 63) to complete further error localization;
[0046] Step 64) The dynamic execution path of the control flow statement block is defined as follows: (1) The dynamic execution path of the If statement block is {If condition, Then statement block} if the If condition of the If statement block is true, then its dynamic execution path is {If condition, Then statement block}, otherwise, it is {If condition} or {If condition, Else statement block}; (2) The dynamic execution path of the While statement block is {While condition, While execution statement block, While condition, While execution statement block…}; (3) The dynamic execution path of the For statement block is {For initialization, For comparison, For execution statement block, For update, For comparison, For execution statement block, For update, For comparison…}; (4) The dynamic execution path of the ForEach statement block is {ForEach iteration, ForEach execution statement block, ForEach iteration, ForEach execution statement block…};
[0047] Step 65) Complete the error localization process from coarse-grained to fine-grained; Error program P b A set of sequentially executed basic blocks and control flow statement blocks are used as input to step 63) to obtain a suspicious basic block.
[0048] The present invention adopts the above technical solution and has the following beneficial effects:
[0049] This method uses static analysis to establish a 1-1 match between code blocks of two programs with similar functions. Based on this, it uses dynamic analysis to construct the specification of the program code blocks. Simultaneously, it combines dependency analysis to construct the context information of the program code blocks, further designs a suspiciousness metric for the code blocks, and finally performs suspiciousness judgment on the code blocks from coarse to fine granular, achieving accurate error location. This improves existing feedback generation techniques and enhances the quality of error repair by reducing redundant repairs. Attached Figure Description
[0050] Figure 1 This is a flowchart illustrating the precise error localization method for student programs according to an embodiment of the present invention.
[0051] Figure 2This is a schematic diagram illustrating the incorrect and correct program inputs in an embodiment of the present invention.
[0052] Figure 3 This is a schematic diagram illustrating the division between erroneous and correct programs in an embodiment of the present invention.
[0053] Figure 4 This is a schematic diagram illustrating the construction of a code block specification in the erroneous program and the correct program according to an embodiment of the present invention.
[0054] Figure 5 This is a flowchart illustrating the suspiciousness measurement of program code blocks in an embodiment of the present invention.
[0055] Figure 6 This is a schematic diagram illustrating the process from coarse-grained to fine-grained to precise error localization in an embodiment of the present invention. Detailed Implementation
[0056] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0057] The aim of this method is to provide a precise error localization approach for student programs. It uses static analysis techniques to establish a 1-1 matching of code blocks between two programs with similar functions. Based on this, dynamic analysis techniques are used to construct the specifications of the program code blocks. Simultaneously, dependency analysis techniques are combined to construct the context information of the program code blocks. Furthermore, a suspiciousness metric for code blocks is designed. Finally, suspiciousness judgment of code blocks is performed from coarse-grained to fine-grained to achieve precise error localization. This improves existing feedback generation techniques by reducing redundant repairs and enhancing the quality of the repair process. Figure 1 As shown, Figure 1 This is a flowchart illustrating a precise error localization method for student programs according to an embodiment of the present invention. The method includes the following steps:
[0058] Step 1) Input an incorrect program, a correct reference program, and a set of test cases, and name them as the incorrect program P. b Correct procedure P c And the test case set T = {t1, t2, ..., t} n}, as input to the method.
[0059] Step 2) Design the program block partitioning criteria, and divide the erroneous program P into blocks. b Correct procedure P c The code is divided into blocks to complete the alignment of program code blocks.
[0060] Step 3) Design a program variable alignment method to complete the error program P. b With correct procedure P c Variable alignment.
[0061] Step 4) Given a test case t i Run the program under test and design a method for constructing the program code block specification.
[0062] Step 5) Perform data dependency and control dependency analysis on the code block and design a suspiciousness metric for the code block.
[0063] Step 6) Locate the error in the program from coarse-grained to fine-grained to obtain the suspicious code block.
[0064] The incorrect program, the correct program, and the set of test cases entered in step 1) must meet the following requirements:
[0065] The rules stipulate that erroneous and correct programs have the same control structure, where erroneous programs must fail all test cases, while correct programs must pass all test cases. For example... Figure 2 As shown, Figure 2 This is a schematic diagram illustrating the input of incorrect and correct programs in an embodiment of the present invention.
[0066] Figure 3 This is a schematic diagram illustrating the division between erroneous and correct programs in an embodiment of the present invention. Step 2) of designing the program division criteria specifically includes the following steps:
[0067] Step 21) specifies that the program code block consists of a control flow statement block and a basic block.
[0068] Step 22) specifies that a basic block is a sequence of statements executed sequentially, containing 0 or more statements.
[0069] Step 23) specifies that the control flow statement block is a group of compound statements, which are divided into conditional statements and loop statements.
[0070] Step 24) specifies the process of dividing program block B as follows: If there are no control flow statements in the program block, then the program block is a basic block, and the division ends. Otherwise, the first control flow statement block (CSB) of the program block is found. The CSB divides the program block into subroutine block B1, control flow statement block (CSB), and subroutine block B2. Subroutine block B1 and subroutine block B2 are then divided into program blocks separately. Finally, control flow statement block (CSB) is divided into control flow statement blocks.
[0071] Step 25) The process of dividing control flow statement blocks is mainly divided into two types: (1) the division of branch control flow statement blocks. The division of the If statement divides the If statement into the If condition and the Then statement block. The If condition cannot be further divided. The Then statement block is the Then branch of the If statement. The program block is executed as a program block. If the If statement has an Else branch, then the Else statement block is similar to the Then statement block and will be executed as a program block. (2) The division of loop control flow statement blocks: The While statement is divided into While condition and While execution statement blocks. The While condition cannot be further divided. The execution statement block is executed as a program block. The For statement is divided into For initialization, For condition, For update and For execution statement blocks. The For initialization, For condition and For update cannot be further divided. The For execution statement block is executed as a program block. The ForEach statement is divided into ForEach iteration and ForEach execution statement blocks. The ForEach iteration cannot be further divided. The ForEach execution statement block is executed as a program block.
[0072] Step 26) Remove the faulty program P b The code is used as input for step 3) to complete the program division, and the correct program P is divided. c The code is used as input for step 3) to complete the program division.
[0073] Step 27) completes the alignment of the program code block. From step 22), it can be deduced that the erroneous program P... b and the correct procedure P c Having the same program partitioning process, we can construct P. b With P c One-to-one matching between program code blocks.
[0074] Step 3) involves designing a program variable alignment method to complete the error program P. b With correct procedure P c Variable alignment. Its implementation process includes:
[0075] Step 31) If the program has a return value, it is the error program P. b and the correct procedure P c Add a set of fictitious variables {r1, r2, ..., r n} to program variables, where r i This represents the variable returned by the i-th Return statement in the program.
[0076] Step 32) specifies This represents the u-th indivisible program block B containing program variable v. u The weights, the This represents the variable v in block B. u The situations in which it is used.
[0077] Step 33) specifies f u (v b ,v c ) represents the variable v b In B ub The usage of the variable v c In B uc The degree of similarity in the use of v b It is P b The variable in, v c It is P c The variable in B ub With B uc These represent the erroneous program P. b With correct procedure P c The u-th indivisible program block.
[0078] Step 34) specifies Sim(v) b ,v c ) indicates an error in program P b With correct procedure P c Any pair of variables <v b ,v c Similarity to >. b With v c The formula for calculating the similarity is:
[0079] Step 35) Complete program variable matching. To reduce false matches, we will perform variable matching round by round, with the matching criteria gradually relaxed. In the first round, we will add variable pairs with a similarity of 1.0 to the variable matching. In the next four rounds, variable pairs with lower similarity will be added to the variable matching. We can obtain... Figure 2 Error program P in ) b With correct procedure P c The variable matching between them is:
[0080] Step 4) Given a test case t i Run the program under test and design a method for constructing the program code block specification. Figure 4 This is a schematic diagram illustrating the construction of a code block specification in both the erroneous and correct programs according to an embodiment of the present invention. The construction process is as follows:
[0081] Step 41) Given test case ti Run the erroneous program P respectively b With correct procedure P c By building a debugger and setting breakpoints, the sequence of changes in the values of all variables in the two programs is collected during runtime.
[0082] Step 42) Define the specification Spec(B,P) of program code block B of program P as a set of input and output values { i O i >} i=1,2,…s I i With O i These represent the values of the i-th variable in the program before and after the execution of code block B.
[0083] Step 43) specifies that the method for constructing a program code block is to extract the values before and after running the program code block from the sequence of changes in the values of all variables, and to form the specification of the program code block.
[0084] Figure 5 This is a flowchart illustrating the suspiciousness measurement of program code blocks according to an embodiment of the present invention, specifically including the following steps:
[0085] Step 51) specifies that the code block has three states: not suspicious, suspicious, and cannot be determined to be suspicious.
[0086] Step 52) Define the suspicious variable table of the erroneous program as a set of suspicious variables. We call variables that may cause program errors suspicious variables. We are more concerned with the changes in the values of variables in the suspicious variable table.
[0087] Step 53) defines the suspected correct variable table as a set of variables in the correct program. The suspected correct variables are defined in the correct program and affect the changes in the values of important variables in the correct program, but are not in the variable matching.
[0088] Step 54) Construct error program P b In the code block B b Specification (B) b ,P b ), and the correct procedure P c code block B c Specification (B) c ,P c ), where B c For code block B b The matched code block.
[0089] Step 55) Construct code block B b The variable dependencies for code block B b Perform data dependency analysis and control dependency analysis to establish the dependencies between the variables involved. Simultaneously, construct code block B. c Variable dependencies.
[0090] Step 56) Construct the set of erroneous variables E. Iterate through the variables in the suspected variable table, let the variable be v. b The variable in the correct program that it matches is v. c From code block B b Specification (B) b ,P b Extracting variable v from ) b Input / output pairs b O b >, from code block B c Specification (B) c ,P c Extracting variable v from ) c Input / output pairs c O c >. If I b ≠I c Step 5) ends, and the code block is determined to be undetermined as suspicious. If I b =I c And O b ≠O c Then add variable v b Add it to the set of error variables E.
[0091] Step 57) Update the suspicious variable table. Iterate through the set of erroneous variables E, and for any variable v in it... b If it is in code block B b The input value I of any variable s that the input depends on. s If the expected result is not met, it will be added to the list of suspicious variables.
[0092] Step 58) Update the table of suspected correct variables, iterate through the set of erroneous variables E, and for any variable v in it... b The variable v it matches c In code block B c The set of variables that Rely (v) depends on c In block B, any unmatched variable q, if it is in code block B c If the input value does not meet expectations, it will be added to the list of suspected correct variables.
[0093] Step 59) Determine code block B b The state. If the suspicious variable table or the suspicious correct variable table has been updated, then the decision code block B is executed. b The status is "unable to determine whether it is suspicious." Otherwise, if the error set variable is empty, then the code block B is checked.b The status is deemed unsuspecting. Otherwise, code block B is judged to be... b The status is suspicious.
[0094] Figure 6 This is a schematic diagram illustrating the process of error localization from coarse-grained to fine-grained to precise error localization in an embodiment of the present invention. The implementation process includes:
[0095] Step 61) Complete the initialization of the suspicious variable table. If P b For non-void functions, the table of suspected variables is initialized to {r1, r2, ..., r...} n}; If P b For void functions, the list of suspicious variables is initialized as a set of parameter variables.
[0096] Step 62) Initialize the suspicious correct variable table, and initialize the suspicious correct variable table as an empty set.
[0097] Step 63) specifies the process of error localization from coarse-grained to fine-grained as follows: given a set of dynamically executed code block paths {B1, B2…B…} n}, sequentially scan the program code blocks during the period, let's call them B i As input to step 5), we obtain B. i The suspicious state of B, if B i If B is deemed not suspicious, proceed to the next code block; if B i If it is undecidable, then backtrack and re-evaluate the previous code block B. i-1 The suspicious state of B; if B i It is suspicious if B i If the block is a basic block or other indivisible block of statements, then step 63) ends, B i This is the output of our method. Otherwise, proceed to step 64) to obtain B. i The path of the dynamically executed code block is used as input for step 63) to complete further error localization.
[0098] Step 64) specifies the dynamic execution path of the control flow statement block as follows: (1) The dynamic execution path of the If statement block is {If condition, Then statement block} if the If condition of the If statement block is true, then its dynamic execution path is {If condition, Then statement block}, otherwise, it is {If condition} or {If condition, Else statement block}. (2) The dynamic execution path of the While statement block is {While condition, While execution statement block, While condition, While execution statement block…}. (3) The dynamic execution path of the For statement block is {For initialization, For comparison, For execution statement block, For update, For comparison, For execution statement block, For update, For comparison…}. (4) The dynamic execution path of the ForEach statement block is {ForEach iteration, ForEach execution statement block, ForEach iteration, ForEach execution statement block…}.
[0099] Step 65) Completes the error localization process from coarse-grained to fine-grained. Error procedure P b A set of sequentially executed basic blocks and control flow statement blocks are used as input to step 63) to obtain the suspected basic blocks. For example... Figure 6 As shown, error program P b Given the block {basic block, While control flow block, basic block, If control flow block, basic block}, we first perform coarse-grained location analysis. This identifies the While control flow block as a suspicious code block, as it can be further subdivided. We obtain the dynamic execution path of the While control flow block as {While condition, While execution code block, While condition, While execution code block…}. Continuing with error location analysis, we ultimately identify the While condition as a suspicious code block, which is the method's output.
[0100] 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 precise error localization method for student programs, characterized in that, Includes the following steps: Step 1) Input an error program, a correct reference program, and a set of test cases as input to the method. The error program is named Error Program P. b The reference program is named Correct Program P. c The test cases are named as test case set T = {t1, t2, ..., t}. n }; Step 2) Design a program block partitioning standard, and divide the erroneous program P into blocks. b Correct procedure P c The code is divided into blocks, and the program code blocks are aligned. Step 3) Design a program variable alignment method to complete the error program P. b and the correct procedure P c Variable alignment; Step 4) Given a test case t i Run the program under test and design a method for constructing the program code block specification; Step 5) Perform data dependency and control dependency analysis on the code block and design a suspiciousness metric for the code block; Specifically, the following steps are included: Step 51) specifies that the code block has three states: not suspicious, suspicious, and cannot be determined to be suspicious; Step 52) Defines the list of suspicious variables for the erroneous program as a set of suspicious variables; Step 53) Defines the suspected correct variable table as a set of variables in the correct program. The suspected correct variables are defined in the correct program and affect the changes in the values of important variables in the correct program, but are not in the variable matching. Step 54) Construct error program P b code block B b Specification (B) b ,P b ), and the correct procedure P c code block B c Specification (B) c ,P c ), where B c It is code block B b The matched code block; Step 55) Construct code block B b The variable dependencies for code block B b Perform data dependency analysis and control dependency analysis to construct the dependencies between the variables involved, and simultaneously construct code block B. c Variable dependencies; Step 56) Construct the set of erroneous variables E; iterate through the variables in the suspected variable table, let the variable be v. b The variable in the correct program that it matches is v. c From code block B b Specification (B) b ,P b Extracting variable v from ) b Input / output pairs b O b > From code block B c Specification (B) c ,P c Extracting variable v from ) c Input / output pairs c O c >, if I b ≠I c Step 5) ends, and the code block is determined to be undetermined as suspicious; if I b =I c And O b ≠O c Then add variable v b Add it to the error variable set E; Step 57) Update the suspicious variable table; iterate through the erroneous variable set E, and for any variable v in it... b If it is in code block B b The input value I of any variable s that the input depends on. s If the expected result is not met, it will be added to the list of suspicious variables; Step 58) Update the table of suspected correct variables, iterate through the set of erroneous variables E, and for any variable v in it... b The variable v it matches c In code block B c The set of variables that Rely (v) depends on c In block B, any unmatched variable q, if it is in code block B c If the input value does not meet expectations, it will be added to the list of suspected correct variables. Step 59) Determine code block B b The state; if the suspicious variable table or the suspicious correct variable table has been updated, then the decision code block B is determined. b The status is "unable to determine whether it is suspicious"; otherwise, if the error set variable is empty, then the code block B is checked. b The status is deemed unsuspecting; otherwise, code block B is judged. b The status is suspicious; Step 6) Locate errors in the program from coarse-grained to fine-grained to identify suspicious code blocks; the specific implementation process includes the following steps: Step 61) Complete the initialization of the suspicious variable table. If P b For non-void functions, the list of suspected variables is initialized to {r1, r2, ..., r...} m }; If P b For void functions, the list of suspicious variables is initialized to the set of parameter variables; Step 62) Complete the initialization of the suspected correct variable table, and initialize the suspected correct variable table as an empty set; Step 63) specifies the process of error localization from coarse-grained to fine-grained as follows: given a set of dynamically executed code block paths {B1, B2, ..., B...} x }, sequentially scan the program code blocks within it, let's call them B i As input to step 5), B is obtained. i The suspicious state of B, if B i If the status is "not suspicious," then proceed to the next code block; if B i If the status is "unable to determine whether it is suspicious," then backtrack and re-evaluate the previous code block B. i-1 The suspicious state of B; if B i The status is suspicious, if B i If the block is a basic block or other indivisible block of statements, then step 63) ends, B i This is the output of our method; otherwise, execute step 64) to obtain B. i The path of the dynamically executed code block is used as input for step 63) to complete further error localization; Step 64) specifies the dynamic execution path of the control flow statement blocks as follows: the dynamic execution path of the If statement block, While statement block, For statement block, and ForEach statement block; Step 65) Complete the error localization process from coarse-grained to fine-grained; Error program P b A set of sequentially executed basic blocks and control flow statement blocks are used as input to step 63) to obtain a suspicious basic block.
2. The precise error localization method for student-oriented programs according to claim 1, characterized in that, The error program P entered in step 1) b Correct procedure P c The test case set T needs to meet the following requirements: Error program P b With correct procedure P c The control structure remains consistent; wherein, the error program P b The correct program P cannot pass all test cases in the test case set T. c You can use all the test cases in the test case set T.