blob: c7f8e1a3b6d2b47abc2a704aea1493f471918a7c [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
philippea02e2672013-03-06 22:39:18 +0000155<!-- Referenced from both the manual and manpage -->
156<sect1 id="&vg-comment-id;" xreflabel="&vg-comment-label;">
debad57fc2005-12-03 22:33:29 +0000157<title>The Commentary</title>
njn3e986b22004-11-30 10:43:45 +0000158
debad57fc2005-12-03 22:33:29 +0000159<para>Valgrind tools write a commentary, a stream of text, detailing
160error reports and other significant events. All lines in the commentary
161have following form:
njn3e986b22004-11-30 10:43:45 +0000162
163<programlisting><![CDATA[
164==12345== some-message-from-Valgrind]]></programlisting>
165</para>
166
debad57fc2005-12-03 22:33:29 +0000167<para>The <computeroutput>12345</computeroutput> is the process ID.
168This scheme makes it easy to distinguish program output from Valgrind
169commentary, and also easy to differentiate commentaries from different
170processes which have become merged together, for whatever reason.</para>
njn3e986b22004-11-30 10:43:45 +0000171
debad57fc2005-12-03 22:33:29 +0000172<para>By default, Valgrind tools write only essential messages to the
173commentary, so as to avoid flooding you with information of secondary
174importance. If you want more information about what is happening,
njnf4b47582009-08-10 01:15:30 +0000175re-run, passing the <option>-v</option> option to Valgrind. A second
debad57fc2005-12-03 22:33:29 +0000176<option>-v</option> gives yet more detail.
sewardj053fe982005-11-15 19:51:04 +0000177</para>
njn3e986b22004-11-30 10:43:45 +0000178
debad57fc2005-12-03 22:33:29 +0000179<para>You can direct the commentary to three different places:</para>
njn3e986b22004-11-30 10:43:45 +0000180
181<orderedlist>
182
debad57fc2005-12-03 22:33:29 +0000183 <listitem id="manual-core.out2fd" xreflabel="Directing output to fd">
184 <para>The default: send it to a file descriptor, which is by default
185 2 (stderr). So, if you give the core no options, it will write
186 commentary to the standard error stream. If you want to send it to
187 some other file descriptor, for example number 9, you can specify
188 <option>--log-fd=9</option>.</para>
189
190 <para>This is the simplest and most common arrangement, but can
sewardj08e31e22007-05-23 21:58:33 +0000191 cause problems when Valgrinding entire trees of processes which
debad57fc2005-12-03 22:33:29 +0000192 expect specific file descriptors, particularly stdin/stdout/stderr,
193 to be available for their own use.</para>
njn3e986b22004-11-30 10:43:45 +0000194 </listitem>
195
196 <listitem id="manual-core.out2file"
debad57fc2005-12-03 22:33:29 +0000197 xreflabel="Directing output to file"> <para>A less intrusive
198 option is to write the commentary to a file, which you specify by
njn374a36d2007-11-23 01:41:32 +0000199 <option>--log-file=filename</option>. There are special format
200 specifiers that can be used to use a process ID or an environment
201 variable name in the log file name. These are useful/necessary if your
202 program invokes multiple processes (especially for MPI programs).
203 See the <link linkend="manual-core.basicopts">basic options section</link>
204 for more details.</para>
njn3e986b22004-11-30 10:43:45 +0000205 </listitem>
206
207 <listitem id="manual-core.out2socket"
debad57fc2005-12-03 22:33:29 +0000208 xreflabel="Directing output to network socket"> <para>The
209 least intrusive option is to send the commentary to a network
210 socket. The socket is specified as an IP address and port number
211 pair, like this: <option>--log-socket=192.168.0.1:12345</option> if
sewardj08e31e22007-05-23 21:58:33 +0000212 you want to send the output to host IP 192.168.0.1 port 12345
213 (note: we
debad57fc2005-12-03 22:33:29 +0000214 have no idea if 12345 is a port of pre-existing significance). You
215 can also omit the port number:
216 <option>--log-socket=192.168.0.1</option>, in which case a default
217 port of 1500 is used. This default is defined by the constant
218 <computeroutput>VG_CLO_DEFAULT_LOGPORT</computeroutput> in the
219 sources.</para>
njn3e986b22004-11-30 10:43:45 +0000220
debad57fc2005-12-03 22:33:29 +0000221 <para>Note, unfortunately, that you have to use an IP address here,
222 rather than a hostname.</para>
njn3e986b22004-11-30 10:43:45 +0000223
sewardj08e31e22007-05-23 21:58:33 +0000224 <para>Writing to a network socket is pointless if you don't
debad57fc2005-12-03 22:33:29 +0000225 have something listening at the other end. We provide a simple
226 listener program,
227 <computeroutput>valgrind-listener</computeroutput>, which accepts
228 connections on the specified port and copies whatever it is sent to
229 stdout. Probably someone will tell us this is a horrible security
230 risk. It seems likely that people will write more sophisticated
231 listeners in the fullness of time.</para>
njn3e986b22004-11-30 10:43:45 +0000232
njn7316df22009-08-04 01:16:01 +0000233 <para><computeroutput>valgrind-listener</computeroutput> can accept
234 simultaneous connections from up to 50 Valgrinded processes. In front
235 of each line of output it prints the current number of active
236 connections in round brackets.</para>
njn3e986b22004-11-30 10:43:45 +0000237
njn7316df22009-08-04 01:16:01 +0000238 <para><computeroutput>valgrind-listener</computeroutput> accepts two
njnf4b47582009-08-10 01:15:30 +0000239 command-line options:</para>
mjw3e8d6342013-07-03 10:00:19 +0000240 <!-- start of xi:include in the manpage -->
241 <variablelist id="listener.opts.list">
242 <varlistentry>
243 <term><option>-e --exit-at-zero</option></term>
244 <listitem>
245 <para>When the number of connected processes falls back to zero,
246 exit. Without this, it will run forever, that is, until you
247 send it Control-C.</para>
248 </listitem>
249 </varlistentry>
250 <varlistentry>
251 <term><option>portnumber</option></term>
252 <listitem>
253 <para>Changes the port it listens on from the default (1500).
254 The specified port must be in the range 1024 to 65535.
255 The same restriction applies to port numbers specified by a
256 <option>--log-socket</option> to Valgrind itself.</para>
257 </listitem>
258 </varlistentry>
259 </variablelist>
260 <!-- end of xi:include in the manpage -->
njn3e986b22004-11-30 10:43:45 +0000261
sewardj08e31e22007-05-23 21:58:33 +0000262 <para>If a Valgrinded process fails to connect to a listener, for
debad57fc2005-12-03 22:33:29 +0000263 whatever reason (the listener isn't running, invalid or unreachable
264 host or port, etc), Valgrind switches back to writing the commentary
265 to stderr. The same goes for any process which loses an established
266 connection to a listener. In other words, killing the listener
267 doesn't kill the processes sending data to it.</para>
njn3e986b22004-11-30 10:43:45 +0000268 </listitem>
njn3e986b22004-11-30 10:43:45 +0000269
debad57fc2005-12-03 22:33:29 +0000270</orderedlist>
271
272<para>Here is an important point about the relationship between the
273commentary and profiling output from tools. The commentary contains a
274mix of messages from the Valgrind core and the selected tool. If the
275tool reports errors, it will report them to the commentary. However, if
276the tool does profiling, the profile data will be written to a file of
277some kind, depending on the tool, and independent of what
278<option>--log-*</option> options are in force. The commentary is
279intended to be a low-bandwidth, human-readable channel. Profiling data,
280on the other hand, is usually voluminous and not meaningful without
281further processing, which is why we have chosen this arrangement.</para>
njn3e986b22004-11-30 10:43:45 +0000282
283</sect1>
284
285
286<sect1 id="manual-core.report" xreflabel="Reporting of errors">
287<title>Reporting of errors</title>
288
sewardj08e31e22007-05-23 21:58:33 +0000289<para>When an error-checking tool
290detects something bad happening in the program, an error
291message is written to the commentary. Here's an example from Memcheck:</para>
njn3e986b22004-11-30 10:43:45 +0000292
293<programlisting><![CDATA[
294==25832== Invalid read of size 4
295==25832== at 0x8048724: BandMatrix::ReSize(int, int, int) (bogon.cpp:45)
296==25832== by 0x80487AF: main (bogon.cpp:66)
njn21f91952005-03-12 22:14:42 +0000297==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd]]></programlisting>
njn3e986b22004-11-30 10:43:45 +0000298
debad57fc2005-12-03 22:33:29 +0000299<para>This message says that the program did an illegal 4-byte read of
300address 0xBFFFF74C, which, as far as Memcheck can tell, is not a valid
njn7316df22009-08-04 01:16:01 +0000301stack address, nor corresponds to any current heap blocks or recently freed
302heap blocks. The read is happening at line 45 of
debad57fc2005-12-03 22:33:29 +0000303<filename>bogon.cpp</filename>, called from line 66 of the same file,
njn7316df22009-08-04 01:16:01 +0000304etc. For errors associated with an identified (current or freed) heap block,
305for example reading freed memory, Valgrind reports not only the
306location where the error happened, but also where the associated heap block
307was allocated/freed.</para>
njn3e986b22004-11-30 10:43:45 +0000308
debad57fc2005-12-03 22:33:29 +0000309<para>Valgrind remembers all error reports. When an error is detected,
310it is compared against old reports, to see if it is a duplicate. If so,
311the error is noted, but no further commentary is emitted. This avoids
312you being swamped with bazillions of duplicate error reports.</para>
njn3e986b22004-11-30 10:43:45 +0000313
debad57fc2005-12-03 22:33:29 +0000314<para>If you want to know how many times each error occurred, run with
315the <option>-v</option> option. When execution finishes, all the
316reports are printed out, along with, and sorted by, their occurrence
317counts. This makes it easy to see which errors have occurred most
318frequently.</para>
njn3e986b22004-11-30 10:43:45 +0000319
debad57fc2005-12-03 22:33:29 +0000320<para>Errors are reported before the associated operation actually
njn7316df22009-08-04 01:16:01 +0000321happens. For example, if you're using Memcheck and your program attempts to
322read from address zero, Memcheck will emit a message to this effect, and
323your program will then likely die with a segmentation fault.</para>
njn3e986b22004-11-30 10:43:45 +0000324
debad57fc2005-12-03 22:33:29 +0000325<para>In general, you should try and fix errors in the order that they
326are reported. Not doing so can be confusing. For example, a program
327which copies uninitialised values to several memory locations, and later
328uses them, will generate several error messages, when run on Memcheck.
329The first such error message may well give the most direct clue to the
330root cause of the problem.</para>
njn3e986b22004-11-30 10:43:45 +0000331
332<para>The process of detecting duplicate errors is quite an
333expensive one and can become a significant performance overhead
334if your program generates huge quantities of errors. To avoid
sewardj053fe982005-11-15 19:51:04 +0000335serious problems, Valgrind will simply stop collecting
sewardj08e31e22007-05-23 21:58:33 +0000336errors after 1,000 different errors have been seen, or 10,000,000 errors
njn3e986b22004-11-30 10:43:45 +0000337in total have been seen. In this situation you might as well
338stop your program and fix it, because Valgrind won't tell you
sewardj08e31e22007-05-23 21:58:33 +0000339anything else useful after this. Note that the 1,000/10,000,000 limits
njn3e986b22004-11-30 10:43:45 +0000340apply after suppressed errors are removed. These limits are
njnc7561b92005-06-19 01:24:32 +0000341defined in <filename>m_errormgr.c</filename> and can be increased
njn3e986b22004-11-30 10:43:45 +0000342if necessary.</para>
343
344<para>To avoid this cutoff you can use the
njnf4b47582009-08-10 01:15:30 +0000345<option>--error-limit=no</option> option. Then Valgrind will always show
346errors, regardless of how many there are. Use this option carefully,
debad57fc2005-12-03 22:33:29 +0000347since it may have a bad effect on performance.</para>
njn3e986b22004-11-30 10:43:45 +0000348
349</sect1>
350
351
352<sect1 id="manual-core.suppress" xreflabel="Suppressing errors">
353<title>Suppressing errors</title>
354
njn7316df22009-08-04 01:16:01 +0000355<para>The error-checking tools detect numerous problems in the system
356libraries, such as the C library,
357which come pre-installed with your OS. You can't easily fix
debad57fc2005-12-03 22:33:29 +0000358these, but you don't want to see these errors (and yes, there are many!)
359So Valgrind reads a list of errors to suppress at startup. A default
sewardj08e31e22007-05-23 21:58:33 +0000360suppression file is created by the
debad57fc2005-12-03 22:33:29 +0000361<computeroutput>./configure</computeroutput> script when the system is
362built.</para>
njn3e986b22004-11-30 10:43:45 +0000363
debad57fc2005-12-03 22:33:29 +0000364<para>You can modify and add to the suppressions file at your leisure,
365or, better, write your own. Multiple suppression files are allowed.
366This is useful if part of your project contains errors you can't or
367don't want to fix, yet you don't want to continuously be reminded of
368them.</para>
njn3e986b22004-11-30 10:43:45 +0000369
debad57fc2005-12-03 22:33:29 +0000370<formalpara><title>Note:</title> <para>By far the easiest way to add
njnf4b47582009-08-10 01:15:30 +0000371suppressions is to use the <option>--gen-suppressions=yes</option> option
372described in <xref linkend="manual-core.options"/>. This generates
sewardj9a0132d2008-11-04 11:29:19 +0000373suppressions automatically. For best results,
374though, you may want to edit the output
375 of <option>--gen-suppressions=yes</option> by hand, in which
376case it would be advisable to read through this section.
377</para>
njn3e986b22004-11-30 10:43:45 +0000378</formalpara>
379
debad57fc2005-12-03 22:33:29 +0000380<para>Each error to be suppressed is described very specifically, to
bart8b6b54b2009-07-19 08:16:30 +0000381minimise the possibility that a suppression-directive inadvertently
debad57fc2005-12-03 22:33:29 +0000382suppresses a bunch of similar errors which you did want to see. The
383suppression mechanism is designed to allow precise yet flexible
384specification of errors to suppress.</para>
njn3e986b22004-11-30 10:43:45 +0000385
njnf4b47582009-08-10 01:15:30 +0000386<para>If you use the <option>-v</option> option, at the end of execution,
philippe4e32d672013-10-17 22:10:41 +0000387Valgrind prints out one line for each used suppression, giving the number of times
388it got used, its name and the filename and line number where the suppression is
389defined. Depending on the suppression kind, the filename and line number are optionally
390followed by additional information (such as the number of blocks and bytes suppressed
391by a memcheck leak suppression). Here's the suppressions used by a
392run of <computeroutput>valgrind -v --tool=memcheck ls -l</computeroutput>:</para>
njn3e986b22004-11-30 10:43:45 +0000393
394<programlisting><![CDATA[
philippe4e32d672013-10-17 22:10:41 +0000395--1610-- used_suppression: 2 dl-hack3-cond-1 /usr/lib/valgrind/default.supp:1234
396--1610-- used_suppression: 2 glibc-2.5.x-on-SUSE-10.2-(PPC)-2a /usr/lib/valgrind/default.supp:1234
397]]></programlisting>
njn3e986b22004-11-30 10:43:45 +0000398
debad57fc2005-12-03 22:33:29 +0000399<para>Multiple suppressions files are allowed. By default, Valgrind
400uses <filename>$PREFIX/lib/valgrind/default.supp</filename>. You can
401ask to add suppressions from another file, by specifying
402<option>--suppressions=/path/to/file.supp</option>.
njn3e986b22004-11-30 10:43:45 +0000403</para>
404
debad57fc2005-12-03 22:33:29 +0000405<para>If you want to understand more about suppressions, look at an
406existing suppressions file whilst reading the following documentation.
sewardj08e31e22007-05-23 21:58:33 +0000407The file <filename>glibc-2.3.supp</filename>, in the source
njn3e986b22004-11-30 10:43:45 +0000408distribution, provides some good examples.</para>
409
410<para>Each suppression has the following components:</para>
411
debad57fc2005-12-03 22:33:29 +0000412<itemizedlist>
njn3e986b22004-11-30 10:43:45 +0000413
414 <listitem>
debad57fc2005-12-03 22:33:29 +0000415 <para>First line: its name. This merely gives a handy name to the
416 suppression, by which it is referred to in the summary of used
417 suppressions printed out when a program finishes. It's not
418 important what the name is; any identifying string will do.</para>
njn3e986b22004-11-30 10:43:45 +0000419 </listitem>
420
421 <listitem>
debad57fc2005-12-03 22:33:29 +0000422 <para>Second line: name of the tool(s) that the suppression is for
423 (if more than one, comma-separated), and the name of the suppression
sewardj33878892007-11-17 09:43:25 +0000424 itself, separated by a colon (n.b.: no spaces are allowed), eg:</para>
njn3e986b22004-11-30 10:43:45 +0000425<programlisting><![CDATA[
426tool_name1,tool_name2:suppression_name]]></programlisting>
427
sewardjf5fa3bd2006-03-14 00:56:29 +0000428 <para>Recall that Valgrind is a modular system, in which
debad57fc2005-12-03 22:33:29 +0000429 different instrumentation tools can observe your program whilst it
430 is running. Since different tools detect different kinds of errors,
431 it is necessary to say which tool(s) the suppression is meaningful
432 to.</para>
njn3e986b22004-11-30 10:43:45 +0000433
debad57fc2005-12-03 22:33:29 +0000434 <para>Tools will complain, at startup, if a tool does not understand
435 any suppression directed to it. Tools ignore suppressions which are
436 not directed to them. As a result, it is quite practical to put
437 suppressions for all tools into the same suppression file.</para>
njn3e986b22004-11-30 10:43:45 +0000438 </listitem>
439
440 <listitem>
debad57fc2005-12-03 22:33:29 +0000441 <para>Next line: a small number of suppression types have extra
442 information after the second line (eg. the <varname>Param</varname>
443 suppression for Memcheck)</para>
njn3e986b22004-11-30 10:43:45 +0000444 </listitem>
445
446 <listitem>
debad57fc2005-12-03 22:33:29 +0000447 <para>Remaining lines: This is the calling context for the error --
sewardj08e31e22007-05-23 21:58:33 +0000448 the chain of function calls that led to it. There can be up to 24
449 of these lines.</para>
njn3e986b22004-11-30 10:43:45 +0000450
sewardj66293252008-11-04 01:38:02 +0000451 <para>Locations may be names of either shared objects or
452 functions. They begin
debad57fc2005-12-03 22:33:29 +0000453 <computeroutput>obj:</computeroutput> and
454 <computeroutput>fun:</computeroutput> respectively. Function and
455 object names to match against may use the wildcard characters
456 <computeroutput>*</computeroutput> and
457 <computeroutput>?</computeroutput>.</para>
njn3e986b22004-11-30 10:43:45 +0000458
debad57fc2005-12-03 22:33:29 +0000459 <para><command>Important note: </command> C++ function names must be
460 <command>mangled</command>. If you are writing suppressions by
461 hand, use the <option>--demangle=no</option> option to get the
sewardj66293252008-11-04 01:38:02 +0000462 mangled names in your error messages. An example of a mangled
463 C++ name is <computeroutput>_ZN9QListView4showEv</computeroutput>.
464 This is the form that the GNU C++ compiler uses internally, and
465 the form that must be used in suppression files. The equivalent
466 demangled name, <computeroutput>QListView::show()</computeroutput>,
467 is what you see at the C++ source code level.
468 </para>
469
470 <para>A location line may also be
471 simply "<computeroutput>...</computeroutput>" (three dots). This is
472 a frame-level wildcard, which matches zero or more frames. Frame
473 level wildcards are useful because they make it easy to ignore
474 varying numbers of uninteresting frames in between frames of
475 interest. That is often important when writing suppressions which
476 are intended to be robust against variations in the amount of
477 function inlining done by compilers.</para>
njn3e986b22004-11-30 10:43:45 +0000478 </listitem>
479
480 <listitem>
debad57fc2005-12-03 22:33:29 +0000481 <para>Finally, the entire suppression must be between curly
482 braces. Each brace must be the first character on its own
483 line.</para>
njn3e986b22004-11-30 10:43:45 +0000484 </listitem>
485
486 </itemizedlist>
487
debad57fc2005-12-03 22:33:29 +0000488<para>A suppression only suppresses an error when the error matches all
489the details in the suppression. Here's an example:</para>
njn3e986b22004-11-30 10:43:45 +0000490
491<programlisting><![CDATA[
492{
493 __gconv_transform_ascii_internal/__mbrtowc/mbtowc
494 Memcheck:Value4
495 fun:__gconv_transform_ascii_internal
496 fun:__mbr*toc
497 fun:mbtowc
498}]]></programlisting>
499
500
501<para>What it means is: for Memcheck only, suppress a
debad57fc2005-12-03 22:33:29 +0000502use-of-uninitialised-value error, when the data size is 4, when it
503occurs in the function
504<computeroutput>__gconv_transform_ascii_internal</computeroutput>, when
505that is called from any function of name matching
506<computeroutput>__mbr*toc</computeroutput>, when that is called from
507<computeroutput>mbtowc</computeroutput>. It doesn't apply under any
508other circumstances. The string by which this suppression is identified
509to the user is
njn3e986b22004-11-30 10:43:45 +0000510<computeroutput>__gconv_transform_ascii_internal/__mbrtowc/mbtowc</computeroutput>.</para>
511
512<para>(See <xref linkend="mc-manual.suppfiles"/> for more details
513on the specifics of Memcheck's suppression kinds.)</para>
514
515<para>Another example, again for the Memcheck tool:</para>
516
517<programlisting><![CDATA[
518{
519 libX11.so.6.2/libX11.so.6.2/libXaw.so.7.0
520 Memcheck:Value4
521 obj:/usr/X11R6/lib/libX11.so.6.2
522 obj:/usr/X11R6/lib/libX11.so.6.2
523 obj:/usr/X11R6/lib/libXaw.so.7.0
524}]]></programlisting>
525
sewardj66293252008-11-04 01:38:02 +0000526<para>This suppresses any size 4 uninitialised-value error which occurs
debad57fc2005-12-03 22:33:29 +0000527anywhere in <filename>libX11.so.6.2</filename>, when called from
528anywhere in the same library, when called from anywhere in
529<filename>libXaw.so.7.0</filename>. The inexact specification of
530locations is regrettable, but is about all you can hope for, given that
sewardj08e31e22007-05-23 21:58:33 +0000531the X11 libraries shipped on the Linux distro on which this example
532was made have had their symbol tables removed.</para>
njn3e986b22004-11-30 10:43:45 +0000533
sewardj08e31e22007-05-23 21:58:33 +0000534<para>Although the above two examples do not make this clear, you can
535freely mix <computeroutput>obj:</computeroutput> and
536<computeroutput>fun:</computeroutput> lines in a suppression.</para>
njn3e986b22004-11-30 10:43:45 +0000537
sewardj66293252008-11-04 01:38:02 +0000538<para>Finally, here's an example using three frame-level wildcards:</para>
539
540<programlisting><![CDATA[
541{
542 a-contrived-example
543 Memcheck:Leak
544 fun:malloc
545 ...
546 fun:ddd
547 ...
548 fun:ccc
549 ...
550 fun:main
551}
552]]></programlisting>
553This suppresses Memcheck memory-leak errors, in the case where
554the allocation was done by <computeroutput>main</computeroutput>
555calling (though any number of intermediaries, including zero)
556<computeroutput>ccc</computeroutput>,
557calling onwards via
558<computeroutput>ddd</computeroutput> and eventually
559to <computeroutput>malloc.</computeroutput>.
njn3e986b22004-11-30 10:43:45 +0000560</sect1>
561
562
njnf4b47582009-08-10 01:15:30 +0000563<sect1 id="manual-core.options"
564 xreflabel="Core Command-line Options">
565<title>Core Command-line Options</title>
njn3e986b22004-11-30 10:43:45 +0000566
njnf4b47582009-08-10 01:15:30 +0000567<para>As mentioned above, Valgrind's core accepts a common set of options.
568The tools also accept tool-specific options, which are documented
sewardj33878892007-11-17 09:43:25 +0000569separately for each tool.</para>
njn3e986b22004-11-30 10:43:45 +0000570
debad57fc2005-12-03 22:33:29 +0000571<para>Valgrind's default settings succeed in giving reasonable behaviour
njn7316df22009-08-04 01:16:01 +0000572in most cases. We group the available options by rough categories.</para>
njn3e986b22004-11-30 10:43:45 +0000573
njnf4b47582009-08-10 01:15:30 +0000574<sect2 id="manual-core.toolopts" xreflabel="Tool-selection Option">
575<title>Tool-selection Option</title>
njn3e986b22004-11-30 10:43:45 +0000576
tom0e1b0c22011-08-15 08:20:53 +0000577<para id="tool.opts.para">The single most important option.</para>
debad57fc2005-12-03 22:33:29 +0000578
tom0e1b0c22011-08-15 08:20:53 +0000579<variablelist id="tool.opts.list">
sewardj6ea37fe2009-07-15 14:52:52 +0000580
581 <varlistentry id="tool_name" xreflabel="--tool">
582 <term>
njn7316df22009-08-04 01:16:01 +0000583 <option><![CDATA[--tool=<toolname> [default: memcheck] ]]></option>
sewardj6ea37fe2009-07-15 14:52:52 +0000584 </term>
585 <listitem>
njn7316df22009-08-04 01:16:01 +0000586 <para>Run the Valgrind tool called <varname>toolname</varname>,
sewardj6ea37fe2009-07-15 14:52:52 +0000587 e.g. Memcheck, Cachegrind, etc.</para>
588 </listitem>
589 </varlistentry>
590
591</variablelist>
debad57fc2005-12-03 22:33:29 +0000592
njn3e986b22004-11-30 10:43:45 +0000593</sect2>
594
debad57fc2005-12-03 22:33:29 +0000595
596
njn3e986b22004-11-30 10:43:45 +0000597<sect2 id="manual-core.basicopts" xreflabel="Basic Options">
598<title>Basic Options</title>
599
de03e0e7c2005-12-03 23:02:33 +0000600<!-- start of xi:include in the manpage -->
601<para id="basic.opts.para">These options work with all tools.</para>
njn3e986b22004-11-30 10:43:45 +0000602
de03e0e7c2005-12-03 23:02:33 +0000603<variablelist id="basic.opts.list">
njn3e986b22004-11-30 10:43:45 +0000604
debad57fc2005-12-03 22:33:29 +0000605 <varlistentry id="opt.help" xreflabel="--help">
606 <term><option>-h --help</option></term>
607 <listitem>
608 <para>Show help for all options, both for the core and for the
njncce38e62010-07-06 04:25:12 +0000609 selected tool. If the option is repeated it is equivalent to giving
610 <option>--help-debug</option>.</para>
debad57fc2005-12-03 22:33:29 +0000611 </listitem>
612 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000613
debad57fc2005-12-03 22:33:29 +0000614 <varlistentry id="opt.help-debug" xreflabel="--help-debug">
615 <term><option>--help-debug</option></term>
616 <listitem>
617 <para>Same as <option>--help</option>, but also lists debugging
618 options which usually are only of use to Valgrind's
619 developers.</para>
620 </listitem>
621 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000622
debad57fc2005-12-03 22:33:29 +0000623 <varlistentry id="opt.version" xreflabel="--version">
624 <term><option>--version</option></term>
625 <listitem>
626 <para>Show the version number of the Valgrind core. Tools can have
627 their own version numbers. There is a scheme in place to ensure
628 that tools only execute when the core version is one they are
629 known to work with. This was done to minimise the chances of
630 strange problems arising from tool-vs-core version
631 incompatibilities.</para>
632 </listitem>
633 </varlistentry>
njn51272982005-07-25 23:18:44 +0000634
debad57fc2005-12-03 22:33:29 +0000635 <varlistentry id="opt.quiet" xreflabel="--quiet">
njn7e5d4ed2009-07-30 02:57:52 +0000636 <term><option>-q</option>, <option>--quiet</option></term>
debad57fc2005-12-03 22:33:29 +0000637 <listitem>
638 <para>Run silently, and only print error messages. Useful if you
639 are running regression tests or have some other automated test
640 machinery.</para>
641 </listitem>
642 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000643
debad57fc2005-12-03 22:33:29 +0000644 <varlistentry id="opt.verbose" xreflabel="--verbose">
njn7e5d4ed2009-07-30 02:57:52 +0000645 <term><option>-v</option>, <option>--verbose</option></term>
debad57fc2005-12-03 22:33:29 +0000646 <listitem>
647 <para>Be more verbose. Gives extra information on various aspects
648 of your program, such as: the shared objects loaded, the
649 suppressions used, the progress of the instrumentation and
650 execution engines, and warnings about unusual behaviour. Repeating
njnf4b47582009-08-10 01:15:30 +0000651 the option increases the verbosity level.</para>
debad57fc2005-12-03 22:33:29 +0000652 </listitem>
653 </varlistentry>
sewardj053fe982005-11-15 19:51:04 +0000654
debad57fc2005-12-03 22:33:29 +0000655 <varlistentry id="opt.trace-children" xreflabel="--trace-children">
656 <term>
657 <option><![CDATA[--trace-children=<yes|no> [default: no] ]]></option>
658 </term>
659 <listitem>
njnae44c382007-05-15 03:59:23 +0000660 <para>When enabled, Valgrind will trace into sub-processes
njn7316df22009-08-04 01:16:01 +0000661 initiated via the <varname>exec</varname> system call. This is
662 necessary for multi-process programs.
njnae44c382007-05-15 03:59:23 +0000663 </para>
664 <para>Note that Valgrind does trace into the child of a
sewardj79c62bc2007-11-28 01:55:29 +0000665 <varname>fork</varname> (it would be difficult not to, since
njnae44c382007-05-15 03:59:23 +0000666 <varname>fork</varname> makes an identical copy of a process), so this
667 option is arguably badly named. However, most children of
668 <varname>fork</varname> calls immediately call <varname>exec</varname>
669 anyway.
670 </para>
debad57fc2005-12-03 22:33:29 +0000671 </listitem>
672 </varlistentry>
njn51272982005-07-25 23:18:44 +0000673
sewardj06421272009-11-05 08:55:13 +0000674 <varlistentry id="opt.trace-children-skip" xreflabel="--trace-children-skip">
675 <term>
sewardj9ab64a42010-12-06 11:40:04 +0000676 <option><![CDATA[--trace-children-skip=patt1,patt2,... ]]></option>
sewardj06421272009-11-05 08:55:13 +0000677 </term>
678 <listitem>
679 <para>This option only has an effect when
680 <option>--trace-children=yes</option> is specified. It allows
681 for some children to be skipped. The option takes a comma
682 separated list of patterns for the names of child executables
683 that Valgrind should not trace into. Patterns may include the
684 metacharacters <computeroutput>?</computeroutput>
685 and <computeroutput>*</computeroutput>, which have the usual
686 meaning.</para>
687 <para>
688 This can be useful for pruning uninteresting branches from a
689 tree of processes being run on Valgrind. But you should be
690 careful when using it. When Valgrind skips tracing into an
691 executable, it doesn't just skip tracing that executable, it
692 also skips tracing any of that executable's child processes.
693 In other words, the flag doesn't merely cause tracing to stop
694 at the specified executables -- it skips tracing of entire
695 process subtrees rooted at any of the specified
696 executables.</para>
697 </listitem>
698 </varlistentry>
699
sewardj9ab64a42010-12-06 11:40:04 +0000700 <varlistentry id="opt.trace-children-skip-by-arg"
701 xreflabel="--trace-children-skip-by-arg">
702 <term>
703 <option><![CDATA[--trace-children-skip-by-arg=patt1,patt2,... ]]></option>
704 </term>
705 <listitem>
706 <para>This is the same as
707 <option>--trace-children-skip</option>, with one difference:
708 the decision as to whether to trace into a child process is
709 made by examining the arguments to the child process, rather
710 than the name of its executable.</para>
711 </listitem>
712 </varlistentry>
713
sewardj778d7832007-11-22 01:21:56 +0000714 <varlistentry id="opt.child-silent-after-fork"
715 xreflabel="--child-silent-after-fork">
716 <term>
717 <option><![CDATA[--child-silent-after-fork=<yes|no> [default: no] ]]></option>
718 </term>
719 <listitem>
720 <para>When enabled, Valgrind will not show any debugging or
721 logging output for the child process resulting from
722 a <varname>fork</varname> call. This can make the output less
723 confusing (although more misleading) when dealing with processes
724 that create children. It is particularly useful in conjunction
njnf4b47582009-08-10 01:15:30 +0000725 with <varname>--trace-children=</varname>. Use of this option is also
sewardj778d7832007-11-22 01:21:56 +0000726 strongly recommended if you are requesting XML output
727 (<varname>--xml=yes</varname>), since otherwise the XML from child and
728 parent may become mixed up, which usually makes it useless.
729 </para>
730 </listitem>
731 </varlistentry>
732
sewardj3b290482011-05-06 21:02:55 +0000733 <varlistentry id="opt.vgdb" xreflabel="--vgdb">
734 <term>
735 <option><![CDATA[--vgdb=<no|yes|full> [default: yes] ]]></option>
736 </term>
737 <listitem>
philippe0d366ad2012-03-05 22:09:20 +0000738
sewardj995c67f2011-06-17 08:14:00 +0000739 <para>Valgrind will provide "gdbserver" functionality when
philippe0d366ad2012-03-05 22:09:20 +0000740 <option>--vgdb=yes</option> or <option>--vgdb=full</option> is
741 specified. This allows an external GNU GDB debugger to control
742 and debug your program when it runs on Valgrind.
743 <option>--vgdb=full</option> incurs significant performance
744 overheads, but provides more precise breakpoints and
745 watchpoints. See <xref linkend="manual-core-adv.gdbserver"/> for
746 a detailed description.
sewardj3b290482011-05-06 21:02:55 +0000747 </para>
748
749 <para> If the embedded gdbserver is enabled but no gdb is
sewardj350c0fe2011-06-17 08:31:22 +0000750 currently being used, the <xref linkend="manual-core-adv.vgdb"/>
sewardj3b290482011-05-06 21:02:55 +0000751 command line utility can send "monitor commands" to Valgrind
752 from a shell. The Valgrind core provides a set of
sewardj350c0fe2011-06-17 08:31:22 +0000753 <xref linkend="manual-core-adv.valgrind-monitor-commands"/>. A tool
sewardj3b290482011-05-06 21:02:55 +0000754 can optionally provide tool specific monitor commands, which are
755 documented in the tool specific chapter.
756 </para>
757
sewardj3b290482011-05-06 21:02:55 +0000758 </listitem>
759 </varlistentry>
760
761 <varlistentry id="opt.vgdb-error" xreflabel="--vgdb-error">
762 <term>
763 <option><![CDATA[--vgdb-error=<number> [default: 999999999] ]]></option>
764 </term>
765 <listitem>
766 <para> Use this option when the Valgrind gdbserver is enabled with
sewardj995c67f2011-06-17 08:14:00 +0000767 <option>--vgdb=yes</option> or <option>--vgdb=full</option>.
768 Tools that report errors will wait
769 for "<computeroutput>number</computeroutput>" errors to be
770 reported before freezing the program and waiting for you to
771 connect with GDB. It follows that a value of zero will cause
772 the gdbserver to be started before your program is executed.
773 This is typically used to insert GDB breakpoints before
774 execution, and also works with tools that do not report
775 errors, such as Massif.
sewardj3b290482011-05-06 21:02:55 +0000776 </para>
777 </listitem>
778 </varlistentry>
779
philippe180a7502014-04-20 13:41:10 +0000780 <varlistentry id="opt.vgdb-stop-at" xreflabel="--vgdb-stop-at">
781 <term>
782 <option><![CDATA[--vgdb-stop-at=<set> [default: none] ]]></option>
783 </term>
784 <listitem>
785 <para> Use this option when the Valgrind gdbserver is enabled with
786 <option>--vgdb=yes</option> or <option>--vgdb=full</option>.
787 The Valgrind gdbserver will be invoked for each error after
788 <option>--vgdb-error</option> have been reported.
789 You can additionally ask the Valgrind gdbserver to be invoked
790 for other events, specified in one of the following ways: </para>
791 <itemizedlist>
792 <listitem><para>a comma separated list of one or more of
793 <option>startup exit valgrindabexit</option>.</para>
794
795 <para>The values <option>startup</option> <option>exit</option>
796 <option>valgrindabexit</option> respectively indicate to
797 invoke gdbserver before your program is executed, after the
798 last instruction of your program, on Valgrind abnormal exit
799 (e.g. internal error, out of memory, ...).</para>
800
801 <para>Note: <option>startup</option> and
802 <option>--vgdb-error=0</option> will both cause Valgrind
803 gdbserver to be invoked before your program is executed. The
804 <option>--vgdb-error=0</option> will in addition cause your
805 program to stop on all subsequent errors.</para>
806
807 </listitem>
808
809 <listitem><para><option>all</option> to specify the complete set.
810 It is equivalent to
811 <option>--vgdb-stop-at=startup,exit,valgrindabexit</option>.</para>
812 </listitem>
813
814 <listitem><para><option>none</option> for the empty set.</para>
815 </listitem>
816 </itemizedlist>
817 </listitem>
818 </varlistentry>
819
debad57fc2005-12-03 22:33:29 +0000820 <varlistentry id="opt.track-fds" xreflabel="--track-fds">
821 <term>
822 <option><![CDATA[--track-fds=<yes|no> [default: no] ]]></option>
823 </term>
824 <listitem>
825 <para>When enabled, Valgrind will print out a list of open file
philippec3360382012-10-21 14:37:14 +0000826 descriptors on exit or on request, via the gdbserver monitor
827 command <varname>v.info open_fds</varname>. Along with each
828 file descriptor is printed a stack backtrace of where the file
829 was opened and any details relating to the file descriptor such
830 as the file name or socket details.</para>
debad57fc2005-12-03 22:33:29 +0000831 </listitem>
832 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000833
debad57fc2005-12-03 22:33:29 +0000834 <varlistentry id="opt.time-stamp" xreflabel="--time-stamp">
835 <term>
836 <option><![CDATA[--time-stamp=<yes|no> [default: no] ]]></option>
837 </term>
838 <listitem>
839 <para>When enabled, each message is preceded with an indication of
840 the elapsed wallclock time since startup, expressed as days,
841 hours, minutes, seconds and milliseconds.</para>
842 </listitem>
843 </varlistentry>
njn3e986b22004-11-30 10:43:45 +0000844
debad57fc2005-12-03 22:33:29 +0000845 <varlistentry id="opt.log-fd" xreflabel="--log-fd">
846 <term>
847 <option><![CDATA[--log-fd=<number> [default: 2, stderr] ]]></option>
848 </term>
849 <listitem>
850 <para>Specifies that Valgrind should send all of its messages to
851 the specified file descriptor. The default, 2, is the standard
852 error channel (stderr). Note that this may interfere with the
853 client's own use of stderr, as Valgrind's output will be
854 interleaved with any output that the client sends to
855 stderr.</para>
856 </listitem>
857 </varlistentry>
njn779a2d62005-07-25 00:12:19 +0000858
debad57fc2005-12-03 22:33:29 +0000859 <varlistentry id="opt.log-file" xreflabel="--log-file">
860 <term>
861 <option><![CDATA[--log-file=<filename> ]]></option>
862 </term>
863 <listitem>
864 <para>Specifies that Valgrind should send all of its messages to
njn374a36d2007-11-23 01:41:32 +0000865 the specified file. If the file name is empty, it causes an abort.
866 There are three special format specifiers that can be used in the file
867 name.</para>
njn779a2d62005-07-25 00:12:19 +0000868
njn374a36d2007-11-23 01:41:32 +0000869 <para><option>%p</option> is replaced with the current process ID.
870 This is very useful for program that invoke multiple processes.
871 WARNING: If you use <option>--trace-children=yes</option> and your
njn7064fb22008-05-29 23:09:52 +0000872 program invokes multiple processes OR your program forks without
873 calling exec afterwards, and you don't use this specifier
njn374a36d2007-11-23 01:41:32 +0000874 (or the <option>%q</option> specifier below), the Valgrind output from
875 all those processes will go into one file, possibly jumbled up, and
njn498685c2007-09-17 23:15:35 +0000876 possibly incomplete.</para>
njn3e986b22004-11-30 10:43:45 +0000877
njn374a36d2007-11-23 01:41:32 +0000878 <para><option>%q{FOO}</option> is replaced with the contents of the
879 environment variable <varname>FOO</varname>. If the
880 <option>{FOO}</option> part is malformed, it causes an abort. This
881 specifier is rarely needed, but very useful in certain circumstances
882 (eg. when running MPI programs). The idea is that you specify a
883 variable which will be set differently for each process in the job,
884 for example <computeroutput>BPROC_RANK</computeroutput> or whatever is
885 applicable in your MPI setup. If the named environment variable is not
886 set, it causes an abort. Note that in some shells, the
887 <option>{</option> and <option>}</option> characters may need to be
888 escaped with a backslash.</para>
889
890 <para><option>%%</option> is replaced with <option>%</option>.</para>
891
892 <para>If an <option>%</option> is followed by any other character, it
893 causes an abort.</para>
debad57fc2005-12-03 22:33:29 +0000894 </listitem>
895 </varlistentry>
896
897 <varlistentry id="opt.log-socket" xreflabel="--log-socket">
898 <term>
899 <option><![CDATA[--log-socket=<ip-address:port-number> ]]></option>
900 </term>
901 <listitem>
902 <para>Specifies that Valgrind should send all of its messages to
903 the specified port at the specified IP address. The port may be
904 omitted, in which case port 1500 is used. If a connection cannot
905 be made to the specified socket, Valgrind falls back to writing
906 output to the standard error (stderr). This option is intended to
907 be used in conjunction with the
908 <computeroutput>valgrind-listener</computeroutput> program. For
909 further details, see
philippea02e2672013-03-06 22:39:18 +0000910 <link linkend="&vg-comment-id;">the commentary</link>
debad57fc2005-12-03 22:33:29 +0000911 in the manual.</para>
912 </listitem>
913 </varlistentry>
914
915</variablelist>
de03e0e7c2005-12-03 23:02:33 +0000916<!-- end of xi:include in the manpage -->
debad57fc2005-12-03 22:33:29 +0000917
918</sect2>
njn3e986b22004-11-30 10:43:45 +0000919
920
921<sect2 id="manual-core.erropts" xreflabel="Error-related Options">
njnf4b47582009-08-10 01:15:30 +0000922<title>Error-related Options</title>
njn3e986b22004-11-30 10:43:45 +0000923
de03e0e7c2005-12-03 23:02:33 +0000924<!-- start of xi:include in the manpage -->
925<para id="error-related.opts.para">These options are used by all tools
926that can report errors, e.g. Memcheck, but not Cachegrind.</para>
njn3e986b22004-11-30 10:43:45 +0000927
de03e0e7c2005-12-03 23:02:33 +0000928<variablelist id="error-related.opts.list">
njn3e986b22004-11-30 10:43:45 +0000929
debad57fc2005-12-03 22:33:29 +0000930 <varlistentry id="opt.xml" xreflabel="--xml">
931 <term>
932 <option><![CDATA[--xml=<yes|no> [default: no] ]]></option>
933 </term>
934 <listitem>
njn7316df22009-08-04 01:16:01 +0000935 <para>When enabled, the important parts of the output (e.g. tool error
936 messages) will be in XML format rather than plain text. Furthermore,
937 the XML output will be sent to a different output channel than the
938 plain text output. Therefore, you also must use one of
939 <option>--xml-fd</option>, <option>--xml-file</option> or
940 <option>--xml-socket</option> to specify where the XML is to be sent.
941 </para>
942
943 <para>Less important messages will still be printed in plain text, but
944 because the XML output and plain text output are sent to different
945 output channels (the destination of the plain text output is still
946 controlled by <option>--log-fd</option>, <option>--log-file</option>
947 and <option>--log-socket</option>) this should not cause problems.
948 </para>
949
950 <para>This option is aimed at making life easier for tools that consume
951 Valgrind's output as input, such as GUI front ends. Currently this
bartc8798592011-10-14 18:06:41 +0000952 option works with Memcheck, Helgrind, DRD and SGcheck. The output
953 format is specified in the file
sewardj6ea37fe2009-07-15 14:52:52 +0000954 <computeroutput>docs/internals/xml-output-protocol4.txt</computeroutput>
955 in the source tree for Valgrind 3.5.0 or later.</para>
njn7316df22009-08-04 01:16:01 +0000956
njnf4b47582009-08-10 01:15:30 +0000957 <para>The recommended options for a GUI to pass, when requesting
njn7316df22009-08-04 01:16:01 +0000958 XML output, are: <option>--xml=yes</option> to enable XML output,
959 <option>--xml-file</option> to send the XML output to a (presumably
960 GUI-selected) file, <option>--log-file</option> to send the plain
961 text output to a second GUI-selected file,
962 <option>--child-silent-after-fork=yes</option>, and
963 <option>-q</option> to restrict the plain text output to critical
964 error messages created by Valgrind itself. For example, failure to
965 read a specified suppressions file counts as a critical error message.
966 In this way, for a successful run the text output file will be empty.
967 But if it isn't empty, then it will contain important information
968 which the GUI user should be made aware
969 of.</para>
sewardj6ea37fe2009-07-15 14:52:52 +0000970 </listitem>
971 </varlistentry>
972
sewardj6ea37fe2009-07-15 14:52:52 +0000973 <varlistentry id="opt.xml-fd" xreflabel="--xml-fd">
974 <term>
975 <option><![CDATA[--xml-fd=<number> [default: -1, disabled] ]]></option>
976 </term>
977 <listitem>
978 <para>Specifies that Valgrind should send its XML output to the
njn7316df22009-08-04 01:16:01 +0000979 specified file descriptor. It must be used in conjunction with
980 <option>--xml=yes</option>.</para>
sewardj6ea37fe2009-07-15 14:52:52 +0000981 </listitem>
982 </varlistentry>
983
984 <varlistentry id="opt.xml-file" xreflabel="--xml-file">
985 <term>
986 <option><![CDATA[--xml-file=<filename> ]]></option>
987 </term>
988 <listitem>
989 <para>Specifies that Valgrind should send its XML output
njn7316df22009-08-04 01:16:01 +0000990 to the specified file. It must be used in conjunction with
991 <option>--xml=yes</option>. Any <option>%p</option> or
992 <option>%q</option> sequences appearing in the filename are expanded
993 in exactly the same way as they are for <option>--log-file</option>.
994 See the description of <option>--log-file</option> for details.
sewardj6ea37fe2009-07-15 14:52:52 +0000995 </para>
996 </listitem>
997 </varlistentry>
998
999 <varlistentry id="opt.xml-socket" xreflabel="--xml-socket">
1000 <term>
1001 <option><![CDATA[--xml-socket=<ip-address:port-number> ]]></option>
1002 </term>
1003 <listitem>
1004 <para>Specifies that Valgrind should send its XML output the
njn7316df22009-08-04 01:16:01 +00001005 specified port at the specified IP address. It must be used in
1006 conjunction with <option>--xml=yes</option>. The form of the argument
1007 is the same as that used by <option>--log-socket</option>.
1008 See the description of <option>--log-socket</option>
sewardj6ea37fe2009-07-15 14:52:52 +00001009 for further details.</para>
debad57fc2005-12-03 22:33:29 +00001010 </listitem>
1011 </varlistentry>
njn3e986b22004-11-30 10:43:45 +00001012
debad57fc2005-12-03 22:33:29 +00001013 <varlistentry id="opt.xml-user-comment" xreflabel="--xml-user-comment">
1014 <term>
1015 <option><![CDATA[--xml-user-comment=<string> ]]></option>
1016 </term>
1017 <listitem>
1018 <para>Embeds an extra user comment string at the start of the XML
1019 output. Only works when <option>--xml=yes</option> is specified;
1020 ignored otherwise.</para>
1021 </listitem>
1022 </varlistentry>
njn3e986b22004-11-30 10:43:45 +00001023
debad57fc2005-12-03 22:33:29 +00001024 <varlistentry id="opt.demangle" xreflabel="--demangle">
1025 <term>
1026 <option><![CDATA[--demangle=<yes|no> [default: yes] ]]></option>
1027 </term>
1028 <listitem>
1029 <para>Enable/disable automatic demangling (decoding) of C++ names.
1030 Enabled by default. When enabled, Valgrind will attempt to
1031 translate encoded C++ names back to something approaching the
1032 original. The demangler handles symbols mangled by g++ versions
1033 2.X, 3.X and 4.X.</para>
njn3e986b22004-11-30 10:43:45 +00001034
debad57fc2005-12-03 22:33:29 +00001035 <para>An important fact about demangling is that function names
1036 mentioned in suppressions files should be in their mangled form.
1037 Valgrind does not demangle function names when searching for
1038 applicable suppressions, because to do otherwise would make
njn7316df22009-08-04 01:16:01 +00001039 suppression file contents dependent on the state of Valgrind's
1040 demangling machinery, and also slow down suppression matching.</para>
debad57fc2005-12-03 22:33:29 +00001041 </listitem>
1042 </varlistentry>
njn3e986b22004-11-30 10:43:45 +00001043
debad57fc2005-12-03 22:33:29 +00001044 <varlistentry id="opt.num-callers" xreflabel="--num-callers">
1045 <term>
1046 <option><![CDATA[--num-callers=<number> [default: 12] ]]></option>
1047 </term>
1048 <listitem>
njn7316df22009-08-04 01:16:01 +00001049 <para>Specifies the maximum number of entries shown in stack traces
1050 that identify program locations. Note that errors are commoned up
1051 using only the top four function locations (the place in the current
1052 function, and that of its three immediate callers). So this doesn't
1053 affect the total number of errors reported.</para>
njn3e986b22004-11-30 10:43:45 +00001054
florian7711f9e2012-06-29 21:20:52 +00001055 <para>The maximum value for this is 500. Note that higher settings
debad57fc2005-12-03 22:33:29 +00001056 will make Valgrind run a bit more slowly and take a bit more
1057 memory, but can be useful when working with programs with
1058 deeply-nested call chains.</para>
1059 </listitem>
1060 </varlistentry>
njn3e986b22004-11-30 10:43:45 +00001061
sewardj4c7254d2013-11-29 23:08:28 +00001062 <varlistentry id="opt.unw-stack-scan-thresh"
1063 xreflabel="--unw-stack-scan-thresh">
1064 <term>
1065 <option><![CDATA[--unw-stack-scan-thresh=<number> [default: 0] ]]></option>
1066 </term>
1067 <term>
1068 <option><![CDATA[--unw-stack-scan-frames=<number> [default: 5] ]]></option>
1069 </term>
1070 <listitem>
1071 <para>Stack-scanning support is available only on ARM
1072 targets.</para>
1073
1074 <para>These flags enable and control stack unwinding by stack
1075 scanning. When the normal stack unwinding mechanisms -- usage
1076 of Dwarf CFI records, and frame-pointer following -- fail, stack
1077 scanning may be able to recover a stack trace.</para>
1078
1079 <para>Note that stack scanning is an imprecise, heuristic
1080 mechanism that may give very misleading results, or none at all.
1081 It should be used only in emergencies, when normal unwinding
1082 fails, and it is important to nevertheless have stack
1083 traces.</para>
1084
1085 <para>Stack scanning is a simple technique: the unwinder reads
1086 words from the stack, and tries to guess which of them might be
1087 return addresses, by checking to see if they point just after
1088 ARM or Thumb call instructions. If so, the word is added to the
1089 backtrace.</para>
1090
1091 <para>The main danger occurs when a function call returns,
1092 leaving its return address exposed, and a new function is
1093 called, but the new function does not overwrite the old address.
1094 The result of this is that the backtrace may contain entries for
1095 functions which have already returned, and so be very
1096 confusing.</para>
1097
1098 <para>A second limitation of this implementation is that it will
1099 scan only the page (4KB, normally) containing the starting stack
1100 pointer. If the stack frames are large, this may result in only
1101 a few (or not even any) being present in the trace. Also, if
1102 you are unlucky and have an initial stack pointer near the end
1103 of its containing page, the scan may miss all interesting
1104 frames.</para>
1105
1106 <para>By default stack scanning is disabled. The normal use
1107 case is to ask for it when a stack trace would otherwise be very
1108 short. So, to enable it,
1109 use <computeroutput>--unw-stack-scan-thresh=number</computeroutput>.
1110 This requests Valgrind to try using stack scanning to "extend"
1111 stack traces which contain fewer
1112 than <computeroutput>number</computeroutput> frames.</para>
1113
1114 <para>If stack scanning does take place, it will only generate
1115 at most the number of frames specified
1116 by <computeroutput>--unw-stack-scan-frames</computeroutput>.
1117 Typically, stack scanning generates so many garbage entries that
1118 this value is set to a low value (5) by default. In no case
1119 will a stack trace larger than the value specified
1120 by <computeroutput>--num-callers</computeroutput> be
1121 created.</para>
1122 </listitem>
1123 </varlistentry>
1124
debad57fc2005-12-03 22:33:29 +00001125 <varlistentry id="opt.error-limit" xreflabel="--error-limit">
1126 <term>
1127 <option><![CDATA[--error-limit=<yes|no> [default: yes] ]]></option>
1128 </term>
1129 <listitem>
sewardj58501082006-05-12 23:35:10 +00001130 <para>When enabled, Valgrind stops reporting errors after 10,000,000
debad57fc2005-12-03 22:33:29 +00001131 in total, or 1,000 different ones, have been seen. This is to
1132 stop the error tracking machinery from becoming a huge performance
1133 overhead in programs with many errors.</para>
1134 </listitem>
1135 </varlistentry>
njn3e986b22004-11-30 10:43:45 +00001136
sewardjb9779082006-05-12 23:50:15 +00001137 <varlistentry id="opt.error-exitcode" xreflabel="--error-exitcode">
1138 <term>
1139 <option><![CDATA[--error-exitcode=<number> [default: 0] ]]></option>
1140 </term>
1141 <listitem>
1142 <para>Specifies an alternative exit code to return if Valgrind
1143 reported any errors in the run. When set to the default value
1144 (zero), the return value from Valgrind will always be the return
1145 value of the process being simulated. When set to a nonzero value,
1146 that value is returned instead, if Valgrind detects any errors.
1147 This is useful for using Valgrind as part of an automated test
1148 suite, since it makes it easy to detect test cases for which
1149 Valgrind has reported errors, just by inspecting return codes.</para>
1150 </listitem>
1151 </varlistentry>
1152
sewardjc30cd9b2012-12-06 18:08:54 +00001153 <varlistentry id="opt.sigill-diagnostics" xreflabel="--sigill-diagnostics">
1154 <term>
1155 <option><![CDATA[--sigill-diagnostics=<yes|no> [default: yes] ]]></option>
1156 </term>
1157 <listitem>
1158 <para>Enable/disable printing of illegal instruction diagnostics.
1159 Enabled by default, but defaults to disabled when
1160 <option>--quiet</option> is given. The default can always be explicitly
1161 overridden by giving this option.</para>
1162
sewardj4c7254d2013-11-29 23:08:28 +00001163 <para>When enabled, a warning message will be printed, along with some
1164 diagnostics, whenever an instruction is encountered that Valgrind
1165 cannot decode or translate, before the program is given a SIGILL signal.
sewardjc30cd9b2012-12-06 18:08:54 +00001166 Often an illegal instruction indicates a bug in the program or missing
sewardj4c7254d2013-11-29 23:08:28 +00001167 support for the particular instruction in Valgrind. But some programs
sewardjc30cd9b2012-12-06 18:08:54 +00001168 do deliberately try to execute an instruction that might be missing
sewardj4c7254d2013-11-29 23:08:28 +00001169 and trap the SIGILL signal to detect processor features. Using
1170 this flag makes it possible to avoid the diagnostic output
1171 that you would otherwise get in such cases.</para>
sewardjc30cd9b2012-12-06 18:08:54 +00001172 </listitem>
1173 </varlistentry>
1174
sewardj4c7254d2013-11-29 23:08:28 +00001175 <varlistentry id="opt.show-below-main" xreflabel="--show-below-main">
debad57fc2005-12-03 22:33:29 +00001176 <term>
1177 <option><![CDATA[--show-below-main=<yes|no> [default: no] ]]></option>
1178 </term>
1179 <listitem>
1180 <para>By default, stack traces for errors do not show any
njn7316df22009-08-04 01:16:01 +00001181 functions that appear beneath <function>main</function> because
njn68824432009-02-10 06:48:00 +00001182 most of the time it's uninteresting C library stuff and/or
njn7316df22009-08-04 01:16:01 +00001183 gobbledygook. Alternatively, if <function>main</function> is not
njn68824432009-02-10 06:48:00 +00001184 present in the stack trace, stack traces will not show any functions
njn7316df22009-08-04 01:16:01 +00001185 below <function>main</function>-like functions such as glibc's
1186 <function>__libc_start_main</function>. Furthermore, if
1187 <function>main</function>-like functions are present in the trace,
1188 they are normalised as <function>(below main)</function>, in order to
1189 make the output more deterministic.</para>
njn68824432009-02-10 06:48:00 +00001190
1191 <para>If this option is enabled, all stack trace entries will be
njn7316df22009-08-04 01:16:01 +00001192 shown and <function>main</function>-like functions will not be
njn68824432009-02-10 06:48:00 +00001193 normalised.</para>
debad57fc2005-12-03 22:33:29 +00001194 </listitem>
1195 </varlistentry>
sewardjd153fae2005-01-10 17:24:47 +00001196
sewardj14cdbf82010-10-12 00:44:05 +00001197 <varlistentry id="opt.fullpath-after" xreflabel="--fullpath-after">
bart5dd01902010-08-31 15:18:32 +00001198 <term>
sewardj14cdbf82010-10-12 00:44:05 +00001199 <option><![CDATA[--fullpath-after=<string>
1200 [default: don't show source paths] ]]></option>
bart5dd01902010-08-31 15:18:32 +00001201 </term>
1202 <listitem>
sewardj14cdbf82010-10-12 00:44:05 +00001203 <para>By default Valgrind only shows the filenames in stack
1204 traces, but not full paths to source files. When using Valgrind
1205 in large projects where the sources reside in multiple different
1206 directories, this can be inconvenient.
1207 <option>--fullpath-after</option> provides a flexible solution
1208 to this problem. When this option is present, the path to each
1209 source file is shown, with the following all-important caveat:
1210 if <option>string</option> is found in the path, then the path
1211 up to and including <option>string</option> is omitted, else the
1212 path is shown unmodified. Note that <option>string</option> is
1213 not required to be a prefix of the path.</para>
1214
1215 <para>For example, consider a file named
1216 <computeroutput>/home/janedoe/blah/src/foo/bar/xyzzy.c</computeroutput>.
1217 Specifying <option>--fullpath-after=/home/janedoe/blah/src/</option>
1218 will cause Valgrind to show the name
1219 as <computeroutput>foo/bar/xyzzy.c</computeroutput>.</para>
1220
1221 <para>Because the string is not required to be a prefix,
1222 <option>--fullpath-after=src/</option> will produce the same
1223 output. This is useful when the path contains arbitrary
1224 machine-generated characters. For example, the
1225 path
1226 <computeroutput>/my/build/dir/C32A1B47/blah/src/foo/xyzzy</computeroutput>
1227 can be pruned to <computeroutput>foo/xyzzy</computeroutput>
1228 using
1229 <option>--fullpath-after=/blah/src/</option>.</para>
1230
1231 <para>If you simply want to see the full path, just specify an
1232 empty string: <option>--fullpath-after=</option>. This isn't a
1233 special case, merely a logical consequence of the above rules.</para>
1234
1235 <para>Finally, you can use <option>--fullpath-after</option>
1236 multiple times. Any appearance of it causes Valgrind to switch
1237 to producing full paths and applying the above filtering rule.
1238 Each produced path is compared against all
1239 the <option>--fullpath-after</option>-specified strings, in the
1240 order specified. The first string to match causes the path to
1241 be truncated as described above. If none match, the full path
1242 is shown. This facilitates chopping off prefixes when the
1243 sources are drawn from a number of unrelated directories.
bart5dd01902010-08-31 15:18:32 +00001244 </para>
1245 </listitem>
1246 </varlistentry>
1247
sewardj8a6a76a2012-12-07 08:40:16 +00001248 <varlistentry id="opt.extra-debuginfo-path" xreflabel="--extra-debuginfo-path">
1249 <term>
1250 <option><![CDATA[--extra-debuginfo-path=<path> [default: undefined and unused] ]]></option>
1251 </term>
1252 <listitem>
1253 <para>By default Valgrind searches in several well-known paths
1254 for debug objects, such
1255 as <computeroutput>/usr/lib/debug/</computeroutput>.</para>
1256
1257 <para>However, there may be scenarios where you may wish to put
1258 debug objects at an arbitrary location, such as external storage
1259 when running Valgrind on a mobile device with limited local
1260 storage. Another example might be a situation where you do not
1261 have permission to install debug object packages on the system
1262 where you are running Valgrind.</para>
1263
1264 <para>In these scenarios, you may provide an absolute path as an extra,
1265 final place for Valgrind to search for debug objects by specifying
1266 <option>--extra-debuginfo-path=/path/to/debug/objects</option>.
1267 The given path will be prepended to the absolute path name of
1268 the searched-for object. For example, if Valgrind is looking
1269 for the debuginfo
1270 for <computeroutput>/w/x/y/zz.so</computeroutput>
1271 and <option>--extra-debuginfo-path=/a/b/c</option> is specified,
1272 it will look for a debug object at
1273 <computeroutput>/a/b/c/w/x/y/zz.so</computeroutput>.</para>
1274
1275 <para>This flag should only be specified once. If it is
1276 specified multiple times, only the last instance is
1277 honoured.</para>
1278 </listitem>
1279 </varlistentry>
1280
sewardj4c7254d2013-11-29 23:08:28 +00001281 <varlistentry id="opt.debuginfo-server" xreflabel="--debuginfo-server">
1282 <term>
1283 <option><![CDATA[--debuginfo-server=ipaddr:port [default: undefined and unused]]]></option>
1284 </term>
1285 <listitem>
1286 <para>This is a new, experimental, feature introduced in version
1287 3.9.0.</para>
1288
1289 <para>In some scenarios it may be convenient to read debuginfo
1290 from objects stored on a different machine. With this flag,
1291 Valgrind will query a debuginfo server running
1292 on <computeroutput>ipaddr</computeroutput> and listening on
1293 port <computeroutput>port</computeroutput>, if it cannot find
1294 the debuginfo object in the local filesystem.</para>
1295
1296 <para>The debuginfo server must accept TCP connections on
1297 port <computeroutput>port</computeroutput>. The debuginfo
1298 server is contained in the source
1299 file <computeroutput>auxprogs/valgrind-di-server.c</computeroutput>.
1300 It will only serve from the directory it is started
1301 in. <computeroutput>port</computeroutput> defaults to 1500 in
1302 both client and server if not specified.</para>
1303
1304 <para>If Valgrind looks for the debuginfo for
1305 <computeroutput>/w/x/y/zz.so</computeroutput> by using the
1306 debuginfo server, it will strip the pathname components and
1307 merely request <computeroutput>zz.so</computeroutput> on the
1308 server. That in turn will look only in its current working
1309 directory for a matching debuginfo object.</para>
1310
1311 <para>The debuginfo data is transmitted in small fragments (8
1312 KB) as requested by Valgrind. Each block is compressed using
1313 LZO to reduce transmission time. The implementation has been
1314 tuned for best performance over a single-stage 802.11g (WiFi)
1315 network link.</para>
1316
1317 <para>Note that checks for matching primary vs debug objects,
1318 using GNU debuglink CRC scheme, are performed even when using
1319 the debuginfo server. To disable such checking, you need to
1320 also specify
1321 <computeroutput>--allow-mismatched-debuginfo=yes</computeroutput>.
1322 </para>
1323
1324 <para>By default the Valgrind build system will
1325 build <computeroutput>valgrind-di-server</computeroutput> for
1326 the target platform, which is almost certainly not what you
1327 want. So far we have been unable to find out how to get
1328 automake/autoconf to build it for the build platform. If
1329 you want to use it, you will have to recompile it by hand using
1330 the command shown at the top
1331 of <computeroutput>auxprogs/valgrind-di-server.c</computeroutput>.</para>
1332 </listitem>
1333 </varlistentry>
1334
1335 <varlistentry id="opt.allow-mismatched-debuginfo"
1336 xreflabel="--allow-mismatched-debuginfo">
1337 <term>
1338 <option><![CDATA[--allow-mismatched-debuginfo=no|yes [no] ]]></option>
1339 </term>
1340 <listitem>
1341 <para>When reading debuginfo from separate debuginfo objects,
1342 Valgrind will by default check that the main and debuginfo
1343 objects match, using the GNU debuglink mechanism. This
1344 guarantees that it does not read debuginfo from out of date
1345 debuginfo objects, and also ensures that Valgrind can't crash as
1346 a result of mismatches.</para>
1347
1348 <para>This check can be overridden using
1349 <computeroutput>--allow-mismatched-debuginfo=yes</computeroutput>.
1350 This may be useful when the debuginfo and main objects have not
1351 been split in the proper way. Be careful when using this,
1352 though: it disables all consistency checking, and Valgrind has
1353 been observed to crash when the main and debuginfo objects don't
1354 match.</para>
1355 </listitem>
1356 </varlistentry>
1357
debad57fc2005-12-03 22:33:29 +00001358 <varlistentry id="opt.suppressions" xreflabel="--suppressions">
1359 <term>
1360 <option><![CDATA[--suppressions=<filename> [default: $PREFIX/lib/valgrind/default.supp] ]]></option>
1361 </term>
1362 <listitem>
1363 <para>Specifies an extra file from which to read descriptions of
sewardjc44b2542008-05-14 06:43:10 +00001364 errors to suppress. You may use up to 100 extra suppression
1365 files.</para>
debad57fc2005-12-03 22:33:29 +00001366 </listitem>
1367 </varlistentry>
njn3e986b22004-11-30 10:43:45 +00001368
sewardj33878892007-11-17 09:43:25 +00001369 <varlistentry id="opt.gen-suppressions" xreflabel="--gen-suppressions">
debad57fc2005-12-03 22:33:29 +00001370 <term>
1371 <option><![CDATA[--gen-suppressions=<yes|no|all> [default: no] ]]></option>
1372 </term>
1373 <listitem>
1374 <para>When set to <varname>yes</varname>, Valgrind will pause
1375 after every error shown and print the line:
njn7316df22009-08-04 01:16:01 +00001376 <literallayout><computeroutput> ---- Print suppression ? --- [Return/N/n/Y/y/C/c] ----</computeroutput></literallayout>
njn3e986b22004-11-30 10:43:45 +00001377
debad57fc2005-12-03 22:33:29 +00001378 The prompt's behaviour is the same as for the
1379 <option>--db-attach</option> option (see below).</para>
njn3e986b22004-11-30 10:43:45 +00001380
debad57fc2005-12-03 22:33:29 +00001381 <para>If you choose to, Valgrind will print out a suppression for
1382 this error. You can then cut and paste it into a suppression file
1383 if you don't want to hear about the error in the future.</para>
sewardjd153fae2005-01-10 17:24:47 +00001384
debad57fc2005-12-03 22:33:29 +00001385 <para>When set to <varname>all</varname>, Valgrind will print a
1386 suppression for every reported error, without querying the
1387 user.</para>
njn3e986b22004-11-30 10:43:45 +00001388
debad57fc2005-12-03 22:33:29 +00001389 <para>This option is particularly useful with C++ programs, as it
1390 prints out the suppressions with mangled names, as
1391 required.</para>
njn3e986b22004-11-30 10:43:45 +00001392
debad57fc2005-12-03 22:33:29 +00001393 <para>Note that the suppressions printed are as specific as
sewardj9a0132d2008-11-04 11:29:19 +00001394 possible. You may want to common up similar ones, by adding
1395 wildcards to function names, and by using frame-level wildcards.
1396 The wildcarding facilities are powerful yet flexible, and with a
1397 bit of careful editing, you may be able to suppress a whole
njn36ef2572009-08-10 00:42:43 +00001398 family of related errors with only a few suppressions.
1399 <!-- commented out because it causes broken links in the man page
1400 For details on how to do this, see
1401 <xref linkend="manual-core.suppress"/>.
1402 -->
1403 </para>
sewardj9a0132d2008-11-04 11:29:19 +00001404
1405 <para>Sometimes two different errors
debad57fc2005-12-03 22:33:29 +00001406 are suppressed by the same suppression, in which case Valgrind
1407 will output the suppression more than once, but you only need to
1408 have one copy in your suppression file (but having more than one
1409 won't cause problems). Also, the suppression name is given as
1410 <computeroutput>&lt;insert a suppression name
1411 here&gt;</computeroutput>; the name doesn't really matter, it's
1412 only used with the <option>-v</option> option which prints out all
1413 used suppression records.</para>
1414 </listitem>
1415 </varlistentry>
njn3e986b22004-11-30 10:43:45 +00001416
debad57fc2005-12-03 22:33:29 +00001417 <varlistentry id="opt.db-attach" xreflabel="--db-attach">
1418 <term>
1419 <option><![CDATA[--db-attach=<yes|no> [default: no] ]]></option>
1420 </term>
1421 <listitem>
1422 <para>When enabled, Valgrind will pause after every error shown
1423 and print the line:
njn7316df22009-08-04 01:16:01 +00001424 <literallayout><computeroutput> ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ----</computeroutput></literallayout>
njn3e986b22004-11-30 10:43:45 +00001425
debad57fc2005-12-03 22:33:29 +00001426 Pressing <varname>Ret</varname>, or <varname>N Ret</varname> or
1427 <varname>n Ret</varname>, causes Valgrind not to start a debugger
1428 for this error.</para>
njn3e986b22004-11-30 10:43:45 +00001429
debad57fc2005-12-03 22:33:29 +00001430 <para>Pressing <varname>Y Ret</varname> or
1431 <varname>y Ret</varname> causes Valgrind to start a debugger for
1432 the program at this point. When you have finished with the
1433 debugger, quit from it, and the program will continue. Trying to
1434 continue from inside the debugger doesn't work.</para>
njn3e986b22004-11-30 10:43:45 +00001435
sewardj3b290482011-05-06 21:02:55 +00001436 <para>
sewardje81a4542011-06-25 10:05:28 +00001437 Note: if you use GDB, more powerful debugging support is
1438 provided by the <option>--vgdb=</option> <varname>yes</varname>
1439 or <varname>full</varname> value. This activates Valgrind's
1440 internal gdbserver, which provides more-or-less full GDB-style
1441 control of the application: insertion of breakpoints, continuing
1442 from inside GDB, inferior function calls, and much more.
sewardj3b290482011-05-06 21:02:55 +00001443 </para>
1444
debad57fc2005-12-03 22:33:29 +00001445 <para><varname>C Ret</varname> or <varname>c Ret</varname> causes
1446 Valgrind not to start a debugger, and not to ask again.</para>
debad57fc2005-12-03 22:33:29 +00001447 </listitem>
1448 </varlistentry>
njn3e986b22004-11-30 10:43:45 +00001449
debad57fc2005-12-03 22:33:29 +00001450 <varlistentry id="opt.db-command" xreflabel="--db-command">
1451 <term>
1452 <option><![CDATA[--db-command=<command> [default: gdb -nw %f %p] ]]></option>
1453 </term>
1454 <listitem>
1455 <para>Specify the debugger to use with the
1456 <option>--db-attach</option> command. The default debugger is
njn7316df22009-08-04 01:16:01 +00001457 GDB. This option is a template that is expanded by Valgrind at
debad57fc2005-12-03 22:33:29 +00001458 runtime. <literal>%f</literal> is replaced with the executable's
1459 file name and <literal>%p</literal> is replaced by the process ID
1460 of the executable.</para>
njn3e986b22004-11-30 10:43:45 +00001461
debad57fc2005-12-03 22:33:29 +00001462 <para>This specifies how Valgrind will invoke the debugger. By
1463 default it will use whatever GDB is detected at build time, which
1464 is usually <computeroutput>/usr/bin/gdb</computeroutput>. Using
1465 this command, you can specify some alternative command to invoke
1466 the debugger you want to use.</para>
njn51272982005-07-25 23:18:44 +00001467
debad57fc2005-12-03 22:33:29 +00001468 <para>The command string given can include one or instances of the
1469 <literal>%p</literal> and <literal>%f</literal> expansions. Each
1470 instance of <literal>%p</literal> expands to the PID of the
1471 process to be debugged and each instance of <literal>%f</literal>
1472 expands to the path to the executable for the process to be
1473 debugged.</para>
sewardj778d7832007-11-22 01:21:56 +00001474
1475 <para>Since <computeroutput>&lt;command&gt;</computeroutput> is likely
njnf4b47582009-08-10 01:15:30 +00001476 to contain spaces, you will need to put this entire option in
sewardj778d7832007-11-22 01:21:56 +00001477 quotes to ensure it is correctly handled by the shell.</para>
debad57fc2005-12-03 22:33:29 +00001478 </listitem>
1479 </varlistentry>
1480
1481 <varlistentry id="opt.input-fd" xreflabel="--input-fd">
1482 <term>
1483 <option><![CDATA[--input-fd=<number> [default: 0, stdin] ]]></option>
1484 </term>
1485 <listitem>
sewardj08e31e22007-05-23 21:58:33 +00001486 <para>When using <option>--db-attach=yes</option> or
debad57fc2005-12-03 22:33:29 +00001487 <option>--gen-suppressions=yes</option>, Valgrind will stop so as
sewardj08e31e22007-05-23 21:58:33 +00001488 to read keyboard input from you when each error occurs. By
debad57fc2005-12-03 22:33:29 +00001489 default it reads from the standard input (stdin), which is
1490 problematic for programs which close stdin. This option allows
1491 you to specify an alternative file descriptor from which to read
1492 input.</para>
1493 </listitem>
1494 </varlistentry>
1495
njn97db7612009-08-04 02:32:55 +00001496 <varlistentry id="opt.dsymutil" xreflabel="--dsymutil">
sewardjb4cf7cd2009-05-31 09:34:05 +00001497 <term>
njn97db7612009-08-04 02:32:55 +00001498 <option><![CDATA[--dsymutil=no|yes [no] ]]></option>
sewardjb4cf7cd2009-05-31 09:34:05 +00001499 </term>
1500 <listitem>
njnf4b47582009-08-10 01:15:30 +00001501 <para>This option is only relevant when running Valgrind on
njn7316df22009-08-04 01:16:01 +00001502 Mac OS X.</para>
sewardjb4cf7cd2009-05-31 09:34:05 +00001503
njn7316df22009-08-04 01:16:01 +00001504 <para>Mac OS X uses a deferred debug information (debuginfo)
sewardjb4cf7cd2009-05-31 09:34:05 +00001505 linking scheme. When object files containing debuginfo are
1506 linked into a <computeroutput>.dylib</computeroutput> or an
1507 executable, the debuginfo is not copied into the final file.
1508 Instead, the debuginfo must be linked manually by
1509 running <computeroutput>dsymutil</computeroutput>, a
1510 system-provided utility, on the executable
1511 or <computeroutput>.dylib</computeroutput>. The resulting
1512 combined debuginfo is placed in a directory alongside the
1513 executable or <computeroutput>.dylib</computeroutput>, but with
1514 the extension <computeroutput>.dSYM</computeroutput>.</para>
1515
njn97db7612009-08-04 02:32:55 +00001516 <para>With <option>--dsymutil=no</option>, Valgrind
sewardjb4cf7cd2009-05-31 09:34:05 +00001517 will detect cases where the
1518 <computeroutput>.dSYM</computeroutput> directory is either
1519 missing, or is present but does not appear to match the
1520 associated executable or <computeroutput>.dylib</computeroutput>,
1521 most likely because it is out of date. In these cases, Valgrind
1522 will print a warning message but take no further action.</para>
1523
njn97db7612009-08-04 02:32:55 +00001524 <para>With <option>--dsymutil=yes</option>, Valgrind
sewardjb4cf7cd2009-05-31 09:34:05 +00001525 will, in such cases, automatically
1526 run <computeroutput>dsymutil</computeroutput> as necessary to
1527 bring the debuginfo up to date. For all practical purposes, if
njn97db7612009-08-04 02:32:55 +00001528 you always use <option>--dsymutil=yes</option>, then
sewardjb4cf7cd2009-05-31 09:34:05 +00001529 there is never any need to
1530 run <computeroutput>dsymutil</computeroutput> manually or as part
1531 of your applications's build system, since Valgrind will run it
1532 as necessary.</para>
1533
1534 <para>Valgrind will not attempt to
1535 run <computeroutput>dsymutil</computeroutput> on any
1536 executable or library in
njn7316df22009-08-04 01:16:01 +00001537 <computeroutput>/usr/</computeroutput>,
1538 <computeroutput>/bin/</computeroutput>,
1539 <computeroutput>/sbin/</computeroutput>,
1540 <computeroutput>/opt/</computeroutput>,
1541 <computeroutput>/sw/</computeroutput>,
1542 <computeroutput>/System/</computeroutput>,
1543 <computeroutput>/Library/</computeroutput> or
1544 <computeroutput>/Applications/</computeroutput>
sewardjb4cf7cd2009-05-31 09:34:05 +00001545 since <computeroutput>dsymutil</computeroutput> will always fail
1546 in such situations. It fails both because the debuginfo for
1547 such pre-installed system components is not available anywhere,
bart2ff151c2009-07-19 08:12:57 +00001548 and also because it would require write privileges in those
sewardjb4cf7cd2009-05-31 09:34:05 +00001549 directories.</para>
1550
1551 <para>Be careful when
njn97db7612009-08-04 02:32:55 +00001552 using <option>--dsymutil=yes</option>, since it will
sewardjb4cf7cd2009-05-31 09:34:05 +00001553 cause pre-existing <computeroutput>.dSYM</computeroutput>
sewardje089f012010-10-13 21:47:29 +00001554 directories to be silently deleted and re-created. Also note that
njn7316df22009-08-04 01:16:01 +00001555 <computeroutput>dsymutil</computeroutput> is quite slow, sometimes
1556 excessively so.</para>
sewardjb4cf7cd2009-05-31 09:34:05 +00001557 </listitem>
1558 </varlistentry>
1559
debad57fc2005-12-03 22:33:29 +00001560 <varlistentry id="opt.max-stackframe" xreflabel="--max-stackframe">
1561 <term>
1562 <option><![CDATA[--max-stackframe=<number> [default: 2000000] ]]></option>
1563 </term>
1564 <listitem>
sewardj08e31e22007-05-23 21:58:33 +00001565 <para>The maximum size of a stack frame. If the stack pointer moves by
debad57fc2005-12-03 22:33:29 +00001566 more than this amount then Valgrind will assume that
1567 the program is switching to a different stack.</para>
1568
1569 <para>You may need to use this option if your program has large
1570 stack-allocated arrays. Valgrind keeps track of your program's
1571 stack pointer. If it changes by more than the threshold amount,
1572 Valgrind assumes your program is switching to a different stack,
1573 and Memcheck behaves differently than it would for a stack pointer
1574 change smaller than the threshold. Usually this heuristic works
1575 well. However, if your program allocates large structures on the
1576 stack, this heuristic will be fooled, and Memcheck will
1577 subsequently report large numbers of invalid stack accesses. This
1578 option allows you to change the threshold to a different
1579 value.</para>
1580
njnf4b47582009-08-10 01:15:30 +00001581 <para>You should only consider use of this option if Valgrind's
debad57fc2005-12-03 22:33:29 +00001582 debug output directs you to do so. In that case it will tell you
1583 the new threshold you should specify.</para>
1584
1585 <para>In general, allocating large structures on the stack is a
sewardj08e31e22007-05-23 21:58:33 +00001586 bad idea, because you can easily run out of stack space,
debad57fc2005-12-03 22:33:29 +00001587 especially on systems with limited memory or which expect to
sewardj08e31e22007-05-23 21:58:33 +00001588 support large numbers of threads each with a small stack, and also
debad57fc2005-12-03 22:33:29 +00001589 because the error checking performed by Memcheck is more effective
1590 for heap-allocated data than for stack-allocated data. If you
njnf4b47582009-08-10 01:15:30 +00001591 have to use this option, you may wish to consider rewriting your
debad57fc2005-12-03 22:33:29 +00001592 code to allocate on the heap rather than on the stack.</para>
1593 </listitem>
1594 </varlistentry>
1595
sewardj95d86c02007-12-18 01:49:23 +00001596 <varlistentry id="opt.main-stacksize" xreflabel="--main-stacksize">
1597 <term>
1598 <option><![CDATA[--main-stacksize=<number>
1599 [default: use current 'ulimit' value] ]]></option>
1600 </term>
1601 <listitem>
1602 <para>Specifies the size of the main thread's stack.</para>
1603
1604 <para>To simplify its memory management, Valgrind reserves all
1605 required space for the main thread's stack at startup. That
1606 means it needs to know the required stack size at
1607 startup.</para>
1608
1609 <para>By default, Valgrind uses the current "ulimit" value for
1610 the stack size, or 16 MB, whichever is lower. In many cases
1611 this gives a stack size in the range 8 to 16 MB, which almost
1612 never overflows for most applications.</para>
1613
1614 <para>If you need a larger total stack size,
1615 use <option>--main-stacksize</option> to specify it. Only set
1616 it as high as you need, since reserving far more space than you
1617 need (that is, hundreds of megabytes more than you need)
1618 constrains Valgrind's memory allocators and may reduce the total
1619 amount of memory that Valgrind can use. This is only really of
1620 significance on 32-bit machines.</para>
1621
1622 <para>On Linux, you may request a stack of size up to 2GB.
1623 Valgrind will stop with a diagnostic message if the stack cannot
sewardj6e9de462011-06-28 07:25:29 +00001624 be allocated.</para>
sewardj95d86c02007-12-18 01:49:23 +00001625
1626 <para><option>--main-stacksize</option> only affects the stack
1627 size for the program's initial thread. It has no bearing on the
1628 size of thread stacks, as Valgrind does not allocate
1629 those.</para>
1630
1631 <para>You may need to use both <option>--main-stacksize</option>
1632 and <option>--max-stackframe</option> together. It is important
1633 to understand that <option>--main-stacksize</option> sets the
1634 maximum total stack size,
1635 whilst <option>--max-stackframe</option> specifies the largest
1636 size of any one stack frame. You will have to work out
1637 the <option>--main-stacksize</option> value for yourself
1638 (usually, if your applications segfaults). But Valgrind will
1639 tell you the needed <option>--max-stackframe</option> size, if
1640 necessary.</para>
1641
1642 <para>As discussed further in the description
1643 of <option>--max-stackframe</option>, a requirement for a large
1644 stack is a sign of potential portability problems. You are best
1645 advised to place all large data in heap-allocated memory.</para>
1646 </listitem>
1647 </varlistentry>
1648
debad57fc2005-12-03 22:33:29 +00001649</variablelist>
de03e0e7c2005-12-03 23:02:33 +00001650<!-- end of xi:include in the manpage -->
debad57fc2005-12-03 22:33:29 +00001651
njn3e986b22004-11-30 10:43:45 +00001652</sect2>
1653
debad57fc2005-12-03 22:33:29 +00001654
njn7316df22009-08-04 01:16:01 +00001655<sect2 id="manual-core.mallocopts" xreflabel="malloc-related Options">
sewardj1160e812010-09-10 14:56:18 +00001656<title>malloc-related Options</title>
njn3e986b22004-11-30 10:43:45 +00001657
de03e0e7c2005-12-03 23:02:33 +00001658<!-- start of xi:include in the manpage -->
1659<para id="malloc-related.opts.para">For tools that use their own version of
philipped99c26a2012-07-31 22:17:28 +00001660<computeroutput>malloc</computeroutput> (e.g. Memcheck,
1661Massif, Helgrind, DRD), the following options apply.</para>
njn3e986b22004-11-30 10:43:45 +00001662
de03e0e7c2005-12-03 23:02:33 +00001663<variablelist id="malloc-related.opts.list">
njn3e986b22004-11-30 10:43:45 +00001664
debad57fc2005-12-03 22:33:29 +00001665 <varlistentry id="opt.alignment" xreflabel="--alignment">
1666 <term>
njn7316df22009-08-04 01:16:01 +00001667 <option><![CDATA[--alignment=<number> [default: 8 or 16, depending on the platform] ]]></option>
debad57fc2005-12-03 22:33:29 +00001668 </term>
1669 <listitem>
njn7316df22009-08-04 01:16:01 +00001670 <para>By default Valgrind's <function>malloc</function>,
1671 <function>realloc</function>, etc, return a block whose starting
1672 address is 8-byte aligned or 16-byte aligned (the value depends on the
1673 platform and matches the platform default). This option allows you to
1674 specify a different alignment. The supplied value must be greater
1675 than or equal to the default, less than or equal to 4096, and must be
1676 a power of two.</para>
njn51272982005-07-25 23:18:44 +00001677 </listitem>
debad57fc2005-12-03 22:33:29 +00001678 </varlistentry>
njn51272982005-07-25 23:18:44 +00001679
philipped99c26a2012-07-31 22:17:28 +00001680 <varlistentry id="opt.redzone-size" xreflabel="--redzone-size">
1681 <term>
1682 <option><![CDATA[--redzone-size=<number> [default: depends on the tool] ]]></option>
1683 </term>
1684 <listitem>
sewardjca456c72012-08-05 13:44:15 +00001685 <para> Valgrind's <function>malloc, realloc,</function> etc, add
1686 padding blocks before and after each heap block allocated by the
1687 program being run. Such padding blocks are called redzones. The
1688 default value for the redzone size depends on the tool. For
1689 example, Memcheck adds and protects a minimum of 16 bytes before
1690 and after each block allocated by the client. This allows it to
1691 detect block underruns or overruns of up to 16 bytes.
philipped99c26a2012-07-31 22:17:28 +00001692 </para>
sewardjca456c72012-08-05 13:44:15 +00001693 <para>Increasing the redzone size makes it possible to detect
1694 overruns of larger distances, but increases the amount of memory
1695 used by Valgrind. Decreasing the redzone size will reduce the
1696 memory needed by Valgrind but also reduces the chances of
1697 detecting over/underruns, so is not recommended.</para>
philipped99c26a2012-07-31 22:17:28 +00001698 </listitem>
1699 </varlistentry>
1700
debad57fc2005-12-03 22:33:29 +00001701</variablelist>
de03e0e7c2005-12-03 23:02:33 +00001702<!-- end of xi:include in the manpage -->
debad57fc2005-12-03 22:33:29 +00001703
1704</sect2>
1705
1706
1707<sect2 id="manual-core.rareopts" xreflabel="Uncommon Options">
1708<title>Uncommon Options</title>
1709
de03e0e7c2005-12-03 23:02:33 +00001710<!-- start of xi:include in the manpage -->
1711<para id="uncommon.opts.para">These options apply to all tools, as they
1712affect certain obscure workings of the Valgrind core. Most people won't
sewardjca456c72012-08-05 13:44:15 +00001713need to use them.</para>
debad57fc2005-12-03 22:33:29 +00001714
de03e0e7c2005-12-03 23:02:33 +00001715<variablelist id="uncommon.opts.list">
debad57fc2005-12-03 22:33:29 +00001716
njn97db7612009-08-04 02:32:55 +00001717 <varlistentry id="opt.smc-check" xreflabel="--smc-check">
1718 <term>
sewardj6dbcc632011-06-07 21:39:28 +00001719 <option><![CDATA[--smc-check=<none|stack|all|all-non-file> [default: stack] ]]></option>
njn97db7612009-08-04 02:32:55 +00001720 </term>
1721 <listitem>
1722 <para>This option controls Valgrind's detection of self-modifying
1723 code. If no checking is done, if a program executes some code, then
1724 overwrites it with new code, and executes the new code, Valgrind will
1725 continue to execute the translations it made for the old code. This
1726 will likely lead to incorrect behaviour and/or crashes.</para>
1727
sewardj6dbcc632011-06-07 21:39:28 +00001728 <para>Valgrind has four levels of self-modifying code detection:
sewardje089f012010-10-13 21:47:29 +00001729 no detection, detect self-modifying code on the stack (which is used by
sewardj6dbcc632011-06-07 21:39:28 +00001730 GCC to implement nested functions), detect self-modifying code
1731 everywhere, and detect self-modifying code everywhere except in
1732 file-backed mappings.
1733
1734 Note that the default option will catch the vast majority
njn97db7612009-08-04 02:32:55 +00001735 of cases. The main case it will not catch is programs such as JIT
1736 compilers that dynamically generate code <emphasis>and</emphasis>
1737 subsequently overwrite part or all of it. Running with
sewardj6dbcc632011-06-07 21:39:28 +00001738 <varname>all</varname> will slow Valgrind down noticeably.
1739 Running with
njn97db7612009-08-04 02:32:55 +00001740 <varname>none</varname> will rarely speed things up, since very little
1741 code gets put on the stack for most programs. The
sewardj6dbcc632011-06-07 21:39:28 +00001742 <function>VALGRIND_DISCARD_TRANSLATIONS</function> client
1743 request is an alternative to <option>--smc-check=all</option>
1744 that requires more programmer effort but allows Valgrind to run
1745 your program faster, by telling it precisely when translations
1746 need to be re-made.
njn36ef2572009-08-10 00:42:43 +00001747 <!-- commented out because it causes broken links in the man page
1748 ; see <xref
1749 linkend="manual-core-adv.clientreq"/> for more details.
1750 -->
1751 </para>
njn97db7612009-08-04 02:32:55 +00001752
sewardj6dbcc632011-06-07 21:39:28 +00001753 <para><option>--smc-check=all-non-file</option> provides a
1754 cheaper but more limited version
1755 of <option>--smc-check=all</option>. It adds checks to any
1756 translations that do not originate from file-backed memory
1757 mappings. Typical applications that generate code, for example
1758 JITs in web browsers, generate code into anonymous mmaped areas,
1759 whereas the "fixed" code of the browser always lives in
1760 file-backed mappings. <option>--smc-check=all-non-file</option>
1761 takes advantage of this observation, limiting the overhead of
1762 checking to code which is likely to be JIT generated.</para>
1763
sewardjca456c72012-08-05 13:44:15 +00001764 <para>Some architectures (including ppc32, ppc64, ARM and MIPS)
1765 require programs which create code at runtime to flush the
1766 instruction cache in between code generation and first use.
1767 Valgrind observes and honours such instructions. Hence, on
1768 ppc32/Linux, ppc64/Linux and ARM/Linux, Valgrind always provides
1769 complete, transparent support for self-modifying code. It is
1770 only on platforms such as x86/Linux, AMD64/Linux, x86/Darwin and
1771 AMD64/Darwin that you need to use this option.</para>
njn97db7612009-08-04 02:32:55 +00001772 </listitem>
1773 </varlistentry>
1774
1775 <varlistentry id="opt.read-var-info" xreflabel="--read-var-info">
1776 <term>
1777 <option><![CDATA[--read-var-info=<yes|no> [default: no] ]]></option>
1778 </term>
1779 <listitem>
sewardje77c7242009-08-16 22:49:53 +00001780 <para>When enabled, Valgrind will read information about
1781 variable types and locations from DWARF3 debug info.
1782 This slows Valgrind down and makes it use more memory, but for
1783 the tools that can take advantage of it (Memcheck, Helgrind,
1784 DRD) it can result in more precise error messages. For example,
1785 here are some standard errors issued by Memcheck:</para>
njn97db7612009-08-04 02:32:55 +00001786<programlisting><![CDATA[
1787==15516== Uninitialised byte(s) found during client check request
1788==15516== at 0x400633: croak (varinfo1.c:28)
1789==15516== by 0x4006B2: main (varinfo1.c:55)
1790==15516== Address 0x60103b is 7 bytes inside data symbol "global_i2"
1791==15516==
1792==15516== Uninitialised byte(s) found during client check request
1793==15516== at 0x400633: croak (varinfo1.c:28)
1794==15516== by 0x4006BC: main (varinfo1.c:56)
1795==15516== Address 0x7fefffefc is on thread 1's stack]]></programlisting>
1796
1797 <para>And here are the same errors with
1798 <option>--read-var-info=yes</option>:</para>
1799
1800<programlisting><![CDATA[
1801==15522== Uninitialised byte(s) found during client check request
1802==15522== at 0x400633: croak (varinfo1.c:28)
1803==15522== by 0x4006B2: main (varinfo1.c:55)
1804==15522== Location 0x60103b is 0 bytes inside global_i2[7],
1805==15522== a global variable declared at varinfo1.c:41
1806==15522==
1807==15522== Uninitialised byte(s) found during client check request
1808==15522== at 0x400633: croak (varinfo1.c:28)
1809==15522== by 0x4006BC: main (varinfo1.c:56)
1810==15522== Location 0x7fefffefc is 0 bytes inside local var "local"
1811==15522== declared at varinfo1.c:46, in frame #1 of thread 1]]></programlisting>
1812 </listitem>
1813 </varlistentry>
1814
sewardj3b290482011-05-06 21:02:55 +00001815 <varlistentry id="opt.vgdb-poll" xreflabel="--vgdb-poll">
1816 <term>
1817 <option><![CDATA[--vgdb-poll=<number> [default: 5000] ]]></option>
1818 </term>
1819 <listitem>
1820 <para> As part of its main loop, the Valgrind scheduler will
1821 poll to check if some activity (such as an external command or
1822 some input from a gdb) has to be handled by gdbserver. This
1823 activity poll will be done after having run the given number of
1824 basic blocks (or slightly more than the given number of basic
1825 blocks). This poll is quite cheap so the default value is set
1826 relatively low. You might further decrease this value if vgdb
1827 cannot use ptrace system call to interrupt Valgrind if all
1828 threads are (most of the time) blocked in a system call.
1829 </para>
sewardj3b290482011-05-06 21:02:55 +00001830 </listitem>
1831 </varlistentry>
1832
1833 <varlistentry id="opt.vgdb-shadow-registers" xreflabel="--vgdb-shadow-registers">
1834 <term>
1835 <option><![CDATA[--vgdb-shadow-registers=no|yes [default: no] ]]></option>
1836 </term>
1837 <listitem>
1838 <para> When activated, gdbserver will expose the Valgrind shadow registers
sewardje81a4542011-06-25 10:05:28 +00001839 to GDB. With this, the value of the Valgrind shadow registers can be examined
1840 or changed using GDB. Exposing shadow registers only works with GDB version
1841 7.1 or later.
sewardj3b290482011-05-06 21:02:55 +00001842 </para>
1843 </listitem>
1844 </varlistentry>
1845
1846 <varlistentry id="opt.vgdb-prefix" xreflabel="--vgdb-prefix">
1847 <term>
1848 <option><![CDATA[--vgdb-prefix=<prefix> [default: /tmp/vgdb-pipe] ]]></option>
1849 </term>
1850 <listitem>
1851 <para> To communicate with gdb/vgdb, the Valgrind gdbserver
1852 creates 3 files (2 named FIFOs and a mmap shared memory
1853 file). The prefix option controls the directory and prefix for
1854 the creation of these files.
1855 </para>
1856 </listitem>
1857 </varlistentry>
1858
debad57fc2005-12-03 22:33:29 +00001859 <varlistentry id="opt.run-libc-freeres" xreflabel="--run-libc-freeres">
1860 <term>
1861 <option><![CDATA[--run-libc-freeres=<yes|no> [default: yes] ]]></option>
1862 </term>
1863 <listitem>
njnf4b47582009-08-10 01:15:30 +00001864 <para>This option is only relevant when running Valgrind on Linux.</para>
njn7316df22009-08-04 01:16:01 +00001865
debad57fc2005-12-03 22:33:29 +00001866 <para>The GNU C library (<function>libc.so</function>), which is
1867 used by all programs, may allocate memory for its own uses.
1868 Usually it doesn't bother to free that memory when the program
sewardj33878892007-11-17 09:43:25 +00001869 ends&mdash;there would be no point, since the Linux kernel reclaims
debad57fc2005-12-03 22:33:29 +00001870 all process resources when a process exits anyway, so it would
1871 just slow things down.</para>
1872
1873 <para>The glibc authors realised that this behaviour causes leak
1874 checkers, such as Valgrind, to falsely report leaks in glibc, when
1875 a leak check is done at exit. In order to avoid this, they
1876 provided a routine called <function>__libc_freeres</function>
1877 specifically to make glibc release all memory it has allocated.
njn1d0825f2006-03-27 11:37:07 +00001878 Memcheck therefore tries to run
debad57fc2005-12-03 22:33:29 +00001879 <function>__libc_freeres</function> at exit.</para>
1880
sewardj08e31e22007-05-23 21:58:33 +00001881 <para>Unfortunately, in some very old versions of glibc,
debad57fc2005-12-03 22:33:29 +00001882 <function>__libc_freeres</function> is sufficiently buggy to cause
sewardj08e31e22007-05-23 21:58:33 +00001883 segmentation faults. This was particularly noticeable on Red Hat
njnf4b47582009-08-10 01:15:30 +00001884 7.1. So this option is provided in order to inhibit the run of
debad57fc2005-12-03 22:33:29 +00001885 <function>__libc_freeres</function>. If your program seems to run
1886 fine on Valgrind, but segfaults at exit, you may find that
1887 <option>--run-libc-freeres=no</option> fixes that, although at the
1888 cost of possibly falsely reporting space leaks in
1889 <filename>libc.so</filename>.</para>
1890 </listitem>
1891 </varlistentry>
1892
1893 <varlistentry id="opt.sim-hints" xreflabel="--sim-hints">
1894 <term>
1895 <option><![CDATA[--sim-hints=hint1,hint2,... ]]></option>
1896 </term>
1897 <listitem>
1898 <para>Pass miscellaneous hints to Valgrind which slightly modify
1899 the simulated behaviour in nonstandard or dangerous ways, possibly
1900 to help the simulation of strange features. By default no hints
1901 are enabled. Use with caution! Currently known hints are:</para>
1902 <itemizedlist>
1903 <listitem>
1904 <para><option>lax-ioctls: </option> Be very lax about ioctl
1905 handling; the only assumption is that the size is
1906 correct. Doesn't require the full buffer to be initialized
1907 when writing. Without this, using some device drivers with a
1908 large number of strange ioctl commands becomes very
1909 tiresome.</para>
1910 </listitem>
1911 <listitem>
philippe277eaff2012-03-03 12:01:48 +00001912 <para><option>enable-outer: </option> Enable some special
debad57fc2005-12-03 22:33:29 +00001913 magic needed when the program being run is itself
1914 Valgrind.</para>
1915 </listitem>
sewardjcc3de2d2011-08-18 15:08:20 +00001916 <listitem>
philippe72faf102012-03-11 22:24:03 +00001917 <para><option>no-inner-prefix: </option> Disable printing
1918 a prefix <option>&gt;</option> in front of each stdout or
1919 stderr output line in an inner Valgrind being run by an
1920 outer Valgrind. This is useful when running Valgrind
1921 regression tests in an outer/inner setup. Note that the
1922 prefix <option>&gt;</option> will always be printed in
1923 front of the inner debug logging lines.</para>
1924 </listitem>
1925 <listitem>
sewardjcc3de2d2011-08-18 15:08:20 +00001926 <para><option>fuse-compatible: </option> Enable special
1927 handling for certain system calls that may block in a FUSE
1928 file-system. This may be necessary when running Valgrind
1929 on a multi-threaded program that uses one thread to manage
1930 a FUSE file-system and another thread to access that
1931 file-system.
1932 </para>
1933 </listitem>
debad57fc2005-12-03 22:33:29 +00001934 </itemizedlist>
1935 </listitem>
1936 </varlistentry>
1937
philippe236a71a2012-02-22 20:23:29 +00001938 <varlistentry id="opt.fair-sched" xreflabel="--fair-sched">
1939 <term>
1940 <option><![CDATA[--fair-sched=<no|yes|try> [default: no] ]]></option>
1941 </term>
1942
sewardjca456c72012-08-05 13:44:15 +00001943 <listitem> <para>The <option>--fair-sched</option> option controls
1944 the locking mechanism used by Valgrind to serialise thread
1945 execution. The locking mechanism controls the way the threads
1946 are scheduled, and different settings give different trade-offs
1947 between fairness and performance. For more details about the
1948 Valgrind thread serialisation scheme and its impact on
1949 performance and thread scheduling, see
philippee52e4452013-12-12 23:19:13 +00001950 <xref linkend="&vg-pthreads-perf-sched-id;"/>.</para>
philippe236a71a2012-02-22 20:23:29 +00001951
1952 <itemizedlist>
1953 <listitem> <para>The value <option>--fair-sched=yes</option>
sewardjca456c72012-08-05 13:44:15 +00001954 activates a fair scheduler. In short, if multiple threads are
philippe236a71a2012-02-22 20:23:29 +00001955 ready to run, the threads will be scheduled in a round robin
1956 fashion. This mechanism is not available on all platforms or
sewardjca456c72012-08-05 13:44:15 +00001957 Linux versions. If not available,
philippe236a71a2012-02-22 20:23:29 +00001958 using <option>--fair-sched=yes</option> will cause Valgrind to
1959 terminate with an error.</para>
sewardjca456c72012-08-05 13:44:15 +00001960 <para>You may find this setting improves overall
1961 responsiveness if you are running an interactive
1962 multithreaded program, for example a web browser, on
1963 Valgrind.</para>
philippe236a71a2012-02-22 20:23:29 +00001964 </listitem>
1965
1966 <listitem> <para>The value <option>--fair-sched=try</option>
sewardjca456c72012-08-05 13:44:15 +00001967 activates fair scheduling if available on the
1968 platform. Otherwise, it will automatically fall back
philippe236a71a2012-02-22 20:23:29 +00001969 to <option>--fair-sched=no</option>.</para>
1970 </listitem>
1971
1972 <listitem> <para>The value <option>--fair-sched=no</option> activates
sewardjca456c72012-08-05 13:44:15 +00001973 a scheduler which does not guarantee fairness
1974 between threads ready to run, but which in general gives the
1975 highest performance.</para>
philippe236a71a2012-02-22 20:23:29 +00001976 </listitem>
1977 </itemizedlist>
philippee52e4452013-12-12 23:19:13 +00001978 </listitem>
philippe236a71a2012-02-22 20:23:29 +00001979
1980 </varlistentry>
1981
debad57fc2005-12-03 22:33:29 +00001982 <varlistentry id="opt.kernel-variant" xreflabel="--kernel-variant">
1983 <term>
1984 <option>--kernel-variant=variant1,variant2,...</option>
1985 </term>
1986 <listitem>
1987 <para>Handle system calls and ioctls arising from minor variants
1988 of the default kernel for this platform. This is useful for
1989 running on hacked kernels or with kernel modules which support
1990 nonstandard ioctls, for example. Use with caution. If you don't
1991 understand what this option does then you almost certainly don't
1992 need it. Currently known variants are:</para>
1993 <itemizedlist>
1994 <listitem>
njn7316df22009-08-04 01:16:01 +00001995 <para><option>bproc: </option> Support the
1996 <function>sys_broc</function> system call on x86. This is for
1997 running on BProc, which is a minor variant of standard Linux which
1998 is sometimes used for building clusters.</para>
debad57fc2005-12-03 22:33:29 +00001999 </listitem>
2000 </itemizedlist>
2001 </listitem>
2002 </varlistentry>
2003
philippe46207652013-01-20 17:11:58 +00002004 <varlistentry id="opt.merge-recursive-frames" xreflabel="--merge-recursive-frames">
2005 <term>
2006 <option><![CDATA[--merge-recursive-frames=<number> [default: 0] ]]></option>
2007 </term>
2008 <listitem>
sewardj4c7254d2013-11-29 23:08:28 +00002009 <para>Some recursive algorithms, for example balanced binary
2010 tree implementations, create many different stack traces, each
2011 containing cycles of calls. A cycle is defined as two identical
2012 program counter values separated by zero or more other program
2013 counter values. Valgrind may then use a lot of memory to store
2014 all these stack traces. This is a poor use of memory
2015 considering that such stack traces contain repeated
2016 uninteresting recursive calls instead of more interesting
2017 information such as the function that has initiated the
2018 recursive call.
philippe46207652013-01-20 17:11:58 +00002019 </para>
2020 <para>The option <option>--merge-recursive-frames=&lt;number&gt;</option>
2021 instructs Valgrind to detect and merge recursive call cycles
2022 having a size of up to <option>&lt;number&gt;</option>
2023 frames. When such a cycle is detected, Valgrind records the
2024 cycle in the stack trace as a unique program counter.
2025 </para>
2026 <para>
2027 The value 0 (the default) causes no recursive call merging.
2028 A value of 1 will cause stack traces of simple recursive algorithms
2029 (for example, a factorial implementation) to be collapsed.
sewardj4c7254d2013-11-29 23:08:28 +00002030 A value of 2 will usually be needed to collapse stack traces produced
2031 by recursive algorithms such as binary trees, quick sort, etc.
philippe46207652013-01-20 17:11:58 +00002032 Higher values might be needed for more complex recursive algorithms.
2033 </para>
sewardj4c7254d2013-11-29 23:08:28 +00002034 <para>Note: recursive calls are detected by analysis of program
2035 counter values. They are not detected by looking at function
2036 names.</para>
philippe46207652013-01-20 17:11:58 +00002037 </listitem>
2038 </varlistentry>
2039
philippe8e1bee42013-10-18 00:08:20 +00002040 <varlistentry id="opt.num-transtab-sectors" xreflabel="--num-transtab-sectors">
2041 <term>
sewardj4c7254d2013-11-29 23:08:28 +00002042 <option><![CDATA[--num-transtab-sectors=<number> [default: 6
2043 for Android platforms, 16 for all others] ]]></option>
philippe8e1bee42013-10-18 00:08:20 +00002044 </term>
2045 <listitem>
sewardja11ec172013-10-18 11:18:45 +00002046 <para>Valgrind translates and instruments your program's machine
2047 code in small fragments. The translations are stored in a
2048 translation cache that is divided into a number of sections
2049 (sectors). If the cache is full, the sector containing the
sewardj4c7254d2013-11-29 23:08:28 +00002050 oldest translations is emptied and reused. If these old
sewardja11ec172013-10-18 11:18:45 +00002051 translations are needed again, Valgrind must re-translate and
sewardj4c7254d2013-11-29 23:08:28 +00002052 re-instrument the corresponding machine code, which is
sewardja11ec172013-10-18 11:18:45 +00002053 expensive. If the "executed instructions" working set of a
2054 program is big, increasing the number of sectors may improve
2055 performance by reducing the number of re-translations needed.
2056 Sectors are allocated on demand. Once allocated, a sector can
philippe1a677312013-10-20 17:12:16 +00002057 never be freed, and occupies considerable space, depending on the tool
sewardja11ec172013-10-18 11:18:45 +00002058 (about 40 MB per sector for Memcheck). Use the
2059 option <option>--stats=yes</option> to obtain precise
philippe8e1bee42013-10-18 00:08:20 +00002060 information about the memory used by a sector and the allocation
2061 and recycling of sectors.</para>
2062 </listitem>
2063 </varlistentry>
2064
philippee4d78122014-04-20 14:20:37 +00002065 <varlistentry id="opt.aspace-minaddr" xreflabel="----aspace-minaddr">
2066 <term>
2067 <option><![CDATA[--aspace-minaddr=<address> [default: depends
2068 on the platform] ]]></option>
2069 </term>
2070 <listitem>
2071 <para>To avoid potential conflicts with some system libraries,
2072 Valgrind does not use the address space
2073 below <option>--aspace-minaddr</option> value, keeping it
2074 reserved in case a library specifically requests memory in this
2075 region. So, some "pessimistic" value is guessed by Valgrind
2076 depending on the platform. On linux, by default, Valgrind avoids
2077 using the first 64MB even if typically there is no conflict in
2078 this complete zone. You can use the
2079 option <option>--aspace-minaddr</option> to have your memory
2080 hungry application benefitting from more of this lower memory.
2081 On the other hand, if you encounter a conflict, increasing
2082 aspace-minaddr value might solve it. Conflicts will typically
2083 manifest themselves with mmap failures in the low range of the
2084 address space. The
2085 provided <computeroutput>address</computeroutput> must be page
2086 aligned and must be equal or bigger to 0x1000 (4KB). To find the
2087 default value on your platform, do something such as
2088 <computeroutput>valgrind -d -d date 2&gt;&amp;1 | grep -i minaddr</computeroutput>. Values lower than 0x10000 (64KB) are known to create problems
2089 on some distributions.
2090 </para>
2091 </listitem>
2092 </varlistentry>
2093
debad57fc2005-12-03 22:33:29 +00002094 <varlistentry id="opt.show-emwarns" xreflabel="--show-emwarns">
2095 <term>
2096 <option><![CDATA[--show-emwarns=<yes|no> [default: no] ]]></option>
2097 </term>
2098 <listitem>
2099 <para>When enabled, Valgrind will emit warnings about its CPU
2100 emulation in certain cases. These are usually not
2101 interesting.</para>
2102 </listitem>
2103 </varlistentry>
2104
sewardjf9ebc392010-05-09 22:30:43 +00002105 <varlistentry id="opt.require-text-symbol"
2106 xreflabel="--require-text-symbol">
2107 <term>
2108 <option><![CDATA[--require-text-symbol=:sonamepatt:fnnamepatt]]></option>
2109 </term>
2110 <listitem>
2111 <para>When a shared object whose soname
2112 matches <varname>sonamepatt</varname> is loaded into the
2113 process, examine all the text symbols it exports. If none of
2114 those match <varname>fnnamepatt</varname>, print an error
2115 message and abandon the run. This makes it possible to ensure
2116 that the run does not continue unless a given shared object
2117 contains a particular function name.
2118 </para>
2119 <para>
2120 Both <varname>sonamepatt</varname> and
2121 <varname>fnnamepatt</varname> can be written using the usual
2122 <varname>?</varname> and <varname>*</varname> wildcards. For
2123 example: <varname>":*libc.so*:foo?bar"</varname>. You may use
2124 characters other than a colon to separate the two patterns. It
2125 is only important that the first character and the separator
2126 character are the same. For example, the above example could
2127 also be written <varname>"Q*libc.so*Qfoo?bar"</varname>.
2128 Multiple <varname> --require-text-symbol</varname> flags are
2129 allowed, in which case shared objects that are loaded into
2130 the process will be checked against all of them.
2131 </para>
2132 <para>
2133 The purpose of this is to support reliable usage of marked-up
2134 libraries. For example, suppose we have a version of GCC's
2135 <varname>libgomp.so</varname> which has been marked up with
2136 annotations to support Helgrind. It is only too easy and
2137 confusing to load the wrong, un-annotated
2138 <varname>libgomp.so</varname> into the application. So the idea
2139 is: add a text symbol in the marked-up library, for
2140 example <varname>annotated_for_helgrind_3_6</varname>, and then
2141 give the flag
2142 <varname>--require-text-symbol=:*libgomp*so*:annotated_for_helgrind_3_6</varname>
2143 so that when <varname>libgomp.so</varname> is loaded, Valgrind
2144 scans its symbol table, and if the symbol isn't present the run
2145 is aborted, rather than continuing silently with the
2146 un-marked-up library. Note that you should put the entire flag
2147 in quotes to stop shells expanding up the <varname>*</varname>
2148 and <varname>?</varname> wildcards.
2149 </para>
2150 </listitem>
2151 </varlistentry>
2152
philippe1e470b52012-05-11 19:33:46 +00002153 <varlistentry id="opt.soname-synonyms"
2154 xreflabel="--soname-synonyms">
2155 <term>
2156 <option><![CDATA[--soname-synonyms=syn1=pattern1,syn2=pattern2,...]]></option>
2157 </term>
2158 <listitem>
sewardjca456c72012-08-05 13:44:15 +00002159 <para>When a shared library is loaded, Valgrind checks for
2160 functions in the library that must be replaced or wrapped.
philippe8ee4f332012-08-05 17:23:55 +00002161 For example, Memcheck replaces all malloc related
sewardjca456c72012-08-05 13:44:15 +00002162 functions (malloc, free, calloc, ...) with its own versions.
philippe1e470b52012-05-11 19:33:46 +00002163 Such replacements are done by default only in shared libraries whose
2164 soname matches a predefined soname pattern (e.g.
2165 <varname>libc.so*</varname> on linux).
2166 By default, no replacement is done for a statically linked
2167 library or for alternative libraries such as tcmalloc.
2168 In some cases, the replacements allow
2169 <option>--soname-synonyms</option> to specify one additional
2170 synonym pattern, giving flexibility in the replacement. </para>
2171
sewardjca456c72012-08-05 13:44:15 +00002172 <para>Currently, this flexibility is only allowed for the
philippe1e470b52012-05-11 19:33:46 +00002173 malloc related functions, using the
2174 synonym <varname>somalloc</varname>. This synonym is usable for
2175 all tools doing standard replacement of malloc related functions
2176 (e.g. memcheck, massif, drd, helgrind, exp-dhat, exp-sgcheck).
2177 </para>
2178
2179 <itemizedlist>
2180 <listitem>
2181
2182 <para>Alternate malloc library: to replace the malloc
2183 related functions in an alternate library with
2184 soname <varname>mymalloclib.so</varname>, give the
2185 option <option>--soname-synonyms=somalloc=mymalloclib.so</option>.
2186 A pattern can be used to match multiple libraries sonames.
2187 For
2188 example, <option>--soname-synonyms=somalloc=*tcmalloc*</option>
2189 will match the soname of all variants of the tcmalloc library
2190 (native, debug, profiled, ... tcmalloc variants). </para>
2191 <para>Note: the soname of a elf shared library can be
2192 retrieved using the readelf utility. </para>
2193
2194 </listitem>
2195
2196 <listitem>
2197 <para>Replacements in a statically linked library are done by
2198 using the <varname>NONE</varname> pattern. For example, if
2199 you link with <varname>libtcmalloc.a</varname>, memcheck
2200 will properly work when you give the
2201 option <option>--soname-synonyms=somalloc=NONE</option>. Note
2202 that a NONE pattern will match the main executable and any
2203 shared library having no soname. </para>
2204 </listitem>
sewardjca456c72012-08-05 13:44:15 +00002205
2206 <listitem>
2207 <para>To run a "default" Firefox build for Linux, in which
2208 JEMalloc is linked in to the main executable,
2209 use <option>--soname-synonyms=somalloc=NONE</option>.
2210 </para>
2211 </listitem>
2212
philippe1e470b52012-05-11 19:33:46 +00002213 </itemizedlist>
2214 </listitem>
2215 </varlistentry>
2216
sewardjf9ebc392010-05-09 22:30:43 +00002217
debad57fc2005-12-03 22:33:29 +00002218</variablelist>
de03e0e7c2005-12-03 23:02:33 +00002219<!-- end of xi:include in the manpage -->
debad57fc2005-12-03 22:33:29 +00002220
njn3e986b22004-11-30 10:43:45 +00002221</sect2>
2222
2223
njnf4b47582009-08-10 01:15:30 +00002224<sect2 id="manual-core.debugopts" xreflabel="Debugging Options">
2225<title>Debugging Options</title>
njn3e986b22004-11-30 10:43:45 +00002226
de03e0e7c2005-12-03 23:02:33 +00002227<!-- start of xi:include in the manpage -->
2228<para id="debug.opts.para">There are also some options for debugging
2229Valgrind itself. You shouldn't need to use them in the normal run of
2230things. If you wish to see the list, use the
2231<option>--help-debug</option> option.</para>
sewardj3b290482011-05-06 21:02:55 +00002232
2233<para>If you wish to debug your program rather than debugging
2234Valgrind itself, then you should use the options
2235<option>--vgdb=yes</option> or <option>--vgdb=full</option>
2236or <option>--db-attach=yes</option>.
2237</para>
2238
de03e0e7c2005-12-03 23:02:33 +00002239<!-- end of xi:include in the manpage -->
njn3e986b22004-11-30 10:43:45 +00002240
njn3e986b22004-11-30 10:43:45 +00002241</sect2>
2242
2243
njnf4b47582009-08-10 01:15:30 +00002244<sect2 id="manual-core.defopts" xreflabel="Setting Default Options">
2245<title>Setting Default Options</title>
njn3e986b22004-11-30 10:43:45 +00002246
2247<para>Note that Valgrind also reads options from three places:</para>
2248
2249 <orderedlist>
2250 <listitem>
2251 <para>The file <computeroutput>~/.valgrindrc</computeroutput></para>
2252 </listitem>
2253
2254 <listitem>
2255 <para>The environment variable
2256 <computeroutput>$VALGRIND_OPTS</computeroutput></para>
2257 </listitem>
2258
2259 <listitem>
2260 <para>The file <computeroutput>./.valgrindrc</computeroutput></para>
2261 </listitem>
2262 </orderedlist>
2263
2264<para>These are processed in the given order, before the
2265command-line options. Options processed later override those
2266processed earlier; for example, options in
2267<computeroutput>./.valgrindrc</computeroutput> will take
2268precedence over those in
njn7316df22009-08-04 01:16:01 +00002269<computeroutput>~/.valgrindrc</computeroutput>.
dirka656f3d2008-11-22 12:03:19 +00002270</para>
2271
2272<para>Please note that the <computeroutput>./.valgrindrc</computeroutput>
2273file is ignored if it is marked as world writeable or not owned
njn7316df22009-08-04 01:16:01 +00002274by the current user. This is because the
2275<computeroutput>./.valgrindrc</computeroutput> can contain options that are
2276potentially harmful or can be used by a local attacker to execute code under
2277your user account.
dirka656f3d2008-11-22 12:03:19 +00002278</para>
njn3e986b22004-11-30 10:43:45 +00002279
2280<para>Any tool-specific options put in
2281<computeroutput>$VALGRIND_OPTS</computeroutput> or the
2282<computeroutput>.valgrindrc</computeroutput> files should be
2283prefixed with the tool name and a colon. For example, if you
2284want Memcheck to always do leak checking, you can put the
2285following entry in <literal>~/.valgrindrc</literal>:</para>
2286
2287<programlisting><![CDATA[
2288--memcheck:leak-check=yes]]></programlisting>
2289
2290<para>This will be ignored if any tool other than Memcheck is
2291run. Without the <computeroutput>memcheck:</computeroutput>
2292part, this will cause problems if you select other tools that
2293don't understand
njn7e5d4ed2009-07-30 02:57:52 +00002294<option>--leak-check=yes</option>.</para>
njn3e986b22004-11-30 10:43:45 +00002295
2296</sect2>
2297
2298</sect1>
2299
2300
sewardj778d7832007-11-22 01:21:56 +00002301
2302<sect1 id="manual-core.pthreads" xreflabel="Support for Threads">
2303<title>Support for Threads</title>
2304
sewardje77c7242009-08-16 22:49:53 +00002305<para>Threaded programs are fully supported.</para>
sewardj778d7832007-11-22 01:21:56 +00002306
sewardje77c7242009-08-16 22:49:53 +00002307<para>The main thing to point out with respect to threaded programs is
2308that your program will use the native threading library, but Valgrind
2309serialises execution so that only one (kernel) thread is running at a
2310time. This approach avoids the horrible implementation problems of
2311implementing a truly multithreaded version of Valgrind, but it does
philippe236a71a2012-02-22 20:23:29 +00002312mean that threaded apps never use more than one CPU simultaneously,
2313even if you have a multiprocessor or multicore machine.</para>
sewardje77c7242009-08-16 22:49:53 +00002314
2315<para>Valgrind doesn't schedule the threads itself. It merely ensures
2316that only one thread runs at once, using a simple locking scheme. The
2317actual thread scheduling remains under control of the OS kernel. What
2318this does mean, though, is that your program will see very different
2319scheduling when run on Valgrind than it does when running normally.
2320This is both because Valgrind is serialising the threads, and because
2321the code runs so much slower than normal.</para>
2322
2323<para>This difference in scheduling may cause your program to behave
2324differently, if you have some kind of concurrency, critical race,
2325locking, or similar, bugs. In that case you might consider using the
2326tools Helgrind and/or DRD to track them down.</para>
sewardj778d7832007-11-22 01:21:56 +00002327
njn7316df22009-08-04 01:16:01 +00002328<para>On Linux, Valgrind also supports direct use of the
2329<computeroutput>clone</computeroutput> system call,
2330<computeroutput>futex</computeroutput> and so on.
2331<computeroutput>clone</computeroutput> is supported where either
sewardj778d7832007-11-22 01:21:56 +00002332everything is shared (a thread) or nothing is shared (fork-like); partial
sewardje089f012010-10-13 21:47:29 +00002333sharing will fail.
sewardj778d7832007-11-22 01:21:56 +00002334</para>
2335
philippea02e2672013-03-06 22:39:18 +00002336<!-- Referenced from both the manual and manpage -->
2337<sect2 id="&vg-pthreads-perf-sched-id;" xreflabel="&vg-pthreads-perf-sched-label;">
philippe236a71a2012-02-22 20:23:29 +00002338<title>Scheduling and Multi-Thread Performance</title>
2339
sewardjca456c72012-08-05 13:44:15 +00002340<para>A thread executes code only when it holds the abovementioned
2341lock. After executing some number of instructions, the running thread
2342will release the lock. All threads ready to run will then compete to
2343acquire the lock.</para>
philippe236a71a2012-02-22 20:23:29 +00002344
sewardjca456c72012-08-05 13:44:15 +00002345<para>The <option>--fair-sched</option> option controls the locking mechanism
2346used to serialise thread execution.</para>
philippe236a71a2012-02-22 20:23:29 +00002347
sewardjca456c72012-08-05 13:44:15 +00002348<para>The default pipe based locking mechanism
2349(<option>--fair-sched=no</option>) is available on all
2350platforms. Pipe based locking does not guarantee fairness between
2351threads: it is quite likely that a thread that has just released the
2352lock reacquires it immediately, even though other threads are ready to
2353run. When using pipe based locking, different runs of the same
2354multithreaded application might give very different thread
2355scheduling.</para>
philippe236a71a2012-02-22 20:23:29 +00002356
sewardjca456c72012-08-05 13:44:15 +00002357<para>An alternative locking mechanism, based on futexes, is available
2358on some platforms. If available, it is activated
2359by <option>--fair-sched=yes</option> or
2360<option>--fair-sched=try</option>. Futex based locking ensures
2361fairness (round-robin scheduling) between threads: if multiple threads
2362are ready to run, the lock will be given to the thread which first
2363requested the lock. Note that a thread which is blocked in a system
2364call (e.g. in a blocking read system call) has not (yet) requested the
2365lock: such a thread requests the lock only after the system call is
2366finished.</para>
philippe236a71a2012-02-22 20:23:29 +00002367
sewardjca456c72012-08-05 13:44:15 +00002368<para> The fairness of the futex based locking produces better
2369reproducibility of thread scheduling for different executions of a
2370multithreaded application. This better reproducibility is particularly
2371helpful when using Helgrind or DRD.</para>
philippe236a71a2012-02-22 20:23:29 +00002372
sewardjca456c72012-08-05 13:44:15 +00002373<para>Valgrind's use of thread serialisation implies that only one
2374thread at a time may run. On a multiprocessor/multicore system, the
philippe236a71a2012-02-22 20:23:29 +00002375running thread is assigned to one of the CPUs by the OS kernel
sewardjca456c72012-08-05 13:44:15 +00002376scheduler. When a thread acquires the lock, sometimes the thread will
philippe236a71a2012-02-22 20:23:29 +00002377be assigned to the same CPU as the thread that just released the
sewardjca456c72012-08-05 13:44:15 +00002378lock. Sometimes, the thread will be assigned to another CPU. When
2379using pipe based locking, the thread that just acquired the lock
2380will usually be scheduled on the same CPU as the thread that just
2381released the lock. With the futex based mechanism, the thread that
philippe236a71a2012-02-22 20:23:29 +00002382just acquired the lock will more often be scheduled on another
sewardjca456c72012-08-05 13:44:15 +00002383CPU.</para>
philippe236a71a2012-02-22 20:23:29 +00002384
sewardjca456c72012-08-05 13:44:15 +00002385<para>Valgrind's thread serialisation and CPU assignment by the OS
2386kernel scheduler can interact badly with the CPU frequency scaling
2387available on many modern CPUs. To decrease power consumption, the
philippe236a71a2012-02-22 20:23:29 +00002388frequency of a CPU or core is automatically decreased if the CPU/core
2389has not been used recently. If the OS kernel often assigns the thread
sewardjca456c72012-08-05 13:44:15 +00002390which just acquired the lock to another CPU/core, it is quite likely
2391that this CPU/core is currently at a low frequency. The frequency of
2392this CPU will be increased after some time. However, during this
2393time, the (only) running thread will have run at the low frequency.
2394Once this thread has run for some time, it will release the lock.
2395Another thread will acquire this lock, and might be scheduled again on
2396another CPU whose clock frequency was decreased in the
2397meantime.</para>
philippe236a71a2012-02-22 20:23:29 +00002398
sewardjca456c72012-08-05 13:44:15 +00002399<para>The futex based locking causes threads to change CPUs/cores more
2400often. So, if CPU frequency scaling is activated, the futex based
2401locking might decrease significantly the performance of a
2402multithreaded app running under Valgrind. Performance losses of up to
240350% degradation have been observed, as compared to running on a
2404machine for which CPU frequency scaling has been disabled. The pipe
2405based locking locking scheme also interacts badly with CPU frequency
2406scaling, with performance losses in the range 10..20% having been
2407observed.</para>
philippe236a71a2012-02-22 20:23:29 +00002408
sewardjca456c72012-08-05 13:44:15 +00002409<para>To avoid such performance degradation, you should indicate to
2410the kernel that all CPUs/cores should always run at maximum clock
2411speed. Depending on your Linux distribution, CPU frequency scaling
2412may be controlled using a graphical interface or using command line
philippe236a71a2012-02-22 20:23:29 +00002413such as
2414<computeroutput>cpufreq-selector</computeroutput> or
sewardjca456c72012-08-05 13:44:15 +00002415<computeroutput>cpufreq-set</computeroutput>.
2416</para>
2417
2418<para>An alternative way to avoid these problems is to tell the
2419OS scheduler to tie a Valgrind process to a specific (fixed) CPU using the
2420<computeroutput>taskset</computeroutput> command. This should ensure
2421that the selected CPU does not fall below its maximum frequency
2422setting so long as any thread of the program has work to do.
philippe236a71a2012-02-22 20:23:29 +00002423</para>
2424
2425</sect2>
2426
sewardj778d7832007-11-22 01:21:56 +00002427
2428</sect1>
2429
2430<sect1 id="manual-core.signals" xreflabel="Handling of Signals">
2431<title>Handling of Signals</title>
2432
2433<para>Valgrind has a fairly complete signal implementation. It should be
2434able to cope with any POSIX-compliant use of signals.</para>
2435
2436<para>If you're using signals in clever ways (for example, catching
2437SIGSEGV, modifying page state and restarting the instruction), you're
2438probably relying on precise exceptions. In this case, you will need
philippe0c0291a2012-08-01 22:03:12 +00002439to use <option>--vex-iropt-register-updates=allregs-at-mem-access</option>
2440or <option>--vex-iropt-register-updates=allregs-at-each-insn</option>.
sewardj778d7832007-11-22 01:21:56 +00002441</para>
2442
2443<para>If your program dies as a result of a fatal core-dumping signal,
2444Valgrind will generate its own core file
2445(<computeroutput>vgcore.NNNNN</computeroutput>) containing your program's
njn7316df22009-08-04 01:16:01 +00002446state. You may use this core file for post-mortem debugging with GDB or
sewardj778d7832007-11-22 01:21:56 +00002447similar. (Note: it will not generate a core if your core dump size limit is
24480.) At the time of writing the core dumps do not include all the floating
2449point register information.</para>
2450
2451<para>In the unlikely event that Valgrind itself crashes, the operating system
2452will create a core dump in the usual way.</para>
2453
2454</sect1>
2455
2456
2457
2458
2459
2460
2461
2462
2463<sect1 id="manual-core.install" xreflabel="Building and Installing">
2464<title>Building and Installing Valgrind</title>
2465
2466<para>We use the standard Unix
2467<computeroutput>./configure</computeroutput>,
2468<computeroutput>make</computeroutput>, <computeroutput>make
sewardje089f012010-10-13 21:47:29 +00002469install</computeroutput> mechanism. Once you have completed
sewardj778d7832007-11-22 01:21:56 +00002470<computeroutput>make install</computeroutput> you may then want
2471to run the regression tests
2472with <computeroutput>make regtest</computeroutput>.
2473</para>
2474
sewardje089f012010-10-13 21:47:29 +00002475<para>In addition to the usual
2476<option>--prefix=/path/to/install/tree</option>, there are three
2477 options which affect how Valgrind is built:
sewardj778d7832007-11-22 01:21:56 +00002478<itemizedlist>
2479
2480 <listitem>
2481 <para><option>--enable-inner</option></para>
2482 <para>This builds Valgrind with some special magic hacks which make
2483 it possible to run it on a standard build of Valgrind (what the
2484 developers call "self-hosting"). Ordinarily you should not use
njnf4b47582009-08-10 01:15:30 +00002485 this option as various kinds of safety checks are disabled.
sewardj778d7832007-11-22 01:21:56 +00002486 </para>
2487 </listitem>
2488
2489 <listitem>
sewardj778d7832007-11-22 01:21:56 +00002490 <para><option>--enable-only64bit</option></para>
2491 <para><option>--enable-only32bit</option></para>
sewardje089f012010-10-13 21:47:29 +00002492 <para>On 64-bit platforms (amd64-linux, ppc64-linux,
2493 amd64-darwin), Valgrind is by default built in such a way that
2494 both 32-bit and 64-bit executables can be run. Sometimes this
2495 cleverness is a problem for a variety of reasons. These two
2496 options allow for single-target builds in this situation. If you
2497 issue both, the configure script will complain. Note they are
2498 ignored on 32-bit-only platforms (x86-linux, ppc32-linux,
2499 arm-linux, x86-darwin).
sewardj778d7832007-11-22 01:21:56 +00002500 </para>
2501 </listitem>
2502
2503</itemizedlist>
2504</para>
2505
2506<para>The <computeroutput>configure</computeroutput> script tests
2507the version of the X server currently indicated by the current
2508<computeroutput>$DISPLAY</computeroutput>. This is a known bug.
2509The intention was to detect the version of the current X
2510client libraries, so that correct suppressions could be selected
2511for them, but instead the test checks the server version. This
2512is just plain wrong.</para>
2513
2514<para>If you are building a binary package of Valgrind for
2515distribution, please read <literal>README_PACKAGERS</literal>
2516<xref linkend="dist.readme-packagers"/>. It contains some
2517important information.</para>
2518
2519<para>Apart from that, there's not much excitement here. Let us
2520know if you have build problems.</para>
2521
2522</sect1>
2523
2524
2525
2526<sect1 id="manual-core.problems" xreflabel="If You Have Problems">
2527<title>If You Have Problems</title>
2528
2529<para>Contact us at <ulink url="&vg-url;">&vg-url;</ulink>.</para>
2530
2531<para>See <xref linkend="manual-core.limits"/> for the known
2532limitations of Valgrind, and for a list of programs which are
2533known not to work on it.</para>
2534
2535<para>All parts of the system make heavy use of assertions and
2536internal self-checks. They are permanently enabled, and we have no
2537plans to disable them. If one of them breaks, please mail us!</para>
2538
2539<para>If you get an assertion failure
2540in <filename>m_mallocfree.c</filename>, this may have happened because
njn7316df22009-08-04 01:16:01 +00002541your program wrote off the end of a heap block, or before its
philipped99c26a2012-07-31 22:17:28 +00002542beginning, thus corrupting heap metadata. Valgrind hopefully will have
njn7316df22009-08-04 01:16:01 +00002543emitted a message to that effect before dying in this way.</para>
sewardj778d7832007-11-22 01:21:56 +00002544
2545<para>Read the <xref linkend="FAQ"/> for more advice about common problems,
2546crashes, etc.</para>
2547
2548</sect1>
2549
2550
2551
2552<sect1 id="manual-core.limits" xreflabel="Limitations">
2553<title>Limitations</title>
2554
2555<para>The following list of limitations seems long. However, most
2556programs actually work fine.</para>
2557
njn7316df22009-08-04 01:16:01 +00002558<para>Valgrind will run programs on the supported platforms
2559subject to the following constraints:</para>
sewardj778d7832007-11-22 01:21:56 +00002560
2561 <itemizedlist>
2562 <listitem>
sewardje089f012010-10-13 21:47:29 +00002563 <para>On x86 and amd64, there is no support for 3DNow!
2564 instructions. If the translator encounters these, Valgrind will
2565 generate a SIGILL when the instruction is executed. Apart from
2566 that, on x86 and amd64, essentially all instructions are supported,
sewardj38415e82012-08-05 14:59:39 +00002567 up to and including AVX and AES in 64-bit mode and SSSE3 in 32-bit
sewardjca456c72012-08-05 13:44:15 +00002568 mode. 32-bit mode does in fact support the bare minimum SSE4
2569 instructions to needed to run programs on MacOSX 10.6 on 32-bit
2570 targets.
sewardj778d7832007-11-22 01:21:56 +00002571 </para>
njn7316df22009-08-04 01:16:01 +00002572 </listitem>
sewardj778d7832007-11-22 01:21:56 +00002573
njn7316df22009-08-04 01:16:01 +00002574 <listitem>
sewardje089f012010-10-13 21:47:29 +00002575 <para>On ppc32 and ppc64, almost all integer, floating point and
2576 Altivec instructions are supported. Specifically: integer and FP
2577 insns that are mandatory for PowerPC, the "General-purpose
2578 optional" group (fsqrt, fsqrts, stfiwx), the "Graphics optional"
2579 group (fre, fres, frsqrte, frsqrtes), and the Altivec (also known
2580 as VMX) SIMD instruction set, are supported. Also, instructions
2581 from the Power ISA 2.05 specification, as present in POWER6 CPUs,
2582 are supported.</para>
2583 </listitem>
2584
2585 <listitem>
2586 <para>On ARM, essentially the entire ARMv7-A instruction set
2587 is supported, in both ARM and Thumb mode. ThumbEE and Jazelle are
sewardjbadefc92011-10-27 10:01:17 +00002588 not supported. NEON, VFPv3 and ARMv6 media support is fairly
2589 complete.
sewardje089f012010-10-13 21:47:29 +00002590 </para>
sewardj778d7832007-11-22 01:21:56 +00002591 </listitem>
2592
2593 <listitem>
sewardj778d7832007-11-22 01:21:56 +00002594 <para>If your program does its own memory management, rather than
2595 using malloc/new/free/delete, it should still work, but Memcheck's
sewardje089f012010-10-13 21:47:29 +00002596 error checking won't be so effective. If you describe your
2597 program's memory management scheme using "client requests" (see
2598 <xref linkend="manual-core-adv.clientreq"/>), Memcheck can do
2599 better. Nevertheless, using malloc/new and free/delete is still
2600 the best approach.</para>
sewardj778d7832007-11-22 01:21:56 +00002601 </listitem>
2602
2603 <listitem>
2604 <para>Valgrind's signal simulation is not as robust as it could be.
2605 Basic POSIX-compliant sigaction and sigprocmask functionality is
2606 supplied, but it's conceivable that things could go badly awry if you
2607 do weird things with signals. Workaround: don't. Programs that do
2608 non-POSIX signal tricks are in any case inherently unportable, so
2609 should be avoided if possible.</para>
2610 </listitem>
2611
2612 <listitem>
2613 <para>Machine instructions, and system calls, have been implemented
2614 on demand. So it's possible, although unlikely, that a program will
2615 fall over with a message to that effect. If this happens, please
2616 report all the details printed out, so we can try and implement the
2617 missing feature.</para>
2618 </listitem>
2619
2620 <listitem>
sewardje089f012010-10-13 21:47:29 +00002621 <para>Memory consumption of your program is majorly increased
2622 whilst running under Valgrind's Memcheck tool. This is due to the
2623 large amount of administrative information maintained behind the
2624 scenes. Another cause is that Valgrind dynamically translates the
2625 original executable. Translated, instrumented code is 12-18 times
sewardjca456c72012-08-05 13:44:15 +00002626 larger than the original so you can easily end up with 150+ MB of
sewardje089f012010-10-13 21:47:29 +00002627 translations when running (eg) a web browser.</para>
sewardj778d7832007-11-22 01:21:56 +00002628 </listitem>
2629
2630 <listitem>
2631 <para>Valgrind can handle dynamically-generated code just fine. If
sewardje089f012010-10-13 21:47:29 +00002632 you regenerate code over the top of old code (ie. at the same
2633 memory addresses), if the code is on the stack Valgrind will
2634 realise the code has changed, and work correctly. This is
2635 necessary to handle the trampolines GCC uses to implemented nested
2636 functions. If you regenerate code somewhere other than the stack,
2637 and you are running on an 32- or 64-bit x86 CPU, you will need to
2638 use the <option>--smc-check=all</option> option, and Valgrind will
2639 run more slowly than normal. Or you can add client requests that
2640 tell Valgrind when your program has overwritten code.
2641 </para>
2642 <para> On other platforms (ARM, PowerPC) Valgrind observes and
2643 honours the cache invalidation hints that programs are obliged to
2644 emit to notify new code, and so self-modifying-code support should
2645 work automatically, without the need
2646 for <option>--smc-check=all</option>.</para>
sewardj778d7832007-11-22 01:21:56 +00002647 </listitem>
2648
2649 <listitem>
njn7316df22009-08-04 01:16:01 +00002650 <para>Valgrind has the following limitations
sewardj778d7832007-11-22 01:21:56 +00002651 in its implementation of x86/AMD64 floating point relative to
2652 IEEE754.</para>
2653
2654 <para>Precision: There is no support for 80 bit arithmetic.
2655 Internally, Valgrind represents all such "long double" numbers in 64
2656 bits, and so there may be some differences in results. Whether or
2657 not this is critical remains to be seen. Note, the x86/amd64
2658 fldt/fstpt instructions (read/write 80-bit numbers) are correctly
2659 simulated, using conversions to/from 64 bits, so that in-memory
2660 images of 80-bit numbers look correct if anyone wants to see.</para>
2661
2662 <para>The impression observed from many FP regression tests is that
2663 the accuracy differences aren't significant. Generally speaking, if
2664 a program relies on 80-bit precision, there may be difficulties
2665 porting it to non x86/amd64 platforms which only support 64-bit FP
2666 precision. Even on x86/amd64, the program may get different results
2667 depending on whether it is compiled to use SSE2 instructions (64-bits
2668 only), or x87 instructions (80-bit). The net effect is to make FP
2669 programs behave as if they had been run on a machine with 64-bit IEEE
2670 floats, for example PowerPC. On amd64 FP arithmetic is done by
2671 default on SSE2, so amd64 looks more like PowerPC than x86 from an FP
2672 perspective, and there are far fewer noticeable accuracy differences
2673 than with x86.</para>
2674
2675 <para>Rounding: Valgrind does observe the 4 IEEE-mandated rounding
2676 modes (to nearest, to +infinity, to -infinity, to zero) for the
2677 following conversions: float to integer, integer to float where
2678 there is a possibility of loss of precision, and float-to-float
2679 rounding. For all other FP operations, only the IEEE default mode
2680 (round to nearest) is supported.</para>
2681
2682 <para>Numeric exceptions in FP code: IEEE754 defines five types of
2683 numeric exception that can happen: invalid operation (sqrt of
2684 negative number, etc), division by zero, overflow, underflow,
2685 inexact (loss of precision).</para>
2686
2687 <para>For each exception, two courses of action are defined by IEEE754:
2688 either (1) a user-defined exception handler may be called, or (2) a
2689 default action is defined, which "fixes things up" and allows the
2690 computation to proceed without throwing an exception.</para>
2691
2692 <para>Currently Valgrind only supports the default fixup actions.
2693 Again, feedback on the importance of exception support would be
2694 appreciated.</para>
2695
2696 <para>When Valgrind detects that the program is trying to exceed any
2697 of these limitations (setting exception handlers, rounding mode, or
2698 precision control), it can print a message giving a traceback of
2699 where this has happened, and continue execution. This behaviour used
2700 to be the default, but the messages are annoying and so showing them
2701 is now disabled by default. Use <option>--show-emwarns=yes</option> to see
2702 them.</para>
2703
2704 <para>The above limitations define precisely the IEEE754 'default'
2705 behaviour: default fixup on all exceptions, round-to-nearest
2706 operations, and 64-bit precision.</para>
2707 </listitem>
2708
2709 <listitem>
njn7316df22009-08-04 01:16:01 +00002710 <para>Valgrind has the following limitations in
sewardj778d7832007-11-22 01:21:56 +00002711 its implementation of x86/AMD64 SSE2 FP arithmetic, relative to
2712 IEEE754.</para>
2713
2714 <para>Essentially the same: no exceptions, and limited observance of
2715 rounding mode. Also, SSE2 has control bits which make it treat
2716 denormalised numbers as zero (DAZ) and a related action, flush
2717 denormals to zero (FTZ). Both of these cause SSE2 arithmetic to be
2718 less accurate than IEEE requires. Valgrind detects, ignores, and can
2719 warn about, attempts to enable either mode.</para>
2720 </listitem>
2721
2722 <listitem>
sewardje089f012010-10-13 21:47:29 +00002723 <para>Valgrind has the following limitations in
2724 its implementation of ARM VFPv3 arithmetic, relative to
2725 IEEE754.</para>
2726
2727 <para>Essentially the same: no exceptions, and limited observance
2728 of rounding mode. Also, switching the VFP unit into vector mode
2729 will cause Valgrind to abort the program -- it has no way to
2730 emulate vector uses of VFP at a reasonable performance level. This
2731 is no big deal given that non-scalar uses of VFP instructions are
2732 in any case deprecated.</para>
2733 </listitem>
2734
2735 <listitem>
njn7316df22009-08-04 01:16:01 +00002736 <para>Valgrind has the following limitations
sewardj778d7832007-11-22 01:21:56 +00002737 in its implementation of PPC32 and PPC64 floating point
2738 arithmetic, relative to IEEE754.</para>
2739
2740 <para>Scalar (non-Altivec): Valgrind provides a bit-exact emulation of
2741 all floating point instructions, except for "fre" and "fres", which are
2742 done more precisely than required by the PowerPC architecture specification.
2743 All floating point operations observe the current rounding mode.
2744 </para>
2745
2746 <para>However, fpscr[FPRF] is not set after each operation. That could
2747 be done but would give measurable performance overheads, and so far
2748 no need for it has been found.</para>
2749
2750 <para>As on x86/AMD64, IEEE754 exceptions are not supported: all floating
2751 point exceptions are handled using the default IEEE fixup actions.
2752 Valgrind detects, ignores, and can warn about, attempts to unmask
2753 the 5 IEEE FP exception kinds by writing to the floating-point status
2754 and control register (fpscr).
2755 </para>
2756
2757 <para>Vector (Altivec, VMX): essentially as with x86/AMD64 SSE/SSE2:
2758 no exceptions, and limited observance of rounding mode.
2759 For Altivec, FP arithmetic
2760 is done in IEEE/Java mode, which is more accurate than the Linux default
2761 setting. "More accurate" means that denormals are handled properly,
2762 rather than simply being flushed to zero.</para>
2763 </listitem>
2764 </itemizedlist>
2765
2766 <para>Programs which are known not to work are:</para>
2767 <itemizedlist>
2768 <listitem>
2769 <para>emacs starts up but immediately concludes it is out of
2770 memory and aborts. It may be that Memcheck does not provide
2771 a good enough emulation of the
2772 <computeroutput>mallinfo</computeroutput> function.
2773 Emacs works fine if you build it to use
2774 the standard malloc/free routines.</para>
2775 </listitem>
2776 </itemizedlist>
2777
2778</sect1>
2779
2780
2781<sect1 id="manual-core.example" xreflabel="An Example Run">
2782<title>An Example Run</title>
2783
2784<para>This is the log for a run of a small program using Memcheck.
2785The program is in fact correct, and the reported error is as the
2786result of a potentially serious code generation bug in GNU g++
2787(snapshot 20010527).</para>
2788
2789<programlisting><![CDATA[
2790sewardj@phoenix:~/newmat10$ ~/Valgrind-6/valgrind -v ./bogon
2791==25832== Valgrind 0.10, a memory error detector for x86 RedHat 7.1.
2792==25832== Copyright (C) 2000-2001, and GNU GPL'd, by Julian Seward.
2793==25832== Startup, with flags:
2794==25832== --suppressions=/home/sewardj/Valgrind/redhat71.supp
2795==25832== reading syms from /lib/ld-linux.so.2
2796==25832== reading syms from /lib/libc.so.6
2797==25832== reading syms from /mnt/pima/jrs/Inst/lib/libgcc_s.so.0
2798==25832== reading syms from /lib/libm.so.6
2799==25832== reading syms from /mnt/pima/jrs/Inst/lib/libstdc++.so.3
2800==25832== reading syms from /home/sewardj/Valgrind/valgrind.so
2801==25832== reading syms from /proc/self/exe
2802==25832==
2803==25832== Invalid read of size 4
2804==25832== at 0x8048724: BandMatrix::ReSize(int,int,int) (bogon.cpp:45)
2805==25832== by 0x80487AF: main (bogon.cpp:66)
2806==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd
2807==25832==
2808==25832== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
2809==25832== malloc/free: in use at exit: 0 bytes in 0 blocks.
2810==25832== malloc/free: 0 allocs, 0 frees, 0 bytes allocated.
2811==25832== For a detailed leak analysis, rerun with: --leak-check=yes
2812]]></programlisting>
2813
njn7316df22009-08-04 01:16:01 +00002814<para>The GCC folks fixed this about a week before GCC 3.0
sewardj778d7832007-11-22 01:21:56 +00002815shipped.</para>
2816
2817</sect1>
2818
2819
2820<sect1 id="manual-core.warnings" xreflabel="Warning Messages">
2821<title>Warning Messages You Might See</title>
2822
njn7316df22009-08-04 01:16:01 +00002823<para>Some of these only appear if you run in verbose mode
njn7e5d4ed2009-07-30 02:57:52 +00002824(enabled by <option>-v</option>):</para>
sewardj778d7832007-11-22 01:21:56 +00002825
2826 <itemizedlist>
2827
2828 <listitem>
2829 <para><computeroutput>More than 100 errors detected. Subsequent
2830 errors will still be recorded, but in less detail than
2831 before.</computeroutput></para>
2832
2833 <para>After 100 different errors have been shown, Valgrind becomes
2834 more conservative about collecting them. It then requires only the
2835 program counters in the top two stack frames to match when deciding
2836 whether or not two errors are really the same one. Prior to this
2837 point, the PCs in the top four frames are required to match. This
2838 hack has the effect of slowing down the appearance of new errors
2839 after the first 100. The 100 constant can be changed by recompiling
2840 Valgrind.</para>
2841 </listitem>
2842
2843 <listitem>
2844 <para><computeroutput>More than 1000 errors detected. I'm not
2845 reporting any more. Final error counts may be inaccurate. Go fix
2846 your program!</computeroutput></para>
2847
2848 <para>After 1000 different errors have been detected, Valgrind
2849 ignores any more. It seems unlikely that collecting even more
2850 different ones would be of practical help to anybody, and it avoids
2851 the danger that Valgrind spends more and more of its time comparing
2852 new errors against an ever-growing collection. As above, the 1000
2853 number is a compile-time constant.</para>
2854 </listitem>
2855
2856 <listitem>
2857 <para><computeroutput>Warning: client switching stacks?</computeroutput></para>
2858
2859 <para>Valgrind spotted such a large change in the stack pointer
philippe20465932013-03-13 22:03:31 +00002860 that it guesses the client is switching to a different stack. At
2861 this point it makes a kludgey guess where the base of the new
2862 stack is, and sets memory permissions accordingly. At the moment
2863 "large change" is defined as a change of more that 2000000 in the
2864 value of the stack pointer register. If Valgrind guesses wrong,
2865 you may get many bogus error messages following this and/or have
2866 crashes in the stack trace recording code. You might avoid these
2867 problems by informing Valgrind about the stack bounds using
2868 VALGRIND_STACK_REGISTER client request. </para>
2869
sewardj778d7832007-11-22 01:21:56 +00002870 </listitem>
2871
2872 <listitem>
2873 <para><computeroutput>Warning: client attempted to close Valgrind's
2874 logfile fd &lt;number&gt;</computeroutput></para>
2875
2876 <para>Valgrind doesn't allow the client to close the logfile,
2877 because you'd never see any diagnostic information after that point.
2878 If you see this message, you may want to use the
2879 <option>--log-fd=&lt;number&gt;</option> option to specify a
2880 different logfile file-descriptor number.</para>
2881 </listitem>
2882
2883 <listitem>
2884 <para><computeroutput>Warning: noted but unhandled ioctl
2885 &lt;number&gt;</computeroutput></para>
2886
2887 <para>Valgrind observed a call to one of the vast family of
2888 <computeroutput>ioctl</computeroutput> system calls, but did not
2889 modify its memory status info (because nobody has yet written a
2890 suitable wrapper). The call will still have gone through, but you may get
2891 spurious errors after this as a result of the non-update of the
2892 memory info.</para>
2893 </listitem>
2894
2895 <listitem>
2896 <para><computeroutput>Warning: set address range perms: large range
2897 &lt;number></computeroutput></para>
2898
2899 <para>Diagnostic message, mostly for benefit of the Valgrind
2900 developers, to do with memory permissions.</para>
2901 </listitem>
2902
2903 </itemizedlist>
2904
2905</sect1>
2906
2907
2908
sewardjf5a491c2006-03-13 13:40:57 +00002909
2910
sewardja737e652006-03-19 18:19:11 +00002911
njn3e986b22004-11-30 10:43:45 +00002912</chapter>