This write-up covers some very basis commands. But I will try to list out some of the other collections of tutorial and reading to complement this lack of information. I’m assuming that you have compiled the program as written in Compiling Valgrind on CentOS 5
One of the most commonly used command in Valgrind is
# valgrind --tool=memcheck --leak-check=full ./my_program
|| –leak-check=<no|summary|yes|full> [default: summary]
|| When enabled, search for memory leaks when the client program finishes. If set to summary, it says how many leaks occurred. If set to full or yes, it also gives details of each individual leak.
|| –show-reachable=<yes|no> [default: no]
|| When disabled, the memory leak detector only shows “definitely lost” and “possibly lost” blocks. When enabled, the leak detector also shows “reachable” and “indirectly lost” blocks. (In other words, it shows all blocks, except suppressed ones)
For more information on more details usage of Valgrind of options and how to use,
- Valgrind Manual – 4.3 Memcheck Command Options
- Using Valgrind to Find Memory Leaks and Invalid Memory Use
- Using Valgrind to debug memory leaks
Valgrind tools automatically detect many memory management and threading bugs, and is able to profile your programs in detail. It runs on the following platforms: X86/Linux, AMD64/Linux, ARM/Linux, PPC32/Linux, PPC64/Linux, S390X/Linux, ARM/Android (2.3.x), X86/Darwin and AMD64/Darwin (Mac OS X 10.6 and 10.7)
According to Valgrind, a number of useful tools are supplied as standard.
- Memcheck is a memory error detector. It helps you make your programs, particularly those written in C and C++, more correct.
- Cachegrind is a cache and branch-prediction profiler. It helps you make your programs run faster.
- Callgrind is a call-graph generating cache profiler. It has some overlap with Cachegrind, but also gathers some information that Cachegrind does not.
- Helgrind is a thread error detector. It helps you make your multi-threaded programs more correct.
- DRD is also a thread error detector. It is similar to Helgrind but uses different analysis techniques and so may find different problems.
- Massif is a heap profiler. It helps you make your programs use less memory.
- DHAT is a different kind of heap profiler. It helps you understand issues of block lifetimes, block utilisation, and layout inefficiencies.
- SGcheck is an experimental tool that can detect overruns of stack and global arrays. Its functionality is complementary to that of Memcheck: SGcheck finds problems that Memcheck can’t, and vice versa..
- BBV is an experimental SimPoint basic block vector generator. It is useful to people doing computer architecture research and development.
Compilation of Valgrind
Compilation is very straightforward……
# tar -xvjpf valgrind-3.7.0.tar.bz2
# cd valgrind-3.7.0
# ./configure --prefix=/usr/local/valgrind-3.7.0
# make; make install
# /usr/local/valgrind-3.7.0/bin/valgrind ls -l
Either this works, or it bombs out with some complaint.