Skip to content
Mingliang Liu edited this page Jan 14, 2016 · 7 revisions

Here is the example case, the example 1 of the paper Dynamic Program Slicing

The example code

1. #include <math.h>
2. #include <stdio.h>
3. #include <stdlib.h>
4.
5. int main(int argc, char *argv[])
6. {
7.    int x, y, z;
8.
9.    x = atoi(argv[1]);
10.
11.   if (x < 0)
12.   {
13.      y = sqrt(x);
14.      z = pow(2, x);
15.    } else {
16.        if (x == 0)
17.        {
18.            y = sqrt(x * 2);
19.            z = pow(3, x);
20.        } else {
21.            y = sqrt(x * 3);
22.            z = pow(4, x);
23.        }
24.    }
25.
26.    printf("%d\n", y);
27.    printf("%d\n", z);
28.
29.    return z;
30.}

Given the input x = 10, we can see that the source line numbers affect the printf statement at line 27 are: 9, 22, 27

Run Without Parameters

The default slicing criterion is the ret instruction at the main function. Notice that there is only one return when the main executes in dynamic slicing. Just 'make' will give you the same result since the z was used in the ret instruction.

Run With Line number of Code

The most convenient way to use Giri is to slice from one line of a source file.

  • Make Giri code, see How To Compile Giri
  • cd test/UnitTests/test4
  • echo example.c 27 > loc.txt # we'd like to slice from the line 27 of example.c
  • make CRITERION="-criterion-loc=loc.txt"

Run With Instruction Count

Sometime you would like to specify the slicing criterion by naming the instruction count for a given function. Thus you should provide the function name and the instruction number. Every instruction is assigned with a unique number by the SourceLineMapping pass.

  • Make Giri code, see How To Compile Giri
  • cd test/UnitTests/test4
  • make mapping MAPPING="-mapping-function=main"
  • view the stdout to find the number of the instruction you'd like to start with, say it's 65
  • echo main 65 > inst.txt # we'd like to slice from the 65th instruction of main function
  • make CRITERION="-criterion-inst=inst.txt"