Title: Program Slicing
1Program Slicing
2Outline
- What is Program Slicing?
- Why Program Slicing?
- How to Slice Program?
- Slicing Classifications
- Applications
- Program Slicing Tools
- Conclusion
3What is Program Slicing?
- More descriptively, it is a decomposition
technique that extracts statements relevant to a
particular computation from a program. - Slicing Criterion lts, vgt
- Program Slices as Originally introduced by
Weiser1 are known as executable backward static
slices
4Why 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
5Why 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
6How?
- 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 lts , vgt, which specifies a location
(Statement s) and a variable (v).
7How? Contd...
- Intermediate Representation of programs for
slicing - Control Flow Graph (CFG)
- Data Flow equations are solved
- Program Dependence Graph (PDG)
- Slice is computed as graph reachability problem
8Slicing Example
- 1 main( )
- 2
- 3 int i, sum
- 4 sum 0
- 5 i 1
- 6 while(i lt 10)
- 7
- 8 sum sum 1
- 9 i
- 10
- 11 Coutltlt sum
- 12 Coutltlt i
- 13
- An Example Program its slice w.r.t. lt12, igt
9PDG of the Example Program
Control Dep. Edge Data Dep. Edge
1
3
12
4
5
6
11
Slice Point
8
9
10Slicing classifications
- Types of slices
- Static
- Dynamic
- Direction of slicing
- Backward
- Forward
- Executabiliy of slice
- Executable
- Closure
- Levels of slices
- Intraprocedural
- Interprocedural
11Slicing 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
12Slicing Properties
- Dynamic Slicing
- Computed on a given input
- Deterministic instead of Probabilistic
- Useful for applications that are input driven
(debugging, testing) - Slicing Criterion lti, p, vgt
13Example of Dynamic Slicing
- read (n)
- for I 1 to n do
- a 2
- if c11 then
- if c21 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 Criterionlt1, 101, zgt
14Backward 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
15Example of Backward Slicing
- 1 main( )
- 2
- 3 int i, sum
- 4 sum 0
- 5 i 1
- 6 while(i lt 10)
- 7
- 8 Sum sum 1
- 9 i
- 10
- 11 Coutltlt sum
- 12 Coutltlt i
- 13
- An Example Program its slice w.r.t. lt12, igt
16Forward 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
17Example of Forward Slicing
- 1 main( )
- 2
- 3 int i, sum
- 4 sum 0
- 5 i 1
- 6 while(i lt 10)
- 7
- 8 sum sum 1
- 9 i
- 10
- 11 Coutltlt sum
- 12 Coutltlt i
- 13
- An Example Program its slice w.r.t. lt3, sumgt
18Slicing 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
19Applications of Slicing
- Differencing
- Debugging
- Testing
- Program understanding
- Software maintenance
- Complexity measurement / Functional Cohesion
- Program integration
- Reverse engineering
- Software Quality Assurance
20Program Slicing Tools
- CodeSurfer
- Commercial product by GammaTech Inc.
- GUI Based
- Scripting language-Tk
- Unravel
- Static Program Slicer Developed at NIST
- Slices ANSI C programs
- Limitations are in the treatment of Unions, Forks
and pointers to functions
21Conclusion
- No Universal algorithm
- Improving performance
- New algorithms
22References
- 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.
23????