Valgrind User Manual

Release 3.3.1 4 June 2008


Table of Contents

1. Introduction
1.1. An Overview of Valgrind
1.2. How to navigate this manual
2. Using and understanding the Valgrind core
2.1. What Valgrind does with your program
2.2. Getting started
2.3. The Commentary
2.4. Reporting of errors
2.5. Suppressing errors
2.6. Command-line flags for the Valgrind core
2.6.1. Tool-selection option
2.6.2. Basic Options
2.6.3. Error-related options
2.6.4. malloc()-related Options
2.6.5. Uncommon Options
2.6.6. Debugging Valgrind Options
2.6.7. Setting default Options
2.7. Support for Threads
2.8. Handling of Signals
2.9. Building and Installing Valgrind
2.10. If You Have Problems
2.11. Limitations
2.12. An Example Run
2.13. Warning Messages You Might See
3. Using and understanding the Valgrind core: Advanced Topics
3.1. The Client Request mechanism
3.2. Function wrapping
3.2.1. A Simple Example
3.2.2. Wrapping Specifications
3.2.3. Wrapping Semantics
3.2.4. Debugging
3.2.5. Limitations - control flow
3.2.6. Limitations - original function signatures
3.2.7. Examples
4. Memcheck: a heavyweight memory checker
4.1. Kinds of bugs that Memcheck can find
4.2. Command-line flags specific to Memcheck
4.3. Explanation of error messages from Memcheck
4.3.1. Illegal read / Illegal write errors
4.3.2. Use of uninitialised values
4.3.3. Illegal frees
4.3.4. When a block is freed with an inappropriate deallocation function
4.3.5. Passing system call parameters with inadequate read/write permissions
4.3.6. Overlapping source and destination blocks
4.3.7. Memory leak detection
4.4. Writing suppression files
4.5. Details of Memcheck's checking machinery
4.5.1. Valid-value (V) bits
4.5.2. Valid-address (A) bits
4.5.3. Putting it all together
4.6. Client Requests
4.7. Memory Pools: describing and working with custom allocators
4.8. Debugging MPI Parallel Programs with Valgrind
4.8.1. Building and installing the wrappers
4.8.2. Getting started
4.8.3. Controlling the wrapper library
4.8.4. Abilities and limitations
4.8.5. Writing new wrappers
4.8.6. What to expect when using the wrappers
5. Cachegrind: a cache and branch profiler
5.1. Cache and branch profiling
5.1.1. Overview
5.1.2. Cache simulation specifics
5.1.3. Branch simulation specifics
5.2. Profiling programs
5.2.1. Output file
5.2.2. Cachegrind options
5.2.3. Annotating C/C++ programs
5.2.4. Annotating assembly code programs
5.2.5. Forking Programs
5.3. cg_annotate options
5.3.1. Warnings
5.3.2. Things to watch out for
5.3.3. Accuracy
5.4. Merging profiles with cg_merge
5.5. Acting on Cachegrind's information
5.6. Implementation details
5.6.1. How Cachegrind works
5.6.2. Cachegrind output file format
6. Callgrind: a call graph profiler
6.1. Overview
6.1.1. Functionality
6.1.2. Basic Usage
6.2. Advanced Usage
6.2.1. Multiple profiling dumps from one program run
6.2.2. Limiting the range of collected events
6.2.3. Avoiding cycles
6.3. Command line option reference
6.3.1. Miscellaneous options
6.3.2. Dump creation options
6.3.3. Activity options
6.3.4. Data collection options
6.3.5. Cost entity separation options
6.3.6. Cache simulation options
7. Helgrind: a thread error detector
7.1. Overview
7.2. Detected errors: Misuses of the POSIX pthreads API
7.3. Detected errors: Inconsistent Lock Orderings
7.4. Detected errors: Data Races
7.4.1. A Simple Data Race
7.4.2. Helgrind's Memory State Machine
7.4.3. Transfers of Exclusive Ownership Between Threads
7.4.4. Restoration of Exclusive Ownership
7.4.5. A Summary of the Race Detection Algorithm
7.4.6. Interpreting Race Error Messages
7.5. Hints and Tips for Effective Use of Helgrind
7.6. Helgrind Options
7.7. A To-Do List for Helgrind
8. Massif: a heap profiler
8.1. Heap profiling
8.2. Using Massif
8.2.1. An Example Program
8.2.2. The Output Preamble
8.2.3. The Output Graph
8.2.4. The Snapshot Details
8.2.5. Forking Programs
8.3. Massif Options
8.4. ms_print Options
8.5. Massif's output file format
9. Nulgrind: the "null" tool
10. Lackey: a simple profiler and memory tracer
10.1. Overview
10.2. Lackey Options
11. Writing a New Valgrind Tool
11.1. Introduction
11.1.1. Tools
11.2. Writing a Tool
11.2.1. How tools work
11.2.2. Getting the code
11.2.3. Getting started
11.2.4. Writing the code
11.2.5. Initialisation
11.2.6. Instrumentation
11.2.7. Finalisation
11.2.8. Other Important Information
11.2.9. Words of Advice
11.3. Advanced Topics
11.3.1. Suppressions
11.3.2. Documentation
11.3.3. Regression Tests
11.3.4. Profiling
11.3.5. Other Makefile Hackery
11.3.6. Core/tool Interface Versions
11.4. Final Words