Professional Documents
Culture Documents
• Review; questions
• Assign (see Schedule for links)
• Slicing overview (cont’d)
• Problem Set 3: due 9/8/09
Program Slicing
1
Program Slicing
1. Slicing overview
2. Types of slices, levels of slices
3. Methods for computing slices
4. Interprocedural slicing (later)
Slicing Overview
2
Some History
Some History
3
Some History
Some History
4
Applications
y Debugging
y Program Comprehension
y Reverse Engineering
y Program Testing
y Measuring Program—metrics
y Coverage, Overlap, Clustering
y Refactoring
y Static Slicing
y Statically available information only
y No assumptions made on input
y Computed slice is in general inaccurate
y Identifying minimal slices is an undecidable problem Æ
approximations
y Results may not be useful
y Dynamic Slicing
y Computed on a given input
y Actual instead of may
y Useful for applications such as debugging and testing
11
5
Example
6
Types of Slicing (Backward Static)
7
Types of Slicing (Backward Static)
16
8
Types of Slicing (Backward Static)
9
Types of Slicing (Executable)
10
Types of Slicing (Forward Static)
11
Types of Slicing (Forward Static)
12
Types of Slicing (Dynamic)
13
Types of Slicing (Dynamic)
1. read (n)
2. for I := 1 to n do
3. a := 2
4. if c1 then
5. if c2 then
6. a := 4
7. else
8. a := 6
9. z := a
10. write (z)
14
Types of Slicing (Dynamic)
15
Types of Slicing (Dynamic)
16
Comparison of Static and Dynamic
17
Types of Slicing (Dynamic)
18
Types of Slicing (Execution)
19
Types of Slicing (Execution)
y Static backward
y Executable
y Static forward
y Dynamic
y Execution
41
20
Methods for Computing Slices
43
21
Methods (Data Flow on the CFG)
Definitions
i —>CFG j: there is a directed edge from i to j
Def(i): set of variables modified at statement i
Ref(i): variables referenced at statement I
Infl(i): Set of nodes that are influenced by i
(control dependent)
0
R C: Directly relevant variables
RkC: Indirectly relevant variables
S0C: Directly relevant statements
SkC: Indirectly relevant statements
BkC: Relevant branch statements
44
Definitions
i —>CFG j: there is a directed edge from i to j
Def(i): set of variables modified at statement i Local
Ref(i): variables referenced at statement I
Infl(i): Set of nodes that are influenced by i Computed
(control dependent) using CFG
0
R C: Directly relevant variables
RkC: Indirectly relevant variables
S0C: Directly relevant statements Propagated
k using CFG
S C: Indirectly relevant statements
BkC: Relevant branch statements
45
22
Methods (Data Flow on the CFG)
1. read (n)
2. i := 1 Criterion <10, product>
3. sum := 0
4. product := 1
5. while i <= n do
6. sum := sum + i
7. product := product * i
8. i := i + 1
9. write (sum)
10. write (product)
47
23
Methods (Data Flow on the CFG)
48
Iteration 0:
Variables used at criterion point are added;
looking for definitions that affect these uses
(for every i —> j)
49
24
Methods (Data Flow on the CFG)
Iteration 0:
(for every i —> j) CFG predecessors
50
Iteration 0:
(for every i —> j) CFG predecessors
51
25
Methods (Data Flow on the CFG)
Iteration 0:
(for every i —> j) CFG predecessors
52
Iteration 0:
(for every i —> j)
53
26
Methods (Data Flow on the CFG)
Iteration 0:
(for every i —> j)
54
Iteration 0:
(for every i —>CFG j)
Iteration k+1:
55
27
Methods (Data Flow on the CFG)
56
Note: You may not get these results for first iteration if
propagation is done in a different order.
57
28