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 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 155 | <sect1 id="manual-core.comment" xreflabel="The Commentary"> |
| 156 | <title>The Commentary</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 157 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 158 | <para>Valgrind tools write a commentary, a stream of text, detailing |
| 159 | error reports and other significant events. All lines in the commentary |
| 160 | have following form: |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 161 | |
| 162 | <programlisting><![CDATA[ |
| 163 | ==12345== some-message-from-Valgrind]]></programlisting> |
| 164 | </para> |
| 165 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 166 | <para>The <computeroutput>12345</computeroutput> is the process ID. |
| 167 | This scheme makes it easy to distinguish program output from Valgrind |
| 168 | commentary, and also easy to differentiate commentaries from different |
| 169 | processes which have become merged together, for whatever reason.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 170 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 171 | <para>By default, Valgrind tools write only essential messages to the |
| 172 | commentary, so as to avoid flooding you with information of secondary |
| 173 | importance. If you want more information about what is happening, |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 174 | re-run, passing the <option>-v</option> option to Valgrind. A second |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 175 | <option>-v</option> gives yet more detail. |
sewardj | 053fe98 | 2005-11-15 19:51:04 +0000 | [diff] [blame] | 176 | </para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 177 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 178 | <para>You can direct the commentary to three different places:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 179 | |
| 180 | <orderedlist> |
| 181 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 182 | <listitem id="manual-core.out2fd" xreflabel="Directing output to fd"> |
| 183 | <para>The default: send it to a file descriptor, which is by default |
| 184 | 2 (stderr). So, if you give the core no options, it will write |
| 185 | commentary to the standard error stream. If you want to send it to |
| 186 | some other file descriptor, for example number 9, you can specify |
| 187 | <option>--log-fd=9</option>.</para> |
| 188 | |
| 189 | <para>This is the simplest and most common arrangement, but can |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 190 | cause problems when Valgrinding entire trees of processes which |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 191 | expect specific file descriptors, particularly stdin/stdout/stderr, |
| 192 | to be available for their own use.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 193 | </listitem> |
| 194 | |
| 195 | <listitem id="manual-core.out2file" |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 196 | xreflabel="Directing output to file"> <para>A less intrusive |
| 197 | option is to write the commentary to a file, which you specify by |
njn | 374a36d | 2007-11-23 01:41:32 +0000 | [diff] [blame] | 198 | <option>--log-file=filename</option>. There are special format |
| 199 | specifiers that can be used to use a process ID or an environment |
| 200 | variable name in the log file name. These are useful/necessary if your |
| 201 | program invokes multiple processes (especially for MPI programs). |
| 202 | See the <link linkend="manual-core.basicopts">basic options section</link> |
| 203 | for more details.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 204 | </listitem> |
| 205 | |
| 206 | <listitem id="manual-core.out2socket" |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 207 | xreflabel="Directing output to network socket"> <para>The |
| 208 | least intrusive option is to send the commentary to a network |
| 209 | socket. The socket is specified as an IP address and port number |
| 210 | pair, like this: <option>--log-socket=192.168.0.1:12345</option> if |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 211 | you want to send the output to host IP 192.168.0.1 port 12345 |
| 212 | (note: we |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 213 | have no idea if 12345 is a port of pre-existing significance). You |
| 214 | can also omit the port number: |
| 215 | <option>--log-socket=192.168.0.1</option>, in which case a default |
| 216 | port of 1500 is used. This default is defined by the constant |
| 217 | <computeroutput>VG_CLO_DEFAULT_LOGPORT</computeroutput> in the |
| 218 | sources.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 219 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 220 | <para>Note, unfortunately, that you have to use an IP address here, |
| 221 | rather than a hostname.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 222 | |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 223 | <para>Writing to a network socket is pointless if you don't |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 224 | have something listening at the other end. We provide a simple |
| 225 | listener program, |
| 226 | <computeroutput>valgrind-listener</computeroutput>, which accepts |
| 227 | connections on the specified port and copies whatever it is sent to |
| 228 | stdout. Probably someone will tell us this is a horrible security |
| 229 | risk. It seems likely that people will write more sophisticated |
| 230 | listeners in the fullness of time.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 231 | |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 232 | <para><computeroutput>valgrind-listener</computeroutput> can accept |
| 233 | simultaneous connections from up to 50 Valgrinded processes. In front |
| 234 | of each line of output it prints the current number of active |
| 235 | connections in round brackets.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 236 | |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 237 | <para><computeroutput>valgrind-listener</computeroutput> accepts two |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 238 | command-line options:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 239 | <itemizedlist> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 240 | <listitem> |
| 241 | <para><option>-e</option> or <option>--exit-at-zero</option>: |
| 242 | when the number of connected processes falls back to zero, |
| 243 | exit. Without this, it will run forever, that is, until you |
| 244 | send it Control-C.</para> |
| 245 | </listitem> |
| 246 | <listitem> |
| 247 | <para><option>portnumber</option>: changes the port it listens |
| 248 | on from the default (1500). The specified port must be in the |
| 249 | range 1024 to 65535. The same restriction applies to port |
| 250 | numbers specified by a <option>--log-socket</option> to |
| 251 | Valgrind itself.</para> |
| 252 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 253 | </itemizedlist> |
| 254 | |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 255 | <para>If a Valgrinded process fails to connect to a listener, for |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 256 | whatever reason (the listener isn't running, invalid or unreachable |
| 257 | host or port, etc), Valgrind switches back to writing the commentary |
| 258 | to stderr. The same goes for any process which loses an established |
| 259 | connection to a listener. In other words, killing the listener |
| 260 | doesn't kill the processes sending data to it.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 261 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 262 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 263 | </orderedlist> |
| 264 | |
| 265 | <para>Here is an important point about the relationship between the |
| 266 | commentary and profiling output from tools. The commentary contains a |
| 267 | mix of messages from the Valgrind core and the selected tool. If the |
| 268 | tool reports errors, it will report them to the commentary. However, if |
| 269 | the tool does profiling, the profile data will be written to a file of |
| 270 | some kind, depending on the tool, and independent of what |
| 271 | <option>--log-*</option> options are in force. The commentary is |
| 272 | intended to be a low-bandwidth, human-readable channel. Profiling data, |
| 273 | on the other hand, is usually voluminous and not meaningful without |
| 274 | further processing, which is why we have chosen this arrangement.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 275 | |
| 276 | </sect1> |
| 277 | |
| 278 | |
| 279 | <sect1 id="manual-core.report" xreflabel="Reporting of errors"> |
| 280 | <title>Reporting of errors</title> |
| 281 | |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 282 | <para>When an error-checking tool |
| 283 | detects something bad happening in the program, an error |
| 284 | message is written to the commentary. Here's an example from Memcheck:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 285 | |
| 286 | <programlisting><![CDATA[ |
| 287 | ==25832== Invalid read of size 4 |
| 288 | ==25832== at 0x8048724: BandMatrix::ReSize(int, int, int) (bogon.cpp:45) |
| 289 | ==25832== by 0x80487AF: main (bogon.cpp:66) |
njn | 21f9195 | 2005-03-12 22:14:42 +0000 | [diff] [blame] | 290 | ==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd]]></programlisting> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 291 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 292 | <para>This message says that the program did an illegal 4-byte read of |
| 293 | address 0xBFFFF74C, which, as far as Memcheck can tell, is not a valid |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 294 | stack address, nor corresponds to any current heap blocks or recently freed |
| 295 | heap blocks. The read is happening at line 45 of |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 296 | <filename>bogon.cpp</filename>, called from line 66 of the same file, |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 297 | etc. For errors associated with an identified (current or freed) heap block, |
| 298 | for example reading freed memory, Valgrind reports not only the |
| 299 | location where the error happened, but also where the associated heap block |
| 300 | was allocated/freed.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 301 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 302 | <para>Valgrind remembers all error reports. When an error is detected, |
| 303 | it is compared against old reports, to see if it is a duplicate. If so, |
| 304 | the error is noted, but no further commentary is emitted. This avoids |
| 305 | you being swamped with bazillions of duplicate error reports.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 306 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 307 | <para>If you want to know how many times each error occurred, run with |
| 308 | the <option>-v</option> option. When execution finishes, all the |
| 309 | reports are printed out, along with, and sorted by, their occurrence |
| 310 | counts. This makes it easy to see which errors have occurred most |
| 311 | frequently.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 312 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 313 | <para>Errors are reported before the associated operation actually |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 314 | happens. For example, if you're using Memcheck and your program attempts to |
| 315 | read from address zero, Memcheck will emit a message to this effect, and |
| 316 | your program will then likely die with a segmentation fault.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 317 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 318 | <para>In general, you should try and fix errors in the order that they |
| 319 | are reported. Not doing so can be confusing. For example, a program |
| 320 | which copies uninitialised values to several memory locations, and later |
| 321 | uses them, will generate several error messages, when run on Memcheck. |
| 322 | The first such error message may well give the most direct clue to the |
| 323 | root cause of the problem.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 324 | |
| 325 | <para>The process of detecting duplicate errors is quite an |
| 326 | expensive one and can become a significant performance overhead |
| 327 | if your program generates huge quantities of errors. To avoid |
sewardj | 053fe98 | 2005-11-15 19:51:04 +0000 | [diff] [blame] | 328 | serious problems, Valgrind will simply stop collecting |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 329 | 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] | 330 | in total have been seen. In this situation you might as well |
| 331 | stop your program and fix it, because Valgrind won't tell you |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 332 | 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] | 333 | apply after suppressed errors are removed. These limits are |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 334 | defined in <filename>m_errormgr.c</filename> and can be increased |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 335 | if necessary.</para> |
| 336 | |
| 337 | <para>To avoid this cutoff you can use the |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 338 | <option>--error-limit=no</option> option. Then Valgrind will always show |
| 339 | errors, regardless of how many there are. Use this option carefully, |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 340 | since it may have a bad effect on performance.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 341 | |
| 342 | </sect1> |
| 343 | |
| 344 | |
| 345 | <sect1 id="manual-core.suppress" xreflabel="Suppressing errors"> |
| 346 | <title>Suppressing errors</title> |
| 347 | |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 348 | <para>The error-checking tools detect numerous problems in the system |
| 349 | libraries, such as the C library, |
| 350 | which come pre-installed with your OS. You can't easily fix |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 351 | these, but you don't want to see these errors (and yes, there are many!) |
| 352 | So Valgrind reads a list of errors to suppress at startup. A default |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 353 | suppression file is created by the |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 354 | <computeroutput>./configure</computeroutput> script when the system is |
| 355 | built.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 356 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 357 | <para>You can modify and add to the suppressions file at your leisure, |
| 358 | or, better, write your own. Multiple suppression files are allowed. |
| 359 | This is useful if part of your project contains errors you can't or |
| 360 | don't want to fix, yet you don't want to continuously be reminded of |
| 361 | them.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 362 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 363 | <formalpara><title>Note:</title> <para>By far the easiest way to add |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 364 | suppressions is to use the <option>--gen-suppressions=yes</option> option |
| 365 | described in <xref linkend="manual-core.options"/>. This generates |
sewardj | 9a0132d | 2008-11-04 11:29:19 +0000 | [diff] [blame] | 366 | suppressions automatically. For best results, |
| 367 | though, you may want to edit the output |
| 368 | of <option>--gen-suppressions=yes</option> by hand, in which |
| 369 | case it would be advisable to read through this section. |
| 370 | </para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 371 | </formalpara> |
| 372 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 373 | <para>Each error to be suppressed is described very specifically, to |
bart | 8b6b54b | 2009-07-19 08:16:30 +0000 | [diff] [blame] | 374 | minimise the possibility that a suppression-directive inadvertently |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 375 | suppresses a bunch of similar errors which you did want to see. The |
| 376 | suppression mechanism is designed to allow precise yet flexible |
| 377 | specification of errors to suppress.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 378 | |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 379 | <para>If you use the <option>-v</option> option, at the end of execution, |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 380 | Valgrind prints out one line for each used suppression, giving its name |
| 381 | and the number of times it got used. Here's the suppressions used by a |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 382 | run of <computeroutput>valgrind --tool=memcheck ls -l</computeroutput>:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 383 | |
| 384 | <programlisting><![CDATA[ |
| 385 | --27579-- supp: 1 socketcall.connect(serv_addr)/__libc_connect/__nscd_getgrgid_r |
| 386 | --27579-- supp: 1 socketcall.connect(serv_addr)/__libc_connect/__nscd_getpwuid_r |
| 387 | --27579-- supp: 6 strrchr/_dl_map_object_from_fd/_dl_map_object]]></programlisting> |
| 388 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 389 | <para>Multiple suppressions files are allowed. By default, Valgrind |
| 390 | uses <filename>$PREFIX/lib/valgrind/default.supp</filename>. You can |
| 391 | ask to add suppressions from another file, by specifying |
| 392 | <option>--suppressions=/path/to/file.supp</option>. |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 393 | </para> |
| 394 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 395 | <para>If you want to understand more about suppressions, look at an |
| 396 | existing suppressions file whilst reading the following documentation. |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 397 | The file <filename>glibc-2.3.supp</filename>, in the source |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 398 | distribution, provides some good examples.</para> |
| 399 | |
| 400 | <para>Each suppression has the following components:</para> |
| 401 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 402 | <itemizedlist> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 403 | |
| 404 | <listitem> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 405 | <para>First line: its name. This merely gives a handy name to the |
| 406 | suppression, by which it is referred to in the summary of used |
| 407 | suppressions printed out when a program finishes. It's not |
| 408 | important what the name is; any identifying string will do.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 409 | </listitem> |
| 410 | |
| 411 | <listitem> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 412 | <para>Second line: name of the tool(s) that the suppression is for |
| 413 | (if more than one, comma-separated), and the name of the suppression |
sewardj | 3387889 | 2007-11-17 09:43:25 +0000 | [diff] [blame] | 414 | itself, separated by a colon (n.b.: no spaces are allowed), eg:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 415 | <programlisting><![CDATA[ |
| 416 | tool_name1,tool_name2:suppression_name]]></programlisting> |
| 417 | |
sewardj | f5fa3bd | 2006-03-14 00:56:29 +0000 | [diff] [blame] | 418 | <para>Recall that Valgrind is a modular system, in which |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 419 | different instrumentation tools can observe your program whilst it |
| 420 | is running. Since different tools detect different kinds of errors, |
| 421 | it is necessary to say which tool(s) the suppression is meaningful |
| 422 | to.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 423 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 424 | <para>Tools will complain, at startup, if a tool does not understand |
| 425 | any suppression directed to it. Tools ignore suppressions which are |
| 426 | not directed to them. As a result, it is quite practical to put |
| 427 | suppressions for all tools into the same suppression file.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 428 | </listitem> |
| 429 | |
| 430 | <listitem> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 431 | <para>Next line: a small number of suppression types have extra |
| 432 | information after the second line (eg. the <varname>Param</varname> |
| 433 | suppression for Memcheck)</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 434 | </listitem> |
| 435 | |
| 436 | <listitem> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 437 | <para>Remaining lines: This is the calling context for the error -- |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 438 | the chain of function calls that led to it. There can be up to 24 |
| 439 | of these lines.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 440 | |
sewardj | 6629325 | 2008-11-04 01:38:02 +0000 | [diff] [blame] | 441 | <para>Locations may be names of either shared objects or |
| 442 | functions. They begin |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 443 | <computeroutput>obj:</computeroutput> and |
| 444 | <computeroutput>fun:</computeroutput> respectively. Function and |
| 445 | object names to match against may use the wildcard characters |
| 446 | <computeroutput>*</computeroutput> and |
| 447 | <computeroutput>?</computeroutput>.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 448 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 449 | <para><command>Important note: </command> C++ function names must be |
| 450 | <command>mangled</command>. If you are writing suppressions by |
| 451 | hand, use the <option>--demangle=no</option> option to get the |
sewardj | 6629325 | 2008-11-04 01:38:02 +0000 | [diff] [blame] | 452 | mangled names in your error messages. An example of a mangled |
| 453 | C++ name is <computeroutput>_ZN9QListView4showEv</computeroutput>. |
| 454 | This is the form that the GNU C++ compiler uses internally, and |
| 455 | the form that must be used in suppression files. The equivalent |
| 456 | demangled name, <computeroutput>QListView::show()</computeroutput>, |
| 457 | is what you see at the C++ source code level. |
| 458 | </para> |
| 459 | |
| 460 | <para>A location line may also be |
| 461 | simply "<computeroutput>...</computeroutput>" (three dots). This is |
| 462 | a frame-level wildcard, which matches zero or more frames. Frame |
| 463 | level wildcards are useful because they make it easy to ignore |
| 464 | varying numbers of uninteresting frames in between frames of |
| 465 | interest. That is often important when writing suppressions which |
| 466 | are intended to be robust against variations in the amount of |
| 467 | function inlining done by compilers.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 468 | </listitem> |
| 469 | |
| 470 | <listitem> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 471 | <para>Finally, the entire suppression must be between curly |
| 472 | braces. Each brace must be the first character on its own |
| 473 | line.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 474 | </listitem> |
| 475 | |
| 476 | </itemizedlist> |
| 477 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 478 | <para>A suppression only suppresses an error when the error matches all |
| 479 | the details in the suppression. Here's an example:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 480 | |
| 481 | <programlisting><![CDATA[ |
| 482 | { |
| 483 | __gconv_transform_ascii_internal/__mbrtowc/mbtowc |
| 484 | Memcheck:Value4 |
| 485 | fun:__gconv_transform_ascii_internal |
| 486 | fun:__mbr*toc |
| 487 | fun:mbtowc |
| 488 | }]]></programlisting> |
| 489 | |
| 490 | |
| 491 | <para>What it means is: for Memcheck only, suppress a |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 492 | use-of-uninitialised-value error, when the data size is 4, when it |
| 493 | occurs in the function |
| 494 | <computeroutput>__gconv_transform_ascii_internal</computeroutput>, when |
| 495 | that is called from any function of name matching |
| 496 | <computeroutput>__mbr*toc</computeroutput>, when that is called from |
| 497 | <computeroutput>mbtowc</computeroutput>. It doesn't apply under any |
| 498 | other circumstances. The string by which this suppression is identified |
| 499 | to the user is |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 500 | <computeroutput>__gconv_transform_ascii_internal/__mbrtowc/mbtowc</computeroutput>.</para> |
| 501 | |
| 502 | <para>(See <xref linkend="mc-manual.suppfiles"/> for more details |
| 503 | on the specifics of Memcheck's suppression kinds.)</para> |
| 504 | |
| 505 | <para>Another example, again for the Memcheck tool:</para> |
| 506 | |
| 507 | <programlisting><![CDATA[ |
| 508 | { |
| 509 | libX11.so.6.2/libX11.so.6.2/libXaw.so.7.0 |
| 510 | Memcheck:Value4 |
| 511 | obj:/usr/X11R6/lib/libX11.so.6.2 |
| 512 | obj:/usr/X11R6/lib/libX11.so.6.2 |
| 513 | obj:/usr/X11R6/lib/libXaw.so.7.0 |
| 514 | }]]></programlisting> |
| 515 | |
sewardj | 6629325 | 2008-11-04 01:38:02 +0000 | [diff] [blame] | 516 | <para>This suppresses any size 4 uninitialised-value error which occurs |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 517 | anywhere in <filename>libX11.so.6.2</filename>, when called from |
| 518 | anywhere in the same library, when called from anywhere in |
| 519 | <filename>libXaw.so.7.0</filename>. The inexact specification of |
| 520 | locations is regrettable, but is about all you can hope for, given that |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 521 | the X11 libraries shipped on the Linux distro on which this example |
| 522 | was made have had their symbol tables removed.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 523 | |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 524 | <para>Although the above two examples do not make this clear, you can |
| 525 | freely mix <computeroutput>obj:</computeroutput> and |
| 526 | <computeroutput>fun:</computeroutput> lines in a suppression.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 527 | |
sewardj | 6629325 | 2008-11-04 01:38:02 +0000 | [diff] [blame] | 528 | <para>Finally, here's an example using three frame-level wildcards:</para> |
| 529 | |
| 530 | <programlisting><![CDATA[ |
| 531 | { |
| 532 | a-contrived-example |
| 533 | Memcheck:Leak |
| 534 | fun:malloc |
| 535 | ... |
| 536 | fun:ddd |
| 537 | ... |
| 538 | fun:ccc |
| 539 | ... |
| 540 | fun:main |
| 541 | } |
| 542 | ]]></programlisting> |
| 543 | This suppresses Memcheck memory-leak errors, in the case where |
| 544 | the allocation was done by <computeroutput>main</computeroutput> |
| 545 | calling (though any number of intermediaries, including zero) |
| 546 | <computeroutput>ccc</computeroutput>, |
| 547 | calling onwards via |
| 548 | <computeroutput>ddd</computeroutput> and eventually |
| 549 | to <computeroutput>malloc.</computeroutput>. |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 550 | </sect1> |
| 551 | |
| 552 | |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 553 | <sect1 id="manual-core.options" |
| 554 | xreflabel="Core Command-line Options"> |
| 555 | <title>Core Command-line Options</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 556 | |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 557 | <para>As mentioned above, Valgrind's core accepts a common set of options. |
| 558 | The tools also accept tool-specific options, which are documented |
sewardj | 3387889 | 2007-11-17 09:43:25 +0000 | [diff] [blame] | 559 | separately for each tool.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 560 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 561 | <para>Valgrind's default settings succeed in giving reasonable behaviour |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 562 | in most cases. We group the available options by rough categories.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 563 | |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 564 | <sect2 id="manual-core.toolopts" xreflabel="Tool-selection Option"> |
| 565 | <title>Tool-selection Option</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 566 | |
| 567 | <para>The single most important option.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 568 | |
sewardj | 6ea37fe | 2009-07-15 14:52:52 +0000 | [diff] [blame] | 569 | <variablelist> |
| 570 | |
| 571 | <varlistentry id="tool_name" xreflabel="--tool"> |
| 572 | <term> |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 573 | <option><![CDATA[--tool=<toolname> [default: memcheck] ]]></option> |
sewardj | 6ea37fe | 2009-07-15 14:52:52 +0000 | [diff] [blame] | 574 | </term> |
| 575 | <listitem> |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 576 | <para>Run the Valgrind tool called <varname>toolname</varname>, |
sewardj | 6ea37fe | 2009-07-15 14:52:52 +0000 | [diff] [blame] | 577 | e.g. Memcheck, Cachegrind, etc.</para> |
| 578 | </listitem> |
| 579 | </varlistentry> |
| 580 | |
| 581 | </variablelist> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 582 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 583 | </sect2> |
| 584 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 585 | |
| 586 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 587 | <sect2 id="manual-core.basicopts" xreflabel="Basic Options"> |
| 588 | <title>Basic Options</title> |
| 589 | |
de | 03e0e7c | 2005-12-03 23:02:33 +0000 | [diff] [blame] | 590 | <!-- start of xi:include in the manpage --> |
| 591 | <para id="basic.opts.para">These options work with all tools.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 592 | |
de | 03e0e7c | 2005-12-03 23:02:33 +0000 | [diff] [blame] | 593 | <variablelist id="basic.opts.list"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 594 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 595 | <varlistentry id="opt.help" xreflabel="--help"> |
| 596 | <term><option>-h --help</option></term> |
| 597 | <listitem> |
| 598 | <para>Show help for all options, both for the core and for the |
njn | cce38e6 | 2010-07-06 04:25:12 +0000 | [diff] [blame] | 599 | selected tool. If the option is repeated it is equivalent to giving |
| 600 | <option>--help-debug</option>.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 601 | </listitem> |
| 602 | </varlistentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 603 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 604 | <varlistentry id="opt.help-debug" xreflabel="--help-debug"> |
| 605 | <term><option>--help-debug</option></term> |
| 606 | <listitem> |
| 607 | <para>Same as <option>--help</option>, but also lists debugging |
| 608 | options which usually are only of use to Valgrind's |
| 609 | developers.</para> |
| 610 | </listitem> |
| 611 | </varlistentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 612 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 613 | <varlistentry id="opt.version" xreflabel="--version"> |
| 614 | <term><option>--version</option></term> |
| 615 | <listitem> |
| 616 | <para>Show the version number of the Valgrind core. Tools can have |
| 617 | their own version numbers. There is a scheme in place to ensure |
| 618 | that tools only execute when the core version is one they are |
| 619 | known to work with. This was done to minimise the chances of |
| 620 | strange problems arising from tool-vs-core version |
| 621 | incompatibilities.</para> |
| 622 | </listitem> |
| 623 | </varlistentry> |
njn | 5127298 | 2005-07-25 23:18:44 +0000 | [diff] [blame] | 624 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 625 | <varlistentry id="opt.quiet" xreflabel="--quiet"> |
njn | 7e5d4ed | 2009-07-30 02:57:52 +0000 | [diff] [blame] | 626 | <term><option>-q</option>, <option>--quiet</option></term> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 627 | <listitem> |
| 628 | <para>Run silently, and only print error messages. Useful if you |
| 629 | are running regression tests or have some other automated test |
| 630 | machinery.</para> |
| 631 | </listitem> |
| 632 | </varlistentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 633 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 634 | <varlistentry id="opt.verbose" xreflabel="--verbose"> |
njn | 7e5d4ed | 2009-07-30 02:57:52 +0000 | [diff] [blame] | 635 | <term><option>-v</option>, <option>--verbose</option></term> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 636 | <listitem> |
| 637 | <para>Be more verbose. Gives extra information on various aspects |
| 638 | of your program, such as: the shared objects loaded, the |
| 639 | suppressions used, the progress of the instrumentation and |
| 640 | execution engines, and warnings about unusual behaviour. Repeating |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 641 | the option increases the verbosity level.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 642 | </listitem> |
| 643 | </varlistentry> |
sewardj | 053fe98 | 2005-11-15 19:51:04 +0000 | [diff] [blame] | 644 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 645 | <varlistentry id="opt.trace-children" xreflabel="--trace-children"> |
| 646 | <term> |
| 647 | <option><![CDATA[--trace-children=<yes|no> [default: no] ]]></option> |
| 648 | </term> |
| 649 | <listitem> |
njn | ae44c38 | 2007-05-15 03:59:23 +0000 | [diff] [blame] | 650 | <para>When enabled, Valgrind will trace into sub-processes |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 651 | initiated via the <varname>exec</varname> system call. This is |
| 652 | necessary for multi-process programs. |
njn | ae44c38 | 2007-05-15 03:59:23 +0000 | [diff] [blame] | 653 | </para> |
| 654 | <para>Note that Valgrind does trace into the child of a |
sewardj | 79c62bc | 2007-11-28 01:55:29 +0000 | [diff] [blame] | 655 | <varname>fork</varname> (it would be difficult not to, since |
njn | ae44c38 | 2007-05-15 03:59:23 +0000 | [diff] [blame] | 656 | <varname>fork</varname> makes an identical copy of a process), so this |
| 657 | option is arguably badly named. However, most children of |
| 658 | <varname>fork</varname> calls immediately call <varname>exec</varname> |
| 659 | anyway. |
| 660 | </para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 661 | </listitem> |
| 662 | </varlistentry> |
njn | 5127298 | 2005-07-25 23:18:44 +0000 | [diff] [blame] | 663 | |
sewardj | 0642127 | 2009-11-05 08:55:13 +0000 | [diff] [blame] | 664 | <varlistentry id="opt.trace-children-skip" xreflabel="--trace-children-skip"> |
| 665 | <term> |
sewardj | 9ab64a4 | 2010-12-06 11:40:04 +0000 | [diff] [blame^] | 666 | <option><![CDATA[--trace-children-skip=patt1,patt2,... ]]></option> |
sewardj | 0642127 | 2009-11-05 08:55:13 +0000 | [diff] [blame] | 667 | </term> |
| 668 | <listitem> |
| 669 | <para>This option only has an effect when |
| 670 | <option>--trace-children=yes</option> is specified. It allows |
| 671 | for some children to be skipped. The option takes a comma |
| 672 | separated list of patterns for the names of child executables |
| 673 | that Valgrind should not trace into. Patterns may include the |
| 674 | metacharacters <computeroutput>?</computeroutput> |
| 675 | and <computeroutput>*</computeroutput>, which have the usual |
| 676 | meaning.</para> |
| 677 | <para> |
| 678 | This can be useful for pruning uninteresting branches from a |
| 679 | tree of processes being run on Valgrind. But you should be |
| 680 | careful when using it. When Valgrind skips tracing into an |
| 681 | executable, it doesn't just skip tracing that executable, it |
| 682 | also skips tracing any of that executable's child processes. |
| 683 | In other words, the flag doesn't merely cause tracing to stop |
| 684 | at the specified executables -- it skips tracing of entire |
| 685 | process subtrees rooted at any of the specified |
| 686 | executables.</para> |
| 687 | </listitem> |
| 688 | </varlistentry> |
| 689 | |
sewardj | 9ab64a4 | 2010-12-06 11:40:04 +0000 | [diff] [blame^] | 690 | <varlistentry id="opt.trace-children-skip-by-arg" |
| 691 | xreflabel="--trace-children-skip-by-arg"> |
| 692 | <term> |
| 693 | <option><![CDATA[--trace-children-skip-by-arg=patt1,patt2,... ]]></option> |
| 694 | </term> |
| 695 | <listitem> |
| 696 | <para>This is the same as |
| 697 | <option>--trace-children-skip</option>, with one difference: |
| 698 | the decision as to whether to trace into a child process is |
| 699 | made by examining the arguments to the child process, rather |
| 700 | than the name of its executable.</para> |
| 701 | </listitem> |
| 702 | </varlistentry> |
| 703 | |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 704 | <varlistentry id="opt.child-silent-after-fork" |
| 705 | xreflabel="--child-silent-after-fork"> |
| 706 | <term> |
| 707 | <option><![CDATA[--child-silent-after-fork=<yes|no> [default: no] ]]></option> |
| 708 | </term> |
| 709 | <listitem> |
| 710 | <para>When enabled, Valgrind will not show any debugging or |
| 711 | logging output for the child process resulting from |
| 712 | a <varname>fork</varname> call. This can make the output less |
| 713 | confusing (although more misleading) when dealing with processes |
| 714 | that create children. It is particularly useful in conjunction |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 715 | with <varname>--trace-children=</varname>. Use of this option is also |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 716 | strongly recommended if you are requesting XML output |
| 717 | (<varname>--xml=yes</varname>), since otherwise the XML from child and |
| 718 | parent may become mixed up, which usually makes it useless. |
| 719 | </para> |
| 720 | </listitem> |
| 721 | </varlistentry> |
| 722 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 723 | <varlistentry id="opt.track-fds" xreflabel="--track-fds"> |
| 724 | <term> |
| 725 | <option><![CDATA[--track-fds=<yes|no> [default: no] ]]></option> |
| 726 | </term> |
| 727 | <listitem> |
| 728 | <para>When enabled, Valgrind will print out a list of open file |
| 729 | descriptors on exit. Along with each file descriptor is printed a |
| 730 | stack backtrace of where the file was opened and any details |
| 731 | relating to the file descriptor such as the file name or socket |
| 732 | details.</para> |
| 733 | </listitem> |
| 734 | </varlistentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 735 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 736 | <varlistentry id="opt.time-stamp" xreflabel="--time-stamp"> |
| 737 | <term> |
| 738 | <option><![CDATA[--time-stamp=<yes|no> [default: no] ]]></option> |
| 739 | </term> |
| 740 | <listitem> |
| 741 | <para>When enabled, each message is preceded with an indication of |
| 742 | the elapsed wallclock time since startup, expressed as days, |
| 743 | hours, minutes, seconds and milliseconds.</para> |
| 744 | </listitem> |
| 745 | </varlistentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 746 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 747 | <varlistentry id="opt.log-fd" xreflabel="--log-fd"> |
| 748 | <term> |
| 749 | <option><![CDATA[--log-fd=<number> [default: 2, stderr] ]]></option> |
| 750 | </term> |
| 751 | <listitem> |
| 752 | <para>Specifies that Valgrind should send all of its messages to |
| 753 | the specified file descriptor. The default, 2, is the standard |
| 754 | error channel (stderr). Note that this may interfere with the |
| 755 | client's own use of stderr, as Valgrind's output will be |
| 756 | interleaved with any output that the client sends to |
| 757 | stderr.</para> |
| 758 | </listitem> |
| 759 | </varlistentry> |
njn | 779a2d6 | 2005-07-25 00:12:19 +0000 | [diff] [blame] | 760 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 761 | <varlistentry id="opt.log-file" xreflabel="--log-file"> |
| 762 | <term> |
| 763 | <option><![CDATA[--log-file=<filename> ]]></option> |
| 764 | </term> |
| 765 | <listitem> |
| 766 | <para>Specifies that Valgrind should send all of its messages to |
njn | 374a36d | 2007-11-23 01:41:32 +0000 | [diff] [blame] | 767 | the specified file. If the file name is empty, it causes an abort. |
| 768 | There are three special format specifiers that can be used in the file |
| 769 | name.</para> |
njn | 779a2d6 | 2005-07-25 00:12:19 +0000 | [diff] [blame] | 770 | |
njn | 374a36d | 2007-11-23 01:41:32 +0000 | [diff] [blame] | 771 | <para><option>%p</option> is replaced with the current process ID. |
| 772 | This is very useful for program that invoke multiple processes. |
| 773 | WARNING: If you use <option>--trace-children=yes</option> and your |
njn | 7064fb2 | 2008-05-29 23:09:52 +0000 | [diff] [blame] | 774 | program invokes multiple processes OR your program forks without |
| 775 | calling exec afterwards, and you don't use this specifier |
njn | 374a36d | 2007-11-23 01:41:32 +0000 | [diff] [blame] | 776 | (or the <option>%q</option> specifier below), the Valgrind output from |
| 777 | all those processes will go into one file, possibly jumbled up, and |
njn | 498685c | 2007-09-17 23:15:35 +0000 | [diff] [blame] | 778 | possibly incomplete.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 779 | |
njn | 374a36d | 2007-11-23 01:41:32 +0000 | [diff] [blame] | 780 | <para><option>%q{FOO}</option> is replaced with the contents of the |
| 781 | environment variable <varname>FOO</varname>. If the |
| 782 | <option>{FOO}</option> part is malformed, it causes an abort. This |
| 783 | specifier is rarely needed, but very useful in certain circumstances |
| 784 | (eg. when running MPI programs). The idea is that you specify a |
| 785 | variable which will be set differently for each process in the job, |
| 786 | for example <computeroutput>BPROC_RANK</computeroutput> or whatever is |
| 787 | applicable in your MPI setup. If the named environment variable is not |
| 788 | set, it causes an abort. Note that in some shells, the |
| 789 | <option>{</option> and <option>}</option> characters may need to be |
| 790 | escaped with a backslash.</para> |
| 791 | |
| 792 | <para><option>%%</option> is replaced with <option>%</option>.</para> |
| 793 | |
| 794 | <para>If an <option>%</option> is followed by any other character, it |
| 795 | causes an abort.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 796 | </listitem> |
| 797 | </varlistentry> |
| 798 | |
| 799 | <varlistentry id="opt.log-socket" xreflabel="--log-socket"> |
| 800 | <term> |
| 801 | <option><![CDATA[--log-socket=<ip-address:port-number> ]]></option> |
| 802 | </term> |
| 803 | <listitem> |
| 804 | <para>Specifies that Valgrind should send all of its messages to |
| 805 | the specified port at the specified IP address. The port may be |
| 806 | omitted, in which case port 1500 is used. If a connection cannot |
| 807 | be made to the specified socket, Valgrind falls back to writing |
| 808 | output to the standard error (stderr). This option is intended to |
| 809 | be used in conjunction with the |
| 810 | <computeroutput>valgrind-listener</computeroutput> program. For |
| 811 | further details, see |
sewardj | 3387889 | 2007-11-17 09:43:25 +0000 | [diff] [blame] | 812 | <link linkend="manual-core.comment">the commentary</link> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 813 | in the manual.</para> |
| 814 | </listitem> |
| 815 | </varlistentry> |
| 816 | |
| 817 | </variablelist> |
de | 03e0e7c | 2005-12-03 23:02:33 +0000 | [diff] [blame] | 818 | <!-- end of xi:include in the manpage --> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 819 | |
| 820 | </sect2> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 821 | |
| 822 | |
| 823 | <sect2 id="manual-core.erropts" xreflabel="Error-related Options"> |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 824 | <title>Error-related Options</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 825 | |
de | 03e0e7c | 2005-12-03 23:02:33 +0000 | [diff] [blame] | 826 | <!-- start of xi:include in the manpage --> |
| 827 | <para id="error-related.opts.para">These options are used by all tools |
| 828 | that can report errors, e.g. Memcheck, but not Cachegrind.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 829 | |
de | 03e0e7c | 2005-12-03 23:02:33 +0000 | [diff] [blame] | 830 | <variablelist id="error-related.opts.list"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 831 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 832 | <varlistentry id="opt.xml" xreflabel="--xml"> |
| 833 | <term> |
| 834 | <option><![CDATA[--xml=<yes|no> [default: no] ]]></option> |
| 835 | </term> |
| 836 | <listitem> |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 837 | <para>When enabled, the important parts of the output (e.g. tool error |
| 838 | messages) will be in XML format rather than plain text. Furthermore, |
| 839 | the XML output will be sent to a different output channel than the |
| 840 | plain text output. Therefore, you also must use one of |
| 841 | <option>--xml-fd</option>, <option>--xml-file</option> or |
| 842 | <option>--xml-socket</option> to specify where the XML is to be sent. |
| 843 | </para> |
| 844 | |
| 845 | <para>Less important messages will still be printed in plain text, but |
| 846 | because the XML output and plain text output are sent to different |
| 847 | output channels (the destination of the plain text output is still |
| 848 | controlled by <option>--log-fd</option>, <option>--log-file</option> |
| 849 | and <option>--log-socket</option>) this should not cause problems. |
| 850 | </para> |
| 851 | |
| 852 | <para>This option is aimed at making life easier for tools that consume |
| 853 | Valgrind's output as input, such as GUI front ends. Currently this |
| 854 | option works with Memcheck, Helgrind and Ptrcheck. The output format |
| 855 | is specified in the file |
sewardj | 6ea37fe | 2009-07-15 14:52:52 +0000 | [diff] [blame] | 856 | <computeroutput>docs/internals/xml-output-protocol4.txt</computeroutput> |
| 857 | in the source tree for Valgrind 3.5.0 or later.</para> |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 858 | |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 859 | <para>The recommended options for a GUI to pass, when requesting |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 860 | XML output, are: <option>--xml=yes</option> to enable XML output, |
| 861 | <option>--xml-file</option> to send the XML output to a (presumably |
| 862 | GUI-selected) file, <option>--log-file</option> to send the plain |
| 863 | text output to a second GUI-selected file, |
| 864 | <option>--child-silent-after-fork=yes</option>, and |
| 865 | <option>-q</option> to restrict the plain text output to critical |
| 866 | error messages created by Valgrind itself. For example, failure to |
| 867 | read a specified suppressions file counts as a critical error message. |
| 868 | In this way, for a successful run the text output file will be empty. |
| 869 | But if it isn't empty, then it will contain important information |
| 870 | which the GUI user should be made aware |
| 871 | of.</para> |
sewardj | 6ea37fe | 2009-07-15 14:52:52 +0000 | [diff] [blame] | 872 | </listitem> |
| 873 | </varlistentry> |
| 874 | |
sewardj | 6ea37fe | 2009-07-15 14:52:52 +0000 | [diff] [blame] | 875 | <varlistentry id="opt.xml-fd" xreflabel="--xml-fd"> |
| 876 | <term> |
| 877 | <option><![CDATA[--xml-fd=<number> [default: -1, disabled] ]]></option> |
| 878 | </term> |
| 879 | <listitem> |
| 880 | <para>Specifies that Valgrind should send its XML output to the |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 881 | specified file descriptor. It must be used in conjunction with |
| 882 | <option>--xml=yes</option>.</para> |
sewardj | 6ea37fe | 2009-07-15 14:52:52 +0000 | [diff] [blame] | 883 | </listitem> |
| 884 | </varlistentry> |
| 885 | |
| 886 | <varlistentry id="opt.xml-file" xreflabel="--xml-file"> |
| 887 | <term> |
| 888 | <option><![CDATA[--xml-file=<filename> ]]></option> |
| 889 | </term> |
| 890 | <listitem> |
| 891 | <para>Specifies that Valgrind should send its XML output |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 892 | to the specified file. It must be used in conjunction with |
| 893 | <option>--xml=yes</option>. Any <option>%p</option> or |
| 894 | <option>%q</option> sequences appearing in the filename are expanded |
| 895 | in exactly the same way as they are for <option>--log-file</option>. |
| 896 | See the description of <option>--log-file</option> for details. |
sewardj | 6ea37fe | 2009-07-15 14:52:52 +0000 | [diff] [blame] | 897 | </para> |
| 898 | </listitem> |
| 899 | </varlistentry> |
| 900 | |
| 901 | <varlistentry id="opt.xml-socket" xreflabel="--xml-socket"> |
| 902 | <term> |
| 903 | <option><![CDATA[--xml-socket=<ip-address:port-number> ]]></option> |
| 904 | </term> |
| 905 | <listitem> |
| 906 | <para>Specifies that Valgrind should send its XML output the |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 907 | specified port at the specified IP address. It must be used in |
| 908 | conjunction with <option>--xml=yes</option>. The form of the argument |
| 909 | is the same as that used by <option>--log-socket</option>. |
| 910 | See the description of <option>--log-socket</option> |
sewardj | 6ea37fe | 2009-07-15 14:52:52 +0000 | [diff] [blame] | 911 | for further details.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 912 | </listitem> |
| 913 | </varlistentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 914 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 915 | <varlistentry id="opt.xml-user-comment" xreflabel="--xml-user-comment"> |
| 916 | <term> |
| 917 | <option><![CDATA[--xml-user-comment=<string> ]]></option> |
| 918 | </term> |
| 919 | <listitem> |
| 920 | <para>Embeds an extra user comment string at the start of the XML |
| 921 | output. Only works when <option>--xml=yes</option> is specified; |
| 922 | ignored otherwise.</para> |
| 923 | </listitem> |
| 924 | </varlistentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 925 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 926 | <varlistentry id="opt.demangle" xreflabel="--demangle"> |
| 927 | <term> |
| 928 | <option><![CDATA[--demangle=<yes|no> [default: yes] ]]></option> |
| 929 | </term> |
| 930 | <listitem> |
| 931 | <para>Enable/disable automatic demangling (decoding) of C++ names. |
| 932 | Enabled by default. When enabled, Valgrind will attempt to |
| 933 | translate encoded C++ names back to something approaching the |
| 934 | original. The demangler handles symbols mangled by g++ versions |
| 935 | 2.X, 3.X and 4.X.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 936 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 937 | <para>An important fact about demangling is that function names |
| 938 | mentioned in suppressions files should be in their mangled form. |
| 939 | Valgrind does not demangle function names when searching for |
| 940 | applicable suppressions, because to do otherwise would make |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 941 | suppression file contents dependent on the state of Valgrind's |
| 942 | demangling machinery, and also slow down suppression matching.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 943 | </listitem> |
| 944 | </varlistentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 945 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 946 | <varlistentry id="opt.num-callers" xreflabel="--num-callers"> |
| 947 | <term> |
| 948 | <option><![CDATA[--num-callers=<number> [default: 12] ]]></option> |
| 949 | </term> |
| 950 | <listitem> |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 951 | <para>Specifies the maximum number of entries shown in stack traces |
| 952 | that identify program locations. Note that errors are commoned up |
| 953 | using only the top four function locations (the place in the current |
| 954 | function, and that of its three immediate callers). So this doesn't |
| 955 | affect the total number of errors reported.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 956 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 957 | <para>The maximum value for this is 50. Note that higher settings |
| 958 | will make Valgrind run a bit more slowly and take a bit more |
| 959 | memory, but can be useful when working with programs with |
| 960 | deeply-nested call chains.</para> |
| 961 | </listitem> |
| 962 | </varlistentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 963 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 964 | <varlistentry id="opt.error-limit" xreflabel="--error-limit"> |
| 965 | <term> |
| 966 | <option><![CDATA[--error-limit=<yes|no> [default: yes] ]]></option> |
| 967 | </term> |
| 968 | <listitem> |
sewardj | 5850108 | 2006-05-12 23:35:10 +0000 | [diff] [blame] | 969 | <para>When enabled, Valgrind stops reporting errors after 10,000,000 |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 970 | in total, or 1,000 different ones, have been seen. This is to |
| 971 | stop the error tracking machinery from becoming a huge performance |
| 972 | overhead in programs with many errors.</para> |
| 973 | </listitem> |
| 974 | </varlistentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 975 | |
sewardj | b977908 | 2006-05-12 23:50:15 +0000 | [diff] [blame] | 976 | <varlistentry id="opt.error-exitcode" xreflabel="--error-exitcode"> |
| 977 | <term> |
| 978 | <option><![CDATA[--error-exitcode=<number> [default: 0] ]]></option> |
| 979 | </term> |
| 980 | <listitem> |
| 981 | <para>Specifies an alternative exit code to return if Valgrind |
| 982 | reported any errors in the run. When set to the default value |
| 983 | (zero), the return value from Valgrind will always be the return |
| 984 | value of the process being simulated. When set to a nonzero value, |
| 985 | that value is returned instead, if Valgrind detects any errors. |
| 986 | This is useful for using Valgrind as part of an automated test |
| 987 | suite, since it makes it easy to detect test cases for which |
| 988 | Valgrind has reported errors, just by inspecting return codes.</para> |
| 989 | </listitem> |
| 990 | </varlistentry> |
| 991 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 992 | <varlistentry id="opt.stack-traces" xreflabel="--show-below-main"> |
| 993 | <term> |
| 994 | <option><![CDATA[--show-below-main=<yes|no> [default: no] ]]></option> |
| 995 | </term> |
| 996 | <listitem> |
| 997 | <para>By default, stack traces for errors do not show any |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 998 | functions that appear beneath <function>main</function> because |
njn | 6882443 | 2009-02-10 06:48:00 +0000 | [diff] [blame] | 999 | most of the time it's uninteresting C library stuff and/or |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1000 | gobbledygook. Alternatively, if <function>main</function> is not |
njn | 6882443 | 2009-02-10 06:48:00 +0000 | [diff] [blame] | 1001 | present in the stack trace, stack traces will not show any functions |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1002 | below <function>main</function>-like functions such as glibc's |
| 1003 | <function>__libc_start_main</function>. Furthermore, if |
| 1004 | <function>main</function>-like functions are present in the trace, |
| 1005 | they are normalised as <function>(below main)</function>, in order to |
| 1006 | make the output more deterministic.</para> |
njn | 6882443 | 2009-02-10 06:48:00 +0000 | [diff] [blame] | 1007 | |
| 1008 | <para>If this option is enabled, all stack trace entries will be |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1009 | shown and <function>main</function>-like functions will not be |
njn | 6882443 | 2009-02-10 06:48:00 +0000 | [diff] [blame] | 1010 | normalised.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1011 | </listitem> |
| 1012 | </varlistentry> |
sewardj | d153fae | 2005-01-10 17:24:47 +0000 | [diff] [blame] | 1013 | |
sewardj | 14cdbf8 | 2010-10-12 00:44:05 +0000 | [diff] [blame] | 1014 | <varlistentry id="opt.fullpath-after" xreflabel="--fullpath-after"> |
bart | 5dd0190 | 2010-08-31 15:18:32 +0000 | [diff] [blame] | 1015 | <term> |
sewardj | 14cdbf8 | 2010-10-12 00:44:05 +0000 | [diff] [blame] | 1016 | <option><![CDATA[--fullpath-after=<string> |
| 1017 | [default: don't show source paths] ]]></option> |
bart | 5dd0190 | 2010-08-31 15:18:32 +0000 | [diff] [blame] | 1018 | </term> |
| 1019 | <listitem> |
sewardj | 14cdbf8 | 2010-10-12 00:44:05 +0000 | [diff] [blame] | 1020 | <para>By default Valgrind only shows the filenames in stack |
| 1021 | traces, but not full paths to source files. When using Valgrind |
| 1022 | in large projects where the sources reside in multiple different |
| 1023 | directories, this can be inconvenient. |
| 1024 | <option>--fullpath-after</option> provides a flexible solution |
| 1025 | to this problem. When this option is present, the path to each |
| 1026 | source file is shown, with the following all-important caveat: |
| 1027 | if <option>string</option> is found in the path, then the path |
| 1028 | up to and including <option>string</option> is omitted, else the |
| 1029 | path is shown unmodified. Note that <option>string</option> is |
| 1030 | not required to be a prefix of the path.</para> |
| 1031 | |
| 1032 | <para>For example, consider a file named |
| 1033 | <computeroutput>/home/janedoe/blah/src/foo/bar/xyzzy.c</computeroutput>. |
| 1034 | Specifying <option>--fullpath-after=/home/janedoe/blah/src/</option> |
| 1035 | will cause Valgrind to show the name |
| 1036 | as <computeroutput>foo/bar/xyzzy.c</computeroutput>.</para> |
| 1037 | |
| 1038 | <para>Because the string is not required to be a prefix, |
| 1039 | <option>--fullpath-after=src/</option> will produce the same |
| 1040 | output. This is useful when the path contains arbitrary |
| 1041 | machine-generated characters. For example, the |
| 1042 | path |
| 1043 | <computeroutput>/my/build/dir/C32A1B47/blah/src/foo/xyzzy</computeroutput> |
| 1044 | can be pruned to <computeroutput>foo/xyzzy</computeroutput> |
| 1045 | using |
| 1046 | <option>--fullpath-after=/blah/src/</option>.</para> |
| 1047 | |
| 1048 | <para>If you simply want to see the full path, just specify an |
| 1049 | empty string: <option>--fullpath-after=</option>. This isn't a |
| 1050 | special case, merely a logical consequence of the above rules.</para> |
| 1051 | |
| 1052 | <para>Finally, you can use <option>--fullpath-after</option> |
| 1053 | multiple times. Any appearance of it causes Valgrind to switch |
| 1054 | to producing full paths and applying the above filtering rule. |
| 1055 | Each produced path is compared against all |
| 1056 | the <option>--fullpath-after</option>-specified strings, in the |
| 1057 | order specified. The first string to match causes the path to |
| 1058 | be truncated as described above. If none match, the full path |
| 1059 | is shown. This facilitates chopping off prefixes when the |
| 1060 | sources are drawn from a number of unrelated directories. |
bart | 5dd0190 | 2010-08-31 15:18:32 +0000 | [diff] [blame] | 1061 | </para> |
| 1062 | </listitem> |
| 1063 | </varlistentry> |
| 1064 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1065 | <varlistentry id="opt.suppressions" xreflabel="--suppressions"> |
| 1066 | <term> |
| 1067 | <option><![CDATA[--suppressions=<filename> [default: $PREFIX/lib/valgrind/default.supp] ]]></option> |
| 1068 | </term> |
| 1069 | <listitem> |
| 1070 | <para>Specifies an extra file from which to read descriptions of |
sewardj | c44b254 | 2008-05-14 06:43:10 +0000 | [diff] [blame] | 1071 | errors to suppress. You may use up to 100 extra suppression |
| 1072 | files.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1073 | </listitem> |
| 1074 | </varlistentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1075 | |
sewardj | 3387889 | 2007-11-17 09:43:25 +0000 | [diff] [blame] | 1076 | <varlistentry id="opt.gen-suppressions" xreflabel="--gen-suppressions"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1077 | <term> |
| 1078 | <option><![CDATA[--gen-suppressions=<yes|no|all> [default: no] ]]></option> |
| 1079 | </term> |
| 1080 | <listitem> |
| 1081 | <para>When set to <varname>yes</varname>, Valgrind will pause |
| 1082 | after every error shown and print the line: |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1083 | <literallayout><computeroutput> ---- Print suppression ? --- [Return/N/n/Y/y/C/c] ----</computeroutput></literallayout> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1084 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1085 | The prompt's behaviour is the same as for the |
| 1086 | <option>--db-attach</option> option (see below).</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1087 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1088 | <para>If you choose to, Valgrind will print out a suppression for |
| 1089 | this error. You can then cut and paste it into a suppression file |
| 1090 | if you don't want to hear about the error in the future.</para> |
sewardj | d153fae | 2005-01-10 17:24:47 +0000 | [diff] [blame] | 1091 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1092 | <para>When set to <varname>all</varname>, Valgrind will print a |
| 1093 | suppression for every reported error, without querying the |
| 1094 | user.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1095 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1096 | <para>This option is particularly useful with C++ programs, as it |
| 1097 | prints out the suppressions with mangled names, as |
| 1098 | required.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1099 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1100 | <para>Note that the suppressions printed are as specific as |
sewardj | 9a0132d | 2008-11-04 11:29:19 +0000 | [diff] [blame] | 1101 | possible. You may want to common up similar ones, by adding |
| 1102 | wildcards to function names, and by using frame-level wildcards. |
| 1103 | The wildcarding facilities are powerful yet flexible, and with a |
| 1104 | bit of careful editing, you may be able to suppress a whole |
njn | 36ef257 | 2009-08-10 00:42:43 +0000 | [diff] [blame] | 1105 | family of related errors with only a few suppressions. |
| 1106 | <!-- commented out because it causes broken links in the man page |
| 1107 | For details on how to do this, see |
| 1108 | <xref linkend="manual-core.suppress"/>. |
| 1109 | --> |
| 1110 | </para> |
sewardj | 9a0132d | 2008-11-04 11:29:19 +0000 | [diff] [blame] | 1111 | |
| 1112 | <para>Sometimes two different errors |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1113 | are suppressed by the same suppression, in which case Valgrind |
| 1114 | will output the suppression more than once, but you only need to |
| 1115 | have one copy in your suppression file (but having more than one |
| 1116 | won't cause problems). Also, the suppression name is given as |
| 1117 | <computeroutput><insert a suppression name |
| 1118 | here></computeroutput>; the name doesn't really matter, it's |
| 1119 | only used with the <option>-v</option> option which prints out all |
| 1120 | used suppression records.</para> |
| 1121 | </listitem> |
| 1122 | </varlistentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1123 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1124 | <varlistentry id="opt.db-attach" xreflabel="--db-attach"> |
| 1125 | <term> |
| 1126 | <option><![CDATA[--db-attach=<yes|no> [default: no] ]]></option> |
| 1127 | </term> |
| 1128 | <listitem> |
| 1129 | <para>When enabled, Valgrind will pause after every error shown |
| 1130 | and print the line: |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1131 | <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] | 1132 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1133 | Pressing <varname>Ret</varname>, or <varname>N Ret</varname> or |
| 1134 | <varname>n Ret</varname>, causes Valgrind not to start a debugger |
| 1135 | for this error.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1136 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1137 | <para>Pressing <varname>Y Ret</varname> or |
| 1138 | <varname>y Ret</varname> causes Valgrind to start a debugger for |
| 1139 | the program at this point. When you have finished with the |
| 1140 | debugger, quit from it, and the program will continue. Trying to |
| 1141 | continue from inside the debugger doesn't work.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1142 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1143 | <para><varname>C Ret</varname> or <varname>c Ret</varname> causes |
| 1144 | Valgrind not to start a debugger, and not to ask again.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1145 | </listitem> |
| 1146 | </varlistentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1147 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1148 | <varlistentry id="opt.db-command" xreflabel="--db-command"> |
| 1149 | <term> |
| 1150 | <option><![CDATA[--db-command=<command> [default: gdb -nw %f %p] ]]></option> |
| 1151 | </term> |
| 1152 | <listitem> |
| 1153 | <para>Specify the debugger to use with the |
| 1154 | <option>--db-attach</option> command. The default debugger is |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1155 | GDB. This option is a template that is expanded by Valgrind at |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1156 | runtime. <literal>%f</literal> is replaced with the executable's |
| 1157 | file name and <literal>%p</literal> is replaced by the process ID |
| 1158 | of the executable.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1159 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1160 | <para>This specifies how Valgrind will invoke the debugger. By |
| 1161 | default it will use whatever GDB is detected at build time, which |
| 1162 | is usually <computeroutput>/usr/bin/gdb</computeroutput>. Using |
| 1163 | this command, you can specify some alternative command to invoke |
| 1164 | the debugger you want to use.</para> |
njn | 5127298 | 2005-07-25 23:18:44 +0000 | [diff] [blame] | 1165 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1166 | <para>The command string given can include one or instances of the |
| 1167 | <literal>%p</literal> and <literal>%f</literal> expansions. Each |
| 1168 | instance of <literal>%p</literal> expands to the PID of the |
| 1169 | process to be debugged and each instance of <literal>%f</literal> |
| 1170 | expands to the path to the executable for the process to be |
| 1171 | debugged.</para> |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1172 | |
| 1173 | <para>Since <computeroutput><command></computeroutput> is likely |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 1174 | to contain spaces, you will need to put this entire option in |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1175 | quotes to ensure it is correctly handled by the shell.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1176 | </listitem> |
| 1177 | </varlistentry> |
| 1178 | |
| 1179 | <varlistentry id="opt.input-fd" xreflabel="--input-fd"> |
| 1180 | <term> |
| 1181 | <option><![CDATA[--input-fd=<number> [default: 0, stdin] ]]></option> |
| 1182 | </term> |
| 1183 | <listitem> |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 1184 | <para>When using <option>--db-attach=yes</option> or |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1185 | <option>--gen-suppressions=yes</option>, Valgrind will stop so as |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 1186 | to read keyboard input from you when each error occurs. By |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1187 | default it reads from the standard input (stdin), which is |
| 1188 | problematic for programs which close stdin. This option allows |
| 1189 | you to specify an alternative file descriptor from which to read |
| 1190 | input.</para> |
| 1191 | </listitem> |
| 1192 | </varlistentry> |
| 1193 | |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1194 | <varlistentry id="opt.dsymutil" xreflabel="--dsymutil"> |
sewardj | b4cf7cd | 2009-05-31 09:34:05 +0000 | [diff] [blame] | 1195 | <term> |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1196 | <option><![CDATA[--dsymutil=no|yes [no] ]]></option> |
sewardj | b4cf7cd | 2009-05-31 09:34:05 +0000 | [diff] [blame] | 1197 | </term> |
| 1198 | <listitem> |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 1199 | <para>This option is only relevant when running Valgrind on |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1200 | Mac OS X.</para> |
sewardj | b4cf7cd | 2009-05-31 09:34:05 +0000 | [diff] [blame] | 1201 | |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1202 | <para>Mac OS X uses a deferred debug information (debuginfo) |
sewardj | b4cf7cd | 2009-05-31 09:34:05 +0000 | [diff] [blame] | 1203 | linking scheme. When object files containing debuginfo are |
| 1204 | linked into a <computeroutput>.dylib</computeroutput> or an |
| 1205 | executable, the debuginfo is not copied into the final file. |
| 1206 | Instead, the debuginfo must be linked manually by |
| 1207 | running <computeroutput>dsymutil</computeroutput>, a |
| 1208 | system-provided utility, on the executable |
| 1209 | or <computeroutput>.dylib</computeroutput>. The resulting |
| 1210 | combined debuginfo is placed in a directory alongside the |
| 1211 | executable or <computeroutput>.dylib</computeroutput>, but with |
| 1212 | the extension <computeroutput>.dSYM</computeroutput>.</para> |
| 1213 | |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1214 | <para>With <option>--dsymutil=no</option>, Valgrind |
sewardj | b4cf7cd | 2009-05-31 09:34:05 +0000 | [diff] [blame] | 1215 | will detect cases where the |
| 1216 | <computeroutput>.dSYM</computeroutput> directory is either |
| 1217 | missing, or is present but does not appear to match the |
| 1218 | associated executable or <computeroutput>.dylib</computeroutput>, |
| 1219 | most likely because it is out of date. In these cases, Valgrind |
| 1220 | will print a warning message but take no further action.</para> |
| 1221 | |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1222 | <para>With <option>--dsymutil=yes</option>, Valgrind |
sewardj | b4cf7cd | 2009-05-31 09:34:05 +0000 | [diff] [blame] | 1223 | will, in such cases, automatically |
| 1224 | run <computeroutput>dsymutil</computeroutput> as necessary to |
| 1225 | bring the debuginfo up to date. For all practical purposes, if |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1226 | you always use <option>--dsymutil=yes</option>, then |
sewardj | b4cf7cd | 2009-05-31 09:34:05 +0000 | [diff] [blame] | 1227 | there is never any need to |
| 1228 | run <computeroutput>dsymutil</computeroutput> manually or as part |
| 1229 | of your applications's build system, since Valgrind will run it |
| 1230 | as necessary.</para> |
| 1231 | |
| 1232 | <para>Valgrind will not attempt to |
| 1233 | run <computeroutput>dsymutil</computeroutput> on any |
| 1234 | executable or library in |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1235 | <computeroutput>/usr/</computeroutput>, |
| 1236 | <computeroutput>/bin/</computeroutput>, |
| 1237 | <computeroutput>/sbin/</computeroutput>, |
| 1238 | <computeroutput>/opt/</computeroutput>, |
| 1239 | <computeroutput>/sw/</computeroutput>, |
| 1240 | <computeroutput>/System/</computeroutput>, |
| 1241 | <computeroutput>/Library/</computeroutput> or |
| 1242 | <computeroutput>/Applications/</computeroutput> |
sewardj | b4cf7cd | 2009-05-31 09:34:05 +0000 | [diff] [blame] | 1243 | since <computeroutput>dsymutil</computeroutput> will always fail |
| 1244 | in such situations. It fails both because the debuginfo for |
| 1245 | such pre-installed system components is not available anywhere, |
bart | 2ff151c | 2009-07-19 08:12:57 +0000 | [diff] [blame] | 1246 | and also because it would require write privileges in those |
sewardj | b4cf7cd | 2009-05-31 09:34:05 +0000 | [diff] [blame] | 1247 | directories.</para> |
| 1248 | |
| 1249 | <para>Be careful when |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1250 | using <option>--dsymutil=yes</option>, since it will |
sewardj | b4cf7cd | 2009-05-31 09:34:05 +0000 | [diff] [blame] | 1251 | cause pre-existing <computeroutput>.dSYM</computeroutput> |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1252 | directories to be silently deleted and re-created. Also note that |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1253 | <computeroutput>dsymutil</computeroutput> is quite slow, sometimes |
| 1254 | excessively so.</para> |
sewardj | b4cf7cd | 2009-05-31 09:34:05 +0000 | [diff] [blame] | 1255 | </listitem> |
| 1256 | </varlistentry> |
| 1257 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1258 | <varlistentry id="opt.max-stackframe" xreflabel="--max-stackframe"> |
| 1259 | <term> |
| 1260 | <option><![CDATA[--max-stackframe=<number> [default: 2000000] ]]></option> |
| 1261 | </term> |
| 1262 | <listitem> |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 1263 | <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] | 1264 | more than this amount then Valgrind will assume that |
| 1265 | the program is switching to a different stack.</para> |
| 1266 | |
| 1267 | <para>You may need to use this option if your program has large |
| 1268 | stack-allocated arrays. Valgrind keeps track of your program's |
| 1269 | stack pointer. If it changes by more than the threshold amount, |
| 1270 | Valgrind assumes your program is switching to a different stack, |
| 1271 | and Memcheck behaves differently than it would for a stack pointer |
| 1272 | change smaller than the threshold. Usually this heuristic works |
| 1273 | well. However, if your program allocates large structures on the |
| 1274 | stack, this heuristic will be fooled, and Memcheck will |
| 1275 | subsequently report large numbers of invalid stack accesses. This |
| 1276 | option allows you to change the threshold to a different |
| 1277 | value.</para> |
| 1278 | |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 1279 | <para>You should only consider use of this option if Valgrind's |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1280 | debug output directs you to do so. In that case it will tell you |
| 1281 | the new threshold you should specify.</para> |
| 1282 | |
| 1283 | <para>In general, allocating large structures on the stack is a |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 1284 | bad idea, because you can easily run out of stack space, |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1285 | especially on systems with limited memory or which expect to |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 1286 | support large numbers of threads each with a small stack, and also |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1287 | because the error checking performed by Memcheck is more effective |
| 1288 | for heap-allocated data than for stack-allocated data. If you |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 1289 | have to use this option, you may wish to consider rewriting your |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1290 | code to allocate on the heap rather than on the stack.</para> |
| 1291 | </listitem> |
| 1292 | </varlistentry> |
| 1293 | |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 1294 | <varlistentry id="opt.main-stacksize" xreflabel="--main-stacksize"> |
| 1295 | <term> |
| 1296 | <option><![CDATA[--main-stacksize=<number> |
| 1297 | [default: use current 'ulimit' value] ]]></option> |
| 1298 | </term> |
| 1299 | <listitem> |
| 1300 | <para>Specifies the size of the main thread's stack.</para> |
| 1301 | |
| 1302 | <para>To simplify its memory management, Valgrind reserves all |
| 1303 | required space for the main thread's stack at startup. That |
| 1304 | means it needs to know the required stack size at |
| 1305 | startup.</para> |
| 1306 | |
| 1307 | <para>By default, Valgrind uses the current "ulimit" value for |
| 1308 | the stack size, or 16 MB, whichever is lower. In many cases |
| 1309 | this gives a stack size in the range 8 to 16 MB, which almost |
| 1310 | never overflows for most applications.</para> |
| 1311 | |
| 1312 | <para>If you need a larger total stack size, |
| 1313 | use <option>--main-stacksize</option> to specify it. Only set |
| 1314 | it as high as you need, since reserving far more space than you |
| 1315 | need (that is, hundreds of megabytes more than you need) |
| 1316 | constrains Valgrind's memory allocators and may reduce the total |
| 1317 | amount of memory that Valgrind can use. This is only really of |
| 1318 | significance on 32-bit machines.</para> |
| 1319 | |
| 1320 | <para>On Linux, you may request a stack of size up to 2GB. |
| 1321 | Valgrind will stop with a diagnostic message if the stack cannot |
| 1322 | be allocated. On AIX5 the allowed stack size is restricted to |
| 1323 | 128MB.</para> |
| 1324 | |
| 1325 | <para><option>--main-stacksize</option> only affects the stack |
| 1326 | size for the program's initial thread. It has no bearing on the |
| 1327 | size of thread stacks, as Valgrind does not allocate |
| 1328 | those.</para> |
| 1329 | |
| 1330 | <para>You may need to use both <option>--main-stacksize</option> |
| 1331 | and <option>--max-stackframe</option> together. It is important |
| 1332 | to understand that <option>--main-stacksize</option> sets the |
| 1333 | maximum total stack size, |
| 1334 | whilst <option>--max-stackframe</option> specifies the largest |
| 1335 | size of any one stack frame. You will have to work out |
| 1336 | the <option>--main-stacksize</option> value for yourself |
| 1337 | (usually, if your applications segfaults). But Valgrind will |
| 1338 | tell you the needed <option>--max-stackframe</option> size, if |
| 1339 | necessary.</para> |
| 1340 | |
| 1341 | <para>As discussed further in the description |
| 1342 | of <option>--max-stackframe</option>, a requirement for a large |
| 1343 | stack is a sign of potential portability problems. You are best |
| 1344 | advised to place all large data in heap-allocated memory.</para> |
| 1345 | </listitem> |
| 1346 | </varlistentry> |
| 1347 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1348 | </variablelist> |
de | 03e0e7c | 2005-12-03 23:02:33 +0000 | [diff] [blame] | 1349 | <!-- end of xi:include in the manpage --> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1350 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1351 | </sect2> |
| 1352 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1353 | |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1354 | <sect2 id="manual-core.mallocopts" xreflabel="malloc-related Options"> |
sewardj | 1160e81 | 2010-09-10 14:56:18 +0000 | [diff] [blame] | 1355 | <title>malloc-related Options</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1356 | |
de | 03e0e7c | 2005-12-03 23:02:33 +0000 | [diff] [blame] | 1357 | <!-- start of xi:include in the manpage --> |
| 1358 | <para id="malloc-related.opts.para">For tools that use their own version of |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1359 | <computeroutput>malloc</computeroutput> (e.g. Memcheck and |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1360 | Massif), the following options apply.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1361 | |
de | 03e0e7c | 2005-12-03 23:02:33 +0000 | [diff] [blame] | 1362 | <variablelist id="malloc-related.opts.list"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1363 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1364 | <varlistentry id="opt.alignment" xreflabel="--alignment"> |
| 1365 | <term> |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1366 | <option><![CDATA[--alignment=<number> [default: 8 or 16, depending on the platform] ]]></option> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1367 | </term> |
| 1368 | <listitem> |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1369 | <para>By default Valgrind's <function>malloc</function>, |
| 1370 | <function>realloc</function>, etc, return a block whose starting |
| 1371 | address is 8-byte aligned or 16-byte aligned (the value depends on the |
| 1372 | platform and matches the platform default). This option allows you to |
| 1373 | specify a different alignment. The supplied value must be greater |
| 1374 | than or equal to the default, less than or equal to 4096, and must be |
| 1375 | a power of two.</para> |
njn | 5127298 | 2005-07-25 23:18:44 +0000 | [diff] [blame] | 1376 | </listitem> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1377 | </varlistentry> |
njn | 5127298 | 2005-07-25 23:18:44 +0000 | [diff] [blame] | 1378 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1379 | </variablelist> |
de | 03e0e7c | 2005-12-03 23:02:33 +0000 | [diff] [blame] | 1380 | <!-- end of xi:include in the manpage --> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1381 | |
| 1382 | </sect2> |
| 1383 | |
| 1384 | |
| 1385 | <sect2 id="manual-core.rareopts" xreflabel="Uncommon Options"> |
| 1386 | <title>Uncommon Options</title> |
| 1387 | |
de | 03e0e7c | 2005-12-03 23:02:33 +0000 | [diff] [blame] | 1388 | <!-- start of xi:include in the manpage --> |
| 1389 | <para id="uncommon.opts.para">These options apply to all tools, as they |
| 1390 | affect certain obscure workings of the Valgrind core. Most people won't |
| 1391 | need to use these.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1392 | |
de | 03e0e7c | 2005-12-03 23:02:33 +0000 | [diff] [blame] | 1393 | <variablelist id="uncommon.opts.list"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1394 | |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1395 | <varlistentry id="opt.smc-check" xreflabel="--smc-check"> |
| 1396 | <term> |
| 1397 | <option><![CDATA[--smc-check=<none|stack|all> [default: stack] ]]></option> |
| 1398 | </term> |
| 1399 | <listitem> |
| 1400 | <para>This option controls Valgrind's detection of self-modifying |
| 1401 | code. If no checking is done, if a program executes some code, then |
| 1402 | overwrites it with new code, and executes the new code, Valgrind will |
| 1403 | continue to execute the translations it made for the old code. This |
| 1404 | will likely lead to incorrect behaviour and/or crashes.</para> |
| 1405 | |
| 1406 | <para>Valgrind has three levels of self-modifying code detection: |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1407 | no detection, detect self-modifying code on the stack (which is used by |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1408 | GCC to implement nested functions), or detect self-modifying code |
| 1409 | everywhere. Note that the default option will catch the vast majority |
| 1410 | of cases. The main case it will not catch is programs such as JIT |
| 1411 | compilers that dynamically generate code <emphasis>and</emphasis> |
| 1412 | subsequently overwrite part or all of it. Running with |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1413 | <varname>all</varname> will slow Valgrind down noticeably. Running with |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1414 | <varname>none</varname> will rarely speed things up, since very little |
| 1415 | code gets put on the stack for most programs. The |
| 1416 | <function>VALGRIND_DISCARD_TRANSLATIONS</function> client request is |
| 1417 | an alternative to <option>--smc-check=all</option> that requires more |
njn | 36ef257 | 2009-08-10 00:42:43 +0000 | [diff] [blame] | 1418 | effort but is much faster. |
| 1419 | <!-- commented out because it causes broken links in the man page |
| 1420 | ; see <xref |
| 1421 | linkend="manual-core-adv.clientreq"/> for more details. |
| 1422 | --> |
| 1423 | </para> |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1424 | |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1425 | <para>Some architectures (including ppc32, ppc64 and ARM) require |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1426 | programs which create code at runtime to flush the instruction |
| 1427 | cache in between code generation and first use. Valgrind |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1428 | observes and honours such instructions. Hence, on ppc32/Linux, |
| 1429 | ppc64/Linux and ARM/Linux, Valgrind always provides complete, transparent |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1430 | support for self-modifying code. It is only on platforms such as |
| 1431 | x86/Linux, AMD64/Linux and x86/Darwin that you need to use this |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 1432 | option.</para> |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1433 | </listitem> |
| 1434 | </varlistentry> |
| 1435 | |
| 1436 | <varlistentry id="opt.read-var-info" xreflabel="--read-var-info"> |
| 1437 | <term> |
| 1438 | <option><![CDATA[--read-var-info=<yes|no> [default: no] ]]></option> |
| 1439 | </term> |
| 1440 | <listitem> |
sewardj | e77c724 | 2009-08-16 22:49:53 +0000 | [diff] [blame] | 1441 | <para>When enabled, Valgrind will read information about |
| 1442 | variable types and locations from DWARF3 debug info. |
| 1443 | This slows Valgrind down and makes it use more memory, but for |
| 1444 | the tools that can take advantage of it (Memcheck, Helgrind, |
| 1445 | DRD) it can result in more precise error messages. For example, |
| 1446 | here are some standard errors issued by Memcheck:</para> |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 1447 | <programlisting><![CDATA[ |
| 1448 | ==15516== Uninitialised byte(s) found during client check request |
| 1449 | ==15516== at 0x400633: croak (varinfo1.c:28) |
| 1450 | ==15516== by 0x4006B2: main (varinfo1.c:55) |
| 1451 | ==15516== Address 0x60103b is 7 bytes inside data symbol "global_i2" |
| 1452 | ==15516== |
| 1453 | ==15516== Uninitialised byte(s) found during client check request |
| 1454 | ==15516== at 0x400633: croak (varinfo1.c:28) |
| 1455 | ==15516== by 0x4006BC: main (varinfo1.c:56) |
| 1456 | ==15516== Address 0x7fefffefc is on thread 1's stack]]></programlisting> |
| 1457 | |
| 1458 | <para>And here are the same errors with |
| 1459 | <option>--read-var-info=yes</option>:</para> |
| 1460 | |
| 1461 | <programlisting><![CDATA[ |
| 1462 | ==15522== Uninitialised byte(s) found during client check request |
| 1463 | ==15522== at 0x400633: croak (varinfo1.c:28) |
| 1464 | ==15522== by 0x4006B2: main (varinfo1.c:55) |
| 1465 | ==15522== Location 0x60103b is 0 bytes inside global_i2[7], |
| 1466 | ==15522== a global variable declared at varinfo1.c:41 |
| 1467 | ==15522== |
| 1468 | ==15522== Uninitialised byte(s) found during client check request |
| 1469 | ==15522== at 0x400633: croak (varinfo1.c:28) |
| 1470 | ==15522== by 0x4006BC: main (varinfo1.c:56) |
| 1471 | ==15522== Location 0x7fefffefc is 0 bytes inside local var "local" |
| 1472 | ==15522== declared at varinfo1.c:46, in frame #1 of thread 1]]></programlisting> |
| 1473 | </listitem> |
| 1474 | </varlistentry> |
| 1475 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1476 | <varlistentry id="opt.run-libc-freeres" xreflabel="--run-libc-freeres"> |
| 1477 | <term> |
| 1478 | <option><![CDATA[--run-libc-freeres=<yes|no> [default: yes] ]]></option> |
| 1479 | </term> |
| 1480 | <listitem> |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 1481 | <para>This option is only relevant when running Valgrind on Linux.</para> |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1482 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1483 | <para>The GNU C library (<function>libc.so</function>), which is |
| 1484 | used by all programs, may allocate memory for its own uses. |
| 1485 | Usually it doesn't bother to free that memory when the program |
sewardj | 3387889 | 2007-11-17 09:43:25 +0000 | [diff] [blame] | 1486 | ends—there would be no point, since the Linux kernel reclaims |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1487 | all process resources when a process exits anyway, so it would |
| 1488 | just slow things down.</para> |
| 1489 | |
| 1490 | <para>The glibc authors realised that this behaviour causes leak |
| 1491 | checkers, such as Valgrind, to falsely report leaks in glibc, when |
| 1492 | a leak check is done at exit. In order to avoid this, they |
| 1493 | provided a routine called <function>__libc_freeres</function> |
| 1494 | specifically to make glibc release all memory it has allocated. |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1495 | Memcheck therefore tries to run |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1496 | <function>__libc_freeres</function> at exit.</para> |
| 1497 | |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 1498 | <para>Unfortunately, in some very old versions of glibc, |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1499 | <function>__libc_freeres</function> is sufficiently buggy to cause |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame] | 1500 | segmentation faults. This was particularly noticeable on Red Hat |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 1501 | 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] | 1502 | <function>__libc_freeres</function>. If your program seems to run |
| 1503 | fine on Valgrind, but segfaults at exit, you may find that |
| 1504 | <option>--run-libc-freeres=no</option> fixes that, although at the |
| 1505 | cost of possibly falsely reporting space leaks in |
| 1506 | <filename>libc.so</filename>.</para> |
| 1507 | </listitem> |
| 1508 | </varlistentry> |
| 1509 | |
| 1510 | <varlistentry id="opt.sim-hints" xreflabel="--sim-hints"> |
| 1511 | <term> |
| 1512 | <option><![CDATA[--sim-hints=hint1,hint2,... ]]></option> |
| 1513 | </term> |
| 1514 | <listitem> |
| 1515 | <para>Pass miscellaneous hints to Valgrind which slightly modify |
| 1516 | the simulated behaviour in nonstandard or dangerous ways, possibly |
| 1517 | to help the simulation of strange features. By default no hints |
| 1518 | are enabled. Use with caution! Currently known hints are:</para> |
| 1519 | <itemizedlist> |
| 1520 | <listitem> |
| 1521 | <para><option>lax-ioctls: </option> Be very lax about ioctl |
| 1522 | handling; the only assumption is that the size is |
| 1523 | correct. Doesn't require the full buffer to be initialized |
| 1524 | when writing. Without this, using some device drivers with a |
| 1525 | large number of strange ioctl commands becomes very |
| 1526 | tiresome.</para> |
| 1527 | </listitem> |
| 1528 | <listitem> |
| 1529 | <para><option>enable-inner: </option> Enable some special |
| 1530 | magic needed when the program being run is itself |
| 1531 | Valgrind.</para> |
| 1532 | </listitem> |
| 1533 | </itemizedlist> |
| 1534 | </listitem> |
| 1535 | </varlistentry> |
| 1536 | |
| 1537 | <varlistentry id="opt.kernel-variant" xreflabel="--kernel-variant"> |
| 1538 | <term> |
| 1539 | <option>--kernel-variant=variant1,variant2,...</option> |
| 1540 | </term> |
| 1541 | <listitem> |
| 1542 | <para>Handle system calls and ioctls arising from minor variants |
| 1543 | of the default kernel for this platform. This is useful for |
| 1544 | running on hacked kernels or with kernel modules which support |
| 1545 | nonstandard ioctls, for example. Use with caution. If you don't |
| 1546 | understand what this option does then you almost certainly don't |
| 1547 | need it. Currently known variants are:</para> |
| 1548 | <itemizedlist> |
| 1549 | <listitem> |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1550 | <para><option>bproc: </option> Support the |
| 1551 | <function>sys_broc</function> system call on x86. This is for |
| 1552 | running on BProc, which is a minor variant of standard Linux which |
| 1553 | is sometimes used for building clusters.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1554 | </listitem> |
| 1555 | </itemizedlist> |
| 1556 | </listitem> |
| 1557 | </varlistentry> |
| 1558 | |
| 1559 | <varlistentry id="opt.show-emwarns" xreflabel="--show-emwarns"> |
| 1560 | <term> |
| 1561 | <option><![CDATA[--show-emwarns=<yes|no> [default: no] ]]></option> |
| 1562 | </term> |
| 1563 | <listitem> |
| 1564 | <para>When enabled, Valgrind will emit warnings about its CPU |
| 1565 | emulation in certain cases. These are usually not |
| 1566 | interesting.</para> |
| 1567 | </listitem> |
| 1568 | </varlistentry> |
| 1569 | |
sewardj | f9ebc39 | 2010-05-09 22:30:43 +0000 | [diff] [blame] | 1570 | <varlistentry id="opt.require-text-symbol" |
| 1571 | xreflabel="--require-text-symbol"> |
| 1572 | <term> |
| 1573 | <option><![CDATA[--require-text-symbol=:sonamepatt:fnnamepatt]]></option> |
| 1574 | </term> |
| 1575 | <listitem> |
| 1576 | <para>When a shared object whose soname |
| 1577 | matches <varname>sonamepatt</varname> is loaded into the |
| 1578 | process, examine all the text symbols it exports. If none of |
| 1579 | those match <varname>fnnamepatt</varname>, print an error |
| 1580 | message and abandon the run. This makes it possible to ensure |
| 1581 | that the run does not continue unless a given shared object |
| 1582 | contains a particular function name. |
| 1583 | </para> |
| 1584 | <para> |
| 1585 | Both <varname>sonamepatt</varname> and |
| 1586 | <varname>fnnamepatt</varname> can be written using the usual |
| 1587 | <varname>?</varname> and <varname>*</varname> wildcards. For |
| 1588 | example: <varname>":*libc.so*:foo?bar"</varname>. You may use |
| 1589 | characters other than a colon to separate the two patterns. It |
| 1590 | is only important that the first character and the separator |
| 1591 | character are the same. For example, the above example could |
| 1592 | also be written <varname>"Q*libc.so*Qfoo?bar"</varname>. |
| 1593 | Multiple <varname> --require-text-symbol</varname> flags are |
| 1594 | allowed, in which case shared objects that are loaded into |
| 1595 | the process will be checked against all of them. |
| 1596 | </para> |
| 1597 | <para> |
| 1598 | The purpose of this is to support reliable usage of marked-up |
| 1599 | libraries. For example, suppose we have a version of GCC's |
| 1600 | <varname>libgomp.so</varname> which has been marked up with |
| 1601 | annotations to support Helgrind. It is only too easy and |
| 1602 | confusing to load the wrong, un-annotated |
| 1603 | <varname>libgomp.so</varname> into the application. So the idea |
| 1604 | is: add a text symbol in the marked-up library, for |
| 1605 | example <varname>annotated_for_helgrind_3_6</varname>, and then |
| 1606 | give the flag |
| 1607 | <varname>--require-text-symbol=:*libgomp*so*:annotated_for_helgrind_3_6</varname> |
| 1608 | so that when <varname>libgomp.so</varname> is loaded, Valgrind |
| 1609 | scans its symbol table, and if the symbol isn't present the run |
| 1610 | is aborted, rather than continuing silently with the |
| 1611 | un-marked-up library. Note that you should put the entire flag |
| 1612 | in quotes to stop shells expanding up the <varname>*</varname> |
| 1613 | and <varname>?</varname> wildcards. |
| 1614 | </para> |
| 1615 | </listitem> |
| 1616 | </varlistentry> |
| 1617 | |
| 1618 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1619 | </variablelist> |
de | 03e0e7c | 2005-12-03 23:02:33 +0000 | [diff] [blame] | 1620 | <!-- end of xi:include in the manpage --> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 1621 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1622 | </sect2> |
| 1623 | |
| 1624 | |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 1625 | <sect2 id="manual-core.debugopts" xreflabel="Debugging Options"> |
| 1626 | <title>Debugging Options</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1627 | |
de | 03e0e7c | 2005-12-03 23:02:33 +0000 | [diff] [blame] | 1628 | <!-- start of xi:include in the manpage --> |
| 1629 | <para id="debug.opts.para">There are also some options for debugging |
| 1630 | Valgrind itself. You shouldn't need to use them in the normal run of |
| 1631 | things. If you wish to see the list, use the |
| 1632 | <option>--help-debug</option> option.</para> |
| 1633 | <!-- end of xi:include in the manpage --> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1634 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1635 | </sect2> |
| 1636 | |
| 1637 | |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 1638 | <sect2 id="manual-core.defopts" xreflabel="Setting Default Options"> |
| 1639 | <title>Setting Default Options</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1640 | |
| 1641 | <para>Note that Valgrind also reads options from three places:</para> |
| 1642 | |
| 1643 | <orderedlist> |
| 1644 | <listitem> |
| 1645 | <para>The file <computeroutput>~/.valgrindrc</computeroutput></para> |
| 1646 | </listitem> |
| 1647 | |
| 1648 | <listitem> |
| 1649 | <para>The environment variable |
| 1650 | <computeroutput>$VALGRIND_OPTS</computeroutput></para> |
| 1651 | </listitem> |
| 1652 | |
| 1653 | <listitem> |
| 1654 | <para>The file <computeroutput>./.valgrindrc</computeroutput></para> |
| 1655 | </listitem> |
| 1656 | </orderedlist> |
| 1657 | |
| 1658 | <para>These are processed in the given order, before the |
| 1659 | command-line options. Options processed later override those |
| 1660 | processed earlier; for example, options in |
| 1661 | <computeroutput>./.valgrindrc</computeroutput> will take |
| 1662 | precedence over those in |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1663 | <computeroutput>~/.valgrindrc</computeroutput>. |
dirk | a656f3d | 2008-11-22 12:03:19 +0000 | [diff] [blame] | 1664 | </para> |
| 1665 | |
| 1666 | <para>Please note that the <computeroutput>./.valgrindrc</computeroutput> |
| 1667 | file is ignored if it is marked as world writeable or not owned |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1668 | by the current user. This is because the |
| 1669 | <computeroutput>./.valgrindrc</computeroutput> can contain options that are |
| 1670 | potentially harmful or can be used by a local attacker to execute code under |
| 1671 | your user account. |
dirk | a656f3d | 2008-11-22 12:03:19 +0000 | [diff] [blame] | 1672 | </para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1673 | |
| 1674 | <para>Any tool-specific options put in |
| 1675 | <computeroutput>$VALGRIND_OPTS</computeroutput> or the |
| 1676 | <computeroutput>.valgrindrc</computeroutput> files should be |
| 1677 | prefixed with the tool name and a colon. For example, if you |
| 1678 | want Memcheck to always do leak checking, you can put the |
| 1679 | following entry in <literal>~/.valgrindrc</literal>:</para> |
| 1680 | |
| 1681 | <programlisting><![CDATA[ |
| 1682 | --memcheck:leak-check=yes]]></programlisting> |
| 1683 | |
| 1684 | <para>This will be ignored if any tool other than Memcheck is |
| 1685 | run. Without the <computeroutput>memcheck:</computeroutput> |
| 1686 | part, this will cause problems if you select other tools that |
| 1687 | don't understand |
njn | 7e5d4ed | 2009-07-30 02:57:52 +0000 | [diff] [blame] | 1688 | <option>--leak-check=yes</option>.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1689 | |
| 1690 | </sect2> |
| 1691 | |
| 1692 | </sect1> |
| 1693 | |
| 1694 | |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1695 | |
| 1696 | |
| 1697 | <sect1 id="manual-core.pthreads" xreflabel="Support for Threads"> |
| 1698 | <title>Support for Threads</title> |
| 1699 | |
sewardj | e77c724 | 2009-08-16 22:49:53 +0000 | [diff] [blame] | 1700 | <para>Threaded programs are fully supported.</para> |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1701 | |
sewardj | e77c724 | 2009-08-16 22:49:53 +0000 | [diff] [blame] | 1702 | <para>The main thing to point out with respect to threaded programs is |
| 1703 | that your program will use the native threading library, but Valgrind |
| 1704 | serialises execution so that only one (kernel) thread is running at a |
| 1705 | time. This approach avoids the horrible implementation problems of |
| 1706 | implementing a truly multithreaded version of Valgrind, but it does |
| 1707 | mean that threaded apps run only on one CPU, even if you have a |
| 1708 | multiprocessor or multicore machine.</para> |
| 1709 | |
| 1710 | <para>Valgrind doesn't schedule the threads itself. It merely ensures |
| 1711 | that only one thread runs at once, using a simple locking scheme. The |
| 1712 | actual thread scheduling remains under control of the OS kernel. What |
| 1713 | this does mean, though, is that your program will see very different |
| 1714 | scheduling when run on Valgrind than it does when running normally. |
| 1715 | This is both because Valgrind is serialising the threads, and because |
| 1716 | the code runs so much slower than normal.</para> |
| 1717 | |
| 1718 | <para>This difference in scheduling may cause your program to behave |
| 1719 | differently, if you have some kind of concurrency, critical race, |
| 1720 | locking, or similar, bugs. In that case you might consider using the |
| 1721 | tools Helgrind and/or DRD to track them down.</para> |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1722 | |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1723 | <para>On Linux, Valgrind also supports direct use of the |
| 1724 | <computeroutput>clone</computeroutput> system call, |
| 1725 | <computeroutput>futex</computeroutput> and so on. |
| 1726 | <computeroutput>clone</computeroutput> is supported where either |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1727 | everything is shared (a thread) or nothing is shared (fork-like); partial |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1728 | sharing will fail. |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1729 | </para> |
| 1730 | |
| 1731 | |
| 1732 | </sect1> |
| 1733 | |
| 1734 | <sect1 id="manual-core.signals" xreflabel="Handling of Signals"> |
| 1735 | <title>Handling of Signals</title> |
| 1736 | |
| 1737 | <para>Valgrind has a fairly complete signal implementation. It should be |
| 1738 | able to cope with any POSIX-compliant use of signals.</para> |
| 1739 | |
| 1740 | <para>If you're using signals in clever ways (for example, catching |
| 1741 | SIGSEGV, modifying page state and restarting the instruction), you're |
| 1742 | probably relying on precise exceptions. In this case, you will need |
njn | 7e5d4ed | 2009-07-30 02:57:52 +0000 | [diff] [blame] | 1743 | to use <option>--vex-iropt-precise-memory-exns=yes</option>. |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1744 | </para> |
| 1745 | |
| 1746 | <para>If your program dies as a result of a fatal core-dumping signal, |
| 1747 | Valgrind will generate its own core file |
| 1748 | (<computeroutput>vgcore.NNNNN</computeroutput>) containing your program's |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1749 | 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] | 1750 | similar. (Note: it will not generate a core if your core dump size limit is |
| 1751 | 0.) At the time of writing the core dumps do not include all the floating |
| 1752 | point register information.</para> |
| 1753 | |
| 1754 | <para>In the unlikely event that Valgrind itself crashes, the operating system |
| 1755 | will create a core dump in the usual way.</para> |
| 1756 | |
| 1757 | </sect1> |
| 1758 | |
| 1759 | |
| 1760 | |
| 1761 | |
| 1762 | |
| 1763 | |
| 1764 | |
| 1765 | |
| 1766 | <sect1 id="manual-core.install" xreflabel="Building and Installing"> |
| 1767 | <title>Building and Installing Valgrind</title> |
| 1768 | |
| 1769 | <para>We use the standard Unix |
| 1770 | <computeroutput>./configure</computeroutput>, |
| 1771 | <computeroutput>make</computeroutput>, <computeroutput>make |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1772 | install</computeroutput> mechanism. Once you have completed |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1773 | <computeroutput>make install</computeroutput> you may then want |
| 1774 | to run the regression tests |
| 1775 | with <computeroutput>make regtest</computeroutput>. |
| 1776 | </para> |
| 1777 | |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1778 | <para>In addition to the usual |
| 1779 | <option>--prefix=/path/to/install/tree</option>, there are three |
| 1780 | options which affect how Valgrind is built: |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1781 | <itemizedlist> |
| 1782 | |
| 1783 | <listitem> |
| 1784 | <para><option>--enable-inner</option></para> |
| 1785 | <para>This builds Valgrind with some special magic hacks which make |
| 1786 | it possible to run it on a standard build of Valgrind (what the |
| 1787 | developers call "self-hosting"). Ordinarily you should not use |
njn | f4b4758 | 2009-08-10 01:15:30 +0000 | [diff] [blame] | 1788 | this option as various kinds of safety checks are disabled. |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1789 | </para> |
| 1790 | </listitem> |
| 1791 | |
| 1792 | <listitem> |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1793 | <para><option>--enable-only64bit</option></para> |
| 1794 | <para><option>--enable-only32bit</option></para> |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1795 | <para>On 64-bit platforms (amd64-linux, ppc64-linux, |
| 1796 | amd64-darwin), Valgrind is by default built in such a way that |
| 1797 | both 32-bit and 64-bit executables can be run. Sometimes this |
| 1798 | cleverness is a problem for a variety of reasons. These two |
| 1799 | options allow for single-target builds in this situation. If you |
| 1800 | issue both, the configure script will complain. Note they are |
| 1801 | ignored on 32-bit-only platforms (x86-linux, ppc32-linux, |
| 1802 | arm-linux, x86-darwin). |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1803 | </para> |
| 1804 | </listitem> |
| 1805 | |
| 1806 | </itemizedlist> |
| 1807 | </para> |
| 1808 | |
| 1809 | <para>The <computeroutput>configure</computeroutput> script tests |
| 1810 | the version of the X server currently indicated by the current |
| 1811 | <computeroutput>$DISPLAY</computeroutput>. This is a known bug. |
| 1812 | The intention was to detect the version of the current X |
| 1813 | client libraries, so that correct suppressions could be selected |
| 1814 | for them, but instead the test checks the server version. This |
| 1815 | is just plain wrong.</para> |
| 1816 | |
| 1817 | <para>If you are building a binary package of Valgrind for |
| 1818 | distribution, please read <literal>README_PACKAGERS</literal> |
| 1819 | <xref linkend="dist.readme-packagers"/>. It contains some |
| 1820 | important information.</para> |
| 1821 | |
| 1822 | <para>Apart from that, there's not much excitement here. Let us |
| 1823 | know if you have build problems.</para> |
| 1824 | |
| 1825 | </sect1> |
| 1826 | |
| 1827 | |
| 1828 | |
| 1829 | <sect1 id="manual-core.problems" xreflabel="If You Have Problems"> |
| 1830 | <title>If You Have Problems</title> |
| 1831 | |
| 1832 | <para>Contact us at <ulink url="&vg-url;">&vg-url;</ulink>.</para> |
| 1833 | |
| 1834 | <para>See <xref linkend="manual-core.limits"/> for the known |
| 1835 | limitations of Valgrind, and for a list of programs which are |
| 1836 | known not to work on it.</para> |
| 1837 | |
| 1838 | <para>All parts of the system make heavy use of assertions and |
| 1839 | internal self-checks. They are permanently enabled, and we have no |
| 1840 | plans to disable them. If one of them breaks, please mail us!</para> |
| 1841 | |
| 1842 | <para>If you get an assertion failure |
| 1843 | in <filename>m_mallocfree.c</filename>, this may have happened because |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1844 | your program wrote off the end of a heap block, or before its |
| 1845 | beginning, thus corrupting head metadata. Valgrind hopefully will have |
| 1846 | emitted a message to that effect before dying in this way.</para> |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1847 | |
| 1848 | <para>Read the <xref linkend="FAQ"/> for more advice about common problems, |
| 1849 | crashes, etc.</para> |
| 1850 | |
| 1851 | </sect1> |
| 1852 | |
| 1853 | |
| 1854 | |
| 1855 | <sect1 id="manual-core.limits" xreflabel="Limitations"> |
| 1856 | <title>Limitations</title> |
| 1857 | |
| 1858 | <para>The following list of limitations seems long. However, most |
| 1859 | programs actually work fine.</para> |
| 1860 | |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1861 | <para>Valgrind will run programs on the supported platforms |
| 1862 | subject to the following constraints:</para> |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1863 | |
| 1864 | <itemizedlist> |
| 1865 | <listitem> |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1866 | <para>On x86 and amd64, there is no support for 3DNow! |
| 1867 | instructions. If the translator encounters these, Valgrind will |
| 1868 | generate a SIGILL when the instruction is executed. Apart from |
| 1869 | that, on x86 and amd64, essentially all instructions are supported, |
| 1870 | up to and including SSE4.2 in 64-bit mode and SSSE3 in 32-bit mode. |
| 1871 | Some exceptions: SSE4.2 AES instructions are not supported in |
| 1872 | 64-bit mode, and 32-bit mode does in fact support the bare minimum |
| 1873 | SSE4 instructions to needed to run programs on MacOSX 10.6 on |
| 1874 | 32-bit targets. |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1875 | </para> |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1876 | </listitem> |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1877 | |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1878 | <listitem> |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1879 | <para>On ppc32 and ppc64, almost all integer, floating point and |
| 1880 | Altivec instructions are supported. Specifically: integer and FP |
| 1881 | insns that are mandatory for PowerPC, the "General-purpose |
| 1882 | optional" group (fsqrt, fsqrts, stfiwx), the "Graphics optional" |
| 1883 | group (fre, fres, frsqrte, frsqrtes), and the Altivec (also known |
| 1884 | as VMX) SIMD instruction set, are supported. Also, instructions |
| 1885 | from the Power ISA 2.05 specification, as present in POWER6 CPUs, |
| 1886 | are supported.</para> |
| 1887 | </listitem> |
| 1888 | |
| 1889 | <listitem> |
| 1890 | <para>On ARM, essentially the entire ARMv7-A instruction set |
| 1891 | is supported, in both ARM and Thumb mode. ThumbEE and Jazelle are |
| 1892 | not supported. NEON and VFPv3 support is fairly complete. ARMv6 |
| 1893 | media instruction support is mostly done but not yet complete. |
| 1894 | </para> |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1895 | </listitem> |
| 1896 | |
| 1897 | <listitem> |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1898 | <para>If your program does its own memory management, rather than |
| 1899 | using malloc/new/free/delete, it should still work, but Memcheck's |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1900 | error checking won't be so effective. If you describe your |
| 1901 | program's memory management scheme using "client requests" (see |
| 1902 | <xref linkend="manual-core-adv.clientreq"/>), Memcheck can do |
| 1903 | better. Nevertheless, using malloc/new and free/delete is still |
| 1904 | the best approach.</para> |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1905 | </listitem> |
| 1906 | |
| 1907 | <listitem> |
| 1908 | <para>Valgrind's signal simulation is not as robust as it could be. |
| 1909 | Basic POSIX-compliant sigaction and sigprocmask functionality is |
| 1910 | supplied, but it's conceivable that things could go badly awry if you |
| 1911 | do weird things with signals. Workaround: don't. Programs that do |
| 1912 | non-POSIX signal tricks are in any case inherently unportable, so |
| 1913 | should be avoided if possible.</para> |
| 1914 | </listitem> |
| 1915 | |
| 1916 | <listitem> |
| 1917 | <para>Machine instructions, and system calls, have been implemented |
| 1918 | on demand. So it's possible, although unlikely, that a program will |
| 1919 | fall over with a message to that effect. If this happens, please |
| 1920 | report all the details printed out, so we can try and implement the |
| 1921 | missing feature.</para> |
| 1922 | </listitem> |
| 1923 | |
| 1924 | <listitem> |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1925 | <para>Memory consumption of your program is majorly increased |
| 1926 | whilst running under Valgrind's Memcheck tool. This is due to the |
| 1927 | large amount of administrative information maintained behind the |
| 1928 | scenes. Another cause is that Valgrind dynamically translates the |
| 1929 | original executable. Translated, instrumented code is 12-18 times |
| 1930 | larger than the original so you can easily end up with 100+ MB of |
| 1931 | translations when running (eg) a web browser.</para> |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1932 | </listitem> |
| 1933 | |
| 1934 | <listitem> |
| 1935 | <para>Valgrind can handle dynamically-generated code just fine. If |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 1936 | you regenerate code over the top of old code (ie. at the same |
| 1937 | memory addresses), if the code is on the stack Valgrind will |
| 1938 | realise the code has changed, and work correctly. This is |
| 1939 | necessary to handle the trampolines GCC uses to implemented nested |
| 1940 | functions. If you regenerate code somewhere other than the stack, |
| 1941 | and you are running on an 32- or 64-bit x86 CPU, you will need to |
| 1942 | use the <option>--smc-check=all</option> option, and Valgrind will |
| 1943 | run more slowly than normal. Or you can add client requests that |
| 1944 | tell Valgrind when your program has overwritten code. |
| 1945 | </para> |
| 1946 | <para> On other platforms (ARM, PowerPC) Valgrind observes and |
| 1947 | honours the cache invalidation hints that programs are obliged to |
| 1948 | emit to notify new code, and so self-modifying-code support should |
| 1949 | work automatically, without the need |
| 1950 | for <option>--smc-check=all</option>.</para> |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1951 | </listitem> |
| 1952 | |
| 1953 | <listitem> |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 1954 | <para>Valgrind has the following limitations |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 1955 | in its implementation of x86/AMD64 floating point relative to |
| 1956 | IEEE754.</para> |
| 1957 | |
| 1958 | <para>Precision: There is no support for 80 bit arithmetic. |
| 1959 | Internally, Valgrind represents all such "long double" numbers in 64 |
| 1960 | bits, and so there may be some differences in results. Whether or |
| 1961 | not this is critical remains to be seen. Note, the x86/amd64 |
| 1962 | fldt/fstpt instructions (read/write 80-bit numbers) are correctly |
| 1963 | simulated, using conversions to/from 64 bits, so that in-memory |
| 1964 | images of 80-bit numbers look correct if anyone wants to see.</para> |
| 1965 | |
| 1966 | <para>The impression observed from many FP regression tests is that |
| 1967 | the accuracy differences aren't significant. Generally speaking, if |
| 1968 | a program relies on 80-bit precision, there may be difficulties |
| 1969 | porting it to non x86/amd64 platforms which only support 64-bit FP |
| 1970 | precision. Even on x86/amd64, the program may get different results |
| 1971 | depending on whether it is compiled to use SSE2 instructions (64-bits |
| 1972 | only), or x87 instructions (80-bit). The net effect is to make FP |
| 1973 | programs behave as if they had been run on a machine with 64-bit IEEE |
| 1974 | floats, for example PowerPC. On amd64 FP arithmetic is done by |
| 1975 | default on SSE2, so amd64 looks more like PowerPC than x86 from an FP |
| 1976 | perspective, and there are far fewer noticeable accuracy differences |
| 1977 | than with x86.</para> |
| 1978 | |
| 1979 | <para>Rounding: Valgrind does observe the 4 IEEE-mandated rounding |
| 1980 | modes (to nearest, to +infinity, to -infinity, to zero) for the |
| 1981 | following conversions: float to integer, integer to float where |
| 1982 | there is a possibility of loss of precision, and float-to-float |
| 1983 | rounding. For all other FP operations, only the IEEE default mode |
| 1984 | (round to nearest) is supported.</para> |
| 1985 | |
| 1986 | <para>Numeric exceptions in FP code: IEEE754 defines five types of |
| 1987 | numeric exception that can happen: invalid operation (sqrt of |
| 1988 | negative number, etc), division by zero, overflow, underflow, |
| 1989 | inexact (loss of precision).</para> |
| 1990 | |
| 1991 | <para>For each exception, two courses of action are defined by IEEE754: |
| 1992 | either (1) a user-defined exception handler may be called, or (2) a |
| 1993 | default action is defined, which "fixes things up" and allows the |
| 1994 | computation to proceed without throwing an exception.</para> |
| 1995 | |
| 1996 | <para>Currently Valgrind only supports the default fixup actions. |
| 1997 | Again, feedback on the importance of exception support would be |
| 1998 | appreciated.</para> |
| 1999 | |
| 2000 | <para>When Valgrind detects that the program is trying to exceed any |
| 2001 | of these limitations (setting exception handlers, rounding mode, or |
| 2002 | precision control), it can print a message giving a traceback of |
| 2003 | where this has happened, and continue execution. This behaviour used |
| 2004 | to be the default, but the messages are annoying and so showing them |
| 2005 | is now disabled by default. Use <option>--show-emwarns=yes</option> to see |
| 2006 | them.</para> |
| 2007 | |
| 2008 | <para>The above limitations define precisely the IEEE754 'default' |
| 2009 | behaviour: default fixup on all exceptions, round-to-nearest |
| 2010 | operations, and 64-bit precision.</para> |
| 2011 | </listitem> |
| 2012 | |
| 2013 | <listitem> |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 2014 | <para>Valgrind has the following limitations in |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 2015 | its implementation of x86/AMD64 SSE2 FP arithmetic, relative to |
| 2016 | IEEE754.</para> |
| 2017 | |
| 2018 | <para>Essentially the same: no exceptions, and limited observance of |
| 2019 | rounding mode. Also, SSE2 has control bits which make it treat |
| 2020 | denormalised numbers as zero (DAZ) and a related action, flush |
| 2021 | denormals to zero (FTZ). Both of these cause SSE2 arithmetic to be |
| 2022 | less accurate than IEEE requires. Valgrind detects, ignores, and can |
| 2023 | warn about, attempts to enable either mode.</para> |
| 2024 | </listitem> |
| 2025 | |
| 2026 | <listitem> |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 2027 | <para>Valgrind has the following limitations in |
| 2028 | its implementation of ARM VFPv3 arithmetic, relative to |
| 2029 | IEEE754.</para> |
| 2030 | |
| 2031 | <para>Essentially the same: no exceptions, and limited observance |
| 2032 | of rounding mode. Also, switching the VFP unit into vector mode |
| 2033 | will cause Valgrind to abort the program -- it has no way to |
| 2034 | emulate vector uses of VFP at a reasonable performance level. This |
| 2035 | is no big deal given that non-scalar uses of VFP instructions are |
| 2036 | in any case deprecated.</para> |
| 2037 | </listitem> |
| 2038 | |
| 2039 | <listitem> |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 2040 | <para>Valgrind has the following limitations |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 2041 | in its implementation of PPC32 and PPC64 floating point |
| 2042 | arithmetic, relative to IEEE754.</para> |
| 2043 | |
| 2044 | <para>Scalar (non-Altivec): Valgrind provides a bit-exact emulation of |
| 2045 | all floating point instructions, except for "fre" and "fres", which are |
| 2046 | done more precisely than required by the PowerPC architecture specification. |
| 2047 | All floating point operations observe the current rounding mode. |
| 2048 | </para> |
| 2049 | |
| 2050 | <para>However, fpscr[FPRF] is not set after each operation. That could |
| 2051 | be done but would give measurable performance overheads, and so far |
| 2052 | no need for it has been found.</para> |
| 2053 | |
| 2054 | <para>As on x86/AMD64, IEEE754 exceptions are not supported: all floating |
| 2055 | point exceptions are handled using the default IEEE fixup actions. |
| 2056 | Valgrind detects, ignores, and can warn about, attempts to unmask |
| 2057 | the 5 IEEE FP exception kinds by writing to the floating-point status |
| 2058 | and control register (fpscr). |
| 2059 | </para> |
| 2060 | |
| 2061 | <para>Vector (Altivec, VMX): essentially as with x86/AMD64 SSE/SSE2: |
| 2062 | no exceptions, and limited observance of rounding mode. |
| 2063 | For Altivec, FP arithmetic |
| 2064 | is done in IEEE/Java mode, which is more accurate than the Linux default |
| 2065 | setting. "More accurate" means that denormals are handled properly, |
| 2066 | rather than simply being flushed to zero.</para> |
| 2067 | </listitem> |
| 2068 | </itemizedlist> |
| 2069 | |
| 2070 | <para>Programs which are known not to work are:</para> |
| 2071 | <itemizedlist> |
| 2072 | <listitem> |
| 2073 | <para>emacs starts up but immediately concludes it is out of |
| 2074 | memory and aborts. It may be that Memcheck does not provide |
| 2075 | a good enough emulation of the |
| 2076 | <computeroutput>mallinfo</computeroutput> function. |
| 2077 | Emacs works fine if you build it to use |
| 2078 | the standard malloc/free routines.</para> |
| 2079 | </listitem> |
| 2080 | </itemizedlist> |
| 2081 | |
| 2082 | </sect1> |
| 2083 | |
| 2084 | |
| 2085 | <sect1 id="manual-core.example" xreflabel="An Example Run"> |
| 2086 | <title>An Example Run</title> |
| 2087 | |
| 2088 | <para>This is the log for a run of a small program using Memcheck. |
| 2089 | The program is in fact correct, and the reported error is as the |
| 2090 | result of a potentially serious code generation bug in GNU g++ |
| 2091 | (snapshot 20010527).</para> |
| 2092 | |
| 2093 | <programlisting><![CDATA[ |
| 2094 | sewardj@phoenix:~/newmat10$ ~/Valgrind-6/valgrind -v ./bogon |
| 2095 | ==25832== Valgrind 0.10, a memory error detector for x86 RedHat 7.1. |
| 2096 | ==25832== Copyright (C) 2000-2001, and GNU GPL'd, by Julian Seward. |
| 2097 | ==25832== Startup, with flags: |
| 2098 | ==25832== --suppressions=/home/sewardj/Valgrind/redhat71.supp |
| 2099 | ==25832== reading syms from /lib/ld-linux.so.2 |
| 2100 | ==25832== reading syms from /lib/libc.so.6 |
| 2101 | ==25832== reading syms from /mnt/pima/jrs/Inst/lib/libgcc_s.so.0 |
| 2102 | ==25832== reading syms from /lib/libm.so.6 |
| 2103 | ==25832== reading syms from /mnt/pima/jrs/Inst/lib/libstdc++.so.3 |
| 2104 | ==25832== reading syms from /home/sewardj/Valgrind/valgrind.so |
| 2105 | ==25832== reading syms from /proc/self/exe |
| 2106 | ==25832== |
| 2107 | ==25832== Invalid read of size 4 |
| 2108 | ==25832== at 0x8048724: BandMatrix::ReSize(int,int,int) (bogon.cpp:45) |
| 2109 | ==25832== by 0x80487AF: main (bogon.cpp:66) |
| 2110 | ==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd |
| 2111 | ==25832== |
| 2112 | ==25832== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) |
| 2113 | ==25832== malloc/free: in use at exit: 0 bytes in 0 blocks. |
| 2114 | ==25832== malloc/free: 0 allocs, 0 frees, 0 bytes allocated. |
| 2115 | ==25832== For a detailed leak analysis, rerun with: --leak-check=yes |
| 2116 | ]]></programlisting> |
| 2117 | |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 2118 | <para>The GCC folks fixed this about a week before GCC 3.0 |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 2119 | shipped.</para> |
| 2120 | |
| 2121 | </sect1> |
| 2122 | |
| 2123 | |
| 2124 | <sect1 id="manual-core.warnings" xreflabel="Warning Messages"> |
| 2125 | <title>Warning Messages You Might See</title> |
| 2126 | |
njn | 7316df2 | 2009-08-04 01:16:01 +0000 | [diff] [blame] | 2127 | <para>Some of these only appear if you run in verbose mode |
njn | 7e5d4ed | 2009-07-30 02:57:52 +0000 | [diff] [blame] | 2128 | (enabled by <option>-v</option>):</para> |
sewardj | 778d783 | 2007-11-22 01:21:56 +0000 | [diff] [blame] | 2129 | |
| 2130 | <itemizedlist> |
| 2131 | |
| 2132 | <listitem> |
| 2133 | <para><computeroutput>More than 100 errors detected. Subsequent |
| 2134 | errors will still be recorded, but in less detail than |
| 2135 | before.</computeroutput></para> |
| 2136 | |
| 2137 | <para>After 100 different errors have been shown, Valgrind becomes |
| 2138 | more conservative about collecting them. It then requires only the |
| 2139 | program counters in the top two stack frames to match when deciding |
| 2140 | whether or not two errors are really the same one. Prior to this |
| 2141 | point, the PCs in the top four frames are required to match. This |
| 2142 | hack has the effect of slowing down the appearance of new errors |
| 2143 | after the first 100. The 100 constant can be changed by recompiling |
| 2144 | Valgrind.</para> |
| 2145 | </listitem> |
| 2146 | |
| 2147 | <listitem> |
| 2148 | <para><computeroutput>More than 1000 errors detected. I'm not |
| 2149 | reporting any more. Final error counts may be inaccurate. Go fix |
| 2150 | your program!</computeroutput></para> |
| 2151 | |
| 2152 | <para>After 1000 different errors have been detected, Valgrind |
| 2153 | ignores any more. It seems unlikely that collecting even more |
| 2154 | different ones would be of practical help to anybody, and it avoids |
| 2155 | the danger that Valgrind spends more and more of its time comparing |
| 2156 | new errors against an ever-growing collection. As above, the 1000 |
| 2157 | number is a compile-time constant.</para> |
| 2158 | </listitem> |
| 2159 | |
| 2160 | <listitem> |
| 2161 | <para><computeroutput>Warning: client switching stacks?</computeroutput></para> |
| 2162 | |
| 2163 | <para>Valgrind spotted such a large change in the stack pointer |
| 2164 | that it guesses the client is switching to |
| 2165 | a different stack. At this point it makes a kludgey guess where the |
| 2166 | base of the new stack is, and sets memory permissions accordingly. |
| 2167 | You may get many bogus error messages following this, if Valgrind |
| 2168 | guesses wrong. At the moment "large change" is defined as a change |
| 2169 | of more that 2000000 in the value of the |
| 2170 | stack pointer register.</para> |
| 2171 | </listitem> |
| 2172 | |
| 2173 | <listitem> |
| 2174 | <para><computeroutput>Warning: client attempted to close Valgrind's |
| 2175 | logfile fd <number></computeroutput></para> |
| 2176 | |
| 2177 | <para>Valgrind doesn't allow the client to close the logfile, |
| 2178 | because you'd never see any diagnostic information after that point. |
| 2179 | If you see this message, you may want to use the |
| 2180 | <option>--log-fd=<number></option> option to specify a |
| 2181 | different logfile file-descriptor number.</para> |
| 2182 | </listitem> |
| 2183 | |
| 2184 | <listitem> |
| 2185 | <para><computeroutput>Warning: noted but unhandled ioctl |
| 2186 | <number></computeroutput></para> |
| 2187 | |
| 2188 | <para>Valgrind observed a call to one of the vast family of |
| 2189 | <computeroutput>ioctl</computeroutput> system calls, but did not |
| 2190 | modify its memory status info (because nobody has yet written a |
| 2191 | suitable wrapper). The call will still have gone through, but you may get |
| 2192 | spurious errors after this as a result of the non-update of the |
| 2193 | memory info.</para> |
| 2194 | </listitem> |
| 2195 | |
| 2196 | <listitem> |
| 2197 | <para><computeroutput>Warning: set address range perms: large range |
| 2198 | <number></computeroutput></para> |
| 2199 | |
| 2200 | <para>Diagnostic message, mostly for benefit of the Valgrind |
| 2201 | developers, to do with memory permissions.</para> |
| 2202 | </listitem> |
| 2203 | |
| 2204 | </itemizedlist> |
| 2205 | |
| 2206 | </sect1> |
| 2207 | |
| 2208 | |
| 2209 | |
sewardj | f5a491c | 2006-03-13 13:40:57 +0000 | [diff] [blame] | 2210 | |
| 2211 | |
sewardj | a737e65 | 2006-03-19 18:19:11 +0000 | [diff] [blame] | 2212 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 2213 | </chapter> |