Saturday, 15 July 2017

Get hands on Valgrind Utility

Valgrind utility can be used for many purpose
- Memory error detection
- Two Thread error detection
- A cache
- Branch prediction profiler
- A call-graph generating cache profiler, and a heap profiler. It also includes two experimental tools: a heap/stack/global array overrun detector, and a SimPoint basic block vector generator.

Before using the valgrind you need to install it on your computer. Installation process might defer according to the linux flavour you are using. I am using opensuse linux.

#zypper install valgrind

How Do I use valgrind?

Before running the program you need to put the command:

valgrind --leak-check=yes ./a.out arg1 arg2
valgrind --log-file=outfile.file --leak-check=yes --tool=memcheck ./a.out arg1 arg2

You can use other option like:
 --leak-check=full --show-leak-kinds=all

-A program running under Valgrind is not executed directly by the CPU. Instead it runs on a synthetic CPU provided by Valgrind. This is why a debugger cannot debug your program when it runs on Valgrind