Program Slicing - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Program Slicing

Description:

A static slice S(Si,v) of variable v at statement number Si is defined as the ... taken into account when transitive closure is taken while computing the slice. ... – PowerPoint PPT presentation

Number of Views:122
Avg rating:3.0/5.0
Slides: 15
Provided by: neelam3
Category:
Tags: program | slicing

less

Transcript and Presenter's Notes

Title: Program Slicing


1
Program Slicing
  • Neelam Gupta
  • The University of Arizona
  • Tucson, Arizona, USA

2
Program Slice
  • A program slice contains the statements in a
    program that affect the value of a variable
    computed at some designated point (statement) of
    interest in the program.
  • Static Slice is computed using statically
    available information.
  • Dynamic Slice assumes a specific execution of the
    program.

3
  • Slicing criterion (program point, set of
    variables).
  • A static slice S(Si,v) of variable v at statement
    number Si is defined as the transitive closure of
    data and control dependences of v at Si
  • set of statements on which the value of v at Si
    is directly or indirectly data or control
    dependent.

4
  • Data dependence refers to value dependence.
  • For example, in the following program value of
    X in statement 3 is data dependent on statement
    1.
  • 1. Y 2 W
  • 2. U 2 W
  • 3. X 2 Y

5
  • Control dependence statement S is directly
    control dependent upon predicate P if the output
    of P (true or false) determines whether or not S
    will be executed.
  • Example
  • S0
  • while P1 do
  • S1
  • if P2 then S2 else S3 endif
  • S4
  • endwhile
  • S0 and P1 are not directly control dependent upon
    any other predicate.
  • S1, P2, and S4 are directly control dependent
    upon P1
  • S2 and S3 are directly control dependent upon P2
  • Note we have considered only direct(immediate)
    control dependence above.

6
  • The indirect dependences are taken into account
    when transitive closure is taken while computing
    the slice.
  • Note that so far we are referring to only
    backward program slice, i.e. the statements on
    which value of v at Si is directly or indirectly,
    control or data dependent is computed backwards
    starting from statement Si.

7
Example
  • Read(n)
  • I 1
  • Sum 0
  • Product 1
  • While Iltn do
  • sum sum I
  • product product I
  • I I 1
  • Endwhile
  • Write(sum)
  • Write(product)

Read(n) I 1 Product 1 While Iltn do
product product I I I
1 Endwhile Write(product)
Example Program
Backward Static Slice for variable product at
last statement
8
  • A dynamic slice D(Si,v,I) of variable v at
    statement instance Si along the execution trace
    for a program input I is defined as the
    transitive closure of data and control
    dependences of v at Si over the set of statements
    that are executed with input I.

9
Example
  • Read(n)
  • I 1
  • Sum 0
  • Product 1
  • While Iltn do
  • sum sum I
  • product product I
  • I I 1
  • Endwhile
  • Write(sum)
  • Write(product)

Read(n) I 1 Product 1 While Iltn do
product product I I I
1 Endwhile Write(product)
Product 1 Write(product)
Example Program
Static Slice for variable product at last
statement
Dynamic Slice for variable product for n0
10
(No Transcript)
11
Dynamic slice of res1 at statement 18 for input
val -12.1
Dynamic slice of res1 at statement 18 for input
val 9.5
12
Dynamic slice of res2 at statement 18 for input
val 9.5
Dynamic slice of res2 at statement 18 for input
val -12.1
13
  • A Static slice contains union of the statements
    in all the dynamic slices of the given variable
    at the point of interest in the program. However,
    it may also contain some statements that may
    never belong to any dynamic slice for the given
    slicing criterion.
  • Therefore static slices are conservative in
    estimating the statements that may affect the
    value of a variable at a point in a program.

14
  • In a forward slice we are interested in
    considering only those statements in which the
    value of a variable v at a statement Si can be
    used directly or indirectly (we are considering
    only reachable uses of value of v at Si).
  • Backward slice is useful in debugging
  • Forward slice is useful in determining which all
    statements in a program can be effected by
    change in value of v at statement Si.
Write a Comment
User Comments (0)
About PowerShow.com