TraceMem is a compiler pass built on LLVM that instruments program loads and stores in a rotating log.
Once you've downloaded the project you need to do the following in the project directory:
- cd TraceMem/llvm/tools
- ln -s ../../clang .
- cd ../projects
- ln -s ../../compiler-rt .
- cd ../../..
- mkdir TraceMem-build
- cd TraceMem-build
- ../TraceMem/llvm/configure
- make
- export PATH=$PWD/Release+Asserts/bin:$PATH
Now we need to build the TraceMem library
- cd ..
- mkdir libtracemem-build
- cd libtracemem-build
- cmake ../TraceMem/libtracemem/
- make
At this point you have everything to compile programs with TraceMem instrumentation. The samples directory contains some example programs that can be compiled as follows:
clang++ series.cpp -S -emit-llvm -o series.ll
opt -mem2reg -load ../../TraceMem-build/Release+Asserts/lib/LLVMTraceMem.dylib -stats -TraceMem series.ll -o series.bc
clang++ series.bc -L../../libtracemem-build/ -lTraceMem -o series
Upon program terminatation the memory traces are written to a file.