Sie sind auf Seite 1von 22

Program Slicing

Binoy Ketan Dash

Outline

What is Program Slicing? Why Program Slicing? How to Slice Program? Slicing Classifications Applications Program Slicing Tools Conclusion

What is Program Slicing?

More descriptively, it is a decomposition technique that extracts statements relevant to a particular computation from a program. Slicing Criterion <s, v> Program Slices as Originally introduced by Weiser[1] are known as executable backward static slices

Why Program Slicing?


Program Debugging: thats how slicing was discovered! Testing: reduce cost of regression testing after modifications (only run those tests that needed) Parallelization Integration : merging two programs A and B that both resulted from modifications to BASE

Why Program Slicing?


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

How?

A slice is constructed by deleting those parts of a program which is irrelevant to the program with respect to the chosen set of variables at the chosen point. A slice is taken from a program with the slicing criterion <s , v>, which specifies a location (Statement s) and a variable (v).

How?

Contd...

Intermediate Representation of programs for slicing:

Control Flow Graph (CFG)

Data Flow equations are solved Slice is computed as graph reachability problem

Program Dependence Graph (PDG)

Slicing Example
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 }

An Example Program & its slice w.r.t. <12, i>

Slicing classifications

Types of slices

Static Dynamic Backward Forward Executable Closure Intraprocedural Interprocedural

Direction of slicing

Executabiliy of slice

Levels of slices

Slicing Properties

Static Slicing

Statically available information only No assumptions made on input Computed slice can never be accurate (minimal slice) Problem is undecidable reduction to the halting problem Current static methods can only compute approximations Result may not be usefull

Slicing Properties

Dynamic Slicing

Computed on a given input Deterministic instead of Probabilistic Useful for applications that are input driven (debugging, testing) Slicing Criterion <i, p, v>

Example of Dynamic Slicing


1. 2. 3. 4. 5. 6. 7. 8.

9.
10.

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)

Input n is 1; c1, c2 both true Execution history is 11, 21, 31, 41, 51, 61, 91, 22, 101
Criterion<1, 101, z>

Backward Static Slicing

A backward slice of a program with respect to a program point p and set of program variables V consists of all statements and predicates in the program that may affect the value of variables in V at p

Example of Backward Slicing


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 }

An Example Program & its slice w.r.t. <12, i>

Forward Static Slicing

A forward slice of a program with respect to a program point p and set of program variables V consists of all statements and predicates in the program that may be affected by the value of variables in V at p

Example of Forward Slicing


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 } An Example Program & its slice w.r.t. <3, sum>

Slicing Properties

Intraprocedural Slicing

Computes slice within one procedure Assumes worse case for function calls

Interprocedural Slicing

Compute slice over an entire program Two ways for crossing procedure boundary

Up going from sliced procedure into calling procedure Down going from sliced procedure into called procedure

Must Be Context Sensitive

Applications of Slicing

Differencing Debugging Testing Program understanding Software maintenance Complexity measurement / Functional Cohesion Program integration Reverse engineering Software Quality Assurance

Program Slicing Tools

CodeSurfer

Commercial product by GammaTech Inc. GUI Based Scripting language-Tk Static Program Slicer Developed at NIST Slices ANSI C programs Limitations are in the treatment of Unions, Forks and pointers to functions

Unravel

Conclusion

No Universal algorithm Improving performance New algorithms

References

[1] M. Weiser. Program Slicing. In Proceedings of the Fifth International Conference on Software Engineering, pages 439-449, May 1981. [2] D. Binkley, K. Gallagher. Program Slicing. In Proceedings of In Advances in Computers, Volume 43, 1996. [3] H.Agrawal, J. Horgan. Dynamic Program Slicing. In Proceedings of the ACM SIGPLAN90 [4] A. DeLucia. Program Slicing: Methods and Applications. IEEE workshop on Source Code Analysis and Manipulation (SCAM 2001) [5] K. B. Gallagher and J. R. Lyle. Using Program Slicing in Software Maintenance. IEEE Transactions on Software Engineering, 17(8), pages 751-761, August 1991.

????