blob: 8431741a40a240c99925847a727edf1644c94461 [file] [log] [blame]
njn3e986b22004-11-30 10:43:45 +00001<?xml version="1.0"?> <!-- -*- sgml -*- -->
2<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5<chapter id="manual-intro" xreflabel="Introduction">
6<title>Introduction</title>
7
8<sect1 id="manual-intro.overview" xreflabel="An Overview of Valgrind">
9<title>An Overview of Valgrind</title>
10
debad57fc2005-12-03 22:33:29 +000011<para>Valgrind is a suite of simulation-based debugging and profiling
12tools for programs running on Linux (x86, amd64 and ppc32). The system
13consists of a core, which provides a synthetic CPU in software, and a
14series of tools, each of which performs some kind of debugging,
15profiling, or similar task. The architecture is modular, so that new
16tools can be created easily and without disturbing the existing
njn3e986b22004-11-30 10:43:45 +000017structure.</para>
18
19<para>A number of useful tools are supplied as standard. In
20summary, these are:</para>
21
22<orderedlist>
23
24 <listitem>
debad57fc2005-12-03 22:33:29 +000025 <para><command>Memcheck</command> detects memory-management problems
26 in your programs. All reads and writes of memory are checked, and
27 calls to malloc/new/free/delete are intercepted. As a result,
28 Memcheck can detect the following problems:</para>
njn3e986b22004-11-30 10:43:45 +000029
30 <itemizedlist>
31 <listitem>
32 <para>Use of uninitialised memory</para>
33 </listitem>
34 <listitem>
35 <para>Reading/writing memory after it has been
36 free'd</para>
37 </listitem>
38 <listitem>
39 <para>Reading/writing off the end of malloc'd
40 blocks</para>
41 </listitem>
42 <listitem>
43 <para>Reading/writing inappropriate areas on the
44 stack</para>
45 </listitem>
46 <listitem>
47 <para>Memory leaks -- where pointers to malloc'd
48 blocks are lost forever</para>
49 </listitem>
50 <listitem>
51 <para>Mismatched use of malloc/new/new [] vs
52 free/delete/delete []</para>
53 </listitem>
54 <listitem>
55 <para>Overlapping <computeroutput>src</computeroutput> and
56 <computeroutput>dst</computeroutput> pointers in
57 <computeroutput>memcpy()</computeroutput> and related
sewardj053fe982005-11-15 19:51:04 +000058 functions</para></listitem>
njn3e986b22004-11-30 10:43:45 +000059 </itemizedlist>
60
debad57fc2005-12-03 22:33:29 +000061 <para>Problems like these can be difficult to find by other means,
62 often lying undetected for long periods, then causing occasional,
63 difficult-to-diagnose crashes.</para>
njn3e986b22004-11-30 10:43:45 +000064 </listitem>
65
66 <listitem>
njn3e986b22004-11-30 10:43:45 +000067 <para><command>Cachegrind</command> is a cache profiler. It
debad57fc2005-12-03 22:33:29 +000068 performs detailed simulation of the I1, D1 and L2 caches in your CPU
69 and so can accurately pinpoint the sources of cache misses in your
70 code. If you desire, it will show the number of cache misses,
71 memory references and instructions accruing to each line of source
72 code, with per-function, per-module and whole-program summaries. If
73 you ask really nicely it will even show counts for each individual
74 machine instruction.</para>
njn3e986b22004-11-30 10:43:45 +000075
njn779a2d62005-07-25 00:12:19 +000076 <para>On x86 and AMD64, Cachegrind auto-detects your machine's cache
debad57fc2005-12-03 22:33:29 +000077 configuration using the <computeroutput>CPUID</computeroutput>
78 instruction, and so needs no further configuration info, in most
79 cases.</para>
njn3e986b22004-11-30 10:43:45 +000080
debad57fc2005-12-03 22:33:29 +000081 <para>Cachegrind is nicely complemented by Josef Weidendorfer's
82 amazing KCacheGrind visualisation tool
de252c6142005-11-27 04:10:00 +000083 (<ulink url="http://kcachegrind.sourceforge.net/cgi-bin/show.cgi/KcacheGrindIndex">http://kcachegrind.sourceforge.net</ulink>),
njn3e986b22004-11-30 10:43:45 +000084 a KDE application which presents these profiling results in a
85 graphical and easier-to-understand form.</para>
86 </listitem>
87
88 <listitem>
debad57fc2005-12-03 22:33:29 +000089 <para><command>Helgrind</command> finds data races in multithreaded
90 programs. Helgrind looks for memory locations which are accessed by
91 more than one (POSIX p-)thread, but for which no consistently used
92 (pthread_mutex_)lock can be found. Such locations are indicative of
93 missing synchronisation between threads, and could cause
94 hard-to-find timing-dependent problems.</para>
njn3e986b22004-11-30 10:43:45 +000095
debad57fc2005-12-03 22:33:29 +000096 <para>Helgrind ("Hell's Gate", in Norse mythology) implements the
97 so-called "Eraser" data-race-detection algorithm, along with various
98 refinements (thread-segment lifetimes) which reduce the number of
99 false errors it reports. It is as yet somewhat of an experimental
100 tool, so your feedback is especially welcomed here.</para>
njn3e986b22004-11-30 10:43:45 +0000101
102 <para>Helgrind has been hacked on extensively by Jeremy
103 Fitzhardinge, and we have him to thank for getting it to a
104 releasable state.</para>
sewardj053fe982005-11-15 19:51:04 +0000105
debad57fc2005-12-03 22:33:29 +0000106 <para>NOTE: Helgrind is, unfortunately, not available in Valgrind
107 3.1.X, as a result of threading changes that happened in the 2.4.0
108 release. We hope to reinstate its functionality in a future 3.2.0
109 release.</para>
njn3e986b22004-11-30 10:43:45 +0000110 </listitem>
111
112</orderedlist>
113
114
debad57fc2005-12-03 22:33:29 +0000115<para>A couple of minor tools (<command>Lackey</command> and
116<command>Nulgrind</command>) are also supplied. These aren't
117particularly useful -- they exist to illustrate how to create simple
118tools and to help the valgrind developers in various ways. Nulgrind is
119the null tool -- it adds no instrumentation. Lackey is a simple example
120tool which counts instructions, memory accesses, and the number of
sewardj053fe982005-11-15 19:51:04 +0000121integer and floating point operations your program does.</para>
njn3e986b22004-11-30 10:43:45 +0000122
njn779a2d62005-07-25 00:12:19 +0000123<para>Valgrind is closely tied to details of the CPU and operating
124system, and to a lesser extent, the compiler and basic C libraries.
debad57fc2005-12-03 22:33:29 +0000125Nonetheless, as of version 3.1.0 it supports several platforms:
126x86/Linux (mature), AMD64/Linux (maturing), and PPC32/Linux (immature
127but works well). Valgrind uses the standard Unix
njn3e986b22004-11-30 10:43:45 +0000128<computeroutput>./configure</computeroutput>,
129<computeroutput>make</computeroutput>, <computeroutput>make
debad57fc2005-12-03 22:33:29 +0000130install</computeroutput> mechanism, and we have attempted to ensure that
131it works on machines with kernel 2.4 or 2.6 and glibc
sewardj053fe982005-11-15 19:51:04 +00001322.2.X--2.3.X.</para>
njn3e986b22004-11-30 10:43:45 +0000133
134<para>Valgrind is licensed under the <xref linkend="license.gpl"/>,
debad57fc2005-12-03 22:33:29 +0000135version 2. The <computeroutput>valgrind/*.h</computeroutput> headers
136that you may wish to include in your code (eg.
137<filename>valgrind.h</filename>, <filename>memcheck.h</filename>) are
138distributed under a BSD-style license, so you may include them in your
139code without worrying about license conflicts. Some of the PThreads
140test cases, <filename>pth_*.c</filename>, are taken from "Pthreads
141Programming" by Bradford Nichols, Dick Buttlar &amp; Jacqueline Proulx
142Farrell, ISBN 1-56592-115-1, published by O'Reilly &amp; Associates,
143Inc.</para>
njn3e986b22004-11-30 10:43:45 +0000144
145</sect1>
146
147
148<sect1 id="manual-intro.navigation" xreflabel="How to navigate this manual">
149<title>How to navigate this manual</title>
150
debad57fc2005-12-03 22:33:29 +0000151<para>The Valgrind distribution consists of the Valgrind core, upon
152which are built Valgrind tools, which do different kinds of debugging
153and profiling. This manual is structured similarly.</para>
njn3e986b22004-11-30 10:43:45 +0000154
debad57fc2005-12-03 22:33:29 +0000155<para>First, we describe the Valgrind core, how to use it, and the flags
156it supports. Then, each tool has its own chapter in this manual. You
157only need to read the documentation for the core and for the tool(s) you
158actually use, although you may find it helpful to be at least a little
njne5eaf3a2006-10-23 21:21:48 +0000159bit familar with what all tools do. If you're new to all this, you probably
160want to run the Memcheck tool. The final chapter explains how to write a
161new tool.</para>
njn3e986b22004-11-30 10:43:45 +0000162
debad57fc2005-12-03 22:33:29 +0000163<para>Be aware that the core understands some command line flags, and
164the tools have their own flags which they know about. This means there
165is no central place describing all the flags that are accepted -- you
166have to read the flags documentation both for
167<xref linkend="manual-core"/> and for the tool you want to use.</para>
njn3e986b22004-11-30 10:43:45 +0000168
169</sect1>
170
171</chapter>