explaining inconsistent code
play

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 .


  1. Explaining Inconsistent Code Muhammad Numair Mansur

  2. Introduction ● 50% of the time in debugging ● Fault localization. ● Becomes more tedious as the program size increase. ● Automatically explaining and localizing inconsistent code . 2

  3. Code Inconsistency ● A code fragment is inconsistent if it is not a part of any normally terminating execution. ● Not necessarily always a bug ! ● But sometimes inconsistent code results in an error. 3

  4. Examples (Unreachability) Generated using Bixie 4

  5. Examples (Unreachability) Generated using Bixie 5

  6. Examples (conflicting assumptions) Generated using Bixie 6

  7. Examples (conflicting assumptions) Generated using Bixie 7

  8. Our Goal Automatically explain inconsistent code. 8

  9. Our Goal Automatically explain inconsistent code. Pre Error Invariant Inconsistent Algorithm Automaton program Automata Post 9

  10. Our Goal Automatically explain inconsistent code. Pre Error Invariant Inconsistent Algorithm Automaton program Automata Post 10

  11. Finite automata A F.A is a 5 tuple: (Q, Σ, δ, q o ,F) Q : A finite set of states. Σ : A finite set of input symbols called an alphabet. δ : A transition function ( δ: Q x Σ → Q ). q o : initial state. F : A finite set of final states. 11

  12. Finite automata Example: S 1 S 2 S 3 S 4 12

  13. Finite automata Example: States S 1 S 2 S 3 S 4 13

  14. Finite automata Example: States S 1 Transitions S 2 S 3 S 4 14

  15. Finite automata F.A input Output (A sequence (accept or reject) from the input alphabet) ● Transitions through the states based on the input ● True, if ends in an accepting state 15

  16. Finite automata Example: S 1 Σ = {a,b,c} Input: abca S 2 S 3 S 4 16

  17. Finite automata Example: S 1 a Σ = {a,b,c} Input: abca S 2 S 3 S 4 17

  18. Finite automata Example: S 1 a Σ = {a,b,c} Input: abca S 2 S 3 b S 4 18

  19. Finite automata Example: S 1 a Σ = {a,b,c} Input: abca S 2 S 3 c b S 4 19

  20. Finite automata Example: S 1 a Σ = {a,b,c} Input: abca S 2 S 3 c b a S 4 accept ! 20

  21. Program automata A simple and an abstract model of a program. 21

  22. Program automata A simple and an abstract model of a program. Defined in terms of a finite automata. State (Q) = Program Location (Loc) Transition (δ) = Program Statement (δ p ) Alphabet(Σ) = A set of program statements Initial State (q 0 ) = Initial program Location ( ) Final State ( F ) = Final program Location ( ) 22

  23. Program automata 23

  24. Program automata assume( b ) means that assume( !b ) means that the branch of if () is taken the branch of if () is taken where b is “true” where b is “not true” 24

  25. Program automata An assertion on the program state that x != null 25

  26. Program automata ● A run ρ is a finite sequence of locations and statements. l o st o l 1 …..st n-1 l n ● A path(ρ) st o st 1 ….. st n-1 is the path associated with a run. ● A run ρ is accepting if its final state is l e A word π ∈ � * is a path if π = path(ρ) for some accepting run ρ. ● 26

  27. Our Goal To automatically explain inconsistent code. Pre Error Invariant Inconsistent Algorithm Automaton program Automata Post 27

  28. Algorithm Input : : precondition state formula : program automata : Postcondition state formula output: : error invariant automata. requires: is inconsistent subject to and . ensures: explains . 28

  29. Algorithm Step 1: Translate the program automata into a single path of statements π . 29

  30. Algorithm Step 1: Translate the program automata into a single path of statements π . 30

  31. Algorithm Step 1: Translate the program automata into a single path of statements π . It can be composed of many atomic statements. 31

  32. Algorithm 1 1 Example: 2 2 3 4 2,9 5 7 6 8 9 9 This was the first step in getting the final result, an error invariant automata. 32

  33. Error Invariant Automaton ● An abstraction of the program, that only mentions the statements and facts that are relevant for understanding the cause of the inconsistency. ● The irrelevant statements are first summarized as first order logical formulas and then eliminated. ● These formulas are called error invariants . ● An error invariant captures the reason of abnormal program termination. ● So, at a high level, an Error Invariant Automaton replaces code which does not contribute to the inconsistency with a suitably chosen invariant. Lets see this in practice on a fragment of code. 33

  34. Error Invariant Automaton 1: public TaskDialog(Tast task) ~: . . . . . . 6: txtDescription.setTask(task.getDescription()); ~: . . . . . . 16: if (notification) { . . . . . } ~: . . . . 27: chbRegular.setEnabled(task == null); ~: . . . . } 34

  35. Error Invariant Automaton No Effect on inconsistency line 1 - 5 1: public TaskDialog(Tast task) ~: . . . . . . 6: txtDescription.setTask(task.getDescription()); line 6 assert ( task != null ) ~: . . . . . . 16: if (notification) { Arbitrary code line 7 - 26 . . . . . No effect on task == null } ~: . . . . 27: chbRegular.setEnabled(task == null); An assertion that task might line 27 be null ~: . . . . line 28 - end No Effect on inconsistency } 35

  36. Error Invariant Automaton No Effect on inconsistency line 1 - 5 1: public TaskDialog(Tast task) ~: . . . . . . 6: txtDescription.setTask(task.getDescription()); line 6 assert ( task != null ) ~: . . . . . . 16: if (notification) { Arbitrary code line 7 - 26 . . . . . No effect on task == null } ~: . . . . 27: chbRegular.setEnabled(task == null); An assertion that task might line 27 be null ~: . . . . line 28 - end No Effect on inconsistency } 36

  37. Error Invariant Automaton No Effect on inconsistency line 1 - 5 1: public TaskDialog(Tast task) ~: . . . . . . 6: txtDescription.setTask(task.getDescription()); line 6 assert ( task != null ) ~: . . . . . . 16: if (notification) { Arbitrary code line 7 - 26 . . . . . No effect on task == null } ~: . . . . 27: chbRegular.setEnabled(task == null); An assertion that task might line 27 be null ~: . . . . line 28 - end No Effect on inconsistency } 37

  38. Error Trace An error trace is a sequence of statements π = st 0 st 1 ... st n , together with and . describes the initial state and is an assertion that is violated. That means, in an error trace Λ PF( π ) Λ is unsatisfiable. 38

  39. Error Trace An error trace is a sequence of statements π = st 0 st 1 ... st n , together with and . describes the initial state and is an assertion that is violated. That means, in an error trace Λ PF( π ) Λ is unsatisfiable. Example: Λ null Λ null Λ task task 39

  40. Error Invariant An error invariant for a position ∈ [ ] in an error trace is a first order logical formula such that. ● The conjunction of the first order logical formulas for each statement implies I i . ● I i and the conjunction of the remaining formulas is unsatisfiable. 40

  41. ErrInv( ) In the previous work, the authors introduced a function which ⊼ given an error trace, computes: I 0 ,st i1 ,I 1 ,st i2 . . . st ik ,I k Such that, st i1 , st i2 …..st ik is a subsequence of ⊼ and I j is an inductive invariant for the position i j and i j+1 . 41

  42. Inductive error invariant We say that an error invariant is inductive for position i < j if : 42

  43. Inductive error invariant We say that an error invariant is inductive for position i < j if : 43

  44. Inductive error invariant We say that an error invariant is inductive for position i < j if : is called an inductive error invariant. 44

  45. Error Invariant Automaton 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

  46. Algorithm Now, after applying step 1 we got a single path π A . Step 2: Apply ErrInv( π A ) ErrInv(π A ) = ErrInv( ) π = I 0 st(l i1 ). . . . . . st(l ik )I k.

  47. Algorithm I 0 Now, after applying step 1 we got a single path π A . I 1 I 2 Step 2: Apply ErrInv( π A ) ErrInv(π A ) = ErrInv( ) π I 3 = I 0 st(l i1 ). . . . . . st(l ik )I k. I 4 47 I 5

  48. Algorithm I 0 Now, after applying step 1 we got a single path π A . I 1 I 2 Step 2: Apply ErrInv( π A ) ErrInv(π A ) = ErrInv( ) π I 3 = I 0 st(l i1 ). . . . . . st(l ik )I k. error invariants I 4 48 I 5

  49. Algorithm Example: assume(task !=null) assume(task =null) 49

  50. Algorithm Example: true assume(task !=null) assume(task !=null) ErrInv() task != null assume(task =null) assume(task =null) false 50

  51. Algorithm Step 3 : I 0 The locations covered with I 0 I 0 an inductive error invariant I 1 can be collapsed into a single I 1 I 1 location. I 4 I 4 I 5 I 5 51

  52. Algorithm Step 4 : For each remaining non-atomic statement, apply the algorithm recursively to all these smaller automata. I 0 I 1 I 2 52 I 5

  53. Algorithm Step 4 : For each remaining non-atomic statement, apply the algorithm recursively to all these smaller automata. I 0 I 1 Apply the algo recursively to these non- atomic statements I 2 53 I 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend