Docsity

Understanding Program Slicing: A Technique for Filtering Relevant Code in Software Systems, Study notes of Computer Science

Partial preview of the text

Download Understanding Program Slicing: A Technique for Filtering Relevant Code in Software Systems and more Study notes Computer Science in PDF only on Docsity!

Dependable Software Systems

Topics in

Program Slicing

Material drawn from [Weiser84,Gallagher91,DeMillo96]

What is a Program Slice?

  • A program slice is a subset of a program.
  • Program slicing enables programmers to view subsets of a program by filtering out code that is not relevant to the computation of interest.
  • E.g., if a program computes many things, including the average of a set of numbers, slicing can be used to isolate the code that computes the average.

Definition of Program Slice

  • Assume that:
    • P is a program.
    • V is the set of variables at a program location (line number) n.
  • A slice S(V,n) produces the portions of the program that contribute to the value of V just before the statement at location n is executed.
  • S(V,n) is called the slicing criteria.

A 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.

Slice S(num,26) main() {

  1. int tmp, num;
  2. tmp = readInt():
  3. num = 1;
  4. while(tmp >= 0)
  5. {
  6. ++num;
  7. tmp = readInt();
  8. }
  9. printf(“\nNum=%d”, num); }

Slice S(sum, 25) main() {

  1. int tmp, sum;
  2. tmp = readInt():
  3. sum = tmp;
  4. while(tmp >= 0)
  5. {
  6. sum += tmp;
  7. tmp = readInt();
  8. }
  9. printf(“\nSum=%d”, sum); }

Slice S(mn, 23) main() {

  1. int mn;
  2. int tmp;
  3. tmp = readInt():
  4. mn = tmp;
  5. while(tmp >= 0)
  6. {
  7. if (mn > tmp)
  8. mn = tmp;
  9. tmp = readInt();
  10. }
  11. printf(“\nMin=%d”, mn); }

Slice S(mx, 22) main() {

  1. int mx;
  2. int tmp;
  3. tmp = readInt():
  4. mx = tmp;
  5. while(tmp >= 0)
  6. {
  7. if (mx < tmp)
  8. mx = tmp;
  9. tmp = readInt();
  10. }
  11. printf(“\nMax=%d”, mx); }

Program Slicing Process

  • Select the slicing criteria (i.e., a variable or a set of variables and a program location).
  • Generate the program slice(s).
  • Perform testing and debugging on the slice(s). During this step a sliced program may be modified.
  • Merge the modified slice with the rest of the modified slices back into the original program.

Tools for Program Slicing

  • Spyder
    • A debugging tool based on program slicing.
  • Unravel
    • A program slicer for ANSI C.