Explaining Inconsistent Code
Muhammad Numair Mansur
Explaining Inconsistent Code Muhammad Numair Mansur Introduction - - PowerPoint PPT Presentation
Explaining Inconsistent Code Muhammad Numair Mansur Introduction 50% of the time in debugging Fault localization. Becomes more tedious as the program size increase. Automatically explaining and localizing inconsistent code .
Muhammad Numair Mansur
2
execution.
3
4
5
6
7
8
9
Algorithm Inconsistent program Automata Error Invariant Automaton Pre Post
10
Algorithm Inconsistent program Automata Error Invariant Automaton Pre Post
A F.A is a 5 tuple: (Q, Σ, δ, qo,F)
11
Example:
12
S1 S4 S2 S3
Example:
13
S1 S4 S2 S3 States
Example:
14
S1 S4 S2 S3 States Transitions
15
F.A
input
(A sequence from the input alphabet)
Output
(accept or reject)
16
S1 S4 S2 S3 Σ = {a,b,c} Input: abca
Example:
Example:
17
S1 S4 S2 S3 a Σ = {a,b,c} Input: abca
Example:
18
S1 S4 S2 S3 a b Σ = {a,b,c} Input: abca
Example:
19
S1 S2 S3 a b c Σ = {a,b,c} Input: abca S4
Example:
20
S1 S4 S2 S3 a b c a accept ! Σ = {a,b,c} Input: abca
21
Defined in terms of a finite automata. State (Q) = Program Location (Loc) Transition (δ) = Program Statement (δp) Alphabet(Σ) = A set of program statements Initial State (q0) = Initial program Location ( ) Final State ( F ) = Final program Location ( )
22
23
24
assume( !b ) means that the branch of if () is taken where b is “not true” assume( b ) means that the branch of if () is taken where b is “true”
25
An assertion on the program state that x != null
lo sto l1 …..stn-1 ln
26
27
Algorithm Inconsistent program Automata Error Invariant Automaton Pre Post
Input: : precondition state formula : program automata : Postcondition state formula
: error invariant automata.
requires: is inconsistent subject to and . ensures:
explains .
28
Step 1: Translate the program automata into a single path of statements π .
29
Step 1: Translate the program automata into a single path of statements π .
30
Step 1: Translate the program automata into a single path of statements π .
31
It can be composed
statements.
Example: This was the first step in getting the final result, an error invariant automata.
32
1 2 3 4 5 6 7 8 9 1 2
2,9
9
that are relevant for understanding the cause of the inconsistency.
formulas and then eliminated.
not contribute to the inconsistency with a suitably chosen invariant. Lets see this in practice on a fragment of code.
33
1: public TaskDialog(Tast task) ~: . . . . . . 6: txtDescription.setTask(task.getDescription()); ~: . . . . . . 16: if (notification) { . . . . . } ~: . . . . 27: chbRegular.setEnabled(task == null); ~: . . . . }
34
1: public TaskDialog(Tast task) ~: . . . . . . 6: txtDescription.setTask(task.getDescription()); ~: . . . . . . 16: if (notification) { . . . . . } ~: . . . . 27: chbRegular.setEnabled(task == null); ~: . . . . }
line 1 - 5 line 6 line 7 - 26 line 27 line 28 - end No Effect on inconsistency assert ( task != null ) Arbitrary code No effect on task == null An assertion that task might be null No Effect on inconsistency
35
1: public TaskDialog(Tast task) ~: . . . . . . 6: txtDescription.setTask(task.getDescription()); ~: . . . . . . 16: if (notification) { . . . . . } ~: . . . . 27: chbRegular.setEnabled(task == null); ~: . . . . }
line 1 - 5 line 6 line 7 - 26 line 27 line 28 - end No Effect on inconsistency assert ( task != null ) Arbitrary code No effect on task == null An assertion that task might be null No Effect on inconsistency
36
1: public TaskDialog(Tast task) ~: . . . . . . 6: txtDescription.setTask(task.getDescription()); ~: . . . . . . 16: if (notification) { . . . . . } ~: . . . . 27: chbRegular.setEnabled(task == null); ~: . . . . }
line 1 - 5 line 6 line 7 - 26 line 27 line 28 - end No Effect on inconsistency assert ( task != null ) Arbitrary code No effect on task == null An assertion that task might be null No Effect on inconsistency
37
An error trace is a sequence of statements π = st0st1... stn, together with and . describes the initial state and is an assertion that is violated. That means, in an error trace Λ PF( π ) Λ is unsatisfiable.
38
An error trace is a sequence of statements π = st0st1... stn, together with and . describes the initial state and is an assertion that is violated. That means, in an error trace Λ PF( π ) Λ is unsatisfiable. Example:
task null Λ task null Λ
39
An error invariant for a position ∈ [ ] in an error trace is a first order logical formula such that.
implies Ii.
40
In the previous work, the authors introduced a function ⊼ which given an error trace, computes: I0,sti1,I1,sti2. . . stik,Ik Such that, sti1, sti2 …..stik is a subsequence of ⊼ and Ij is an inductive invariant for the position ij and ij+1 .
41
We say that an error invariant is inductive for position i < j if :
42
We say that an error invariant is inductive for position i < j if :
43
We say that an error invariant is inductive for position i < j if : is called an inductive error invariant.
44
An Error Invariant Automaton is an inconsistent program automaton with a mapping from locations of to state formulas, such that for all locations , is an error invariant for .
45
Now, after applying step 1 we got a single path π A. Step 2: Apply ErrInv( π A ) ErrInv(π A) = ErrInv( π ) = I0st(li1). . . . . . st(lik)Ik.
47
Now, after applying step 1 we got a single path π A. Step 2: Apply ErrInv( π A ) ErrInv(π A) = ErrInv( π ) = I0st(li1). . . . . . st(lik)Ik.
I2 I5 I3 I4 I1 I0
48
Now, after applying step 1 we got a single path π A. Step 2: Apply ErrInv( π A ) ErrInv(π A) = ErrInv( π ) = I0st(li1). . . . . . st(lik)Ik.
I2 I5 I3 I4 I1 I0 error invariants
49
Example:
assume(task !=null) assume(task =null)
50
Example:
assume(task !=null) assume(task =null) assume(task !=null) assume(task =null)
true task != null false
ErrInv()
Step 3: The locations covered with an inductive error invariant can be collapsed into a single location.
51
I0 I1 I5 I1 I4 I0 I0 I1 I4 I5
Step 4: For each remaining non-atomic statement, apply the algorithm recursively to all these smaller automata.
52
I0 I5 I2 I1
Step 4: For each remaining non-atomic statement, apply the algorithm recursively to all these smaller automata.
53
I0 I5 Apply the algo recursively to these non- atomic statements I2 I1
Step 4: For each remaining non-atomic statement, apply the algorithm recursively to all these smaller automata.
54
I0 I5 In case of this location Pre Post I2 I1
Step 4: For each remaining non-atomic statement, apply the algorithm recursively to all these smaller automata.
55
I0 I5 In case of the location with invariant I2 Inconsistent w.r.t pre and post Post I2 I1 Pre
Step 4: For each remaining non-atomic statement, apply the algorithm recursively to all these smaller automata.
56
I0 I5 In case of the location with invariant I2 I2 I1
Step 4: For each remaining non-atomic statement, apply the algorithm recursively to all these smaller automata.
57
I0 I5 In case of the location with invariant I2 pre post I2
recursively
I1
Step 4: For each remaining non-atomic statement, apply the algorithm recursively to all these smaller automata.
58
I0 I5 I2 I I1
1: public TaskDialog(Tast task) ~: . . . . . . 6: txtDescription.setTask(task.getDescription()); ~: . . . . . . 16: if (notification) { . . . . . } ~: . . . . 27: chbRegular.setEnabled(task == null); ~: . . . . }
59
The approach was tested on 6 real world examples. For each of these examples, Error invariant automatas were generated using the technique introduced. All the generated error invariant automatas represented real world inconsistencies with no false alarms. Running time to prove inconsistency using unsat ranged from 0.008 seconds in
60
Usability testing was also conducted on 11 programmers. Half of the test subjects were shown the full programs, while the other half were just shown the error invariant automata. All candidates took 1 hour and 6 minutes to identify the bug. For the full programs without error invariant automata : 51 minutes With error invariant automata : 17 minutes
61
The experiments indicate that EIA provide useful visual assistance to spot inconsistencies. EIA can also be used for fault localization on a single trace and thus provide a general tool to assist programmers in debugging.
62
63
Martin Schaf, Daniel Schawrtz, Thomas Wies Book Title: Joint meeting of the European Software Engineering conference and the Symposium on the Foundations of Software Engineering, ESEC/FSE’13, Saint Petersburg, Russian Federation, August18-26,2013 url: http://dl.acm.org/citation.cfm?id=2491411 Title: Explaining Inconsistent Code, pages: 521 - 531 Bixie - FInd inconsistencies in Java code. http://martinschaef.github.io/bixie/ Jurgen Christ, Evren Ermis, Martin Schaf, Thomas Weis Book Title: Verification, Model Checking, and Abstract Interpretation,14th International Conference, VMCAI 2013, Rome, Italy, January 20-22, 2013. Proceedings url: http://link.springer.com/book/10.1007/978-3-642-35873-9 Title: Flow-Sensitive Fault Localization, pages : 189 - 208 .