Red Hat Training

A Red Hat training course is available for Red Hat Developer Toolset

Chapter 12. Valgrind

Valgrind is an instrumentation framework that ships with a number of tools for profiling applications. It can be used to detect various memory errors and memory-management problems, such as the use of uninitialized memory or an improper allocation and freeing of memory, or to identify the use of improper arguments in system calls. For a complete list of profiling tools that are distributed with the Red Hat Developer Toolset version of Valgrind, see Table 12.1, “Tools Distributed with Valgrind for Red Hat Developer Toolset”.
Valgrind profiles an application by rewriting it and instrumenting the rewritten binary. This allows you to profile your application without the need to recompile it, but it also makes Valgrind significantly slower than other profilers, especially when performing extremely detailed runs. It is therefore not suited to debugging time-specific issues, or kernel-space debugging.
Red Hat Developer Toolset is distributed with Valgrind 3.12.0. This version is more recent than the version included in the previous release of Red Hat Developer Toolset and provides numerous bug fixes and enhancements.

Table 12.1. Tools Distributed with Valgrind for Red Hat Developer Toolset

Name Description
Memcheck Detects memory management problems by intercepting system calls and checking all read and write operations.
Cachegrind Identifies the sources of cache misses by simulating the level 1 instruction cache (I1), level 1 data cache (D1), and unified level 2 cache (L2).
Callgrind Generates a call graph representing the function call history.
Helgrind Detects synchronization errors in multithreaded C, C++, and Fortran programs that use POSIX threading primitives.
DRD Detects errors in multithreaded C and C++ programs that use POSIX threading primitives or any other threading concepts that are built on top of these POSIX threading primitives.
Massif Monitors heap and stack usage.

12.1. Installing Valgrind

In Red Hat Developer Toolset, Valgrind is provided by the devtoolset-6-valgrind package and is automatically installed with devtoolset-6-perftools.
For detailed instructions on how to install Red Hat Developer Toolset and related packages to your system, see Section 1.5, “Installing Red Hat Developer Toolset”.


Note that if you use Valgrind in combination with the GNU Debugger, it is recommended that you use the version of GDB that is included in Red Hat Developer Toolset to ensure that all features are fully supported.