blob: 7d556fc7f708e70f965e881b979c4cc543539ba5 [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"
de252c6142005-11-27 04:10:00 +00003 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
4[ <!ENTITY % vg-entities SYSTEM "vg-entities.xml"> %vg-entities; ]>
5
njn3e986b22004-11-30 10:43:45 +00006
7<chapter id="manual-core" xreflabel="Valgrind's core">
8<title>Using and understanding the Valgrind core</title>
9
sewardja5fac792007-11-25 00:55:11 +000010<para>This chapter describes the Valgrind core services, flags and
debad57fc2005-12-03 22:33:29 +000011behaviours. That means it is relevant regardless of what particular
sewardja5fac792007-11-25 00:55:11 +000012tool you are using. The information should be sufficient for you to
13make effective day-to-day use of Valgrind. Advanced topics related to
14the Valgrind core are described in <xref linkend="manual-core-adv"/>.
15</para>
16
17<para>
18A point of terminology: most references to "Valgrind" in this chapter
19refer to the Valgrind core services. </para>
20
21
njn3e986b22004-11-30 10:43:45 +000022
23<sect1 id="manual-core.whatdoes"
24 xreflabel="What Valgrind does with your program">
25<title>What Valgrind does with your program</title>
26
debad57fc2005-12-03 22:33:29 +000027<para>Valgrind is designed to be as non-intrusive as possible. It works
28directly with existing executables. You don't need to recompile, relink,
29or otherwise modify, the program to be checked.</para>
njn3e986b22004-11-30 10:43:45 +000030
debad57fc2005-12-03 22:33:29 +000031<para>Simply put
32<computeroutput>valgrind --tool=tool_name</computeroutput>
33at the start of the command line normally used to run the program. For
34example, if want to run the command
35<computeroutput>ls -l</computeroutput> using the heavyweight
36memory-checking tool Memcheck, issue the command:</para>
njn3e986b22004-11-30 10:43:45 +000037
38<programlisting><![CDATA[
39valgrind --tool=memcheck ls -l]]></programlisting>
40
sewardj08e31e22007-05-23 21:58:33 +000041<para>Memcheck is the default, so if you want to use it you can
42omit the <option>--tool</option> flag.</para>
njn779a2d62005-07-25 00:12:19 +000043
debad57fc2005-12-03 22:33:29 +000044<para>Regardless of which tool is in use, Valgrind takes control of your
45program before it starts. Debugging information is read from the
46executable and associated libraries, so that error messages and other
sewardj08e31e22007-05-23 21:58:33 +000047outputs can be phrased in terms of source code locations, when
48appropriate.</para>
njn3e986b22004-11-30 10:43:45 +000049
debad57fc2005-12-03 22:33:29 +000050<para>Your program is then run on a synthetic CPU provided by the
51Valgrind core. As new code is executed for the first time, the core
52hands the code to the selected tool. The tool adds its own
53instrumentation code to this and hands the result back to the core,
54which coordinates the continued execution of this instrumented
55code.</para>
njn3e986b22004-11-30 10:43:45 +000056
debad57fc2005-12-03 22:33:29 +000057<para>The amount of instrumentation code added varies widely between
58tools. At one end of the scale, Memcheck adds code to check every
sewardj08e31e22007-05-23 21:58:33 +000059memory access and every value computed,
60making it run 10-50 times slower than natively.
debad57fc2005-12-03 22:33:29 +000061At the other end of the spectrum, the ultra-trivial "none" tool
sewardj08e31e22007-05-23 21:58:33 +000062(also referred to as Nulgrind) adds no instrumentation at all
63and causes in total
debad57fc2005-12-03 22:33:29 +000064"only" about a 4 times slowdown.</para>
njn3e986b22004-11-30 10:43:45 +000065
debad57fc2005-12-03 22:33:29 +000066<para>Valgrind simulates every single instruction your program executes.
67Because of this, the active tool checks, or profiles, not only the code
68in your application but also in all supporting dynamically-linked
69(<computeroutput>.so</computeroutput>-format) libraries, including the
70GNU C library, the X client libraries, Qt, if you work with KDE, and so
71on.</para>
njn3e986b22004-11-30 10:43:45 +000072
sewardj08e31e22007-05-23 21:58:33 +000073<para>If you're using an error-detection tool, Valgrind may
74detect errors in libraries, for example the GNU C or X11
debad57fc2005-12-03 22:33:29 +000075libraries, which you have to use. You might not be interested in these
76errors, since you probably have no control over that code. Therefore,
77Valgrind allows you to selectively suppress errors, by recording them in
78a suppressions file which is read when Valgrind starts up. The build
79mechanism attempts to select suppressions which give reasonable
sewardj08e31e22007-05-23 21:58:33 +000080behaviour for the C library
81and X11 client library versions detected on your machine.
debad57fc2005-12-03 22:33:29 +000082To make it easier to write suppressions, you can use the
sewardj08e31e22007-05-23 21:58:33 +000083<option>--gen-suppressions=yes</option> option. This tells Valgrind to
84print out a suppression for each reported error, which you can then
debad57fc2005-12-03 22:33:29 +000085copy into a suppressions file.</para>
njn3e986b22004-11-30 10:43:45 +000086
debad57fc2005-12-03 22:33:29 +000087<para>Different error-checking tools report different kinds of errors.
88The suppression mechanism therefore allows you to say which tool or
89tool(s) each suppression applies to.</para>
njn3e986b22004-11-30 10:43:45 +000090
91</sect1>
92
93
94<sect1 id="manual-core.started" xreflabel="Getting started">
95<title>Getting started</title>
96
debad57fc2005-12-03 22:33:29 +000097<para>First off, consider whether it might be beneficial to recompile
98your application and supporting libraries with debugging info enabled
99(the <option>-g</option> flag). Without debugging info, the best
100Valgrind tools will be able to do is guess which function a particular
101piece of code belongs to, which makes both error messages and profiling
sewardj08e31e22007-05-23 21:58:33 +0000102output nearly useless. With <option>-g</option>, you'll get
debad57fc2005-12-03 22:33:29 +0000103messages which point directly to the relevant source code lines.</para>
njn3e986b22004-11-30 10:43:45 +0000104
debad57fc2005-12-03 22:33:29 +0000105<para>Another flag you might like to consider, if you are working with
106C++, is <option>-fno-inline</option>. That makes it easier to see the
107function-call chain, which can help reduce confusion when navigating
sewardj08e31e22007-05-23 21:58:33 +0000108around large C++ apps. For example, debugging
debad57fc2005-12-03 22:33:29 +0000109OpenOffice.org with Memcheck is a bit easier when using this flag. You
110don't have to do this, but doing so helps Valgrind produce more accurate
111and less confusing error reports. Chances are you're set up like this
112already, if you intended to debug your program with GNU gdb, or some
113other debugger.</para>
njn3e986b22004-11-30 10:43:45 +0000114
njn3d92f9c2007-10-17 22:29:08 +0000115<para>If you are planning to use Memcheck: On rare
116occasions, compiler optimisations (at <computeroutput>-O2</computeroutput>
117and above, and sometimes <computeroutput>-O1</computeroutput>) have been
118observed to generate code which fools Memcheck into wrongly reporting
119uninitialised value errors, or missing uninitialised value errors. We have
120looked in detail into fixing this, and unfortunately the result is that
121doing so would give a further significant slowdown in what is already a slow
122tool. So the best solution is to turn off optimisation altogether. Since
sewardj33878892007-11-17 09:43:25 +0000123this often makes things unmanageably slow, a reasonable compromise is to use
debad57fc2005-12-03 22:33:29 +0000124<computeroutput>-O</computeroutput>. This gets you the majority of the
njn3d92f9c2007-10-17 22:29:08 +0000125benefits of higher optimisation levels whilst keeping relatively small the
njn9bd4bd42007-10-18 23:14:48 +0000126chances of false positives or false negatives from Memcheck. Also, you
127should compile your code with <computeroutput>-Wall</computeroutput> because
128it can identify some or all of the problems that Valgrind can miss at the
sewardj778d7832007-11-22 01:21:56 +0000129higher optimisation levels. (Using <computeroutput>-Wall</computeroutput>
njn9bd4bd42007-10-18 23:14:48 +0000130is also a good idea in general.) All other tools (as far as we know) are
131unaffected by optimisation level.</para>
njn3e986b22004-11-30 10:43:45 +0000132
debad57fc2005-12-03 22:33:29 +0000133<para>Valgrind understands both the older "stabs" debugging format, used
sewardj08e31e22007-05-23 21:58:33 +0000134by gcc versions prior to 3.1, and the newer DWARF2 and DWARF3 formats
135used by gcc
1363.1 and later. We continue to develop our debug-info readers,
debad57fc2005-12-03 22:33:29 +0000137although the majority of effort will naturally enough go into the newer
sewardj08e31e22007-05-23 21:58:33 +0000138DWARF2/3 reader.</para>
njn3e986b22004-11-30 10:43:45 +0000139
140<para>When you're ready to roll, just run your application as you
debad57fc2005-12-03 22:33:29 +0000141would normally, but place
142<computeroutput>valgrind --tool=tool_name</computeroutput> in front of
143your usual command-line invocation. Note that you should run the real
144(machine-code) executable here. If your application is started by, for
145example, a shell or perl script, you'll need to modify it to invoke
146Valgrind on the real executables. Running such scripts directly under
147Valgrind will result in you getting error reports pertaining to
148<computeroutput>/bin/sh</computeroutput>,
149<computeroutput>/usr/bin/perl</computeroutput>, or whatever interpreter
150you're using. This may not be what you want and can be confusing. You
151can force the issue by giving the flag
152<option>--trace-children=yes</option>, but confusion is still
153likely.</para>
njn3e986b22004-11-30 10:43:45 +0000154
155</sect1>
156
157
debad57fc2005-12-03 22:33:29 +0000158<sect1 id="manual-core.comment" xreflabel="The Commentary">
159<title>The Commentary</title>
njn3e986b22004-11-30 10:43:45 +0000160
debad57fc2005-12-03 22:33:29 +0000161<para>Valgrind tools write a commentary, a stream of text, detailing
162error reports and other significant events. All lines in the commentary
163have following form:
njn3e986b22004-11-30 10:43:45 +0000164
165<programlisting><![CDATA[
166==12345== some-message-from-Valgrind]]></programlisting>
167</para>
168
debad57fc2005-12-03 22:33:29 +0000169<para>The <computeroutput>12345</computeroutput> is the process ID.
170This scheme makes it easy to distinguish program output from Valgrind
171commentary, and also easy to differentiate commentaries from different
172processes which have become merged together, for whatever reason.</para>
njn3e986b22004-11-30 10:43:45 +0000173
debad57fc2005-12-03 22:33:29 +0000174<para>By default, Valgrind tools write only essential messages to the
175commentary, so as to avoid flooding you with information of secondary
176importance. If you want more information about what is happening,
177re-run, passing the <option>-v</option> flag to Valgrind. A second
178<option>-v</option> gives yet more detail.
sewardj053fe982005-11-15 19:51:04 +0000179</para>
njn3e986b22004-11-30 10:43:45 +0000180
debad57fc2005-12-03 22:33:29 +0000181<para>You can direct the commentary to three different places:</para>
njn3e986b22004-11-30 10:43:45 +0000182
183<orderedlist>
184
debad57fc2005-12-03 22:33:29 +0000185 <listitem id="manual-core.out2fd" xreflabel="Directing output to fd">
186 <para>The default: send it to a file descriptor, which is by default
187 2 (stderr). So, if you give the core no options, it will write
188 commentary to the standard error stream. If you want to send it to
189 some other file descriptor, for example number 9, you can specify
190 <option>--log-fd=9</option>.</para>
191
192 <para>This is the simplest and most common arrangement, but can
sewardj08e31e22007-05-23 21:58:33 +0000193 cause problems when Valgrinding entire trees of processes which
debad57fc2005-12-03 22:33:29 +0000194 expect specific file descriptors, particularly stdin/stdout/stderr,
195 to be available for their own use.</para>
njn3e986b22004-11-30 10:43:45 +0000196 </listitem>
197
198 <listitem id="manual-core.out2file"
debad57fc2005-12-03 22:33:29 +0000199 xreflabel="Directing output to file"> <para>A less intrusive
200 option is to write the commentary to a file, which you specify by
njn374a36d2007-11-23 01:41:32 +0000201 <option>--log-file=filename</option>. There are special format
202 specifiers that can be used to use a process ID or an environment
203 variable name in the log file name. These are useful/necessary if your
204 program invokes multiple processes (especially for MPI programs).
205 See the <link linkend="manual-core.basicopts">basic options section</link>
206 for more details.</para>
njn3e986b22004-11-30 10:43:45 +0000207 </listitem>
208
209 <listitem id="manual-core.out2socket"
debad57fc2005-12-03 22:33:29 +0000210 xreflabel="Directing output to network socket"> <para>The
211 least intrusive option is to send the commentary to a network
212 socket. The socket is specified as an IP address and port number
213 pair, like this: <option>--log-socket=192.168.0.1:12345</option> if
sewardj08e31e22007-05-23 21:58:33 +0000214 you want to send the output to host IP 192.168.0.1 port 12345
215 (note: we
debad57fc2005-12-03 22:33:29 +0000216 have no idea if 12345 is a port of pre-existing significance). You
217 can also omit the port number:
218 <option>--log-socket=192.168.0.1</option>, in which case a default
219 port of 1500 is used. This default is defined by the constant
220 <computeroutput>VG_CLO_DEFAULT_LOGPORT</computeroutput> in the
221 sources.</para>
njn3e986b22004-11-30 10:43:45 +0000222
debad57fc2005-12-03 22:33:29 +0000223 <para>Note, unfortunately, that you have to use an IP address here,
224 rather than a hostname.</para>
njn3e986b22004-11-30 10:43:45 +0000225
sewardj08e31e22007-05-23 21:58:33 +0000226 <para>Writing to a network socket is pointless if you don't
debad57fc2005-12-03 22:33:29 +0000227 have something listening at the other end. We provide a simple
228 listener program,
229 <computeroutput>valgrind-listener</computeroutput>, which accepts
230 connections on the specified port and copies whatever it is sent to
231 stdout. Probably someone will tell us this is a horrible security
232 risk. It seems likely that people will write more sophisticated
233 listeners in the fullness of time.</para>
njn3e986b22004-11-30 10:43:45 +0000234
debad57fc2005-12-03 22:33:29 +0000235 <para>valgrind-listener can accept simultaneous connections from up
sewardj08e31e22007-05-23 21:58:33 +0000236 to 50 Valgrinded processes. In front of each line of output it
debad57fc2005-12-03 22:33:29 +0000237 prints the current number of active connections in round
238 brackets.</para>
njn3e986b22004-11-30 10:43:45 +0000239
debad57fc2005-12-03 22:33:29 +0000240 <para>valgrind-listener accepts two command-line flags:</para>
njn3e986b22004-11-30 10:43:45 +0000241 <itemizedlist>
debad57fc2005-12-03 22:33:29 +0000242 <listitem>
243 <para><option>-e</option> or <option>--exit-at-zero</option>:
244 when the number of connected processes falls back to zero,
245 exit. Without this, it will run forever, that is, until you
246 send it Control-C.</para>
247 </listitem>
248 <listitem>
249 <para><option>portnumber</option>: changes the port it listens
250 on from the default (1500). The specified port must be in the
251 range 1024 to 65535. The same restriction applies to port
252 numbers specified by a <option>--log-socket</option> to
253 Valgrind itself.</para>
254 </listitem>
njn3e986b22004-11-30 10:43:45 +0000255 </itemizedlist>
256
sewardj08e31e22007-05-23 21:58:33 +0000257 <para>If a Valgrinded process fails to connect to a listener, for
debad57fc2005-12-03 22:33:29 +0000258 whatever reason (the listener isn't running, invalid or unreachable
259 host or port, etc), Valgrind switches back to writing the commentary
260 to stderr. The same goes for any process which loses an established
261 connection to a listener. In other words, killing the listener
262 doesn't kill the processes sending data to it.</para>
njn3e986b22004-11-30 10:43:45 +0000263 </listitem>
njn3e986b22004-11-30 10:43:45 +0000264
debad57fc2005-12-03 22:33:29 +0000265</orderedlist>
266
267<para>Here is an important point about the relationship between the
268commentary and profiling output from tools. The commentary contains a
269mix of messages from the Valgrind core and the selected tool. If the
270tool reports errors, it will report them to the commentary. However, if
271the tool does profiling, the profile data will be written to a file of
272some kind, depending on the tool, and independent of what
273<option>--log-*</option> options are in force. The commentary is
274intended to be a low-bandwidth, human-readable channel. Profiling data,
275on the other hand, is usually voluminous and not meaningful without
276further processing, which is why we have chosen this arrangement.</para>
njn3e986b22004-11-30 10:43:45 +0000277
278</sect1>
279
280
281<sect1 id="manual-core.report" xreflabel="Reporting of errors">
282<title>Reporting of errors</title>
283
sewardj08e31e22007-05-23 21:58:33 +0000284<para>When an error-checking tool
285detects something bad happening in the program, an error
286message is written to the commentary. Here's an example from Memcheck:</para>
njn3e986b22004-11-30 10:43:45 +0000287
288<programlisting><![CDATA[
289==25832== Invalid read of size 4
290==25832== at 0x8048724: BandMatrix::ReSize(int, int, int) (bogon.cpp:45)
291==25832== by 0x80487AF: main (bogon.cpp:66)
njn21f91952005-03-12 22:14:42 +0000292==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd]]></programlisting>
njn3e986b22004-11-30 10:43:45 +0000293
debad57fc2005-12-03 22:33:29 +0000294<para>This message says that the program did an illegal 4-byte read of
295address 0xBFFFF74C, which, as far as Memcheck can tell, is not a valid
sewardj08e31e22007-05-23 21:58:33 +0000296stack address, nor corresponds to any current malloc'd or free'd
debad57fc2005-12-03 22:33:29 +0000297blocks. The read is happening at line 45 of
298<filename>bogon.cpp</filename>, called from line 66 of the same file,
299etc. For errors associated with an identified malloc'd/free'd block,
300for example reading free'd memory, Valgrind reports not only the
301location where the error happened, but also where the associated block
302was malloc'd/free'd.</para>
njn3e986b22004-11-30 10:43:45 +0000303
debad57fc2005-12-03 22:33:29 +0000304<para>Valgrind remembers all error reports. When an error is detected,
305it is compared against old reports, to see if it is a duplicate. If so,
306the error is noted, but no further commentary is emitted. This avoids
307you being swamped with bazillions of duplicate error reports.</para>
njn3e986b22004-11-30 10:43:45 +0000308
debad57fc2005-12-03 22:33:29 +0000309<para>If you want to know how many times each error occurred, run with
310the <option>-v</option> option. When execution finishes, all the
311reports are printed out, along with, and sorted by, their occurrence
312counts. This makes it easy to see which errors have occurred most
313frequently.</para>
njn3e986b22004-11-30 10:43:45 +0000314
debad57fc2005-12-03 22:33:29 +0000315<para>Errors are reported before the associated operation actually
sewardj08e31e22007-05-23 21:58:33 +0000316happens. If you're using a tool (eg. Memcheck) which does
debad57fc2005-12-03 22:33:29 +0000317address checking, and your program attempts to read from address zero,
318the tool will emit a message to this effect, and the program will then
319duly die with a segmentation fault.</para>
njn3e986b22004-11-30 10:43:45 +0000320
debad57fc2005-12-03 22:33:29 +0000321<para>In general, you should try and fix errors in the order that they
322are reported. Not doing so can be confusing. For example, a program
323which copies uninitialised values to several memory locations, and later
324uses them, will generate several error messages, when run on Memcheck.
325The first such error message may well give the most direct clue to the
326root cause of the problem.</para>
njn3e986b22004-11-30 10:43:45 +0000327
328<para>The process of detecting duplicate errors is quite an
329expensive one and can become a significant performance overhead
330if your program generates huge quantities of errors. To avoid
sewardj053fe982005-11-15 19:51:04 +0000331serious problems, Valgrind will simply stop collecting
sewardj08e31e22007-05-23 21:58:33 +0000332errors after 1,000 different errors have been seen, or 10,000,000 errors
njn3e986b22004-11-30 10:43:45 +0000333in total have been seen. In this situation you might as well
334stop your program and fix it, because Valgrind won't tell you
sewardj08e31e22007-05-23 21:58:33 +0000335anything else useful after this. Note that the 1,000/10,000,000 limits
njn3e986b22004-11-30 10:43:45 +0000336apply after suppressed errors are removed. These limits are
njnc7561b92005-06-19 01:24:32 +0000337defined in <filename>m_errormgr.c</filename> and can be increased
njn3e986b22004-11-30 10:43:45 +0000338if necessary.</para>
339
340<para>To avoid this cutoff you can use the
debad57fc2005-12-03 22:33:29 +0000341<option>--error-limit=no</option> flag. Then Valgrind will always show
342errors, regardless of how many there are. Use this flag carefully,
343since it may have a bad effect on performance.</para>
njn3e986b22004-11-30 10:43:45 +0000344
345</sect1>
346
347
348<sect1 id="manual-core.suppress" xreflabel="Suppressing errors">
349<title>Suppressing errors</title>
350
debad57fc2005-12-03 22:33:29 +0000351<para>The error-checking tools detect numerous problems in the base
sewardj08e31e22007-05-23 21:58:33 +0000352libraries, such as the GNU C library, and the X11 client libraries,
debad57fc2005-12-03 22:33:29 +0000353which come pre-installed on your GNU/Linux system. You can't easily fix
354these, but you don't want to see these errors (and yes, there are many!)
355So Valgrind reads a list of errors to suppress at startup. A default
sewardj08e31e22007-05-23 21:58:33 +0000356suppression file is created by the
debad57fc2005-12-03 22:33:29 +0000357<computeroutput>./configure</computeroutput> script when the system is
358built.</para>
njn3e986b22004-11-30 10:43:45 +0000359
debad57fc2005-12-03 22:33:29 +0000360<para>You can modify and add to the suppressions file at your leisure,
361or, better, write your own. Multiple suppression files are allowed.
362This is useful if part of your project contains errors you can't or
363don't want to fix, yet you don't want to continuously be reminded of
364them.</para>
njn3e986b22004-11-30 10:43:45 +0000365
debad57fc2005-12-03 22:33:29 +0000366<formalpara><title>Note:</title> <para>By far the easiest way to add
367suppressions is to use the <option>--gen-suppressions=yes</option> flag
njn3e986b22004-11-30 10:43:45 +0000368described in <xref linkend="manual-core.flags"/>.</para>
369</formalpara>
370
debad57fc2005-12-03 22:33:29 +0000371<para>Each error to be suppressed is described very specifically, to
372minimise the possibility that a suppression-directive inadvertantly
373suppresses a bunch of similar errors which you did want to see. The
374suppression mechanism is designed to allow precise yet flexible
375specification of errors to suppress.</para>
njn3e986b22004-11-30 10:43:45 +0000376
debad57fc2005-12-03 22:33:29 +0000377<para>If you use the <option>-v</option> flag, at the end of execution,
378Valgrind prints out one line for each used suppression, giving its name
379and the number of times it got used. Here's the suppressions used by a
sewardj08e31e22007-05-23 21:58:33 +0000380run of <computeroutput>valgrind --tool=memcheck ls -l</computeroutput>:</para>
njn3e986b22004-11-30 10:43:45 +0000381
382<programlisting><![CDATA[
383--27579-- supp: 1 socketcall.connect(serv_addr)/__libc_connect/__nscd_getgrgid_r
384--27579-- supp: 1 socketcall.connect(serv_addr)/__libc_connect/__nscd_getpwuid_r
385--27579-- supp: 6 strrchr/_dl_map_object_from_fd/_dl_map_object]]></programlisting>
386
debad57fc2005-12-03 22:33:29 +0000387<para>Multiple suppressions files are allowed. By default, Valgrind
388uses <filename>$PREFIX/lib/valgrind/default.supp</filename>. You can
389ask to add suppressions from another file, by specifying
390<option>--suppressions=/path/to/file.supp</option>.
njn3e986b22004-11-30 10:43:45 +0000391</para>
392
debad57fc2005-12-03 22:33:29 +0000393<para>If you want to understand more about suppressions, look at an
394existing suppressions file whilst reading the following documentation.
sewardj08e31e22007-05-23 21:58:33 +0000395The file <filename>glibc-2.3.supp</filename>, in the source
njn3e986b22004-11-30 10:43:45 +0000396distribution, provides some good examples.</para>
397
398<para>Each suppression has the following components:</para>
399
debad57fc2005-12-03 22:33:29 +0000400<itemizedlist>
njn3e986b22004-11-30 10:43:45 +0000401
402 <listitem>
debad57fc2005-12-03 22:33:29 +0000403 <para>First line: its name. This merely gives a handy name to the
404 suppression, by which it is referred to in the summary of used
405 suppressions printed out when a program finishes. It's not
406 important what the name is; any identifying string will do.</para>
njn3e986b22004-11-30 10:43:45 +0000407 </listitem>
408
409 <listitem>
debad57fc2005-12-03 22:33:29 +0000410 <para>Second line: name of the tool(s) that the suppression is for
411 (if more than one, comma-separated), and the name of the suppression
sewardj33878892007-11-17 09:43:25 +0000412 itself, separated by a colon (n.b.: no spaces are allowed), eg:</para>
njn3e986b22004-11-30 10:43:45 +0000413<programlisting><![CDATA[
414tool_name1,tool_name2:suppression_name]]></programlisting>
415
sewardjf5fa3bd2006-03-14 00:56:29 +0000416 <para>Recall that Valgrind is a modular system, in which
debad57fc2005-12-03 22:33:29 +0000417 different instrumentation tools can observe your program whilst it
418 is running. Since different tools detect different kinds of errors,
419 it is necessary to say which tool(s) the suppression is meaningful
420 to.</para>
njn3e986b22004-11-30 10:43:45 +0000421
debad57fc2005-12-03 22:33:29 +0000422 <para>Tools will complain, at startup, if a tool does not understand
423 any suppression directed to it. Tools ignore suppressions which are
424 not directed to them. As a result, it is quite practical to put
425 suppressions for all tools into the same suppression file.</para>
njn3e986b22004-11-30 10:43:45 +0000426 </listitem>
427
428 <listitem>
debad57fc2005-12-03 22:33:29 +0000429 <para>Next line: a small number of suppression types have extra
430 information after the second line (eg. the <varname>Param</varname>
431 suppression for Memcheck)</para>
njn3e986b22004-11-30 10:43:45 +0000432 </listitem>
433
434 <listitem>
debad57fc2005-12-03 22:33:29 +0000435 <para>Remaining lines: This is the calling context for the error --
sewardj08e31e22007-05-23 21:58:33 +0000436 the chain of function calls that led to it. There can be up to 24
437 of these lines.</para>
njn3e986b22004-11-30 10:43:45 +0000438
debad57fc2005-12-03 22:33:29 +0000439 <para>Locations may be either names of shared objects/executables or
440 wildcards matching function names. They begin
441 <computeroutput>obj:</computeroutput> and
442 <computeroutput>fun:</computeroutput> respectively. Function and
443 object names to match against may use the wildcard characters
444 <computeroutput>*</computeroutput> and
445 <computeroutput>?</computeroutput>.</para>
njn3e986b22004-11-30 10:43:45 +0000446
debad57fc2005-12-03 22:33:29 +0000447 <para><command>Important note: </command> C++ function names must be
448 <command>mangled</command>. If you are writing suppressions by
449 hand, use the <option>--demangle=no</option> option to get the
450 mangled names in your error messages.</para>
njn3e986b22004-11-30 10:43:45 +0000451 </listitem>
452
453 <listitem>
debad57fc2005-12-03 22:33:29 +0000454 <para>Finally, the entire suppression must be between curly
455 braces. Each brace must be the first character on its own
456 line.</para>
njn3e986b22004-11-30 10:43:45 +0000457 </listitem>
458
459 </itemizedlist>
460
debad57fc2005-12-03 22:33:29 +0000461<para>A suppression only suppresses an error when the error matches all
462the details in the suppression. Here's an example:</para>
njn3e986b22004-11-30 10:43:45 +0000463
464<programlisting><![CDATA[
465{
466 __gconv_transform_ascii_internal/__mbrtowc/mbtowc
467 Memcheck:Value4
468 fun:__gconv_transform_ascii_internal
469 fun:__mbr*toc
470 fun:mbtowc
471}]]></programlisting>
472
473
474<para>What it means is: for Memcheck only, suppress a
debad57fc2005-12-03 22:33:29 +0000475use-of-uninitialised-value error, when the data size is 4, when it
476occurs in the function
477<computeroutput>__gconv_transform_ascii_internal</computeroutput>, when
478that is called from any function of name matching
479<computeroutput>__mbr*toc</computeroutput>, when that is called from
480<computeroutput>mbtowc</computeroutput>. It doesn't apply under any
481other circumstances. The string by which this suppression is identified
482to the user is
njn3e986b22004-11-30 10:43:45 +0000483<computeroutput>__gconv_transform_ascii_internal/__mbrtowc/mbtowc</computeroutput>.</para>
484
485<para>(See <xref linkend="mc-manual.suppfiles"/> for more details
486on the specifics of Memcheck's suppression kinds.)</para>
487
488<para>Another example, again for the Memcheck tool:</para>
489
490<programlisting><![CDATA[
491{
492 libX11.so.6.2/libX11.so.6.2/libXaw.so.7.0
493 Memcheck:Value4
494 obj:/usr/X11R6/lib/libX11.so.6.2
495 obj:/usr/X11R6/lib/libX11.so.6.2
496 obj:/usr/X11R6/lib/libXaw.so.7.0
497}]]></programlisting>
498
499<para>Suppress any size 4 uninitialised-value error which occurs
debad57fc2005-12-03 22:33:29 +0000500anywhere in <filename>libX11.so.6.2</filename>, when called from
501anywhere in the same library, when called from anywhere in
502<filename>libXaw.so.7.0</filename>. The inexact specification of
503locations is regrettable, but is about all you can hope for, given that
sewardj08e31e22007-05-23 21:58:33 +0000504the X11 libraries shipped on the Linux distro on which this example
505was made have had their symbol tables removed.</para>
njn3e986b22004-11-30 10:43:45 +0000506
sewardj08e31e22007-05-23 21:58:33 +0000507<para>Although the above two examples do not make this clear, you can
508freely mix <computeroutput>obj:</computeroutput> and
509<computeroutput>fun:</computeroutput> lines in a suppression.</para>
njn3e986b22004-11-30 10:43:45 +0000510
511</sect1>
512
513
514<sect1 id="manual-core.flags"
515 xreflabel="Command-line flags for the Valgrind core">
516<title>Command-line flags for the Valgrind core</title>
517
debad57fc2005-12-03 22:33:29 +0000518<para>As mentioned above, Valgrind's core accepts a common set of flags.
519The tools also accept tool-specific flags, which are documented
sewardj33878892007-11-17 09:43:25 +0000520separately for each tool.</para>
njn3e986b22004-11-30 10:43:45 +0000521
522<para>You invoke Valgrind like this:</para>
523
524<programlisting><![CDATA[
debad57fc2005-12-03 22:33:29 +0000525valgrind [valgrind-options] your-prog [your-prog-options]]]></programlisting>
njn3e986b22004-11-30 10:43:45 +0000526
debad57fc2005-12-03 22:33:29 +0000527<para>Valgrind's default settings succeed in giving reasonable behaviour
528in most cases. We group the available options by rough
njn3e986b22004-11-30 10:43:45 +0000529categories.</para>
530
531<sect2 id="manual-core.toolopts" xreflabel="Tool-selection option">
532<title>Tool-selection option</title>
533
534<para>The single most important option.</para>
debad57fc2005-12-03 22:33:29 +0000535
536<itemizedlist>
537 <listitem id="tool_name">
538 <para><option>--tool=&lt;name&gt;</option> [default=memcheck]</para>
njn3e986b22004-11-30 10:43:45 +0000539 <para>Run the Valgrind tool called <emphasis>name</emphasis>,
njn1d0825f2006-03-27 11:37:07 +0000540 e.g. Memcheck, Cachegrind, etc.</para>
debad57fc2005-12-03 22:33:29 +0000541 </listitem>
542</itemizedlist>
543
njn3e986b22004-11-30 10:43:45 +0000544</sect2>
545
debad57fc2005-12-03 22:33:29 +0000546
547
njn3e986b22004-11-30 10:43:45 +0000548<sect2 id="manual-core.basicopts" xreflabel="Basic Options">
549<title>Basic Options</title>
550
de03e0e7c2005-12-03 23:02:33 +0000551<!-- start of xi:include in the manpage -->
552<para id="basic.opts.para">These options work with all tools.</para>
njn3e986b22004-11-30 10:43:45 +0000553
de03e0e7c2005-12-03 23:02:33 +0000554<variablelist id="basic.opts.list">
njn3e986b22004-11-30 10:43:45 +0000555
debad57fc2005-12-03 22:33:29 +0000556 <varlistentry id="opt.help" xreflabel="--help">
557 <term><option>-h --help</option></term>
558 <listitem>
559 <para>Show help for all options, both for the core and for the
560 selected tool.</para>
561 </listitem>
562 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000563
debad57fc2005-12-03 22:33:29 +0000564 <varlistentry id="opt.help-debug" xreflabel="--help-debug">
565 <term><option>--help-debug</option></term>
566 <listitem>
567 <para>Same as <option>--help</option>, but also lists debugging
568 options which usually are only of use to Valgrind's
569 developers.</para>
570 </listitem>
571 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000572
debad57fc2005-12-03 22:33:29 +0000573 <varlistentry id="opt.version" xreflabel="--version">
574 <term><option>--version</option></term>
575 <listitem>
576 <para>Show the version number of the Valgrind core. Tools can have
577 their own version numbers. There is a scheme in place to ensure
578 that tools only execute when the core version is one they are
579 known to work with. This was done to minimise the chances of
580 strange problems arising from tool-vs-core version
581 incompatibilities.</para>
582 </listitem>
583 </varlistentry>
njn51272982005-07-25 23:18:44 +0000584
debad57fc2005-12-03 22:33:29 +0000585 <varlistentry id="opt.quiet" xreflabel="--quiet">
586 <term><option>-q --quiet</option></term>
587 <listitem>
588 <para>Run silently, and only print error messages. Useful if you
589 are running regression tests or have some other automated test
590 machinery.</para>
591 </listitem>
592 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000593
debad57fc2005-12-03 22:33:29 +0000594 <varlistentry id="opt.verbose" xreflabel="--verbose">
595 <term><option>-v --verbose</option></term>
596 <listitem>
597 <para>Be more verbose. Gives extra information on various aspects
598 of your program, such as: the shared objects loaded, the
599 suppressions used, the progress of the instrumentation and
600 execution engines, and warnings about unusual behaviour. Repeating
601 the flag increases the verbosity level.</para>
602 </listitem>
603 </varlistentry>
sewardj053fe982005-11-15 19:51:04 +0000604
debad57fc2005-12-03 22:33:29 +0000605 <varlistentry id="opt.d" xreflabel="-d">
606 <term><option>-d</option></term>
607 <listitem>
608 <para>Emit information for debugging Valgrind itself. This is
609 usually only of interest to the Valgrind developers. Repeating
610 the flag produces more detailed output. If you want to send us a
611 bug report, a log of the output generated by
612 <option>-v -v -d -d</option> will make your report more
613 useful.</para>
614 </listitem>
615 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000616
debad57fc2005-12-03 22:33:29 +0000617 <varlistentry id="opt.tool" xreflabel="--tool">
618 <term>
619 <option><![CDATA[--tool=<toolname> [default: memcheck] ]]></option>
620 </term>
621 <listitem>
622 <para>Run the Valgrind tool called <varname>toolname</varname>,
sewardj08e31e22007-05-23 21:58:33 +0000623 e.g. Memcheck, Cachegrind, etc.</para>
debad57fc2005-12-03 22:33:29 +0000624 </listitem>
625 </varlistentry>
njn51272982005-07-25 23:18:44 +0000626
debad57fc2005-12-03 22:33:29 +0000627 <varlistentry id="opt.trace-children" xreflabel="--trace-children">
628 <term>
629 <option><![CDATA[--trace-children=<yes|no> [default: no] ]]></option>
630 </term>
631 <listitem>
njnae44c382007-05-15 03:59:23 +0000632 <para>When enabled, Valgrind will trace into sub-processes
633 initiated via the <varname>exec</varname> system call. This can be
634 confusing and isn't usually what you want, so it is disabled by
635 default.
636 </para>
637 <para>Note that Valgrind does trace into the child of a
sewardj79c62bc2007-11-28 01:55:29 +0000638 <varname>fork</varname> (it would be difficult not to, since
njnae44c382007-05-15 03:59:23 +0000639 <varname>fork</varname> makes an identical copy of a process), so this
640 option is arguably badly named. However, most children of
641 <varname>fork</varname> calls immediately call <varname>exec</varname>
642 anyway.
643 </para>
debad57fc2005-12-03 22:33:29 +0000644 </listitem>
645 </varlistentry>
njn51272982005-07-25 23:18:44 +0000646
sewardj778d7832007-11-22 01:21:56 +0000647 <varlistentry id="opt.child-silent-after-fork"
648 xreflabel="--child-silent-after-fork">
649 <term>
650 <option><![CDATA[--child-silent-after-fork=<yes|no> [default: no] ]]></option>
651 </term>
652 <listitem>
653 <para>When enabled, Valgrind will not show any debugging or
654 logging output for the child process resulting from
655 a <varname>fork</varname> call. This can make the output less
656 confusing (although more misleading) when dealing with processes
657 that create children. It is particularly useful in conjunction
658 with <varname>--trace-children=</varname>. Use of this flag is also
659 strongly recommended if you are requesting XML output
660 (<varname>--xml=yes</varname>), since otherwise the XML from child and
661 parent may become mixed up, which usually makes it useless.
662 </para>
663 </listitem>
664 </varlistentry>
665
debad57fc2005-12-03 22:33:29 +0000666 <varlistentry id="opt.track-fds" xreflabel="--track-fds">
667 <term>
668 <option><![CDATA[--track-fds=<yes|no> [default: no] ]]></option>
669 </term>
670 <listitem>
671 <para>When enabled, Valgrind will print out a list of open file
672 descriptors on exit. Along with each file descriptor is printed a
673 stack backtrace of where the file was opened and any details
674 relating to the file descriptor such as the file name or socket
675 details.</para>
676 </listitem>
677 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000678
debad57fc2005-12-03 22:33:29 +0000679 <varlistentry id="opt.time-stamp" xreflabel="--time-stamp">
680 <term>
681 <option><![CDATA[--time-stamp=<yes|no> [default: no] ]]></option>
682 </term>
683 <listitem>
684 <para>When enabled, each message is preceded with an indication of
685 the elapsed wallclock time since startup, expressed as days,
686 hours, minutes, seconds and milliseconds.</para>
687 </listitem>
688 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000689
debad57fc2005-12-03 22:33:29 +0000690 <varlistentry id="opt.log-fd" xreflabel="--log-fd">
691 <term>
692 <option><![CDATA[--log-fd=<number> [default: 2, stderr] ]]></option>
693 </term>
694 <listitem>
695 <para>Specifies that Valgrind should send all of its messages to
696 the specified file descriptor. The default, 2, is the standard
697 error channel (stderr). Note that this may interfere with the
698 client's own use of stderr, as Valgrind's output will be
699 interleaved with any output that the client sends to
700 stderr.</para>
701 </listitem>
702 </varlistentry>
njn779a2d62005-07-25 00:12:19 +0000703
debad57fc2005-12-03 22:33:29 +0000704 <varlistentry id="opt.log-file" xreflabel="--log-file">
705 <term>
706 <option><![CDATA[--log-file=<filename> ]]></option>
707 </term>
708 <listitem>
709 <para>Specifies that Valgrind should send all of its messages to
njn374a36d2007-11-23 01:41:32 +0000710 the specified file. If the file name is empty, it causes an abort.
711 There are three special format specifiers that can be used in the file
712 name.</para>
njn779a2d62005-07-25 00:12:19 +0000713
njn374a36d2007-11-23 01:41:32 +0000714 <para><option>%p</option> is replaced with the current process ID.
715 This is very useful for program that invoke multiple processes.
716 WARNING: If you use <option>--trace-children=yes</option> and your
njn7064fb22008-05-29 23:09:52 +0000717 program invokes multiple processes OR your program forks without
718 calling exec afterwards, and you don't use this specifier
njn374a36d2007-11-23 01:41:32 +0000719 (or the <option>%q</option> specifier below), the Valgrind output from
720 all those processes will go into one file, possibly jumbled up, and
njn498685c2007-09-17 23:15:35 +0000721 possibly incomplete.</para>
njn3e986b22004-11-30 10:43:45 +0000722
njn374a36d2007-11-23 01:41:32 +0000723 <para><option>%q{FOO}</option> is replaced with the contents of the
724 environment variable <varname>FOO</varname>. If the
725 <option>{FOO}</option> part is malformed, it causes an abort. This
726 specifier is rarely needed, but very useful in certain circumstances
727 (eg. when running MPI programs). The idea is that you specify a
728 variable which will be set differently for each process in the job,
729 for example <computeroutput>BPROC_RANK</computeroutput> or whatever is
730 applicable in your MPI setup. If the named environment variable is not
731 set, it causes an abort. Note that in some shells, the
732 <option>{</option> and <option>}</option> characters may need to be
733 escaped with a backslash.</para>
734
735 <para><option>%%</option> is replaced with <option>%</option>.</para>
736
737 <para>If an <option>%</option> is followed by any other character, it
738 causes an abort.</para>
debad57fc2005-12-03 22:33:29 +0000739 </listitem>
740 </varlistentry>
741
742 <varlistentry id="opt.log-socket" xreflabel="--log-socket">
743 <term>
744 <option><![CDATA[--log-socket=<ip-address:port-number> ]]></option>
745 </term>
746 <listitem>
747 <para>Specifies that Valgrind should send all of its messages to
748 the specified port at the specified IP address. The port may be
749 omitted, in which case port 1500 is used. If a connection cannot
750 be made to the specified socket, Valgrind falls back to writing
751 output to the standard error (stderr). This option is intended to
752 be used in conjunction with the
753 <computeroutput>valgrind-listener</computeroutput> program. For
754 further details, see
sewardj33878892007-11-17 09:43:25 +0000755 <link linkend="manual-core.comment">the commentary</link>
debad57fc2005-12-03 22:33:29 +0000756 in the manual.</para>
757 </listitem>
758 </varlistentry>
759
760</variablelist>
de03e0e7c2005-12-03 23:02:33 +0000761<!-- end of xi:include in the manpage -->
debad57fc2005-12-03 22:33:29 +0000762
763</sect2>
njn3e986b22004-11-30 10:43:45 +0000764
765
766<sect2 id="manual-core.erropts" xreflabel="Error-related Options">
767<title>Error-related options</title>
768
de03e0e7c2005-12-03 23:02:33 +0000769<!-- start of xi:include in the manpage -->
770<para id="error-related.opts.para">These options are used by all tools
771that can report errors, e.g. Memcheck, but not Cachegrind.</para>
njn3e986b22004-11-30 10:43:45 +0000772
de03e0e7c2005-12-03 23:02:33 +0000773<variablelist id="error-related.opts.list">
njn3e986b22004-11-30 10:43:45 +0000774
debad57fc2005-12-03 22:33:29 +0000775 <varlistentry id="opt.xml" xreflabel="--xml">
776 <term>
777 <option><![CDATA[--xml=<yes|no> [default: no] ]]></option>
778 </term>
779 <listitem>
780 <para>When enabled, output will be in XML format. This is aimed
781 at making life easier for tools that consume Valgrind's output as
782 input, such as GUI front ends. Currently this option only works
njnca54af32006-04-16 10:25:43 +0000783 with Memcheck.</para>
debad57fc2005-12-03 22:33:29 +0000784 </listitem>
785 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000786
debad57fc2005-12-03 22:33:29 +0000787 <varlistentry id="opt.xml-user-comment" xreflabel="--xml-user-comment">
788 <term>
789 <option><![CDATA[--xml-user-comment=<string> ]]></option>
790 </term>
791 <listitem>
792 <para>Embeds an extra user comment string at the start of the XML
793 output. Only works when <option>--xml=yes</option> is specified;
794 ignored otherwise.</para>
795 </listitem>
796 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000797
debad57fc2005-12-03 22:33:29 +0000798 <varlistentry id="opt.demangle" xreflabel="--demangle">
799 <term>
800 <option><![CDATA[--demangle=<yes|no> [default: yes] ]]></option>
801 </term>
802 <listitem>
803 <para>Enable/disable automatic demangling (decoding) of C++ names.
804 Enabled by default. When enabled, Valgrind will attempt to
805 translate encoded C++ names back to something approaching the
806 original. The demangler handles symbols mangled by g++ versions
807 2.X, 3.X and 4.X.</para>
njn3e986b22004-11-30 10:43:45 +0000808
debad57fc2005-12-03 22:33:29 +0000809 <para>An important fact about demangling is that function names
810 mentioned in suppressions files should be in their mangled form.
811 Valgrind does not demangle function names when searching for
812 applicable suppressions, because to do otherwise would make
813 suppressions file contents dependent on the state of Valgrind's
814 demangling machinery, and would also be slow and pointless.</para>
815 </listitem>
816 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000817
debad57fc2005-12-03 22:33:29 +0000818 <varlistentry id="opt.num-callers" xreflabel="--num-callers">
819 <term>
820 <option><![CDATA[--num-callers=<number> [default: 12] ]]></option>
821 </term>
822 <listitem>
823 <para>By default, Valgrind shows twelve levels of function call
824 names to help you identify program locations. You can change that
825 number with this option. This can help in determining the
826 program's location in deeply-nested call chains. Note that errors
827 are commoned up using only the top four function locations (the
828 place in the current function, and that of its three immediate
829 callers). So this doesn't affect the total number of errors
830 reported.</para>
njn3e986b22004-11-30 10:43:45 +0000831
debad57fc2005-12-03 22:33:29 +0000832 <para>The maximum value for this is 50. Note that higher settings
833 will make Valgrind run a bit more slowly and take a bit more
834 memory, but can be useful when working with programs with
835 deeply-nested call chains.</para>
836 </listitem>
837 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000838
debad57fc2005-12-03 22:33:29 +0000839 <varlistentry id="opt.error-limit" xreflabel="--error-limit">
840 <term>
841 <option><![CDATA[--error-limit=<yes|no> [default: yes] ]]></option>
842 </term>
843 <listitem>
sewardj58501082006-05-12 23:35:10 +0000844 <para>When enabled, Valgrind stops reporting errors after 10,000,000
debad57fc2005-12-03 22:33:29 +0000845 in total, or 1,000 different ones, have been seen. This is to
846 stop the error tracking machinery from becoming a huge performance
847 overhead in programs with many errors.</para>
848 </listitem>
849 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000850
sewardjb9779082006-05-12 23:50:15 +0000851 <varlistentry id="opt.error-exitcode" xreflabel="--error-exitcode">
852 <term>
853 <option><![CDATA[--error-exitcode=<number> [default: 0] ]]></option>
854 </term>
855 <listitem>
856 <para>Specifies an alternative exit code to return if Valgrind
857 reported any errors in the run. When set to the default value
858 (zero), the return value from Valgrind will always be the return
859 value of the process being simulated. When set to a nonzero value,
860 that value is returned instead, if Valgrind detects any errors.
861 This is useful for using Valgrind as part of an automated test
862 suite, since it makes it easy to detect test cases for which
863 Valgrind has reported errors, just by inspecting return codes.</para>
864 </listitem>
865 </varlistentry>
866
debad57fc2005-12-03 22:33:29 +0000867 <varlistentry id="opt.stack-traces" xreflabel="--show-below-main">
868 <term>
869 <option><![CDATA[--show-below-main=<yes|no> [default: no] ]]></option>
870 </term>
871 <listitem>
872 <para>By default, stack traces for errors do not show any
873 functions that appear beneath <function>main()</function>
874 (or similar functions such as glibc's
875 <function>__libc_start_main()</function>, if
876 <function>main()</function> is not present in the stack trace);
877 most of the time it's uninteresting C library stuff. If this
878 option is enabled, those entries below <function>main()</function>
879 will be shown.</para>
880 </listitem>
881 </varlistentry>
sewardjd153fae2005-01-10 17:24:47 +0000882
debad57fc2005-12-03 22:33:29 +0000883 <varlistentry id="opt.suppressions" xreflabel="--suppressions">
884 <term>
885 <option><![CDATA[--suppressions=<filename> [default: $PREFIX/lib/valgrind/default.supp] ]]></option>
886 </term>
887 <listitem>
888 <para>Specifies an extra file from which to read descriptions of
sewardjc44b2542008-05-14 06:43:10 +0000889 errors to suppress. You may use up to 100 extra suppression
890 files.</para>
debad57fc2005-12-03 22:33:29 +0000891 </listitem>
892 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000893
sewardj33878892007-11-17 09:43:25 +0000894 <varlistentry id="opt.gen-suppressions" xreflabel="--gen-suppressions">
debad57fc2005-12-03 22:33:29 +0000895 <term>
896 <option><![CDATA[--gen-suppressions=<yes|no|all> [default: no] ]]></option>
897 </term>
898 <listitem>
899 <para>When set to <varname>yes</varname>, Valgrind will pause
900 after every error shown and print the line:
901 <literallayout> ---- Print suppression ? --- [Return/N/n/Y/y/C/c] ----</literallayout>
njn3e986b22004-11-30 10:43:45 +0000902
debad57fc2005-12-03 22:33:29 +0000903 The prompt's behaviour is the same as for the
904 <option>--db-attach</option> option (see below).</para>
njn3e986b22004-11-30 10:43:45 +0000905
debad57fc2005-12-03 22:33:29 +0000906 <para>If you choose to, Valgrind will print out a suppression for
907 this error. You can then cut and paste it into a suppression file
908 if you don't want to hear about the error in the future.</para>
sewardjd153fae2005-01-10 17:24:47 +0000909
debad57fc2005-12-03 22:33:29 +0000910 <para>When set to <varname>all</varname>, Valgrind will print a
911 suppression for every reported error, without querying the
912 user.</para>
njn3e986b22004-11-30 10:43:45 +0000913
debad57fc2005-12-03 22:33:29 +0000914 <para>This option is particularly useful with C++ programs, as it
915 prints out the suppressions with mangled names, as
916 required.</para>
njn3e986b22004-11-30 10:43:45 +0000917
debad57fc2005-12-03 22:33:29 +0000918 <para>Note that the suppressions printed are as specific as
919 possible. You may want to common up similar ones, eg. by adding
sewardj08e31e22007-05-23 21:58:33 +0000920 wildcards to function names. Sometimes two different errors
debad57fc2005-12-03 22:33:29 +0000921 are suppressed by the same suppression, in which case Valgrind
922 will output the suppression more than once, but you only need to
923 have one copy in your suppression file (but having more than one
924 won't cause problems). Also, the suppression name is given as
925 <computeroutput>&lt;insert a suppression name
926 here&gt;</computeroutput>; the name doesn't really matter, it's
927 only used with the <option>-v</option> option which prints out all
928 used suppression records.</para>
929 </listitem>
930 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000931
debad57fc2005-12-03 22:33:29 +0000932 <varlistentry id="opt.db-attach" xreflabel="--db-attach">
933 <term>
934 <option><![CDATA[--db-attach=<yes|no> [default: no] ]]></option>
935 </term>
936 <listitem>
937 <para>When enabled, Valgrind will pause after every error shown
938 and print the line:
939 <literallayout> ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ----</literallayout>
njn3e986b22004-11-30 10:43:45 +0000940
debad57fc2005-12-03 22:33:29 +0000941 Pressing <varname>Ret</varname>, or <varname>N Ret</varname> or
942 <varname>n Ret</varname>, causes Valgrind not to start a debugger
943 for this error.</para>
njn3e986b22004-11-30 10:43:45 +0000944
debad57fc2005-12-03 22:33:29 +0000945 <para>Pressing <varname>Y Ret</varname> or
946 <varname>y Ret</varname> causes Valgrind to start a debugger for
947 the program at this point. When you have finished with the
948 debugger, quit from it, and the program will continue. Trying to
949 continue from inside the debugger doesn't work.</para>
njn3e986b22004-11-30 10:43:45 +0000950
debad57fc2005-12-03 22:33:29 +0000951 <para><varname>C Ret</varname> or <varname>c Ret</varname> causes
952 Valgrind not to start a debugger, and not to ask again.</para>
debad57fc2005-12-03 22:33:29 +0000953 </listitem>
954 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000955
debad57fc2005-12-03 22:33:29 +0000956 <varlistentry id="opt.db-command" xreflabel="--db-command">
957 <term>
958 <option><![CDATA[--db-command=<command> [default: gdb -nw %f %p] ]]></option>
959 </term>
960 <listitem>
961 <para>Specify the debugger to use with the
962 <option>--db-attach</option> command. The default debugger is
963 gdb. This option is a template that is expanded by Valgrind at
964 runtime. <literal>%f</literal> is replaced with the executable's
965 file name and <literal>%p</literal> is replaced by the process ID
966 of the executable.</para>
njn3e986b22004-11-30 10:43:45 +0000967
debad57fc2005-12-03 22:33:29 +0000968 <para>This specifies how Valgrind will invoke the debugger. By
969 default it will use whatever GDB is detected at build time, which
970 is usually <computeroutput>/usr/bin/gdb</computeroutput>. Using
971 this command, you can specify some alternative command to invoke
972 the debugger you want to use.</para>
njn51272982005-07-25 23:18:44 +0000973
debad57fc2005-12-03 22:33:29 +0000974 <para>The command string given can include one or instances of the
975 <literal>%p</literal> and <literal>%f</literal> expansions. Each
976 instance of <literal>%p</literal> expands to the PID of the
977 process to be debugged and each instance of <literal>%f</literal>
978 expands to the path to the executable for the process to be
979 debugged.</para>
sewardj778d7832007-11-22 01:21:56 +0000980
981 <para>Since <computeroutput>&lt;command&gt;</computeroutput> is likely
982 to contain spaces, you will need to put this entire flag in
983 quotes to ensure it is correctly handled by the shell.</para>
debad57fc2005-12-03 22:33:29 +0000984 </listitem>
985 </varlistentry>
986
987 <varlistentry id="opt.input-fd" xreflabel="--input-fd">
988 <term>
989 <option><![CDATA[--input-fd=<number> [default: 0, stdin] ]]></option>
990 </term>
991 <listitem>
sewardj08e31e22007-05-23 21:58:33 +0000992 <para>When using <option>--db-attach=yes</option> or
debad57fc2005-12-03 22:33:29 +0000993 <option>--gen-suppressions=yes</option>, Valgrind will stop so as
sewardj08e31e22007-05-23 21:58:33 +0000994 to read keyboard input from you when each error occurs. By
debad57fc2005-12-03 22:33:29 +0000995 default it reads from the standard input (stdin), which is
996 problematic for programs which close stdin. This option allows
997 you to specify an alternative file descriptor from which to read
998 input.</para>
999 </listitem>
1000 </varlistentry>
1001
1002 <varlistentry id="opt.max-stackframe" xreflabel="--max-stackframe">
1003 <term>
1004 <option><![CDATA[--max-stackframe=<number> [default: 2000000] ]]></option>
1005 </term>
1006 <listitem>
sewardj08e31e22007-05-23 21:58:33 +00001007 <para>The maximum size of a stack frame. If the stack pointer moves by
debad57fc2005-12-03 22:33:29 +00001008 more than this amount then Valgrind will assume that
1009 the program is switching to a different stack.</para>
1010
1011 <para>You may need to use this option if your program has large
1012 stack-allocated arrays. Valgrind keeps track of your program's
1013 stack pointer. If it changes by more than the threshold amount,
1014 Valgrind assumes your program is switching to a different stack,
1015 and Memcheck behaves differently than it would for a stack pointer
1016 change smaller than the threshold. Usually this heuristic works
1017 well. However, if your program allocates large structures on the
1018 stack, this heuristic will be fooled, and Memcheck will
1019 subsequently report large numbers of invalid stack accesses. This
1020 option allows you to change the threshold to a different
1021 value.</para>
1022
1023 <para>You should only consider use of this flag if Valgrind's
1024 debug output directs you to do so. In that case it will tell you
1025 the new threshold you should specify.</para>
1026
1027 <para>In general, allocating large structures on the stack is a
sewardj08e31e22007-05-23 21:58:33 +00001028 bad idea, because you can easily run out of stack space,
debad57fc2005-12-03 22:33:29 +00001029 especially on systems with limited memory or which expect to
sewardj08e31e22007-05-23 21:58:33 +00001030 support large numbers of threads each with a small stack, and also
debad57fc2005-12-03 22:33:29 +00001031 because the error checking performed by Memcheck is more effective
1032 for heap-allocated data than for stack-allocated data. If you
1033 have to use this flag, you may wish to consider rewriting your
1034 code to allocate on the heap rather than on the stack.</para>
1035 </listitem>
1036 </varlistentry>
1037
sewardj95d86c02007-12-18 01:49:23 +00001038 <varlistentry id="opt.main-stacksize" xreflabel="--main-stacksize">
1039 <term>
1040 <option><![CDATA[--main-stacksize=<number>
1041 [default: use current 'ulimit' value] ]]></option>
1042 </term>
1043 <listitem>
1044 <para>Specifies the size of the main thread's stack.</para>
1045
1046 <para>To simplify its memory management, Valgrind reserves all
1047 required space for the main thread's stack at startup. That
1048 means it needs to know the required stack size at
1049 startup.</para>
1050
1051 <para>By default, Valgrind uses the current "ulimit" value for
1052 the stack size, or 16 MB, whichever is lower. In many cases
1053 this gives a stack size in the range 8 to 16 MB, which almost
1054 never overflows for most applications.</para>
1055
1056 <para>If you need a larger total stack size,
1057 use <option>--main-stacksize</option> to specify it. Only set
1058 it as high as you need, since reserving far more space than you
1059 need (that is, hundreds of megabytes more than you need)
1060 constrains Valgrind's memory allocators and may reduce the total
1061 amount of memory that Valgrind can use. This is only really of
1062 significance on 32-bit machines.</para>
1063
1064 <para>On Linux, you may request a stack of size up to 2GB.
1065 Valgrind will stop with a diagnostic message if the stack cannot
1066 be allocated. On AIX5 the allowed stack size is restricted to
1067 128MB.</para>
1068
1069 <para><option>--main-stacksize</option> only affects the stack
1070 size for the program's initial thread. It has no bearing on the
1071 size of thread stacks, as Valgrind does not allocate
1072 those.</para>
1073
1074 <para>You may need to use both <option>--main-stacksize</option>
1075 and <option>--max-stackframe</option> together. It is important
1076 to understand that <option>--main-stacksize</option> sets the
1077 maximum total stack size,
1078 whilst <option>--max-stackframe</option> specifies the largest
1079 size of any one stack frame. You will have to work out
1080 the <option>--main-stacksize</option> value for yourself
1081 (usually, if your applications segfaults). But Valgrind will
1082 tell you the needed <option>--max-stackframe</option> size, if
1083 necessary.</para>
1084
1085 <para>As discussed further in the description
1086 of <option>--max-stackframe</option>, a requirement for a large
1087 stack is a sign of potential portability problems. You are best
1088 advised to place all large data in heap-allocated memory.</para>
1089 </listitem>
1090 </varlistentry>
1091
debad57fc2005-12-03 22:33:29 +00001092</variablelist>
de03e0e7c2005-12-03 23:02:33 +00001093<!-- end of xi:include in the manpage -->
debad57fc2005-12-03 22:33:29 +00001094
njn3e986b22004-11-30 10:43:45 +00001095</sect2>
1096
debad57fc2005-12-03 22:33:29 +00001097
njn3e986b22004-11-30 10:43:45 +00001098<sect2 id="manual-core.mallocopts" xreflabel="malloc()-related Options">
1099<title><computeroutput>malloc()</computeroutput>-related Options</title>
1100
de03e0e7c2005-12-03 23:02:33 +00001101<!-- start of xi:include in the manpage -->
1102<para id="malloc-related.opts.para">For tools that use their own version of
njn3e986b22004-11-30 10:43:45 +00001103<computeroutput>malloc()</computeroutput> (e.g. Memcheck and
njn1d0825f2006-03-27 11:37:07 +00001104Massif), the following options apply.</para>
njn3e986b22004-11-30 10:43:45 +00001105
de03e0e7c2005-12-03 23:02:33 +00001106<variablelist id="malloc-related.opts.list">
njn3e986b22004-11-30 10:43:45 +00001107
debad57fc2005-12-03 22:33:29 +00001108 <varlistentry id="opt.alignment" xreflabel="--alignment">
1109 <term>
1110 <option><![CDATA[--alignment=<number> [default: 8] ]]></option>
1111 </term>
1112 <listitem>
1113 <para>By default Valgrind's <function>malloc()</function>,
1114 <function>realloc()</function>, etc, return 8-byte aligned
1115 addresses. This is standard for most processors. However, some
1116 programs might assume that <function>malloc()</function> et al
1117 return 16-byte or more aligned memory. The supplied value must be
1118 between 8 and 4096 inclusive, and must be a power of two.</para>
njn51272982005-07-25 23:18:44 +00001119 </listitem>
debad57fc2005-12-03 22:33:29 +00001120 </varlistentry>
njn51272982005-07-25 23:18:44 +00001121
debad57fc2005-12-03 22:33:29 +00001122</variablelist>
de03e0e7c2005-12-03 23:02:33 +00001123<!-- end of xi:include in the manpage -->
debad57fc2005-12-03 22:33:29 +00001124
1125</sect2>
1126
1127
1128<sect2 id="manual-core.rareopts" xreflabel="Uncommon Options">
1129<title>Uncommon Options</title>
1130
de03e0e7c2005-12-03 23:02:33 +00001131<!-- start of xi:include in the manpage -->
1132<para id="uncommon.opts.para">These options apply to all tools, as they
1133affect certain obscure workings of the Valgrind core. Most people won't
1134need to use these.</para>
debad57fc2005-12-03 22:33:29 +00001135
de03e0e7c2005-12-03 23:02:33 +00001136<variablelist id="uncommon.opts.list">
debad57fc2005-12-03 22:33:29 +00001137
1138 <varlistentry id="opt.run-libc-freeres" xreflabel="--run-libc-freeres">
1139 <term>
1140 <option><![CDATA[--run-libc-freeres=<yes|no> [default: yes] ]]></option>
1141 </term>
1142 <listitem>
1143 <para>The GNU C library (<function>libc.so</function>), which is
1144 used by all programs, may allocate memory for its own uses.
1145 Usually it doesn't bother to free that memory when the program
sewardj33878892007-11-17 09:43:25 +00001146 ends&mdash;there would be no point, since the Linux kernel reclaims
debad57fc2005-12-03 22:33:29 +00001147 all process resources when a process exits anyway, so it would
1148 just slow things down.</para>
1149
1150 <para>The glibc authors realised that this behaviour causes leak
1151 checkers, such as Valgrind, to falsely report leaks in glibc, when
1152 a leak check is done at exit. In order to avoid this, they
1153 provided a routine called <function>__libc_freeres</function>
1154 specifically to make glibc release all memory it has allocated.
njn1d0825f2006-03-27 11:37:07 +00001155 Memcheck therefore tries to run
debad57fc2005-12-03 22:33:29 +00001156 <function>__libc_freeres</function> at exit.</para>
1157
sewardj08e31e22007-05-23 21:58:33 +00001158 <para>Unfortunately, in some very old versions of glibc,
debad57fc2005-12-03 22:33:29 +00001159 <function>__libc_freeres</function> is sufficiently buggy to cause
sewardj08e31e22007-05-23 21:58:33 +00001160 segmentation faults. This was particularly noticeable on Red Hat
debad57fc2005-12-03 22:33:29 +00001161 7.1. So this flag is provided in order to inhibit the run of
1162 <function>__libc_freeres</function>. If your program seems to run
1163 fine on Valgrind, but segfaults at exit, you may find that
1164 <option>--run-libc-freeres=no</option> fixes that, although at the
1165 cost of possibly falsely reporting space leaks in
1166 <filename>libc.so</filename>.</para>
1167 </listitem>
1168 </varlistentry>
1169
1170 <varlistentry id="opt.sim-hints" xreflabel="--sim-hints">
1171 <term>
1172 <option><![CDATA[--sim-hints=hint1,hint2,... ]]></option>
1173 </term>
1174 <listitem>
1175 <para>Pass miscellaneous hints to Valgrind which slightly modify
1176 the simulated behaviour in nonstandard or dangerous ways, possibly
1177 to help the simulation of strange features. By default no hints
1178 are enabled. Use with caution! Currently known hints are:</para>
1179 <itemizedlist>
1180 <listitem>
1181 <para><option>lax-ioctls: </option> Be very lax about ioctl
1182 handling; the only assumption is that the size is
1183 correct. Doesn't require the full buffer to be initialized
1184 when writing. Without this, using some device drivers with a
1185 large number of strange ioctl commands becomes very
1186 tiresome.</para>
1187 </listitem>
1188 <listitem>
1189 <para><option>enable-inner: </option> Enable some special
1190 magic needed when the program being run is itself
1191 Valgrind.</para>
1192 </listitem>
1193 </itemizedlist>
1194 </listitem>
1195 </varlistentry>
1196
1197 <varlistentry id="opt.kernel-variant" xreflabel="--kernel-variant">
1198 <term>
1199 <option>--kernel-variant=variant1,variant2,...</option>
1200 </term>
1201 <listitem>
1202 <para>Handle system calls and ioctls arising from minor variants
1203 of the default kernel for this platform. This is useful for
1204 running on hacked kernels or with kernel modules which support
1205 nonstandard ioctls, for example. Use with caution. If you don't
1206 understand what this option does then you almost certainly don't
1207 need it. Currently known variants are:</para>
1208 <itemizedlist>
1209 <listitem>
1210 <para><option>bproc: </option> Support the sys_broc system
1211 call on x86. This is for running on BProc, which is a minor
1212 variant of standard Linux which is sometimes used for building
1213 clusters.</para>
1214 </listitem>
1215 </itemizedlist>
1216 </listitem>
1217 </varlistentry>
1218
1219 <varlistentry id="opt.show-emwarns" xreflabel="--show-emwarns">
1220 <term>
1221 <option><![CDATA[--show-emwarns=<yes|no> [default: no] ]]></option>
1222 </term>
1223 <listitem>
1224 <para>When enabled, Valgrind will emit warnings about its CPU
1225 emulation in certain cases. These are usually not
1226 interesting.</para>
1227 </listitem>
1228 </varlistentry>
1229
1230 <varlistentry id="opt.smc-check" xreflabel="--smc-check">
1231 <term>
1232 <option><![CDATA[--smc-check=<none|stack|all> [default: stack] ]]></option>
1233 </term>
1234 <listitem>
1235 <para>This option controls Valgrind's detection of self-modifying
1236 code. Valgrind can do no detection, detect self-modifying code on
1237 the stack, or detect self-modifying code anywhere. Note that the
1238 default option will catch the vast majority of cases, as far as we
1239 know. Running with <varname>all</varname> will slow Valgrind down
sewardj08e31e22007-05-23 21:58:33 +00001240 greatly. Running with <varname>none</varname> will rarely
debad57fc2005-12-03 22:33:29 +00001241 speed things up, since very little code gets put on the stack for
sewardj08e31e22007-05-23 21:58:33 +00001242 most programs.</para>
1243
1244 <para>Some architectures (including ppc32 and ppc64) require
1245 programs which create code at runtime to flush the instruction
1246 cache in between code generation and first use. Valgrind
1247 observes and honours such instructions. Hence, on ppc32/Linux
1248 and ppc64/Linux, Valgrind always provides complete, transparent
1249 support for self-modifying code. It is only on x86/Linux
1250 and amd64/Linux that you need to use this flag.</para>
debad57fc2005-12-03 22:33:29 +00001251 </listitem>
1252 </varlistentry>
1253
1254</variablelist>
de03e0e7c2005-12-03 23:02:33 +00001255<!-- end of xi:include in the manpage -->
debad57fc2005-12-03 22:33:29 +00001256
njn3e986b22004-11-30 10:43:45 +00001257</sect2>
1258
1259
1260<sect2 id="manual-core.debugopts" xreflabel="Debugging Valgrind Options">
1261<title>Debugging Valgrind Options</title>
1262
de03e0e7c2005-12-03 23:02:33 +00001263<!-- start of xi:include in the manpage -->
1264<para id="debug.opts.para">There are also some options for debugging
1265Valgrind itself. You shouldn't need to use them in the normal run of
1266things. If you wish to see the list, use the
1267<option>--help-debug</option> option.</para>
1268<!-- end of xi:include in the manpage -->
njn3e986b22004-11-30 10:43:45 +00001269
njn3e986b22004-11-30 10:43:45 +00001270</sect2>
1271
1272
1273<sect2 id="manual-core.defopts" xreflabel="Setting default options">
1274<title>Setting default Options</title>
1275
1276<para>Note that Valgrind also reads options from three places:</para>
1277
1278 <orderedlist>
1279 <listitem>
1280 <para>The file <computeroutput>~/.valgrindrc</computeroutput></para>
1281 </listitem>
1282
1283 <listitem>
1284 <para>The environment variable
1285 <computeroutput>$VALGRIND_OPTS</computeroutput></para>
1286 </listitem>
1287
1288 <listitem>
1289 <para>The file <computeroutput>./.valgrindrc</computeroutput></para>
1290 </listitem>
1291 </orderedlist>
1292
1293<para>These are processed in the given order, before the
1294command-line options. Options processed later override those
1295processed earlier; for example, options in
1296<computeroutput>./.valgrindrc</computeroutput> will take
1297precedence over those in
1298<computeroutput>~/.valgrindrc</computeroutput>. The first two
1299are particularly useful for setting the default tool to
1300use.</para>
1301
1302<para>Any tool-specific options put in
1303<computeroutput>$VALGRIND_OPTS</computeroutput> or the
1304<computeroutput>.valgrindrc</computeroutput> files should be
1305prefixed with the tool name and a colon. For example, if you
1306want Memcheck to always do leak checking, you can put the
1307following entry in <literal>~/.valgrindrc</literal>:</para>
1308
1309<programlisting><![CDATA[
1310--memcheck:leak-check=yes]]></programlisting>
1311
1312<para>This will be ignored if any tool other than Memcheck is
1313run. Without the <computeroutput>memcheck:</computeroutput>
1314part, this will cause problems if you select other tools that
1315don't understand
1316<computeroutput>--leak-check=yes</computeroutput>.</para>
1317
1318</sect2>
1319
1320</sect1>
1321
1322
sewardj778d7832007-11-22 01:21:56 +00001323
1324
1325<sect1 id="manual-core.pthreads" xreflabel="Support for Threads">
1326<title>Support for Threads</title>
1327
1328<para>Valgrind supports programs which use POSIX pthreads.
1329Getting this to work was technically challenging but it now works
1330well enough for significant threaded applications to run.</para>
1331
1332<para>The main thing to point out is that although Valgrind works
1333with the standard Linux threads library (eg. NPTL or LinuxThreads), it
1334serialises execution so that only one thread is running at a time. This
1335approach avoids the horrible implementation problems of implementing a
1336truly multiprocessor version of Valgrind, but it does mean that threaded
1337apps run only on one CPU, even if you have a multiprocessor
1338machine.</para>
1339
1340<para>Valgrind schedules your program's threads in a round-robin fashion,
1341with all threads having equal priority. It switches threads
1342every 100000 basic blocks (on x86, typically around 600000
1343instructions), which means you'll get a much finer interleaving
1344of thread executions than when run natively. This in itself may
1345cause your program to behave differently if you have some kind of
1346concurrency, critical race, locking, or similar, bugs. In that case
1347you might consider using Valgrind's Helgrind tool to track them down.</para>
1348
1349<para>Your program will use the native
1350<computeroutput>libpthread</computeroutput>, but not all of its facilities
1351will work. In particular, synchronisation of processes via shared-memory
1352segments will not work. This relies on special atomic instruction sequences
1353which Valgrind does not emulate in a way which works between processes.
1354Unfortunately there's no way for Valgrind to warn when this is happening,
1355and such calls will mostly work. Only when there's a race will
1356it fail.
1357</para>
1358
1359<para>Valgrind also supports direct use of the
1360<computeroutput>clone()</computeroutput> system call,
1361<computeroutput>futex()</computeroutput> and so on.
1362<computeroutput>clone()</computeroutput> is supported where either
1363everything is shared (a thread) or nothing is shared (fork-like); partial
1364sharing will fail. Again, any use of atomic instruction sequences in shared
1365memory between processes will not work reliably.
1366</para>
1367
1368
1369</sect1>
1370
1371<sect1 id="manual-core.signals" xreflabel="Handling of Signals">
1372<title>Handling of Signals</title>
1373
1374<para>Valgrind has a fairly complete signal implementation. It should be
1375able to cope with any POSIX-compliant use of signals.</para>
1376
1377<para>If you're using signals in clever ways (for example, catching
1378SIGSEGV, modifying page state and restarting the instruction), you're
1379probably relying on precise exceptions. In this case, you will need
1380to use <computeroutput>--vex-iropt-precise-memory-exns=yes</computeroutput>.
1381</para>
1382
1383<para>If your program dies as a result of a fatal core-dumping signal,
1384Valgrind will generate its own core file
1385(<computeroutput>vgcore.NNNNN</computeroutput>) containing your program's
1386state. You may use this core file for post-mortem debugging with gdb or
1387similar. (Note: it will not generate a core if your core dump size limit is
13880.) At the time of writing the core dumps do not include all the floating
1389point register information.</para>
1390
1391<para>In the unlikely event that Valgrind itself crashes, the operating system
1392will create a core dump in the usual way.</para>
1393
1394</sect1>
1395
1396
1397
1398
1399
1400
1401
1402
1403<sect1 id="manual-core.install" xreflabel="Building and Installing">
1404<title>Building and Installing Valgrind</title>
1405
1406<para>We use the standard Unix
1407<computeroutput>./configure</computeroutput>,
1408<computeroutput>make</computeroutput>, <computeroutput>make
1409install</computeroutput> mechanism, and we have attempted to
1410ensure that it works on machines with kernel 2.4 or 2.6 and glibc
14112.2.X to 2.5.X. Once you have completed
1412<computeroutput>make install</computeroutput> you may then want
1413to run the regression tests
1414with <computeroutput>make regtest</computeroutput>.
1415</para>
1416
1417<para>There are five options (in addition to the usual
1418<option>--prefix=</option> which affect how Valgrind is built:
1419<itemizedlist>
1420
1421 <listitem>
1422 <para><option>--enable-inner</option></para>
1423 <para>This builds Valgrind with some special magic hacks which make
1424 it possible to run it on a standard build of Valgrind (what the
1425 developers call "self-hosting"). Ordinarily you should not use
1426 this flag as various kinds of safety checks are disabled.
1427 </para>
1428 </listitem>
1429
1430 <listitem>
1431 <para><option>--enable-tls</option></para>
1432 <para>TLS (Thread Local Storage) is a relatively new mechanism which
1433 requires compiler, linker and kernel support. Valgrind tries to
1434 automatically test if TLS is supported and if so enables this option.
1435 Sometimes it cannot test for TLS, so this option allows you to
1436 override the automatic test.</para>
1437 </listitem>
1438
1439 <listitem>
1440 <para><option>--with-vex=</option></para>
1441 <para>Specifies the path to the underlying VEX dynamic-translation
1442 library. By default this is taken to be in the VEX directory off
1443 the root of the source tree.
1444 </para>
1445 </listitem>
1446
1447 <listitem>
1448 <para><option>--enable-only64bit</option></para>
1449 <para><option>--enable-only32bit</option></para>
1450 <para>On 64-bit
1451 platforms (amd64-linux, ppc64-linux), Valgrind is by default built
1452 in such a way that both 32-bit and 64-bit executables can be run.
1453 Sometimes this cleverness is a problem for a variety of reasons.
1454 These two flags allow for single-target builds in this situation.
1455 If you issue both, the configure script will complain. Note they
1456 are ignored on 32-bit-only platforms (x86-linux, ppc32-linux).
1457 </para>
1458 </listitem>
1459
1460</itemizedlist>
1461</para>
1462
1463<para>The <computeroutput>configure</computeroutput> script tests
1464the version of the X server currently indicated by the current
1465<computeroutput>$DISPLAY</computeroutput>. This is a known bug.
1466The intention was to detect the version of the current X
1467client libraries, so that correct suppressions could be selected
1468for them, but instead the test checks the server version. This
1469is just plain wrong.</para>
1470
1471<para>If you are building a binary package of Valgrind for
1472distribution, please read <literal>README_PACKAGERS</literal>
1473<xref linkend="dist.readme-packagers"/>. It contains some
1474important information.</para>
1475
1476<para>Apart from that, there's not much excitement here. Let us
1477know if you have build problems.</para>
1478
1479</sect1>
1480
1481
1482
1483<sect1 id="manual-core.problems" xreflabel="If You Have Problems">
1484<title>If You Have Problems</title>
1485
1486<para>Contact us at <ulink url="&vg-url;">&vg-url;</ulink>.</para>
1487
1488<para>See <xref linkend="manual-core.limits"/> for the known
1489limitations of Valgrind, and for a list of programs which are
1490known not to work on it.</para>
1491
1492<para>All parts of the system make heavy use of assertions and
1493internal self-checks. They are permanently enabled, and we have no
1494plans to disable them. If one of them breaks, please mail us!</para>
1495
1496<para>If you get an assertion failure
1497in <filename>m_mallocfree.c</filename>, this may have happened because
1498your program wrote off the end of a malloc'd block, or before its
1499beginning. Valgrind hopefully will have emitted a proper message to that
1500effect before dying in this way. This is a known problem which
1501we should fix.</para>
1502
1503<para>Read the <xref linkend="FAQ"/> for more advice about common problems,
1504crashes, etc.</para>
1505
1506</sect1>
1507
1508
1509
1510<sect1 id="manual-core.limits" xreflabel="Limitations">
1511<title>Limitations</title>
1512
1513<para>The following list of limitations seems long. However, most
1514programs actually work fine.</para>
1515
1516<para>Valgrind will run Linux ELF binaries, on a kernel 2.4.X or 2.6.X
1517system, on the x86, amd64, ppc32 and ppc64 architectures, subject to the
1518following constraints:</para>
1519
1520 <itemizedlist>
1521 <listitem>
1522 <para>On x86 and amd64, there is no support for 3DNow! instructions.
1523 If the translator encounters these, Valgrind will generate a SIGILL
1524 when the instruction is executed. Apart from that, on x86 and amd64,
1525 essentially all instructions are supported, up to and including SSE3.
1526 </para>
1527
1528 <para>On ppc32 and ppc64, almost all integer, floating point and Altivec
1529 instructions are supported. Specifically: integer and FP insns that are
1530 mandatory for PowerPC, the "General-purpose optional" group (fsqrt, fsqrts,
1531 stfiwx), the "Graphics optional" group (fre, fres, frsqrte, frsqrtes), and
1532 the Altivec (also known as VMX) SIMD instruction set, are supported.</para>
1533 </listitem>
1534
1535 <listitem>
1536 <para>Atomic instruction sequences are not properly supported, in the
1537 sense that their atomicity is not preserved. This will affect any
1538 use of synchronization via memory shared between processes. They
1539 will appear to work, but fail sporadically.</para>
1540 </listitem>
1541
1542 <listitem>
1543 <para>If your program does its own memory management, rather than
1544 using malloc/new/free/delete, it should still work, but Memcheck's
1545 error checking won't be so effective. If you describe your program's
1546 memory management scheme using "client requests"
sewardj4c3270b2007-11-25 14:09:26 +00001547 (see <xref linkend="manual-core-adv.clientreq"/>), Memcheck can do
sewardj778d7832007-11-22 01:21:56 +00001548 better. Nevertheless, using malloc/new and free/delete is still the
1549 best approach.</para>
1550 </listitem>
1551
1552 <listitem>
1553 <para>Valgrind's signal simulation is not as robust as it could be.
1554 Basic POSIX-compliant sigaction and sigprocmask functionality is
1555 supplied, but it's conceivable that things could go badly awry if you
1556 do weird things with signals. Workaround: don't. Programs that do
1557 non-POSIX signal tricks are in any case inherently unportable, so
1558 should be avoided if possible.</para>
1559 </listitem>
1560
1561 <listitem>
1562 <para>Machine instructions, and system calls, have been implemented
1563 on demand. So it's possible, although unlikely, that a program will
1564 fall over with a message to that effect. If this happens, please
1565 report all the details printed out, so we can try and implement the
1566 missing feature.</para>
1567 </listitem>
1568
1569 <listitem>
1570 <para>Memory consumption of your program is majorly increased whilst
1571 running under Valgrind. This is due to the large amount of
1572 administrative information maintained behind the scenes. Another
1573 cause is that Valgrind dynamically translates the original
1574 executable. Translated, instrumented code is 12-18 times larger than
1575 the original so you can easily end up with 50+ MB of translations
1576 when running (eg) a web browser.</para>
1577 </listitem>
1578
1579 <listitem>
1580 <para>Valgrind can handle dynamically-generated code just fine. If
1581 you regenerate code over the top of old code (ie. at the same memory
1582 addresses), if the code is on the stack Valgrind will realise the
1583 code has changed, and work correctly. This is necessary to handle
1584 the trampolines GCC uses to implemented nested functions. If you
1585 regenerate code somewhere other than the stack, you will need to use
1586 the <option>--smc-check=all</option> flag, and Valgrind will run more
1587 slowly than normal.</para>
1588 </listitem>
1589
1590 <listitem>
1591 <para>As of version 3.0.0, Valgrind has the following limitations
1592 in its implementation of x86/AMD64 floating point relative to
1593 IEEE754.</para>
1594
1595 <para>Precision: There is no support for 80 bit arithmetic.
1596 Internally, Valgrind represents all such "long double" numbers in 64
1597 bits, and so there may be some differences in results. Whether or
1598 not this is critical remains to be seen. Note, the x86/amd64
1599 fldt/fstpt instructions (read/write 80-bit numbers) are correctly
1600 simulated, using conversions to/from 64 bits, so that in-memory
1601 images of 80-bit numbers look correct if anyone wants to see.</para>
1602
1603 <para>The impression observed from many FP regression tests is that
1604 the accuracy differences aren't significant. Generally speaking, if
1605 a program relies on 80-bit precision, there may be difficulties
1606 porting it to non x86/amd64 platforms which only support 64-bit FP
1607 precision. Even on x86/amd64, the program may get different results
1608 depending on whether it is compiled to use SSE2 instructions (64-bits
1609 only), or x87 instructions (80-bit). The net effect is to make FP
1610 programs behave as if they had been run on a machine with 64-bit IEEE
1611 floats, for example PowerPC. On amd64 FP arithmetic is done by
1612 default on SSE2, so amd64 looks more like PowerPC than x86 from an FP
1613 perspective, and there are far fewer noticeable accuracy differences
1614 than with x86.</para>
1615
1616 <para>Rounding: Valgrind does observe the 4 IEEE-mandated rounding
1617 modes (to nearest, to +infinity, to -infinity, to zero) for the
1618 following conversions: float to integer, integer to float where
1619 there is a possibility of loss of precision, and float-to-float
1620 rounding. For all other FP operations, only the IEEE default mode
1621 (round to nearest) is supported.</para>
1622
1623 <para>Numeric exceptions in FP code: IEEE754 defines five types of
1624 numeric exception that can happen: invalid operation (sqrt of
1625 negative number, etc), division by zero, overflow, underflow,
1626 inexact (loss of precision).</para>
1627
1628 <para>For each exception, two courses of action are defined by IEEE754:
1629 either (1) a user-defined exception handler may be called, or (2) a
1630 default action is defined, which "fixes things up" and allows the
1631 computation to proceed without throwing an exception.</para>
1632
1633 <para>Currently Valgrind only supports the default fixup actions.
1634 Again, feedback on the importance of exception support would be
1635 appreciated.</para>
1636
1637 <para>When Valgrind detects that the program is trying to exceed any
1638 of these limitations (setting exception handlers, rounding mode, or
1639 precision control), it can print a message giving a traceback of
1640 where this has happened, and continue execution. This behaviour used
1641 to be the default, but the messages are annoying and so showing them
1642 is now disabled by default. Use <option>--show-emwarns=yes</option> to see
1643 them.</para>
1644
1645 <para>The above limitations define precisely the IEEE754 'default'
1646 behaviour: default fixup on all exceptions, round-to-nearest
1647 operations, and 64-bit precision.</para>
1648 </listitem>
1649
1650 <listitem>
1651 <para>As of version 3.0.0, Valgrind has the following limitations in
1652 its implementation of x86/AMD64 SSE2 FP arithmetic, relative to
1653 IEEE754.</para>
1654
1655 <para>Essentially the same: no exceptions, and limited observance of
1656 rounding mode. Also, SSE2 has control bits which make it treat
1657 denormalised numbers as zero (DAZ) and a related action, flush
1658 denormals to zero (FTZ). Both of these cause SSE2 arithmetic to be
1659 less accurate than IEEE requires. Valgrind detects, ignores, and can
1660 warn about, attempts to enable either mode.</para>
1661 </listitem>
1662
1663 <listitem>
1664 <para>As of version 3.2.0, Valgrind has the following limitations
1665 in its implementation of PPC32 and PPC64 floating point
1666 arithmetic, relative to IEEE754.</para>
1667
1668 <para>Scalar (non-Altivec): Valgrind provides a bit-exact emulation of
1669 all floating point instructions, except for "fre" and "fres", which are
1670 done more precisely than required by the PowerPC architecture specification.
1671 All floating point operations observe the current rounding mode.
1672 </para>
1673
1674 <para>However, fpscr[FPRF] is not set after each operation. That could
1675 be done but would give measurable performance overheads, and so far
1676 no need for it has been found.</para>
1677
1678 <para>As on x86/AMD64, IEEE754 exceptions are not supported: all floating
1679 point exceptions are handled using the default IEEE fixup actions.
1680 Valgrind detects, ignores, and can warn about, attempts to unmask
1681 the 5 IEEE FP exception kinds by writing to the floating-point status
1682 and control register (fpscr).
1683 </para>
1684
1685 <para>Vector (Altivec, VMX): essentially as with x86/AMD64 SSE/SSE2:
1686 no exceptions, and limited observance of rounding mode.
1687 For Altivec, FP arithmetic
1688 is done in IEEE/Java mode, which is more accurate than the Linux default
1689 setting. "More accurate" means that denormals are handled properly,
1690 rather than simply being flushed to zero.</para>
1691 </listitem>
1692 </itemizedlist>
1693
1694 <para>Programs which are known not to work are:</para>
1695 <itemizedlist>
1696 <listitem>
1697 <para>emacs starts up but immediately concludes it is out of
1698 memory and aborts. It may be that Memcheck does not provide
1699 a good enough emulation of the
1700 <computeroutput>mallinfo</computeroutput> function.
1701 Emacs works fine if you build it to use
1702 the standard malloc/free routines.</para>
1703 </listitem>
1704 </itemizedlist>
1705
1706</sect1>
1707
1708
1709<sect1 id="manual-core.example" xreflabel="An Example Run">
1710<title>An Example Run</title>
1711
1712<para>This is the log for a run of a small program using Memcheck.
1713The program is in fact correct, and the reported error is as the
1714result of a potentially serious code generation bug in GNU g++
1715(snapshot 20010527).</para>
1716
1717<programlisting><![CDATA[
1718sewardj@phoenix:~/newmat10$ ~/Valgrind-6/valgrind -v ./bogon
1719==25832== Valgrind 0.10, a memory error detector for x86 RedHat 7.1.
1720==25832== Copyright (C) 2000-2001, and GNU GPL'd, by Julian Seward.
1721==25832== Startup, with flags:
1722==25832== --suppressions=/home/sewardj/Valgrind/redhat71.supp
1723==25832== reading syms from /lib/ld-linux.so.2
1724==25832== reading syms from /lib/libc.so.6
1725==25832== reading syms from /mnt/pima/jrs/Inst/lib/libgcc_s.so.0
1726==25832== reading syms from /lib/libm.so.6
1727==25832== reading syms from /mnt/pima/jrs/Inst/lib/libstdc++.so.3
1728==25832== reading syms from /home/sewardj/Valgrind/valgrind.so
1729==25832== reading syms from /proc/self/exe
1730==25832==
1731==25832== Invalid read of size 4
1732==25832== at 0x8048724: BandMatrix::ReSize(int,int,int) (bogon.cpp:45)
1733==25832== by 0x80487AF: main (bogon.cpp:66)
1734==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd
1735==25832==
1736==25832== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
1737==25832== malloc/free: in use at exit: 0 bytes in 0 blocks.
1738==25832== malloc/free: 0 allocs, 0 frees, 0 bytes allocated.
1739==25832== For a detailed leak analysis, rerun with: --leak-check=yes
1740]]></programlisting>
1741
1742<para>The GCC folks fixed this about a week before gcc-3.0
1743shipped.</para>
1744
1745</sect1>
1746
1747
1748<sect1 id="manual-core.warnings" xreflabel="Warning Messages">
1749<title>Warning Messages You Might See</title>
1750
1751<para>Most of these only appear if you run in verbose mode
1752(enabled by <computeroutput>-v</computeroutput>):</para>
1753
1754 <itemizedlist>
1755
1756 <listitem>
1757 <para><computeroutput>More than 100 errors detected. Subsequent
1758 errors will still be recorded, but in less detail than
1759 before.</computeroutput></para>
1760
1761 <para>After 100 different errors have been shown, Valgrind becomes
1762 more conservative about collecting them. It then requires only the
1763 program counters in the top two stack frames to match when deciding
1764 whether or not two errors are really the same one. Prior to this
1765 point, the PCs in the top four frames are required to match. This
1766 hack has the effect of slowing down the appearance of new errors
1767 after the first 100. The 100 constant can be changed by recompiling
1768 Valgrind.</para>
1769 </listitem>
1770
1771 <listitem>
1772 <para><computeroutput>More than 1000 errors detected. I'm not
1773 reporting any more. Final error counts may be inaccurate. Go fix
1774 your program!</computeroutput></para>
1775
1776 <para>After 1000 different errors have been detected, Valgrind
1777 ignores any more. It seems unlikely that collecting even more
1778 different ones would be of practical help to anybody, and it avoids
1779 the danger that Valgrind spends more and more of its time comparing
1780 new errors against an ever-growing collection. As above, the 1000
1781 number is a compile-time constant.</para>
1782 </listitem>
1783
1784 <listitem>
1785 <para><computeroutput>Warning: client switching stacks?</computeroutput></para>
1786
1787 <para>Valgrind spotted such a large change in the stack pointer
1788 that it guesses the client is switching to
1789 a different stack. At this point it makes a kludgey guess where the
1790 base of the new stack is, and sets memory permissions accordingly.
1791 You may get many bogus error messages following this, if Valgrind
1792 guesses wrong. At the moment "large change" is defined as a change
1793 of more that 2000000 in the value of the
1794 stack pointer register.</para>
1795 </listitem>
1796
1797 <listitem>
1798 <para><computeroutput>Warning: client attempted to close Valgrind's
1799 logfile fd &lt;number&gt;</computeroutput></para>
1800
1801 <para>Valgrind doesn't allow the client to close the logfile,
1802 because you'd never see any diagnostic information after that point.
1803 If you see this message, you may want to use the
1804 <option>--log-fd=&lt;number&gt;</option> option to specify a
1805 different logfile file-descriptor number.</para>
1806 </listitem>
1807
1808 <listitem>
1809 <para><computeroutput>Warning: noted but unhandled ioctl
1810 &lt;number&gt;</computeroutput></para>
1811
1812 <para>Valgrind observed a call to one of the vast family of
1813 <computeroutput>ioctl</computeroutput> system calls, but did not
1814 modify its memory status info (because nobody has yet written a
1815 suitable wrapper). The call will still have gone through, but you may get
1816 spurious errors after this as a result of the non-update of the
1817 memory info.</para>
1818 </listitem>
1819
1820 <listitem>
1821 <para><computeroutput>Warning: set address range perms: large range
1822 &lt;number></computeroutput></para>
1823
1824 <para>Diagnostic message, mostly for benefit of the Valgrind
1825 developers, to do with memory permissions.</para>
1826 </listitem>
1827
1828 </itemizedlist>
1829
1830</sect1>
1831
1832
1833
sewardjf5a491c2006-03-13 13:40:57 +00001834
1835
sewardja737e652006-03-19 18:19:11 +00001836
njn3e986b22004-11-30 10:43:45 +00001837</chapter>