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