| 1 |
<html> |
| 2 |
<head> |
| 3 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 4 |
<title>2. Using and understanding the Valgrind core</title> |
| 5 |
<link rel="stylesheet" type="text/css" href="vg_basic.css"> |
| 6 |
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"> |
| 7 |
<link rel="home" href="index.html" title="Valgrind Documentation"> |
| 8 |
<link rel="up" href="manual.html" title="Valgrind User Manual"> |
| 9 |
<link rel="prev" href="manual-intro.html" title="1. Introduction"> |
| 10 |
<link rel="next" href="manual-core-adv.html" title="3. Using and understanding the Valgrind core: Advanced Topics"> |
| 11 |
</head> |
| 12 |
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| 13 |
<div><table class="nav" width="100%" cellspacing="3" cellpadding="3" border="0" summary="Navigation header"><tr> |
| 14 |
<td width="22px" align="center" valign="middle"><a accesskey="p" href="manual-intro.html"><img src="images/prev.png" width="18" height="21" border="0" alt="Prev"></a></td> |
| 15 |
<td width="25px" align="center" valign="middle"><a accesskey="u" href="manual.html"><img src="images/up.png" width="21" height="18" border="0" alt="Up"></a></td> |
| 16 |
<td width="31px" align="center" valign="middle"><a accesskey="h" href="index.html"><img src="images/home.png" width="27" height="20" border="0" alt="Up"></a></td> |
| 17 |
<th align="center" valign="middle">Valgrind User Manual</th> |
| 18 |
<td width="22px" align="center" valign="middle"><a accesskey="n" href="manual-core-adv.html"><img src="images/next.png" width="18" height="21" border="0" alt="Next"></a></td> |
| 19 |
</tr></table></div> |
| 20 |
<div class="chapter"> |
| 21 |
<div class="titlepage"><div><div><h1 class="title"> |
| 22 |
<a name="manual-core"></a>2. Using and understanding the Valgrind core</h1></div></div></div> |
| 23 |
<div class="toc"> |
| 24 |
<p><b>Table of Contents</b></p> |
| 25 |
<dl class="toc"> |
| 26 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.whatdoes">2.1. What Valgrind does with your program</a></span></dt> |
| 27 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.started">2.2. Getting started</a></span></dt> |
| 28 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.comment">2.3. The Commentary</a></span></dt> |
| 29 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.report">2.4. Reporting of errors</a></span></dt> |
| 30 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.suppress">2.5. Suppressing errors</a></span></dt> |
| 31 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.debuginfod">2.6. Debuginfod</a></span></dt> |
| 32 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.options">2.7. Core Command-line Options</a></span></dt> |
| 33 |
<dd><dl> |
| 34 |
<dt><span class="sect2"><a href="manual-core.html#manual-core.toolopts">2.7.1. Tool-selection Option</a></span></dt> |
| 35 |
<dt><span class="sect2"><a href="manual-core.html#manual-core.basicopts">2.7.2. Basic Options</a></span></dt> |
| 36 |
<dt><span class="sect2"><a href="manual-core.html#manual-core.erropts">2.7.3. Error-related Options</a></span></dt> |
| 37 |
<dt><span class="sect2"><a href="manual-core.html#manual-core.mallocopts">2.7.4. malloc-related Options</a></span></dt> |
| 38 |
<dt><span class="sect2"><a href="manual-core.html#manual-core.rareopts">2.7.5. Uncommon Options</a></span></dt> |
| 39 |
<dt><span class="sect2"><a href="manual-core.html#manual-core.debugopts">2.7.6. Debugging Options</a></span></dt> |
| 40 |
<dt><span class="sect2"><a href="manual-core.html#manual-core.defopts">2.7.7. Setting Default Options</a></span></dt> |
| 41 |
<dt><span class="sect2"><a href="manual-core.html#manual-core.dynopts">2.7.8. Dynamically Changing Options</a></span></dt> |
| 42 |
</dl></dd> |
| 43 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.pthreads">2.8. Support for Threads</a></span></dt> |
| 44 |
<dd><dl><dt><span class="sect2"><a href="manual-core.html#manual-core.pthreads_perf_sched">2.8.1. Scheduling and Multi-Thread Performance</a></span></dt></dl></dd> |
| 45 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.signals">2.9. Handling of Signals</a></span></dt> |
| 46 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.xtree">2.10. Execution Trees</a></span></dt> |
| 47 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.install">2.11. Building and Installing Valgrind</a></span></dt> |
| 48 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.problems">2.12. If You Have Problems</a></span></dt> |
| 49 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.limits">2.13. Limitations</a></span></dt> |
| 50 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.example">2.14. An Example Run</a></span></dt> |
| 51 |
<dt><span class="sect1"><a href="manual-core.html#manual-core.warnings">2.15. Warning Messages You Might See</a></span></dt> |
| 52 |
</dl> |
| 53 |
</div> |
| 54 |
<p>This chapter describes the Valgrind core services, command-line |
| 55 |
options and behaviours. That means it is relevant regardless of what |
| 56 |
particular tool you are using. The information should be sufficient for you |
| 57 |
to make effective day-to-day use of Valgrind. Advanced topics related to |
| 58 |
the Valgrind core are described in <a class="xref" href="manual-core-adv.html" title="3. Using and understanding the Valgrind core: Advanced Topics">Valgrind's core: advanced topics</a>. |
| 59 |
</p> |
| 60 |
<p> |
| 61 |
A point of terminology: most references to "Valgrind" in this chapter |
| 62 |
refer to the Valgrind core services. </p> |
| 63 |
<div class="sect1"> |
| 64 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 65 |
<a name="manual-core.whatdoes"></a>2.1. What Valgrind does with your program</h2></div></div></div> |
| 66 |
<p>Valgrind is designed to be as non-intrusive as possible. It works |
| 67 |
directly with existing executables. You don't need to recompile, relink, |
| 68 |
or otherwise modify the program to be checked.</p> |
| 69 |
<p>You invoke Valgrind like this:</p> |
| 70 |
<pre class="programlisting"> |
| 71 |
valgrind [valgrind-options] your-prog [your-prog-options]</pre> |
| 72 |
<p>The most important option is <code class="option">--tool</code> which dictates |
| 73 |
which Valgrind tool to run. For example, if want to run the command |
| 74 |
<code class="computeroutput">ls -l</code> using the memory-checking tool |
| 75 |
Memcheck, issue this command:</p> |
| 76 |
<pre class="programlisting"> |
| 77 |
valgrind --tool=memcheck ls -l</pre> |
| 78 |
<p>However, Memcheck is the default, so if you want to use it you can |
| 79 |
omit the <code class="option">--tool</code> option.</p> |
| 80 |
<p>Regardless of which tool is in use, Valgrind takes control of your |
| 81 |
program before it starts. Debugging information is read from the |
| 82 |
executable and associated libraries, so that error messages and other |
| 83 |
outputs can be phrased in terms of source code locations, when |
| 84 |
appropriate.</p> |
| 85 |
<p>Your program is then run on a synthetic CPU provided by the |
| 86 |
Valgrind core. As new code is executed for the first time, the core |
| 87 |
hands the code to the selected tool. The tool adds its own |
| 88 |
instrumentation code to this and hands the result back to the core, |
| 89 |
which coordinates the continued execution of this instrumented |
| 90 |
code.</p> |
| 91 |
<p>The amount of instrumentation code added varies widely between |
| 92 |
tools. At one end of the scale, Memcheck adds code to check every |
| 93 |
memory access and every value computed, |
| 94 |
making it run 10-50 times slower than natively. |
| 95 |
At the other end of the spectrum, the minimal tool, called Nulgrind, |
| 96 |
adds no instrumentation at all and causes in total "only" about a 4 times |
| 97 |
slowdown.</p> |
| 98 |
<p>Valgrind simulates every single instruction your program executes. |
| 99 |
Because of this, the active tool checks, or profiles, not only the code |
| 100 |
in your application but also in all supporting dynamically-linked libraries, |
| 101 |
including the C library, graphical libraries, and so on.</p> |
| 102 |
<p>If you're using an error-detection tool, Valgrind may |
| 103 |
detect errors in system libraries, for example the GNU C or X11 |
| 104 |
libraries, which you have to use. You might not be interested in these |
| 105 |
errors, since you probably have no control over that code. Therefore, |
| 106 |
Valgrind allows you to selectively suppress errors, by recording them in |
| 107 |
a suppressions file which is read when Valgrind starts up. The build |
| 108 |
mechanism selects default suppressions which give reasonable |
| 109 |
behaviour for the OS and libraries detected on your machine. |
| 110 |
To make it easier to write suppressions, you can use the |
| 111 |
<code class="option">--gen-suppressions=yes</code> option. This tells Valgrind to |
| 112 |
print out a suppression for each reported error, which you can then |
| 113 |
copy into a suppressions file.</p> |
| 114 |
<p>Valgrind will try to match the behaviour of applications |
| 115 |
compiled to run on the same OS and libraries that Valgrind was |
| 116 |
built with. If you use different libraries or a different |
| 117 |
OS version there may be some small differences in behaviour.</p> |
| 118 |
<p>Different error-checking tools report different kinds of errors. |
| 119 |
The suppression mechanism therefore allows you to say which tool or |
| 120 |
tool(s) each suppression applies to.</p> |
| 121 |
</div> |
| 122 |
<div class="sect1"> |
| 123 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 124 |
<a name="manual-core.started"></a>2.2. Getting started</h2></div></div></div> |
| 125 |
<p>First off, consider whether it might be beneficial to recompile |
| 126 |
your application and supporting libraries with debugging info enabled |
| 127 |
(the <code class="option">-g</code> option). Without debugging info, the best |
| 128 |
Valgrind tools will be able to do is guess which function a particular |
| 129 |
piece of code belongs to, which makes both error messages and profiling |
| 130 |
output nearly useless. With <code class="option">-g</code>, you'll get |
| 131 |
messages which point directly to the relevant source code lines.</p> |
| 132 |
<p>Another option you might like to consider, if you are working with |
| 133 |
C++, is <code class="option">-fno-inline</code>. That makes it easier to see the |
| 134 |
function-call chain, which can help reduce confusion when navigating |
| 135 |
around large C++ apps. For example, debugging |
| 136 |
OpenOffice.org with Memcheck is a bit easier when using this option. You |
| 137 |
don't have to do this, but doing so helps Valgrind produce more accurate |
| 138 |
and less confusing error reports. Chances are you're set up like this |
| 139 |
already, if you intended to debug your program with GNU GDB, or some |
| 140 |
other debugger. Alternatively, the Valgrind option |
| 141 |
<code class="option">--read-inline-info=yes</code> instructs Valgrind to read |
| 142 |
the debug information describing inlining information. With this, |
| 143 |
function call chain will be properly shown, even when your application |
| 144 |
is compiled with inlining. </p> |
| 145 |
<p>If you are planning to use Memcheck: On rare |
| 146 |
occasions, compiler optimisations (at <code class="option">-O2</code> |
| 147 |
and above, and sometimes <code class="option">-O1</code>) have been |
| 148 |
observed to generate code which fools Memcheck into wrongly reporting |
| 149 |
uninitialised value errors, or missing uninitialised value errors. We have |
| 150 |
looked in detail into fixing this, and unfortunately the result is that |
| 151 |
doing so would give a further significant slowdown in what is already a slow |
| 152 |
tool. So the best solution is to turn off optimisation altogether. Since |
| 153 |
this often makes things unmanageably slow, a reasonable compromise is to use |
| 154 |
<code class="option">-O</code>. This gets you the majority of the |
| 155 |
benefits of higher optimisation levels whilst keeping relatively small the |
| 156 |
chances of false positives or false negatives from Memcheck. Also, you |
| 157 |
should compile your code with <code class="option">-Wall</code> because |
| 158 |
it can identify some or all of the problems that Valgrind can miss at the |
| 159 |
higher optimisation levels. (Using <code class="option">-Wall</code> |
| 160 |
is also a good idea in general.) All other tools (as far as we know) are |
| 161 |
unaffected by optimisation level, and for profiling tools like Cachegrind it |
| 162 |
is better to compile your program at its normal optimisation level.</p> |
| 163 |
<p>Valgrind understands the DWARF2/3/4 formats used by GCC 3.1 and |
| 164 |
later. The reader for "stabs" debugging format (used by GCC versions |
| 165 |
prior to 3.1) has been disabled in Valgrind 3.9.0.</p> |
| 166 |
<p>When you're ready to roll, run Valgrind as described above. |
| 167 |
Note that you should run the real |
| 168 |
(machine-code) executable here. If your application is started by, for |
| 169 |
example, a shell or Perl script, you'll need to modify it to invoke |
| 170 |
Valgrind on the real executables. Running such scripts directly under |
| 171 |
Valgrind will result in you getting error reports pertaining to |
| 172 |
<code class="filename">/bin/sh</code>, |
| 173 |
<code class="filename">/usr/bin/perl</code>, or whatever interpreter |
| 174 |
you're using. This may not be what you want and can be confusing. You |
| 175 |
can force the issue by giving the option |
| 176 |
<code class="option">--trace-children=yes</code>, but confusion is still |
| 177 |
likely.</p> |
| 178 |
</div> |
| 179 |
<div class="sect1"> |
| 180 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 181 |
<a name="manual-core.comment"></a>2.3. The Commentary</h2></div></div></div> |
| 182 |
<p>Valgrind tools write a commentary, a stream of text, detailing |
| 183 |
error reports and other significant events. All lines in the commentary |
| 184 |
have following form: |
| 185 |
|
| 186 |
</p> |
| 187 |
<pre class="programlisting"> |
| 188 |
==12345== some-message-from-Valgrind</pre> |
| 189 |
<p> |
| 190 |
</p> |
| 191 |
<p>The <code class="computeroutput">12345</code> is the process ID. |
| 192 |
This scheme makes it easy to distinguish program output from Valgrind |
| 193 |
commentary, and also easy to differentiate commentaries from different |
| 194 |
processes which have become merged together, for whatever reason.</p> |
| 195 |
<p>By default, Valgrind tools write only essential messages to the |
| 196 |
commentary, so as to avoid flooding you with information of secondary |
| 197 |
importance. If you want more information about what is happening, |
| 198 |
re-run, passing the <code class="option">-v</code> option to Valgrind. A second |
| 199 |
<code class="option">-v</code> gives yet more detail. |
| 200 |
</p> |
| 201 |
<p>You can direct the commentary to three different places:</p> |
| 202 |
<div class="orderedlist"><ol class="orderedlist" type="1"> |
| 203 |
<li class="listitem"> |
| 204 |
<p><a name="manual-core.out2fd"></a>The default: send it to a file descriptor, which is by default |
| 205 |
2 (stderr). So, if you give the core no options, it will write |
| 206 |
commentary to the standard error stream. If you want to send it to |
| 207 |
some other file descriptor, for example number 9, you can specify |
| 208 |
<code class="option">--log-fd=9</code>.</p> |
| 209 |
<p>This is the simplest and most common arrangement, but can |
| 210 |
cause problems when Valgrinding entire trees of processes which |
| 211 |
expect specific file descriptors, particularly stdin/stdout/stderr, |
| 212 |
to be available for their own use.</p> |
| 213 |
</li> |
| 214 |
<li class="listitem"><p><a name="manual-core.out2file"></a>A less intrusive |
| 215 |
option is to write the commentary to a file, which you specify by |
| 216 |
<code class="option">--log-file=filename</code>. There are special format |
| 217 |
specifiers that can be used to use a process ID or an environment |
| 218 |
variable name in the log file name. These are useful/necessary if your |
| 219 |
program invokes multiple processes (especially for MPI programs). |
| 220 |
See the <a class="link" href="manual-core.html#manual-core.basicopts" title="2.7.2. Basic Options">basic options section</a> |
| 221 |
for more details.</p></li> |
| 222 |
<li class="listitem"> |
| 223 |
<p><a name="manual-core.out2socket"></a>The |
| 224 |
least intrusive option is to send the commentary to a network |
| 225 |
socket. The socket is specified as an IP address and port number |
| 226 |
pair, like this: <code class="option">--log-socket=192.168.0.1:12345</code> if |
| 227 |
you want to send the output to host IP 192.168.0.1 port 12345 |
| 228 |
(note: we |
| 229 |
have no idea if 12345 is a port of pre-existing significance). You |
| 230 |
can also omit the port number: |
| 231 |
<code class="option">--log-socket=192.168.0.1</code>, in which case a default |
| 232 |
port of 1500 is used. This default is defined by the constant |
| 233 |
<code class="computeroutput">VG_CLO_DEFAULT_LOGPORT</code> in the |
| 234 |
sources.</p> |
| 235 |
<p>Note, unfortunately, that you have to use an IP address here, |
| 236 |
rather than a hostname.</p> |
| 237 |
<p>Writing to a network socket is pointless if you don't |
| 238 |
have something listening at the other end. We provide a simple |
| 239 |
listener program, |
| 240 |
<code class="computeroutput">valgrind-listener</code>, which accepts |
| 241 |
connections on the specified port and copies whatever it is sent to |
| 242 |
stdout. Probably someone will tell us this is a horrible security |
| 243 |
risk. It seems likely that people will write more sophisticated |
| 244 |
listeners in the fullness of time.</p> |
| 245 |
<p><code class="computeroutput">valgrind-listener</code> can accept |
| 246 |
simultaneous connections from up to 50 Valgrinded processes. In front |
| 247 |
of each line of output it prints the current number of active |
| 248 |
connections in round brackets.</p> |
| 249 |
<p><code class="computeroutput">valgrind-listener</code> accepts three |
| 250 |
command-line options:</p> |
| 251 |
<div class="variablelist"> |
| 252 |
<a name="listener.opts.list"></a><dl class="variablelist"> |
| 253 |
<dt><span class="term"><code class="option">-e --exit-at-zero</code></span></dt> |
| 254 |
<dd><p>When the number of connected processes falls back to zero, |
| 255 |
exit. Without this, it will run forever, that is, until you |
| 256 |
send it Control-C.</p></dd> |
| 257 |
<dt><span class="term"><code class="option">--max-connect=INTEGER</code></span></dt> |
| 258 |
<dd><p>By default, the listener can connect to up to 50 processes. |
| 259 |
Occasionally, that number is too small. Use this option to |
| 260 |
provide a different limit. E.g. |
| 261 |
<code class="computeroutput">--max-connect=100</code>. |
| 262 |
</p></dd> |
| 263 |
<dt><span class="term"><code class="option">portnumber</code></span></dt> |
| 264 |
<dd><p>Changes the port it listens on from the default (1500). |
| 265 |
The specified port must be in the range 1024 to 65535. |
| 266 |
The same restriction applies to port numbers specified by a |
| 267 |
<code class="option">--log-socket</code> to Valgrind itself.</p></dd> |
| 268 |
</dl> |
| 269 |
</div> |
| 270 |
<p>If a Valgrinded process fails to connect to a listener, for |
| 271 |
whatever reason (the listener isn't running, invalid or unreachable |
| 272 |
host or port, etc), Valgrind switches back to writing the commentary |
| 273 |
to stderr. The same goes for any process which loses an established |
| 274 |
connection to a listener. In other words, killing the listener |
| 275 |
doesn't kill the processes sending data to it.</p> |
| 276 |
</li> |
| 277 |
</ol></div> |
| 278 |
<p>Here is an important point about the relationship between the |
| 279 |
commentary and profiling output from tools. The commentary contains a |
| 280 |
mix of messages from the Valgrind core and the selected tool. If the |
| 281 |
tool reports errors, it will report them to the commentary. However, if |
| 282 |
the tool does profiling, the profile data will be written to a file of |
| 283 |
some kind, depending on the tool, and independent of what |
| 284 |
<code class="option">--log-*</code> options are in force. The commentary is |
| 285 |
intended to be a low-bandwidth, human-readable channel. Profiling data, |
| 286 |
on the other hand, is usually voluminous and not meaningful without |
| 287 |
further processing, which is why we have chosen this arrangement.</p> |
| 288 |
</div> |
| 289 |
<div class="sect1"> |
| 290 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 291 |
<a name="manual-core.report"></a>2.4. Reporting of errors</h2></div></div></div> |
| 292 |
<p>When an error-checking tool |
| 293 |
detects something bad happening in the program, an error |
| 294 |
message is written to the commentary. Here's an example from Memcheck:</p> |
| 295 |
<pre class="programlisting"> |
| 296 |
==25832== Invalid read of size 4 |
| 297 |
==25832== at 0x8048724: BandMatrix::ReSize(int, int, int) (bogon.cpp:45) |
| 298 |
==25832== by 0x80487AF: main (bogon.cpp:66) |
| 299 |
==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd</pre> |
| 300 |
<p>This message says that the program did an illegal 4-byte read of |
| 301 |
address 0xBFFFF74C, which, as far as Memcheck can tell, is not a valid |
| 302 |
stack address, nor corresponds to any current heap blocks or recently freed |
| 303 |
heap blocks. The read is happening at line 45 of |
| 304 |
<code class="filename">bogon.cpp</code>, called from line 66 of the same file, |
| 305 |
etc. For errors associated with an identified (current or freed) heap block, |
| 306 |
for example reading freed memory, Valgrind reports not only the |
| 307 |
location where the error happened, but also where the associated heap block |
| 308 |
was allocated/freed.</p> |
| 309 |
<p>Valgrind remembers all error reports. When an error is detected, |
| 310 |
it is compared against old reports, to see if it is a duplicate. If so, |
| 311 |
the error is noted, but no further commentary is emitted. This avoids |
| 312 |
you being swamped with bazillions of duplicate error reports.</p> |
| 313 |
<p>If you want to know how many times each error occurred, run with |
| 314 |
the <code class="option">-v</code> option. When execution finishes, all the |
| 315 |
reports are printed out, along with, and sorted by, their occurrence |
| 316 |
counts. This makes it easy to see which errors have occurred most |
| 317 |
frequently.</p> |
| 318 |
<p>Errors are reported before the associated operation actually |
| 319 |
happens. For example, if you're using Memcheck and your program attempts to |
| 320 |
read from address zero, Memcheck will emit a message to this effect, and |
| 321 |
your program will then likely die with a segmentation fault.</p> |
| 322 |
<p>In general, you should try and fix errors in the order that they |
| 323 |
are reported. Not doing so can be confusing. For example, a program |
| 324 |
which copies uninitialised values to several memory locations, and later |
| 325 |
uses them, will generate several error messages, when run on Memcheck. |
| 326 |
The first such error message may well give the most direct clue to the |
| 327 |
root cause of the problem.</p> |
| 328 |
<p>The process of detecting duplicate errors is quite an |
| 329 |
expensive one and can become a significant performance overhead |
| 330 |
if your program generates huge quantities of errors. To avoid |
| 331 |
serious problems, Valgrind will simply stop collecting |
| 332 |
errors after 1,000 different errors have been seen, or 10,000,000 errors |
| 333 |
in total have been seen. In this situation you might as well |
| 334 |
stop your program and fix it, because Valgrind won't tell you |
| 335 |
anything else useful after this. Note that the 1,000/10,000,000 limits |
| 336 |
apply after suppressed errors are removed. These limits are |
| 337 |
defined in <code class="filename">m_errormgr.c</code> and can be increased |
| 338 |
if necessary.</p> |
| 339 |
<p>To avoid this cutoff you can use the |
| 340 |
<code class="option">--error-limit=no</code> option. Then Valgrind will always show |
| 341 |
errors, regardless of how many there are. Use this option carefully, |
| 342 |
since it may have a bad effect on performance.</p> |
| 343 |
</div> |
| 344 |
<div class="sect1"> |
| 345 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 346 |
<a name="manual-core.suppress"></a>2.5. Suppressing errors</h2></div></div></div> |
| 347 |
<p>The error-checking tools detect numerous problems in the system |
| 348 |
libraries, such as the C library, |
| 349 |
which come pre-installed with your OS. You can't easily fix |
| 350 |
these, but you don't want to see these errors (and yes, there are many!) |
| 351 |
So Valgrind reads a list of errors to suppress at startup. A default |
| 352 |
suppression file is created by the |
| 353 |
<code class="computeroutput">./configure</code> script when the system is |
| 354 |
built.</p> |
| 355 |
<p>You can modify and add to the suppressions file at your leisure, |
| 356 |
or, better, write your own. Multiple suppression files are allowed. |
| 357 |
This is useful if part of your project contains errors you can't or |
| 358 |
don't want to fix, yet you don't want to continuously be reminded of |
| 359 |
them.</p> |
| 360 |
<p><b>Note: </b>By far the easiest way to add |
| 361 |
suppressions is to use the <code class="option">--gen-suppressions=yes</code> option |
| 362 |
described in <a class="xref" href="manual-core.html#manual-core.options" title="2.7. Core Command-line Options">Core Command-line Options</a>. This generates |
| 363 |
suppressions automatically. For best results, |
| 364 |
though, you may want to edit the output |
| 365 |
of <code class="option">--gen-suppressions=yes</code> by hand, in which |
| 366 |
case it would be advisable to read through this section. |
| 367 |
</p> |
| 368 |
<p>Each error to be suppressed is described very specifically, to |
| 369 |
minimise the possibility that a suppression-directive inadvertently |
| 370 |
suppresses a bunch of similar errors which you did want to see. The |
| 371 |
suppression mechanism is designed to allow precise yet flexible |
| 372 |
specification of errors to suppress.</p> |
| 373 |
<p>If you use the <code class="option">-v</code> option, at the end of execution, |
| 374 |
Valgrind prints out one line for each used suppression, giving the number of times |
| 375 |
it got used, its name and the filename and line number where the suppression is |
| 376 |
defined. Depending on the suppression kind, the filename and line number are optionally |
| 377 |
followed by additional information (such as the number of blocks and bytes suppressed |
| 378 |
by a Memcheck leak suppression). Here's the suppressions used by a |
| 379 |
run of <code class="computeroutput">valgrind -v --tool=memcheck ls -l</code>:</p> |
| 380 |
<pre class="programlisting"> |
| 381 |
--1610-- used_suppression: 2 dl-hack3-cond-1 /usr/lib/valgrind/default.supp:1234 |
| 382 |
--1610-- used_suppression: 2 glibc-2.5.x-on-SUSE-10.2-(PPC)-2a /usr/lib/valgrind/default.supp:1234 |
| 383 |
</pre> |
| 384 |
<p>Multiple suppressions files are allowed. Valgrind loads suppression |
| 385 |
patterns from <code class="filename">$PREFIX/lib/valgrind/default.supp</code> unless |
| 386 |
<code class="option">--default-suppressions=no</code> has been specified. You can |
| 387 |
ask to add suppressions from additional files by specifying |
| 388 |
<code class="option">--suppressions=/path/to/file.supp</code> one or more times. |
| 389 |
</p> |
| 390 |
<p>If you want to understand more about suppressions, look at an |
| 391 |
existing suppressions file whilst reading the following documentation. |
| 392 |
The file <code class="filename">glibc-2.3.supp</code>, in the source |
| 393 |
distribution, provides some good examples.</p> |
| 394 |
<p>Blank and comment lines in a suppression file are ignored. Comment lines |
| 395 |
are made of 0 or more blanks followed by a # character followed by some |
| 396 |
text.</p> |
| 397 |
<p>Each suppression has the following components:</p> |
| 398 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 399 |
<li class="listitem"><p>First line: its name. This merely gives a handy name to the |
| 400 |
suppression, by which it is referred to in the summary of used |
| 401 |
suppressions printed out when a program finishes. It's not |
| 402 |
important what the name is; any identifying string will do.</p></li> |
| 403 |
<li class="listitem"> |
| 404 |
<p>Second line: name of the tool(s) that the suppression is for |
| 405 |
(if more than one, comma-separated), and the name of the suppression |
| 406 |
itself, separated by a colon (n.b.: no spaces are allowed), eg:</p> |
| 407 |
<pre class="programlisting"> |
| 408 |
tool_name1,tool_name2:suppression_name</pre> |
| 409 |
<p>Recall that Valgrind is a modular system, in which |
| 410 |
different instrumentation tools can observe your program whilst it |
| 411 |
is running. Since different tools detect different kinds of errors, |
| 412 |
it is necessary to say which tool(s) the suppression is meaningful |
| 413 |
to.</p> |
| 414 |
<p>Tools will complain, at startup, if a tool does not understand |
| 415 |
any suppression directed to it. Tools ignore suppressions which are |
| 416 |
not directed to them. As a result, it is quite practical to put |
| 417 |
suppressions for all tools into the same suppression file.</p> |
| 418 |
</li> |
| 419 |
<li class="listitem"><p>Next line: a small number of suppression types have extra |
| 420 |
information after the second line (eg. the <code class="varname">Param</code> |
| 421 |
suppression for Memcheck)</p></li> |
| 422 |
<li class="listitem"> |
| 423 |
<p>Remaining lines: This is the calling context for the error -- |
| 424 |
the chain of function calls that led to it. There can be up to 24 |
| 425 |
of these lines.</p> |
| 426 |
<p>Locations may be names of either shared objects, functions, |
| 427 |
or source lines. They begin with |
| 428 |
<code class="computeroutput">obj:</code>, |
| 429 |
<code class="computeroutput">fun:</code>, or |
| 430 |
<code class="computeroutput">src:</code> respectively. Function, |
| 431 |
object, and file names to match against may use the wildcard characters |
| 432 |
<code class="computeroutput">*</code> and |
| 433 |
<code class="computeroutput">?</code>. Source lines are specified |
| 434 |
using the form <code class="filename">filename[:lineNumber]</code>.</p> |
| 435 |
<p><span class="command"><strong>Important note: </strong></span> C++ function names must be |
| 436 |
<span class="command"><strong>mangled</strong></span>. If you are writing suppressions by |
| 437 |
hand, use the <code class="option">--demangle=no</code> option to get the |
| 438 |
mangled names in your error messages. An example of a mangled |
| 439 |
C++ name is <code class="computeroutput">_ZN9QListView4showEv</code>. |
| 440 |
This is the form that the GNU C++ compiler uses internally, and |
| 441 |
the form that must be used in suppression files. The equivalent |
| 442 |
demangled name, <code class="computeroutput">QListView::show()</code>, |
| 443 |
is what you see at the C++ source code level. |
| 444 |
</p> |
| 445 |
<p>A location line may also be |
| 446 |
simply "<code class="computeroutput">...</code>" (three dots). This is |
| 447 |
a frame-level wildcard, which matches zero or more frames. Frame |
| 448 |
level wildcards are useful because they make it easy to ignore |
| 449 |
varying numbers of uninteresting frames in between frames of |
| 450 |
interest. That is often important when writing suppressions which |
| 451 |
are intended to be robust against variations in the amount of |
| 452 |
function inlining done by compilers.</p> |
| 453 |
</li> |
| 454 |
<li class="listitem"><p>Finally, the entire suppression must be between curly |
| 455 |
braces. Each brace must be the first character on its own |
| 456 |
line.</p></li> |
| 457 |
</ul></div> |
| 458 |
<p>A suppression only suppresses an error when the error matches all |
| 459 |
the details in the suppression. Here's an example:</p> |
| 460 |
<pre class="programlisting"> |
| 461 |
{ |
| 462 |
__gconv_transform_ascii_internal/__mbrtowc/mbtowc |
| 463 |
Memcheck:Value4 |
| 464 |
fun:__gconv_transform_ascii_internal |
| 465 |
fun:__mbr*toc |
| 466 |
fun:mbtowc |
| 467 |
}</pre> |
| 468 |
<p>What it means is: for Memcheck only, suppress a |
| 469 |
use-of-uninitialised-value error, when the data size is 4, when it |
| 470 |
occurs in the function |
| 471 |
<code class="computeroutput">__gconv_transform_ascii_internal</code>, when |
| 472 |
that is called from any function of name matching |
| 473 |
<code class="computeroutput">__mbr*toc</code>, when that is called from |
| 474 |
<code class="computeroutput">mbtowc</code>. It doesn't apply under any |
| 475 |
other circumstances. The string by which this suppression is identified |
| 476 |
to the user is |
| 477 |
<code class="computeroutput">__gconv_transform_ascii_internal/__mbrtowc/mbtowc</code>.</p> |
| 478 |
<p>(See <a class="xref" href="mc-manual.html#mc-manual.suppfiles" title="4.4. Writing suppression files">Writing suppression files</a> for more details |
| 479 |
on the specifics of Memcheck's suppression kinds.)</p> |
| 480 |
<p>Another example, again for the Memcheck tool:</p> |
| 481 |
<pre class="programlisting"> |
| 482 |
{ |
| 483 |
libX11.so.6.2/libX11.so.6.2/libXaw.so.7.0 |
| 484 |
Memcheck:Value4 |
| 485 |
obj:/usr/X11R6/lib/libX11.so.6.2 |
| 486 |
obj:/usr/X11R6/lib/libX11.so.6.2 |
| 487 |
obj:/usr/X11R6/lib/libXaw.so.7.0 |
| 488 |
}</pre> |
| 489 |
<p>This suppresses any size 4 uninitialised-value error which occurs |
| 490 |
anywhere in <code class="filename">libX11.so.6.2</code>, when called from |
| 491 |
anywhere in the same library, when called from anywhere in |
| 492 |
<code class="filename">libXaw.so.7.0</code>. The inexact specification of |
| 493 |
locations is regrettable, but is about all you can hope for, given that |
| 494 |
the X11 libraries shipped on the Linux distro on which this example |
| 495 |
was made have had their symbol tables removed.</p> |
| 496 |
<p>An example of the src: specification, again for the Memcheck tool:</p> |
| 497 |
<pre class="programlisting"> |
| 498 |
{ |
| 499 |
libX11.so.6.2/libX11.so.6.2/libXaw.so.7.0 |
| 500 |
Memcheck:Value4 |
| 501 |
src:valid.c:321 |
| 502 |
}</pre> |
| 503 |
<p>This suppresses any size-4 uninitialised-value error which occurs |
| 504 |
at line 321 in <code class="filename">valid.c</code>.</p> |
| 505 |
<p>Although the above two examples do not make this clear, you can |
| 506 |
freely mix <code class="computeroutput">obj:</code>, |
| 507 |
<code class="computeroutput">fun:</code>, and |
| 508 |
<code class="computeroutput">src:</code> |
| 509 |
lines in a suppression.</p> |
| 510 |
<p>Finally, here's an example using three frame-level wildcards:</p> |
| 511 |
<pre class="programlisting"> |
| 512 |
{ |
| 513 |
a-contrived-example |
| 514 |
Memcheck:Leak |
| 515 |
fun:malloc |
| 516 |
... |
| 517 |
fun:ddd |
| 518 |
... |
| 519 |
fun:ccc |
| 520 |
... |
| 521 |
fun:main |
| 522 |
} |
| 523 |
</pre> |
| 524 |
<p>This suppresses Memcheck memory-leak errors, in the case where |
| 525 |
the allocation was done by <code class="computeroutput">main</code> |
| 526 |
calling (though any number of intermediaries, including zero) |
| 527 |
<code class="computeroutput">ccc</code>, |
| 528 |
calling onwards via |
| 529 |
<code class="computeroutput">ddd</code> and eventually |
| 530 |
to <code class="computeroutput">malloc.</code>.</p> |
| 531 |
</div> |
| 532 |
<div class="sect1"> |
| 533 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 534 |
<a name="manual-core.debuginfod"></a>2.6. Debuginfod</h2></div></div></div> |
| 535 |
<p><a name="debuginfod.para.1"></a>Valgrind supports the downloading of debuginfo |
| 536 |
files via debuginfod, an HTTP server for distributing ELF/DWARF debugging |
| 537 |
information. When a debuginfo file cannot be found locally, Valgrind is able |
| 538 |
to query debuginfod servers for the file using the file's build-id.</p> |
| 539 |
<p><a name="debuginfod.para.2"></a>In order to use this feature |
| 540 |
<code class="computeroutput">debuginfod-find</code> must be installed and the |
| 541 |
<code class="computeroutput">$DEBUGINFOD_URLS</code> environment variable must |
| 542 |
contain space-separated URLs of debuginfod servers. Valgrind does not support |
| 543 |
<code class="computeroutput">debuginfod-find</code> verbose output that is |
| 544 |
normally enabled with <code class="computeroutput">$DEBUGINFOD_PROGRESS</code> |
| 545 |
and <code class="computeroutput">$DEBUGINFOD_VERBOSE</code>. These environment |
| 546 |
variables will be ignored. This feature is supported on Linux only.</p> |
| 547 |
<p><a name="debuginfod.para.3"></a>For more information regarding debuginfod, see |
| 548 |
<a class="ulink" href="https://sourceware.org/elfutils/Debuginfod.html" target="_top">Elfutils Debuginfod</a> |
| 549 |
.</p> |
| 550 |
</div> |
| 551 |
<div class="sect1"> |
| 552 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 553 |
<a name="manual-core.options"></a>2.7. Core Command-line Options</h2></div></div></div> |
| 554 |
<p>As mentioned above, Valgrind's core accepts a common set of options. |
| 555 |
The tools also accept tool-specific options, which are documented |
| 556 |
separately for each tool.</p> |
| 557 |
<p>Valgrind's default settings succeed in giving reasonable behaviour |
| 558 |
in most cases. We group the available options by rough categories.</p> |
| 559 |
<div class="sect2"> |
| 560 |
<div class="titlepage"><div><div><h3 class="title"> |
| 561 |
<a name="manual-core.toolopts"></a>2.7.1. Tool-selection Option</h3></div></div></div> |
| 562 |
<p><a name="tool.opts.para"></a>The single most important option.</p> |
| 563 |
<div class="variablelist"> |
| 564 |
<a name="tool.opts.list"></a><dl class="variablelist"> |
| 565 |
<dt> |
| 566 |
<a name="tool_name"></a><span class="term"> |
| 567 |
<code class="option">--tool=<toolname> [default: memcheck] </code> |
| 568 |
</span> |
| 569 |
</dt> |
| 570 |
<dd><p>Run the Valgrind tool called <code class="varname">toolname</code>, |
| 571 |
e.g. memcheck, cachegrind, callgrind, helgrind, drd, massif, |
| 572 |
dhat, lackey, none, exp-bbv, etc.</p></dd> |
| 573 |
</dl> |
| 574 |
</div> |
| 575 |
</div> |
| 576 |
<div class="sect2"> |
| 577 |
<div class="titlepage"><div><div><h3 class="title"> |
| 578 |
<a name="manual-core.basicopts"></a>2.7.2. Basic Options</h3></div></div></div> |
| 579 |
<p><a name="basic.opts.para"></a>These options work with all tools.</p> |
| 580 |
<div class="variablelist"> |
| 581 |
<a name="basic.opts.list"></a><dl class="variablelist"> |
| 582 |
<dt> |
| 583 |
<a name="opt.help"></a><span class="term"><code class="option">-h --help</code></span> |
| 584 |
</dt> |
| 585 |
<dd><p>Show help for all options, both for the core and for the |
| 586 |
selected tool. If the option is repeated it is equivalent to giving |
| 587 |
<code class="option">--help-debug</code>.</p></dd> |
| 588 |
<dt> |
| 589 |
<a name="opt.help-debug"></a><span class="term"><code class="option">--help-debug</code></span> |
| 590 |
</dt> |
| 591 |
<dd><p>Same as <code class="option">--help</code>, but also lists debugging |
| 592 |
options which usually are only of use to Valgrind's |
| 593 |
developers.</p></dd> |
| 594 |
<dt> |
| 595 |
<a name="opt.version"></a><span class="term"><code class="option">--version</code></span> |
| 596 |
</dt> |
| 597 |
<dd><p>Show the version number of the Valgrind core. Tools can have |
| 598 |
their own version numbers. There is a scheme in place to ensure |
| 599 |
that tools only execute when the core version is one they are |
| 600 |
known to work with. This was done to minimise the chances of |
| 601 |
strange problems arising from tool-vs-core version |
| 602 |
incompatibilities.</p></dd> |
| 603 |
<dt> |
| 604 |
<a name="opt.quiet"></a><span class="term"><code class="option">-q</code>, <code class="option">--quiet</code></span> |
| 605 |
</dt> |
| 606 |
<dd><p>Run silently, and only print error messages. Useful if you |
| 607 |
are running regression tests or have some other automated test |
| 608 |
machinery.</p></dd> |
| 609 |
<dt> |
| 610 |
<a name="opt.verbose"></a><span class="term"><code class="option">-v</code>, <code class="option">--verbose</code></span> |
| 611 |
</dt> |
| 612 |
<dd><p>Be more verbose. Gives extra information on various aspects |
| 613 |
of your program, such as: the shared objects loaded, the |
| 614 |
suppressions used, the progress of the instrumentation and |
| 615 |
execution engines, and warnings about unusual behaviour. Repeating |
| 616 |
the option increases the verbosity level.</p></dd> |
| 617 |
<dt> |
| 618 |
<a name="opt.trace-children"></a><span class="term"> |
| 619 |
<code class="option">--trace-children=<yes|no> [default: no] </code> |
| 620 |
</span> |
| 621 |
</dt> |
| 622 |
<dd> |
| 623 |
<p>When enabled, Valgrind will trace into sub-processes |
| 624 |
initiated via the <code class="varname">exec</code> system call. This is |
| 625 |
necessary for multi-process programs. |
| 626 |
</p> |
| 627 |
<p>Note that Valgrind does trace into the child of a |
| 628 |
<code class="varname">fork</code> (it would be difficult not to, since |
| 629 |
<code class="varname">fork</code> makes an identical copy of a process), so this |
| 630 |
option is arguably badly named. However, most children of |
| 631 |
<code class="varname">fork</code> calls immediately call <code class="varname">exec</code> |
| 632 |
anyway. |
| 633 |
</p> |
| 634 |
</dd> |
| 635 |
<dt> |
| 636 |
<a name="opt.trace-children-skip"></a><span class="term"> |
| 637 |
<code class="option">--trace-children-skip=patt1,patt2,... </code> |
| 638 |
</span> |
| 639 |
</dt> |
| 640 |
<dd> |
| 641 |
<p>This option only has an effect when |
| 642 |
<code class="option">--trace-children=yes</code> is specified. It allows |
| 643 |
for some children to be skipped. The option takes a comma |
| 644 |
separated list of patterns for the names of child executables |
| 645 |
that Valgrind should not trace into. Patterns may include the |
| 646 |
metacharacters <code class="computeroutput">?</code> |
| 647 |
and <code class="computeroutput">*</code>, which have the usual |
| 648 |
meaning.</p> |
| 649 |
<p> |
| 650 |
This can be useful for pruning uninteresting branches from a |
| 651 |
tree of processes being run on Valgrind. But you should be |
| 652 |
careful when using it. When Valgrind skips tracing into an |
| 653 |
executable, it doesn't just skip tracing that executable, it |
| 654 |
also skips tracing any of that executable's child processes. |
| 655 |
In other words, the flag doesn't merely cause tracing to stop |
| 656 |
at the specified executables -- it skips tracing of entire |
| 657 |
process subtrees rooted at any of the specified |
| 658 |
executables.</p> |
| 659 |
</dd> |
| 660 |
<dt> |
| 661 |
<a name="opt.trace-children-skip-by-arg"></a><span class="term"> |
| 662 |
<code class="option">--trace-children-skip-by-arg=patt1,patt2,... </code> |
| 663 |
</span> |
| 664 |
</dt> |
| 665 |
<dd><p>This is the same as |
| 666 |
<code class="option">--trace-children-skip</code>, with one difference: |
| 667 |
the decision as to whether to trace into a child process is |
| 668 |
made by examining the arguments to the child process, rather |
| 669 |
than the name of its executable.</p></dd> |
| 670 |
<dt> |
| 671 |
<a name="opt.child-silent-after-fork"></a><span class="term"> |
| 672 |
<code class="option">--child-silent-after-fork=<yes|no> [default: no] </code> |
| 673 |
</span> |
| 674 |
</dt> |
| 675 |
<dd><p>When enabled, Valgrind will not show any debugging or |
| 676 |
logging output for the child process resulting from |
| 677 |
a <code class="varname">fork</code> call. This can make the output less |
| 678 |
confusing (although more misleading) when dealing with processes |
| 679 |
that create children. It is particularly useful in conjunction |
| 680 |
with <code class="varname">--trace-children=</code>. Use of this option is also |
| 681 |
strongly recommended if you are requesting XML output |
| 682 |
(<code class="varname">--xml=yes</code>), since otherwise the XML from child and |
| 683 |
parent may become mixed up, which usually makes it useless. |
| 684 |
</p></dd> |
| 685 |
<dt> |
| 686 |
<a name="opt.vgdb"></a><span class="term"> |
| 687 |
<code class="option">--vgdb=<no|yes|full> [default: yes] </code> |
| 688 |
</span> |
| 689 |
</dt> |
| 690 |
<dd> |
| 691 |
<p>Valgrind will provide "gdbserver" functionality when |
| 692 |
<code class="option">--vgdb=yes</code> or <code class="option">--vgdb=full</code> is |
| 693 |
specified. This allows an external GNU GDB debugger to control |
| 694 |
and debug your program when it runs on Valgrind. |
| 695 |
<code class="option">--vgdb=full</code> incurs significant performance |
| 696 |
overheads, but provides more precise breakpoints and |
| 697 |
watchpoints. See <a class="xref" href="manual-core-adv.html#manual-core-adv.gdbserver" title="3.2. Debugging your program using Valgrind gdbserver and GDB">Debugging your program using Valgrind's gdbserver and GDB</a> for |
| 698 |
a detailed description. |
| 699 |
</p> |
| 700 |
<p> If the embedded gdbserver is enabled but no gdb is |
| 701 |
currently being used, the <a class="xref" href="manual-core-adv.html#manual-core-adv.vgdb" title="3.2.10. vgdb command line options">vgdb</a> |
| 702 |
command line utility can send "monitor commands" to Valgrind |
| 703 |
from a shell. The Valgrind core provides a set of |
| 704 |
<a class="xref" href="manual-core-adv.html#manual-core-adv.valgrind-monitor-commands" title="3.2.11. Valgrind monitor commands">Valgrind monitor commands</a>. A tool |
| 705 |
can optionally provide tool specific monitor commands, which are |
| 706 |
documented in the tool specific chapter. |
| 707 |
</p> |
| 708 |
</dd> |
| 709 |
<dt> |
| 710 |
<a name="opt.vgdb-error"></a><span class="term"> |
| 711 |
<code class="option">--vgdb-error=<number> [default: 999999999] </code> |
| 712 |
</span> |
| 713 |
</dt> |
| 714 |
<dd><p> Use this option when the Valgrind gdbserver is enabled with |
| 715 |
<code class="option">--vgdb=yes</code> or <code class="option">--vgdb=full</code>. |
| 716 |
Tools that report errors will wait |
| 717 |
for "<code class="computeroutput">number</code>" errors to be |
| 718 |
reported before freezing the program and waiting for you to |
| 719 |
connect with GDB. It follows that a value of zero will cause |
| 720 |
the gdbserver to be started before your program is executed. |
| 721 |
This is typically used to insert GDB breakpoints before |
| 722 |
execution, and also works with tools that do not report |
| 723 |
errors, such as Massif. |
| 724 |
</p></dd> |
| 725 |
<dt> |
| 726 |
<a name="opt.vgdb-stop-at"></a><span class="term"> |
| 727 |
<code class="option">--vgdb-stop-at=<set> [default: none] </code> |
| 728 |
</span> |
| 729 |
</dt> |
| 730 |
<dd> |
| 731 |
<p> Use this option when the Valgrind gdbserver is enabled with |
| 732 |
<code class="option">--vgdb=yes</code> or <code class="option">--vgdb=full</code>. |
| 733 |
The Valgrind gdbserver will be invoked for each error after |
| 734 |
<code class="option">--vgdb-error</code> have been reported. |
| 735 |
You can additionally ask the Valgrind gdbserver to be invoked |
| 736 |
for other events, specified in one of the following ways: </p> |
| 737 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 738 |
<li class="listitem"> |
| 739 |
<p>a comma separated list of one or more of |
| 740 |
<code class="option">startup exit abexit valgrindabexit</code>.</p> |
| 741 |
<p>The values <code class="option">startup</code> <code class="option">exit</code> |
| 742 |
<code class="option">valgrindabexit</code> respectively indicate to invoke |
| 743 |
gdbserver before your program is executed, after the last instruction |
| 744 |
of your program, on Valgrind abnormal exit (e.g. internal error, out |
| 745 |
of memory, ...).</p> |
| 746 |
<p>The option <code class="option">abexit</code> is similar to <code class="option">exit</code> |
| 747 |
but tells to invoke gdbserver only when your application exits abnormally |
| 748 |
(i.e. with an exit code different of 0). </p> |
| 749 |
<p>Note: <code class="option">startup</code> and |
| 750 |
<code class="option">--vgdb-error=0</code> will both cause Valgrind |
| 751 |
gdbserver to be invoked before your program is executed. The |
| 752 |
<code class="option">--vgdb-error=0</code> will in addition cause your |
| 753 |
program to stop on all subsequent errors.</p> |
| 754 |
</li> |
| 755 |
<li class="listitem"><p><code class="option">all</code> to specify the complete set. |
| 756 |
It is equivalent to |
| 757 |
<code class="option">--vgdb-stop-at=startup,exit,abexit,valgrindabexit</code>.</p></li> |
| 758 |
<li class="listitem"><p><code class="option">none</code> for the empty set.</p></li> |
| 759 |
</ul></div> |
| 760 |
</dd> |
| 761 |
<dt> |
| 762 |
<a name="opt.track-fds"></a><span class="term"> |
| 763 |
<code class="option">--track-fds=<yes|no|all> [default: no] </code> |
| 764 |
</span> |
| 765 |
</dt> |
| 766 |
<dd><p>When enabled, Valgrind will print out a list of open file |
| 767 |
descriptors on exit or on request, via the gdbserver monitor |
| 768 |
command <code class="varname">v.info open_fds</code>. Along with each |
| 769 |
file descriptor is printed a stack backtrace of where the file |
| 770 |
was opened and any details relating to the file descriptor such |
| 771 |
as the file name or socket details. Use <code class="option">all</code> to |
| 772 |
include reporting on <code class="computeroutput">stdin</code>, |
| 773 |
<code class="computeroutput">stdout</code> and |
| 774 |
<code class="computeroutput">stderr</code>.</p></dd> |
| 775 |
<dt> |
| 776 |
<a name="opt.modify-fds"></a><span class="term"> |
| 777 |
<code class="option">--modify-fds=<no|high> [default: no] </code> |
| 778 |
</span> |
| 779 |
</dt> |
| 780 |
<dd><p>When enabled, when the program opens a new file descriptor, |
| 781 |
the highest available file descriptor is returned instead of the |
| 782 |
lowest one.</p></dd> |
| 783 |
<dt> |
| 784 |
<a name="opt.time-stamp"></a><span class="term"> |
| 785 |
<code class="option">--time-stamp=<yes|no> [default: no] </code> |
| 786 |
</span> |
| 787 |
</dt> |
| 788 |
<dd><p>When enabled, each message is preceded with an indication of |
| 789 |
the elapsed wallclock time since startup, expressed as days, |
| 790 |
hours, minutes, seconds and milliseconds.</p></dd> |
| 791 |
<dt> |
| 792 |
<a name="opt.log-fd"></a><span class="term"> |
| 793 |
<code class="option">--log-fd=<number> [default: 2, stderr] </code> |
| 794 |
</span> |
| 795 |
</dt> |
| 796 |
<dd><p>Specifies that Valgrind should send all of its messages to |
| 797 |
the specified file descriptor. The default, 2, is the standard |
| 798 |
error channel (stderr). Note that this may interfere with the |
| 799 |
client's own use of stderr, as Valgrind's output will be |
| 800 |
interleaved with any output that the client sends to |
| 801 |
stderr.</p></dd> |
| 802 |
<dt> |
| 803 |
<a name="opt.log-file"></a><span class="term"> |
| 804 |
<code class="option">--log-file=<filename> </code> |
| 805 |
</span> |
| 806 |
</dt> |
| 807 |
<dd> |
| 808 |
<p>Specifies that Valgrind should send all of its messages to |
| 809 |
the specified file. If the file name is empty, it causes an abort. |
| 810 |
There are three special format specifiers that can be used in the file |
| 811 |
name.</p> |
| 812 |
<p><code class="option">%p</code> is replaced with the current process ID. |
| 813 |
This is very useful for program that invoke multiple processes. |
| 814 |
WARNING: If you use <code class="option">--trace-children=yes</code> and your |
| 815 |
program invokes multiple processes OR your program forks without |
| 816 |
calling exec afterwards, and you don't use this specifier |
| 817 |
(or the <code class="option">%q</code> specifier below), the Valgrind output from |
| 818 |
all those processes will go into one file, possibly jumbled up, and |
| 819 |
possibly incomplete. Note: If the program forks and calls exec afterwards, |
| 820 |
Valgrind output of the child from the period between fork and exec |
| 821 |
will be lost. Fortunately this gap is really tiny for most programs; |
| 822 |
and modern programs use <code class="computeroutput">posix_spawn</code> |
| 823 |
anyway.</p> |
| 824 |
<p><code class="option">%n</code> is replaced with a file sequence number |
| 825 |
unique for this process. |
| 826 |
This is useful for processes that produces several files |
| 827 |
from the same filename template.</p> |
| 828 |
<p><code class="option">%q{FOO}</code> is replaced with the contents of the |
| 829 |
environment variable <code class="varname">FOO</code>. If the |
| 830 |
<code class="option">{FOO}</code> part is malformed, it causes an abort. This |
| 831 |
specifier is rarely needed, but very useful in certain circumstances |
| 832 |
(eg. when running MPI programs). The idea is that you specify a |
| 833 |
variable which will be set differently for each process in the job, |
| 834 |
for example <code class="computeroutput">BPROC_RANK</code> or whatever is |
| 835 |
applicable in your MPI setup. If the named environment variable is not |
| 836 |
set, it causes an abort. Note that in some shells, the |
| 837 |
<code class="option">{</code> and <code class="option">}</code> characters may need to be |
| 838 |
escaped with a backslash.</p> |
| 839 |
<p><code class="option">%%</code> is replaced with <code class="option">%</code>.</p> |
| 840 |
<p>If an <code class="option">%</code> is followed by any other character, it |
| 841 |
causes an abort.</p> |
| 842 |
<p>If the file name specifies a relative file name, it is put |
| 843 |
in the program's initial working directory: this is the current |
| 844 |
directory when the program started its execution after the fork |
| 845 |
or after the exec. If it specifies an absolute file name (ie. |
| 846 |
starts with '/') then it is put there. |
| 847 |
</p> |
| 848 |
</dd> |
| 849 |
<dt> |
| 850 |
<a name="opt.log-socket"></a><span class="term"> |
| 851 |
<code class="option">--log-socket=<ip-address:port-number> </code> |
| 852 |
</span> |
| 853 |
</dt> |
| 854 |
<dd><p>Specifies that Valgrind should send all of its messages to |
| 855 |
the specified port at the specified IP address. The port may be |
| 856 |
omitted, in which case port 1500 is used. If a connection cannot |
| 857 |
be made to the specified socket, Valgrind falls back to writing |
| 858 |
output to the standard error (stderr). This option is intended to |
| 859 |
be used in conjunction with the |
| 860 |
<code class="computeroutput">valgrind-listener</code> program. For |
| 861 |
further details, see |
| 862 |
<a class="link" href="manual-core.html#manual-core.comment" title="2.3. The Commentary">the commentary</a> |
| 863 |
in the manual.</p></dd> |
| 864 |
<dt> |
| 865 |
<a name="opt.enable-debuginfod"></a><span class="term"> |
| 866 |
<code class="option">--enable-debuginfod=<no|yes> [default: yes] </code> |
| 867 |
</span> |
| 868 |
</dt> |
| 869 |
<dd><p>When enabled Valgrind will attempt to download missing debuginfo |
| 870 |
from debuginfod servers if space-separated server URLs are present |
| 871 |
in the <code class="computeroutput">$DEBUGINFOD_URLS</code> environment |
| 872 |
variable. This option is supported on Linux only. |
| 873 |
</p></dd> |
| 874 |
</dl> |
| 875 |
</div> |
| 876 |
</div> |
| 877 |
<div class="sect2"> |
| 878 |
<div class="titlepage"><div><div><h3 class="title"> |
| 879 |
<a name="manual-core.erropts"></a>2.7.3. Error-related Options</h3></div></div></div> |
| 880 |
<p><a name="error-related.opts.para"></a>These options are used by all tools |
| 881 |
that can report errors, e.g. Memcheck, but not Cachegrind.</p> |
| 882 |
<div class="variablelist"> |
| 883 |
<a name="error-related.opts.list"></a><dl class="variablelist"> |
| 884 |
<dt> |
| 885 |
<a name="opt.xml"></a><span class="term"> |
| 886 |
<code class="option">--xml=<yes|no> [default: no] </code> |
| 887 |
</span> |
| 888 |
</dt> |
| 889 |
<dd> |
| 890 |
<p>When enabled, the important parts of the output (e.g. tool error |
| 891 |
messages) will be in XML format rather than plain text. Furthermore, |
| 892 |
the XML output will be sent to a different output channel than the |
| 893 |
plain text output. Therefore, you also must use one of |
| 894 |
<code class="option">--xml-fd</code>, <code class="option">--xml-file</code> or |
| 895 |
<code class="option">--xml-socket</code> to specify where the XML is to be sent. |
| 896 |
</p> |
| 897 |
<p>Less important messages will still be printed in plain text, but |
| 898 |
because the XML output and plain text output are sent to different |
| 899 |
output channels (the destination of the plain text output is still |
| 900 |
controlled by <code class="option">--log-fd</code>, <code class="option">--log-file</code> |
| 901 |
and <code class="option">--log-socket</code>) this should not cause problems. |
| 902 |
</p> |
| 903 |
<p>This option is aimed at making life easier for tools that consume |
| 904 |
Valgrind's output as input, such as GUI front ends. Currently this |
| 905 |
option works with Memcheck, Helgrind and DRD. The output format is |
| 906 |
specified in the file |
| 907 |
<code class="computeroutput">docs/internals/xml-output-protocol4.txt</code> |
| 908 |
in the source tree for Valgrind 3.5.0 or later.</p> |
| 909 |
<p>The recommended options for a GUI to pass, when requesting |
| 910 |
XML output, are: <code class="option">--xml=yes</code> to enable XML output, |
| 911 |
<code class="option">--xml-file</code> to send the XML output to a (presumably |
| 912 |
GUI-selected) file, <code class="option">--log-file</code> to send the plain |
| 913 |
text output to a second GUI-selected file, |
| 914 |
<code class="option">--child-silent-after-fork=yes</code>, and |
| 915 |
<code class="option">-q</code> to restrict the plain text output to critical |
| 916 |
error messages created by Valgrind itself. For example, failure to |
| 917 |
read a specified suppressions file counts as a critical error message. |
| 918 |
In this way, for a successful run the text output file will be empty. |
| 919 |
But if it isn't empty, then it will contain important information |
| 920 |
which the GUI user should be made aware |
| 921 |
of.</p> |
| 922 |
</dd> |
| 923 |
<dt> |
| 924 |
<a name="opt.xml-fd"></a><span class="term"> |
| 925 |
<code class="option">--xml-fd=<number> [default: -1, disabled] </code> |
| 926 |
</span> |
| 927 |
</dt> |
| 928 |
<dd><p>Specifies that Valgrind should send its XML output to the |
| 929 |
specified file descriptor. It must be used in conjunction with |
| 930 |
<code class="option">--xml=yes</code>.</p></dd> |
| 931 |
<dt> |
| 932 |
<a name="opt.xml-file"></a><span class="term"> |
| 933 |
<code class="option">--xml-file=<filename> </code> |
| 934 |
</span> |
| 935 |
</dt> |
| 936 |
<dd><p>Specifies that Valgrind should send its XML output |
| 937 |
to the specified file. It must be used in conjunction with |
| 938 |
<code class="option">--xml=yes</code>. Any <code class="option">%p</code> or |
| 939 |
<code class="option">%q</code> sequences appearing in the filename are expanded |
| 940 |
in exactly the same way as they are for <code class="option">--log-file</code>. |
| 941 |
See the description of <a class="xref" href="manual-core.html#opt.log-file">--log-file</a> for details. |
| 942 |
</p></dd> |
| 943 |
<dt> |
| 944 |
<a name="opt.xml-socket"></a><span class="term"> |
| 945 |
<code class="option">--xml-socket=<ip-address:port-number> </code> |
| 946 |
</span> |
| 947 |
</dt> |
| 948 |
<dd><p>Specifies that Valgrind should send its XML output the |
| 949 |
specified port at the specified IP address. It must be used in |
| 950 |
conjunction with <code class="option">--xml=yes</code>. The form of the argument |
| 951 |
is the same as that used by <code class="option">--log-socket</code>. |
| 952 |
See the description of <code class="option">--log-socket</code> |
| 953 |
for further details.</p></dd> |
| 954 |
<dt> |
| 955 |
<a name="opt.xml-user-comment"></a><span class="term"> |
| 956 |
<code class="option">--xml-user-comment=<string> </code> |
| 957 |
</span> |
| 958 |
</dt> |
| 959 |
<dd><p>Embeds an extra user comment string at the start of the XML |
| 960 |
output. Only works when <code class="option">--xml=yes</code> is specified; |
| 961 |
ignored otherwise.</p></dd> |
| 962 |
<dt> |
| 963 |
<a name="opt.demangle"></a><span class="term"> |
| 964 |
<code class="option">--demangle=<yes|no> [default: yes] </code> |
| 965 |
</span> |
| 966 |
</dt> |
| 967 |
<dd> |
| 968 |
<p>Enable/disable automatic demangling (decoding) of C++, D, |
| 969 |
Rust, Java, Ada names. |
| 970 |
Enabled by default. When enabled, Valgrind will attempt to |
| 971 |
translate encoded names in the listed languages back to something |
| 972 |
approaching the original. |
| 973 |
Note that the callgrind tool always disables Ada demangling in order |
| 974 |
to differentiate overloaded functions and procedures in the callgraph. |
| 975 |
The demangler handles symbols mangled by g++ versions |
| 976 |
2.X, 3.X and 4.X.</p> |
| 977 |
<p>An important fact about demangling is that function names |
| 978 |
mentioned in suppressions files should be in their mangled form. |
| 979 |
Valgrind does not demangle function names when searching for |
| 980 |
applicable suppressions, because to do otherwise would make |
| 981 |
suppression file contents dependent on the state of Valgrind's |
| 982 |
demangling machinery, and also slow down suppression matching.</p> |
| 983 |
</dd> |
| 984 |
<dt> |
| 985 |
<a name="opt.num-callers"></a><span class="term"> |
| 986 |
<code class="option">--num-callers=<number> [default: 12] </code> |
| 987 |
</span> |
| 988 |
</dt> |
| 989 |
<dd> |
| 990 |
<p>Specifies the maximum number of entries shown in stack traces |
| 991 |
that identify program locations. Note that errors are commoned up |
| 992 |
using only the top four function locations (the place in the current |
| 993 |
function, and that of its three immediate callers). So this doesn't |
| 994 |
affect the total number of errors reported.</p> |
| 995 |
<p>The maximum value for this is 500. Note that higher settings |
| 996 |
will make Valgrind run a bit more slowly and take a bit more |
| 997 |
memory, but can be useful when working with programs with |
| 998 |
deeply-nested call chains.</p> |
| 999 |
</dd> |
| 1000 |
<dt> |
| 1001 |
<a name="opt.unw-stack-scan-thresh"></a><span class="term"> |
| 1002 |
<code class="option">--unw-stack-scan-thresh=<number> [default: 0] </code> |
| 1003 |
, </span><span class="term"> |
| 1004 |
<code class="option">--unw-stack-scan-frames=<number> [default: 5] </code> |
| 1005 |
</span> |
| 1006 |
</dt> |
| 1007 |
<dd> |
| 1008 |
<p>Stack-scanning support is available only on ARM |
| 1009 |
targets.</p> |
| 1010 |
<p>These flags enable and control stack unwinding by stack |
| 1011 |
scanning. When the normal stack unwinding mechanisms -- usage |
| 1012 |
of Dwarf CFI records, and frame-pointer following -- fail, stack |
| 1013 |
scanning may be able to recover a stack trace.</p> |
| 1014 |
<p>Note that stack scanning is an imprecise, heuristic |
| 1015 |
mechanism that may give very misleading results, or none at all. |
| 1016 |
It should be used only in emergencies, when normal unwinding |
| 1017 |
fails, and it is important to nevertheless have stack |
| 1018 |
traces.</p> |
| 1019 |
<p>Stack scanning is a simple technique: the unwinder reads |
| 1020 |
words from the stack, and tries to guess which of them might be |
| 1021 |
return addresses, by checking to see if they point just after |
| 1022 |
ARM or Thumb call instructions. If so, the word is added to the |
| 1023 |
backtrace.</p> |
| 1024 |
<p>The main danger occurs when a function call returns, |
| 1025 |
leaving its return address exposed, and a new function is |
| 1026 |
called, but the new function does not overwrite the old address. |
| 1027 |
The result of this is that the backtrace may contain entries for |
| 1028 |
functions which have already returned, and so be very |
| 1029 |
confusing.</p> |
| 1030 |
<p>A second limitation of this implementation is that it will |
| 1031 |
scan only the page (4KB, normally) containing the starting stack |
| 1032 |
pointer. If the stack frames are large, this may result in only |
| 1033 |
a few (or not even any) being present in the trace. Also, if |
| 1034 |
you are unlucky and have an initial stack pointer near the end |
| 1035 |
of its containing page, the scan may miss all interesting |
| 1036 |
frames.</p> |
| 1037 |
<p>By default stack scanning is disabled. The normal use |
| 1038 |
case is to ask for it when a stack trace would otherwise be very |
| 1039 |
short. So, to enable it, |
| 1040 |
use <code class="computeroutput">--unw-stack-scan-thresh=number</code>. |
| 1041 |
This requests Valgrind to try using stack scanning to "extend" |
| 1042 |
stack traces which contain fewer |
| 1043 |
than <code class="computeroutput">number</code> frames.</p> |
| 1044 |
<p>If stack scanning does take place, it will only generate |
| 1045 |
at most the number of frames specified |
| 1046 |
by <code class="computeroutput">--unw-stack-scan-frames</code>. |
| 1047 |
Typically, stack scanning generates so many garbage entries that |
| 1048 |
this value is set to a low value (5) by default. In no case |
| 1049 |
will a stack trace larger than the value specified |
| 1050 |
by <code class="computeroutput">--num-callers</code> be |
| 1051 |
created.</p> |
| 1052 |
</dd> |
| 1053 |
<dt> |
| 1054 |
<a name="opt.error-limit"></a><span class="term"> |
| 1055 |
<code class="option">--error-limit=<yes|no> [default: yes] </code> |
| 1056 |
</span> |
| 1057 |
</dt> |
| 1058 |
<dd><p>When enabled, Valgrind stops reporting errors after 10,000,000 |
| 1059 |
in total, or 1,000 different ones, have been seen. This is to |
| 1060 |
stop the error tracking machinery from becoming a huge performance |
| 1061 |
overhead in programs with many errors.</p></dd> |
| 1062 |
<dt> |
| 1063 |
<a name="opt.error-exitcode"></a><span class="term"> |
| 1064 |
<code class="option">--error-exitcode=<number> [default: 0] </code> |
| 1065 |
</span> |
| 1066 |
</dt> |
| 1067 |
<dd><p>Specifies an alternative exit code to return if Valgrind |
| 1068 |
reported any errors in the run. When set to the default value |
| 1069 |
(zero), the return value from Valgrind will always be the return |
| 1070 |
value of the process being simulated. When set to a nonzero value, |
| 1071 |
that value is returned instead, if Valgrind detects any errors. |
| 1072 |
This is useful for using Valgrind as part of an automated test |
| 1073 |
suite, since it makes it easy to detect test cases for which |
| 1074 |
Valgrind has reported errors, just by inspecting return codes. |
| 1075 |
When set to a nonzero value and Valgrind detects no error, |
| 1076 |
the return value of Valgrind will be the return value of the |
| 1077 |
program being simulated. |
| 1078 |
</p></dd> |
| 1079 |
<dt> |
| 1080 |
<a name="opt.exit-on-first-error"></a><span class="term"> |
| 1081 |
<code class="option">--exit-on-first-error=<yes|no> [default: no] </code> |
| 1082 |
</span> |
| 1083 |
</dt> |
| 1084 |
<dd><p>If this option is enabled, Valgrind exits on the first error. |
| 1085 |
A nonzero exit value must be defined using |
| 1086 |
<code class="computeroutput">--error-exitcode</code> option. |
| 1087 |
Useful if you are running regression tests or have some other |
| 1088 |
automated test machinery.</p></dd> |
| 1089 |
<dt> |
| 1090 |
<a name="opt.error-markers"></a><span class="term"> |
| 1091 |
<code class="option">--error-markers=<begin>,<end> [default: none]</code> |
| 1092 |
</span> |
| 1093 |
</dt> |
| 1094 |
<dd> |
| 1095 |
<p>When errors are output as plain text (i.e. XML not used), |
| 1096 |
<code class="option">--error-markers</code> instructs to output a line |
| 1097 |
containing the <code class="option">begin</code> (<code class="option">end</code>) |
| 1098 |
string before (after) each error. </p> |
| 1099 |
<p> Such marker lines facilitate searching for errors and/or |
| 1100 |
extracting errors in an output file that contain valgrind errors mixed |
| 1101 |
with the program output. </p> |
| 1102 |
<p> Note that empty markers are accepted. So, only using a begin |
| 1103 |
(or an end) marker is possible.</p> |
| 1104 |
</dd> |
| 1105 |
<dt> |
| 1106 |
<a name="opt.show-error-list"></a><span class="term"> |
| 1107 |
<code class="option">--show-error-list=no|yes|all [default: no]</code> |
| 1108 |
</span> |
| 1109 |
</dt> |
| 1110 |
<dd> |
| 1111 |
<p>If this option is yes, for tools that report errors, valgrind |
| 1112 |
will show the list of detected errors and the list of used suppressions |
| 1113 |
at exit. The value all indicates to also show the list of suppressed |
| 1114 |
errors. |
| 1115 |
</p> |
| 1116 |
<p>Note that at verbosity 2 and above, valgrind automatically shows |
| 1117 |
the list of detected errors and the list of used suppressions |
| 1118 |
at exit, unless <code class="option">--show-error-list=no</code> is selected. |
| 1119 |
</p> |
| 1120 |
</dd> |
| 1121 |
<dt> |
| 1122 |
<a name="opt.s"></a><span class="term"> |
| 1123 |
<code class="option">-s</code> |
| 1124 |
</span> |
| 1125 |
</dt> |
| 1126 |
<dd><p>Specifying <code class="option">-s</code> is equivalent to |
| 1127 |
<code class="option">--show-error-list=yes</code>. |
| 1128 |
</p></dd> |
| 1129 |
<dt> |
| 1130 |
<a name="opt.sigill-diagnostics"></a><span class="term"> |
| 1131 |
<code class="option">--sigill-diagnostics=<yes|no> [default: yes] </code> |
| 1132 |
</span> |
| 1133 |
</dt> |
| 1134 |
<dd> |
| 1135 |
<p>Enable/disable printing of illegal instruction diagnostics. |
| 1136 |
Enabled by default, but defaults to disabled when |
| 1137 |
<code class="option">--quiet</code> is given. The default can always be explicitly |
| 1138 |
overridden by giving this option.</p> |
| 1139 |
<p>When enabled, a warning message will be printed, along with some |
| 1140 |
diagnostics, whenever an instruction is encountered that Valgrind |
| 1141 |
cannot decode or translate, before the program is given a SIGILL signal. |
| 1142 |
Often an illegal instruction indicates a bug in the program or missing |
| 1143 |
support for the particular instruction in Valgrind. But some programs |
| 1144 |
do deliberately try to execute an instruction that might be missing |
| 1145 |
and trap the SIGILL signal to detect processor features. Using |
| 1146 |
this flag makes it possible to avoid the diagnostic output |
| 1147 |
that you would otherwise get in such cases.</p> |
| 1148 |
</dd> |
| 1149 |
<dt> |
| 1150 |
<a name="opt.keep-debuginfo"></a><span class="term"> |
| 1151 |
<code class="option">--keep-debuginfo=<yes|no> [default: no] </code> |
| 1152 |
</span> |
| 1153 |
</dt> |
| 1154 |
<dd> |
| 1155 |
<p>When enabled, keep ("archive") symbols and all other debuginfo |
| 1156 |
for unloaded code. This allows saved stack traces to include file/line |
| 1157 |
info for code that has been dlclose'd (or similar). Be careful with |
| 1158 |
this, since it can lead to unbounded memory use for programs which |
| 1159 |
repeatedly load and unload shared objects.</p> |
| 1160 |
<p>Some tools and some functionalities have only limited support |
| 1161 |
for archived debug info. Memcheck fully supports it. Generally, |
| 1162 |
tools that report errors can use archived debug info to show the error |
| 1163 |
stack traces. The known limitations are: Helgrind's past access stack |
| 1164 |
trace of a race condition is does not use archived debug info. Massif |
| 1165 |
(and more generally the xtree Massif output format) does not make use |
| 1166 |
of archived debug info. Only Memcheck has been (somewhat) tested |
| 1167 |
with <code class="option">--keep-debuginfo=yes</code>, so other tools may have |
| 1168 |
unknown limitations. </p> |
| 1169 |
</dd> |
| 1170 |
<dt> |
| 1171 |
<a name="opt.show-below-main"></a><span class="term"> |
| 1172 |
<code class="option">--show-below-main=<yes|no> [default: no] </code> |
| 1173 |
</span> |
| 1174 |
</dt> |
| 1175 |
<dd> |
| 1176 |
<p>By default, stack traces for errors do not show any |
| 1177 |
functions that appear beneath <code class="function">main</code> because |
| 1178 |
most of the time it's uninteresting C library stuff and/or |
| 1179 |
gobbledygook. Alternatively, if <code class="function">main</code> is not |
| 1180 |
present in the stack trace, stack traces will not show any functions |
| 1181 |
below <code class="function">main</code>-like functions such as glibc's |
| 1182 |
<code class="function">__libc_start_main</code>. Furthermore, if |
| 1183 |
<code class="function">main</code>-like functions are present in the trace, |
| 1184 |
they are normalised as <code class="function">(below main)</code>, in order to |
| 1185 |
make the output more deterministic.</p> |
| 1186 |
<p>If this option is enabled, all stack trace entries will be |
| 1187 |
shown and <code class="function">main</code>-like functions will not be |
| 1188 |
normalised.</p> |
| 1189 |
</dd> |
| 1190 |
<dt> |
| 1191 |
<a name="opt.fullpath-after"></a><span class="term"> |
| 1192 |
<code class="option">--fullpath-after=<string> |
| 1193 |
[default: don't show source paths] </code> |
| 1194 |
</span> |
| 1195 |
</dt> |
| 1196 |
<dd> |
| 1197 |
<p>By default Valgrind only shows the filenames in stack |
| 1198 |
traces, but not full paths to source files. When using Valgrind |
| 1199 |
in large projects where the sources reside in multiple different |
| 1200 |
directories, this can be inconvenient. |
| 1201 |
<code class="option">--fullpath-after</code> provides a flexible solution |
| 1202 |
to this problem. When this option is present, the path to each |
| 1203 |
source file is shown, with the following all-important caveat: |
| 1204 |
if <code class="option">string</code> is found in the path, then the path |
| 1205 |
up to and including <code class="option">string</code> is omitted, else the |
| 1206 |
path is shown unmodified. Note that <code class="option">string</code> is |
| 1207 |
not required to be a prefix of the path.</p> |
| 1208 |
<p>For example, consider a file named |
| 1209 |
<code class="computeroutput">/home/janedoe/blah/src/foo/bar/xyzzy.c</code>. |
| 1210 |
Specifying <code class="option">--fullpath-after=/home/janedoe/blah/src/</code> |
| 1211 |
will cause Valgrind to show the name |
| 1212 |
as <code class="computeroutput">foo/bar/xyzzy.c</code>.</p> |
| 1213 |
<p>Because the string is not required to be a prefix, |
| 1214 |
<code class="option">--fullpath-after=src/</code> will produce the same |
| 1215 |
output. This is useful when the path contains arbitrary |
| 1216 |
machine-generated characters. For example, the |
| 1217 |
path |
| 1218 |
<code class="computeroutput">/my/build/dir/C32A1B47/blah/src/foo/xyzzy</code> |
| 1219 |
can be pruned to <code class="computeroutput">foo/xyzzy</code> |
| 1220 |
using |
| 1221 |
<code class="option">--fullpath-after=/blah/src/</code>.</p> |
| 1222 |
<p>If you simply want to see the full path, just specify an |
| 1223 |
empty string: <code class="option">--fullpath-after=</code>. This isn't a |
| 1224 |
special case, merely a logical consequence of the above rules.</p> |
| 1225 |
<p>Finally, you can use <code class="option">--fullpath-after</code> |
| 1226 |
multiple times. Any appearance of it causes Valgrind to switch |
| 1227 |
to producing full paths and applying the above filtering rule. |
| 1228 |
Each produced path is compared against all |
| 1229 |
the <code class="option">--fullpath-after</code>-specified strings, in the |
| 1230 |
order specified. The first string to match causes the path to |
| 1231 |
be truncated as described above. If none match, the full path |
| 1232 |
is shown. This facilitates chopping off prefixes when the |
| 1233 |
sources are drawn from a number of unrelated directories. |
| 1234 |
</p> |
| 1235 |
</dd> |
| 1236 |
<dt> |
| 1237 |
<a name="opt.extra-debuginfo-path"></a><span class="term"> |
| 1238 |
<code class="option">--extra-debuginfo-path=<path> [default: undefined and unused] </code> |
| 1239 |
</span> |
| 1240 |
</dt> |
| 1241 |
<dd> |
| 1242 |
<p>By default Valgrind searches in several well-known paths |
| 1243 |
for debug objects, such |
| 1244 |
as <code class="computeroutput">/usr/lib/debug/</code>.</p> |
| 1245 |
<p>However, there may be scenarios where you may wish to put |
| 1246 |
debug objects at an arbitrary location, such as external storage |
| 1247 |
when running Valgrind on a mobile device with limited local |
| 1248 |
storage. Another example might be a situation where you do not |
| 1249 |
have permission to install debug object packages on the system |
| 1250 |
where you are running Valgrind.</p> |
| 1251 |
<p>In these scenarios, you may provide an absolute path as an extra, |
| 1252 |
final place for Valgrind to search for debug objects by specifying |
| 1253 |
<code class="option">--extra-debuginfo-path=/path/to/debug/objects</code>. |
| 1254 |
The given path will be prepended to the absolute path name of |
| 1255 |
the searched-for object. For example, if Valgrind is looking |
| 1256 |
for the debuginfo |
| 1257 |
for <code class="computeroutput">/w/x/y/zz.so</code> |
| 1258 |
and <code class="option">--extra-debuginfo-path=/a/b/c</code> is specified, |
| 1259 |
it will look for a debug object at |
| 1260 |
<code class="computeroutput">/a/b/c/w/x/y/zz.so</code>.</p> |
| 1261 |
<p>This flag should only be specified once. If it is |
| 1262 |
specified multiple times, only the last instance is |
| 1263 |
honoured.</p> |
| 1264 |
</dd> |
| 1265 |
<dt> |
| 1266 |
<a name="opt.debuginfo-server"></a><span class="term"> |
| 1267 |
<code class="option">--debuginfo-server=ipaddr:port [default: undefined and unused]</code> |
| 1268 |
</span> |
| 1269 |
</dt> |
| 1270 |
<dd> |
| 1271 |
<p>This is a new, experimental, feature introduced in version |
| 1272 |
3.9.0.</p> |
| 1273 |
<p>In some scenarios it may be convenient to read debuginfo |
| 1274 |
from objects stored on a different machine. With this flag, |
| 1275 |
Valgrind will query a debuginfo server running |
| 1276 |
on <code class="computeroutput">ipaddr</code> and listening on |
| 1277 |
port <code class="computeroutput">port</code>, if it cannot find |
| 1278 |
the debuginfo object in the local filesystem.</p> |
| 1279 |
<p>The debuginfo server must accept TCP connections on |
| 1280 |
port <code class="computeroutput">port</code>. The debuginfo |
| 1281 |
server is contained in the source |
| 1282 |
file <code class="computeroutput">auxprogs/valgrind-di-server.c</code>. |
| 1283 |
It will only serve from the directory it is started |
| 1284 |
in. <code class="computeroutput">port</code> defaults to 1500 in |
| 1285 |
both client and server if not specified.</p> |
| 1286 |
<p>If Valgrind looks for the debuginfo for |
| 1287 |
<code class="computeroutput">/w/x/y/zz.so</code> by using the |
| 1288 |
debuginfo server, it will strip the pathname components and |
| 1289 |
merely request <code class="computeroutput">zz.so</code> on the |
| 1290 |
server. That in turn will look only in its current working |
| 1291 |
directory for a matching debuginfo object.</p> |
| 1292 |
<p>The debuginfo data is transmitted in small fragments (8 |
| 1293 |
KB) as requested by Valgrind. Each block is compressed using |
| 1294 |
LZO to reduce transmission time. The implementation has been |
| 1295 |
tuned for best performance over a single-stage 802.11g (WiFi) |
| 1296 |
network link.</p> |
| 1297 |
<p>Note that checks for matching primary vs debug objects, |
| 1298 |
using GNU debuglink CRC scheme, are performed even when using |
| 1299 |
the debuginfo server. To disable such checking, you need to |
| 1300 |
also specify |
| 1301 |
<code class="computeroutput">--allow-mismatched-debuginfo=yes</code>. |
| 1302 |
</p> |
| 1303 |
<p>By default the Valgrind build system will |
| 1304 |
build <code class="computeroutput">valgrind-di-server</code> for |
| 1305 |
the target platform, which is almost certainly not what you |
| 1306 |
want. So far we have been unable to find out how to get |
| 1307 |
automake/autoconf to build it for the build platform. If |
| 1308 |
you want to use it, you will have to recompile it by hand using |
| 1309 |
the command shown at the top |
| 1310 |
of <code class="computeroutput">auxprogs/valgrind-di-server.c</code>.</p> |
| 1311 |
<p>Valgrind can also download debuginfo via debuginfod. See the |
| 1312 |
DEBUGINFOD section for more information.</p> |
| 1313 |
</dd> |
| 1314 |
<dt> |
| 1315 |
<a name="opt.allow-mismatched-debuginfo"></a><span class="term"> |
| 1316 |
<code class="option">--allow-mismatched-debuginfo=no|yes [no] </code> |
| 1317 |
</span> |
| 1318 |
</dt> |
| 1319 |
<dd> |
| 1320 |
<p>When reading debuginfo from separate debuginfo objects, |
| 1321 |
Valgrind will by default check that the main and debuginfo |
| 1322 |
objects match, using the GNU debuglink mechanism. This |
| 1323 |
guarantees that it does not read debuginfo from out of date |
| 1324 |
debuginfo objects, and also ensures that Valgrind can't crash as |
| 1325 |
a result of mismatches.</p> |
| 1326 |
<p>This check can be overridden using |
| 1327 |
<code class="computeroutput">--allow-mismatched-debuginfo=yes</code>. |
| 1328 |
This may be useful when the debuginfo and main objects have not |
| 1329 |
been split in the proper way. Be careful when using this, |
| 1330 |
though: it disables all consistency checking, and Valgrind has |
| 1331 |
been observed to crash when the main and debuginfo objects don't |
| 1332 |
match.</p> |
| 1333 |
</dd> |
| 1334 |
<dt> |
| 1335 |
<a name="opt.suppressions"></a><span class="term"> |
| 1336 |
<code class="option">--suppressions=<filename> [default: $PREFIX/lib/valgrind/default.supp] </code> |
| 1337 |
</span> |
| 1338 |
</dt> |
| 1339 |
<dd><p>Specifies an extra file from which to read descriptions of |
| 1340 |
errors to suppress. You may use up to 100 extra suppression |
| 1341 |
files.</p></dd> |
| 1342 |
<dt> |
| 1343 |
<a name="opt.gen-suppressions"></a><span class="term"> |
| 1344 |
<code class="option">--gen-suppressions=<yes|no|all> [default: no] </code> |
| 1345 |
</span> |
| 1346 |
</dt> |
| 1347 |
<dd> |
| 1348 |
<p>When set to <code class="varname">yes</code>, Valgrind will pause |
| 1349 |
after every error shown and print the line: |
| 1350 |
</p> |
| 1351 |
<div class="literallayout"><p><code class="computeroutput"> ---- Print suppression ? --- [Return/N/n/Y/y/C/c] ----</code></p></div> |
| 1352 |
<p> |
| 1353 |
|
| 1354 |
Pressing <code class="varname">Ret</code>, or <code class="varname">N Ret</code> or |
| 1355 |
<code class="varname">n Ret</code>, causes Valgrind continue execution without |
| 1356 |
printing a suppression for this error.</p> |
| 1357 |
<p>Pressing <code class="varname">Y Ret</code> or |
| 1358 |
<code class="varname">y Ret</code> causes Valgrind to write a suppression |
| 1359 |
for this error. You can then cut and paste it into a suppression file |
| 1360 |
if you don't want to hear about the error in the future.</p> |
| 1361 |
<p>When set to <code class="varname">all</code>, Valgrind will print a |
| 1362 |
suppression for every reported error, without querying the |
| 1363 |
user.</p> |
| 1364 |
<p>This option is particularly useful with C++ programs, as it |
| 1365 |
prints out the suppressions with mangled names, as |
| 1366 |
required.</p> |
| 1367 |
<p>Note that the suppressions printed are as specific as |
| 1368 |
possible. You may want to common up similar ones, by adding |
| 1369 |
wildcards to function names, and by using frame-level wildcards. |
| 1370 |
The wildcarding facilities are powerful yet flexible, and with a |
| 1371 |
bit of careful editing, you may be able to suppress a whole |
| 1372 |
family of related errors with only a few suppressions. |
| 1373 |
|
| 1374 |
</p> |
| 1375 |
<p>Sometimes two different errors |
| 1376 |
are suppressed by the same suppression, in which case Valgrind |
| 1377 |
will output the suppression more than once, but you only need to |
| 1378 |
have one copy in your suppression file (but having more than one |
| 1379 |
won't cause problems). Also, the suppression name is given as |
| 1380 |
<code class="computeroutput"><insert a suppression name |
| 1381 |
here></code>; the name doesn't really matter, it's |
| 1382 |
only used with the <code class="option">-v</code> option which prints out all |
| 1383 |
used suppression records.</p> |
| 1384 |
</dd> |
| 1385 |
<dt> |
| 1386 |
<a name="opt.input-fd"></a><span class="term"> |
| 1387 |
<code class="option">--input-fd=<number> [default: 0, stdin] </code> |
| 1388 |
</span> |
| 1389 |
</dt> |
| 1390 |
<dd><p>When using |
| 1391 |
<code class="option">--gen-suppressions=yes</code>, Valgrind will stop so as |
| 1392 |
to read keyboard input from you when each error occurs. By |
| 1393 |
default it reads from the standard input (stdin), which is |
| 1394 |
problematic for programs which close stdin. This option allows |
| 1395 |
you to specify an alternative file descriptor from which to read |
| 1396 |
input.</p></dd> |
| 1397 |
<dt> |
| 1398 |
<a name="opt.dsymutil"></a><span class="term"> |
| 1399 |
<code class="option">--dsymutil=no|yes [yes] </code> |
| 1400 |
</span> |
| 1401 |
</dt> |
| 1402 |
<dd> |
| 1403 |
<p>This option is only relevant when running Valgrind on |
| 1404 |
macOS.</p> |
| 1405 |
<p>macOS uses a deferred debug information (debuginfo) |
| 1406 |
linking scheme. When object files containing debuginfo are |
| 1407 |
linked into a <code class="computeroutput">.dylib</code> or an |
| 1408 |
executable, the debuginfo is not copied into the final file. |
| 1409 |
Instead, the debuginfo must be linked manually by |
| 1410 |
running <code class="computeroutput">dsymutil</code>, a |
| 1411 |
system-provided utility, on the executable |
| 1412 |
or <code class="computeroutput">.dylib</code>. The resulting |
| 1413 |
combined debuginfo is placed in a directory alongside the |
| 1414 |
executable or <code class="computeroutput">.dylib</code>, but with |
| 1415 |
the extension <code class="computeroutput">.dSYM</code>.</p> |
| 1416 |
<p>With <code class="option">--dsymutil=no</code>, Valgrind |
| 1417 |
will detect cases where the |
| 1418 |
<code class="computeroutput">.dSYM</code> directory is either |
| 1419 |
missing, or is present but does not appear to match the |
| 1420 |
associated executable or <code class="computeroutput">.dylib</code>, |
| 1421 |
most likely because it is out of date. In these cases, Valgrind |
| 1422 |
will print a warning message but take no further action.</p> |
| 1423 |
<p>With <code class="option">--dsymutil=yes</code>, Valgrind |
| 1424 |
will, in such cases, automatically |
| 1425 |
run <code class="computeroutput">dsymutil</code> as necessary to |
| 1426 |
bring the debuginfo up to date. For all practical purposes, if |
| 1427 |
you always use <code class="option">--dsymutil=yes</code>, then |
| 1428 |
there is never any need to |
| 1429 |
run <code class="computeroutput">dsymutil</code> manually or as part |
| 1430 |
of your applications's build system, since Valgrind will run it |
| 1431 |
as necessary.</p> |
| 1432 |
<p>Valgrind will not attempt to |
| 1433 |
run <code class="computeroutput">dsymutil</code> on any |
| 1434 |
executable or library in |
| 1435 |
<code class="computeroutput">/usr/</code>, |
| 1436 |
<code class="computeroutput">/bin/</code>, |
| 1437 |
<code class="computeroutput">/sbin/</code>, |
| 1438 |
<code class="computeroutput">/opt/</code>, |
| 1439 |
<code class="computeroutput">/sw/</code>, |
| 1440 |
<code class="computeroutput">/System/</code>, |
| 1441 |
<code class="computeroutput">/Library/</code> or |
| 1442 |
<code class="computeroutput">/Applications/</code> |
| 1443 |
since <code class="computeroutput">dsymutil</code> will always fail |
| 1444 |
in such situations. It fails both because the debuginfo for |
| 1445 |
such pre-installed system components is not available anywhere, |
| 1446 |
and also because it would require write privileges in those |
| 1447 |
directories.</p> |
| 1448 |
<p>Be careful when |
| 1449 |
using <code class="option">--dsymutil=yes</code>, since it will |
| 1450 |
cause pre-existing <code class="computeroutput">.dSYM</code> |
| 1451 |
directories to be silently deleted and re-created. Also note that |
| 1452 |
<code class="computeroutput">dsymutil</code> is quite slow, sometimes |
| 1453 |
excessively so.</p> |
| 1454 |
</dd> |
| 1455 |
<dt> |
| 1456 |
<a name="opt.max-stackframe"></a><span class="term"> |
| 1457 |
<code class="option">--max-stackframe=<number> [default: 2000000] </code> |
| 1458 |
</span> |
| 1459 |
</dt> |
| 1460 |
<dd> |
| 1461 |
<p>The maximum size of a stack frame. If the stack pointer moves by |
| 1462 |
more than this amount then Valgrind will assume that |
| 1463 |
the program is switching to a different stack.</p> |
| 1464 |
<p>You may need to use this option if your program has large |
| 1465 |
stack-allocated arrays. Valgrind keeps track of your program's |
| 1466 |
stack pointer. If it changes by more than the threshold amount, |
| 1467 |
Valgrind assumes your program is switching to a different stack, |
| 1468 |
and Memcheck behaves differently than it would for a stack pointer |
| 1469 |
change smaller than the threshold. Usually this heuristic works |
| 1470 |
well. However, if your program allocates large structures on the |
| 1471 |
stack, this heuristic will be fooled, and Memcheck will |
| 1472 |
subsequently report large numbers of invalid stack accesses. This |
| 1473 |
option allows you to change the threshold to a different |
| 1474 |
value.</p> |
| 1475 |
<p>You should only consider use of this option if Valgrind's |
| 1476 |
debug output directs you to do so. In that case it will tell you |
| 1477 |
the new threshold you should specify.</p> |
| 1478 |
<p>In general, allocating large structures on the stack is a |
| 1479 |
bad idea, because you can easily run out of stack space, |
| 1480 |
especially on systems with limited memory or which expect to |
| 1481 |
support large numbers of threads each with a small stack, and also |
| 1482 |
because the error checking performed by Memcheck is more effective |
| 1483 |
for heap-allocated data than for stack-allocated data. If you |
| 1484 |
have to use this option, you may wish to consider rewriting your |
| 1485 |
code to allocate on the heap rather than on the stack.</p> |
| 1486 |
</dd> |
| 1487 |
<dt> |
| 1488 |
<a name="opt.main-stacksize"></a><span class="term"> |
| 1489 |
<code class="option">--main-stacksize=<number> |
| 1490 |
[default: use current 'ulimit' value] </code> |
| 1491 |
</span> |
| 1492 |
</dt> |
| 1493 |
<dd> |
| 1494 |
<p>Specifies the size of the main thread's stack.</p> |
| 1495 |
<p>To simplify its memory management, Valgrind reserves all |
| 1496 |
required space for the main thread's stack at startup. That |
| 1497 |
means it needs to know the required stack size at |
| 1498 |
startup.</p> |
| 1499 |
<p>By default, Valgrind uses the current "ulimit" value for |
| 1500 |
the stack size, or 16 MB, whichever is lower. In many cases |
| 1501 |
this gives a stack size in the range 8 to 16 MB, which almost |
| 1502 |
never overflows for most applications.</p> |
| 1503 |
<p>If you need a larger total stack size, |
| 1504 |
use <code class="option">--main-stacksize</code> to specify it. Only set |
| 1505 |
it as high as you need, since reserving far more space than you |
| 1506 |
need (that is, hundreds of megabytes more than you need) |
| 1507 |
constrains Valgrind's memory allocators and may reduce the total |
| 1508 |
amount of memory that Valgrind can use. This is only really of |
| 1509 |
significance on 32-bit machines.</p> |
| 1510 |
<p>On Linux, you may request a stack of size up to 2GB. |
| 1511 |
Valgrind will stop with a diagnostic message if the stack cannot |
| 1512 |
be allocated.</p> |
| 1513 |
<p><code class="option">--main-stacksize</code> only affects the stack |
| 1514 |
size for the program's initial thread. It has no bearing on the |
| 1515 |
size of thread stacks, as Valgrind does not allocate |
| 1516 |
those.</p> |
| 1517 |
<p>You may need to use both <code class="option">--main-stacksize</code> |
| 1518 |
and <code class="option">--max-stackframe</code> together. It is important |
| 1519 |
to understand that <code class="option">--main-stacksize</code> sets the |
| 1520 |
maximum total stack size, |
| 1521 |
whilst <code class="option">--max-stackframe</code> specifies the largest |
| 1522 |
size of any one stack frame. You will have to work out |
| 1523 |
the <code class="option">--main-stacksize</code> value for yourself |
| 1524 |
(usually, if your applications segfaults). But Valgrind will |
| 1525 |
tell you the needed <code class="option">--max-stackframe</code> size, if |
| 1526 |
necessary.</p> |
| 1527 |
<p>As discussed further in the description |
| 1528 |
of <code class="option">--max-stackframe</code>, a requirement for a large |
| 1529 |
stack is a sign of potential portability problems. You are best |
| 1530 |
advised to place all large data in heap-allocated memory.</p> |
| 1531 |
</dd> |
| 1532 |
<dt> |
| 1533 |
<a name="opt.max-threads"></a><span class="term"> |
| 1534 |
<code class="option">--max-threads=<number> [default: 500] </code> |
| 1535 |
</span> |
| 1536 |
</dt> |
| 1537 |
<dd><p>By default, Valgrind can handle to up to 500 threads. |
| 1538 |
Occasionally, that number is too small. Use this option to |
| 1539 |
provide a different limit. E.g. |
| 1540 |
<code class="computeroutput">--max-threads=3000</code>. |
| 1541 |
</p></dd> |
| 1542 |
<dt> |
| 1543 |
<a name="opt.realloc-zero-bytes-frees"></a><span class="term"> |
| 1544 |
<code class="option">--realloc-zero-bytes-frees=yes|no [default: yes for glibc no otherwise] </code> |
| 1545 |
</span> |
| 1546 |
</dt> |
| 1547 |
<dd> |
| 1548 |
<p>The behaviour of <code class="computeroutput">realloc()</code> with a size |
| 1549 |
of zero is implementation defined in C17 and undefined in C23. |
| 1550 |
Valgrind tries to work in the same way as the |
| 1551 |
underlying system and C runtime library that it was configured and built on. |
| 1552 |
However, if you use a different C runtime library then this default may be wrong. |
| 1553 |
If the value is <code class="option">yes</code> then <code class="varname">realloc</code> will |
| 1554 |
deallocate the memory and return NULL. If the value is <code class="option">no</code> then |
| 1555 |
<code class="varname">realloc</code> will not deallocate the memory and |
| 1556 |
the size will be handled as though it were one byte.</p> |
| 1557 |
<p>As an example, if you use Valgrind installed via a package on a |
| 1558 |
Linux distro using GNU libc but link your test executable with musl libc or |
| 1559 |
the JEMalloc library then consider using |
| 1560 |
<code class="computeroutput">--realloc-zero-bytes-frees=no</code>. |
| 1561 |
</p> |
| 1562 |
<p>Address Sanitizer has a similar and even wordier option |
| 1563 |
<code class="computeroutput">allocator_frees_and_returns_null_on_realloc_zero</code>. |
| 1564 |
</p> |
| 1565 |
</dd> |
| 1566 |
</dl> |
| 1567 |
</div> |
| 1568 |
</div> |
| 1569 |
<div class="sect2"> |
| 1570 |
<div class="titlepage"><div><div><h3 class="title"> |
| 1571 |
<a name="manual-core.mallocopts"></a>2.7.4. malloc-related Options</h3></div></div></div> |
| 1572 |
<p><a name="malloc-related.opts.para"></a>For tools that use their own version of |
| 1573 |
<code class="computeroutput">malloc</code> (e.g. Memcheck, |
| 1574 |
Massif, Helgrind, DRD), the following options apply.</p> |
| 1575 |
<div class="variablelist"> |
| 1576 |
<a name="malloc-related.opts.list"></a><dl class="variablelist"> |
| 1577 |
<dt> |
| 1578 |
<a name="opt.alignment"></a><span class="term"> |
| 1579 |
<code class="option">--alignment=<number> [default: 8 or 16, depending on the platform] </code> |
| 1580 |
</span> |
| 1581 |
</dt> |
| 1582 |
<dd><p>By default Valgrind's <code class="function">malloc</code>, |
| 1583 |
<code class="function">realloc</code>, etc, return a block whose starting |
| 1584 |
address is 8-byte aligned or 16-byte aligned (the value depends on the |
| 1585 |
platform and matches the platform default). This option allows you to |
| 1586 |
specify a different alignment. The supplied value must be greater |
| 1587 |
than or equal to the default, less than or equal to 4096, and must be |
| 1588 |
a power of two.</p></dd> |
| 1589 |
<dt> |
| 1590 |
<a name="opt.redzone-size"></a><span class="term"> |
| 1591 |
<code class="option">--redzone-size=<number> [default: depends on the tool] </code> |
| 1592 |
</span> |
| 1593 |
</dt> |
| 1594 |
<dd> |
| 1595 |
<p> Valgrind's <code class="function">malloc, realloc,</code> etc, add |
| 1596 |
padding blocks before and after each heap block allocated by the |
| 1597 |
program being run. Such padding blocks are called redzones. The |
| 1598 |
default value for the redzone size depends on the tool. For |
| 1599 |
example, Memcheck adds and protects a minimum of 16 bytes before |
| 1600 |
and after each block allocated by the client. This allows it to |
| 1601 |
detect block underruns or overruns of up to 16 bytes. |
| 1602 |
</p> |
| 1603 |
<p>Increasing the redzone size makes it possible to detect |
| 1604 |
overruns of larger distances, but increases the amount of memory |
| 1605 |
used by Valgrind. Decreasing the redzone size will reduce the |
| 1606 |
memory needed by Valgrind but also reduces the chances of |
| 1607 |
detecting over/underruns, so is not recommended.</p> |
| 1608 |
</dd> |
| 1609 |
<dt> |
| 1610 |
<a name="opt.xtree-memory"></a><span class="term"> |
| 1611 |
<code class="option">--xtree-memory=none|allocs|full [none] </code> |
| 1612 |
</span> |
| 1613 |
</dt> |
| 1614 |
<dd> |
| 1615 |
<p> Tools replacing Valgrind's <code class="function">malloc, |
| 1616 |
realloc,</code> etc, can optionally produce an execution |
| 1617 |
tree detailing which piece of code is responsible for heap |
| 1618 |
memory usage. See <a class="xref" href="manual-core.html#manual-core.xtree" title="2.10. Execution Trees">Execution Trees</a> |
| 1619 |
for a detailed explanation about execution trees. </p> |
| 1620 |
<p> When set to <code class="varname">none</code>, no memory execution |
| 1621 |
tree is produced.</p> |
| 1622 |
<p> When set to <code class="varname">allocs</code>, the memory |
| 1623 |
execution tree gives the current number of allocated bytes and |
| 1624 |
the current number of allocated blocks. </p> |
| 1625 |
<p> When set to <code class="varname">full</code>, the memory execution |
| 1626 |
tree gives 6 different measurements : the current number of |
| 1627 |
allocated bytes and blocks (same values as |
| 1628 |
for <code class="varname">allocs</code>), the total number of allocated |
| 1629 |
bytes and blocks, the total number of freed bytes and |
| 1630 |
blocks.</p> |
| 1631 |
<p>Note that the overhead in cpu and memory to produce |
| 1632 |
an xtree depends on the tool. The overhead in cpu is small for |
| 1633 |
the value <code class="varname">allocs</code>, as the information needed |
| 1634 |
to produce this report is maintained in any case by the tool. |
| 1635 |
For massif and helgrind, specifying <code class="varname">full</code> |
| 1636 |
implies to capture a stack trace for each free operation, |
| 1637 |
while normally these tools only capture an allocation stack |
| 1638 |
trace. For Memcheck, the cpu overhead for the |
| 1639 |
value <code class="varname">full</code> is small, as this can only be |
| 1640 |
used in combination with |
| 1641 |
<code class="option">--keep-stacktraces=alloc-and-free</code> or |
| 1642 |
<code class="option">--keep-stacktraces=alloc-then-free</code>, which |
| 1643 |
already records a stack trace for each free operation. The |
| 1644 |
memory overhead varies between 5 and 10 words per unique |
| 1645 |
stacktrace in the xtree, plus the memory needed to record the |
| 1646 |
stack trace for the free operations, if needed specifically |
| 1647 |
for the xtree. |
| 1648 |
</p> |
| 1649 |
</dd> |
| 1650 |
<dt> |
| 1651 |
<a name="opt.xtree-memory-file"></a><span class="term"> |
| 1652 |
<code class="option">--xtree-memory-file=<filename> [default: |
| 1653 |
xtmemory.kcg.%p] </code> |
| 1654 |
</span> |
| 1655 |
</dt> |
| 1656 |
<dd> |
| 1657 |
<p>Specifies that Valgrind should produce the xtree memory |
| 1658 |
report in the specified file. Any <code class="option">%p</code> or |
| 1659 |
<code class="option">%q</code> sequences appearing in the filename are expanded |
| 1660 |
in exactly the same way as they are for <code class="option">--log-file</code>. |
| 1661 |
See the description of <a class="xref" href="manual-core.html#opt.log-file">--log-file</a> |
| 1662 |
for details. </p> |
| 1663 |
<p>If the filename contains the extension <code class="option">.ms</code>, |
| 1664 |
then the produced file format will be a massif output file format. |
| 1665 |
If the filename contains the extension <code class="option">.kcg</code> |
| 1666 |
or no extension is provided or recognised, |
| 1667 |
then the produced file format will be a callgrind output format.</p> |
| 1668 |
<p>See <a class="xref" href="manual-core.html#manual-core.xtree" title="2.10. Execution Trees">Execution Trees</a> |
| 1669 |
for a detailed explanation about execution trees formats. </p> |
| 1670 |
</dd> |
| 1671 |
</dl> |
| 1672 |
</div> |
| 1673 |
</div> |
| 1674 |
<div class="sect2"> |
| 1675 |
<div class="titlepage"><div><div><h3 class="title"> |
| 1676 |
<a name="manual-core.rareopts"></a>2.7.5. Uncommon Options</h3></div></div></div> |
| 1677 |
<p><a name="uncommon.opts.para"></a>These options apply to all tools, as they |
| 1678 |
affect certain obscure workings of the Valgrind core. Most people won't |
| 1679 |
need to use them.</p> |
| 1680 |
<div class="variablelist"> |
| 1681 |
<a name="uncommon.opts.list"></a><dl class="variablelist"> |
| 1682 |
<dt> |
| 1683 |
<a name="opt.smc-check"></a><span class="term"> |
| 1684 |
<code class="option">--smc-check=<none|stack|all|all-non-file> |
| 1685 |
[default: all-non-file for x86/amd64/s390x, stack for other archs] </code> |
| 1686 |
</span> |
| 1687 |
</dt> |
| 1688 |
<dd> |
| 1689 |
<p>This option controls Valgrind's detection of self-modifying |
| 1690 |
code. If no checking is done, when a program executes some code, then |
| 1691 |
overwrites it with new code, and executes the new code, Valgrind will |
| 1692 |
continue to execute the translations it made for the old code. This |
| 1693 |
will likely lead to incorrect behaviour and/or crashes.</p> |
| 1694 |
<p>For "modern" architectures -- anything that's not x86, |
| 1695 |
amd64 or s390x -- the default is <code class="varname">stack</code>. |
| 1696 |
This is because a correct program must take explicit action |
| 1697 |
to reestablish D-I cache coherence following code |
| 1698 |
modification. Valgrind observes and honours such actions, |
| 1699 |
with the result that self-modifying code is transparently |
| 1700 |
handled with zero extra cost.</p> |
| 1701 |
<p>For x86, amd64 and s390x, the program is not required to |
| 1702 |
notify the hardware of required D-I coherence syncing. Hence |
| 1703 |
the default is <code class="varname">all-non-file</code>, which covers |
| 1704 |
the normal case of generating code into an anonymous |
| 1705 |
(non-file-backed) mmap'd area.</p> |
| 1706 |
<p>The meanings of the four available settings are as |
| 1707 |
follows. No detection (<code class="varname">none</code>), |
| 1708 |
detect self-modifying code |
| 1709 |
on the stack (which is used by GCC to implement nested |
| 1710 |
functions) (<code class="varname">stack</code>), detect self-modifying code |
| 1711 |
everywhere (<code class="varname">all</code>), and detect |
| 1712 |
self-modifying code everywhere except in file-backed |
| 1713 |
mappings (<code class="varname">all-non-file</code>).</p> |
| 1714 |
<p>Running with <code class="varname">all</code> will slow Valgrind |
| 1715 |
down noticeably. Running with <code class="varname">none</code> will |
| 1716 |
rarely speed things up, since very little code gets |
| 1717 |
dynamically generated in most programs. The |
| 1718 |
<code class="function">VALGRIND_DISCARD_TRANSLATIONS</code> client |
| 1719 |
request is an alternative to <code class="option">--smc-check=all</code> |
| 1720 |
and <code class="option">--smc-check=all-non-file</code> |
| 1721 |
that requires more programmer effort but allows Valgrind to run |
| 1722 |
your program faster, by telling it precisely when translations |
| 1723 |
need to be re-made. |
| 1724 |
|
| 1725 |
</p> |
| 1726 |
<p><code class="option">--smc-check=all-non-file</code> provides a |
| 1727 |
cheaper but more limited version |
| 1728 |
of <code class="option">--smc-check=all</code>. It adds checks to any |
| 1729 |
translations that do not originate from file-backed memory |
| 1730 |
mappings. Typical applications that generate code, for example |
| 1731 |
JITs in web browsers, generate code into anonymous mmaped areas, |
| 1732 |
whereas the "fixed" code of the browser always lives in |
| 1733 |
file-backed mappings. <code class="option">--smc-check=all-non-file</code> |
| 1734 |
takes advantage of this observation, limiting the overhead of |
| 1735 |
checking to code which is likely to be JIT generated.</p> |
| 1736 |
</dd> |
| 1737 |
<dt> |
| 1738 |
<a name="opt.read-inline-info"></a><span class="term"> |
| 1739 |
<code class="option">--read-inline-info=<yes|no> [default: see below] </code> |
| 1740 |
</span> |
| 1741 |
</dt> |
| 1742 |
<dd> |
| 1743 |
<p>When enabled, Valgrind will read information about inlined |
| 1744 |
function calls from DWARF3 debug info. This slows Valgrind |
| 1745 |
startup and makes it use more memory (typically for each inlined |
| 1746 |
piece of code, 6 words and space for the function name), but it |
| 1747 |
results in more descriptive stacktraces. Currently, |
| 1748 |
this functionality is enabled by default only for Linux, FreeBSD, |
| 1749 |
Android and Solaris targets and only for the tools Memcheck, Massif, |
| 1750 |
Helgrind and DRD. Here is an example of some stacktraces with |
| 1751 |
<code class="option">--read-inline-info=no</code>: |
| 1752 |
</p> |
| 1753 |
<pre class="programlisting"> |
| 1754 |
==15380== Conditional jump or move depends on uninitialised value(s) |
| 1755 |
==15380== at 0x80484EA: main (inlinfo.c:6) |
| 1756 |
==15380== |
| 1757 |
==15380== Conditional jump or move depends on uninitialised value(s) |
| 1758 |
==15380== at 0x8048550: fun_noninline (inlinfo.c:6) |
| 1759 |
==15380== by 0x804850E: main (inlinfo.c:34) |
| 1760 |
==15380== |
| 1761 |
==15380== Conditional jump or move depends on uninitialised value(s) |
| 1762 |
==15380== at 0x8048520: main (inlinfo.c:6) |
| 1763 |
</pre> |
| 1764 |
<p>And here are the same errors with |
| 1765 |
<code class="option">--read-inline-info=yes</code>:</p> |
| 1766 |
<pre class="programlisting"> |
| 1767 |
==15377== Conditional jump or move depends on uninitialised value(s) |
| 1768 |
==15377== at 0x80484EA: fun_d (inlinfo.c:6) |
| 1769 |
==15377== by 0x80484EA: fun_c (inlinfo.c:14) |
| 1770 |
==15377== by 0x80484EA: fun_b (inlinfo.c:20) |
| 1771 |
==15377== by 0x80484EA: fun_a (inlinfo.c:26) |
| 1772 |
==15377== by 0x80484EA: main (inlinfo.c:33) |
| 1773 |
==15377== |
| 1774 |
==15377== Conditional jump or move depends on uninitialised value(s) |
| 1775 |
==15377== at 0x8048550: fun_d (inlinfo.c:6) |
| 1776 |
==15377== by 0x8048550: fun_noninline (inlinfo.c:41) |
| 1777 |
==15377== by 0x804850E: main (inlinfo.c:34) |
| 1778 |
==15377== |
| 1779 |
==15377== Conditional jump or move depends on uninitialised value(s) |
| 1780 |
==15377== at 0x8048520: fun_d (inlinfo.c:6) |
| 1781 |
==15377== by 0x8048520: main (inlinfo.c:35) |
| 1782 |
</pre> |
| 1783 |
</dd> |
| 1784 |
<dt> |
| 1785 |
<a name="opt.read-var-info"></a><span class="term"> |
| 1786 |
<code class="option">--read-var-info=<yes|no> [default: no] </code> |
| 1787 |
</span> |
| 1788 |
</dt> |
| 1789 |
<dd> |
| 1790 |
<p>When enabled, Valgrind will read information about |
| 1791 |
variable types and locations from DWARF3 debug info. |
| 1792 |
This slows Valgrind startup significantly and makes it use significantly |
| 1793 |
more memory, but for the tools that can take advantage of it (Memcheck, |
| 1794 |
Helgrind, DRD) it can result in more precise error messages. For example, |
| 1795 |
here are some standard errors issued by Memcheck:</p> |
| 1796 |
<pre class="programlisting"> |
| 1797 |
==15363== Uninitialised byte(s) found during client check request |
| 1798 |
==15363== at 0x80484A9: croak (varinfo1.c:28) |
| 1799 |
==15363== by 0x8048544: main (varinfo1.c:55) |
| 1800 |
==15363== Address 0x80497f7 is 7 bytes inside data symbol "global_i2" |
| 1801 |
==15363== |
| 1802 |
==15363== Uninitialised byte(s) found during client check request |
| 1803 |
==15363== at 0x80484A9: croak (varinfo1.c:28) |
| 1804 |
==15363== by 0x8048550: main (varinfo1.c:56) |
| 1805 |
==15363== Address 0xbea0d0cc is on thread 1's stack |
| 1806 |
==15363== in frame #1, created by main (varinfo1.c:45) |
| 1807 |
</pre> |
| 1808 |
<p>And here are the same errors with |
| 1809 |
<code class="option">--read-var-info=yes</code>:</p> |
| 1810 |
<pre class="programlisting"> |
| 1811 |
==15370== Uninitialised byte(s) found during client check request |
| 1812 |
==15370== at 0x80484A9: croak (varinfo1.c:28) |
| 1813 |
==15370== by 0x8048544: main (varinfo1.c:55) |
| 1814 |
==15370== Location 0x80497f7 is 0 bytes inside global_i2[7], |
| 1815 |
==15370== a global variable declared at varinfo1.c:41 |
| 1816 |
==15370== |
| 1817 |
==15370== Uninitialised byte(s) found during client check request |
| 1818 |
==15370== at 0x80484A9: croak (varinfo1.c:28) |
| 1819 |
==15370== by 0x8048550: main (varinfo1.c:56) |
| 1820 |
==15370== Location 0xbeb4a0cc is 0 bytes inside local var "local" |
| 1821 |
==15370== declared at varinfo1.c:46, in frame #1 of thread 1 |
| 1822 |
</pre> |
| 1823 |
</dd> |
| 1824 |
<dt> |
| 1825 |
<a name="opt.vgdb-poll"></a><span class="term"> |
| 1826 |
<code class="option">--vgdb-poll=<number> [default: 5000] </code> |
| 1827 |
</span> |
| 1828 |
</dt> |
| 1829 |
<dd><p> As part of its main loop, the Valgrind scheduler will |
| 1830 |
poll to check if some activity (such as an external command or |
| 1831 |
some input from a gdb) has to be handled by gdbserver. This |
| 1832 |
activity poll will be done after having run the given number of |
| 1833 |
basic blocks (or slightly more than the given number of basic |
| 1834 |
blocks). This poll is quite cheap so the default value is set |
| 1835 |
relatively low. You might further decrease this value if vgdb |
| 1836 |
cannot use ptrace system call to interrupt Valgrind if all |
| 1837 |
threads are (most of the time) blocked in a system call. |
| 1838 |
</p></dd> |
| 1839 |
<dt> |
| 1840 |
<a name="opt.vgdb-shadow-registers"></a><span class="term"> |
| 1841 |
<code class="option">--vgdb-shadow-registers=no|yes [default: no] </code> |
| 1842 |
</span> |
| 1843 |
</dt> |
| 1844 |
<dd><p> When activated, gdbserver will expose the Valgrind shadow registers |
| 1845 |
to GDB. With this, the value of the Valgrind shadow registers can be examined |
| 1846 |
or changed using GDB. Exposing shadow registers only works with GDB version |
| 1847 |
7.1 or later. |
| 1848 |
</p></dd> |
| 1849 |
<dt> |
| 1850 |
<a name="opt.vgdb-prefix"></a><span class="term"> |
| 1851 |
<code class="option">--vgdb-prefix=<prefix> [default: /tmp/vgdb-pipe] </code> |
| 1852 |
</span> |
| 1853 |
</dt> |
| 1854 |
<dd><p> To communicate with gdb/vgdb, the Valgrind gdbserver |
| 1855 |
creates 3 files (2 named FIFOs and a mmap shared memory |
| 1856 |
file). The prefix option controls the directory and prefix for |
| 1857 |
the creation of these files. |
| 1858 |
</p></dd> |
| 1859 |
<dt> |
| 1860 |
<a name="opt.run-libc-freeres"></a><span class="term"> |
| 1861 |
<code class="option">--run-libc-freeres=<yes|no> [default: yes] </code> |
| 1862 |
</span> |
| 1863 |
</dt> |
| 1864 |
<dd> |
| 1865 |
<p>This option is only relevant when running Valgrind on Linux with |
| 1866 |
GNU libc.</p> |
| 1867 |
<p>The GNU C library (<code class="function">libc.so</code>), which is |
| 1868 |
used by all programs, may allocate memory for its own uses. |
| 1869 |
Usually it doesn't bother to free that memory when the program |
| 1870 |
ends—there would be no point, since the Linux kernel reclaims |
| 1871 |
all process resources when a process exits anyway, so it would |
| 1872 |
just slow things down.</p> |
| 1873 |
<p>The glibc authors realised that this behaviour causes leak |
| 1874 |
checkers, such as Valgrind, to falsely report leaks in glibc, when |
| 1875 |
a leak check is done at exit. In order to avoid this, they |
| 1876 |
provided a routine called <code class="function">__libc_freeres</code> |
| 1877 |
specifically to make glibc release all memory it has allocated. |
| 1878 |
Memcheck therefore tries to run |
| 1879 |
<code class="function">__libc_freeres</code> at exit.</p> |
| 1880 |
<p>Unfortunately, in some very old versions of glibc, |
| 1881 |
<code class="function">__libc_freeres</code> is sufficiently buggy to cause |
| 1882 |
segmentation faults. This was particularly noticeable on Red Hat |
| 1883 |
7.1. So this option is provided in order to inhibit the run of |
| 1884 |
<code class="function">__libc_freeres</code>. If your program seems to run |
| 1885 |
fine on Valgrind, but segfaults at exit, you may find that |
| 1886 |
<code class="option">--run-libc-freeres=no</code> fixes that, although at the |
| 1887 |
cost of possibly falsely reporting space leaks in |
| 1888 |
<code class="filename">libc.so</code>.</p> |
| 1889 |
</dd> |
| 1890 |
<dt> |
| 1891 |
<a name="opt.run-cxx-freeres"></a><span class="term"> |
| 1892 |
<code class="option">--run-cxx-freeres=<yes|no> [default: yes] </code> |
| 1893 |
</span> |
| 1894 |
</dt> |
| 1895 |
<dd> |
| 1896 |
<p>This option is only relevant when running Valgrind on Linux, |
| 1897 |
FreeBSD or Solaris C++ programs using libstdc++.</p> |
| 1898 |
<p>The GNU Standard C++ library (<code class="function">libstdc++.so</code>), |
| 1899 |
which is used by all C++ programs compiled with g++, may allocate memory |
| 1900 |
for its own uses. Usually it doesn't bother to free that memory when |
| 1901 |
the program ends—there would be no point, since the kernel reclaims |
| 1902 |
all process resources when a process exits anyway, so it would |
| 1903 |
just slow things down.</p> |
| 1904 |
<p>The gcc authors realised that this behaviour causes leak |
| 1905 |
checkers, such as Valgrind, to falsely report leaks in libstdc++, when |
| 1906 |
a leak check is done at exit. In order to avoid this, they |
| 1907 |
provided a routine called <code class="function">__gnu_cxx::__freeres</code> |
| 1908 |
specifically to make libstdc++ release all memory it has allocated. |
| 1909 |
Memcheck therefore tries to run |
| 1910 |
<code class="function">__gnu_cxx::__freeres</code> at exit.</p> |
| 1911 |
<p>For the sake of flexibility and unforeseen problems with |
| 1912 |
<code class="function">__gnu_cxx::__freeres</code>, option |
| 1913 |
<code class="option">--run-cxx-freeres=no</code> exists, |
| 1914 |
although at the cost of possibly falsely reporting space leaks in |
| 1915 |
<code class="filename">libstdc++.so</code>.</p> |
| 1916 |
</dd> |
| 1917 |
<dt> |
| 1918 |
<a name="opt.sim-hints"></a><span class="term"> |
| 1919 |
<code class="option">--sim-hints=hint1,hint2,... </code> |
| 1920 |
</span> |
| 1921 |
</dt> |
| 1922 |
<dd> |
| 1923 |
<p>Pass miscellaneous hints to Valgrind which slightly modify |
| 1924 |
the simulated behaviour in nonstandard or dangerous ways, possibly |
| 1925 |
to help the simulation of strange features. By default no hints |
| 1926 |
are enabled. Use with caution! Currently known hints are:</p> |
| 1927 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 1928 |
<li class="listitem"><p><code class="option">lax-ioctls: </code> Be very lax about ioctl |
| 1929 |
handling; the only assumption is that the size is |
| 1930 |
correct. Doesn't require the full buffer to be initialised |
| 1931 |
when writing. Without this, using some device drivers with a |
| 1932 |
large number of strange ioctl commands becomes very |
| 1933 |
tiresome.</p></li> |
| 1934 |
<li class="listitem"><p><code class="option">fuse-compatible: </code> Enable special |
| 1935 |
handling for certain system calls that may block in a FUSE |
| 1936 |
file-system. This may be necessary when running Valgrind |
| 1937 |
on a multi-threaded program that uses one thread to manage |
| 1938 |
a FUSE file-system and another thread to access that |
| 1939 |
file-system. |
| 1940 |
</p></li> |
| 1941 |
<li class="listitem"><p><code class="option">enable-outer: </code> Enable some special |
| 1942 |
magic needed when the program being run is itself |
| 1943 |
Valgrind.</p></li> |
| 1944 |
<li class="listitem"><p><code class="option">no-inner-prefix: </code> Disable printing |
| 1945 |
a prefix <code class="option">></code> in front of each stdout or |
| 1946 |
stderr output line in an inner Valgrind being run by an |
| 1947 |
outer Valgrind. This is useful when running Valgrind |
| 1948 |
regression tests in an outer/inner setup. Note that the |
| 1949 |
prefix <code class="option">></code> will always be printed in |
| 1950 |
front of the inner debug logging lines.</p></li> |
| 1951 |
<li class="listitem"> |
| 1952 |
<p><code class="option">no-nptl-pthread-stackcache: </code> |
| 1953 |
This hint is only relevant when running Valgrind on Linux; |
| 1954 |
it is ignored on FreeBSD, Solaris and macOS.</p> |
| 1955 |
<p>The GNU glibc pthread library |
| 1956 |
(<code class="function">libpthread.so</code>), which is used by |
| 1957 |
pthread programs, maintains a cache of pthread stacks. |
| 1958 |
When a pthread terminates, the memory used for the pthread |
| 1959 |
stack and some thread local storage related data structure |
| 1960 |
are not always directly released. This memory is kept in |
| 1961 |
a cache (up to a certain size), and is re-used if a new |
| 1962 |
thread is started.</p> |
| 1963 |
<p>This cache causes the helgrind tool to report some |
| 1964 |
false positive race condition errors on this cached |
| 1965 |
memory, as helgrind does not understand the internal glibc |
| 1966 |
cache synchronisation primitives. So, when using helgrind, |
| 1967 |
disabling the cache helps to avoid false positive race |
| 1968 |
conditions, in particular when using thread local storage |
| 1969 |
variables (e.g. variables using the |
| 1970 |
<code class="function">__thread</code> qualifier).</p> |
| 1971 |
<p>When using the memcheck tool, disabling the cache |
| 1972 |
ensures the memory used by glibc to handle __thread |
| 1973 |
variables is directly released when a thread |
| 1974 |
terminates.</p> |
| 1975 |
<p>Note: Valgrind disables the cache using some internal |
| 1976 |
knowledge of the glibc stack cache implementation and by |
| 1977 |
examining the debug information of the pthread |
| 1978 |
library. This technique is thus somewhat fragile and might |
| 1979 |
not work for all glibc versions. This has been successfully |
| 1980 |
tested with various glibc versions (e.g. 2.11, 2.16, 2.18) |
| 1981 |
on various platforms.</p> |
| 1982 |
</li> |
| 1983 |
<li class="listitem"><p><code class="option">lax-doors: </code> (Solaris only) Be very lax |
| 1984 |
about door syscall handling over unrecognised door file |
| 1985 |
descriptors. Does not require that full buffer is initialised |
| 1986 |
when writing. Without this, programs using libdoor(3LIB) |
| 1987 |
functionality with completely proprietary semantics may report |
| 1988 |
large number of false positives.</p></li> |
| 1989 |
<li class="listitem"><p><code class="option">fallback-llsc: </code>(MIPS and ARM64 only): Enables |
| 1990 |
an alternative implementation of Load-Linked (LL) and |
| 1991 |
Store-Conditional (SC) instructions. The standard implementation |
| 1992 |
gives more correct behaviour, but can cause indefinite looping on |
| 1993 |
certain processor implementations that are intolerant of extra |
| 1994 |
memory references between LL and SC. So far this is known only to |
| 1995 |
happen on Cavium 3 cores. |
| 1996 |
|
| 1997 |
You should not need to use this flag, since the relevant cores are |
| 1998 |
detected at startup and the alternative implementation is |
| 1999 |
automatically enabled if necessary. There is no equivalent |
| 2000 |
anti-flag: you cannot force-disable the alternative |
| 2001 |
implementation, if it is automatically enabled. |
| 2002 |
|
| 2003 |
The underlying problem exists because the "standard" |
| 2004 |
implementation of LL and SC is done by copying through LL and SC |
| 2005 |
instructions into the instrumented code. However, tools may |
| 2006 |
insert extra instrumentation memory references in between the LL |
| 2007 |
and SC instructions. These memory references are not present in |
| 2008 |
the original uninstrumented code, and their presence in the |
| 2009 |
instrumented code can cause the SC instructions to persistently |
| 2010 |
fail, leading to indefinite looping in LL-SC blocks. |
| 2011 |
|
| 2012 |
The alternative implementation gives correct behaviour of LL and |
| 2013 |
SC instructions between threads in a process, up to and including |
| 2014 |
the ABA scenario. It also gives correct behaviour between a |
| 2015 |
Valgrinded thread and a non-Valgrinded thread running in a |
| 2016 |
different process, that communicate via shared memory, but only up |
| 2017 |
to and including correct CAS behaviour -- in this case the ABA |
| 2018 |
scenario may not be correctly handled. |
| 2019 |
</p></li> |
| 2020 |
</ul></div> |
| 2021 |
</dd> |
| 2022 |
<dt> |
| 2023 |
<a name="opt.scheduling-quantum"></a><span class="term"> |
| 2024 |
<code class="option">--scheduling-quantum=<number> [default: 100000] </code> |
| 2025 |
</span> |
| 2026 |
</dt> |
| 2027 |
<dd><p>The <code class="option">--scheduling-quantum</code> option controls |
| 2028 |
the maximum number of basic blocks executed by a thread before releasing |
| 2029 |
the lock used by Valgrind to serialise thread execution. Smaller values |
| 2030 |
give finer interleaving but increases the scheduling overhead. Finer |
| 2031 |
interleaving can be useful to reproduce race conditions with helgrind or |
| 2032 |
DRD. For more details about the Valgrind thread serialisation scheme and |
| 2033 |
its impact on performance and thread scheduling, see |
| 2034 |
<a class="xref" href="manual-core.html#manual-core.pthreads_perf_sched" title="2.8.1. Scheduling and Multi-Thread Performance">Scheduling and Multi-Thread Performance</a>. |
| 2035 |
</p></dd> |
| 2036 |
<dt> |
| 2037 |
<a name="opt.fair-sched"></a><span class="term"> |
| 2038 |
<code class="option">--fair-sched=<no|yes|try> [default: no] </code> |
| 2039 |
</span> |
| 2040 |
</dt> |
| 2041 |
<dd> |
| 2042 |
<p>The <code class="option">--fair-sched</code> option controls |
| 2043 |
the locking mechanism used by Valgrind to serialise thread |
| 2044 |
execution. The locking mechanism controls the way the threads |
| 2045 |
are scheduled, and different settings give different trade-offs |
| 2046 |
between fairness and performance. For more details about the |
| 2047 |
Valgrind thread serialisation scheme and its impact on |
| 2048 |
performance and thread scheduling, see |
| 2049 |
<a class="xref" href="manual-core.html#manual-core.pthreads_perf_sched" title="2.8.1. Scheduling and Multi-Thread Performance">Scheduling and Multi-Thread Performance</a>.</p> |
| 2050 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 2051 |
<li class="listitem"> |
| 2052 |
<p>The value <code class="option">--fair-sched=yes</code> |
| 2053 |
activates a fair scheduler. In short, if multiple threads are |
| 2054 |
ready to run, the threads will be scheduled in a round robin |
| 2055 |
fashion. This mechanism is not available on all platforms or |
| 2056 |
Linux versions. If not available, |
| 2057 |
using <code class="option">--fair-sched=yes</code> will cause Valgrind to |
| 2058 |
terminate with an error.</p> |
| 2059 |
<p>You may find this setting improves overall |
| 2060 |
responsiveness if you are running an interactive |
| 2061 |
multithreaded program, for example a web browser, on |
| 2062 |
Valgrind.</p> |
| 2063 |
</li> |
| 2064 |
<li class="listitem"><p>The value <code class="option">--fair-sched=try</code> |
| 2065 |
activates fair scheduling if available on the |
| 2066 |
platform. Otherwise, it will automatically fall back |
| 2067 |
to <code class="option">--fair-sched=no</code>.</p></li> |
| 2068 |
<li class="listitem"><p>The value <code class="option">--fair-sched=no</code> activates |
| 2069 |
a scheduler which does not guarantee fairness |
| 2070 |
between threads ready to run, but which in general gives the |
| 2071 |
highest performance.</p></li> |
| 2072 |
</ul></div> |
| 2073 |
</dd> |
| 2074 |
<dt> |
| 2075 |
<a name="opt.kernel-variant"></a><span class="term"> |
| 2076 |
<code class="option">--kernel-variant=variant1,variant2,...</code> |
| 2077 |
</span> |
| 2078 |
</dt> |
| 2079 |
<dd> |
| 2080 |
<p>Handle system calls and ioctls arising from minor variants |
| 2081 |
of the default kernel for this platform. This is useful for |
| 2082 |
running on hacked kernels or with kernel modules which support |
| 2083 |
nonstandard ioctls, for example. Use with caution. If you don't |
| 2084 |
understand what this option does then you almost certainly don't |
| 2085 |
need it. Currently known variants are:</p> |
| 2086 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 2087 |
<li class="listitem"><p><code class="option">bproc</code>: support the |
| 2088 |
<code class="function">sys_broc</code> system call on x86. This is for |
| 2089 |
running on BProc, which is a minor variant of standard Linux which |
| 2090 |
is sometimes used for building clusters. |
| 2091 |
</p></li> |
| 2092 |
<li class="listitem"><p><code class="option">android-no-hw-tls</code>: some |
| 2093 |
versions of the Android emulator for ARM do not provide a |
| 2094 |
hardware TLS (thread-local state) register, and Valgrind |
| 2095 |
crashes at startup. Use this variant to select software |
| 2096 |
support for TLS. |
| 2097 |
</p></li> |
| 2098 |
<li class="listitem"><p><code class="option">android-gpu-sgx5xx</code>: use this to |
| 2099 |
support handling of proprietary ioctls for the PowerVR SGX |
| 2100 |
5XX series of GPUs on Android devices. Failure to select |
| 2101 |
this does not cause stability problems, but may cause |
| 2102 |
Memcheck to report false errors after the program performs |
| 2103 |
GPU-specific ioctls. |
| 2104 |
</p></li> |
| 2105 |
<li class="listitem"><p><code class="option">android-gpu-adreno3xx</code>: similarly, use |
| 2106 |
this to support handling of proprietary ioctls for the |
| 2107 |
Qualcomm Adreno 3XX series of GPUs on Android devices. |
| 2108 |
</p></li> |
| 2109 |
</ul></div> |
| 2110 |
</dd> |
| 2111 |
<dt> |
| 2112 |
<a name="opt.merge-recursive-frames"></a><span class="term"> |
| 2113 |
<code class="option">--merge-recursive-frames=<number> [default: 0] </code> |
| 2114 |
</span> |
| 2115 |
</dt> |
| 2116 |
<dd> |
| 2117 |
<p>Some recursive algorithms, for example balanced binary |
| 2118 |
tree implementations, create many different stack traces, each |
| 2119 |
containing cycles of calls. A cycle is defined as two identical |
| 2120 |
program counter values separated by zero or more other program |
| 2121 |
counter values. Valgrind may then use a lot of memory to store |
| 2122 |
all these stack traces. This is a poor use of memory |
| 2123 |
considering that such stack traces contain repeated |
| 2124 |
uninteresting recursive calls instead of more interesting |
| 2125 |
information such as the function that has initiated the |
| 2126 |
recursive call. |
| 2127 |
</p> |
| 2128 |
<p>The option <code class="option">--merge-recursive-frames=<number></code> |
| 2129 |
instructs Valgrind to detect and merge recursive call cycles |
| 2130 |
having a size of up to <code class="option"><number></code> |
| 2131 |
frames. When such a cycle is detected, Valgrind records the |
| 2132 |
cycle in the stack trace as a unique program counter. |
| 2133 |
</p> |
| 2134 |
<p> |
| 2135 |
The value 0 (the default) causes no recursive call merging. |
| 2136 |
A value of 1 will cause stack traces of simple recursive algorithms |
| 2137 |
(for example, a factorial implementation) to be collapsed. |
| 2138 |
A value of 2 will usually be needed to collapse stack traces produced |
| 2139 |
by recursive algorithms such as binary trees, quick sort, etc. |
| 2140 |
Higher values might be needed for more complex recursive algorithms. |
| 2141 |
</p> |
| 2142 |
<p>Note: recursive calls are detected by analysis of program |
| 2143 |
counter values. They are not detected by looking at function |
| 2144 |
names.</p> |
| 2145 |
</dd> |
| 2146 |
<dt> |
| 2147 |
<a name="opt.num-transtab-sectors"></a><span class="term"> |
| 2148 |
<code class="option">--num-transtab-sectors=<number> [default: 6 |
| 2149 |
for Android platforms, 16 for all others] </code> |
| 2150 |
</span> |
| 2151 |
</dt> |
| 2152 |
<dd><p>Valgrind translates and instruments your program's machine |
| 2153 |
code in small fragments (basic blocks). The translations are stored in a |
| 2154 |
translation cache that is divided into a number of sections |
| 2155 |
(sectors). If the cache is full, the sector containing the |
| 2156 |
oldest translations is emptied and reused. If these old |
| 2157 |
translations are needed again, Valgrind must re-translate and |
| 2158 |
re-instrument the corresponding machine code, which is |
| 2159 |
expensive. If the "executed instructions" working set of a |
| 2160 |
program is big, increasing the number of sectors may improve |
| 2161 |
performance by reducing the number of re-translations needed. |
| 2162 |
Sectors are allocated on demand. Once allocated, a sector can |
| 2163 |
never be freed, and occupies considerable space, depending on the tool |
| 2164 |
and the value of <code class="option">--avg-transtab-entry-size</code> |
| 2165 |
(about 40 MB per sector for Memcheck). Use the |
| 2166 |
option <code class="option">--stats=yes</code> to obtain precise |
| 2167 |
information about the memory used by a sector and the allocation |
| 2168 |
and recycling of sectors.</p></dd> |
| 2169 |
<dt> |
| 2170 |
<a name="opt.avg-transtab-entry-size"></a><span class="term"> |
| 2171 |
<code class="option">--avg-transtab-entry-size=<number> [default: 0, |
| 2172 |
meaning use tool provided default] </code> |
| 2173 |
</span> |
| 2174 |
</dt> |
| 2175 |
<dd><p>Average size of translated basic block. This average size |
| 2176 |
is used to dimension the size of a sector. |
| 2177 |
Each tool provides a default value to be used. |
| 2178 |
If this default value is too small, the translation sectors |
| 2179 |
will become full too quickly. If this default value is too big, |
| 2180 |
a significant part of the translation sector memory will be unused. |
| 2181 |
Note that the average size of a basic block translation depends |
| 2182 |
on the tool, and might depend on tool options. For example, |
| 2183 |
the memcheck option <code class="option">--track-origins=yes</code> |
| 2184 |
increases the size of the basic block translations. |
| 2185 |
Use <code class="option">--avg-transtab-entry-size</code> to tune the size of the |
| 2186 |
sectors, either to gain memory or to avoid too many retranslations. |
| 2187 |
</p></dd> |
| 2188 |
<dt> |
| 2189 |
<a name="opt.aspace-minaddr"></a><span class="term"> |
| 2190 |
<code class="option">--aspace-minaddr=<address> [default: depends |
| 2191 |
on the platform] </code> |
| 2192 |
</span> |
| 2193 |
</dt> |
| 2194 |
<dd><p>To avoid potential conflicts with some system libraries, |
| 2195 |
Valgrind does not use the address space |
| 2196 |
below <code class="option">--aspace-minaddr</code> value, keeping it |
| 2197 |
reserved in case a library specifically requests memory in this |
| 2198 |
region. So, some "pessimistic" value is guessed by Valgrind |
| 2199 |
depending on the platform. On linux, by default, Valgrind avoids |
| 2200 |
using the first 64MB even if typically there is no conflict in |
| 2201 |
this complete zone. You can use the |
| 2202 |
option <code class="option">--aspace-minaddr</code> to have your memory |
| 2203 |
hungry application benefitting from more of this lower memory. |
| 2204 |
On the other hand, if you encounter a conflict, increasing |
| 2205 |
aspace-minaddr value might solve it. Conflicts will typically |
| 2206 |
manifest themselves with mmap failures in the low range of the |
| 2207 |
address space. The |
| 2208 |
provided <code class="computeroutput">address</code> must be page |
| 2209 |
aligned and must be equal or bigger to 0x1000 (4KB). To find the |
| 2210 |
default value on your platform, do something such as |
| 2211 |
<code class="computeroutput">valgrind -d -d date 2>&1 | grep -i minaddr</code>. |
| 2212 |
Values lower than 0x10000 (64KB) are known to create problems |
| 2213 |
on some distributions. |
| 2214 |
</p></dd> |
| 2215 |
<dt> |
| 2216 |
<a name="opt.valgrind-stacksize"></a><span class="term"> |
| 2217 |
<code class="option">--valgrind-stacksize=<number> [default: 1MB] </code> |
| 2218 |
</span> |
| 2219 |
</dt> |
| 2220 |
<dd> |
| 2221 |
<p>For each thread, Valgrind needs its own 'private' stack. |
| 2222 |
The default size for these stacks is largely dimensioned, and so |
| 2223 |
should be sufficient in most cases. In case the size is too small, |
| 2224 |
Valgrind will segfault. Before segfaulting, a warning might be produced |
| 2225 |
by Valgrind when approaching the limit. |
| 2226 |
</p> |
| 2227 |
<p> |
| 2228 |
Use the option <code class="option">--valgrind-stacksize</code> if such an (unlikely) |
| 2229 |
warning is produced, or Valgrind dies due to a segmentation violation. |
| 2230 |
Such segmentation violations have been seen when demangling huge C++ |
| 2231 |
symbols. |
| 2232 |
</p> |
| 2233 |
<p>If your application uses many threads and needs a lot of memory, you can |
| 2234 |
gain some memory by reducing the size of these Valgrind stacks using |
| 2235 |
the option <code class="option">--valgrind-stacksize</code>. |
| 2236 |
</p> |
| 2237 |
</dd> |
| 2238 |
<dt> |
| 2239 |
<a name="opt.show-emwarns"></a><span class="term"> |
| 2240 |
<code class="option">--show-emwarns=<yes|no> [default: no] </code> |
| 2241 |
</span> |
| 2242 |
</dt> |
| 2243 |
<dd><p>When enabled, Valgrind will emit warnings about its CPU |
| 2244 |
emulation in certain cases. These are usually not |
| 2245 |
interesting.</p></dd> |
| 2246 |
<dt> |
| 2247 |
<a name="opt.require-text-symbol"></a><span class="term"> |
| 2248 |
<code class="option">--require-text-symbol=:sonamepatt:fnnamepatt</code> |
| 2249 |
</span> |
| 2250 |
</dt> |
| 2251 |
<dd> |
| 2252 |
<p>When a shared object whose soname |
| 2253 |
matches <code class="varname">sonamepatt</code> is loaded into the |
| 2254 |
process, examine all the text symbols it exports. If none of |
| 2255 |
those match <code class="varname">fnnamepatt</code>, print an error |
| 2256 |
message and abandon the run. This makes it possible to ensure |
| 2257 |
that the run does not continue unless a given shared object |
| 2258 |
contains a particular function name. |
| 2259 |
</p> |
| 2260 |
<p> |
| 2261 |
Both <code class="varname">sonamepatt</code> and |
| 2262 |
<code class="varname">fnnamepatt</code> can be written using the usual |
| 2263 |
<code class="varname">?</code> and <code class="varname">*</code> wildcards. For |
| 2264 |
example: <code class="varname">":*libc.so*:foo?bar"</code>. You may use |
| 2265 |
characters other than a colon to separate the two patterns. It |
| 2266 |
is only important that the first character and the separator |
| 2267 |
character are the same. For example, the above example could |
| 2268 |
also be written <code class="varname">"Q*libc.so*Qfoo?bar"</code>. |
| 2269 |
Multiple <code class="varname"> --require-text-symbol</code> flags are |
| 2270 |
allowed, in which case shared objects that are loaded into |
| 2271 |
the process will be checked against all of them. |
| 2272 |
</p> |
| 2273 |
<p> |
| 2274 |
The purpose of this is to support reliable usage of marked-up |
| 2275 |
libraries. For example, suppose we have a version of GCC's |
| 2276 |
<code class="varname">libgomp.so</code> which has been marked up with |
| 2277 |
annotations to support Helgrind. It is only too easy and |
| 2278 |
confusing to load the wrong, un-annotated |
| 2279 |
<code class="varname">libgomp.so</code> into the application. So the idea |
| 2280 |
is: add a text symbol in the marked-up library, for |
| 2281 |
example <code class="varname">annotated_for_helgrind_3_6</code>, and then |
| 2282 |
give the flag |
| 2283 |
<code class="varname">--require-text-symbol=:*libgomp*so*:annotated_for_helgrind_3_6</code> |
| 2284 |
so that when <code class="varname">libgomp.so</code> is loaded, Valgrind |
| 2285 |
scans its symbol table, and if the symbol isn't present the run |
| 2286 |
is aborted, rather than continuing silently with the |
| 2287 |
un-marked-up library. Note that you should put the entire flag |
| 2288 |
in quotes to stop shells expanding up the <code class="varname">*</code> |
| 2289 |
and <code class="varname">?</code> wildcards. |
| 2290 |
</p> |
| 2291 |
</dd> |
| 2292 |
<dt> |
| 2293 |
<a name="opt.soname-synonyms"></a><span class="term"> |
| 2294 |
<code class="option">--soname-synonyms=syn1=pattern1,syn2=pattern2,...</code> |
| 2295 |
</span> |
| 2296 |
</dt> |
| 2297 |
<dd> |
| 2298 |
<p>When a shared library is loaded, Valgrind checks for |
| 2299 |
functions in the library that must be replaced or wrapped. For |
| 2300 |
example, Memcheck replaces some string and memory functions |
| 2301 |
(strchr, strlen, strcpy, memchr, memcpy, memmove, etc.) with its |
| 2302 |
own versions. Such replacements are normally done only in shared |
| 2303 |
libraries whose soname matches a predefined soname pattern (e.g. |
| 2304 |
<code class="varname">libc.so*</code> on linux). By default, no |
| 2305 |
replacement is done for a statically linked binary or for |
| 2306 |
alternative libraries, except for the allocation functions |
| 2307 |
(malloc, free, calloc, memalign, realloc, operator new, operator |
| 2308 |
delete, etc.) Such allocation functions are intercepted by |
| 2309 |
default in any shared library or in the executable if they are |
| 2310 |
exported as global symbols. This means that if a replacement |
| 2311 |
allocation library such as tcmalloc is found, its functions are |
| 2312 |
also intercepted by default. |
| 2313 |
|
| 2314 |
In some cases, the replacements allow |
| 2315 |
<code class="option">--soname-synonyms</code> to specify one additional |
| 2316 |
synonym pattern, giving flexibility in the replacement. Or to |
| 2317 |
prevent interception of all public allocation symbols.</p> |
| 2318 |
<p>Currently, this flexibility is only allowed for the |
| 2319 |
malloc related functions, using the |
| 2320 |
synonym <code class="varname">somalloc</code>. This synonym is usable for |
| 2321 |
all tools doing standard replacement of malloc related functions |
| 2322 |
(e.g. memcheck, helgrind, drd, massif, dhat). |
| 2323 |
</p> |
| 2324 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 2325 |
<li class="listitem"> |
| 2326 |
<p>Alternate malloc library: to replace the malloc |
| 2327 |
related functions in a specific alternate library with |
| 2328 |
soname <code class="varname">mymalloclib.so</code> (and not in any |
| 2329 |
others), give the |
| 2330 |
option <code class="option">--soname-synonyms=somalloc=mymalloclib.so</code>. |
| 2331 |
A pattern can be used to match multiple libraries sonames. |
| 2332 |
For |
| 2333 |
example, <code class="option">--soname-synonyms=somalloc=*tcmalloc*</code> |
| 2334 |
will match the soname of all variants of the tcmalloc |
| 2335 |
library (native, debug, profiled, ... tcmalloc |
| 2336 |
variants). </p> |
| 2337 |
<p>Note: the soname of a elf shared library can be |
| 2338 |
retrieved using the readelf utility. </p> |
| 2339 |
</li> |
| 2340 |
<li class="listitem"><p>Replacements in a statically linked library are done |
| 2341 |
by using the <code class="varname">NONE</code> pattern. For example, |
| 2342 |
if you link with <code class="varname">libtcmalloc.a</code>, and only |
| 2343 |
want to intercept the malloc related functions in the |
| 2344 |
executable (and standard libraries) themselves, but not any |
| 2345 |
other shared libraries, you can give the |
| 2346 |
option <code class="option">--soname-synonyms=somalloc=NONE</code>. |
| 2347 |
Note that a NONE pattern will match the main executable and |
| 2348 |
any shared library having no soname. </p></li> |
| 2349 |
<li class="listitem"><p>To only intercept allocation symbols in the default |
| 2350 |
system libraries, but not in any other shared library or the |
| 2351 |
executable defining public malloc or operator new related |
| 2352 |
functions use a non-existing library name |
| 2353 |
like <code class="option">--soname-synonyms=somalloc=nouserintercepts</code> |
| 2354 |
(where <code class="varname">nouserintercepts</code> can be any |
| 2355 |
non-existing library name). |
| 2356 |
</p></li> |
| 2357 |
<li class="listitem"><p>Shared library of the dynamic (runtime) linker is excluded from |
| 2358 |
searching for global public symbols, such as those for the malloc |
| 2359 |
related functions (identified by <code class="varname">somalloc</code> synonym). |
| 2360 |
</p></li> |
| 2361 |
</ul></div> |
| 2362 |
</dd> |
| 2363 |
<dt> |
| 2364 |
<a name="opt.progress-interval"></a><span class="term"> |
| 2365 |
<code class="option">--progress-interval=<number> [default: 0, meaning 'disabled'] </code> |
| 2366 |
</span> |
| 2367 |
</dt> |
| 2368 |
<dd> |
| 2369 |
<p>This is an enhancement to Valgrind's debugging output. It is |
| 2370 |
unlikely to be of interest to end users.</p> |
| 2371 |
<p>When <code class="varname">number</code> is set to a non-zero value, |
| 2372 |
Valgrind will print a one-line progress summary |
| 2373 |
every <code class="varname">number</code> seconds. Valid settings |
| 2374 |
for <code class="varname">number</code> are between 0 and 3600 |
| 2375 |
inclusive. Here's some example output |
| 2376 |
with <code class="varname">number</code> |
| 2377 |
set to 10: |
| 2378 |
</p> |
| 2379 |
<pre class="programlisting"> |
| 2380 |
PROGRESS: U 110s, W 113s, 97.3% CPU, EvC 414.79M, TIn 616.7k, TOut 0.5k, #thr 67 |
| 2381 |
PROGRESS: U 120s, W 124s, 96.8% CPU, EvC 505.27M, TIn 636.6k, TOut 3.0k, #thr 64 |
| 2382 |
PROGRESS: U 130s, W 134s, 97.0% CPU, EvC 574.90M, TIn 657.5k, TOut 3.0k, #thr 63 |
| 2383 |
</pre> |
| 2384 |
<p> |
| 2385 |
Each line shows: |
| 2386 |
</p> |
| 2387 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 2388 |
<li class="listitem"><p><code class="varname">U</code>: total user time</p></li> |
| 2389 |
<li class="listitem"><p><code class="varname">W</code>: total wallclock time</p></li> |
| 2390 |
<li class="listitem"><p><code class="varname">CPU</code>: overall average cpu use</p></li> |
| 2391 |
<li class="listitem"><p><code class="varname">EvC</code>: number of event checks. An event |
| 2392 |
check is a backwards branch in the simulated program, so this is a |
| 2393 |
measure of forward progress of the program</p></li> |
| 2394 |
<li class="listitem"><p><code class="varname">TIn</code>: number of code blocks instrumented |
| 2395 |
by the JIT</p></li> |
| 2396 |
<li class="listitem"><p><code class="varname">TOut</code>: number of instrumented code |
| 2397 |
blocks that have been thrown away</p></li> |
| 2398 |
<li class="listitem"><p><code class="varname">#thr</code>: number of threads in the |
| 2399 |
program</p></li> |
| 2400 |
</ul></div> |
| 2401 |
<p> |
| 2402 |
From the progress of these, it is possible to observe: |
| 2403 |
</p> |
| 2404 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 2405 |
<li class="listitem"><p>when the program is compute bound (<code class="varname">TIn</code> |
| 2406 |
rises slowly, <code class="varname">EvC</code> rises rapidly)</p></li> |
| 2407 |
<li class="listitem"><p>when the program is in a spinloop |
| 2408 |
(<code class="varname">TIn</code>/<code class="varname">TOut</code> |
| 2409 |
fixed, <code class="varname">EvC</code> rises rapidly)</p></li> |
| 2410 |
<li class="listitem"><p>when the program is JIT-bound (<code class="varname">TIn</code> |
| 2411 |
rises rapidly)</p></li> |
| 2412 |
<li class="listitem"><p>when the program is rapidly discarding code |
| 2413 |
(<code class="varname">TOut</code> rises rapidly)</p></li> |
| 2414 |
<li class="listitem"><p>when the program is about to achieve some expected state |
| 2415 |
(<code class="varname">EvC</code> arrives at some value you |
| 2416 |
expect)</p></li> |
| 2417 |
<li class="listitem"><p> when the program is idling (<code class="varname">U</code> rises |
| 2418 |
more slowly than <code class="varname">W</code>)</p></li> |
| 2419 |
</ul></div> |
| 2420 |
<p> |
| 2421 |
</p> |
| 2422 |
</dd> |
| 2423 |
</dl> |
| 2424 |
</div> |
| 2425 |
</div> |
| 2426 |
<div class="sect2"> |
| 2427 |
<div class="titlepage"><div><div><h3 class="title"> |
| 2428 |
<a name="manual-core.debugopts"></a>2.7.6. Debugging Options</h3></div></div></div> |
| 2429 |
<p><a name="debug.opts.para"></a>There are also some options for debugging |
| 2430 |
Valgrind itself. You shouldn't need to use them in the normal run of |
| 2431 |
things. If you wish to see the list, use the |
| 2432 |
<code class="option">--help-debug</code> option.</p> |
| 2433 |
<p>If you wish to debug your program rather than debugging |
| 2434 |
Valgrind itself, then you should use the options |
| 2435 |
<code class="option">--vgdb=yes</code> or <code class="option">--vgdb=full</code>. |
| 2436 |
</p> |
| 2437 |
</div> |
| 2438 |
<div class="sect2"> |
| 2439 |
<div class="titlepage"><div><div><h3 class="title"> |
| 2440 |
<a name="manual-core.defopts"></a>2.7.7. Setting Default Options</h3></div></div></div> |
| 2441 |
<p>Note that Valgrind also reads options from three places:</p> |
| 2442 |
<div class="orderedlist"><ol class="orderedlist" type="1"> |
| 2443 |
<li class="listitem"><p>The file <code class="computeroutput">~/.valgrindrc</code></p></li> |
| 2444 |
<li class="listitem"><p>The environment variable |
| 2445 |
<code class="computeroutput">$VALGRIND_OPTS</code></p></li> |
| 2446 |
<li class="listitem"><p>The file <code class="computeroutput">./.valgrindrc</code></p></li> |
| 2447 |
</ol></div> |
| 2448 |
<p>These are processed in the given order, before the |
| 2449 |
command-line options. Options processed later override those |
| 2450 |
processed earlier; for example, options in |
| 2451 |
<code class="computeroutput">./.valgrindrc</code> will take |
| 2452 |
precedence over those in |
| 2453 |
<code class="computeroutput">~/.valgrindrc</code>. |
| 2454 |
</p> |
| 2455 |
<p>Please note that the <code class="computeroutput">./.valgrindrc</code> |
| 2456 |
file is ignored if it is not a regular file, or is marked as world writeable, |
| 2457 |
or is not owned by the current user. This is because the |
| 2458 |
<code class="computeroutput">./.valgrindrc</code> can contain options that are |
| 2459 |
potentially harmful or can be used by a local attacker to execute code under |
| 2460 |
your user account. |
| 2461 |
</p> |
| 2462 |
<p>Any tool-specific options put in |
| 2463 |
<code class="computeroutput">$VALGRIND_OPTS</code> or the |
| 2464 |
<code class="computeroutput">.valgrindrc</code> files should be |
| 2465 |
prefixed with the tool name and a colon. For example, if you |
| 2466 |
want Memcheck to always do leak checking, you can put the |
| 2467 |
following entry in <code class="literal">~/.valgrindrc</code>:</p> |
| 2468 |
<pre class="programlisting"> |
| 2469 |
--memcheck:leak-check=yes</pre> |
| 2470 |
<p>This will be ignored if any tool other than Memcheck is |
| 2471 |
run. Without the <code class="computeroutput">memcheck:</code> |
| 2472 |
part, this will cause problems if you select other tools that |
| 2473 |
don't understand |
| 2474 |
<code class="option">--leak-check=yes</code>.</p> |
| 2475 |
</div> |
| 2476 |
<div class="sect2"> |
| 2477 |
<div class="titlepage"><div><div><h3 class="title"> |
| 2478 |
<a name="manual-core.dynopts"></a>2.7.8. Dynamically Changing Options</h3></div></div></div> |
| 2479 |
<p>The value of some command line options can be changed dynamically |
| 2480 |
while your program is running under Valgrind.</p> |
| 2481 |
<p>The dynamically changeable options of the valgrind core and a given |
| 2482 |
tool can be listed using option |
| 2483 |
<code class="computeroutput">--help-dyn-options</code>, for example:</p> |
| 2484 |
<pre class="screen"> |
| 2485 |
$ valgrind --tool=memcheck --help-dyn-options |
| 2486 |
dynamically changeable options: |
| 2487 |
-v -q -d --stats --vgdb=no --vgdb=yes --vgdb=full --vgdb-poll --vgdb-error |
| 2488 |
--vgdb-stop-at --error-markers --show-error-list -s --show-below-main |
| 2489 |
--time-stamp --trace-children --child-silent-after-fork --trace-sched |
| 2490 |
--trace-signals --trace-symtab --trace-cfi --debug-dump=syms |
| 2491 |
--debug-dump=line --debug-dump=frames --trace-redir --trace-syscalls |
| 2492 |
--sym-offsets --progress-interval --merge-recursive-frames |
| 2493 |
--vex-iropt-verbosity --suppressions --trace-flags --trace-notbelow |
| 2494 |
--trace-notabove --profile-flags --gen-suppressions=no |
| 2495 |
--gen-suppressions=yes --gen-suppressions=all --errors-for-leak-kinds |
| 2496 |
--show-leak-kinds --leak-check-heuristics --show-reachable |
| 2497 |
--show-possibly-lost --freelist-vol --freelist-big-blocks --leak-check=no |
| 2498 |
--leak-check=summary --leak-check=yes --leak-check=full --ignore-ranges |
| 2499 |
--ignore-range-below-sp --show-mismatched-frees |
| 2500 |
valgrind: Use --help for more information. |
| 2501 |
$</pre> |
| 2502 |
<p>The dynamic options can be changed the following ways:</p> |
| 2503 |
<div class="orderedlist"><ol class="orderedlist" type="1"> |
| 2504 |
<li class="listitem"> |
| 2505 |
<p>From the shell, using vgdb and the monitor command |
| 2506 |
<code class="computeroutput">v.clo</code>:</p> |
| 2507 |
<pre class="screen"> |
| 2508 |
$ vgdb "v.clo --trace-children=yes --child-silent-after-fork=no" |
| 2509 |
sending command v.clo --trace-children=yes --child-silent-after-fork=no to pid 4404 |
| 2510 |
$</pre> |
| 2511 |
<p>Note: you must use double quotes around the monitor command to avoid |
| 2512 |
vgdb interpreting the valgrind options as its own options.</p> |
| 2513 |
</li> |
| 2514 |
<li class="listitem"> |
| 2515 |
<p>From gdb, using the monitor command |
| 2516 |
<code class="computeroutput">v.clo</code>:</p> |
| 2517 |
<pre class="screen"> |
| 2518 |
(gdb) monitor v.clo --trace-children=yes --child-silent-after-fork=no |
| 2519 |
(gdb) </pre> |
| 2520 |
</li> |
| 2521 |
<li class="listitem"> |
| 2522 |
<p>From your program, using the client request |
| 2523 |
<code class="computeroutput">VALGRIND_CLO_CHANGE(option)</code>:</p> |
| 2524 |
<pre class="screen"> |
| 2525 |
VALGRIND_CLO_CHANGE ("--trace-children=yes"); |
| 2526 |
VALGRIND_CLO_CHANGE ("--child-silent-after-fork=no");</pre> |
| 2527 |
</li> |
| 2528 |
</ol></div> |
| 2529 |
<p>Dynamically changeable options can be used in various circumstances, |
| 2530 |
such as changing the valgrind behaviour during execution, loading |
| 2531 |
suppression files as part of shared library initialisation, change or |
| 2532 |
set valgrind options in child processes, ... |
| 2533 |
</p> |
| 2534 |
</div> |
| 2535 |
</div> |
| 2536 |
<div class="sect1"> |
| 2537 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 2538 |
<a name="manual-core.pthreads"></a>2.8. Support for Threads</h2></div></div></div> |
| 2539 |
<p>Threaded programs are fully supported.</p> |
| 2540 |
<p>The main thing to point out with respect to threaded programs is |
| 2541 |
that your program will use the native threading library, but Valgrind |
| 2542 |
serialises execution so that only one (kernel) thread is running at a |
| 2543 |
time. This approach avoids the horrible implementation problems of |
| 2544 |
implementing a truly multithreaded version of Valgrind, but it does |
| 2545 |
mean that threaded apps never use more than one CPU simultaneously, |
| 2546 |
even if you have a multiprocessor or multicore machine.</p> |
| 2547 |
<p>Valgrind doesn't schedule the threads itself. It merely ensures |
| 2548 |
that only one thread runs at once, using a simple locking scheme. The |
| 2549 |
actual thread scheduling remains under control of the OS kernel. What |
| 2550 |
this does mean, though, is that your program will see very different |
| 2551 |
scheduling when run on Valgrind than it does when running normally. |
| 2552 |
This is both because Valgrind is serialising the threads, and because |
| 2553 |
the code runs so much slower than normal.</p> |
| 2554 |
<p>This difference in scheduling may cause your program to behave |
| 2555 |
differently, if you have some kind of concurrency, critical race, |
| 2556 |
locking, or similar, bugs. In that case you might consider using the |
| 2557 |
tools Helgrind and/or DRD to track them down.</p> |
| 2558 |
<p>On Linux, Valgrind also supports direct use of the |
| 2559 |
<code class="computeroutput">clone</code> system call, |
| 2560 |
<code class="computeroutput">futex</code> and so on. |
| 2561 |
<code class="computeroutput">clone</code> is supported where either |
| 2562 |
everything is shared (a thread) or nothing is shared (fork-like); partial |
| 2563 |
sharing will fail. |
| 2564 |
</p> |
| 2565 |
<div class="sect2"> |
| 2566 |
<div class="titlepage"><div><div><h3 class="title"> |
| 2567 |
<a name="manual-core.pthreads_perf_sched"></a>2.8.1. Scheduling and Multi-Thread Performance</h3></div></div></div> |
| 2568 |
<p>A thread executes code only when it holds the abovementioned |
| 2569 |
lock. After executing some number of instructions, the running thread |
| 2570 |
will release the lock. All threads ready to run will then compete to |
| 2571 |
acquire the lock.</p> |
| 2572 |
<p>The <code class="option">--fair-sched</code> option controls the locking mechanism |
| 2573 |
used to serialise thread execution.</p> |
| 2574 |
<p>The default pipe based locking mechanism |
| 2575 |
(<code class="option">--fair-sched=no</code>) is available on all |
| 2576 |
platforms. Pipe based locking does not guarantee fairness between |
| 2577 |
threads: it is quite likely that a thread that has just released the |
| 2578 |
lock reacquires it immediately, even though other threads are ready to |
| 2579 |
run. When using pipe based locking, different runs of the same |
| 2580 |
multithreaded application might give very different thread |
| 2581 |
scheduling.</p> |
| 2582 |
<p>An alternative locking mechanism, based on futexes, is available |
| 2583 |
on some platforms. If available, it is activated |
| 2584 |
by <code class="option">--fair-sched=yes</code> or |
| 2585 |
<code class="option">--fair-sched=try</code>. Futex based locking ensures |
| 2586 |
fairness (round-robin scheduling) between threads: if multiple threads |
| 2587 |
are ready to run, the lock will be given to the thread which first |
| 2588 |
requested the lock. Note that a thread which is blocked in a system |
| 2589 |
call (e.g. in a blocking read system call) has not (yet) requested the |
| 2590 |
lock: such a thread requests the lock only after the system call is |
| 2591 |
finished.</p> |
| 2592 |
<p> The fairness of the futex based locking produces better |
| 2593 |
reproducibility of thread scheduling for different executions of a |
| 2594 |
multithreaded application. This better reproducibility is particularly |
| 2595 |
helpful when using Helgrind or DRD.</p> |
| 2596 |
<p>Valgrind's use of thread serialisation implies that only one |
| 2597 |
thread at a time may run. On a multiprocessor/multicore system, the |
| 2598 |
running thread is assigned to one of the CPUs by the OS kernel |
| 2599 |
scheduler. When a thread acquires the lock, sometimes the thread will |
| 2600 |
be assigned to the same CPU as the thread that just released the |
| 2601 |
lock. Sometimes, the thread will be assigned to another CPU. When |
| 2602 |
using pipe based locking, the thread that just acquired the lock |
| 2603 |
will usually be scheduled on the same CPU as the thread that just |
| 2604 |
released the lock. With the futex based mechanism, the thread that |
| 2605 |
just acquired the lock will more often be scheduled on another |
| 2606 |
CPU.</p> |
| 2607 |
<p>Valgrind's thread serialisation and CPU assignment by the OS |
| 2608 |
kernel scheduler can interact badly with the CPU frequency scaling |
| 2609 |
available on many modern CPUs. To decrease power consumption, the |
| 2610 |
frequency of a CPU or core is automatically decreased if the CPU/core |
| 2611 |
has not been used recently. If the OS kernel often assigns the thread |
| 2612 |
which just acquired the lock to another CPU/core, it is quite likely |
| 2613 |
that this CPU/core is currently at a low frequency. The frequency of |
| 2614 |
this CPU will be increased after some time. However, during this |
| 2615 |
time, the (only) running thread will have run at the low frequency. |
| 2616 |
Once this thread has run for some time, it will release the lock. |
| 2617 |
Another thread will acquire this lock, and might be scheduled again on |
| 2618 |
another CPU whose clock frequency was decreased in the |
| 2619 |
meantime.</p> |
| 2620 |
<p>The futex based locking causes threads to change CPUs/cores more |
| 2621 |
often. So, if CPU frequency scaling is activated, the futex based |
| 2622 |
locking might decrease significantly the performance of a |
| 2623 |
multithreaded app running under Valgrind. Performance losses of up to |
| 2624 |
50% degradation have been observed, as compared to running on a |
| 2625 |
machine for which CPU frequency scaling has been disabled. The pipe |
| 2626 |
based locking locking scheme also interacts badly with CPU frequency |
| 2627 |
scaling, with performance losses in the range 10..20% having been |
| 2628 |
observed.</p> |
| 2629 |
<p>To avoid such performance degradation, you should indicate to |
| 2630 |
the kernel that all CPUs/cores should always run at maximum clock |
| 2631 |
speed. Depending on your Linux distribution, CPU frequency scaling |
| 2632 |
may be controlled using a graphical interface or using command line |
| 2633 |
such as |
| 2634 |
<code class="computeroutput">cpufreq-selector</code> or |
| 2635 |
<code class="computeroutput">cpufreq-set</code>. |
| 2636 |
</p> |
| 2637 |
<p>An alternative way to avoid these problems is to tell the |
| 2638 |
OS scheduler to tie a Valgrind process to a specific (fixed) CPU using the |
| 2639 |
<code class="computeroutput">taskset</code> command. This should ensure |
| 2640 |
that the selected CPU does not fall below its maximum frequency |
| 2641 |
setting so long as any thread of the program has work to do. |
| 2642 |
</p> |
| 2643 |
</div> |
| 2644 |
</div> |
| 2645 |
<div class="sect1"> |
| 2646 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 2647 |
<a name="manual-core.signals"></a>2.9. Handling of Signals</h2></div></div></div> |
| 2648 |
<p>Valgrind has a fairly complete signal implementation. It should be |
| 2649 |
able to cope with any POSIX-compliant use of signals.</p> |
| 2650 |
<p>If you're using signals in clever ways (for example, catching |
| 2651 |
SIGSEGV, modifying page state and restarting the instruction), you're |
| 2652 |
probably relying on precise exceptions. In this case, you will need |
| 2653 |
to use <code class="option">--vex-iropt-register-updates=allregs-at-mem-access</code> |
| 2654 |
or <code class="option">--vex-iropt-register-updates=allregs-at-each-insn</code>. |
| 2655 |
</p> |
| 2656 |
<p>If your program dies as a result of a fatal core-dumping signal, |
| 2657 |
Valgrind will generate its own core file |
| 2658 |
(<code class="computeroutput">vgcore.NNNNN</code>) containing your program's |
| 2659 |
state. You may use this core file for post-mortem debugging with GDB or |
| 2660 |
similar. (Note: it will not generate a core if your core dump size limit is |
| 2661 |
0.) At the time of writing the core dumps do not include all the floating |
| 2662 |
point register information.</p> |
| 2663 |
<p>In the unlikely event that Valgrind itself crashes, the operating system |
| 2664 |
will create a core dump in the usual way.</p> |
| 2665 |
</div> |
| 2666 |
<div class="sect1"> |
| 2667 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 2668 |
<a name="manual-core.xtree"></a>2.10. Execution Trees</h2></div></div></div> |
| 2669 |
<p>An execution tree (xtree) is made of a set of stack traces, each |
| 2670 |
stack trace is associated with some resource consumptions or event |
| 2671 |
counts. Depending on the xtree, different event counts/resource |
| 2672 |
consumptions can be recorded in the xtree. Multiple tools can |
| 2673 |
produce memory use xtree. Memcheck can output the leak search results |
| 2674 |
in an xtree.</p> |
| 2675 |
<p> A typical usage for an xtree is to show a graphical or textual |
| 2676 |
representation of the heap usage of a program. The below figure is |
| 2677 |
a heap usage xtree graphical representation produced by |
| 2678 |
kcachegrind. In the kcachegrind output, you can see that main |
| 2679 |
current heap usage (allocated indirectly) is 528 bytes : 388 bytes |
| 2680 |
allocated indirectly via a call to function f1 and 140 bytes |
| 2681 |
indirectly allocated via a call to function f2. f2 has allocated |
| 2682 |
memory by calling g2, while f1 has allocated memory by calling g11 |
| 2683 |
and g12. g11, g12 and g2 have directly called a memory allocation |
| 2684 |
function (malloc), and so have a non zero 'Self' value. Note that when |
| 2685 |
kcachegrind shows an xtree, the 'Called' column and call nr indications in |
| 2686 |
the Call Graph are not significant (always set to 0 or 1, independently |
| 2687 |
of the real nr of calls. The kcachegrind versions >= 0.8.0 do not show |
| 2688 |
anymore such irrelevant xtree call number information.</p> |
| 2689 |
<div><img src="images/kcachegrind_xtree.png"></div> |
| 2690 |
<p>An xtree heap memory report is produced at the end of the |
| 2691 |
execution when required using the |
| 2692 |
option <code class="option">--xtree-memory</code>. It can also be produced on |
| 2693 |
demand using the <code class="option">xtmemory</code> monitor command (see |
| 2694 |
<a class="xref" href="manual-core-adv.html#manual-core-adv.valgrind-monitor-commands" title="3.2.11. Valgrind monitor commands">Valgrind monitor commands</a>). Currently, |
| 2695 |
an xtree heap memory report can be produced by |
| 2696 |
the <code class="option">memcheck</code>, <code class="option">helgrind</code> |
| 2697 |
and <code class="option">massif</code> tools.</p> |
| 2698 |
<p>The xtrees produced by the option |
| 2699 |
<a class="xref" href="manual-core.html#opt.xtree-memory">--xtree-memory</a> or the <code class="option">xtmemory</code> |
| 2700 |
monitor command are showing the following events/resource |
| 2701 |
consumption describing heap usage:</p> |
| 2702 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 2703 |
<li class="listitem"><p><code class="option">curB</code> current number of Bytes allocated. The |
| 2704 |
number of allocated bytes is added to the <code class="option">curB</code> |
| 2705 |
value of a stack trace for each allocation. It is decreased when |
| 2706 |
a block allocated by this stack trace is released (by another |
| 2707 |
"freeing" stack trace)</p></li> |
| 2708 |
<li class="listitem"><p><code class="option">curBk</code> current number of Blocks allocated, |
| 2709 |
maintained similary to curB : +1 for each allocation, -1 when |
| 2710 |
the block is freed.</p></li> |
| 2711 |
<li class="listitem"><p><code class="option">totB</code> total allocated Bytes. This is |
| 2712 |
increased for each allocation with the number of allocated bytes.</p></li> |
| 2713 |
<li class="listitem"><p><code class="option">totBk</code> total allocated Blocks, maintained similary |
| 2714 |
to totB : +1 for each allocation.</p></li> |
| 2715 |
<li class="listitem"><p><code class="option">totFdB</code> total Freed Bytes, increased each time |
| 2716 |
a block is released by this ("freeing") stack trace : + nr freed bytes |
| 2717 |
for each free operation.</p></li> |
| 2718 |
<li class="listitem"><p><code class="option">totFdBk</code> total Freed Blocks, maintained similarly |
| 2719 |
to totFdB : +1 for each free operation.</p></li> |
| 2720 |
</ul></div> |
| 2721 |
<p>Note that the last 4 counts are produced only when the |
| 2722 |
<code class="option">--xtree-memory=full</code> was given at startup.</p> |
| 2723 |
<p>Xtrees can be saved in 2 file formats, the "Callgrind Format" and |
| 2724 |
the "Massif Format".</p> |
| 2725 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 2726 |
<li class="listitem"> |
| 2727 |
<p>Callgrind Format</p> |
| 2728 |
<p>An xtree file in the Callgrind Format contains a single callgraph, |
| 2729 |
associating each stack trace with the values recorded |
| 2730 |
in the xtree. </p> |
| 2731 |
<p>Different Callgrind Format file visualizers are available:</p> |
| 2732 |
<p>Valgrind distribution includes the <code class="option">callgrind_annotate</code> |
| 2733 |
command line utility that reads in the xtree data, and prints a sorted |
| 2734 |
lists of functions, optionally with source annotation. Note that due to |
| 2735 |
xtree specificities, you must give the option |
| 2736 |
<code class="option">--inclusive=yes</code> to callgrind_annotate.</p> |
| 2737 |
<p>For graphical visualization of the data, you can use |
| 2738 |
<a class="ulink" href="https://kcachegrind.github.io/html/Home.html" target="_top">KCachegrind</a>, which is a KDE/Qt based |
| 2739 |
GUI that makes it easy to navigate the large amount of data that |
| 2740 |
an xtree can contain.</p> |
| 2741 |
<p>Note that xtree Callgrind Format does not make use of the inline |
| 2742 |
information even when specifying <code class="option">--read-inline-info=yes</code>. |
| 2743 |
</p> |
| 2744 |
</li> |
| 2745 |
<li class="listitem"> |
| 2746 |
<p>Massif Format</p> |
| 2747 |
<p>An xtree file in the Massif Format contains one detailed tree |
| 2748 |
callgraph data for each type of event recorded in the xtree. So, |
| 2749 |
for <code class="option">--xtree-memory=alloc</code>, the output file will |
| 2750 |
contain 2 detailed trees (for the counts <code class="option">curB</code> |
| 2751 |
and <code class="option">curBk</code>), |
| 2752 |
while <code class="option">--xtree-memory=full</code> will give a file |
| 2753 |
with 6 detailed trees.</p> |
| 2754 |
<p>Different Massif Format file visualizers are available. Valgrind |
| 2755 |
distribution includes the <code class="option">ms_print</code> |
| 2756 |
command line utility that produces an easy to read reprentation of |
| 2757 |
a massif output file. See <a class="xref" href="ms-manual.html#ms-manual.using-print" title="9.2. Using Massif and ms_print">Using Massif and ms_print</a> and |
| 2758 |
<a class="xref" href="ms-manual.html#ms-manual.using-visualizer" title="9.3. Using massif-visualizer">Using massif-visualizer</a> for more details |
| 2759 |
about visualising Massif Format output files.</p> |
| 2760 |
<p>Note that xtree Massif Format makes use of the inline |
| 2761 |
information when specifying <code class="option">--read-inline-info=yes</code>. |
| 2762 |
</p> |
| 2763 |
</li> |
| 2764 |
</ul></div> |
| 2765 |
<p>Note that for equivalent information, the Callgrind Format is more compact |
| 2766 |
than the Massif Format. However, the Callgrind Format always contains the |
| 2767 |
full data: there is no filtering done during file production, filtering is |
| 2768 |
done by visualizers such as kcachegrind. kcachegrind is particularly easy to |
| 2769 |
use to analyse big xtree data containing multiple events counts or resources |
| 2770 |
consumption. The Massif Format (optionally) only contains a part of the data. |
| 2771 |
For example, the Massif tool might filter some of the data, according to the |
| 2772 |
<code class="option">--threshold</code> option. |
| 2773 |
</p> |
| 2774 |
<p>To clarify the xtree concept, the below gives several extracts of |
| 2775 |
the output produced by the following commands: |
| 2776 |
</p> |
| 2777 |
<pre class="screen"> |
| 2778 |
valgrind --xtree-memory=full --xtree-memory-file=xtmemory.kcg mfg |
| 2779 |
callgrind_annotate --auto=yes --inclusive=yes --sort=curB:100,curBk:100,totB:100,totBk:100,totFdB:100,totFdBk:100 xtmemory.kcg |
| 2780 |
</pre> |
| 2781 |
<p> |
| 2782 |
</p> |
| 2783 |
<p>The below extract shows that the program mfg has allocated in |
| 2784 |
total 770 bytes in 60 different blocks. Of these 60 blocks, 19 were |
| 2785 |
freed, releasing a total of 242 bytes. The heap currently contains |
| 2786 |
528 bytes in 41 blocks.</p> |
| 2787 |
<pre class="screen"> |
| 2788 |
-------------------------------------------------------------------------------- |
| 2789 |
curB curBk totB totBk totFdB totFdBk |
| 2790 |
-------------------------------------------------------------------------------- |
| 2791 |
528 41 770 60 242 19 PROGRAM TOTALS |
| 2792 |
</pre> |
| 2793 |
<p>The below gives more details about which functions have |
| 2794 |
allocated or released memory. As an example, we see that main has |
| 2795 |
(directly or indirectly) allocated 770 bytes of memory and freed |
| 2796 |
(directly or indirectly) 242 bytes of memory. The function f1 has |
| 2797 |
(directly or indirectly) allocated 570 bytes of memory, and has not |
| 2798 |
(directly or indirectly) freed memory. Of the 570 bytes allocated |
| 2799 |
by function f1, 388 bytes (34 blocks) have not been |
| 2800 |
released.</p> |
| 2801 |
<pre class="screen"> |
| 2802 |
-------------------------------------------------------------------------------- |
| 2803 |
curB curBk totB totBk totFdB totFdBk file:function |
| 2804 |
-------------------------------------------------------------------------------- |
| 2805 |
528 41 770 60 242 19 mfg.c:main |
| 2806 |
388 34 570 50 0 0 mfg.c:f1 |
| 2807 |
220 20 330 30 0 0 mfg.c:g11 |
| 2808 |
168 14 240 20 0 0 mfg.c:g12 |
| 2809 |
140 7 200 10 0 0 mfg.c:g2 |
| 2810 |
140 7 200 10 0 0 mfg.c:f2 |
| 2811 |
0 0 0 0 131 10 mfg.c:freeY |
| 2812 |
0 0 0 0 111 9 mfg.c:freeX |
| 2813 |
</pre> |
| 2814 |
<p>The below gives a more detailed information about the callgraph |
| 2815 |
and which source lines/calls have (directly or indirectly) allocated or |
| 2816 |
released memory. The below shows that the 770 bytes allocated by |
| 2817 |
main have been indirectly allocated by calls to f1 and f2. |
| 2818 |
Similarly, we see that the 570 bytes allocated by f1 have been |
| 2819 |
indirectly allocated by calls to g11 and g12. Of the 330 bytes allocated |
| 2820 |
by the 30 calls to g11, 168 bytes have not been freed. |
| 2821 |
The function freeY (called once by main) has released in total |
| 2822 |
10 blocks and 131 bytes. </p> |
| 2823 |
<pre class="screen"> |
| 2824 |
-------------------------------------------------------------------------------- |
| 2825 |
-- Auto-annotated source: /home/philippe/valgrind/littleprogs/ + mfg.c |
| 2826 |
-------------------------------------------------------------------------------- |
| 2827 |
curB curBk totB totBk totFdB totFdBk |
| 2828 |
.... |
| 2829 |
. . . . . . static void freeY(void) |
| 2830 |
. . . . . . { |
| 2831 |
. . . . . . int i; |
| 2832 |
. . . . . . for (i = 0; i < next_ptr; i++) |
| 2833 |
. . . . . . if(i % 5 == 0 && ptrs[i] != NULL) |
| 2834 |
0 0 0 0 131 10 free(ptrs[i]); |
| 2835 |
. . . . . . } |
| 2836 |
. . . . . . static void f1(void) |
| 2837 |
. . . . . . { |
| 2838 |
. . . . . . int i; |
| 2839 |
. . . . . . for (i = 0; i < 30; i++) |
| 2840 |
220 20 330 30 0 0 g11(); |
| 2841 |
. . . . . . for (i = 0; i < 20; i++) |
| 2842 |
168 14 240 20 0 0 g12(); |
| 2843 |
. . . . . . } |
| 2844 |
. . . . . . int main() |
| 2845 |
. . . . . . { |
| 2846 |
388 34 570 50 0 0 f1(); |
| 2847 |
140 7 200 10 0 0 f2(); |
| 2848 |
0 0 0 0 111 9 freeX(); |
| 2849 |
0 0 0 0 131 10 freeY(); |
| 2850 |
. . . . . . return 0; |
| 2851 |
. . . . . . } |
| 2852 |
</pre> |
| 2853 |
<p>Heap memory xtrees are helping to understand how your (big) |
| 2854 |
program is using the heap. A full heap memory xtree helps to pin |
| 2855 |
point some code that allocates a lot of small objects : allocating |
| 2856 |
such small objects might be replaced by more efficient technique, |
| 2857 |
such as allocating a big block using malloc, and then diviving this |
| 2858 |
block into smaller blocks in order to decrease the cpu and/or memory |
| 2859 |
overhead of allocating a lot of small blocks. Such full xtree information |
| 2860 |
complements e.g. what callgrind can show: callgrind can show the number |
| 2861 |
of calls to a function (such as malloc) but does not indicate the volume |
| 2862 |
of memory allocated (or freed).</p> |
| 2863 |
<p>A full heap memory xtree also can identify the code that allocates |
| 2864 |
and frees a lot of blocks : the total foot print of the program might |
| 2865 |
not reflect the fact that the same memory was over and over allocated |
| 2866 |
then released.</p> |
| 2867 |
<p>Finally, Xtree visualizers such as kcachegrind are helping to |
| 2868 |
identify big memory consumers, in order to possibly optimise the |
| 2869 |
amount of memory needed by your program.</p> |
| 2870 |
</div> |
| 2871 |
<div class="sect1"> |
| 2872 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 2873 |
<a name="manual-core.install"></a>2.11. Building and Installing Valgrind</h2></div></div></div> |
| 2874 |
<p>We use the standard Unix |
| 2875 |
<code class="computeroutput">./configure</code>, |
| 2876 |
<code class="computeroutput">make</code>, <code class="computeroutput">make |
| 2877 |
install</code> mechanism. Once you have completed |
| 2878 |
<code class="computeroutput">make install</code> you may then want |
| 2879 |
to run the regression tests |
| 2880 |
with <code class="computeroutput">make regtest</code>. |
| 2881 |
</p> |
| 2882 |
<p>In addition to the usual |
| 2883 |
<code class="option">--prefix=/path/to/install/tree</code>, there are three |
| 2884 |
options which affect how Valgrind is built: |
| 2885 |
</p> |
| 2886 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 2887 |
<li class="listitem"> |
| 2888 |
<p><code class="option">--enable-inner</code></p> |
| 2889 |
<p>This builds Valgrind with some special magic hacks which make |
| 2890 |
it possible to run it on a standard build of Valgrind (what the |
| 2891 |
developers call "self-hosting"). Ordinarily you should not use |
| 2892 |
this option as various kinds of safety checks are disabled. |
| 2893 |
</p> |
| 2894 |
</li> |
| 2895 |
<li class="listitem"> |
| 2896 |
<p><code class="option">--enable-only64bit</code></p> |
| 2897 |
<p><code class="option">--enable-only32bit</code></p> |
| 2898 |
<p>On 64-bit platforms (amd64-linux, ppc64-linux, |
| 2899 |
amd64-darwin), Valgrind is by default built in such a way that |
| 2900 |
both 32-bit and 64-bit executables can be run. Sometimes this |
| 2901 |
cleverness is a problem for a variety of reasons. These two |
| 2902 |
options allow for single-target builds in this situation. If you |
| 2903 |
issue both, the configure script will complain. Note they are |
| 2904 |
ignored on 32-bit-only platforms (x86-linux, ppc32-linux, |
| 2905 |
arm-linux, x86-darwin). |
| 2906 |
</p> |
| 2907 |
</li> |
| 2908 |
</ul></div> |
| 2909 |
<p> |
| 2910 |
</p> |
| 2911 |
<p>The <code class="computeroutput">configure</code> script tests |
| 2912 |
the version of the X server currently indicated by the current |
| 2913 |
<code class="computeroutput">$DISPLAY</code>. This is a known bug. |
| 2914 |
The intention was to detect the version of the current X |
| 2915 |
client libraries, so that correct suppressions could be selected |
| 2916 |
for them, but instead the test checks the server version. This |
| 2917 |
is just plain wrong.</p> |
| 2918 |
<p>If you are building a binary package of Valgrind for |
| 2919 |
distribution, please read <code class="literal">README_PACKAGERS</code> |
| 2920 |
<a class="xref" href="dist.readme-packagers.html" title="7. README_PACKAGERS">Readme Packagers</a>. It contains some |
| 2921 |
important information.</p> |
| 2922 |
<p>Apart from that, there's not much excitement here. Let us |
| 2923 |
know if you have build problems.</p> |
| 2924 |
</div> |
| 2925 |
<div class="sect1"> |
| 2926 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 2927 |
<a name="manual-core.problems"></a>2.12. If You Have Problems</h2></div></div></div> |
| 2928 |
<p>Contact us at <a class="ulink" href="http://www.valgrind.org/" target="_top">http://www.valgrind.org/</a>.</p> |
| 2929 |
<p>See <a class="xref" href="manual-core.html#manual-core.limits" title="2.13. Limitations">Limitations</a> for the known |
| 2930 |
limitations of Valgrind, and for a list of programs which are |
| 2931 |
known not to work on it.</p> |
| 2932 |
<p>All parts of the system make heavy use of assertions and |
| 2933 |
internal self-checks. They are permanently enabled, and we have no |
| 2934 |
plans to disable them. If one of them breaks, please mail us!</p> |
| 2935 |
<p>If you get an assertion failure |
| 2936 |
in <code class="filename">m_mallocfree.c</code>, this may have happened because |
| 2937 |
your program wrote off the end of a heap block, or before its |
| 2938 |
beginning, thus corrupting heap metadata. Valgrind hopefully will have |
| 2939 |
emitted a message to that effect before dying in this way.</p> |
| 2940 |
<p>Read the <a class="xref" href="FAQ.html" title="Valgrind FAQ">Valgrind FAQ</a> for more advice about common problems, |
| 2941 |
crashes, etc.</p> |
| 2942 |
</div> |
| 2943 |
<div class="sect1"> |
| 2944 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 2945 |
<a name="manual-core.limits"></a>2.13. Limitations</h2></div></div></div> |
| 2946 |
<p>The following list of limitations seems long. However, most |
| 2947 |
programs actually work fine.</p> |
| 2948 |
<p>Valgrind will run programs on the supported platforms |
| 2949 |
subject to the following constraints:</p> |
| 2950 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 2951 |
<li class="listitem"><p>On Linux, Valgrind determines at startup the size of the 'brk |
| 2952 |
segment' using the RLIMIT_DATA rlim_cur, with a minimum of 1 MB and |
| 2953 |
a maximum of 8 MB. Valgrind outputs a message each time a program |
| 2954 |
tries to extend the brk segment beyond the size determined at |
| 2955 |
startup. Most programs will work properly with this limit, |
| 2956 |
typically by switching to the use of mmap to get more memory. |
| 2957 |
If your program really needs a big brk segment, you must change |
| 2958 |
the 8 MB hardcoded limit and recompile Valgrind. |
| 2959 |
</p></li> |
| 2960 |
<li class="listitem"><p>On x86 and amd64, there is no support for 3DNow! |
| 2961 |
instructions. If the translator encounters these, Valgrind will |
| 2962 |
generate a SIGILL when the instruction is executed. Apart from |
| 2963 |
that, on x86 and amd64, essentially all instructions are supported, |
| 2964 |
up to and including AVX and AES in 64-bit mode and SSSE3 in 32-bit |
| 2965 |
mode. 32-bit mode does in fact support the bare minimum SSE4 |
| 2966 |
instructions needed to run programs on MacOSX 10.6 on 32-bit |
| 2967 |
targets. |
| 2968 |
</p></li> |
| 2969 |
<li class="listitem"><p>On ppc32 and ppc64, almost all integer, floating point and |
| 2970 |
Altivec instructions are supported. Specifically: integer and FP |
| 2971 |
insns that are mandatory for PowerPC, the "General-purpose |
| 2972 |
optional" group (fsqrt, fsqrts, stfiwx), the "Graphics optional" |
| 2973 |
group (fre, fres, frsqrte, frsqrtes), and the Altivec (also known |
| 2974 |
as VMX) SIMD instruction set, are supported. Also, instructions |
| 2975 |
from the Power ISA 2.05 specification, as present in POWER6 CPUs, |
| 2976 |
are supported.</p></li> |
| 2977 |
<li class="listitem"><p>On ARM, essentially the entire ARMv7-A instruction set |
| 2978 |
is supported, in both ARM and Thumb mode. ThumbEE and Jazelle are |
| 2979 |
not supported. NEON, VFPv3 and ARMv6 media support is fairly |
| 2980 |
complete. |
| 2981 |
</p></li> |
| 2982 |
<li class="listitem"><p>If your program does its own memory management, rather than |
| 2983 |
using malloc/new/free/delete, it should still work, but Memcheck's |
| 2984 |
error checking won't be so effective. If you describe your |
| 2985 |
program's memory management scheme using "client requests" (see |
| 2986 |
<a class="xref" href="manual-core-adv.html#manual-core-adv.clientreq" title="3.1. The Client Request mechanism">The Client Request mechanism</a>), Memcheck can do |
| 2987 |
better. Nevertheless, using malloc/new and free/delete is still |
| 2988 |
the best approach.</p></li> |
| 2989 |
<li class="listitem"><p>Valgrind's signal simulation is not as robust as it could be. |
| 2990 |
Basic POSIX-compliant sigaction and sigprocmask functionality is |
| 2991 |
supplied, but it's conceivable that things could go badly awry if you |
| 2992 |
do weird things with signals. Workaround: don't. Programs that do |
| 2993 |
non-POSIX signal tricks are in any case inherently unportable, so |
| 2994 |
should be avoided if possible.</p></li> |
| 2995 |
<li class="listitem"><p>Machine instructions, and system calls, have been implemented |
| 2996 |
on demand. So it's possible, although unlikely, that a program will |
| 2997 |
fall over with a message to that effect. If this happens, please |
| 2998 |
report all the details printed out, so we can try and implement the |
| 2999 |
missing feature.</p></li> |
| 3000 |
<li class="listitem"><p>Memory consumption of your program is majorly increased |
| 3001 |
whilst running under Valgrind's Memcheck tool. This is due to the |
| 3002 |
large amount of administrative information maintained behind the |
| 3003 |
scenes. Another cause is that Valgrind dynamically translates the |
| 3004 |
original executable. Translated, instrumented code is 12-18 times |
| 3005 |
larger than the original so you can easily end up with 150+ MB of |
| 3006 |
translations when running (eg) a web browser.</p></li> |
| 3007 |
<li class="listitem"> |
| 3008 |
<p>Valgrind can handle dynamically-generated code just fine. If |
| 3009 |
you regenerate code over the top of old code (ie. at the same |
| 3010 |
memory addresses), if the code is on the stack Valgrind will |
| 3011 |
realise the code has changed, and work correctly. This is |
| 3012 |
necessary to handle the trampolines GCC uses to implemented nested |
| 3013 |
functions. If you regenerate code somewhere other than the stack, |
| 3014 |
and you are running on an 32- or 64-bit x86 CPU, you will need to |
| 3015 |
use the <code class="option">--smc-check=all</code> option, and Valgrind will |
| 3016 |
run more slowly than normal. Or you can add client requests that |
| 3017 |
tell Valgrind when your program has overwritten code. |
| 3018 |
</p> |
| 3019 |
<p> On other platforms (ARM, PowerPC) Valgrind observes and |
| 3020 |
honours the cache invalidation hints that programs are obliged to |
| 3021 |
emit to notify new code, and so self-modifying-code support should |
| 3022 |
work automatically, without the need |
| 3023 |
for <code class="option">--smc-check=all</code>.</p> |
| 3024 |
</li> |
| 3025 |
<li class="listitem"> |
| 3026 |
<p>Valgrind has the following limitations |
| 3027 |
in its implementation of x86/AMD64 floating point relative to |
| 3028 |
IEEE754.</p> |
| 3029 |
<p>Precision: There is no support for 80 bit arithmetic. |
| 3030 |
Internally, Valgrind represents all such "long double" numbers in 64 |
| 3031 |
bits, and so there may be some differences in results. Whether or |
| 3032 |
not this is critical remains to be seen. Note, the x86/amd64 |
| 3033 |
fldt/fstpt instructions (read/write 80-bit numbers) are correctly |
| 3034 |
simulated, using conversions to/from 64 bits, so that in-memory |
| 3035 |
images of 80-bit numbers look correct if anyone wants to see.</p> |
| 3036 |
<p>The impression observed from many FP regression tests is that |
| 3037 |
the accuracy differences aren't significant. Generally speaking, if |
| 3038 |
a program relies on 80-bit precision, there may be difficulties |
| 3039 |
porting it to non x86/amd64 platforms which only support 64-bit FP |
| 3040 |
precision. Even on x86/amd64, the program may get different results |
| 3041 |
depending on whether it is compiled to use SSE2 instructions (64-bits |
| 3042 |
only), or x87 instructions (80-bit). The net effect is to make FP |
| 3043 |
programs behave as if they had been run on a machine with 64-bit IEEE |
| 3044 |
floats, for example PowerPC. On amd64 FP arithmetic is done by |
| 3045 |
default on SSE2, so amd64 looks more like PowerPC than x86 from an FP |
| 3046 |
perspective, and there are far fewer noticeable accuracy differences |
| 3047 |
than with x86.</p> |
| 3048 |
<p>Rounding: Valgrind does observe the 4 IEEE-mandated rounding |
| 3049 |
modes (to nearest, to +infinity, to -infinity, to zero) for the |
| 3050 |
following conversions: float to integer, integer to float where |
| 3051 |
there is a possibility of loss of precision, and float-to-float |
| 3052 |
rounding. For all other FP operations, only the IEEE default mode |
| 3053 |
(round to nearest) is supported.</p> |
| 3054 |
<p>Numeric exceptions in FP code: IEEE754 defines five types of |
| 3055 |
numeric exception that can happen: invalid operation (sqrt of |
| 3056 |
negative number, etc), division by zero, overflow, underflow, |
| 3057 |
inexact (loss of precision).</p> |
| 3058 |
<p>For each exception, two courses of action are defined by IEEE754: |
| 3059 |
either (1) a user-defined exception handler may be called, or (2) a |
| 3060 |
default action is defined, which "fixes things up" and allows the |
| 3061 |
computation to proceed without throwing an exception.</p> |
| 3062 |
<p>Currently Valgrind only supports the default fixup actions. |
| 3063 |
Again, feedback on the importance of exception support would be |
| 3064 |
appreciated.</p> |
| 3065 |
<p>When Valgrind detects that the program is trying to exceed any |
| 3066 |
of these limitations (setting exception handlers, rounding mode, or |
| 3067 |
precision control), it can print a message giving a traceback of |
| 3068 |
where this has happened, and continue execution. This behaviour used |
| 3069 |
to be the default, but the messages are annoying and so showing them |
| 3070 |
is now disabled by default. Use <code class="option">--show-emwarns=yes</code> to see |
| 3071 |
them.</p> |
| 3072 |
<p>The above limitations define precisely the IEEE754 'default' |
| 3073 |
behaviour: default fixup on all exceptions, round-to-nearest |
| 3074 |
operations, and 64-bit precision.</p> |
| 3075 |
</li> |
| 3076 |
<li class="listitem"> |
| 3077 |
<p>Valgrind has the following limitations in |
| 3078 |
its implementation of x86/AMD64 SSE2 FP arithmetic, relative to |
| 3079 |
IEEE754.</p> |
| 3080 |
<p>Essentially the same: no exceptions, and limited observance of |
| 3081 |
rounding mode. Also, SSE2 has control bits which make it treat |
| 3082 |
denormalised numbers as zero (DAZ) and a related action, flush |
| 3083 |
denormals to zero (FTZ). Both of these cause SSE2 arithmetic to be |
| 3084 |
less accurate than IEEE requires. Valgrind detects, ignores, and can |
| 3085 |
warn about, attempts to enable either mode.</p> |
| 3086 |
</li> |
| 3087 |
<li class="listitem"> |
| 3088 |
<p>Valgrind has the following limitations in |
| 3089 |
its implementation of ARM VFPv3 arithmetic, relative to |
| 3090 |
IEEE754.</p> |
| 3091 |
<p>Essentially the same: no exceptions, and limited observance |
| 3092 |
of rounding mode. Also, switching the VFP unit into vector mode |
| 3093 |
will cause Valgrind to abort the program -- it has no way to |
| 3094 |
emulate vector uses of VFP at a reasonable performance level. This |
| 3095 |
is no big deal given that non-scalar uses of VFP instructions are |
| 3096 |
in any case deprecated.</p> |
| 3097 |
</li> |
| 3098 |
<li class="listitem"> |
| 3099 |
<p>Valgrind has the following limitations |
| 3100 |
in its implementation of PPC32 and PPC64 floating point |
| 3101 |
arithmetic, relative to IEEE754.</p> |
| 3102 |
<p>Scalar (non-Altivec): Valgrind provides a bit-exact emulation of |
| 3103 |
all floating point instructions, except for "fre" and "fres", which are |
| 3104 |
done more precisely than required by the PowerPC architecture specification. |
| 3105 |
All floating point operations observe the current rounding mode. |
| 3106 |
</p> |
| 3107 |
<p>However, fpscr[FPRF] is not set after each operation. That could |
| 3108 |
be done but would give measurable performance overheads, and so far |
| 3109 |
no need for it has been found.</p> |
| 3110 |
<p>As on x86/AMD64, IEEE754 exceptions are not supported: all floating |
| 3111 |
point exceptions are handled using the default IEEE fixup actions. |
| 3112 |
Valgrind detects, ignores, and can warn about, attempts to unmask |
| 3113 |
the 5 IEEE FP exception kinds by writing to the floating-point status |
| 3114 |
and control register (fpscr). |
| 3115 |
</p> |
| 3116 |
<p>Vector (Altivec, VMX): essentially as with x86/AMD64 SSE/SSE2: |
| 3117 |
no exceptions, and limited observance of rounding mode. |
| 3118 |
For Altivec, FP arithmetic |
| 3119 |
is done in IEEE/Java mode, which is more accurate than the Linux default |
| 3120 |
setting. "More accurate" means that denormals are handled properly, |
| 3121 |
rather than simply being flushed to zero.</p> |
| 3122 |
</li> |
| 3123 |
</ul></div> |
| 3124 |
<p>Programs which are known not to work are:</p> |
| 3125 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>emacs starts up but immediately concludes it is out of |
| 3126 |
memory and aborts. It may be that Memcheck does not provide |
| 3127 |
a good enough emulation of the |
| 3128 |
<code class="computeroutput">mallinfo</code> function. |
| 3129 |
Emacs works fine if you build it to use |
| 3130 |
the standard malloc/free routines.</p></li></ul></div> |
| 3131 |
</div> |
| 3132 |
<div class="sect1"> |
| 3133 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 3134 |
<a name="manual-core.example"></a>2.14. An Example Run</h2></div></div></div> |
| 3135 |
<p>This is the log for a run of a small program using Memcheck. |
| 3136 |
The program is in fact correct, and the reported error is as the |
| 3137 |
result of a potentially serious code generation bug in GNU g++ |
| 3138 |
(snapshot 20010527).</p> |
| 3139 |
<pre class="programlisting"> |
| 3140 |
sewardj@phoenix:~/newmat10$ ~/Valgrind-6/valgrind -v ./bogon |
| 3141 |
==25832== Valgrind 0.10, a memory error detector for x86 RedHat 7.1. |
| 3142 |
==25832== Copyright (C) 2000-2001, and GNU GPL'd, by Julian Seward. |
| 3143 |
==25832== Startup, with flags: |
| 3144 |
==25832== --suppressions=/home/sewardj/Valgrind/redhat71.supp |
| 3145 |
==25832== reading syms from /lib/ld-linux.so.2 |
| 3146 |
==25832== reading syms from /lib/libc.so.6 |
| 3147 |
==25832== reading syms from /mnt/pima/jrs/Inst/lib/libgcc_s.so.0 |
| 3148 |
==25832== reading syms from /lib/libm.so.6 |
| 3149 |
==25832== reading syms from /mnt/pima/jrs/Inst/lib/libstdc++.so.3 |
| 3150 |
==25832== reading syms from /home/sewardj/Valgrind/valgrind.so |
| 3151 |
==25832== reading syms from /proc/self/exe |
| 3152 |
==25832== |
| 3153 |
==25832== Invalid read of size 4 |
| 3154 |
==25832== at 0x8048724: BandMatrix::ReSize(int,int,int) (bogon.cpp:45) |
| 3155 |
==25832== by 0x80487AF: main (bogon.cpp:66) |
| 3156 |
==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd |
| 3157 |
==25832== |
| 3158 |
==25832== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) |
| 3159 |
==25832== malloc/free: in use at exit: 0 bytes in 0 blocks. |
| 3160 |
==25832== malloc/free: 0 allocs, 0 frees, 0 bytes allocated. |
| 3161 |
==25832== For a detailed leak analysis, rerun with: --leak-check=yes |
| 3162 |
</pre> |
| 3163 |
<p>The GCC folks fixed this about a week before GCC 3.0 |
| 3164 |
shipped.</p> |
| 3165 |
</div> |
| 3166 |
<div class="sect1"> |
| 3167 |
<div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
| 3168 |
<a name="manual-core.warnings"></a>2.15. Warning Messages You Might See</h2></div></div></div> |
| 3169 |
<p>Some of these only appear if you run in verbose mode |
| 3170 |
(enabled by <code class="option">-v</code>):</p> |
| 3171 |
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> |
| 3172 |
<li class="listitem"> |
| 3173 |
<p><code class="computeroutput">More than 100 errors detected. Subsequent |
| 3174 |
errors will still be recorded, but in less detail than |
| 3175 |
before.</code></p> |
| 3176 |
<p>After 100 different errors have been shown, Valgrind becomes |
| 3177 |
more conservative about collecting them. It then requires only the |
| 3178 |
program counters in the top two stack frames to match when deciding |
| 3179 |
whether or not two errors are really the same one. Prior to this |
| 3180 |
point, the PCs in the top four frames are required to match. This |
| 3181 |
hack has the effect of slowing down the appearance of new errors |
| 3182 |
after the first 100. The 100 constant can be changed by recompiling |
| 3183 |
Valgrind.</p> |
| 3184 |
</li> |
| 3185 |
<li class="listitem"> |
| 3186 |
<p><code class="computeroutput">More than 1000 errors detected. I'm not |
| 3187 |
reporting any more. Final error counts may be inaccurate. Go fix |
| 3188 |
your program!</code></p> |
| 3189 |
<p>After 1000 different errors have been detected, Valgrind |
| 3190 |
ignores any more. It seems unlikely that collecting even more |
| 3191 |
different ones would be of practical help to anybody, and it avoids |
| 3192 |
the danger that Valgrind spends more and more of its time comparing |
| 3193 |
new errors against an ever-growing collection. As above, the 1000 |
| 3194 |
number is a compile-time constant.</p> |
| 3195 |
</li> |
| 3196 |
<li class="listitem"> |
| 3197 |
<p><code class="computeroutput">Warning: client switching stacks?</code></p> |
| 3198 |
<p>Valgrind spotted such a large change in the stack pointer |
| 3199 |
that it guesses the client is switching to a different stack. At |
| 3200 |
this point it makes a kludgey guess where the base of the new |
| 3201 |
stack is, and sets memory permissions accordingly. At the moment |
| 3202 |
"large change" is defined as a change of more that 2000000 in the |
| 3203 |
value of the stack pointer register. If Valgrind guesses wrong, |
| 3204 |
you may get many bogus error messages following this and/or have |
| 3205 |
crashes in the stack trace recording code. You might avoid these |
| 3206 |
problems by informing Valgrind about the stack bounds using |
| 3207 |
VALGRIND_STACK_REGISTER client request. </p> |
| 3208 |
</li> |
| 3209 |
<li class="listitem"> |
| 3210 |
<p><code class="computeroutput">Warning: client attempted to close Valgrind's |
| 3211 |
logfile fd <number></code></p> |
| 3212 |
<p>Valgrind doesn't allow the client to close the logfile, |
| 3213 |
because you'd never see any diagnostic information after that point. |
| 3214 |
If you see this message, you may want to use the |
| 3215 |
<code class="option">--log-fd=<number></code> option to specify a |
| 3216 |
different logfile file-descriptor number.</p> |
| 3217 |
</li> |
| 3218 |
<li class="listitem"> |
| 3219 |
<p><code class="computeroutput">Warning: noted but unhandled ioctl |
| 3220 |
<number></code></p> |
| 3221 |
<p>Valgrind observed a call to one of the vast family of |
| 3222 |
<code class="computeroutput">ioctl</code> system calls, but did not |
| 3223 |
modify its memory status info (because nobody has yet written a |
| 3224 |
suitable wrapper). The call will still have gone through, but you may get |
| 3225 |
spurious errors after this as a result of the non-update of the |
| 3226 |
memory info.</p> |
| 3227 |
</li> |
| 3228 |
<li class="listitem"> |
| 3229 |
<p><code class="computeroutput">Warning: set address range perms: large range |
| 3230 |
<number></code></p> |
| 3231 |
<p>Diagnostic message, mostly for benefit of the Valgrind |
| 3232 |
developers, to do with memory permissions.</p> |
| 3233 |
</li> |
| 3234 |
</ul></div> |
| 3235 |
</div> |
| 3236 |
</div> |
| 3237 |
<div> |
| 3238 |
<br><table class="nav" width="100%" cellspacing="3" cellpadding="2" border="0" summary="Navigation footer"> |
| 3239 |
<tr> |
| 3240 |
<td rowspan="2" width="40%" align="left"> |
| 3241 |
<a accesskey="p" href="manual-intro.html"><< 1. Introduction</a> </td> |
| 3242 |
<td width="20%" align="center"><a accesskey="u" href="manual.html">Up</a></td> |
| 3243 |
<td rowspan="2" width="40%" align="right"> <a accesskey="n" href="manual-core-adv.html">3. Using and understanding the Valgrind core: Advanced Topics >></a> |
| 3244 |
</td> |
| 3245 |
</tr> |
| 3246 |
<tr><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td></tr> |
| 3247 |
</table> |
| 3248 |
</div> |
| 3249 |
</body> |
| 3250 |
</html> |