Automatic bug-fixing is the automatic repair of software bugs without the intervention of a human programmer. It is also commonly referred to as automatic patch generation, automatic bug repair, or automatic program repair. The typical goal of such techniques is to automatically generate correct patches to eliminate bugs in software programs without causing software regression.
Video Automatic bug fixing
Basic concept
At a high level, automatic bug-fixing techniques generate a patch for a program in two steps. The first step is patch generation, which analyzes the original program and produces one or more candidate patches with a variety of techniques such search-based program mutation, machine learning, and genetic programming. The second step is patch validation, which validates the produced candidate patches from the previous step with either a formal specification or a test suite of the program.
Generate-and-validate techniques
The generate-and-validate techniques are arguably the standard approach to generate repairs for a bug of a program. Such a technique typically starts with a test suite of the program, i.e., a set of test cases, at least one of which exposes the bug. The technique assumes that the bug can be fixed with a series of mutation operations on the source code of the program. It first uses fault localization techniques to identify suspicious statements in the program. It then applies the mutation operations to the identified statements to generate a space of candidate patches and searches this space to find validated patches that produce correct outputs for all cases in the test suite.
Generate-and-validate techniques for automatic bug-fixing are still in their infancy. Two earliest generate-and-validate bug-fixing systems are GenProg and ClearView. The effectiveness of generate-and-validate techniques remains controversial, because they typically do not provide patch correctness guarantees. Nevertheless, the reported results of recent state-of-the-art techniques are generally promising. For example, on systematically collected 69 real world bugs in eight large C software programs, the state-of-the-art bug-fixing system Prophet generates correct patches for 18 out of the 69 bugs.
Targeted techniques
Targeted automatic bug-fixing techniques generate repairs for specific classes of errors such as null pointer exception integer overflow , buffer overflow , memory leak , etc.. Such techniques often use empirical fix templates to fix bugs in the targeted scope. For example, insert a conditional statement to check whether the value of a variable is null or insert missing memory deallocation statements. Comparing to generate-and-validate techniques, targeted techniques tend to have better bug-fixing accuracy but a much narrowed scope.
Maps Automatic bug fixing
Patch generation
At the patch generation step, automatic bug-fixing techniques use one or more of the followings to generate a set of candidate patches.
Program mutation
One way to generate candidate patches is to apply mutation operators on the original program. Mutation operators manipulate the original program, potentially via its abstract syntax tree representation, or a more coarse-grained representation such as operating at the statement-level or block-level. Earlier genetic improvement approaches operate at the statement level and carry out simple delete/replace operations such as deleting an existing statement or replacing an existing statement with another statement in the same source file. Recent machine learning and solver approaches use more fine-grained operators at the abstract syntax tree level to generate more diverse set of candidate patches.
Fix template
Using fix templates is an alternative way to generate candidate patches. Fix templates are typically predefined program mutation rules for fixing specific classes of bugs. Examples of fix templates include inserting a conditional statement to check whether the value of a variable is null to fix null pointer exception, inserting memory deallocation statement to fix memory leaks, and changing an integer constant by one to fix off-by-one errors. Comparing to program mutation techniques, fix templates tend to achieve better candidate patches for bugs within its scope. Fix templates are therefore often adopted by targeted techniques.
Code learning and transfer
Machine learning techniques can improve the effectiveness of automatic bug-fixing systems. One example of such techniques learns from past successful patches from human developers collected from open source repositories in GitHub and SourceForge. It then use the learned information to recognize and prioritize potentially correct patches among all generated candidate patches. Alternatively, patches can be directly mined from existing sources. Example approaches include mining patches from donor applications or from QA web sites.
SMT Solver
Another way to generate candidate patches is to use solvers for satisfiability modulo theories (SMT). Solver-based techniques convert a program into SMT formulas. They then query SMT solvers to solve the converted SMT formulas to find candidate patches that allow the patched program to pass all supplied test cases. The benefit of this approach is that SMT solvers can quickly find patches passing test cases for small to medium-sized formulas. The limitation of this approach is that real world programs are often converted to intractably large formulas especially for modifying statements with side effects.
Patch validation
At the patch validation step, automatic bug-fixing techniques rely on either formal specifications or a test suite to validate generated candidate patches. Formal specifications specify the correct behavior of a program and are often only available for specific classes of errors in practice. Therefore, standard generate-and-validate techniques typically rely on the availability of a test suite.
Validation with a test suite
A test-suite - the input/output pairs specify the functionality of the program, possibly captured in assertions can be used as a test oracle to validate candidate patches. This oracle can in fact be divided between the bug oracle that exposes the faulty behavior, and the regression oracle, which encapsulates the functionality any program repair method must preserve. Generate-and-validate approaches use automated testing techniques to compile and test each candidate patch produced in the patch generation stop and collect all validated patches that produce expected outputs for all inputs in the test suite.
Note that a test suite is typically incomplete and does not cover all possible cases. Therefore, it is often possible for a validated patch to produce expected outputs for all inputs in the test suite but incorrect outputs for other inputs. The existence of such validated but incorrect patches is a major challenge for generate-and-validate techniques. Recent successful automatic bug-fixing techniques often rely on additional information other than the test suite, such as information learned from previous human patches, to further identify correct patches among validated patches.
Validation with formal specifications
Another way to validate candidate patch is to verify the patched program against formal specifications which specify the correct behavior of the program Verification against full specifications that specify the whole program behavior including functionalities is less common because such specifications are typically not available in practice and the computation cost of such verification is prohibitive. For specific classes of errors, however, implicit partial specifications are often available. For example, there are targeted bug-fixing techniques validating that the patched program can no longer trigger overflow errors in the same execution path.
Limitations of automatic bug-fixing
Automatic bug-fixing techniques that rely on a test suite do not provide patch correctness guarantees, because the test suite is incomplete and does not cover all cases. A weak test suite may cause generate-and-validate techniques to produce validated but incorrect patches that have negative effects such as eliminating desirable functionalities, causing memory leaks, and introducing security vulnerabilities. This weak test suite issue is alternatively called as "overfitting" of bug-fixing systems . For example, a recent study shows that for 52 out of 55 cases that the previous bug-fixing system GenProg reports to generate repairs, all of the generated patches are incorrect. Recent state-of-the-art systems with machine learning or SMT solver techniques are able to generate correct patches for much more cases on the same benchmark set, but there are still plenty of validated but incorrect patches generated by these systems.
Another limitation of generate-and-validate systems is the search space explosion. For a program, there are a large number of statements to change and for each statement there are a large number of possible modifications. State-of-the-art systems often explicitly or implicitly assume that a small modification is enough for fixing a bug. As a result, such systems can currently repair a small proportion of bugs in real world programs.
Example tools
Automatic bug-fixing is an active research topic in computer science. There are many implementations of various bug-fixing techniques especially for C and Java programs. Note that most of these implementations are research prototypes for demonstrating their techniques, i.e., it is unclear whether their current implementations are ready for industrial usage or not.
GenProg and ClearView are two earliest generate-and-validate bug-fixing tools published at 2009. The benchmark collected by GenProg authors contains 69 real world defects and it is widely used to evaluate many other bug-fixing tools in C as well. The state-of-the-art tool evaluated on GenProg benchmark is Prophet, generating correct patches for 18 out of 69 defects.
Tools for C
- ClearView: A generate-and-validate tool of generating binary patches for deployed systems. It is evaluated on 10 security vulnerability cases. A later study shows that it generates correct patches for at least 4 of the 10 cases.
- GenProg: A genetic improvement generate-and-validate bug-fixing tool. It
is evaluated on 105 cases and reported to generate repairs for 55 cases. A later study shows that only 69 cases out of the 105 evaluated cases correspond to bugs and correct patches for only 2 cases out of the 69 cases are generated.
- SemFix: The first solver-based bug-fixing tool for C.
- CodePhage: The first bug-fixing tool that directly transfer code across programs to generate patch for C program. Note that although it generates C patches, it can extract code from binary programs without source code.
- LeakFix: A tool that automatically fixes memory leaks in C programs.
- Prophet: The first generate-and-validate tool that uses machine learning techniques to learn useful knowledge from past human patches to recognize correct patches. It is evaluated on the same benchmark as GenProg and generate correct patches (i.e., equivalent to human patches) for 18 out of 69 cases.
- SearchRepair: A tool for replacing buggy code using snippets of code from elsewhere. It is evaluated on the IntroClass benchmark and generates much higher quality patches on that benchmark than GenProg, RSRepair, and AE.
- Angelix: An improved solver-based bug-fixing tool. It is evaluated on the GenProg benchmark. For 10 out of the 69 cases, it generate patches that is equivalent to human patches.
Tools for Java
- PAR: A generate-and-validate tool that uses a set of manually defined fix templates. A later study raised concerns about the generalizability of the fix templates in PAR.
- NOPOL: A solver-based tool focusing on modifying condition statements.
- QACrashFix: A tool that fixes Java crash bugs by mining fixes from Q&A web site.
- Astor: An automatic repair library for Java, containing jGenProg, a Java implementation of GenProg.
- NpeFix: An automatic repair tool for NullPointerException in Java, available on Github.
Tools for other languages
- AutoFixE: A bug-fixing tool for Eiffel language. It relies the contracts (i.e., a form of formal specification) in Eiffel programs to validate generated patches.
References
External links
- program-repair
.org datasets, tools, etc., related to automated program repair research.
Source of the article : Wikipedia