120 likes | 259 Views
An Algorithmic Debugger for Java. David Insa Cabrera. Contents. Introduction. Algorithmic Debugging. AD Strategies. A Debugging Session. Adaptation to Java. This, arguments and return value. System Demo. DDJ. Algorithmic Debugging.
E N D
AnAlgorithmic Debuggerfor Java David Insa Cabrera
Contents Introduction Algorithmic Debugging • AD Strategies • A Debugging Session Adaptation to Java This, arguments and return value System Demo DDJ
Algorithmic Debugging • Algorithmic Debugging [Shapiro 82]Logic Paradigm • TWO PHASES: • Generate an execution tree • Traverse the execution tree asking questions until the bug is found If the effect of a bug is detected then AD will find the bug main = 4 What is an Execution Tree? listSum [1,2] = 4 Example: main = listSum [1,2] listSum [] = 1 listSum (x:xs) = x + (listSumxs) 1+3 = 4 listSum [2] = 3 2+1 = 3 listSum [] = 1
Algorithmic Debugging • Traversing Execution Trees • GOLDEN RULE: When a wrong equation has not • wrong children, then this equation is buggy main = 4 listSum [1,2] = 4 Example: main = listSum [1,2] listSum [] = 1 listSum (x:xs) = x + (listSumxs) 1+3 = 4 listSum [2] = 3 2+1 = 3 listSum [] = 1
Algorithmic Debugging • Traversing Execution Trees • GOLDEN RULE: When a wrong equation has not • wrong children, then this equation is buggy main = 5 listSum [1,2] = 5 Example: main = listSum [1,2] listSum [] = 0 listSum (x:xs) = x + (listSum xs) + 1 1+3+1 = 5 listSum [2] = 3 2+0+1 = 3 listSum [] = 0
Contents Introduction Algorithmic Debugging • AD Strategies • A Debugging session Adaptation to Java This, arguments and return value System Demo DDJ
Algorithmic Debugging Strategies Strategies Single Stepping Single Stepping Divide & Query Top Down Top Down Left to Right Top Down Heaviest First Top Down More Rules First Divide & Query Shapiro Divide & Query Hirunkitti Divide by Rules & Query Hat Delta Hat Delta More Wrongs Hat Delta Less Rights Hat Delta Best Division
A Debugging Session A Debugging Session main = sqrTest [1,2] sqrTest x = test (squares (listSum x)) test (x,y,z) = (x==y) && (y==z) listSum [] = 0 listSum (x:xs) = x + (listSumxs) squares x = ((square1 x),(square2 x),(square3 x)) square1 x = square x square x = x*x square2 x = listSum (list x x) list x y | y==0 = [] | otherwise = x:list x (y-1) square3 x = listSum (partialSums x) partialSums x = [(sum1 x),(sum2 x)] sum1 x = div (x * (incr x)) 2 sum2 x = div (x + (decr x)) 2 incr x = x + 1 decr x = x - 1
A Debugging Session A Debugging Session with Top-Down Left to Right search. main = False Starting Debugging Session… main = False? NO sqrTest [1,2] = False? NO test [9,9,8] = False? YES squares 3 = [9,9,8]? NO square1 3 = 9? YES square2 3 = 9? YES square3 3 = 8? NO listSum [6,2] = 8? YES partialSums 3 = [6,2]? NO sum1 3 = 6? YES sum2 3 = 2? NO decr 3 = 2? YES Bug found in rule: sum2 x = div (x + (decr x)) 2 sqrTest [1,2] = False test (9,9,8) = False squares 3 = (9,9,8) listSum [1,2] = 3 listSum [2] = 2 squares1 3 = 9 squares2 3 = 9 squares3 3 = 8 listSum [] = 0 square 3 = 9 listSum [3,3,3] = 9 list 3 3 = [3,3,3] partialSums 3 = [6,2] listSum [6,2] = 8 listSum [3,3] = 6 list 3 2 = [3,3] listSum [2] = 2 sum1 3 = 6 sum2 3 = 2 decr 3 = 2 listSum [3] = 3 list 3 1 = [3] listSum [] = 0 incr 3 = 4 listSum [] = 0 list 3 0 = []
Contents Introduction Algorithmic Debugging • AD Strategies • A Debugging Session Adaptation to Java This, arguments and return value System Demo DDJ
Adaptation to Java public class Class { private intatribute; public void procedure(AnObjectarg1, AnObjectarg2) { this.atribute = 5; } public intfunction(MyObjectarg1, AnObjectarg2) { arg1.setProperty(this.atribute); arg2.atribute = this.atribute; return this.atribute; } } public class MyObject { private int property; public void setProperty(int argument) { this.property = argument; } }
Contents Introduction Algorithmic Debugging • AD Strategies • A Debugging Session Adaptation to Java This, arguments and return value System Demo DDJ