How to install NIONKA-x86

NIONKA-x86 is implemented with the help of Valgrind, an instrumentation framework for building dynamic analysis tools. More precisely, it is build on the top of Memcheck, Valgrind's tool for detection of memory errors in C and C++ programs. The installation process consists of checking out Valgrind, patching Memcheck with Nionka-x86 modifications and compiling Valgrind.

  1. Download and extract nionka-x86.tar.gz

    $ wget http://peshko.net/nionka/nionka-x86.tar.gz
    $ tar xvzpf nionka-x86.tar.gz
    $ cd nionka-x86
  2. Check out Valgrind's latest version.

    $ svn co svn://svn.valgrind.org/valgrind/trunk valgrind
  3. Patch Memcheck with Nionka's modifications and copy necessary files.

    $ patch valgrind/memcheck/mc_main.c < nionka_patch/mc_main.patch
    $ patch valgrind/memcheck/mc_translate.c < nionka_patch/mc_translate.patch
    $ cp nionka_patch/hijack.h valgrind/memcheck/
  4. Compile Valgrind

    $ cd valgrind
    $ autogen.sh
    $ ./configure --prefix=$VALGRIND-BIN**
    $ make
    $ make install

    **$VALGRIND-BIN is the place where you want to store Valgrind's binary files. You need to add this directory to your PATH in order to run valgrind without specifying the absolute path to the executable.

How to test if the installation was successful

  1. Go to test directory and compile test.c

    $ cd ../test
    $ gcc -g test.c -o test
  2. Check the output of the normal execution.

    $ ./test 1 1
    arg1 is true
    arg2 is true
  3. Check the output of the hijacked execution.

    $ valgrind --hijack=yes --branches-file=test.branches --fileslist=test.files --coverage-file=test.cov ./test 1 1
    The output has to be similar to this:
    ==5713== Memcheck, a memory error detector
    ==5713== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
    ==5713== Using Valgrind-3.6.0.SVN and LibVEX; rerun with -h for copyright info
    ==5713== Command: ./test 1 1
    ==5713==
    arg1 is false
    arg2 is true
    ==5713==
    ==5713== HEAP SUMMARY:
    ==5713== in use at exit: 0 bytes in 0 blocks
    ==5713== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
    ==5713==
    ==5713== All heap blocks were freed -- no leaks are possible
    ==5713==
    ==5713== For counts of detected and suppressed errors, rerun with: -v
    ==5713== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)

    Important to check is that arg1 is exercised as "false". If this is the case, then your NIONKA-x86 installation was successful.

How to use NIONKA-x86

In order to use NIONKA-x86 you must compile your executable with debugging information using the -g flag.

To run Memcheck in execution hijacking mode you need to run Valgrind with the --hijack=yes argument. Running Memcheck in execution hijacking mode requires also the following arguments:

--branches-file=file1
--fileslist=file2
--coverage-file=file3

Where

  • file1 is the file indicating which predicates' outcome to be flipped at runtime. The predicates are identified by the name of source file and line number. For example, if you want to flip the outcome of the predicate located at line 13 in test.c, you need to add "test.c:13" to
  • file2 is a file containing the source file names of the program. The file contains one source file name per line.
  • file3 is a file where the coverage information is stored.