CN108170466A - A kind of C/C++ bugs self-repairing methods based on program synthesis - Google Patents
A kind of C/C++ bugs self-repairing methods based on program synthesis Download PDFInfo
- Publication number
- CN108170466A CN108170466A CN201711394256.5A CN201711394256A CN108170466A CN 108170466 A CN108170466 A CN 108170466A CN 201711394256 A CN201711394256 A CN 201711394256A CN 108170466 A CN108170466 A CN 108170466A
- Authority
- CN
- China
- Prior art keywords
- program
- expression formula
- bugs
- selection expression
- defective
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 40
- 230000015572 biosynthetic process Effects 0.000 title claims description 18
- 230000007547 defect Effects 0.000 claims abstract description 39
- 230000002950 deficient Effects 0.000 claims abstract description 32
- 238000011084 recovery Methods 0.000 claims abstract description 17
- 230000008439 repair process Effects 0.000 claims description 18
- 238000012360 testing method Methods 0.000 claims description 9
- 230000007812 deficiency Effects 0.000 claims description 2
- 238000003786 synthesis reaction Methods 0.000 description 4
- 230000000694 effects Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012795 verification Methods 0.000 description 2
- 238000013461 design Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/72—Code refactoring
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
- G06F8/315—Object-oriented languages
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Stored Programmes (AREA)
- Debugging And Monitoring (AREA)
Abstract
The present invention discloses a kind of C/C++ bugs self-repairing methods synthesized based on program, and the defective C/C++ programs of input tape according to the type of common bugs and Defective program, set rewriting rule, and rewriting rule includes defect mode and Recovery Options.Defect mode is matched with the syntax tree of Defective program later.If there is no any matched rewriting rule, the defects of showing that the program can not be repaired.If there are matched rewriting rule, matched syntax tree subtree is replaced with into selection expression formula.Later using program synthetic method, according to the stipulations that program needs meet, the option of each selection expression formula is obtained.The stipulations that program with selection expression formula and program needs meet are converted into logical expression by program synthetic method, constraint solver is used later, it is solved within the time of setting, substitute into the option of each selection expression formula, syntax tree is exported as C/C++ codes, the program after being repaired.
Description
Technical field
The present invention relates to a kind of bugs self-repairing methods, using program synthetic method, realize bugs oneself
It is dynamic to repair, belong to field of software engineering.
Background technology
Refer in the case of given stipulations in the synthesis of computer science program, automatically constructor.Due to can
With automatic code generating, program synthesis is typically used in code completion, software development, algorithm design.Program synthetic method
Including two steps of synthesis and verification, problem is converted into SAT/SMT problems, finally used by the method guided using counter-example
SAT/SMT solvers are solved.
Current bugs self-repairing method, method of the generally use based on test case.Generation after usually repairing
Code can not ensure to repair the correctness of post code by test case.Program synthetic method includes synthesis and verification two
Step, using the stipulations of program as constraint, it is ensured that the code after synthesis is correct.
Invention content
Current bugs self-repairing method, method of the generally use based on test case, after can not ensureing reparation
The correctness of code.The present invention uses following technical scheme to solve above-mentioned technical problem:
A kind of C/C++ bugs self-repairing methods based on program synthesis, include the following steps:
The defective C/C++ programs of step 1) input tape, the program is in test set S1S2...S0Upper discovery defect, there are scarce
Fall into d0d0...dk。
Step 2) sets several rewriting rules, rewrites rule according to the type of common C/C++ bugs and Defective program
Then include defect mode and Recovery Options, syntactic structure is:expr->expr1|expr2..., the expression Defect Modes before arrow
Formula, the possible Recovery Options of expression after arrow, for defect di, it is understood that there may be a variety of Recovery Options are denoted as respectively
ci1ci2...ciu.
Step 3) matches pattern the defects of rewriting rule with Defective program, finds out all matched rewriting rules,
It is as follows:
Step 3.1) will resolve to abstract syntax tree with defective C/C++ programs and rewriting rule.
Step 3.2) carries out pattern the defects of every subtree and rewriting rule in the abstract syntax tree of Defective program
Match.
If step 3.3) is matched there are part rewriting rule with Defective program, show that the Defective program is repaiied there are possible
Final election item.
If there is no any rewriting rules to be matched with Defective program for step 3.4), show that this method can not repair the program
The defects of.
If there are matched rewriting rules for step 4), matched syntax tree subtree is replaced with into selection expression formula, specifically
Step is as follows:
Each matched syntax tree subtree is replaced with selection expression formula, original by step 4.1) for each rewriting rule
First subtree of the beginning syntax tree subtree as the selection expression formula.
Step 4.2) is by the follow-up subtree of several Recovery Options of the rewriting rule alternatively expression formula.
Each selection expression formula is denoted as e by step 4.3) respectively1e2...emIf ei0 is taken to show the selection expression formula
Option is first subtree, i.e. Original program code, if ei1 option for showing the selection expression formula is taken as second subtree,
That is first Recovery Options c of the defect modei1, and so on.
The stipulations that program needs meet are denoted as f by step 5), and stipulations have arranged program to be needed to meet under specific input
Output.Using program synthetic method, according to the stipulations f of the program, the option of each selection expression formula is obtained, specific steps are such as
Under:
Program with selection expression formula and the stipulations of the program are converted into logical expression by step 5.1), and form is such as
Under:
S1S2...SnFor the test case of program, eiRepresent the option of each selection expression formula, f ' is band selection expression formula
Program, f is the stipulations that meet of program needs.
Step 5.2) in the time t of setting, solves above-mentioned logical expression using constraint solver.If
To S1S2...SnThere are e1e2…enSo that formula is set up, then the defects of showing for the program, this method can repair.If nothing
The defects of solution or time-out, then this method can not repair the program.
If step 6) step 5 has solution, the option of each selection expression formula is substituted into, the program after being repaired is specific to walk
It is rapid as follows:
Step 6.1) is for each selection expression formula, and the subtree that option is represented replaces selection expression formula, after obtaining reparation
Syntax tree.
Step 6.2) exports syntax tree for C/C++ codes, the program after being repaired.
Advantageous effect:The present invention is using above technical scheme, compared with prior art, specific following advantageous effect:
1. inputting rewriting rule according to common C/C++ bugs, this method can repair the common of C/C++ programs and lack
It falls into.
2. this method can realize defect repair in polynomial time complexity.
3. this method uses program synthetic method, according to the stipulations that meet of Defective program needs, defect repair is realized, it can be with
Ensure program correctness after repairing.
Description of the drawings
Fig. 1 is the flow chart of C/C++ bugs self-repairing methods synthesized based on program.
Fig. 2 is the C/C++ program examples with defect.
Fig. 3 is rewriting rule example.
Specific embodiment
The C/C++ bugs self-repairing method specific embodiments synthesized based on program used below the present invention
It is described in more detail.
The C/C++ bugs self-repairing methods based on program synthesis of the present embodiment, this method input tape are defective
C/C++ programs, according to the type of common bugs and Defective program, rewriting rule is set, rewriting rule includes defect
Pattern and Recovery Options.Defect mode is matched with the syntax tree of Defective program later.If there is no any matched heavy
The defects of writing rule, then showing that the program can not be repaired.If there are matched rewriting rule, matched syntax tree subtree is replaced
It is changed to selection expression formula.Later using program synthetic method, according to the stipulations that program needs meet, each selection expression is obtained
The option of formula.The stipulations that program with selection expression formula and program needs meet are converted into logical table by program synthetic method
Up to formula, later using constraint solver, solved within the time of setting.If without solution or time-out, show that this can not be repaired
The defects of program.The option of each selection expression formula is finally substituted into, is C/C++ codes by syntax tree output, after being repaired
Program.This method can repair the common deficiency of C/C++ programs in polynomial time complexity, and this method ensures to repair
Program correctness afterwards.The C/C++ bugs self-repairing method flow charts based on program synthesis shown in 1 with reference to the accompanying drawings,
The present invention specific embodiment be:
1) the defective C/C++ programs of input tape, the program is in test set S1S2...SnUpper discovery defect, existing defects
d1d2, as shown in Figure 2.
2) according to the type of common C/C++ bugs and Defective program, several rewriting rules, rewriting rule packet are set
Defect mode and Recovery Options are included, syntactic structure is:expr->expr1|expr2..., the expression defect mode before arrow, arrow
The possible Recovery Options of expression after head, for defect di, it is understood that there may be a variety of Recovery Options are denoted as c respectivelyi1ci2…ciu, such as
Shown in Fig. 3.
3) pattern the defects of rewriting rule with Defective program is matched, finds out all matched rewriting rules, specifically
Step is as follows:
3.1) abstract syntax tree will be resolved to defective C/C++ programs and rewriting rule.
3.2) every subtree in the abstract syntax tree of Defective program is matched with pattern the defects of rewriting rule.
3.3) it is matched there are part rewriting rule with Defective program, showing the Defective program, there are possible Recovery Options.
4) for matched two rewriting rules, matched syntax tree subtree is replaced with into selection expression formula, specific steps
It is as follows:
4.1) for the two rewriting rules, matched syntax tree subtree is replaced with into selection expression formula, original syntax tree
First subtree of the subtree as the selection expression formula.
4.2) by the follow-up subtree of several Recovery Options of the rewriting rule alternatively expression formula.
4.3) the two selection expression formulas are denoted as e respectively1e2, the two select expression formulas as follows:
(w-max-min)/(n-2)|double(w-max-min)/double(n-2)
i<=n | i<=n+1 | i<=n-1
5) stipulations that meet of program needs are denoted as f, stipulations arranged program need to meet under specific input it is defeated
Go out.Using program synthetic method, according to the stipulations f of the program, the option of each selection expression formula is obtained, is as follows:
5.1) program with selection expression formula and the stipulations of the program are converted into logical expression, form is as follows:
S1S2…SnFor the test case of program, e1e2Represent the option of two selection expression formulas, f ' is band selection expression formula
Program, f is the stipulations that meet of program needs.
5.2) using constraint solver, within the 30 minutes time of setting, above-mentioned logical expression is solved.
To d1=1 d2=2.
6) result of step 5 is substituted into the option of each selection expression formula, the program after being repaired, specific steps are such as
Under:
6.1) for the two selection expression formulas, the subtree that option is represented replaces selection expression formula, after being repaired
Syntax tree.
6.2) it is C/C++ codes by syntax tree output, the program after being repaired, program is as follows after reparation:
The foregoing is only a preferred embodiment of the present invention, not makees limitation in any form to the present invention, appoints
What those skilled in the art, without departing from the scope of the present invention, technical spirit according to the present invention to
Any simple modification that upper embodiment is made, equivalent variations and modification, are still within the scope of the technical scheme of the invention.
Claims (8)
1. a kind of C/C++ bugs self-repairing methods based on program synthesis, which is characterized in that this method includes following step
Suddenly:
The defective C/C++ programs of step 1) input tape, the program is in test set S1S2…SnUpper discovery defect, existing defects
d1d2...dk;
Step 2) sets several rewriting rules, rewriting rule packet according to the type of common C/C++ bugs and Defective program
Defect mode and Recovery Options are included, syntactic structure is:expr->expr1|expr2..., the expression defect mode before arrow, arrow
The possible Recovery Options of expression after head, for defect di, it is understood that there may be a variety of Recovery Options are denoted as c respectivelyi1ci2...ciu;
Step 3) matches pattern the defects of rewriting rule with Defective program, finds out all matched rewriting rules;
If there are matched rewriting rules for step 4), matched syntax tree subtree is replaced with into selection expression formula;
The stipulations that meet of program needs are denoted as f by step 5), stipulations arranged program need to meet under specific input it is defeated
Go out, using program synthetic method, according to the stipulations f of the program, obtain the option of each selection expression formula;
If step 6) step 5) has solution, the option of each selection expression formula, the program after being repaired are substituted into.
2. the C/C++ bugs self-repairing methods according to claim 1 based on program synthesis, it is characterised in that:
The step 3) matches pattern the defects of rewriting rule with Defective program, finds out all matched rewriting rules, specifically
Step is as follows:
Step 3.1) will resolve to abstract syntax tree with defective C/C++ programs and rewriting rule;
Step 3.2) matches every subtree in the abstract syntax tree of Defective program with pattern the defects of rewriting rule;
If step 3.3) is matched there are part rewriting rule with Defective program, show that the Defective program repairs choosing there are possible
;
If there is no any rewriting rules to be matched with Defective program for step 3.4), show that this method can not repair lacking for the program
It falls into.
3. the C/C++ bugs self-repairing methods according to claim 1 based on program synthesis, it is characterised in that:
If there are matched rewriting rules for the step 4), matched syntax tree subtree is replaced with into selection expression formula, specific steps
It is as follows:
Each matched syntax tree subtree is replaced with selection expression formula, original language by step 4.1) for each rewriting rule
First subtree of the method tree tree as the selection expression formula;
Step 4.2) is by the follow-up subtree of several Recovery Options of the rewriting rule alternatively expression formula;
Each selection expression formula is denoted as e by step 4.3) respectively1e2...emIf ei0 option for showing the selection expression formula is taken to be
First subtree, i.e. Original program code, if eiTaking 1 option for showing the selection expression formula, that is, this is lacked for second subtree
First Recovery Options c of the pattern of falling intoi1, and so on.
4. the C/C++ bugs self-repairing methods according to claim 1 based on program synthesis, it is characterised in that:
The stipulations that meet of program needs are denoted as f by the step 5), stipulations arranged program need to meet under specific input it is defeated
Go out, using program synthetic method, according to the stipulations f of the program, obtain the option of each selection expression formula, be as follows:
Program with selection expression formula and the stipulations of the program are converted into logical expression by step 5.1), and form is as follows:
S1S2...SnFor the test case of program, eiRepresent the option of each selection expression formula, f ' is the journey with selection expression formula
Sequence, f are the stipulations that program needs meet;
Step 5.2) in the time t of setting, solves above-mentioned logical expression using constraint solver.It is if right
S1S2...SnThere are e1e2...enSo that formula is set up, then the defects of showing for the program, this method can repair.If without solution
Or time-out, then the defects of this method can not repair the program.
5. the C/C++ bugs self-repairing methods according to claim 1 based on program synthesis, it is characterised in that:
If the step 6) step 5) has solution, the option of each selection expression formula is substituted into, the program after being repaired, specific steps are such as
Under:
For step 6.1) for each selection expression formula, the subtree that option is represented replaces selection expression formula, the language after being repaired
Method tree;
Step 6.2) exports syntax tree for C/C++ codes, the program after being repaired.
6. the C/C++ bugs self-repairing methods based on program synthesis according to one of claim 1 to 5, special
Sign is:Rewriting rule is inputted according to common C/C++ bugs, this method repairs the common deficiency of C/C++ programs.
7. the C/C++ bugs self-repairing methods based on program synthesis according to one of claim 1 to 5, special
Sign is:This method realizes defect repair in polynomial time complexity.
8. the C/C++ bugs self-repairing methods based on program synthesis according to one of claim 1 to 5, special
Sign is:This method uses program synthetic method, according to the stipulations that Defective program needs meet, realizes defect repair, ensures to repair
Program correctness after multiple.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201711394256.5A CN108170466B (en) | 2017-12-21 | 2017-12-21 | A kind of C/C++ bugs self-repairing method based on program synthesis |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201711394256.5A CN108170466B (en) | 2017-12-21 | 2017-12-21 | A kind of C/C++ bugs self-repairing method based on program synthesis |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108170466A true CN108170466A (en) | 2018-06-15 |
CN108170466B CN108170466B (en) | 2019-09-20 |
Family
ID=62523004
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201711394256.5A Active CN108170466B (en) | 2017-12-21 | 2017-12-21 | A kind of C/C++ bugs self-repairing method based on program synthesis |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108170466B (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108829438A (en) * | 2018-07-05 | 2018-11-16 | 南京大学 | A kind of C/C++ bugs self-repairing method synthesized based on deep learning with program |
CN110674031A (en) * | 2019-09-04 | 2020-01-10 | 中国石油大学(华东) | Restricted set-based automatic program semantic defect repairing method |
CN111506493A (en) * | 2019-12-31 | 2020-08-07 | 中国石油大学(华东) | Program slice-based repair position determination method for automatically repairing defects |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20120167053A1 (en) * | 2010-06-29 | 2012-06-28 | International Business Machine Corporation | Targeting code sections for correcting computer program product defects using records of a defect tracking system |
CN105302724A (en) * | 2015-11-05 | 2016-02-03 | 南京大学 | Instant defect predicting method based on mixed effect removing |
-
2017
- 2017-12-21 CN CN201711394256.5A patent/CN108170466B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20120167053A1 (en) * | 2010-06-29 | 2012-06-28 | International Business Machine Corporation | Targeting code sections for correcting computer program product defects using records of a defect tracking system |
CN105302724A (en) * | 2015-11-05 | 2016-02-03 | 南京大学 | Instant defect predicting method based on mixed effect removing |
Non-Patent Citations (2)
Title |
---|
FENGJUAN GAO 等: "BovInspector: Automatic inspection and repair of buffer overflow vulnerabilities", 《2016 31ST IEEE/ACM INTERNATIONAL CONFERENCE ON AUTOMATED SOFTWARE ENGINEERING》 * |
TAO YE 等: "An Empirical Study on Detecting and Fixing Buffer Overflow Bugs", 《2016 IEEE INTERNATIONAL CONFERENCE ON SOFTWARE TESTING, VERIFICATION AND VALIDATION》 * |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108829438A (en) * | 2018-07-05 | 2018-11-16 | 南京大学 | A kind of C/C++ bugs self-repairing method synthesized based on deep learning with program |
CN108829438B (en) * | 2018-07-05 | 2020-04-07 | 南京大学 | C/C + + program defect automatic repairing method based on deep learning and program synthesis |
CN110674031A (en) * | 2019-09-04 | 2020-01-10 | 中国石油大学(华东) | Restricted set-based automatic program semantic defect repairing method |
CN110674031B (en) * | 2019-09-04 | 2022-09-30 | 中国石油大学(华东) | Restricted set-based automatic program semantic defect repairing method |
CN111506493A (en) * | 2019-12-31 | 2020-08-07 | 中国石油大学(华东) | Program slice-based repair position determination method for automatically repairing defects |
Also Published As
Publication number | Publication date |
---|---|
CN108170466B (en) | 2019-09-20 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108170466B (en) | A kind of C/C++ bugs self-repairing method based on program synthesis | |
US20140316540A1 (en) | Method for producing plc and hmi tag database and system | |
CN107864052A (en) | Method and its system based on lasting application deployment configuration automatic updating | |
CN104991863A (en) | Method for automatically generating testing case on basis of function block diagram testing module | |
CN107273117A (en) | A kind of quick Code automatic build system for programming friendly | |
CN107291450A (en) | A kind of quick code automatic generation method for programming friendly | |
JP5005510B2 (en) | Software design support method, design support apparatus, and design support program | |
CN104035873A (en) | Method and device for generating testing codes | |
CN101071378A (en) | Source code generation method, apparatus and program | |
JP2014186407A (en) | Test case generation method, test case generation device and program | |
CN105335246B (en) | A kind of program crashing defect self-repairing method based on question and answer web analytics | |
CN104657274A (en) | Method and device for testing software interface | |
CN104536885A (en) | Method for generating Soc random verification platform | |
CN107148615A (en) | Computer executable model reverse engineering approach and device | |
CN107169210A (en) | The self checking method and self-checking system of BIM database | |
CN100483429C (en) | Verification operation supporting system and method of the same | |
JP2007011605A (en) | Model inspection support device for software operation specification, model inspection system provided with the same, and model inspection support program | |
CN111190880B (en) | Database detection method, device and computer readable storage medium | |
JP5747698B2 (en) | Requirements management support device | |
CN110968307A (en) | Micro-service construction method and device based on intelligent generation of basic codes | |
JP2002259161A (en) | Device for automatically generating test script | |
CN103810365A (en) | Automatic grading method based on hydroelectric simulation training system | |
CN108829438A (en) | A kind of C/C++ bugs self-repairing method synthesized based on deep learning with program | |
CN112181399A (en) | Method for generating front-end code based on data analysis construction model | |
CN109117431A (en) | System and method for the source data applied from source to be incorporated into the target data of target application |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |