blob: 0fb6c9d33423a3a29fce6056c8a072f7b63c4350 [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
njnf4b47582009-08-10 01:15:30 +000010<para>This chapter describes the Valgrind core services, command-line
11options and behaviours. That means it is relevant regardless of what
12particular tool you are using. The information should be sufficient for you
13to make effective day-to-day use of Valgrind. Advanced topics related to
sewardja5fac792007-11-25 00:55:11 +000014the 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,
njn7316df22009-08-04 01:16:01 +000029or otherwise modify the program to be checked.</para>
njn3e986b22004-11-30 10:43:45 +000030
njn7316df22009-08-04 01:16:01 +000031<para>You invoke Valgrind like this:</para>
32<programlisting><![CDATA[
33valgrind [valgrind-options] your-prog [your-prog-options]]]></programlisting>
34
35<para>The most important option is <option>--tool</option> which dictates
36which Valgrind tool to run. For example, if want to run the command
37<computeroutput>ls -l</computeroutput> using the memory-checking tool
38Memcheck, issue this command:</para>
njn3e986b22004-11-30 10:43:45 +000039
40<programlisting><![CDATA[
41valgrind --tool=memcheck ls -l]]></programlisting>
42
njn7316df22009-08-04 01:16:01 +000043<para>However, Memcheck is the default, so if you want to use it you can
njnf4b47582009-08-10 01:15:30 +000044omit the <option>--tool</option> option.</para>
njn779a2d62005-07-25 00:12:19 +000045
debad57fc2005-12-03 22:33:29 +000046<para>Regardless of which tool is in use, Valgrind takes control of your
47program before it starts. Debugging information is read from the
48executable and associated libraries, so that error messages and other
sewardj08e31e22007-05-23 21:58:33 +000049outputs can be phrased in terms of source code locations, when
50appropriate.</para>
njn3e986b22004-11-30 10:43:45 +000051
debad57fc2005-12-03 22:33:29 +000052<para>Your program is then run on a synthetic CPU provided by the
53Valgrind core. As new code is executed for the first time, the core
54hands the code to the selected tool. The tool adds its own
55instrumentation code to this and hands the result back to the core,
56which coordinates the continued execution of this instrumented
57code.</para>
njn3e986b22004-11-30 10:43:45 +000058
debad57fc2005-12-03 22:33:29 +000059<para>The amount of instrumentation code added varies widely between
60tools. At one end of the scale, Memcheck adds code to check every
sewardj08e31e22007-05-23 21:58:33 +000061memory access and every value computed,
62making it run 10-50 times slower than natively.
njn7316df22009-08-04 01:16:01 +000063At the other end of the spectrum, the minimal tool, called Nulgrind,
64adds no instrumentation at all and causes in total "only" about a 4 times
65slowdown.</para>
njn3e986b22004-11-30 10:43:45 +000066
debad57fc2005-12-03 22:33:29 +000067<para>Valgrind simulates every single instruction your program executes.
68Because of this, the active tool checks, or profiles, not only the code
njn7316df22009-08-04 01:16:01 +000069in your application but also in all supporting dynamically-linked libraries,
70including the C library, graphical libraries, and so on.</para>
njn3e986b22004-11-30 10:43:45 +000071
sewardj08e31e22007-05-23 21:58:33 +000072<para>If you're using an error-detection tool, Valgrind may
njn7316df22009-08-04 01:16:01 +000073detect errors in system libraries, for example the GNU C or X11
debad57fc2005-12-03 22:33:29 +000074libraries, which you have to use. You might not be interested in these
75errors, since you probably have no control over that code. Therefore,
76Valgrind allows you to selectively suppress errors, by recording them in
77a suppressions file which is read when Valgrind starts up. The build
njn7316df22009-08-04 01:16:01 +000078mechanism selects default suppressions which give reasonable
79behaviour for the OS and libraries detected on your machine.
debad57fc2005-12-03 22:33:29 +000080To make it easier to write suppressions, you can use the
sewardj08e31e22007-05-23 21:58:33 +000081<option>--gen-suppressions=yes</option> option. This tells Valgrind to
82print out a suppression for each reported error, which you can then
debad57fc2005-12-03 22:33:29 +000083copy into a suppressions file.</para>
njn3e986b22004-11-30 10:43:45 +000084
debad57fc2005-12-03 22:33:29 +000085<para>Different error-checking tools report different kinds of errors.
86The suppression mechanism therefore allows you to say which tool or
87tool(s) each suppression applies to.</para>
njn3e986b22004-11-30 10:43:45 +000088
89</sect1>
90
91
92<sect1 id="manual-core.started" xreflabel="Getting started">
93<title>Getting started</title>
94
debad57fc2005-12-03 22:33:29 +000095<para>First off, consider whether it might be beneficial to recompile
96your application and supporting libraries with debugging info enabled
njnf4b47582009-08-10 01:15:30 +000097(the <option>-g</option> option). Without debugging info, the best
debad57fc2005-12-03 22:33:29 +000098Valgrind tools will be able to do is guess which function a particular
99piece of code belongs to, which makes both error messages and profiling
sewardj08e31e22007-05-23 21:58:33 +0000100output nearly useless. With <option>-g</option>, you'll get
debad57fc2005-12-03 22:33:29 +0000101messages which point directly to the relevant source code lines.</para>
njn3e986b22004-11-30 10:43:45 +0000102
njnf4b47582009-08-10 01:15:30 +0000103<para>Another option you might like to consider, if you are working with
debad57fc2005-12-03 22:33:29 +0000104C++, is <option>-fno-inline</option>. That makes it easier to see the
105function-call chain, which can help reduce confusion when navigating
sewardj08e31e22007-05-23 21:58:33 +0000106around large C++ apps. For example, debugging
njnf4b47582009-08-10 01:15:30 +0000107OpenOffice.org with Memcheck is a bit easier when using this option. You
debad57fc2005-12-03 22:33:29 +0000108don't have to do this, but doing so helps Valgrind produce more accurate
109and less confusing error reports. Chances are you're set up like this
njn7316df22009-08-04 01:16:01 +0000110already, if you intended to debug your program with GNU GDB, or some
debad57fc2005-12-03 22:33:29 +0000111other debugger.</para>
njn3e986b22004-11-30 10:43:45 +0000112
njn3d92f9c2007-10-17 22:29:08 +0000113<para>If you are planning to use Memcheck: On rare
njn7e5d4ed2009-07-30 02:57:52 +0000114occasions, compiler optimisations (at <option>-O2</option>
115and above, and sometimes <option>-O1</option>) have been
njn3d92f9c2007-10-17 22:29:08 +0000116observed to generate code which fools Memcheck into wrongly reporting
117uninitialised value errors, or missing uninitialised value errors. We have
118looked in detail into fixing this, and unfortunately the result is that
119doing so would give a further significant slowdown in what is already a slow
120tool. So the best solution is to turn off optimisation altogether. Since
sewardj33878892007-11-17 09:43:25 +0000121this often makes things unmanageably slow, a reasonable compromise is to use
njn7e5d4ed2009-07-30 02:57:52 +0000122<option>-O</option>. This gets you the majority of the
njn3d92f9c2007-10-17 22:29:08 +0000123benefits of higher optimisation levels whilst keeping relatively small the
njn9bd4bd42007-10-18 23:14:48 +0000124chances of false positives or false negatives from Memcheck. Also, you
njn7e5d4ed2009-07-30 02:57:52 +0000125should compile your code with <option>-Wall</option> because
njn9bd4bd42007-10-18 23:14:48 +0000126it can identify some or all of the problems that Valgrind can miss at the
njn7e5d4ed2009-07-30 02:57:52 +0000127higher optimisation levels. (Using <option>-Wall</option>
njn9bd4bd42007-10-18 23:14:48 +0000128is also a good idea in general.) All other tools (as far as we know) are
njn7316df22009-08-04 01:16:01 +0000129unaffected by optimisation level, and for profiling tools like Cachegrind it
130is better to compile your program at its normal optimisation level.</para>
njn3e986b22004-11-30 10:43:45 +0000131
debad57fc2005-12-03 22:33:29 +0000132<para>Valgrind understands both the older "stabs" debugging format, used
sewardje089f012010-10-13 21:47:29 +0000133by GCC versions prior to 3.1, and the newer DWARF2/3/4 formats
njn7316df22009-08-04 01:16:01 +0000134used by GCC
sewardj08e31e22007-05-23 21:58:33 +00001353.1 and later. We continue to develop our debug-info readers,
debad57fc2005-12-03 22:33:29 +0000136although the majority of effort will naturally enough go into the newer
sewardje089f012010-10-13 21:47:29 +0000137DWARF readers.</para>
njn3e986b22004-11-30 10:43:45 +0000138
njn7316df22009-08-04 01:16:01 +0000139<para>When you're ready to roll, run Valgrind as described above.
140Note that you should run the real
debad57fc2005-12-03 22:33:29 +0000141(machine-code) executable here. If your application is started by, for
njn7316df22009-08-04 01:16:01 +0000142example, a shell or Perl script, you'll need to modify it to invoke
debad57fc2005-12-03 22:33:29 +0000143Valgrind on the real executables. Running such scripts directly under
144Valgrind will result in you getting error reports pertaining to
njn7316df22009-08-04 01:16:01 +0000145<filename>/bin/sh</filename>,
146<filename>/usr/bin/perl</filename>, or whatever interpreter
debad57fc2005-12-03 22:33:29 +0000147you're using. This may not be what you want and can be confusing. You
njnf4b47582009-08-10 01:15:30 +0000148can force the issue by giving the option
debad57fc2005-12-03 22:33:29 +0000149<option>--trace-children=yes</option>, but confusion is still
150likely.</para>
njn3e986b22004-11-30 10:43:45 +0000151
152</sect1>
153
154
debad57fc2005-12-03 22:33:29 +0000155<sect1 id="manual-core.comment" xreflabel="The Commentary">
156<title>The Commentary</title>
njn3e986b22004-11-30 10:43:45 +0000157
debad57fc2005-12-03 22:33:29 +0000158<para>Valgrind tools write a commentary, a stream of text, detailing
159error reports and other significant events. All lines in the commentary
160have following form:
njn3e986b22004-11-30 10:43:45 +0000161
162<programlisting><![CDATA[
163==12345== some-message-from-Valgrind]]></programlisting>
164</para>
165
debad57fc2005-12-03 22:33:29 +0000166<para>The <computeroutput>12345</computeroutput> is the process ID.
167This scheme makes it easy to distinguish program output from Valgrind
168commentary, and also easy to differentiate commentaries from different
169processes which have become merged together, for whatever reason.</para>
njn3e986b22004-11-30 10:43:45 +0000170
debad57fc2005-12-03 22:33:29 +0000171<para>By default, Valgrind tools write only essential messages to the
172commentary, so as to avoid flooding you with information of secondary
173importance. If you want more information about what is happening,
njnf4b47582009-08-10 01:15:30 +0000174re-run, passing the <option>-v</option> option to Valgrind. A second
debad57fc2005-12-03 22:33:29 +0000175<option>-v</option> gives yet more detail.
sewardj053fe982005-11-15 19:51:04 +0000176</para>
njn3e986b22004-11-30 10:43:45 +0000177
debad57fc2005-12-03 22:33:29 +0000178<para>You can direct the commentary to three different places:</para>
njn3e986b22004-11-30 10:43:45 +0000179
180<orderedlist>
181
debad57fc2005-12-03 22:33:29 +0000182 <listitem id="manual-core.out2fd" xreflabel="Directing output to fd">
183 <para>The default: send it to a file descriptor, which is by default
184 2 (stderr). So, if you give the core no options, it will write
185 commentary to the standard error stream. If you want to send it to
186 some other file descriptor, for example number 9, you can specify
187 <option>--log-fd=9</option>.</para>
188
189 <para>This is the simplest and most common arrangement, but can
sewardj08e31e22007-05-23 21:58:33 +0000190 cause problems when Valgrinding entire trees of processes which
debad57fc2005-12-03 22:33:29 +0000191 expect specific file descriptors, particularly stdin/stdout/stderr,
192 to be available for their own use.</para>
njn3e986b22004-11-30 10:43:45 +0000193 </listitem>
194
195 <listitem id="manual-core.out2file"
debad57fc2005-12-03 22:33:29 +0000196 xreflabel="Directing output to file"> <para>A less intrusive
197 option is to write the commentary to a file, which you specify by
njn374a36d2007-11-23 01:41:32 +0000198 <option>--log-file=filename</option>. There are special format
199 specifiers that can be used to use a process ID or an environment
200 variable name in the log file name. These are useful/necessary if your
201 program invokes multiple processes (especially for MPI programs).
202 See the <link linkend="manual-core.basicopts">basic options section</link>
203 for more details.</para>
njn3e986b22004-11-30 10:43:45 +0000204 </listitem>
205
206 <listitem id="manual-core.out2socket"
debad57fc2005-12-03 22:33:29 +0000207 xreflabel="Directing output to network socket"> <para>The
208 least intrusive option is to send the commentary to a network
209 socket. The socket is specified as an IP address and port number
210 pair, like this: <option>--log-socket=192.168.0.1:12345</option> if
sewardj08e31e22007-05-23 21:58:33 +0000211 you want to send the output to host IP 192.168.0.1 port 12345
212 (note: we
debad57fc2005-12-03 22:33:29 +0000213 have no idea if 12345 is a port of pre-existing significance). You
214 can also omit the port number:
215 <option>--log-socket=192.168.0.1</option>, in which case a default
216 port of 1500 is used. This default is defined by the constant
217 <computeroutput>VG_CLO_DEFAULT_LOGPORT</computeroutput> in the
218 sources.</para>
njn3e986b22004-11-30 10:43:45 +0000219
debad57fc2005-12-03 22:33:29 +0000220 <para>Note, unfortunately, that you have to use an IP address here,
221 rather than a hostname.</para>
njn3e986b22004-11-30 10:43:45 +0000222
sewardj08e31e22007-05-23 21:58:33 +0000223 <para>Writing to a network socket is pointless if you don't
debad57fc2005-12-03 22:33:29 +0000224 have something listening at the other end. We provide a simple
225 listener program,
226 <computeroutput>valgrind-listener</computeroutput>, which accepts
227 connections on the specified port and copies whatever it is sent to
228 stdout. Probably someone will tell us this is a horrible security
229 risk. It seems likely that people will write more sophisticated
230 listeners in the fullness of time.</para>
njn3e986b22004-11-30 10:43:45 +0000231
njn7316df22009-08-04 01:16:01 +0000232 <para><computeroutput>valgrind-listener</computeroutput> can accept
233 simultaneous connections from up to 50 Valgrinded processes. In front
234 of each line of output it prints the current number of active
235 connections in round brackets.</para>
njn3e986b22004-11-30 10:43:45 +0000236
njn7316df22009-08-04 01:16:01 +0000237 <para><computeroutput>valgrind-listener</computeroutput> accepts two
njnf4b47582009-08-10 01:15:30 +0000238 command-line options:</para>
njn3e986b22004-11-30 10:43:45 +0000239 <itemizedlist>
debad57fc2005-12-03 22:33:29 +0000240 <listitem>
241 <para><option>-e</option> or <option>--exit-at-zero</option>:
242 when the number of connected processes falls back to zero,
243 exit. Without this, it will run forever, that is, until you
244 send it Control-C.</para>
245 </listitem>
246 <listitem>
247 <para><option>portnumber</option>: changes the port it listens
248 on from the default (1500). The specified port must be in the
249 range 1024 to 65535. The same restriction applies to port
250 numbers specified by a <option>--log-socket</option> to
251 Valgrind itself.</para>
252 </listitem>
njn3e986b22004-11-30 10:43:45 +0000253 </itemizedlist>
254
sewardj08e31e22007-05-23 21:58:33 +0000255 <para>If a Valgrinded process fails to connect to a listener, for
debad57fc2005-12-03 22:33:29 +0000256 whatever reason (the listener isn't running, invalid or unreachable
257 host or port, etc), Valgrind switches back to writing the commentary
258 to stderr. The same goes for any process which loses an established
259 connection to a listener. In other words, killing the listener
260 doesn't kill the processes sending data to it.</para>
njn3e986b22004-11-30 10:43:45 +0000261 </listitem>
njn3e986b22004-11-30 10:43:45 +0000262
debad57fc2005-12-03 22:33:29 +0000263</orderedlist>
264
265<para>Here is an important point about the relationship between the
266commentary and profiling output from tools. The commentary contains a
267mix of messages from the Valgrind core and the selected tool. If the
268tool reports errors, it will report them to the commentary. However, if
269the tool does profiling, the profile data will be written to a file of
270some kind, depending on the tool, and independent of what
271<option>--log-*</option> options are in force. The commentary is
272intended to be a low-bandwidth, human-readable channel. Profiling data,
273on the other hand, is usually voluminous and not meaningful without
274further processing, which is why we have chosen this arrangement.</para>
njn3e986b22004-11-30 10:43:45 +0000275
276</sect1>
277
278
279<sect1 id="manual-core.report" xreflabel="Reporting of errors">
280<title>Reporting of errors</title>
281
sewardj08e31e22007-05-23 21:58:33 +0000282<para>When an error-checking tool
283detects something bad happening in the program, an error
284message is written to the commentary. Here's an example from Memcheck:</para>
njn3e986b22004-11-30 10:43:45 +0000285
286<programlisting><![CDATA[
287==25832== Invalid read of size 4
288==25832== at 0x8048724: BandMatrix::ReSize(int, int, int) (bogon.cpp:45)
289==25832== by 0x80487AF: main (bogon.cpp:66)
njn21f91952005-03-12 22:14:42 +0000290==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd]]></programlisting>
njn3e986b22004-11-30 10:43:45 +0000291
debad57fc2005-12-03 22:33:29 +0000292<para>This message says that the program did an illegal 4-byte read of
293address 0xBFFFF74C, which, as far as Memcheck can tell, is not a valid
njn7316df22009-08-04 01:16:01 +0000294stack address, nor corresponds to any current heap blocks or recently freed
295heap blocks. The read is happening at line 45 of
debad57fc2005-12-03 22:33:29 +0000296<filename>bogon.cpp</filename>, called from line 66 of the same file,
njn7316df22009-08-04 01:16:01 +0000297etc. For errors associated with an identified (current or freed) heap block,
298for example reading freed memory, Valgrind reports not only the
299location where the error happened, but also where the associated heap block
300was allocated/freed.</para>
njn3e986b22004-11-30 10:43:45 +0000301
debad57fc2005-12-03 22:33:29 +0000302<para>Valgrind remembers all error reports. When an error is detected,
303it is compared against old reports, to see if it is a duplicate. If so,
304the error is noted, but no further commentary is emitted. This avoids
305you being swamped with bazillions of duplicate error reports.</para>
njn3e986b22004-11-30 10:43:45 +0000306
debad57fc2005-12-03 22:33:29 +0000307<para>If you want to know how many times each error occurred, run with
308the <option>-v</option> option. When execution finishes, all the
309reports are printed out, along with, and sorted by, their occurrence
310counts. This makes it easy to see which errors have occurred most
311frequently.</para>
njn3e986b22004-11-30 10:43:45 +0000312
debad57fc2005-12-03 22:33:29 +0000313<para>Errors are reported before the associated operation actually
njn7316df22009-08-04 01:16:01 +0000314happens. For example, if you're using Memcheck and your program attempts to
315read from address zero, Memcheck will emit a message to this effect, and
316your program will then likely die with a segmentation fault.</para>
njn3e986b22004-11-30 10:43:45 +0000317
debad57fc2005-12-03 22:33:29 +0000318<para>In general, you should try and fix errors in the order that they
319are reported. Not doing so can be confusing. For example, a program
320which copies uninitialised values to several memory locations, and later
321uses them, will generate several error messages, when run on Memcheck.
322The first such error message may well give the most direct clue to the
323root cause of the problem.</para>
njn3e986b22004-11-30 10:43:45 +0000324
325<para>The process of detecting duplicate errors is quite an
326expensive one and can become a significant performance overhead
327if your program generates huge quantities of errors. To avoid
sewardj053fe982005-11-15 19:51:04 +0000328serious problems, Valgrind will simply stop collecting
sewardj08e31e22007-05-23 21:58:33 +0000329errors after 1,000 different errors have been seen, or 10,000,000 errors
njn3e986b22004-11-30 10:43:45 +0000330in total have been seen. In this situation you might as well
331stop your program and fix it, because Valgrind won't tell you
sewardj08e31e22007-05-23 21:58:33 +0000332anything else useful after this. Note that the 1,000/10,000,000 limits
njn3e986b22004-11-30 10:43:45 +0000333apply after suppressed errors are removed. These limits are
njnc7561b92005-06-19 01:24:32 +0000334defined in <filename>m_errormgr.c</filename> and can be increased
njn3e986b22004-11-30 10:43:45 +0000335if necessary.</para>
336
337<para>To avoid this cutoff you can use the
njnf4b47582009-08-10 01:15:30 +0000338<option>--error-limit=no</option> option. Then Valgrind will always show
339errors, regardless of how many there are. Use this option carefully,
debad57fc2005-12-03 22:33:29 +0000340since it may have a bad effect on performance.</para>
njn3e986b22004-11-30 10:43:45 +0000341
342</sect1>
343
344
345<sect1 id="manual-core.suppress" xreflabel="Suppressing errors">
346<title>Suppressing errors</title>
347
njn7316df22009-08-04 01:16:01 +0000348<para>The error-checking tools detect numerous problems in the system
349libraries, such as the C library,
350which come pre-installed with your OS. You can't easily fix
debad57fc2005-12-03 22:33:29 +0000351these, but you don't want to see these errors (and yes, there are many!)
352So Valgrind reads a list of errors to suppress at startup. A default
sewardj08e31e22007-05-23 21:58:33 +0000353suppression file is created by the
debad57fc2005-12-03 22:33:29 +0000354<computeroutput>./configure</computeroutput> script when the system is
355built.</para>
njn3e986b22004-11-30 10:43:45 +0000356
debad57fc2005-12-03 22:33:29 +0000357<para>You can modify and add to the suppressions file at your leisure,
358or, better, write your own. Multiple suppression files are allowed.
359This is useful if part of your project contains errors you can't or
360don't want to fix, yet you don't want to continuously be reminded of
361them.</para>
njn3e986b22004-11-30 10:43:45 +0000362
debad57fc2005-12-03 22:33:29 +0000363<formalpara><title>Note:</title> <para>By far the easiest way to add
njnf4b47582009-08-10 01:15:30 +0000364suppressions is to use the <option>--gen-suppressions=yes</option> option
365described in <xref linkend="manual-core.options"/>. This generates
sewardj9a0132d2008-11-04 11:29:19 +0000366suppressions automatically. For best results,
367though, you may want to edit the output
368 of <option>--gen-suppressions=yes</option> by hand, in which
369case it would be advisable to read through this section.
370</para>
njn3e986b22004-11-30 10:43:45 +0000371</formalpara>
372
debad57fc2005-12-03 22:33:29 +0000373<para>Each error to be suppressed is described very specifically, to
bart8b6b54b2009-07-19 08:16:30 +0000374minimise the possibility that a suppression-directive inadvertently
debad57fc2005-12-03 22:33:29 +0000375suppresses a bunch of similar errors which you did want to see. The
376suppression mechanism is designed to allow precise yet flexible
377specification of errors to suppress.</para>
njn3e986b22004-11-30 10:43:45 +0000378
njnf4b47582009-08-10 01:15:30 +0000379<para>If you use the <option>-v</option> option, at the end of execution,
debad57fc2005-12-03 22:33:29 +0000380Valgrind prints out one line for each used suppression, giving its name
381and the number of times it got used. Here's the suppressions used by a
sewardj08e31e22007-05-23 21:58:33 +0000382run of <computeroutput>valgrind --tool=memcheck ls -l</computeroutput>:</para>
njn3e986b22004-11-30 10:43:45 +0000383
384<programlisting><![CDATA[
385--27579-- supp: 1 socketcall.connect(serv_addr)/__libc_connect/__nscd_getgrgid_r
386--27579-- supp: 1 socketcall.connect(serv_addr)/__libc_connect/__nscd_getpwuid_r
387--27579-- supp: 6 strrchr/_dl_map_object_from_fd/_dl_map_object]]></programlisting>
388
debad57fc2005-12-03 22:33:29 +0000389<para>Multiple suppressions files are allowed. By default, Valgrind
390uses <filename>$PREFIX/lib/valgrind/default.supp</filename>. You can
391ask to add suppressions from another file, by specifying
392<option>--suppressions=/path/to/file.supp</option>.
njn3e986b22004-11-30 10:43:45 +0000393</para>
394
debad57fc2005-12-03 22:33:29 +0000395<para>If you want to understand more about suppressions, look at an
396existing suppressions file whilst reading the following documentation.
sewardj08e31e22007-05-23 21:58:33 +0000397The file <filename>glibc-2.3.supp</filename>, in the source
njn3e986b22004-11-30 10:43:45 +0000398distribution, provides some good examples.</para>
399
400<para>Each suppression has the following components:</para>
401
debad57fc2005-12-03 22:33:29 +0000402<itemizedlist>
njn3e986b22004-11-30 10:43:45 +0000403
404 <listitem>
debad57fc2005-12-03 22:33:29 +0000405 <para>First line: its name. This merely gives a handy name to the
406 suppression, by which it is referred to in the summary of used
407 suppressions printed out when a program finishes. It's not
408 important what the name is; any identifying string will do.</para>
njn3e986b22004-11-30 10:43:45 +0000409 </listitem>
410
411 <listitem>
debad57fc2005-12-03 22:33:29 +0000412 <para>Second line: name of the tool(s) that the suppression is for
413 (if more than one, comma-separated), and the name of the suppression
sewardj33878892007-11-17 09:43:25 +0000414 itself, separated by a colon (n.b.: no spaces are allowed), eg:</para>
njn3e986b22004-11-30 10:43:45 +0000415<programlisting><![CDATA[
416tool_name1,tool_name2:suppression_name]]></programlisting>
417
sewardjf5fa3bd2006-03-14 00:56:29 +0000418 <para>Recall that Valgrind is a modular system, in which
debad57fc2005-12-03 22:33:29 +0000419 different instrumentation tools can observe your program whilst it
420 is running. Since different tools detect different kinds of errors,
421 it is necessary to say which tool(s) the suppression is meaningful
422 to.</para>
njn3e986b22004-11-30 10:43:45 +0000423
debad57fc2005-12-03 22:33:29 +0000424 <para>Tools will complain, at startup, if a tool does not understand
425 any suppression directed to it. Tools ignore suppressions which are
426 not directed to them. As a result, it is quite practical to put
427 suppressions for all tools into the same suppression file.</para>
njn3e986b22004-11-30 10:43:45 +0000428 </listitem>
429
430 <listitem>
debad57fc2005-12-03 22:33:29 +0000431 <para>Next line: a small number of suppression types have extra
432 information after the second line (eg. the <varname>Param</varname>
433 suppression for Memcheck)</para>
njn3e986b22004-11-30 10:43:45 +0000434 </listitem>
435
436 <listitem>
debad57fc2005-12-03 22:33:29 +0000437 <para>Remaining lines: This is the calling context for the error --
sewardj08e31e22007-05-23 21:58:33 +0000438 the chain of function calls that led to it. There can be up to 24
439 of these lines.</para>
njn3e986b22004-11-30 10:43:45 +0000440
sewardj66293252008-11-04 01:38:02 +0000441 <para>Locations may be names of either shared objects or
442 functions. They begin
debad57fc2005-12-03 22:33:29 +0000443 <computeroutput>obj:</computeroutput> and
444 <computeroutput>fun:</computeroutput> respectively. Function and
445 object names to match against may use the wildcard characters
446 <computeroutput>*</computeroutput> and
447 <computeroutput>?</computeroutput>.</para>
njn3e986b22004-11-30 10:43:45 +0000448
debad57fc2005-12-03 22:33:29 +0000449 <para><command>Important note: </command> C++ function names must be
450 <command>mangled</command>. If you are writing suppressions by
451 hand, use the <option>--demangle=no</option> option to get the
sewardj66293252008-11-04 01:38:02 +0000452 mangled names in your error messages. An example of a mangled
453 C++ name is <computeroutput>_ZN9QListView4showEv</computeroutput>.
454 This is the form that the GNU C++ compiler uses internally, and
455 the form that must be used in suppression files. The equivalent
456 demangled name, <computeroutput>QListView::show()</computeroutput>,
457 is what you see at the C++ source code level.
458 </para>
459
460 <para>A location line may also be
461 simply "<computeroutput>...</computeroutput>" (three dots). This is
462 a frame-level wildcard, which matches zero or more frames. Frame
463 level wildcards are useful because they make it easy to ignore
464 varying numbers of uninteresting frames in between frames of
465 interest. That is often important when writing suppressions which
466 are intended to be robust against variations in the amount of
467 function inlining done by compilers.</para>
njn3e986b22004-11-30 10:43:45 +0000468 </listitem>
469
470 <listitem>
debad57fc2005-12-03 22:33:29 +0000471 <para>Finally, the entire suppression must be between curly
472 braces. Each brace must be the first character on its own
473 line.</para>
njn3e986b22004-11-30 10:43:45 +0000474 </listitem>
475
476 </itemizedlist>
477
debad57fc2005-12-03 22:33:29 +0000478<para>A suppression only suppresses an error when the error matches all
479the details in the suppression. Here's an example:</para>
njn3e986b22004-11-30 10:43:45 +0000480
481<programlisting><![CDATA[
482{
483 __gconv_transform_ascii_internal/__mbrtowc/mbtowc
484 Memcheck:Value4
485 fun:__gconv_transform_ascii_internal
486 fun:__mbr*toc
487 fun:mbtowc
488}]]></programlisting>
489
490
491<para>What it means is: for Memcheck only, suppress a
debad57fc2005-12-03 22:33:29 +0000492use-of-uninitialised-value error, when the data size is 4, when it
493occurs in the function
494<computeroutput>__gconv_transform_ascii_internal</computeroutput>, when
495that is called from any function of name matching
496<computeroutput>__mbr*toc</computeroutput>, when that is called from
497<computeroutput>mbtowc</computeroutput>. It doesn't apply under any
498other circumstances. The string by which this suppression is identified
499to the user is
njn3e986b22004-11-30 10:43:45 +0000500<computeroutput>__gconv_transform_ascii_internal/__mbrtowc/mbtowc</computeroutput>.</para>
501
502<para>(See <xref linkend="mc-manual.suppfiles"/> for more details
503on the specifics of Memcheck's suppression kinds.)</para>
504
505<para>Another example, again for the Memcheck tool:</para>
506
507<programlisting><![CDATA[
508{
509 libX11.so.6.2/libX11.so.6.2/libXaw.so.7.0
510 Memcheck:Value4
511 obj:/usr/X11R6/lib/libX11.so.6.2
512 obj:/usr/X11R6/lib/libX11.so.6.2
513 obj:/usr/X11R6/lib/libXaw.so.7.0
514}]]></programlisting>
515
sewardj66293252008-11-04 01:38:02 +0000516<para>This suppresses any size 4 uninitialised-value error which occurs
debad57fc2005-12-03 22:33:29 +0000517anywhere in <filename>libX11.so.6.2</filename>, when called from
518anywhere in the same library, when called from anywhere in
519<filename>libXaw.so.7.0</filename>. The inexact specification of
520locations is regrettable, but is about all you can hope for, given that
sewardj08e31e22007-05-23 21:58:33 +0000521the X11 libraries shipped on the Linux distro on which this example
522was made have had their symbol tables removed.</para>
njn3e986b22004-11-30 10:43:45 +0000523
sewardj08e31e22007-05-23 21:58:33 +0000524<para>Although the above two examples do not make this clear, you can
525freely mix <computeroutput>obj:</computeroutput> and
526<computeroutput>fun:</computeroutput> lines in a suppression.</para>
njn3e986b22004-11-30 10:43:45 +0000527
sewardj66293252008-11-04 01:38:02 +0000528<para>Finally, here's an example using three frame-level wildcards:</para>
529
530<programlisting><![CDATA[
531{
532 a-contrived-example
533 Memcheck:Leak
534 fun:malloc
535 ...
536 fun:ddd
537 ...
538 fun:ccc
539 ...
540 fun:main
541}
542]]></programlisting>
543This suppresses Memcheck memory-leak errors, in the case where
544the allocation was done by <computeroutput>main</computeroutput>
545calling (though any number of intermediaries, including zero)
546<computeroutput>ccc</computeroutput>,
547calling onwards via
548<computeroutput>ddd</computeroutput> and eventually
549to <computeroutput>malloc.</computeroutput>.
njn3e986b22004-11-30 10:43:45 +0000550</sect1>
551
552
njnf4b47582009-08-10 01:15:30 +0000553<sect1 id="manual-core.options"
554 xreflabel="Core Command-line Options">
555<title>Core Command-line Options</title>
njn3e986b22004-11-30 10:43:45 +0000556
njnf4b47582009-08-10 01:15:30 +0000557<para>As mentioned above, Valgrind's core accepts a common set of options.
558The tools also accept tool-specific options, which are documented
sewardj33878892007-11-17 09:43:25 +0000559separately for each tool.</para>
njn3e986b22004-11-30 10:43:45 +0000560
debad57fc2005-12-03 22:33:29 +0000561<para>Valgrind's default settings succeed in giving reasonable behaviour
njn7316df22009-08-04 01:16:01 +0000562in most cases. We group the available options by rough categories.</para>
njn3e986b22004-11-30 10:43:45 +0000563
njnf4b47582009-08-10 01:15:30 +0000564<sect2 id="manual-core.toolopts" xreflabel="Tool-selection Option">
565<title>Tool-selection Option</title>
njn3e986b22004-11-30 10:43:45 +0000566
567<para>The single most important option.</para>
debad57fc2005-12-03 22:33:29 +0000568
sewardj6ea37fe2009-07-15 14:52:52 +0000569<variablelist>
570
571 <varlistentry id="tool_name" xreflabel="--tool">
572 <term>
njn7316df22009-08-04 01:16:01 +0000573 <option><![CDATA[--tool=<toolname> [default: memcheck] ]]></option>
sewardj6ea37fe2009-07-15 14:52:52 +0000574 </term>
575 <listitem>
njn7316df22009-08-04 01:16:01 +0000576 <para>Run the Valgrind tool called <varname>toolname</varname>,
sewardj6ea37fe2009-07-15 14:52:52 +0000577 e.g. Memcheck, Cachegrind, etc.</para>
578 </listitem>
579 </varlistentry>
580
581</variablelist>
debad57fc2005-12-03 22:33:29 +0000582
njn3e986b22004-11-30 10:43:45 +0000583</sect2>
584
debad57fc2005-12-03 22:33:29 +0000585
586
njn3e986b22004-11-30 10:43:45 +0000587<sect2 id="manual-core.basicopts" xreflabel="Basic Options">
588<title>Basic Options</title>
589
de03e0e7c2005-12-03 23:02:33 +0000590<!-- start of xi:include in the manpage -->
591<para id="basic.opts.para">These options work with all tools.</para>
njn3e986b22004-11-30 10:43:45 +0000592
de03e0e7c2005-12-03 23:02:33 +0000593<variablelist id="basic.opts.list">
njn3e986b22004-11-30 10:43:45 +0000594
debad57fc2005-12-03 22:33:29 +0000595 <varlistentry id="opt.help" xreflabel="--help">
596 <term><option>-h --help</option></term>
597 <listitem>
598 <para>Show help for all options, both for the core and for the
njncce38e62010-07-06 04:25:12 +0000599 selected tool. If the option is repeated it is equivalent to giving
600 <option>--help-debug</option>.</para>
debad57fc2005-12-03 22:33:29 +0000601 </listitem>
602 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000603
debad57fc2005-12-03 22:33:29 +0000604 <varlistentry id="opt.help-debug" xreflabel="--help-debug">
605 <term><option>--help-debug</option></term>
606 <listitem>
607 <para>Same as <option>--help</option>, but also lists debugging
608 options which usually are only of use to Valgrind's
609 developers.</para>
610 </listitem>
611 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000612
debad57fc2005-12-03 22:33:29 +0000613 <varlistentry id="opt.version" xreflabel="--version">
614 <term><option>--version</option></term>
615 <listitem>
616 <para>Show the version number of the Valgrind core. Tools can have
617 their own version numbers. There is a scheme in place to ensure
618 that tools only execute when the core version is one they are
619 known to work with. This was done to minimise the chances of
620 strange problems arising from tool-vs-core version
621 incompatibilities.</para>
622 </listitem>
623 </varlistentry>
njn51272982005-07-25 23:18:44 +0000624
debad57fc2005-12-03 22:33:29 +0000625 <varlistentry id="opt.quiet" xreflabel="--quiet">
njn7e5d4ed2009-07-30 02:57:52 +0000626 <term><option>-q</option>, <option>--quiet</option></term>
debad57fc2005-12-03 22:33:29 +0000627 <listitem>
628 <para>Run silently, and only print error messages. Useful if you
629 are running regression tests or have some other automated test
630 machinery.</para>
631 </listitem>
632 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000633
debad57fc2005-12-03 22:33:29 +0000634 <varlistentry id="opt.verbose" xreflabel="--verbose">
njn7e5d4ed2009-07-30 02:57:52 +0000635 <term><option>-v</option>, <option>--verbose</option></term>
debad57fc2005-12-03 22:33:29 +0000636 <listitem>
637 <para>Be more verbose. Gives extra information on various aspects
638 of your program, such as: the shared objects loaded, the
639 suppressions used, the progress of the instrumentation and
640 execution engines, and warnings about unusual behaviour. Repeating
njnf4b47582009-08-10 01:15:30 +0000641 the option increases the verbosity level.</para>
debad57fc2005-12-03 22:33:29 +0000642 </listitem>
643 </varlistentry>
sewardj053fe982005-11-15 19:51:04 +0000644
debad57fc2005-12-03 22:33:29 +0000645 <varlistentry id="opt.trace-children" xreflabel="--trace-children">
646 <term>
647 <option><![CDATA[--trace-children=<yes|no> [default: no] ]]></option>
648 </term>
649 <listitem>
njnae44c382007-05-15 03:59:23 +0000650 <para>When enabled, Valgrind will trace into sub-processes
njn7316df22009-08-04 01:16:01 +0000651 initiated via the <varname>exec</varname> system call. This is
652 necessary for multi-process programs.
njnae44c382007-05-15 03:59:23 +0000653 </para>
654 <para>Note that Valgrind does trace into the child of a
sewardj79c62bc2007-11-28 01:55:29 +0000655 <varname>fork</varname> (it would be difficult not to, since
njnae44c382007-05-15 03:59:23 +0000656 <varname>fork</varname> makes an identical copy of a process), so this
657 option is arguably badly named. However, most children of
658 <varname>fork</varname> calls immediately call <varname>exec</varname>
659 anyway.
660 </para>
debad57fc2005-12-03 22:33:29 +0000661 </listitem>
662 </varlistentry>
njn51272982005-07-25 23:18:44 +0000663
sewardj06421272009-11-05 08:55:13 +0000664 <varlistentry id="opt.trace-children-skip" xreflabel="--trace-children-skip">
665 <term>
sewardj9ab64a42010-12-06 11:40:04 +0000666 <option><![CDATA[--trace-children-skip=patt1,patt2,... ]]></option>
sewardj06421272009-11-05 08:55:13 +0000667 </term>
668 <listitem>
669 <para>This option only has an effect when
670 <option>--trace-children=yes</option> is specified. It allows
671 for some children to be skipped. The option takes a comma
672 separated list of patterns for the names of child executables
673 that Valgrind should not trace into. Patterns may include the
674 metacharacters <computeroutput>?</computeroutput>
675 and <computeroutput>*</computeroutput>, which have the usual
676 meaning.</para>
677 <para>
678 This can be useful for pruning uninteresting branches from a
679 tree of processes being run on Valgrind. But you should be
680 careful when using it. When Valgrind skips tracing into an
681 executable, it doesn't just skip tracing that executable, it
682 also skips tracing any of that executable's child processes.
683 In other words, the flag doesn't merely cause tracing to stop
684 at the specified executables -- it skips tracing of entire
685 process subtrees rooted at any of the specified
686 executables.</para>
687 </listitem>
688 </varlistentry>
689
sewardj9ab64a42010-12-06 11:40:04 +0000690 <varlistentry id="opt.trace-children-skip-by-arg"
691 xreflabel="--trace-children-skip-by-arg">
692 <term>
693 <option><![CDATA[--trace-children-skip-by-arg=patt1,patt2,... ]]></option>
694 </term>
695 <listitem>
696 <para>This is the same as
697 <option>--trace-children-skip</option>, with one difference:
698 the decision as to whether to trace into a child process is
699 made by examining the arguments to the child process, rather
700 than the name of its executable.</para>
701 </listitem>
702 </varlistentry>
703
sewardj778d7832007-11-22 01:21:56 +0000704 <varlistentry id="opt.child-silent-after-fork"
705 xreflabel="--child-silent-after-fork">
706 <term>
707 <option><![CDATA[--child-silent-after-fork=<yes|no> [default: no] ]]></option>
708 </term>
709 <listitem>
710 <para>When enabled, Valgrind will not show any debugging or
711 logging output for the child process resulting from
712 a <varname>fork</varname> call. This can make the output less
713 confusing (although more misleading) when dealing with processes
714 that create children. It is particularly useful in conjunction
njnf4b47582009-08-10 01:15:30 +0000715 with <varname>--trace-children=</varname>. Use of this option is also
sewardj778d7832007-11-22 01:21:56 +0000716 strongly recommended if you are requesting XML output
717 (<varname>--xml=yes</varname>), since otherwise the XML from child and
718 parent may become mixed up, which usually makes it useless.
719 </para>
720 </listitem>
721 </varlistentry>
722
debad57fc2005-12-03 22:33:29 +0000723 <varlistentry id="opt.track-fds" xreflabel="--track-fds">
724 <term>
725 <option><![CDATA[--track-fds=<yes|no> [default: no] ]]></option>
726 </term>
727 <listitem>
728 <para>When enabled, Valgrind will print out a list of open file
729 descriptors on exit. Along with each file descriptor is printed a
730 stack backtrace of where the file was opened and any details
731 relating to the file descriptor such as the file name or socket
732 details.</para>
733 </listitem>
734 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000735
debad57fc2005-12-03 22:33:29 +0000736 <varlistentry id="opt.time-stamp" xreflabel="--time-stamp">
737 <term>
738 <option><![CDATA[--time-stamp=<yes|no> [default: no] ]]></option>
739 </term>
740 <listitem>
741 <para>When enabled, each message is preceded with an indication of
742 the elapsed wallclock time since startup, expressed as days,
743 hours, minutes, seconds and milliseconds.</para>
744 </listitem>
745 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000746
debad57fc2005-12-03 22:33:29 +0000747 <varlistentry id="opt.log-fd" xreflabel="--log-fd">
748 <term>
749 <option><![CDATA[--log-fd=<number> [default: 2, stderr] ]]></option>
750 </term>
751 <listitem>
752 <para>Specifies that Valgrind should send all of its messages to
753 the specified file descriptor. The default, 2, is the standard
754 error channel (stderr). Note that this may interfere with the
755 client's own use of stderr, as Valgrind's output will be
756 interleaved with any output that the client sends to
757 stderr.</para>
758 </listitem>
759 </varlistentry>
njn779a2d62005-07-25 00:12:19 +0000760
debad57fc2005-12-03 22:33:29 +0000761 <varlistentry id="opt.log-file" xreflabel="--log-file">
762 <term>
763 <option><![CDATA[--log-file=<filename> ]]></option>
764 </term>
765 <listitem>
766 <para>Specifies that Valgrind should send all of its messages to
njn374a36d2007-11-23 01:41:32 +0000767 the specified file. If the file name is empty, it causes an abort.
768 There are three special format specifiers that can be used in the file
769 name.</para>
njn779a2d62005-07-25 00:12:19 +0000770
njn374a36d2007-11-23 01:41:32 +0000771 <para><option>%p</option> is replaced with the current process ID.
772 This is very useful for program that invoke multiple processes.
773 WARNING: If you use <option>--trace-children=yes</option> and your
njn7064fb22008-05-29 23:09:52 +0000774 program invokes multiple processes OR your program forks without
775 calling exec afterwards, and you don't use this specifier
njn374a36d2007-11-23 01:41:32 +0000776 (or the <option>%q</option> specifier below), the Valgrind output from
777 all those processes will go into one file, possibly jumbled up, and
njn498685c2007-09-17 23:15:35 +0000778 possibly incomplete.</para>
njn3e986b22004-11-30 10:43:45 +0000779
njn374a36d2007-11-23 01:41:32 +0000780 <para><option>%q{FOO}</option> is replaced with the contents of the
781 environment variable <varname>FOO</varname>. If the
782 <option>{FOO}</option> part is malformed, it causes an abort. This
783 specifier is rarely needed, but very useful in certain circumstances
784 (eg. when running MPI programs). The idea is that you specify a
785 variable which will be set differently for each process in the job,
786 for example <computeroutput>BPROC_RANK</computeroutput> or whatever is
787 applicable in your MPI setup. If the named environment variable is not
788 set, it causes an abort. Note that in some shells, the
789 <option>{</option> and <option>}</option> characters may need to be
790 escaped with a backslash.</para>
791
792 <para><option>%%</option> is replaced with <option>%</option>.</para>
793
794 <para>If an <option>%</option> is followed by any other character, it
795 causes an abort.</para>
debad57fc2005-12-03 22:33:29 +0000796 </listitem>
797 </varlistentry>
798
799 <varlistentry id="opt.log-socket" xreflabel="--log-socket">
800 <term>
801 <option><![CDATA[--log-socket=<ip-address:port-number> ]]></option>
802 </term>
803 <listitem>
804 <para>Specifies that Valgrind should send all of its messages to
805 the specified port at the specified IP address. The port may be
806 omitted, in which case port 1500 is used. If a connection cannot
807 be made to the specified socket, Valgrind falls back to writing
808 output to the standard error (stderr). This option is intended to
809 be used in conjunction with the
810 <computeroutput>valgrind-listener</computeroutput> program. For
811 further details, see
sewardj33878892007-11-17 09:43:25 +0000812 <link linkend="manual-core.comment">the commentary</link>
debad57fc2005-12-03 22:33:29 +0000813 in the manual.</para>
814 </listitem>
815 </varlistentry>
816
817</variablelist>
de03e0e7c2005-12-03 23:02:33 +0000818<!-- end of xi:include in the manpage -->
debad57fc2005-12-03 22:33:29 +0000819
820</sect2>
njn3e986b22004-11-30 10:43:45 +0000821
822
823<sect2 id="manual-core.erropts" xreflabel="Error-related Options">
njnf4b47582009-08-10 01:15:30 +0000824<title>Error-related Options</title>
njn3e986b22004-11-30 10:43:45 +0000825
de03e0e7c2005-12-03 23:02:33 +0000826<!-- start of xi:include in the manpage -->
827<para id="error-related.opts.para">These options are used by all tools
828that can report errors, e.g. Memcheck, but not Cachegrind.</para>
njn3e986b22004-11-30 10:43:45 +0000829
de03e0e7c2005-12-03 23:02:33 +0000830<variablelist id="error-related.opts.list">
njn3e986b22004-11-30 10:43:45 +0000831
debad57fc2005-12-03 22:33:29 +0000832 <varlistentry id="opt.xml" xreflabel="--xml">
833 <term>
834 <option><![CDATA[--xml=<yes|no> [default: no] ]]></option>
835 </term>
836 <listitem>
njn7316df22009-08-04 01:16:01 +0000837 <para>When enabled, the important parts of the output (e.g. tool error
838 messages) will be in XML format rather than plain text. Furthermore,
839 the XML output will be sent to a different output channel than the
840 plain text output. Therefore, you also must use one of
841 <option>--xml-fd</option>, <option>--xml-file</option> or
842 <option>--xml-socket</option> to specify where the XML is to be sent.
843 </para>
844
845 <para>Less important messages will still be printed in plain text, but
846 because the XML output and plain text output are sent to different
847 output channels (the destination of the plain text output is still
848 controlled by <option>--log-fd</option>, <option>--log-file</option>
849 and <option>--log-socket</option>) this should not cause problems.
850 </para>
851
852 <para>This option is aimed at making life easier for tools that consume
853 Valgrind's output as input, such as GUI front ends. Currently this
854 option works with Memcheck, Helgrind and Ptrcheck. The output format
855 is specified in the file
sewardj6ea37fe2009-07-15 14:52:52 +0000856 <computeroutput>docs/internals/xml-output-protocol4.txt</computeroutput>
857 in the source tree for Valgrind 3.5.0 or later.</para>
njn7316df22009-08-04 01:16:01 +0000858
njnf4b47582009-08-10 01:15:30 +0000859 <para>The recommended options for a GUI to pass, when requesting
njn7316df22009-08-04 01:16:01 +0000860 XML output, are: <option>--xml=yes</option> to enable XML output,
861 <option>--xml-file</option> to send the XML output to a (presumably
862 GUI-selected) file, <option>--log-file</option> to send the plain
863 text output to a second GUI-selected file,
864 <option>--child-silent-after-fork=yes</option>, and
865 <option>-q</option> to restrict the plain text output to critical
866 error messages created by Valgrind itself. For example, failure to
867 read a specified suppressions file counts as a critical error message.
868 In this way, for a successful run the text output file will be empty.
869 But if it isn't empty, then it will contain important information
870 which the GUI user should be made aware
871 of.</para>
sewardj6ea37fe2009-07-15 14:52:52 +0000872 </listitem>
873 </varlistentry>
874
sewardj6ea37fe2009-07-15 14:52:52 +0000875 <varlistentry id="opt.xml-fd" xreflabel="--xml-fd">
876 <term>
877 <option><![CDATA[--xml-fd=<number> [default: -1, disabled] ]]></option>
878 </term>
879 <listitem>
880 <para>Specifies that Valgrind should send its XML output to the
njn7316df22009-08-04 01:16:01 +0000881 specified file descriptor. It must be used in conjunction with
882 <option>--xml=yes</option>.</para>
sewardj6ea37fe2009-07-15 14:52:52 +0000883 </listitem>
884 </varlistentry>
885
886 <varlistentry id="opt.xml-file" xreflabel="--xml-file">
887 <term>
888 <option><![CDATA[--xml-file=<filename> ]]></option>
889 </term>
890 <listitem>
891 <para>Specifies that Valgrind should send its XML output
njn7316df22009-08-04 01:16:01 +0000892 to the specified file. It must be used in conjunction with
893 <option>--xml=yes</option>. Any <option>%p</option> or
894 <option>%q</option> sequences appearing in the filename are expanded
895 in exactly the same way as they are for <option>--log-file</option>.
896 See the description of <option>--log-file</option> for details.
sewardj6ea37fe2009-07-15 14:52:52 +0000897 </para>
898 </listitem>
899 </varlistentry>
900
901 <varlistentry id="opt.xml-socket" xreflabel="--xml-socket">
902 <term>
903 <option><![CDATA[--xml-socket=<ip-address:port-number> ]]></option>
904 </term>
905 <listitem>
906 <para>Specifies that Valgrind should send its XML output the
njn7316df22009-08-04 01:16:01 +0000907 specified port at the specified IP address. It must be used in
908 conjunction with <option>--xml=yes</option>. The form of the argument
909 is the same as that used by <option>--log-socket</option>.
910 See the description of <option>--log-socket</option>
sewardj6ea37fe2009-07-15 14:52:52 +0000911 for further details.</para>
debad57fc2005-12-03 22:33:29 +0000912 </listitem>
913 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000914
debad57fc2005-12-03 22:33:29 +0000915 <varlistentry id="opt.xml-user-comment" xreflabel="--xml-user-comment">
916 <term>
917 <option><![CDATA[--xml-user-comment=<string> ]]></option>
918 </term>
919 <listitem>
920 <para>Embeds an extra user comment string at the start of the XML
921 output. Only works when <option>--xml=yes</option> is specified;
922 ignored otherwise.</para>
923 </listitem>
924 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000925
debad57fc2005-12-03 22:33:29 +0000926 <varlistentry id="opt.demangle" xreflabel="--demangle">
927 <term>
928 <option><![CDATA[--demangle=<yes|no> [default: yes] ]]></option>
929 </term>
930 <listitem>
931 <para>Enable/disable automatic demangling (decoding) of C++ names.
932 Enabled by default. When enabled, Valgrind will attempt to
933 translate encoded C++ names back to something approaching the
934 original. The demangler handles symbols mangled by g++ versions
935 2.X, 3.X and 4.X.</para>
njn3e986b22004-11-30 10:43:45 +0000936
debad57fc2005-12-03 22:33:29 +0000937 <para>An important fact about demangling is that function names
938 mentioned in suppressions files should be in their mangled form.
939 Valgrind does not demangle function names when searching for
940 applicable suppressions, because to do otherwise would make
njn7316df22009-08-04 01:16:01 +0000941 suppression file contents dependent on the state of Valgrind's
942 demangling machinery, and also slow down suppression matching.</para>
debad57fc2005-12-03 22:33:29 +0000943 </listitem>
944 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000945
debad57fc2005-12-03 22:33:29 +0000946 <varlistentry id="opt.num-callers" xreflabel="--num-callers">
947 <term>
948 <option><![CDATA[--num-callers=<number> [default: 12] ]]></option>
949 </term>
950 <listitem>
njn7316df22009-08-04 01:16:01 +0000951 <para>Specifies the maximum number of entries shown in stack traces
952 that identify program locations. Note that errors are commoned up
953 using only the top four function locations (the place in the current
954 function, and that of its three immediate callers). So this doesn't
955 affect the total number of errors reported.</para>
njn3e986b22004-11-30 10:43:45 +0000956
debad57fc2005-12-03 22:33:29 +0000957 <para>The maximum value for this is 50. Note that higher settings
958 will make Valgrind run a bit more slowly and take a bit more
959 memory, but can be useful when working with programs with
960 deeply-nested call chains.</para>
961 </listitem>
962 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000963
debad57fc2005-12-03 22:33:29 +0000964 <varlistentry id="opt.error-limit" xreflabel="--error-limit">
965 <term>
966 <option><![CDATA[--error-limit=<yes|no> [default: yes] ]]></option>
967 </term>
968 <listitem>
sewardj58501082006-05-12 23:35:10 +0000969 <para>When enabled, Valgrind stops reporting errors after 10,000,000
debad57fc2005-12-03 22:33:29 +0000970 in total, or 1,000 different ones, have been seen. This is to
971 stop the error tracking machinery from becoming a huge performance
972 overhead in programs with many errors.</para>
973 </listitem>
974 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000975
sewardjb9779082006-05-12 23:50:15 +0000976 <varlistentry id="opt.error-exitcode" xreflabel="--error-exitcode">
977 <term>
978 <option><![CDATA[--error-exitcode=<number> [default: 0] ]]></option>
979 </term>
980 <listitem>
981 <para>Specifies an alternative exit code to return if Valgrind
982 reported any errors in the run. When set to the default value
983 (zero), the return value from Valgrind will always be the return
984 value of the process being simulated. When set to a nonzero value,
985 that value is returned instead, if Valgrind detects any errors.
986 This is useful for using Valgrind as part of an automated test
987 suite, since it makes it easy to detect test cases for which
988 Valgrind has reported errors, just by inspecting return codes.</para>
989 </listitem>
990 </varlistentry>
991
debad57fc2005-12-03 22:33:29 +0000992 <varlistentry id="opt.stack-traces" xreflabel="--show-below-main">
993 <term>
994 <option><![CDATA[--show-below-main=<yes|no> [default: no] ]]></option>
995 </term>
996 <listitem>
997 <para>By default, stack traces for errors do not show any
njn7316df22009-08-04 01:16:01 +0000998 functions that appear beneath <function>main</function> because
njn68824432009-02-10 06:48:00 +0000999 most of the time it's uninteresting C library stuff and/or
njn7316df22009-08-04 01:16:01 +00001000 gobbledygook. Alternatively, if <function>main</function> is not
njn68824432009-02-10 06:48:00 +00001001 present in the stack trace, stack traces will not show any functions
njn7316df22009-08-04 01:16:01 +00001002 below <function>main</function>-like functions such as glibc's
1003 <function>__libc_start_main</function>. Furthermore, if
1004 <function>main</function>-like functions are present in the trace,
1005 they are normalised as <function>(below main)</function>, in order to
1006 make the output more deterministic.</para>
njn68824432009-02-10 06:48:00 +00001007
1008 <para>If this option is enabled, all stack trace entries will be
njn7316df22009-08-04 01:16:01 +00001009 shown and <function>main</function>-like functions will not be
njn68824432009-02-10 06:48:00 +00001010 normalised.</para>
debad57fc2005-12-03 22:33:29 +00001011 </listitem>
1012 </varlistentry>
sewardjd153fae2005-01-10 17:24:47 +00001013
sewardj14cdbf82010-10-12 00:44:05 +00001014 <varlistentry id="opt.fullpath-after" xreflabel="--fullpath-after">
bart5dd01902010-08-31 15:18:32 +00001015 <term>
sewardj14cdbf82010-10-12 00:44:05 +00001016 <option><![CDATA[--fullpath-after=<string>
1017 [default: don't show source paths] ]]></option>
bart5dd01902010-08-31 15:18:32 +00001018 </term>
1019 <listitem>
sewardj14cdbf82010-10-12 00:44:05 +00001020 <para>By default Valgrind only shows the filenames in stack
1021 traces, but not full paths to source files. When using Valgrind
1022 in large projects where the sources reside in multiple different
1023 directories, this can be inconvenient.
1024 <option>--fullpath-after</option> provides a flexible solution
1025 to this problem. When this option is present, the path to each
1026 source file is shown, with the following all-important caveat:
1027 if <option>string</option> is found in the path, then the path
1028 up to and including <option>string</option> is omitted, else the
1029 path is shown unmodified. Note that <option>string</option> is
1030 not required to be a prefix of the path.</para>
1031
1032 <para>For example, consider a file named
1033 <computeroutput>/home/janedoe/blah/src/foo/bar/xyzzy.c</computeroutput>.
1034 Specifying <option>--fullpath-after=/home/janedoe/blah/src/</option>
1035 will cause Valgrind to show the name
1036 as <computeroutput>foo/bar/xyzzy.c</computeroutput>.</para>
1037
1038 <para>Because the string is not required to be a prefix,
1039 <option>--fullpath-after=src/</option> will produce the same
1040 output. This is useful when the path contains arbitrary
1041 machine-generated characters. For example, the
1042 path
1043 <computeroutput>/my/build/dir/C32A1B47/blah/src/foo/xyzzy</computeroutput>
1044 can be pruned to <computeroutput>foo/xyzzy</computeroutput>
1045 using
1046 <option>--fullpath-after=/blah/src/</option>.</para>
1047
1048 <para>If you simply want to see the full path, just specify an
1049 empty string: <option>--fullpath-after=</option>. This isn't a
1050 special case, merely a logical consequence of the above rules.</para>
1051
1052 <para>Finally, you can use <option>--fullpath-after</option>
1053 multiple times. Any appearance of it causes Valgrind to switch
1054 to producing full paths and applying the above filtering rule.
1055 Each produced path is compared against all
1056 the <option>--fullpath-after</option>-specified strings, in the
1057 order specified. The first string to match causes the path to
1058 be truncated as described above. If none match, the full path
1059 is shown. This facilitates chopping off prefixes when the
1060 sources are drawn from a number of unrelated directories.
bart5dd01902010-08-31 15:18:32 +00001061 </para>
1062 </listitem>
1063 </varlistentry>
1064
debad57fc2005-12-03 22:33:29 +00001065 <varlistentry id="opt.suppressions" xreflabel="--suppressions">
1066 <term>
1067 <option><![CDATA[--suppressions=<filename> [default: $PREFIX/lib/valgrind/default.supp] ]]></option>
1068 </term>
1069 <listitem>
1070 <para>Specifies an extra file from which to read descriptions of
sewardjc44b2542008-05-14 06:43:10 +00001071 errors to suppress. You may use up to 100 extra suppression
1072 files.</para>
debad57fc2005-12-03 22:33:29 +00001073 </listitem>
1074 </varlistentry>
njn3e986b22004-11-30 10:43:45 +00001075
sewardj33878892007-11-17 09:43:25 +00001076 <varlistentry id="opt.gen-suppressions" xreflabel="--gen-suppressions">
debad57fc2005-12-03 22:33:29 +00001077 <term>
1078 <option><![CDATA[--gen-suppressions=<yes|no|all> [default: no] ]]></option>
1079 </term>
1080 <listitem>
1081 <para>When set to <varname>yes</varname>, Valgrind will pause
1082 after every error shown and print the line:
njn7316df22009-08-04 01:16:01 +00001083 <literallayout><computeroutput> ---- Print suppression ? --- [Return/N/n/Y/y/C/c] ----</computeroutput></literallayout>
njn3e986b22004-11-30 10:43:45 +00001084
debad57fc2005-12-03 22:33:29 +00001085 The prompt's behaviour is the same as for the
1086 <option>--db-attach</option> option (see below).</para>
njn3e986b22004-11-30 10:43:45 +00001087
debad57fc2005-12-03 22:33:29 +00001088 <para>If you choose to, Valgrind will print out a suppression for
1089 this error. You can then cut and paste it into a suppression file
1090 if you don't want to hear about the error in the future.</para>
sewardjd153fae2005-01-10 17:24:47 +00001091
debad57fc2005-12-03 22:33:29 +00001092 <para>When set to <varname>all</varname>, Valgrind will print a
1093 suppression for every reported error, without querying the
1094 user.</para>
njn3e986b22004-11-30 10:43:45 +00001095
debad57fc2005-12-03 22:33:29 +00001096 <para>This option is particularly useful with C++ programs, as it
1097 prints out the suppressions with mangled names, as
1098 required.</para>
njn3e986b22004-11-30 10:43:45 +00001099
debad57fc2005-12-03 22:33:29 +00001100 <para>Note that the suppressions printed are as specific as
sewardj9a0132d2008-11-04 11:29:19 +00001101 possible. You may want to common up similar ones, by adding
1102 wildcards to function names, and by using frame-level wildcards.
1103 The wildcarding facilities are powerful yet flexible, and with a
1104 bit of careful editing, you may be able to suppress a whole
njn36ef2572009-08-10 00:42:43 +00001105 family of related errors with only a few suppressions.
1106 <!-- commented out because it causes broken links in the man page
1107 For details on how to do this, see
1108 <xref linkend="manual-core.suppress"/>.
1109 -->
1110 </para>
sewardj9a0132d2008-11-04 11:29:19 +00001111
1112 <para>Sometimes two different errors
debad57fc2005-12-03 22:33:29 +00001113 are suppressed by the same suppression, in which case Valgrind
1114 will output the suppression more than once, but you only need to
1115 have one copy in your suppression file (but having more than one
1116 won't cause problems). Also, the suppression name is given as
1117 <computeroutput>&lt;insert a suppression name
1118 here&gt;</computeroutput>; the name doesn't really matter, it's
1119 only used with the <option>-v</option> option which prints out all
1120 used suppression records.</para>
1121 </listitem>
1122 </varlistentry>
njn3e986b22004-11-30 10:43:45 +00001123
debad57fc2005-12-03 22:33:29 +00001124 <varlistentry id="opt.db-attach" xreflabel="--db-attach">
1125 <term>
1126 <option><![CDATA[--db-attach=<yes|no> [default: no] ]]></option>
1127 </term>
1128 <listitem>
1129 <para>When enabled, Valgrind will pause after every error shown
1130 and print the line:
njn7316df22009-08-04 01:16:01 +00001131 <literallayout><computeroutput> ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ----</computeroutput></literallayout>
njn3e986b22004-11-30 10:43:45 +00001132
debad57fc2005-12-03 22:33:29 +00001133 Pressing <varname>Ret</varname>, or <varname>N Ret</varname> or
1134 <varname>n Ret</varname>, causes Valgrind not to start a debugger
1135 for this error.</para>
njn3e986b22004-11-30 10:43:45 +00001136
debad57fc2005-12-03 22:33:29 +00001137 <para>Pressing <varname>Y Ret</varname> or
1138 <varname>y Ret</varname> causes Valgrind to start a debugger for
1139 the program at this point. When you have finished with the
1140 debugger, quit from it, and the program will continue. Trying to
1141 continue from inside the debugger doesn't work.</para>
njn3e986b22004-11-30 10:43:45 +00001142
debad57fc2005-12-03 22:33:29 +00001143 <para><varname>C Ret</varname> or <varname>c Ret</varname> causes
1144 Valgrind not to start a debugger, and not to ask again.</para>
debad57fc2005-12-03 22:33:29 +00001145 </listitem>
1146 </varlistentry>
njn3e986b22004-11-30 10:43:45 +00001147
debad57fc2005-12-03 22:33:29 +00001148 <varlistentry id="opt.db-command" xreflabel="--db-command">
1149 <term>
1150 <option><![CDATA[--db-command=<command> [default: gdb -nw %f %p] ]]></option>
1151 </term>
1152 <listitem>
1153 <para>Specify the debugger to use with the
1154 <option>--db-attach</option> command. The default debugger is
njn7316df22009-08-04 01:16:01 +00001155 GDB. This option is a template that is expanded by Valgrind at
debad57fc2005-12-03 22:33:29 +00001156 runtime. <literal>%f</literal> is replaced with the executable's
1157 file name and <literal>%p</literal> is replaced by the process ID
1158 of the executable.</para>
njn3e986b22004-11-30 10:43:45 +00001159
debad57fc2005-12-03 22:33:29 +00001160 <para>This specifies how Valgrind will invoke the debugger. By
1161 default it will use whatever GDB is detected at build time, which
1162 is usually <computeroutput>/usr/bin/gdb</computeroutput>. Using
1163 this command, you can specify some alternative command to invoke
1164 the debugger you want to use.</para>
njn51272982005-07-25 23:18:44 +00001165
debad57fc2005-12-03 22:33:29 +00001166 <para>The command string given can include one or instances of the
1167 <literal>%p</literal> and <literal>%f</literal> expansions. Each
1168 instance of <literal>%p</literal> expands to the PID of the
1169 process to be debugged and each instance of <literal>%f</literal>
1170 expands to the path to the executable for the process to be
1171 debugged.</para>
sewardj778d7832007-11-22 01:21:56 +00001172
1173 <para>Since <computeroutput>&lt;command&gt;</computeroutput> is likely
njnf4b47582009-08-10 01:15:30 +00001174 to contain spaces, you will need to put this entire option in
sewardj778d7832007-11-22 01:21:56 +00001175 quotes to ensure it is correctly handled by the shell.</para>
debad57fc2005-12-03 22:33:29 +00001176 </listitem>
1177 </varlistentry>
1178
1179 <varlistentry id="opt.input-fd" xreflabel="--input-fd">
1180 <term>
1181 <option><![CDATA[--input-fd=<number> [default: 0, stdin] ]]></option>
1182 </term>
1183 <listitem>
sewardj08e31e22007-05-23 21:58:33 +00001184 <para>When using <option>--db-attach=yes</option> or
debad57fc2005-12-03 22:33:29 +00001185 <option>--gen-suppressions=yes</option>, Valgrind will stop so as
sewardj08e31e22007-05-23 21:58:33 +00001186 to read keyboard input from you when each error occurs. By
debad57fc2005-12-03 22:33:29 +00001187 default it reads from the standard input (stdin), which is
1188 problematic for programs which close stdin. This option allows
1189 you to specify an alternative file descriptor from which to read
1190 input.</para>
1191 </listitem>
1192 </varlistentry>
1193
njn97db7612009-08-04 02:32:55 +00001194 <varlistentry id="opt.dsymutil" xreflabel="--dsymutil">
sewardjb4cf7cd2009-05-31 09:34:05 +00001195 <term>
njn97db7612009-08-04 02:32:55 +00001196 <option><![CDATA[--dsymutil=no|yes [no] ]]></option>
sewardjb4cf7cd2009-05-31 09:34:05 +00001197 </term>
1198 <listitem>
njnf4b47582009-08-10 01:15:30 +00001199 <para>This option is only relevant when running Valgrind on
njn7316df22009-08-04 01:16:01 +00001200 Mac OS X.</para>
sewardjb4cf7cd2009-05-31 09:34:05 +00001201
njn7316df22009-08-04 01:16:01 +00001202 <para>Mac OS X uses a deferred debug information (debuginfo)
sewardjb4cf7cd2009-05-31 09:34:05 +00001203 linking scheme. When object files containing debuginfo are
1204 linked into a <computeroutput>.dylib</computeroutput> or an
1205 executable, the debuginfo is not copied into the final file.
1206 Instead, the debuginfo must be linked manually by
1207 running <computeroutput>dsymutil</computeroutput>, a
1208 system-provided utility, on the executable
1209 or <computeroutput>.dylib</computeroutput>. The resulting
1210 combined debuginfo is placed in a directory alongside the
1211 executable or <computeroutput>.dylib</computeroutput>, but with
1212 the extension <computeroutput>.dSYM</computeroutput>.</para>
1213
njn97db7612009-08-04 02:32:55 +00001214 <para>With <option>--dsymutil=no</option>, Valgrind
sewardjb4cf7cd2009-05-31 09:34:05 +00001215 will detect cases where the
1216 <computeroutput>.dSYM</computeroutput> directory is either
1217 missing, or is present but does not appear to match the
1218 associated executable or <computeroutput>.dylib</computeroutput>,
1219 most likely because it is out of date. In these cases, Valgrind
1220 will print a warning message but take no further action.</para>
1221
njn97db7612009-08-04 02:32:55 +00001222 <para>With <option>--dsymutil=yes</option>, Valgrind
sewardjb4cf7cd2009-05-31 09:34:05 +00001223 will, in such cases, automatically
1224 run <computeroutput>dsymutil</computeroutput> as necessary to
1225 bring the debuginfo up to date. For all practical purposes, if
njn97db7612009-08-04 02:32:55 +00001226 you always use <option>--dsymutil=yes</option>, then
sewardjb4cf7cd2009-05-31 09:34:05 +00001227 there is never any need to
1228 run <computeroutput>dsymutil</computeroutput> manually or as part
1229 of your applications's build system, since Valgrind will run it
1230 as necessary.</para>
1231
1232 <para>Valgrind will not attempt to
1233 run <computeroutput>dsymutil</computeroutput> on any
1234 executable or library in
njn7316df22009-08-04 01:16:01 +00001235 <computeroutput>/usr/</computeroutput>,
1236 <computeroutput>/bin/</computeroutput>,
1237 <computeroutput>/sbin/</computeroutput>,
1238 <computeroutput>/opt/</computeroutput>,
1239 <computeroutput>/sw/</computeroutput>,
1240 <computeroutput>/System/</computeroutput>,
1241 <computeroutput>/Library/</computeroutput> or
1242 <computeroutput>/Applications/</computeroutput>
sewardjb4cf7cd2009-05-31 09:34:05 +00001243 since <computeroutput>dsymutil</computeroutput> will always fail
1244 in such situations. It fails both because the debuginfo for
1245 such pre-installed system components is not available anywhere,
bart2ff151c2009-07-19 08:12:57 +00001246 and also because it would require write privileges in those
sewardjb4cf7cd2009-05-31 09:34:05 +00001247 directories.</para>
1248
1249 <para>Be careful when
njn97db7612009-08-04 02:32:55 +00001250 using <option>--dsymutil=yes</option>, since it will
sewardjb4cf7cd2009-05-31 09:34:05 +00001251 cause pre-existing <computeroutput>.dSYM</computeroutput>
sewardje089f012010-10-13 21:47:29 +00001252 directories to be silently deleted and re-created. Also note that
njn7316df22009-08-04 01:16:01 +00001253 <computeroutput>dsymutil</computeroutput> is quite slow, sometimes
1254 excessively so.</para>
sewardjb4cf7cd2009-05-31 09:34:05 +00001255 </listitem>
1256 </varlistentry>
1257
debad57fc2005-12-03 22:33:29 +00001258 <varlistentry id="opt.max-stackframe" xreflabel="--max-stackframe">
1259 <term>
1260 <option><![CDATA[--max-stackframe=<number> [default: 2000000] ]]></option>
1261 </term>
1262 <listitem>
sewardj08e31e22007-05-23 21:58:33 +00001263 <para>The maximum size of a stack frame. If the stack pointer moves by
debad57fc2005-12-03 22:33:29 +00001264 more than this amount then Valgrind will assume that
1265 the program is switching to a different stack.</para>
1266
1267 <para>You may need to use this option if your program has large
1268 stack-allocated arrays. Valgrind keeps track of your program's
1269 stack pointer. If it changes by more than the threshold amount,
1270 Valgrind assumes your program is switching to a different stack,
1271 and Memcheck behaves differently than it would for a stack pointer
1272 change smaller than the threshold. Usually this heuristic works
1273 well. However, if your program allocates large structures on the
1274 stack, this heuristic will be fooled, and Memcheck will
1275 subsequently report large numbers of invalid stack accesses. This
1276 option allows you to change the threshold to a different
1277 value.</para>
1278
njnf4b47582009-08-10 01:15:30 +00001279 <para>You should only consider use of this option if Valgrind's
debad57fc2005-12-03 22:33:29 +00001280 debug output directs you to do so. In that case it will tell you
1281 the new threshold you should specify.</para>
1282
1283 <para>In general, allocating large structures on the stack is a
sewardj08e31e22007-05-23 21:58:33 +00001284 bad idea, because you can easily run out of stack space,
debad57fc2005-12-03 22:33:29 +00001285 especially on systems with limited memory or which expect to
sewardj08e31e22007-05-23 21:58:33 +00001286 support large numbers of threads each with a small stack, and also
debad57fc2005-12-03 22:33:29 +00001287 because the error checking performed by Memcheck is more effective
1288 for heap-allocated data than for stack-allocated data. If you
njnf4b47582009-08-10 01:15:30 +00001289 have to use this option, you may wish to consider rewriting your
debad57fc2005-12-03 22:33:29 +00001290 code to allocate on the heap rather than on the stack.</para>
1291 </listitem>
1292 </varlistentry>
1293
sewardj95d86c02007-12-18 01:49:23 +00001294 <varlistentry id="opt.main-stacksize" xreflabel="--main-stacksize">
1295 <term>
1296 <option><![CDATA[--main-stacksize=<number>
1297 [default: use current 'ulimit' value] ]]></option>
1298 </term>
1299 <listitem>
1300 <para>Specifies the size of the main thread's stack.</para>
1301
1302 <para>To simplify its memory management, Valgrind reserves all
1303 required space for the main thread's stack at startup. That
1304 means it needs to know the required stack size at
1305 startup.</para>
1306
1307 <para>By default, Valgrind uses the current "ulimit" value for
1308 the stack size, or 16 MB, whichever is lower. In many cases
1309 this gives a stack size in the range 8 to 16 MB, which almost
1310 never overflows for most applications.</para>
1311
1312 <para>If you need a larger total stack size,
1313 use <option>--main-stacksize</option> to specify it. Only set
1314 it as high as you need, since reserving far more space than you
1315 need (that is, hundreds of megabytes more than you need)
1316 constrains Valgrind's memory allocators and may reduce the total
1317 amount of memory that Valgrind can use. This is only really of
1318 significance on 32-bit machines.</para>
1319
1320 <para>On Linux, you may request a stack of size up to 2GB.
1321 Valgrind will stop with a diagnostic message if the stack cannot
1322 be allocated. On AIX5 the allowed stack size is restricted to
1323 128MB.</para>
1324
1325 <para><option>--main-stacksize</option> only affects the stack
1326 size for the program's initial thread. It has no bearing on the
1327 size of thread stacks, as Valgrind does not allocate
1328 those.</para>
1329
1330 <para>You may need to use both <option>--main-stacksize</option>
1331 and <option>--max-stackframe</option> together. It is important
1332 to understand that <option>--main-stacksize</option> sets the
1333 maximum total stack size,
1334 whilst <option>--max-stackframe</option> specifies the largest
1335 size of any one stack frame. You will have to work out
1336 the <option>--main-stacksize</option> value for yourself
1337 (usually, if your applications segfaults). But Valgrind will
1338 tell you the needed <option>--max-stackframe</option> size, if
1339 necessary.</para>
1340
1341 <para>As discussed further in the description
1342 of <option>--max-stackframe</option>, a requirement for a large
1343 stack is a sign of potential portability problems. You are best
1344 advised to place all large data in heap-allocated memory.</para>
1345 </listitem>
1346 </varlistentry>
1347
debad57fc2005-12-03 22:33:29 +00001348</variablelist>
de03e0e7c2005-12-03 23:02:33 +00001349<!-- end of xi:include in the manpage -->
debad57fc2005-12-03 22:33:29 +00001350
njn3e986b22004-11-30 10:43:45 +00001351</sect2>
1352
debad57fc2005-12-03 22:33:29 +00001353
njn7316df22009-08-04 01:16:01 +00001354<sect2 id="manual-core.mallocopts" xreflabel="malloc-related Options">
sewardj1160e812010-09-10 14:56:18 +00001355<title>malloc-related Options</title>
njn3e986b22004-11-30 10:43:45 +00001356
de03e0e7c2005-12-03 23:02:33 +00001357<!-- start of xi:include in the manpage -->
1358<para id="malloc-related.opts.para">For tools that use their own version of
njn7316df22009-08-04 01:16:01 +00001359<computeroutput>malloc</computeroutput> (e.g. Memcheck and
njn1d0825f2006-03-27 11:37:07 +00001360Massif), the following options apply.</para>
njn3e986b22004-11-30 10:43:45 +00001361
de03e0e7c2005-12-03 23:02:33 +00001362<variablelist id="malloc-related.opts.list">
njn3e986b22004-11-30 10:43:45 +00001363
debad57fc2005-12-03 22:33:29 +00001364 <varlistentry id="opt.alignment" xreflabel="--alignment">
1365 <term>
njn7316df22009-08-04 01:16:01 +00001366 <option><![CDATA[--alignment=<number> [default: 8 or 16, depending on the platform] ]]></option>
debad57fc2005-12-03 22:33:29 +00001367 </term>
1368 <listitem>
njn7316df22009-08-04 01:16:01 +00001369 <para>By default Valgrind's <function>malloc</function>,
1370 <function>realloc</function>, etc, return a block whose starting
1371 address is 8-byte aligned or 16-byte aligned (the value depends on the
1372 platform and matches the platform default). This option allows you to
1373 specify a different alignment. The supplied value must be greater
1374 than or equal to the default, less than or equal to 4096, and must be
1375 a power of two.</para>
njn51272982005-07-25 23:18:44 +00001376 </listitem>
debad57fc2005-12-03 22:33:29 +00001377 </varlistentry>
njn51272982005-07-25 23:18:44 +00001378
debad57fc2005-12-03 22:33:29 +00001379</variablelist>
de03e0e7c2005-12-03 23:02:33 +00001380<!-- end of xi:include in the manpage -->
debad57fc2005-12-03 22:33:29 +00001381
1382</sect2>
1383
1384
1385<sect2 id="manual-core.rareopts" xreflabel="Uncommon Options">
1386<title>Uncommon Options</title>
1387
de03e0e7c2005-12-03 23:02:33 +00001388<!-- start of xi:include in the manpage -->
1389<para id="uncommon.opts.para">These options apply to all tools, as they
1390affect certain obscure workings of the Valgrind core. Most people won't
1391need to use these.</para>
debad57fc2005-12-03 22:33:29 +00001392
de03e0e7c2005-12-03 23:02:33 +00001393<variablelist id="uncommon.opts.list">
debad57fc2005-12-03 22:33:29 +00001394
njn97db7612009-08-04 02:32:55 +00001395 <varlistentry id="opt.smc-check" xreflabel="--smc-check">
1396 <term>
1397 <option><![CDATA[--smc-check=<none|stack|all> [default: stack] ]]></option>
1398 </term>
1399 <listitem>
1400 <para>This option controls Valgrind's detection of self-modifying
1401 code. If no checking is done, if a program executes some code, then
1402 overwrites it with new code, and executes the new code, Valgrind will
1403 continue to execute the translations it made for the old code. This
1404 will likely lead to incorrect behaviour and/or crashes.</para>
1405
1406 <para>Valgrind has three levels of self-modifying code detection:
sewardje089f012010-10-13 21:47:29 +00001407 no detection, detect self-modifying code on the stack (which is used by
njn97db7612009-08-04 02:32:55 +00001408 GCC to implement nested functions), or detect self-modifying code
1409 everywhere. Note that the default option will catch the vast majority
1410 of cases. The main case it will not catch is programs such as JIT
1411 compilers that dynamically generate code <emphasis>and</emphasis>
1412 subsequently overwrite part or all of it. Running with
sewardje089f012010-10-13 21:47:29 +00001413 <varname>all</varname> will slow Valgrind down noticeably. Running with
njn97db7612009-08-04 02:32:55 +00001414 <varname>none</varname> will rarely speed things up, since very little
1415 code gets put on the stack for most programs. The
1416 <function>VALGRIND_DISCARD_TRANSLATIONS</function> client request is
1417 an alternative to <option>--smc-check=all</option> that requires more
njn36ef2572009-08-10 00:42:43 +00001418 effort but is much faster.
1419 <!-- commented out because it causes broken links in the man page
1420 ; see <xref
1421 linkend="manual-core-adv.clientreq"/> for more details.
1422 -->
1423 </para>
njn97db7612009-08-04 02:32:55 +00001424
sewardje089f012010-10-13 21:47:29 +00001425 <para>Some architectures (including ppc32, ppc64 and ARM) require
njn97db7612009-08-04 02:32:55 +00001426 programs which create code at runtime to flush the instruction
1427 cache in between code generation and first use. Valgrind
sewardje089f012010-10-13 21:47:29 +00001428 observes and honours such instructions. Hence, on ppc32/Linux,
1429 ppc64/Linux and ARM/Linux, Valgrind always provides complete, transparent
njn97db7612009-08-04 02:32:55 +00001430 support for self-modifying code. It is only on platforms such as
1431 x86/Linux, AMD64/Linux and x86/Darwin that you need to use this
njnf4b47582009-08-10 01:15:30 +00001432 option.</para>
njn97db7612009-08-04 02:32:55 +00001433 </listitem>
1434 </varlistentry>
1435
1436 <varlistentry id="opt.read-var-info" xreflabel="--read-var-info">
1437 <term>
1438 <option><![CDATA[--read-var-info=<yes|no> [default: no] ]]></option>
1439 </term>
1440 <listitem>
sewardje77c7242009-08-16 22:49:53 +00001441 <para>When enabled, Valgrind will read information about
1442 variable types and locations from DWARF3 debug info.
1443 This slows Valgrind down and makes it use more memory, but for
1444 the tools that can take advantage of it (Memcheck, Helgrind,
1445 DRD) it can result in more precise error messages. For example,
1446 here are some standard errors issued by Memcheck:</para>
njn97db7612009-08-04 02:32:55 +00001447<programlisting><![CDATA[
1448==15516== Uninitialised byte(s) found during client check request
1449==15516== at 0x400633: croak (varinfo1.c:28)
1450==15516== by 0x4006B2: main (varinfo1.c:55)
1451==15516== Address 0x60103b is 7 bytes inside data symbol "global_i2"
1452==15516==
1453==15516== Uninitialised byte(s) found during client check request
1454==15516== at 0x400633: croak (varinfo1.c:28)
1455==15516== by 0x4006BC: main (varinfo1.c:56)
1456==15516== Address 0x7fefffefc is on thread 1's stack]]></programlisting>
1457
1458 <para>And here are the same errors with
1459 <option>--read-var-info=yes</option>:</para>
1460
1461<programlisting><![CDATA[
1462==15522== Uninitialised byte(s) found during client check request
1463==15522== at 0x400633: croak (varinfo1.c:28)
1464==15522== by 0x4006B2: main (varinfo1.c:55)
1465==15522== Location 0x60103b is 0 bytes inside global_i2[7],
1466==15522== a global variable declared at varinfo1.c:41
1467==15522==
1468==15522== Uninitialised byte(s) found during client check request
1469==15522== at 0x400633: croak (varinfo1.c:28)
1470==15522== by 0x4006BC: main (varinfo1.c:56)
1471==15522== Location 0x7fefffefc is 0 bytes inside local var "local"
1472==15522== declared at varinfo1.c:46, in frame #1 of thread 1]]></programlisting>
1473 </listitem>
1474 </varlistentry>
1475
debad57fc2005-12-03 22:33:29 +00001476 <varlistentry id="opt.run-libc-freeres" xreflabel="--run-libc-freeres">
1477 <term>
1478 <option><![CDATA[--run-libc-freeres=<yes|no> [default: yes] ]]></option>
1479 </term>
1480 <listitem>
njnf4b47582009-08-10 01:15:30 +00001481 <para>This option is only relevant when running Valgrind on Linux.</para>
njn7316df22009-08-04 01:16:01 +00001482
debad57fc2005-12-03 22:33:29 +00001483 <para>The GNU C library (<function>libc.so</function>), which is
1484 used by all programs, may allocate memory for its own uses.
1485 Usually it doesn't bother to free that memory when the program
sewardj33878892007-11-17 09:43:25 +00001486 ends&mdash;there would be no point, since the Linux kernel reclaims
debad57fc2005-12-03 22:33:29 +00001487 all process resources when a process exits anyway, so it would
1488 just slow things down.</para>
1489
1490 <para>The glibc authors realised that this behaviour causes leak
1491 checkers, such as Valgrind, to falsely report leaks in glibc, when
1492 a leak check is done at exit. In order to avoid this, they
1493 provided a routine called <function>__libc_freeres</function>
1494 specifically to make glibc release all memory it has allocated.
njn1d0825f2006-03-27 11:37:07 +00001495 Memcheck therefore tries to run
debad57fc2005-12-03 22:33:29 +00001496 <function>__libc_freeres</function> at exit.</para>
1497
sewardj08e31e22007-05-23 21:58:33 +00001498 <para>Unfortunately, in some very old versions of glibc,
debad57fc2005-12-03 22:33:29 +00001499 <function>__libc_freeres</function> is sufficiently buggy to cause
sewardj08e31e22007-05-23 21:58:33 +00001500 segmentation faults. This was particularly noticeable on Red Hat
njnf4b47582009-08-10 01:15:30 +00001501 7.1. So this option is provided in order to inhibit the run of
debad57fc2005-12-03 22:33:29 +00001502 <function>__libc_freeres</function>. If your program seems to run
1503 fine on Valgrind, but segfaults at exit, you may find that
1504 <option>--run-libc-freeres=no</option> fixes that, although at the
1505 cost of possibly falsely reporting space leaks in
1506 <filename>libc.so</filename>.</para>
1507 </listitem>
1508 </varlistentry>
1509
1510 <varlistentry id="opt.sim-hints" xreflabel="--sim-hints">
1511 <term>
1512 <option><![CDATA[--sim-hints=hint1,hint2,... ]]></option>
1513 </term>
1514 <listitem>
1515 <para>Pass miscellaneous hints to Valgrind which slightly modify
1516 the simulated behaviour in nonstandard or dangerous ways, possibly
1517 to help the simulation of strange features. By default no hints
1518 are enabled. Use with caution! Currently known hints are:</para>
1519 <itemizedlist>
1520 <listitem>
1521 <para><option>lax-ioctls: </option> Be very lax about ioctl
1522 handling; the only assumption is that the size is
1523 correct. Doesn't require the full buffer to be initialized
1524 when writing. Without this, using some device drivers with a
1525 large number of strange ioctl commands becomes very
1526 tiresome.</para>
1527 </listitem>
1528 <listitem>
1529 <para><option>enable-inner: </option> Enable some special
1530 magic needed when the program being run is itself
1531 Valgrind.</para>
1532 </listitem>
1533 </itemizedlist>
1534 </listitem>
1535 </varlistentry>
1536
1537 <varlistentry id="opt.kernel-variant" xreflabel="--kernel-variant">
1538 <term>
1539 <option>--kernel-variant=variant1,variant2,...</option>
1540 </term>
1541 <listitem>
1542 <para>Handle system calls and ioctls arising from minor variants
1543 of the default kernel for this platform. This is useful for
1544 running on hacked kernels or with kernel modules which support
1545 nonstandard ioctls, for example. Use with caution. If you don't
1546 understand what this option does then you almost certainly don't
1547 need it. Currently known variants are:</para>
1548 <itemizedlist>
1549 <listitem>
njn7316df22009-08-04 01:16:01 +00001550 <para><option>bproc: </option> Support the
1551 <function>sys_broc</function> system call on x86. This is for
1552 running on BProc, which is a minor variant of standard Linux which
1553 is sometimes used for building clusters.</para>
debad57fc2005-12-03 22:33:29 +00001554 </listitem>
1555 </itemizedlist>
1556 </listitem>
1557 </varlistentry>
1558
1559 <varlistentry id="opt.show-emwarns" xreflabel="--show-emwarns">
1560 <term>
1561 <option><![CDATA[--show-emwarns=<yes|no> [default: no] ]]></option>
1562 </term>
1563 <listitem>
1564 <para>When enabled, Valgrind will emit warnings about its CPU
1565 emulation in certain cases. These are usually not
1566 interesting.</para>
1567 </listitem>
1568 </varlistentry>
1569
sewardjf9ebc392010-05-09 22:30:43 +00001570 <varlistentry id="opt.require-text-symbol"
1571 xreflabel="--require-text-symbol">
1572 <term>
1573 <option><![CDATA[--require-text-symbol=:sonamepatt:fnnamepatt]]></option>
1574 </term>
1575 <listitem>
1576 <para>When a shared object whose soname
1577 matches <varname>sonamepatt</varname> is loaded into the
1578 process, examine all the text symbols it exports. If none of
1579 those match <varname>fnnamepatt</varname>, print an error
1580 message and abandon the run. This makes it possible to ensure
1581 that the run does not continue unless a given shared object
1582 contains a particular function name.
1583 </para>
1584 <para>
1585 Both <varname>sonamepatt</varname> and
1586 <varname>fnnamepatt</varname> can be written using the usual
1587 <varname>?</varname> and <varname>*</varname> wildcards. For
1588 example: <varname>":*libc.so*:foo?bar"</varname>. You may use
1589 characters other than a colon to separate the two patterns. It
1590 is only important that the first character and the separator
1591 character are the same. For example, the above example could
1592 also be written <varname>"Q*libc.so*Qfoo?bar"</varname>.
1593 Multiple <varname> --require-text-symbol</varname> flags are
1594 allowed, in which case shared objects that are loaded into
1595 the process will be checked against all of them.
1596 </para>
1597 <para>
1598 The purpose of this is to support reliable usage of marked-up
1599 libraries. For example, suppose we have a version of GCC's
1600 <varname>libgomp.so</varname> which has been marked up with
1601 annotations to support Helgrind. It is only too easy and
1602 confusing to load the wrong, un-annotated
1603 <varname>libgomp.so</varname> into the application. So the idea
1604 is: add a text symbol in the marked-up library, for
1605 example <varname>annotated_for_helgrind_3_6</varname>, and then
1606 give the flag
1607 <varname>--require-text-symbol=:*libgomp*so*:annotated_for_helgrind_3_6</varname>
1608 so that when <varname>libgomp.so</varname> is loaded, Valgrind
1609 scans its symbol table, and if the symbol isn't present the run
1610 is aborted, rather than continuing silently with the
1611 un-marked-up library. Note that you should put the entire flag
1612 in quotes to stop shells expanding up the <varname>*</varname>
1613 and <varname>?</varname> wildcards.
1614 </para>
1615 </listitem>
1616 </varlistentry>
1617
1618
debad57fc2005-12-03 22:33:29 +00001619</variablelist>
de03e0e7c2005-12-03 23:02:33 +00001620<!-- end of xi:include in the manpage -->
debad57fc2005-12-03 22:33:29 +00001621
njn3e986b22004-11-30 10:43:45 +00001622</sect2>
1623
1624
njnf4b47582009-08-10 01:15:30 +00001625<sect2 id="manual-core.debugopts" xreflabel="Debugging Options">
1626<title>Debugging Options</title>
njn3e986b22004-11-30 10:43:45 +00001627
de03e0e7c2005-12-03 23:02:33 +00001628<!-- start of xi:include in the manpage -->
1629<para id="debug.opts.para">There are also some options for debugging
1630Valgrind itself. You shouldn't need to use them in the normal run of
1631things. If you wish to see the list, use the
1632<option>--help-debug</option> option.</para>
1633<!-- end of xi:include in the manpage -->
njn3e986b22004-11-30 10:43:45 +00001634
njn3e986b22004-11-30 10:43:45 +00001635</sect2>
1636
1637
njnf4b47582009-08-10 01:15:30 +00001638<sect2 id="manual-core.defopts" xreflabel="Setting Default Options">
1639<title>Setting Default Options</title>
njn3e986b22004-11-30 10:43:45 +00001640
1641<para>Note that Valgrind also reads options from three places:</para>
1642
1643 <orderedlist>
1644 <listitem>
1645 <para>The file <computeroutput>~/.valgrindrc</computeroutput></para>
1646 </listitem>
1647
1648 <listitem>
1649 <para>The environment variable
1650 <computeroutput>$VALGRIND_OPTS</computeroutput></para>
1651 </listitem>
1652
1653 <listitem>
1654 <para>The file <computeroutput>./.valgrindrc</computeroutput></para>
1655 </listitem>
1656 </orderedlist>
1657
1658<para>These are processed in the given order, before the
1659command-line options. Options processed later override those
1660processed earlier; for example, options in
1661<computeroutput>./.valgrindrc</computeroutput> will take
1662precedence over those in
njn7316df22009-08-04 01:16:01 +00001663<computeroutput>~/.valgrindrc</computeroutput>.
dirka656f3d2008-11-22 12:03:19 +00001664</para>
1665
1666<para>Please note that the <computeroutput>./.valgrindrc</computeroutput>
1667file is ignored if it is marked as world writeable or not owned
njn7316df22009-08-04 01:16:01 +00001668by the current user. This is because the
1669<computeroutput>./.valgrindrc</computeroutput> can contain options that are
1670potentially harmful or can be used by a local attacker to execute code under
1671your user account.
dirka656f3d2008-11-22 12:03:19 +00001672</para>
njn3e986b22004-11-30 10:43:45 +00001673
1674<para>Any tool-specific options put in
1675<computeroutput>$VALGRIND_OPTS</computeroutput> or the
1676<computeroutput>.valgrindrc</computeroutput> files should be
1677prefixed with the tool name and a colon. For example, if you
1678want Memcheck to always do leak checking, you can put the
1679following entry in <literal>~/.valgrindrc</literal>:</para>
1680
1681<programlisting><![CDATA[
1682--memcheck:leak-check=yes]]></programlisting>
1683
1684<para>This will be ignored if any tool other than Memcheck is
1685run. Without the <computeroutput>memcheck:</computeroutput>
1686part, this will cause problems if you select other tools that
1687don't understand
njn7e5d4ed2009-07-30 02:57:52 +00001688<option>--leak-check=yes</option>.</para>
njn3e986b22004-11-30 10:43:45 +00001689
1690</sect2>
1691
1692</sect1>
1693
1694
sewardj778d7832007-11-22 01:21:56 +00001695
1696
1697<sect1 id="manual-core.pthreads" xreflabel="Support for Threads">
1698<title>Support for Threads</title>
1699
sewardje77c7242009-08-16 22:49:53 +00001700<para>Threaded programs are fully supported.</para>
sewardj778d7832007-11-22 01:21:56 +00001701
sewardje77c7242009-08-16 22:49:53 +00001702<para>The main thing to point out with respect to threaded programs is
1703that your program will use the native threading library, but Valgrind
1704serialises execution so that only one (kernel) thread is running at a
1705time. This approach avoids the horrible implementation problems of
1706implementing a truly multithreaded version of Valgrind, but it does
1707mean that threaded apps run only on one CPU, even if you have a
1708multiprocessor or multicore machine.</para>
1709
1710<para>Valgrind doesn't schedule the threads itself. It merely ensures
1711that only one thread runs at once, using a simple locking scheme. The
1712actual thread scheduling remains under control of the OS kernel. What
1713this does mean, though, is that your program will see very different
1714scheduling when run on Valgrind than it does when running normally.
1715This is both because Valgrind is serialising the threads, and because
1716the code runs so much slower than normal.</para>
1717
1718<para>This difference in scheduling may cause your program to behave
1719differently, if you have some kind of concurrency, critical race,
1720locking, or similar, bugs. In that case you might consider using the
1721tools Helgrind and/or DRD to track them down.</para>
sewardj778d7832007-11-22 01:21:56 +00001722
njn7316df22009-08-04 01:16:01 +00001723<para>On Linux, Valgrind also supports direct use of the
1724<computeroutput>clone</computeroutput> system call,
1725<computeroutput>futex</computeroutput> and so on.
1726<computeroutput>clone</computeroutput> is supported where either
sewardj778d7832007-11-22 01:21:56 +00001727everything is shared (a thread) or nothing is shared (fork-like); partial
sewardje089f012010-10-13 21:47:29 +00001728sharing will fail.
sewardj778d7832007-11-22 01:21:56 +00001729</para>
1730
1731
1732</sect1>
1733
1734<sect1 id="manual-core.signals" xreflabel="Handling of Signals">
1735<title>Handling of Signals</title>
1736
1737<para>Valgrind has a fairly complete signal implementation. It should be
1738able to cope with any POSIX-compliant use of signals.</para>
1739
1740<para>If you're using signals in clever ways (for example, catching
1741SIGSEGV, modifying page state and restarting the instruction), you're
1742probably relying on precise exceptions. In this case, you will need
njn7e5d4ed2009-07-30 02:57:52 +00001743to use <option>--vex-iropt-precise-memory-exns=yes</option>.
sewardj778d7832007-11-22 01:21:56 +00001744</para>
1745
1746<para>If your program dies as a result of a fatal core-dumping signal,
1747Valgrind will generate its own core file
1748(<computeroutput>vgcore.NNNNN</computeroutput>) containing your program's
njn7316df22009-08-04 01:16:01 +00001749state. You may use this core file for post-mortem debugging with GDB or
sewardj778d7832007-11-22 01:21:56 +00001750similar. (Note: it will not generate a core if your core dump size limit is
17510.) At the time of writing the core dumps do not include all the floating
1752point register information.</para>
1753
1754<para>In the unlikely event that Valgrind itself crashes, the operating system
1755will create a core dump in the usual way.</para>
1756
1757</sect1>
1758
1759
1760
1761
1762
1763
1764
1765
1766<sect1 id="manual-core.install" xreflabel="Building and Installing">
1767<title>Building and Installing Valgrind</title>
1768
1769<para>We use the standard Unix
1770<computeroutput>./configure</computeroutput>,
1771<computeroutput>make</computeroutput>, <computeroutput>make
sewardje089f012010-10-13 21:47:29 +00001772install</computeroutput> mechanism. Once you have completed
sewardj778d7832007-11-22 01:21:56 +00001773<computeroutput>make install</computeroutput> you may then want
1774to run the regression tests
1775with <computeroutput>make regtest</computeroutput>.
1776</para>
1777
sewardje089f012010-10-13 21:47:29 +00001778<para>In addition to the usual
1779<option>--prefix=/path/to/install/tree</option>, there are three
1780 options which affect how Valgrind is built:
sewardj778d7832007-11-22 01:21:56 +00001781<itemizedlist>
1782
1783 <listitem>
1784 <para><option>--enable-inner</option></para>
1785 <para>This builds Valgrind with some special magic hacks which make
1786 it possible to run it on a standard build of Valgrind (what the
1787 developers call "self-hosting"). Ordinarily you should not use
njnf4b47582009-08-10 01:15:30 +00001788 this option as various kinds of safety checks are disabled.
sewardj778d7832007-11-22 01:21:56 +00001789 </para>
1790 </listitem>
1791
1792 <listitem>
sewardj778d7832007-11-22 01:21:56 +00001793 <para><option>--enable-only64bit</option></para>
1794 <para><option>--enable-only32bit</option></para>
sewardje089f012010-10-13 21:47:29 +00001795 <para>On 64-bit platforms (amd64-linux, ppc64-linux,
1796 amd64-darwin), Valgrind is by default built in such a way that
1797 both 32-bit and 64-bit executables can be run. Sometimes this
1798 cleverness is a problem for a variety of reasons. These two
1799 options allow for single-target builds in this situation. If you
1800 issue both, the configure script will complain. Note they are
1801 ignored on 32-bit-only platforms (x86-linux, ppc32-linux,
1802 arm-linux, x86-darwin).
sewardj778d7832007-11-22 01:21:56 +00001803 </para>
1804 </listitem>
1805
1806</itemizedlist>
1807</para>
1808
1809<para>The <computeroutput>configure</computeroutput> script tests
1810the version of the X server currently indicated by the current
1811<computeroutput>$DISPLAY</computeroutput>. This is a known bug.
1812The intention was to detect the version of the current X
1813client libraries, so that correct suppressions could be selected
1814for them, but instead the test checks the server version. This
1815is just plain wrong.</para>
1816
1817<para>If you are building a binary package of Valgrind for
1818distribution, please read <literal>README_PACKAGERS</literal>
1819<xref linkend="dist.readme-packagers"/>. It contains some
1820important information.</para>
1821
1822<para>Apart from that, there's not much excitement here. Let us
1823know if you have build problems.</para>
1824
1825</sect1>
1826
1827
1828
1829<sect1 id="manual-core.problems" xreflabel="If You Have Problems">
1830<title>If You Have Problems</title>
1831
1832<para>Contact us at <ulink url="&vg-url;">&vg-url;</ulink>.</para>
1833
1834<para>See <xref linkend="manual-core.limits"/> for the known
1835limitations of Valgrind, and for a list of programs which are
1836known not to work on it.</para>
1837
1838<para>All parts of the system make heavy use of assertions and
1839internal self-checks. They are permanently enabled, and we have no
1840plans to disable them. If one of them breaks, please mail us!</para>
1841
1842<para>If you get an assertion failure
1843in <filename>m_mallocfree.c</filename>, this may have happened because
njn7316df22009-08-04 01:16:01 +00001844your program wrote off the end of a heap block, or before its
1845beginning, thus corrupting head metadata. Valgrind hopefully will have
1846emitted a message to that effect before dying in this way.</para>
sewardj778d7832007-11-22 01:21:56 +00001847
1848<para>Read the <xref linkend="FAQ"/> for more advice about common problems,
1849crashes, etc.</para>
1850
1851</sect1>
1852
1853
1854
1855<sect1 id="manual-core.limits" xreflabel="Limitations">
1856<title>Limitations</title>
1857
1858<para>The following list of limitations seems long. However, most
1859programs actually work fine.</para>
1860
njn7316df22009-08-04 01:16:01 +00001861<para>Valgrind will run programs on the supported platforms
1862subject to the following constraints:</para>
sewardj778d7832007-11-22 01:21:56 +00001863
1864 <itemizedlist>
1865 <listitem>
sewardje089f012010-10-13 21:47:29 +00001866 <para>On x86 and amd64, there is no support for 3DNow!
1867 instructions. If the translator encounters these, Valgrind will
1868 generate a SIGILL when the instruction is executed. Apart from
1869 that, on x86 and amd64, essentially all instructions are supported,
1870 up to and including SSE4.2 in 64-bit mode and SSSE3 in 32-bit mode.
1871 Some exceptions: SSE4.2 AES instructions are not supported in
1872 64-bit mode, and 32-bit mode does in fact support the bare minimum
1873 SSE4 instructions to needed to run programs on MacOSX 10.6 on
1874 32-bit targets.
sewardj778d7832007-11-22 01:21:56 +00001875 </para>
njn7316df22009-08-04 01:16:01 +00001876 </listitem>
sewardj778d7832007-11-22 01:21:56 +00001877
njn7316df22009-08-04 01:16:01 +00001878 <listitem>
sewardje089f012010-10-13 21:47:29 +00001879 <para>On ppc32 and ppc64, almost all integer, floating point and
1880 Altivec instructions are supported. Specifically: integer and FP
1881 insns that are mandatory for PowerPC, the "General-purpose
1882 optional" group (fsqrt, fsqrts, stfiwx), the "Graphics optional"
1883 group (fre, fres, frsqrte, frsqrtes), and the Altivec (also known
1884 as VMX) SIMD instruction set, are supported. Also, instructions
1885 from the Power ISA 2.05 specification, as present in POWER6 CPUs,
1886 are supported.</para>
1887 </listitem>
1888
1889 <listitem>
1890 <para>On ARM, essentially the entire ARMv7-A instruction set
1891 is supported, in both ARM and Thumb mode. ThumbEE and Jazelle are
1892 not supported. NEON and VFPv3 support is fairly complete. ARMv6
1893 media instruction support is mostly done but not yet complete.
1894 </para>
sewardj778d7832007-11-22 01:21:56 +00001895 </listitem>
1896
1897 <listitem>
sewardj778d7832007-11-22 01:21:56 +00001898 <para>If your program does its own memory management, rather than
1899 using malloc/new/free/delete, it should still work, but Memcheck's
sewardje089f012010-10-13 21:47:29 +00001900 error checking won't be so effective. If you describe your
1901 program's memory management scheme using "client requests" (see
1902 <xref linkend="manual-core-adv.clientreq"/>), Memcheck can do
1903 better. Nevertheless, using malloc/new and free/delete is still
1904 the best approach.</para>
sewardj778d7832007-11-22 01:21:56 +00001905 </listitem>
1906
1907 <listitem>
1908 <para>Valgrind's signal simulation is not as robust as it could be.
1909 Basic POSIX-compliant sigaction and sigprocmask functionality is
1910 supplied, but it's conceivable that things could go badly awry if you
1911 do weird things with signals. Workaround: don't. Programs that do
1912 non-POSIX signal tricks are in any case inherently unportable, so
1913 should be avoided if possible.</para>
1914 </listitem>
1915
1916 <listitem>
1917 <para>Machine instructions, and system calls, have been implemented
1918 on demand. So it's possible, although unlikely, that a program will
1919 fall over with a message to that effect. If this happens, please
1920 report all the details printed out, so we can try and implement the
1921 missing feature.</para>
1922 </listitem>
1923
1924 <listitem>
sewardje089f012010-10-13 21:47:29 +00001925 <para>Memory consumption of your program is majorly increased
1926 whilst running under Valgrind's Memcheck tool. This is due to the
1927 large amount of administrative information maintained behind the
1928 scenes. Another cause is that Valgrind dynamically translates the
1929 original executable. Translated, instrumented code is 12-18 times
1930 larger than the original so you can easily end up with 100+ MB of
1931 translations when running (eg) a web browser.</para>
sewardj778d7832007-11-22 01:21:56 +00001932 </listitem>
1933
1934 <listitem>
1935 <para>Valgrind can handle dynamically-generated code just fine. If
sewardje089f012010-10-13 21:47:29 +00001936 you regenerate code over the top of old code (ie. at the same
1937 memory addresses), if the code is on the stack Valgrind will
1938 realise the code has changed, and work correctly. This is
1939 necessary to handle the trampolines GCC uses to implemented nested
1940 functions. If you regenerate code somewhere other than the stack,
1941 and you are running on an 32- or 64-bit x86 CPU, you will need to
1942 use the <option>--smc-check=all</option> option, and Valgrind will
1943 run more slowly than normal. Or you can add client requests that
1944 tell Valgrind when your program has overwritten code.
1945 </para>
1946 <para> On other platforms (ARM, PowerPC) Valgrind observes and
1947 honours the cache invalidation hints that programs are obliged to
1948 emit to notify new code, and so self-modifying-code support should
1949 work automatically, without the need
1950 for <option>--smc-check=all</option>.</para>
sewardj778d7832007-11-22 01:21:56 +00001951 </listitem>
1952
1953 <listitem>
njn7316df22009-08-04 01:16:01 +00001954 <para>Valgrind has the following limitations
sewardj778d7832007-11-22 01:21:56 +00001955 in its implementation of x86/AMD64 floating point relative to
1956 IEEE754.</para>
1957
1958 <para>Precision: There is no support for 80 bit arithmetic.
1959 Internally, Valgrind represents all such "long double" numbers in 64
1960 bits, and so there may be some differences in results. Whether or
1961 not this is critical remains to be seen. Note, the x86/amd64
1962 fldt/fstpt instructions (read/write 80-bit numbers) are correctly
1963 simulated, using conversions to/from 64 bits, so that in-memory
1964 images of 80-bit numbers look correct if anyone wants to see.</para>
1965
1966 <para>The impression observed from many FP regression tests is that
1967 the accuracy differences aren't significant. Generally speaking, if
1968 a program relies on 80-bit precision, there may be difficulties
1969 porting it to non x86/amd64 platforms which only support 64-bit FP
1970 precision. Even on x86/amd64, the program may get different results
1971 depending on whether it is compiled to use SSE2 instructions (64-bits
1972 only), or x87 instructions (80-bit). The net effect is to make FP
1973 programs behave as if they had been run on a machine with 64-bit IEEE
1974 floats, for example PowerPC. On amd64 FP arithmetic is done by
1975 default on SSE2, so amd64 looks more like PowerPC than x86 from an FP
1976 perspective, and there are far fewer noticeable accuracy differences
1977 than with x86.</para>
1978
1979 <para>Rounding: Valgrind does observe the 4 IEEE-mandated rounding
1980 modes (to nearest, to +infinity, to -infinity, to zero) for the
1981 following conversions: float to integer, integer to float where
1982 there is a possibility of loss of precision, and float-to-float
1983 rounding. For all other FP operations, only the IEEE default mode
1984 (round to nearest) is supported.</para>
1985
1986 <para>Numeric exceptions in FP code: IEEE754 defines five types of
1987 numeric exception that can happen: invalid operation (sqrt of
1988 negative number, etc), division by zero, overflow, underflow,
1989 inexact (loss of precision).</para>
1990
1991 <para>For each exception, two courses of action are defined by IEEE754:
1992 either (1) a user-defined exception handler may be called, or (2) a
1993 default action is defined, which "fixes things up" and allows the
1994 computation to proceed without throwing an exception.</para>
1995
1996 <para>Currently Valgrind only supports the default fixup actions.
1997 Again, feedback on the importance of exception support would be
1998 appreciated.</para>
1999
2000 <para>When Valgrind detects that the program is trying to exceed any
2001 of these limitations (setting exception handlers, rounding mode, or
2002 precision control), it can print a message giving a traceback of
2003 where this has happened, and continue execution. This behaviour used
2004 to be the default, but the messages are annoying and so showing them
2005 is now disabled by default. Use <option>--show-emwarns=yes</option> to see
2006 them.</para>
2007
2008 <para>The above limitations define precisely the IEEE754 'default'
2009 behaviour: default fixup on all exceptions, round-to-nearest
2010 operations, and 64-bit precision.</para>
2011 </listitem>
2012
2013 <listitem>
njn7316df22009-08-04 01:16:01 +00002014 <para>Valgrind has the following limitations in
sewardj778d7832007-11-22 01:21:56 +00002015 its implementation of x86/AMD64 SSE2 FP arithmetic, relative to
2016 IEEE754.</para>
2017
2018 <para>Essentially the same: no exceptions, and limited observance of
2019 rounding mode. Also, SSE2 has control bits which make it treat
2020 denormalised numbers as zero (DAZ) and a related action, flush
2021 denormals to zero (FTZ). Both of these cause SSE2 arithmetic to be
2022 less accurate than IEEE requires. Valgrind detects, ignores, and can
2023 warn about, attempts to enable either mode.</para>
2024 </listitem>
2025
2026 <listitem>
sewardje089f012010-10-13 21:47:29 +00002027 <para>Valgrind has the following limitations in
2028 its implementation of ARM VFPv3 arithmetic, relative to
2029 IEEE754.</para>
2030
2031 <para>Essentially the same: no exceptions, and limited observance
2032 of rounding mode. Also, switching the VFP unit into vector mode
2033 will cause Valgrind to abort the program -- it has no way to
2034 emulate vector uses of VFP at a reasonable performance level. This
2035 is no big deal given that non-scalar uses of VFP instructions are
2036 in any case deprecated.</para>
2037 </listitem>
2038
2039 <listitem>
njn7316df22009-08-04 01:16:01 +00002040 <para>Valgrind has the following limitations
sewardj778d7832007-11-22 01:21:56 +00002041 in its implementation of PPC32 and PPC64 floating point
2042 arithmetic, relative to IEEE754.</para>
2043
2044 <para>Scalar (non-Altivec): Valgrind provides a bit-exact emulation of
2045 all floating point instructions, except for "fre" and "fres", which are
2046 done more precisely than required by the PowerPC architecture specification.
2047 All floating point operations observe the current rounding mode.
2048 </para>
2049
2050 <para>However, fpscr[FPRF] is not set after each operation. That could
2051 be done but would give measurable performance overheads, and so far
2052 no need for it has been found.</para>
2053
2054 <para>As on x86/AMD64, IEEE754 exceptions are not supported: all floating
2055 point exceptions are handled using the default IEEE fixup actions.
2056 Valgrind detects, ignores, and can warn about, attempts to unmask
2057 the 5 IEEE FP exception kinds by writing to the floating-point status
2058 and control register (fpscr).
2059 </para>
2060
2061 <para>Vector (Altivec, VMX): essentially as with x86/AMD64 SSE/SSE2:
2062 no exceptions, and limited observance of rounding mode.
2063 For Altivec, FP arithmetic
2064 is done in IEEE/Java mode, which is more accurate than the Linux default
2065 setting. "More accurate" means that denormals are handled properly,
2066 rather than simply being flushed to zero.</para>
2067 </listitem>
2068 </itemizedlist>
2069
2070 <para>Programs which are known not to work are:</para>
2071 <itemizedlist>
2072 <listitem>
2073 <para>emacs starts up but immediately concludes it is out of
2074 memory and aborts. It may be that Memcheck does not provide
2075 a good enough emulation of the
2076 <computeroutput>mallinfo</computeroutput> function.
2077 Emacs works fine if you build it to use
2078 the standard malloc/free routines.</para>
2079 </listitem>
2080 </itemizedlist>
2081
2082</sect1>
2083
2084
2085<sect1 id="manual-core.example" xreflabel="An Example Run">
2086<title>An Example Run</title>
2087
2088<para>This is the log for a run of a small program using Memcheck.
2089The program is in fact correct, and the reported error is as the
2090result of a potentially serious code generation bug in GNU g++
2091(snapshot 20010527).</para>
2092
2093<programlisting><![CDATA[
2094sewardj@phoenix:~/newmat10$ ~/Valgrind-6/valgrind -v ./bogon
2095==25832== Valgrind 0.10, a memory error detector for x86 RedHat 7.1.
2096==25832== Copyright (C) 2000-2001, and GNU GPL'd, by Julian Seward.
2097==25832== Startup, with flags:
2098==25832== --suppressions=/home/sewardj/Valgrind/redhat71.supp
2099==25832== reading syms from /lib/ld-linux.so.2
2100==25832== reading syms from /lib/libc.so.6
2101==25832== reading syms from /mnt/pima/jrs/Inst/lib/libgcc_s.so.0
2102==25832== reading syms from /lib/libm.so.6
2103==25832== reading syms from /mnt/pima/jrs/Inst/lib/libstdc++.so.3
2104==25832== reading syms from /home/sewardj/Valgrind/valgrind.so
2105==25832== reading syms from /proc/self/exe
2106==25832==
2107==25832== Invalid read of size 4
2108==25832== at 0x8048724: BandMatrix::ReSize(int,int,int) (bogon.cpp:45)
2109==25832== by 0x80487AF: main (bogon.cpp:66)
2110==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd
2111==25832==
2112==25832== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
2113==25832== malloc/free: in use at exit: 0 bytes in 0 blocks.
2114==25832== malloc/free: 0 allocs, 0 frees, 0 bytes allocated.
2115==25832== For a detailed leak analysis, rerun with: --leak-check=yes
2116]]></programlisting>
2117
njn7316df22009-08-04 01:16:01 +00002118<para>The GCC folks fixed this about a week before GCC 3.0
sewardj778d7832007-11-22 01:21:56 +00002119shipped.</para>
2120
2121</sect1>
2122
2123
2124<sect1 id="manual-core.warnings" xreflabel="Warning Messages">
2125<title>Warning Messages You Might See</title>
2126
njn7316df22009-08-04 01:16:01 +00002127<para>Some of these only appear if you run in verbose mode
njn7e5d4ed2009-07-30 02:57:52 +00002128(enabled by <option>-v</option>):</para>
sewardj778d7832007-11-22 01:21:56 +00002129
2130 <itemizedlist>
2131
2132 <listitem>
2133 <para><computeroutput>More than 100 errors detected. Subsequent
2134 errors will still be recorded, but in less detail than
2135 before.</computeroutput></para>
2136
2137 <para>After 100 different errors have been shown, Valgrind becomes
2138 more conservative about collecting them. It then requires only the
2139 program counters in the top two stack frames to match when deciding
2140 whether or not two errors are really the same one. Prior to this
2141 point, the PCs in the top four frames are required to match. This
2142 hack has the effect of slowing down the appearance of new errors
2143 after the first 100. The 100 constant can be changed by recompiling
2144 Valgrind.</para>
2145 </listitem>
2146
2147 <listitem>
2148 <para><computeroutput>More than 1000 errors detected. I'm not
2149 reporting any more. Final error counts may be inaccurate. Go fix
2150 your program!</computeroutput></para>
2151
2152 <para>After 1000 different errors have been detected, Valgrind
2153 ignores any more. It seems unlikely that collecting even more
2154 different ones would be of practical help to anybody, and it avoids
2155 the danger that Valgrind spends more and more of its time comparing
2156 new errors against an ever-growing collection. As above, the 1000
2157 number is a compile-time constant.</para>
2158 </listitem>
2159
2160 <listitem>
2161 <para><computeroutput>Warning: client switching stacks?</computeroutput></para>
2162
2163 <para>Valgrind spotted such a large change in the stack pointer
2164 that it guesses the client is switching to
2165 a different stack. At this point it makes a kludgey guess where the
2166 base of the new stack is, and sets memory permissions accordingly.
2167 You may get many bogus error messages following this, if Valgrind
2168 guesses wrong. At the moment "large change" is defined as a change
2169 of more that 2000000 in the value of the
2170 stack pointer register.</para>
2171 </listitem>
2172
2173 <listitem>
2174 <para><computeroutput>Warning: client attempted to close Valgrind's
2175 logfile fd &lt;number&gt;</computeroutput></para>
2176
2177 <para>Valgrind doesn't allow the client to close the logfile,
2178 because you'd never see any diagnostic information after that point.
2179 If you see this message, you may want to use the
2180 <option>--log-fd=&lt;number&gt;</option> option to specify a
2181 different logfile file-descriptor number.</para>
2182 </listitem>
2183
2184 <listitem>
2185 <para><computeroutput>Warning: noted but unhandled ioctl
2186 &lt;number&gt;</computeroutput></para>
2187
2188 <para>Valgrind observed a call to one of the vast family of
2189 <computeroutput>ioctl</computeroutput> system calls, but did not
2190 modify its memory status info (because nobody has yet written a
2191 suitable wrapper). The call will still have gone through, but you may get
2192 spurious errors after this as a result of the non-update of the
2193 memory info.</para>
2194 </listitem>
2195
2196 <listitem>
2197 <para><computeroutput>Warning: set address range perms: large range
2198 &lt;number></computeroutput></para>
2199
2200 <para>Diagnostic message, mostly for benefit of the Valgrind
2201 developers, to do with memory permissions.</para>
2202 </listitem>
2203
2204 </itemizedlist>
2205
2206</sect1>
2207
2208
2209
sewardjf5a491c2006-03-13 13:40:57 +00002210
2211
sewardja737e652006-03-19 18:19:11 +00002212
njn3e986b22004-11-30 10:43:45 +00002213</chapter>