Skip to content

Commit b423451

Browse files
committed
add tutorial scripts and example c code.
1 parent fa7d832 commit b423451

File tree

6 files changed

+65
-0
lines changed

6 files changed

+65
-0
lines changed

00_setup.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# download and extract intel pin
2+
pushd .
3+
cd ..
4+
wget https://software.intel.com/sites/landingpage/pintool/downloads/pin-3.27-98718-gbeaa5d51e-gcc-linux.tar.gz
5+
tar xf pin-3.27-98718-gbeaa5d51e-gcc-linux.tar.gz
6+
popd
7+
8+
# build CodeCoverage(this repository code)
9+
./build.sh
10+
11+
# build code coverage target example
12+
pushd .
13+
cd examples/c_function_call
14+
make
15+
popd
16+
17+
# run code coverage tool
18+

01_run_example.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../pin-3.27-98718-gbeaa5d51e-gcc-linux/pin -t ./obj-intel64/CodeCoverage.so -- examples/c_function_call/cov_sample 1 2

build.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
make PIN_ROOT=../pin-3.27-98718-gbeaa5d51e-gcc-linux
2+

examples/c_function_call/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
all:
2+
${CC} -g -gdwarf-4 main.c calc.c -o cov_sample
3+
4+
clean:
5+
rm -f cov_sample
6+

examples/c_function_call/calc.c

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int add(int a, int b)
2+
{
3+
return a+b;
4+
}

examples/c_function_call/main.c

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
extern int add(int, int);
5+
6+
int main(int argc, char **argv)
7+
{
8+
/*
9+
* With command line arg example, call function implemented in onother file(calc.c)
10+
* Comment lines are not count as executable lines.
11+
*/
12+
int a, b;
13+
int result = 0;
14+
15+
if (argc < 3) {
16+
// must input 2 number args
17+
fprintf(stderr, "input 2 numbers for calc add.\n");
18+
fprintf(stderr, "Usage) ./a.out 1 2\n");
19+
return -1;
20+
}
21+
22+
a = atoi(argv[1]);
23+
b = atoi(argv[2]);
24+
25+
result = add(a, b);
26+
27+
if (result < 10) {
28+
printf("a + b = %d, the answer is smaller than 10!\n", result);
29+
} else {
30+
printf("a + b = %d, the answer is greater than or equal to 10!\n", result);
31+
}
32+
33+
return 0;
34+
}

0 commit comments

Comments
 (0)