Debcov is a coverage-based debloating tool. It accepts as input a program and a set of coverage files (in gcov format that shows what code is covered during execution). As output, it produces a reduced program with all the code that is not covered eliminated.
- CMake >= 3.11
- Clang and LibClang >= 7.0
- spdlog >= 1.3.1
- ROPgadget >= 5.8
Make sure you have installed all the required libraries (shown above).
Once you have all the requirements, do the following steps.
- Run
./compile_java
. - In CMakeLists.txt, change to your own paths the last two
include_directories
(lines ending with "Change to your own path!"). - Run
cd build
. - Run
cmake ..
. - Run
make
.
DEBCOV_BIN SOURCE_FILE COVERAGE_FILE/DIR
DEBCOV_BIN: The debcov binary (bin/debcov). NOTE: If you haven't done so, change DEBCOVDIR to your own path in this file. SOURCE_FILE: The program source file. COVERAGE_FILE/DIR: A coverage file (or a directory) generated by gcov (with the -i option). Please refer to https://gcc.gnu.org/onlinedocs/gcc/Gcov.html for more information.
cd test
../bin/debcov mkdir-5.2.1.c mkdir-5.2.1.c.gcov
mkdir-5.2.1.c.gcov
contains the coverage information derived from running the program instrumented against two inputs: (1) dir
and (2) -p foo/bar
. What's generated as a result is a file named mkdir-5.2.1.reduced.c
. Now compile the resulting program by running gcc -w -o mkdir-5.2.1.reduced mkdir-5.2.1.reduced.c
and see if it can produce the correct outputs for the two inputs.
To generate mkdir-5.2.1.c.gcov
, try the following.
./clean.sh
gcc -w -fprofile-arcs -ftest-coverage -o mkdir-5.2.1 mkdir-5.2.1.c
./mkdir-5.2.1 dir
./mkdir-5.2.1 -p foo/bar
gcov -i mkdir-5.2.1.c