The Valgrind Quick Start Guide
The Valgrind Quick Start Guide
1. Introduction
The Valgrind tool suite provides a number of debugging and profiling tools. The most popular is Memcheck, a
memory checking tool which can detect many common memory errors such as:
• Touching memory you shouldn’t (eg. overrunning heap block boundaries, or reading/writing freed memory).
• Using values before they have been initialized.
• Incorrect freeing of memory, such as double-freeing heap blocks.
• Memory leaks.
Memcheck is only one of the tools in the Valgrind suite. Other tools you may find useful are:
• Cachegrind: a profiling tool which produces detailed data on cache (miss) and branch (misprediction) events.
Statistics are gathered for the entire program, for each function, and for each line of code, if you need that level of
detail.
• Callgrind: a profiling tool that shows cost relationships across function calls, optionally with cache simulation
similar to Cachegrind. Information gathered by Callgrind can be viewed either with an included command line
tool, or by using the KCachegrind GUI. KCachegrind is not part of the Valgrind suite -- it is part of the KDE
Desktop Environment.
• Massif: a space profiling tool. It allows you to explore in detail which parts of your program allocate memory.
• Helgrind: a debugging tool for threaded programs. Helgrind looks for various kinds of synchronisation errors in
code that uses the POSIX PThreads API.
• In addition, there are a number of "experimental" tools in the codebase. They can be distinguished by the "exp-"
prefix on their names. Experimental tools are not subject to the same quality control standards that apply to our
production-grade tools (Memcheck, Cachegrind, Callgrind, Massif and Helgrind).
1