1 <?xml version="1.0"?> <!-- -*- sgml -*- -->
2 <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"
4 [ <!ENTITY % vg-entities SYSTEM "vg-entities.xml"> %vg-entities; ]>
7 <chapter id="manual-core" xreflabel="Valgrind's core">
8 <title>Using and understanding the Valgrind core</title>
10 <para>This chapter describes the Valgrind core services, command-line
11 options and behaviours. That means it is relevant regardless of what
12 particular tool you are using. The information should be sufficient for you
13 to make effective day-to-day use of Valgrind. Advanced topics related to
14 the Valgrind core are described in <xref linkend="manual-core-adv"/>.
18 A point of terminology: most references to "Valgrind" in this chapter
19 refer to the Valgrind core services. </para>
23 <sect1 id="manual-core.whatdoes"
24 xreflabel="What Valgrind does with your program">
25 <title>What Valgrind does with your program</title>
27 <para>Valgrind is designed to be as non-intrusive as possible. It works
28 directly with existing executables. You don't need to recompile, relink,
29 or otherwise modify the program to be checked.</para>
31 <para>You invoke Valgrind like this:</para>
32 <programlisting><![CDATA[
33 valgrind [valgrind-options] your-prog [your-prog-options]]]></programlisting>
35 <para>The most important option is <option>--tool</option> which dictates
36 which Valgrind tool to run. For example, if want to run the command
37 <computeroutput>ls -l</computeroutput> using the memory-checking tool
38 Memcheck, issue this command:</para>
40 <programlisting><![CDATA[
41 valgrind --tool=memcheck ls -l]]></programlisting>
43 <para>However, Memcheck is the default, so if you want to use it you can
44 omit the <option>--tool</option> option.</para>
46 <para>Regardless of which tool is in use, Valgrind takes control of your
47 program before it starts. Debugging information is read from the
48 executable and associated libraries, so that error messages and other
49 outputs can be phrased in terms of source code locations, when
52 <para>Your program is then run on a synthetic CPU provided by the
53 Valgrind core. As new code is executed for the first time, the core
54 hands the code to the selected tool. The tool adds its own
55 instrumentation code to this and hands the result back to the core,
56 which coordinates the continued execution of this instrumented
59 <para>The amount of instrumentation code added varies widely between
60 tools. At one end of the scale, Memcheck adds code to check every
61 memory access and every value computed,
62 making it run 10-50 times slower than natively.
63 At the other end of the spectrum, the minimal tool, called Nulgrind,
64 adds no instrumentation at all and causes in total "only" about a 4 times
67 <para>Valgrind simulates every single instruction your program executes.
68 Because of this, the active tool checks, or profiles, not only the code
69 in your application but also in all supporting dynamically-linked libraries,
70 including the C library, graphical libraries, and so on.</para>
72 <para>If you're using an error-detection tool, Valgrind may
73 detect errors in system libraries, for example the GNU C or X11
74 libraries, which you have to use. You might not be interested in these
75 errors, since you probably have no control over that code. Therefore,
76 Valgrind allows you to selectively suppress errors, by recording them in
77 a suppressions file which is read when Valgrind starts up. The build
78 mechanism selects default suppressions which give reasonable
79 behaviour for the OS and libraries detected on your machine.
80 To make it easier to write suppressions, you can use the
81 <option>--gen-suppressions=yes</option> option. This tells Valgrind to
82 print out a suppression for each reported error, which you can then
83 copy into a suppressions file.</para>
85 <para>Valgrind will try to match the behaviour of applications
86 compiled to run on the same OS and libraries that Valgrind was
87 built with. If you use different libraries or a different
88 OS version there may be some small differences in behaviour.</para>
90 <para>Different error-checking tools report different kinds of errors.
91 The suppression mechanism therefore allows you to say which tool or
92 tool(s) each suppression applies to.</para>
97 <sect1 id="manual-core.started" xreflabel="Getting started">
98 <title>Getting started</title>
100 <para>First off, consider whether it might be beneficial to recompile
101 your application and supporting libraries with debugging info enabled
102 (the <option>-g</option> option). Without debugging info, the best
103 Valgrind tools will be able to do is guess which function a particular
104 piece of code belongs to, which makes both error messages and profiling
105 output nearly useless. With <option>-g</option>, you'll get
106 messages which point directly to the relevant source code lines.</para>
108 <para>Another option you might like to consider, if you are working with
109 C++, is <option>-fno-inline</option>. That makes it easier to see the
110 function-call chain, which can help reduce confusion when navigating
111 around large C++ apps. For example, debugging
112 OpenOffice.org with Memcheck is a bit easier when using this option. You
113 don't have to do this, but doing so helps Valgrind produce more accurate
114 and less confusing error reports. Chances are you're set up like this
115 already, if you intended to debug your program with GNU GDB, or some
116 other debugger. Alternatively, the Valgrind option
117 <option>--read-inline-info=yes</option> instructs Valgrind to read
118 the debug information describing inlining information. With this,
119 function call chain will be properly shown, even when your application
120 is compiled with inlining. </para>
122 <para>If you are planning to use Memcheck: On rare
123 occasions, compiler optimisations (at <option>-O2</option>
124 and above, and sometimes <option>-O1</option>) have been
125 observed to generate code which fools Memcheck into wrongly reporting
126 uninitialised value errors, or missing uninitialised value errors. We have
127 looked in detail into fixing this, and unfortunately the result is that
128 doing so would give a further significant slowdown in what is already a slow
129 tool. So the best solution is to turn off optimisation altogether. Since
130 this often makes things unmanageably slow, a reasonable compromise is to use
131 <option>-O</option>. This gets you the majority of the
132 benefits of higher optimisation levels whilst keeping relatively small the
133 chances of false positives or false negatives from Memcheck. Also, you
134 should compile your code with <option>-Wall</option> because
135 it can identify some or all of the problems that Valgrind can miss at the
136 higher optimisation levels. (Using <option>-Wall</option>
137 is also a good idea in general.) All other tools (as far as we know) are
138 unaffected by optimisation level, and for profiling tools like Cachegrind it
139 is better to compile your program at its normal optimisation level.</para>
141 <para>Valgrind understands the DWARF2/3/4 formats used by GCC 3.1 and
142 later. The reader for "stabs" debugging format (used by GCC versions
143 prior to 3.1) has been disabled in Valgrind 3.9.0.</para>
145 <para>When you're ready to roll, run Valgrind as described above.
146 Note that you should run the real
147 (machine-code) executable here. If your application is started by, for
148 example, a shell or Perl script, you'll need to modify it to invoke
149 Valgrind on the real executables. Running such scripts directly under
150 Valgrind will result in you getting error reports pertaining to
151 <filename>/bin/sh</filename>,
152 <filename>/usr/bin/perl</filename>, or whatever interpreter
153 you're using. This may not be what you want and can be confusing. You
154 can force the issue by giving the option
155 <option>--trace-children=yes</option>, but confusion is still
161 <!-- Referenced from both the manual and manpage -->
162 <sect1 id="&vg-comment-id;" xreflabel="&vg-comment-label;">
163 <title>The Commentary</title>
165 <para>Valgrind tools write a commentary, a stream of text, detailing
166 error reports and other significant events. All lines in the commentary
169 <programlisting><![CDATA[
170 ==12345== some-message-from-Valgrind]]></programlisting>
173 <para>The <computeroutput>12345</computeroutput> is the process ID.
174 This scheme makes it easy to distinguish program output from Valgrind
175 commentary, and also easy to differentiate commentaries from different
176 processes which have become merged together, for whatever reason.</para>
178 <para>By default, Valgrind tools write only essential messages to the
179 commentary, so as to avoid flooding you with information of secondary
180 importance. If you want more information about what is happening,
181 re-run, passing the <option>-v</option> option to Valgrind. A second
182 <option>-v</option> gives yet more detail.
185 <para>You can direct the commentary to three different places:</para>
189 <listitem id="manual-core.out2fd" xreflabel="Directing output to fd">
190 <para>The default: send it to a file descriptor, which is by default
191 2 (stderr). So, if you give the core no options, it will write
192 commentary to the standard error stream. If you want to send it to
193 some other file descriptor, for example number 9, you can specify
194 <option>--log-fd=9</option>.</para>
196 <para>This is the simplest and most common arrangement, but can
197 cause problems when Valgrinding entire trees of processes which
198 expect specific file descriptors, particularly stdin/stdout/stderr,
199 to be available for their own use.</para>
202 <listitem id="manual-core.out2file"
203 xreflabel="Directing output to file"> <para>A less intrusive
204 option is to write the commentary to a file, which you specify by
205 <option>--log-file=filename</option>. There are special format
206 specifiers that can be used to use a process ID or an environment
207 variable name in the log file name. These are useful/necessary if your
208 program invokes multiple processes (especially for MPI programs).
209 See the <link linkend="manual-core.basicopts">basic options section</link>
210 for more details.</para>
213 <listitem id="manual-core.out2socket"
214 xreflabel="Directing output to network socket"> <para>The
215 least intrusive option is to send the commentary to a network
216 socket. The socket is specified as an IP address and port number
217 pair, like this: <option>--log-socket=192.168.0.1:12345</option> if
218 you want to send the output to host IP 192.168.0.1 port 12345
220 have no idea if 12345 is a port of pre-existing significance). You
221 can also omit the port number:
222 <option>--log-socket=192.168.0.1</option>, in which case a default
223 port of 1500 is used. This default is defined by the constant
224 <computeroutput>VG_CLO_DEFAULT_LOGPORT</computeroutput> in the
227 <para>Note, unfortunately, that you have to use an IP address here,
228 rather than a hostname.</para>
230 <para>Writing to a network socket is pointless if you don't
231 have something listening at the other end. We provide a simple
233 <computeroutput>valgrind-listener</computeroutput>, which accepts
234 connections on the specified port and copies whatever it is sent to
235 stdout. Probably someone will tell us this is a horrible security
236 risk. It seems likely that people will write more sophisticated
237 listeners in the fullness of time.</para>
239 <para><computeroutput>valgrind-listener</computeroutput> can accept
240 simultaneous connections from up to 50 Valgrinded processes. In front
241 of each line of output it prints the current number of active
242 connections in round brackets.</para>
244 <para><computeroutput>valgrind-listener</computeroutput> accepts three
245 command-line options:</para>
246 <!-- start of xi:include in the manpage -->
247 <variablelist id="listener.opts.list">
249 <term><option>-e --exit-at-zero</option></term>
251 <para>When the number of connected processes falls back to zero,
252 exit. Without this, it will run forever, that is, until you
253 send it Control-C.</para>
257 <term><option>--max-connect=INTEGER</option></term>
259 <para>By default, the listener can connect to up to 50 processes.
260 Occasionally, that number is too small. Use this option to
261 provide a different limit. E.g.
262 <computeroutput>--max-connect=100</computeroutput>.
267 <term><option>portnumber</option></term>
269 <para>Changes the port it listens on from the default (1500).
270 The specified port must be in the range 1024 to 65535.
271 The same restriction applies to port numbers specified by a
272 <option>--log-socket</option> to Valgrind itself.</para>
276 <!-- end of xi:include in the manpage -->
278 <para>If a Valgrinded process fails to connect to a listener, for
279 whatever reason (the listener isn't running, invalid or unreachable
280 host or port, etc), Valgrind switches back to writing the commentary
281 to stderr. The same goes for any process which loses an established
282 connection to a listener. In other words, killing the listener
283 doesn't kill the processes sending data to it.</para>
288 <para>Here is an important point about the relationship between the
289 commentary and profiling output from tools. The commentary contains a
290 mix of messages from the Valgrind core and the selected tool. If the
291 tool reports errors, it will report them to the commentary. However, if
292 the tool does profiling, the profile data will be written to a file of
293 some kind, depending on the tool, and independent of what
294 <option>--log-*</option> options are in force. The commentary is
295 intended to be a low-bandwidth, human-readable channel. Profiling data,
296 on the other hand, is usually voluminous and not meaningful without
297 further processing, which is why we have chosen this arrangement.</para>
302 <sect1 id="manual-core.report" xreflabel="Reporting of errors">
303 <title>Reporting of errors</title>
305 <para>When an error-checking tool
306 detects something bad happening in the program, an error
307 message is written to the commentary. Here's an example from Memcheck:</para>
309 <programlisting><![CDATA[
310 ==25832== Invalid read of size 4
311 ==25832== at 0x8048724: BandMatrix::ReSize(int, int, int) (bogon.cpp:45)
312 ==25832== by 0x80487AF: main (bogon.cpp:66)
313 ==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd]]></programlisting>
315 <para>This message says that the program did an illegal 4-byte read of
316 address 0xBFFFF74C, which, as far as Memcheck can tell, is not a valid
317 stack address, nor corresponds to any current heap blocks or recently freed
318 heap blocks. The read is happening at line 45 of
319 <filename>bogon.cpp</filename>, called from line 66 of the same file,
320 etc. For errors associated with an identified (current or freed) heap block,
321 for example reading freed memory, Valgrind reports not only the
322 location where the error happened, but also where the associated heap block
323 was allocated/freed.</para>
325 <para>Valgrind remembers all error reports. When an error is detected,
326 it is compared against old reports, to see if it is a duplicate. If so,
327 the error is noted, but no further commentary is emitted. This avoids
328 you being swamped with bazillions of duplicate error reports.</para>
330 <para>If you want to know how many times each error occurred, run with
331 the <option>-v</option> option. When execution finishes, all the
332 reports are printed out, along with, and sorted by, their occurrence
333 counts. This makes it easy to see which errors have occurred most
336 <para>Errors are reported before the associated operation actually
337 happens. For example, if you're using Memcheck and your program attempts to
338 read from address zero, Memcheck will emit a message to this effect, and
339 your program will then likely die with a segmentation fault.</para>
341 <para>In general, you should try and fix errors in the order that they
342 are reported. Not doing so can be confusing. For example, a program
343 which copies uninitialised values to several memory locations, and later
344 uses them, will generate several error messages, when run on Memcheck.
345 The first such error message may well give the most direct clue to the
346 root cause of the problem.</para>
348 <para>The process of detecting duplicate errors is quite an
349 expensive one and can become a significant performance overhead
350 if your program generates huge quantities of errors. To avoid
351 serious problems, Valgrind will simply stop collecting
352 errors after 1,000 different errors have been seen, or 10,000,000 errors
353 in total have been seen. In this situation you might as well
354 stop your program and fix it, because Valgrind won't tell you
355 anything else useful after this. Note that the 1,000/10,000,000 limits
356 apply after suppressed errors are removed. These limits are
357 defined in <filename>m_errormgr.c</filename> and can be increased
360 <para>To avoid this cutoff you can use the
361 <option>--error-limit=no</option> option. Then Valgrind will always show
362 errors, regardless of how many there are. Use this option carefully,
363 since it may have a bad effect on performance.</para>
368 <sect1 id="manual-core.suppress" xreflabel="Suppressing errors">
369 <title>Suppressing errors</title>
371 <para>The error-checking tools detect numerous problems in the system
372 libraries, such as the C library,
373 which come pre-installed with your OS. You can't easily fix
374 these, but you don't want to see these errors (and yes, there are many!)
375 So Valgrind reads a list of errors to suppress at startup. A default
376 suppression file is created by the
377 <computeroutput>./configure</computeroutput> script when the system is
380 <para>You can modify and add to the suppressions file at your leisure,
381 or, better, write your own. Multiple suppression files are allowed.
382 This is useful if part of your project contains errors you can't or
383 don't want to fix, yet you don't want to continuously be reminded of
386 <formalpara><title>Note:</title> <para>By far the easiest way to add
387 suppressions is to use the <option>--gen-suppressions=yes</option> option
388 described in <xref linkend="manual-core.options"/>. This generates
389 suppressions automatically. For best results,
390 though, you may want to edit the output
391 of <option>--gen-suppressions=yes</option> by hand, in which
392 case it would be advisable to read through this section.
396 <para>Each error to be suppressed is described very specifically, to
397 minimise the possibility that a suppression-directive inadvertently
398 suppresses a bunch of similar errors which you did want to see. The
399 suppression mechanism is designed to allow precise yet flexible
400 specification of errors to suppress.</para>
402 <para>If you use the <option>-v</option> option, at the end of execution,
403 Valgrind prints out one line for each used suppression, giving the number of times
404 it got used, its name and the filename and line number where the suppression is
405 defined. Depending on the suppression kind, the filename and line number are optionally
406 followed by additional information (such as the number of blocks and bytes suppressed
407 by a Memcheck leak suppression). Here's the suppressions used by a
408 run of <computeroutput>valgrind -v --tool=memcheck ls -l</computeroutput>:</para>
410 <programlisting><![CDATA[
411 --1610-- used_suppression: 2 dl-hack3-cond-1 /usr/lib/valgrind/default.supp:1234
412 --1610-- used_suppression: 2 glibc-2.5.x-on-SUSE-10.2-(PPC)-2a /usr/lib/valgrind/default.supp:1234
415 <para>Multiple suppressions files are allowed. Valgrind loads suppression
416 patterns from <filename>$PREFIX/lib/valgrind/default.supp</filename> unless
417 <option>--default-suppressions=no</option> has been specified. You can
418 ask to add suppressions from additional files by specifying
419 <option>--suppressions=/path/to/file.supp</option> one or more times.
422 <para>If you want to understand more about suppressions, look at an
423 existing suppressions file whilst reading the following documentation.
424 The file <filename>glibc-2.3.supp</filename>, in the source
425 distribution, provides some good examples.</para>
427 <para>Blank and comment lines in a suppression file are ignored. Comment lines
428 are made of 0 or more blanks followed by a # character followed by some
431 <para>Each suppression has the following components:</para>
436 <para>First line: its name. This merely gives a handy name to the
437 suppression, by which it is referred to in the summary of used
438 suppressions printed out when a program finishes. It's not
439 important what the name is; any identifying string will do.</para>
443 <para>Second line: name of the tool(s) that the suppression is for
444 (if more than one, comma-separated), and the name of the suppression
445 itself, separated by a colon (n.b.: no spaces are allowed), eg:</para>
446 <programlisting><![CDATA[
447 tool_name1,tool_name2:suppression_name]]></programlisting>
449 <para>Recall that Valgrind is a modular system, in which
450 different instrumentation tools can observe your program whilst it
451 is running. Since different tools detect different kinds of errors,
452 it is necessary to say which tool(s) the suppression is meaningful
455 <para>Tools will complain, at startup, if a tool does not understand
456 any suppression directed to it. Tools ignore suppressions which are
457 not directed to them. As a result, it is quite practical to put
458 suppressions for all tools into the same suppression file.</para>
462 <para>Next line: a small number of suppression types have extra
463 information after the second line (eg. the <varname>Param</varname>
464 suppression for Memcheck)</para>
468 <para>Remaining lines: This is the calling context for the error --
469 the chain of function calls that led to it. There can be up to 24
470 of these lines.</para>
472 <para>Locations may be names of either shared objects, functions,
473 or source lines. They begin with
474 <computeroutput>obj:</computeroutput>,
475 <computeroutput>fun:</computeroutput>, or
476 <computeroutput>src:</computeroutput> respectively. Function,
477 object, and file names to match against may use the wildcard characters
478 <computeroutput>*</computeroutput> and
479 <computeroutput>?</computeroutput>. Source lines are specified
480 using the form <filename>filename[:lineNumber]</filename>.</para>
482 <para><command>Important note: </command> C++ function names must be
483 <command>mangled</command>. If you are writing suppressions by
484 hand, use the <option>--demangle=no</option> option to get the
485 mangled names in your error messages. An example of a mangled
486 C++ name is <computeroutput>_ZN9QListView4showEv</computeroutput>.
487 This is the form that the GNU C++ compiler uses internally, and
488 the form that must be used in suppression files. The equivalent
489 demangled name, <computeroutput>QListView::show()</computeroutput>,
490 is what you see at the C++ source code level.
493 <para>A location line may also be
494 simply "<computeroutput>...</computeroutput>" (three dots). This is
495 a frame-level wildcard, which matches zero or more frames. Frame
496 level wildcards are useful because they make it easy to ignore
497 varying numbers of uninteresting frames in between frames of
498 interest. That is often important when writing suppressions which
499 are intended to be robust against variations in the amount of
500 function inlining done by compilers.</para>
504 <para>Finally, the entire suppression must be between curly
505 braces. Each brace must be the first character on its own
511 <para>A suppression only suppresses an error when the error matches all
512 the details in the suppression. Here's an example:</para>
514 <programlisting><![CDATA[
516 __gconv_transform_ascii_internal/__mbrtowc/mbtowc
518 fun:__gconv_transform_ascii_internal
521 }]]></programlisting>
524 <para>What it means is: for Memcheck only, suppress a
525 use-of-uninitialised-value error, when the data size is 4, when it
526 occurs in the function
527 <computeroutput>__gconv_transform_ascii_internal</computeroutput>, when
528 that is called from any function of name matching
529 <computeroutput>__mbr*toc</computeroutput>, when that is called from
530 <computeroutput>mbtowc</computeroutput>. It doesn't apply under any
531 other circumstances. The string by which this suppression is identified
533 <computeroutput>__gconv_transform_ascii_internal/__mbrtowc/mbtowc</computeroutput>.</para>
535 <para>(See <xref linkend="mc-manual.suppfiles"/> for more details
536 on the specifics of Memcheck's suppression kinds.)</para>
538 <para>Another example, again for the Memcheck tool:</para>
540 <programlisting><![CDATA[
542 libX11.so.6.2/libX11.so.6.2/libXaw.so.7.0
544 obj:/usr/X11R6/lib/libX11.so.6.2
545 obj:/usr/X11R6/lib/libX11.so.6.2
546 obj:/usr/X11R6/lib/libXaw.so.7.0
547 }]]></programlisting>
549 <para>This suppresses any size 4 uninitialised-value error which occurs
550 anywhere in <filename>libX11.so.6.2</filename>, when called from
551 anywhere in the same library, when called from anywhere in
552 <filename>libXaw.so.7.0</filename>. The inexact specification of
553 locations is regrettable, but is about all you can hope for, given that
554 the X11 libraries shipped on the Linux distro on which this example
555 was made have had their symbol tables removed.</para>
557 <para>An example of the src: specification, again for the Memcheck tool:</para>
559 <programlisting><![CDATA[
561 libX11.so.6.2/libX11.so.6.2/libXaw.so.7.0
564 }]]></programlisting>
566 <para>This suppresses any size-4 uninitialised-value error which occurs
567 at line 321 in <filename>valid.c</filename>.</para>
569 <para>Although the above two examples do not make this clear, you can
570 freely mix <computeroutput>obj:</computeroutput>,
571 <computeroutput>fun:</computeroutput>, and
572 <computeroutput>src:</computeroutput>
573 lines in a suppression.</para>
575 <para>Finally, here's an example using three frame-level wildcards:</para>
577 <programlisting><![CDATA[
590 <para>This suppresses Memcheck memory-leak errors, in the case where
591 the allocation was done by <computeroutput>main</computeroutput>
592 calling (though any number of intermediaries, including zero)
593 <computeroutput>ccc</computeroutput>,
595 <computeroutput>ddd</computeroutput> and eventually
596 to <computeroutput>malloc.</computeroutput>.</para>
600 <sect1 id="manual-core.debuginfod"
601 xreflabel="Debuginfod">
602 <title>Debuginfod</title>
604 <para id="debuginfod.para.1">Valgrind supports the downloading of debuginfo
605 files via debuginfod, an HTTP server for distributing ELF/DWARF debugging
606 information. When a debuginfo file cannot be found locally, Valgrind is able
607 to query debuginfod servers for the file using the file's build-id.</para>
609 <para id="debuginfod.para.2">In order to use this feature
610 <computeroutput>debuginfod-find</computeroutput> must be installed and the
611 <computeroutput>$DEBUGINFOD_URLS</computeroutput> environment variable must
612 contain space-separated URLs of debuginfod servers. Valgrind does not support
613 <computeroutput>debuginfod-find</computeroutput> verbose output that is
614 normally enabled with <computeroutput>$DEBUGINFOD_PROGRESS</computeroutput>
615 and <computeroutput>$DEBUGINFOD_VERBOSE</computeroutput>. These environment
616 variables will be ignored. This feature is supported on Linux only.</para>
618 <para id="debuginfod.para.3">For more information regarding debuginfod, see
619 <ulink url="https://sourceware.org/elfutils/Debuginfod.html">Elfutils Debuginfod</ulink>
625 <sect1 id="manual-core.options"
626 xreflabel="Core Command-line Options">
627 <title>Core Command-line Options</title>
629 <para>As mentioned above, Valgrind's core accepts a common set of options.
630 The tools also accept tool-specific options, which are documented
631 separately for each tool.</para>
633 <para>Valgrind's default settings succeed in giving reasonable behaviour
634 in most cases. We group the available options by rough categories.</para>
636 <sect2 id="manual-core.toolopts" xreflabel="Tool-selection Option">
637 <title>Tool-selection Option</title>
639 <para id="tool.opts.para">The single most important option.</para>
641 <variablelist id="tool.opts.list">
643 <varlistentry id="tool_name" xreflabel="--tool">
645 <option><![CDATA[--tool=<toolname> [default: memcheck] ]]></option>
648 <para>Run the Valgrind tool called <varname>toolname</varname>,
649 e.g. memcheck, cachegrind, callgrind, helgrind, drd, massif,
650 dhat, lackey, none, exp-bbv, etc.</para>
660 <sect2 id="manual-core.basicopts" xreflabel="Basic Options">
661 <title>Basic Options</title>
663 <!-- start of xi:include in the manpage -->
664 <para id="basic.opts.para">These options work with all tools.</para>
666 <variablelist id="basic.opts.list">
668 <varlistentry id="opt.help" xreflabel="--help">
669 <term><option>-h --help</option></term>
671 <para>Show help for all options, both for the core and for the
672 selected tool. If the option is repeated it is equivalent to giving
673 <option>--help-debug</option>.</para>
677 <varlistentry id="opt.help-debug" xreflabel="--help-debug">
678 <term><option>--help-debug</option></term>
680 <para>Same as <option>--help</option>, but also lists debugging
681 options which usually are only of use to Valgrind's
686 <varlistentry id="opt.version" xreflabel="--version">
687 <term><option>--version</option></term>
689 <para>Show the version number of the Valgrind core. Tools can have
690 their own version numbers. There is a scheme in place to ensure
691 that tools only execute when the core version is one they are
692 known to work with. This was done to minimise the chances of
693 strange problems arising from tool-vs-core version
694 incompatibilities.</para>
698 <varlistentry id="opt.quiet" xreflabel="--quiet">
699 <term><option>-q</option>, <option>--quiet</option></term>
701 <para>Run silently, and only print error messages. Useful if you
702 are running regression tests or have some other automated test
707 <varlistentry id="opt.verbose" xreflabel="--verbose">
708 <term><option>-v</option>, <option>--verbose</option></term>
710 <para>Be more verbose. Gives extra information on various aspects
711 of your program, such as: the shared objects loaded, the
712 suppressions used, the progress of the instrumentation and
713 execution engines, and warnings about unusual behaviour. Repeating
714 the option increases the verbosity level.</para>
718 <varlistentry id="opt.trace-children" xreflabel="--trace-children">
720 <option><![CDATA[--trace-children=<yes|no> [default: no] ]]></option>
723 <para>When enabled, Valgrind will trace into sub-processes
724 initiated via the <varname>exec</varname> system call. This is
725 necessary for multi-process programs.
727 <para>Note that Valgrind does trace into the child of a
728 <varname>fork</varname> (it would be difficult not to, since
729 <varname>fork</varname> makes an identical copy of a process), so this
730 option is arguably badly named. However, most children of
731 <varname>fork</varname> calls immediately call <varname>exec</varname>
737 <varlistentry id="opt.trace-children-skip" xreflabel="--trace-children-skip">
739 <option><![CDATA[--trace-children-skip=patt1,patt2,... ]]></option>
742 <para>This option only has an effect when
743 <option>--trace-children=yes</option> is specified. It allows
744 for some children to be skipped. The option takes a comma
745 separated list of patterns for the names of child executables
746 that Valgrind should not trace into. Patterns may include the
747 metacharacters <computeroutput>?</computeroutput>
748 and <computeroutput>*</computeroutput>, which have the usual
751 This can be useful for pruning uninteresting branches from a
752 tree of processes being run on Valgrind. But you should be
753 careful when using it. When Valgrind skips tracing into an
754 executable, it doesn't just skip tracing that executable, it
755 also skips tracing any of that executable's child processes.
756 In other words, the flag doesn't merely cause tracing to stop
757 at the specified executables -- it skips tracing of entire
758 process subtrees rooted at any of the specified
763 <varlistentry id="opt.trace-children-skip-by-arg"
764 xreflabel="--trace-children-skip-by-arg">
766 <option><![CDATA[--trace-children-skip-by-arg=patt1,patt2,... ]]></option>
769 <para>This is the same as
770 <option>--trace-children-skip</option>, with one difference:
771 the decision as to whether to trace into a child process is
772 made by examining the arguments to the child process, rather
773 than the name of its executable.</para>
777 <varlistentry id="opt.child-silent-after-fork"
778 xreflabel="--child-silent-after-fork">
780 <option><![CDATA[--child-silent-after-fork=<yes|no> [default: no] ]]></option>
783 <para>When enabled, Valgrind will not show any debugging or
784 logging output for the child process resulting from
785 a <varname>fork</varname> call. This can make the output less
786 confusing (although more misleading) when dealing with processes
787 that create children. It is particularly useful in conjunction
788 with <varname>--trace-children=</varname>. Use of this option is also
789 strongly recommended if you are requesting XML output
790 (<varname>--xml=yes</varname>), since otherwise the XML from child and
791 parent may become mixed up, which usually makes it useless.
796 <varlistentry id="opt.vgdb" xreflabel="--vgdb">
798 <option><![CDATA[--vgdb=<no|yes|full> [default: yes] ]]></option>
802 <para>Valgrind will provide "gdbserver" functionality when
803 <option>--vgdb=yes</option> or <option>--vgdb=full</option> is
804 specified. This allows an external GNU GDB debugger to control
805 and debug your program when it runs on Valgrind.
806 <option>--vgdb=full</option> incurs significant performance
807 overheads, but provides more precise breakpoints and
808 watchpoints. See <xref linkend="manual-core-adv.gdbserver"/> for
809 a detailed description.
812 <para> If the embedded gdbserver is enabled but no gdb is
813 currently being used, the <xref linkend="manual-core-adv.vgdb"/>
814 command line utility can send "monitor commands" to Valgrind
815 from a shell. The Valgrind core provides a set of
816 <xref linkend="manual-core-adv.valgrind-monitor-commands"/>. A tool
817 can optionally provide tool specific monitor commands, which are
818 documented in the tool specific chapter.
824 <varlistentry id="opt.vgdb-error" xreflabel="--vgdb-error">
826 <option><![CDATA[--vgdb-error=<number> [default: 999999999] ]]></option>
829 <para> Use this option when the Valgrind gdbserver is enabled with
830 <option>--vgdb=yes</option> or <option>--vgdb=full</option>.
831 Tools that report errors will wait
832 for "<computeroutput>number</computeroutput>" errors to be
833 reported before freezing the program and waiting for you to
834 connect with GDB. It follows that a value of zero will cause
835 the gdbserver to be started before your program is executed.
836 This is typically used to insert GDB breakpoints before
837 execution, and also works with tools that do not report
838 errors, such as Massif.
843 <varlistentry id="opt.vgdb-stop-at" xreflabel="--vgdb-stop-at">
845 <option><![CDATA[--vgdb-stop-at=<set> [default: none] ]]></option>
848 <para> Use this option when the Valgrind gdbserver is enabled with
849 <option>--vgdb=yes</option> or <option>--vgdb=full</option>.
850 The Valgrind gdbserver will be invoked for each error after
851 <option>--vgdb-error</option> have been reported.
852 You can additionally ask the Valgrind gdbserver to be invoked
853 for other events, specified in one of the following ways: </para>
855 <listitem><para>a comma separated list of one or more of
856 <option>startup exit abexit valgrindabexit</option>.</para>
858 <para>The values <option>startup</option> <option>exit</option>
859 <option>valgrindabexit</option> respectively indicate to invoke
860 gdbserver before your program is executed, after the last instruction
861 of your program, on Valgrind abnormal exit (e.g. internal error, out
862 of memory, ...).</para>
864 <para>The option <option>abexit</option> is similar to <option>exit</option>
865 but tells to invoke gdbserver only when your application exits abnormally
866 (i.e. with an exit code different of 0). </para>
868 <para>Note: <option>startup</option> and
869 <option>--vgdb-error=0</option> will both cause Valgrind
870 gdbserver to be invoked before your program is executed. The
871 <option>--vgdb-error=0</option> will in addition cause your
872 program to stop on all subsequent errors.</para>
876 <listitem><para><option>all</option> to specify the complete set.
878 <option>--vgdb-stop-at=startup,exit,abexit,valgrindabexit</option>.</para>
881 <listitem><para><option>none</option> for the empty set.</para>
887 <varlistentry id="opt.track-fds" xreflabel="--track-fds">
889 <option><![CDATA[--track-fds=<yes|no|all> [default: no] ]]></option>
892 <para>When enabled, Valgrind will print out a list of open file
893 descriptors on exit or on request, via the gdbserver monitor
894 command <varname>v.info open_fds</varname>. Along with each
895 file descriptor is printed a stack backtrace of where the file
896 was opened and any details relating to the file descriptor such
897 as the file name or socket details. Use <option>all</option> to
898 include reporting on <computeroutput>stdin</computeroutput>,
899 <computeroutput>stdout</computeroutput> and
900 <computeroutput>stderr</computeroutput>.</para>
904 <varlistentry id="opt.time-stamp" xreflabel="--time-stamp">
906 <option><![CDATA[--time-stamp=<yes|no> [default: no] ]]></option>
909 <para>When enabled, each message is preceded with an indication of
910 the elapsed wallclock time since startup, expressed as days,
911 hours, minutes, seconds and milliseconds.</para>
915 <varlistentry id="opt.log-fd" xreflabel="--log-fd">
917 <option><![CDATA[--log-fd=<number> [default: 2, stderr] ]]></option>
920 <para>Specifies that Valgrind should send all of its messages to
921 the specified file descriptor. The default, 2, is the standard
922 error channel (stderr). Note that this may interfere with the
923 client's own use of stderr, as Valgrind's output will be
924 interleaved with any output that the client sends to
929 <varlistentry id="opt.log-file" xreflabel="--log-file">
931 <option><![CDATA[--log-file=<filename> ]]></option>
934 <para>Specifies that Valgrind should send all of its messages to
935 the specified file. If the file name is empty, it causes an abort.
936 There are three special format specifiers that can be used in the file
939 <para><option>%p</option> is replaced with the current process ID.
940 This is very useful for program that invoke multiple processes.
941 WARNING: If you use <option>--trace-children=yes</option> and your
942 program invokes multiple processes OR your program forks without
943 calling exec afterwards, and you don't use this specifier
944 (or the <option>%q</option> specifier below), the Valgrind output from
945 all those processes will go into one file, possibly jumbled up, and
946 possibly incomplete. Note: If the program forks and calls exec afterwards,
947 Valgrind output of the child from the period between fork and exec
948 will be lost. Fortunately this gap is really tiny for most programs;
949 and modern programs use <computeroutput>posix_spawn</computeroutput>
952 <para><option>%n</option> is replaced with a file sequence number
953 unique for this process.
954 This is useful for processes that produces several files
955 from the same filename template.</para>
958 <para><option>%q{FOO}</option> is replaced with the contents of the
959 environment variable <varname>FOO</varname>. If the
960 <option>{FOO}</option> part is malformed, it causes an abort. This
961 specifier is rarely needed, but very useful in certain circumstances
962 (eg. when running MPI programs). The idea is that you specify a
963 variable which will be set differently for each process in the job,
964 for example <computeroutput>BPROC_RANK</computeroutput> or whatever is
965 applicable in your MPI setup. If the named environment variable is not
966 set, it causes an abort. Note that in some shells, the
967 <option>{</option> and <option>}</option> characters may need to be
968 escaped with a backslash.</para>
970 <para><option>%%</option> is replaced with <option>%</option>.</para>
972 <para>If an <option>%</option> is followed by any other character, it
973 causes an abort.</para>
975 <para>If the file name specifies a relative file name, it is put
976 in the program's initial working directory: this is the current
977 directory when the program started its execution after the fork
978 or after the exec. If it specifies an absolute file name (ie.
979 starts with '/') then it is put there.
984 <varlistentry id="opt.log-socket" xreflabel="--log-socket">
986 <option><![CDATA[--log-socket=<ip-address:port-number> ]]></option>
989 <para>Specifies that Valgrind should send all of its messages to
990 the specified port at the specified IP address. The port may be
991 omitted, in which case port 1500 is used. If a connection cannot
992 be made to the specified socket, Valgrind falls back to writing
993 output to the standard error (stderr). This option is intended to
994 be used in conjunction with the
995 <computeroutput>valgrind-listener</computeroutput> program. For
997 <link linkend="&vg-comment-id;">the commentary</link>
998 in the manual.</para>
1002 <varlistentry id="opt.enable-debuginfod" xreflabel="--enable-debuginfod">
1004 <option><![CDATA[--enable-debuginfod=<no|yes> [default: yes] ]]></option>
1007 <para>When enabled Valgrind will attempt to download missing debuginfo
1008 from debuginfod servers if space-separated server URLs are present
1009 in the <computeroutput>$DEBUGINFOD_URLS</computeroutput> environment
1010 variable. This option is supported on Linux only.
1011 <!-- commented out because it causes broken links in the man page
1012 For more information see <xref linkend="manual-core.debuginfod"/>.
1018 <!-- end of xi:include in the manpage -->
1023 <sect2 id="manual-core.erropts" xreflabel="Error-related Options">
1024 <title>Error-related Options</title>
1026 <!-- start of xi:include in the manpage -->
1027 <para id="error-related.opts.para">These options are used by all tools
1028 that can report errors, e.g. Memcheck, but not Cachegrind.</para>
1030 <variablelist id="error-related.opts.list">
1032 <varlistentry id="opt.xml" xreflabel="--xml">
1034 <option><![CDATA[--xml=<yes|no> [default: no] ]]></option>
1037 <para>When enabled, the important parts of the output (e.g. tool error
1038 messages) will be in XML format rather than plain text. Furthermore,
1039 the XML output will be sent to a different output channel than the
1040 plain text output. Therefore, you also must use one of
1041 <option>--xml-fd</option>, <option>--xml-file</option> or
1042 <option>--xml-socket</option> to specify where the XML is to be sent.
1045 <para>Less important messages will still be printed in plain text, but
1046 because the XML output and plain text output are sent to different
1047 output channels (the destination of the plain text output is still
1048 controlled by <option>--log-fd</option>, <option>--log-file</option>
1049 and <option>--log-socket</option>) this should not cause problems.
1052 <para>This option is aimed at making life easier for tools that consume
1053 Valgrind's output as input, such as GUI front ends. Currently this
1054 option works with Memcheck, Helgrind and DRD. The output format is
1055 specified in the file
1056 <computeroutput>docs/internals/xml-output-protocol4.txt</computeroutput>
1057 in the source tree for Valgrind 3.5.0 or later.</para>
1059 <para>The recommended options for a GUI to pass, when requesting
1060 XML output, are: <option>--xml=yes</option> to enable XML output,
1061 <option>--xml-file</option> to send the XML output to a (presumably
1062 GUI-selected) file, <option>--log-file</option> to send the plain
1063 text output to a second GUI-selected file,
1064 <option>--child-silent-after-fork=yes</option>, and
1065 <option>-q</option> to restrict the plain text output to critical
1066 error messages created by Valgrind itself. For example, failure to
1067 read a specified suppressions file counts as a critical error message.
1068 In this way, for a successful run the text output file will be empty.
1069 But if it isn't empty, then it will contain important information
1070 which the GUI user should be made aware
1075 <varlistentry id="opt.xml-fd" xreflabel="--xml-fd">
1077 <option><![CDATA[--xml-fd=<number> [default: -1, disabled] ]]></option>
1080 <para>Specifies that Valgrind should send its XML output to the
1081 specified file descriptor. It must be used in conjunction with
1082 <option>--xml=yes</option>.</para>
1086 <varlistentry id="opt.xml-file" xreflabel="--xml-file">
1088 <option><![CDATA[--xml-file=<filename> ]]></option>
1091 <para>Specifies that Valgrind should send its XML output
1092 to the specified file. It must be used in conjunction with
1093 <option>--xml=yes</option>. Any <option>%p</option> or
1094 <option>%q</option> sequences appearing in the filename are expanded
1095 in exactly the same way as they are for <option>--log-file</option>.
1096 See the description of <xref linkend="opt.log-file"/> for details.
1101 <varlistentry id="opt.xml-socket" xreflabel="--xml-socket">
1103 <option><![CDATA[--xml-socket=<ip-address:port-number> ]]></option>
1106 <para>Specifies that Valgrind should send its XML output the
1107 specified port at the specified IP address. It must be used in
1108 conjunction with <option>--xml=yes</option>. The form of the argument
1109 is the same as that used by <option>--log-socket</option>.
1110 See the description of <option>--log-socket</option>
1111 for further details.</para>
1115 <varlistentry id="opt.xml-user-comment" xreflabel="--xml-user-comment">
1117 <option><![CDATA[--xml-user-comment=<string> ]]></option>
1120 <para>Embeds an extra user comment string at the start of the XML
1121 output. Only works when <option>--xml=yes</option> is specified;
1122 ignored otherwise.</para>
1126 <varlistentry id="opt.demangle" xreflabel="--demangle">
1128 <option><![CDATA[--demangle=<yes|no> [default: yes] ]]></option>
1131 <para>Enable/disable automatic demangling (decoding) of C++ names.
1132 Enabled by default. When enabled, Valgrind will attempt to
1133 translate encoded C++ names back to something approaching the
1134 original. The demangler handles symbols mangled by g++ versions
1135 2.X, 3.X and 4.X.</para>
1137 <para>An important fact about demangling is that function names
1138 mentioned in suppressions files should be in their mangled form.
1139 Valgrind does not demangle function names when searching for
1140 applicable suppressions, because to do otherwise would make
1141 suppression file contents dependent on the state of Valgrind's
1142 demangling machinery, and also slow down suppression matching.</para>
1146 <varlistentry id="opt.num-callers" xreflabel="--num-callers">
1148 <option><![CDATA[--num-callers=<number> [default: 12] ]]></option>
1151 <para>Specifies the maximum number of entries shown in stack traces
1152 that identify program locations. Note that errors are commoned up
1153 using only the top four function locations (the place in the current
1154 function, and that of its three immediate callers). So this doesn't
1155 affect the total number of errors reported.</para>
1157 <para>The maximum value for this is 500. Note that higher settings
1158 will make Valgrind run a bit more slowly and take a bit more
1159 memory, but can be useful when working with programs with
1160 deeply-nested call chains.</para>
1164 <varlistentry id="opt.unw-stack-scan-thresh"
1165 xreflabel="--unw-stack-scan-thresh">
1167 <option><![CDATA[--unw-stack-scan-thresh=<number> [default: 0] ]]></option>
1170 <option><![CDATA[--unw-stack-scan-frames=<number> [default: 5] ]]></option>
1173 <para>Stack-scanning support is available only on ARM
1176 <para>These flags enable and control stack unwinding by stack
1177 scanning. When the normal stack unwinding mechanisms -- usage
1178 of Dwarf CFI records, and frame-pointer following -- fail, stack
1179 scanning may be able to recover a stack trace.</para>
1181 <para>Note that stack scanning is an imprecise, heuristic
1182 mechanism that may give very misleading results, or none at all.
1183 It should be used only in emergencies, when normal unwinding
1184 fails, and it is important to nevertheless have stack
1187 <para>Stack scanning is a simple technique: the unwinder reads
1188 words from the stack, and tries to guess which of them might be
1189 return addresses, by checking to see if they point just after
1190 ARM or Thumb call instructions. If so, the word is added to the
1193 <para>The main danger occurs when a function call returns,
1194 leaving its return address exposed, and a new function is
1195 called, but the new function does not overwrite the old address.
1196 The result of this is that the backtrace may contain entries for
1197 functions which have already returned, and so be very
1200 <para>A second limitation of this implementation is that it will
1201 scan only the page (4KB, normally) containing the starting stack
1202 pointer. If the stack frames are large, this may result in only
1203 a few (or not even any) being present in the trace. Also, if
1204 you are unlucky and have an initial stack pointer near the end
1205 of its containing page, the scan may miss all interesting
1208 <para>By default stack scanning is disabled. The normal use
1209 case is to ask for it when a stack trace would otherwise be very
1210 short. So, to enable it,
1211 use <computeroutput>--unw-stack-scan-thresh=number</computeroutput>.
1212 This requests Valgrind to try using stack scanning to "extend"
1213 stack traces which contain fewer
1214 than <computeroutput>number</computeroutput> frames.</para>
1216 <para>If stack scanning does take place, it will only generate
1217 at most the number of frames specified
1218 by <computeroutput>--unw-stack-scan-frames</computeroutput>.
1219 Typically, stack scanning generates so many garbage entries that
1220 this value is set to a low value (5) by default. In no case
1221 will a stack trace larger than the value specified
1222 by <computeroutput>--num-callers</computeroutput> be
1227 <varlistentry id="opt.error-limit" xreflabel="--error-limit">
1229 <option><![CDATA[--error-limit=<yes|no> [default: yes] ]]></option>
1232 <para>When enabled, Valgrind stops reporting errors after 10,000,000
1233 in total, or 1,000 different ones, have been seen. This is to
1234 stop the error tracking machinery from becoming a huge performance
1235 overhead in programs with many errors.</para>
1239 <varlistentry id="opt.error-exitcode" xreflabel="--error-exitcode">
1241 <option><![CDATA[--error-exitcode=<number> [default: 0] ]]></option>
1244 <para>Specifies an alternative exit code to return if Valgrind
1245 reported any errors in the run. When set to the default value
1246 (zero), the return value from Valgrind will always be the return
1247 value of the process being simulated. When set to a nonzero value,
1248 that value is returned instead, if Valgrind detects any errors.
1249 This is useful for using Valgrind as part of an automated test
1250 suite, since it makes it easy to detect test cases for which
1251 Valgrind has reported errors, just by inspecting return codes.
1252 When set to a nonzero value and Valgrind detects no error,
1253 the return value of Valgrind will be the return value of the
1254 program being simulated.
1259 <varlistentry id="opt.exit-on-first-error" xreflabel="--exit-on-first-error">
1261 <option><![CDATA[--exit-on-first-error=<yes|no> [default: no] ]]></option>
1264 <para>If this option is enabled, Valgrind exits on the first error.
1265 A nonzero exit value must be defined using
1266 <computeroutput>--error-exitcode</computeroutput> option.
1267 Useful if you are running regression tests or have some other
1268 automated test machinery.</para>
1272 <varlistentry id="opt.error-markers" xreflabel="--error-markers">
1274 <option><![CDATA[--error-markers=<begin>,<end> [default: none]]]></option>
1277 <para>When errors are output as plain text (i.e. XML not used),
1278 <option>--error-markers</option> instructs to output a line
1279 containing the <option>begin</option> (<option>end</option>)
1280 string before (after) each error. </para>
1281 <para> Such marker lines facilitate searching for errors and/or
1282 extracting errors in an output file that contain valgrind errors mixed
1283 with the program output. </para>
1284 <para> Note that empty markers are accepted. So, only using a begin
1285 (or an end) marker is possible.</para>
1289 <varlistentry id="opt.show-error-list" xreflabel="--show-error-list">
1291 <option><![CDATA[--show-error-list=no|yes|all [default: no]]]></option>
1294 <para>If this option is yes, for tools that report errors, valgrind
1295 will show the list of detected errors and the list of used suppressions
1296 at exit. The value all indicates to also show the list of suppressed
1299 <para>Note that at verbosity 2 and above, valgrind automatically shows
1300 the list of detected errors and the list of used suppressions
1301 at exit, unless <option>--show-error-list=no</option> is selected.
1306 <varlistentry id="opt.s" xreflabel="-s">
1308 <option><![CDATA[-s]]></option>
1311 <para>Specifying <option>-s</option> is equivalent to
1312 <option>--show-error-list=yes</option>.
1318 <varlistentry id="opt.sigill-diagnostics" xreflabel="--sigill-diagnostics">
1320 <option><![CDATA[--sigill-diagnostics=<yes|no> [default: yes] ]]></option>
1323 <para>Enable/disable printing of illegal instruction diagnostics.
1324 Enabled by default, but defaults to disabled when
1325 <option>--quiet</option> is given. The default can always be explicitly
1326 overridden by giving this option.</para>
1328 <para>When enabled, a warning message will be printed, along with some
1329 diagnostics, whenever an instruction is encountered that Valgrind
1330 cannot decode or translate, before the program is given a SIGILL signal.
1331 Often an illegal instruction indicates a bug in the program or missing
1332 support for the particular instruction in Valgrind. But some programs
1333 do deliberately try to execute an instruction that might be missing
1334 and trap the SIGILL signal to detect processor features. Using
1335 this flag makes it possible to avoid the diagnostic output
1336 that you would otherwise get in such cases.</para>
1340 <varlistentry id="opt.keep-debuginfo" xreflabel="--keep-debuginfo">
1342 <option><![CDATA[--keep-debuginfo=<yes|no> [default: no] ]]></option>
1345 <para>When enabled, keep ("archive") symbols and all other debuginfo
1346 for unloaded code. This allows saved stack traces to include file/line
1347 info for code that has been dlclose'd (or similar). Be careful with
1348 this, since it can lead to unbounded memory use for programs which
1349 repeatedly load and unload shared objects.</para>
1350 <para>Some tools and some functionalities have only limited support
1351 for archived debug info. Memcheck fully supports it. Generally,
1352 tools that report errors can use archived debug info to show the error
1353 stack traces. The known limitations are: Helgrind's past access stack
1354 trace of a race condition is does not use archived debug info. Massif
1355 (and more generally the xtree Massif output format) does not make use
1356 of archived debug info. Only Memcheck has been (somewhat) tested
1357 with <option>--keep-debuginfo=yes</option>, so other tools may have
1358 unknown limitations. </para>
1362 <varlistentry id="opt.show-below-main" xreflabel="--show-below-main">
1364 <option><![CDATA[--show-below-main=<yes|no> [default: no] ]]></option>
1367 <para>By default, stack traces for errors do not show any
1368 functions that appear beneath <function>main</function> because
1369 most of the time it's uninteresting C library stuff and/or
1370 gobbledygook. Alternatively, if <function>main</function> is not
1371 present in the stack trace, stack traces will not show any functions
1372 below <function>main</function>-like functions such as glibc's
1373 <function>__libc_start_main</function>. Furthermore, if
1374 <function>main</function>-like functions are present in the trace,
1375 they are normalised as <function>(below main)</function>, in order to
1376 make the output more deterministic.</para>
1378 <para>If this option is enabled, all stack trace entries will be
1379 shown and <function>main</function>-like functions will not be
1384 <varlistentry id="opt.fullpath-after" xreflabel="--fullpath-after">
1386 <option><![CDATA[--fullpath-after=<string>
1387 [default: don't show source paths] ]]></option>
1390 <para>By default Valgrind only shows the filenames in stack
1391 traces, but not full paths to source files. When using Valgrind
1392 in large projects where the sources reside in multiple different
1393 directories, this can be inconvenient.
1394 <option>--fullpath-after</option> provides a flexible solution
1395 to this problem. When this option is present, the path to each
1396 source file is shown, with the following all-important caveat:
1397 if <option>string</option> is found in the path, then the path
1398 up to and including <option>string</option> is omitted, else the
1399 path is shown unmodified. Note that <option>string</option> is
1400 not required to be a prefix of the path.</para>
1402 <para>For example, consider a file named
1403 <computeroutput>/home/janedoe/blah/src/foo/bar/xyzzy.c</computeroutput>.
1404 Specifying <option>--fullpath-after=/home/janedoe/blah/src/</option>
1405 will cause Valgrind to show the name
1406 as <computeroutput>foo/bar/xyzzy.c</computeroutput>.</para>
1408 <para>Because the string is not required to be a prefix,
1409 <option>--fullpath-after=src/</option> will produce the same
1410 output. This is useful when the path contains arbitrary
1411 machine-generated characters. For example, the
1413 <computeroutput>/my/build/dir/C32A1B47/blah/src/foo/xyzzy</computeroutput>
1414 can be pruned to <computeroutput>foo/xyzzy</computeroutput>
1416 <option>--fullpath-after=/blah/src/</option>.</para>
1418 <para>If you simply want to see the full path, just specify an
1419 empty string: <option>--fullpath-after=</option>. This isn't a
1420 special case, merely a logical consequence of the above rules.</para>
1422 <para>Finally, you can use <option>--fullpath-after</option>
1423 multiple times. Any appearance of it causes Valgrind to switch
1424 to producing full paths and applying the above filtering rule.
1425 Each produced path is compared against all
1426 the <option>--fullpath-after</option>-specified strings, in the
1427 order specified. The first string to match causes the path to
1428 be truncated as described above. If none match, the full path
1429 is shown. This facilitates chopping off prefixes when the
1430 sources are drawn from a number of unrelated directories.
1435 <varlistentry id="opt.extra-debuginfo-path" xreflabel="--extra-debuginfo-path">
1437 <option><![CDATA[--extra-debuginfo-path=<path> [default: undefined and unused] ]]></option>
1440 <para>By default Valgrind searches in several well-known paths
1441 for debug objects, such
1442 as <computeroutput>/usr/lib/debug/</computeroutput>.</para>
1444 <para>However, there may be scenarios where you may wish to put
1445 debug objects at an arbitrary location, such as external storage
1446 when running Valgrind on a mobile device with limited local
1447 storage. Another example might be a situation where you do not
1448 have permission to install debug object packages on the system
1449 where you are running Valgrind.</para>
1451 <para>In these scenarios, you may provide an absolute path as an extra,
1452 final place for Valgrind to search for debug objects by specifying
1453 <option>--extra-debuginfo-path=/path/to/debug/objects</option>.
1454 The given path will be prepended to the absolute path name of
1455 the searched-for object. For example, if Valgrind is looking
1457 for <computeroutput>/w/x/y/zz.so</computeroutput>
1458 and <option>--extra-debuginfo-path=/a/b/c</option> is specified,
1459 it will look for a debug object at
1460 <computeroutput>/a/b/c/w/x/y/zz.so</computeroutput>.</para>
1462 <para>This flag should only be specified once. If it is
1463 specified multiple times, only the last instance is
1468 <varlistentry id="opt.debuginfo-server" xreflabel="--debuginfo-server">
1470 <option><![CDATA[--debuginfo-server=ipaddr:port [default: undefined and unused]]]></option>
1473 <para>This is a new, experimental, feature introduced in version
1476 <para>In some scenarios it may be convenient to read debuginfo
1477 from objects stored on a different machine. With this flag,
1478 Valgrind will query a debuginfo server running
1479 on <computeroutput>ipaddr</computeroutput> and listening on
1480 port <computeroutput>port</computeroutput>, if it cannot find
1481 the debuginfo object in the local filesystem.</para>
1483 <para>The debuginfo server must accept TCP connections on
1484 port <computeroutput>port</computeroutput>. The debuginfo
1485 server is contained in the source
1486 file <computeroutput>auxprogs/valgrind-di-server.c</computeroutput>.
1487 It will only serve from the directory it is started
1488 in. <computeroutput>port</computeroutput> defaults to 1500 in
1489 both client and server if not specified.</para>
1491 <para>If Valgrind looks for the debuginfo for
1492 <computeroutput>/w/x/y/zz.so</computeroutput> by using the
1493 debuginfo server, it will strip the pathname components and
1494 merely request <computeroutput>zz.so</computeroutput> on the
1495 server. That in turn will look only in its current working
1496 directory for a matching debuginfo object.</para>
1498 <para>The debuginfo data is transmitted in small fragments (8
1499 KB) as requested by Valgrind. Each block is compressed using
1500 LZO to reduce transmission time. The implementation has been
1501 tuned for best performance over a single-stage 802.11g (WiFi)
1502 network link.</para>
1504 <para>Note that checks for matching primary vs debug objects,
1505 using GNU debuglink CRC scheme, are performed even when using
1506 the debuginfo server. To disable such checking, you need to
1508 <computeroutput>--allow-mismatched-debuginfo=yes</computeroutput>.
1511 <para>By default the Valgrind build system will
1512 build <computeroutput>valgrind-di-server</computeroutput> for
1513 the target platform, which is almost certainly not what you
1514 want. So far we have been unable to find out how to get
1515 automake/autoconf to build it for the build platform. If
1516 you want to use it, you will have to recompile it by hand using
1517 the command shown at the top
1518 of <computeroutput>auxprogs/valgrind-di-server.c</computeroutput>.</para>
1520 <para>Valgrind can also download debuginfo via debuginfod. See the
1521 DEBUGINFOD section for more information.</para>
1526 <varlistentry id="opt.allow-mismatched-debuginfo"
1527 xreflabel="--allow-mismatched-debuginfo">
1529 <option><![CDATA[--allow-mismatched-debuginfo=no|yes [no] ]]></option>
1532 <para>When reading debuginfo from separate debuginfo objects,
1533 Valgrind will by default check that the main and debuginfo
1534 objects match, using the GNU debuglink mechanism. This
1535 guarantees that it does not read debuginfo from out of date
1536 debuginfo objects, and also ensures that Valgrind can't crash as
1537 a result of mismatches.</para>
1539 <para>This check can be overridden using
1540 <computeroutput>--allow-mismatched-debuginfo=yes</computeroutput>.
1541 This may be useful when the debuginfo and main objects have not
1542 been split in the proper way. Be careful when using this,
1543 though: it disables all consistency checking, and Valgrind has
1544 been observed to crash when the main and debuginfo objects don't
1549 <varlistentry id="opt.suppressions" xreflabel="--suppressions">
1551 <option><![CDATA[--suppressions=<filename> [default: $PREFIX/lib/valgrind/default.supp] ]]></option>
1554 <para>Specifies an extra file from which to read descriptions of
1555 errors to suppress. You may use up to 100 extra suppression
1560 <varlistentry id="opt.gen-suppressions" xreflabel="--gen-suppressions">
1562 <option><![CDATA[--gen-suppressions=<yes|no|all> [default: no] ]]></option>
1565 <para>When set to <varname>yes</varname>, Valgrind will pause
1566 after every error shown and print the line:
1567 <literallayout><computeroutput> ---- Print suppression ? --- [Return/N/n/Y/y/C/c] ----</computeroutput></literallayout>
1569 Pressing <varname>Ret</varname>, or <varname>N Ret</varname> or
1570 <varname>n Ret</varname>, causes Valgrind continue execution without
1571 printing a suppression for this error.</para>
1573 <para>Pressing <varname>Y Ret</varname> or
1574 <varname>y Ret</varname> causes Valgrind to write a suppression
1575 for this error. You can then cut and paste it into a suppression file
1576 if you don't want to hear about the error in the future.</para>
1578 <para>When set to <varname>all</varname>, Valgrind will print a
1579 suppression for every reported error, without querying the
1582 <para>This option is particularly useful with C++ programs, as it
1583 prints out the suppressions with mangled names, as
1586 <para>Note that the suppressions printed are as specific as
1587 possible. You may want to common up similar ones, by adding
1588 wildcards to function names, and by using frame-level wildcards.
1589 The wildcarding facilities are powerful yet flexible, and with a
1590 bit of careful editing, you may be able to suppress a whole
1591 family of related errors with only a few suppressions.
1592 <!-- commented out because it causes broken links in the man page
1593 For details on how to do this, see
1594 <xref linkend="manual-core.suppress"/>.
1598 <para>Sometimes two different errors
1599 are suppressed by the same suppression, in which case Valgrind
1600 will output the suppression more than once, but you only need to
1601 have one copy in your suppression file (but having more than one
1602 won't cause problems). Also, the suppression name is given as
1603 <computeroutput><insert a suppression name
1604 here></computeroutput>; the name doesn't really matter, it's
1605 only used with the <option>-v</option> option which prints out all
1606 used suppression records.</para>
1610 <varlistentry id="opt.input-fd" xreflabel="--input-fd">
1612 <option><![CDATA[--input-fd=<number> [default: 0, stdin] ]]></option>
1616 <option>--gen-suppressions=yes</option>, Valgrind will stop so as
1617 to read keyboard input from you when each error occurs. By
1618 default it reads from the standard input (stdin), which is
1619 problematic for programs which close stdin. This option allows
1620 you to specify an alternative file descriptor from which to read
1625 <varlistentry id="opt.dsymutil" xreflabel="--dsymutil">
1627 <option><![CDATA[--dsymutil=no|yes [yes] ]]></option>
1630 <para>This option is only relevant when running Valgrind on
1633 <para>macOS uses a deferred debug information (debuginfo)
1634 linking scheme. When object files containing debuginfo are
1635 linked into a <computeroutput>.dylib</computeroutput> or an
1636 executable, the debuginfo is not copied into the final file.
1637 Instead, the debuginfo must be linked manually by
1638 running <computeroutput>dsymutil</computeroutput>, a
1639 system-provided utility, on the executable
1640 or <computeroutput>.dylib</computeroutput>. The resulting
1641 combined debuginfo is placed in a directory alongside the
1642 executable or <computeroutput>.dylib</computeroutput>, but with
1643 the extension <computeroutput>.dSYM</computeroutput>.</para>
1645 <para>With <option>--dsymutil=no</option>, Valgrind
1646 will detect cases where the
1647 <computeroutput>.dSYM</computeroutput> directory is either
1648 missing, or is present but does not appear to match the
1649 associated executable or <computeroutput>.dylib</computeroutput>,
1650 most likely because it is out of date. In these cases, Valgrind
1651 will print a warning message but take no further action.</para>
1653 <para>With <option>--dsymutil=yes</option>, Valgrind
1654 will, in such cases, automatically
1655 run <computeroutput>dsymutil</computeroutput> as necessary to
1656 bring the debuginfo up to date. For all practical purposes, if
1657 you always use <option>--dsymutil=yes</option>, then
1658 there is never any need to
1659 run <computeroutput>dsymutil</computeroutput> manually or as part
1660 of your applications's build system, since Valgrind will run it
1661 as necessary.</para>
1663 <para>Valgrind will not attempt to
1664 run <computeroutput>dsymutil</computeroutput> on any
1665 executable or library in
1666 <computeroutput>/usr/</computeroutput>,
1667 <computeroutput>/bin/</computeroutput>,
1668 <computeroutput>/sbin/</computeroutput>,
1669 <computeroutput>/opt/</computeroutput>,
1670 <computeroutput>/sw/</computeroutput>,
1671 <computeroutput>/System/</computeroutput>,
1672 <computeroutput>/Library/</computeroutput> or
1673 <computeroutput>/Applications/</computeroutput>
1674 since <computeroutput>dsymutil</computeroutput> will always fail
1675 in such situations. It fails both because the debuginfo for
1676 such pre-installed system components is not available anywhere,
1677 and also because it would require write privileges in those
1680 <para>Be careful when
1681 using <option>--dsymutil=yes</option>, since it will
1682 cause pre-existing <computeroutput>.dSYM</computeroutput>
1683 directories to be silently deleted and re-created. Also note that
1684 <computeroutput>dsymutil</computeroutput> is quite slow, sometimes
1685 excessively so.</para>
1689 <varlistentry id="opt.max-stackframe" xreflabel="--max-stackframe">
1691 <option><![CDATA[--max-stackframe=<number> [default: 2000000] ]]></option>
1694 <para>The maximum size of a stack frame. If the stack pointer moves by
1695 more than this amount then Valgrind will assume that
1696 the program is switching to a different stack.</para>
1698 <para>You may need to use this option if your program has large
1699 stack-allocated arrays. Valgrind keeps track of your program's
1700 stack pointer. If it changes by more than the threshold amount,
1701 Valgrind assumes your program is switching to a different stack,
1702 and Memcheck behaves differently than it would for a stack pointer
1703 change smaller than the threshold. Usually this heuristic works
1704 well. However, if your program allocates large structures on the
1705 stack, this heuristic will be fooled, and Memcheck will
1706 subsequently report large numbers of invalid stack accesses. This
1707 option allows you to change the threshold to a different
1710 <para>You should only consider use of this option if Valgrind's
1711 debug output directs you to do so. In that case it will tell you
1712 the new threshold you should specify.</para>
1714 <para>In general, allocating large structures on the stack is a
1715 bad idea, because you can easily run out of stack space,
1716 especially on systems with limited memory or which expect to
1717 support large numbers of threads each with a small stack, and also
1718 because the error checking performed by Memcheck is more effective
1719 for heap-allocated data than for stack-allocated data. If you
1720 have to use this option, you may wish to consider rewriting your
1721 code to allocate on the heap rather than on the stack.</para>
1725 <varlistentry id="opt.main-stacksize" xreflabel="--main-stacksize">
1727 <option><![CDATA[--main-stacksize=<number>
1728 [default: use current 'ulimit' value] ]]></option>
1731 <para>Specifies the size of the main thread's stack.</para>
1733 <para>To simplify its memory management, Valgrind reserves all
1734 required space for the main thread's stack at startup. That
1735 means it needs to know the required stack size at
1738 <para>By default, Valgrind uses the current "ulimit" value for
1739 the stack size, or 16 MB, whichever is lower. In many cases
1740 this gives a stack size in the range 8 to 16 MB, which almost
1741 never overflows for most applications.</para>
1743 <para>If you need a larger total stack size,
1744 use <option>--main-stacksize</option> to specify it. Only set
1745 it as high as you need, since reserving far more space than you
1746 need (that is, hundreds of megabytes more than you need)
1747 constrains Valgrind's memory allocators and may reduce the total
1748 amount of memory that Valgrind can use. This is only really of
1749 significance on 32-bit machines.</para>
1751 <para>On Linux, you may request a stack of size up to 2GB.
1752 Valgrind will stop with a diagnostic message if the stack cannot
1753 be allocated.</para>
1755 <para><option>--main-stacksize</option> only affects the stack
1756 size for the program's initial thread. It has no bearing on the
1757 size of thread stacks, as Valgrind does not allocate
1760 <para>You may need to use both <option>--main-stacksize</option>
1761 and <option>--max-stackframe</option> together. It is important
1762 to understand that <option>--main-stacksize</option> sets the
1763 maximum total stack size,
1764 whilst <option>--max-stackframe</option> specifies the largest
1765 size of any one stack frame. You will have to work out
1766 the <option>--main-stacksize</option> value for yourself
1767 (usually, if your applications segfaults). But Valgrind will
1768 tell you the needed <option>--max-stackframe</option> size, if
1771 <para>As discussed further in the description
1772 of <option>--max-stackframe</option>, a requirement for a large
1773 stack is a sign of potential portability problems. You are best
1774 advised to place all large data in heap-allocated memory.</para>
1778 <varlistentry id="opt.max-threads" xreflabel="--max-threads">
1780 <option><![CDATA[--max-threads=<number> [default: 500] ]]></option>
1783 <para>By default, Valgrind can handle to up to 500 threads.
1784 Occasionally, that number is too small. Use this option to
1785 provide a different limit. E.g.
1786 <computeroutput>--max-threads=3000</computeroutput>.
1791 <varlistentry id="opt.realloc-zero-bytes-frees" xreflabel="--realloc-zero-bytes-frees">
1793 <option><![CDATA[--realloc-zero-bytes-frees=yes|no [default: yes for glibc no otherwise] ]]></option>
1796 <para>The behaviour of <computeroutput>realloc()</computeroutput> is
1797 implementation defined (in C17, in C23 it is likely to become
1798 undefined). Valgrind tries to work in the same way as the
1799 underlying system and C runtime library that it was configured and built on.
1800 However, if you use a different C runtime library then this default may be wrong.
1801 If the value is <option>yes</option> then <varname>realloc</varname> will
1802 deallocate the memory and return NULL. If the value is <option>no</option> then
1803 <varname>realloc</varname> will not deallocate the memory and
1804 the size will be handled as though it were one byte.</para>
1805 <para>As an example, if you use Valgrind installed via a package on a
1806 Linux distro using GNU libc but link your test executable with musl libc or
1807 the JEMalloc library then consider using
1808 <computeroutput>--realloc-zero-bytes-frees=no</computeroutput>.
1810 <para>Address Sanitizer has a similar and even wordier option
1811 <computeroutput>allocator_frees_and_returns_null_on_realloc_zero</computeroutput>.
1817 <!-- end of xi:include in the manpage -->
1822 <sect2 id="manual-core.mallocopts" xreflabel="malloc-related Options">
1823 <title>malloc-related Options</title>
1825 <!-- start of xi:include in the manpage -->
1826 <para id="malloc-related.opts.para">For tools that use their own version of
1827 <computeroutput>malloc</computeroutput> (e.g. Memcheck,
1828 Massif, Helgrind, DRD), the following options apply.</para>
1830 <variablelist id="malloc-related.opts.list">
1832 <varlistentry id="opt.alignment" xreflabel="--alignment">
1834 <option><![CDATA[--alignment=<number> [default: 8 or 16, depending on the platform] ]]></option>
1837 <para>By default Valgrind's <function>malloc</function>,
1838 <function>realloc</function>, etc, return a block whose starting
1839 address is 8-byte aligned or 16-byte aligned (the value depends on the
1840 platform and matches the platform default). This option allows you to
1841 specify a different alignment. The supplied value must be greater
1842 than or equal to the default, less than or equal to 4096, and must be
1843 a power of two.</para>
1847 <varlistentry id="opt.redzone-size" xreflabel="--redzone-size">
1849 <option><![CDATA[--redzone-size=<number> [default: depends on the tool] ]]></option>
1852 <para> Valgrind's <function>malloc, realloc,</function> etc, add
1853 padding blocks before and after each heap block allocated by the
1854 program being run. Such padding blocks are called redzones. The
1855 default value for the redzone size depends on the tool. For
1856 example, Memcheck adds and protects a minimum of 16 bytes before
1857 and after each block allocated by the client. This allows it to
1858 detect block underruns or overruns of up to 16 bytes.
1860 <para>Increasing the redzone size makes it possible to detect
1861 overruns of larger distances, but increases the amount of memory
1862 used by Valgrind. Decreasing the redzone size will reduce the
1863 memory needed by Valgrind but also reduces the chances of
1864 detecting over/underruns, so is not recommended.</para>
1868 <varlistentry id="opt.xtree-memory" xreflabel="--xtree-memory">
1870 <option><![CDATA[--xtree-memory=none|allocs|full [none] ]]></option>
1873 <para> Tools replacing Valgrind's <function>malloc,
1874 realloc,</function> etc, can optionally produce an execution
1875 tree detailing which piece of code is responsible for heap
1876 memory usage. See <xref linkend="&vg-xtree-id;"/>
1877 for a detailed explanation about execution trees. </para>
1879 <para> When set to <varname>none</varname>, no memory execution
1880 tree is produced.</para>
1882 <para> When set to <varname>allocs</varname>, the memory
1883 execution tree gives the current number of allocated bytes and
1884 the current number of allocated blocks. </para>
1886 <para> When set to <varname>full</varname>, the memory execution
1887 tree gives 6 different measurements : the current number of
1888 allocated bytes and blocks (same values as
1889 for <varname>allocs</varname>), the total number of allocated
1890 bytes and blocks, the total number of freed bytes and
1893 <para>Note that the overhead in cpu and memory to produce
1894 an xtree depends on the tool. The overhead in cpu is small for
1895 the value <varname>allocs</varname>, as the information needed
1896 to produce this report is maintained in any case by the tool.
1897 For massif and helgrind, specifying <varname>full</varname>
1898 implies to capture a stack trace for each free operation,
1899 while normally these tools only capture an allocation stack
1900 trace. For Memcheck, the cpu overhead for the
1901 value <varname>full</varname> is small, as this can only be
1902 used in combination with
1903 <option>--keep-stacktraces=alloc-and-free</option> or
1904 <option>--keep-stacktraces=alloc-then-free</option>, which
1905 already records a stack trace for each free operation. The
1906 memory overhead varies between 5 and 10 words per unique
1907 stacktrace in the xtree, plus the memory needed to record the
1908 stack trace for the free operations, if needed specifically
1914 <varlistentry id="opt.xtree-memory-file" xreflabel="--xtree-memory-file">
1916 <option><![CDATA[--xtree-memory-file=<filename> [default:
1917 xtmemory.kcg.%p] ]]></option>
1920 <para>Specifies that Valgrind should produce the xtree memory
1921 report in the specified file. Any <option>%p</option> or
1922 <option>%q</option> sequences appearing in the filename are expanded
1923 in exactly the same way as they are for <option>--log-file</option>.
1924 See the description of <xref linkend="opt.log-file"/>
1925 for details. </para>
1926 <para>If the filename contains the extension <option>.ms</option>,
1927 then the produced file format will be a massif output file format.
1928 If the filename contains the extension <option>.kcg</option>
1929 or no extension is provided or recognised,
1930 then the produced file format will be a callgrind output format.</para>
1931 <para>See <xref linkend="&vg-xtree-id;"/>
1932 for a detailed explanation about execution trees formats. </para>
1937 <!-- end of xi:include in the manpage -->
1942 <sect2 id="manual-core.rareopts" xreflabel="Uncommon Options">
1943 <title>Uncommon Options</title>
1945 <!-- start of xi:include in the manpage -->
1946 <para id="uncommon.opts.para">These options apply to all tools, as they
1947 affect certain obscure workings of the Valgrind core. Most people won't
1948 need to use them.</para>
1950 <variablelist id="uncommon.opts.list">
1952 <varlistentry id="opt.smc-check" xreflabel="--smc-check">
1954 <option><![CDATA[--smc-check=<none|stack|all|all-non-file>
1955 [default: all-non-file for x86/amd64/s390x, stack for other archs] ]]></option>
1958 <para>This option controls Valgrind's detection of self-modifying
1959 code. If no checking is done, when a program executes some code, then
1960 overwrites it with new code, and executes the new code, Valgrind will
1961 continue to execute the translations it made for the old code. This
1962 will likely lead to incorrect behaviour and/or crashes.</para>
1963 <para>For "modern" architectures -- anything that's not x86,
1964 amd64 or s390x -- the default is <varname>stack</varname>.
1965 This is because a correct program must take explicit action
1966 to reestablish D-I cache coherence following code
1967 modification. Valgrind observes and honours such actions,
1968 with the result that self-modifying code is transparently
1969 handled with zero extra cost.</para>
1970 <para>For x86, amd64 and s390x, the program is not required to
1971 notify the hardware of required D-I coherence syncing. Hence
1972 the default is <varname>all-non-file</varname>, which covers
1973 the normal case of generating code into an anonymous
1974 (non-file-backed) mmap'd area.</para>
1975 <para>The meanings of the four available settings are as
1976 follows. No detection (<varname>none</varname>),
1977 detect self-modifying code
1978 on the stack (which is used by GCC to implement nested
1979 functions) (<varname>stack</varname>), detect self-modifying code
1980 everywhere (<varname>all</varname>), and detect
1981 self-modifying code everywhere except in file-backed
1982 mappings (<varname>all-non-file</varname>).</para>
1983 <para>Running with <varname>all</varname> will slow Valgrind
1984 down noticeably. Running with <varname>none</varname> will
1985 rarely speed things up, since very little code gets
1986 dynamically generated in most programs. The
1987 <function>VALGRIND_DISCARD_TRANSLATIONS</function> client
1988 request is an alternative to <option>--smc-check=all</option>
1989 and <option>--smc-check=all-non-file</option>
1990 that requires more programmer effort but allows Valgrind to run
1991 your program faster, by telling it precisely when translations
1993 <!-- commented out because it causes broken links in the man page
1995 linkend="manual-core-adv.clientreq"/> for more details.
1998 <para><option>--smc-check=all-non-file</option> provides a
1999 cheaper but more limited version
2000 of <option>--smc-check=all</option>. It adds checks to any
2001 translations that do not originate from file-backed memory
2002 mappings. Typical applications that generate code, for example
2003 JITs in web browsers, generate code into anonymous mmaped areas,
2004 whereas the "fixed" code of the browser always lives in
2005 file-backed mappings. <option>--smc-check=all-non-file</option>
2006 takes advantage of this observation, limiting the overhead of
2007 checking to code which is likely to be JIT generated.</para>
2011 <varlistentry id="opt.read-inline-info" xreflabel="--read-inline-info">
2013 <option><![CDATA[--read-inline-info=<yes|no> [default: see below] ]]></option>
2016 <para>When enabled, Valgrind will read information about inlined
2017 function calls from DWARF3 debug info. This slows Valgrind
2018 startup and makes it use more memory (typically for each inlined
2019 piece of code, 6 words and space for the function name), but it
2020 results in more descriptive stacktraces. Currently,
2021 this functionality is enabled by default only for Linux, FreeBSD,
2022 Android and Solaris targets and only for the tools Memcheck, Massif,
2023 Helgrind and DRD. Here is an example of some stacktraces with
2024 <option>--read-inline-info=no</option>:
2026 <programlisting><![CDATA[
2027 ==15380== Conditional jump or move depends on uninitialised value(s)
2028 ==15380== at 0x80484EA: main (inlinfo.c:6)
2030 ==15380== Conditional jump or move depends on uninitialised value(s)
2031 ==15380== at 0x8048550: fun_noninline (inlinfo.c:6)
2032 ==15380== by 0x804850E: main (inlinfo.c:34)
2034 ==15380== Conditional jump or move depends on uninitialised value(s)
2035 ==15380== at 0x8048520: main (inlinfo.c:6)
2036 ]]></programlisting>
2037 <para>And here are the same errors with
2038 <option>--read-inline-info=yes</option>:</para>
2039 <programlisting><![CDATA[
2040 ==15377== Conditional jump or move depends on uninitialised value(s)
2041 ==15377== at 0x80484EA: fun_d (inlinfo.c:6)
2042 ==15377== by 0x80484EA: fun_c (inlinfo.c:14)
2043 ==15377== by 0x80484EA: fun_b (inlinfo.c:20)
2044 ==15377== by 0x80484EA: fun_a (inlinfo.c:26)
2045 ==15377== by 0x80484EA: main (inlinfo.c:33)
2047 ==15377== Conditional jump or move depends on uninitialised value(s)
2048 ==15377== at 0x8048550: fun_d (inlinfo.c:6)
2049 ==15377== by 0x8048550: fun_noninline (inlinfo.c:41)
2050 ==15377== by 0x804850E: main (inlinfo.c:34)
2052 ==15377== Conditional jump or move depends on uninitialised value(s)
2053 ==15377== at 0x8048520: fun_d (inlinfo.c:6)
2054 ==15377== by 0x8048520: main (inlinfo.c:35)
2055 ]]></programlisting>
2059 <varlistentry id="opt.read-var-info" xreflabel="--read-var-info">
2061 <option><![CDATA[--read-var-info=<yes|no> [default: no] ]]></option>
2064 <para>When enabled, Valgrind will read information about
2065 variable types and locations from DWARF3 debug info.
2066 This slows Valgrind startup significantly and makes it use significantly
2067 more memory, but for the tools that can take advantage of it (Memcheck,
2068 Helgrind, DRD) it can result in more precise error messages. For example,
2069 here are some standard errors issued by Memcheck:</para>
2070 <programlisting><![CDATA[
2071 ==15363== Uninitialised byte(s) found during client check request
2072 ==15363== at 0x80484A9: croak (varinfo1.c:28)
2073 ==15363== by 0x8048544: main (varinfo1.c:55)
2074 ==15363== Address 0x80497f7 is 7 bytes inside data symbol "global_i2"
2076 ==15363== Uninitialised byte(s) found during client check request
2077 ==15363== at 0x80484A9: croak (varinfo1.c:28)
2078 ==15363== by 0x8048550: main (varinfo1.c:56)
2079 ==15363== Address 0xbea0d0cc is on thread 1's stack
2080 ==15363== in frame #1, created by main (varinfo1.c:45)
2081 ]]></programlisting>
2083 <para>And here are the same errors with
2084 <option>--read-var-info=yes</option>:</para>
2086 <programlisting><![CDATA[
2087 ==15370== Uninitialised byte(s) found during client check request
2088 ==15370== at 0x80484A9: croak (varinfo1.c:28)
2089 ==15370== by 0x8048544: main (varinfo1.c:55)
2090 ==15370== Location 0x80497f7 is 0 bytes inside global_i2[7],
2091 ==15370== a global variable declared at varinfo1.c:41
2093 ==15370== Uninitialised byte(s) found during client check request
2094 ==15370== at 0x80484A9: croak (varinfo1.c:28)
2095 ==15370== by 0x8048550: main (varinfo1.c:56)
2096 ==15370== Location 0xbeb4a0cc is 0 bytes inside local var "local"
2097 ==15370== declared at varinfo1.c:46, in frame #1 of thread 1
2098 ]]></programlisting>
2102 <varlistentry id="opt.vgdb-poll" xreflabel="--vgdb-poll">
2104 <option><![CDATA[--vgdb-poll=<number> [default: 5000] ]]></option>
2107 <para> As part of its main loop, the Valgrind scheduler will
2108 poll to check if some activity (such as an external command or
2109 some input from a gdb) has to be handled by gdbserver. This
2110 activity poll will be done after having run the given number of
2111 basic blocks (or slightly more than the given number of basic
2112 blocks). This poll is quite cheap so the default value is set
2113 relatively low. You might further decrease this value if vgdb
2114 cannot use ptrace system call to interrupt Valgrind if all
2115 threads are (most of the time) blocked in a system call.
2120 <varlistentry id="opt.vgdb-shadow-registers" xreflabel="--vgdb-shadow-registers">
2122 <option><![CDATA[--vgdb-shadow-registers=no|yes [default: no] ]]></option>
2125 <para> When activated, gdbserver will expose the Valgrind shadow registers
2126 to GDB. With this, the value of the Valgrind shadow registers can be examined
2127 or changed using GDB. Exposing shadow registers only works with GDB version
2133 <varlistentry id="opt.vgdb-prefix" xreflabel="--vgdb-prefix">
2135 <option><![CDATA[--vgdb-prefix=<prefix> [default: /tmp/vgdb-pipe] ]]></option>
2138 <para> To communicate with gdb/vgdb, the Valgrind gdbserver
2139 creates 3 files (2 named FIFOs and a mmap shared memory
2140 file). The prefix option controls the directory and prefix for
2141 the creation of these files.
2146 <varlistentry id="opt.run-libc-freeres" xreflabel="--run-libc-freeres">
2148 <option><![CDATA[--run-libc-freeres=<yes|no> [default: yes] ]]></option>
2151 <para>This option is only relevant when running Valgrind on Linux with
2154 <para>The GNU C library (<function>libc.so</function>), which is
2155 used by all programs, may allocate memory for its own uses.
2156 Usually it doesn't bother to free that memory when the program
2157 ends—there would be no point, since the Linux kernel reclaims
2158 all process resources when a process exits anyway, so it would
2159 just slow things down.</para>
2161 <para>The glibc authors realised that this behaviour causes leak
2162 checkers, such as Valgrind, to falsely report leaks in glibc, when
2163 a leak check is done at exit. In order to avoid this, they
2164 provided a routine called <function>__libc_freeres</function>
2165 specifically to make glibc release all memory it has allocated.
2166 Memcheck therefore tries to run
2167 <function>__libc_freeres</function> at exit.</para>
2169 <para>Unfortunately, in some very old versions of glibc,
2170 <function>__libc_freeres</function> is sufficiently buggy to cause
2171 segmentation faults. This was particularly noticeable on Red Hat
2172 7.1. So this option is provided in order to inhibit the run of
2173 <function>__libc_freeres</function>. If your program seems to run
2174 fine on Valgrind, but segfaults at exit, you may find that
2175 <option>--run-libc-freeres=no</option> fixes that, although at the
2176 cost of possibly falsely reporting space leaks in
2177 <filename>libc.so</filename>.</para>
2181 <varlistentry id="opt.run-cxx-freeres" xreflabel="--run-cxx-freeres">
2183 <option><![CDATA[--run-cxx-freeres=<yes|no> [default: yes] ]]></option>
2186 <para>This option is only relevant when running Valgrind on Linux,
2187 FreeBSD or Solaris C++ programs using libstdc++.</para>
2189 <para>The GNU Standard C++ library (<function>libstdc++.so</function>),
2190 which is used by all C++ programs compiled with g++, may allocate memory
2191 for its own uses. Usually it doesn't bother to free that memory when
2192 the program ends—there would be no point, since the kernel reclaims
2193 all process resources when a process exits anyway, so it would
2194 just slow things down.</para>
2196 <para>The gcc authors realised that this behaviour causes leak
2197 checkers, such as Valgrind, to falsely report leaks in libstdc++, when
2198 a leak check is done at exit. In order to avoid this, they
2199 provided a routine called <function>__gnu_cxx::__freeres</function>
2200 specifically to make libstdc++ release all memory it has allocated.
2201 Memcheck therefore tries to run
2202 <function>__gnu_cxx::__freeres</function> at exit.</para>
2204 <para>For the sake of flexibility and unforeseen problems with
2205 <function>__gnu_cxx::__freeres</function>, option
2206 <option>--run-cxx-freeres=no</option> exists,
2207 although at the cost of possibly falsely reporting space leaks in
2208 <filename>libstdc++.so</filename>.</para>
2212 <varlistentry id="opt.sim-hints" xreflabel="--sim-hints">
2214 <option><![CDATA[--sim-hints=hint1,hint2,... ]]></option>
2217 <para>Pass miscellaneous hints to Valgrind which slightly modify
2218 the simulated behaviour in nonstandard or dangerous ways, possibly
2219 to help the simulation of strange features. By default no hints
2220 are enabled. Use with caution! Currently known hints are:</para>
2224 <para><option>lax-ioctls: </option> Be very lax about ioctl
2225 handling; the only assumption is that the size is
2226 correct. Doesn't require the full buffer to be initialised
2227 when writing. Without this, using some device drivers with a
2228 large number of strange ioctl commands becomes very
2233 <para><option>fuse-compatible: </option> Enable special
2234 handling for certain system calls that may block in a FUSE
2235 file-system. This may be necessary when running Valgrind
2236 on a multi-threaded program that uses one thread to manage
2237 a FUSE file-system and another thread to access that
2243 <para><option>enable-outer: </option> Enable some special
2244 magic needed when the program being run is itself
2249 <para><option>no-inner-prefix: </option> Disable printing
2250 a prefix <option>></option> in front of each stdout or
2251 stderr output line in an inner Valgrind being run by an
2252 outer Valgrind. This is useful when running Valgrind
2253 regression tests in an outer/inner setup. Note that the
2254 prefix <option>></option> will always be printed in
2255 front of the inner debug logging lines.</para>
2258 <para><option>no-nptl-pthread-stackcache: </option>
2259 This hint is only relevant when running Valgrind on Linux;
2260 it is ignored on FreeBSD, Solaris and macOS.</para>
2262 <para>The GNU glibc pthread library
2263 (<function>libpthread.so</function>), which is used by
2264 pthread programs, maintains a cache of pthread stacks.
2265 When a pthread terminates, the memory used for the pthread
2266 stack and some thread local storage related data structure
2267 are not always directly released. This memory is kept in
2268 a cache (up to a certain size), and is re-used if a new
2269 thread is started.</para>
2271 <para>This cache causes the helgrind tool to report some
2272 false positive race condition errors on this cached
2273 memory, as helgrind does not understand the internal glibc
2274 cache synchronisation primitives. So, when using helgrind,
2275 disabling the cache helps to avoid false positive race
2276 conditions, in particular when using thread local storage
2277 variables (e.g. variables using the
2278 <function>__thread</function> qualifier).</para>
2280 <para>When using the memcheck tool, disabling the cache
2281 ensures the memory used by glibc to handle __thread
2282 variables is directly released when a thread
2285 <para>Note: Valgrind disables the cache using some internal
2286 knowledge of the glibc stack cache implementation and by
2287 examining the debug information of the pthread
2288 library. This technique is thus somewhat fragile and might
2289 not work for all glibc versions. This has been successfully
2290 tested with various glibc versions (e.g. 2.11, 2.16, 2.18)
2291 on various platforms.</para>
2294 <para><option>lax-doors: </option> (Solaris only) Be very lax
2295 about door syscall handling over unrecognised door file
2296 descriptors. Does not require that full buffer is initialised
2297 when writing. Without this, programs using libdoor(3LIB)
2298 functionality with completely proprietary semantics may report
2299 large number of false positives.</para>
2302 <para><option>fallback-llsc: </option>(MIPS and ARM64 only): Enables
2303 an alternative implementation of Load-Linked (LL) and
2304 Store-Conditional (SC) instructions. The standard implementation
2305 gives more correct behaviour, but can cause indefinite looping on
2306 certain processor implementations that are intolerant of extra
2307 memory references between LL and SC. So far this is known only to
2308 happen on Cavium 3 cores.
2310 You should not need to use this flag, since the relevant cores are
2311 detected at startup and the alternative implementation is
2312 automatically enabled if necessary. There is no equivalent
2313 anti-flag: you cannot force-disable the alternative
2314 implementation, if it is automatically enabled.
2316 The underlying problem exists because the "standard"
2317 implementation of LL and SC is done by copying through LL and SC
2318 instructions into the instrumented code. However, tools may
2319 insert extra instrumentation memory references in between the LL
2320 and SC instructions. These memory references are not present in
2321 the original uninstrumented code, and their presence in the
2322 instrumented code can cause the SC instructions to persistently
2323 fail, leading to indefinite looping in LL-SC blocks.
2325 The alternative implementation gives correct behaviour of LL and
2326 SC instructions between threads in a process, up to and including
2327 the ABA scenario. It also gives correct behaviour between a
2328 Valgrinded thread and a non-Valgrinded thread running in a
2329 different process, that communicate via shared memory, but only up
2330 to and including correct CAS behaviour -- in this case the ABA
2331 scenario may not be correctly handled.
2338 <varlistentry id="opt.scheduling-quantum" xreflabel="--scheduling-quantum">
2340 <option><![CDATA[--scheduling-quantum=<number> [default: 100000] ]]></option>
2343 <para>The <option>--scheduling-quantum</option> option controls
2344 the maximum number of basic blocks executed by a thread before releasing
2345 the lock used by Valgrind to serialise thread execution. Smaller values
2346 give finer interleaving but increases the scheduling overhead. Finer
2347 interleaving can be useful to reproduce race conditions with helgrind or
2348 DRD. For more details about the Valgrind thread serialisation scheme and
2349 its impact on performance and thread scheduling, see
2350 <xref linkend="&vg-pthreads-perf-sched-id;"/>.
2355 <varlistentry id="opt.fair-sched" xreflabel="--fair-sched">
2357 <option><![CDATA[--fair-sched=<no|yes|try> [default: no] ]]></option>
2360 <listitem> <para>The <option>--fair-sched</option> option controls
2361 the locking mechanism used by Valgrind to serialise thread
2362 execution. The locking mechanism controls the way the threads
2363 are scheduled, and different settings give different trade-offs
2364 between fairness and performance. For more details about the
2365 Valgrind thread serialisation scheme and its impact on
2366 performance and thread scheduling, see
2367 <xref linkend="&vg-pthreads-perf-sched-id;"/>.</para>
2370 <listitem> <para>The value <option>--fair-sched=yes</option>
2371 activates a fair scheduler. In short, if multiple threads are
2372 ready to run, the threads will be scheduled in a round robin
2373 fashion. This mechanism is not available on all platforms or
2374 Linux versions. If not available,
2375 using <option>--fair-sched=yes</option> will cause Valgrind to
2376 terminate with an error.</para>
2377 <para>You may find this setting improves overall
2378 responsiveness if you are running an interactive
2379 multithreaded program, for example a web browser, on
2383 <listitem> <para>The value <option>--fair-sched=try</option>
2384 activates fair scheduling if available on the
2385 platform. Otherwise, it will automatically fall back
2386 to <option>--fair-sched=no</option>.</para>
2389 <listitem> <para>The value <option>--fair-sched=no</option> activates
2390 a scheduler which does not guarantee fairness
2391 between threads ready to run, but which in general gives the
2392 highest performance.</para>
2399 <varlistentry id="opt.kernel-variant" xreflabel="--kernel-variant">
2401 <option>--kernel-variant=variant1,variant2,...</option>
2404 <para>Handle system calls and ioctls arising from minor variants
2405 of the default kernel for this platform. This is useful for
2406 running on hacked kernels or with kernel modules which support
2407 nonstandard ioctls, for example. Use with caution. If you don't
2408 understand what this option does then you almost certainly don't
2409 need it. Currently known variants are:</para>
2412 <para><option>bproc</option>: support the
2413 <function>sys_broc</function> system call on x86. This is for
2414 running on BProc, which is a minor variant of standard Linux which
2415 is sometimes used for building clusters.
2419 <para><option>android-no-hw-tls</option>: some
2420 versions of the Android emulator for ARM do not provide a
2421 hardware TLS (thread-local state) register, and Valgrind
2422 crashes at startup. Use this variant to select software
2427 <para><option>android-gpu-sgx5xx</option>: use this to
2428 support handling of proprietary ioctls for the PowerVR SGX
2429 5XX series of GPUs on Android devices. Failure to select
2430 this does not cause stability problems, but may cause
2431 Memcheck to report false errors after the program performs
2432 GPU-specific ioctls.
2436 <para><option>android-gpu-adreno3xx</option>: similarly, use
2437 this to support handling of proprietary ioctls for the
2438 Qualcomm Adreno 3XX series of GPUs on Android devices.
2445 <varlistentry id="opt.merge-recursive-frames" xreflabel="--merge-recursive-frames">
2447 <option><![CDATA[--merge-recursive-frames=<number> [default: 0] ]]></option>
2450 <para>Some recursive algorithms, for example balanced binary
2451 tree implementations, create many different stack traces, each
2452 containing cycles of calls. A cycle is defined as two identical
2453 program counter values separated by zero or more other program
2454 counter values. Valgrind may then use a lot of memory to store
2455 all these stack traces. This is a poor use of memory
2456 considering that such stack traces contain repeated
2457 uninteresting recursive calls instead of more interesting
2458 information such as the function that has initiated the
2461 <para>The option <option>--merge-recursive-frames=<number></option>
2462 instructs Valgrind to detect and merge recursive call cycles
2463 having a size of up to <option><number></option>
2464 frames. When such a cycle is detected, Valgrind records the
2465 cycle in the stack trace as a unique program counter.
2468 The value 0 (the default) causes no recursive call merging.
2469 A value of 1 will cause stack traces of simple recursive algorithms
2470 (for example, a factorial implementation) to be collapsed.
2471 A value of 2 will usually be needed to collapse stack traces produced
2472 by recursive algorithms such as binary trees, quick sort, etc.
2473 Higher values might be needed for more complex recursive algorithms.
2475 <para>Note: recursive calls are detected by analysis of program
2476 counter values. They are not detected by looking at function
2481 <varlistentry id="opt.num-transtab-sectors" xreflabel="--num-transtab-sectors">
2483 <option><![CDATA[--num-transtab-sectors=<number> [default: 6
2484 for Android platforms, 16 for all others] ]]></option>
2487 <para>Valgrind translates and instruments your program's machine
2488 code in small fragments (basic blocks). The translations are stored in a
2489 translation cache that is divided into a number of sections
2490 (sectors). If the cache is full, the sector containing the
2491 oldest translations is emptied and reused. If these old
2492 translations are needed again, Valgrind must re-translate and
2493 re-instrument the corresponding machine code, which is
2494 expensive. If the "executed instructions" working set of a
2495 program is big, increasing the number of sectors may improve
2496 performance by reducing the number of re-translations needed.
2497 Sectors are allocated on demand. Once allocated, a sector can
2498 never be freed, and occupies considerable space, depending on the tool
2499 and the value of <option>--avg-transtab-entry-size</option>
2500 (about 40 MB per sector for Memcheck). Use the
2501 option <option>--stats=yes</option> to obtain precise
2502 information about the memory used by a sector and the allocation
2503 and recycling of sectors.</para>
2507 <varlistentry id="opt.avg-transtab-entry-size" xreflabel="--avg-transtab-entry-size">
2509 <option><![CDATA[--avg-transtab-entry-size=<number> [default: 0,
2510 meaning use tool provided default] ]]></option>
2513 <para>Average size of translated basic block. This average size
2514 is used to dimension the size of a sector.
2515 Each tool provides a default value to be used.
2516 If this default value is too small, the translation sectors
2517 will become full too quickly. If this default value is too big,
2518 a significant part of the translation sector memory will be unused.
2519 Note that the average size of a basic block translation depends
2520 on the tool, and might depend on tool options. For example,
2521 the memcheck option <option>--track-origins=yes</option>
2522 increases the size of the basic block translations.
2523 Use <option>--avg-transtab-entry-size</option> to tune the size of the
2524 sectors, either to gain memory or to avoid too many retranslations.
2529 <varlistentry id="opt.aspace-minaddr" xreflabel="----aspace-minaddr">
2531 <option><![CDATA[--aspace-minaddr=<address> [default: depends
2532 on the platform] ]]></option>
2535 <para>To avoid potential conflicts with some system libraries,
2536 Valgrind does not use the address space
2537 below <option>--aspace-minaddr</option> value, keeping it
2538 reserved in case a library specifically requests memory in this
2539 region. So, some "pessimistic" value is guessed by Valgrind
2540 depending on the platform. On linux, by default, Valgrind avoids
2541 using the first 64MB even if typically there is no conflict in
2542 this complete zone. You can use the
2543 option <option>--aspace-minaddr</option> to have your memory
2544 hungry application benefitting from more of this lower memory.
2545 On the other hand, if you encounter a conflict, increasing
2546 aspace-minaddr value might solve it. Conflicts will typically
2547 manifest themselves with mmap failures in the low range of the
2549 provided <computeroutput>address</computeroutput> must be page
2550 aligned and must be equal or bigger to 0x1000 (4KB). To find the
2551 default value on your platform, do something such as
2552 <computeroutput>valgrind -d -d date 2>&1 | grep -i minaddr</computeroutput>.
2553 Values lower than 0x10000 (64KB) are known to create problems
2554 on some distributions.
2559 <varlistentry id="opt.valgrind-stacksize" xreflabel="----valgrind-stacksize">
2561 <option><![CDATA[--valgrind-stacksize=<number> [default: 1MB] ]]></option>
2564 <para>For each thread, Valgrind needs its own 'private' stack.
2565 The default size for these stacks is largely dimensioned, and so
2566 should be sufficient in most cases. In case the size is too small,
2567 Valgrind will segfault. Before segfaulting, a warning might be produced
2568 by Valgrind when approaching the limit.
2571 Use the option <option>--valgrind-stacksize</option> if such an (unlikely)
2572 warning is produced, or Valgrind dies due to a segmentation violation.
2573 Such segmentation violations have been seen when demangling huge C++
2576 <para>If your application uses many threads and needs a lot of memory, you can
2577 gain some memory by reducing the size of these Valgrind stacks using
2578 the option <option>--valgrind-stacksize</option>.
2583 <varlistentry id="opt.show-emwarns" xreflabel="--show-emwarns">
2585 <option><![CDATA[--show-emwarns=<yes|no> [default: no] ]]></option>
2588 <para>When enabled, Valgrind will emit warnings about its CPU
2589 emulation in certain cases. These are usually not
2594 <varlistentry id="opt.require-text-symbol"
2595 xreflabel="--require-text-symbol">
2597 <option><![CDATA[--require-text-symbol=:sonamepatt:fnnamepatt]]></option>
2600 <para>When a shared object whose soname
2601 matches <varname>sonamepatt</varname> is loaded into the
2602 process, examine all the text symbols it exports. If none of
2603 those match <varname>fnnamepatt</varname>, print an error
2604 message and abandon the run. This makes it possible to ensure
2605 that the run does not continue unless a given shared object
2606 contains a particular function name.
2609 Both <varname>sonamepatt</varname> and
2610 <varname>fnnamepatt</varname> can be written using the usual
2611 <varname>?</varname> and <varname>*</varname> wildcards. For
2612 example: <varname>":*libc.so*:foo?bar"</varname>. You may use
2613 characters other than a colon to separate the two patterns. It
2614 is only important that the first character and the separator
2615 character are the same. For example, the above example could
2616 also be written <varname>"Q*libc.so*Qfoo?bar"</varname>.
2617 Multiple <varname> --require-text-symbol</varname> flags are
2618 allowed, in which case shared objects that are loaded into
2619 the process will be checked against all of them.
2622 The purpose of this is to support reliable usage of marked-up
2623 libraries. For example, suppose we have a version of GCC's
2624 <varname>libgomp.so</varname> which has been marked up with
2625 annotations to support Helgrind. It is only too easy and
2626 confusing to load the wrong, un-annotated
2627 <varname>libgomp.so</varname> into the application. So the idea
2628 is: add a text symbol in the marked-up library, for
2629 example <varname>annotated_for_helgrind_3_6</varname>, and then
2631 <varname>--require-text-symbol=:*libgomp*so*:annotated_for_helgrind_3_6</varname>
2632 so that when <varname>libgomp.so</varname> is loaded, Valgrind
2633 scans its symbol table, and if the symbol isn't present the run
2634 is aborted, rather than continuing silently with the
2635 un-marked-up library. Note that you should put the entire flag
2636 in quotes to stop shells expanding up the <varname>*</varname>
2637 and <varname>?</varname> wildcards.
2642 <varlistentry id="opt.soname-synonyms"
2643 xreflabel="--soname-synonyms">
2645 <option><![CDATA[--soname-synonyms=syn1=pattern1,syn2=pattern2,...]]></option>
2648 <para>When a shared library is loaded, Valgrind checks for
2649 functions in the library that must be replaced or wrapped. For
2650 example, Memcheck replaces some string and memory functions
2651 (strchr, strlen, strcpy, memchr, memcpy, memmove, etc.) with its
2652 own versions. Such replacements are normally done only in shared
2653 libraries whose soname matches a predefined soname pattern (e.g.
2654 <varname>libc.so*</varname> on linux). By default, no
2655 replacement is done for a statically linked binary or for
2656 alternative libraries, except for the allocation functions
2657 (malloc, free, calloc, memalign, realloc, operator new, operator
2658 delete, etc.) Such allocation functions are intercepted by
2659 default in any shared library or in the executable if they are
2660 exported as global symbols. This means that if a replacement
2661 allocation library such as tcmalloc is found, its functions are
2662 also intercepted by default.
2664 In some cases, the replacements allow
2665 <option>--soname-synonyms</option> to specify one additional
2666 synonym pattern, giving flexibility in the replacement. Or to
2667 prevent interception of all public allocation symbols.</para>
2669 <para>Currently, this flexibility is only allowed for the
2670 malloc related functions, using the
2671 synonym <varname>somalloc</varname>. This synonym is usable for
2672 all tools doing standard replacement of malloc related functions
2673 (e.g. memcheck, helgrind, drd, massif, dhat).
2679 <para>Alternate malloc library: to replace the malloc
2680 related functions in a specific alternate library with
2681 soname <varname>mymalloclib.so</varname> (and not in any
2683 option <option>--soname-synonyms=somalloc=mymalloclib.so</option>.
2684 A pattern can be used to match multiple libraries sonames.
2686 example, <option>--soname-synonyms=somalloc=*tcmalloc*</option>
2687 will match the soname of all variants of the tcmalloc
2688 library (native, debug, profiled, ... tcmalloc
2690 <para>Note: the soname of a elf shared library can be
2691 retrieved using the readelf utility. </para>
2696 <para>Replacements in a statically linked library are done
2697 by using the <varname>NONE</varname> pattern. For example,
2698 if you link with <varname>libtcmalloc.a</varname>, and only
2699 want to intercept the malloc related functions in the
2700 executable (and standard libraries) themselves, but not any
2701 other shared libraries, you can give the
2702 option <option>--soname-synonyms=somalloc=NONE</option>.
2703 Note that a NONE pattern will match the main executable and
2704 any shared library having no soname. </para>
2708 <para>To only intercept allocation symbols in the default
2709 system libraries, but not in any other shared library or the
2710 executable defining public malloc or operator new related
2711 functions use a non-existing library name
2712 like <option>--soname-synonyms=somalloc=nouserintercepts</option>
2713 (where <varname>nouserintercepts</varname> can be any
2714 non-existing library name).
2719 <para>Shared library of the dynamic (runtime) linker is excluded from
2720 searching for global public symbols, such as those for the malloc
2721 related functions (identified by <varname>somalloc</varname> synonym).
2729 <varlistentry id="opt.progress-interval" xreflabel="--progress-interval">
2731 <option><![CDATA[--progress-interval=<number> [default: 0, meaning 'disabled'] ]]></option>
2734 <para>This is an enhancement to Valgrind's debugging output. It is
2735 unlikely to be of interest to end users.</para>
2736 <para>When <varname>number</varname> is set to a non-zero value,
2737 Valgrind will print a one-line progress summary
2738 every <varname>number</varname> seconds. Valid settings
2739 for <varname>number</varname> are between 0 and 3600
2740 inclusive. Here's some example output
2741 with <varname>number</varname>
2743 <programlisting><![CDATA[
2744 PROGRESS: U 110s, W 113s, 97.3% CPU, EvC 414.79M, TIn 616.7k, TOut 0.5k, #thr 67
2745 PROGRESS: U 120s, W 124s, 96.8% CPU, EvC 505.27M, TIn 636.6k, TOut 3.0k, #thr 64
2746 PROGRESS: U 130s, W 134s, 97.0% CPU, EvC 574.90M, TIn 657.5k, TOut 3.0k, #thr 63
2747 ]]></programlisting>
2750 <listitem><para><varname>U</varname>: total user time</para></listitem>
2751 <listitem><para><varname>W</varname>: total wallclock time</para></listitem>
2752 <listitem><para><varname>CPU</varname>: overall average cpu use</para></listitem>
2753 <listitem><para><varname>EvC</varname>: number of event checks. An event
2754 check is a backwards branch in the simulated program, so this is a
2755 measure of forward progress of the program</para></listitem>
2756 <listitem><para><varname>TIn</varname>: number of code blocks instrumented
2757 by the JIT</para></listitem>
2758 <listitem><para><varname>TOut</varname>: number of instrumented code
2759 blocks that have been thrown away</para></listitem>
2760 <listitem><para><varname>#thr</varname>: number of threads in the
2761 program</para></listitem>
2763 From the progress of these, it is possible to observe:
2765 <listitem><para>when the program is compute bound (<varname>TIn</varname>
2766 rises slowly, <varname>EvC</varname> rises rapidly)</para></listitem>
2767 <listitem><para>when the program is in a spinloop
2768 (<varname>TIn</varname>/<varname>TOut</varname>
2769 fixed, <varname>EvC</varname> rises rapidly)</para></listitem>
2770 <listitem><para>when the program is JIT-bound (<varname>TIn</varname>
2771 rises rapidly)</para></listitem>
2772 <listitem><para>when the program is rapidly discarding code
2773 (<varname>TOut</varname> rises rapidly)</para></listitem>
2774 <listitem><para>when the program is about to achieve some expected state
2775 (<varname>EvC</varname> arrives at some value you
2776 expect)</para></listitem>
2777 <listitem><para> when the program is idling (<varname>U</varname> rises
2778 more slowly than <varname>W</varname>)</para></listitem>
2785 <!-- end of xi:include in the manpage -->
2790 <sect2 id="manual-core.debugopts" xreflabel="Debugging Options">
2791 <title>Debugging Options</title>
2793 <!-- start of xi:include in the manpage -->
2794 <para id="debug.opts.para">There are also some options for debugging
2795 Valgrind itself. You shouldn't need to use them in the normal run of
2796 things. If you wish to see the list, use the
2797 <option>--help-debug</option> option.</para>
2799 <para>If you wish to debug your program rather than debugging
2800 Valgrind itself, then you should use the options
2801 <option>--vgdb=yes</option> or <option>--vgdb=full</option>.
2804 <!-- end of xi:include in the manpage -->
2809 <sect2 id="manual-core.defopts" xreflabel="Setting Default Options">
2810 <title>Setting Default Options</title>
2812 <para>Note that Valgrind also reads options from three places:</para>
2816 <para>The file <computeroutput>~/.valgrindrc</computeroutput></para>
2820 <para>The environment variable
2821 <computeroutput>$VALGRIND_OPTS</computeroutput></para>
2825 <para>The file <computeroutput>./.valgrindrc</computeroutput></para>
2829 <para>These are processed in the given order, before the
2830 command-line options. Options processed later override those
2831 processed earlier; for example, options in
2832 <computeroutput>./.valgrindrc</computeroutput> will take
2833 precedence over those in
2834 <computeroutput>~/.valgrindrc</computeroutput>.
2837 <para>Please note that the <computeroutput>./.valgrindrc</computeroutput>
2838 file is ignored if it is not a regular file, or is marked as world writeable,
2839 or is not owned by the current user. This is because the
2840 <computeroutput>./.valgrindrc</computeroutput> can contain options that are
2841 potentially harmful or can be used by a local attacker to execute code under
2845 <para>Any tool-specific options put in
2846 <computeroutput>$VALGRIND_OPTS</computeroutput> or the
2847 <computeroutput>.valgrindrc</computeroutput> files should be
2848 prefixed with the tool name and a colon. For example, if you
2849 want Memcheck to always do leak checking, you can put the
2850 following entry in <literal>~/.valgrindrc</literal>:</para>
2852 <programlisting><![CDATA[
2853 --memcheck:leak-check=yes]]></programlisting>
2855 <para>This will be ignored if any tool other than Memcheck is
2856 run. Without the <computeroutput>memcheck:</computeroutput>
2857 part, this will cause problems if you select other tools that
2859 <option>--leak-check=yes</option>.</para>
2863 <sect2 id="manual-core.dynopts" xreflabel="Dynamically Change Options">
2864 <title>Dynamically Changing Options</title>
2866 <para>The value of some command line options can be changed dynamically
2867 while your program is running under Valgrind.</para>
2869 <para>The dynamically changeable options of the valgrind core and a given
2870 tool can be listed using option
2871 <computeroutput>--help-dyn-options</computeroutput>, for example:</para>
2873 $ valgrind --tool=memcheck --help-dyn-options
2874 dynamically changeable options:
2875 -v -q -d --stats --vgdb=no --vgdb=yes --vgdb=full --vgdb-poll --vgdb-error
2876 --vgdb-stop-at --error-markers --show-error-list -s --show-below-main
2877 --time-stamp --trace-children --child-silent-after-fork --trace-sched
2878 --trace-signals --trace-symtab --trace-cfi --debug-dump=syms
2879 --debug-dump=line --debug-dump=frames --trace-redir --trace-syscalls
2880 --sym-offsets --progress-interval --merge-recursive-frames
2881 --vex-iropt-verbosity --suppressions --trace-flags --trace-notbelow
2882 --trace-notabove --profile-flags --gen-suppressions=no
2883 --gen-suppressions=yes --gen-suppressions=all --errors-for-leak-kinds
2884 --show-leak-kinds --leak-check-heuristics --show-reachable
2885 --show-possibly-lost --freelist-vol --freelist-big-blocks --leak-check=no
2886 --leak-check=summary --leak-check=yes --leak-check=full --ignore-ranges
2887 --ignore-range-below-sp --show-mismatched-frees
2888 valgrind: Use --help for more information.
2891 <para>The dynamic options can be changed the following ways:</para>
2895 <para>From the shell, using vgdb and the monitor command
2896 <computeroutput>v.clo</computeroutput>:</para>
2898 $ vgdb "v.clo --trace-children=yes --child-silent-after-fork=no"
2899 sending command v.clo --trace-children=yes --child-silent-after-fork=no to pid 4404
2902 <para>Note: you must use double quotes around the monitor command to avoid
2903 vgdb interpreting the valgrind options as its own options.</para>
2907 <para>From gdb, using the monitor command
2908 <computeroutput>v.clo</computeroutput>:</para>
2910 (gdb) monitor v.clo --trace-children=yes --child-silent-after-fork=no
2915 <para>From your program, using the client request
2916 <computeroutput>VALGRIND_CLO_CHANGE(option)</computeroutput>:</para>
2918 VALGRIND_CLO_CHANGE ("--trace-children=yes");
2919 VALGRIND_CLO_CHANGE ("--child-silent-after-fork=no");]]></screen>
2923 <para>Dynamically changeable options can be used in various circumstances,
2924 such as changing the valgrind behaviour during execution, loading
2925 suppression files as part of shared library initialisation, change or
2926 set valgrind options in child processes, ...
2935 <sect1 id="manual-core.pthreads" xreflabel="Support for Threads">
2936 <title>Support for Threads</title>
2938 <para>Threaded programs are fully supported.</para>
2940 <para>The main thing to point out with respect to threaded programs is
2941 that your program will use the native threading library, but Valgrind
2942 serialises execution so that only one (kernel) thread is running at a
2943 time. This approach avoids the horrible implementation problems of
2944 implementing a truly multithreaded version of Valgrind, but it does
2945 mean that threaded apps never use more than one CPU simultaneously,
2946 even if you have a multiprocessor or multicore machine.</para>
2948 <para>Valgrind doesn't schedule the threads itself. It merely ensures
2949 that only one thread runs at once, using a simple locking scheme. The
2950 actual thread scheduling remains under control of the OS kernel. What
2951 this does mean, though, is that your program will see very different
2952 scheduling when run on Valgrind than it does when running normally.
2953 This is both because Valgrind is serialising the threads, and because
2954 the code runs so much slower than normal.</para>
2956 <para>This difference in scheduling may cause your program to behave
2957 differently, if you have some kind of concurrency, critical race,
2958 locking, or similar, bugs. In that case you might consider using the
2959 tools Helgrind and/or DRD to track them down.</para>
2961 <para>On Linux, Valgrind also supports direct use of the
2962 <computeroutput>clone</computeroutput> system call,
2963 <computeroutput>futex</computeroutput> and so on.
2964 <computeroutput>clone</computeroutput> is supported where either
2965 everything is shared (a thread) or nothing is shared (fork-like); partial
2969 <!-- Referenced from both the manual and manpage -->
2970 <sect2 id="&vg-pthreads-perf-sched-id;" xreflabel="&vg-pthreads-perf-sched-label;">
2971 <title>Scheduling and Multi-Thread Performance</title>
2973 <para>A thread executes code only when it holds the abovementioned
2974 lock. After executing some number of instructions, the running thread
2975 will release the lock. All threads ready to run will then compete to
2976 acquire the lock.</para>
2978 <para>The <option>--fair-sched</option> option controls the locking mechanism
2979 used to serialise thread execution.</para>
2981 <para>The default pipe based locking mechanism
2982 (<option>--fair-sched=no</option>) is available on all
2983 platforms. Pipe based locking does not guarantee fairness between
2984 threads: it is quite likely that a thread that has just released the
2985 lock reacquires it immediately, even though other threads are ready to
2986 run. When using pipe based locking, different runs of the same
2987 multithreaded application might give very different thread
2990 <para>An alternative locking mechanism, based on futexes, is available
2991 on some platforms. If available, it is activated
2992 by <option>--fair-sched=yes</option> or
2993 <option>--fair-sched=try</option>. Futex based locking ensures
2994 fairness (round-robin scheduling) between threads: if multiple threads
2995 are ready to run, the lock will be given to the thread which first
2996 requested the lock. Note that a thread which is blocked in a system
2997 call (e.g. in a blocking read system call) has not (yet) requested the
2998 lock: such a thread requests the lock only after the system call is
3001 <para> The fairness of the futex based locking produces better
3002 reproducibility of thread scheduling for different executions of a
3003 multithreaded application. This better reproducibility is particularly
3004 helpful when using Helgrind or DRD.</para>
3006 <para>Valgrind's use of thread serialisation implies that only one
3007 thread at a time may run. On a multiprocessor/multicore system, the
3008 running thread is assigned to one of the CPUs by the OS kernel
3009 scheduler. When a thread acquires the lock, sometimes the thread will
3010 be assigned to the same CPU as the thread that just released the
3011 lock. Sometimes, the thread will be assigned to another CPU. When
3012 using pipe based locking, the thread that just acquired the lock
3013 will usually be scheduled on the same CPU as the thread that just
3014 released the lock. With the futex based mechanism, the thread that
3015 just acquired the lock will more often be scheduled on another
3018 <para>Valgrind's thread serialisation and CPU assignment by the OS
3019 kernel scheduler can interact badly with the CPU frequency scaling
3020 available on many modern CPUs. To decrease power consumption, the
3021 frequency of a CPU or core is automatically decreased if the CPU/core
3022 has not been used recently. If the OS kernel often assigns the thread
3023 which just acquired the lock to another CPU/core, it is quite likely
3024 that this CPU/core is currently at a low frequency. The frequency of
3025 this CPU will be increased after some time. However, during this
3026 time, the (only) running thread will have run at the low frequency.
3027 Once this thread has run for some time, it will release the lock.
3028 Another thread will acquire this lock, and might be scheduled again on
3029 another CPU whose clock frequency was decreased in the
3032 <para>The futex based locking causes threads to change CPUs/cores more
3033 often. So, if CPU frequency scaling is activated, the futex based
3034 locking might decrease significantly the performance of a
3035 multithreaded app running under Valgrind. Performance losses of up to
3036 50% degradation have been observed, as compared to running on a
3037 machine for which CPU frequency scaling has been disabled. The pipe
3038 based locking locking scheme also interacts badly with CPU frequency
3039 scaling, with performance losses in the range 10..20% having been
3042 <para>To avoid such performance degradation, you should indicate to
3043 the kernel that all CPUs/cores should always run at maximum clock
3044 speed. Depending on your Linux distribution, CPU frequency scaling
3045 may be controlled using a graphical interface or using command line
3047 <computeroutput>cpufreq-selector</computeroutput> or
3048 <computeroutput>cpufreq-set</computeroutput>.
3051 <para>An alternative way to avoid these problems is to tell the
3052 OS scheduler to tie a Valgrind process to a specific (fixed) CPU using the
3053 <computeroutput>taskset</computeroutput> command. This should ensure
3054 that the selected CPU does not fall below its maximum frequency
3055 setting so long as any thread of the program has work to do.
3063 <sect1 id="manual-core.signals" xreflabel="Handling of Signals">
3064 <title>Handling of Signals</title>
3066 <para>Valgrind has a fairly complete signal implementation. It should be
3067 able to cope with any POSIX-compliant use of signals.</para>
3069 <para>If you're using signals in clever ways (for example, catching
3070 SIGSEGV, modifying page state and restarting the instruction), you're
3071 probably relying on precise exceptions. In this case, you will need
3072 to use <option>--vex-iropt-register-updates=allregs-at-mem-access</option>
3073 or <option>--vex-iropt-register-updates=allregs-at-each-insn</option>.
3076 <para>If your program dies as a result of a fatal core-dumping signal,
3077 Valgrind will generate its own core file
3078 (<computeroutput>vgcore.NNNNN</computeroutput>) containing your program's
3079 state. You may use this core file for post-mortem debugging with GDB or
3080 similar. (Note: it will not generate a core if your core dump size limit is
3081 0.) At the time of writing the core dumps do not include all the floating
3082 point register information.</para>
3084 <para>In the unlikely event that Valgrind itself crashes, the operating system
3085 will create a core dump in the usual way.</para>
3090 <sect1 id="&vg-xtree-id;" xreflabel="&vg-xtree-label;">
3091 <title>Execution Trees</title>
3093 <para>An execution tree (xtree) is made of a set of stack traces, each
3094 stack trace is associated with some resource consumptions or event
3095 counts. Depending on the xtree, different event counts/resource
3096 consumptions can be recorded in the xtree. Multiple tools can
3097 produce memory use xtree. Memcheck can output the leak search results
3100 <para> A typical usage for an xtree is to show a graphical or textual
3101 representation of the heap usage of a program. The below figure is
3102 a heap usage xtree graphical representation produced by
3103 kcachegrind. In the kcachegrind output, you can see that main
3104 current heap usage (allocated indirectly) is 528 bytes : 388 bytes
3105 allocated indirectly via a call to function f1 and 140 bytes
3106 indirectly allocated via a call to function f2. f2 has allocated
3107 memory by calling g2, while f1 has allocated memory by calling g11
3108 and g12. g11, g12 and g2 have directly called a memory allocation
3109 function (malloc), and so have a non zero 'Self' value. Note that when
3110 kcachegrind shows an xtree, the 'Called' column and call nr indications in
3111 the Call Graph are not significant (always set to 0 or 1, independently
3112 of the real nr of calls. The kcachegrind versions >= 0.8.0 do not show
3113 anymore such irrelevant xtree call number information.</para>
3115 <graphic fileref="images/kcachegrind_xtree.png" scalefit="1"/>
3117 <para>An xtree heap memory report is produced at the end of the
3118 execution when required using the
3119 option <option>--xtree-memory</option>. It can also be produced on
3120 demand using the <option>xtmemory</option> monitor command (see
3121 <xref linkend="manual-core-adv.valgrind-monitor-commands"/>). Currently,
3122 an xtree heap memory report can be produced by
3123 the <option>memcheck</option>, <option>helgrind</option>
3124 and <option>massif</option> tools.</para>
3126 <para>The xtrees produced by the option
3127 <xref linkend="opt.xtree-memory"/> or the <option>xtmemory</option>
3128 monitor command are showing the following events/resource
3129 consumption describing heap usage:</para>
3132 <para><option>curB</option> current number of Bytes allocated. The
3133 number of allocated bytes is added to the <option>curB</option>
3134 value of a stack trace for each allocation. It is decreased when
3135 a block allocated by this stack trace is released (by another
3136 "freeing" stack trace)</para>
3140 <para><option>curBk</option> current number of Blocks allocated,
3141 maintained similary to curB : +1 for each allocation, -1 when
3142 the block is freed.</para>
3146 <para><option>totB</option> total allocated Bytes. This is
3147 increased for each allocation with the number of allocated bytes.</para>
3151 <para><option>totBk</option> total allocated Blocks, maintained similary
3152 to totB : +1 for each allocation.</para>
3156 <para><option>totFdB</option> total Freed Bytes, increased each time
3157 a block is released by this ("freeing") stack trace : + nr freed bytes
3158 for each free operation.</para>
3162 <para><option>totFdBk</option> total Freed Blocks, maintained similarly
3163 to totFdB : +1 for each free operation.</para>
3166 <para>Note that the last 4 counts are produced only when the
3167 <option>--xtree-memory=full</option> was given at startup.</para>
3169 <para>Xtrees can be saved in 2 file formats, the "Callgrind Format" and
3170 the "Massif Format".</para>
3174 <para>Callgrind Format</para>
3175 <para>An xtree file in the Callgrind Format contains a single callgraph,
3176 associating each stack trace with the values recorded
3177 in the xtree. </para>
3178 <para>Different Callgrind Format file visualizers are available:</para>
3179 <para>Valgrind distribution includes the <option>callgrind_annotate</option>
3180 command line utility that reads in the xtree data, and prints a sorted
3181 lists of functions, optionally with source annotation. Note that due to
3182 xtree specificities, you must give the option
3183 <option>--inclusive=yes</option> to callgrind_annotate.</para>
3184 <para>For graphical visualization of the data, you can use
3185 <ulink url="&cl-gui-url;">KCachegrind</ulink>, which is a KDE/Qt based
3186 GUI that makes it easy to navigate the large amount of data that
3187 an xtree can contain.</para>
3188 <para>Note that xtree Callgrind Format does not make use of the inline
3189 information even when specifying <option>--read-inline-info=yes</option>.
3194 <para>Massif Format</para>
3195 <para>An xtree file in the Massif Format contains one detailed tree
3196 callgraph data for each type of event recorded in the xtree. So,
3197 for <option>--xtree-memory=alloc</option>, the output file will
3198 contain 2 detailed trees (for the counts <option>curB</option>
3199 and <option>curBk</option>),
3200 while <option>--xtree-memory=full</option> will give a file
3201 with 6 detailed trees.</para>
3202 <para>Different Massif Format file visualizers are available. Valgrind
3203 distribution includes the <option>ms_print</option>
3204 command line utility that produces an easy to read reprentation of
3205 a massif output file. See <xref linkend="ms-manual.using-print"/> and
3206 <xref linkend="ms-manual.using-visualizer"/> for more details
3207 about visualising Massif Format output files.</para>
3208 <para>Note that xtree Massif Format makes use of the inline
3209 information when specifying <option>--read-inline-info=yes</option>.
3215 <para>Note that for equivalent information, the Callgrind Format is more compact
3216 than the Massif Format. However, the Callgrind Format always contains the
3217 full data: there is no filtering done during file production, filtering is
3218 done by visualizers such as kcachegrind. kcachegrind is particularly easy to
3219 use to analyse big xtree data containing multiple events counts or resources
3220 consumption. The Massif Format (optionally) only contains a part of the data.
3221 For example, the Massif tool might filter some of the data, according to the
3222 <option>--threshold</option> option.
3225 <para>To clarify the xtree concept, the below gives several extracts of
3226 the output produced by the following commands:
3228 valgrind --xtree-memory=full --xtree-memory-file=xtmemory.kcg mfg
3229 callgrind_annotate --auto=yes --inclusive=yes --sort=curB:100,curBk:100,totB:100,totBk:100,totFdB:100,totFdBk:100 xtmemory.kcg
3233 <para>The below extract shows that the program mfg has allocated in
3234 total 770 bytes in 60 different blocks. Of these 60 blocks, 19 were
3235 freed, releasing a total of 242 bytes. The heap currently contains
3236 528 bytes in 41 blocks.</para>
3238 --------------------------------------------------------------------------------
3239 curB curBk totB totBk totFdB totFdBk
3240 --------------------------------------------------------------------------------
3241 528 41 770 60 242 19 PROGRAM TOTALS
3244 <para>The below gives more details about which functions have
3245 allocated or released memory. As an example, we see that main has
3246 (directly or indirectly) allocated 770 bytes of memory and freed
3247 (directly or indirectly) 242 bytes of memory. The function f1 has
3248 (directly or indirectly) allocated 570 bytes of memory, and has not
3249 (directly or indirectly) freed memory. Of the 570 bytes allocated
3250 by function f1, 388 bytes (34 blocks) have not been
3253 --------------------------------------------------------------------------------
3254 curB curBk totB totBk totFdB totFdBk file:function
3255 --------------------------------------------------------------------------------
3256 528 41 770 60 242 19 mfg.c:main
3257 388 34 570 50 0 0 mfg.c:f1
3258 220 20 330 30 0 0 mfg.c:g11
3259 168 14 240 20 0 0 mfg.c:g12
3260 140 7 200 10 0 0 mfg.c:g2
3261 140 7 200 10 0 0 mfg.c:f2
3262 0 0 0 0 131 10 mfg.c:freeY
3263 0 0 0 0 111 9 mfg.c:freeX
3266 <para>The below gives a more detailed information about the callgraph
3267 and which source lines/calls have (directly or indirectly) allocated or
3268 released memory. The below shows that the 770 bytes allocated by
3269 main have been indirectly allocated by calls to f1 and f2.
3270 Similarly, we see that the 570 bytes allocated by f1 have been
3271 indirectly allocated by calls to g11 and g12. Of the 330 bytes allocated
3272 by the 30 calls to g11, 168 bytes have not been freed.
3273 The function freeY (called once by main) has released in total
3274 10 blocks and 131 bytes. </para>
3276 --------------------------------------------------------------------------------
3277 -- Auto-annotated source: /home/philippe/valgrind/littleprogs/ + mfg.c
3278 --------------------------------------------------------------------------------
3279 curB curBk totB totBk totFdB totFdBk
3281 . . . . . . static void freeY(void)
3284 . . . . . . for (i = 0; i < next_ptr; i++)
3285 . . . . . . if(i % 5 == 0 && ptrs[i] != NULL)
3286 0 0 0 0 131 10 free(ptrs[i]);
3288 . . . . . . static void f1(void)
3291 . . . . . . for (i = 0; i < 30; i++)
3292 220 20 330 30 0 0 g11();
3293 . . . . . . for (i = 0; i < 20; i++)
3294 168 14 240 20 0 0 g12();
3296 . . . . . . int main()
3298 388 34 570 50 0 0 f1();
3299 140 7 200 10 0 0 f2();
3300 0 0 0 0 111 9 freeX();
3301 0 0 0 0 131 10 freeY();
3302 . . . . . . return 0;
3306 <para>Heap memory xtrees are helping to understand how your (big)
3307 program is using the heap. A full heap memory xtree helps to pin
3308 point some code that allocates a lot of small objects : allocating
3309 such small objects might be replaced by more efficient technique,
3310 such as allocating a big block using malloc, and then diviving this
3311 block into smaller blocks in order to decrease the cpu and/or memory
3312 overhead of allocating a lot of small blocks. Such full xtree information
3313 complements e.g. what callgrind can show: callgrind can show the number
3314 of calls to a function (such as malloc) but does not indicate the volume
3315 of memory allocated (or freed).</para>
3317 <para>A full heap memory xtree also can identify the code that allocates
3318 and frees a lot of blocks : the total foot print of the program might
3319 not reflect the fact that the same memory was over and over allocated
3320 then released.</para>
3322 <para>Finally, Xtree visualizers such as kcachegrind are helping to
3323 identify big memory consumers, in order to possibly optimise the
3324 amount of memory needed by your program.</para>
3328 <sect1 id="manual-core.install" xreflabel="Building and Installing">
3329 <title>Building and Installing Valgrind</title>
3331 <para>We use the standard Unix
3332 <computeroutput>./configure</computeroutput>,
3333 <computeroutput>make</computeroutput>, <computeroutput>make
3334 install</computeroutput> mechanism. Once you have completed
3335 <computeroutput>make install</computeroutput> you may then want
3336 to run the regression tests
3337 with <computeroutput>make regtest</computeroutput>.
3340 <para>In addition to the usual
3341 <option>--prefix=/path/to/install/tree</option>, there are three
3342 options which affect how Valgrind is built:
3346 <para><option>--enable-inner</option></para>
3347 <para>This builds Valgrind with some special magic hacks which make
3348 it possible to run it on a standard build of Valgrind (what the
3349 developers call "self-hosting"). Ordinarily you should not use
3350 this option as various kinds of safety checks are disabled.
3355 <para><option>--enable-only64bit</option></para>
3356 <para><option>--enable-only32bit</option></para>
3357 <para>On 64-bit platforms (amd64-linux, ppc64-linux,
3358 amd64-darwin), Valgrind is by default built in such a way that
3359 both 32-bit and 64-bit executables can be run. Sometimes this
3360 cleverness is a problem for a variety of reasons. These two
3361 options allow for single-target builds in this situation. If you
3362 issue both, the configure script will complain. Note they are
3363 ignored on 32-bit-only platforms (x86-linux, ppc32-linux,
3364 arm-linux, x86-darwin).
3371 <para>The <computeroutput>configure</computeroutput> script tests
3372 the version of the X server currently indicated by the current
3373 <computeroutput>$DISPLAY</computeroutput>. This is a known bug.
3374 The intention was to detect the version of the current X
3375 client libraries, so that correct suppressions could be selected
3376 for them, but instead the test checks the server version. This
3377 is just plain wrong.</para>
3379 <para>If you are building a binary package of Valgrind for
3380 distribution, please read <literal>README_PACKAGERS</literal>
3381 <xref linkend="dist.readme-packagers"/>. It contains some
3382 important information.</para>
3384 <para>Apart from that, there's not much excitement here. Let us
3385 know if you have build problems.</para>
3391 <sect1 id="manual-core.problems" xreflabel="If You Have Problems">
3392 <title>If You Have Problems</title>
3394 <para>Contact us at <ulink url="&vg-url;">&vg-url;</ulink>.</para>
3396 <para>See <xref linkend="manual-core.limits"/> for the known
3397 limitations of Valgrind, and for a list of programs which are
3398 known not to work on it.</para>
3400 <para>All parts of the system make heavy use of assertions and
3401 internal self-checks. They are permanently enabled, and we have no
3402 plans to disable them. If one of them breaks, please mail us!</para>
3404 <para>If you get an assertion failure
3405 in <filename>m_mallocfree.c</filename>, this may have happened because
3406 your program wrote off the end of a heap block, or before its
3407 beginning, thus corrupting heap metadata. Valgrind hopefully will have
3408 emitted a message to that effect before dying in this way.</para>
3410 <para>Read the <xref linkend="FAQ"/> for more advice about common problems,
3411 crashes, etc.</para>
3417 <sect1 id="manual-core.limits" xreflabel="Limitations">
3418 <title>Limitations</title>
3420 <para>The following list of limitations seems long. However, most
3421 programs actually work fine.</para>
3423 <para>Valgrind will run programs on the supported platforms
3424 subject to the following constraints:</para>
3428 <para>On Linux, Valgrind determines at startup the size of the 'brk
3429 segment' using the RLIMIT_DATA rlim_cur, with a minimum of 1 MB and
3430 a maximum of 8 MB. Valgrind outputs a message each time a program
3431 tries to extend the brk segment beyond the size determined at
3432 startup. Most programs will work properly with this limit,
3433 typically by switching to the use of mmap to get more memory.
3434 If your program really needs a big brk segment, you must change
3435 the 8 MB hardcoded limit and recompile Valgrind.
3440 <para>On x86 and amd64, there is no support for 3DNow!
3441 instructions. If the translator encounters these, Valgrind will
3442 generate a SIGILL when the instruction is executed. Apart from
3443 that, on x86 and amd64, essentially all instructions are supported,
3444 up to and including AVX and AES in 64-bit mode and SSSE3 in 32-bit
3445 mode. 32-bit mode does in fact support the bare minimum SSE4
3446 instructions needed to run programs on MacOSX 10.6 on 32-bit
3452 <para>On ppc32 and ppc64, almost all integer, floating point and
3453 Altivec instructions are supported. Specifically: integer and FP
3454 insns that are mandatory for PowerPC, the "General-purpose
3455 optional" group (fsqrt, fsqrts, stfiwx), the "Graphics optional"
3456 group (fre, fres, frsqrte, frsqrtes), and the Altivec (also known
3457 as VMX) SIMD instruction set, are supported. Also, instructions
3458 from the Power ISA 2.05 specification, as present in POWER6 CPUs,
3459 are supported.</para>
3463 <para>On ARM, essentially the entire ARMv7-A instruction set
3464 is supported, in both ARM and Thumb mode. ThumbEE and Jazelle are
3465 not supported. NEON, VFPv3 and ARMv6 media support is fairly
3471 <para>If your program does its own memory management, rather than
3472 using malloc/new/free/delete, it should still work, but Memcheck's
3473 error checking won't be so effective. If you describe your
3474 program's memory management scheme using "client requests" (see
3475 <xref linkend="manual-core-adv.clientreq"/>), Memcheck can do
3476 better. Nevertheless, using malloc/new and free/delete is still
3477 the best approach.</para>
3481 <para>Valgrind's signal simulation is not as robust as it could be.
3482 Basic POSIX-compliant sigaction and sigprocmask functionality is
3483 supplied, but it's conceivable that things could go badly awry if you
3484 do weird things with signals. Workaround: don't. Programs that do
3485 non-POSIX signal tricks are in any case inherently unportable, so
3486 should be avoided if possible.</para>
3490 <para>Machine instructions, and system calls, have been implemented
3491 on demand. So it's possible, although unlikely, that a program will
3492 fall over with a message to that effect. If this happens, please
3493 report all the details printed out, so we can try and implement the
3494 missing feature.</para>
3498 <para>Memory consumption of your program is majorly increased
3499 whilst running under Valgrind's Memcheck tool. This is due to the
3500 large amount of administrative information maintained behind the
3501 scenes. Another cause is that Valgrind dynamically translates the
3502 original executable. Translated, instrumented code is 12-18 times
3503 larger than the original so you can easily end up with 150+ MB of
3504 translations when running (eg) a web browser.</para>
3508 <para>Valgrind can handle dynamically-generated code just fine. If
3509 you regenerate code over the top of old code (ie. at the same
3510 memory addresses), if the code is on the stack Valgrind will
3511 realise the code has changed, and work correctly. This is
3512 necessary to handle the trampolines GCC uses to implemented nested
3513 functions. If you regenerate code somewhere other than the stack,
3514 and you are running on an 32- or 64-bit x86 CPU, you will need to
3515 use the <option>--smc-check=all</option> option, and Valgrind will
3516 run more slowly than normal. Or you can add client requests that
3517 tell Valgrind when your program has overwritten code.
3519 <para> On other platforms (ARM, PowerPC) Valgrind observes and
3520 honours the cache invalidation hints that programs are obliged to
3521 emit to notify new code, and so self-modifying-code support should
3522 work automatically, without the need
3523 for <option>--smc-check=all</option>.</para>
3527 <para>Valgrind has the following limitations
3528 in its implementation of x86/AMD64 floating point relative to
3531 <para>Precision: There is no support for 80 bit arithmetic.
3532 Internally, Valgrind represents all such "long double" numbers in 64
3533 bits, and so there may be some differences in results. Whether or
3534 not this is critical remains to be seen. Note, the x86/amd64
3535 fldt/fstpt instructions (read/write 80-bit numbers) are correctly
3536 simulated, using conversions to/from 64 bits, so that in-memory
3537 images of 80-bit numbers look correct if anyone wants to see.</para>
3539 <para>The impression observed from many FP regression tests is that
3540 the accuracy differences aren't significant. Generally speaking, if
3541 a program relies on 80-bit precision, there may be difficulties
3542 porting it to non x86/amd64 platforms which only support 64-bit FP
3543 precision. Even on x86/amd64, the program may get different results
3544 depending on whether it is compiled to use SSE2 instructions (64-bits
3545 only), or x87 instructions (80-bit). The net effect is to make FP
3546 programs behave as if they had been run on a machine with 64-bit IEEE
3547 floats, for example PowerPC. On amd64 FP arithmetic is done by
3548 default on SSE2, so amd64 looks more like PowerPC than x86 from an FP
3549 perspective, and there are far fewer noticeable accuracy differences
3550 than with x86.</para>
3552 <para>Rounding: Valgrind does observe the 4 IEEE-mandated rounding
3553 modes (to nearest, to +infinity, to -infinity, to zero) for the
3554 following conversions: float to integer, integer to float where
3555 there is a possibility of loss of precision, and float-to-float
3556 rounding. For all other FP operations, only the IEEE default mode
3557 (round to nearest) is supported.</para>
3559 <para>Numeric exceptions in FP code: IEEE754 defines five types of
3560 numeric exception that can happen: invalid operation (sqrt of
3561 negative number, etc), division by zero, overflow, underflow,
3562 inexact (loss of precision).</para>
3564 <para>For each exception, two courses of action are defined by IEEE754:
3565 either (1) a user-defined exception handler may be called, or (2) a
3566 default action is defined, which "fixes things up" and allows the
3567 computation to proceed without throwing an exception.</para>
3569 <para>Currently Valgrind only supports the default fixup actions.
3570 Again, feedback on the importance of exception support would be
3573 <para>When Valgrind detects that the program is trying to exceed any
3574 of these limitations (setting exception handlers, rounding mode, or
3575 precision control), it can print a message giving a traceback of
3576 where this has happened, and continue execution. This behaviour used
3577 to be the default, but the messages are annoying and so showing them
3578 is now disabled by default. Use <option>--show-emwarns=yes</option> to see
3581 <para>The above limitations define precisely the IEEE754 'default'
3582 behaviour: default fixup on all exceptions, round-to-nearest
3583 operations, and 64-bit precision.</para>
3587 <para>Valgrind has the following limitations in
3588 its implementation of x86/AMD64 SSE2 FP arithmetic, relative to
3591 <para>Essentially the same: no exceptions, and limited observance of
3592 rounding mode. Also, SSE2 has control bits which make it treat
3593 denormalised numbers as zero (DAZ) and a related action, flush
3594 denormals to zero (FTZ). Both of these cause SSE2 arithmetic to be
3595 less accurate than IEEE requires. Valgrind detects, ignores, and can
3596 warn about, attempts to enable either mode.</para>
3600 <para>Valgrind has the following limitations in
3601 its implementation of ARM VFPv3 arithmetic, relative to
3604 <para>Essentially the same: no exceptions, and limited observance
3605 of rounding mode. Also, switching the VFP unit into vector mode
3606 will cause Valgrind to abort the program -- it has no way to
3607 emulate vector uses of VFP at a reasonable performance level. This
3608 is no big deal given that non-scalar uses of VFP instructions are
3609 in any case deprecated.</para>
3613 <para>Valgrind has the following limitations
3614 in its implementation of PPC32 and PPC64 floating point
3615 arithmetic, relative to IEEE754.</para>
3617 <para>Scalar (non-Altivec): Valgrind provides a bit-exact emulation of
3618 all floating point instructions, except for "fre" and "fres", which are
3619 done more precisely than required by the PowerPC architecture specification.
3620 All floating point operations observe the current rounding mode.
3623 <para>However, fpscr[FPRF] is not set after each operation. That could
3624 be done but would give measurable performance overheads, and so far
3625 no need for it has been found.</para>
3627 <para>As on x86/AMD64, IEEE754 exceptions are not supported: all floating
3628 point exceptions are handled using the default IEEE fixup actions.
3629 Valgrind detects, ignores, and can warn about, attempts to unmask
3630 the 5 IEEE FP exception kinds by writing to the floating-point status
3631 and control register (fpscr).
3634 <para>Vector (Altivec, VMX): essentially as with x86/AMD64 SSE/SSE2:
3635 no exceptions, and limited observance of rounding mode.
3636 For Altivec, FP arithmetic
3637 is done in IEEE/Java mode, which is more accurate than the Linux default
3638 setting. "More accurate" means that denormals are handled properly,
3639 rather than simply being flushed to zero.</para>
3643 <para>Programs which are known not to work are:</para>
3646 <para>emacs starts up but immediately concludes it is out of
3647 memory and aborts. It may be that Memcheck does not provide
3648 a good enough emulation of the
3649 <computeroutput>mallinfo</computeroutput> function.
3650 Emacs works fine if you build it to use
3651 the standard malloc/free routines.</para>
3658 <sect1 id="manual-core.example" xreflabel="An Example Run">
3659 <title>An Example Run</title>
3661 <para>This is the log for a run of a small program using Memcheck.
3662 The program is in fact correct, and the reported error is as the
3663 result of a potentially serious code generation bug in GNU g++
3664 (snapshot 20010527).</para>
3666 <programlisting><![CDATA[
3667 sewardj@phoenix:~/newmat10$ ~/Valgrind-6/valgrind -v ./bogon
3668 ==25832== Valgrind 0.10, a memory error detector for x86 RedHat 7.1.
3669 ==25832== Copyright (C) 2000-2001, and GNU GPL'd, by Julian Seward.
3670 ==25832== Startup, with flags:
3671 ==25832== --suppressions=/home/sewardj/Valgrind/redhat71.supp
3672 ==25832== reading syms from /lib/ld-linux.so.2
3673 ==25832== reading syms from /lib/libc.so.6
3674 ==25832== reading syms from /mnt/pima/jrs/Inst/lib/libgcc_s.so.0
3675 ==25832== reading syms from /lib/libm.so.6
3676 ==25832== reading syms from /mnt/pima/jrs/Inst/lib/libstdc++.so.3
3677 ==25832== reading syms from /home/sewardj/Valgrind/valgrind.so
3678 ==25832== reading syms from /proc/self/exe
3680 ==25832== Invalid read of size 4
3681 ==25832== at 0x8048724: BandMatrix::ReSize(int,int,int) (bogon.cpp:45)
3682 ==25832== by 0x80487AF: main (bogon.cpp:66)
3683 ==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd
3685 ==25832== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
3686 ==25832== malloc/free: in use at exit: 0 bytes in 0 blocks.
3687 ==25832== malloc/free: 0 allocs, 0 frees, 0 bytes allocated.
3688 ==25832== For a detailed leak analysis, rerun with: --leak-check=yes
3689 ]]></programlisting>
3691 <para>The GCC folks fixed this about a week before GCC 3.0
3697 <sect1 id="manual-core.warnings" xreflabel="Warning Messages">
3698 <title>Warning Messages You Might See</title>
3700 <para>Some of these only appear if you run in verbose mode
3701 (enabled by <option>-v</option>):</para>
3706 <para><computeroutput>More than 100 errors detected. Subsequent
3707 errors will still be recorded, but in less detail than
3708 before.</computeroutput></para>
3710 <para>After 100 different errors have been shown, Valgrind becomes
3711 more conservative about collecting them. It then requires only the
3712 program counters in the top two stack frames to match when deciding
3713 whether or not two errors are really the same one. Prior to this
3714 point, the PCs in the top four frames are required to match. This
3715 hack has the effect of slowing down the appearance of new errors
3716 after the first 100. The 100 constant can be changed by recompiling
3721 <para><computeroutput>More than 1000 errors detected. I'm not
3722 reporting any more. Final error counts may be inaccurate. Go fix
3723 your program!</computeroutput></para>
3725 <para>After 1000 different errors have been detected, Valgrind
3726 ignores any more. It seems unlikely that collecting even more
3727 different ones would be of practical help to anybody, and it avoids
3728 the danger that Valgrind spends more and more of its time comparing
3729 new errors against an ever-growing collection. As above, the 1000
3730 number is a compile-time constant.</para>
3734 <para><computeroutput>Warning: client switching stacks?</computeroutput></para>
3736 <para>Valgrind spotted such a large change in the stack pointer
3737 that it guesses the client is switching to a different stack. At
3738 this point it makes a kludgey guess where the base of the new
3739 stack is, and sets memory permissions accordingly. At the moment
3740 "large change" is defined as a change of more that 2000000 in the
3741 value of the stack pointer register. If Valgrind guesses wrong,
3742 you may get many bogus error messages following this and/or have
3743 crashes in the stack trace recording code. You might avoid these
3744 problems by informing Valgrind about the stack bounds using
3745 VALGRIND_STACK_REGISTER client request. </para>
3750 <para><computeroutput>Warning: client attempted to close Valgrind's
3751 logfile fd <number></computeroutput></para>
3753 <para>Valgrind doesn't allow the client to close the logfile,
3754 because you'd never see any diagnostic information after that point.
3755 If you see this message, you may want to use the
3756 <option>--log-fd=<number></option> option to specify a
3757 different logfile file-descriptor number.</para>
3761 <para><computeroutput>Warning: noted but unhandled ioctl
3762 <number></computeroutput></para>
3764 <para>Valgrind observed a call to one of the vast family of
3765 <computeroutput>ioctl</computeroutput> system calls, but did not
3766 modify its memory status info (because nobody has yet written a
3767 suitable wrapper). The call will still have gone through, but you may get
3768 spurious errors after this as a result of the non-update of the
3773 <para><computeroutput>Warning: set address range perms: large range
3774 <number></computeroutput></para>
3776 <para>Diagnostic message, mostly for benefit of the Valgrind
3777 developers, to do with memory permissions.</para>