1 / 18

SwE 455 Program Slicing

SwE 455 Program Slicing. Our Goals. Debug your thousands lines of code easily by reducing the complexity of the program Write a robust program before testing your code Save your regression testing time by limiting the tests to only those that exercise the changed code. Approach.

roz
Download Presentation

SwE 455 Program Slicing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SwE 455Program Slicing

  2. Our Goals • Debug your thousands lines of code easily by reducing the complexity of the program • Write a robust program before testing your code • Save your regression testing time by limiting the tests to only those that exercise the changed code

  3. Approach “Break your code into smaller pieces”

  4. Program Slicing • What is it? - A well-known program analysis and transformation technique that uses program statement dependence information to identify parts of a program that influence or are influenced by an initial set of program points of interest which is called the slice criteria - Introduced by Mark Weiser in his Ph.D. thesis (1979)

  5. indirectly relevant Slice Resulting slice Program Slicing (cont’d) • slicing criterion is provided by the user Slicing Criterion Source program

  6. Variants of Program Slicing • Many different variants of program slicing exist • Static Slicing • Backward Slicing • Forward Slicing • Dynamic Slicing • Conditional Slicing • Chopping • Also Many Different tools, however • Most program slicing tools are written for C but there are also some for C++ and Java • Most of these have problems with dynamic binding, inheritance, polymorphism and performance

  7. Example of backward slicing Static • Slice criterion <12,i> • 1 main( ) • 2 { • 3 int i, sum; • 4 sum = 0; • 5 i = 1; • 6 while(i <= 10) • 7 { • 8 Sum = sum + 1; • 9 ++ i; • 10 } • 11 Cout<< sum; • 12 Cout<< i; • 13 }

  8. Backward Slice Example public class SimpleExample { static int add(int a, int b){ return(a+b); } public static void main(final String[] arg){ inti = 1; int sum = 0; while (i < 11) { sum = add(sum, i); i = add(i, 1); } System.out.println("sum = " + sum); System.out.println("i = " + i); } } Slicing Criterion

  9. Example of forward static slicing • Slice criterion <3,sum> • 1 main( ) • 2 { • 3 int i, sum; • 4 sum = 0; • 5 i = 1; • 6 while(i <= 10) • 7 { • 8 sum = sum + 1; • 9 ++ i; • 10 } • 11 Cout<< sum; • 12 Cout<< i; • 13}

  10. Forward Slice Example public class SimpleExample { static int add(int a, int b){ return(a+b); } public static void main(final String[] arg){ inti = 1; int sum = 0; while (i < 11) { sum = add(sum, i); i = add(i, 1); } System.out.println("sum = " + sum); System.out.println("i = " + i); } } Slicing Criterion

  11. What is program slicing? • Program slice must satisfy the following conditions • Slice S(V,n) must be derived from P by deleting statements from P • Slice S(V,n) must be syntactically correct • For all executions of P, the value of V in the execution of S(V,n) just before the location n must be the same value of V in the execution of the program P just before location n

  12. Example of program slicing • Original program: • 1 begin • 2 read(x,y) • 3 total := 0.0 • 4 sum := 0.0 • 5 if x <= 1 • then sum := y • else begin • read(z) • total := x*y • end • 11 write(total, sum) • 12 end. Slice criterion: <9, x> begin read(x,y) end. Slice criterion: <12, z> begin read(x,y) if x <= 1 then else read(z) end. Slice criterion: <12, total> begin read(x,y) total := 0 if x <= 1 then else total := x*y end.

  13. Variants of program slicingStatic slices • Slice criterion <p, V> • Where p is a program point and V is a subset of program variables • Program slice on the slicing criterion <p, V> is a subset of program statements that preserves the behavior of the original program at the program point p with respect to the program variables in V

  14. Variants of program slicingStatic slices • Slices derived from the source code for all possible input values • No assumptions about input values • May lead to relatively big slices • Contains all statements that may affect a variable for every possible execution • Current static methods can only compute approximations

  15. Static slices example • Slice criterion (12,i) • 1 main( ) • 2 { • 3 int i, sum; • 4 sum = 0; • 5 i = 1; • 6 while(i <= 10) • 7 { • 8 sum = sum + 1; • 9 ++ i; • 10 } • 11 Cout<< sum; • 12 Cout<< i; • 13 }

  16. Example of dynamic slices • read (n) • for I := 1 to n do • a := 2 • if c1==1 then • if c2==1 then • a := 4 • else • a := 6 • z := a • write (z) • Assumptions • Input n is 1 • C1, c2 both true • Execution history is 11, 21, 31, 41, 51, 61, 91, 22, 101 • Slice criterion<1, 101, z>

  17. Applications of program slices • Program debugging • Was introduced by Mark Weiser as debugging aid • Slicing visualizes control and data dependencies • It highlights statements influencing the slice • Testing: reduce cost of regression testing after modifications (only run those tests that needed) • Integration : merging two programs A and B that both resulted from modifications to BASE

  18. Applications of program slices • Program understanding • Reverse engineering: comprehending the design by abstracting out of the source code the design decisions • Software maintenance: changing source code without unwanted side effects • Software quality assurance: validate interactions between safety-critical components

More Related