njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1 | <?xml version="1.0"?> <!-- -*- sgml -*- --> |
| 2 | <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" |
| 3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" |
| 4 | [ <!ENTITY % vg-entities SYSTEM "vg-entities.xml"> %vg-entities; ]> |
| 5 | |
de | 252c614 | 2005-11-27 04:10:00 +0000 | [diff] [blame] | 6 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 7 | <book id="FAQ" xreflabel="Valgrind FAQ"> |
de | 53ad684 | 2005-11-19 03:28:10 +0000 | [diff] [blame] | 8 | |
de | e9b715c | 2005-08-03 20:28:33 +0000 | [diff] [blame] | 9 | <bookinfo> |
de | 53ad684 | 2005-11-19 03:28:10 +0000 | [diff] [blame] | 10 | <title>Valgrind FAQ</title> |
de | 53ad684 | 2005-11-19 03:28:10 +0000 | [diff] [blame] | 11 | <releaseinfo>&rel-type; &rel-version; &rel-date;</releaseinfo> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 12 | <copyright> |
| 13 | <year>&vg-lifespan;</year> |
| 14 | <holder><ulink url="&vg-developers;">Valgrind Developers</ulink></holder> |
| 15 | </copyright> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 16 | <legalnotice> |
| 17 | <para>Email: <ulink url="mailto:&vg-vemail;">&vg-vemail;</ulink></para> |
| 18 | </legalnotice> |
de | e9b715c | 2005-08-03 20:28:33 +0000 | [diff] [blame] | 19 | </bookinfo> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 20 | |
de | 53ad684 | 2005-11-19 03:28:10 +0000 | [diff] [blame] | 21 | |
de | 252c614 | 2005-11-27 04:10:00 +0000 | [diff] [blame] | 22 | <article id="faq"> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 23 | <title>Valgrind Frequently Asked Questions</title> |
| 24 | |
| 25 | |
| 26 | <!-- FAQ starts here --> |
| 27 | <qandaset> |
| 28 | |
| 29 | |
| 30 | <!-- Background --> |
| 31 | <qandadiv id="faq.background" xreflabel="Background"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 32 | <title>Background</title> |
| 33 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 34 | <qandaentry id="faq.pronounce"> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 35 | <question id="q-pronounce"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 36 | <para>How do you pronounce "Valgrind"?</para> |
| 37 | </question> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 38 | <answer id="a-pronounce"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 39 | <para>The "Val" as in the world "value". The "grind" is pronounced |
| 40 | with a short 'i' -- ie. "grinned" (rhymes with "tinned") rather than |
| 41 | "grined" (rhymes with "find").</para> <para>Don't feel bad: almost |
| 42 | everyone gets it wrong at first.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 43 | </answer> |
| 44 | </qandaentry> |
| 45 | |
| 46 | <qandaentry id="faq.whence"> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 47 | <question id="q-whence"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 48 | <para>Where does the name "Valgrind" come from?</para> |
| 49 | </question> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 50 | <answer id="a-whence"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 51 | |
| 52 | <para>From Nordic mythology. Originally (before release) the project |
| 53 | was named Heimdall, after the watchman of the Nordic gods. He could |
| 54 | "see a hundred miles by day or night, hear the grass growing, see the |
| 55 | wool growing on a sheep's back" (etc). This would have been a great |
| 56 | name, but it was already taken by a security package "Heimdal".</para> |
| 57 | |
| 58 | <para>Keeping with the Nordic theme, Valgrind was chosen. Valgrind is |
| 59 | the name of the main entrance to Valhalla (the Hall of the Chosen |
| 60 | Slain in Asgard). Over this entrance there resides a wolf and over it |
| 61 | there is the head of a boar and on it perches a huge eagle, whose eyes |
| 62 | can see to the far regions of the nine worlds. Only those judged |
| 63 | worthy by the guardians are allowed to pass through Valgrind. All |
| 64 | others are refused entrance.</para> |
| 65 | |
| 66 | <para>It's not short for "value grinder", although that's not a bad |
| 67 | guess.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 68 | </answer> |
| 69 | </qandaentry> |
| 70 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 71 | </qandadiv> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 72 | |
| 73 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 74 | |
| 75 | <!-- Compiling, Installing and Configuring --> |
| 76 | <qandadiv id="faq.installing" xreflabel="Compiling, installing and configuring"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 77 | <title>Compiling, installing and configuring</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 78 | |
| 79 | <qandaentry id="faq.make_dies"> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 80 | <question id="q-make_dies"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 81 | <para>When I trying building Valgrind, 'make' dies partway with |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 82 | an assertion failure, something like this:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 83 | <screen> |
| 84 | % make: expand.c:489: allocated_variable_append: |
| 85 | Assertion 'current_variable_set_list->next != 0' failed. |
| 86 | </screen> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 87 | </question> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 88 | <answer id="a-make_dies"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 89 | <para>It's probably a bug in 'make'. Some, but not all, instances of |
| 90 | version 3.79.1 have this bug, see |
| 91 | www.mail-archive.com/bug-make@gnu.org/msg01658.html. Try upgrading to |
| 92 | a more recent version of 'make'. Alternatively, we have heard that |
| 93 | unsetting the CFLAGS environment variable avoids the problem.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 94 | </answer> |
| 95 | </qandaentry> |
| 96 | |
njn | a874ef4 | 2006-04-06 14:04:48 +0000 | [diff] [blame] | 97 | <qandaentry id="faq.glibc_devel"> |
| 98 | <question> |
| 99 | <para>When I try to build Valgrind, 'make' fails with |
| 100 | <programlisting> |
| 101 | /usr/bin/ld: cannot find -lc |
| 102 | collect2: ld returned 1 exit status |
| 103 | </programlisting> |
| 104 | </para> |
| 105 | </question> |
| 106 | <answer> |
| 107 | <para>You need to install the glibc-static-devel package.</para> |
| 108 | </answer> |
| 109 | </qandaentry> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 110 | |
njn | a874ef4 | 2006-04-06 14:04:48 +0000 | [diff] [blame] | 111 | </qandadiv> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 112 | |
| 113 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 114 | <!-- Valgrind aborts unexpectedly --> |
| 115 | <qandadiv id="faq.abort" xreflabel="Valgrind aborts unexpectedly"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 116 | <title>Valgrind aborts unexpectedly</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 117 | |
| 118 | <qandaentry id="faq.exit_errors"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 119 | <question id="q-exit_errors"> |
| 120 | <para>Programs run OK on Valgrind, but at exit produce a bunch of |
| 121 | errors involving <literal>__libc_freeres()</literal> and then die |
| 122 | with a segmentation fault.</para> |
| 123 | </question> |
| 124 | <answer id="a-exit_errors"> |
| 125 | <para>When the program exits, Valgrind runs the procedure |
| 126 | <function>__libc_freeres()</function> in glibc. This is a hook for |
| 127 | memory debuggers, so they can ask glibc to free up any memory it has |
| 128 | used. Doing that is needed to ensure that Valgrind doesn't |
| 129 | incorrectly report space leaks in glibc.</para> |
| 130 | |
| 131 | <para>Problem is that running <literal>__libc_freeres()</literal> in |
| 132 | older glibc versions causes this crash.</para> |
| 133 | |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame^] | 134 | <para>Workaround for 1.1.X and later versions of Valgrind: use the |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 135 | <option>--run-libc-freeres=no</option> flag. You may then get space |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame^] | 136 | leak reports for glibc allocations (please don't report these to |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 137 | the glibc people, since they are not real leaks), but at least the |
| 138 | program runs.</para> |
| 139 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 140 | </qandaentry> |
| 141 | |
| 142 | <qandaentry id="faq.bugdeath"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 143 | <question id="q-bugdeath"> |
| 144 | <para>My (buggy) program dies like this:</para> |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame^] | 145 | <screen>valgrind: m_mallocfree.c:442 (bszW_to_pszW): Assertion 'pszW >= 0' failed.</screen> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 146 | </question> |
| 147 | <answer id="a-bugdeath"> |
| 148 | <para>If Memcheck (the memory checker) shows any invalid reads, |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame^] | 149 | invalid writes or invalid frees in your program, the above may |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 150 | happen. Reason is that your program may trash Valgrind's low-level |
| 151 | memory manager, which then dies with the above assertion, or |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame^] | 152 | something similar. The cure is to fix your program so that it |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 153 | doesn't do any illegal memory accesses. The above failure will |
| 154 | hopefully go away after that.</para> |
| 155 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 156 | </qandaentry> |
| 157 | |
| 158 | <qandaentry id="faq.msgdeath"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 159 | <question id="q-msgdeath"> |
| 160 | <para>My program dies, printing a message like this along the |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 161 | way:</para> |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame^] | 162 | <screen>vex x86->IR: unhandled instruction bytes: 0x66 0xF 0x2E 0x5</screen> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 163 | </question> |
| 164 | <answer id="a-msgdeath"> |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame^] | 165 | <para>Older versions did not support some x86 and amd64 instructions, |
| 166 | particularly SSE/SSE2/SSE3 instructions. Try a newer Valgrind; we now |
| 167 | support almost all instructions. If it still breaks, file a bug |
| 168 | report.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 169 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 170 | <para>Another possibility is that your program has a bug and |
| 171 | erroneously jumps to a non-code address, in which case you'll get a |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 172 | SIGILL signal. Memcheck may issue a warning just before |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame^] | 173 | this happens, but it might not if the jump happens to land in |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 174 | addressable memory.</para> |
| 175 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 176 | </qandaentry> |
| 177 | |
njn | dde37b4 | 2005-10-06 18:58:33 +0000 | [diff] [blame] | 178 | <qandaentry id="faq.java"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 179 | <question id="q-java"> |
| 180 | <para>I tried running a Java program (or another program that uses a |
| 181 | just-in-time compiler) under Valgrind but something went wrong. |
| 182 | Does Valgrind handle such programs?</para> |
| 183 | </question> |
| 184 | <answer id="a-java"> |
| 185 | <para>Valgrind can handle dynamically generated code, so long as |
| 186 | none of the generated code is later overwritten by other generated |
| 187 | code. If this happens, though, things will go wrong as Valgrind |
| 188 | will continue running its translations of the old code (this is true |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame^] | 189 | on x86 and amd64, on PowerPC there are explicit cache flush |
| 190 | instructions which Valgrind detects and honours). |
| 191 | You should try running with |
| 192 | <option>--smc-check=all</option> in this case. Valgrind will run |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 193 | much more slowly, but should detect the use of the out-of-date |
| 194 | code.</para> |
| 195 | |
| 196 | <para>Alternativaly, if you have the source code to the JIT compiler |
| 197 | you can insert calls to the |
| 198 | <computeroutput>VALGRIND_DISCARD_TRANSLATIONS</computeroutput> |
| 199 | client request to mark out-of-date code, saving you from using |
| 200 | <option>--smc-check=all</option>.</para> |
| 201 | |
| 202 | <para>Apart from this, in theory Valgrind can run any Java program |
| 203 | just fine, even those that use JNI and are partially implemented in |
| 204 | other languages like C and C++. In practice, Java implementations |
| 205 | tend to do nasty things that most programs do not, and Valgrind |
| 206 | sometimes falls over these corner cases.</para> |
| 207 | |
| 208 | <para>If your Java programs do not run under Valgrind, even with |
| 209 | <option>--smc-check=all</option>, please file a bug report and |
| 210 | hopefully we'll be able to fix the problem.</para> |
| 211 | </answer> |
njn | dde37b4 | 2005-10-06 18:58:33 +0000 | [diff] [blame] | 212 | </qandaentry> |
| 213 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 214 | </qandadiv> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 215 | |
| 216 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 217 | <!-- Valgrind behaves unexpectedly --> |
| 218 | <qandadiv id="faq.unexpected" xreflabel="Valgrind behaves unexpectedly"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 219 | <title>Valgrind behaves unexpectedly</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 220 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 221 | <qandaentry id="faq.reports"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 222 | <question id="q-reports"> |
| 223 | <para>My program uses the C++ STL and string classes. Valgrind |
| 224 | reports 'still reachable' memory leaks involving these classes at |
| 225 | the exit of the program, but there should be none.</para> |
| 226 | </question> |
| 227 | <answer id="a-reports"> |
| 228 | <para>First of all: relax, it's probably not a bug, but a feature. |
| 229 | Many implementations of the C++ standard libraries use their own |
| 230 | memory pool allocators. Memory for quite a number of destructed |
| 231 | objects is not immediately freed and given back to the OS, but kept |
| 232 | in the pool(s) for later re-use. The fact that the pools are not |
| 233 | freed at the exit() of the program cause Valgrind to report this |
| 234 | memory as still reachable. The behaviour not to free pools at the |
| 235 | exit() could be called a bug of the library though.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 236 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 237 | <para>Using gcc, you can force the STL to use malloc and to free |
| 238 | memory as soon as possible by globally disabling memory caching. |
| 239 | Beware! Doing so will probably slow down your program, sometimes |
| 240 | drastically.</para> |
| 241 | <itemizedlist> |
| 242 | <listitem> |
| 243 | <para>With gcc 2.91, 2.95, 3.0 and 3.1, compile all source using |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame^] | 244 | the STL with <literal>-D__USE_MALLOC</literal>. Beware! This was |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 245 | removed from gcc starting with version 3.3.</para> |
| 246 | </listitem> |
| 247 | <listitem> |
| 248 | <para>With gcc 3.2.2 and later, you should export the |
| 249 | environment variable <literal>GLIBCPP_FORCE_NEW</literal> before |
| 250 | running your program.</para> |
| 251 | </listitem> |
| 252 | <listitem> |
| 253 | <para>With gcc 3.4 and later, that variable has changed name to |
| 254 | <literal>GLIBCXX_FORCE_NEW</literal>.</para> |
| 255 | </listitem> |
| 256 | </itemizedlist> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 257 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 258 | <para>There are other ways to disable memory pooling: using the |
| 259 | <literal>malloc_alloc</literal> template with your objects (not |
| 260 | portable, but should work for gcc) or even writing your own memory |
| 261 | allocators. But all this goes beyond the scope of this FAQ. Start |
| 262 | by reading |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame^] | 263 | <ulink |
| 264 | url="http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#4_4_leak"> |
| 265 | http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#4_4_leak</ulink> if |
| 266 | you absolutely want to do that. But beware: |
| 267 | allocators belong to the more messy parts of the STL and |
| 268 | people went to great lengths to make the STL portable across |
| 269 | platforms. Chances are good that your solution will work on your |
| 270 | platform, but not on others.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 271 | </answer> |
| 272 | </qandaentry> |
| 273 | |
| 274 | |
| 275 | <qandaentry id="faq.unhelpful"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 276 | <question id="q-unhelpful"> |
| 277 | <para>The stack traces given by Memcheck (or another tool) aren't |
| 278 | helpful. How can I improve them?</para> |
| 279 | </question> |
| 280 | <answer id="a-unhelpful"> |
| 281 | <para>If they're not long enough, use <option>--num-callers</option> |
| 282 | to make them longer.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 283 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 284 | <para>If they're not detailed enough, make sure you are compiling |
| 285 | with <option>-g</option> to add debug information. And don't strip |
| 286 | symbol tables (programs should be unstripped unless you run 'strip' |
| 287 | on them; some libraries ship stripped).</para> |
njn | 0211ff3 | 2005-05-15 14:49:24 +0000 | [diff] [blame] | 288 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 289 | <para>Also, for leak reports involving shared objects, if the shared |
| 290 | object is unloaded before the program terminates, Valgrind will |
| 291 | discard the debug information and the error message will be full of |
| 292 | <literal>???</literal> entries. The workaround here is to avoid |
| 293 | calling dlclose() on these shared objects.</para> |
| 294 | |
| 295 | <para>Also, <option>-fomit-frame-pointer</option> and |
| 296 | <option>-fstack-check</option> can make stack traces worse.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 297 | |
| 298 | <para>Some example sub-traces:</para> |
| 299 | |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 300 | <itemizedlist> |
| 301 | <listitem> |
| 302 | <para>With debug information and unstripped (best):</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 303 | <programlisting> |
| 304 | Invalid write of size 1 |
| 305 | at 0x80483BF: really (malloc1.c:20) |
| 306 | by 0x8048370: main (malloc1.c:9) |
| 307 | </programlisting> |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 308 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 309 | |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 310 | <listitem> |
| 311 | <para>With no debug information, unstripped:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 312 | <programlisting> |
| 313 | Invalid write of size 1 |
| 314 | at 0x80483BF: really (in /auto/homes/njn25/grind/head5/a.out) |
| 315 | by 0x8048370: main (in /auto/homes/njn25/grind/head5/a.out) |
| 316 | </programlisting> |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 317 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 318 | |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 319 | <listitem> |
| 320 | <para>With no debug information, stripped:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 321 | <programlisting> |
| 322 | Invalid write of size 1 |
| 323 | at 0x80483BF: (within /auto/homes/njn25/grind/head5/a.out) |
| 324 | by 0x8048370: (within /auto/homes/njn25/grind/head5/a.out) |
| 325 | by 0x42015703: __libc_start_main (in /lib/tls/libc-2.3.2.so) |
| 326 | by 0x80482CC: (within /auto/homes/njn25/grind/head5/a.out) |
| 327 | </programlisting> |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 328 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 329 | |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 330 | <listitem> |
| 331 | <para>With debug information and -fomit-frame-pointer:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 332 | <programlisting> |
| 333 | Invalid write of size 1 |
| 334 | at 0x80483C4: really (malloc1.c:20) |
| 335 | by 0x42015703: __libc_start_main (in /lib/tls/libc-2.3.2.so) |
| 336 | by 0x80482CC: ??? (start.S:81) |
| 337 | </programlisting> |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 338 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 339 | |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 340 | <listitem> |
| 341 | <para>A leak error message involving an unloaded shared object:</para> |
njn | 0211ff3 | 2005-05-15 14:49:24 +0000 | [diff] [blame] | 342 | <programlisting> |
| 343 | 84 bytes in 1 blocks are possibly lost in loss record 488 of 713 |
| 344 | at 0x1B9036DA: operator new(unsigned) (vg_replace_malloc.c:132) |
| 345 | by 0x1DB63EEB: ??? |
| 346 | by 0x1DB4B800: ??? |
| 347 | by 0x1D65E007: ??? |
| 348 | by 0x8049EE6: main (main.cpp:24) |
| 349 | </programlisting> |
njn | 15d7c34 | 2005-09-30 01:43:32 +0000 | [diff] [blame] | 350 | </listitem> |
| 351 | </itemizedlist> |
njn | 0211ff3 | 2005-05-15 14:49:24 +0000 | [diff] [blame] | 352 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 353 | </answer> |
| 354 | </qandaentry> |
| 355 | |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 356 | <qandaentry id="faq.aliases"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 357 | <question id="q-aliases"> |
| 358 | <para>The stack traces given by Memcheck (or another tool) seem to |
| 359 | have the wrong function name in them. What's happening?</para> |
| 360 | </question> |
| 361 | <answer id="a-aliases"> |
| 362 | <para>Occasionally Valgrind stack traces get the wrong function |
| 363 | names. This is caused by glibc using aliases to effectively give |
| 364 | one function two names. Most of the time Valgrind chooses a |
| 365 | suitable name, but very occasionally it gets it wrong. Examples we |
| 366 | know of are printing 'bcmp' instead of 'memcmp', 'index' instead of |
| 367 | 'strchr', and 'rindex' instead of 'strrchr'.</para> |
| 368 | </answer> |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 369 | </qandaentry> |
| 370 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 371 | </qandadiv> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 372 | |
| 373 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 374 | |
| 375 | <!-- Memcheck doesn't find my bug --> |
| 376 | <qandadiv id="faq.notfound" xreflabel="Memcheck doesn't find my bug"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 377 | <title>Memcheck doesn't find my bug</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 378 | |
| 379 | <qandaentry id="faq.hiddenbug"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 380 | <question id="q-hiddenbug"> |
| 381 | <para>I try running "valgrind --tool=memcheck my_program" and get |
| 382 | Valgrind's startup message, but I don't get any errors and I know my |
| 383 | program has errors.</para> |
| 384 | </question> |
| 385 | <answer id="a-hiddenbug"> |
| 386 | <para>There are two possible causes of this.</para> |
njn | a11b9b0 | 2005-03-27 17:05:08 +0000 | [diff] [blame] | 387 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 388 | <para>First, by default, Valgrind only traces the top-level process. |
| 389 | So if your program spawns children, they won't be traced by Valgrind |
| 390 | by default. Also, if your program is started by a shell script, |
| 391 | Perl script, or something similar, Valgrind will trace the shell, or |
| 392 | the Perl interpreter, or equivalent.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 393 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 394 | <para>To trace child processes, use the |
| 395 | <option>--trace-children=yes</option> option.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 396 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 397 | <para>If you are tracing large trees of processes, it can be less |
| 398 | disruptive to have the output sent over the network. Give Valgrind |
| 399 | the flag <option>--log-socket=127.0.0.1:12345</option> (if you want |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame^] | 400 | logging output sent to port <literal>12345</literal> on |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 401 | <literal>localhost</literal>). You can use the valgrind-listener |
| 402 | program to listen on that port:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 403 | <programlisting> |
| 404 | valgrind-listener 12345 |
| 405 | </programlisting> |
| 406 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 407 | <para>Obviously you have to start the listener process first. See |
| 408 | the manual for more details.</para> |
njn | a11b9b0 | 2005-03-27 17:05:08 +0000 | [diff] [blame] | 409 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 410 | <para>Second, if your program is statically linked, most Valgrind |
| 411 | tools won't work as well, because they won't be able to replace |
| 412 | certain functions, such as malloc(), with their own versions. A key |
| 413 | indicator of this is if Memcheck says: |
njn | a11b9b0 | 2005-03-27 17:05:08 +0000 | [diff] [blame] | 414 | <programlisting> |
njn | 5666ee6 | 2005-12-19 19:38:02 +0000 | [diff] [blame] | 415 | All heap blocks were freed -- no leaks are possible |
njn | a11b9b0 | 2005-03-27 17:05:08 +0000 | [diff] [blame] | 416 | </programlisting> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 417 | when you know your program calls malloc(). The workaround is to |
| 418 | avoid statically linking your program.</para> |
| 419 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 420 | </qandaentry> |
| 421 | |
| 422 | |
| 423 | <qandaentry id="faq.overruns"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 424 | <question id="q-overruns"> |
| 425 | <para>Why doesn't Memcheck find the array overruns in this |
| 426 | program?</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 427 | <programlisting> |
| 428 | int static[5]; |
| 429 | |
| 430 | int main(void) |
| 431 | { |
| 432 | int stack[5]; |
| 433 | |
| 434 | static[5] = 0; |
| 435 | stack [5] = 0; |
| 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | </programlisting> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 440 | </question> |
| 441 | <answer id="a-overruns"> |
| 442 | <para>Unfortunately, Memcheck doesn't do bounds checking on static |
| 443 | or stack arrays. We'd like to, but it's just not possible to do in |
| 444 | a reasonable way that fits with how Memcheck works. Sorry.</para> |
| 445 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 446 | </qandaentry> |
| 447 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 448 | </qandadiv> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 449 | |
| 450 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 451 | |
| 452 | <!-- Miscellaneous --> |
| 453 | <qandadiv id="faq.misc" xreflabel="Miscellaneous"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 454 | <title>Miscellaneous</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 455 | |
| 456 | <qandaentry id="faq.writesupp"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 457 | <question id="q-writesupp"> |
| 458 | <para>I tried writing a suppression but it didn't work. Can you |
| 459 | write my suppression for me?</para> |
| 460 | </question> |
| 461 | <answer id="a-writesupp"> |
| 462 | <para>Yes! Use the <option>--gen-suppressions=yes</option> feature |
| 463 | to spit out suppressions automatically for you. You can then edit |
| 464 | them if you like, eg. combining similar automatically generated |
| 465 | suppressions using wildcards like <literal>'*'</literal>.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 466 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 467 | <para>If you really want to write suppressions by hand, read the |
| 468 | manual carefully. Note particularly that C++ function names must be |
sewardj | 08e31e2 | 2007-05-23 21:58:33 +0000 | [diff] [blame^] | 469 | mangled (that is, not demangled).</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 470 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 471 | </qandaentry> |
| 472 | |
| 473 | |
| 474 | <qandaentry id="faq.deflost"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 475 | <question id="q-deflost"> |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 476 | <para>With Memcheck's memory leak detector, what's the |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 477 | difference between "definitely lost", "possibly lost", "still |
| 478 | reachable", and "suppressed"?</para> |
| 479 | </question> |
| 480 | <answer id="a-deflost"> |
| 481 | <para>The details are in the Memcheck section of the user |
| 482 | manual.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 483 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 484 | <para>In short:</para> |
| 485 | <itemizedlist> |
| 486 | <listitem> |
| 487 | <para>"definitely lost" means your program is leaking memory -- |
| 488 | fix it!</para> |
| 489 | </listitem> |
| 490 | <listitem> |
| 491 | <para>"possibly lost" means your program is probably leaking |
| 492 | memory, unless you're doing funny things with pointers.</para> |
| 493 | </listitem> |
| 494 | <listitem> |
| 495 | <para>"still reachable" means your program is probably ok -- it |
| 496 | didn't free some memory it could have. This is quite common and |
| 497 | often reasonable. Don't use |
| 498 | <option>--show-reachable=yes</option> if you don't want to see |
| 499 | these reports.</para> |
| 500 | </listitem> |
| 501 | <listitem> |
| 502 | <para>"suppressed" means that a leak error has been suppressed. |
| 503 | There are some suppressions in the default suppression files. |
| 504 | You can ignore suppressed errors.</para> |
| 505 | </listitem> |
| 506 | </itemizedlist> |
| 507 | </answer> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 508 | </qandaentry> |
| 509 | |
njn | 3fdb362 | 2006-10-20 22:16:57 +0000 | [diff] [blame] | 510 | <qandaentry id="faq.undeferrors"> |
| 511 | <question id="q-undeferrors"> |
| 512 | <para>Memcheck's uninitialised value errors are hard to track down, |
| 513 | because they are often reported some time after they are caused. Could |
| 514 | Memcheck record a trail of operations to better link the cause to the |
| 515 | effect? Or maybe just eagerly report any copies of uninitialised |
| 516 | memory values?</para> |
| 517 | </question> |
| 518 | <answer id="a-undeferrors"> |
| 519 | <para>We'd love to improve these errors, but we don't know how to do it |
| 520 | without huge performance penalties.</para> |
| 521 | |
| 522 | <para>You can use the client request |
| 523 | <computeroutput>VALGRIND_CHECK_VALUE_IS_DEFINED</computeroutput> to help |
| 524 | track these errors down -- work backwards from the point where the |
| 525 | uninitialised error occurs, checking suspect values until you find the |
| 526 | cause. This requires editing, compiling and re-running your program |
| 527 | multiple times, which is a pain, but still easier than debugging the |
| 528 | problem without Memcheck's help.</para> |
| 529 | |
| 530 | <para>As for eager reporting of copies of uninitialised memory values, |
| 531 | this has been suggested multiple times. Unfortunately, almost all |
| 532 | programs legitimately copy uninitialise memory values around (because |
| 533 | compilers pad structs to preserve alignment) and eager checking leads to |
| 534 | hundreds of false positives. Therefore Memcheck does not support eager |
| 535 | checking at this time.</para> |
| 536 | </answer> |
| 537 | </qandaentry> |
| 538 | |
| 539 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 540 | </qandadiv> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 541 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 542 | |
| 543 | |
| 544 | <!-- Further Assistance --> |
| 545 | <qandadiv id="faq.help" xreflabel="How To Get Further Assistance"> |
| 546 | <title>How To Get Further Assistance</title> |
| 547 | |
| 548 | <qandaentry id="e-help"> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 549 | <!-- <question><para/></question> --> |
| 550 | <answer id="a-help"> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 551 | <para>Please read all of this section before posting.</para> |
| 552 | |
| 553 | <para>If you think an answer is incomplete or inaccurate, please |
| 554 | e-mail <ulink url="mailto:&vg-vemail;">&vg-vemail;</ulink>.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 555 | |
de | 97ab7e7 | 2005-11-27 18:19:40 +0000 | [diff] [blame] | 556 | <para>Read the appropriate section(s) of the |
| 557 | <ulink url="&vg-bookset;">Valgrind Documentation</ulink>.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 558 | |
de | 97ab7e7 | 2005-11-27 18:19:40 +0000 | [diff] [blame] | 559 | <para>Read the |
| 560 | <ulink url="&vg-dist-docs;">Distribution Documents</ulink>.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 561 | |
| 562 | <para><ulink url="http://search.gmane.org">Search</ulink> the |
| 563 | <ulink url="http://news.gmane.org/gmane.comp.debugging.valgrind">valgrind-users</ulink> mailing list archives, using the group name |
| 564 | <computeroutput>gmane.comp.debugging.valgrind</computeroutput>.</para> |
| 565 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 566 | <para>Only when you have tried all of these things and are still |
| 567 | stuck, should you post to the |
| 568 | <ulink url="&vg-users-list;">valgrind-users mailing list</ulink>. In |
| 569 | which case, please read the following carefully. Making a complete |
| 570 | posting will greatly increase the chances that an expert or fellow |
| 571 | user reading it will have enough information and motivation to |
| 572 | reply.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 573 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 574 | <para>Make sure you give full details of the problem, including the |
njn | 1ac2f0d | 2005-12-04 19:26:00 +0000 | [diff] [blame] | 575 | full output of <computeroutput>valgrind -v <your-prog></computeroutput>, if |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 576 | applicable. Also which Linux distribution you're using (Red Hat, |
| 577 | Debian, etc) and its version number.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 578 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 579 | <para>You are in little danger of making your posting too long unless |
| 580 | you include large chunks of Valgrind's (unsuppressed) output, so err |
| 581 | on the side of giving too much information.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 582 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 583 | <para>Clearly written subject lines and message bodies are |
| 584 | appreciated, too.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 585 | |
| 586 | <para>Finally, remember that, despite the fact that most of the |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 587 | community are very helpful and responsive to emailed questions, you |
| 588 | are probably requesting help from unpaid volunteers, so you have no |
| 589 | guarantee of receiving an answer.</para> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 590 | </answer> |
| 591 | |
| 592 | </qandaentry> |
| 593 | </qandadiv> |
| 594 | |
| 595 | |
| 596 | <!-- FAQ ends here --> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 597 | </qandaset> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 598 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 599 | |
| 600 | |
| 601 | <!-- template |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 602 | <qandadiv id="faq.installing" xreflabel="Installing"> |
| 603 | <title>Installing</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 604 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 605 | <qandaentry id="faq.problem"> |
| 606 | <question id="q-problem"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 607 | <para></para> |
| 608 | </question> |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 609 | <answer id="a-problem"> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 610 | <para></para> |
| 611 | </answer> |
| 612 | </qandaentry> |
| 613 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 614 | </qandadiv> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 615 | --> |
| 616 | |
de | 9bec93c | 2005-11-25 05:36:48 +0000 | [diff] [blame] | 617 | </article> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 618 | |
| 619 | </book> |